diff options
author | Andrei Zmievski <andrei@php.net> | 1999-12-11 19:51:04 +0000 |
---|---|---|
committer | Andrei Zmievski <andrei@php.net> | 1999-12-11 19:51:04 +0000 |
commit | 33d82cb6d1dc8e1fc1a0e2e93c0a9a21cb55b46d (patch) | |
tree | f73007066ad0d36e06c606ac8c5618d43363b00f | |
parent | 17ff0f3af3acbfb611858a8a7ac2913e3309da9a (diff) | |
download | php-git-33d82cb6d1dc8e1fc1a0e2e93c0a9a21cb55b46d.tar.gz |
get_meta_tags() was using php_stristr() so it needed to be changed.
Optimized it to use php_memnstr() directly.
-rw-r--r-- | ext/standard/file.c | 17 | ||||
-rw-r--r-- | ext/standard/php_string.h | 3 |
2 files changed, 14 insertions, 6 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c index df2c2af36a..60e0b30d9a 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -386,6 +386,7 @@ PHP_FUNCTION(get_meta_tags) pval **filename, **arg2; FILE *fp; char buf[8192]; + char buf_lcase[8192]; int use_include_path = 0; int issock=0, socketd=0; int len, var_namelen; @@ -432,14 +433,19 @@ PHP_FUNCTION(get_meta_tags) } /* Now loop through the file and do the magic quotes thing if needed */ memset(buf, 0, 8191); - while((FP_FGETS(buf,8191,socketd,fp,issock) != NULL) - && !php_stristr(buf,"</head>")) { - if(php_stristr(buf,"<meta")) { + while((FP_FGETS(buf,8191,socketd,fp,issock) != NULL)) { + memcpy(buf_lcase, buf, 8191); + php_strtolower(buf_lcase, 8191); + if (php_memnstr(buf_lcase, "</head>", sizeof("</head>")-1, buf_lcase + 8191)) + break; + + if(php_memnstr(buf_lcase, "<meta", sizeof("<meta")-1, buf_lcase + 8191)) { memset(var_name,0,50); /* get the variable name from the name attribute of the meta tag */ - tmp=php_stristr(buf,"name=\""); + tmp = php_memnstr(buf_lcase, "name=\"", sizeof("name=\"")-1, buf_lcase + 8191); if(tmp) { + tmp = &buf[tmp - buf_lcase]; tmp+=6; end=strstr(tmp,"\""); if(end) { @@ -473,8 +479,9 @@ PHP_FUNCTION(get_meta_tags) } /* get the variable value from the content attribute of the meta tag */ - tmp=php_stristr(buf,"content=\""); + tmp = php_memnstr(buf_lcase, "content=\"", sizeof("content=\"")-1, buf_lcase + 8191); if(tmp) { + tmp = &buf[tmp - buf_lcase]; tmp+=9; end=strstr(tmp,"\""); if(end) { diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h index 2f9041491d..d7078f0201 100644 --- a/ext/standard/php_string.h +++ b/ext/standard/php_string.h @@ -92,7 +92,7 @@ extern PHPAPI char *php_addcslashes(char *string, int length, int *new_length, i extern PHPAPI void php_stripslashes(char *string, int *len); extern PHPAPI void php_stripcslashes(char *string, int *len); extern PHPAPI void php_dirname(char *str, int len); -extern PHPAPI char *php_stristr(unsigned char *s, unsigned char *t); +extern PHPAPI char *php_stristr(unsigned char *s, unsigned char *t, size_t s_len, size_t t_len); extern PHPAPI char *php_str_to_str(char *haystack, int length, char *needle, int needle_len, char *str, int str_len, int *_new_length); extern PHPAPI void php_trim(pval *str, pval *return_value, int mode); @@ -102,5 +102,6 @@ extern PHPAPI void php_char_to_str(char *str, uint len, char from, char *to, int extern PHPAPI void php_implode(pval *delim, pval *arr, pval *return_value); extern PHPAPI void php_explode(pval *delim, pval *str, pval *return_value); +PHPAPI inline char *php_memnstr(char *haystack, char *needle, int needle_len, char *end); #endif /* _PHPSTRING_H */ |