Mercurial > hg > nginx-quic
annotate src/core/ngx_inet.c @ 2764:d4a717592877
use ngx_vslprintf(), ngx_slprintf()
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 27 Apr 2009 13:06:20 +0000 |
parents | a472d954c534 |
children | 219aa0b0fd58 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
425
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
425
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
425
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
425
diff
changeset
|
5 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
425
diff
changeset
|
6 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
57
diff
changeset
|
8 #include <ngx_core.h> |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
11 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
12 static size_t ngx_inet6_ntop(u_char *p, u_char *text, size_t len); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
13 #endif |
2200 | 14 static ngx_int_t ngx_parse_unix_domain_url(ngx_pool_t *pool, ngx_url_t *u); |
15 static ngx_int_t ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u); | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
16 static ngx_int_t ngx_parse_inet6_url(ngx_pool_t *pool, ngx_url_t *u); |
2200 | 17 |
1647 | 18 |
19 in_addr_t | |
20 ngx_inet_addr(u_char *text, size_t len) | |
21 { | |
22 u_char *p, c; | |
23 in_addr_t addr; | |
24 ngx_uint_t octet, n; | |
25 | |
26 addr = 0; | |
27 octet = 0; | |
28 n = 0; | |
29 | |
30 for (p = text; p < text + len; p++) { | |
31 | |
32 c = *p; | |
33 | |
34 if (c >= '0' && c <= '9') { | |
35 octet = octet * 10 + (c - '0'); | |
36 continue; | |
37 } | |
38 | |
39 if (c == '.' && octet < 256) { | |
40 addr = (addr << 8) + octet; | |
41 octet = 0; | |
42 n++; | |
43 continue; | |
44 } | |
45 | |
46 return INADDR_NONE; | |
47 } | |
48 | |
49 if (n != 3) { | |
50 return INADDR_NONE; | |
51 } | |
52 | |
53 if (octet < 256) { | |
54 addr = (addr << 8) + octet; | |
55 return htonl(addr); | |
56 } | |
57 | |
58 return INADDR_NONE; | |
59 } | |
60 | |
61 | |
509 | 62 size_t |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
63 ngx_sock_ntop(struct sockaddr *sa, u_char *text, size_t len, ngx_uint_t port) |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
64 { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
65 u_char *p; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
66 struct sockaddr_in *sin; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
67 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
68 size_t n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
69 struct sockaddr_in6 *sin6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
70 #endif |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
71 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
72 switch (sa->sa_family) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
73 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
74 case AF_INET: |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
75 |
2197
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
76 sin = (struct sockaddr_in *) sa; |
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
77 p = (u_char *) &sin->sin_addr; |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
78 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
79 if (port) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
80 p = ngx_snprintf(text, len, "%ud.%ud.%ud.%ud:%d", |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
81 p[0], p[1], p[2], p[3], ntohs(sin->sin_port)); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
82 } else { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
83 p = ngx_snprintf(text, len, "%ud.%ud.%ud.%ud", |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
84 p[0], p[1], p[2], p[3]); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
85 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
86 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
87 return (p - text); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
88 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
89 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
90 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
91 case AF_INET6: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
92 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
93 sin6 = (struct sockaddr_in6 *) sa; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
94 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
95 n = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
96 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
97 if (port) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
98 text[n++] = '['; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
99 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
100 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
101 n = ngx_inet6_ntop((u_char *) &sin6->sin6_addr, &text[n], len); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
102 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
103 if (port) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
104 n = ngx_sprintf(&text[1 + n], "]:%d", |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
105 ntohs(sin6->sin6_port)) - text; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
106 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
107 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
108 return n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
109 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
110 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
111 default: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
112 return 0; |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
113 } |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
114 } |
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
115 |
1830 | 116 |
509 | 117 size_t |
118 ngx_inet_ntop(int family, void *addr, u_char *text, size_t len) | |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
119 { |
2197
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
120 u_char *p; |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
121 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
122 switch (family) { |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
123 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
124 case AF_INET: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
125 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
126 p = addr; |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
127 |
2197
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
128 return ngx_snprintf(text, len, "%ud.%ud.%ud.%ud", |
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
129 p[0], p[1], p[2], p[3]) |
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
130 - text; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
131 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
132 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
133 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
134 case AF_INET6: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
135 return ngx_inet6_ntop(addr, text, len); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
136 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
137 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
138 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
139 default: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
140 return 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
141 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
142 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
143 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
144 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
145 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
146 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
147 static size_t |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
148 ngx_inet6_ntop(u_char *p, u_char *text, size_t len) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
149 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
150 u_char *dst; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
151 size_t max, n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
152 ngx_uint_t i, zero, last; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
153 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
154 if (len < NGX_INET6_ADDRSTRLEN) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
155 return 0; |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
156 } |
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
157 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
158 zero = (ngx_uint_t) -1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
159 last = (ngx_uint_t) -1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
160 max = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
161 n = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
162 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
163 for (i = 0; i < 16; i += 2) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
164 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
165 if (p[i] || p[i + 1]) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
166 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
167 if (max < n) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
168 zero = last; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
169 max = n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
170 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
171 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
172 n = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
173 continue; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
174 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
175 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
176 if (n++ == 0) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
177 last = i; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
178 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
179 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
180 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
181 if (max < n) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
182 zero = last; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
183 max = n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
184 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
185 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
186 dst = text; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
187 n = 16; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
188 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
189 if (zero == 0) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
190 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
191 if ((max == 5 && p[10] == 0xff && p[11] == 0xff) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
192 || (max == 6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
193 || (max == 7 && p[14] != 0 && p[15] != 1)) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
194 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
195 n = 12; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
196 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
197 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
198 *dst++ = ':'; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
199 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
200 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
201 for (i = 0; i < n; i += 2) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
202 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
203 if (i == zero) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
204 *dst++ = ':'; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
205 i += (max - 1) * 2; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
206 continue; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
207 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
208 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
209 dst = ngx_sprintf(dst, "%uxi", p[i] * 256 + p[i + 1]); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
210 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
211 if (i < 14) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
212 *dst++ = ':'; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
213 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
214 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
215 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
216 if (n == 12) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
217 dst = ngx_sprintf(dst, "%ud.%ud.%ud.%ud", p[12], p[13], p[14], p[15]); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
218 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
219 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
220 return dst - text; |
1830 | 221 } |
222 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
223 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
224 |
1830 | 225 |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
226 /* AF_INET only */ |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
227 |
509 | 228 ngx_int_t |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
229 ngx_ptocidr(ngx_str_t *text, ngx_cidr_t *cidr) |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
230 { |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
231 u_char *addr, *mask, *last; |
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
232 ngx_int_t shift; |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
233 |
2202 | 234 addr = text->data; |
235 last = addr + text->len; | |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
236 |
2202 | 237 mask = ngx_strlchr(addr, last, '/'); |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
238 |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
239 cidr->u.in.addr = ngx_inet_addr(addr, (mask ? mask : last) - addr); |
2202 | 240 |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
241 if (cidr->u.in.addr == INADDR_NONE) { |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
242 return NGX_ERROR; |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
243 } |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
244 |
2202 | 245 if (mask == NULL) { |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
246 cidr->family = AF_INET; |
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
247 cidr->u.in.mask = 0xffffffff; |
2202 | 248 return NGX_OK; |
249 } | |
250 | |
251 mask++; | |
252 | |
253 shift = ngx_atoi(mask, last - mask); | |
254 if (shift == NGX_ERROR) { | |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
255 return NGX_ERROR; |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
256 } |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
257 |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
258 cidr->family = AF_INET; |
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
259 |
2202 | 260 if (shift == 0) { |
368
15c84a40e87d
nginx-0.0.7-2004-06-24-20:07:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
340
diff
changeset
|
261 |
15c84a40e87d
nginx-0.0.7-2004-06-24-20:07:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
340
diff
changeset
|
262 /* the x86 compilers use the shl instruction that shifts by modulo 32 */ |
15c84a40e87d
nginx-0.0.7-2004-06-24-20:07:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
340
diff
changeset
|
263 |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
264 cidr->u.in.mask = 0; |
2202 | 265 |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
266 if (cidr->u.in.addr == 0) { |
2202 | 267 return NGX_OK; |
268 } | |
269 | |
270 return NGX_DONE; | |
368
15c84a40e87d
nginx-0.0.7-2004-06-24-20:07:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
340
diff
changeset
|
271 } |
15c84a40e87d
nginx-0.0.7-2004-06-24-20:07:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
340
diff
changeset
|
272 |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
273 cidr->u.in.mask = htonl((ngx_uint_t) (0 - (1 << (32 - shift)))); |
368
15c84a40e87d
nginx-0.0.7-2004-06-24-20:07:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
340
diff
changeset
|
274 |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
275 if (cidr->u.in.addr == (cidr->u.in.addr & cidr->u.in.mask)) { |
1380
b590a528fd41
ignore meaningless bits in CIDR and warn about them
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
276 return NGX_OK; |
b590a528fd41
ignore meaningless bits in CIDR and warn about them
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
277 } |
b590a528fd41
ignore meaningless bits in CIDR and warn about them
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
278 |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
279 cidr->u.in.addr &= cidr->u.in.mask; |
1380
b590a528fd41
ignore meaningless bits in CIDR and warn about them
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
280 |
b590a528fd41
ignore meaningless bits in CIDR and warn about them
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
281 return NGX_DONE; |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
282 } |
425
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
283 |
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
284 |
651 | 285 ngx_int_t |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
286 ngx_parse_url(ngx_pool_t *pool, ngx_url_t *u) |
651 | 287 { |
2200 | 288 u_char *p; |
651 | 289 |
290 p = u->url.data; | |
291 | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
906
diff
changeset
|
292 if (ngx_strncasecmp(p, (u_char *) "unix:", 5) == 0) { |
2200 | 293 return ngx_parse_unix_domain_url(pool, u); |
651 | 294 } |
295 | |
296 if ((p[0] == ':' || p[0] == '/') && !u->listen) { | |
297 u->err = "invalid host"; | |
298 return NGX_ERROR; | |
299 } | |
300 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
301 if (p[0] == '[') { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
302 return ngx_parse_inet6_url(pool, u); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
303 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
304 |
2200 | 305 return ngx_parse_inet_url(pool, u); |
306 } | |
307 | |
308 | |
309 static ngx_int_t | |
310 ngx_parse_unix_domain_url(ngx_pool_t *pool, ngx_url_t *u) | |
311 { | |
312 #if (NGX_HAVE_UNIX_DOMAIN) | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
313 u_char *path, *uri, *last; |
2200 | 314 size_t len; |
315 struct sockaddr_un *saun; | |
316 | |
317 len = u->url.len; | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
318 path = u->url.data; |
2200 | 319 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
320 path += 5; |
2200 | 321 len -= 5; |
322 | |
323 if (u->uri_part) { | |
324 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
325 last = path + len; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
326 uri = ngx_strlchr(path, last, ':'); |
2200 | 327 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
328 if (uri) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
329 len = uri - path; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
330 uri++; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
331 u->uri.len = last - uri; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
332 u->uri.data = uri; |
2200 | 333 } |
334 } | |
335 | |
336 if (len == 0) { | |
337 u->err = "no path in the unix domain socket"; | |
338 return NGX_ERROR; | |
339 } | |
340 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
341 u->host.len = len++; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
342 u->host.data = path; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
343 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
344 if (len > sizeof(saun->sun_path)) { |
2200 | 345 u->err = "too long path in the unix domain socket"; |
346 return NGX_ERROR; | |
347 } | |
348 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
349 u->socklen = sizeof(struct sockaddr_un); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
350 saun = (struct sockaddr_un *) &u->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
351 saun->sun_family = AF_UNIX; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
352 (void) ngx_cpystrn((u_char *) saun->sun_path, path, len); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
353 |
2200 | 354 u->addrs = ngx_pcalloc(pool, sizeof(ngx_peer_addr_t)); |
355 if (u->addrs == NULL) { | |
356 return NGX_ERROR; | |
357 } | |
358 | |
359 saun = ngx_pcalloc(pool, sizeof(struct sockaddr_un)); | |
360 if (saun == NULL) { | |
361 return NGX_ERROR; | |
362 } | |
363 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
364 u->family = AF_UNIX; |
2200 | 365 u->naddrs = 1; |
366 | |
367 saun->sun_family = AF_UNIX; | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
368 (void) ngx_cpystrn((u_char *) saun->sun_path, path, len); |
2200 | 369 |
370 u->addrs[0].sockaddr = (struct sockaddr *) saun; | |
371 u->addrs[0].socklen = sizeof(struct sockaddr_un); | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
372 u->addrs[0].name.len = len + 4; |
2200 | 373 u->addrs[0].name.data = u->url.data; |
374 | |
375 return NGX_OK; | |
376 | |
377 #else | |
378 | |
379 u->err = "the unix domain sockets are not supported on this platform"; | |
380 | |
381 return NGX_ERROR; | |
382 | |
383 #endif | |
384 } | |
385 | |
386 | |
387 static ngx_int_t | |
388 ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u) | |
389 { | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
390 u_char *p, *host, *port, *last, *uri, *args; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
391 size_t len; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
392 ngx_int_t n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
393 struct hostent *h; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
394 struct sockaddr_in *sin; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
395 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
396 u->socklen = sizeof(struct sockaddr_in); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
397 sin = (struct sockaddr_in *) &u->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
398 sin->sin_family = AF_INET; |
2200 | 399 |
2206 | 400 u->family = AF_INET; |
401 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
402 host = u->url.data; |
2200 | 403 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
404 last = host + u->url.len; |
906 | 405 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
406 port = ngx_strlchr(host, last, ':'); |
651 | 407 |
2283
231b52f8adc0
fix case when URL has no port, but has ":" in URI part,
Igor Sysoev <igor@sysoev.ru>
parents:
2206
diff
changeset
|
408 uri = ngx_strlchr(host, last, '/'); |
651 | 409 |
2284
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
410 args = ngx_strlchr(host, last, '?'); |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
411 |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
412 if (args) { |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
413 if (uri == NULL) { |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
414 uri = args; |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
415 |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
416 } else if (args < uri) { |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
417 uri = args; |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
418 } |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
419 } |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
420 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
421 if (uri) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
422 if (u->listen || !u->uri_part) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
423 u->err = "invalid host"; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
424 return NGX_ERROR; |
651 | 425 } |
426 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
427 u->uri.len = last - uri; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
428 u->uri.data = uri; |
651 | 429 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
430 last = uri; |
2283
231b52f8adc0
fix case when URL has no port, but has ":" in URI part,
Igor Sysoev <igor@sysoev.ru>
parents:
2206
diff
changeset
|
431 |
231b52f8adc0
fix case when URL has no port, but has ":" in URI part,
Igor Sysoev <igor@sysoev.ru>
parents:
2206
diff
changeset
|
432 if (uri < port) { |
231b52f8adc0
fix case when URL has no port, but has ":" in URI part,
Igor Sysoev <igor@sysoev.ru>
parents:
2206
diff
changeset
|
433 port = NULL; |
2301
148c2e840c2b
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
2284
diff
changeset
|
434 } |
651 | 435 } |
436 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
437 if (port) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
438 port++; |
651 | 439 |
2206 | 440 len = last - port; |
441 | |
442 if (len == 0) { | |
651 | 443 u->err = "invalid port"; |
444 return NGX_ERROR; | |
445 } | |
446 | |
2206 | 447 n = ngx_atoi(port, len); |
448 | |
449 if (n < 1 || n > 65536) { | |
450 u->err = "invalid port"; | |
451 return NGX_ERROR; | |
452 } | |
453 | |
454 u->port = (in_port_t) n; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
455 sin->sin_port = htons((in_port_t) n); |
2206 | 456 |
457 u->port_text.len = len; | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
458 u->port_text.data = port; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
459 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
460 last = port - 1; |
1671
8075179cae21
ngx_parse_url() saves port text, this allows to use it in proxy host header
Igor Sysoev <igor@sysoev.ru>
parents:
1647
diff
changeset
|
461 |
651 | 462 } else { |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
463 if (uri == NULL) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
464 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
465 if (u->listen) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
466 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
467 /* test value as port only */ |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
468 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
469 n = ngx_atoi(host, last - host); |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
470 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
471 if (n != NGX_ERROR) { |
651 | 472 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
473 if (n < 1 || n > 65536) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
474 u->err = "invalid port"; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
475 return NGX_ERROR; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
476 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
477 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
478 u->port = (in_port_t) n; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
479 sin->sin_port = htons((in_port_t) n); |
651 | 480 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
481 u->port_text.len = last - host; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
482 u->port_text.data = host; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
483 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
484 u->wildcard = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
485 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
486 return NGX_OK; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
487 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
488 } |
651 | 489 } |
490 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
491 u->no_port = 1; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
492 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
493 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
494 len = last - host; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
495 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
496 if (len == 0) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
497 u->err = "no host"; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
498 return NGX_ERROR; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
499 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
500 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
501 if (len == 1 && *host == '*') { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
502 len = 0; |
651 | 503 } |
504 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
505 u->host.len = len; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
506 u->host.data = host; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
507 |
2206 | 508 if (u->no_resolve) { |
509 return NGX_OK; | |
510 } | |
511 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
512 if (len++) { |
651 | 513 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
514 p = ngx_alloc(len, pool->log); |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
515 if (p == NULL) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
516 return NGX_ERROR; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
517 } |
651 | 518 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
519 (void) ngx_cpystrn(p, host, len); |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
520 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
521 u->addr.in_addr = inet_addr((const char *) p); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
522 sin->sin_addr.s_addr = inet_addr((const char *) p); |
884 | 523 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
524 if (sin->sin_addr.s_addr == INADDR_NONE) { |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
525 h = gethostbyname((const char *) p); |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
526 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
527 if (h == NULL || h->h_addr_list[0] == NULL) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
528 ngx_free(p); |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
529 u->err = "host not found"; |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
712
diff
changeset
|
530 return NGX_ERROR; |
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
712
diff
changeset
|
531 } |
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
712
diff
changeset
|
532 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
533 u->addr.in_addr = *(in_addr_t *) (h->h_addr_list[0]); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
534 sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[0]); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
535 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
536 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
537 if (sin->sin_addr.s_addr == INADDR_ANY) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
538 u->wildcard = 1; |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
712
diff
changeset
|
539 } |
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
712
diff
changeset
|
540 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
541 ngx_free(p); |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
712
diff
changeset
|
542 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
543 } else { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
544 u->addr.in_addr = INADDR_ANY; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
545 sin->sin_addr.s_addr = INADDR_ANY; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
546 u->wildcard = 1; |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
547 } |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
712
diff
changeset
|
548 |
906 | 549 if (u->no_port) { |
550 u->port = u->default_port; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
551 sin->sin_port = htons(u->default_port); |
906 | 552 } |
553 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
554 if (u->listen) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
555 return NGX_OK; |
906 | 556 } |
557 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
558 if (ngx_inet_resolve_host(pool, u) != NGX_OK) { |
651 | 559 return NGX_ERROR; |
560 } | |
561 | |
562 return NGX_OK; | |
563 } | |
564 | |
565 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
566 static ngx_int_t |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
567 ngx_parse_inet6_url(ngx_pool_t *pool, ngx_url_t *u) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
568 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
569 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
570 int rc; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
571 u_char *p, *host, *port, *last, *uri; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
572 size_t len; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
573 ngx_int_t n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
574 struct sockaddr_in6 *sin6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
575 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
576 u->socklen = sizeof(struct sockaddr_in6); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
577 sin6 = (struct sockaddr_in6 *) &u->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
578 sin6->sin6_family = AF_INET6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
579 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
580 host = u->url.data + 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
581 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
582 last = u->url.data + u->url.len; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
583 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
584 p = ngx_strlchr(host, last, ']'); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
585 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
586 if (p == NULL) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
587 u->err = "invalid host"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
588 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
589 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
590 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
591 if (last - p) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
592 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
593 port = p + 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
594 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
595 uri = ngx_strlchr(port, last, '/'); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
596 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
597 if (uri) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
598 if (u->listen || !u->uri_part) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
599 u->err = "invalid host"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
600 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
601 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
602 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
603 u->uri.len = last - uri; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
604 u->uri.data = uri; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
605 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
606 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
607 if (*port == ':') { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
608 port++; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
609 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
610 len = last - port; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
611 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
612 if (len == 0) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
613 u->err = "invalid port"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
614 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
615 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
616 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
617 n = ngx_atoi(port, len); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
618 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
619 if (n < 1 || n > 65536) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
620 u->err = "invalid port"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
621 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
622 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
623 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
624 u->port = (in_port_t) n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
625 sin6->sin6_port = htons((in_port_t) n); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
626 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
627 u->port_text.len = len; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
628 u->port_text.data = port; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
629 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
630 } else { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
631 u->no_port = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
632 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
633 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
634 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
635 len = p - host; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
636 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
637 if (len == 0) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
638 u->err = "no host"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
639 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
640 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
641 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
642 u->host.len = len++; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
643 u->host.data = host; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
644 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
645 p = ngx_alloc(len, pool->log); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
646 if (p == NULL) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
647 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
648 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
649 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
650 (void) ngx_cpystrn(p, host, len); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
651 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
652 rc = inet_pton(AF_INET6, (const char *) p, &sin6->sin6_addr); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
653 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
654 ngx_free(p); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
655 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
656 if (rc == 0) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
657 u->err = "invalid IPv6 address"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
658 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
659 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
660 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
661 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
662 u->wildcard = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
663 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
664 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
665 u->family = AF_INET6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
666 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
667 if (u->no_resolve) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
668 return NGX_OK; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
669 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
670 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
671 if (u->no_port) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
672 u->port = u->default_port; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
673 sin6->sin6_port = htons(u->default_port); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
674 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
675 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
676 return NGX_OK; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
677 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
678 #else |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
679 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
680 u->err = "the INET6 sockets are not supported on this platform"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
681 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
682 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
683 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
684 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
685 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
686 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
687 |
884 | 688 ngx_int_t |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
689 ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u) |
651 | 690 { |
906 | 691 u_char *p, *host; |
651 | 692 size_t len; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
693 in_port_t port; |
651 | 694 in_addr_t in_addr; |
695 ngx_uint_t i; | |
696 struct hostent *h; | |
697 struct sockaddr_in *sin; | |
698 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
699 host = ngx_alloc(u->host.len + 1, pool->log); |
651 | 700 if (host == NULL) { |
884 | 701 return NGX_ERROR; |
651 | 702 } |
703 | |
884 | 704 (void) ngx_cpystrn(host, u->host.data, u->host.len + 1); |
651 | 705 |
706 /* AF_INET only */ | |
707 | |
2517
095f28fc0c4a
fix upstream port, introduced in r2513
Igor Sysoev <igor@sysoev.ru>
parents:
2512
diff
changeset
|
708 port = htons(u->port); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
709 |
651 | 710 in_addr = inet_addr((char *) host); |
711 | |
712 if (in_addr == INADDR_NONE) { | |
713 h = gethostbyname((char *) host); | |
714 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
715 ngx_free(host); |
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
716 |
651 | 717 if (h == NULL || h->h_addr_list[0] == NULL) { |
884 | 718 u->err = "host not found"; |
719 return NGX_ERROR; | |
651 | 720 } |
721 | |
884 | 722 if (u->one_addr == 0) { |
723 for (i = 0; h->h_addr_list[i] != NULL; i++) { /* void */ } | |
724 | |
725 } else { | |
726 i = 1; | |
727 } | |
651 | 728 |
729 /* MP: ngx_shared_palloc() */ | |
730 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
731 u->addrs = ngx_pcalloc(pool, i * sizeof(ngx_peer_addr_t)); |
884 | 732 if (u->addrs == NULL) { |
733 return NGX_ERROR; | |
651 | 734 } |
735 | |
884 | 736 u->naddrs = i; |
651 | 737 |
738 for (i = 0; h->h_addr_list[i] != NULL; i++) { | |
739 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
740 sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in)); |
651 | 741 if (sin == NULL) { |
884 | 742 return NGX_ERROR; |
651 | 743 } |
744 | |
745 sin->sin_family = AF_INET; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
746 sin->sin_port = port; |
651 | 747 sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[i]); |
748 | |
884 | 749 u->addrs[i].sockaddr = (struct sockaddr *) sin; |
750 u->addrs[i].socklen = sizeof(struct sockaddr_in); | |
651 | 751 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
752 len = NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1; |
651 | 753 |
2049 | 754 p = ngx_pnalloc(pool, len); |
906 | 755 if (p == NULL) { |
884 | 756 return NGX_ERROR; |
651 | 757 } |
758 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
759 len = ngx_sock_ntop((struct sockaddr *) sin, p, len, 1); |
651 | 760 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
761 u->addrs[i].name.len = len; |
906 | 762 u->addrs[i].name.data = p; |
651 | 763 } |
764 | |
765 } else { | |
766 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
767 ngx_free(host); |
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
768 |
651 | 769 /* MP: ngx_shared_palloc() */ |
770 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
771 u->addrs = ngx_pcalloc(pool, sizeof(ngx_peer_addr_t)); |
884 | 772 if (u->addrs == NULL) { |
773 return NGX_ERROR; | |
651 | 774 } |
775 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
776 sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in)); |
651 | 777 if (sin == NULL) { |
884 | 778 return NGX_ERROR; |
651 | 779 } |
780 | |
884 | 781 u->naddrs = 1; |
651 | 782 |
783 sin->sin_family = AF_INET; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
784 sin->sin_port = port; |
651 | 785 sin->sin_addr.s_addr = in_addr; |
786 | |
884 | 787 u->addrs[0].sockaddr = (struct sockaddr *) sin; |
788 u->addrs[0].socklen = sizeof(struct sockaddr_in); | |
651 | 789 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
790 p = ngx_pnalloc(pool, u->host.len + sizeof(":65535") - 1); |
906 | 791 if (p == NULL) { |
884 | 792 return NGX_ERROR; |
651 | 793 } |
794 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
795 u->addrs[0].name.len = ngx_sprintf(p, "%V:%d", |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
796 &u->host, ntohs(port)) - p; |
906 | 797 u->addrs[0].name.data = p; |
651 | 798 } |
799 | |
884 | 800 return NGX_OK; |
651 | 801 } |