Mercurial > hg > nginx
comparison src/http/modules/ngx_http_userid_filter.c @ 410:48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 30 Aug 2004 15:42:44 +0000 |
parents | 8ac40cae79f0 |
children | 4765ded59eaa |
comparison
equal
deleted
inserted
replaced
409:8ac40cae79f0 | 410:48b9ad5ca1fc |
---|---|
44 static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf, | 44 static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf, |
45 uintptr_t data); | 45 uintptr_t data); |
46 static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf, | 46 static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf, |
47 uintptr_t data); | 47 uintptr_t data); |
48 | 48 |
49 static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle); | |
49 static ngx_int_t ngx_http_userid_pre_conf(ngx_conf_t *cf); | 50 static ngx_int_t ngx_http_userid_pre_conf(ngx_conf_t *cf); |
50 static void *ngx_http_userid_create_conf(ngx_conf_t *cf); | 51 static void *ngx_http_userid_create_conf(ngx_conf_t *cf); |
51 static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, | 52 static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, |
52 void *child); | 53 void *child); |
53 static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle); | 54 char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
54 | 55 |
55 | 56 |
56 static uint32_t sequencer_v1 = 1; | 57 static uint32_t sequencer_v1 = 1; |
57 static uint32_t sequencer_v2 = 0x03030302; | 58 static uint32_t sequencer_v2 = 0x03030302; |
58 | 59 |
109 offsetof(ngx_http_userid_conf_t, path), | 110 offsetof(ngx_http_userid_conf_t, path), |
110 NULL}, | 111 NULL}, |
111 | 112 |
112 { ngx_string("userid_expires"), | 113 { ngx_string("userid_expires"), |
113 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 114 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
114 ngx_conf_set_sec_slot, | 115 ngx_http_userid_expires, |
115 NGX_HTTP_LOC_CONF_OFFSET, | 116 NGX_HTTP_LOC_CONF_OFFSET, |
116 offsetof(ngx_http_userid_conf_t, expires), | 117 0, |
117 NULL}, | 118 NULL}, |
118 | 119 |
119 ngx_null_command | 120 ngx_null_command |
120 }; | 121 }; |
121 | 122 |
275 ngx_http_userid_conf_t *conf) | 276 ngx_http_userid_conf_t *conf) |
276 | 277 |
277 { | 278 { |
278 u_char *cookie, *p; | 279 u_char *cookie, *p; |
279 size_t len; | 280 size_t len; |
281 uint32_t service; | |
280 ngx_str_t src, dst; | 282 ngx_str_t src, dst; |
281 ngx_table_elt_t *set_cookie; | 283 ngx_table_elt_t *set_cookie; |
282 | 284 |
283 /* TODO: mutex for sequencers */ | 285 /* TODO: mutex for sequencers */ |
284 | 286 |
287 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
288 "service: %d", r->in_addr); | |
289 | |
285 if (conf->enable == NGX_HTTP_USERID_V1) { | 290 if (conf->enable == NGX_HTTP_USERID_V1) { |
286 ctx->uid_set[0] = conf->service; | 291 if (conf->service == NGX_CONF_UNSET) { |
292 ctx->uid_set[0] = 0; | |
293 } else { | |
294 ctx->uid_set[0] = htonl(conf->service); | |
295 } | |
296 | |
287 ctx->uid_set[1] = ngx_time(); | 297 ctx->uid_set[1] = ngx_time(); |
288 ctx->uid_set[2] = ngx_pid; | 298 ctx->uid_set[2] = ngx_pid; |
289 ctx->uid_set[3] = sequencer_v1; | 299 ctx->uid_set[3] = sequencer_v1; |
290 sequencer_v1 += 0x100; | 300 sequencer_v1 += 0x100; |
291 | 301 |
292 } else { | 302 } else { |
293 ctx->uid_set[0] = htonl(conf->service); | 303 if (conf->service == NGX_CONF_UNSET) { |
304 ctx->uid_set[0] = htonl(r->in_addr); | |
305 } else { | |
306 ctx->uid_set[0] = htonl(conf->service); | |
307 } | |
308 | |
294 ctx->uid_set[1] = htonl(ngx_time()); | 309 ctx->uid_set[1] = htonl(ngx_time()); |
295 ctx->uid_set[2] = htonl(ngx_pid); | 310 ctx->uid_set[2] = htonl(ngx_pid); |
296 ctx->uid_set[3] = htonl(sequencer_v2); | 311 ctx->uid_set[3] = htonl(sequencer_v2); |
297 sequencer_v2 += 0x100; | 312 sequencer_v2 += 0x100; |
298 if (sequencer_v2 < 0x03030302) { | 313 if (sequencer_v2 < 0x03030302) { |
430 ctx->uid_set[0], ctx->uid_set[1], | 445 ctx->uid_set[0], ctx->uid_set[1], |
431 ctx->uid_set[2], ctx->uid_set[3]); | 446 ctx->uid_set[2], ctx->uid_set[3]); |
432 } | 447 } |
433 | 448 |
434 | 449 |
450 static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle) | |
451 { | |
452 ngx_http_next_header_filter = ngx_http_top_header_filter; | |
453 ngx_http_top_header_filter = ngx_http_userid_filter; | |
454 | |
455 return NGX_OK; | |
456 } | |
457 | |
458 | |
435 static ngx_int_t ngx_http_userid_pre_conf(ngx_conf_t *cf) | 459 static ngx_int_t ngx_http_userid_pre_conf(ngx_conf_t *cf) |
436 { | 460 { |
437 ngx_http_log_op_name_t *op; | 461 ngx_http_log_op_name_t *op; |
438 | 462 |
439 for (op = ngx_http_userid_log_fmt_ops; op->name.len; op++) { /* void */ } | 463 for (op = ngx_http_userid_log_fmt_ops; op->name.len; op++) { /* void */ } |
471 conf->path.date = NULL; | 495 conf->path.date = NULL; |
472 | 496 |
473 */ | 497 */ |
474 | 498 |
475 conf->enable = NGX_CONF_UNSET; | 499 conf->enable = NGX_CONF_UNSET; |
500 conf->service = NGX_CONF_UNSET; | |
476 conf->expires = NGX_CONF_UNSET; | 501 conf->expires = NGX_CONF_UNSET; |
477 | 502 |
478 return conf; | 503 return conf; |
479 } | 504 } |
480 | 505 |
489 | 514 |
490 ngx_conf_merge_str_value(conf->name, prev->name, "uid"); | 515 ngx_conf_merge_str_value(conf->name, prev->name, "uid"); |
491 ngx_conf_merge_str_value(conf->domain, prev->domain, "."); | 516 ngx_conf_merge_str_value(conf->domain, prev->domain, "."); |
492 ngx_conf_merge_str_value(conf->path, prev->path, "/"); | 517 ngx_conf_merge_str_value(conf->path, prev->path, "/"); |
493 | 518 |
519 ngx_conf_merge_value(conf->service, prev->service, NGX_CONF_UNSET); | |
494 ngx_conf_merge_sec_value(conf->expires, prev->expires, 0); | 520 ngx_conf_merge_sec_value(conf->expires, prev->expires, 0); |
495 | 521 |
496 return NGX_CONF_OK; | 522 return NGX_CONF_OK; |
497 } | 523 } |
498 | 524 |
499 | 525 |
500 static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle) | 526 char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
501 { | 527 { |
502 ngx_http_next_header_filter = ngx_http_top_header_filter; | 528 ngx_http_userid_conf_t *ucf = conf; |
503 ngx_http_top_header_filter = ngx_http_userid_filter; | 529 |
504 | 530 ngx_str_t *value; |
505 return NGX_OK; | 531 |
506 } | 532 if (ucf->expires != NGX_CONF_UNSET) { |
533 return "is duplicate"; | |
534 } | |
535 | |
536 value = cf->args->elts; | |
537 | |
538 if (ngx_strcmp(value[1].data, "max") == 0) { | |
539 ucf->expires = NGX_HTTP_USERID_MAX_EXPIRES; | |
540 return NGX_CONF_OK; | |
541 } | |
542 | |
543 if (ngx_strcmp(value[1].data, "off") == 0) { | |
544 ucf->expires = 0; | |
545 return NGX_CONF_OK; | |
546 } | |
547 | |
548 ucf->expires = ngx_parse_time(&value[1], 1); | |
549 if (ucf->expires == NGX_ERROR) { | |
550 return "invalid value"; | |
551 } | |
552 | |
553 if (ucf->expires == NGX_PARSE_LARGE_TIME) { | |
554 return "value must be less than 68 years"; | |
555 } | |
556 | |
557 return NGX_CONF_OK; | |
558 } |