Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--agent/tcf/framework/cache.h4
-rw-r--r--agent/tcf/framework/json.c207
-rw-r--r--agent/tcf/framework/json.h6
-rw-r--r--agent/tcf/framework/protocol.c2
-rw-r--r--agent/tcf/services/breakpoints.c199
-rw-r--r--agent/tcf/services/contextquery.c6
-rw-r--r--agent/tcf/services/diagnostics.c34
-rw-r--r--agent/tcf/services/discovery.c8
-rw-r--r--agent/tcf/services/expressions.c30
-rw-r--r--agent/tcf/services/filesystem.c108
-rw-r--r--agent/tcf/services/linenumbers.c18
-rw-r--r--agent/tcf/services/linenumbers_proxy.c4
-rw-r--r--agent/tcf/services/memorymap.c10
-rw-r--r--agent/tcf/services/memoryservice.c34
-rw-r--r--agent/tcf/services/pathmap.c6
-rw-r--r--agent/tcf/services/processes.c58
-rw-r--r--agent/tcf/services/registers.c38
-rw-r--r--agent/tcf/services/runctrl.c34
-rw-r--r--agent/tcf/services/stacktrace.c8
-rw-r--r--agent/tcf/services/streamsservice.c34
-rw-r--r--agent/tcf/services/symbols.c58
-rw-r--r--agent/tcf/services/symbols_proxy.c52
-rw-r--r--agent/tcf/services/sysmon.c48
-rw-r--r--agent/tcf/services/terminals.c24
-rw-r--r--server/tcf/services/context-proxy.c96
25 files changed, 538 insertions, 588 deletions
diff --git a/agent/tcf/framework/cache.h b/agent/tcf/framework/cache.h
index 8c97f8ba..35a916cd 100644
--- a/agent/tcf/framework/cache.h
+++ b/agent/tcf/framework/cache.h
@@ -81,8 +81,8 @@
CommandArgs args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
// Start cache client state machine:
diff --git a/agent/tcf/framework/json.c b/agent/tcf/framework/json.c
index bb642d39..e05689b1 100644
--- a/agent/tcf/framework/json.c
+++ b/agent/tcf/framework/json.c
@@ -160,7 +160,23 @@ void json_write_string_len(OutputStream * out, const char * str, size_t len) {
}
}
-static int readHex(InputStream * inp) {
+static const char * char2str(int ch, char * buf) {
+ if (ch == MARKER_EOS) return "<eos>";
+ if (ch == MARKER_EOM) return "<eom>";
+ if (ch == MARKER_EOA) return "<eoa>";
+ if (ch >= ' ' && ch < 127) sprintf(buf, "'%c'", ch);
+ else sprintf(buf, "'\\%3o'", ch);
+ return buf;
+}
+
+static void check_char(int ch, int exp) {
+ char s0[16], s1[16];
+ if (exp == ch) return;
+ str_fmt_exception(ERR_JSON_SYNTAX, "Expected %s, got %s",
+ char2str(exp, s0), char2str(ch, s1));
+}
+
+static int read_hex_digit(InputStream * inp) {
int ch = read_stream(inp);
if (ch >= '0' && ch <= '9') return ch - '0';
if (ch >= 'A' && ch <= 'F') return ch - 'A' + 10;
@@ -169,11 +185,11 @@ static int readHex(InputStream * inp) {
return 0;
}
-static int readHexChar(InputStream * inp) {
- int n = readHex(inp) << 12;
- n |= readHex(inp) << 8;
- n |= readHex(inp) << 4;
- n |= readHex(inp);
+static int read_hex_char(InputStream * inp) {
+ int n = read_hex_digit(inp) << 12;
+ n |= read_hex_digit(inp) << 8;
+ n |= read_hex_digit(inp) << 4;
+ n |= read_hex_digit(inp);
return n;
}
@@ -188,7 +204,7 @@ static unsigned read_esc_char(InputStream * inp, char * utf8) {
case 'n': ch = '\n'; break;
case 'r': ch = '\r'; break;
case 't': ch = '\t'; break;
- case 'u': ch = readHexChar(inp); break;
+ case 'u': ch = read_hex_char(inp); break;
default: exception(ERR_JSON_SYNTAX);
}
/* 'ch' can be wide character - convert it to UTF-8 sequence */
@@ -211,13 +227,13 @@ int json_read_string(InputStream * inp, char * str, size_t size) {
unsigned i = 0;
int ch = read_stream(inp);
if (ch == 'n') {
- if (read_stream(inp) != 'u') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, 'u');
+ json_test_char(inp, 'l');
+ json_test_char(inp, 'l');
str[0] = 0;
return -1;
}
- if (ch != '"') exception(ERR_JSON_SYNTAX);
+ if (ch != '"') exception(ERR_PROTOCOL);
for (;;) {
ch = read_stream(inp);
if (ch < 0) exception(ERR_JSON_SYNTAX);
@@ -244,13 +260,13 @@ char * json_read_alloc_string(InputStream * inp) {
char * str = NULL;
int ch = read_stream(inp);
if (ch == 'n') {
- if (read_stream(inp) != 'u') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, 'u');
+ json_test_char(inp, 'l');
+ json_test_char(inp, 'l');
return NULL;
}
buf_pos = 0;
- if (ch != '"') exception(ERR_JSON_SYNTAX);
+ if (ch != '"') exception(ERR_PROTOCOL);
for (;;) {
ch = read_stream(inp);
if (ch < 0) exception(ERR_JSON_SYNTAX);
@@ -274,16 +290,16 @@ char * json_read_alloc_string(InputStream * inp) {
int json_read_boolean(InputStream * inp) {
int ch = read_stream(inp);
if (ch == 'f') {
- if (read_stream(inp) != 'a') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 's') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'e') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, 'a');
+ json_test_char(inp, 'l');
+ json_test_char(inp, 's');
+ json_test_char(inp, 'e');
return 0;
}
if (ch == 't') {
- if (read_stream(inp) != 'r') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'u') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'e') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, 'r');
+ json_test_char(inp, 'u');
+ json_test_char(inp, 'e');
return 1;
}
exception(ERR_JSON_SYNTAX);
@@ -410,40 +426,38 @@ double json_read_double(InputStream * inp) {
int json_read_struct(InputStream * inp, JsonStructCallBack * call_back, void * arg) {
int ch = read_stream(inp);
if (ch == 'n') {
- if (read_stream(inp) != 'u') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, 'u');
+ json_test_char(inp, 'l');
+ json_test_char(inp, 'l');
return 0;
}
- if (ch == '{') {
- ch = peek_stream(inp);
- if (ch != '}') {
- for (;;) {
- char nm[256];
- json_read_string(inp, nm, sizeof(nm));
- ch = read_stream(inp);
- if (ch != ':') exception(ERR_JSON_SYNTAX);
- call_back(inp, nm, arg);
- ch = read_stream(inp);
- if (ch == '}') break;
- if (ch != ',') exception(ERR_JSON_SYNTAX);
- }
- }
- else {
- read_stream(inp);
- }
+ if (ch != '{') {
+ exception(ERR_PROTOCOL);
return 1;
}
- exception(ERR_JSON_SYNTAX);
- return 0;
+ if (peek_stream(inp) == '}') {
+ read_stream(inp);
+ return 1;
+ }
+ for (;;) {
+ char nm[256];
+ json_read_string(inp, nm, sizeof(nm));
+ json_test_char(inp, ':');
+ call_back(inp, nm, arg);
+ ch = read_stream(inp);
+ if (ch == ',') continue;
+ check_char(ch, '}');
+ break;
+ }
+ return 1;
}
char ** json_read_alloc_string_array(InputStream * inp, int * cnt) {
int ch = read_stream(inp);
if (ch == 'n') {
- if (read_stream(inp) != 'u') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, 'u');
+ json_test_char(inp, 'l');
+ json_test_char(inp, 'l');
if (cnt) *cnt = 0;
return NULL;
}
@@ -475,13 +489,13 @@ char ** json_read_alloc_string_array(InputStream * inp, int * cnt) {
len_buf = (size_t *)loc_realloc(len_buf, len_buf_size * sizeof(size_t));
}
if (ch == 'n') {
- if (read_stream(inp) != 'u') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, 'u');
+ json_test_char(inp, 'l');
+ json_test_char(inp, 'l');
}
else {
size_t buf_pos0 = buf_pos;
- if (ch != '"') exception(ERR_JSON_SYNTAX);
+ if (ch != '"') exception(ERR_PROTOCOL);
for (;;) {
ch = read_stream(inp);
if (ch < 0) exception(ERR_JSON_SYNTAX);
@@ -502,8 +516,8 @@ char ** json_read_alloc_string_array(InputStream * inp, int * cnt) {
len_buf[len_pos++] = len;
ch = read_stream(inp);
if (ch == ',') continue;
- if (ch == ']') break;
- exception(ERR_JSON_SYNTAX);
+ check_char(ch, ']');
+ break;
}
}
buf_add(0);
@@ -531,9 +545,9 @@ char ** json_read_alloc_string_array(InputStream * inp, int * cnt) {
int json_read_array(InputStream * inp, JsonArrayCallBack * call_back, void * arg) {
int ch = read_stream(inp);
if (ch == 'n') {
- if (read_stream(inp) != 'u') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, 'u');
+ json_test_char(inp, 'l');
+ json_test_char(inp, 'l');
return 0;
}
if (ch != '[') {
@@ -548,8 +562,8 @@ int json_read_array(InputStream * inp, JsonArrayCallBack * call_back, void * arg
call_back(inp, arg);
ch = read_stream(inp);
if (ch == ',') continue;
- if (ch == ']') break;
- exception(ERR_JSON_SYNTAX);
+ check_char(ch, ']');
+ break;
}
return 1;
}
@@ -563,15 +577,15 @@ void json_read_binary_start(JsonReadBinaryState * state, InputStream * inp) {
if (ch == '(') {
state->encoding = ENCODING_BINARY;
state->size_start = json_read_ulong(inp);
- if (read_stream(inp) != ')') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, ')');
}
else if (ch == '"') {
state->encoding = ENCODING_BASE64;
}
else if (ch == 'n') {
- if (read_stream(inp) != 'u') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, 'u');
+ json_test_char(inp, 'l');
+ json_test_char(inp, 'l');
state->encoding = ENCODING_BINARY;
state->size_start = 0;
}
@@ -625,7 +639,7 @@ void json_read_binary_end(JsonReadBinaryState * state) {
assert(state->size_start == state->size_done);
}
else {
- if (read_stream(state->inp) != '"') exception(ERR_JSON_SYNTAX);
+ json_test_char(state->inp, '"');
}
}
@@ -635,9 +649,9 @@ char * json_read_alloc_binary(InputStream * inp, size_t * size) {
*size = 0;
if (ch == 'n') {
read_stream(inp);
- if (read_stream(inp) != 'u') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, 'u');
+ json_test_char(inp, 'l');
+ json_test_char(inp, 'l');
}
else {
JsonReadBinaryState state;
@@ -716,11 +730,8 @@ void json_write_binary_end(JsonWriteBinaryState * state) {
assert(state->size_start == state->size_done);
}
else {
- size_t rem;
-
- if ((rem = state->rem) > 0) {
- write_base64(state->out, state->buf, rem);
- }
+ size_t rem = state->rem;
+ if (rem > 0) write_base64(state->out, state->buf, rem);
write_stream(state->out, '"');
}
}
@@ -786,22 +797,22 @@ static int skip_char(InputStream * inp) {
static void skip_object(InputStream * inp) {
int ch = skip_char(inp);
if (ch == 'n') {
- if (skip_char(inp) != 'u') exception(ERR_JSON_SYNTAX);
- if (skip_char(inp) != 'l') exception(ERR_JSON_SYNTAX);
- if (skip_char(inp) != 'l') exception(ERR_JSON_SYNTAX);
+ check_char(skip_char(inp), 'u');
+ check_char(skip_char(inp), 'l');
+ check_char(skip_char(inp), 'l');
return;
}
if (ch == 'f') {
- if (skip_char(inp) != 'a') exception(ERR_JSON_SYNTAX);
- if (skip_char(inp) != 'l') exception(ERR_JSON_SYNTAX);
- if (skip_char(inp) != 's') exception(ERR_JSON_SYNTAX);
- if (skip_char(inp) != 'e') exception(ERR_JSON_SYNTAX);
+ check_char(skip_char(inp), 'a');
+ check_char(skip_char(inp), 'l');
+ check_char(skip_char(inp), 's');
+ check_char(skip_char(inp), 'e');
return;
}
if (ch == 't') {
- if (skip_char(inp) != 'r') exception(ERR_JSON_SYNTAX);
- if (skip_char(inp) != 'u') exception(ERR_JSON_SYNTAX);
- if (skip_char(inp) != 'e') exception(ERR_JSON_SYNTAX);
+ check_char(skip_char(inp), 'r');
+ check_char(skip_char(inp), 'u');
+ check_char(skip_char(inp), 'e');
return;
}
if (ch == '"') {
@@ -831,8 +842,8 @@ static void skip_object(InputStream * inp) {
skip_object(inp);
ch = skip_char(inp);
if (ch == ',') continue;
- if (ch == ']') break;
- exception(ERR_JSON_SYNTAX);
+ check_char(ch, ']');
+ break;
}
}
return;
@@ -845,12 +856,12 @@ static void skip_object(InputStream * inp) {
for (;;) {
int ch;
skip_object(inp);
- if (skip_char(inp) != ':') exception(ERR_JSON_SYNTAX);
+ check_char(skip_char(inp), ':');
skip_object(inp);
ch = skip_char(inp);
if (ch == ',') continue;
- if (ch == '}') break;
- exception(ERR_JSON_SYNTAX);
+ check_char(ch, '}');
+ break;
}
}
return;
@@ -858,7 +869,7 @@ static void skip_object(InputStream * inp) {
if (ch == '(') {
unsigned long size = json_read_ulong(inp);
ch = skip_char(inp);
- if (ch != ')') exception(ERR_JSON_SYNTAX);
+ check_char(ch, ')');
while (size) {
skip_char(inp);
size--;
@@ -883,6 +894,10 @@ void json_skip_object(InputStream * inp) {
skip_object(inp);
}
+void json_test_char(InputStream * inp, int ch) {
+ check_char(read_stream(inp), ch);
+}
+
static void read_errno_param(InputStream * inp, void * x) {
ErrorReport * err = (ErrorReport *)x;
if (err->param_cnt >= err->param_max) {
@@ -898,13 +913,13 @@ int read_errno(InputStream * inp) {
int ch = read_stream(inp);
if (ch == 0) return 0;
if (ch == 'n') {
- if (read_stream(inp) != 'u') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 'l') exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, 'u');
+ json_test_char(inp, 'l');
+ json_test_char(inp, 'l');
+ json_test_char(inp, MARKER_EOA);
return 0;
}
- if (ch != '{') exception(ERR_JSON_SYNTAX);
+ check_char(ch, '{');
if (peek_stream(inp) == '}') {
read_stream(inp);
}
@@ -912,7 +927,7 @@ int read_errno(InputStream * inp) {
for (;;) {
char name[256];
json_read_string(inp, name, sizeof(name));
- if (read_stream(inp) != ':') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, ':');
if (err == NULL) err = create_error_report();
if (strcmp(name, "Code") == 0) {
err->code = json_read_long(inp);
@@ -935,11 +950,11 @@ int read_errno(InputStream * inp) {
}
ch = read_stream(inp);
if (ch == ',') continue;
- if (ch == '}') break;
- exception(ERR_JSON_SYNTAX);
+ check_char(ch, '}');
+ break;
}
}
- if (read_stream(inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, MARKER_EOA);
if (err == NULL) return 0;
if (err->code != 0) no = set_error_report_errno(err);
release_error_report(err);
diff --git a/agent/tcf/framework/json.h b/agent/tcf/framework/json.h
index 1082ce61..cd44377b 100644
--- a/agent/tcf/framework/json.h
+++ b/agent/tcf/framework/json.h
@@ -29,6 +29,9 @@
#include <stdlib.h>
#include <tcf/framework/streams.h>
+/* Marker of end of command argument */
+#define MARKER_EOA 0
+
extern int json_read_string(InputStream * inp, char * str, size_t size);
extern int json_read_boolean(InputStream * inp);
extern long json_read_long(InputStream * inp);
@@ -52,6 +55,9 @@ extern char * json_read_object(InputStream * inp);
/* Skip one JSON object in the input stream */
extern void json_skip_object(InputStream * inp);
+/* Read one char and check that it matches 'ch' */
+extern void json_test_char(InputStream * inp, int ch);
+
extern void json_write_ulong(OutputStream * out, unsigned long n);
extern void json_write_long(OutputStream * out, long n);
extern void json_write_uint64(OutputStream * out, uint64_t n);
diff --git a/agent/tcf/framework/protocol.c b/agent/tcf/framework/protocol.c
index abcb0588..9ddbf764 100644
--- a/agent/tcf/framework/protocol.c
+++ b/agent/tcf/framework/protocol.c
@@ -459,7 +459,7 @@ static void redirect_done(Channel * c, void * client_data, int error) {
if (!error) {
assert(c->state == ChannelStateRedirectSent);
error = read_errno(&c->inp);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOM);
if (!error) {
c->state = ChannelStateHelloSent;
}
diff --git a/agent/tcf/services/breakpoints.c b/agent/tcf/services/breakpoints.c
index d36405cd..b912ee78 100644
--- a/agent/tcf/services/breakpoints.c
+++ b/agent/tcf/services/breakpoints.c
@@ -1578,7 +1578,7 @@ static BreakpointRef * find_breakpoint_ref(BreakpointInfo * bp, Channel * channe
static BreakpointAttribute * read_breakpoint_properties(InputStream * inp) {
BreakpointAttribute * attrs = NULL;
- if (read_stream(inp) != '{') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, '{');
if (peek_stream(inp) == '}') {
read_stream(inp);
}
@@ -1590,7 +1590,7 @@ static BreakpointAttribute * read_breakpoint_properties(InputStream * inp) {
BreakpointAttribute * attr = (BreakpointAttribute *)loc_alloc_zero(sizeof(BreakpointAttribute));
json_read_string(inp, name, sizeof(name));
- if (read_stream(inp) != ':') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, ':');
attr->name = loc_strdup(name);
attr->value = json_read_object(inp);
*p = attr;
@@ -1611,7 +1611,7 @@ static void read_id_attribute(BreakpointAttribute * attrs, char * id, size_t id_
ByteArrayInputStream buf;
InputStream * inp = create_byte_array_input_stream(&buf, attrs->value, strlen(attrs->value));
json_read_string(inp, id, id_size);
- if (read_stream(inp) != MARKER_EOS) exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, MARKER_EOS);
return;
}
attrs = attrs->next;
@@ -1744,7 +1744,7 @@ static int set_breakpoint_attributes(BreakpointInfo * bp, BreakpointAttribute *
unsupported_attr = 1;
}
- if (!unsupported_attr && read_stream(buf_inp) != MARKER_EOS) exception(ERR_JSON_SYNTAX);
+ if (!unsupported_attr) json_test_char(buf_inp, MARKER_EOS);
}
while (old_attrs != NULL) {
@@ -1963,8 +1963,11 @@ static void delete_breakpoint_refs(Channel * c) {
}
}
+static void command_set_array_cb(InputStream * inp, void * args) {
+ add_breakpoint((Channel *)args, read_breakpoint_properties(inp));
+}
+
static void command_set(char * token, Channel * c) {
- int ch;
LINK * l = NULL;
/* Delete all breakpoints of this channel */
@@ -1982,30 +1985,9 @@ static void command_set(char * token, Channel * c) {
}
/* Add breakpoints for this channel */
- ch = read_stream(&c->inp);
- if (ch == 'n') {
- if (read_stream(&c->inp) != 'u') exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != 'l') exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != 'l') exception(ERR_JSON_SYNTAX);
- }
- else {
- if (ch != '[') exception(ERR_PROTOCOL);
- if (peek_stream(&c->inp) == ']') {
- read_stream(&c->inp);
- }
- else {
- for (;;) {
- int ch;
- add_breakpoint(c, read_breakpoint_properties(&c->inp));
- ch = read_stream(&c->inp);
- if (ch == ',') continue;
- if (ch == ']') break;
- exception(ERR_JSON_SYNTAX);
- }
- }
- }
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_read_array(&c->inp, command_set_array_cb, c);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -2017,7 +1999,7 @@ static void command_get_ids(char * token, Channel * c) {
LINK * l = breakpoints.next;
int cnt = 0;
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
write_errno(&c->out, 0);
@@ -2044,8 +2026,8 @@ static void command_get_properties(char * token, Channel * c) {
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
bp = find_breakpoint(id);
if (bp == NULL || list_is_empty(&bp->link_clients)) err = ERR_INV_CONTEXT;
@@ -2069,8 +2051,8 @@ static void command_get_status(char * token, Channel * c) {
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
bp = find_breakpoint(id);
if (bp == NULL || list_is_empty(&bp->link_clients)) err = ERR_INV_CONTEXT;
@@ -2090,8 +2072,8 @@ static void command_get_status(char * token, Channel * c) {
static void command_add(char * token, Channel * c) {
BreakpointAttribute * props = read_breakpoint_properties(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
add_breakpoint(c, props);
@@ -2103,8 +2085,8 @@ static void command_add(char * token, Channel * c) {
static void command_change(char * token, Channel * c) {
BreakpointAttribute * props = read_breakpoint_properties(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
add_breakpoint(c, props);
@@ -2114,40 +2096,23 @@ static void command_change(char * token, Channel * c) {
write_stream(&c->out, MARKER_EOM);
}
-static void command_enable(char * token, Channel * c) {
- int ch = read_stream(&c->inp);
- if (ch == 'n') {
- if (read_stream(&c->inp) != 'u') exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != 'l') exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != 'l') exception(ERR_JSON_SYNTAX);
- }
- else {
- if (ch != '[') exception(ERR_PROTOCOL);
- if (peek_stream(&c->inp) == ']') {
- read_stream(&c->inp);
- }
- else {
- for (;;) {
- int ch;
- char id[256];
- BreakpointInfo * bp;
- json_read_string(&c->inp, id, sizeof(id));
- bp = find_breakpoint(id);
- if (bp != NULL && !list_is_empty(&bp->link_clients) && !bp->enabled) {
- bp->enabled = 1;
- set_breakpoint_attribute(bp, BREAKPOINT_ENABLED, "true");
- replant_breakpoint(bp);
- send_event_context_changed(bp);
- }
- ch = read_stream(&c->inp);
- if (ch == ',') continue;
- if (ch == ']') break;
- exception(ERR_JSON_SYNTAX);
- }
- }
+static void command_enable_array_cb(InputStream * inp, void * args) {
+ char id[256];
+ BreakpointInfo * bp;
+ json_read_string(inp, id, sizeof(id));
+ bp = find_breakpoint(id);
+ if (bp != NULL && !list_is_empty(&bp->link_clients) && !bp->enabled) {
+ bp->enabled = 1;
+ set_breakpoint_attribute(bp, BREAKPOINT_ENABLED, "true");
+ replant_breakpoint(bp);
+ send_event_context_changed(bp);
}
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+}
+
+static void command_enable(char * token, Channel * c) {
+ json_read_array(&c->inp, command_enable_array_cb, NULL);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -2155,40 +2120,23 @@ static void command_enable(char * token, Channel * c) {
write_stream(&c->out, MARKER_EOM);
}
-static void command_disable(char * token, Channel * c) {
- int ch = read_stream(&c->inp);
- if (ch == 'n') {
- if (read_stream(&c->inp) != 'u') exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != 'l') exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != 'l') exception(ERR_JSON_SYNTAX);
- }
- else {
- if (ch != '[') exception(ERR_PROTOCOL);
- if (peek_stream(&c->inp) == ']') {
- read_stream(&c->inp);
- }
- else {
- for (;;) {
- int ch;
- char id[256];
- BreakpointInfo * bp;
- json_read_string(&c->inp, id, sizeof(id));
- bp = find_breakpoint(id);
- if (bp != NULL && !list_is_empty(&bp->link_clients) && bp->enabled) {
- bp->enabled = 0;
- set_breakpoint_attribute(bp, BREAKPOINT_ENABLED, "false");
- replant_breakpoint(bp);
- send_event_context_changed(bp);
- }
- ch = read_stream(&c->inp);
- if (ch == ',') continue;
- if (ch == ']') break;
- exception(ERR_JSON_SYNTAX);
- }
- }
+static void command_disable_array_cb(InputStream * inp, void * args) {
+ char id[256];
+ BreakpointInfo * bp;
+ json_read_string(inp, id, sizeof(id));
+ bp = find_breakpoint(id);
+ if (bp != NULL && !list_is_empty(&bp->link_clients) && bp->enabled) {
+ bp->enabled = 0;
+ set_breakpoint_attribute(bp, BREAKPOINT_ENABLED, "false");
+ replant_breakpoint(bp);
+ send_event_context_changed(bp);
}
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+}
+
+static void command_disable(char * token, Channel * c) {
+ json_read_array(&c->inp, command_disable_array_cb, NULL);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -2196,35 +2144,18 @@ static void command_disable(char * token, Channel * c) {
write_stream(&c->out, MARKER_EOM);
}
+static void command_remove_array_cb(InputStream * inp, void * args) {
+ char id[256];
+ BreakpointRef * br;
+ json_read_string(inp, id, sizeof(id));
+ br = find_breakpoint_ref(find_breakpoint(id), (Channel *)args);
+ if (br != NULL) remove_ref(br);
+}
+
static void command_remove(char * token, Channel * c) {
- int ch = read_stream(&c->inp);
- if (ch == 'n') {
- if (read_stream(&c->inp) != 'u') exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != 'l') exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != 'l') exception(ERR_JSON_SYNTAX);
- }
- else {
- if (ch != '[') exception(ERR_PROTOCOL);
- if (peek_stream(&c->inp) == ']') {
- read_stream(&c->inp);
- }
- else {
- for (;;) {
- int ch;
- char id[256];
- BreakpointRef * br;
- json_read_string(&c->inp, id, sizeof(id));
- br = find_breakpoint_ref(find_breakpoint(id), c);
- if (br != NULL) remove_ref(br);
- ch = read_stream(&c->inp);
- if (ch == ',') continue;
- if (ch == ']') break;
- exception(ERR_JSON_SYNTAX);
- }
- }
- }
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_read_array(&c->inp, command_remove_array_cb, c);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -2239,8 +2170,8 @@ static void command_get_capabilities(char * token, Channel * c) {
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
ctx = id2ctx(id);
if ((strlen(id)>0) && !ctx) err = ERR_INV_CONTEXT;
diff --git a/agent/tcf/services/contextquery.c b/agent/tcf/services/contextquery.c
index 903893d3..ec9f1f34 100644
--- a/agent/tcf/services/contextquery.c
+++ b/agent/tcf/services/contextquery.c
@@ -259,8 +259,8 @@ int context_query(Context * ctx, const char * query) {
static void command_query(char * token, Channel * c) {
int err = 0;
char * query = json_read_alloc_string(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (parse_context_query(query) < 0) err = errno;
@@ -293,7 +293,7 @@ static void command_get_attr_names(char * token, Channel * c) {
unsigned cnt = 0;
Comparator * l = NULL;
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
diff --git a/agent/tcf/services/diagnostics.c b/agent/tcf/services/diagnostics.c
index 655fc983..4ec22404 100644
--- a/agent/tcf/services/diagnostics.c
+++ b/agent/tcf/services/diagnostics.c
@@ -94,8 +94,8 @@ static void command_echo(char * token, Channel * c) {
char str[0x1000];
int len = json_read_string(&c->inp, str, sizeof(str));
if (len >= (int)sizeof(str)) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
json_write_string_len(&c->out, str, len);
@@ -105,8 +105,8 @@ static void command_echo(char * token, Channel * c) {
static void command_echo_fp(char * token, Channel * c) {
double x = json_read_double(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
json_write_double(&c->out, x);
@@ -131,7 +131,7 @@ static void command_echo_err(char * token, Channel * c) {
static void command_get_test_list(char * token, Channel * c) {
const char * arr = "[]";
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
write_errno(&c->out, 0);
@@ -172,8 +172,8 @@ static void command_run_test(char * token, Channel * c) {
char id[256];
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (strcmp(id, "RCBP1") == 0) {
#if ENABLE_RCBP_TEST
@@ -206,8 +206,8 @@ static void command_cancel_test(char * token, Channel * c) {
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
#if ENABLE_RCBP_TEST
if (terminate_debug_context(id2ctx(id)) != 0) err = errno;
@@ -285,10 +285,10 @@ static void command_get_symbol(char * token, Channel * c) {
ContextAddress addr = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
name = json_read_alloc_string(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
#if ENABLE_DebugContext
{
@@ -379,10 +379,10 @@ static void command_create_test_streams(char * token, Channel * c) {
int err = 0;
buf_size0 = json_read_long(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
buf_size1 = json_read_long(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (buf_size0 <= 0 || buf_size1 <= 0) err = ERR_INV_NUMBER;
@@ -421,8 +421,8 @@ static void command_dispose_test_stream(char * token, Channel * c) {
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
#if SERVICE_Streams
if (!err) {
diff --git a/agent/tcf/services/discovery.c b/agent/tcf/services/discovery.c
index 9fbac909..7f2d8477 100644
--- a/agent/tcf/services/discovery.c
+++ b/agent/tcf/services/discovery.c
@@ -61,7 +61,7 @@ static int write_peer_properties(PeerServer * ps, void * arg) {
}
static void command_sync(char * token, Channel * c) {
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
write_errno(&c->out, 0);
@@ -116,8 +116,8 @@ static void command_redirect(char * token, Channel * c) {
json_read_string(&c->inp, id, sizeof(id));
ps = peer_server_find(id);
}
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (ps != NULL) {
RedirectInfo * info = (RedirectInfo *)loc_alloc_zero(sizeof(RedirectInfo));
@@ -137,7 +137,7 @@ static void command_redirect(char * token, Channel * c) {
}
static void command_get_peers(char * token, Channel * c) {
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
diff --git a/agent/tcf/services/expressions.c b/agent/tcf/services/expressions.c
index 63811145..5181bd01 100644
--- a/agent/tcf/services/expressions.c
+++ b/agent/tcf/services/expressions.c
@@ -2950,8 +2950,8 @@ static void command_get_context(char * token, Channel * c) {
CommandArgs args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(get_context_cache_client, c, &args, sizeof(args));
@@ -3042,8 +3042,8 @@ static void command_get_children(char * token, Channel * c) {
CommandArgs args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(get_children_cache_client, c, &args, sizeof(args));
@@ -3112,12 +3112,12 @@ static void command_create(char * token, Channel * c) {
CommandCreateArgs args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
json_read_string(&c->inp, args.language, sizeof(args.language));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
args.script = json_read_alloc_string(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_create_cache_client, c, &args, sizeof(args));
@@ -3236,8 +3236,8 @@ static void command_evaluate(char * token, Channel * c) {
CommandArgs args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_evaluate_cache_client, c, &args, sizeof(args));
@@ -3289,10 +3289,10 @@ static void command_assign(char * token, Channel * c) {
CommandAssignArgs args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
args.value_buf = json_read_alloc_binary(&c->inp, &args.value_size);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_assign_cache_client, c, &args, sizeof(args));
@@ -3304,8 +3304,8 @@ static void command_dispose(char * token, Channel * c) {
Expression * e;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
e = find_expression(id);
if (e != NULL) {
diff --git a/agent/tcf/services/filesystem.c b/agent/tcf/services/filesystem.c
index 42a26d68..e415cf27 100644
--- a/agent/tcf/services/filesystem.c
+++ b/agent/tcf/services/filesystem.c
@@ -431,16 +431,16 @@ static void command_open(char * token, Channel * c) {
OpenFileInfo * handle = NULL;
read_path(&c->inp, path, sizeof(path));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
flags = json_read_ulong(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
memset(&attrs, 0, sizeof(FileAttrs));
#if defined(_WIN32)
attrs.win32_attrs = INVALID_FILE_ATTRIBUTES;
#endif
json_read_struct(&c->inp, read_file_attrs, &attrs);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if ((attrs.flags & ATTR_PERMISSIONS) == 0) {
attrs.permissions = 0775;
@@ -681,8 +681,8 @@ static void command_close(char * token, Channel * c) {
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
h = find_open_file_info(id);
if (h == NULL) {
@@ -714,12 +714,12 @@ static void command_read(char * token, Channel * c) {
unsigned long len;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
offset = json_read_int64(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
len = json_read_ulong(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
h = find_open_file_info(id);
if (h == NULL) {
@@ -752,9 +752,9 @@ static void command_write(char * token, Channel * c) {
static char * buf = NULL;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
offset = json_read_int64(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
json_read_binary_start(&state, &c->inp);
@@ -770,8 +770,8 @@ static void command_write(char * token, Channel * c) {
len += rd;
}
json_read_binary_end(&state);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (h == NULL) {
reply_write(token, &c->out, EBADF);
@@ -799,8 +799,8 @@ static void command_stat(char * token, Channel * c) {
int err = 0;
read_path(&c->inp, path, sizeof(path));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
memset(&buf, 0, sizeof(buf));
if (stat(path, &buf) < 0) err = errno;
@@ -814,8 +814,8 @@ static void command_lstat(char * token, Channel * c) {
int err = 0;
read_path(&c->inp, path, sizeof(path));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
memset(&buf, 0, sizeof(buf));
if (lstat(path, &buf) < 0) err = errno;
@@ -828,8 +828,8 @@ static void command_fstat(char * token, Channel * c) {
OpenFileInfo * h = NULL;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
h = find_open_file_info(id);
if (h == NULL) {
@@ -847,14 +847,14 @@ static void command_setstat(char * token, Channel * c) {
int err = 0;
read_path(&c->inp, path, sizeof(path));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
memset(&attrs, 0, sizeof(FileAttrs));
#if defined(_WIN32)
attrs.win32_attrs = INVALID_FILE_ATTRIBUTES;
#endif
json_read_struct(&c->inp, read_file_attrs, &attrs);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (attrs.flags & ATTR_SIZE) {
if (truncate(path, attrs.size) < 0) err = errno;
@@ -889,14 +889,14 @@ static void command_fsetstat(char * token, Channel * c) {
OpenFileInfo * h = NULL;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
memset(&attrs, 0, sizeof(FileAttrs));
#if defined(_WIN32)
attrs.win32_attrs = INVALID_FILE_ATTRIBUTES;
#endif
json_read_struct(&c->inp, read_file_attrs, &attrs);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
h = find_open_file_info(id);
if (h == NULL) {
@@ -916,8 +916,8 @@ static void command_opendir(char * token, Channel * c) {
OpenFileInfo * handle = NULL;
read_path(&c->inp, path, sizeof(path));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
dir = opendir(path);
if (dir == NULL) {
@@ -941,8 +941,8 @@ static void command_readdir(char * token, Channel * c) {
int eof = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -1004,8 +1004,8 @@ static void command_remove(char * token, Channel * c) {
int err = 0;
read_path(&c->inp, path, sizeof(path));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (remove(path) < 0) err = errno;
@@ -1020,8 +1020,8 @@ static void command_rmdir(char * token, Channel * c) {
int err = 0;
read_path(&c->inp, path, sizeof(path));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (rmdir(path) < 0) err = errno;
@@ -1038,14 +1038,14 @@ static void command_mkdir(char * token, Channel * c) {
int mode = 0777;
read_path(&c->inp, path, sizeof(path));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
memset(&attrs, 0, sizeof(FileAttrs));
#if defined(_WIN32)
attrs.win32_attrs = INVALID_FILE_ATTRIBUTES;
#endif
json_read_struct(&c->inp, read_file_attrs, &attrs);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (attrs.flags & ATTR_PERMISSIONS) {
mode = attrs.permissions;
@@ -1074,8 +1074,8 @@ static void command_realpath(char * token, Channel * c) {
int err = 0;
read_path(&c->inp, path, sizeof(path));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
#if defined(__CYGWIN__)
if (strncmp(path, "/cygdrive/", 10) == 0) {
@@ -1103,10 +1103,10 @@ static void command_rename(char * token, Channel * c) {
int err = 0;
read_path(&c->inp, path, sizeof(path));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
read_path(&c->inp, newp, sizeof(newp));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (rename(path, newp) < 0) err = errno;
@@ -1122,8 +1122,8 @@ static void command_readlink(char * token, Channel * c) {
int err = 0;
read_path(&c->inp, path, sizeof(path));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
link[0] = 0;
#if defined(_WIN32) || defined(_WRS_KERNEL)
@@ -1146,10 +1146,10 @@ static void command_symlink(char * token, Channel * c) {
int err = 0;
read_path(&c->inp, link, sizeof(link));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
read_path(&c->inp, target, sizeof(target));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
#if defined(_WIN32) || defined(_WRS_KERNEL)
err = ENOSYS;
@@ -1175,14 +1175,14 @@ static void command_copy(char * token, Channel * c) {
int64_t pos = 0;
read_path(&c->inp, src, sizeof(src));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
read_path(&c->inp, dst, sizeof(dst));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
copy_uidgid = json_read_boolean(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
copy_perms = json_read_boolean(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (stat(src, &st) < 0) err = errno;
if (err == 0 && (fi = open(src, O_RDONLY | O_BINARY, 0)) < 0) err = errno;
@@ -1233,7 +1233,7 @@ static void command_copy(char * token, Channel * c) {
}
static void command_user(char * token, Channel * c) {
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
json_write_long(&c->out, getuid());
@@ -1254,7 +1254,7 @@ static void command_roots(char * token, Channel * c) {
struct stat st;
int err = 0;
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
write_stream(&c->out, '[');
diff --git a/agent/tcf/services/linenumbers.c b/agent/tcf/services/linenumbers.c
index 9ee3bfad..63cc2a98 100644
--- a/agent/tcf/services/linenumbers.c
+++ b/agent/tcf/services/linenumbers.c
@@ -209,12 +209,12 @@ static void command_map_to_source(char * token, Channel * c) {
MapToSourceArgs args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
args.addr0 = (ContextAddress)json_read_uint64(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
args.addr1 = (ContextAddress)json_read_uint64(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(map_to_source_cache_client, c, &args, sizeof(args));
@@ -263,14 +263,14 @@ static void command_map_to_memory(char * token, Channel * c) {
MapToMemoryArgs args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
args.file = json_read_alloc_string(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
args.line = json_read_long(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
args.column = json_read_long(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(map_to_memory_cache_client, c, &args, sizeof(args));
diff --git a/agent/tcf/services/linenumbers_proxy.c b/agent/tcf/services/linenumbers_proxy.c
index eaf7a238..7b55d6bf 100644
--- a/agent/tcf/services/linenumbers_proxy.c
+++ b/agent/tcf/services/linenumbers_proxy.c
@@ -186,8 +186,8 @@ static void validate_cache_entry(Channel * c, void * args, int error) {
error = read_errno(&c->inp);
code_area_cnt = 0;
json_read_array(&c->inp, read_code_area_array, NULL);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (code_area_cnt > 0) {
entry->areas_cnt = code_area_cnt;
entry->areas = (CodeArea *)loc_alloc(sizeof(CodeArea) * code_area_cnt);
diff --git a/agent/tcf/services/memorymap.c b/agent/tcf/services/memorymap.c
index 9df32b9c..81072bc6 100644
--- a/agent/tcf/services/memorymap.c
+++ b/agent/tcf/services/memorymap.c
@@ -387,8 +387,8 @@ static void command_get(char * token, Channel * c) {
MemoryMap * target_map = NULL;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
ctx = id2ctx(id);
if (ctx == NULL) err = ERR_INV_CONTEXT;
@@ -459,10 +459,10 @@ static void command_set(char * token, Channel * c) {
memset(&map, 0, sizeof(map));
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
json_read_array(&c->inp, read_map_item, &map);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
for (l = client_map_list.next; l != &client_map_list; l = l->next) {
ClientMap * m = list2map(l);
diff --git a/agent/tcf/services/memoryservice.c b/agent/tcf/services/memoryservice.c
index 88052769..0542a352 100644
--- a/agent/tcf/services/memoryservice.c
+++ b/agent/tcf/services/memoryservice.c
@@ -218,8 +218,8 @@ static void command_get_context(char * token, Channel * c) {
Context * ctx = NULL;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
ctx = id2ctx(id);
@@ -243,8 +243,8 @@ static void command_get_children(char * token, Channel * c) {
char id[256];
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -294,16 +294,16 @@ static MemoryCommandArgs * read_command_args(char * token, Channel * c, int cmd)
memset(&buf, 0, sizeof(buf));
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
buf.addr = json_read_ulong(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
buf.word_size = (int)json_read_long(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
buf.size = (int)json_read_long(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
buf.mode = (int)json_read_long(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (cmd == CMD_GET && read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ if (cmd == CMD_GET) json_test_char(&c->inp, MARKER_EOM);
buf.ctx = id2ctx(id);
if (buf.ctx == NULL) err = ERR_INV_CONTEXT;
@@ -313,10 +313,8 @@ static MemoryCommandArgs * read_command_args(char * token, Channel * c, int cmd)
if (err != 0) {
if (cmd != CMD_GET) {
int ch;
- while ((ch = read_stream(&c->inp)) != 0) {
- if (ch < 0) exception(ERR_JSON_SYNTAX);
- }
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ do ch = read_stream(&c->inp);
+ while (ch != MARKER_EOM && ch != MARKER_EOS);
}
write_stringz(&c->out, "R");
@@ -412,8 +410,8 @@ static void safe_memory_set(void * parm) {
size += rd;
}
json_read_binary_end(&state);
- if (read_stream(inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, MARKER_EOA);
+ json_test_char(inp, MARKER_EOM);
send_event_memory_changed(ctx, addr0, size);
@@ -559,8 +557,8 @@ static void safe_memory_fill(void * parm) {
exception(ERR_JSON_SYNTAX);
}
}
- if (read_stream(inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, MARKER_EOA);
+ json_test_char(inp, MARKER_EOM);
while (err == 0 && buf_pos < (int)size && buf_pos <= (int)(sizeof(buf) / 2)) {
if (buf_pos == 0) {
diff --git a/agent/tcf/services/pathmap.c b/agent/tcf/services/pathmap.c
index a4a45a7a..9532fc16 100644
--- a/agent/tcf/services/pathmap.c
+++ b/agent/tcf/services/pathmap.c
@@ -508,7 +508,7 @@ static void command_get(char * token, Channel * c) {
unsigned n = 0;
LINK * l = maps.next;
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -532,8 +532,8 @@ static void command_get(char * token, Channel * c) {
static void command_set(char * token, Channel * c) {
set_path_map(c, &c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
diff --git a/agent/tcf/services/processes.c b/agent/tcf/services/processes.c
index d644a1e1..10d81320 100644
--- a/agent/tcf/services/processes.c
+++ b/agent/tcf/services/processes.c
@@ -301,8 +301,8 @@ static void command_get_context(char * token, Channel * c) {
pid_t pid, parent;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
pid = id2pid(id, &parent);
write_stringz(&c->out, "R");
@@ -340,10 +340,10 @@ static void command_get_children(char * token, Channel * c) {
int attached_only;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
attached_only = json_read_boolean(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -464,8 +464,8 @@ static void command_attach(char * token, Channel * c) {
pid_t pid, parent;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
pid = id2pid(id, &parent);
@@ -498,8 +498,8 @@ static void command_detach(char * token, Channel * c) {
Context * ctx = NULL;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
ctx = id2ctx(id);
if (ctx == NULL) err = ERR_INV_CONTEXT;
@@ -518,8 +518,8 @@ static void command_get_signal_mask(char * token, Channel * c) {
Context * ctx = NULL;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
ctx = id2ctx(id);
if (ctx == NULL) err = ERR_INV_CONTEXT;
@@ -553,12 +553,12 @@ static void command_set_signal_mask(char * token, Channel * c) {
int dont_pass;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
dont_stop = json_read_long(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
dont_pass = json_read_long(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
ctx = id2ctx(id);
if (ctx == NULL) {
@@ -600,8 +600,8 @@ static void command_terminate(char * token, Channel * c) {
pid_t pid, parent;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
pid = id2pid(id, &parent);
write_stringz(&c->out, "R");
@@ -636,10 +636,10 @@ static void command_signal(char * token, Channel * c) {
pid_t pid, parent;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
signal = (int)json_read_long(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
pid = id2pid(id, &parent);
write_stringz(&c->out, "R");
@@ -685,8 +685,8 @@ static void command_get_signal_list(char * token, Channel * c) {
char id[256];
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
/* pid is ignored, same signal list for all */
id2pid(id, NULL);
@@ -740,7 +740,7 @@ static void command_get_signal_list(char * token, Channel * c) {
static void command_get_environment(char * token, Channel * c) {
char ** p = environ;
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -1452,21 +1452,21 @@ static void command_start(char * token, Channel * c, void * x) {
if (set_trap(&trap)) {
memset(&params, 0, sizeof(params));
params.dir = json_read_alloc_string(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
params.exe = json_read_alloc_string(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
params.args = json_read_alloc_string_array(&c->inp, &args_len);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
params.envp = json_read_alloc_string_array(&c->inp, &envp_len);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
if (version > 0 && (peek_stream(&c->inp) == '{' || peek_stream(&c->inp) == 'n')) {
json_read_struct(&c->inp, read_start_params, &params);
}
else {
params.attach = json_read_boolean(&c->inp);
}
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (params.dir != NULL && params.dir[0] == 0) {
loc_free(params.dir);
diff --git a/agent/tcf/services/registers.c b/agent/tcf/services/registers.c
index 232d305c..3ec69778 100644
--- a/agent/tcf/services/registers.c
+++ b/agent/tcf/services/registers.c
@@ -254,8 +254,8 @@ static void command_get_context(char * token, Channel * c) {
GetContextArgs args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_get_context_cache_client, c, &args, sizeof(args));
@@ -322,8 +322,8 @@ static void command_get_children(char * token, Channel * c) {
GetChildrenArgs args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_get_children_cache_client, c, &args, sizeof(args));
@@ -409,8 +409,8 @@ static void command_get(char * token, Channel * c) {
GetArgs args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_get_cache_client, c, &args, sizeof(args));
@@ -459,10 +459,10 @@ static void command_set(char * token, Channel * c) {
SetArgs args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
args.data = (uint8_t *)json_read_alloc_binary(&c->inp, &args.data_len);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_set_cache_client, c, &args, sizeof(args));
@@ -493,9 +493,9 @@ static void read_location(InputStream * inp, void * args) {
loc = buf + buf_pos++;
memset(loc, 0, sizeof(Location));
json_read_string(inp, loc->id, sizeof(loc->id));
- if (read_stream(inp) != ',') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, ',');
loc->offs = json_read_ulong(inp);
- if (read_stream(inp) != ',') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, ',');
loc->size = json_read_ulong(inp);
if (read_stream(inp) != ']') exception(ERR_JSON_SYNTAX);
}
@@ -577,8 +577,8 @@ static void command_getm(char * token, Channel * c) {
GetmArgs args;
args.locs = read_location_list(&c->inp, &args.locs_cnt);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_getm_cache_client, c, &args, sizeof(args));
@@ -628,10 +628,10 @@ static void command_setm(char * token, Channel * c) {
SetmArgs args;
args.locs = read_location_list(&c->inp, &args.locs_cnt);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
args.data = (uint8_t *)json_read_alloc_binary(&c->inp, &args.data_len);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_setm_cache_client, c, &args, sizeof(args));
@@ -645,10 +645,10 @@ static void command_search(char * token, Channel * c) {
char id[256];
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
json_read_struct(&c->inp, read_filter_attrs, NULL);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
diff --git a/agent/tcf/services/runctrl.c b/agent/tcf/services/runctrl.c
index 130ffd1c..b73ffa71 100644
--- a/agent/tcf/services/runctrl.c
+++ b/agent/tcf/services/runctrl.c
@@ -428,8 +428,8 @@ static void command_get_context(char * token, Channel * c) {
Context * ctx = NULL;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
ctx = id2ctx(id);
@@ -453,8 +453,8 @@ static void command_get_children(char * token, Channel * c) {
char id[256];
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -502,8 +502,8 @@ static void command_get_state(char * token, Channel * c) {
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
ctx = id2ctx(id);
ext = EXT(ctx);
@@ -685,17 +685,17 @@ static void command_resume(char * token, Channel * c) {
memset(&args, 0, sizeof(args));
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
mode = (int)json_read_long(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
count = json_read_long(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
if (peek_stream(&c->inp) != MARKER_EOM) {
json_read_struct(&c->inp, resume_params_callback, &args);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
err = args.error;
}
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOM);
if (err == 0 && (ctx = id2ctx(id)) == NULL) err = ERR_INV_CONTEXT;
if (err == 0 && continue_debug_context(ctx, c, mode, count, args.range_start, args.range_end) < 0) err = errno;
@@ -741,8 +741,8 @@ static void command_suspend(char * token, Channel * c) {
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
ctx = id2ctx(id);
ext = EXT(ctx);
@@ -812,8 +812,8 @@ static void command_terminate(char * token, Channel * c) {
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (terminate_debug_context(id2ctx(id)) != 0) err = errno;
@@ -869,8 +869,8 @@ static void command_detach(char * token, Channel * c) {
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (detach_debug_context(id2ctx(id)) != 0) err = errno;
diff --git a/agent/tcf/services/stacktrace.c b/agent/tcf/services/stacktrace.c
index 1e387a8b..3eae56d2 100644
--- a/agent/tcf/services/stacktrace.c
+++ b/agent/tcf/services/stacktrace.c
@@ -289,8 +289,8 @@ static void command_get_context(char * token, Channel * c) {
CommandGetContextArgs args;
args.ids = json_read_alloc_string_array(&c->inp, &args.id_cnt);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
args.data = (CommandGetContextData *)loc_alloc(sizeof(CommandGetContextData) * args.id_cnt);
strlcpy(args.token, token, sizeof(args.token));
@@ -348,8 +348,8 @@ static void command_get_children(char * token, Channel * c) {
CommandGetChildrenArgs args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_get_children_cache_client, c, &args, sizeof(args));
diff --git a/agent/tcf/services/streamsservice.c b/agent/tcf/services/streamsservice.c
index ecee7a79..375befb8 100644
--- a/agent/tcf/services/streamsservice.c
+++ b/agent/tcf/services/streamsservice.c
@@ -572,8 +572,8 @@ static void command_subscribe(char * token, Channel * c) {
LINK * l;
json_read_string(&c->inp, type, sizeof(type));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
for (l = subscriptions.next; l != &subscriptions;) {
Subscription * h = all2subscription(l);
@@ -604,8 +604,8 @@ static void command_unsubscribe(char * token, Channel * c) {
LINK * l;
json_read_string(&c->inp, type, sizeof(type));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
for (l = subscriptions.next; l != &subscriptions;) {
Subscription * h = all2subscription(l);
@@ -631,10 +631,10 @@ static void command_read(char * token, Channel * c) {
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
size = json_read_ulong(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
client = find_client(id, c);
if (client == NULL) err = errno;
@@ -679,9 +679,9 @@ static void command_write(char * token, Channel * c) {
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
size = json_read_long(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
client = find_client(id, c);
if (client == NULL) err = errno;
@@ -720,8 +720,8 @@ static void command_write(char * token, Channel * c) {
json_read_binary_end(&state);
}
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (data != NULL) {
WriteRequest * r = (WriteRequest *)loc_alloc_zero(sizeof(WriteRequest));
@@ -748,8 +748,8 @@ static void command_eos(char * token, Channel * c) {
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
client = find_client(id, c);
if (client == NULL) err = errno;
@@ -777,8 +777,8 @@ static void command_connect(char * token, Channel * c) {
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (find_client(id, c) == NULL) {
VirtualStream * stream = virtual_stream_find(id);
@@ -798,8 +798,8 @@ static void command_disconnect(char * token, Channel * c) {
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
client = find_client(id, c);
if (client == NULL) err = errno;
diff --git a/agent/tcf/services/symbols.c b/agent/tcf/services/symbols.c
index 55b065b3..a02137b9 100644
--- a/agent/tcf/services/symbols.c
+++ b/agent/tcf/services/symbols.c
@@ -312,8 +312,8 @@ static void command_get_context(char * token, Channel * c) {
CommandGetContextArgs args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_get_context_cache_client, c, &args, sizeof(args));
@@ -362,8 +362,8 @@ static void command_get_children(char * token, Channel * c) {
CommandGetChildrenArgs args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_get_children_cache_client, c, &args, sizeof(args));
@@ -433,14 +433,14 @@ static void command_find_by_name_cache_client(void * x) {
static void command_find_by_name_args(char * token, Channel * c, CommandFindByNameArgs * args) {
args->ip = 0;
json_read_string(&c->inp, args->id, sizeof(args->id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
if (peek_stream(&c->inp) != '"' && peek_stream(&c->inp) != 'n') {
args->ip = (ContextAddress)json_read_uint64(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
}
args->name = json_read_alloc_string(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args->token, token, sizeof(args->token));
cache_enter(command_find_by_name_cache_client, c, args, sizeof(CommandFindByNameArgs));
@@ -498,10 +498,10 @@ static void command_find_by_addr(char * token, Channel * c) {
CommandFindByAddrArgs args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
args.addr = (ContextAddress)json_read_uint64(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_find_by_addr_cache_client, c, &args, sizeof(args));
@@ -552,14 +552,14 @@ static void command_find_in_scope(char * token, Channel * c) {
CommandFindInScopeArgs args;
json_read_string(&c->inp, args.frame_id, sizeof(args.frame_id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
args.ip = (ContextAddress)json_read_uint64(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
json_read_string(&c->inp, args.scope_id, sizeof(args.scope_id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
args.name = json_read_alloc_string(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_find_in_scope_cache_client, c, &args, sizeof(args));
@@ -616,8 +616,8 @@ static void command_list(char * token, Channel * c) {
CommandListArgs args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_list_cache_client, c, &args, sizeof(args));
@@ -660,10 +660,10 @@ static void command_get_array_type(char * token, Channel * c) {
CommandGetArrayTypeArgs args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
args.length = json_read_uint64(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_get_array_type_cache_client, c, &args, sizeof(args));
@@ -820,8 +820,8 @@ static void command_get_location_info(char * token, Channel * c) {
CommandGetLocationInfo args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_get_location_info_cache_client, c, &args, sizeof(args));
@@ -883,10 +883,10 @@ static void command_find_frame_info(char * token, Channel * c) {
CommandFindFrameInfo args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
args.addr = (ContextAddress)json_read_uint64(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_find_frame_info_cache_client, c, &args, sizeof(args));
@@ -969,10 +969,10 @@ static void command_get_sym_file_info(char * token, Channel * c) {
CommandSymFileInfo args;
json_read_string(&c->inp, args.id, sizeof(args.id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
args.addr = (ContextAddress)json_read_uint64(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
strlcpy(args.token, token, sizeof(args.token));
cache_enter(command_get_sym_file_info_cache_client, c, &args, sizeof(args));
diff --git a/agent/tcf/services/symbols_proxy.c b/agent/tcf/services/symbols_proxy.c
index 03996ada..3b12f33a 100644
--- a/agent/tcf/services/symbols_proxy.c
+++ b/agent/tcf/services/symbols_proxy.c
@@ -424,8 +424,8 @@ static void validate_context(Channel * c, void * args, int error) {
if (!error) {
error = read_errno(&c->inp);
json_read_struct(&c->inp, read_context_data, s);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (!error && s->update_owner == NULL) error = ERR_INV_CONTEXT;
if (!error && s->update_owner->exited) error = ERR_ALREADY_EXITED;
}
@@ -529,8 +529,8 @@ static void validate_find(Channel * c, void * args, int error) {
if (!error) {
error = read_errno(&c->inp);
f->id_buf = read_symbol_list(&c->inp, &f->id_cnt);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
}
clear_trap(&trap);
}
@@ -1048,8 +1048,8 @@ static void validate_children(Channel * c, void * args, int error) {
if (!error) {
error = read_errno(&c->inp);
s->children_ids = read_symbol_list(&c->inp, &s->children_count);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
}
clear_trap(&trap);
}
@@ -1107,8 +1107,8 @@ static void validate_type_id(Channel * c, void * args, int error) {
if (!error) {
error = read_errno(&c->inp);
s->id = json_read_alloc_string(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
}
clear_trap(&trap);
}
@@ -1209,43 +1209,43 @@ static void read_location_command(InputStream * inp, void * args) {
cmd = add_location_command((int)json_read_long(inp));
switch (cmd->cmd) {
case SFT_CMD_NUMBER:
- if (read_stream(inp) != ',') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, ',');
cmd->args.num = json_read_int64(inp);
break;
case SFT_CMD_ARG:
- if (read_stream(inp) != ',') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, ',');
cmd->args.num = (unsigned)json_read_ulong(inp);
break;
case SFT_CMD_RD_REG:
case SFT_CMD_WR_REG:
- if (read_stream(inp) != ',') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, ',');
json_read_string(inp, id, sizeof(id));
if (id2register(id, &ctx, &frame, &cmd->args.reg) < 0) id2register_error = errno;
break;
case SFT_CMD_RD_MEM:
case SFT_CMD_WR_MEM:
- if (read_stream(inp) != ',') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, ',');
cmd->args.mem.size = json_read_ulong(inp);
- if (read_stream(inp) != ',') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, ',');
cmd->args.mem.big_endian = json_read_boolean(inp);
break;
case SFT_CMD_LOCATION:
- if (read_stream(inp) != ',') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, ',');
cmd->args.loc.code_addr = (uint8_t *)json_read_alloc_binary(inp, &cmd->args.loc.code_size);
- if (read_stream(inp) != ',') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, ',');
json_read_struct(inp, read_dwarf_location_params, cmd);
cmd->args.loc.func = evaluate_vm_expression;
break;
case SFT_CMD_PIECE:
- if (read_stream(inp) != ',') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, ',');
cmd->args.piece.bit_offs = (unsigned)json_read_ulong(inp);
- if (read_stream(inp) != ',') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, ',');
cmd->args.piece.bit_size = (unsigned)json_read_ulong(inp);
- if (read_stream(inp) != ',') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, ',');
if (json_read_string(inp, id, sizeof(id)) > 0) {
if (id2register(id, &ctx, &frame, &cmd->args.piece.reg) < 0) id2register_error = errno;
}
- if (read_stream(inp) != ',') exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, ',');
cmd->args.piece.value = json_read_alloc_binary(inp, &val_size);
if (cmd->args.piece.value != NULL && val_size < (cmd->args.piece.bit_size + 7) / 8) {
exception(ERR_JSON_SYNTAX);
@@ -1284,8 +1284,8 @@ static void validate_location_info(Channel * c, void * args, int error) {
id2register_error = 0;
error = read_errno(&c->inp);
json_read_struct(&c->inp, read_location_attrs, f);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (!error && id2register_error) error = id2register_error;
}
clear_trap(&trap);
@@ -1420,9 +1420,9 @@ static void validate_frame(Channel * c, void * args, int error) {
id2register_error = 0;
error = read_errno(&c->inp);
addr = json_read_uint64(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
size = json_read_uint64(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
if (error || size == 0) {
f->address = f->ip & ~(uint64_t)3;
f->size = 4;
@@ -1442,15 +1442,15 @@ static void validate_frame(Channel * c, void * args, int error) {
f->fp->cmds_max = location_cmds.cnt;
memcpy(f->fp->cmds, location_cmds.cmds, location_cmds.cnt * sizeof(LocationExpressionCommand));
}
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
trace_regs_cnt = 0;
if (json_read_struct(&c->inp, read_stack_trace_register, NULL)) {
f->regs_cnt = trace_regs_cnt;
f->regs = (StackFrameRegisterLocation **)loc_alloc(trace_regs_cnt * sizeof(StackFrameRegisterLocation *));
memcpy(f->regs, trace_regs, trace_regs_cnt * sizeof(StackFrameRegisterLocation *));
}
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (!error && id2register_error) error = id2register_error;
}
clear_trap(&trap);
diff --git a/agent/tcf/services/sysmon.c b/agent/tcf/services/sysmon.c
index cacf06e0..baa13e64 100644
--- a/agent/tcf/services/sysmon.c
+++ b/agent/tcf/services/sysmon.c
@@ -243,8 +243,8 @@ static void command_get_context(char * token, Channel * c) {
kinfo_proc * p;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -276,8 +276,8 @@ static void command_get_children(char * token, Channel * c) {
pid_t parent = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -367,8 +367,8 @@ static void command_get_command_line(char * token, Channel * c) {
kinfo_proc * p;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
pid = id2pid(id, &parent);
if (pid != 0 && parent == 0) {
@@ -398,8 +398,8 @@ static void command_get_environment(char * token, Channel * c) {
char id[256];
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -686,8 +686,8 @@ static void command_get_context(char * token, Channel * c) {
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -726,8 +726,8 @@ static void command_get_children(char * token, Channel * c) {
int err = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -813,8 +813,8 @@ static void command_get_command_line(char * token, Channel * c) {
wchar_t * cmd = NULL;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -918,8 +918,8 @@ static void command_get_environment(char * token, Channel * c) {
wchar_t * env = NULL;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -1445,8 +1445,8 @@ static void command_get_context(char * token, Channel * c) {
char dir[FILE_PATH_SIZE];
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -1484,8 +1484,8 @@ static void command_get_children(char * token, Channel * c) {
pid_t parent = 0;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -1549,8 +1549,8 @@ static void command_get_command_line(char * token, Channel * c) {
int f = -1;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
@@ -1592,8 +1592,8 @@ static void command_get_environment(char * token, Channel * c) {
int f = -1;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
diff --git a/agent/tcf/services/terminals.c b/agent/tcf/services/terminals.c
index a9af8e10..138764ef 100644
--- a/agent/tcf/services/terminals.c
+++ b/agent/tcf/services/terminals.c
@@ -255,8 +255,8 @@ static void command_exit(char * token, Channel * c) {
Terminal * term = NULL;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
tid = id2tid(id);
write_stringz(&c->out, "R");
@@ -357,8 +357,8 @@ static void command_get_context(char * token, Channel * c) {
Terminal * term = NULL;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
tid = id2tid(id);
write_stringz(&c->out, "R");
@@ -385,7 +385,7 @@ static char ** read_env(InputStream * inp) {
char ** env = json_read_alloc_string_array(inp, &len);
char ** tmp = (char **)tmp_alloc_zero((len + 1) * sizeof(char *));
- if (read_stream(inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(inp, MARKER_EOA);
if (env == NULL) return NULL;
/* convert the env memory layout */
for (i = 0; i < len; i++) tmp[i] = tmp_strdup(env[i]);
@@ -407,11 +407,11 @@ static void command_launch(char * token, Channel * c) {
memset(&prms, 0, sizeof(prms));
json_read_string(&c->inp, pty_type, sizeof(pty_type));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
json_read_string(&c->inp, encoding, sizeof(encoding));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
prms.envp = read_env(&c->inp);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOM);
#if !defined(_WIN32)
{
@@ -499,12 +499,12 @@ static void command_set_win_size(char * token, Channel * c) {
Terminal * term = NULL;
json_read_string(&c->inp, id, sizeof(id));
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
size.ws_col = json_read_ulong(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
size.ws_row = json_read_ulong(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
tid = id2tid(id);
diff --git a/server/tcf/services/context-proxy.c b/server/tcf/services/context-proxy.c
index a645b23a..a91731ec 100644
--- a/server/tcf/services/context-proxy.c
+++ b/server/tcf/services/context-proxy.c
@@ -474,8 +474,8 @@ static void event_context_added(Channel * c, void * args) {
write_stringz(&p->host->out, RUN_CONTROL);
write_stringz(&p->host->out, "contextAdded");
json_read_array(p->bck_inp, read_context_added_item, p);
- if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(p->bck_inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(p->bck_inp, MARKER_EOA);
+ json_test_char(p->bck_inp, MARKER_EOM);
}
static void event_context_changed(Channel * c, void * args) {
@@ -484,8 +484,8 @@ static void event_context_changed(Channel * c, void * args) {
write_stringz(&p->host->out, RUN_CONTROL);
write_stringz(&p->host->out, "contextChanged");
json_read_array(p->bck_inp, read_context_changed_item, p);
- if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(p->bck_inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(p->bck_inp, MARKER_EOA);
+ json_test_char(p->bck_inp, MARKER_EOM);
}
static void event_context_removed(Channel * c, void * args) {
@@ -494,8 +494,8 @@ static void event_context_removed(Channel * c, void * args) {
write_stringz(&p->host->out, RUN_CONTROL);
write_stringz(&p->host->out, "contextRemoved");
json_read_array(p->bck_inp, read_context_removed_item, p);
- if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(p->bck_inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(p->bck_inp, MARKER_EOA);
+ json_test_char(p->bck_inp, MARKER_EOM);
}
static void event_context_suspended(Channel * ch, void * args) {
@@ -509,17 +509,17 @@ static void event_context_suspended(Channel * ch, void * args) {
write_stringz(&p->host->out, RUN_CONTROL);
write_stringz(&p->host->out, "contextSuspended");
json_read_string(p->bck_inp, c->id, sizeof(c->id));
- if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(p->bck_inp, MARKER_EOA);
c = find_context_cache(p, c->id);
if (c == NULL) c = &buf;
else clear_context_suspended_data(c);
c->suspend_pc = json_read_uint64(p->bck_inp);
- if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(p->bck_inp, MARKER_EOA);
c->suspend_reason = json_read_alloc_string(p->bck_inp);
- if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(p->bck_inp, MARKER_EOA);
json_read_struct(p->bck_inp, read_context_suspended_data, c);
- if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(p->bck_inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(p->bck_inp, MARKER_EOA);
+ json_test_char(p->bck_inp, MARKER_EOM);
if (c != &buf) {
assert(*EXT(c->ctx) == c);
@@ -546,8 +546,8 @@ static void event_context_resumed(Channel * ch, void * args) {
write_stringz(&p->host->out, RUN_CONTROL);
write_stringz(&p->host->out, "contextResumed");
json_read_string(p->bck_inp, id, sizeof(id));
- if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(p->bck_inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(p->bck_inp, MARKER_EOA);
+ json_test_char(p->bck_inp, MARKER_EOM);
c = find_context_cache(p, id);
if (c != NULL) {
@@ -574,16 +574,16 @@ static void event_container_suspended(Channel * ch, void * args) {
write_stringz(&p->host->out, RUN_CONTROL);
write_stringz(&p->host->out, "containerSuspended");
json_read_string(p->bck_inp, c->id, sizeof(c->id));
- if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(p->bck_inp, MARKER_EOA);
c = find_context_cache(p, c->id);
if (c == NULL) c = &buf;
else clear_context_suspended_data(c);
c->suspend_pc = json_read_uint64(p->bck_inp);
- if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(p->bck_inp, MARKER_EOA);
c->suspend_reason = json_read_alloc_string(p->bck_inp);
- if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(p->bck_inp, MARKER_EOA);
json_read_struct(p->bck_inp, read_context_suspended_data, c);
- if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(p->bck_inp, MARKER_EOA);
if (c != &buf) {
assert(*EXT(c->ctx) == c);
c->pc_valid = 1;
@@ -598,8 +598,8 @@ static void event_container_suspended(Channel * ch, void * args) {
clear_context_suspended_data(c);
}
json_read_array(p->bck_inp, read_container_suspended_item, p);
- if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(p->bck_inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(p->bck_inp, MARKER_EOA);
+ json_test_char(p->bck_inp, MARKER_EOM);
}
static void event_container_resumed(Channel * c, void * args) {
@@ -608,8 +608,8 @@ static void event_container_resumed(Channel * c, void * args) {
write_stringz(&p->host->out, RUN_CONTROL);
write_stringz(&p->host->out, "containerResumed");
json_read_array(p->bck_inp, read_container_resumed_item, p);
- if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(p->bck_inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(p->bck_inp, MARKER_EOA);
+ json_test_char(p->bck_inp, MARKER_EOM);
}
static void event_memory_map_changed(Channel * c, void * args) {
@@ -621,8 +621,8 @@ static void event_memory_map_changed(Channel * c, void * args) {
write_stringz(&p->host->out, MEMORY_MAP);
write_stringz(&p->host->out, "changed");
json_read_string(p->bck_inp, id, sizeof(id));
- if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(p->bck_inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(p->bck_inp, MARKER_EOA);
+ json_test_char(p->bck_inp, MARKER_EOM);
ctx = find_context_cache(p, id);
if (ctx != NULL) {
@@ -642,8 +642,8 @@ static void command_path_map_set(char * token, Channel * c, void * args) {
write_stringz(&p->target->out, PATH_MAP);
write_stringz(&p->target->out, "set");
set_path_map(p->host, p->fwd_inp);
- if (read_stream(p->fwd_inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(p->fwd_inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(p->fwd_inp, MARKER_EOA);
+ json_test_char(p->fwd_inp, MARKER_EOM);
}
static void validate_peer_cache_children(Channel * c, void * args, int error);
@@ -736,8 +736,8 @@ static void validate_peer_cache_children(Channel * c, void * args, int error) {
if (!error) {
error = read_errno(&c->inp);
json_read_array(&c->inp, read_rc_children_item, p);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
}
clear_trap(&trap);
}
@@ -764,8 +764,8 @@ static void validate_peer_cache_context(Channel * c, void * args, int error) {
else {
set_rc_error(p, error = read_errno(&c->inp));
json_read_struct(&c->inp, read_run_control_context_property, x);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (error || find_context_cache(p, x->id) != NULL) {
free_context_cache(x);
}
@@ -811,14 +811,14 @@ static void validate_peer_cache_state(Channel * c, void * args, int error) {
set_rc_error(p, error = read_errno(&c->inp));
clear_context_suspended_data(x);
x->pc_valid = json_read_boolean(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
x->suspend_pc = json_read_uint64(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
x->suspend_reason = json_read_alloc_string(&c->inp);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
json_read_struct(&c->inp, read_context_suspended_data, x);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (error || find_context_cache(p, x->id) != NULL) {
free_context_cache(x);
@@ -902,10 +902,10 @@ static void validate_memory_cache(Channel * c, void * args, int error) {
pos += rd;
}
json_read_binary_end(&state);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
error = read_errno(&c->inp);
while (read_stream(&c->inp) != 0) {}
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOM);
}
clear_trap(&trap);
}
@@ -1043,8 +1043,8 @@ static void validate_memory_map_cache(Channel * c, void * args, int error) {
cache->mmap.regions = (MemoryRegion *)loc_realloc(cache->mmap.regions, sizeof(MemoryRegion) * mem_buf_pos);
memcpy(cache->mmap.regions, mem_buf, sizeof(MemoryRegion) * mem_buf_pos);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
}
clear_trap(&trap);
}
@@ -1171,8 +1171,8 @@ static void validate_registers_cache(Channel * c, void * args, int error) {
ids_buf_pos = 0;
str_buf_pos = 0;
json_read_array(&c->inp, read_ids_item, NULL);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
for (i = 0; i < ids_buf_pos; i++) {
cache->pending_regs_cnt++;
protocol_send_command(c, "Registers", "getContext", validate_registers_cache, cache);
@@ -1190,8 +1190,8 @@ static void validate_registers_cache(Channel * c, void * args, int error) {
props.def.dwarf_id = -1;
props.def.eh_frame_id = -1;
json_read_struct(&c->inp, read_register_property, &props);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
i = get_reg_index(cache, props.id);
if (i >= cache->reg_max) {
unsigned pos = cache->reg_max;
@@ -1301,8 +1301,8 @@ static void validate_reg_values_cache(Channel * c, void * args, int error) {
}
}
json_read_binary_end(&state);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
}
clear_trap(&trap);
}
@@ -1329,8 +1329,8 @@ static void validate_reg_children_cache(Channel * c, void * args, int error) {
str_buf_pos = 0;
error = read_errno(&c->inp);
json_read_array(&c->inp, read_ids_item, NULL);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
+ json_test_char(&c->inp, MARKER_EOM);
if (!error && !s->disposed) {
unsigned n = 0;
s->reg_cnt = ids_buf_pos;
@@ -1400,9 +1400,9 @@ static void validate_stack_frame_cache(Channel * c, void * args, int error) {
s->pending = NULL;
if (!error) {
json_read_array(&c->inp, read_stack_frame, s);
- if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOA);
error = read_errno(&c->inp);
- if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);
+ json_test_char(&c->inp, MARKER_EOM);
if (!error && !s->disposed) {
if (s->info.is_top_frame) {
unsigned cnt = 0;

Back to the top