From 5f418146c429922700e2a660b2d2f390377911ee Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 12 Feb 2025 11:47:11 -0400 Subject: [PATCH] MT#55283 convert endpoint_parse_any_getaddrinfo_full to bool Change-Id: I74dbdcb6798203306652078997b74bdaacfb8526 --- daemon/main.c | 11 ++++++----- lib/socket.h | 22 ++++++---------------- recording-daemon/main.c | 2 +- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/daemon/main.c b/daemon/main.c index 88841a762..a6e4d3114 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -478,7 +478,7 @@ static int redis_ep_parse(endpoint_t *ep, int *db, char **hostname, char **auth, else *hostname = g_strdup(s); - if (endpoint_parse_any_getaddrinfo_full(ep, s)) + if (!endpoint_parse_any_getaddrinfo_full(ep, s)) return -1; return 0; } @@ -962,15 +962,16 @@ static void options(int *argc, char ***argv, charp_ht templates) { die("Missing option --listen-tcp, --listen-udp, --listen-ng, --listen-tcp-ng, " "--listen-http, or --listen-https"); - if (graphitep) {if (endpoint_parse_any_getaddrinfo_full(&rtpe_config.graphite_ep, graphitep)) - die("Invalid IP or port '%s' (--graphite)", graphitep); + if (graphitep) { + if (!endpoint_parse_any_getaddrinfo_full(&rtpe_config.graphite_ep, graphitep)) + die("Invalid IP or port '%s' (--graphite)", graphitep); } if (graphite_prefix_s) set_prefix(graphite_prefix_s); if (homerp) { - if (endpoint_parse_any_getaddrinfo_full(&rtpe_config.homer_ep, homerp)) + if (!endpoint_parse_any_getaddrinfo_full(&rtpe_config.homer_ep, homerp)) die("Invalid IP or port '%s' (--homer)", homerp); } if (homerproto) { @@ -1077,7 +1078,7 @@ static void options(int *argc, char ***argv, charp_ht templates) { rtpe_config.common.log_levels[log_level_index_srtp] = LOG_DEBUG; if (dtmf_udp_ep) { - if (endpoint_parse_any_getaddrinfo_full(&rtpe_config.dtmf_udp_ep, dtmf_udp_ep)) + if (!endpoint_parse_any_getaddrinfo_full(&rtpe_config.dtmf_udp_ep, dtmf_udp_ep)) die("Invalid IP or port '%s' (--dtmf-log-dest)", dtmf_udp_ep); } diff --git a/lib/socket.h b/lib/socket.h index 42320d4f5..19eb46847 100644 --- a/lib/socket.h +++ b/lib/socket.h @@ -315,25 +315,15 @@ INLINE bool endpoint_parse_port_any(endpoint_t *e, const char *p, unsigned int p e->port = port; return sockaddr_parse_any(&e->address, p); } -// address (ip) required -INLINE int endpoint_parse_any_full(endpoint_t *d, const char *s) { - int ret; - ret = endpoint_parse_any(d, s) ? 0 : -1; - if (ret) - return ret; - if (is_addr_unspecified(&d->address)) - return -1; - return 0; -} // address (ip or hostname) required -INLINE int endpoint_parse_any_getaddrinfo_full(endpoint_t *d, const char *s) { - int ret; - ret = endpoint_parse_any_getaddrinfo(d, s) ? 0 : 1; - if (ret) +INLINE bool endpoint_parse_any_getaddrinfo_full(endpoint_t *d, const char *s) { + bool ret; + ret = endpoint_parse_any_getaddrinfo(d, s); + if (!ret) return ret; if (is_addr_unspecified(&d->address)) - return -1; - return 0; + return false; + return true; } INLINE int sockaddr_getaddrinfo(sockaddr_t *a, const char *s) { return sockaddr_getaddrinfo_alt(a, NULL, s) ? 0 : 1; diff --git a/recording-daemon/main.c b/recording-daemon/main.c index da0865c02..c7db6e152 100644 --- a/recording-daemon/main.c +++ b/recording-daemon/main.c @@ -257,7 +257,7 @@ static void options(int *argc, char ***argv) { } if (tls_send_to) { - if (endpoint_parse_any_getaddrinfo_full(&tls_send_to_ep, tls_send_to)) + if (!endpoint_parse_any_getaddrinfo_full(&tls_send_to_ep, tls_send_to)) die("Failed to parse 'tcp-send-to' or 'tls-send-to' option"); }