summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2009-08-23 17:39:16 +0000
committerEric S. Raymond <esr@thyrsus.com>2009-08-23 17:39:16 +0000
commitfa90ccb8403d7e0f704a10517935a6bebde061e0 (patch)
tree3615678ff542a5a0c474d685c46ad62358a4b382
parent786b64c58720d4f0cab5f9ca08445cbd5a94e6a0 (diff)
downloadgpsd-fa90ccb8403d7e0f704a10517935a6bebde061e0.tar.gz
Arrange for clients to see a VERSION response when they first connect.
-rw-r--r--gps_json.h1
-rw-r--r--gpsd.c14
-rw-r--r--gpsd.xml3
-rw-r--r--gpsd_json.c7
4 files changed, 21 insertions, 4 deletions
diff --git a/gps_json.h b/gps_json.h
index 7f7033d9..dd6d4b1e 100644
--- a/gps_json.h
+++ b/gps_json.h
@@ -7,6 +7,7 @@
int json_watch_read(const char *, struct policy_t *, const char **);
int json_configdev_read(const char *, struct devconfig_t *, const char **);
+void json_version_dump(char *reply, size_t replylen);
void json_tpv_dump(struct gps_data_t *, struct gps_fix_t *, char *, size_t);
void json_sky_dump(struct gps_data_t *, char *, size_t);
void json_device_dump(struct gps_device_t *, char *, size_t);
diff --git a/gpsd.c b/gpsd.c
index 2ebab296..74dbdc5b 100644
--- a/gpsd.c
+++ b/gpsd.c
@@ -1717,10 +1717,8 @@ static void handle_newstyle_request(struct subscriber_t *sub,
reply[strlen(reply)-2] = '\0';
}
} else if (strncmp(buf, "VERSION;", 8) == 0) {
- (void)snprintf(reply+strlen(reply), replylen-strlen(reply),
- "{\"class\":\"VERSION\",\"release\":\"" VERSION "\",\"rev\":\"$Id$\",\"api_major\":%d,\"api_minor\":%d}",
- GPSD_API_MAJOR_VERSION, GPSD_API_MINOR_VERSION);
buf += 8;
+ json_version_dump(reply + strlen(reply), replylen - strlen(reply));
} else {
const char *errend;
errend = buf + strlen(buf) - 1;
@@ -2031,6 +2029,9 @@ int main(int argc, char *argv[])
if (FD_ISSET(msock, &rfds)) {
socklen_t alen = (socklen_t)sizeof(fsin);
char *c_ip;
+#ifdef GPSDNG_ENABLE
+ char announce[GPS_JSON_RESPONSE_MAX];
+#endif /* GPSDNG_ENABLE */
/*@i1@*/int ssock = accept(msock, (struct sockaddr *) &fsin, &alen);
if (ssock == -1)
@@ -2057,7 +2058,12 @@ int main(int argc, char *argv[])
client->tied = false;
#endif /* OLDSTYLE_ENABLE */
gpsd_report(LOG_INF, "client %s (%d) connect on fd %d\n",
- c_ip, sub_index(client), ssock);
+ c_ip, sub_index(client), ssock);
+#ifdef GPSDNG_ENABLE
+ json_version_dump(announce, sizeof(announce));
+ (void)strlcat(announce, "\r\n", sizeof(announce));
+ (void)throttled_write(client, announce, strlen(announce));
+#endif /* GPSDNG_ENABLE */
}
}
FD_CLR(msock, &rfds);
diff --git a/gpsd.xml b/gpsd.xml
index 9cd83207..2e36185f 100644
--- a/gpsd.xml
+++ b/gpsd.xml
@@ -832,6 +832,9 @@ limit is 1024 characters, including trailing newline.</para>
</tgroup>
</table>
+<para>The daemon ships a VERSION response to each client when the
+client first connects to it.</para>
+
<para>When the C client library parses a response of this kind, it
will assert the VERSION_SET bit in the top-level set member.</para>
diff --git a/gpsd_json.c b/gpsd_json.c
index b022333e..d18ba5b7 100644
--- a/gpsd_json.c
+++ b/gpsd_json.c
@@ -18,6 +18,13 @@ representations to gpsd core strctures, and vice_versa.
#include "gpsd.h"
#include "gps_json.h"
+void json_version_dump(char *reply, size_t replylen)
+{
+ (void)snprintf(reply, replylen,
+ "{\"class\":\"VERSION\",\"release\":\"" VERSION "\",\"rev\":\"$Id: gpsd.c 5957 2009-08-23 15:45:54Z esr $\",\"api_major\":%d,\"api_minor\":%d}",
+ GPSD_API_MAJOR_VERSION, GPSD_API_MINOR_VERSION);
+}
+
void json_tpv_dump(struct gps_data_t *gpsdata, struct gps_fix_t *fixp,
char *reply, size_t replylen)
{