return pair;
}
-static struct json_value *json_create_value_int(long number)
+static struct json_value *json_create_value_int(long long number)
{
struct json_value *value = malloc(sizeof(struct json_value));
return value;
}
+static char *strdup_escape(const char *str)
+{
+ const char *input = str;
+ char *p, *ret;
+ int escapes;
+
+ if (!strlen(str))
+ return NULL;
+
+ escapes = 0;
+ while ((input = strpbrk(input, "\\\"")) != NULL) {
+ escapes++;
+ input++;
+ }
+
+ p = ret = malloc(strlen(str) + escapes + 1);
+ while (*str) {
+ if (*str == '\\' || *str == '\"')
+ *p++ = '\\';
+ *p++ = *str++;
+ }
+ *p = '\0';
+
+ return ret;
+}
+
+/*
+ * Valid JSON strings must escape '"' and '/' with a preceding '/'
+ */
static struct json_value *json_create_value_string(const char *str)
{
struct json_value *value = malloc(sizeof(struct json_value));
if (value) {
value->type = JSON_TYPE_STRING;
- value->string = strdup(str);
+ value->string = strdup_escape(str);
if (!value->string) {
free(value);
value = NULL;
if (type == JSON_TYPE_STRING)
value = json_create_value_string(va_arg(args, char *));
else if (type == JSON_TYPE_INTEGER)
- value = json_create_value_int(va_arg(args, long));
+ value = json_create_value_int(va_arg(args, long long));
else if (type == JSON_TYPE_FLOAT)
value = json_create_value_float(va_arg(args, double));
else if (type == JSON_TYPE_OBJECT)
if (type == JSON_TYPE_STRING)
value = json_create_value_string(va_arg(args, char *));
else if (type == JSON_TYPE_INTEGER)
- value = json_create_value_int(va_arg(args, long));
+ value = json_create_value_int(va_arg(args, long long));
else if (type == JSON_TYPE_FLOAT)
value = json_create_value_float(va_arg(args, double));
else if (type == JSON_TYPE_OBJECT)
log_info("\"%s\"", value->string);
break;
case JSON_TYPE_INTEGER:
- log_info("%ld", value->integer_number);
+ log_info("%lld", value->integer_number);
break;
case JSON_TYPE_FLOAT:
log_info("%.2f", value->float_number);