Refacting smart_str

This commit is contained in:
Xinchen Hui 2014-02-18 17:42:46 +08:00
parent 1c4f3d39a8
commit 43b03c74b3
21 changed files with 256 additions and 275 deletions

View File

@ -554,7 +554,7 @@ END_EXTERN_C()
} while (0)
#define ZVAL_EMPTY_STRING(z) do { \
ZVAL_STRINGL(z, "", 0); \
ZVAL_STR(z, STR_EMPTY_ALLOC()); \
} while (0)
#define ZVAL_PSTRINGL(z, s, l) do { \

View File

@ -1046,7 +1046,7 @@ char *php_date_short_day_name(timelib_sll y, timelib_sll m, timelib_sll d)
/* }}} */
/* {{{ date_format - (gm)date helper */
static char *date_format(char *format, int format_len, timelib_time *t, int localtime)
static zend_string *date_format(char *format, int format_len, timelib_time *t, int localtime)
{
smart_str string = {0};
int i, length = 0;
@ -1057,7 +1057,7 @@ static char *date_format(char *format, int format_len, timelib_time *t, int loca
int weekYearSet = 0;
if (!format_len) {
return estrdup("");
return STR_EMPTY_ALLOC();
}
if (localtime) {
@ -1201,7 +1201,7 @@ static char *date_format(char *format, int format_len, timelib_time *t, int loca
timelib_time_offset_dtor(offset);
}
return string.c;
return string.s;
}
static void php_date(INTERNAL_FUNCTION_PARAMETERS, int localtime)
@ -1209,7 +1209,6 @@ static void php_date(INTERNAL_FUNCTION_PARAMETERS, int localtime)
char *format;
int format_len;
long ts;
char *string;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &format, &format_len, &ts) == FAILURE) {
RETURN_FALSE;
@ -1218,18 +1217,15 @@ static void php_date(INTERNAL_FUNCTION_PARAMETERS, int localtime)
ts = time(NULL);
}
string = php_format_date(format, format_len, ts, localtime TSRMLS_CC);
//??? RETVAL_STRING(string, 0);
RETVAL_STRING(string);
RETURN_STR(php_format_date(format, format_len, ts, localtime TSRMLS_CC));
}
/* }}} */
PHPAPI char *php_format_date(char *format, int format_len, time_t ts, int localtime TSRMLS_DC) /* {{{ */
PHPAPI zend_string *php_format_date(char *format, int format_len, time_t ts, int localtime TSRMLS_DC) /* {{{ */
{
timelib_time *t;
timelib_tzinfo *tzi;
char *string;
zend_string *string;
t = timelib_time_ctor();
@ -2204,8 +2200,7 @@ static HashTable *date_object_get_properties(zval *object TSRMLS_DC)
}
/* first we add the date and time in ISO format */
//??? ZVAL_STRING(zv, date_format("Y-m-d H:i:s", 12, dateobj->time, 1), 0);
ZVAL_STRING(&zv, date_format("Y-m-d H:i:s", 12, dateobj->time, 1));
ZVAL_STR(&zv, date_format("Y-m-d H:i:s", 12, dateobj->time, 1));
zend_hash_str_update(props, "date", sizeof("date")-1, &zv);
/* then we add the timezone name (or similar) */
@ -2989,8 +2984,7 @@ PHP_FUNCTION(date_format)
}
dateobj = (php_date_obj *) Z_OBJ_P(object);
DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
//??? RETURN_STRING(date_format(format, format_len, dateobj->time, dateobj->time->is_localtime), 0);
RETURN_STRING(date_format(format, format_len, dateobj->time, dateobj->time->is_localtime));
RETURN_STR(date_format(format, format_len, dateobj->time, dateobj->time->is_localtime));
}
/* }}} */
@ -3846,7 +3840,7 @@ PHP_FUNCTION(timezone_transitions_get)
#define add_nominal() \
array_init(&element); \
add_assoc_long(&element, "ts", timestamp_begin); \
add_assoc_string(&element, "time", php_format_date(DATE_FORMAT_ISO8601, 13, timestamp_begin, 0 TSRMLS_CC), 0); \
add_assoc_str(&element, "time", php_format_date(DATE_FORMAT_ISO8601, 13, timestamp_begin, 0 TSRMLS_CC)); \
add_assoc_long(&element, "offset", tzobj->tzi.tz->type[0].offset); \
add_assoc_bool(&element, "isdst", tzobj->tzi.tz->type[0].isdst); \
add_assoc_string(&element, "abbr", &tzobj->tzi.tz->timezone_abbr[tzobj->tzi.tz->type[0].abbr_idx], 1); \
@ -3855,7 +3849,7 @@ PHP_FUNCTION(timezone_transitions_get)
#define add(i,ts) \
array_init(&element); \
add_assoc_long(&element, "ts", ts); \
add_assoc_string(&element, "time", php_format_date(DATE_FORMAT_ISO8601, 13, ts, 0 TSRMLS_CC), 0); \
add_assoc_str(&element, "time", php_format_date(DATE_FORMAT_ISO8601, 13, ts, 0 TSRMLS_CC)); \
add_assoc_long(&element, "offset", tzobj->tzi.tz->type[tzobj->tzi.tz->trans_idx[i]].offset); \
add_assoc_bool(&element, "isdst", tzobj->tzi.tz->type[tzobj->tzi.tz->trans_idx[i]].isdst); \
add_assoc_string(&element, "abbr", &tzobj->tzi.tz->timezone_abbr[tzobj->tzi.tz->type[tzobj->tzi.tz->trans_idx[i]].abbr_idx], 1); \
@ -4278,7 +4272,7 @@ static char *date_interval_format(char *format, int format_len, timelib_rel_time
smart_str_0(&string);
return string.c;
return string.s;
}
/* }}} */

View File

@ -190,7 +190,7 @@ PHPAPI int php_idate(char format, time_t ts, int localtime TSRMLS_DC);
#define _php_strftime php_strftime
PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gm);
#endif
PHPAPI char *php_format_date(char *format, int format_len, time_t ts, int localtime TSRMLS_DC);
PHPAPI zend_string *php_format_date(char *format, int format_len, time_t ts, int localtime TSRMLS_DC);
/* Mechanism to set new TZ database */
PHPAPI void php_date_set_tzdb(timelib_tzdb *tzdb);

View File

