diff --git a/src/accept.c b/src/accept.c index 557d80d..16c8027 100644 --- a/src/accept.c +++ b/src/accept.c @@ -449,6 +449,15 @@ static void peerip_clients_config(void) inbound_connects_account(3, c->udpclient->portaccount); /* "3" = udp, not listening.. */ + /* set up peer serverid to username */ +#ifndef FIXED_IOBUFS + c->username = hstrdup(pe->serverid); +#else + strncpy(c->username, pe->serverid, sizeof(c->username)); + c->username[sizeof(c->username)-1] = 0; +#endif + c->username_len = strlen(c->username); + /* convert client address to string */ s = strsockaddr( &c->udpaddr.sa, c->udpaddrlen ); diff --git a/src/cfgfile.c b/src/cfgfile.c index 78d2910..1a15c5f 100644 --- a/src/cfgfile.c +++ b/src/cfgfile.c @@ -252,6 +252,40 @@ int cmdparse(struct cfgcmd *cmds, char *cmdline) /* ***************************************************************** */ + +char *fgets_multiline(char *buf, int buflen, FILE *fp) +{ + char *p = buf; + int left = buflen; + char *s; + int len; + + while (1) { + s = fgets(p, left, fp); + if (!s) + return NULL; + + len = strlen(s); + + /* trim newlines and whitespace */ + while (len > 1 && (s[len-1] == '\r' || s[len-1] == '\n' || s[len-1] == ' ' || s[len-1] == '\t')) + len--; + + /* nul-terminate */ + s[len] = 0; + + /* If the string does not end with a '\', return it */ + if (s[len-1] != '\\') + return buf; + + /* ahh, line continues... remove the \ and read next line. */ + len--; + s[len] = 0; + p = s + len; + left = buflen - len; + } +} + /* * Read configuration */ @@ -267,8 +301,9 @@ int read_cfgfile(char *f, struct cfgcmd *cmds) return 1; } - while (fgets(line, CFGLINE_LEN, fp) != NULL) { + while (fgets_multiline(line, CFGLINE_LEN, fp) != NULL) { n++; + ret = cmdparse(cmds, line); if (ret < 0) { hlog(LOG_ERR, "Problem in %s at line %d: %s", f, n, line); diff --git a/src/config.c b/src/config.c index fdffe6d..3323c05 100644 --- a/src/config.c +++ b/src/config.c @@ -274,6 +274,7 @@ void free_peerip_config(struct peerip_config_t **lc) *lc = this->next; hfree((void*)this->name); hfree((void*)this->host); + hfree((void*)this->serverid); freeaddrinfo(this->ai); hfree(this); } @@ -454,6 +455,7 @@ int do_peergroup(struct peerip_config_t **lq, int argc, char **argv) struct peerip_config_t *pe; struct listen_config_t *li; struct addrinfo req, *my_ai, *ai, *a; + char *peerid = NULL; char *fullhost, *host_s, *port_s; int af; @@ -540,6 +542,14 @@ int do_peergroup(struct peerip_config_t **lq, int argc, char **argv) for (i = 4; i < argc; i++) { //hlog(LOG_DEBUG, "PeerGroup: configuring peer %s", argv[i]); + peerid = hstrdup(argv[i]); + i++; + + if (i >= argc) { + hlog(LOG_ERR, "PeerGroup: No host:port specified for peer ServerID '%s'", peerid); + goto err; + } + /* Parse address */ fullhost = hstrdup(argv[i]); if (parse_hostport(argv[i], &host_s, &port_s)) { @@ -597,6 +607,8 @@ int do_peergroup(struct peerip_config_t **lq, int argc, char **argv) memset(pe, 0, sizeof(*pe)); pe->name = hstrdup(host_s); pe->host = hstrdup(host_s); + pe->serverid = peerid; + peerid = NULL; pe->af = af; pe->local_port = localport; pe->remote_port = port; @@ -614,7 +626,9 @@ int do_peergroup(struct peerip_config_t **lq, int argc, char **argv) err: if (fullhost) hfree(fullhost); - + if (peerid) + hfree(peerid); + return -2; } diff --git a/src/config.h b/src/config.h index aa6d755..c8e5e41 100644 --- a/src/config.h +++ b/src/config.h @@ -123,11 +123,13 @@ struct peerip_config_t { const char *name; /* name of socket */ const char *host; /* hostname or dotted-quad IP to bind the UDP socket to, default INADDR_ANY */ + const char *serverid; /* expected/configured serverid of remote */ + struct addrinfo *ai; + int af; int remote_port; int local_port; - struct addrinfo *ai; int client_flags; }; diff --git a/tests/cfg-aprsc/basic b/tests/cfg-aprsc/basic index 8b1edb4..7d1f9b4 100644 --- a/tests/cfg-aprsc/basic +++ b/tests/cfg-aprsc/basic @@ -52,8 +52,12 @@ Listen "UDP submit port" udpsubmit udp ::0 55080 Uplink full1 full tcp 127.0.0.1 10153 # UDP peering, first address is my local address, the rest are remote. -PeerGroup TEST udp 127.0.0.1:16404 127.0.0.1:16405 127.0.0.1:16406 -PeerGroup TEST6 udp [::1]:16504 [::1]:16505 [::1]:16506 +PeerGroup TEST udp 127.0.0.1:16404 \ + PEER1 127.0.0.1:16405 \ + PEER2 127.0.0.1:16406 +PeerGroup TEST6 udp [::1]:16504 \ + PEER61 [::1]:16505 \ + PEER62 [::1]:16506 ### HTTP listener ########## # Status port provides a status view to web browsers.