Mercurial > hg > nginx
comparison src/http/modules/ngx_http_userid_filter.c @ 415:3c56e834be46
nginx-0.0.10-2004-09-05-23:54:02 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 05 Sep 2004 19:54:02 +0000 |
parents | 199cd29f35a3 |
children | b9bd635011de |
comparison
equal
deleted
inserted
replaced
414:388a842cbbe1 | 415:3c56e834be46 |
---|---|
194 | 194 |
195 static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r, | 195 static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r, |
196 ngx_http_userid_ctx_t *ctx, | 196 ngx_http_userid_ctx_t *ctx, |
197 ngx_http_userid_conf_t *conf) | 197 ngx_http_userid_conf_t *conf) |
198 { | 198 { |
199 u_char *start, *last, *end; | 199 u_char *start, *last, *end; |
200 ngx_uint_t *cookies, i; | 200 ngx_uint_t i; |
201 ngx_str_t src, dst; | 201 ngx_str_t src, dst; |
202 ngx_table_elt_t *headers; | 202 ngx_table_elt_t **cookies; |
203 | 203 |
204 headers = r->headers_in.headers.elts; | |
205 cookies = r->headers_in.cookies.elts; | 204 cookies = r->headers_in.cookies.elts; |
206 | 205 |
207 for (i = 0; i < r->headers_in.cookies.nelts; i++) { | 206 for (i = 0; i < r->headers_in.cookies.nelts; i++) { |
208 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 207 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
209 "cookie: %d:\"%s\"", | 208 "cookie: \"%s\"", cookies[i]->value.data); |
210 cookies[i], | 209 |
211 headers[cookies[i]].value.data); | 210 end = cookies[i]->value.data + cookies[i]->value.len; |
212 | 211 |
213 end = headers[cookies[i]].value.data + headers[cookies[i]].value.len; | 212 for (start = cookies[i]->value.data; start < end; /* void */) { |
214 | 213 |
215 for (start = headers[cookies[i]].value.data; start < end; /* void */) { | 214 if (conf->name.len >= cookies[i]->value.len |
216 | |
217 if (conf->name.len >= headers[cookies[i]].value.len | |
218 || ngx_strncmp(start, conf->name.data, conf->name.len) != 0) | 215 || ngx_strncmp(start, conf->name.data, conf->name.len) != 0) |
219 { | 216 { |
220 start += conf->name.len; | 217 start += conf->name.len; |
221 while (start < end && *start++ != ';') { /* void */ } | 218 while (start < end && *start++ != ';') { /* void */ } |
222 | 219 |
239 for (last = start; last < end && *last != ';'; last++) { /**/ } | 236 for (last = start; last < end && *last != ';'; last++) { /**/ } |
240 | 237 |
241 if (last - start < 22) { | 238 if (last - start < 22) { |
242 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 239 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
243 "client sent too short userid cookie \"%s\"", | 240 "client sent too short userid cookie \"%s\"", |
244 headers[cookies[i]].value.data); | 241 cookies[i]->value.data); |
245 break; | 242 break; |
246 } | 243 } |
247 | 244 |
248 /* | 245 /* |
249 * we have to limit encoded string to 22 characters | 246 * we have to limit encoded string to 22 characters |
256 dst.data = (u_char *) ctx->uid_got; | 253 dst.data = (u_char *) ctx->uid_got; |
257 | 254 |
258 if (ngx_decode_base64(&src, &dst) == NGX_ERROR) { | 255 if (ngx_decode_base64(&src, &dst) == NGX_ERROR) { |
259 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 256 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
260 "client sent invalid userid cookie \"%s\"", | 257 "client sent invalid userid cookie \"%s\"", |
261 headers[cookies[i]].value.data); | 258 cookies[i]->value.data); |
262 break; | 259 break; |
263 } | 260 } |
264 | 261 |
265 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 262 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
266 "uid: %08X%08X%08X%08X", | 263 "uid: %08X%08X%08X%08X", |
382 *p = '\0'; | 379 *p = '\0'; |
383 | 380 |
384 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 381 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
385 "uid cookie: \"%s\"", cookie); | 382 "uid cookie: \"%s\"", cookie); |
386 | 383 |
387 set_cookie = ngx_http_add_header(&r->headers_out, ngx_http_headers_out); | 384 if (!(set_cookie = ngx_push_list(&r->headers_out.headers))) { |
388 if (set_cookie == NULL) { | |
389 return NGX_ERROR; | 385 return NGX_ERROR; |
390 } | 386 } |
391 | 387 |
392 set_cookie->key.len = sizeof("Set-Cookie") - 1; | 388 set_cookie->key.len = sizeof("Set-Cookie") - 1; |
393 set_cookie->key.data = (u_char *) "Set-Cookie"; | 389 set_cookie->key.data = (u_char *) "Set-Cookie"; |