summaryrefslogtreecommitdiff
path: root/shared/config-parser.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-06-28 14:58:32 +0200
committerDavid Härdeman <david@hardeman.nu>2020-06-28 14:58:32 +0200
commitd3352b997ca59a336a40fe6660c6e5b7079864aa (patch)
treef365d6c0304e512057223e9a3cf37357da44a443 /shared/config-parser.c
parent99b2c70137fef05a5a18f439b9010ddba455f5cb (diff)
Run clang-format on source tree (excl igmp.c)
Diffstat (limited to 'shared/config-parser.c')
-rw-r--r--shared/config-parser.c66
1 files changed, 34 insertions, 32 deletions
diff --git a/shared/config-parser.c b/shared/config-parser.c
index 386d5a2..13b26e1 100644
--- a/shared/config-parser.c
+++ b/shared/config-parser.c
@@ -13,8 +13,7 @@
#include "config-parser.h"
#include "config.h"
-static void
-eat_whitespace_and_comments(char **pos)
+static void eat_whitespace_and_comments(char **pos)
{
assert_return(pos && *pos);
@@ -30,8 +29,7 @@ eat_whitespace_and_comments(char **pos)
}
}
-static char *
-get_line(char **pos)
+static char *get_line(char **pos)
{
char *begin, *end;
@@ -63,9 +61,8 @@ get_line(char **pos)
return begin;
}
-static bool
-dnslookup(const char *name, uint16_t port, struct cfg_value *rvalue,
- unsigned *naddrs, bool async)
+static bool dnslookup(const char *name, uint16_t port, struct cfg_value *rvalue,
+ unsigned *naddrs, bool async)
{
struct sockaddr_in *in4;
struct sockaddr_in6 *in6;
@@ -77,7 +74,9 @@ dnslookup(const char *name, uint16_t port, struct cfg_value *rvalue,
bool rv = false;
int r;
- assert_return(!empty_str(name) && strlen(name) < sizeof(dns->name) && port > 0 && rvalue, false);
+ assert_return(!empty_str(name) && strlen(name) < sizeof(dns->name) &&
+ port > 0 && rvalue,
+ false);
if (async) {
rvalue->type = CFG_VAL_TYPE_ASYNC_ADDRS;
@@ -94,7 +93,7 @@ dnslookup(const char *name, uint16_t port, struct cfg_value *rvalue,
debug(DBG_DNS, "doing sync DNS lookup of %s", name);
}
- sprintf(dns->name, "%s", name);
+ sprintf(dns->name, "%s", name);
sprintf(dns->port, "%" PRIu16, port);
dns->req.ai_family = AF_UNSPEC;
@@ -114,7 +113,8 @@ dnslookup(const char *name, uint16_t port, struct cfg_value *rvalue,
r = getaddrinfo_a(mode, gcbs, ARRAY_SIZE(gcbs), &dns->sev);
if (r != 0) {
- error("getaddrinfo(%s:%" PRIu16 "): %s", name, port, gai_strerror(r));
+ error("getaddrinfo(%s:%" PRIu16 "): %s", name, port,
+ gai_strerror(r));
goto out;
}
@@ -136,7 +136,8 @@ dnslookup(const char *name, uint16_t port, struct cfg_value *rvalue,
switch (ai->ai_family) {
case AF_INET:
in4 = (struct sockaddr_in *)ai->ai_addr;
- saddr_set_ipv4(saddr, in4->sin_addr.s_addr, in4->sin_port);
+ saddr_set_ipv4(saddr, in4->sin_addr.s_addr,
+ in4->sin_port);
debug(DBG_CFG, "addrstr: %s", saddr->addrstr);
list_add(&saddr->list, &rvalue->saddrs);
(*naddrs)++;
@@ -165,8 +166,7 @@ out:
return rv;
}
-bool
-strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async)
+bool strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async)
{
struct saddr *saddr;
uint16_t port;
@@ -235,7 +235,8 @@ strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async)
} else if ((tmp = strchr(str, ':'))) {
/* IPv4, a.b.c.d:p or IPv4/6 hostname:p */
- debug(DBG_CFG, "attempting to parse IPv4 addr or hostname (%s)", str);
+ debug(DBG_CFG, "attempting to parse IPv4 addr or hostname (%s)",
+ str);
*tmp = '\0';
tmp++;
@@ -247,15 +248,18 @@ strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async)
goto error;
if (inet_pton(AF_INET, str, &saddr->in4.sin_addr) > 0) {
- debug(DBG_CFG, "got an IPv4:port (%s:%" PRIu16 ")", str, port);
- saddr_set_ipv4(saddr, saddr->in4.sin_addr.s_addr, htons(port));
+ debug(DBG_CFG, "got an IPv4:port (%s:%" PRIu16 ")", str,
+ port);
+ saddr_set_ipv4(saddr, saddr->in4.sin_addr.s_addr,
+ htons(port));
list_add(&saddr->list, list);
naddrs++;
goto success;
- }
+ }
xfree(saddr);
- debug(DBG_CFG, "maybe got a hostname:port (%s:%" PRIu16 ")", str, port);
+ debug(DBG_CFG, "maybe got a hostname:port (%s:%" PRIu16 ")",
+ str, port);
if (!dnslookup(str, port, rvalue, &naddrs, async))
goto error;
@@ -318,16 +322,16 @@ error:
}
/* Returns true if there's data left to parse in buf */
-bool
-config_parse_line(const char *filename, char **buf,
- struct cfg_key_value_map *kvmap, int *rkey,
- const char **rkeyname, struct cfg_value *rvalue,
- bool async_dns)
+bool config_parse_line(const char *filename, char **buf,
+ struct cfg_key_value_map *kvmap, int *rkey,
+ const char **rkeyname, struct cfg_value *rvalue,
+ bool async_dns)
{
char *line, *tmp, *key;
int i;
- assert_return(buf && *buf && kvmap && rkey && rkeyname && rvalue, false);
+ assert_return(buf && *buf && kvmap && rkey && rkeyname && rvalue,
+ false);
line = get_line(buf);
if (!line)
@@ -370,7 +374,6 @@ config_parse_line(const char *filename, char **buf,
continue;
switch (kvmap[i].value_type) {
-
case CFG_VAL_TYPE_STRING:
rvalue->type = CFG_VAL_TYPE_STRING;
rvalue->str = tmp;
@@ -425,7 +428,8 @@ config_parse_line(const char *filename, char **buf,
if (strcaseeq(tmp, "yes") || strcaseeq(tmp, "true")) {
rvalue->type = CFG_VAL_TYPE_BOOL;
rvalue->boolean = true;
- } else if (strcaseeq(tmp, "no") || strcaseeq(tmp, "false")) {
+ } else if (strcaseeq(tmp, "no") ||
+ strcaseeq(tmp, "false")) {
rvalue->type = CFG_VAL_TYPE_BOOL;
rvalue->boolean = false;
} else {
@@ -454,7 +458,8 @@ config_parse_line(const char *filename, char **buf,
}
error:
- /* FIXME: the line is already mangled here, a line number would be nice */
+ /* FIXME: the line is already mangled here, a line number would be nice
+ */
error("%s: invalid config line: %s", filename, line);
rvalue->type = CFG_VAL_TYPE_INVALID;
*rkey = 0;
@@ -462,8 +467,7 @@ error:
return true;
}
-bool
-config_parse_header(const char *title, char **buf)
+bool config_parse_header(const char *title, char **buf)
{
char *line;
@@ -481,8 +485,7 @@ config_parse_header(const char *title, char **buf)
return false;
}
-bool
-is_valid_server_config_filename(struct dirent *dent, const char *filename)
+bool is_valid_server_config_filename(struct dirent *dent, const char *filename)
{
const char *suffix;
@@ -512,4 +515,3 @@ is_valid_server_config_filename(struct dirent *dent, const char *filename)
return true;
}
-