diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2013-11-11 23:16:47 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2013-11-11 23:16:47 -0500 |
commit | dc474138fe67f41f08f4f942e9e68e1fbc15a6ad (patch) | |
tree | d515a95d947de6e87e6fa8475f4a6b61d1d7ffec /gpsd_json.c | |
parent | 134114023bf10242a6d8d3caf9c8d6219dc136e6 (diff) | |
download | gpsd-dc474138fe67f41f08f4f942e9e68e1fbc15a6ad.tar.gz |
Correctly mark deactivated devices, and do a better job of dumping them.
Diffstat (limited to 'gpsd_json.c')
-rw-r--r-- | gpsd_json.c | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/gpsd_json.c b/gpsd_json.c index 6cd1571f..b3188e99 100644 --- a/gpsd_json.c +++ b/gpsd_json.c @@ -358,11 +358,30 @@ void json_device_dump(const struct gps_device_t *device, /*@out@*/ char *reply, size_t replylen) { struct classmap_t *cmp; + char buf1[JSON_VAL_MAX * 2 + 1]; + (void)strlcpy(reply, "{\"class\":\"DEVICE\",\"path\":\"", replylen); (void)strlcat(reply, device->gpsdata.dev.path, replylen); (void)strlcat(reply, "\",", replylen); + if (device->device_type != NULL) { + (void)strlcat(reply, "\"driver\":\"", replylen); + (void)strlcat(reply, device->device_type->type_name, replylen); + (void)strlcat(reply, "\",", replylen); + } + /*@-mustfreefresh@*/ + if (device->subtype[0] != '\0') { + (void)strlcat(reply, "\"subtype\":\"", replylen); + (void)strlcat(reply, + json_stringify(buf1, sizeof(buf1), device->subtype), + replylen); + (void)strlcat(reply, "\",", replylen); + } + /*@+mustfreefresh@*/ + /* + * There's an assumption here: Anything that we type service_sensor is + * a serial device with the usual control parameters. + */ if (device->gpsdata.online > 0) { - char buf1[JSON_VAL_MAX * 2 + 1]; (void)snprintf(reply + strlen(reply), replylen - strlen(reply), "\"activated\":\"%s\",", unix_to_iso8601(device->gpsdata.online, buf1, sizeof(buf1))); @@ -376,24 +395,6 @@ void json_device_dump(const struct gps_device_t *device, replylen - strlen(reply), "\"flags\":%d,", mask); } - if (device->device_type != NULL) { - (void)strlcat(reply, "\"driver\":\"", replylen); - (void)strlcat(reply, device->device_type->type_name, replylen); - (void)strlcat(reply, "\",", replylen); - } - /*@-mustfreefresh@*/ - if (device->subtype[0] != '\0') { - (void)strlcat(reply, "\"subtype\":\"", replylen); - (void)strlcat(reply, - json_stringify(buf1, sizeof(buf1), device->subtype), - replylen); - (void)strlcat(reply, "\",", replylen); - } - /*@+mustfreefresh@*/ - /* - * There's an assumption here: Anything that we type service_sensor is - * a serial device with the usual control parameters. - */ if (device->servicetype == service_sensor) { /* speed can be 0 if the device is not currently active */ speed_t speed = gpsd_get_speed(device); |