comparison src/http/modules/ngx_http_userid_filter_module.c @ 1651:555ee689cecc

use usec and pid as start value
author Igor Sysoev <igor@sysoev.ru>
date Sat, 24 Nov 2007 10:43:15 +0000
parents 02a22cd5282a
children bb72f7518992
comparison
equal deleted inserted replaced
1650:d640570c342a 1651:555ee689cecc
59 static char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, 59 static char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd,
60 void *conf); 60 void *conf);
61 static char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data); 61 static char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data);
62 static char *ngx_http_userid_mark(ngx_conf_t *cf, ngx_command_t *cmd, 62 static char *ngx_http_userid_mark(ngx_conf_t *cf, ngx_command_t *cmd,
63 void *conf); 63 void *conf);
64 64 static ngx_int_t ngx_http_userid_init_worker(ngx_cycle_t *cycle);
65 65
66 66
67
68 static uint32_t start_value;
67 static uint32_t sequencer_v1 = 1; 69 static uint32_t sequencer_v1 = 1;
68 static uint32_t sequencer_v2 = 0x03030302; 70 static uint32_t sequencer_v2 = 0x03030302;
69 71
70 72
71 static u_char expires[] = "; expires=Thu, 31-Dec-37 23:55:55 GMT"; 73 static u_char expires[] = "; expires=Thu, 31-Dec-37 23:55:55 GMT";
171 &ngx_http_userid_filter_module_ctx, /* module context */ 173 &ngx_http_userid_filter_module_ctx, /* module context */
172 ngx_http_userid_commands, /* module directives */ 174 ngx_http_userid_commands, /* module directives */
173 NGX_HTTP_MODULE, /* module type */ 175 NGX_HTTP_MODULE, /* module type */
174 NULL, /* init master */ 176 NULL, /* init master */
175 NULL, /* init module */ 177 NULL, /* init module */
176 NULL, /* init process */ 178 ngx_http_userid_init_worker, /* init process */
177 NULL, /* init thread */ 179 NULL, /* init thread */
178 NULL, /* exit thread */ 180 NULL, /* exit thread */
179 NULL, /* exit process */ 181 NULL, /* exit process */
180 NULL, /* exit master */ 182 NULL, /* exit master */
181 NGX_MODULE_V1_PADDING 183 NGX_MODULE_V1_PADDING
317 ctx->uid_set[0] = 0; 319 ctx->uid_set[0] = 0;
318 } else { 320 } else {
319 ctx->uid_set[0] = conf->service; 321 ctx->uid_set[0] = conf->service;
320 } 322 }
321 ctx->uid_set[1] = (uint32_t) ngx_time(); 323 ctx->uid_set[1] = (uint32_t) ngx_time();
322 ctx->uid_set[2] = ngx_pid; 324 ctx->uid_set[2] = start_value;
323 ctx->uid_set[3] = sequencer_v1; 325 ctx->uid_set[3] = sequencer_v1;
324 sequencer_v1 += 0x100; 326 sequencer_v1 += 0x100;
325 327
326 } else { 328 } else {
327 if (conf->service == NGX_CONF_UNSET) { 329 if (conf->service == NGX_CONF_UNSET) {
344 } else { 346 } else {
345 ctx->uid_set[0] = htonl(conf->service); 347 ctx->uid_set[0] = htonl(conf->service);
346 } 348 }
347 349
348 ctx->uid_set[1] = htonl((uint32_t) ngx_time()); 350 ctx->uid_set[1] = htonl((uint32_t) ngx_time());
349 ctx->uid_set[2] = htonl(ngx_pid); 351 ctx->uid_set[2] = htonl(start_value);
350 ctx->uid_set[3] = htonl(sequencer_v2); 352 ctx->uid_set[3] = htonl(sequencer_v2);
351 sequencer_v2 += 0x100; 353 sequencer_v2 += 0x100;
352 if (sequencer_v2 < 0x03030302) { 354 if (sequencer_v2 < 0x03030302) {
353 sequencer_v2 = 0x03030302; 355 sequencer_v2 = 0x03030302;
354 } 356 }
704 706
705 ucf->mark = value[1].data[0]; 707 ucf->mark = value[1].data[0];
706 708
707 return NGX_CONF_OK; 709 return NGX_CONF_OK;
708 } 710 }
711
712
713 static ngx_int_t
714 ngx_http_userid_init_worker(ngx_cycle_t *cycle)
715 {
716 struct timeval tp;
717
718 ngx_gettimeofday(&tp);
719
720 /* use the most significant usec part that fits to 16 bits */
721 start_value = ((tp.tv_usec / 20) << 16) | ngx_pid;
722
723 return NGX_OK;
724 }
725