diff options
author | Wez Furlong <wez@php.net> | 2002-03-20 14:38:13 +0000 |
---|---|---|
committer | Wez Furlong <wez@php.net> | 2002-03-20 14:38:13 +0000 |
commit | 3dbde958967b28cba3f03629b21081208d1e0ac2 (patch) | |
tree | 46061964bbb5dc9581cf9c8b8b9732bb96787592 | |
parent | 659a071e3df2f16cd21083d1dec8c19e199f7757 (diff) | |
download | php-git-3dbde958967b28cba3f03629b21081208d1e0ac2.tar.gz |
Make state parameter of php_strip_tags passed by reference.
Move state tracking to stream structure.
-rw-r--r-- | ext/standard/file.c | 12 | ||||
-rw-r--r-- | ext/standard/file.h | 1 | ||||
-rw-r--r-- | ext/standard/php_string.h | 2 | ||||
-rw-r--r-- | ext/standard/string.c | 10 | ||||
-rw-r--r-- | ext/zlib/zlib.c | 2 | ||||
-rwxr-xr-x | main/php_streams.h | 1 |
6 files changed, 16 insertions, 12 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c index cf76315f2b..0a6d1716a9 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -124,7 +124,6 @@ PHPAPI int php_file_le_stream(void) static void file_globals_ctor(php_file_globals *file_globals_p TSRMLS_DC) { zend_hash_init(&FG(ht_persistent_socks), 0, NULL, NULL, 1); - FG(fgetss_state) = 0; FG(pclose_ret) = 0; FG(def_chunk_size) = PHP_SOCK_CHUNK_SIZE; } @@ -592,7 +591,6 @@ PHP_NAMED_FUNCTION(php_if_fopen) if (stream == NULL) { RETURN_FALSE; } - FG(fgetss_state) = 0; php_stream_to_zval(stream, return_value); @@ -973,7 +971,7 @@ PHP_FUNCTION(fgetss) zval **fd, **bytes, **allow=NULL; int len, type; char *buf; - void *what; + php_stream *stream; char *allowed_tags=NULL; int allowed_tags_len=0; @@ -997,8 +995,8 @@ PHP_FUNCTION(fgetss) break; } - what = zend_fetch_resource(fd TSRMLS_CC, -1, "File-Handle", &type, 1, le_stream); - ZEND_VERIFY_RESOURCE(what); + stream = zend_fetch_resource(fd TSRMLS_CC, -1, "File-Handle", &type, 1, le_stream); + ZEND_VERIFY_RESOURCE(stream); convert_to_long_ex(bytes); len = Z_LVAL_PP(bytes); @@ -1011,13 +1009,13 @@ PHP_FUNCTION(fgetss) /*needed because recv doesnt set null char at end*/ memset(buf, 0, len + 1); - if (php_stream_gets((php_stream *) what, buf, len) == NULL) { + if (php_stream_gets(stream, buf, len) == NULL) { efree(buf); RETURN_FALSE; } /* strlen() can be used here since we are doing it on the return of an fgets() anyway */ - php_strip_tags(buf, strlen(buf), FG(fgetss_state), allowed_tags, allowed_tags_len); + php_strip_tags(buf, strlen(buf), &stream->fgetss_state, allowed_tags, allowed_tags_len); RETURN_STRING(buf, 0); } diff --git a/ext/standard/file.h b/ext/standard/file.h index 54d63469d1..ec17259ea4 100644 --- a/ext/standard/file.h +++ b/ext/standard/file.h @@ -105,7 +105,6 @@ typedef struct _php_meta_tags_data { php_meta_tags_token php_next_meta_token(php_meta_tags_data * TSRMLS_DC); typedef struct { - int fgetss_state; int pclose_ret; HashTable ht_persistent_socks; size_t def_chunk_size; diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h index 5f5a47dae4..8dfbb4704a 100644 --- a/ext/standard/php_string.h +++ b/ext/standard/php_string.h @@ -115,7 +115,7 @@ PHPAPI char *php_str_to_str(char *haystack, int length, char *needle, int needle_len, char *str, int str_len, int *_new_length); PHPAPI void php_trim(zval **str, zval *return_value, int mode TSRMLS_DC); PHPAPI void php_trim2(zval **str, zval **what, zval *return_value, int mode TSRMLS_DC); -PHPAPI void php_strip_tags(char *rbuf, int len, int state, char *allow, int allow_len); +PHPAPI void php_strip_tags(char *rbuf, int len, int *state, char *allow, int allow_len); PHPAPI int php_char_to_str(char *str, uint len, char from, char *to, int to_len, pval *result); diff --git a/ext/standard/string.c b/ext/standard/string.c index 09b2e46941..7c3ade6e4e 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -3095,7 +3095,7 @@ PHP_FUNCTION(strip_tags) } convert_to_string_ex(str); buf = estrndup(Z_STRVAL_PP(str), Z_STRLEN_PP(str)); - php_strip_tags(buf, Z_STRLEN_PP(str), 0, allowed_tags, allowed_tags_len); + php_strip_tags(buf, Z_STRLEN_PP(str), NULL, allowed_tags, allowed_tags_len); RETURN_STRING(buf, 0); } /* }}} */ @@ -3286,10 +3286,14 @@ int php_tag_find(char *tag, int len, char *set) { swm: Added ability to strip <?xml tags without assuming it PHP code. */ -PHPAPI void php_strip_tags(char *rbuf, int len, int state, char *allow, int allow_len) +PHPAPI void php_strip_tags(char *rbuf, int len, int *stateptr, char *allow, int allow_len) { char *tbuf, *buf, *p, *tp, *rp, c, lc; int br, i=0; + int state; + + if (stateptr) + state = *stateptr; buf = estrndup(rbuf, len); c = *buf; @@ -3417,6 +3421,8 @@ PHPAPI void php_strip_tags(char *rbuf, int len, int state, char *allow, int allo *rp = '\0'; efree(buf); if(allow) efree(tbuf); + if (stateptr) + *stateptr = state; } /* }}} */ diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 9c46953f83..ce5b67ffdf 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -517,7 +517,7 @@ PHP_FUNCTION(gzgetss) } /* strlen() can be used here since we are doing it on the return of an fgets() anyway */ - php_strip_tags(buf, strlen(buf), ZLIBG(gzgetss_state), allowed_tags, allowed_tags_len); + php_strip_tags(buf, strlen(buf), &ZLIBG(gzgetss_state), allowed_tags, allowed_tags_len); RETURN_STRING(buf, 0); } diff --git a/main/php_streams.h b/main/php_streams.h index 4a63edcd5c..efce5adcef 100755 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -118,6 +118,7 @@ struct _php_stream { void *wrapperthis; /* convenience pointer for a instance of a wrapper */ zval *wrapperdata; /* fgetwrapperdata retrieves this */ + int fgetss_state; /* for fgetss to handle multiline tags */ int is_persistent; char mode[16]; /* "rwb" etc. ala stdio */ int rsrc_id; /* used for auto-cleanup */ |