The dialect this parses has some limitations. First, it cannot
recognize the JSON "null" value. Second, all elements of an array must
-be of the same type. Third, some types (t_time, t_character) may not
-be array elements (this restriction could be lifted)
+be of the same type. Third, characters may not be array elements (this
+restriction could be lifted)
There are separate entry points for beginning a parse of either
JSON object or a JSON array. JSON "float" quantities are actually
# define json_debug_trace(args) /*@i1@*/do { } while (0)
#endif /* DEBUG_ENABLE */
-#define MONTHSPERYEAR 12 /* months per calendar year */
-
-static time_t mkutctime(register struct tm * t)
-/* struct tm to seconds since Unix epoch */
-{
- register int year;
- register time_t result;
- static const int cumdays[MONTHSPERYEAR] =
- { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
-
- /*@ +matchanyintegral @*/
- year = 1900 + t->tm_year + t->tm_mon / MONTHSPERYEAR;
- result = (year - 1970) * 365 + cumdays[t->tm_mon % MONTHSPERYEAR];
- result += (year - 1968) / 4;
- result -= (year - 1900) / 100;
- result += (year - 1600) / 400;
- if ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0) &&
- (t->tm_mon % MONTHSPERYEAR) < 2)
- result--;
- result += t->tm_mday - 1;
- result *= 24;
- result += t->tm_hour;
- result *= 60;
- result += t->tm_min;
- result *= 60;
- result += t->tm_sec;
- /*@ -matchanyintegral @*/
- return (result);
-}
-
-static double iso8601_to_unix(/*@in@*/const char *isotime)
-/* ISO8601 UTC to Unix UTC */
-{
- char *dp = NULL;
- double usec;
- struct tm tm;
-
- /*@i1@*/ dp = strptime(isotime, "%Y-%m-%dT%H:%M:%S", &tm);
- if (dp != NULL && *dp == '.')
- usec = strtod(dp, NULL);
- else
- usec = 0;
- return mkutctime(&tm) + usec;
-}
-
/*@-immediatetrans -dependenttrans -usereleased -compdef@*/
static /*@null@*/ char *json_target_address(const struct json_attr_t *cursor,
/*@null@*/
case t_uinteger:
targetaddr = (char *)&cursor->addr.uinteger[offset];
break;
- case t_time:
case t_real:
targetaddr = (char *)&cursor->addr.real[offset];
break;
case t_uinteger:
memcpy(lptr, &cursor->dflt.uinteger, sizeof(unsigned int));
break;
- case t_time:
case t_real:
memcpy(lptr, &cursor->dflt.real, sizeof(double));
break;
maxlen = (int)cursor->len - 1;
else if (cursor->type == t_check)
maxlen = (int)strlen(cursor->dflt.check);
- else if (cursor->type == t_time || cursor->type == t_ignore)
+ else if (cursor->type == t_ignore)
maxlen = JSON_VAL_MAX;
else if (cursor->map != NULL)
maxlen = (int)sizeof(valbuf) - 1;
*/
for (;;) {
int seeking = cursor->type;
- if (value_quoted && (cursor->type == t_string || cursor->type == t_time))
+ if (value_quoted && cursor->type == t_string)
break;
if ((strcmp(valbuf, "true")==0 || strcmp(valbuf, "false")==0)
&& seeking == t_boolean)
}
if (value_quoted
&& (cursor->type != t_string && cursor->type != t_character
- && cursor->type != t_check && cursor->type != t_time
+ && cursor->type != t_check
&& cursor->type != t_ignore && cursor->map == 0)) {
json_debug_trace((1,
"Saw quoted value when expecting non-string.\n"));
}
if (!value_quoted
&& (cursor->type == t_string || cursor->type == t_check
- || cursor->type == t_time || cursor->map != 0)) {
+ || cursor->map != 0)) {
json_debug_trace((1,
"Didn't see quoted value when expecting string.\n"));
return JSON_ERR_NONQSTRING;
memcpy(lptr, &tmp, sizeof(unsigned int));
}
break;
- case t_time:
- {
- double tmp = iso8601_to_unix(valbuf);
- memcpy(lptr, &tmp, sizeof(double));
- }
- break;
case t_real:
{
double tmp = atof(valbuf);
cp += 5;
}
break;
- case t_time:
case t_character:
case t_array:
case t_check:
{"class", t_check, .dflt.check = "TPV"},
{"device", t_string, .addr.string = gpsdata->dev.path,
.len = sizeof(gpsdata->dev.path)},
- {"time", t_time, .addr.real = &gpsdata->fix.time,
- .dflt.real = NAN},
- {"time", t_real, .addr.real = &gpsdata->fix.time,
- .dflt.real = NAN},
{"ept", t_real, .addr.real = &gpsdata->fix.ept,
.dflt.real = NAN},
{"lon", t_real, .addr.real = &gpsdata->fix.longitude,
{"class", t_check, .dflt.check = "SKY"},
{"device", t_string, .addr.string = gpsdata->dev.path,
.len = sizeof(gpsdata->dev.path)},
- {"time", t_time, .addr.real = &gpsdata->skyview_time,
- .dflt.real = NAN},
- {"time", t_real, .addr.real = &gpsdata->skyview_time,
- .dflt.real = NAN},
{"hdop", t_real, .addr.real = &gpsdata->dop.hdop,
.dflt.real = NAN},
{"xdop", t_real, .addr.real = &gpsdata->dop.xdop,
{"class", t_check, .dflt.check = "DEVICE"},
{"path", t_string, STRUCTOBJECT(struct devconfig_t, path),
.len = sizeof(gpsdata->devices.list[0].path)},
- {"activated", t_time, STRUCTOBJECT(struct devconfig_t, activated)},
{"activated", t_real, STRUCTOBJECT(struct devconfig_t, activated)},
{"flags", t_integer, STRUCTOBJECT(struct devconfig_t, flags)},
{"driver", t_string, STRUCTOBJECT(struct devconfig_t, driver),
/* *INDENT-OFF* */
static const char json_str1[] = "{\"class\":\"TPV\",\
\"device\":\"GPS#1\", \
- \"time\":\"2005-06-19T08:12:41.89Z\",\"lon\":46.498203637,\"lat\":7.568074350,\
+ \"lon\":46.498203637,\"lat\":7.568074350,\
\"alt\":1327.780,\"epx\":21.000,\"epy\":23.000,\"epv\":124.484,\"mode\":3}";
/* Case 2: SKY report */
static const char *json_str2 = "{\"class\":\"SKY\",\
- \"time\":\"2005-06-19T12:12:42.03Z\", \
\"satellites\":[\
{\"PRN\":10,\"el\":45,\"az\":196,\"ss\":34,\"used\":true},\
{\"PRN\":29,\"el\":67,\"az\":310,\"ss\":40,\"used\":true},\
assert_case(1, status);
assert_string("device", gpsdata.dev.path, "GPS#1");
assert_integer("mode", gpsdata.fix.mode, 3);
- assert_real("time", gpsdata.fix.time, 1119168761.8900001);
assert_real("lon", gpsdata.fix.longitude, 46.498203637);
assert_real("lat", gpsdata.fix.latitude, 7.568074350);
break;