more fixes for chat

This commit is contained in:
Andrew Pamment 2017-03-20 13:26:28 +10:00
parent 0d89741851
commit 14aef25985
2 changed files with 5 additions and 3 deletions

View File

@ -41,7 +41,7 @@ static char *encapsulate_quote(char *in) {
int i; int i;
int j = 0; int j = 0;
for (i=0;i<strlen(in);i++) { for (i=0;i<strlen(in);i++) {
if (in[j] == '\"') { if (in[j] == '\"' || in[j] == '\\') {
out[i++] = '\\'; out[i++] = '\\';
} }
out[i] = in[j]; out[i] = in[j];
@ -155,7 +155,7 @@ void chat_system(struct user_record *user) {
return; return;
} }
jsmn_init(&parser);
row_at = 0; row_at = 0;
line_at = 0; line_at = 0;
@ -255,6 +255,7 @@ void chat_system(struct user_record *user) {
} }
// json parse // json parse
jsmn_init(&parser);
// we got some data from a client // we got some data from a client
r = jsmn_parse(&parser, readbuffer, len, tokens, sizeof(tokens)/sizeof(tokens[0])); r = jsmn_parse(&parser, readbuffer, len, tokens, sizeof(tokens)/sizeof(tokens[0]));

View File

@ -85,7 +85,6 @@ int main(int argc, char **argv) {
c = sizeof(struct sockaddr_in); c = sizeof(struct sockaddr_in);
jsmn_init(&parser);
while (1) { while (1) {
read_fds = master; read_fds = master;
@ -165,6 +164,8 @@ int main(int argc, char **argv) {
FD_CLR(i, &master); // remove from master set FD_CLR(i, &master); // remove from master set
} else { } else {
// we got some data from a client // we got some data from a client
jsmn_init(&parser);
r = jsmn_parse(&parser, buf, nbytes, tokens, sizeof(tokens)/sizeof(tokens[0])); r = jsmn_parse(&parser, buf, nbytes, tokens, sizeof(tokens)/sizeof(tokens[0]));
if (r < 0) { if (r < 0) {