summaryrefslogtreecommitdiff
path: root/json.h
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2009-07-14 00:36:47 +0000
committerEric S. Raymond <esr@thyrsus.com>2009-07-14 00:36:47 +0000
commitfd19d4685df2b4d5bff0bfc19a0c507e6722536b (patch)
tree4485df597def1639434f2071519ff0d780ff1b83 /json.h
parent6a593c217d16551c3f27253f38ec190df5fa5edc (diff)
downloadgpsd-fd19d4685df2b4d5bff0bfc19a0c507e6722536b.tar.gz
JSON parser can now handle arrays of strings.
Diffstat (limited to 'json.h')
-rw-r--r--json.h19
1 files changed, 16 insertions, 3 deletions
diff --git a/json.h b/json.h
index 1c829859..1bb0a119 100644
--- a/json.h
+++ b/json.h
@@ -3,14 +3,24 @@
#include <stdbool.h>
#include <ctype.h>
+typedef enum {integer, real, string, boolean, object, array} json_type;
+
struct json_array_t {
- const struct json_attr_t *subtype;
- int maxlen;
+ json_type element_type;
+ union {
+ const struct json_attr_t *subtype;
+ struct {
+ char **ptrs;
+ char *store;
+ int storelen;
+ } strings;
+ } arr;
+ int *count, maxlen;
};
struct json_attr_t {
char *attribute;
- enum {integer, real, string, boolean, array} type;
+ json_type type;
union {
int *integer;
double *real;
@@ -34,6 +44,7 @@ struct json_attr_t {
#define JSON_VAL_MAX 63 /* max charss in JSON value part */
int json_read_object(const char *, const struct json_attr_t *, int, const char **end);
+int json_read_array(const char *, const struct json_array_t *, const char **);
const char *json_error_string(int);
#define JSON_ERR_OBSTART -1 /* non-WS when expecting object start */
@@ -49,5 +60,7 @@ const char *json_error_string(int);
#define JSON_ERR_OBJARR -11 /* error while parsing object array */
#define JSON_ERR_SUBTOOLONG -12 /* too many array elements */
#define JSON_ERR_BADSUBTRAIL -13 /* garbage while expecting array comma */
+#define JSON_ERR_SUBTYPE -14 /* unsupported array element type */
+#define JSON_ERR_BADSTRING -15 /* error while string parsing */
/* json.h ends here */