summaryrefslogtreecommitdiff
path: root/json.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2011-04-15 18:39:30 -0400
committerEric S. Raymond <esr@thyrsus.com>2011-04-15 18:39:30 -0400
commit62bc9311632aaba85f011f4d6306b4e6904d1937 (patch)
treeabf75c205d5c7f28f0da7fd55e75a6c36130141f /json.c
parentf0680f02af44a8f3a35065a9653bbdb827c7c629 (diff)
downloadgpsd-62bc9311632aaba85f011f4d6306b4e6904d1937.tar.gz
Add a 'timestamp' type to the JSON parser to solve a compatibility problem.
Sigh, no other way to get DEVICELIST to recignize both new and old timestamps. All regression tests pass.
Diffstat (limited to 'json.c')
-rw-r--r--json.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/json.c b/json.c
index 462c0c23..111c2e74 100644
--- a/json.c
+++ b/json.c
@@ -70,6 +70,8 @@ PERMISSIONS
#ifdef SOCKET_EXPORT_ENABLE
#include "json.h"
+#include "gps.h" /* only for timestamp_t prototype */
+
#ifdef CLIENTDEBUG_ENABLE
static int debuglevel = 0;
static FILE *debugfp;
@@ -119,6 +121,7 @@ static /*@null@*/ char *json_target_address(const struct json_attr_t *cursor,
case t_uinteger:
targetaddr = (char *)&cursor->addr.uinteger[offset];
break;
+ case t_timestamp:
case t_real:
targetaddr = (char *)&cursor->addr.real[offset];
break;
@@ -196,6 +199,7 @@ static int json_internal_read_object(const char *cp,
case t_uinteger:
*((unsigned int *)lptr) = cursor->dflt.uinteger;
break;
+ case t_timestamp:
case t_real:
*((double *)lptr) = cursor->dflt.real;
break;
@@ -382,7 +386,7 @@ static int json_internal_read_object(const char *cp,
*/
for (;;) {
int seeking = cursor->type;
- if (value_quoted && cursor->type == t_string)
+ if (value_quoted && (cursor->type == t_string || cursor->type == t_timestamp))
break;
if ((strcmp(valbuf, "true")==0 || strcmp(valbuf, "false")==0)
&& seeking == t_boolean)
@@ -402,14 +406,15 @@ static int json_internal_read_object(const char *cp,
}
if (value_quoted
&& (cursor->type != t_string && cursor->type != t_character
- && cursor->type != t_check && cursor->map == 0)) {
+ && cursor->type != t_check && cursor->type != t_timestamp
+ && cursor->map == 0)) {
json_debug_trace((1,
"Saw quoted value when expecting non-string.\n"));
return JSON_ERR_QNONSTRING;
}
if (!value_quoted
&& (cursor->type == t_string || cursor->type == t_check
- || cursor->map != 0)) {
+ || cursor->type == t_timestamp || cursor->map != 0)) {
json_debug_trace((1,
"Didn't see quoted value when expecting string.\n"));
return JSON_ERR_NONQSTRING;
@@ -434,6 +439,9 @@ static int json_internal_read_object(const char *cp,
case t_uinteger:
*((unsigned int *)lptr) = (unsigned)atoi(valbuf);
break;
+ case t_timestamp:
+ *((double *)lptr) = iso8601_to_unix(valbuf);
+ break;
case t_real:
*((double *)lptr) = atof(valbuf);
break;
@@ -554,6 +562,7 @@ int json_read_array(const char *cp, const struct json_array_t *arr,
break;
case t_integer:
case t_uinteger:
+ case t_timestamp:
case t_real:
case t_boolean:
case t_character: