]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Replace host:port parsers with net_str2hostport().
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 29 Jan 2016 15:42:51 +0000 (17:42 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 29 Jan 2016 15:42:51 +0000 (17:42 +0200)
src/director/director-host.c
src/doveadm/doveadm-util.c
src/lib-lda/smtp-client.c
src/lib/iostream-rawlog.c

index bb868279b2dfa37a0802ddd706996acb04efc3fb..f8fb2cbebbc8e8f665ce42fbcc86bfcf5f7ca89f 100644 (file)
@@ -152,16 +152,9 @@ static void director_host_add_string(struct director *dir, const char *host)
        struct ip_addr *ips;
        in_port_t port;
        unsigned int i, ips_count;
-       const char *p;
-
-       p = strrchr(host, ':');
-       if (p != NULL) {
-               if (net_str2port(p + 1, &port) < 0)
-                       i_fatal("Invalid director port in %s", host);
-               host = t_strdup_until(host, p);
-       } else {
-               port = dir->self_port;
-       }
+
+       if (net_str2hostport(host, dir->self_port, &host, &port) < 0)
+               i_fatal("Invalid director host:port in '%s'", host);
 
        if (net_gethostbyname(host, &ips, &ips_count) < 0)
                i_fatal("Unknown director host: %s", host);
index e62e3a0efbf54affdab5f4558a40f81b8906477d..d32309022ea741743d3e154024f6773efdefbaae 100644 (file)
@@ -96,25 +96,6 @@ const char *doveadm_plugin_getenv(const char *name)
        return NULL;
 }
 
-static bool
-parse_hostport(const char *str, in_port_t default_port,
-              const char **host_r, in_port_t *port_r)
-{
-       const char *p;
-
-       /* host:port */
-       p = strrchr(str, ':');
-       if (p == NULL && default_port != 0) {
-               *host_r = str;
-               *port_r = default_port;
-       } else {
-               if (p == NULL || net_str2port(p+1, port_r) < 0)
-                       return FALSE;
-               *host_r = t_strdup_until(str, p);
-       }
-       return TRUE;
-}
-
 static int
 doveadm_tcp_connect_port(const char *host, in_port_t port)
 {
@@ -140,7 +121,7 @@ int doveadm_tcp_connect(const char *target, in_port_t default_port)
        const char *host;
        in_port_t port;
 
-       if (!parse_hostport(target, default_port, &host, &port)) {
+       if (net_str2hostport(target, default_port, &host, &port) < 0) {
                i_fatal("Port not known for %s. Either set proxy_port "
                        "or use %s:port", target, target);
        }
index e7149d2f0dbeb31bf3342822811f4dccefd06305..9033e8fe7948215fd7e299552a7bdc95847dbdfa 100644 (file)
@@ -255,17 +255,13 @@ smtp_client_send_flush(struct smtp_client *smtp_client,
        struct ioloop *ioloop;
        struct istream *input;
        const char *host, *p, *const *destp;
-       in_port_t port = DEFAULT_SUBMISSION_PORT;
-
-       host = smtp_client->set->submission_host;
-       p = strchr(host, ':');
-       if (p != NULL) {
-               host = t_strdup_until(host, p);
-               if (net_str2port(p + 1, &port) < 0) {
-                       *error_r = t_strdup_printf(
-                               "Invalid port in submission_host: %s", p+1);
-                       return -1;
-               }
+       in_port_t port;
+
+       if (net_str2hostport(smtp_client->set->submission_host,
+                            DEFAULT_SUBMISSION_PORT, &host, &port) < 0) {
+               *error_r = t_strdup_printf(
+                       "Invalid submission_host: %s", host);
+               return -1;
        }
 
        if (o_stream_nfinish(smtp_client->output) < 0) {
index 71d07d78988482814a4c046eeaa5009d0e4ce300..eeaceb0d9da234a4ea0b686b9cbc4443f37c4a64 100644 (file)
@@ -165,7 +165,7 @@ static int
 iostream_rawlog_try_create_tcp(const char *path,
                               struct istream **input, struct ostream **output)
 {
-       const char *p, *host;
+       const char *host;
        struct ip_addr *ips;
        unsigned int ips_count;
        in_port_t port;
@@ -178,11 +178,8 @@ iostream_rawlog_try_create_tcp(const char *path,
 
        if (strchr(path, '/') != NULL)
                return 0;
-       if ((p = strchr(path, ':')) == NULL)
+       if (net_str2hostport(path, 0, &host, &port) < 0 || port == 0)
                return 0;
-       if (net_str2port(p+1, &port) < 0)
-               return 0;
-       host = t_strdup_until(path, p);
 
        ret = net_gethostbyname(host, &ips, &ips_count);
        if (ret != 0) {