From 4d9dc10206d9be5d72a1dff79aee1f6059bd2cd5 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 22 Aug 2014 10:34:57 +1000 Subject: [PATCH 1/4] Use realloc in strbuffer_append_bytes --- src/jansson-2.6/src/strbuffer.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/jansson-2.6/src/strbuffer.c b/src/jansson-2.6/src/strbuffer.c index 2d6ff310..c8abf46e 100644 --- a/src/jansson-2.6/src/strbuffer.c +++ b/src/jansson-2.6/src/strbuffer.c @@ -86,13 +86,10 @@ int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size) new_size = max(strbuff->size * STRBUFFER_FACTOR, strbuff->length + size + 1); - new_value = jsonp_malloc(new_size); + new_value = realloc(strbuff->value, new_size); if(!new_value) return -1; - memcpy(new_value, strbuff->value, strbuff->length); - - jsonp_free(strbuff->value); strbuff->value = new_value; strbuff->size = new_size; } From 1dfc48698b00dbcc3d88a2795c6153fba992999a Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 22 Aug 2014 14:33:44 +1000 Subject: [PATCH 2/4] Provide a way to dump json when it is known there is no utf8 in it --- src/jansson-2.6/src/dump.c | 20 +++++++++++++++++++- src/jansson-2.6/src/jansson.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/jansson-2.6/src/dump.c b/src/jansson-2.6/src/dump.c index 3b19c73b..452f166b 100644 --- a/src/jansson-2.6/src/dump.c +++ b/src/jansson-2.6/src/dump.c @@ -65,6 +65,21 @@ static int dump_indent(size_t flags, int depth, int space, json_dump_callback_t return 0; } +static const char *noutf8_iterate(const char *buffer, int32_t *codepoint) +{ + int32_t value; + + if(!*buffer) + return buffer; + + value = (unsigned char)buffer[0]; + + if(codepoint) + *codepoint = value; + + return buffer + 1; +} + static int dump_string(const char *str, json_dump_callback_t dump, void *data, size_t flags) { const char *pos, *end; @@ -82,7 +97,10 @@ static int dump_string(const char *str, json_dump_callback_t dump, void *data, s while(*end) { - end = utf8_iterate(pos, &codepoint); + if(flags & JSON_NO_UTF8) + end = noutf8_iterate(pos, &codepoint); + else + end = utf8_iterate(pos, &codepoint); if(!end) return -1; diff --git a/src/jansson-2.6/src/jansson.h b/src/jansson-2.6/src/jansson.h index 3f67edf1..8cc2760e 100644 --- a/src/jansson-2.6/src/jansson.h +++ b/src/jansson-2.6/src/jansson.h @@ -260,6 +260,7 @@ json_t *json_load_callback(json_load_callback_t callback, void *data, size_t fla #define JSON_PRESERVE_ORDER 0x100 #define JSON_ENCODE_ANY 0x200 #define JSON_ESCAPE_SLASH 0x400 +#define JSON_NO_UTF8 0x800 typedef int (*json_dump_callback_t)(const char *buffer, size_t size, void *data); From f794f4afaba1422fd1a5d2f8e913951a0961c097 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 22 Aug 2014 14:40:56 +1000 Subject: [PATCH 3/4] Add not no utf8 flag to json we know will only contain ascii --- src/generator.c | 8 ++++---- src/stratifier.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/generator.c b/src/generator.c index 9efadd1f..e0b3735a 100644 --- a/src/generator.c +++ b/src/generator.c @@ -263,7 +263,7 @@ retry: send_unix_msg(sockd, "Failed"); goto reconnect; } else { - char *s = json_dumps(gbt->json, 0); + char *s = json_dumps(gbt->json, JSON_NO_UTF8); send_unix_msg(sockd, s); free(s); @@ -915,7 +915,7 @@ static void send_subscribe(proxy_instance_t *proxi, int sockd) json_msg = json_pack("{sssi}", "enonce1", proxi->enonce1, "nonce2len", proxi->nonce2len); - msg = json_dumps(json_msg, 0); + msg = json_dumps(json_msg, JSON_NO_UTF8); json_decref(json_msg); send_unix_msg(sockd, msg); free(msg); @@ -944,7 +944,7 @@ static void send_notify(proxy_instance_t *proxi, int sockd) "clean", ni->clean); mutex_unlock(&proxi->notify_lock); - msg = json_dumps(json_msg, 0); + msg = json_dumps(json_msg, JSON_NO_UTF8); json_decref(json_msg); send_unix_msg(sockd, msg); free(msg); @@ -957,7 +957,7 @@ static void send_diff(proxy_instance_t *proxi, int sockd) char *msg; json_msg = json_pack("{sf}", "diff", proxi->diff); - msg = json_dumps(json_msg, 0); + msg = json_dumps(json_msg, JSON_NO_UTF8); json_decref(json_msg); send_unix_msg(sockd, msg); free(msg); diff --git a/src/stratifier.c b/src/stratifier.c index fc8a0914..9e57ef55 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -2368,7 +2368,7 @@ static void *statsupdate(void *arg) "runtime", diff.tv_sec, "Users", stats.users, "Workers", stats.workers); - s = json_dumps(val, 0); + s = json_dumps(val, JSON_NO_UTF8); json_decref(val); LOGNOTICE("Pool:%s", s); fprintf(fp, "%s\n", s); @@ -2381,7 +2381,7 @@ static void *statsupdate(void *arg) "hashrate1hr", suffix60, "hashrate6hr", suffix360, "hashrate1d", suffix1440); - s = json_dumps(val, 0); + s = json_dumps(val, JSON_NO_UTF8); json_decref(val); LOGNOTICE("Pool:%s", s); fprintf(fp, "%s\n", s); @@ -2392,7 +2392,7 @@ static void *statsupdate(void *arg) "SPS5m", sps5, "SPS15m", sps15, "SPS1h", sps60); - s = json_dumps(val, 0); + s = json_dumps(val, JSON_NO_UTF8); json_decref(val); LOGNOTICE("Pool:%s", s); fprintf(fp, "%s\n", s); @@ -2439,7 +2439,7 @@ static void *statsupdate(void *arg) LOGERR("Failed to fopen %s", fname); continue; } - s = json_dumps(val, 0); + s = json_dumps(val, JSON_NO_UTF8); fprintf(fp, "%s\n", s); /* Only display the status of connected users to the * console log. */ From a0cf598c83fe92208991aea3e6dac007e0740c1d Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 22 Aug 2014 15:13:49 +1000 Subject: [PATCH 4/4] Inline the only caller of noutf8_iterate --- src/jansson-2.6/src/dump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jansson-2.6/src/dump.c b/src/jansson-2.6/src/dump.c index 452f166b..a8e99c12 100644 --- a/src/jansson-2.6/src/dump.c +++ b/src/jansson-2.6/src/dump.c @@ -65,7 +65,7 @@ static int dump_indent(size_t flags, int depth, int space, json_dump_callback_t return 0; } -static const char *noutf8_iterate(const char *buffer, int32_t *codepoint) +static inline const char *noutf8_iterate(const char *buffer, int32_t *codepoint) { int32_t value;