Mercurial > hg > nginx
comparison src/http/ngx_http_parse.c @ 2670:20a655d8a1f8
refactor ngx_http_arg() using ngx_strcasestrn(),
back out zero termination introduced in r2138
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sat, 04 Apr 2009 17:51:38 +0000 |
parents | 754ab3d3fe18 |
children | e50a2faac31d |
comparison
equal
deleted
inserted
replaced
2669:5e4d8bd4486c | 2670:20a655d8a1f8 |
---|---|
1484 | 1484 |
1485 | 1485 |
1486 ngx_int_t | 1486 ngx_int_t |
1487 ngx_http_arg(ngx_http_request_t *r, u_char *name, size_t len, ngx_str_t *value) | 1487 ngx_http_arg(ngx_http_request_t *r, u_char *name, size_t len, ngx_str_t *value) |
1488 { | 1488 { |
1489 u_char *p; | 1489 u_char *p, *last; |
1490 | 1490 |
1491 if (r->args.len == 0) { | 1491 if (r->args.len == 0) { |
1492 return NGX_DECLINED; | 1492 return NGX_DECLINED; |
1493 } | 1493 } |
1494 | 1494 |
1495 for (p = r->args.data; *p && *p != ' '; p++) { | 1495 p = r->args.data; |
1496 | 1496 last = p + r->args.len; |
1497 /* | 1497 |
1498 * although r->args.data is not null-terminated by itself, | 1498 for ( /* void */ ; p < last; p++) { |
1499 * however, there is null in the end of request line | 1499 |
1500 */ | 1500 /* we need '=' after name, so drop one char from last */ |
1501 | 1501 |
1502 p = ngx_strcasestrn(p, (char *) name, len - 1); | 1502 p = ngx_strlcasestrn(p, last - 1, name, len - 1); |
1503 | 1503 |
1504 if (p == NULL) { | 1504 if (p == NULL) { |
1505 return NGX_DECLINED; | 1505 return NGX_DECLINED; |
1506 } | 1506 } |
1507 | 1507 |
1508 if ((p == r->args.data || *(p - 1) == '&') && *(p + len) == '=') { | 1508 if ((p == r->args.data || *(p - 1) == '&') && *(p + len) == '=') { |
1509 | 1509 |
1510 value->data = p + len + 1; | 1510 value->data = p + len + 1; |
1511 | 1511 |
1512 p = (u_char *) ngx_strchr(p, '&'); | 1512 p = ngx_strlchr(p, last, '&'); |
1513 | 1513 |
1514 if (p == NULL) { | 1514 if (p == NULL) { |
1515 p = r->args.data + r->args.len; | 1515 p = r->args.data + r->args.len; |
1516 } | 1516 } |
1517 | 1517 |