summaryrefslogtreecommitdiff
path: root/gpsd.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2009-09-19 13:51:54 +0000
committerEric S. Raymond <esr@thyrsus.com>2009-09-19 13:51:54 +0000
commitcb1eae416026ab7ef89529a546158a8f30a45dc2 (patch)
treeb724d9731ff8efe018cc097811c317eda0bc9595 /gpsd.c
parentcb830d185eece1a07cfc8aaadcb8765278fe1d1f (diff)
downloadgpsd-cb1eae416026ab7ef89529a546158a8f30a45dc2.tar.gz
Add ckuethe's most requested JSON feature: WATCH a specified single device only.
Diffstat (limited to 'gpsd.c')
-rw-r--r--gpsd.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/gpsd.c b/gpsd.c
index caaed26a..09c4df3b 100644
--- a/gpsd.c
+++ b/gpsd.c
@@ -507,6 +507,7 @@ static void detach_client(struct subscriber_t *sub)
sub->policy.nmea = false;
sub->policy.raw = 0;
sub->policy.scaled = false;
+ sub->policy.devpath[0] = '\0';
for (channel = channels; channel < channels + NITEMS(channels); channel++)
if (channel->subscriber == sub)
{
@@ -515,6 +516,7 @@ static void detach_client(struct subscriber_t *sub)
}
sub->fd = -1;
+ /*@+mustfreeonly@*/
}
static ssize_t throttled_write(struct subscriber_t *sub, char *buf, size_t len)
@@ -1645,15 +1647,28 @@ static void handle_newstyle_request(struct subscriber_t *sub,
++end;
buf = end;
}
- if (status == 0) {
- if (sub->policy.watcher)
+ if (status != 0) {
+ (void)snprintf(reply, replylen,
+ "{\"class\":\"ERROR\",\"message\":\"Invalid WATCH: %s\"}\r\n",
+ json_error_string(status));
+ } else if (sub->policy.watcher) {
+ if (sub->policy.devpath[0] == '\0') {
+ /* assign all devices */
for(devp = devices; devp < devices + MAXDEVICES; devp++)
if (allocated_device(devp))
(void)assign_channel(sub, ANY, devp);
- } else
- (void)snprintf(reply+strlen(reply), replylen-strlen(reply),
- "{\"class\":\"ERROR\",\"message\":\"Invalid WATCH: %s\"}\r\n",
- json_error_string(status));
+ } else {
+ devp = find_device(sub->policy.devpath);
+ if (devp == NULL) {
+ (void)snprintf(reply, replylen,
+ "{\"class\":\"ERROR\",\"message\":\"Do nuch device as %s\"}\r\n", sub->policy.devpath);
+ goto bailout;
+ } else if (assign_channel(sub, ANY, devp) == NULL)
+ (void)snprintf(reply, replylen,
+ "{\"class\":\"ERROR\",\"message\":\"Can't assign %s\"}\r\n", sub->policy.devpath);
+ goto bailout;
+ }
+ }
}
/* display the user's policy */
json_watch_dump(&sub->policy,
@@ -2266,7 +2281,7 @@ int main(int argc, char *argv[])
/* we may need to add device to new-style watcher lists */
if ((changed & DEVICE_SET) != 0) {
for (sub = subscribers; sub < subscribers + MAXSUBSCRIBERS; sub++)
- if (sub->policy.watcher && newstyle(sub))
+ if (sub->policy.watcher && newstyle(sub) && sub->policy.devpath[0] == '\0')
(void)assign_channel(sub, ANY, device);
}
/* handle laggy response to a firmware version query */