Mercurial > hg > nginx-vendor-0-7
comparison src/http/modules/ngx_http_userid_filter.c @ 48:6cfc63e68377 NGINX_0_1_24
nginx 0.1.24
*) Feature: the ngx_http_ssi_filter_module supports the QUERY_STRING
and DOCUMENT_URI variables.
*) Bugfix: the ngx_http_autoindex_module may some times return the 404
response for existent directory, if this directory was used in
"alias" directive.
*) Bugfix: the ngx_http_ssi_filter_module ran incorrectly for large
responses.
*) Bugfix: the lack of the "Referer" header line was always accounted
as valid referrer.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Fri, 04 Mar 2005 00:00:00 +0300 |
parents | 7ca9bdc82b3f |
children |
comparison
equal
deleted
inserted
replaced
47:4ae32548452c | 48:6cfc63e68377 |
---|---|
36 uint32_t uid_set[4]; | 36 uint32_t uid_set[4]; |
37 } ngx_http_userid_ctx_t; | 37 } ngx_http_userid_ctx_t; |
38 | 38 |
39 | 39 |
40 static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r, | 40 static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r, |
41 ngx_http_userid_ctx_t *ctx, | 41 ngx_http_userid_ctx_t *ctx, 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, | 42 static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r, |
44 ngx_http_userid_ctx_t *ctx, | 43 ngx_http_userid_ctx_t *ctx, ngx_http_userid_conf_t *conf); |
45 ngx_http_userid_conf_t *conf); | |
46 | 44 |
47 static size_t ngx_http_userid_log_uid_got_getlen(ngx_http_request_t *r, | 45 static size_t ngx_http_userid_log_uid_got_getlen(ngx_http_request_t *r, |
48 uintptr_t data); | 46 uintptr_t data); |
49 static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf, | 47 static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf, |
50 ngx_http_log_op_t *op); | 48 ngx_http_log_op_t *op); |
51 static size_t ngx_http_userid_log_uid_set_getlen(ngx_http_request_t *r, | 49 static size_t ngx_http_userid_log_uid_set_getlen(ngx_http_request_t *r, |
52 uintptr_t data); | 50 uintptr_t data); |
53 static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf, | 51 static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf, |
54 ngx_http_log_op_t *op); | 52 ngx_http_log_op_t *op); |
55 | 53 |
56 static ngx_int_t ngx_http_userid_add_log_formats(ngx_conf_t *cf); | 54 static ngx_int_t ngx_http_userid_add_log_formats(ngx_conf_t *cf); |
57 static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle); | 55 static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle); |
58 static void *ngx_http_userid_create_conf(ngx_conf_t *cf); | 56 static void *ngx_http_userid_create_conf(ngx_conf_t *cf); |
59 static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, | 57 static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, |
60 void *child); | 58 void *child); |
61 char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data); | 59 static char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data); |
62 char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data); | 60 static char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data); |
63 char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 61 static char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, |
64 char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data); | 62 void *conf); |
63 static char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data); | |
65 | 64 |
66 | 65 |
67 static uint32_t sequencer_v1 = 1; | 66 static uint32_t sequencer_v1 = 1; |
68 static uint32_t sequencer_v2 = 0x03030302; | 67 static uint32_t sequencer_v2 = 0x03030302; |
69 | 68 |
139 ngx_conf_set_str_slot, | 138 ngx_conf_set_str_slot, |
140 NGX_HTTP_LOC_CONF_OFFSET, | 139 NGX_HTTP_LOC_CONF_OFFSET, |
141 offsetof(ngx_http_userid_conf_t, p3p), | 140 offsetof(ngx_http_userid_conf_t, p3p), |
142 &ngx_http_userid_p3p_p }, | 141 &ngx_http_userid_p3p_p }, |
143 | 142 |
144 ngx_null_command | 143 ngx_null_command |
145 }; | 144 }; |
146 | 145 |
147 | 146 |
148 ngx_http_module_t ngx_http_userid_filter_module_ctx = { | 147 ngx_http_module_t ngx_http_userid_filter_module_ctx = { |
149 ngx_http_userid_add_log_formats, /* pre conf */ | 148 ngx_http_userid_add_log_formats, /* pre conf */ |
178 ngx_http_userid_log_uid_set }, | 177 ngx_http_userid_log_uid_set }, |
179 { ngx_null_string, 0, NULL, NULL, NULL } | 178 { ngx_null_string, 0, NULL, NULL, NULL } |
180 }; | 179 }; |
181 | 180 |
182 | 181 |
183 static ngx_int_t ngx_http_userid_filter(ngx_http_request_t *r) | 182 static ngx_int_t |
183 ngx_http_userid_filter(ngx_http_request_t *r) | |
184 { | 184 { |
185 ngx_int_t rc; | 185 ngx_int_t rc; |
186 ngx_http_userid_ctx_t *ctx; | 186 ngx_http_userid_ctx_t *ctx; |
187 ngx_http_userid_conf_t *conf; | 187 ngx_http_userid_conf_t *conf; |
188 | 188 |
190 | 190 |
191 if (conf->enable == NGX_HTTP_USERID_OFF) { | 191 if (conf->enable == NGX_HTTP_USERID_OFF) { |
192 return ngx_http_next_header_filter(r); | 192 return ngx_http_next_header_filter(r); |
193 } | 193 } |
194 | 194 |
195 ngx_http_create_ctx(r, ctx, ngx_http_userid_filter_module, | 195 |
196 sizeof(ngx_http_userid_ctx_t), NGX_ERROR); | 196 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_userid_ctx_t)); |
197 if (ctx == NULL) { | |
198 return NGX_ERROR; | |
199 } | |
200 | |
201 ngx_http_set_ctx(r, ctx, ngx_http_userid_filter_module); | |
202 | |
197 | 203 |
198 rc = ngx_http_userid_get_uid(r, ctx, conf); | 204 rc = ngx_http_userid_get_uid(r, ctx, conf); |
199 | 205 |
200 if (rc != NGX_OK) { | 206 if (rc != NGX_OK) { |
201 return rc; | 207 return rc; |
213 | 219 |
214 return ngx_http_next_header_filter(r); | 220 return ngx_http_next_header_filter(r); |
215 } | 221 } |
216 | 222 |
217 | 223 |
218 static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r, | 224 static ngx_int_t |
219 ngx_http_userid_ctx_t *ctx, | 225 ngx_http_userid_get_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx, |
220 ngx_http_userid_conf_t *conf) | 226 ngx_http_userid_conf_t *conf) |
221 { | 227 { |
222 u_char *start, *last, *end; | 228 u_char *start, *last, *end; |
223 ngx_uint_t i; | 229 ngx_uint_t i; |
224 ngx_str_t src, dst; | 230 ngx_str_t src, dst; |
225 ngx_table_elt_t **cookies; | 231 ngx_table_elt_t **cookies; |
297 | 303 |
298 return NGX_OK; | 304 return NGX_OK; |
299 } | 305 } |
300 | 306 |
301 | 307 |
302 static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r, | 308 static ngx_int_t |
303 ngx_http_userid_ctx_t *ctx, | 309 ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx, |
304 ngx_http_userid_conf_t *conf) | 310 ngx_http_userid_conf_t *conf) |
305 { | 311 { |
306 u_char *cookie, *p; | 312 u_char *cookie, *p; |
307 size_t len; | 313 size_t len; |
308 socklen_t slen; | 314 socklen_t slen; |
309 struct sockaddr_in sin; | 315 struct sockaddr_in sin; |
361 | 367 |
362 if (conf->domain.len) { | 368 if (conf->domain.len) { |
363 len += conf->domain.len; | 369 len += conf->domain.len; |
364 } | 370 } |
365 | 371 |
366 if (!(cookie = ngx_palloc(r->pool, len))) { | 372 cookie = ngx_palloc(r->pool, len); |
373 if (cookie == NULL) { | |
367 return NGX_ERROR; | 374 return NGX_ERROR; |
368 } | 375 } |
369 | 376 |
370 p = ngx_cpymem(cookie, conf->name.data, conf->name.len); | 377 p = ngx_cpymem(cookie, conf->name.data, conf->name.len); |
371 *p++ = '='; | 378 *p++ = '='; |
390 p = ngx_cpymem(p, conf->domain.data, conf->domain.len); | 397 p = ngx_cpymem(p, conf->domain.data, conf->domain.len); |
391 } | 398 } |
392 | 399 |
393 p = ngx_cpymem(p, conf->path.data, conf->path.len); | 400 p = ngx_cpymem(p, conf->path.data, conf->path.len); |
394 | 401 |
395 if (!(set_cookie = ngx_list_push(&r->headers_out.headers))) { | 402 set_cookie = ngx_list_push(&r->headers_out.headers); |
403 if (set_cookie == NULL) { | |
396 return NGX_ERROR; | 404 return NGX_ERROR; |
397 } | 405 } |
398 | 406 |
399 set_cookie->key.len = sizeof("Set-Cookie") - 1; | 407 set_cookie->key.len = sizeof("Set-Cookie") - 1; |
400 set_cookie->key.data = (u_char *) "Set-Cookie"; | 408 set_cookie->key.data = (u_char *) "Set-Cookie"; |
406 | 414 |
407 if (conf->p3p.len == 0) { | 415 if (conf->p3p.len == 0) { |
408 return NGX_OK; | 416 return NGX_OK; |
409 } | 417 } |
410 | 418 |
411 if (!(p3p = ngx_list_push(&r->headers_out.headers))) { | 419 p3p = ngx_list_push(&r->headers_out.headers); |
420 if (p3p == NULL) { | |
412 return NGX_ERROR; | 421 return NGX_ERROR; |
413 } | 422 } |
414 | 423 |
415 p3p->key.len = sizeof("P3P") - 1; | 424 p3p->key.len = sizeof("P3P") - 1; |
416 p3p->key.data = (u_char *) "P3P"; | 425 p3p->key.data = (u_char *) "P3P"; |
418 | 427 |
419 return NGX_OK; | 428 return NGX_OK; |
420 } | 429 } |
421 | 430 |
422 | 431 |
423 static size_t ngx_http_userid_log_uid_got_getlen(ngx_http_request_t *r, | 432 static size_t |
424 uintptr_t data) | 433 ngx_http_userid_log_uid_got_getlen(ngx_http_request_t *r, uintptr_t data) |
425 { | 434 { |
426 ngx_http_userid_ctx_t *ctx; | 435 ngx_http_userid_ctx_t *ctx; |
427 ngx_http_userid_conf_t *conf; | 436 ngx_http_userid_conf_t *conf; |
428 | 437 |
429 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); | 438 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); |
436 | 445 |
437 return conf->name.len + 1 + 32; | 446 return conf->name.len + 1 + 32; |
438 } | 447 } |
439 | 448 |
440 | 449 |
441 static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf, | 450 static u_char * |
442 ngx_http_log_op_t *op) | 451 ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf, |
452 ngx_http_log_op_t *op) | |
443 { | 453 { |
444 ngx_http_userid_ctx_t *ctx; | 454 ngx_http_userid_ctx_t *ctx; |
445 ngx_http_userid_conf_t *conf; | 455 ngx_http_userid_conf_t *conf; |
446 | 456 |
447 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); | 457 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); |
461 ctx->uid_got[0], ctx->uid_got[1], | 471 ctx->uid_got[0], ctx->uid_got[1], |
462 ctx->uid_got[2], ctx->uid_got[3]); | 472 ctx->uid_got[2], ctx->uid_got[3]); |
463 } | 473 } |
464 | 474 |
465 | 475 |
466 static size_t ngx_http_userid_log_uid_set_getlen(ngx_http_request_t *r, | 476 static size_t |
467 uintptr_t data) | 477 ngx_http_userid_log_uid_set_getlen(ngx_http_request_t *r, uintptr_t data) |
468 { | 478 { |
469 ngx_http_userid_ctx_t *ctx; | 479 ngx_http_userid_ctx_t *ctx; |
470 ngx_http_userid_conf_t *conf; | 480 ngx_http_userid_conf_t *conf; |
471 | 481 |
472 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); | 482 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); |
479 | 489 |
480 return conf->name.len + 1 + 32; | 490 return conf->name.len + 1 + 32; |
481 } | 491 } |
482 | 492 |
483 | 493 |
484 static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf, | 494 static u_char * |
485 ngx_http_log_op_t *op) | 495 ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf, |
496 ngx_http_log_op_t *op) | |
486 { | 497 { |
487 ngx_http_userid_ctx_t *ctx; | 498 ngx_http_userid_ctx_t *ctx; |
488 ngx_http_userid_conf_t *conf; | 499 ngx_http_userid_conf_t *conf; |
489 | 500 |
490 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); | 501 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); |
504 ctx->uid_set[0], ctx->uid_set[1], | 515 ctx->uid_set[0], ctx->uid_set[1], |
505 ctx->uid_set[2], ctx->uid_set[3]); | 516 ctx->uid_set[2], ctx->uid_set[3]); |
506 } | 517 } |
507 | 518 |
508 | 519 |
509 static ngx_int_t ngx_http_userid_add_log_formats(ngx_conf_t *cf) | 520 static ngx_int_t |
521 ngx_http_userid_add_log_formats(ngx_conf_t *cf) | |
510 { | 522 { |
511 ngx_http_log_op_name_t *op; | 523 ngx_http_log_op_name_t *op; |
512 | 524 |
513 for (op = ngx_http_userid_log_fmt_ops; op->name.len; op++) { /* void */ } | 525 for (op = ngx_http_userid_log_fmt_ops; op->name.len; op++) { /* void */ } |
514 op->run = NULL; | 526 op->run = NULL; |
523 | 535 |
524 return NGX_OK; | 536 return NGX_OK; |
525 } | 537 } |
526 | 538 |
527 | 539 |
528 static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle) | 540 static ngx_int_t |
541 ngx_http_userid_init(ngx_cycle_t *cycle) | |
529 { | 542 { |
530 ngx_http_next_header_filter = ngx_http_top_header_filter; | 543 ngx_http_next_header_filter = ngx_http_top_header_filter; |
531 ngx_http_top_header_filter = ngx_http_userid_filter; | 544 ngx_http_top_header_filter = ngx_http_userid_filter; |
532 | 545 |
533 return NGX_OK; | 546 return NGX_OK; |
534 } | 547 } |
535 | 548 |
536 | 549 |
537 static void *ngx_http_userid_create_conf(ngx_conf_t *cf) | 550 static void * |
551 ngx_http_userid_create_conf(ngx_conf_t *cf) | |
538 { | 552 { |
539 ngx_http_userid_conf_t *conf; | 553 ngx_http_userid_conf_t *conf; |
540 | 554 |
541 if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_userid_conf_t)))) { | 555 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_userid_conf_t)); |
556 if (conf == NULL) { | |
542 return NGX_CONF_ERROR; | 557 return NGX_CONF_ERROR; |
543 } | 558 } |
544 | 559 |
545 /* | 560 /* |
546 * set by ngx_pcalloc(): | 561 * set by ngx_pcalloc(): |
561 | 576 |
562 return conf; | 577 return conf; |
563 } | 578 } |
564 | 579 |
565 | 580 |
566 static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, | 581 static char * |
567 void *child) | 582 ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, void *child) |
568 { | 583 { |
569 ngx_http_userid_conf_t *prev = parent; | 584 ngx_http_userid_conf_t *prev = parent; |
570 ngx_http_userid_conf_t *conf = child; | 585 ngx_http_userid_conf_t *conf = child; |
571 | 586 |
572 ngx_conf_merge_value(conf->enable, prev->enable, NGX_HTTP_USERID_OFF); | 587 ngx_conf_merge_value(conf->enable, prev->enable, NGX_HTTP_USERID_OFF); |
581 | 596 |
582 return NGX_CONF_OK; | 597 return NGX_CONF_OK; |
583 } | 598 } |
584 | 599 |
585 | 600 |
586 char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data) | 601 static char * |
602 ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data) | |
587 { | 603 { |
588 ngx_str_t *domain = data; | 604 ngx_str_t *domain = data; |
589 | 605 |
590 u_char *p, *new; | 606 u_char *p, *new; |
591 | 607 |
594 domain->data = (u_char *) ""; | 610 domain->data = (u_char *) ""; |
595 | 611 |
596 return NGX_CONF_OK; | 612 return NGX_CONF_OK; |
597 } | 613 } |
598 | 614 |
599 if (!(new = ngx_palloc(cf->pool, sizeof("; domain=") - 1 + domain->len))) { | 615 new = ngx_palloc(cf->pool, sizeof("; domain=") - 1 + domain->len); |
616 if (new == NULL) { | |
600 return NGX_CONF_ERROR; | 617 return NGX_CONF_ERROR; |
601 } | 618 } |
602 | 619 |
603 p = ngx_cpymem(new, "; domain=", sizeof("; domain=") - 1); | 620 p = ngx_cpymem(new, "; domain=", sizeof("; domain=") - 1); |
604 p = ngx_cpymem(p, domain->data, domain->len); | 621 p = ngx_cpymem(p, domain->data, domain->len); |
608 | 625 |
609 return NGX_CONF_OK; | 626 return NGX_CONF_OK; |
610 } | 627 } |
611 | 628 |
612 | 629 |
613 char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data) | 630 static char * |
631 ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data) | |
614 { | 632 { |
615 ngx_str_t *path = data; | 633 ngx_str_t *path = data; |
616 | 634 |
617 u_char *p, *new; | 635 u_char *p, *new; |
618 | 636 |
619 if (!(new = ngx_palloc(cf->pool, sizeof("; path=") - 1 + path->len))) { | 637 new = ngx_palloc(cf->pool, sizeof("; path=") - 1 + path->len); |
638 if (new == NULL) { | |
620 return NGX_CONF_ERROR; | 639 return NGX_CONF_ERROR; |
621 } | 640 } |
622 | 641 |
623 p = ngx_cpymem(new, "; path=", sizeof("; path=") - 1); | 642 p = ngx_cpymem(new, "; path=", sizeof("; path=") - 1); |
624 p = ngx_cpymem(p, path->data, path->len); | 643 p = ngx_cpymem(p, path->data, path->len); |
628 | 647 |
629 return NGX_CONF_OK; | 648 return NGX_CONF_OK; |
630 } | 649 } |
631 | 650 |
632 | 651 |
633 char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 652 static char * |
653 ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
634 { | 654 { |
635 ngx_http_userid_conf_t *ucf = conf; | 655 ngx_http_userid_conf_t *ucf = conf; |
636 | 656 |
637 ngx_str_t *value; | 657 ngx_str_t *value; |
638 | 658 |
663 | 683 |
664 return NGX_CONF_OK; | 684 return NGX_CONF_OK; |
665 } | 685 } |
666 | 686 |
667 | 687 |
668 char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data) | 688 static char * |
689 ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data) | |
669 { | 690 { |
670 ngx_str_t *p3p = data; | 691 ngx_str_t *p3p = data; |
671 | 692 |
672 if (p3p->len == 4 && ngx_strcmp(p3p->data, "none") == 0) { | 693 if (p3p->len == 4 && ngx_strcmp(p3p->data, "none") == 0) { |
673 p3p->len = 0; | 694 p3p->len = 0; |