mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Make state parameter of php_strip_tags passed by reference.
Move state tracking to stream structure.
This commit is contained in:
parent
659a071e3d
commit
3dbde95896
6 changed files with 16 additions and 12 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue