diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2013-11-07 07:05:35 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2013-11-07 07:05:35 -0500 |
commit | da16b5f3e379e89d30207b0fba92559e0f99e502 (patch) | |
tree | 4a9f67d50e486e1a298c6e8f1850939099c8ef6c | |
parent | 7d2389b9b492026e0b653e3eccdba89b0ee113b6 (diff) | |
download | gpsd-da16b5f3e379e89d30207b0fba92559e0f99e502.tar.gz |
Polish the JSON passthrough code, and add a regression test.
-rw-r--r-- | drivers.c | 8 | ||||
-rw-r--r-- | test/daemon/passthrough.log | 8 | ||||
-rw-r--r-- | test/daemon/passthrough.log.chk | 3 |
3 files changed, 15 insertions, 4 deletions
@@ -1394,7 +1394,7 @@ static void path_rewrite(struct gps_device_t *session, char *prefix) /* * Hack the packet to reflect its origin. This code is supposed * to insert the path naming the remote gpsd instance into the - * baginning of the path attribute, followed by a # to separate it + * beginning of the path attribute, followed by a # to separate it * from the device. */ char *prefloc; @@ -1402,7 +1402,7 @@ static void path_rewrite(struct gps_device_t *session, char *prefix) prefloc < (char *)session->packet.outbuffer+session->packet.outbuflen; prefloc++) if (strncmp(prefloc, prefix, strlen(prefix)) == 0) { - char copy[sizeof(session->packet.outbuffer)]; + char copy[sizeof(session->packet.outbuffer)+1]; (void)strlcpy(copy, (char *)session->packet.outbuffer, sizeof(copy)); @@ -1419,13 +1419,13 @@ static void path_rewrite(struct gps_device_t *session, char *prefix) session->packet.outbuflen = strlen((char *)session->packet.outbuffer); } -static gps_mask_t json_pass_packet(struct gps_device_t *session UNUSED) +static gps_mask_t json_pass_packet(struct gps_device_t *session) { gpsd_report(session->context->debug, LOG_IO, "<= GPS: %s\n", (char *)session->packet.outbuffer); /*@-nullpass@*/ /* required only because splint is buggy */ - /* devices and paths need to be edited to */ + /* devices and paths need to be edited */ if (strstr((char *)session->packet.outbuffer, "DEVICE") != NULL) path_rewrite(session, "\"path\":\""); path_rewrite(session, "\"device\":\""); diff --git a/test/daemon/passthrough.log b/test/daemon/passthrough.log new file mode 100644 index 00000000..1aca5827 --- /dev/null +++ b/test/daemon/passthrough.log @@ -0,0 +1,8 @@ +# Name: JSON +# Submitter: Eric S. Raymond <esr@thyrsus.com> +# Date: 2013-11-07 +# Notes: Tests the JSON passthrough feature. +# +{"class":"XXX","text":"U can't touch dis."} +{"class":"YYY","path":"theyellowbrickroad"} +{"class":"ZZZ","device":"amireacleofstrange"} diff --git a/test/daemon/passthrough.log.chk b/test/daemon/passthrough.log.chk new file mode 100644 index 00000000..d82280bf --- /dev/null +++ b/test/daemon/passthrough.log.chk @@ -0,0 +1,3 @@ +{"class":"XXX","text":"U can't touch dis."}
+{"class":"YYY","path":"theyellowbrickroad"}
+{"class":"ZZZ"}
|