diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2018-05-11 23:40:26 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2018-05-11 23:40:26 +0200 |
commit | 8d40122372e31052f10e68005c989c5f067916aa (patch) | |
tree | daa330cb5ce02cc028d8b2510c6c80ff7dccabb6 | |
parent | 19e10aaf3e1683548e0dd5da81ba1d5c20714a0c (diff) | |
download | json-rpc-shell-8d40122372e31052f10e68005c989c5f067916aa.tar.gz json-rpc-shell-8d40122372e31052f10e68005c989c5f067916aa.tar.xz json-rpc-shell-8d40122372e31052f10e68005c989c5f067916aa.zip |
Display unexpected messages, too
-rw-r--r-- | json-rpc-shell.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/json-rpc-shell.c b/json-rpc-shell.c index 77a9fa9..eda958b 100644 --- a/json-rpc-shell.c +++ b/json-rpc-shell.c @@ -1917,6 +1917,9 @@ backend_ws_on_control_frame return true; } +static int normalize_whitespace (int c) { return isspace_ascii (c) ? ' ' : c; } + +/// Caller guarantees that data[len] is a NUL byte (because of iconv_xstrdup()) static bool backend_ws_on_message (struct ws_context *self, enum ws_opcode type, const void *data, size_t len) @@ -1926,7 +1929,12 @@ backend_ws_on_message (struct ws_context *self, if (!self->waiting_for_event || !self->response_buffer) { - print_warning ("unexpected message received"); + char *s = iconv_xstrdup (self->ctx->term_from_utf8, + (char *) data, len + 1 /* null byte */, NULL); + // Does not affect JSON and ensures the message is printed out okay + cstr_transform (s, normalize_whitespace); + print_warning ("unexpected message received: %s", s); + free (s); return true; } |