# HG changeset patch # User Igor Sysoev # Date 1193670631 0 # Node ID ca6845b191137faf98c8302ac3a78a21d523fd40 # Parent a0ec4734d2e980014766975e36d9125ab86dbd4a r1553, r1554 merge: ngx_strnstr() diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c --- a/src/core/ngx_string.c +++ b/src/core/ngx_string.c @@ -503,6 +503,40 @@ ngx_strncasecmp(u_char *s1, u_char *s2, } +u_char * +ngx_strnstr(u_char *s1, char *s2, size_t len) +{ + u_char c1, c2; + size_t n; + + c2 = *(u_char *) s2++; + + n = ngx_strlen(s2); + + do { + do { + if (len-- == 0) { + return NULL; + } + + c1 = *s1++; + + if (c1 == 0) { + return NULL; + } + + } while (c1 != c2); + + if (n > len) { + return NULL; + } + + } while (ngx_strncmp(s1, (u_char *) s2, n) != 0); + + return --s1; +} + + /* * ngx_strstrn() and ngx_strcasestrn() are intended to search for static * substring with known length in null-terminated string. The argument n diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h --- a/src/core/ngx_string.h +++ b/src/core/ngx_string.h @@ -126,6 +126,8 @@ u_char *ngx_vsnprintf(u_char *buf, size_ ngx_int_t ngx_strcasecmp(u_char *s1, u_char *s2); ngx_int_t ngx_strncasecmp(u_char *s1, u_char *s2, size_t n); +u_char *ngx_strnstr(u_char *s1, char *s2, size_t n); + u_char *ngx_strstrn(u_char *s1, char *s2, size_t n); u_char *ngx_strcasestrn(u_char *s1, char *s2, size_t n); diff --git a/src/http/modules/ngx_http_flv_module.c b/src/http/modules/ngx_http_flv_module.c --- a/src/http/modules/ngx_http_flv_module.c +++ b/src/http/modules/ngx_http_flv_module.c @@ -167,7 +167,7 @@ ngx_http_flv_handler(ngx_http_request_t i = 1; if (r->args.len) { - p = (u_char *) ngx_strstr(r->args.data, "start="); + p = (u_char *) ngx_strnstr(r->args.data, "start=", r->args.len); if (p) { p += 6;