Mercurial > hg > nginx-vendor-0-6
comparison src/http/modules/ngx_http_userid_filter.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 | 46833bd150cb |
children | 6cfc63e68377 |
comparison
equal
deleted
inserted
replaced
27:66901c2556fd | 28:7ca9bdc82b3f |
---|---|
42 ngx_http_userid_conf_t *conf); | 42 ngx_http_userid_conf_t *conf); |
43 static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r, | 43 static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r, |
44 ngx_http_userid_ctx_t *ctx, | 44 ngx_http_userid_ctx_t *ctx, |
45 ngx_http_userid_conf_t *conf); | 45 ngx_http_userid_conf_t *conf); |
46 | 46 |
47 static size_t ngx_http_userid_log_uid_got_getlen(ngx_http_request_t *r, | |
48 uintptr_t data); | |
47 static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf, | 49 static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf, |
48 uintptr_t data); | 50 ngx_http_log_op_t *op); |
51 static size_t ngx_http_userid_log_uid_set_getlen(ngx_http_request_t *r, | |
52 uintptr_t data); | |
49 static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf, | 53 static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf, |
50 uintptr_t data); | 54 ngx_http_log_op_t *op); |
51 | 55 |
56 static ngx_int_t ngx_http_userid_add_log_formats(ngx_conf_t *cf); | |
52 static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle); | 57 static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle); |
53 static ngx_int_t ngx_http_userid_pre_conf(ngx_conf_t *cf); | |
54 static void *ngx_http_userid_create_conf(ngx_conf_t *cf); | 58 static void *ngx_http_userid_create_conf(ngx_conf_t *cf); |
55 static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, | 59 static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, |
56 void *child); | 60 void *child); |
57 char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data); | 61 char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data); |
58 char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data); | 62 char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data); |
140 ngx_null_command | 144 ngx_null_command |
141 }; | 145 }; |
142 | 146 |
143 | 147 |
144 ngx_http_module_t ngx_http_userid_filter_module_ctx = { | 148 ngx_http_module_t ngx_http_userid_filter_module_ctx = { |
145 ngx_http_userid_pre_conf, /* pre conf */ | 149 ngx_http_userid_add_log_formats, /* pre conf */ |
146 | 150 |
147 NULL, /* create main configuration */ | 151 NULL, /* create main configuration */ |
148 NULL, /* init main configuration */ | 152 NULL, /* init main configuration */ |
149 | 153 |
150 NULL, /* create server configuration */ | 154 NULL, /* create server configuration */ |
164 NULL /* init process */ | 168 NULL /* init process */ |
165 }; | 169 }; |
166 | 170 |
167 | 171 |
168 static ngx_http_log_op_name_t ngx_http_userid_log_fmt_ops[] = { | 172 static ngx_http_log_op_name_t ngx_http_userid_log_fmt_ops[] = { |
169 { ngx_string("uid_got"), 0, ngx_http_userid_log_uid_got }, | 173 { ngx_string("uid_got"), 0, NULL, |
170 { ngx_string("uid_set"), 0, ngx_http_userid_log_uid_set }, | 174 ngx_http_userid_log_uid_got_getlen, |
171 { ngx_null_string, 0, NULL } | 175 ngx_http_userid_log_uid_got }, |
176 { ngx_string("uid_set"), 0, NULL, | |
177 ngx_http_userid_log_uid_set_getlen, | |
178 ngx_http_userid_log_uid_set }, | |
179 { ngx_null_string, 0, NULL, NULL, NULL } | |
172 }; | 180 }; |
173 | 181 |
174 | 182 |
175 static ngx_int_t ngx_http_userid_filter(ngx_http_request_t *r) | 183 static ngx_int_t ngx_http_userid_filter(ngx_http_request_t *r) |
176 { | 184 { |
296 ngx_http_userid_conf_t *conf) | 304 ngx_http_userid_conf_t *conf) |
297 { | 305 { |
298 u_char *cookie, *p; | 306 u_char *cookie, *p; |
299 size_t len; | 307 size_t len; |
300 socklen_t slen; | 308 socklen_t slen; |
301 struct sockaddr_in addr_in; | 309 struct sockaddr_in sin; |
302 ngx_str_t src, dst; | 310 ngx_str_t src, dst; |
303 ngx_table_elt_t *set_cookie, *p3p; | 311 ngx_table_elt_t *set_cookie, *p3p; |
304 | 312 |
305 /* TODO: mutex for sequencers */ | 313 /* TODO: mutex for sequencers */ |
306 | 314 |
319 } else { | 327 } else { |
320 if (conf->service == NGX_CONF_UNSET) { | 328 if (conf->service == NGX_CONF_UNSET) { |
321 if (r->in_addr == 0) { | 329 if (r->in_addr == 0) { |
322 slen = sizeof(struct sockaddr_in); | 330 slen = sizeof(struct sockaddr_in); |
323 if (getsockname(r->connection->fd, | 331 if (getsockname(r->connection->fd, |
324 (struct sockaddr *) &addr_in, &slen) == -1) | 332 (struct sockaddr *) &sin, &slen) == -1) |
325 { | 333 { |
326 ngx_log_error(NGX_LOG_CRIT, r->connection->log, | 334 ngx_log_error(NGX_LOG_CRIT, r->connection->log, |
327 ngx_socket_errno, | 335 ngx_socket_errno, "getsockname() failed"); |
328 "getsockname() failed"); | |
329 } | 336 } |
330 | 337 |
331 r->in_addr = addr_in.sin_addr.s_addr; | 338 r->in_addr = sin.sin_addr.s_addr; |
332 } | 339 } |
333 | 340 |
334 ctx->uid_set[0] = htonl(r->in_addr); | 341 ctx->uid_set[0] = htonl(r->in_addr); |
335 | 342 |
336 } else { | 343 } else { |
350 | 357 |
351 if (conf->expires) { | 358 if (conf->expires) { |
352 len += sizeof(expires) - 1 + 2; | 359 len += sizeof(expires) - 1 + 2; |
353 } | 360 } |
354 | 361 |
355 if (conf->domain.len > 1) { | 362 if (conf->domain.len) { |
356 len += conf->domain.len; | 363 len += conf->domain.len; |
357 } | 364 } |
358 | 365 |
359 if (!(cookie = ngx_palloc(r->pool, len))) { | 366 if (!(cookie = ngx_palloc(r->pool, len))) { |
360 return NGX_ERROR; | 367 return NGX_ERROR; |
377 } else if (conf->expires) { | 384 } else if (conf->expires) { |
378 p = ngx_cpymem(p, expires, sizeof("; expires=") - 1); | 385 p = ngx_cpymem(p, expires, sizeof("; expires=") - 1); |
379 p = ngx_http_cookie_time(p, ngx_time() + conf->expires); | 386 p = ngx_http_cookie_time(p, ngx_time() + conf->expires); |
380 } | 387 } |
381 | 388 |
382 if (conf->domain.len > 1) { | 389 if (conf->domain.len) { |
383 p = ngx_cpymem(p, conf->domain.data, conf->domain.len); | 390 p = ngx_cpymem(p, conf->domain.data, conf->domain.len); |
384 } | 391 } |
385 | 392 |
386 p = ngx_cpymem(p, conf->path.data, conf->path.len); | 393 p = ngx_cpymem(p, conf->path.data, conf->path.len); |
387 | 394 |
395 set_cookie->value.data = cookie; | 402 set_cookie->value.data = cookie; |
396 | 403 |
397 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 404 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
398 "uid cookie: \"%V\"", &set_cookie->value); | 405 "uid cookie: \"%V\"", &set_cookie->value); |
399 | 406 |
400 if (conf->p3p.len == 1) { | 407 if (conf->p3p.len == 0) { |
401 return NGX_OK; | 408 return NGX_OK; |
402 } | 409 } |
403 | 410 |
404 if (!(p3p = ngx_list_push(&r->headers_out.headers))) { | 411 if (!(p3p = ngx_list_push(&r->headers_out.headers))) { |
405 return NGX_ERROR; | 412 return NGX_ERROR; |
411 | 418 |
412 return NGX_OK; | 419 return NGX_OK; |
413 } | 420 } |
414 | 421 |
415 | 422 |
416 static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf, | 423 static size_t ngx_http_userid_log_uid_got_getlen(ngx_http_request_t *r, |
417 uintptr_t data) | 424 uintptr_t data) |
418 { | 425 { |
419 ngx_http_userid_ctx_t *ctx; | 426 ngx_http_userid_ctx_t *ctx; |
420 ngx_http_userid_conf_t *conf; | 427 ngx_http_userid_conf_t *conf; |
421 | 428 |
422 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); | 429 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); |
423 | 430 |
424 if (ctx == NULL || ctx->uid_got[3] == 0) { | 431 if (ctx == NULL || ctx->uid_got[3] == 0) { |
425 if (buf == NULL) { | 432 return 1; |
426 return (u_char *) 1; | 433 } |
427 } | 434 |
428 | 435 conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); |
436 | |
437 return conf->name.len + 1 + 32; | |
438 } | |
439 | |
440 | |
441 static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf, | |
442 ngx_http_log_op_t *op) | |
443 { | |
444 ngx_http_userid_ctx_t *ctx; | |
445 ngx_http_userid_conf_t *conf; | |
446 | |
447 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); | |
448 | |
449 if (ctx == NULL || ctx->uid_got[3] == 0) { | |
429 *buf = '-'; | 450 *buf = '-'; |
430 return buf + 1; | 451 return buf + 1; |
431 } | 452 } |
432 | 453 |
433 conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); | 454 conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); |
434 | |
435 if (buf == NULL) { | |
436 return (u_char *) (conf->name.len + 1 + 32); | |
437 } | |
438 | 455 |
439 buf = ngx_cpymem(buf, conf->name.data, conf->name.len); | 456 buf = ngx_cpymem(buf, conf->name.data, conf->name.len); |
440 | 457 |
441 *buf++ = '='; | 458 *buf++ = '='; |
442 | 459 |
444 ctx->uid_got[0], ctx->uid_got[1], | 461 ctx->uid_got[0], ctx->uid_got[1], |
445 ctx->uid_got[2], ctx->uid_got[3]); | 462 ctx->uid_got[2], ctx->uid_got[3]); |
446 } | 463 } |
447 | 464 |
448 | 465 |
449 static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf, | 466 static size_t ngx_http_userid_log_uid_set_getlen(ngx_http_request_t *r, |
450 uintptr_t data) | 467 uintptr_t data) |
451 { | 468 { |
452 ngx_http_userid_ctx_t *ctx; | 469 ngx_http_userid_ctx_t *ctx; |
453 ngx_http_userid_conf_t *conf; | 470 ngx_http_userid_conf_t *conf; |
454 | 471 |
455 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); | 472 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); |
456 | 473 |
457 if (ctx == NULL || ctx->uid_set[3] == 0) { | 474 if (ctx == NULL || ctx->uid_set[3] == 0) { |
458 if (buf == NULL) { | 475 return 1; |
459 return (u_char *) 1; | 476 } |
460 } | 477 |
461 | 478 conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); |
479 | |
480 return conf->name.len + 1 + 32; | |
481 } | |
482 | |
483 | |
484 static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf, | |
485 ngx_http_log_op_t *op) | |
486 { | |
487 ngx_http_userid_ctx_t *ctx; | |
488 ngx_http_userid_conf_t *conf; | |
489 | |
490 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); | |
491 | |
492 if (ctx == NULL || ctx->uid_set[3] == 0) { | |
462 *buf = '-'; | 493 *buf = '-'; |
463 return buf + 1; | 494 return buf + 1; |
464 } | 495 } |
465 | 496 |
466 conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); | 497 conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); |
467 | |
468 if (buf == NULL) { | |
469 return (u_char *) (conf->name.len + 1 + 32); | |
470 } | |
471 | 498 |
472 buf = ngx_cpymem(buf, conf->name.data, conf->name.len); | 499 buf = ngx_cpymem(buf, conf->name.data, conf->name.len); |
473 | 500 |
474 *buf++ = '='; | 501 *buf++ = '='; |
475 | 502 |
477 ctx->uid_set[0], ctx->uid_set[1], | 504 ctx->uid_set[0], ctx->uid_set[1], |
478 ctx->uid_set[2], ctx->uid_set[3]); | 505 ctx->uid_set[2], ctx->uid_set[3]); |
479 } | 506 } |
480 | 507 |
481 | 508 |
509 static ngx_int_t ngx_http_userid_add_log_formats(ngx_conf_t *cf) | |
510 { | |
511 ngx_http_log_op_name_t *op; | |
512 | |
513 for (op = ngx_http_userid_log_fmt_ops; op->name.len; op++) { /* void */ } | |
514 op->run = NULL; | |
515 | |
516 for (op = ngx_http_log_fmt_ops; op->run; op++) { | |
517 if (op->name.len == 0) { | |
518 op = (ngx_http_log_op_name_t *) op->run; | |
519 } | |
520 } | |
521 | |
522 op->run = (ngx_http_log_op_run_pt) ngx_http_userid_log_fmt_ops; | |
523 | |
524 return NGX_OK; | |
525 } | |
526 | |
527 | |
482 static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle) | 528 static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle) |
483 { | 529 { |
484 ngx_http_next_header_filter = ngx_http_top_header_filter; | 530 ngx_http_next_header_filter = ngx_http_top_header_filter; |
485 ngx_http_top_header_filter = ngx_http_userid_filter; | 531 ngx_http_top_header_filter = ngx_http_userid_filter; |
486 | |
487 return NGX_OK; | |
488 } | |
489 | |
490 | |
491 static ngx_int_t ngx_http_userid_pre_conf(ngx_conf_t *cf) | |
492 { | |
493 ngx_http_log_op_name_t *op; | |
494 | |
495 for (op = ngx_http_userid_log_fmt_ops; op->name.len; op++) { /* void */ } | |
496 op->op = NULL; | |
497 | |
498 op = ngx_http_log_fmt_ops; | |
499 | |
500 for (op = ngx_http_log_fmt_ops; op->op; op++) { | |
501 if (op->name.len == 0) { | |
502 op = (ngx_http_log_op_name_t *) op->op; | |
503 } | |
504 } | |
505 | |
506 op->op = (ngx_http_log_op_pt) ngx_http_userid_log_fmt_ops; | |
507 | 532 |
508 return NGX_OK; | 533 return NGX_OK; |
509 } | 534 } |
510 | 535 |
511 | 536 |
515 | 540 |
516 if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_userid_conf_t)))) { | 541 if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_userid_conf_t)))) { |
517 return NGX_CONF_ERROR; | 542 return NGX_CONF_ERROR; |
518 } | 543 } |
519 | 544 |
520 /* set by ngx_pcalloc(): | 545 /* |
521 | 546 * set by ngx_pcalloc(): |
522 conf->name.len = 0; | 547 * |
523 conf->name.date = NULL; | 548 * conf->name.len = 0; |
524 conf->domain.len = 0; | 549 * conf->name.date = NULL; |
525 conf->domain.date = NULL; | 550 * conf->domain.len = 0; |
526 conf->path.len = 0; | 551 * conf->domain.date = NULL; |
527 conf->path.date = NULL; | 552 * conf->path.len = 0; |
528 conf->p3p.len = 0; | 553 * conf->path.date = NULL; |
529 conf->p3p.date = NULL; | 554 * conf->p3p.len = 0; |
530 | 555 * conf->p3p.date = NULL; |
531 */ | 556 */ |
532 | 557 |
533 conf->enable = NGX_CONF_UNSET; | 558 conf->enable = NGX_CONF_UNSET; |
534 conf->service = NGX_CONF_UNSET; | 559 conf->service = NGX_CONF_UNSET; |
535 conf->expires = NGX_CONF_UNSET; | 560 conf->expires = NGX_CONF_UNSET; |
536 | 561 |
545 ngx_http_userid_conf_t *conf = child; | 570 ngx_http_userid_conf_t *conf = child; |
546 | 571 |
547 ngx_conf_merge_value(conf->enable, prev->enable, NGX_HTTP_USERID_OFF); | 572 ngx_conf_merge_value(conf->enable, prev->enable, NGX_HTTP_USERID_OFF); |
548 | 573 |
549 ngx_conf_merge_str_value(conf->name, prev->name, "uid"); | 574 ngx_conf_merge_str_value(conf->name, prev->name, "uid"); |
550 ngx_conf_merge_str_value(conf->domain, prev->domain, "."); | 575 ngx_conf_merge_str_value(conf->domain, prev->domain, ""); |
551 ngx_conf_merge_str_value(conf->path, prev->path, "; path=/"); | 576 ngx_conf_merge_str_value(conf->path, prev->path, "; path=/"); |
552 ngx_conf_merge_str_value(conf->p3p, prev->p3p, "."); | 577 ngx_conf_merge_str_value(conf->p3p, prev->p3p, ""); |
553 | 578 |
554 ngx_conf_merge_value(conf->service, prev->service, NGX_CONF_UNSET); | 579 ngx_conf_merge_value(conf->service, prev->service, NGX_CONF_UNSET); |
555 ngx_conf_merge_sec_value(conf->expires, prev->expires, 0); | 580 ngx_conf_merge_sec_value(conf->expires, prev->expires, 0); |
556 | 581 |
557 return NGX_CONF_OK; | 582 return NGX_CONF_OK; |
563 ngx_str_t *domain = data; | 588 ngx_str_t *domain = data; |
564 | 589 |
565 u_char *p, *new; | 590 u_char *p, *new; |
566 | 591 |
567 if (domain->len == 4 && ngx_strcmp(domain->data, "none") == 0) { | 592 if (domain->len == 4 && ngx_strcmp(domain->data, "none") == 0) { |
568 domain->len = 1; | 593 domain->len = 0; |
569 domain->data = (u_char *) "."; | 594 domain->data = (u_char *) ""; |
570 | 595 |
571 return NGX_CONF_OK; | 596 return NGX_CONF_OK; |
572 } | 597 } |
573 | 598 |
574 if (!(new = ngx_palloc(cf->pool, sizeof("; domain=") - 1 + domain->len))) { | 599 if (!(new = ngx_palloc(cf->pool, sizeof("; domain=") - 1 + domain->len))) { |
643 char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data) | 668 char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data) |
644 { | 669 { |
645 ngx_str_t *p3p = data; | 670 ngx_str_t *p3p = data; |
646 | 671 |
647 if (p3p->len == 4 && ngx_strcmp(p3p->data, "none") == 0) { | 672 if (p3p->len == 4 && ngx_strcmp(p3p->data, "none") == 0) { |
648 p3p->len = 1; | 673 p3p->len = 0; |
649 p3p->data = (u_char *) "."; | 674 p3p->data = (u_char *) ""; |
650 } | 675 } |
651 | 676 |
652 return NGX_CONF_OK; | 677 return NGX_CONF_OK; |
653 } | 678 } |