X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_api.c;h=d0acbf3e7e6e13b68ab2814c7dd4540df3fad652;hp=5840edacb94123622c91fb3377bf9e06b3b80fda;hb=a12e8ddfaa5a94e76261f165b0c0299c87b886b1;hpb=e26d1af5bcad6068bcd4854693d6a1fa12d7912d diff --git a/http_api.c b/http_api.c index 5840eda..d0acbf3 100644 --- a/http_api.c +++ b/http_api.c @@ -39,12 +39,11 @@ #ifdef ZEND_ENGINE_2 # include "ext/standard/php_http.h" -#else - #include "http_build_query.c" #endif #include "php_http.h" #include "php_http_api.h" +#include "php_http_std_defs.h" ZEND_DECLARE_MODULE_GLOBALS(http) @@ -128,7 +127,6 @@ static int check_day(char *day, size_t len); static int check_month(char *month); static int check_tzone(char *tzone); - static int http_ob_stack_get(php_ob_buffer *, php_ob_buffer **); /* {{{ static int http_sort_q(const void *, const void *) */ @@ -167,10 +165,10 @@ static STATUS _http_send_chunk(const void *data, const size_t begin, if (php_stream_seek(s, begin, SEEK_SET)) { return FAILURE; } - buf = (char *) ecalloc(1, HTTP_BUF_SIZE); + buf = (char *) ecalloc(1, HTTP_SENDBUF_SIZE); /* read into buf and write out */ - while ((len -= HTTP_BUF_SIZE) >= 0) { - if (!(read = php_stream_read(s, buf, HTTP_BUF_SIZE))) { + while ((len -= HTTP_SENDBUF_SIZE) >= 0) { + if (!(read = php_stream_read(s, buf, HTTP_SENDBUF_SIZE))) { efree(buf); return FAILURE; } @@ -182,7 +180,7 @@ static STATUS _http_send_chunk(const void *data, const size_t begin, /* read & write left over */ if (len) { - if (read = php_stream_read(s, buf, HTTP_BUF_SIZE + len)) { + if (read = php_stream_read(s, buf, HTTP_SENDBUF_SIZE + len)) { if (read - php_body_write(buf, read TSRMLS_CC)) { efree(buf); return FAILURE; @@ -300,16 +298,19 @@ static STATUS http_ob_stack_get(php_ob_buffer *o, php_ob_buffer **s) PHP_HTTP_API char *_http_date(time_t t TSRMLS_DC) { struct tm *gmtime, tmbuf; - char *date = ecalloc(1, 31); - - gmtime = php_gmtime_r(&t, &tmbuf); - snprintf(date, 30, - "%s, %02d %s %04d %02d:%02d:%02d GMT", - days[gmtime->tm_wday], gmtime->tm_mday, - months[gmtime->tm_mon], gmtime->tm_year + 1900, - gmtime->tm_hour, gmtime->tm_min, gmtime->tm_sec - ); - return date; + + if (gmtime = php_gmtime_r(&t, &tmbuf)) { + char *date = ecalloc(1, 31); + snprintf(date, 30, + "%s, %02d %s %04d %02d:%02d:%02d GMT", + days[gmtime->tm_wday], gmtime->tm_mday, + months[gmtime->tm_mon], gmtime->tm_year + 1900, + gmtime->tm_hour, gmtime->tm_min, gmtime->tm_sec + ); + return date; + } + + return NULL; } /* }}} */ @@ -371,7 +372,8 @@ PHP_HTTP_API time_t _http_parse_date(const char *date) /* a digit */ int val; char *end; - if((seconds == -1) && (3 == sscanf(date, "%02d:%02d:%02d", &hours, &minutes, &seconds))) { + if ((seconds == -1) && + (3 == sscanf(date, "%02d:%02d:%02d", &hours, &minutes, &seconds))) { /* time stamp! */ date += 8; found = 1; @@ -379,7 +381,8 @@ PHP_HTTP_API time_t _http_parse_date(const char *date) else { val = (int) strtol(date, &end, 10); - if ((tz_offset == -1) && ((end - date) == 4) && (val < 1300) && (indate < date) && ((date[-1] == '+' || date[-1] == '-'))) { + if ((tz_offset == -1) && ((end - date) == 4) && (val < 1300) && + (indate < date) && ((date[-1] == '+' || date[-1] == '-'))) { /* four digits and a value less than 1300 and it is preceeded with a plus or minus. This is a time zone indication. */ found = 1; @@ -483,8 +486,8 @@ PHP_HTTP_API time_t _http_parse_date(const char *date) } /* }}} */ -/* {{{ inline char *http_etag(void *, size_t, http_send_mode) */ -PHP_HTTP_API inline char *_http_etag(const void *data_ptr, const size_t data_len, +/* {{{ char *http_etag(void *, size_t, http_send_mode) */ +PHP_HTTP_API char *_http_etag(const void *data_ptr, const size_t data_len, const http_send_mode data_mode TSRMLS_DC) { char ssb_buf[128] = {0}; @@ -527,8 +530,8 @@ PHP_HTTP_API inline char *_http_etag(const void *data_ptr, const size_t data_len } /* }}} */ -/* {{{ inline http_lmod(void *, http_send_mode) */ -PHP_HTTP_API inline time_t _http_lmod(const void *data_ptr, const http_send_mode data_mode TSRMLS_DC) +/* {{{ time_t http_lmod(void *, http_send_mode) */ +PHP_HTTP_API time_t _http_lmod(const void *data_ptr, const http_send_mode data_mode TSRMLS_DC) { switch (data_mode) { @@ -560,39 +563,16 @@ PHP_HTTP_API inline time_t _http_lmod(const void *data_ptr, const http_send_mode } /* }}} */ -/* {{{inline int http_is_range_request(void) */ -PHP_HTTP_API inline int _http_is_range_request(TSRMLS_D) -{ - return zend_hash_exists(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), - "HTTP_RANGE", sizeof("HTTP_RANGE")); -} -/* }}} */ - -/* {{{ inline STATUS http_send_status(int) */ -PHP_HTTP_API inline STATUS _http_send_status(const int status TSRMLS_DC) -{ - int s = status; - return sapi_header_op(SAPI_HEADER_SET_STATUS, (void *) s TSRMLS_CC); -} -/* }}} */ - -/* {{{ inline STATUS http_send_header(char *) */ -PHP_HTTP_API inline STATUS _http_send_header(const char *header TSRMLS_DC) -{ - return http_send_status_header(0, header); -} -/* }}} */ - -/* {{{ inline STATUS http_send_status_header(int, char *) */ -PHP_HTTP_API inline STATUS _http_send_status_header(const int status, const char *header TSRMLS_DC) +/* {{{ STATUS http_send_status_header(int, char *) */ +PHP_HTTP_API STATUS _http_send_status_header(const int status, const char *header TSRMLS_DC) { sapi_header_line h = {(char *) header, strlen(header), status}; return sapi_header_op(SAPI_HEADER_REPLACE, &h TSRMLS_CC); } /* }}} */ -/* {{{ inline zval *http_get_server_var(char *) */ -PHP_HTTP_API inline zval *_http_get_server_var(const char *key TSRMLS_DC) +/* {{{ zval *http_get_server_var(char *) */ +PHP_HTTP_API zval *_http_get_server_var(const char *key TSRMLS_DC) { zval **var; if (SUCCESS == zend_hash_find( @@ -729,15 +709,18 @@ PHP_HTTP_API int _http_etag_match(const char *entry, const char *etag TSRMLS_DC) /* {{{ STATUS http_send_last_modified(int) */ PHP_HTTP_API STATUS _http_send_last_modified(const time_t t TSRMLS_DC) { - char modified[96] = "Last-Modified: ", *date; - date = http_date(t); - strcat(modified, date); - efree(date); + char *date = NULL; + if (date = http_date(t)) { + char modified[96] = "Last-Modified: "; + strcat(modified, date); + efree(date); - /* remember */ - HTTP_G(lmod) = t; + /* remember */ + HTTP_G(lmod) = t; - return http_send_header(modified); + return http_send_header(modified); + } + return FAILURE; } /* }}} */ @@ -995,10 +978,7 @@ PHP_HTTP_API char *_http_negotiate_q(const char *entry, const zval *supported, } /* walk through the supported array */ - for ( zend_hash_internal_pointer_reset(Z_ARRVAL_P(supported)); - SUCCESS == zend_hash_get_current_data( - Z_ARRVAL_P(supported), (void **) &zsupp); - zend_hash_move_forward(Z_ARRVAL_P(supported))) { + FOREACH_VAL(supported, zsupp) { if (!strcasecmp(Z_STRVAL_PP(zsupp), Z_STRVAL_PP(zentry))) { add_assoc_double(zentries, Z_STRVAL_PP(zsupp), qual); break; @@ -1025,8 +1005,8 @@ PHP_HTTP_API char *_http_negotiate_q(const char *entry, const zval *supported, } /* }}} */ -/* {{{ http_range_status http_get_request_ranges(zval *zranges, size_t) */ -PHP_HTTP_API http_range_status _http_get_request_ranges(zval *zranges, +/* {{{ http_range_status http_get_request_ranges(HashTable *ranges, size_t) */ +PHP_HTTP_API http_range_status _http_get_request_ranges(HashTable *ranges, const size_t length TSRMLS_DC) { zval *zrange; @@ -1135,7 +1115,7 @@ PHP_HTTP_API http_range_status _http_get_request_ranges(zval *zranges, array_init(zentry); add_index_long(zentry, 0, begin); add_index_long(zentry, 1, end); - add_next_index_zval(zranges, zentry); + zend_hash_next_index_insert(ranges, &zentry, sizeof(zval *), NULL); begin = -1; end = -1; @@ -1153,23 +1133,24 @@ PHP_HTTP_API http_range_status _http_get_request_ranges(zval *zranges, } /* }}} */ -/* {{{ STATUS http_send_ranges(zval *, void *, size_t, http_send_mode) */ -PHP_HTTP_API STATUS _http_send_ranges(zval *zranges, const void *data, const size_t size, const http_send_mode mode TSRMLS_DC) +/* {{{ STATUS http_send_ranges(HashTable *, void *, size_t, http_send_mode) */ +PHP_HTTP_API STATUS _http_send_ranges(HashTable *ranges, const void *data, const size_t size, const http_send_mode mode TSRMLS_DC) { - int c; long **begin, **end; zval **zrange; - /* Send HTTP 206 Partial Content */ - http_send_status(206); - /* single range */ - if ((c = zend_hash_num_elements(Z_ARRVAL_P(zranges))) == 1) { + if (zend_hash_num_elements(ranges) == 1) { char range_header[256] = {0}; - zend_hash_index_find(Z_ARRVAL_P(zranges), 0, (void **) &zrange); - zend_hash_index_find(Z_ARRVAL_PP(zrange), 0, (void **) &begin); - zend_hash_index_find(Z_ARRVAL_PP(zrange), 1, (void **) &end); + if (SUCCESS != zend_hash_index_find(ranges, 0, (void **) &zrange) || + SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(zrange), 0, (void **) &begin) || + SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(zrange), 1, (void **) &end)) { + return FAILURE; + } + + /* Send HTTP 206 Partial Content */ + http_send_status(206); /* send content range header */ snprintf(range_header, 255, "Content-Range: bytes %d-%d/%d", **begin, **end, size); @@ -1181,24 +1162,21 @@ PHP_HTTP_API STATUS _http_send_ranges(zval *zranges, const void *data, const siz /* multi range */ else { - int i; char bound[23] = {0}, preface[1024] = {0}, multi_header[68] = "Content-Type: multipart/byteranges; boundary="; + /* Send HTTP 206 Partial Content */ + http_send_status(206); + + /* send multipart/byteranges header */ snprintf(bound, 22, "--%d%0.9f", time(NULL), php_combined_lcg(TSRMLS_C)); strncat(multi_header, bound + 2, 21); http_send_header(multi_header); /* send each requested chunk */ - for ( i = 0, zend_hash_internal_pointer_reset(Z_ARRVAL_P(zranges)); - i < c; - i++, zend_hash_move_forward(Z_ARRVAL_P(zranges))) { - if ( HASH_KEY_NON_EXISTANT == zend_hash_get_current_data( - Z_ARRVAL_P(zranges), (void **) &zrange) || - SUCCESS != zend_hash_index_find( - Z_ARRVAL_PP(zrange), 0, (void **) &begin) || - SUCCESS != zend_hash_index_find( - Z_ARRVAL_PP(zrange), 1, (void **) &end)) { + FOREACH_HASH_VAL(ranges, zrange) { + if (SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(zrange), 0, (void **) &begin) || + SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(zrange), 1, (void **) &end)) { break; } @@ -1221,15 +1199,16 @@ PHP_HTTP_API STATUS _http_send_ranges(zval *zranges, const void *data, const siz } /* write boundary once more */ - php_body_write(HTTP_CRLF, 2 TSRMLS_CC); + php_body_write(HTTP_CRLF, sizeof(HTTP_CRLF) - 1 TSRMLS_CC); php_body_write(bound, strlen(bound) TSRMLS_CC); + php_body_write("--", 2 TSRMLS_CC); return SUCCESS; } } /* }}} */ -/* {{{ STATUS http_send(void *, sizezo_t, http_send_mode) */ +/* {{{ STATUS http_send(void *, size_t, http_send_mode) */ PHP_HTTP_API STATUS _http_send(const void *data_ptr, const size_t data_size, const http_send_mode data_mode TSRMLS_DC) { @@ -1238,6 +1217,9 @@ PHP_HTTP_API STATUS _http_send(const void *data_ptr, const size_t data_size, if (!data_ptr) { return FAILURE; } + if (!data_size) { + return SUCCESS; + } /* etag handling */ if (HTTP_G(etag_started)) { @@ -1277,28 +1259,24 @@ PHP_HTTP_API STATUS _http_send(const void *data_ptr, const size_t data_size, ) { STATUS result = FAILURE; - zval *zranges = NULL; - MAKE_STD_ZVAL(zranges); - array_init(zranges); + HashTable ranges; + zend_hash_init(&ranges, 0, NULL, ZVAL_PTR_DTOR, 0); - switch (http_get_request_ranges(zranges, data_size)) + switch (http_get_request_ranges(&ranges, data_size)) { case RANGE_NO: - zval_dtor(zranges); - efree(zranges); + zend_hash_destroy(&ranges); /* go ahead and send all */ break; case RANGE_OK: - result = http_send_ranges(zranges, data_ptr, data_size, data_mode); - zval_dtor(zranges); - efree(zranges); + result = http_send_ranges(&ranges, data_ptr, data_size, data_mode); + zend_hash_destroy(&ranges); return result; break; case RANGE_ERR: - zval_dtor(zranges); - efree(zranges); + zend_hash_destroy(&ranges); http_send_status(416); return FAILURE; break; @@ -1314,49 +1292,23 @@ PHP_HTTP_API STATUS _http_send(const void *data_ptr, const size_t data_size, } /* }}} */ -/* {{{ STATUS http_send_data(zval *) */ -PHP_HTTP_API STATUS _http_send_data(const zval *zdata TSRMLS_DC) -{ - if (!Z_STRLEN_P(zdata)) { - return SUCCESS; - } - if (!Z_STRVAL_P(zdata)) { - return FAILURE; - } - - return http_send(Z_STRVAL_P(zdata), Z_STRLEN_P(zdata), SEND_DATA); -} -/* }}} */ - /* {{{ STATUS http_send_stream(php_stream *) */ -PHP_HTTP_API STATUS _http_send_stream(const php_stream *file TSRMLS_DC) -{ - if (php_stream_stat((php_stream *) file, &HTTP_G(ssb))) { - return FAILURE; - } - - return http_send(file, HTTP_G(ssb).sb.st_size, SEND_RSRC); -} -/* }}} */ - -/* {{{ STATUS http_send_file(zval *) */ -PHP_HTTP_API STATUS _http_send_file(const zval *zfile TSRMLS_DC) +PHP_HTTP_API STATUS _http_send_stream_ex(php_stream *file, + zend_bool close_stream TSRMLS_DC) { - php_stream *file; - STATUS ret; + STATUS status; - if (!Z_STRLEN_P(zfile)) { + if ((!file) || php_stream_stat(file, &HTTP_G(ssb))) { return FAILURE; } - if (!(file = php_stream_open_wrapper(Z_STRVAL_P(zfile), "rb", - REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL))) { - return FAILURE; + status = http_send(file, HTTP_G(ssb).sb.st_size, SEND_RSRC); + + if (close_stream) { + php_stream_close(file); } - ret = http_send_stream(file); - php_stream_close(file); - return ret; + return status; } /* }}} */ @@ -1425,13 +1377,13 @@ PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded, /* }}} */ /* {{{ proto STATUS http_split_response_ex(char *, size_t, zval *, zval *) */ -PHP_HTTP_API STATUS _http_split_response_ex( char *response, +PHP_HTTP_API STATUS _http_split_response_ex(char *response, size_t response_len, zval *zheaders, zval *zbody TSRMLS_DC) { char *body = NULL; char *header = response; - while ((response - header + 4) < response_len) { + while (0 < (response_len - (response - header + 4))) { if ( (*response++ == '\r') && (*response++ == '\n') && (*response++ == '\r') && @@ -1520,12 +1472,11 @@ PHP_HTTP_API STATUS _http_parse_headers(char *header, int header_len, zval *arra /* {{{ void http_get_request_headers(zval *) */ PHP_HTTP_API void _http_get_request_headers(zval *array TSRMLS_DC) { - char *key; + char *key = NULL; + long idx = 0; - for ( zend_hash_internal_pointer_reset(HTTP_SERVER_VARS); - zend_hash_get_current_key(HTTP_SERVER_VARS, &key, NULL, 0) != HASH_KEY_NON_EXISTANT; - zend_hash_move_forward(HTTP_SERVER_VARS)) { - if (!strncmp(key, "HTTP_", 5)) { + FOREACH_HASH_KEY(HTTP_SERVER_VARS, key, idx) { + if (key && !strncmp(key, "HTTP_", 5)) { zval **header; zend_hash_get_current_data(HTTP_SERVER_VARS, (void **) &header); add_assoc_stringl(array, pretty_key(key + 5, strlen(key) - 5, 1, 1), Z_STRVAL_PP(header), Z_STRLEN_PP(header), 1); @@ -1534,6 +1485,47 @@ PHP_HTTP_API void _http_get_request_headers(zval *array TSRMLS_DC) } /* }}} */ +/* {{{ STATUS http_urlencode_hash_ex(HashTable *, int, char **, size_t *) */ +PHP_HTTP_API STATUS _http_urlencode_hash_ex(HashTable *hash, int override_argsep, + char *pre_encoded_data, size_t pre_encoded_len, + char **encoded_data, size_t *encoded_len TSRMLS_DC) +{ + smart_str qstr = {0}; + + if (override_argsep) { + HTTP_URL_ARGSEP_OVERRIDE; + } + + if (pre_encoded_len && pre_encoded_data) { + smart_str_appendl(&qstr, pre_encoded_data, pre_encoded_len); + } + + if (SUCCESS != php_url_encode_hash_ex(hash, &qstr, NULL, 0, NULL, 0, NULL, 0, NULL TSRMLS_CC)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't encode query data"); + if (qstr.c) { + efree(qstr.c); + } + if (override_argsep) { + HTTP_URL_ARGSEP_RESTORE; + } + return FAILURE; + } + + if (override_argsep) { + HTTP_URL_ARGSEP_RESTORE; + } + + smart_str_0(&qstr); + + *encoded_data = qstr.c; + if (encoded_len) { + *encoded_len = qstr.len; + } + + return SUCCESS; +} +/* }}} */ + /* {{{ STATUS http_auth_header(char *, char*) */ PHP_HTTP_API STATUS _http_auth_header(const char *type, const char *realm TSRMLS_DC) { @@ -1578,6 +1570,170 @@ PHP_HTTP_API STATUS _http_auth_credentials(char **user, char **pass TSRMLS_DC) } /* }}} */ +#ifndef ZEND_ENGINE_2 +/* {{{ php_url_encode_hash + Author: Sara Golemon */ +PHP_HTTP_API STATUS php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, + const char *num_prefix, int num_prefix_len, + const char *key_prefix, int key_prefix_len, + const char *key_suffix, int key_suffix_len, + zval *type TSRMLS_DC) +{ + char *arg_sep = NULL, *key = NULL, *ekey, *newprefix, *p; + int arg_sep_len, key_len, ekey_len, key_type, newprefix_len; + ulong idx; + zval **zdata = NULL, *copyzval; + + if (!ht) { + return FAILURE; + } + + if (ht->nApplyCount > 0) { + /* Prevent recursion */ + return SUCCESS; + } + + arg_sep = INI_STR("arg_separator.output"); + if (!arg_sep || !strlen(arg_sep)) { + arg_sep = HTTP_URL_ARGSEP_DEFAULT; + } + arg_sep_len = strlen(arg_sep); + + for (zend_hash_internal_pointer_reset(ht); + (key_type = zend_hash_get_current_key_ex(ht, &key, &key_len, &idx, 0, NULL)) != HASH_KEY_NON_EXISTANT; + zend_hash_move_forward(ht) + ) { + if (key_type == HASH_KEY_IS_STRING && key_len && key[key_len-1] == '\0') { + /* We don't want that trailing NULL */ + key_len -= 1; + } + +#ifdef ZEND_ENGINE_2 + /* handling for private & protected object properties */ + if (key && *key == '\0' && type != NULL) { + char *tmp; + + zend_object *zobj = zend_objects_get_address(type TSRMLS_CC); + if (zend_check_property_access(zobj, key TSRMLS_CC) != SUCCESS) { + /* private or protected property access outside of the class */ + continue; + } + zend_unmangle_property_name(key, &tmp, &key); + key_len = strlen(key); + } +#endif + + if (zend_hash_get_current_data_ex(ht, (void **)&zdata, NULL) == FAILURE || !zdata || !(*zdata)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error traversing form data array."); + return FAILURE; + } + if (Z_TYPE_PP(zdata) == IS_ARRAY || Z_TYPE_PP(zdata) == IS_OBJECT) { + if (key_type == HASH_KEY_IS_STRING) { + ekey = php_url_encode(key, key_len, &ekey_len); + newprefix_len = key_suffix_len + ekey_len + key_prefix_len + 1; + newprefix = emalloc(newprefix_len + 1); + p = newprefix; + + if (key_prefix) { + memcpy(p, key_prefix, key_prefix_len); + p += key_prefix_len; + } + + memcpy(p, ekey, ekey_len); + p += ekey_len; + efree(ekey); + + if (key_suffix) { + memcpy(p, key_suffix, key_suffix_len); + p += key_suffix_len; + } + + *(p++) = '['; + *p = '\0'; + } else { + /* Is an integer key */ + ekey_len = spprintf(&ekey, 12, "%ld", idx); + newprefix_len = key_prefix_len + num_prefix_len + ekey_len + key_suffix_len + 1; + newprefix = emalloc(newprefix_len + 1); + p = newprefix; + + if (key_prefix) { + memcpy(p, key_prefix, key_prefix_len); + p += key_prefix_len; + } + + memcpy(p, num_prefix, num_prefix_len); + p += num_prefix_len; + + memcpy(p, ekey, ekey_len); + p += ekey_len; + efree(ekey); + + if (key_suffix) { + memcpy(p, key_suffix, key_suffix_len); + p += key_suffix_len; + } + *(p++) = '['; + *p = '\0'; + } + ht->nApplyCount++; + php_url_encode_hash_ex(HASH_OF(*zdata), formstr, NULL, 0, newprefix, newprefix_len, "]", 1, (Z_TYPE_PP(zdata) == IS_OBJECT ? *zdata : NULL) TSRMLS_CC); + ht->nApplyCount--; + efree(newprefix); + } else if (Z_TYPE_PP(zdata) == IS_NULL || Z_TYPE_PP(zdata) == IS_RESOURCE) { + /* Skip these types */ + continue; + } else { + if (formstr->len) { + smart_str_appendl(formstr, arg_sep, arg_sep_len); + } + /* Simple key=value */ + smart_str_appendl(formstr, key_prefix, key_prefix_len); + if (key_type == HASH_KEY_IS_STRING) { + ekey = php_url_encode(key, key_len, &ekey_len); + smart_str_appendl(formstr, ekey, ekey_len); + efree(ekey); + } else { + /* Numeric key */ + if (num_prefix) { + smart_str_appendl(formstr, num_prefix, num_prefix_len); + } + ekey_len = spprintf(&ekey, 12, "%ld", idx); + smart_str_appendl(formstr, ekey, ekey_len); + efree(ekey); + } + smart_str_appendl(formstr, key_suffix, key_suffix_len); + smart_str_appendl(formstr, "=", 1); + switch (Z_TYPE_PP(zdata)) { + case IS_STRING: + ekey = php_url_encode(Z_STRVAL_PP(zdata), Z_STRLEN_PP(zdata), &ekey_len); + break; + case IS_LONG: + case IS_BOOL: + ekey_len = spprintf(&ekey, 12, "%ld", Z_LVAL_PP(zdata)); + break; + case IS_DOUBLE: + ekey_len = spprintf(&ekey, 48, "%.*G", (int) EG(precision), Z_DVAL_PP(zdata)); + break; + default: + /* fall back on convert to string */ + MAKE_STD_ZVAL(copyzval); + *copyzval = **zdata; + zval_copy_ctor(copyzval); + convert_to_string_ex(©zval); + ekey = php_url_encode(Z_STRVAL_P(copyzval), Z_STRLEN_P(copyzval), &ekey_len); + zval_ptr_dtor(©zval); + } + smart_str_appendl(formstr, ekey, ekey_len); + efree(ekey); + } + } + + return SUCCESS; +} +/* }}} */ +#endif /* !ZEND_ENDGINE_2 */ + /* }}} public API */ /*