diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2013-09-29 01:42:45 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2013-09-29 01:46:53 -0400 |
commit | 4361ec2d89bdf451602d659ddfd0fb9a79c178a2 (patch) | |
tree | af067d1d7614a9e67f449eec933ba3347cde10b0 /net_ntrip.c | |
parent | a77b95b57475c2856707e91b197f8aaa8e5eb407 (diff) | |
download | gpsd-4361ec2d89bdf451602d659ddfd0fb9a79c178a2.tar.gz |
Change gpsd_report to no longer use a global. All regression tests pass.
This is a large, ugly change. But without it we can't troubleshoot the
ICP/IP-source initialization bug properly - colliding definitions of
gpsd_report() were interfering with error reporting early in gpsd runs.
More cleanup work remains to be done, but at least this is working.
Diffstat (limited to 'net_ntrip.c')
-rw-r--r-- | net_ntrip.c | 138 |
1 files changed, 79 insertions, 59 deletions
diff --git a/net_ntrip.c b/net_ntrip.c index dd21f139..858a1872 100644 --- a/net_ntrip.c +++ b/net_ntrip.c @@ -35,7 +35,8 @@ /*@ -temptrans -mustfreefresh @*/ static /*@null@*/ char *ntrip_field_iterate( /*@null@ */ char *start, /*@null@*/ char *prev, - const char *eol) + const char *eol, + const int debug) { char *s, *t, *u; @@ -57,7 +58,7 @@ static /*@null@*/ char *ntrip_field_iterate( /*@null@ */ char *start, if ((t = strstr(t, ";"))) *t = '\0'; - gpsd_report(LOG_RAW, "Next Ntrip source table field %s\n", s); + gpsd_report(debug, LOG_RAW, "Next Ntrip source table field %s\n", s); return s; } @@ -66,19 +67,20 @@ static /*@null@*/ char *ntrip_field_iterate( /*@null@ */ char *start, /*@ -mustfreefresh @*/ static void ntrip_str_parse(char *str, size_t len, - /*@out@*/ struct ntrip_stream_t *hold) + /*@out@*/ struct ntrip_stream_t *hold, + const int debug) { char *s, *eol = str + len; memset(hold, 0, sizeof(*hold)); /* <mountpoint> */ - if ((s = ntrip_field_iterate(str, NULL, eol))) + if ((s = ntrip_field_iterate(str, NULL, eol, debug))) (void)strlcpy(hold->mountpoint, s, sizeof(hold->mountpoint)); /* <identifier> */ - s = ntrip_field_iterate(NULL, s, eol); + s = ntrip_field_iterate(NULL, s, eol, debug); /* <format> */ - if ((s = ntrip_field_iterate(NULL, s, eol))) { + if ((s = ntrip_field_iterate(NULL, s, eol, debug))) { if (strcasecmp("RTCM 2", s) == 0) hold->format = fmt_rtcm2; else if (strcasecmp("RTCM 2.0", s) == 0) @@ -98,41 +100,41 @@ static void ntrip_str_parse(char *str, size_t len, hold->format = fmt_unknown; } /* <format-details> */ - s = ntrip_field_iterate(NULL, s, eol); + s = ntrip_field_iterate(NULL, s, eol, debug); /* <carrier> */ - if ((s = ntrip_field_iterate(NULL, s, eol))) + if ((s = ntrip_field_iterate(NULL, s, eol, debug))) hold->carrier = atoi(s); /* <nav-system> */ - s = ntrip_field_iterate(NULL, s, eol); + s = ntrip_field_iterate(NULL, s, eol, debug); /* <network> */ - s = ntrip_field_iterate(NULL, s, eol); + s = ntrip_field_iterate(NULL, s, eol, debug); /* <country> */ - s = ntrip_field_iterate(NULL, s, eol); + s = ntrip_field_iterate(NULL, s, eol, debug); /* <latitude> */ hold->latitude = NAN; - if ((s = ntrip_field_iterate(NULL, s, eol))) + if ((s = ntrip_field_iterate(NULL, s, eol, debug))) hold->latitude = atof(s); /* <longitude> */ hold->longitude = NAN; - if ((s = ntrip_field_iterate(NULL, s, eol))) + if ((s = ntrip_field_iterate(NULL, s, eol, debug))) hold->longitude = atof(s); /* <nmea> */ - if ((s = ntrip_field_iterate(NULL, s, eol))) { + if ((s = ntrip_field_iterate(NULL, s, eol, debug))) { hold->nmea = atoi(s); } /* <solution> */ - s = ntrip_field_iterate(NULL, s, eol); + s = ntrip_field_iterate(NULL, s, eol, debug); /* <generator> */ - s = ntrip_field_iterate(NULL, s, eol); + s = ntrip_field_iterate(NULL, s, eol, debug); /* <compr-encryp> */ - if ((s = ntrip_field_iterate(NULL, s, eol))) { + if ((s = ntrip_field_iterate(NULL, s, eol, debug))) { if (strcasecmp("none", s) == 0) hold->compr_encryp = cmp_enc_none; else hold->compr_encryp = cmp_enc_unknown; } /* <authentication> */ - if ((s = ntrip_field_iterate(NULL, s, eol))) { + if ((s = ntrip_field_iterate(NULL, s, eol, debug))) { if (strcasecmp("N", s) == 0) hold->authentication = auth_none; else if (strcasecmp("B", s) == 0) @@ -143,15 +145,15 @@ static void ntrip_str_parse(char *str, size_t len, hold->authentication = auth_unknown; } /* <fee> */ - if ((s = ntrip_field_iterate(NULL, s, eol))) { + if ((s = ntrip_field_iterate(NULL, s, eol, debug))) { hold->fee = atoi(s); } /* <bitrate> */ - if ((s = ntrip_field_iterate(NULL, s, eol))) { + if ((s = ntrip_field_iterate(NULL, s, eol, debug))) { hold->bitrate = atoi(s); } /* ...<misc> */ - while ((s = ntrip_field_iterate(NULL, s, eol))); + while ((s = ntrip_field_iterate(NULL, s, eol, debug))); } static int ntrip_sourcetable_parse(struct gps_device_t *device) @@ -181,19 +183,22 @@ static int ntrip_sourcetable_parse(struct gps_device_t *device) if (match) { return 1; } - gpsd_report(LOG_ERROR, "ntrip stream read error %d on fd %d\n", - errno, fd); + gpsd_report(device->context->debug, LOG_ERROR, + "ntrip stream read error %d on fd %d\n", + errno, fd); return -1; } else if (rlen == 0) { // server closed the connection - gpsd_report(LOG_ERROR, "ntrip stream unexpected close %d on fd %d during sourcetable read\n", - errno, fd); + gpsd_report(device->context->debug, LOG_ERROR, + "ntrip stream unexpected close %d on fd %d during sourcetable read\n", + errno, fd); return -1; } line = buf; rlen = len += rlen; - gpsd_report(LOG_RAW, "Ntrip source table buffer %s\n", buf); + gpsd_report(device->context->debug, LOG_RAW, + "Ntrip source table buffer %s\n", buf); sourcetable = device->ntrip.sourcetable_parse; if (!sourcetable) { @@ -206,8 +211,9 @@ static int ntrip_sourcetable_parse(struct gps_device_t *device) line += llen; len -= llen; } else { - gpsd_report(LOG_WARN, "Received unexpexted Ntrip reply %s.\n", - buf); + gpsd_report(device->context->debug, LOG_WARN, + "Received unexpexted Ntrip reply %s.\n", + buf); return -1; } } @@ -223,7 +229,8 @@ static int ntrip_sourcetable_parse(struct gps_device_t *device) if (!(eol = strstr(line, NTRIP_BR))) break; - gpsd_report(LOG_IO, "next Ntrip source table line %s\n", line); + gpsd_report(device->context->debug, LOG_IO, + "next Ntrip source table line %s\n", line); *eol = '\0'; llen = (ssize_t) (eol - line); @@ -233,18 +240,19 @@ static int ntrip_sourcetable_parse(struct gps_device_t *device) /* parse STR */ if (strncmp(line, NTRIP_STR, strlen(NTRIP_STR)) == 0) { ntrip_str_parse(line + strlen(NTRIP_STR), - (size_t) (llen - strlen(NTRIP_STR)), &hold); + (size_t) (llen - strlen(NTRIP_STR)), + &hold, device->context->debug); if (strcmp(device->ntrip.stream.mountpoint, hold.mountpoint) == 0) { /* todo: support for RTCM 3.0, SBAS (WAAS, EGNOS), ... */ if (hold.format == fmt_unknown) { - gpsd_report(LOG_ERROR, + gpsd_report(device->context->debug, LOG_ERROR, "Ntrip stream %s format not supported\n", line); return -1; } /* todo: support encryption and compression algorithms */ if (hold.compr_encryp != cmp_enc_none) { - gpsd_report(LOG_ERROR, + gpsd_report(device->context->debug, LOG_ERROR, "Ntrip stream %s compression/encryption algorithm not supported\n", line); return -1; @@ -252,7 +260,7 @@ static int ntrip_sourcetable_parse(struct gps_device_t *device) /* todo: support digest authentication */ if (hold.authentication != auth_none && hold.authentication != auth_basic) { - gpsd_report(LOG_ERROR, + gpsd_report(device->context->debug, LOG_ERROR, "Ntrip stream %s authentication method not supported\n", line); return -1; @@ -282,7 +290,7 @@ static int ntrip_sourcetable_parse(struct gps_device_t *device) llen += strlen(NTRIP_BR); line += llen; len -= llen; - gpsd_report(LOG_RAW, + gpsd_report(device->context->debug, LOG_RAW, "Remaining Ntrip source table buffer %zd %s\n", len, line); } @@ -298,7 +306,8 @@ done: return match ? 1 : -1; } -static int ntrip_stream_req_probe(const struct ntrip_stream_t *stream) +static int ntrip_stream_req_probe(const struct ntrip_stream_t *stream, + const int debug) { int dsock; ssize_t r; @@ -306,10 +315,10 @@ static int ntrip_stream_req_probe(const struct ntrip_stream_t *stream) dsock = netlib_connectsock(AF_UNSPEC, stream->url, stream->port, "tcp"); if (dsock < 0) { - gpsd_report(LOG_ERROR, "ntrip stream connect error %d in req probe\n", dsock); + gpsd_report(debug, LOG_ERROR, "ntrip stream connect error %d in req probe\n", dsock); return -1; } - gpsd_report(LOG_SPIN, "ntrip stream for req probe connected on fd %d\n", dsock); + gpsd_report(debug, LOG_SPIN, "ntrip stream for req probe connected on fd %d\n", dsock); (void)snprintf(buf, sizeof(buf), "GET / HTTP/1.1\r\n" "User-Agent: NTRIP gpsd/%s\r\n" @@ -318,8 +327,9 @@ static int ntrip_stream_req_probe(const struct ntrip_stream_t *stream) "\r\n", VERSION, stream->url); r = write(dsock, buf, strlen(buf)); if (r != (ssize_t)strlen(buf)) { - gpsd_report(LOG_ERROR, "ntrip stream write error %d on fd %d during probe request %zd\n", - errno, dsock, r); + gpsd_report(debug, LOG_ERROR, + "ntrip stream write error %d on fd %d during probe request %zd\n", + errno, dsock, r); (int)close(dsock); return -1; } @@ -353,19 +363,22 @@ static int ntrip_auth_encode(const struct ntrip_stream_t *stream, /* *INDENT-ON* */ -static int ntrip_stream_get_req(const struct ntrip_stream_t *stream) +static int ntrip_stream_get_req(const struct ntrip_stream_t *stream, + const int debug) { int dsock; char buf[BUFSIZ]; dsock = netlib_connectsock(AF_UNSPEC, stream->url, stream->port, "tcp"); if (BAD_SOCKET(dsock)) { - gpsd_report(LOG_ERROR, "ntrip stream connect error %d\n", dsock); + gpsd_report(debug, LOG_ERROR, + "ntrip stream connect error %d\n", dsock); return -1; } - gpsd_report(LOG_SPIN, "netlib_connectsock() returns socket on fd %d\n", - dsock); + gpsd_report(debug, LOG_SPIN, + "netlib_connectsock() returns socket on fd %d\n", + dsock); (void)snprintf(buf, sizeof(buf), "GET /%s HTTP/1.1\r\n" @@ -376,15 +389,17 @@ static int ntrip_stream_get_req(const struct ntrip_stream_t *stream) "Connection: close\r\n" "\r\n", stream->mountpoint, VERSION, stream->url, stream->authStr); if (write(dsock, buf, strlen(buf)) != (ssize_t) strlen(buf)) { - gpsd_report(LOG_ERROR, "ntrip stream write error %d on fd %d during get request\n", errno, - dsock); + gpsd_report(debug, LOG_ERROR, + "ntrip stream write error %d on fd %d during get request\n", errno, + dsock); (void)close(dsock); return -1; } return dsock; } -static int ntrip_stream_get_parse(const struct ntrip_stream_t *stream, int dsock) +static int ntrip_stream_get_parse(const struct ntrip_stream_t *stream, + const int dsock, const int debug) { /*@-nullpass@*/ char buf[BUFSIZ]; @@ -393,29 +408,30 @@ static int ntrip_stream_get_parse(const struct ntrip_stream_t *stream, int dsock while (read(dsock, buf, sizeof(buf) - 1) == -1) { if (errno == EINTR) continue; - gpsd_report(LOG_ERROR, "ntrip stream read error %d on fd %d during get rsp\n", errno, - dsock); + gpsd_report(debug, LOG_ERROR, + "ntrip stream read error %d on fd %d during get rsp\n", errno, + dsock); goto close; } /* parse 401 Unauthorized */ /* coverity[string_null] - guaranteed terminated by the memset above */ if (strstr(buf, NTRIP_UNAUTH)!=NULL) { - gpsd_report(LOG_ERROR, + gpsd_report(debug, LOG_ERROR, "not authorized for Ntrip stream %s/%s\n", stream->url, stream->mountpoint); goto close; } /* parse SOURCETABLE */ if (strstr(buf, NTRIP_SOURCETABLE)!=NULL) { - gpsd_report(LOG_ERROR, + gpsd_report(debug, LOG_ERROR, "Broadcaster doesn't recognize Ntrip stream %s:%s/%s\n", stream->url, stream->port, stream->mountpoint); goto close; } /* parse ICY 200 OK */ if (strstr(buf, NTRIP_ICY)==NULL) { - gpsd_report(LOG_ERROR, + gpsd_report(debug, LOG_ERROR, "Unknown reply %s from Ntrip service %s:%s/%s\n", buf, stream->url, stream->port, stream->mountpoint); goto close; @@ -462,7 +478,7 @@ int ntrip_open(struct gps_device_t *device, char *caster) tmp = amp + 1; url = tmp; } else { - gpsd_report(LOG_ERROR, + gpsd_report(device->context->debug, LOG_ERROR, "can't extract user-ID and password from %s\n", caster); device->ntrip.conn_state = ntrip_conn_err; @@ -475,8 +491,9 @@ int ntrip_open(struct gps_device_t *device, char *caster) stream = slash + 1; } else { /* todo: add autoconnect like in dgpsip.c */ - gpsd_report(LOG_ERROR, "can't extract Ntrip stream from %s\n", - caster); + gpsd_report(device->context->debug, LOG_ERROR, + "can't extract Ntrip stream from %s\n", + caster); device->ntrip.conn_state = ntrip_conn_err; return -1; } @@ -510,7 +527,8 @@ int ntrip_open(struct gps_device_t *device, char *caster) port, sizeof(device->ntrip.stream.port)); - ret = ntrip_stream_req_probe(&device->ntrip.stream); + ret = ntrip_stream_req_probe(&device->ntrip.stream, + device->context->debug); if (ret == -1) { device->ntrip.conn_state = ntrip_conn_err; return -1; @@ -532,7 +550,8 @@ int ntrip_open(struct gps_device_t *device, char *caster) device->ntrip.conn_state = ntrip_conn_err; return -1; } - ret = ntrip_stream_get_req(&device->ntrip.stream); + ret = ntrip_stream_get_req(&device->ntrip.stream, + device->context->debug); if (ret == -1) { device->ntrip.conn_state = ntrip_conn_err; return -1; @@ -542,7 +561,8 @@ int ntrip_open(struct gps_device_t *device, char *caster) break; case ntrip_conn_sent_get: ret = ntrip_stream_get_parse(&device->ntrip.stream, - device->gpsdata.gps_fd); + device->gpsdata.gps_fd, + device->context->debug); if (ret == -1) { device->ntrip.conn_state = ntrip_conn_err; return -1; @@ -578,9 +598,9 @@ void ntrip_report(struct gps_context_t *context, gpsd_position_fix_dump(gps, buf, sizeof(buf)); if (write(caster->gpsdata.gps_fd, buf, strlen(buf)) == (ssize_t) strlen(buf)) { - gpsd_report(LOG_IO, "=> dgps %s\n", buf); + gpsd_report(context->debug, LOG_IO, "=> dgps %s\n", buf); } else { - gpsd_report(LOG_IO, "ntrip report write failed\n"); + gpsd_report(context->debug, LOG_IO, "ntrip report write failed\n"); } } } |