summaryrefslogtreecommitdiff
path: root/libgps_json.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2009-08-23 16:16:41 +0000
committerEric S. Raymond <esr@thyrsus.com>2009-08-23 16:16:41 +0000
commit786b64c58720d4f0cab5f9ca08445cbd5a94e6a0 (patch)
tree05249d84a6388cc3318ba074f8f8b11b29ab55eb /libgps_json.c
parenta9ba00e95e6e6760ad96d88e7e1d2581af75822b (diff)
downloadgpsd-786b64c58720d4f0cab5f9ca08445cbd5a94e6a0.tar.gz
Correctly read JSON ERROR responses in the client library.
Diffstat (limited to 'libgps_json.c')
-rw-r--r--libgps_json.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/libgps_json.c b/libgps_json.c
index fc293de6..fa0a2b82 100644
--- a/libgps_json.c
+++ b/libgps_json.c
@@ -222,7 +222,26 @@ static int json_version_read(const char *buf,
if (status != 0)
return status;
- gpsdata->set |= DEVICELIST_SET;
+ gpsdata->set |= VERSION_SET;
+ return 0;
+}
+
+static int json_error_read(const char *buf,
+ struct gps_data_t *gpsdata, const char **endptr)
+{
+ const struct json_attr_t json_attrs_error[] = {
+ {"class", check, .dflt.check = "ERROR"},
+ {"message", string, .addr.string.ptr = gpsdata->error,
+ .addr.string.len = sizeof(gpsdata->error)},
+ {NULL},
+ };
+ int status;
+
+ status = json_read_object(buf, json_attrs_error, endptr);
+ if (status != 0)
+ return status;
+
+ gpsdata->set |= ERR_SET;
return 0;
}
@@ -254,6 +273,8 @@ int libgps_json_unpack(const char *buf, struct gps_data_t *gpsdata)
return status;
} else if (strstr(buf, "\"class\":\"VERSION\"") != 0) {
return json_version_read(buf, gpsdata, NULL);
+ } else if (strstr(buf, "\"class\":\"ERROR\"") != 0) {
+ return json_error_read(buf, gpsdata, NULL);
} else
return -1;
}