@ -906,7 +906,7 @@ static int preg_do_eval(char *eval_str, int eval_str_len, char *subject,
if ('\\' == *walk || '$' == *walk) {
smart_str_appendl(&code, segment, walk - segment);
if (walk_last == '\\') {
code.c[code.len-1] = *walk++;
code.s->val[code.s->len-1] = *walk++;
segment = walk;
walk_last = 0;
continue;
@ -946,9 +946,9 @@ static int preg_do_eval(char *eval_str, int eval_str_len, char *subject,
compiled_string_description = zend_make_compiled_string_description("regexp code" TSRMLS_CC);
/* Run the code */
if (zend_eval_stringl(code.c, code.len, &retval, compiled_string_description TSRMLS_CC) == FAILURE) {
if (zend_eval_stringl(code.s->val, code.s->len, &retval, compiled_string_description TSRMLS_CC) == FAILURE) {
efree(compiled_string_description);
php_error_docref(NULL TSRMLS_CC,E_ERROR, "Failed evaluating code: %s%s", PHP_EOL, code.c);
php_error_docref(NULL TSRMLS_CC,E_ERROR, "Failed evaluating code: %s%s", PHP_EOL, code.s->val);
/* zend_error() does not return in this case */
}
efree(compiled_string_description);

View File

@ -717,7 +717,7 @@ void spl_array_iterator_append(zval *object, zval *append_value TSRMLS_DC) /* {{
}
if (Z_TYPE(intern->array) == IS_OBJECT) {
php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Cannot append properties to objects, use %s::offsetSet() instead", Z_OBJCE_P(object)->name);
php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Cannot append properties to objects, use %s::offsetSet() instead", Z_OBJCE_P(object)->name->val);
return;
}
@ -759,11 +759,11 @@ SPL_METHOD(Array, offsetUnset)
Return a copy of the contained array */
SPL_METHOD(Array, getArrayCopy)
{
zval *object = getThis(), *tmp;
zval *object = getThis();
spl_array_object *intern = (spl_array_object*)Z_OBJ_P(object);
array_init(return_value);
zend_hash_copy(HASH_OF(return_value), spl_array_get_hash_table(intern, 0 TSRMLS_CC), (copy_ctor_func_t) zval_add_ref);
zend_hash_copy(Z_ARRVAL_P(return_value), spl_array_get_hash_table(intern, 0 TSRMLS_CC), (copy_ctor_func_t) zval_add_ref);
} /* }}} */
static HashTable *spl_array_get_properties(zval *object TSRMLS_DC) /* {{{ */
@ -1683,10 +1683,8 @@ SPL_METHOD(Array, serialize)
/* done */
PHP_VAR_SERIALIZE_DESTROY(var_hash);
if (buf.c) {
RETVAL_STRINGL(buf.c, buf.len);
smart_str_free(&buf);
return;
if (buf.s) {
RETVAL_STR(buf.s);
}
zval_ptr_dtor(&members);

View File

@ -317,7 +317,7 @@ static void spl_ptr_llist_shift(spl_ptr_llist *llist, zval *ret TSRMLS_DC) /* {{
static void spl_ptr_llist_copy(spl_ptr_llist *from, spl_ptr_llist *to TSRMLS_DC) /* {{{ */
{
spl_ptr_llist_element *current = from->head, *next;
spl_ptr_llist_element *current = from->head, *next;
spl_ptr_llist_ctor_func ctor = from->ctor;
while (current) {
@ -1145,10 +1145,8 @@ SPL_METHOD(SplDoublyLinkedList, serialize)
/* done */
PHP_VAR_SERIALIZE_DESTROY(var_hash);
if (buf.c) {
RETVAL_STRINGL(buf.c, buf.len);
smart_str_free(&buf);
return;
if (buf.s) {
RETURN_STR(buf.s);
} else {
RETURN_NULL();
}

View File

@ -972,15 +972,15 @@ static void spl_recursive_tree_iterator_get_prefix(spl_recursive_it_object *obje
zval has_next;
int level;
smart_str_appendl(&str, object->prefix[0].c, object->prefix[0].len);
smart_str_appendl(&str, object->prefix[0].s->val, object->prefix[0].s->len);
for (level = 0; level < object->level; ++level) {
zend_call_method_with_0_params(&object->iterators[level].zobject, object->iterators[level].ce, NULL, "hasnext", &has_next);
if (Z_TYPE(has_next) != IS_UNDEF) {
if (Z_LVAL(has_next)) {
smart_str_appendl(&str, object->prefix[1].c, object->prefix[1].len);
smart_str_appendl(&str, object->prefix[1].s->val, object->prefix[1].s->len);
} else {
smart_str_appendl(&str, object->prefix[2].c, object->prefix[2].len);
smart_str_appendl(&str, object->prefix[2].s->val, object->prefix[2].s->len);
}
zval_ptr_dtor(&has_next);
}
@ -988,21 +988,20 @@ static void spl_recursive_tree_iterator_get_prefix(spl_recursive_it_object *obje
zend_call_method_with_0_params(&object->iterators[level].zobject, object->iterators[level].ce, NULL, "hasnext", &has_next);
if (Z_TYPE(has_next) != IS_UNDEF) {
if (Z_LVAL(has_next)) {
smart_str_appendl(&str, object->prefix[3].c, object->prefix[3].len);
smart_str_appendl(&str, object->prefix[3].s->val, object->prefix[3].s->len);
} else {
smart_str_appendl(&str, object->prefix[4].c, object->prefix[4].len);
smart_str_appendl(&str, object->prefix[4].s->val, object->prefix[4].s->len);
}
zval_ptr_dtor(&has_next);
}
smart_str_appendl(&str, object->prefix[5].c, object->prefix[5].len);
smart_str_appendl(&str, object->prefix[5].s->val, object->prefix[5].s->len);
smart_str_0(&str);
RETVAL_STRINGL(str.c, str.len);
smart_str_free(&str);
RETURN_STR(str.s);
}
static void spl_recursive_tree_iterator_get_entry(spl_recursive_it_object * object, zval * return_value TSRMLS_DC)
static void spl_recursive_tree_iterator_get_entry(spl_recursive_it_object *object, zval *return_value TSRMLS_DC)
{
zend_object_iterator *iterator = object->iterators[object->level].iterator;
zval *data;
@ -1023,9 +1022,10 @@ static void spl_recursive_tree_iterator_get_entry(spl_recursive_it_object * obje
zend_restore_error_handling(&error_handling TSRMLS_CC);
}
static void spl_recursive_tree_iterator_get_postfix(spl_recursive_it_object * object, zval * return_value TSRMLS_DC)
static void spl_recursive_tree_iterator_get_postfix(spl_recursive_it_object *object, zval *return_value TSRMLS_DC)
{
RETVAL_STRINGL(object->postfix[0].c, object->postfix[0].len);
RETVAL_STR(object->postfix[0].s);
Z_ADDREF_P(return_value);
}
/* {{{ proto void RecursiveTreeIterator::__construct(RecursiveIterator|IteratorAggregate it [, int flags = RTIT_BYPASS_KEY [, int cit_flags = CIT_CATCH_GET_CHILD [, mode = RIT_SELF_FIRST ]]]) throws InvalidArgumentException

View File

@ -284,7 +284,6 @@ static zend_object *spl_object_storage_clone(zval *zobject TSRMLS_DC)
{
zend_object *old_object;
zend_object *new_object;
spl_SplObjectStorage *intern;
old_object = Z_OBJ_P(zobject);
new_object = spl_object_storage_new_ex(old_object->ce, zobject TSRMLS_CC);
@ -763,10 +762,8 @@ SPL_METHOD(SplObjectStorage, serialize)
/* done */
PHP_VAR_SERIALIZE_DESTROY(var_hash);
if (buf.c) {
RETVAL_STRINGL(buf.c, buf.len);
smart_str_free(&buf);
return;
if (buf.s) {
RETURN_STR(buf.s);
} else {
RETURN_NULL();
}

View File

@ -1934,7 +1934,7 @@ PHPAPI int php_fputcsv(php_stream *stream, zval *fields, char delimiter, char en
smart_str_appendc(&csvline, '\n');
smart_str_0(&csvline);
ret = php_stream_write(stream, csvline.c, csvline.len);
ret = php_stream_write(stream, csvline.s->val, csvline.s->len);
smart_str_free(&csvline);

View File

@ -247,7 +247,7 @@ static php_stream_filter_ops strfilter_strip_tags_ops = {
static php_stream_filter *strfilter_strip_tags_create(const char *filtername, zval *filterparams, int persistent TSRMLS_DC)
{
php_strip_tags_filter *inst;
smart_str tags_ss = { 0, 0, 0 };
smart_str tags_ss = {0};
inst = pemalloc(sizeof(php_strip_tags_filter), persistent);
@ -273,24 +273,17 @@ static php_stream_filter *strfilter_strip_tags_create(const char *filtername, zv
} else {
/* FIXME: convert_to_* may clutter zvals and lead it into segfault ? */
convert_to_string_ex(filterparams);
tags_ss.c = Z_STRVAL_P(filterparams);
tags_ss.len = Z_STRLEN_P(filterparams);
tags_ss.a = 0;
smart_str_setl(&tags_ss, Z_STRVAL_P(filterparams), Z_STRLEN_P(filterparams));
}
}
if (php_strip_tags_filter_ctor(inst, tags_ss.c, tags_ss.len, persistent) != SUCCESS) {
if (tags_ss.a != 0) {
//??? STR_FREE(tags_ss.c);
}
if (php_strip_tags_filter_ctor(inst, tags_ss.s->val, tags_ss.s->len, persistent) != SUCCESS) {
smart_str_free(&tags_ss);
pefree(inst, persistent);
return NULL;
}
if (tags_ss.a != 0) {
//??? STR_FREE(tags_ss.c);
}
smart_str_free(&tags_ss);
return php_stream_filter_alloc(&strfilter_strip_tags_ops, inst, persistent);
}

View File

@ -141,7 +141,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
/* Skip these types */
continue;
} else {
if (formstr->len) {
if (formstr->s->len) {
smart_str_appendl(formstr, arg_sep, arg_sep_len);
}
/* Simple key=value */
@ -220,20 +220,19 @@ PHP_FUNCTION(http_build_query)
}
if (php_url_encode_hash_ex(HASH_OF(formdata), &formstr, prefix, prefix_len, NULL, 0, NULL, 0, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL), arg_sep, enc_type TSRMLS_CC) == FAILURE) {
if (formstr.c) {
efree(formstr.c);
if (formstr.s) {
smart_str_free(&formstr);
}
RETURN_FALSE;
}
if (!formstr.c) {
if (!formstr.s) {
RETURN_EMPTY_STRING();
}
smart_str_0(&formstr);
//??? RETURN_STRINGL(formstr.c, formstr.len, 0);
RETURN_STRINGL(formstr.c, formstr.len);
RETURN_STR(formstr.s);
}
/* }}} */

View File

@ -294,7 +294,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
finish:
smart_str_appendl(&header, "\r\n", sizeof("\r\n")-1);
if (php_stream_write(stream, header.c, header.len) != header.len) {
if (php_stream_write(stream, header.s->val, header.s->len) != header.s->len) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "Cannot connect to HTTPS server through proxy");
php_stream_close(stream);
stream = NULL;
@ -438,8 +438,8 @@ finish:
}
smart_str_0(&tmpstr);
/* Remove newlines and spaces from start and end. there's at least one extra \r\n at the end that needs to go. */
if (tmpstr.c) {
tmp = php_trim(tmpstr.c, strlen(tmpstr.c), NULL, 0, NULL, 3 TSRMLS_CC);
if (tmpstr.s) {
tmp = php_trim(tmpstr.s->val, tmpstr.s->len, NULL, 0, NULL, 3 TSRMLS_CC);
smart_str_free(&tmpstr);
}
}

View File

@ -29,8 +29,8 @@
#endif
#define smart_str_0(x) do { \
if ((x)->c) { \
(x)->c[(x)->len] = '\0'; \
if ((x)->s) { \
(x)->s->val[(x)->s->len] = '\0'; \
} \
} while (0)
@ -42,28 +42,31 @@
#define SMART_STR_START_SIZE 78
#endif
#ifdef SMART_STR_USE_REALLOC
#define SMART_STR_REALLOC(a,b,c) realloc((a),(b))
#define SMART_STR_DO_REALLOC(b, w) do { \
(b)->s = erealloc((buf)->s, sizeof(zend_string) + (b)->a); \
} while (0)
#else
#define SMART_STR_REALLOC(a,b,c) perealloc((a),(b),(c))
#define SMART_STR_DO_REALLOC(b, w) do { \
(b)->s = perealloc((b)->s, sizeof(zend_string) + (b)->a, (w)); \
} while (0)
#endif
#define SMART_STR_DO_REALLOC(d, what) \
(d)->c = SMART_STR_REALLOC((d)->c, (d)->a + 1, (what))
#define smart_str_alloc4(d, n, what, newlen) do { \
if (!(d)->c) { \
(d)->len = 0; \
if (!(d)->s) { \
newlen = (n); \
(d)->a = newlen < SMART_STR_START_SIZE \
? SMART_STR_START_SIZE \
: newlen + SMART_STR_PREALLOC; \
SMART_STR_DO_REALLOC(d, what); \
(d)->s = STR_ALLOC((d)->a, (what)); \
(d)->s->len = 0; \
} else { \
newlen = (d)->len + (n); \
newlen = (d)->s->len + (n); \
if (newlen >= (d)->a) { \
(d)->a = newlen + SMART_STR_PREALLOC; \
SMART_STR_DO_REALLOC(d, what); \
SMART_STR_DO_REALLOC((d), (what)); \
} \
} \
} while (0)
@ -93,20 +96,20 @@
#define smart_str_append_unsigned(dest, val) \
smart_str_append_unsigned_ex((dest), (val), 0)
#define smart_str_appendc_ex(dest, ch, what) do { \
register size_t __nl; \
smart_str_alloc4((dest), 1, (what), __nl); \
(dest)->len = __nl; \
((unsigned char *) (dest)->c)[(dest)->len - 1] = (ch); \
#define smart_str_appendc_ex(dest, ch, what) do { \
register size_t __nl; \
smart_str_alloc4((dest), 1, (what), __nl); \
(dest)->s->len = __nl; \
((unsigned char *) (dest)->s->val)[(dest)->s->len - 1] = (ch); \
} while (0)
#define smart_str_free_ex(s, what) do { \
smart_str *__s = (smart_str *) (s); \
if (__s->c) { \
pefree(__s->c, what); \
__s->c = NULL; \
#define smart_str_free_ex(buf, what) do { \
smart_str *__s = (smart_str *) (buf); \
if (__s->s) { \
STR_RELEASE(__s->s); \
__s->s = NULL; \
} \
__s->a = __s->len = 0; \
__s->a = 0; \
} while (0)
#define smart_str_appendl_ex(dest, src, nlen, what) do { \
@ -114,8 +117,8 @@
smart_str *__dest = (smart_str *) (dest); \
\
smart_str_alloc4(__dest, (nlen), (what), __nl); \
memcpy(__dest->c + __dest->len, (src), (nlen)); \
__dest->len = __nl; \
memcpy(__dest->s->val + __dest->s->len, (src), (nlen)); \
__dest->s->len = __nl; \
} while (0)
/* input: buf points to the END of the buffer */
@ -131,12 +134,12 @@
} while (0)
/* buf points to the END of the buffer */
#define smart_str_print_long4(buf, num, vartype, result) do { \
#define smart_str_print_long4(buf, num, vartype, result) do { \
if (num < 0) { \
/* this might cause problems when dealing with LONG_MIN \
and machines which don't support long long. Works \
flawlessly on 32bit x86 */ \
smart_str_print_unsigned4((buf), -(num), vartype, (result)); \
smart_str_print_unsigned4((buf), -(num), vartype, (result));\
*--(result) = '-'; \
} else { \
smart_str_print_unsigned4((buf), (num), vartype, (result)); \
@ -178,15 +181,13 @@ static inline char *smart_str_print_unsigned(char *buf, long num) {
#define smart_str_append_off_t_ex(dest, num, type) \
smart_str_append_generic_ex((dest), (num), (type), off_t, _long)
#define smart_str_append_ex(dest, src, what) \
smart_str_appendl_ex((dest), ((smart_str *)(src))->c, \
((smart_str *)(src))->len, (what));
#define smart_str_append_ex(dest, src, what) \
smart_str_appendl_ex((dest), ((smart_str *)(src))->s->val, \
((smart_str *)(src))->s->len, (what));
#define smart_str_setl(dest, src, nlen) do { \
(dest)->len = (nlen); \
(dest)->a = (nlen) + 1; \
(dest)->c = (char *) (src); \
smart_str_appendl_ex((dest), (src), (nlen), 0); \
} while (0)
#define smart_str_sets(dest, src) \

View File

@ -24,8 +24,7 @@
#include <sys/types.h>
typedef struct {
char *c;
size_t len;
zend_string *s;
size_t a;
} smart_str;

View File

@ -1201,9 +1201,8 @@ PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value TSRMLS_DC)
}
smart_str_0(&implstr);
if (implstr.len) {
//??? RETURN_STRINGL(implstr.c, implstr.len, 0);
RETURN_STRINGL(implstr.c, implstr.len);
if (implstr.s) {
RETURN_STR(implstr.s);
} else {
smart_str_free(&implstr);
RETURN_EMPTY_STRING();
@ -3069,10 +3068,9 @@ end_outer_loop: ;
smart_str_appendl(&result, &S(text)[nextwpos], L(text) - nextwpos);
if (result.c != NULL) {
if (result.s) {
smart_str_0(&result);
//??? RETVAL_STRINGL(result.c, result.len, 0);
RETVAL_STRINGL(result.c, result.len);
RETURN_STR(result.s);
} else {
RETURN_EMPTY_STRING();
}

View File

@ -115,7 +115,7 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st
const char *bash = NULL;
const char *sep = "?";
q = (p = url->c) + url->len;
q = (p = url->s->val) + url->s->len;
scan:
@ -194,13 +194,13 @@ yy8:
done:
/* Don't modify URLs of the format "#mark" */
if (bash && bash - url->c == 0) {
if (bash && bash - url->s->val == 0) {
smart_str_append(dest, url);
return;
}
if (bash)
smart_str_appendl(dest, url->c, bash - url->c);
smart_str_appendl(dest, url->s->val, bash - url->s->val);
else
smart_str_append(dest, url);
@ -222,7 +222,7 @@ static inline void tag_arg(url_adapt_state_ex_t *ctx, char quotes, char type TSR
{
char f = 0;
if (strncasecmp(ctx->arg.c, ctx->lookup_data, ctx->arg.len) == 0)
if (strncasecmp(ctx->arg.s->val, ctx->lookup_data, ctx->arg.s->len) == 0)
f = 1;
if (quotes)
@ -276,18 +276,18 @@ static void handle_form(STD_PARA)
{
int doit = 0;
if (ctx->form_app.len > 0) {
switch (ctx->tag.len) {
if (ctx->form_app.s->len > 0) {
switch (ctx->tag.s->len) {
case sizeof("form") - 1:
if (!strncasecmp(ctx->tag.c, "form", sizeof("form") - 1)) {
if (!strncasecmp(ctx->tag.s->val, "form", sizeof("form") - 1)) {
doit = 1;
}
if (doit && ctx->val.c && ctx->lookup_data && *ctx->lookup_data) {
char *e, *p = zend_memnstr(ctx->val.c, "://", sizeof("://") - 1, ctx->val.c + ctx->val.len);
if (doit && ctx->val.s->val && ctx->lookup_data && *ctx->lookup_data) {
char *e, *p = (char *)zend_memnstr(ctx->val.s->val, "://", sizeof("://") - 1, ctx->val.s->val + ctx->val.s->len);
if (p) {
e = memchr(p, '/', (ctx->val.c + ctx->val.len) - p);
e = memchr(p, '/', (ctx->val.s->val + ctx->val.s->len) - p);
if (!e) {
e = ctx->val.c + ctx->val.len;
e = ctx->val.s->val + ctx->val.s->len;
}
if ((e - p) && strncasecmp(p, ctx->lookup_data, (e - p))) {
doit = 0;
@ -297,7 +297,7 @@ static void handle_form(STD_PARA)
break;
case sizeof("fieldset") - 1:
if (!strncasecmp(ctx->tag.c, "fieldset", sizeof("fieldset") - 1)) {
if (!strncasecmp(ctx->tag.s->val, "fieldset", sizeof("fieldset") - 1)) {
doit = 1;
}
break;
@ -320,18 +320,19 @@ static inline void handle_tag(STD_PARA)
int ok = 0;
unsigned int i;
ctx->tag.len = 0;
ctx->tag.s->len = 0;
smart_str_appendl(&ctx->tag, start, YYCURSOR - start);
for (i = 0; i < ctx->tag.len; i++)
ctx->tag.c[i] = tolower((int)(unsigned char)ctx->tag.c[i]);
if ((ctx->lookup_data = zend_hash_str_find_ptr(ctx->tags, ctx->tag.c, ctx->tag.len)) != NULL)
for (i = 0; i < ctx->tag.s->len; i++)
ctx->tag.s->val[i] = tolower((int)(unsigned char)ctx->tag.s->val[i]);
/* intentionally using str_find here, in case the hash value is set, but the string val is changed later */
if ((ctx->lookup_data = zend_hash_str_find_ptr(ctx->tags, ctx->tag.s->val, ctx->tag.s->len)) != NULL)
ok = 1;
STATE = ok ? STATE_NEXT_ARG : STATE_PLAIN;
}
static inline void handle_arg(STD_PARA)
{
ctx->arg.len = 0;
ctx->arg.s->len = 0;
smart_str_appendl(&ctx->arg, start, YYCURSOR - start);
}
@ -350,8 +351,8 @@ static inline void xx_mainloop(url_adapt_state_ex_t *ctx, const char *newdata, s
smart_str_appendl(&ctx->buf, newdata, newlen);
YYCURSOR = ctx->buf.c;
YYLIMIT = ctx->buf.c + ctx->buf.len;
YYCURSOR = ctx->buf.s->val;
YYLIMIT = ctx->buf.s->val + ctx->buf.s->len;
switch (STATE) {
case STATE_PLAIN: goto state_plain;
@ -369,7 +370,7 @@ state_plain_begin:
state_plain:
start = YYCURSOR;
#line 373 "ext/standard/url_scanner_ex.c"
#line 374 "ext/standard/url_scanner_ex.c"
{
YYCTYPE yych;
static const unsigned char yybm[] = {
@ -412,9 +413,9 @@ state_plain:
goto yy15;
}
++YYCURSOR;
#line 308 "ext/standard/url_scanner_ex.re"
#line 309 "ext/standard/url_scanner_ex.re"
{ passthru(STD_ARGS); STATE = STATE_TAG; goto state_tag; }
#line 418 "ext/standard/url_scanner_ex.c"
#line 419 "ext/standard/url_scanner_ex.c"
yy15:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
@ -422,17 +423,17 @@ yy15:
if (yybm[0+yych] & 128) {
goto yy15;
}
#line 309 "ext/standard/url_scanner_ex.re"
{ passthru(STD_ARGS); goto state_plain; }
#line 428 "ext/standard/url_scanner_ex.c"
}
#line 310 "ext/standard/url_scanner_ex.re"
{ passthru(STD_ARGS); goto state_plain; }
#line 429 "ext/standard/url_scanner_ex.c"
}
#line 311 "ext/standard/url_scanner_ex.re"
state_tag:
start = YYCURSOR;
#line 436 "ext/standard/url_scanner_ex.c"
#line 437 "ext/standard/url_scanner_ex.c"
{
YYCTYPE yych;
static const unsigned char yybm[] = {
@ -483,14 +484,14 @@ yy20:
yych = *YYCURSOR;
goto yy25;
yy21:
#line 315 "ext/standard/url_scanner_ex.re"
#line 316 "ext/standard/url_scanner_ex.re"
{ handle_tag(STD_ARGS); /* Sets STATE */; passthru(STD_ARGS); if (STATE == STATE_PLAIN) goto state_plain; else goto state_next_arg; }
#line 489 "ext/standard/url_scanner_ex.c"
#line 490 "ext/standard/url_scanner_ex.c"
yy22:
++YYCURSOR;
#line 316 "ext/standard/url_scanner_ex.re"
#line 317 "ext/standard/url_scanner_ex.re"
{ passthru(STD_ARGS); goto state_plain_begin; }
#line 494 "ext/standard/url_scanner_ex.c"
#line 495 "ext/standard/url_scanner_ex.c"
yy24:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
@ -501,7 +502,7 @@ yy25:
}
goto yy21;
}
#line 317 "ext/standard/url_scanner_ex.re"
#line 318 "ext/standard/url_scanner_ex.re"
state_next_arg_begin:
@ -510,7 +511,7 @@ state_next_arg_begin:
state_next_arg:
start = YYCURSOR;
#line 514 "ext/standard/url_scanner_ex.c"
#line 515 "ext/standard/url_scanner_ex.c"
{
YYCTYPE yych;
static const unsigned char yybm[] = {
@ -575,28 +576,28 @@ yy28:
++YYCURSOR;
if ((yych = *YYCURSOR) == '>') goto yy39;
yy29:
#line 328 "ext/standard/url_scanner_ex.re"
#line 329 "ext/standard/url_scanner_ex.re"
{ passthru(STD_ARGS); goto state_plain_begin; }
#line 581 "ext/standard/url_scanner_ex.c"
#line 582 "ext/standard/url_scanner_ex.c"
yy30:
++YYCURSOR;
yy31:
#line 325 "ext/standard/url_scanner_ex.re"
#line 326 "ext/standard/url_scanner_ex.re"
{ passthru(STD_ARGS); handle_form(STD_ARGS); goto state_plain_begin; }
#line 587 "ext/standard/url_scanner_ex.c"
#line 588 "ext/standard/url_scanner_ex.c"
yy32:
++YYCURSOR;
yych = *YYCURSOR;
goto yy38;
yy33:
#line 326 "ext/standard/url_scanner_ex.re"
#line 327 "ext/standard/url_scanner_ex.re"
{ passthru(STD_ARGS); goto state_next_arg; }
#line 595 "ext/standard/url_scanner_ex.c"
#line 596 "ext/standard/url_scanner_ex.c"
yy34:
++YYCURSOR;
#line 327 "ext/standard/url_scanner_ex.re"
#line 328 "ext/standard/url_scanner_ex.re"
{ --YYCURSOR; STATE = STATE_ARG; goto state_arg; }
#line 600 "ext/standard/url_scanner_ex.c"
#line 601 "ext/standard/url_scanner_ex.c"
yy36:
yych = *++YYCURSOR;
goto yy29;
@ -614,13 +615,13 @@ yy39:
yych = *YYCURSOR;
goto yy31;
}
#line 329 "ext/standard/url_scanner_ex.re"
#line 330 "ext/standard/url_scanner_ex.re"
state_arg:
start = YYCURSOR;
#line 624 "ext/standard/url_scanner_ex.c"
#line 625 "ext/standard/url_scanner_ex.c"
{
YYCTYPE yych;
static const unsigned char yybm[] = {
@ -668,14 +669,14 @@ yy42:
yych = *YYCURSOR;
goto yy47;
yy43:
#line 334 "ext/standard/url_scanner_ex.re"
#line 335 "ext/standard/url_scanner_ex.re"
{ passthru(STD_ARGS); handle_arg(STD_ARGS); STATE = STATE_BEFORE_VAL; goto state_before_val; }
#line 674 "ext/standard/url_scanner_ex.c"
#line 675 "ext/standard/url_scanner_ex.c"
yy44:
++YYCURSOR;
#line 335 "ext/standard/url_scanner_ex.re"
#line 336 "ext/standard/url_scanner_ex.re"
{ passthru(STD_ARGS); STATE = STATE_NEXT_ARG; goto state_next_arg; }
#line 679 "ext/standard/url_scanner_ex.c"
#line 680 "ext/standard/url_scanner_ex.c"
yy46:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
@ -686,13 +687,13 @@ yy47:
}
goto yy43;
}
#line 336 "ext/standard/url_scanner_ex.re"
#line 337 "ext/standard/url_scanner_ex.re"
state_before_val:
start = YYCURSOR;
#line 696 "ext/standard/url_scanner_ex.c"
#line 697 "ext/standard/url_scanner_ex.c"
{
YYCTYPE yych;
static const unsigned char yybm[] = {
@ -739,17 +740,17 @@ yy50:
if (yych == ' ') goto yy57;
if (yych == '=') goto yy55;
yy51:
#line 342 "ext/standard/url_scanner_ex.re"
#line 343 "ext/standard/url_scanner_ex.re"
{ --YYCURSOR; goto state_next_arg_begin; }
#line 745 "ext/standard/url_scanner_ex.c"
#line 746 "ext/standard/url_scanner_ex.c"
yy52:
++YYCURSOR;
yych = *YYCURSOR;
goto yy56;
yy53:
#line 341 "ext/standard/url_scanner_ex.re"
#line 342 "ext/standard/url_scanner_ex.re"
{ passthru(STD_ARGS); STATE = STATE_VAL; goto state_val; }
#line 753 "ext/standard/url_scanner_ex.c"
#line 754 "ext/standard/url_scanner_ex.c"
yy54:
yych = *++YYCURSOR;
goto yy51;
@ -771,14 +772,14 @@ yy57:
YYCURSOR = YYMARKER;
goto yy51;
}
#line 343 "ext/standard/url_scanner_ex.re"
#line 344 "ext/standard/url_scanner_ex.re"
state_val:
start = YYCURSOR;
#line 782 "ext/standard/url_scanner_ex.c"
#line 783 "ext/standard/url_scanner_ex.c"
{
YYCTYPE yych;
static const unsigned char yybm[] = {
@ -839,9 +840,9 @@ state_val:
yych = *(YYMARKER = ++YYCURSOR);
if (yych != '>') goto yy76;
yy63:
#line 352 "ext/standard/url_scanner_ex.re"
#line 353 "ext/standard/url_scanner_ex.re"
{ passthru(STD_ARGS); goto state_next_arg_begin; }
#line 845 "ext/standard/url_scanner_ex.c"
#line 846 "ext/standard/url_scanner_ex.c"
yy64:
yych = *(YYMARKER = ++YYCURSOR);
if (yych == '>') goto yy63;
@ -851,9 +852,9 @@ yy65:
yych = *YYCURSOR;
goto yy69;
yy66:
#line 351 "ext/standard/url_scanner_ex.re"
#line 352 "ext/standard/url_scanner_ex.re"
{ handle_val(STD_ARGS, 0, ' '); goto state_next_arg_begin; }
#line 857 "ext/standard/url_scanner_ex.c"
#line 858 "ext/standard/url_scanner_ex.c"
yy67:
yych = *++YYCURSOR;
goto yy63;
@ -880,9 +881,9 @@ yy72:
goto yy63;
yy73:
++YYCURSOR;
#line 350 "ext/standard/url_scanner_ex.re"
#line 351 "ext/standard/url_scanner_ex.re"
{ handle_val(STD_ARGS, 1, '\''); goto state_next_arg_begin; }
#line 886 "ext/standard/url_scanner_ex.c"
#line 887 "ext/standard/url_scanner_ex.c"
yy75:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
@ -893,11 +894,11 @@ yy76:
}
if (yych >= '>') goto yy72;
++YYCURSOR;
#line 349 "ext/standard/url_scanner_ex.re"
#line 350 "ext/standard/url_scanner_ex.re"
{ handle_val(STD_ARGS, 1, '"'); goto state_next_arg_begin; }
#line 899 "ext/standard/url_scanner_ex.c"
#line 900 "ext/standard/url_scanner_ex.c"
}
#line 353 "ext/standard/url_scanner_ex.re"
#line 354 "ext/standard/url_scanner_ex.re"
stop:
@ -906,12 +907,13 @@ stop:
/* XXX: Crash avoidance. Need to work with reporter to figure out what goes wrong */
if (rest < 0) rest = 0;
if (rest) memmove(ctx->buf.c, start, rest);
ctx->buf.len = rest;
if (rest) memmove(ctx->buf.s->val, start, rest);
ctx->buf.s->len = rest;
}
char *php_url_scanner_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, size_t *newlen TSRMLS_DC)
{
char *result;
smart_str surl = {0};
smart_str buf = {0};
smart_str url_app = {0};
@ -925,11 +927,13 @@ char *php_url_scanner_adapt_single_url(const char *url, size_t urllen, const cha
append_modified_url(&surl, &buf, &url_app, PG(arg_separator).output);
smart_str_0(&buf);
if (newlen) *newlen = buf.len;
if (newlen) *newlen = buf.s->len;
result = estrndup(buf.s->val, buf.s->len);
smart_str_free(&url_app);
smart_str_free(&buf);
return buf.c;
return result;
}
@ -942,19 +946,18 @@ static char *url_adapt_ext(const char *src, size_t srclen, size_t *newlen, zend_
xx_mainloop(ctx, src, srclen TSRMLS_CC);
*newlen = ctx->result.len;
if (!ctx->result.c) {
*newlen = ctx->result.s->len;
if (!ctx->result.s) {
smart_str_appendl(&ctx->result, "", 0);
}
smart_str_0(&ctx->result);
if (do_flush) {
smart_str_appendl(&ctx->result, ctx->buf.c, ctx->buf.len);
*newlen += ctx->buf.len;
smart_str_appendl(&ctx->result, ctx->buf.s->val, ctx->buf.s->len);
*newlen += ctx->buf.s->len;
smart_str_free(&ctx->buf);
}
retval = ctx->result.c;
ctx->result.c = NULL;
ctx->result.len = 0;
retval = estrndup(ctx->result.s->val, ctx->result.s->len);
smart_str_free(&ctx->result);
return retval;
}
@ -987,25 +990,24 @@ static void php_url_scanner_output_handler(char *output, uint output_len, char *
{
size_t len;
if (BG(url_adapt_state_ex).url_app.len != 0) {
if (BG(url_adapt_state_ex).url_app.s->len != 0) {
*handled_output = url_adapt_ext(output, output_len, &len, (zend_bool) (mode & (PHP_OUTPUT_HANDLER_END | PHP_OUTPUT_HANDLER_CONT | PHP_OUTPUT_HANDLER_FLUSH | PHP_OUTPUT_HANDLER_FINAL) ? 1 : 0) TSRMLS_CC);
if (sizeof(uint) < sizeof(size_t)) {
if (len > UINT_MAX)
len = UINT_MAX;
}
*handled_output_len = len;
} else if (BG(url_adapt_state_ex).url_app.len == 0) {
} else if (BG(url_adapt_state_ex).url_app.s->len == 0) {
url_adapt_state_ex_t *ctx = &BG(url_adapt_state_ex);
if (ctx->buf.len) {
smart_str_appendl(&ctx->result, ctx->buf.c, ctx->buf.len);
if (ctx->buf.s) {
smart_str_appendl(&ctx->result, ctx->buf.s->val, ctx->buf.s->len);
smart_str_appendl(&ctx->result, output, output_len);
*handled_output = ctx->result.c;
*handled_output_len = ctx->buf.len + output_len;
*handled_output = estrndup(ctx->result.s->val, ctx->result.s->len);
*handled_output_len = ctx->buf.s->len + output_len;
ctx->result.c = NULL;
ctx->result.len = 0;
smart_str_free(&ctx->buf);
smart_str_free(&ctx->result);
} else {
*handled_output = estrndup(output, *handled_output_len = output_len);
}
@ -1027,7 +1029,7 @@ PHPAPI int php_url_scanner_add_var(char *name, int name_len, char *value, int va
}
if (BG(url_adapt_state_ex).url_app.len != 0) {
if (BG(url_adapt_state_ex).url_app.s->len != 0) {
smart_str_appends(&BG(url_adapt_state_ex).url_app, PG(arg_separator).output);
}
@ -1056,8 +1058,8 @@ PHPAPI int php_url_scanner_add_var(char *name, int name_len, char *value, int va
PHPAPI int php_url_scanner_reset_vars(TSRMLS_D)
{
BG(url_adapt_state_ex).form_app.len = 0;
BG(url_adapt_state_ex).url_app.len = 0;
BG(url_adapt_state_ex).form_app.s->len = 0;
BG(url_adapt_state_ex).url_app.s->len = 0;
return SUCCESS;
}
@ -1066,8 +1068,7 @@ PHP_MINIT_FUNCTION(url_scanner)
{
BG(url_adapt_state_ex).tags = NULL;
BG(url_adapt_state_ex).form_app.c = BG(url_adapt_state_ex).url_app.c = 0;
BG(url_adapt_state_ex).form_app.len = BG(url_adapt_state_ex).url_app.len = 0;
BG(url_adapt_state_ex).form_app.s = BG(url_adapt_state_ex).url_app.s = NULL;
REGISTER_INI_ENTRIES();
return SUCCESS;

View File

@ -118,7 +118,7 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st
const char *bash = NULL;
const char *sep = "?";
q = (p = url->c) + url->len;
q = (p = url->s->val) + url->s->len;
scan:
/*!re2c
@ -130,13 +130,13 @@ scan:
done:
/* Don't modify URLs of the format "#mark" */
if (bash && bash - url->c == 0) {
if (bash && bash - url->s->val == 0) {
smart_str_append(dest, url);
return;
}
if (bash)
smart_str_appendl(dest, url->c, bash - url->c);
smart_str_appendl(dest, url->s->val, bash - url->s->val);
else
smart_str_append(dest, url);
@ -158,7 +158,7 @@ static inline void tag_arg(url_adapt_state_ex_t *ctx, char quotes, char type TSR
{
char f = 0;
if (strncasecmp(ctx->arg.c, ctx->lookup_data, ctx->arg.len) == 0)
if (strncasecmp(ctx->arg.s->val, ctx->lookup_data, ctx->arg.s->len) == 0)
f = 1;
if (quotes)
@ -212,18 +212,18 @@ static void handle_form(STD_PARA)
{
int doit = 0;
if (ctx->form_app.len > 0) {
switch (ctx->tag.len) {
if (ctx->form_app.s->len > 0) {
switch (ctx->tag.s->len) {
case sizeof("form") - 1:
if (!strncasecmp(ctx->tag.c, "form", sizeof("form") - 1)) {
if (!strncasecmp(ctx->tag.s->val, "form", sizeof("form") - 1)) {
doit = 1;
}
if (doit && ctx->val.c && ctx->lookup_data && *ctx->lookup_data) {
char *e, *p = zend_memnstr(ctx->val.c, "://", sizeof("://") - 1, ctx->val.c + ctx->val.len);
if (doit && ctx->val.s->val && ctx->lookup_data && *ctx->lookup_data) {
char *e, *p = (char *)zend_memnstr(ctx->val.s->val, "://", sizeof("://") - 1, ctx->val.s->val + ctx->val.s->len);
if (p) {
e = memchr(p, '/', (ctx->val.c + ctx->val.len) - p);
e = memchr(p, '/', (ctx->val.s->val + ctx->val.s->len) - p);
if (!e) {
e = ctx->val.c + ctx->val.len;
e = ctx->val.s->val + ctx->val.s->len;
}
if ((e - p) && strncasecmp(p, ctx->lookup_data, (e - p))) {
doit = 0;
@ -233,7 +233,7 @@ static void handle_form(STD_PARA)
break;
case sizeof("fieldset") - 1:
if (!strncasecmp(ctx->tag.c, "fieldset", sizeof("fieldset") - 1)) {
if (!strncasecmp(ctx->tag.s->val, "fieldset", sizeof("fieldset") - 1)) {
doit = 1;
}
break;
@ -256,18 +256,19 @@ static inline void handle_tag(STD_PARA)
int ok = 0;
unsigned int i;
ctx->tag.len = 0;
ctx->tag.s->len = 0;
smart_str_appendl(&ctx->tag, start, YYCURSOR - start);
for (i = 0; i < ctx->tag.len; i++)
ctx->tag.c[i] = tolower((int)(unsigned char)ctx->tag.c[i]);
if ((ctx->lookup_data = zend_hash_str_find_ptr(ctx->tags, ctx->tag.c, ctx->tag.len)) != NULL)
for (i = 0; i < ctx->tag.s->len; i++)
ctx->tag.s->val[i] = tolower((int)(unsigned char)ctx->tag.s->val[i]);
/* intentionally using str_find here, in case the hash value is set, but the string val is changed later */
if ((ctx->lookup_data = zend_hash_str_find_ptr(ctx->tags, ctx->tag.s->val, ctx->tag.s->len)) != NULL)
ok = 1;
STATE = ok ? STATE_NEXT_ARG : STATE_PLAIN;
}
static inline void handle_arg(STD_PARA)
{
ctx->arg.len = 0;
ctx->arg.s->len = 0;
smart_str_appendl(&ctx->arg, start, YYCURSOR - start);
}
@ -286,8 +287,8 @@ static inline void xx_mainloop(url_adapt_state_ex_t *ctx, const char *newdata, s
smart_str_appendl(&ctx->buf, newdata, newlen);
YYCURSOR = ctx->buf.c;
YYLIMIT = ctx->buf.c + ctx->buf.len;
YYCURSOR = ctx->buf.s->val;
YYLIMIT = ctx->buf.s->val + ctx->buf.s->len;
switch (STATE) {
case STATE_PLAIN: goto state_plain;
@ -358,12 +359,13 @@ stop:
/* XXX: Crash avoidance. Need to work with reporter to figure out what goes wrong */
if (rest < 0) rest = 0;
if (rest) memmove(ctx->buf.c, start, rest);
ctx->buf.len = rest;
if (rest) memmove(ctx->buf.s->val, start, rest);
ctx->buf.s->len = rest;
}
char *php_url_scanner_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, size_t *newlen TSRMLS_DC)
{
char *result;
smart_str surl = {0};
smart_str buf = {0};
smart_str url_app = {0};
@ -377,11 +379,13 @@ char *php_url_scanner_adapt_single_url(const char *url, size_t urllen, const cha
append_modified_url(&surl, &buf, &url_app, PG(arg_separator).output);
smart_str_0(&buf);
if (newlen) *newlen = buf.len;
if (newlen) *newlen = buf.s->len;
result = estrndup(buf.s->val, buf.s->len);
smart_str_free(&url_app);
smart_str_free(&buf);
return buf.c;
return result;
}
@ -394,19 +398,18 @@ static char *url_adapt_ext(const char *src, size_t srclen, size_t *newlen, zend_
xx_mainloop(ctx, src, srclen TSRMLS_CC);
*newlen = ctx->result.len;
if (!ctx->result.c) {
*newlen = ctx->result.s->len;
if (!ctx->result.s) {
smart_str_appendl(&ctx->result, "", 0);
}
smart_str_0(&ctx->result);
if (do_flush) {
smart_str_appendl(&ctx->result, ctx->buf.c, ctx->buf.len);
*newlen += ctx->buf.len;
smart_str_appendl(&ctx->result, ctx->buf.s->val, ctx->buf.s->len);
*newlen += ctx->buf.s->len;
smart_str_free(&ctx->buf);
}
retval = ctx->result.c;
ctx->result.c = NULL;
ctx->result.len = 0;
retval = estrndup(ctx->result.s->val, ctx->result.s->len);
smart_str_free(&ctx->result);
return retval;
}
@ -439,25 +442,24 @@ static void php_url_scanner_output_handler(char *output, uint output_len, char *
{
size_t len;
if (BG(url_adapt_state_ex).url_app.len != 0) {
if (BG(url_adapt_state_ex).url_app.s->len != 0) {
*handled_output = url_adapt_ext(output, output_len, &len, (zend_bool) (mode & (PHP_OUTPUT_HANDLER_END | PHP_OUTPUT_HANDLER_CONT | PHP_OUTPUT_HANDLER_FLUSH | PHP_OUTPUT_HANDLER_FINAL) ? 1 : 0) TSRMLS_CC);
if (sizeof(uint) < sizeof(size_t)) {
if (len > UINT_MAX)
len = UINT_MAX;
}
*handled_output_len = len;
} else if (BG(url_adapt_state_ex).url_app.len == 0) {
} else if (BG(url_adapt_state_ex).url_app.s->len == 0) {
url_adapt_state_ex_t *ctx = &BG(url_adapt_state_ex);
if (ctx->buf.len) {
smart_str_appendl(&ctx->result, ctx->buf.c, ctx->buf.len);
if (ctx->buf.s) {
smart_str_appendl(&ctx->result, ctx->buf.s->val, ctx->buf.s->len);
smart_str_appendl(&ctx->result, output, output_len);
*handled_output = ctx->result.c;
*handled_output_len = ctx->buf.len + output_len;
*handled_output = estrndup(ctx->result.s->val, ctx->result.s->len);
*handled_output_len = ctx->buf.s->len + output_len;
ctx->result.c = NULL;
ctx->result.len = 0;
smart_str_free(&ctx->buf);
smart_str_free(&ctx->result);
} else {
*handled_output = estrndup(output, *handled_output_len = output_len);
}
@ -479,7 +481,7 @@ PHPAPI int php_url_scanner_add_var(char *name, int name_len, char *value, int va
}
if (BG(url_adapt_state_ex).url_app.len != 0) {
if (BG(url_adapt_state_ex).url_app.s->len != 0) {
smart_str_appends(&BG(url_adapt_state_ex).url_app, PG(arg_separator).output);
}
@ -508,8 +510,8 @@ PHPAPI int php_url_scanner_add_var(char *name, int name_len, char *value, int va
PHPAPI int php_url_scanner_reset_vars(TSRMLS_D)
{
BG(url_adapt_state_ex).form_app.len = 0;
BG(url_adapt_state_ex).url_app.len = 0;
BG(url_adapt_state_ex).form_app.s->len = 0;
BG(url_adapt_state_ex).url_app.s->len = 0;
return SUCCESS;
}
@ -518,8 +520,7 @@ PHP_MINIT_FUNCTION(url_scanner)
{
BG(url_adapt_state_ex).tags = NULL;
BG(url_adapt_state_ex).form_app.c = BG(url_adapt_state_ex).url_app.c = 0;
BG(url_adapt_state_ex).form_app.len = BG(url_adapt_state_ex).url_app.len = 0;
BG(url_adapt_state_ex).form_app.s = BG(url_adapt_state_ex).url_app.s = NULL;
REGISTER_INI_ENTRIES();
return SUCCESS;

View File

@ -507,8 +507,8 @@ PHPAPI void php_var_export(zval *struc, int level TSRMLS_DC) /* {{{ */
{
smart_str buf = {0};
php_var_export_ex(struc, level, &buf TSRMLS_CC);
smart_str_0 (&buf);
PHPWRITE(buf.c, buf.len);
smart_str_0(&buf);
PHPWRITE(buf.s->val, buf.s->len);
smart_str_free(&buf);
}
/* }}} */
@ -530,11 +530,11 @@ PHP_FUNCTION(var_export)
smart_str_0 (&buf);
if (return_output) {
RETVAL_STRINGL(buf.c, buf.len);
RETURN_STR(buf.s);
} else {
PHPWRITE(buf.c, buf.len);
PHPWRITE(buf.s->val, buf.s->len);
smart_str_free(&buf);
}
smart_str_free(&buf);
}
/* }}} */
@ -924,9 +924,8 @@ PHP_FUNCTION(serialize)
RETURN_FALSE;
}
if (buf.c) {
//??? RETURN_STRINGL(buf.c, buf.len, 0);
RETURN_STRINGL(buf.c, buf.len);
if (buf.s) {
RETURN_STR(buf.s);
} else {
RETURN_NULL();
}

View File

@ -283,8 +283,8 @@ static inline int add_post_vars(zval *arr, post_var_data_t *vars, zend_bool eof
{
uint64_t max_vars = PG(max_input_vars);
vars->ptr = vars->str.c;
vars->end = vars->str.c + vars->str.len;
vars->ptr = vars->str.s->val;
vars->end = vars->str.s->val + vars->str.s->len;
while (add_post_var(arr, vars, eof TSRMLS_CC)) {
if (++vars->cnt > max_vars) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,
@ -296,7 +296,7 @@ static inline int add_post_vars(zval *arr, post_var_data_t *vars, zend_bool eof
}
if (!eof) {
memmove(vars->str.c, vars->ptr, vars->str.len = vars->end - vars->ptr);
memmove(vars->str.s->val, vars->ptr, vars->str.s->len = vars->end - vars->ptr);
}
return SUCCESS;
}
@ -318,8 +318,8 @@ SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler)
smart_str_appendl(&post_data.str, buf, len);
if (SUCCESS != add_post_vars(arr, &post_data, 0 TSRMLS_CC)) {
if (post_data.str.c) {
efree(post_data.str.c);
if (post_data.str.s) {
smart_str_free(&post_data.str);
}
return;
}
@ -331,8 +331,8 @@ SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler)
}
add_post_vars(arr, &post_data, 1 TSRMLS_CC);
if (post_data.str.c) {
efree(post_data.str.c);
if (post_data.str.s) {
smart_str_free(&post_data.str);
}
}
}

View File

@ -145,13 +145,13 @@
* Macro that does padding. The padding is done by printing
* the character ch.
*/
#define PAD(xbuf, count, ch) do { \
if ((count) > 0) { \
size_t newlen; \
smart_str_alloc(xbuf, (count), 0); \
memset(xbuf->c + xbuf->len, ch, (count)); \
xbuf->len += (count); \
} \
#define PAD(xbuf, count, ch) do { \
if ((count) > 0) { \
size_t newlen; \
smart_str_alloc(xbuf, (count), 0); \
memset(xbuf->s->val + xbuf->s->len, ch, (count)); \
xbuf->s->len += (count); \
} \
} while (0)
#define NUM(c) (c - '0')
@ -700,7 +700,7 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap)
case 'n':
*(va_arg(ap, int *)) = xbuf->len;
*(va_arg(ap, int *)) = xbuf->s->len;
goto skip_output;
/*
@ -795,17 +795,20 @@ skip_output:
PHPAPI int vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) /* {{{ */
{
smart_str xbuf = {0};
int result;
xbuf_format_converter(&xbuf, format, ap);
if (max_len && xbuf.len > max_len) {
xbuf.len = max_len;
if (max_len && xbuf.s->len > max_len) {
xbuf.s->len = max_len;
}
smart_str_0(&xbuf);
*pbuf = xbuf.c;
*pbuf = estrndup(xbuf.s->val, xbuf.s->len);
result = xbuf.s->len;
smart_str_free(&xbuf);
return xbuf.len;
return result;
}
/* }}} */

View File

@ -669,7 +669,7 @@ static int sapi_cli_server_send_headers(sapi_headers_struct *sapi_headers TSRMLS
}
smart_str_appendl(&buffer, "\r\n", 2);
php_cli_server_client_send_through(client, buffer.c, buffer.len);
php_cli_server_client_send_through(client, buffer.s->val, buffer.s->len);
smart_str_free(&buffer);
return SAPI_HEADER_SENT_SUCCESSFULLY;
@ -1961,7 +1961,7 @@ static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server
php_cli_server_chunk *chunk;
smart_str buffer = { 0 };
append_http_status_line(&buffer, client->request.protocol_version, status, 1);
if (!buffer.c) {
if (!buffer.s) {
/* out of memory */
goto fail;
}
@ -1972,7 +1972,7 @@ static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server
smart_str_appendl_ex(&buffer, "\r\n", 2, 1);
smart_str_appendl_ex(&buffer, "\r\n", 2, 1);
chunk = php_cli_server_chunk_heap_new(buffer.c, buffer.c, buffer.len);
chunk = php_cli_server_chunk_heap_new(buffer.s->val, buffer.s->val, buffer.s->len);
if (!chunk) {
smart_str_free_ex(&buffer, 1);
goto fail;
@ -2046,7 +2046,7 @@ static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_serv
}
append_http_status_line(&buffer, client->request.protocol_version, status, 1);
if (!buffer.c) {
if (!buffer.s) {
/* out of memory */
php_cli_server_log_response(client, 500, NULL TSRMLS_CC);
return FAILURE;
@ -2062,7 +2062,7 @@ static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_serv
smart_str_append_generic_ex(&buffer, client->request.sb.st_size, 1, size_t, _unsigned);
smart_str_appendl_ex(&buffer, "\r\n", 2, 1);
smart_str_appendl_ex(&buffer, "\r\n", 2, 1);
chunk = php_cli_server_chunk_heap_new(buffer.c, buffer.c, buffer.len);
chunk = php_cli_server_chunk_heap_new(buffer.s->val, buffer.s->val, buffer.s->len);
if (!chunk) {
smart_str_free_ex(&buffer, 1);
php_cli_server_log_response(client, 500, NULL TSRMLS_CC);