comparison src/http/modules/ngx_http_userid_filter_module.c @ 3661:8649a0c0f09d

change logic introduced in r3649: *) now $uid_set is cacheable again *) allow to see at any processing stage that uid cookie is remarked
author Igor Sysoev <igor@sysoev.ru>
date Wed, 30 Jun 2010 14:30:55 +0000
parents 7e69af2dd93c
children bfab2536197b
comparison
equal deleted inserted replaced
3660:564b4ca17cb3 3661:8649a0c0f09d
209 209
210 if (ctx == NULL) { 210 if (ctx == NULL) {
211 return NGX_ERROR; 211 return NGX_ERROR;
212 } 212 }
213 213
214 if (ctx->uid_got[3] != 0) {
215
216 if (conf->mark == '\0') {
217 return ngx_http_next_header_filter(r);
218
219 } else {
220 if (ctx->cookie.len > 23
221 && ctx->cookie.data[22] == conf->mark
222 && ctx->cookie.data[23] == '=')
223 {
224 return ngx_http_next_header_filter(r);
225 }
226 }
227 }
228
229 if (ngx_http_userid_set_uid(r, ctx, conf) == NGX_OK) { 214 if (ngx_http_userid_set_uid(r, ctx, conf) == NGX_OK) {
230 return ngx_http_next_header_filter(r); 215 return ngx_http_next_header_filter(r);
231 } 216 }
232 217
233 return NGX_ERROR; 218 return NGX_ERROR;
282 267
283 if (ctx == NULL) { 268 if (ctx == NULL) {
284 return NGX_ERROR; 269 return NGX_ERROR;
285 } 270 }
286 271
272 if (ngx_http_userid_create_uid(r->main, ctx, conf) != NGX_OK) {
273 return NGX_ERROR;
274 }
275
287 if (ctx->uid_set[3] == 0) { 276 if (ctx->uid_set[3] == 0) {
288 277 v->not_found = 1;
289 if (ctx->uid_got[3] != 0) { 278 return NGX_OK;
290 v->not_found = 1;
291 return NGX_OK;
292 }
293
294 if (ngx_http_userid_create_uid(r->main, ctx, conf) != NGX_OK) {
295 return NGX_ERROR;
296 }
297 } 279 }
298 280
299 return ngx_http_userid_variable(r->main, v, &conf->name, ctx->uid_set); 281 return ngx_http_userid_variable(r->main, v, &conf->name, ctx->uid_set);
300 } 282 }
301 283
377 u_char *cookie, *p; 359 u_char *cookie, *p;
378 size_t len; 360 size_t len;
379 ngx_str_t src, dst; 361 ngx_str_t src, dst;
380 ngx_table_elt_t *set_cookie, *p3p; 362 ngx_table_elt_t *set_cookie, *p3p;
381 363
364 if (ngx_http_userid_create_uid(r, ctx, conf) != NGX_OK) {
365 return NGX_ERROR;
366 }
367
382 if (ctx->uid_set[3] == 0) { 368 if (ctx->uid_set[3] == 0) {
383 if (ctx->uid_got[3] == 0) { 369 return NGX_OK;
384 if (ngx_http_userid_create_uid(r, ctx, conf) != NGX_OK) {
385 return NGX_ERROR;
386 }
387
388 } else {
389 ctx->uid_set[0] = ctx->uid_got[0];
390 ctx->uid_set[1] = ctx->uid_got[1];
391 ctx->uid_set[2] = ctx->uid_got[2];
392 ctx->uid_set[3] = ctx->uid_got[3];
393 }
394 } 370 }
395 371
396 len = conf->name.len + 1 + ngx_base64_encoded_length(16) + conf->path.len; 372 len = conf->name.len + 1 + ngx_base64_encoded_length(16) + conf->path.len;
397 373
398 if (conf->expires) { 374 if (conf->expires) {
480 struct sockaddr_in *sin; 456 struct sockaddr_in *sin;
481 #if (NGX_HAVE_INET6) 457 #if (NGX_HAVE_INET6)
482 u_char *p; 458 u_char *p;
483 struct sockaddr_in6 *sin6; 459 struct sockaddr_in6 *sin6;
484 #endif 460 #endif
461
462 if (ctx->uid_set[3] != 0) {
463 return NGX_OK;
464 }
465
466 if (ctx->uid_got[3] != 0) {
467
468 if (conf->mark == '\0'
469 || (ctx->cookie.len > 23
470 && ctx->cookie.data[22] == conf->mark
471 && ctx->cookie.data[23] == '='))
472 {
473 return NGX_OK;
474 }
475
476 ctx->uid_set[0] = ctx->uid_got[0];
477 ctx->uid_set[1] = ctx->uid_got[1];
478 ctx->uid_set[2] = ctx->uid_got[2];
479 ctx->uid_set[3] = ctx->uid_got[3];
480
481 return NGX_OK;
482 }
485 483
486 /* 484 /*
487 * TODO: in the threaded mode the sequencers should be in TLS and their 485 * TODO: in the threaded mode the sequencers should be in TLS and their
488 * ranges should be divided between threads 486 * ranges should be divided between threads
489 */ 487 */
577 return NGX_ERROR; 575 return NGX_ERROR;
578 } 576 }
579 577
580 var->get_handler = ngx_http_userid_got_variable; 578 var->get_handler = ngx_http_userid_got_variable;
581 579
582 var = ngx_http_add_variable(cf, &ngx_http_userid_set, 580 var = ngx_http_add_variable(cf, &ngx_http_userid_set, 0);
583 NGX_HTTP_VAR_NOCACHEABLE);
584 if (var == NULL) { 581 if (var == NULL) {
585 return NGX_ERROR; 582 return NGX_ERROR;
586 } 583 }
587 584
588 var->get_handler = ngx_http_userid_set_variable; 585 var->get_handler = ngx_http_userid_set_variable;