Mercurial > hg > nginx-vendor-current
comparison src/core/ngx_inet.c @ 28:7ca9bdc82b3f NGINX_0_1_14
nginx 0.1.14
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; bug appeared in 0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Tue, 18 Jan 2005 00:00:00 +0300 |
parents | 74b1868dd3cd |
children | a39d1b793287 |
comparison
equal
deleted
inserted
replaced
27:66901c2556fd | 28:7ca9bdc82b3f |
---|---|
2 /* | 2 /* |
3 * Copyright (C) Igor Sysoev | 3 * Copyright (C) Igor Sysoev |
4 */ | 4 */ |
5 | 5 |
6 | 6 |
7 | |
8 #include <ngx_config.h> | 7 #include <ngx_config.h> |
9 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 #include <ngx_event.h> | |
10 #include <ngx_event_connect.h> | |
10 | 11 |
11 | 12 |
12 /* | 13 /* |
13 * ngx_sock_ntop() and ngx_inet_ntop() may be implemented as | 14 * ngx_sock_ntop() and ngx_inet_ntop() may be implemented as |
14 * "ngx_sprintf(text, "%ud.%ud.%ud.%ud", p[0], p[1], p[2], p[3])", | 15 * "ngx_sprintf(text, "%ud.%ud.%ud.%ud", p[0], p[1], p[2], p[3])", |
15 * however, they were implemented long before the ngx_sprintf() appeared | 16 * however, they were implemented long before the ngx_sprintf() appeared |
16 * and they are faster by 1.5-2.5 times, so it is worth to keep them. | 17 * and they are faster by 1.5-2.5 times, so it is worth to keep them. |
17 * | 18 * |
18 * By the way, the implementation using ngx_sprintf() is faster by 2.5-3 times | 19 * By the way, the implementation using ngx_sprintf() is faster by 2.5-3 times |
19 * than using FreeBSD libc's snrpintf(). | 20 * than using FreeBSD libc's snprintf(). |
20 */ | 21 */ |
21 | 22 |
22 | 23 |
23 static ngx_inline size_t ngx_sprint_uchar(u_char *text, u_char c, size_t len) | 24 static ngx_inline size_t ngx_sprint_uchar(u_char *text, u_char c, size_t len) |
24 { | 25 { |
62 } | 63 } |
63 | 64 |
64 | 65 |
65 /* AF_INET only */ | 66 /* AF_INET only */ |
66 | 67 |
67 size_t ngx_sock_ntop(int family, struct sockaddr *addr, u_char *text, | 68 size_t ngx_sock_ntop(int family, struct sockaddr *sa, u_char *text, |
68 size_t len) | 69 size_t len) |
69 { | 70 { |
70 u_char *p; | 71 u_char *p; |
71 size_t n; | 72 size_t n; |
72 ngx_uint_t i; | 73 ngx_uint_t i; |
73 struct sockaddr_in *addr_in; | 74 struct sockaddr_in *sin; |
74 | 75 |
75 if (len == 0) { | 76 if (len == 0) { |
76 return 0; | 77 return 0; |
77 } | 78 } |
78 | 79 |
79 if (family != AF_INET) { | 80 if (family != AF_INET) { |
80 return 0; | 81 return 0; |
81 } | 82 } |
82 | 83 |
83 addr_in = (struct sockaddr_in *) addr; | 84 sin = (struct sockaddr_in *) sa; |
84 p = (u_char *) &addr_in->sin_addr; | 85 p = (u_char *) &sin->sin_addr; |
85 | 86 |
86 if (len > INET_ADDRSTRLEN) { | 87 if (len > INET_ADDRSTRLEN) { |
87 len = INET_ADDRSTRLEN; | 88 len = INET_ADDRSTRLEN; |
88 } | 89 } |
89 | 90 |
214 | 215 |
215 return NGX_OK; | 216 return NGX_OK; |
216 } | 217 } |
217 | 218 |
218 | 219 |
219 #if 0 | 220 ngx_peers_t *ngx_inet_upstream_parse(ngx_conf_t *cf, ngx_inet_upstream_t *u) |
220 | 221 { |
221 ngx_int_t ngx_inet_addr_port(ngx_conf_t *cf, ngx_command_t *cmd, | 222 char *err; |
222 ngx_str_t *addr_port) | 223 u_char *host; |
223 { | 224 in_addr_t in_addr; |
224 u_char *host; | 225 ngx_uint_t i, len; |
225 ngx_int_t port; | 226 ngx_peers_t *peers; |
226 ngx_uint_t p; | 227 struct hostent *h; |
227 struct hostent *h; | 228 struct sockaddr_in *sin; |
228 | 229 |
229 for (p = 0; p < addr_port->len; p++) { | 230 err = ngx_inet_parse_host_port(u); |
230 if (addr_port->data[p] == ':') { | 231 |
232 if (err) { | |
233 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
234 "%s in upstream \"%V\"", err, &u->name); | |
235 return NULL; | |
236 } | |
237 | |
238 if (u->default_port) { | |
239 if (u->default_port_value == 0) { | |
240 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
241 "no port in upstream \"%V\"", &u->name); | |
242 return NULL; | |
243 } | |
244 | |
245 u->port = u->default_port_value; | |
246 | |
247 if (!(u->port_text.data = ngx_palloc(cf->pool, sizeof("65536") - 1))) { | |
248 return NULL; | |
249 } | |
250 | |
251 u->port_text.len = ngx_sprintf(u->port_text.data, "%d", | |
252 u->default_port_value) | |
253 - u->port_text.data; | |
254 | |
255 } else if (u->port) { | |
256 if (u->port == u->default_port_value) { | |
257 u->default_port = 1; | |
258 } | |
259 | |
260 } else { | |
261 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
262 "no port in upstream \"%V\"", &u->name); | |
263 return NULL; | |
264 } | |
265 | |
266 if (u->host.len == 0) { | |
267 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
268 "no host in upstream \"%V\"", &u->name); | |
269 return NULL; | |
270 } | |
271 | |
272 u->port = htons(u->port); | |
273 | |
274 if (!(host = ngx_palloc(cf->pool, u->host.len + 1))) { | |
275 return NULL; | |
276 } | |
277 | |
278 ngx_cpystrn(host, u->host.data, u->host.len + 1); | |
279 | |
280 /* AF_INET only */ | |
281 | |
282 in_addr = inet_addr((char *) host); | |
283 | |
284 if (in_addr == INADDR_NONE) { | |
285 h = gethostbyname((char *) host); | |
286 | |
287 if (h == NULL || h->h_addr_list[0] == NULL) { | |
288 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
289 "host %s is not found in upstream \"%V\"", | |
290 host, &u->name); | |
291 return NULL; | |
292 } | |
293 | |
294 for (i = 0; h->h_addr_list[i] != NULL; i++) { /* void */ } | |
295 | |
296 /* MP: ngx_shared_palloc() */ | |
297 | |
298 peers = ngx_pcalloc(cf->pool, | |
299 sizeof(ngx_peers_t) + sizeof(ngx_peer_t) * (i - 1)); | |
300 | |
301 if (peers == NULL) { | |
302 return NULL; | |
303 } | |
304 | |
305 peers->number = i; | |
306 peers->weight = 1; | |
307 | |
308 for (i = 0; h->h_addr_list[i] != NULL; i++) { | |
309 | |
310 if (!(sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)))) { | |
311 return NULL; | |
312 } | |
313 | |
314 sin->sin_family = AF_INET; | |
315 sin->sin_port = u->port; | |
316 sin->sin_addr.s_addr = *(in_addr_t *)(h->h_addr_list[i]); | |
317 | |
318 peers->peer[i].sockaddr = (struct sockaddr *) sin; | |
319 peers->peer[i].socklen = sizeof(struct sockaddr_in); | |
320 | |
321 len = INET_ADDRSTRLEN - 1 + 1 + u->port_text.len; | |
322 | |
323 if (!(peers->peer[i].name.data = ngx_palloc(cf->pool, len))) { | |
324 return NULL; | |
325 } | |
326 | |
327 len = ngx_sock_ntop(AF_INET, (struct sockaddr *) sin, | |
328 peers->peer[i].name.data, len); | |
329 | |
330 peers->peer[i].name.data[len++] = ':'; | |
331 | |
332 ngx_memcpy(peers->peer[i].name.data + len, | |
333 u->port_text.data, u->port_text.len); | |
334 | |
335 peers->peer[i].name.len = len + u->port_text.len; | |
336 | |
337 peers->peer[i].uri_separator = ""; | |
338 | |
339 peers->peer[i].weight = 1; | |
340 peers->peer[i].max_fails = 1; | |
341 peers->peer[i].fail_timeout = 60; | |
342 } | |
343 | |
344 } else { | |
345 | |
346 /* MP: ngx_shared_palloc() */ | |
347 | |
348 if (!(peers = ngx_pcalloc(cf->pool, sizeof(ngx_peers_t)))) { | |
349 return NULL; | |
350 } | |
351 | |
352 if (!(sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)))) { | |
353 return NULL; | |
354 } | |
355 | |
356 peers->number = 1; | |
357 | |
358 sin->sin_family = AF_INET; | |
359 sin->sin_port = u->port; | |
360 sin->sin_addr.s_addr = in_addr; | |
361 | |
362 peers->peer[0].sockaddr = (struct sockaddr *) sin; | |
363 peers->peer[0].socklen = sizeof(struct sockaddr_in); | |
364 | |
365 len = u->host.len + 1 + u->port_text.len; | |
366 | |
367 peers->peer[0].name.len = len; | |
368 | |
369 if (!(peers->peer[0].name.data = ngx_palloc(cf->pool, len))) { | |
370 return NULL; | |
371 } | |
372 | |
373 len = u->host.len; | |
374 | |
375 ngx_memcpy(peers->peer[0].name.data, u->host.data, len); | |
376 | |
377 peers->peer[0].name.data[len++] = ':'; | |
378 | |
379 ngx_memcpy(peers->peer[0].name.data + len, | |
380 u->port_text.data, u->port_text.len); | |
381 | |
382 peers->peer[0].uri_separator = ""; | |
383 } | |
384 | |
385 return peers; | |
386 } | |
387 | |
388 | |
389 char *ngx_inet_parse_host_port(ngx_inet_upstream_t *u) | |
390 { | |
391 size_t i; | |
392 ngx_int_t port; | |
393 ngx_str_t *url; | |
394 | |
395 url = &u->url; | |
396 | |
397 if (u->port_only) { | |
398 i = 0; | |
399 | |
400 } else { | |
401 if (url->data[0] == ':' || url->data[0] == '/') { | |
402 return "invalid host"; | |
403 } | |
404 | |
405 i = 1; | |
406 } | |
407 | |
408 u->host.data = url->data; | |
409 u->host_header = *url; | |
410 | |
411 for (/* void */; i < url->len; i++) { | |
412 | |
413 if (url->data[i] == ':') { | |
414 u->port_text.data = &url->data[i] + 1; | |
415 u->host.len = i; | |
416 | |
417 if (!u->uri_part) { | |
418 u->port_text.len = &url->data[url->len] - u->port_text.data; | |
419 break; | |
420 } | |
421 } | |
422 | |
423 if (url->data[i] == '/') { | |
424 u->uri.data = &url->data[i]; | |
425 u->uri.len = url->len - i; | |
426 u->host_header.len = i; | |
427 | |
428 if (u->host.len == 0) { | |
429 u->host.len = i; | |
430 } | |
431 | |
432 if (u->port_text.data == NULL) { | |
433 u->default_port = 1; | |
434 return NULL; | |
435 } | |
436 | |
437 u->port_text.len = &url->data[i] - u->port_text.data; | |
438 | |
439 if (u->port_text.len == 0) { | |
440 return "invalid port"; | |
441 } | |
442 | |
231 break; | 443 break; |
232 } | 444 } |
233 } | 445 } |
234 | 446 |
235 in_addr->host.len = p; | 447 if (u->port_text.data == NULL) { |
236 if (!(in_addr->host.data = ngx_palloc(pool, p + 1))) { | 448 port = ngx_atoi(url->data, url->len); |
237 return NGX_ERROR; | 449 |
238 } | 450 if (port == NGX_ERROR) { |
239 | 451 u->default_port = 1; |
240 ngx_cpystrn(in_addr->host.data, addr_port->data, p + 1); | 452 u->host.len = url->len; |
241 | 453 |
242 if (p == addr_port->len) { | 454 return NULL; |
243 p = 0; | 455 } |
244 } | 456 |
245 | 457 u->port_text = *url; |
246 port = ngx_atoi(&addr[p], args[1].len - p); | 458 u->wildcard = 1; |
247 if (port == NGX_ERROR && p == 0) { | 459 |
248 | 460 } else { |
249 /* default port */ | 461 if (u->port_text.len == 0) { |
250 iap->port = 0; | 462 return "no URI"; |
251 | 463 } |
252 } else if ((port == NGX_ERROR && p != 0) /* "listen host:NONNUMBER" */ | 464 |
253 || (port < 1 || port > 65536)) { /* "listen 99999" */ | 465 port = ngx_atoi(u->port_text.data, u->port_text.len); |
254 | 466 |
255 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 467 if (port == NGX_ERROR || port < 1 || port > 65536) { |
256 "invalid port \"%s\" in \"%s\" directive, " | 468 return "invalid port"; |
257 "it must be a number between 1 and 65535", | 469 } |
258 &addr[p], cmd->name.data); | 470 } |
259 | 471 |
260 return NGX_CONF_ERROR; | 472 u->port = (in_port_t) port; |
261 | 473 |
262 } else if (p == 0) { | 474 return NULL; |
263 ls->addr = INADDR_ANY; | 475 } |
264 ls->port = (in_port_t) port; | |
265 return NGX_CONF_OK; | |
266 } | |
267 | |
268 return NGX_OK; | |
269 } | |
270 | |
271 #endif |