comparison src/http/modules/ngx_http_uwsgi_module.c @ 3552:40eba0271b1d

improve uwsgi_modifierX processing: *) use ngx_conf_set_num_slot() *) check bounds *) check duplicates
author Igor Sysoev <igor@sysoev.ru>
date Tue, 01 Jun 2010 20:19:57 +0000
parents fb4cbe681e81
children b4a60663f6c0
comparison
equal deleted inserted replaced
3551:fb4cbe681e81 3552:40eba0271b1d
22 ngx_array_t *uwsgi_lengths; 22 ngx_array_t *uwsgi_lengths;
23 ngx_array_t *uwsgi_values; 23 ngx_array_t *uwsgi_values;
24 24
25 ngx_str_t uwsgi_string; 25 ngx_str_t uwsgi_string;
26 26
27 u_char modifier1; 27 ngx_uint_t modifier1;
28 u_char modifier2; 28 ngx_uint_t modifier2;
29 } ngx_http_uwsgi_loc_conf_t; 29 } ngx_http_uwsgi_loc_conf_t;
30 30
31 typedef struct { 31 typedef struct {
32 ngx_uint_t status; 32 ngx_uint_t status;
33 ngx_uint_t status_count; 33 ngx_uint_t status_count;
50 static ngx_int_t ngx_http_uwsgi_process_header(ngx_http_request_t *r); 50 static ngx_int_t ngx_http_uwsgi_process_header(ngx_http_request_t *r);
51 static void ngx_http_uwsgi_abort_request(ngx_http_request_t *r); 51 static void ngx_http_uwsgi_abort_request(ngx_http_request_t *r);
52 static void ngx_http_uwsgi_finalize_request(ngx_http_request_t *r, 52 static void ngx_http_uwsgi_finalize_request(ngx_http_request_t *r,
53 ngx_int_t rc); 53 ngx_int_t rc);
54 54
55 static char *ngx_http_uwsgi_modifier1(ngx_conf_t *cf, ngx_command_t *cmd,
56 void *conf);
57
58 static char *ngx_http_uwsgi_modifier2(ngx_conf_t *cf, ngx_command_t *cmd,
59 void *conf);
60
61 static ngx_int_t ngx_http_uwsgi_add_variables(ngx_conf_t *cf); 55 static ngx_int_t ngx_http_uwsgi_add_variables(ngx_conf_t *cf);
62 static void *ngx_http_uwsgi_create_loc_conf(ngx_conf_t *cf); 56 static void *ngx_http_uwsgi_create_loc_conf(ngx_conf_t *cf);
63 static char *ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent, 57 static char *ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent,
64 void *child); 58 void *child);
65 59
66 static char *ngx_http_uwsgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, 60 static char *ngx_http_uwsgi_pass(ngx_conf_t *cf, ngx_command_t *cmd,
67 void *conf); 61 void *conf);
62
63
64 static ngx_conf_num_bounds_t ngx_http_uwsgi_modifier_bounds = {
65 ngx_conf_check_num_bounds, 0, 255
66 };
68 67
69 68
70 static ngx_conf_bitmask_t ngx_http_uwsgi_next_upstream_masks[] = { 69 static ngx_conf_bitmask_t ngx_http_uwsgi_next_upstream_masks[] = {
71 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR }, 70 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR },
72 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT }, 71 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT },
101 0, 100 0,
102 NULL }, 101 NULL },
103 102
104 { ngx_string("uwsgi_modifier1"), 103 { ngx_string("uwsgi_modifier1"),
105 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 104 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
106 ngx_http_uwsgi_modifier1, 105 ngx_conf_set_num_slot,
107 NGX_HTTP_LOC_CONF_OFFSET, 106 NGX_HTTP_LOC_CONF_OFFSET,
108 0, 107 offsetof(ngx_http_uwsgi_loc_conf_t, modifier1),
109 NULL }, 108 &ngx_http_uwsgi_modifier_bounds },
110 109
111 { ngx_string("uwsgi_modifier2"), 110 { ngx_string("uwsgi_modifier2"),
112 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 111 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
113 ngx_http_uwsgi_modifier2, 112 ngx_conf_set_num_slot,
114 NGX_HTTP_LOC_CONF_OFFSET, 113 NGX_HTTP_LOC_CONF_OFFSET,
115 0, 114 offsetof(ngx_http_uwsgi_loc_conf_t, modifier2),
116 NULL }, 115 &ngx_http_uwsgi_modifier_bounds },
117 116
118 { ngx_string("uwsgi_ignore_client_abort"), 117 { ngx_string("uwsgi_ignore_client_abort"),
119 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, 118 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
120 ngx_conf_set_flag_slot, 119 ngx_conf_set_flag_slot,
121 NGX_HTTP_LOC_CONF_OFFSET, 120 NGX_HTTP_LOC_CONF_OFFSET,
510 return NGX_ERROR; 509 return NGX_ERROR;
511 } 510 }
512 511
513 cl->buf = b; 512 cl->buf = b;
514 513
515 *b->last++ = uwcf->modifier1; 514 *b->last++ = (u_char) uwcf->modifier1;
516 *b->last++ = (u_char) (len & 0xff); 515 *b->last++ = (u_char) (len & 0xff);
517 *b->last++ = (u_char) ((len >> 8) & 0xff); 516 *b->last++ = (u_char) ((len >> 8) & 0xff);
518 *b->last++ = uwcf->modifier2; 517 *b->last++ = (u_char) uwcf->modifier2;
519 518
520 if (uwcf->params_len) { 519 if (uwcf->params_len) {
521 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); 520 ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
522 521
523 e.ip = uwcf->params->elts; 522 e.ip = uwcf->params->elts;
1091 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_uwsgi_loc_conf_t)); 1090 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_uwsgi_loc_conf_t));
1092 if (conf == NULL) { 1091 if (conf == NULL) {
1093 return NULL; 1092 return NULL;
1094 } 1093 }
1095 1094
1095 conf->modifier1 = NGX_CONF_UNSET_UINT;
1096 conf->modifier2 = NGX_CONF_UNSET_UINT;
1097
1096 conf->upstream.store = NGX_CONF_UNSET; 1098 conf->upstream.store = NGX_CONF_UNSET;
1097 conf->upstream.store_access = NGX_CONF_UNSET_UINT; 1099 conf->upstream.store_access = NGX_CONF_UNSET_UINT;
1098 conf->upstream.buffering = NGX_CONF_UNSET; 1100 conf->upstream.buffering = NGX_CONF_UNSET;
1099 conf->upstream.ignore_client_abort = NGX_CONF_UNSET; 1101 conf->upstream.ignore_client_abort = NGX_CONF_UNSET;
1100 1102
1318 if (conf->uwsgi_lengths == NULL) { 1320 if (conf->uwsgi_lengths == NULL) {
1319 conf->uwsgi_lengths = prev->uwsgi_lengths; 1321 conf->uwsgi_lengths = prev->uwsgi_lengths;
1320 conf->uwsgi_values = prev->uwsgi_values; 1322 conf->uwsgi_values = prev->uwsgi_values;
1321 } 1323 }
1322 1324
1323 if (conf->modifier1 == 0) { 1325 ngx_conf_merge_uint_value(conf->modifier1, prev->modifier1, 0);
1324 conf->modifier1 = prev->modifier1; 1326 ngx_conf_merge_uint_value(conf->modifier2, prev->modifier2, 0);
1325 }
1326
1327 if (conf->modifier2 == 0) {
1328 conf->modifier2 = prev->modifier2;
1329 }
1330 1327
1331 if (conf->params_source == NULL) { 1328 if (conf->params_source == NULL) {
1332 conf->flushes = prev->flushes; 1329 conf->flushes = prev->flushes;
1333 conf->params_len = prev->params_len; 1330 conf->params_len = prev->params_len;
1334 conf->params = prev->params; 1331 conf->params = prev->params;
1474 clcf->auto_redirect = 1; 1471 clcf->auto_redirect = 1;
1475 } 1472 }
1476 1473
1477 return NGX_CONF_OK; 1474 return NGX_CONF_OK;
1478 } 1475 }
1479
1480
1481 static char *
1482 ngx_http_uwsgi_modifier1(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1483 {
1484 ngx_http_uwsgi_loc_conf_t *uwcf = conf;
1485 ngx_str_t *value;
1486
1487 value = cf->args->elts;
1488
1489 uwcf->modifier1 = (u_char) ngx_atoi(value[1].data, value[1].len);
1490
1491 return NGX_CONF_OK;
1492 }
1493
1494
1495 static char *
1496 ngx_http_uwsgi_modifier2(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1497 {
1498 ngx_http_uwsgi_loc_conf_t *uwcf = conf;
1499
1500 ngx_str_t *value;
1501
1502 value = cf->args->elts;
1503
1504 uwcf->modifier2 = (u_char) ngx_atoi(value[1].data, value[1].len);
1505
1506 return NGX_CONF_OK;
1507 }