summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-09-08 20:38:41 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-09-08 20:53:50 +0200
commitfdd447a7ea42f8eee89b43d75a65d1ad4516773b (patch)
tree44f43859fbff05cc5d78e77669de326907b8c80a
parent0cbcf609923f9e05195705835650c4cc9a96b80d (diff)
downloadjson-rpc-shell-fdd447a7ea42f8eee89b43d75a65d1ad4516773b.tar.gz
json-rpc-shell-fdd447a7ea42f8eee89b43d75a65d1ad4516773b.tar.xz
json-rpc-shell-fdd447a7ea42f8eee89b43d75a65d1ad4516773b.zip
Some twiddling
- also accept the obsolete application/json-rpc content type - don't quote regular responses - don't separate results with newlines - instead make sure to print a newline upon receiving EOF
-rw-r--r--json-rpc-shell.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/json-rpc-shell.c b/json-rpc-shell.c
index b880038..9edb937 100644
--- a/json-rpc-shell.c
+++ b/json-rpc-shell.c
@@ -84,6 +84,7 @@ log_message (const char *quote, const char *fmt, ...)
// `fatal' is reserved for unexpected failures that would harm further operation
+// TODO: colors (probably copy over from stracepkg)
#define print_fatal(...) log_message ("fatal: ", __VA_ARGS__)
#define print_error(...) log_message ("error: ", __VA_ARGS__)
#define print_warning(...) log_message ("warning: ", __VA_ARGS__)
@@ -351,7 +352,7 @@ parse_response (struct app_context *ctx, struct str *buf)
if (!s)
print_error ("character conversion failed for `%s'", "result");
else
- printf ("result: %s\n", s);
+ printf ("%s\n", s);
free (s);
}
@@ -442,10 +443,11 @@ make_json_rpc_call (struct app_context *ctx,
bool success = false;
if (id)
{
+ // TODO: maybe also accept "...; charset=UTF-8"
if (!type)
print_warning ("missing `Content-Type' header");
- else if (strcmp (type, "application/json"))
- // FIXME: expect e.g. application/json; charset=UTF-8
+ else if (strcmp (type, "application/json")
+ && strcmp (type, "application/json-rpc")) // obsolete
print_warning ("unexpected `Content-Type' header: %s", type);
success = parse_response (ctx, &buf);
@@ -560,7 +562,6 @@ fail_parse:
json_decref (args[i]);
fail:
free (input);
- putchar ('\n');
}
static void
@@ -673,6 +674,7 @@ main (int argc, char *argv[])
char *encoding = nl_langinfo (CODESET);
#ifdef __linux__
// XXX: not quite sure if this is actually desirable
+ // TODO: instead retry with JSON_ENSURE_ASCII
encoding = strdup_printf ("%s//TRANSLIT", encoding);
#endif // __linux__
@@ -713,6 +715,7 @@ main (int argc, char *argv[])
process_input (&ctx, line);
free (line);
}
+ putchar ('\n');
char *dir = strdup (history_path);
(void) mkdir_with_parents (dirname (dir));