Coverage Report

Created: 2026-10-10 07:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gpsd/gpsd-3.27.6~dev/gpsd/net_gnss_dispatch.c
Line
Count
Source
1
/* net_gnss_dispatch.c -- common interface to a number of Network GNSS services
2
 *
3
 * This file is Copyright by the GPSD project
4
 * SPDX-License-Identifier: BSD-2-clause
5
 */
6
7
#include "../include/gpsd_config.h"  // must be before all includes
8
9
#include <errno.h>
10
#include <string.h>
11
#include <sys/socket.h>
12
#include <sys/stat.h>
13
#include <sys/types.h>
14
#include <unistd.h>
15
16
#include "../include/gpsd.h"
17
#include "../include/strfuncs.h"
18
19
0
#define NETGNSS_TCP       "tcp://"
20
0
#define NETGNSS_UDP       "udp://"
21
0
#define NETGNSS_DGPSIP    "dgpsip://"
22
0
#define NETGNSS_NTRIP     "ntrip://"
23
0
#define NETGNSS_GPSD      "gpsd://"
24
0
#define NETGNSS_NMEA2000  "nmea2000://"
25
26
// is given string a valid URI for network/service? Is so, which one?
27
net_link_type netgnss_uri_type(const char *name)
28
0
{
29
0
    if (str_starts_with(name, NETGNSS_DGPSIP)) {
30
0
        return NET_DGPSIP;
31
0
    }
32
33
0
    if (str_starts_with(name, NETGNSS_GPSD)) {
34
0
        return NET_GPSD;
35
0
    }
36
37
0
    if (str_starts_with(name, NETGNSS_NTRIP)) {
38
0
        return NET_NTRIP;
39
0
    }
40
41
0
    if (str_starts_with(name, NETGNSS_TCP)) {
42
0
        return NET_TCP;
43
0
    }
44
45
0
    if (str_starts_with(name, NETGNSS_UDP)) {
46
0
        return NET_UDP;
47
0
    }
48
49
0
    if (str_starts_with(name, NETGNSS_NMEA2000)) {
50
0
        return NET_NMEA2000;
51
0
    }
52
53
0
    return NET_LOCAL;
54
0
}
55
56
// is given string a valid URI for DGPS/NTRIP service?
57
// FIXME: replace with netgnss_uri_type()
58
bool netgnss_uri_check(const char *name)
59
0
{
60
0
    switch (netgnss_uri_type(name)) {
61
0
    case NET_DGPSIP:
62
0
        FALLTHROUGH
63
0
    case NET_NTRIP:
64
0
        return true;
65
66
0
    case NET_GPSD:
67
0
        FALLTHROUGH
68
0
    case NET_LOCAL:
69
0
        FALLTHROUGH
70
0
    case NET_NMEA2000:
71
0
        FALLTHROUGH
72
0
    case NET_TCP:
73
0
        FALLTHROUGH
74
0
    case NET_UDP:
75
0
        FALLTHROUGH
76
0
    case NET_UNKNOWN:
77
0
        FALLTHROUGH
78
0
    default:
79
0
        return false;
80
0
    }
81
0
}
82
83
84
// open a connection to a DGNSS service
85
gps_fd_t netgnss_uri_open(struct gps_device_t *dev, char *netgnss_service)
86
0
{
87
0
    GPSD_LOG(LOG_IO, &dev->context->errout,
88
0
             "DGNSS/NTRIP: netgnss_uri_open(%s)\n", netgnss_service);
89
90
0
    switch (netgnss_uri_type(netgnss_service)) {
91
0
    case NET_DGPSIP:
92
0
        return dgpsip_open(dev, netgnss_service + sizeof(NETGNSS_DGPSIP) - 1);
93
0
    case NET_NTRIP:
94
        // could be initial open, or reopen, or...
95
0
        return ntrip_open(dev, netgnss_service + sizeof(NETGNSS_NTRIP) - 1);
96
97
0
    case NET_GPSD:
98
0
        FALLTHROUGH
99
0
    case NET_LOCAL:
100
0
        FALLTHROUGH
101
0
    case NET_NMEA2000:
102
0
        FALLTHROUGH
103
0
    case NET_TCP:
104
0
        FALLTHROUGH
105
0
    case NET_UDP:
106
0
        FALLTHROUGH
107
0
    case NET_UNKNOWN:
108
0
        FALLTHROUGH
109
0
    default:
110
0
        GPSD_LOG(LOG_ERROR, &dev->context->errout,
111
0
                 "DGNSS/NTRIP: Unknown/unspecified protocol for service %s\n",
112
0
                 netgnss_service);
113
0
        return -1;
114
0
    }
115
0
}
116
117
// may be time to ship a usage report to the DGNSS service
118
void netgnss_report(struct gps_context_t *context,
119
                    struct gps_device_t *gps, struct gps_device_t *dgnss)
120
0
{
121
0
    if (SERVICE_DGPSIP == dgnss->servicetype) {
122
0
        dgpsip_report(context, gps, dgnss);
123
0
    } else if (SERVICE_NTRIP == dgnss->servicetype) {
124
0
        ntrip_report(context, gps, dgnss);
125
0
    }
126
0
}
127
128
// end
129
// vim: set expandtab shiftwidth=4