summaryrefslogtreecommitdiff
path: root/json.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2009-07-11 16:19:47 +0000
committerEric S. Raymond <esr@thyrsus.com>2009-07-11 16:19:47 +0000
commit6150cf71e8beb21e29ed4048f04806c9197734e1 (patch)
tree430f5a402a247b36d16ca34ebc0d98c7c9fbd14d /json.c
parentc60d911ef627fcbdd26dfce051b683d9f1280659 (diff)
downloadgpsd-6150cf71e8beb21e29ed4048f04806c9197734e1.tar.gz
JSON parser now verified to handle booleans.
Diffstat (limited to 'json.c')
-rw-r--r--json.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/json.c b/json.c
index 2a6a4a6c..2f5b6c37 100644
--- a/json.c
+++ b/json.c
@@ -6,8 +6,6 @@
#include "json.h"
-#define JSON_DEBUG
-
int parse_json(const char *cp, const struct json_attr_t *attrs)
{
enum {init, await_attr, in_attr, await_value,
@@ -92,10 +90,10 @@ int parse_json(const char *cp, const struct json_attr_t *attrs)
break;
case in_val_string:
if (*cp == '"') {
+ *pval = '\0';
#ifdef JSONDEBUG
(void) printf("Collected string value %s\n", valbuf);
#endif /* JSONDEBUG */
- *pval = '\0';
state = post_val;
} else if (pval > valbuf + JSON_VAL_MAX - 1)
return -5; /* value too long */
@@ -104,10 +102,10 @@ int parse_json(const char *cp, const struct json_attr_t *attrs)
break;
case in_val_token:
if (isspace(*cp) || *cp == ',' || *cp == '}') {
+ *pval = '\0';
#ifdef JSONDEBUG
(void) printf("Collected token value %s\n", valbuf);
#endif /* JSONDEBUG */
- *pval = '\0';
state = post_val;
if (*cp == '}' || *cp == ',')
--cp;
@@ -129,6 +127,9 @@ int parse_json(const char *cp, const struct json_attr_t *attrs)
(void)strcpy(cursor->addr.string, valbuf);
break;
case boolean:
+#ifdef JSONDEBUG
+ (void) printf("Boolean value '%s' processed to %d\n", valbuf, !strcmp(valbuf, "true"));
+#endif /* JSONDEBUG */
*(cursor->addr.boolean) = (bool)!strcmp(valbuf, "true");
break;
}