diff src/imap/ngx_imap_core_module.c @ 804:472cd9768ac2

now the "listen" directives use ngx_parse_url()
author Igor Sysoev <igor@sysoev.ru>
date Tue, 24 Oct 2006 13:06:55 +0000
parents 887d8dec72dc
children da9c1521319d
line wrap: on
line diff
--- a/src/imap/ngx_imap_core_module.c
+++ b/src/imap/ngx_imap_core_module.c
@@ -471,56 +471,27 @@ ngx_imap_core_server(ngx_conf_t *cf, ngx
 static char *
 ngx_imap_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 {
-    char                       *err;
     ngx_str_t                  *value;
-    in_addr_t                   in_addr;
+    ngx_url_t                   u;
     ngx_uint_t                  i;
-    struct hostent             *h;
     ngx_imap_listen_t          *imls;
-    ngx_inet_upstream_t         inet_upstream;
     ngx_imap_core_main_conf_t  *cmcf;
 
     value = cf->args->elts;
 
-    ngx_memzero(&inet_upstream, sizeof(ngx_inet_upstream_t));
-
-    inet_upstream.url = value[1];
-    inet_upstream.port_only = 1;
-
-    err = ngx_inet_parse_host_port(&inet_upstream);
+    ngx_memzero(&u, sizeof(ngx_url_t));
 
-    if (err) {
-        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
-                           "%s in \"%V\" of the \"listen\" directive",
-                           err, &inet_upstream.url);
-        return NGX_CONF_ERROR;
-    }
-
-    if (inet_upstream.host.len == 1 && inet_upstream.host.data[0] == '*') {
-        inet_upstream.host.len = 0;
-    }
+    u.url = value[1];
+    u.listen = 1;
 
-    if (inet_upstream.host.len) {
-        inet_upstream.host.data[inet_upstream.host.len] = '\0';
-
-        in_addr = inet_addr((const char *) inet_upstream.host.data);
-
-        if (in_addr == INADDR_NONE) {
-            h = gethostbyname((const char *) inet_upstream.host.data);
-
-            if (h == NULL || h->h_addr_list[0] == NULL) {
-                ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
-                                   "can not resolve host \"%s\" "
-                                   "in the \"listen\" directive",
-                                   inet_upstream.host.data);
-                return NGX_CONF_ERROR;
-            }
-
-            in_addr = *(in_addr_t *)(h->h_addr_list[0]);
+    if (ngx_parse_url(cf, &u) != NGX_OK) {
+        if (u.err) {
+            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                               "%s in \"%V\" of the \"listen\" directive",
+                               u.err, &u.url);
         }
 
-    } else {
-        in_addr = INADDR_ANY;
+        return NGX_CONF_ERROR;
     }
 
     cmcf = ngx_imap_conf_get_module_main_conf(cf, ngx_imap_core_module);
@@ -529,13 +500,12 @@ ngx_imap_core_listen(ngx_conf_t *cf, ngx
 
     for (i = 0; i < cmcf->listen.nelts; i++) {
 
-        if (imls[i].addr != in_addr || imls[i].port != inet_upstream.port) {
+        if (imls[i].addr != u.addr.in_addr || imls[i].port != u.portn) {
             continue;
         }
 
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
-                           "duplicate \"%V\" address and port pair",
-                           &inet_upstream.url);
+                           "duplicate \"%V\" address and port pair", &u.url);
         return NGX_CONF_ERROR;
     }
 
@@ -546,8 +516,8 @@ ngx_imap_core_listen(ngx_conf_t *cf, ngx
 
     ngx_memzero(imls, sizeof(ngx_imap_listen_t));
 
-    imls->addr = in_addr;
-    imls->port = inet_upstream.port;
+    imls->addr = u.addr.in_addr;
+    imls->port = u.portn;
     imls->family = AF_INET;
     imls->ctx = cf->ctx;