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/jansson-2.6/src/dump.c b/src/jansson-2.6/src/dump.c index 3b19c73b..a8e99c12 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 inline 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); 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; } 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. */