From: Michael Wallner Date: Wed, 14 Sep 2016 07:54:24 +0000 (+0200) Subject: Merge branch 'v2.6.x' X-Git-Tag: RELEASE_3_1_0_RC1~27 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=commitdiff_plain;h=e7f3c1766222862532aadbfbafdb6017fef2747c;hp=-c Merge branch 'v2.6.x' --- e7f3c1766222862532aadbfbafdb6017fef2747c diff --combined src/php_http_buffer.c index b214f1d,64e559a..d7cfd56 --- a/src/php_http_buffer.c +++ b/src/php_http_buffer.c @@@ -13,8 -13,7 +13,8 @@@ #include "php.h" #include "php_http_buffer.h" -PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_init_ex(php_http_buffer_t *buf, size_t chunk_size, int flags) +PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_init_ex( + php_http_buffer_t *buf, size_t chunk_size, unsigned flags) { if (!buf) { buf = pemalloc(sizeof(*buf), flags & PHP_HTTP_BUFFER_INIT_PERSISTENT); @@@ -23,8 -22,7 +23,8 @@@ if (buf) { buf->size = (chunk_size) ? chunk_size : PHP_HTTP_BUFFER_DEFAULT_SIZE; buf->pmem = (flags & PHP_HTTP_BUFFER_INIT_PERSISTENT) ? 1 : 0; - buf->data = (flags & PHP_HTTP_BUFFER_INIT_PREALLOC) ? pemalloc(buf->size, buf->pmem) : NULL; + buf->data = (flags & PHP_HTTP_BUFFER_INIT_PREALLOC) ? + pemalloc(buf->size, buf->pmem) : NULL; buf->free = (flags & PHP_HTTP_BUFFER_INIT_PREALLOC) ? buf->size : 0; buf->used = 0; } @@@ -32,21 -30,22 +32,25 @@@ return buf; } -PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_from_string_ex(php_http_buffer_t *buf, const char *string, size_t length) +PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_from_string_ex( + php_http_buffer_t *buf, const char *str, size_t len) { + int free_buf = !!buf; + if ((buf = php_http_buffer_init(buf))) { - if (PHP_HTTP_BUFFER_NOMEM == php_http_buffer_append(buf, string, length)) { + if (PHP_HTTP_BUFFER_NOMEM == php_http_buffer_append(buf, str, len)) { - pefree(buf, buf->pmem); + if (free_buf) { + pefree(buf, buf->pmem); + } buf = NULL; } } return buf; } -PHP_HTTP_BUFFER_API size_t php_http_buffer_resize_ex(php_http_buffer_t *buf, size_t len, size_t override_size, int allow_error) +PHP_HTTP_BUFFER_API size_t php_http_buffer_resize_ex( + php_http_buffer_t *buf, size_t len, size_t override_size, + zend_bool allow_error) { char *ptr = NULL; #if 0 @@@ -60,8 -59,7 +64,8 @@@ } if (allow_error) { - ptr = perealloc_recoverable(buf->data, buf->used + buf->free + size, buf->pmem); + ptr = perealloc_recoverable(buf->data, + buf->used + buf->free + size, buf->pmem); } else { ptr = perealloc(buf->data, buf->used + buf->free + size, buf->pmem); } @@@ -78,8 -76,7 +82,8 @@@ return 0; } -PHP_HTTP_BUFFER_API char *php_http_buffer_account(php_http_buffer_t *buf, size_t to_account) +PHP_HTTP_BUFFER_API char *php_http_buffer_account( + php_http_buffer_t *buf, size_t to_account) { assert(to_account <= buf->free); @@@ -105,12 -102,9 +109,12 @@@ PHP_HTTP_BUFFER_API size_t php_http_buf return buf->used; } -PHP_HTTP_BUFFER_API size_t php_http_buffer_append(php_http_buffer_t *buf, const char *append, size_t append_len) +PHP_HTTP_BUFFER_API size_t php_http_buffer_append(php_http_buffer_t *buf, + const char *append, size_t append_len) { - if (buf->free < append_len && PHP_HTTP_BUFFER_NOMEM == php_http_buffer_resize(buf, append_len)) { + if ( buf->free < append_len && + PHP_HTTP_BUFFER_NOMEM == php_http_buffer_resize(buf, append_len) + ) { return PHP_HTTP_BUFFER_NOMEM; } memcpy(buf->data + buf->used, append, append_len); @@@ -119,8 -113,7 +123,8 @@@ return append_len; } -PHP_HTTP_BUFFER_API size_t php_http_buffer_appendf(php_http_buffer_t *buf, const char *format, ...) +PHP_HTTP_BUFFER_API size_t php_http_buffer_appendf(php_http_buffer_t *buf, + const char *format, ...) { va_list argv; char *append; @@@ -139,8 -132,7 +143,8 @@@ return append_len; } -PHP_HTTP_BUFFER_API char *php_http_buffer_data(const php_http_buffer_t *buf, char **into, size_t *len) +PHP_HTTP_BUFFER_API char *php_http_buffer_data(const php_http_buffer_t *buf, + char **into, size_t *len) { char *copy = ecalloc(1, buf->used + 1); memcpy(copy, buf->data, buf->used); @@@ -153,8 -145,7 +157,8 @@@ return copy; } -PHP_HTTP_BUFFER_API size_t php_http_buffer_cut(php_http_buffer_t *buf, size_t offset, size_t length) +PHP_HTTP_BUFFER_API size_t php_http_buffer_cut(php_http_buffer_t *buf, + size_t offset, size_t length) { if (offset > buf->used) { return 0; @@@ -162,19 -153,15 +166,19 @@@ if (offset + length > buf->used) { length = buf->used - offset; } - memmove(buf->data + offset, buf->data + offset + length, buf->used - length - offset); + memmove(buf->data + offset, buf->data + offset + length, + buf->used - length - offset); buf->used -= length; buf->free += length; return length; } -PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_fix(php_http_buffer_t *buf) +PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_fix( + php_http_buffer_t *buf) { - if (buf->free < 1 && PHP_HTTP_BUFFER_NOMEM == php_http_buffer_resize_ex(buf, 1, 1, 0)) { + if ( buf->free < 1 && + PHP_HTTP_BUFFER_NOMEM == php_http_buffer_resize_ex(buf, 1, 1, 0) + ) { return NULL; } buf->data[buf->used] = '\0'; @@@ -206,16 -193,14 +210,16 @@@ PHP_HTTP_BUFFER_API void php_http_buffe } } -PHP_HTTP_BUFFER_API size_t php_http_buffer_chunk_buffer(php_http_buffer_t **s, const char *data, size_t data_len, char **chunk, size_t chunk_size) +PHP_HTTP_BUFFER_API size_t php_http_buffer_chunk_buffer(php_http_buffer_t **s, + const char *data, size_t data_len, char **chunk, size_t chunk_size) { php_http_buffer_t *storage; *chunk = NULL; if (!*s) { - *s = php_http_buffer_init_ex(NULL, chunk_size << 1, chunk_size ? PHP_HTTP_BUFFER_INIT_PREALLOC : 0); + *s = php_http_buffer_init_ex(NULL, chunk_size << 1, + chunk_size ? PHP_HTTP_BUFFER_INIT_PREALLOC : 0); } storage = *s; @@@ -238,15 -223,13 +242,15 @@@ return 0; } -PHP_HTTP_BUFFER_API size_t php_http_buffer_chunked_output(php_http_buffer_t **s, const char *data, size_t data_len, size_t chunk_len, php_http_buffer_pass_func_t passout, void *opaque TSRMLS_DC) +PHP_HTTP_BUFFER_API size_t php_http_buffer_chunked_output(php_http_buffer_t **s, + const char *data, size_t data_len, size_t chunk_len, + php_http_buffer_pass_func_t passout, void *opaque) { char *chunk = NULL; size_t passed = 0, got = 0; while ((got = php_http_buffer_chunk_buffer(s, data, data_len, &chunk, chunk_len))) { - if (PHP_HTTP_BUFFER_PASS0 == passout(opaque, chunk, got TSRMLS_CC)) { + if (PHP_HTTP_BUFFER_PASS0 == passout(opaque, chunk, got)) { PTR_SET(chunk, NULL); return PHP_HTTP_BUFFER_PASS0; } @@@ -264,19 -247,15 +268,19 @@@ return passed; } -PHP_HTTP_BUFFER_API ssize_t php_http_buffer_passthru(php_http_buffer_t **s, size_t chunk_size, php_http_buffer_pass_func_t passin, void *passin_arg, php_http_buffer_pass_func_t passon, void *passon_arg TSRMLS_DC) +PHP_HTTP_BUFFER_API ssize_t php_http_buffer_passthru(php_http_buffer_t **s, size_t chunk_size, + php_http_buffer_pass_func_t passin, void *passin_arg, + php_http_buffer_pass_func_t passon, void *passon_arg) { - size_t passed_on = 0, passed_in = php_http_buffer_chunked_input(s, chunk_size, passin, passin_arg TSRMLS_CC); + size_t passed_on = 0, passed_in; + + passed_in = php_http_buffer_chunked_input(s, chunk_size, passin, passin_arg); if (passed_in == PHP_HTTP_BUFFER_PASS0) { return passed_in; } if (passed_in || (*s)->used) { - passed_on = passon(passon_arg, (*s)->data, (*s)->used TSRMLS_CC); + passed_on = passon(passon_arg, (*s)->data, (*s)->used); if (passed_on == PHP_HTTP_BUFFER_PASS0) { return passed_on; @@@ -290,20 -269,18 +294,20 @@@ return passed_on - passed_in; } -PHP_HTTP_BUFFER_API size_t php_http_buffer_chunked_input(php_http_buffer_t **s, size_t chunk_size, php_http_buffer_pass_func_t passin, void *opaque TSRMLS_DC) +PHP_HTTP_BUFFER_API size_t php_http_buffer_chunked_input(php_http_buffer_t **s, + size_t chunk_size, php_http_buffer_pass_func_t passin, void *opaque) { php_http_buffer_t *str; size_t passed; if (!*s) { - *s = php_http_buffer_init_ex(NULL, chunk_size, chunk_size ? PHP_HTTP_BUFFER_INIT_PREALLOC : 0); + *s = php_http_buffer_init_ex(NULL, chunk_size, + chunk_size ? PHP_HTTP_BUFFER_INIT_PREALLOC : 0); } str = *s; php_http_buffer_resize(str, chunk_size); - passed = passin(opaque, str->data + str->used, chunk_size TSRMLS_CC); + passed = passin(opaque, str->data + str->used, chunk_size); if (passed != PHP_HTTP_BUFFER_PASS0) { str->used += passed; @@@ -317,8 -294,7 +321,8 @@@ #ifdef PHP_HTTP_BUFFER_EXTENDED -PHP_HTTP_BUFFER_API int php_http_buffer_cmp(php_http_buffer_t *left, php_http_buffer_t *right) +PHP_HTTP_BUFFER_API int php_http_buffer_cmp(php_http_buffer_t *left, + php_http_buffer_t *right) { if (left->used > right->used) { return -1; @@@ -329,8 -305,7 +333,8 @@@ } } -PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_copy(const php_http_buffer_t *from, php_http_buffer_t *to) +PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_copy( + const php_http_buffer_t *from, php_http_buffer_t *to) { int free_to = !to; @@@ -346,8 -321,7 +350,8 @@@ return to; } -PHP_HTTP_BUFFER_API size_t php_http_buffer_insert(php_http_buffer_t *buf, const char *insert, size_t insert_len, size_t offset) +PHP_HTTP_BUFFER_API size_t php_http_buffer_insert(php_http_buffer_t *buf, + const char *insert, size_t insert_len, size_t offset) { if (PHP_HTTP_BUFFER_NOMEM == php_http_buffer_resize(buf, insert_len)) { return PHP_HTTP_BUFFER_NOMEM; @@@ -359,8 -333,7 +363,8 @@@ return insert_len; } -PHP_HTTP_BUFFER_API size_t php_http_buffer_insertf(php_http_buffer_t *buf, size_t offset, const char *format, ...) +PHP_HTTP_BUFFER_API size_t php_http_buffer_insertf(php_http_buffer_t *buf, + size_t offset, const char *format, ...) { va_list argv; char *insert; @@@ -379,8 -352,7 +383,8 @@@ return insert_len; } -PHP_HTTP_BUFFER_API size_t php_http_buffer_prepend(php_http_buffer_t *buf, const char *prepend, size_t prepend_len) +PHP_HTTP_BUFFER_API size_t php_http_buffer_prepend(php_http_buffer_t *buf, + const char *prepend, size_t prepend_len) { if (PHP_HTTP_BUFFER_NOMEM == php_http_buffer_resize(buf, prepend_len)) { return PHP_HTTP_BUFFER_NOMEM; @@@ -392,8 -364,7 +396,8 @@@ return prepend_len; } -PHP_HTTP_BUFFER_API size_t php_http_buffer_prependf(php_http_buffer_t *buf, const char *format, ...) +PHP_HTTP_BUFFER_API size_t php_http_buffer_prependf(php_http_buffer_t *buf, + const char *format, ...) { va_list argv; char *prepend; @@@ -412,20 -383,13 +416,20 @@@ return prepend_len; } -PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_sub(const php_http_buffer_t *buf, size_t offset, size_t length) +PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_sub( + const php_http_buffer_t *buf, size_t offset, size_t length) { if (offset >= buf->used) { return NULL; } else { - size_t need = 1 + ((length + offset) > buf->used ? (buf->used - offset) : (length - offset)); - php_http_buffer_t *sub = php_http_buffer_init_ex(NULL, need, PHP_HTTP_BUFFER_INIT_PREALLOC | (buf->pmem ? PHP_HTTP_BUFFER_INIT_PERSISTENT:0)); + php_http_buffer_t *sub; + size_t need = 1 + ((length + offset) > buf->used ? + (buf->used - offset) : (length - offset)); + unsigned flags = buf->pmem ? PHP_HTTP_BUFFER_INIT_PERSISTENT : 0; + + sub = php_http_buffer_init_ex(NULL, need, + PHP_HTTP_BUFFER_INIT_PREALLOC | flags); + if (sub) { if (PHP_HTTP_BUFFER_NOMEM == php_http_buffer_append(sub, buf->data + offset, need)) { php_http_buffer_free(&sub); @@@ -437,8 -401,7 +441,8 @@@ } } -PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_right(const php_http_buffer_t *buf, size_t length) +PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_right( + const php_http_buffer_t *buf, size_t length) { if (length < buf->used) { return php_http_buffer_sub(buf, buf->used - length, length); @@@ -448,8 -411,7 +452,8 @@@ } -PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_merge_va(php_http_buffer_t *buf, unsigned argc, va_list argv) +PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_merge_va( + php_http_buffer_t *buf, unsigned argc, va_list argv) { unsigned i = 0; buf = php_http_buffer_init(buf); @@@ -466,8 -428,7 +470,8 @@@ return buf; } -PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_merge_ex(php_http_buffer_t *buf, unsigned argc, ...) +PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_merge_ex( + php_http_buffer_t *buf, unsigned argc, ...) { va_list argv; php_http_buffer_t *ret; diff --combined src/php_http_encoding.c index 7fbe7c7,6d32652..0aa7dc1 --- a/src/php_http_encoding.c +++ b/src/php_http_encoding.c @@@ -28,7 -28,7 +28,7 @@@ static inline int eol_match(char **line } } -const char *php_http_encoding_dechunk(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC) +const char *php_http_encoding_dechunk(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len) { int eol_len = 0; char *n_ptr = NULL; @@@ -50,13 -50,13 +50,13 @@@ * not encoded data and return a copy */ if (e_ptr == encoded) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Data does not seem to be chunked encoded"); + php_error_docref(NULL, E_NOTICE, "Data does not seem to be chunked encoded"); memcpy(*decoded, encoded, encoded_len); *decoded_len = encoded_len; return encoded + encoded_len; } else { efree(*decoded); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected chunk size at pos %tu of %zu but got trash", n_ptr - encoded, encoded_len); + php_error_docref(NULL, E_WARNING, "Expected chunk size at pos %tu of %zu but got trash", n_ptr - encoded, encoded_len); return NULL; } } @@@ -79,16 -79,16 +79,16 @@@ /* there should be CRLF after the chunk size, but we'll ignore SP+ too */ if (*n_ptr && !eol_match(&n_ptr, &eol_len)) { if (eol_len == 2) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected CRLF at pos %tu of %zu but got 0x%02X 0x%02X", n_ptr - encoded, encoded_len, *n_ptr, *(n_ptr + 1)); + php_error_docref(NULL, E_WARNING, "Expected CRLF at pos %tu of %zu but got 0x%02X 0x%02X", n_ptr - encoded, encoded_len, *n_ptr, *(n_ptr + 1)); } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected LF at pos %tu of %zu but got 0x%02X", n_ptr - encoded, encoded_len, *n_ptr); + php_error_docref(NULL, E_WARNING, "Expected LF at pos %tu of %zu but got 0x%02X", n_ptr - encoded, encoded_len, *n_ptr); } } n_ptr += eol_len; /* chunk size pretends more data than we actually got, so it's probably a truncated message */ if (chunk_len > (rest = encoded + encoded_len - n_ptr)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Truncated message: chunk size %lu exceeds remaining data size %lu at pos %tu of %zu", chunk_len, rest, n_ptr - encoded, encoded_len); + php_error_docref(NULL, E_WARNING, "Truncated message: chunk size %lu exceeds remaining data size %lu at pos %tu of %zu", chunk_len, rest, n_ptr - encoded, encoded_len); chunk_len = rest; } @@@ -148,7 -148,7 +148,7 @@@ static inline int php_http_inflate_roun return status; } -ZEND_RESULT_CODE php_http_encoding_deflate(int flags, const char *data, size_t data_len, char **encoded, size_t *encoded_len TSRMLS_DC) +ZEND_RESULT_CODE php_http_encoding_deflate(int flags, const char *data, size_t data_len, char **encoded, size_t *encoded_len) { int status, level, wbits, strategy; z_stream Z; @@@ -185,11 -185,11 +185,11 @@@ } } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not deflate data: %s", zError(status)); + php_error_docref(NULL, E_WARNING, "Could not deflate data: %s", zError(status)); return FAILURE; } -ZEND_RESULT_CODE php_http_encoding_inflate(const char *data, size_t data_len, char **decoded, size_t *decoded_len TSRMLS_DC) +ZEND_RESULT_CODE php_http_encoding_inflate(const char *data, size_t data_len, char **decoded, size_t *decoded_len) { z_stream Z; int status, wbits = PHP_HTTP_WINDOW_BITS_ANY; @@@ -222,16 -222,16 +222,16 @@@ retry_raw_inflate } inflateEnd(&Z); - if (decoded_len && *decoded) { + if (*decoded_len && *decoded) { efree(*decoded); } } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not inflate data: %s", zError(status)); + php_error_docref(NULL, E_WARNING, "Could not inflate data: %s", zError(status)); return FAILURE; } -php_http_encoding_stream_t *php_http_encoding_stream_init(php_http_encoding_stream_t *s, php_http_encoding_stream_ops_t *ops, unsigned flags TSRMLS_DC) +php_http_encoding_stream_t *php_http_encoding_stream_init(php_http_encoding_stream_t *s, php_http_encoding_stream_ops_t *ops, unsigned flags) { int freeme; @@@ -241,6 -241,7 +241,6 @@@ memset(s, 0, sizeof(*s)); s->flags = flags; - TSRMLS_SET_CTX(s->ts); if ((s->ops = ops)) { php_http_encoding_stream_t *ss = s->ops->init(s); @@@ -260,6 -261,8 +260,6 @@@ php_http_encoding_stream_t *php_http_encoding_stream_copy(php_http_encoding_stream_t *from, php_http_encoding_stream_t *to) { - TSRMLS_FETCH_FROM_CTX(from->ts); - if (from->ops->copy) { int freeme; php_http_encoding_stream_t *ns; @@@ -271,6 -274,7 +271,6 @@@ to->flags = from->flags; to->ops = from->ops; - TSRMLS_SET_CTX(to->ts); if ((ns = to->ops->copy(from, to))) { return ns; @@@ -289,7 -293,6 +289,7 @@@ ZEND_RESULT_CODE php_http_encoding_stream_reset(php_http_encoding_stream_t **s) { php_http_encoding_stream_t *ss; + if ((*s)->ops->dtor) { (*s)->ops->dtor(*s); } @@@ -364,6 -367,7 +364,6 @@@ static php_http_encoding_stream_t *defl { int status, level, wbits, strategy, p = (s->flags & PHP_HTTP_ENCODING_STREAM_PERSISTENT); z_streamp ctx = pecalloc(1, sizeof(z_stream), p); - TSRMLS_FETCH_FROM_CTX(s->ts); PHP_HTTP_DEFLATE_LEVEL_SET(s->flags, level); PHP_HTTP_DEFLATE_WBITS_SET(s->flags, wbits); @@@ -378,7 -382,7 +378,7 @@@ status = Z_MEM_ERROR; } pefree(ctx, p); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to initialize deflate encoding stream: %s", zError(status)); + php_error_docref(NULL, E_WARNING, "Failed to initialize deflate encoding stream: %s", zError(status)); return NULL; } @@@ -386,6 -390,7 +386,6 @@@ static php_http_encoding_stream_t *infl { int status, wbits, p = (s->flags & PHP_HTTP_ENCODING_STREAM_PERSISTENT); z_streamp ctx = pecalloc(1, sizeof(z_stream), p); - TSRMLS_FETCH_FROM_CTX(s->ts); PHP_HTTP_INFLATE_WBITS_SET(s->flags, wbits); @@@ -398,7 -403,7 +398,7 @@@ status = Z_MEM_ERROR; } pefree(ctx, p); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to initialize inflate stream: %s", zError(status)); + php_error_docref(NULL, E_WARNING, "Failed to initialize inflate stream: %s", zError(status)); return NULL; } @@@ -421,6 -426,7 +421,6 @@@ static php_http_encoding_stream_t *defl { int status, p = to->flags & PHP_HTTP_ENCODING_STREAM_PERSISTENT; z_streamp from_ctx = from->ctx, to_ctx = pecalloc(1, sizeof(*to_ctx), p); - TSRMLS_FETCH_FROM_CTX(from->ts); if (Z_OK == (status = deflateCopy(to_ctx, from_ctx))) { if ((to_ctx->opaque = php_http_buffer_init_ex(NULL, PHP_HTTP_DEFLATE_BUFFER_SIZE, p ? PHP_HTTP_BUFFER_INIT_PERSISTENT : 0))) { @@@ -431,7 -437,7 +431,7 @@@ deflateEnd(to_ctx); status = Z_MEM_ERROR; } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to copy deflate encoding stream: %s", zError(status)); + php_error_docref(NULL, E_WARNING, "Failed to copy deflate encoding stream: %s", zError(status)); return NULL; } @@@ -439,6 -445,7 +439,6 @@@ static php_http_encoding_stream_t *infl { int status, p = from->flags & PHP_HTTP_ENCODING_STREAM_PERSISTENT; z_streamp from_ctx = from->ctx, to_ctx = pecalloc(1, sizeof(*to_ctx), p); - TSRMLS_FETCH_FROM_CTX(from->ts); if (Z_OK == (status = inflateCopy(to_ctx, from_ctx))) { if ((to_ctx->opaque = php_http_buffer_init_ex(NULL, PHP_HTTP_DEFLATE_BUFFER_SIZE, p ? PHP_HTTP_BUFFER_INIT_PERSISTENT : 0))) { @@@ -449,7 -456,7 +449,7 @@@ inflateEnd(to_ctx); status = Z_MEM_ERROR; } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to copy inflate encoding stream: %s", zError(status)); + php_error_docref(NULL, E_WARNING, "Failed to copy inflate encoding stream: %s", zError(status)); return NULL; } @@@ -457,6 -464,7 +457,6 @@@ static php_http_encoding_stream_t *dech { int p = from->flags & PHP_HTTP_ENCODING_STREAM_PERSISTENT; struct dechunk_ctx *from_ctx = from->ctx, *to_ctx = pemalloc(sizeof(*to_ctx), p); - TSRMLS_FETCH_FROM_CTX(from->ts); if (php_http_buffer_init_ex(&to_ctx->buffer, PHP_HTTP_BUFFER_DEFAULT_SIZE, p ? PHP_HTTP_BUFFER_INIT_PERSISTENT : 0)) { to_ctx->hexlen = from_ctx->hexlen; @@@ -466,7 -474,7 +466,7 @@@ return to; } pefree(to_ctx, p); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to copy inflate encoding stream: out of memory"); + php_error_docref(NULL, E_WARNING, "Failed to copy inflate encoding stream: out of memory"); return NULL; } @@@ -474,6 -482,7 +474,6 @@@ static ZEND_RESULT_CODE deflate_update( { int status; z_streamp ctx = s->ctx; - TSRMLS_FETCH_FROM_CTX(s->ts); /* append input to our buffer */ php_http_buffer_append(PHP_HTTP_BUFFER(ctx->opaque), data, data_len); @@@ -506,7 -515,7 +506,7 @@@ PTR_SET(*encoded, NULL); *encoded_len = 0; - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to update deflate stream: %s", zError(status)); + php_error_docref(NULL, E_WARNING, "Failed to update deflate stream: %s", zError(status)); return FAILURE; } @@@ -514,6 -523,7 +514,6 @@@ static ZEND_RESULT_CODE inflate_update( { int status; z_streamp ctx = s->ctx; - TSRMLS_FETCH_FROM_CTX(s->ts); /* append input to buffer */ php_http_buffer_append(PHP_HTTP_BUFFER(ctx->opaque), data, data_len); @@@ -544,7 -554,7 +544,7 @@@ retry_raw_inflate break; } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to update inflate stream: %s", zError(status)); + php_error_docref(NULL, E_WARNING, "Failed to update inflate stream: %s", zError(status)); return FAILURE; } @@@ -552,9 -562,10 +552,9 @@@ static ZEND_RESULT_CODE dechunk_update( { php_http_buffer_t tmp; struct dechunk_ctx *ctx = s->ctx; - TSRMLS_FETCH_FROM_CTX(s->ts); if (ctx->zeroed) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Dechunk encoding stream has already reached the end of chunked input"); + php_error_docref(NULL, E_WARNING, "Dechunk encoding stream has already reached the end of chunked input"); return FAILURE; } if ((PHP_HTTP_BUFFER_NOMEM == php_http_buffer_append(&ctx->buffer, data, data_len)) || !php_http_buffer_fix(&ctx->buffer)) { @@@ -634,7 -645,7 +634,7 @@@ /* if strtoul() stops at the beginning of the buffered data there's something oddly wrong, i.e. bad input */ if (stop == ctx->buffer.data) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse chunk len from '%.*s'", (int) MIN(16, ctx->buffer.used), ctx->buffer.data); + php_error_docref(NULL, E_WARNING, "Failed to parse chunk len from '%.*s'", (int) MIN(16, ctx->buffer.used), ctx->buffer.data); php_http_buffer_dtor(&tmp); return FAILURE; } @@@ -679,6 -690,7 +679,6 @@@ static ZEND_RESULT_CODE deflate_flush(p { int status; z_streamp ctx = s->ctx; - TSRMLS_FETCH_FROM_CTX(s->ts); *encoded_len = PHP_HTTP_DEFLATE_BUFFER_SIZE; *encoded = emalloc(*encoded_len); @@@ -699,7 -711,7 +699,7 @@@ PTR_SET(*encoded, NULL); *encoded_len = 0; - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to flush deflate stream: %s", zError(status)); + php_error_docref(NULL, E_WARNING, "Failed to flush deflate stream: %s", zError(status)); return FAILURE; } @@@ -727,6 -739,7 +727,6 @@@ static ZEND_RESULT_CODE deflate_finish( { int status; z_streamp ctx = s->ctx; - TSRMLS_FETCH_FROM_CTX(s->ts); *encoded_len = PHP_HTTP_DEFLATE_BUFFER_SIZE; *encoded = emalloc(*encoded_len); @@@ -755,7 -768,7 +755,7 @@@ PTR_SET(*encoded, NULL); *encoded_len = 0; - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to finish deflate stream: %s", zError(status)); + php_error_docref(NULL, E_WARNING, "Failed to finish deflate stream: %s", zError(status)); return FAILURE; } @@@ -763,6 -776,7 +763,6 @@@ static ZEND_RESULT_CODE inflate_finish( { int status; z_streamp ctx = s->ctx; - TSRMLS_FETCH_FROM_CTX(s->ts); if (!PHP_HTTP_BUFFER(ctx->opaque)->used) { *decoded = NULL; @@@ -793,7 -807,7 +793,7 @@@ PTR_SET(*decoded, NULL); *decoded_len = 0; - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to finish inflate stream: %s", zError(status)); + php_error_docref(NULL, E_WARNING, "Failed to finish inflate stream: %s", zError(status)); return FAILURE; } @@@ -900,68 -914,53 +900,68 @@@ php_http_encoding_stream_ops_t *php_htt static zend_object_handlers php_http_encoding_stream_object_handlers; -zend_object_value php_http_encoding_stream_object_new(zend_class_entry *ce TSRMLS_DC) +zend_object *php_http_encoding_stream_object_new(zend_class_entry *ce) { - return php_http_encoding_stream_object_new_ex(ce, NULL, NULL TSRMLS_CC); + return &php_http_encoding_stream_object_new_ex(ce, NULL)->zo; } -zend_object_value php_http_encoding_stream_object_new_ex(zend_class_entry *ce, php_http_encoding_stream_t *s, php_http_encoding_stream_object_t **ptr TSRMLS_DC) +php_http_encoding_stream_object_t *php_http_encoding_stream_object_new_ex(zend_class_entry *ce, php_http_encoding_stream_t *s) { php_http_encoding_stream_object_t *o; - o = ecalloc(1, sizeof(*o)); - zend_object_std_init((zend_object *) o, ce TSRMLS_CC); - object_properties_init((zend_object *) o, ce); - - if (ptr) { - *ptr = o; - } + o = ecalloc(1, sizeof(*o) + zend_object_properties_size(ce)); + zend_object_std_init(&o->zo, ce); + object_properties_init(&o->zo, ce); if (s) { o->stream = s; } - o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_http_encoding_stream_object_free, NULL TSRMLS_CC); - o->zv.handlers = &php_http_encoding_stream_object_handlers; + o->zo.handlers = &php_http_encoding_stream_object_handlers; - return o->zv; + return o; } -zend_object_value php_http_encoding_stream_object_clone(zval *this_ptr TSRMLS_DC) +zend_object *php_http_encoding_stream_object_clone(zval *object) { - zend_object_value new_ov; - php_http_encoding_stream_object_t *new_obj = NULL, *old_obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_encoding_stream_object_t *new_obj = NULL, *old_obj = PHP_HTTP_OBJ(NULL, object); + php_http_encoding_stream_t *cpy = php_http_encoding_stream_copy(old_obj->stream, NULL); - new_ov = php_http_encoding_stream_object_new_ex(old_obj->zo.ce, php_http_encoding_stream_copy(old_obj->stream, NULL), &new_obj TSRMLS_CC); - zend_objects_clone_members(&new_obj->zo, new_ov, &old_obj->zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC); + new_obj = php_http_encoding_stream_object_new_ex(old_obj->zo.ce, cpy); + zend_objects_clone_members(&new_obj->zo, &old_obj->zo); - return new_ov; + return &new_obj->zo; } -void php_http_encoding_stream_object_free(void *object TSRMLS_DC) +void php_http_encoding_stream_object_free(zend_object *object) { - php_http_encoding_stream_object_t *o = (php_http_encoding_stream_object_t *) object; + php_http_encoding_stream_object_t *o = PHP_HTTP_OBJ(object, NULL); if (o->stream) { php_http_encoding_stream_free(&o->stream); } - zend_object_std_dtor((zend_object *) o TSRMLS_CC); - efree(o); + zend_object_std_dtor(object); +} + +static zend_class_entry *php_http_encoding_stream_class_entry; +zend_class_entry *php_http_get_encoding_stream_class_entry(void) +{ + return php_http_encoding_stream_class_entry; +} +static zend_class_entry *php_http_deflate_stream_class_entry; +zend_class_entry *php_http_get_deflate_stream_class_entry(void) +{ + return php_http_deflate_stream_class_entry; +} +static zend_class_entry *php_http_inflate_stream_class_entry; +zend_class_entry *php_http_get_inflate_stream_class_entry(void) +{ + return php_http_inflate_stream_class_entry; +} +static zend_class_entry *php_http_dechunk_stream_class_entry; +zend_class_entry *php_http_get_dechunk_stream_class_entry(void) +{ + return php_http_dechunk_stream_class_entry; } ZEND_BEGIN_ARG_INFO_EX(ai_HttpEncodingStream___construct, 0, 0, 0) @@@ -969,31 -968,31 +969,31 @@@ ZEND_END_ARG_INFO(); static PHP_METHOD(HttpEncodingStream, __construct) { - long flags = 0; + zend_long flags = 0; php_http_encoding_stream_object_t *obj; php_http_encoding_stream_ops_t *ops; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags), invalid_arg, return); - obj = zend_object_store_get_object(getThis() TSRMLS_CC); + obj = PHP_HTTP_OBJ(NULL, getThis()); if (obj->stream) { php_http_throw(bad_method_call, "http\\Encoding\\Stream cannot be initialized twice", NULL); return; } - if (instanceof_function(obj->zo.ce, php_http_deflate_stream_class_entry TSRMLS_CC)) { + if (instanceof_function(obj->zo.ce, php_http_deflate_stream_class_entry)) { ops = &php_http_encoding_deflate_ops; - } else if (instanceof_function(obj->zo.ce, php_http_inflate_stream_class_entry TSRMLS_CC)) { + } else if (instanceof_function(obj->zo.ce, php_http_inflate_stream_class_entry)) { ops = &php_http_encoding_inflate_ops; - } else if (instanceof_function(obj->zo.ce, php_http_dechunk_stream_class_entry TSRMLS_CC)) { + } else if (instanceof_function(obj->zo.ce, php_http_dechunk_stream_class_entry)) { ops = &php_http_encoding_dechunk_ops; } else { - php_http_throw(runtime, "Unknown http\\Encoding\\Stream class '%s'", obj->zo.ce->name); + php_http_throw(runtime, "Unknown http\\Encoding\\Stream class '%s'", obj->zo.ce->name->val); return; } - php_http_expect(obj->stream = php_http_encoding_stream_init(obj->stream, ops, flags TSRMLS_CC), runtime, return); + php_http_expect(obj->stream = php_http_encoding_stream_init(obj->stream, ops, flags), runtime, return); } ZEND_BEGIN_ARG_INFO_EX(ai_HttpEncodingStream_update, 0, 0, 1) @@@ -1001,22 -1000,18 +1001,22 @@@ ZEND_END_ARG_INFO(); static PHP_METHOD(HttpEncodingStream, update) { - int data_len; + size_t data_len; char *data_str; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data_str, &data_len)) { - php_http_encoding_stream_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &data_str, &data_len)) { + php_http_encoding_stream_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); if (obj->stream) { + char *encoded_str = NULL; size_t encoded_len; - char *encoded_str; if (SUCCESS == php_http_encoding_stream_update(obj->stream, data_str, data_len, &encoded_str, &encoded_len)) { - RETURN_STRINGL(encoded_str, encoded_len, 0); + if (encoded_str) { + RETURN_STR(php_http_cs2zs(encoded_str, encoded_len)); + } else { + RETURN_EMPTY_STRING(); + } } } } @@@ -1027,15 -1022,15 +1027,15 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpEncodingStream, flush) { if (SUCCESS == zend_parse_parameters_none()) { - php_http_encoding_stream_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_encoding_stream_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); if (obj->stream) { - char *encoded_str; + char *encoded_str = NULL; size_t encoded_len; if (SUCCESS == php_http_encoding_stream_flush(obj->stream, &encoded_str, &encoded_len)) { if (encoded_str) { - RETURN_STRINGL(encoded_str, encoded_len, 0); + RETURN_STR(php_http_cs2zs(encoded_str, encoded_len)); } else { RETURN_EMPTY_STRING(); } @@@ -1049,7 -1044,7 +1049,7 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpEncodingStream, done) { if (SUCCESS == zend_parse_parameters_none()) { - php_http_encoding_stream_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_encoding_stream_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); if (obj->stream) { RETURN_BOOL(php_http_encoding_stream_done(obj->stream)); @@@ -1062,16 -1057,16 +1062,16 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpEncodingStream, finish) { if (SUCCESS == zend_parse_parameters_none()) { - php_http_encoding_stream_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_encoding_stream_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); if (obj->stream) { - char *encoded_str; + char *encoded_str = NULL; size_t encoded_len; if (SUCCESS == php_http_encoding_stream_finish(obj->stream, &encoded_str, &encoded_len)) { if (SUCCESS == php_http_encoding_stream_reset(&obj->stream)) { if (encoded_str) { - RETURN_STRINGL(encoded_str, encoded_len, 0); + RETURN_STR(php_http_cs2zs(encoded_str, encoded_len)); } else { RETURN_EMPTY_STRING(); } @@@ -1099,19 -1094,15 +1099,19 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpDeflateStream, encode) { char *str; - int len; - long flags = 0; + size_t len; + zend_long flags = 0; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &len, &flags)) { - char *enc_str; + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &str, &len, &flags)) { + char *enc_str = NULL; size_t enc_len; - if (SUCCESS == php_http_encoding_deflate(flags, str, len, &enc_str, &enc_len TSRMLS_CC)) { - RETURN_STRINGL(enc_str, enc_len, 0); + if (SUCCESS == php_http_encoding_deflate(flags, str, len, &enc_str, &enc_len)) { + if (enc_str) { + RETURN_STR(php_http_cs2zs(enc_str, enc_len)); + } else { + RETURN_EMPTY_STRING(); + } } } RETURN_FALSE; @@@ -1128,18 -1119,14 +1128,18 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpInflateStream, decode) { char *str; - int len; + size_t len; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len)) { - char *enc_str; + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str, &len)) { + char *enc_str = NULL; size_t enc_len; - if (SUCCESS == php_http_encoding_inflate(str, len, &enc_str, &enc_len TSRMLS_CC)) { - RETURN_STRINGL(enc_str, enc_len, 0); + if (SUCCESS == php_http_encoding_inflate(str, len, &enc_str, &enc_len)) { + if (enc_str) { + RETURN_STR(php_http_cs2zs(enc_str, enc_len)); + } else { + RETURN_EMPTY_STRING(); + } } } RETURN_FALSE; @@@ -1157,25 -1144,20 +1157,25 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpDechunkStream, decode) { char *str; - int len; + size_t len; zval *zlen = NULL; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z!", &str, &len, &zlen)) { + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s|z!", &str, &len, &zlen)) { const char *end_ptr; - char *enc_str; + char *enc_str = NULL; size_t enc_len; - if ((end_ptr = php_http_encoding_dechunk(str, len, &enc_str, &enc_len TSRMLS_CC))) { + if ((end_ptr = php_http_encoding_dechunk(str, len, &enc_str, &enc_len))) { if (zlen) { + ZVAL_DEREF(zlen); zval_dtor(zlen); ZVAL_LONG(zlen, str + len - end_ptr); } - RETURN_STRINGL(enc_str, enc_len, 0); + if (enc_str) { + RETURN_STR(php_http_cs2zs(enc_str, enc_len)); + } else { + RETURN_EMPTY_STRING(); + } } } RETURN_FALSE; @@@ -1186,49 -1168,49 +1186,49 @@@ static zend_function_entry php_http_dec EMPTY_FUNCTION_ENTRY }; -zend_class_entry *php_http_encoding_stream_class_entry; -zend_class_entry *php_http_deflate_stream_class_entry; -zend_class_entry *php_http_inflate_stream_class_entry; -zend_class_entry *php_http_dechunk_stream_class_entry; - PHP_MINIT_FUNCTION(http_encoding) { zend_class_entry ce = {0}; INIT_NS_CLASS_ENTRY(ce, "http\\Encoding", "Stream", php_http_encoding_stream_methods); - php_http_encoding_stream_class_entry = zend_register_internal_class(&ce TSRMLS_CC); + php_http_encoding_stream_class_entry = zend_register_internal_class(&ce); php_http_encoding_stream_class_entry->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS; php_http_encoding_stream_class_entry->create_object = php_http_encoding_stream_object_new; memcpy(&php_http_encoding_stream_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); + php_http_encoding_stream_object_handlers.offset = XtOffsetOf(php_http_encoding_stream_object_t, zo); php_http_encoding_stream_object_handlers.clone_obj = php_http_encoding_stream_object_clone; + php_http_encoding_stream_object_handlers.free_obj = php_http_encoding_stream_object_free; - zend_declare_class_constant_long(php_http_encoding_stream_class_entry, ZEND_STRL("FLUSH_NONE"), PHP_HTTP_ENCODING_STREAM_FLUSH_NONE TSRMLS_CC); - zend_declare_class_constant_long(php_http_encoding_stream_class_entry, ZEND_STRL("FLUSH_SYNC"), PHP_HTTP_ENCODING_STREAM_FLUSH_SYNC TSRMLS_CC); - zend_declare_class_constant_long(php_http_encoding_stream_class_entry, ZEND_STRL("FLUSH_FULL"), PHP_HTTP_ENCODING_STREAM_FLUSH_FULL TSRMLS_CC); + zend_declare_class_constant_long(php_http_encoding_stream_class_entry, ZEND_STRL("FLUSH_NONE"), PHP_HTTP_ENCODING_STREAM_FLUSH_NONE); + zend_declare_class_constant_long(php_http_encoding_stream_class_entry, ZEND_STRL("FLUSH_SYNC"), PHP_HTTP_ENCODING_STREAM_FLUSH_SYNC); + zend_declare_class_constant_long(php_http_encoding_stream_class_entry, ZEND_STRL("FLUSH_FULL"), PHP_HTTP_ENCODING_STREAM_FLUSH_FULL); memset(&ce, 0, sizeof(ce)); INIT_NS_CLASS_ENTRY(ce, "http\\Encoding\\Stream", "Deflate", php_http_deflate_stream_methods); - php_http_deflate_stream_class_entry = zend_register_internal_class_ex(&ce, php_http_encoding_stream_class_entry, NULL TSRMLS_CC); - - zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("TYPE_GZIP"), PHP_HTTP_DEFLATE_TYPE_GZIP TSRMLS_CC); - zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("TYPE_ZLIB"), PHP_HTTP_DEFLATE_TYPE_ZLIB TSRMLS_CC); - zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("TYPE_RAW"), PHP_HTTP_DEFLATE_TYPE_RAW TSRMLS_CC); - zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("LEVEL_DEF"), PHP_HTTP_DEFLATE_LEVEL_DEF TSRMLS_CC); - zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("LEVEL_MIN"), PHP_HTTP_DEFLATE_LEVEL_MIN TSRMLS_CC); - zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("LEVEL_MAX"), PHP_HTTP_DEFLATE_LEVEL_MAX TSRMLS_CC); - zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_DEF"), PHP_HTTP_DEFLATE_STRATEGY_DEF TSRMLS_CC); - zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_FILT"), PHP_HTTP_DEFLATE_STRATEGY_FILT TSRMLS_CC); - zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_HUFF"), PHP_HTTP_DEFLATE_STRATEGY_HUFF TSRMLS_CC); - zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_RLE"), PHP_HTTP_DEFLATE_STRATEGY_RLE TSRMLS_CC); - zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_FIXED"), PHP_HTTP_DEFLATE_STRATEGY_FIXED TSRMLS_CC); + php_http_deflate_stream_class_entry = zend_register_internal_class_ex(&ce, php_http_encoding_stream_class_entry); + php_http_deflate_stream_class_entry->create_object = php_http_encoding_stream_object_new; + + zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("TYPE_GZIP"), PHP_HTTP_DEFLATE_TYPE_GZIP); + zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("TYPE_ZLIB"), PHP_HTTP_DEFLATE_TYPE_ZLIB); + zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("TYPE_RAW"), PHP_HTTP_DEFLATE_TYPE_RAW); + zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("LEVEL_DEF"), PHP_HTTP_DEFLATE_LEVEL_DEF); + zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("LEVEL_MIN"), PHP_HTTP_DEFLATE_LEVEL_MIN); + zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("LEVEL_MAX"), PHP_HTTP_DEFLATE_LEVEL_MAX); + zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_DEF"), PHP_HTTP_DEFLATE_STRATEGY_DEF); + zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_FILT"), PHP_HTTP_DEFLATE_STRATEGY_FILT); + zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_HUFF"), PHP_HTTP_DEFLATE_STRATEGY_HUFF); + zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_RLE"), PHP_HTTP_DEFLATE_STRATEGY_RLE); + zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_FIXED"), PHP_HTTP_DEFLATE_STRATEGY_FIXED); memset(&ce, 0, sizeof(ce)); INIT_NS_CLASS_ENTRY(ce, "http\\Encoding\\Stream", "Inflate", php_http_inflate_stream_methods); - php_http_inflate_stream_class_entry = zend_register_internal_class_ex(&ce, php_http_encoding_stream_class_entry, NULL TSRMLS_CC); + php_http_inflate_stream_class_entry = zend_register_internal_class_ex(&ce, php_http_encoding_stream_class_entry); + php_http_inflate_stream_class_entry->create_object = php_http_encoding_stream_object_new; memset(&ce, 0, sizeof(ce)); INIT_NS_CLASS_ENTRY(ce, "http\\Encoding\\Stream", "Dechunk", php_http_dechunk_stream_methods); - php_http_dechunk_stream_class_entry = zend_register_internal_class_ex(&ce, php_http_encoding_stream_class_entry, NULL TSRMLS_CC); + php_http_dechunk_stream_class_entry = zend_register_internal_class_ex(&ce, php_http_encoding_stream_class_entry); + php_http_dechunk_stream_class_entry->create_object = php_http_encoding_stream_object_new; return SUCCESS; } diff --combined src/php_http_env_response.c index 6324698,b4927a1..3a5a8e8 --- a/src/php_http_env_response.c +++ b/src/php_http_env_response.c @@@ -12,186 -12,207 +12,186 @@@ #include "php_http_api.h" -static void set_option(zval *options, const char *name_str, size_t name_len, int type, void *value_ptr, size_t value_len TSRMLS_DC) +static void set_option(zval *options, const char *name_str, size_t name_len, int type, void *value_ptr, size_t value_len) { if (Z_TYPE_P(options) == IS_OBJECT) { if (value_ptr) { switch (type) { case IS_DOUBLE: - zend_update_property_double(Z_OBJCE_P(options), options, name_str, name_len, *(double *)value_ptr TSRMLS_CC); + zend_update_property_double(Z_OBJCE_P(options), options, name_str, name_len, *(double *)value_ptr); break; case IS_LONG: - zend_update_property_long(Z_OBJCE_P(options), options, name_str, name_len, *(long *)value_ptr TSRMLS_CC); + zend_update_property_long(Z_OBJCE_P(options), options, name_str, name_len, *(zend_long *)value_ptr); break; case IS_STRING: - zend_update_property_stringl(Z_OBJCE_P(options), options, name_str, name_len, value_ptr, value_len TSRMLS_CC); + zend_update_property_stringl(Z_OBJCE_P(options), options, name_str, name_len, value_ptr, value_len); break; case IS_ARRAY: case IS_OBJECT: - zend_update_property(Z_OBJCE_P(options), options, name_str, name_len, value_ptr TSRMLS_CC); + zend_update_property(Z_OBJCE_P(options), options, name_str, name_len, value_ptr); break; } } else { - zend_update_property_null(Z_OBJCE_P(options), options, name_str, name_len TSRMLS_CC); + zend_update_property_null(Z_OBJCE_P(options), options, name_str, name_len); } } else { convert_to_array(options); if (value_ptr) { switch (type) { case IS_DOUBLE: - add_assoc_double_ex(options, name_str, name_len + 1, *(double *)value_ptr); + add_assoc_double_ex(options, name_str, name_len, *(double *)value_ptr); break; case IS_LONG: - add_assoc_long_ex(options, name_str, name_len + 1, *(long *)value_ptr); + add_assoc_long_ex(options, name_str, name_len, *(zend_long *)value_ptr); break; case IS_STRING: { - char *value = estrndup(value_ptr, value_len); - add_assoc_stringl_ex(options, name_str, name_len + 1, value, value_len, 0); + zend_string *value = zend_string_init(value_ptr, value_len, 0); + add_assoc_str_ex(options, name_str, name_len, value); break; case IS_ARRAY: case IS_OBJECT: Z_ADDREF_P(value_ptr); - add_assoc_zval_ex(options, name_str, name_len + 1, value_ptr); + add_assoc_zval_ex(options, name_str, name_len, value_ptr); break; } } } else { - add_assoc_null_ex(options, name_str, name_len + 1); + add_assoc_null_ex(options, name_str, name_len); } } } -static zval *get_option(zval *options, const char *name_str, size_t name_len TSRMLS_DC) +static zval *get_option(zval *options, const char *name_str, size_t name_len, zval *tmp) { - zval *val, **valptr; + zval *val = NULL; if (Z_TYPE_P(options) == IS_OBJECT) { - val = zend_read_property(Z_OBJCE_P(options), options, name_str, name_len, 0 TSRMLS_CC); + val = zend_read_property(Z_OBJCE_P(options), options, name_str, name_len, 0, tmp); + } else if (Z_TYPE_P(options) == IS_ARRAY) { + val = zend_symtable_str_find(Z_ARRVAL_P(options), name_str, name_len); } else { - if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(options), name_str, name_len + 1, (void *) &valptr)) { - val = *valptr; - } else { - val = NULL; - } + abort(); } if (val) { - Z_ADDREF_P(val); + Z_TRY_ADDREF_P(val); } return val; } -static php_http_message_body_t *get_body(zval *options TSRMLS_DC) +static php_http_message_body_t *get_body(zval *options) { - zval *zbody; + zval zbody_tmp, *zbody; php_http_message_body_t *body = NULL; - if ((zbody = get_option(options, ZEND_STRL("body") TSRMLS_CC))) { - if ((Z_TYPE_P(zbody) == IS_OBJECT) && instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_class_entry TSRMLS_CC)) { - php_http_message_body_object_t *body_obj = zend_object_store_get_object(zbody TSRMLS_CC); + if ((zbody = get_option(options, ZEND_STRL("body"), &zbody_tmp))) { + if ((Z_TYPE_P(zbody) == IS_OBJECT) && instanceof_function(Z_OBJCE_P(zbody), php_http_get_message_body_class_entry())) { + php_http_message_body_object_t *body_obj = PHP_HTTP_OBJ(NULL, zbody); body = body_obj->body; } - zval_ptr_dtor(&zbody); + Z_TRY_DELREF_P(zbody); } return body; } -static php_http_message_t *get_request(zval *options TSRMLS_DC) +static php_http_message_t *get_request(zval *options) { - zval *zrequest; + zval zrequest_tmp, *zrequest; php_http_message_t *request = NULL; - if ((zrequest = get_option(options, ZEND_STRL("request") TSRMLS_CC))) { - if (Z_TYPE_P(zrequest) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zrequest), php_http_message_class_entry TSRMLS_CC)) { - php_http_message_object_t *request_obj = zend_object_store_get_object(zrequest TSRMLS_CC); + if ((zrequest = get_option(options, ZEND_STRL("request"), &zrequest_tmp))) { + if (Z_TYPE_P(zrequest) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zrequest), php_http_message_get_class_entry())) { + php_http_message_object_t *request_obj = PHP_HTTP_OBJ(NULL, zrequest); request = request_obj->message; } - zval_ptr_dtor(&zrequest); + Z_TRY_DELREF_P(zrequest); } return request; } -static void set_cookie(zval *options, zval *zcookie_new TSRMLS_DC) +static void set_cookie(zval *options, zval *zcookie_new) { - HashPosition pos; - zval *zcookies_set; - php_http_array_hashkey_t key = php_http_array_hashkey_init(0); - php_http_cookie_object_t *obj = zend_object_store_get_object(zcookie_new TSRMLS_CC); - - zcookies_set = get_option(options, ZEND_STRL("cookies") TSRMLS_CC); - if (!zcookies_set || Z_TYPE_P(zcookies_set) != IS_ARRAY) { - if (zcookies_set) { - zval_ptr_dtor(&zcookies_set); - } - MAKE_STD_ZVAL(zcookies_set); - array_init_size(zcookies_set, zend_hash_num_elements(&obj->list->cookies)); - } else { - SEPARATE_ZVAL(&zcookies_set); + zval tmp, zcookies_set_tmp, *zcookies_set; + php_http_arrkey_t key; + php_http_cookie_object_t *obj = PHP_HTTP_OBJ(NULL, zcookie_new); + + array_init(&tmp); + zcookies_set = get_option(options, ZEND_STRL("cookies"), &zcookies_set_tmp); + if (zcookies_set && Z_TYPE_P(zcookies_set) == IS_ARRAY) { + array_copy(Z_ARRVAL_P(zcookies_set), Z_ARRVAL(tmp)); + zval_ptr_dtor(zcookies_set); } - FOREACH_HASH_KEY(pos, &obj->list->cookies, key) { + ZEND_HASH_FOREACH_KEY(&obj->list->cookies, key.h, key.key) + { Z_ADDREF_P(zcookie_new); - if (key.type == HASH_KEY_IS_STRING) { - add_assoc_zval_ex(zcookies_set, key.str, key.len, zcookie_new); + if (key.key) { + add_assoc_zval_ex(&tmp, key.key->val, key.key->len, zcookie_new); } else { - add_index_zval(zcookies_set, key.num, zcookie_new); + add_index_zval(&tmp, key.h, zcookie_new); } } + ZEND_HASH_FOREACH_END(); - set_option(options, ZEND_STRL("cookies"), IS_ARRAY, zcookies_set, 0 TSRMLS_CC); - zval_ptr_dtor(&zcookies_set); + set_option(options, ZEND_STRL("cookies"), IS_ARRAY, &tmp, 0); + zval_ptr_dtor(&tmp); } -php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *options, const char *header_str, size_t header_len, php_http_message_t *request TSRMLS_DC) +php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *options, const char *header_str, size_t header_len, php_http_message_t *request) { php_http_cache_status_t ret = PHP_HTTP_CACHE_NO; - int free_etag = 0; - char *header = NULL, *etag; + char *header = NULL, *etag = NULL; php_http_message_body_t *body; - zval *zetag; + zval zetag_tmp, *zetag; - if (!(body = get_body(options TSRMLS_CC))) { + if (!(body = get_body(options))) { return ret; } - if ((zetag = get_option(options, ZEND_STRL("etag") TSRMLS_CC))) { - zval *zetag_copy = php_http_ztyp(IS_STRING, zetag); - zval_ptr_dtor(&zetag); - zetag = zetag_copy; + if ((zetag = get_option(options, ZEND_STRL("etag"), &zetag_tmp)) && Z_TYPE_P(zetag) != IS_NULL) { + zend_string *zs = zval_get_string(zetag); + etag = estrndup(zs->val, zs->len); + zend_string_release(zs); + zval_ptr_dtor(zetag); } - if (zetag && Z_STRLEN_P(zetag)) { - etag = Z_STRVAL_P(zetag); - } else if ((etag = php_http_message_body_etag(body))) { - set_option(options, ZEND_STRL("etag"), IS_STRING, etag, strlen(etag) TSRMLS_CC); - free_etag = 1; + if (!etag && (etag = php_http_message_body_etag(body))) { + set_option(options, ZEND_STRL("etag"), IS_STRING, etag, strlen(etag)); } - if (zetag) { - zval_ptr_dtor(&zetag); - } - - if (etag && (header = php_http_env_get_request_header(header_str, header_len, NULL, request TSRMLS_CC))) { - ret = php_http_match(header, etag, PHP_HTTP_MATCH_WORD) ? PHP_HTTP_CACHE_HIT : PHP_HTTP_CACHE_MISS; - } - - if (free_etag) { - efree(etag); + if (etag && (header = php_http_env_get_request_header(header_str, header_len, NULL, request))) { + ret = php_http_match(header, etag, PHP_HTTP_MATCH_WORD) ? PHP_HTTP_CACHE_HIT : PHP_HTTP_CACHE_MISS; } + PTR_FREE(etag); PTR_FREE(header); + return ret; } -php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *options, const char *header_str, size_t header_len, php_http_message_t *request TSRMLS_DC) +php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *options, const char *header_str, size_t header_len, php_http_message_t *request) { php_http_cache_status_t ret = PHP_HTTP_CACHE_NO; char *header; time_t ums, lm = 0; php_http_message_body_t *body; - zval *zlm; + zval zlm_tmp, *zlm; - if (!(body = get_body(options TSRMLS_CC))) { + if (!(body = get_body(options))) { return ret; } - if ((zlm = get_option(options, ZEND_STRL("lastModified") TSRMLS_CC))) { - zval *zlm_copy = php_http_ztyp(IS_LONG, zlm); - zval_ptr_dtor(&zlm); - zlm = zlm_copy; + if ((zlm = get_option(options, ZEND_STRL("lastModified"), &zlm_tmp))) { + lm = zval_get_long(zlm); + zval_ptr_dtor(zlm); } - if (zlm && Z_LVAL_P(zlm) > 0) { - lm = Z_LVAL_P(zlm); - } else { + if (lm <= 0) { lm = php_http_message_body_mtime(body); - set_option(options, ZEND_STRL("lastModified"), IS_LONG, &lm, 0 TSRMLS_CC); + set_option(options, ZEND_STRL("lastModified"), IS_LONG, &lm, 0); } - if (zlm) { - zval_ptr_dtor(&zlm); - } - - if ((header = php_http_env_get_request_header(header_str, header_len, NULL, request TSRMLS_CC))) { + if ((header = php_http_env_get_request_header(header_str, header_len, NULL, request))) { ums = php_parse_date(header, NULL); if (ums > 0 && ums >= lm) { @@@ -208,23 -229,24 +208,23 @@@ static zend_bool php_http_env_response_is_cacheable(php_http_env_response_t *r, php_http_message_t *request) { long status = r->ops->get_status(r); - TSRMLS_FETCH_FROM_CTX(r->ts); if (status && status / 100 != 2) { return 0; } - if (php_http_env_got_request_header(ZEND_STRL("Authorization"), request TSRMLS_CC)) { + if (php_http_env_got_request_header(ZEND_STRL("Authorization"), request)) { return 0; } - if (-1 == php_http_select_str(php_http_env_get_request_method(request TSRMLS_CC), 2, "HEAD", "GET")) { + if (-1 == php_http_select_str(php_http_env_get_request_method(request), 2, "HEAD", "GET")) { return 0; } return 1; } -static size_t output(void *context, char *buf, size_t len TSRMLS_DC) +static size_t output(void *context, char *buf, size_t len) { php_http_env_response_t *r = context; @@@ -241,9 -263,11 +241,9 @@@ return len; } -#define php_http_env_response_send_done(r) php_http_env_response_send_data((r), NULL, 0) static ZEND_RESULT_CODE php_http_env_response_send_data(php_http_env_response_t *r, const char *buf, size_t len) { size_t chunks_sent, chunk = r->throttle.chunk ? r->throttle.chunk : PHP_HTTP_SENDBUF_SIZE; - TSRMLS_FETCH_FROM_CTX(r->ts); if (r->content.encoder) { char *enc_str = NULL; @@@ -262,21 -286,16 +262,21 @@@ if (!enc_str) { return SUCCESS; } - chunks_sent = php_http_buffer_chunked_output(&r->buffer, enc_str, enc_len, buf ? chunk : 0, output, r TSRMLS_CC); + chunks_sent = php_http_buffer_chunked_output(&r->buffer, enc_str, enc_len, buf ? chunk : 0, output, r); PTR_FREE(enc_str); } else { - chunks_sent = php_http_buffer_chunked_output(&r->buffer, buf, len, buf ? chunk : 0, output, r TSRMLS_CC); + chunks_sent = php_http_buffer_chunked_output(&r->buffer, buf, len, buf ? chunk : 0, output, r); } return chunks_sent != (size_t) -1 ? SUCCESS : FAILURE; } -php_http_env_response_t *php_http_env_response_init(php_http_env_response_t *r, zval *options, php_http_env_response_ops_t *ops, void *init_arg TSRMLS_DC) +static inline ZEND_RESULT_CODE php_http_env_response_send_done(php_http_env_response_t *r) +{ + return php_http_env_response_send_data(r, NULL, 0); +} + +php_http_env_response_t *php_http_env_response_init(php_http_env_response_t *r, zval *options, php_http_env_response_ops_t *ops, void *init_arg) { zend_bool free_r; @@@ -293,7 -312,10 +293,7 @@@ r->buffer = php_http_buffer_init(NULL); - Z_ADDREF_P(options); - r->options = options; - - TSRMLS_SET_CTX(r->ts); + ZVAL_COPY(&r->options, options); if (r->ops->init && (SUCCESS != r->ops->init(r, init_arg))) { if (free_r) { @@@ -333,60 -355,58 +333,56 @@@ void php_http_env_response_free(php_htt static ZEND_RESULT_CODE php_http_env_response_send_head(php_http_env_response_t *r, php_http_message_t *request) { ZEND_RESULT_CODE ret = SUCCESS; - zval *zoption, *options = r->options; - TSRMLS_FETCH_FROM_CTX(r->ts); + zval zoption_tmp, *zoption, *options = &r->options; if (r->done) { return ret; } - if ((zoption = get_option(options, ZEND_STRL("headers") TSRMLS_CC))) { + if ((zoption = get_option(options, ZEND_STRL("headers"), &zoption_tmp))) { if (Z_TYPE_P(zoption) == IS_ARRAY) { - php_http_header_to_callback(Z_ARRVAL_P(zoption), 0, (php_http_pass_format_callback_t) r->ops->set_header, r TSRMLS_CC); + php_http_header_to_callback(Z_ARRVAL_P(zoption), 0, (php_http_pass_format_callback_t) r->ops->set_header, r); } - zval_ptr_dtor(&zoption); + zval_ptr_dtor(zoption); } - if (ret != SUCCESS) { - return ret; - } - - if ((zoption = get_option(options, ZEND_STRL("responseCode") TSRMLS_CC))) { - zval *zoption_copy = php_http_ztyp(IS_LONG, zoption); + if ((zoption = get_option(options, ZEND_STRL("responseCode"), &zoption_tmp))) { + zend_long rc = zval_get_long(zoption); - zval_ptr_dtor(&zoption); - if (Z_LVAL_P(zoption_copy) > 0) { - ret = r->ops->set_status(r, Z_LVAL_P(zoption_copy)); + zval_ptr_dtor(zoption); + if (rc > 0) { + ret = r->ops->set_status(r, rc); } - zval_ptr_dtor(&zoption_copy); } if (ret != SUCCESS) { return ret; } - if ((zoption = get_option(options, ZEND_STRL("httpVersion") TSRMLS_CC))) { + if ((zoption = get_option(options, ZEND_STRL("httpVersion"), &zoption_tmp))) { php_http_version_t v; - zval *zoption_copy = php_http_ztyp(IS_STRING, zoption); + zend_string *zs = zval_get_string(zoption); - zval_ptr_dtor(&zoption); - if (Z_STRLEN_P(zoption_copy) && php_http_version_parse(&v, Z_STRVAL_P(zoption_copy) TSRMLS_CC)) { + zval_ptr_dtor(zoption); + if (zs->len && php_http_version_parse(&v, zs->val)) { ret = r->ops->set_protocol_version(r, &v); php_http_version_dtor(&v); } - zval_ptr_dtor(&zoption_copy); + zend_string_release(zs); } if (ret != SUCCESS) { return ret; } - if ((zoption = get_option(options, ZEND_STRL("cookies") TSRMLS_CC))) { + if ((zoption = get_option(options, ZEND_STRL("cookies"), &zoption_tmp))) { if (Z_TYPE_P(zoption) == IS_ARRAY) { - HashPosition pos; - zval **zcookie; + zval *zcookie; - FOREACH_VAL(pos, zoption, zcookie) { - if (Z_TYPE_PP(zcookie) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(zcookie), php_http_cookie_class_entry TSRMLS_CC)) { - php_http_cookie_object_t *obj = zend_object_store_get_object(*zcookie TSRMLS_CC); + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(zoption), zcookie) + { + if (Z_TYPE_P(zcookie) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zcookie), php_http_cookie_get_class_entry())) { + php_http_cookie_object_t *obj = PHP_HTTP_OBJ(NULL, zcookie); char *str; size_t len; @@@ -398,25 -418,24 +394,25 @@@ efree(str); } } + ZEND_HASH_FOREACH_END(); } - zval_ptr_dtor(&zoption); + zval_ptr_dtor(zoption); } if (ret != SUCCESS) { return ret; } - if ((zoption = get_option(options, ZEND_STRL("contentType") TSRMLS_CC))) { - zval *zoption_copy = php_http_ztyp(IS_STRING, zoption); + if ((zoption = get_option(options, ZEND_STRL("contentType"), &zoption_tmp))) { + zend_string *zs = zval_get_string(zoption); - zval_ptr_dtor(&zoption); - if (Z_STRLEN_P(zoption_copy) && strchr(Z_STRVAL_P(zoption_copy), '/')) { - if (SUCCESS == (ret = r->ops->set_header(r, "Content-Type: %.*s", Z_STRLEN_P(zoption_copy), Z_STRVAL_P(zoption_copy)))) { - r->content.type = estrndup(Z_STRVAL_P(zoption_copy), Z_STRLEN_P(zoption_copy)); + zval_ptr_dtor(zoption); + if (zs->len && strchr(zs->val, '/')) { + if (SUCCESS == (ret = r->ops->set_header(r, "Content-Type: %.*s", zs->len, zs->val))) { + r->content.type = estrndup(zs->val, zs->len); } } - zval_ptr_dtor(&zoption_copy); + zend_string_release(zs); } if (ret != SUCCESS) { @@@ -425,13 -444,13 +421,13 @@@ if (r->range.status == PHP_HTTP_RANGE_OK) { if (zend_hash_num_elements(&r->range.values) == 1) { - zval **range, **begin, **end; + zval *range, *begin, *end; - if ( 1 == php_http_array_list(&r->range.values TSRMLS_CC, 1, &range) - && 2 == php_http_array_list(Z_ARRVAL_PP(range) TSRMLS_CC, 2, &begin, &end) + if ( 1 == php_http_array_list(&r->range.values, 1, &range) + && 2 == php_http_array_list(Z_ARRVAL_P(range), 2, &begin, &end) ) { if (SUCCESS == (ret = r->ops->set_status(r, 206))) { - ret = r->ops->set_header(r, "Content-Range: bytes %ld-%ld/%zu", Z_LVAL_PP(begin), Z_LVAL_PP(end), r->content.length); + ret = r->ops->set_header(r, "Content-Range: bytes %ld-%ld/%zu", Z_LVAL_P(begin), Z_LVAL_P(end), r->content.length); } } else { /* this should never happen */ @@@ -439,77 -458,77 +435,77 @@@ ret = FAILURE; } } else { - php_http_boundary(r->range.boundary, sizeof(r->range.boundary) TSRMLS_CC); + php_http_boundary(r->range.boundary, sizeof(r->range.boundary)); if (SUCCESS == (ret = r->ops->set_status(r, 206))) { ret = r->ops->set_header(r, "Content-Type: multipart/byteranges; boundary=%s", r->range.boundary); } } } else { - if ((zoption = get_option(options, ZEND_STRL("cacheControl") TSRMLS_CC))) { - zval *zoption_copy = php_http_ztyp(IS_STRING, zoption); + if ((zoption = get_option(options, ZEND_STRL("cacheControl"), &zoption_tmp))) { + zend_string *zs = zval_get_string(zoption); - zval_ptr_dtor(&zoption); - if (Z_STRLEN_P(zoption_copy)) { - ret = r->ops->set_header(r, "Cache-Control: %.*s", Z_STRLEN_P(zoption_copy), Z_STRVAL_P(zoption_copy)); + zval_ptr_dtor(zoption); + if (zs->len) { + ret = r->ops->set_header(r, "Cache-Control: %.*s", zs->len, zs->val); } - zval_ptr_dtor(&zoption_copy); + zend_string_release(zs); } if (ret != SUCCESS) { return ret; } - if ((zoption = get_option(options, ZEND_STRL("contentDisposition") TSRMLS_CC))) { - zval *zoption_copy = php_http_ztyp(IS_ARRAY, zoption); - php_http_buffer_t buf; + if ((zoption = get_option(options, ZEND_STRL("contentDisposition"), &zoption_tmp))) { + + if (Z_TYPE_P(zoption) == IS_ARRAY) { + php_http_buffer_t buf; - php_http_buffer_init(&buf); - if (php_http_params_to_string(&buf, Z_ARRVAL_P(zoption_copy), ZEND_STRL(","), ZEND_STRL(";"), ZEND_STRL("="), PHP_HTTP_PARAMS_DEFAULT TSRMLS_CC)) { - if (buf.used) { - ret = r->ops->set_header(r, "Content-Disposition: %.*s", buf.used, buf.data); + php_http_buffer_init(&buf); + if (php_http_params_to_string(&buf, Z_ARRVAL_P(zoption), ZEND_STRL(","), ZEND_STRL(";"), ZEND_STRL("="), PHP_HTTP_PARAMS_DEFAULT)) { + if (buf.used) { + ret = r->ops->set_header(r, "Content-Disposition: %.*s", buf.used, buf.data); + } } - } - php_http_buffer_dtor(&buf); - zval_ptr_dtor(&zoption_copy); - zval_ptr_dtor(&zoption); + php_http_buffer_dtor(&buf); + } + zval_ptr_dtor(zoption); } if (ret != SUCCESS) { return ret; } - if ((zoption = get_option(options, ZEND_STRL("contentEncoding") TSRMLS_CC))) { - zval *zoption_copy = php_http_ztyp(IS_LONG, zoption); + if ((zoption = get_option(options, ZEND_STRL("contentEncoding"), &zoption_tmp))) { + zend_long ce = zval_get_long(zoption); zval zsupported; HashTable *result = NULL; - zval_ptr_dtor(&zoption); - switch (Z_LVAL_P(zoption_copy)) { + zval_ptr_dtor(zoption); + switch (ce) { case PHP_HTTP_CONTENT_ENCODING_GZIP: - INIT_PZVAL(&zsupported); array_init(&zsupported); - add_next_index_stringl(&zsupported, ZEND_STRL("none"), 1); - add_next_index_stringl(&zsupported, ZEND_STRL("gzip"), 1); - add_next_index_stringl(&zsupported, ZEND_STRL("deflate"), 1); + add_next_index_stringl(&zsupported, ZEND_STRL("none")); + add_next_index_stringl(&zsupported, ZEND_STRL("gzip")); + add_next_index_stringl(&zsupported, ZEND_STRL("deflate")); - if ((result = php_http_negotiate_encoding(Z_ARRVAL(zsupported), request TSRMLS_CC))) { - char *key_str = NULL; - uint key_len = 0; + if ((result = php_http_negotiate_encoding(Z_ARRVAL(zsupported), request))) { + zend_string *key_str = NULL; + zend_ulong index = 0; zend_hash_internal_pointer_reset(result); - if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(result, &key_str, &key_len, NULL, 0, NULL)) { - if (!strcmp(key_str, "gzip")) { - if (!(r->content.encoder = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), PHP_HTTP_DEFLATE_TYPE_GZIP TSRMLS_CC))) { + if (HASH_KEY_IS_STRING == zend_hash_get_current_key(result, &key_str, &index)) { + if (zend_string_equals_literal(key_str, "gzip")) { + if (!(r->content.encoder = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), PHP_HTTP_DEFLATE_TYPE_GZIP))) { ret = FAILURE; } else if (SUCCESS == (ret = r->ops->set_header(r, "Content-Encoding: gzip"))) { - r->content.encoding = estrndup(key_str, key_len - 1); + r->content.encoding = estrndup(key_str->val, key_str->len); } - } else if (!strcmp(key_str, "deflate")) { - if (!(r->content.encoder = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), PHP_HTTP_DEFLATE_TYPE_ZLIB TSRMLS_CC))) { + } else if (zend_string_equals_literal(key_str, "deflate")) { + if (!(r->content.encoder = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), PHP_HTTP_DEFLATE_TYPE_ZLIB))) { ret = FAILURE; } else if (SUCCESS == (ret = r->ops->set_header(r, "Content-Encoding: deflate"))) { - r->content.encoding = estrndup(key_str, key_len - 1); + r->content.encoding = estrndup(key_str->val, key_str->len); } } else { ret = r->ops->del_header(r, ZEND_STRL("Content-Encoding")); @@@ -532,6 -551,7 +528,6 @@@ ret = r->ops->del_header(r, ZEND_STRL("Content-Encoding")); break; } - zval_ptr_dtor(&zoption_copy); } if (SUCCESS != ret) { @@@ -539,12 -559,12 +535,12 @@@ } if (php_http_env_response_is_cacheable(r, request)) { - switch (php_http_env_is_response_cached_by_etag(options, ZEND_STRL("If-None-Match"), request TSRMLS_CC)) { + switch (php_http_env_is_response_cached_by_etag(options, ZEND_STRL("If-None-Match"), request)) { case PHP_HTTP_CACHE_MISS: break; case PHP_HTTP_CACHE_NO: - if (PHP_HTTP_CACHE_HIT != php_http_env_is_response_cached_by_last_modified(options, ZEND_STRL("If-Modified-Since"), request TSRMLS_CC)) { + if (PHP_HTTP_CACHE_HIT != php_http_env_is_response_cached_by_last_modified(options, ZEND_STRL("If-Modified-Since"), request)) { break; } /* no break */ @@@ -555,28 -575,29 +551,28 @@@ break; } - if ((zoption = get_option(options, ZEND_STRL("etag") TSRMLS_CC))) { - zval *zoption_copy = php_http_ztyp(IS_STRING, zoption); + if ((zoption = get_option(options, ZEND_STRL("etag"), &zoption_tmp))) { + zend_string *zs = zval_get_string(zoption); - zval_ptr_dtor(&zoption); - if (*Z_STRVAL_P(zoption_copy) != '"' && strncmp(Z_STRVAL_P(zoption_copy), "W/\"", 3)) { - ret = r->ops->set_header(r, "ETag: \"%s\"", Z_STRVAL_P(zoption_copy)); + zval_ptr_dtor(zoption); + if (*zs->val != '"' && strncmp(zs->val, "W/\"", 3)) { + ret = r->ops->set_header(r, "ETag: \"%s\"", zs->val); } else { - ret = r->ops->set_header(r, "ETag: %s", Z_STRVAL_P(zoption_copy)); + ret = r->ops->set_header(r, "ETag: %s", zs->val); } - zval_ptr_dtor(&zoption_copy); + zend_string_release(zs); } - if ((zoption = get_option(options, ZEND_STRL("lastModified") TSRMLS_CC))) { - zval *zoption_copy = php_http_ztyp(IS_LONG, zoption); + if ((zoption = get_option(options, ZEND_STRL("lastModified"), &zoption_tmp))) { + zend_long lm = zval_get_long(zoption); - zval_ptr_dtor(&zoption); - if (Z_LVAL_P(zoption_copy)) { - char *date = php_format_date(ZEND_STRL(PHP_HTTP_DATE_FORMAT), Z_LVAL_P(zoption_copy), 0 TSRMLS_CC); + zval_ptr_dtor(zoption); + if (lm) { + zend_string *date = php_format_date(ZEND_STRL(PHP_HTTP_DATE_FORMAT), lm, 0); if (date) { - ret = r->ops->set_header(r, "Last-Modified: %s", date); - efree(date); + ret = r->ops->set_header(r, "Last-Modified: %s", date->val); + zend_string_release(date); } } - zval_ptr_dtor(&zoption_copy); } } } @@@ -587,33 -608,38 +583,33 @@@ static ZEND_RESULT_CODE php_http_env_response_send_body(php_http_env_response_t *r) { ZEND_RESULT_CODE ret = SUCCESS; - zval *zoption; + zval zoption_tmp, *zoption; php_http_message_body_t *body; - TSRMLS_FETCH_FROM_CTX(r->ts); if (r->done) { return ret; } - if ((body = get_body(r->options TSRMLS_CC))) { - if ((zoption = get_option(r->options, ZEND_STRL("throttleDelay") TSRMLS_CC))) { - if (Z_TYPE_P(zoption) == IS_DOUBLE) { - r->throttle.delay = Z_DVAL_P(zoption); - } - zval_ptr_dtor(&zoption); + if ((body = get_body(&r->options))) { + if ((zoption = get_option(&r->options, ZEND_STRL("throttleDelay"), &zoption_tmp))) { + r->throttle.delay = zval_get_double(zoption); + zval_ptr_dtor(zoption); } - if ((zoption = get_option(r->options, ZEND_STRL("throttleChunk") TSRMLS_CC))) { - if (Z_TYPE_P(zoption) == IS_LONG) { - r->throttle.chunk = Z_LVAL_P(zoption); - } - zval_ptr_dtor(&zoption); + if ((zoption = get_option(&r->options, ZEND_STRL("throttleChunk"), &zoption_tmp))) { + r->throttle.chunk = zval_get_long(zoption); + zval_ptr_dtor(zoption); } if (r->range.status == PHP_HTTP_RANGE_OK) { if (zend_hash_num_elements(&r->range.values) == 1) { /* single range */ - zval **range, **begin, **end; + zval *range, *begin, *end; - if ( 1 == php_http_array_list(&r->range.values TSRMLS_CC, 1, &range) - && 2 == php_http_array_list(Z_ARRVAL_PP(range) TSRMLS_CC, 2, &begin, &end) + if ( 1 == php_http_array_list(&r->range.values, 1, &range) + && 2 == php_http_array_list(Z_ARRVAL_P(range), 2, &begin, &end) ) { /* send chunk */ - ret = php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_PP(begin), Z_LVAL_PP(end) - Z_LVAL_PP(begin) + 1); + ret = php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_P(begin), Z_LVAL_P(end) - Z_LVAL_P(begin) + 1); if (ret == SUCCESS) { ret = php_http_env_response_send_done(r); } @@@ -627,13 -653,13 +623,13 @@@ } else { /* send multipart/byte-ranges message */ - HashPosition pos; - zval **chunk; + zval *chunk; - FOREACH_HASH_VAL(pos, &r->range.values, chunk) { - zval **begin, **end; + ZEND_HASH_FOREACH_VAL(&r->range.values, chunk) + { + zval *begin, *end; - if (2 == php_http_array_list(Z_ARRVAL_PP(chunk) TSRMLS_CC, 2, &begin, &end)) { + if (2 == php_http_array_list(Z_ARRVAL_P(chunk), 2, &begin, &end)) { php_http_buffer_appendf(r->buffer, PHP_HTTP_CRLF "--%s" PHP_HTTP_CRLF @@@ -642,14 -668,13 +638,14 @@@ /* - */ r->range.boundary, r->content.type ? r->content.type : "application/octet-stream", - Z_LVAL_PP(begin), - Z_LVAL_PP(end), + Z_LVAL_P(begin), + Z_LVAL_P(end), r->content.length ); - ret = php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_PP(begin), Z_LVAL_PP(end) - Z_LVAL_PP(begin) + 1); + ret = php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_P(begin), Z_LVAL_P(end) - Z_LVAL_P(begin) + 1); } } + ZEND_HASH_FOREACH_END(); if (ret == SUCCESS) { php_http_buffer_appendf(r->buffer, PHP_HTTP_CRLF "--%s--", r->range.boundary); @@@ -672,18 -697,19 +668,18 @@@ ZEND_RESULT_CODE php_http_env_response_ { php_http_message_t *request; php_http_message_body_t *body; - TSRMLS_FETCH_FROM_CTX(r->ts); - request = get_request(r->options TSRMLS_CC); + request = get_request(&r->options); /* check for ranges */ - if ((body = get_body(r->options TSRMLS_CC))) { + if ((body = get_body(&r->options))) { r->content.length = php_http_message_body_size(body); if (SUCCESS != r->ops->set_header(r, "Accept-Ranges: bytes")) { return FAILURE; } else { - zend_hash_init(&r->range.values, 0, NULL, ZVAL_PTR_DTOR, 0); - r->range.status = php_http_env_get_request_ranges(&r->range.values, r->content.length, request TSRMLS_CC); + ZEND_INIT_SYMTABLE_EX(&r->range.values, 0, 0); + r->range.status = php_http_env_get_request_ranges(&r->range.values, r->content.length, request); switch (r->range.status) { case PHP_HTTP_RANGE_NO: @@@ -691,7 -717,7 +687,7 @@@ break; case PHP_HTTP_RANGE_ERR: - if (php_http_env_got_request_header(ZEND_STRL("If-Range"), request TSRMLS_CC)) { + if (php_http_env_got_request_header(ZEND_STRL("If-Range"), request)) { r->range.status = PHP_HTTP_RANGE_NO; zend_hash_destroy(&r->range.values); } else { @@@ -707,16 -733,16 +703,16 @@@ break; case PHP_HTTP_RANGE_OK: - if (PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_etag(r->options, ZEND_STRL("If-Range"), request TSRMLS_CC) - || PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(r->options, ZEND_STRL("If-Range"), request TSRMLS_CC) + if (PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_etag(&r->options, ZEND_STRL("If-Range"), request) + || PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(&r->options, ZEND_STRL("If-Range"), request) ) { r->range.status = PHP_HTTP_RANGE_NO; zend_hash_destroy(&r->range.values); break; } - if (PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_etag(r->options, ZEND_STRL("If-Match"), request TSRMLS_CC) - || PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(r->options, ZEND_STRL("If-Unmodified-Since"), request TSRMLS_CC) - || PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(r->options, ZEND_STRL("Unless-Modified-Since"), request TSRMLS_CC) + if (PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_etag(&r->options, ZEND_STRL("If-Match"), request) + || PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(&r->options, ZEND_STRL("If-Unmodified-Since"), request) + || PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(&r->options, ZEND_STRL("Unless-Modified-Since"), request) ) { r->done = 1; zend_hash_destroy(&r->range.values); @@@ -732,17 -758,17 +728,17 @@@ } if (SUCCESS != php_http_env_response_send_head(r, request)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to send response headers"); + php_error_docref(NULL, E_WARNING, "Failed to send response headers"); return FAILURE; } if (SUCCESS != php_http_env_response_send_body(r)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to send response body"); + php_error_docref(NULL, E_WARNING, "Failed to send response body"); return FAILURE; } if (SUCCESS != r->ops->finish(r)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to finish response"); + php_error_docref(NULL, E_WARNING, "Failed to finish response"); return FAILURE; } @@@ -751,24 -777,30 +747,24 @@@ static long php_http_env_response_sapi_get_status(php_http_env_response_t *r) { - TSRMLS_FETCH_FROM_CTX(r->ts); - - return php_http_env_get_response_code(TSRMLS_C); + return php_http_env_get_response_code(); } static ZEND_RESULT_CODE php_http_env_response_sapi_set_status(php_http_env_response_t *r, long http_code) { - TSRMLS_FETCH_FROM_CTX(r->ts); - - return php_http_env_set_response_code(http_code TSRMLS_CC); + return php_http_env_set_response_code(http_code); } static ZEND_RESULT_CODE php_http_env_response_sapi_set_protocol_version(php_http_env_response_t *r, php_http_version_t *v) { - TSRMLS_FETCH_FROM_CTX(r->ts); - return php_http_env_set_response_protocol_version(v TSRMLS_CC); + return php_http_env_set_response_protocol_version(v); } static ZEND_RESULT_CODE php_http_env_response_sapi_set_header(php_http_env_response_t *r, const char *fmt, ...) { ZEND_RESULT_CODE ret; va_list args; - TSRMLS_FETCH_FROM_CTX(r->ts); va_start(args, fmt); - ret = php_http_env_set_response_header_va(0, 1, fmt, args TSRMLS_CC); + ret = php_http_env_set_response_header_va(0, 1, fmt, args); va_end(args); return ret; @@@ -777,19 -809,24 +773,19 @@@ static ZEND_RESULT_CODE php_http_env_re { ZEND_RESULT_CODE ret; va_list args; - TSRMLS_FETCH_FROM_CTX(r->ts); va_start(args, fmt); - ret = php_http_env_set_response_header_va(0, 0, fmt, args TSRMLS_CC); + ret = php_http_env_set_response_header_va(0, 0, fmt, args); va_end(args); return ret; } static ZEND_RESULT_CODE php_http_env_response_sapi_del_header(php_http_env_response_t *r, const char *header_str, size_t header_len) { - TSRMLS_FETCH_FROM_CTX(r->ts); - - return php_http_env_set_response_header_value(0, header_str, header_len, NULL, 1 TSRMLS_CC); + return php_http_env_set_response_header_value(0, header_str, header_len, NULL, 1); } static ZEND_RESULT_CODE php_http_env_response_sapi_write(php_http_env_response_t *r, const char *data_str, size_t data_len) { - TSRMLS_FETCH_FROM_CTX(r->ts); - if (0 < PHPWRITE(data_str, data_len)) { return SUCCESS; } @@@ -797,12 -834,19 +793,12 @@@ } static ZEND_RESULT_CODE php_http_env_response_sapi_flush(php_http_env_response_t *r) { - TSRMLS_FETCH_FROM_CTX(r->ts); - -#if PHP_VERSION_ID >= 50400 - if (php_output_get_level(TSRMLS_C)) { - php_output_flush_all(TSRMLS_C); + if (php_output_get_level()) { + php_output_flush_all(); } - if (!(php_output_get_status(TSRMLS_C) & PHP_OUTPUT_IMPLICITFLUSH)) { - sapi_flush(TSRMLS_C); + if (!(php_output_get_status() & PHP_OUTPUT_IMPLICITFLUSH)) { + sapi_flush(); } -#else - php_end_ob_buffer(1, 1 TSRMLS_CC); - sapi_flush(TSRMLS_C); -#endif return SUCCESS; } @@@ -848,17 -892,21 +844,17 @@@ static ZEND_RESULT_CODE php_http_env_re { php_http_env_response_stream_ctx_t *ctx; size_t buffer_size = 0x1000; - TSRMLS_FETCH_FROM_CTX(r->ts); ctx = ecalloc(1, sizeof(*ctx)); ctx->stream = init_arg; - if (!ctx->stream || SUCCESS != zend_list_addref(ctx->stream->rsrc_id)) { - efree(ctx); - return FAILURE; - } + ++GC_REFCOUNT(ctx->stream->res); + ZEND_INIT_SYMTABLE(&ctx->header); + php_http_version_init(&ctx->version, 1, 1); php_stream_set_option(ctx->stream, PHP_STREAM_OPTION_WRITE_BUFFER, PHP_STREAM_BUFFER_FULL, &buffer_size); - zend_hash_init(&ctx->header, 0, NULL, ZVAL_PTR_DTOR, 0); - php_http_version_init(&ctx->version, 1, 1 TSRMLS_CC); ctx->status_code = 200; ctx->chunked = 1; - ctx->request = get_request(r->options TSRMLS_CC); + ctx->request = get_request(&r->options); /* there are some limitations regarding TE:chunked, see https://tools.ietf.org/html/rfc7230#section-3.3.1 */ if (ctx->request && ctx->request->http.version.major == 1 && ctx->request->http.version.minor == 0) { @@@ -872,40 -920,40 +868,40 @@@ static void php_http_env_response_stream_dtor(php_http_env_response_t *r) { php_http_env_response_stream_ctx_t *ctx = r->ctx; - TSRMLS_FETCH_FROM_CTX(r->ts); if (ctx->chunked_filter) { - ctx->chunked_filter = php_stream_filter_remove(ctx->chunked_filter, 1 TSRMLS_CC); + ctx->chunked_filter = php_stream_filter_remove(ctx->chunked_filter, 1); } zend_hash_destroy(&ctx->header); - zend_list_delete(ctx->stream->rsrc_id); + zend_list_delete(ctx->stream->res); efree(ctx); r->ctx = NULL; } -static void php_http_env_response_stream_header(php_http_env_response_stream_ctx_t *ctx, HashTable *header, php_http_buffer_t *buf TSRMLS_DC) +static void php_http_env_response_stream_header(php_http_env_response_stream_ctx_t *ctx, HashTable *header, php_http_buffer_t *buf) { - HashPosition pos; - zval **val; + zval *val; - FOREACH_HASH_VAL(pos, header, val) { - if (Z_TYPE_PP(val) == IS_ARRAY) { - php_http_env_response_stream_header(ctx, Z_ARRVAL_PP(val), buf TSRMLS_CC); + ZEND_HASH_FOREACH_VAL(header, val) + { + if (Z_TYPE_P(val) == IS_ARRAY) { + php_http_env_response_stream_header(ctx, Z_ARRVAL_P(val), buf); } else { - zval *tmp = php_http_ztyp(IS_STRING, *val); + zend_string *zs = zval_get_string(val); if (ctx->chunked) { /* disable chunked transfer encoding if we've got an explicit content-length */ - if (!strncasecmp(Z_STRVAL_P(tmp), "Content-Length:", lenof("Content-Length:"))) { + if (!strncasecmp(zs->val, "Content-Length:", lenof("Content-Length:"))) { ctx->chunked = 0; } } - php_http_buffer_append(buf, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); + php_http_buffer_append(buf, zs->val, zs->len); php_http_buffer_appends(buf, PHP_HTTP_CRLF); - zval_ptr_dtor(&tmp); + zend_string_release(zs); } } + ZEND_HASH_FOREACH_END(); } -static ZEND_RESULT_CODE php_http_env_response_stream_start(php_http_env_response_stream_ctx_t *ctx TSRMLS_DC) +static ZEND_RESULT_CODE php_http_env_response_stream_start(php_http_env_response_stream_ctx_t *ctx) { php_http_buffer_t header_buf; @@@ -925,13 -973,12 +921,13 @@@ ctx->chunked = 0; } - php_http_env_response_stream_header(ctx, &ctx->header, &header_buf TSRMLS_CC); + php_http_env_response_stream_header(ctx, &ctx->header, &header_buf); /* enable chunked transfer encoding */ if (ctx->chunked) { php_http_buffer_appends(&header_buf, "Transfer-Encoding: chunked" PHP_HTTP_CRLF); } + php_http_buffer_appends(&header_buf, PHP_HTTP_CRLF); if (header_buf.used == php_stream_write(ctx->stream, header_buf.data, header_buf.used)) { @@@ -941,7 -988,7 +937,7 @@@ php_stream_flush(ctx->stream); if (ctx->chunked) { - ctx->chunked_filter = php_stream_filter_create("http.chunked_encode", NULL, 0 TSRMLS_CC); + ctx->chunked_filter = php_stream_filter_create("http.chunked_encode", NULL, 0); php_stream_filter_append(&ctx->stream->writefilters, ctx->chunked_filter); } @@@ -982,9 -1029,7 +978,9 @@@ static ZEND_RESULT_CODE php_http_env_re php_http_env_response_stream_ctx_t *stream_ctx = r->ctx; char *header_end, *header_str = NULL; size_t header_len = 0; - zval *zheader, **zheader_ptr; + zval zheader, *zheader_ptr; + zend_string *header_key; + ZEND_RESULT_CODE rv; if (stream_ctx->started || stream_ctx->finished) { return FAILURE; @@@ -997,21 -1042,24 +993,21 @@@ return FAILURE; } - *header_end = '\0'; + header_key = zend_string_init(header_str, header_end - header_str, 0); - if (!replace && (SUCCESS == zend_hash_find(&stream_ctx->header, header_str, header_end - header_str + 1, (void *) &zheader_ptr))) { - convert_to_array(*zheader_ptr); - *header_end = ':'; - return add_next_index_stringl(*zheader_ptr, header_str, header_len, 0); + if (!replace && (zheader_ptr = zend_hash_find(&stream_ctx->header, header_key))) { + convert_to_array(zheader_ptr); + rv = add_next_index_str(zheader_ptr, php_http_cs2zs(header_str, header_len)); } else { - MAKE_STD_ZVAL(zheader); - ZVAL_STRINGL(zheader, header_str, header_len, 0); + ZVAL_STR(&zheader, php_http_cs2zs(header_str, header_len)); - if (SUCCESS != zend_hash_update(&stream_ctx->header, header_str, header_end - header_str + 1, (void *) &zheader, sizeof(zval *), NULL)) { - zval_ptr_dtor(&zheader); - return FAILURE; - } - - *header_end = ':'; - return SUCCESS; + rv = zend_hash_update(&stream_ctx->header, header_key, &zheader) + ? SUCCESS : FAILURE; } + + zend_string_release(header_key); + + return rv; } static ZEND_RESULT_CODE php_http_env_response_stream_set_header(php_http_env_response_t *r, const char *fmt, ...) { @@@ -1043,18 -1091,19 +1039,18 @@@ static ZEND_RESULT_CODE php_http_env_re return FAILURE; } - zend_hash_del(&stream_ctx->header, header_str, header_len + 1); + zend_hash_str_del(&stream_ctx->header, header_str, header_len); return SUCCESS; } static ZEND_RESULT_CODE php_http_env_response_stream_write(php_http_env_response_t *r, const char *data_str, size_t data_len) { php_http_env_response_stream_ctx_t *stream_ctx = r->ctx; - TSRMLS_FETCH_FROM_CTX(r->ts); if (stream_ctx->finished) { return FAILURE; } if (!stream_ctx->started) { - if (SUCCESS != php_http_env_response_stream_start(stream_ctx TSRMLS_CC)) { + if (SUCCESS != php_http_env_response_stream_start(stream_ctx)) { return FAILURE; } } @@@ -1068,12 -1117,13 +1064,12 @@@ static ZEND_RESULT_CODE php_http_env_response_stream_flush(php_http_env_response_t *r) { php_http_env_response_stream_ctx_t *stream_ctx = r->ctx; - TSRMLS_FETCH_FROM_CTX(r->ts); if (stream_ctx->finished) { return FAILURE; } if (!stream_ctx->started) { - if (SUCCESS != php_http_env_response_stream_start(stream_ctx TSRMLS_CC)) { + if (SUCCESS != php_http_env_response_stream_start(stream_ctx)) { return FAILURE; } } @@@ -1083,12 -1133,13 +1079,12 @@@ static ZEND_RESULT_CODE php_http_env_response_stream_finish(php_http_env_response_t *r) { php_http_env_response_stream_ctx_t *ctx = r->ctx; - TSRMLS_FETCH_FROM_CTX(r->ts); if (ctx->finished) { return FAILURE; } if (!ctx->started) { - if (SUCCESS != php_http_env_response_stream_start(ctx TSRMLS_CC)) { + if (SUCCESS != php_http_env_response_stream_start(ctx)) { return FAILURE; } } @@@ -1096,7 -1147,7 +1092,7 @@@ php_stream_flush(ctx->stream); if (ctx->chunked && ctx->chunked_filter) { php_stream_filter_flush(ctx->chunked_filter, 1); - ctx->chunked_filter = php_stream_filter_remove(ctx->chunked_filter, 1 TSRMLS_CC); + ctx->chunked_filter = php_stream_filter_remove(ctx->chunked_filter, 1); } ctx->finished = 1; @@@ -1126,7 -1177,7 +1122,7 @@@ php_http_env_response_ops_t *php_http_e #define PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj) \ do { \ if (!obj->message) { \ - obj->message = php_http_message_init_env(NULL, PHP_HTTP_RESPONSE TSRMLS_CC); \ + obj->message = php_http_message_init_env(NULL, PHP_HTTP_RESPONSE); \ } \ } while (0) @@@ -1138,9 -1189,9 +1134,9 @@@ static PHP_METHOD(HttpEnvResponse, __co php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return); - obj = zend_object_store_get_object(getThis() TSRMLS_CC); + obj = PHP_HTTP_OBJ(NULL, getThis()); - php_http_expect(obj->message = php_http_message_init_env(obj->message, PHP_HTTP_RESPONSE TSRMLS_CC), unexpected_val, return); + php_http_expect(obj->message = php_http_message_init_env(obj->message, PHP_HTTP_RESPONSE), unexpected_val, return); } ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse___invoke, 0, 0, 1) @@@ -1150,24 -1201,26 +1146,24 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpEnvResponse, __invoke) { char *ob_str; - int ob_len; - long ob_flags = 0; + size_t ob_len; + zend_long ob_flags = 0; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &ob_str, &ob_len, &ob_flags)) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &ob_str, &ob_len, &ob_flags)) { + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj); if (!obj->body) { php_http_message_object_init_body_object(obj); } - php_http_message_body_append(obj->message->body, ob_str, ob_len); -#if PHP_VERSION_ID >= 50400 + if (ob_flags & PHP_OUTPUT_HANDLER_CLEAN) { php_stream_truncate_set_size(php_http_message_body_stream(obj->message->body), 0); + } else { + php_http_message_body_append(obj->message->body, ob_str, ob_len); } RETURN_TRUE; -#else - RETURN_EMPTY_STRING(); -#endif } } @@@ -1178,9 -1231,9 +1174,9 @@@ static PHP_METHOD(HttpEnvResponse, setE { zval *env_req = NULL; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O", &env_req, php_http_message_class_entry), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|O", &env_req, php_http_message_get_class_entry()), invalid_arg, return); - set_option(getThis(), ZEND_STRL("request"), IS_OBJECT, env_req, 0 TSRMLS_CC); + set_option(getThis(), ZEND_STRL("request"), IS_OBJECT, env_req, 0); RETVAL_ZVAL(getThis(), 1, 0); } @@@ -1190,11 -1243,11 +1186,11 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpEnvResponse, setContentType) { char *ct_str = NULL; - int ct_len = 0; + size_t ct_len = 0; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &ct_str, &ct_len), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &ct_str, &ct_len), invalid_arg, return); - set_option(getThis(), ZEND_STRL("contentType"), IS_STRING, ct_str, ct_len TSRMLS_CC); + set_option(getThis(), ZEND_STRL("contentType"), IS_STRING, ct_str, ct_len); RETVAL_ZVAL(getThis(), 1, 0); } @@@ -1205,9 -1258,9 +1201,9 @@@ static PHP_METHOD(HttpEnvResponse, setC { zval *zdisposition; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &zdisposition), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zdisposition), invalid_arg, return); - zend_update_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL("contentDisposition"), zdisposition TSRMLS_CC); + zend_update_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL("contentDisposition"), zdisposition); RETVAL_ZVAL(getThis(), 1, 0); } @@@ -1216,11 -1269,11 +1212,11 @@@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvRespon ZEND_END_ARG_INFO(); static PHP_METHOD(HttpEnvResponse, setContentEncoding) { - long ce; + zend_long ce; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ce), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "l", &ce), invalid_arg, return); - set_option(getThis(), ZEND_STRL("contentEncoding"), IS_LONG, &ce, 0 TSRMLS_CC); + set_option(getThis(), ZEND_STRL("contentEncoding"), IS_LONG, &ce, 0); RETVAL_ZVAL(getThis(), 1, 0); } @@@ -1230,11 -1283,11 +1226,11 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpEnvResponse, setCacheControl) { char *cc_str = NULL; - int cc_len = 0; + size_t cc_len = 0; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &cc_str, &cc_len), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &cc_str, &cc_len), invalid_arg, return); - set_option(getThis(), ZEND_STRL("cacheControl"), IS_STRING, cc_str, cc_len TSRMLS_CC); + set_option(getThis(), ZEND_STRL("cacheControl"), IS_STRING, cc_str, cc_len); RETVAL_ZVAL(getThis(), 1, 0); } @@@ -1243,11 -1296,11 +1239,11 @@@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvRespon ZEND_END_ARG_INFO(); static PHP_METHOD(HttpEnvResponse, setLastModified) { - long last_modified; + zend_long last_modified; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &last_modified), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "l", &last_modified), invalid_arg, return); - set_option(getThis(), ZEND_STRL("lastModified"), IS_LONG, &last_modified, 0 TSRMLS_CC); + set_option(getThis(), ZEND_STRL("lastModified"), IS_LONG, &last_modified, 0); RETVAL_ZVAL(getThis(), 1, 0); } @@@ -1257,15 -1310,15 +1253,15 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpEnvResponse, isCachedByLastModified) { char *header_name_str = NULL; - int header_name_len = 0; + size_t header_name_len = 0; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) { + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &header_name_str, &header_name_len)) { if (!header_name_str || !header_name_len) { header_name_str = "If-Modified-Since"; header_name_len = lenof("If-Modified-Since"); } - RETURN_LONG(php_http_env_is_response_cached_by_last_modified(getThis(), header_name_str, header_name_len, get_request(getThis() TSRMLS_CC) TSRMLS_CC)); + RETURN_LONG(php_http_env_is_response_cached_by_last_modified(getThis(), header_name_str, header_name_len, get_request(getThis()))); } } @@@ -1275,11 -1328,11 +1271,11 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpEnvResponse, setEtag) { char *etag_str = NULL; - int etag_len = 0; + size_t etag_len = 0; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &etag_str, &etag_len), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &etag_str, &etag_len), invalid_arg, return); - set_option(getThis(), ZEND_STRL("etag"), IS_STRING, etag_str, etag_len TSRMLS_CC); + set_option(getThis(), ZEND_STRL("etag"), IS_STRING, etag_str, etag_len); RETVAL_ZVAL(getThis(), 1, 0); } @@@ -1289,14 -1342,14 +1285,14 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpEnvResponse, isCachedByEtag) { char *header_name_str = NULL; - int header_name_len = 0; + size_t header_name_len = 0; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) { + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &header_name_str, &header_name_len)) { if (!header_name_str || !header_name_len) { header_name_str = "If-None-Match"; header_name_len = lenof("If-None-Match"); } - RETURN_LONG(php_http_env_is_response_cached_by_etag(getThis(), header_name_str, header_name_len, get_request(getThis() TSRMLS_CC) TSRMLS_CC)); + RETURN_LONG(php_http_env_is_response_cached_by_etag(getThis(), header_name_str, header_name_len, get_request(getThis()))); } } @@@ -1306,13 -1359,13 +1302,13 @@@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvRespon ZEND_END_ARG_INFO(); static PHP_METHOD(HttpEnvResponse, setThrottleRate) { - long chunk_size; + zend_long chunk_size; double delay = 1; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|d", &chunk_size, &delay), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "l|d", &chunk_size, &delay), invalid_arg, return); - set_option(getThis(), ZEND_STRL("throttleDelay"), IS_DOUBLE, &delay, 0 TSRMLS_CC); - set_option(getThis(), ZEND_STRL("throttleChunk"), IS_LONG, &chunk_size, 0 TSRMLS_CC); + set_option(getThis(), ZEND_STRL("throttleDelay"), IS_DOUBLE, &delay, 0); + set_option(getThis(), ZEND_STRL("throttleChunk"), IS_LONG, &chunk_size, 0); RETVAL_ZVAL(getThis(), 1, 0); } @@@ -1321,38 -1374,37 +1317,38 @@@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvRespon ZEND_END_ARG_INFO(); static PHP_METHOD(HttpEnvResponse, setCookie) { - zval *zcookie_new; + zval *zcookie_new, tmp; + zend_string *zs; zend_error_handling zeh; php_http_cookie_list_t *list = NULL; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zcookie_new), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zcookie_new), invalid_arg, return); - zend_replace_error_handling(EH_THROW, php_http_exception_unexpected_val_class_entry, &zeh TSRMLS_CC); + zend_replace_error_handling(EH_THROW, php_http_get_exception_unexpected_val_class_entry(), &zeh); switch (Z_TYPE_P(zcookie_new)) { case IS_OBJECT: - if (instanceof_function(Z_OBJCE_P(zcookie_new), php_http_cookie_class_entry TSRMLS_CC)) { + if (instanceof_function(Z_OBJCE_P(zcookie_new), php_http_cookie_get_class_entry())) { Z_ADDREF_P(zcookie_new); break; } /* no break */ case IS_ARRAY: - list = php_http_cookie_list_from_struct(NULL, zcookie_new TSRMLS_CC); - MAKE_STD_ZVAL(zcookie_new); - ZVAL_OBJVAL(zcookie_new, php_http_cookie_object_new_ex(php_http_cookie_class_entry, list, NULL TSRMLS_CC), 0); + list = php_http_cookie_list_from_struct(NULL, zcookie_new); + zcookie_new = &tmp; + ZVAL_OBJECT(zcookie_new, &php_http_cookie_object_new_ex(php_http_cookie_get_class_entry(), list)->zo, 0); break; default: - zcookie_new = php_http_ztyp(IS_STRING, zcookie_new); - list = php_http_cookie_list_parse(NULL, Z_STRVAL_P(zcookie_new), Z_STRLEN_P(zcookie_new), 0, NULL TSRMLS_CC); - zval_ptr_dtor(&zcookie_new); - MAKE_STD_ZVAL(zcookie_new); - ZVAL_OBJVAL(zcookie_new, php_http_cookie_object_new_ex(php_http_cookie_class_entry, list, NULL TSRMLS_CC), 0); + zs = zval_get_string(zcookie_new); + list = php_http_cookie_list_parse(NULL, zs->val, zs->len, 0, NULL); + zend_string_release(zs); + zcookie_new = &tmp; + ZVAL_OBJECT(zcookie_new, &php_http_cookie_object_new_ex(php_http_cookie_get_class_entry(), list)->zo, 0); } - zend_restore_error_handling(&zeh TSRMLS_CC); + zend_restore_error_handling(&zeh); - set_cookie(getThis(), zcookie_new TSRMLS_CC); - zval_ptr_dtor(&zcookie_new); + set_cookie(getThis(), zcookie_new); + zval_ptr_dtor(zcookie_new); RETVAL_ZVAL(getThis(), 1, 0); } @@@ -1365,16 -1417,20 +1361,16 @@@ static PHP_METHOD(HttpEnvResponse, send zval *zstream = NULL; php_stream *s = NULL; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &zstream)) { + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &zstream)) { /* first flush the output layer to avoid conflicting headers and output; * also, ob_start($thisEnvResponse) might have been called */ -#if PHP_VERSION_ID >= 50400 - php_output_end_all(TSRMLS_C); -#else - php_end_ob_buffers(1 TSRMLS_CC); -#endif + php_output_end_all(); if (zstream) { php_http_env_response_t *r; - php_stream_from_zval(s, &zstream); - r = php_http_env_response_init(NULL, getThis(), php_http_env_response_get_stream_ops(), s TSRMLS_CC); + php_stream_from_zval(s, zstream); + r = php_http_env_response_init(NULL, getThis(), php_http_env_response_get_stream_ops(), s); if (!r) { RETURN_FALSE; } @@@ -1384,7 -1440,7 +1380,7 @@@ } else { php_http_env_response_t r; - if (!php_http_env_response_init(&r, getThis(), NULL, NULL TSRMLS_CC)) { + if (!php_http_env_response_init(&r, getThis(), NULL, NULL)) { RETURN_FALSE; } @@@ -1412,36 -1468,32 +1408,36 @@@ static zend_function_entry php_http_env EMPTY_FUNCTION_ENTRY }; -zend_class_entry *php_http_env_response_class_entry; +static zend_class_entry *php_http_env_response_class_entry; +zend_class_entry *php_http_get_env_response_class_entry(void) +{ + return php_http_env_response_class_entry; +} PHP_MINIT_FUNCTION(http_env_response) { zend_class_entry ce = {0}; INIT_NS_CLASS_ENTRY(ce, "http\\Env", "Response", php_http_env_response_methods); - php_http_env_response_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry, NULL TSRMLS_CC); - - zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_ENCODING_NONE"), PHP_HTTP_CONTENT_ENCODING_NONE TSRMLS_CC); - zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_ENCODING_GZIP"), PHP_HTTP_CONTENT_ENCODING_GZIP TSRMLS_CC); - - zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_NO"), PHP_HTTP_CACHE_NO TSRMLS_CC); - zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_HIT"), PHP_HTTP_CACHE_HIT TSRMLS_CC); - zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_MISS"), PHP_HTTP_CACHE_MISS TSRMLS_CC); - - zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("request"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("cookies"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentType"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentDisposition"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentEncoding"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("cacheControl"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("etag"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("lastModified"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("throttleDelay"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("throttleChunk"), ZEND_ACC_PROTECTED TSRMLS_CC); + php_http_env_response_class_entry = zend_register_internal_class_ex(&ce, php_http_message_get_class_entry()); + + zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_ENCODING_NONE"), PHP_HTTP_CONTENT_ENCODING_NONE); + zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_ENCODING_GZIP"), PHP_HTTP_CONTENT_ENCODING_GZIP); + + zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_NO"), PHP_HTTP_CACHE_NO); + zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_HIT"), PHP_HTTP_CACHE_HIT); + zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_MISS"), PHP_HTTP_CACHE_MISS); + + zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("request"), ZEND_ACC_PROTECTED); + zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("cookies"), ZEND_ACC_PROTECTED); + zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentType"), ZEND_ACC_PROTECTED); + zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentDisposition"), ZEND_ACC_PROTECTED); + zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentEncoding"), ZEND_ACC_PROTECTED); + zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("cacheControl"), ZEND_ACC_PROTECTED); + zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("etag"), ZEND_ACC_PROTECTED); + zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("lastModified"), ZEND_ACC_PROTECTED); + zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("throttleDelay"), ZEND_ACC_PROTECTED); + zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("throttleChunk"), ZEND_ACC_PROTECTED); return SUCCESS; } diff --combined src/php_http_etag.c index 8c6a548,4d34d57..a02548c --- a/src/php_http_etag.c +++ b/src/php_http_etag.c @@@ -20,7 -20,7 +20,7 @@@ #include "ext/standard/sha1.h" #include "ext/standard/md5.h" -php_http_etag_t *php_http_etag_init(const char *mode TSRMLS_DC) +php_http_etag_t *php_http_etag_init(const char *mode) { void *ctx; php_http_etag_t *e; @@@ -47,6 -47,7 +47,6 @@@ e = emalloc(sizeof(*e)); e->ctx = ctx; e->mode = estrdup(mode); - TSRMLS_SET_CTX(e->ts); return e; } @@@ -79,7 -80,7 +79,7 @@@ char *php_http_etag_finish(php_http_eta #ifdef PHP_HTTP_HAVE_HASH const php_hash_ops *eho = NULL; - if (e->mode && (eho = php_hash_fetch_ops(e->mode, strlen(e->mode)))) { + if ((eho = php_hash_fetch_ops(e->mode, strlen(e->mode)))) { eho->hash_final(digest, e->ctx); etag = php_http_etag_digest(digest, eho->digest_size); } @@@ -109,7 -110,7 +109,7 @@@ size_t php_http_etag_update(php_http_et #ifdef PHP_HTTP_HAVE_HASH const php_hash_ops *eho = NULL; - if (e->mode && (eho = php_hash_fetch_ops(e->mode, strlen(e->mode)))) { + if ((eho = php_hash_fetch_ops(e->mode, strlen(e->mode)))) { eho->hash_update(e->ctx, (const unsigned char *) data_ptr, data_len); } #endif diff --combined src/php_http_filter.c index f145f02,9b39104..92bfd15 --- a/src/php_http_filter.c +++ b/src/php_http_filter.c @@@ -18,7 -18,7 +18,7 @@@ PHP_MINIT_FUNCTION(http_filter) { - php_stream_filter_register_factory("http.*", &php_http_filter_factory TSRMLS_CC); + php_stream_filter_register_factory("http.*", &php_http_filter_factory); return SUCCESS; } @@@ -27,8 -27,8 +27,8 @@@ php_stream_filter *this, \ php_stream_bucket_brigade *buckets_in, \ php_stream_bucket_brigade *buckets_out, \ - size_t *bytes_consumed, int flags \ - TSRMLS_DC + size_t *bytes_consumed, \ + int flags #define PHP_HTTP_FILTER_OP(filter) \ http_filter_op_ ##filter #define PHP_HTTP_FILTER_OPS(filter) \ @@@ -36,7 -36,7 +36,7 @@@ #define PHP_HTTP_FILTER_DTOR(filter) \ http_filter_ ##filter## _dtor #define PHP_HTTP_FILTER_DESTRUCTOR(filter) \ - void PHP_HTTP_FILTER_DTOR(filter)(php_stream_filter *this TSRMLS_DC) + void PHP_HTTP_FILTER_DTOR(filter)(php_stream_filter *this) #define PHP_HTTP_FILTER_FUNC(filter) \ http_filter_ ##filter #define PHP_HTTP_FILTER_FUNCTION(filter) \ @@@ -61,13 -61,13 +61,13 @@@ } \ memcpy(__data, data, length); \ \ - __buck = php_stream_bucket_new(stream, __data, length, 1, this->is_persistent TSRMLS_CC); \ + __buck = php_stream_bucket_new(stream, __data, length, 1, this->is_persistent); \ if (!__buck) { \ pefree(__data, this->is_persistent); \ return PSFS_ERR_FATAL; \ } \ \ - php_stream_bucket_append(buckets_out, __buck TSRMLS_CC); \ + php_stream_bucket_append(buckets_out, __buck); \ } typedef struct _http_chunked_decode_filter_buffer_t { @@@ -81,7 -81,7 +81,7 @@@ static PHP_HTTP_FILTER_FUNCTION(chunked { int out_avail = 0; php_stream_bucket *ptr, *nxt; - PHP_HTTP_FILTER_BUFFER(chunked_decode) *buffer = (PHP_HTTP_FILTER_BUFFER(chunked_decode) *) (this->abstract); + PHP_HTTP_FILTER_BUFFER(chunked_decode) *buffer = Z_PTR(this->abstract); if (bytes_consumed) { *bytes_consumed = 0; @@@ -98,8 -98,8 +98,8 @@@ } nxt = ptr->next; - php_stream_bucket_unlink(ptr TSRMLS_CC); - php_stream_bucket_delref(ptr TSRMLS_CC); + php_stream_bucket_unlink(ptr); + php_stream_bucket_delref(ptr); } if (!php_http_buffer_fix(PHP_HTTP_BUFFER(buffer))) { @@@ -185,7 -185,7 +185,7 @@@ php_http_buffer_cut(PHP_HTTP_BUFFER(buffer), 0, eolstr + eollen - PHP_HTTP_BUFFER(buffer)->data); /* buffer->hexlen is 0 now or contains the size of the next chunk */ if (!buffer->hexlen) { - php_stream_notify_info(stream->context, PHP_STREAM_NOTIFY_COMPLETED, NULL, 0); + php_stream_notify_info(PHP_STREAM_CONTEXT(stream), PHP_STREAM_NOTIFY_COMPLETED, NULL, 0); break; } /* continue */ @@@ -211,7 -211,7 +211,7 @@@ static PHP_HTTP_FILTER_DESTRUCTOR(chunked_decode) { - PHP_HTTP_FILTER_BUFFER(chunked_decode) *b = (PHP_HTTP_FILTER_BUFFER(chunked_decode) *) (this->abstract); + PHP_HTTP_FILTER_BUFFER(chunked_decode) *b = Z_PTR(this->abstract); php_http_buffer_dtor(PHP_HTTP_BUFFER(b)); pefree(b, this->is_persistent); @@@ -239,7 -239,7 +239,7 @@@ static PHP_HTTP_FILTER_FUNCTION(chunked #endif nxt = ptr->next; - php_stream_bucket_unlink(ptr TSRMLS_CC); + php_stream_bucket_unlink(ptr); php_http_buffer_appendf(&buf, "%lx" PHP_HTTP_CRLF, (long unsigned int) ptr->buflen); php_http_buffer_append(&buf, ptr->buf, ptr->buflen); php_http_buffer_appends(&buf, PHP_HTTP_CRLF); @@@ -248,7 -248,7 +248,7 @@@ NEW_BUCKET(buf.data, buf.used); /* reset */ php_http_buffer_reset(&buf); - php_stream_bucket_delref(ptr TSRMLS_CC); + php_stream_bucket_delref(ptr); } /* free buffer */ @@@ -281,7 -281,7 +281,7 @@@ static PHP_HTTP_FILTER_OPS(chunked_enco static PHP_HTTP_FILTER_FUNCTION(zlib) { php_stream_bucket *ptr, *nxt; - PHP_HTTP_FILTER_BUFFER(zlib) *buffer = (PHP_HTTP_FILTER_BUFFER(zlib) *) this->abstract; + PHP_HTTP_FILTER_BUFFER(zlib) *buffer = Z_PTR(this->abstract); if (bytes_consumed) { *bytes_consumed = 0; @@@ -301,8 -301,10 +301,10 @@@ #endif nxt = ptr->next; - php_stream_bucket_unlink(ptr TSRMLS_CC); + php_stream_bucket_unlink(ptr); - php_http_encoding_stream_update(buffer, ptr->buf, ptr->buflen, &encoded, &encoded_len); + if (SUCCESS != php_http_encoding_stream_update(buffer, ptr->buf, ptr->buflen, &encoded, &encoded_len)) { + return PSFS_ERR_FATAL; + } #if DBG_FILTER fprintf(stderr, "update: deflate (-> %zu) (w: %zu, r: %zu)\n", encoded_len, stream->writepos, stream->readpos); @@@ -314,7 -316,7 +316,7 @@@ } efree(encoded); } - php_stream_bucket_delref(ptr TSRMLS_CC); + php_stream_bucket_delref(ptr); } /* flush & close */ @@@ -322,7 -324,9 +324,9 @@@ char *encoded = NULL; size_t encoded_len = 0; - php_http_encoding_stream_flush(buffer, &encoded, &encoded_len); + if (SUCCESS != php_http_encoding_stream_flush(buffer, &encoded, &encoded_len)) { + return PSFS_ERR_FATAL; + } #if DBG_FILTER fprintf(stderr, "flush: deflate (-> %zu)\n", encoded_len); @@@ -340,7 -344,9 +344,9 @@@ char *encoded = NULL; size_t encoded_len = 0; - php_http_encoding_stream_finish(buffer, &encoded, &encoded_len); + if (SUCCESS != php_http_encoding_stream_finish(buffer, &encoded, &encoded_len)) { + return PSFS_ERR_FATAL; + } #if DBG_FILTER fprintf(stderr, "finish: deflate (-> %zu)\n", encoded_len); @@@ -358,7 -364,7 +364,7 @@@ } static PHP_HTTP_FILTER_DESTRUCTOR(zlib) { - PHP_HTTP_FILTER_BUFFER(zlib) *buffer = (PHP_HTTP_FILTER_BUFFER(zlib) *) this->abstract; + PHP_HTTP_FILTER_BUFFER(zlib) *buffer = Z_PTR(this->abstract); php_http_encoding_stream_free(&buffer); } @@@ -374,22 -380,28 +380,22 @@@ static PHP_HTTP_FILTER_OPS(inflate) = "http.inflate" }; -static php_stream_filter *http_filter_create(const char *name, zval *params, int p TSRMLS_DC) +static php_stream_filter *http_filter_create(const char *name, zval *params, int p) { - zval **tmp = ¶ms; + zval *tmp = params; php_stream_filter *f = NULL; int flags = p ? PHP_HTTP_ENCODING_STREAM_PERSISTENT : 0; if (params) { switch (Z_TYPE_P(params)) { - case IS_ARRAY: - case IS_OBJECT: - if (SUCCESS != zend_hash_find(HASH_OF(params), "flags", sizeof("flags"), (void *) &tmp)) { - break; - } - /* no break */ - default: - { - zval *num = php_http_ztyp(IS_LONG, *tmp); - - flags |= (Z_LVAL_P(num) & 0x0fffffff); - zval_ptr_dtor(&num); - + case IS_ARRAY: + case IS_OBJECT: + if (!(tmp = zend_hash_str_find_ind(HASH_OF(params), ZEND_STRL("flags")))) { + break; } + /* no break */ + default: + flags |= zval_get_long(tmp) & 0x0fffffff; break; } } @@@ -412,7 -424,7 +418,7 @@@ if (!strcasecmp(name, "http.inflate")) { PHP_HTTP_FILTER_BUFFER(zlib) *b = NULL; - if ((b = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_inflate_ops(), flags TSRMLS_CC))) { + if ((b = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_inflate_ops(), flags))) { if (!(f = php_stream_filter_alloc(&PHP_HTTP_FILTER_OP(inflate), b, p))) { php_http_encoding_stream_free(&b); } @@@ -422,7 -434,7 +428,7 @@@ if (!strcasecmp(name, "http.deflate")) { PHP_HTTP_FILTER_BUFFER(zlib) *b = NULL; - if ((b = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), flags TSRMLS_CC))) { + if ((b = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), flags))) { if (!(f = php_stream_filter_alloc(&PHP_HTTP_FILTER_OP(deflate), b, p))) { php_http_encoding_stream_free(&b); } diff --combined src/php_http_message.c index 5a5b5ca,3186b79..feef265 --- a/src/php_http_message.c +++ b/src/php_http_message.c @@@ -14,13 -14,13 +14,13 @@@ static void message_headers(php_http_message_t *msg, php_http_buffer_t *str); -zend_bool php_http_message_info_callback(php_http_message_t **message, HashTable **headers, php_http_info_t *info TSRMLS_DC) +zend_bool php_http_message_info_callback(php_http_message_t **message, HashTable **headers, php_http_info_t *info) { php_http_message_t *old = *message; /* advance message */ if (!old || old->type || zend_hash_num_elements(&old->hdrs)) { - (*message) = php_http_message_init(NULL, 0, NULL TSRMLS_CC); + (*message) = php_http_message_init(NULL, 0, NULL); (*message)->parent = old; if (headers) { (*headers) = &((*message)->hdrs); @@@ -34,23 -34,24 +34,23 @@@ return old != *message; } -php_http_message_t *php_http_message_init(php_http_message_t *message, php_http_message_type_t type, php_http_message_body_t *body TSRMLS_DC) +php_http_message_t *php_http_message_init(php_http_message_t *message, php_http_message_type_t type, php_http_message_body_t *body) { if (!message) { message = emalloc(sizeof(*message)); } memset(message, 0, sizeof(*message)); - TSRMLS_SET_CTX(message->ts); php_http_message_set_type(message, type); message->http.version.major = 1; message->http.version.minor = 1; zend_hash_init(&message->hdrs, 0, NULL, ZVAL_PTR_DTOR, 0); - message->body = body ? body : php_http_message_body_init(NULL, NULL TSRMLS_CC); + message->body = body ? body : php_http_message_body_init(NULL, NULL); return message; } -php_http_message_t *php_http_message_init_env(php_http_message_t *message, php_http_message_type_t type TSRMLS_DC) +php_http_message_t *php_http_message_init_env(php_http_message_t *message, php_http_message_type_t type) { int free_msg = !message; zval *sval, tval; @@@ -58,45 -59,59 +58,45 @@@ switch (type) { case PHP_HTTP_REQUEST: - mbody = php_http_env_get_request_body(TSRMLS_C); + mbody = php_http_env_get_request_body(); php_http_message_body_addref(mbody); - message = php_http_message_init(message, type, mbody TSRMLS_CC); - if ((sval = php_http_env_get_server_var(ZEND_STRL("SERVER_PROTOCOL"), 1 TSRMLS_CC)) && !strncmp(Z_STRVAL_P(sval), "HTTP/", lenof("HTTP/"))) { - php_http_version_parse(&message->http.version, Z_STRVAL_P(sval) TSRMLS_CC); + message = php_http_message_init(message, type, mbody); + if ((sval = php_http_env_get_server_var(ZEND_STRL("SERVER_PROTOCOL"), 1)) && !strncmp(Z_STRVAL_P(sval), "HTTP/", lenof("HTTP/"))) { + php_http_version_parse(&message->http.version, Z_STRVAL_P(sval)); } - if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_METHOD"), 1 TSRMLS_CC))) { + if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_METHOD"), 1))) { message->http.info.request.method = estrdup(Z_STRVAL_P(sval)); } - if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_URI"), 1 TSRMLS_CC))) { - message->http.info.request.url = php_http_url_parse(Z_STRVAL_P(sval), Z_STRLEN_P(sval), PHP_HTTP_URL_STDFLAGS TSRMLS_CC); + if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_URI"), 1))) { + message->http.info.request.url = php_http_url_parse(Z_STRVAL_P(sval), Z_STRLEN_P(sval), PHP_HTTP_URL_STDFLAGS); } - php_http_env_get_request_headers(&message->hdrs TSRMLS_CC); + php_http_env_get_request_headers(&message->hdrs); break; case PHP_HTTP_RESPONSE: - message = php_http_message_init(NULL, type, NULL TSRMLS_CC); - if (!SG(sapi_headers).http_status_line || !php_http_info_parse((php_http_info_t *) &message->http, SG(sapi_headers).http_status_line TSRMLS_CC)) { + message = php_http_message_init(NULL, type, NULL); + if (!SG(sapi_headers).http_status_line || !php_http_info_parse((php_http_info_t *) &message->http, SG(sapi_headers).http_status_line)) { if (!(message->http.info.response.code = SG(sapi_headers).http_response_code)) { message->http.info.response.code = 200; } message->http.info.response.status = estrdup(php_http_env_get_response_status_for_code(message->http.info.response.code)); } - php_http_env_get_response_headers(&message->hdrs TSRMLS_CC); -#if PHP_VERSION_ID >= 50400 - if (php_output_get_level(TSRMLS_C)) { - if (php_output_get_status(TSRMLS_C) & PHP_OUTPUT_SENT) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not fetch response body, output has already been sent at %s:%d", php_output_get_start_filename(TSRMLS_C), php_output_get_start_lineno(TSRMLS_C)); - goto error; - } else if (SUCCESS != php_output_get_contents(&tval TSRMLS_CC)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not fetch response body"); - goto error; - } else { - php_http_message_body_append(message->body, Z_STRVAL(tval), Z_STRLEN(tval)); - zval_dtor(&tval); - } - } -#else - if (OG(ob_nesting_level)) { - if (php_get_output_start_filename(TSRMLS_C)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not fetch response body, output has already been sent at %s:%d", php_get_output_start_filename(TSRMLS_C), php_get_output_start_lineno(TSRMLS_C)); + php_http_env_get_response_headers(&message->hdrs); + if (php_output_get_level()) { + if (php_output_get_status() & PHP_OUTPUT_SENT) { + php_error_docref(NULL, E_WARNING, "Could not fetch response body, output has already been sent at %s:%d", php_output_get_start_filename(), php_output_get_start_lineno()); + goto error; - } else if (SUCCESS != php_ob_get_buffer(&tval TSRMLS_CC)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not fetch response body"); + } else if (SUCCESS != php_output_get_contents(&tval)) { + php_error_docref(NULL, E_WARNING, "Could not fetch response body"); goto error; } else { php_http_message_body_append(message->body, Z_STRVAL(tval), Z_STRLEN(tval)); zval_dtor(&tval); } } -#endif break; default: @@@ -114,7 -129,7 +114,7 @@@ return message; } -php_http_message_t *php_http_message_parse(php_http_message_t *msg, const char *str, size_t len, zend_bool greedy TSRMLS_DC) +php_http_message_t *php_http_message_parse(php_http_message_t *msg, const char *str, size_t len, zend_bool greedy) { php_http_message_parser_t p; php_http_buffer_t buf; @@@ -122,10 -137,10 +122,10 @@@ int free_msg; php_http_buffer_from_string_ex(&buf, str, len); - php_http_message_parser_init(&p TSRMLS_CC); + php_http_message_parser_init(&p); if ((free_msg = !msg)) { - msg = php_http_message_init(NULL, 0, NULL TSRMLS_CC); + msg = php_http_message_init(NULL, 0, NULL); } if (greedy) { @@@ -144,19 -159,27 +144,19 @@@ return msg; } -zval *php_http_message_header(php_http_message_t *msg, const char *key_str, size_t key_len, int join) +zval *php_http_message_header(php_http_message_t *msg, const char *key_str, size_t key_len) { - zval *ret = NULL, **header; + zval *ret; char *key; ALLOCA_FLAG(free_key); key = do_alloca(key_len + 1, free_key); + memcpy(key, key_str, key_len); key[key_len] = '\0'; php_http_pretty_key(key, key_len, 1, 1); - if (SUCCESS == zend_symtable_find(&msg->hdrs, key, key_len + 1, (void *) &header)) { - if (join && Z_TYPE_PP(header) == IS_ARRAY) { - TSRMLS_FETCH_FROM_CTX(msg->ts); - - ret = php_http_header_value_to_string(*header TSRMLS_CC); - } else { - Z_ADDREF_PP(header); - ret = *header; - } - } + ret = zend_symtable_str_find(&msg->hdrs, key, key_len); free_alloca(key, free_key); @@@ -165,8 -188,9 +165,8 @@@ zend_bool php_http_message_is_multipart(php_http_message_t *msg, char **boundary) { - zval *ct = php_http_message_header(msg, ZEND_STRL("Content-Type"), 1); + zend_string *ct = php_http_message_header_string(msg, ZEND_STRL("Content-Type")); zend_bool is_multipart = 0; - TSRMLS_FETCH_FROM_CTX(msg->ts); if (ct) { php_http_params_opts_t popts; @@@ -174,49 -198,47 +174,49 @@@ ZEND_INIT_SYMTABLE(¶ms); php_http_params_opts_default_get(&popts); - popts.input.str = Z_STRVAL_P(ct); - popts.input.len = Z_STRLEN_P(ct); + popts.input.str = ct->val; + popts.input.len = ct->len; - if (php_http_params_parse(¶ms, &popts TSRMLS_CC)) { - zval **cur, **arg; - char *ct_str; + if (php_http_params_parse(¶ms, &popts)) { + zval *cur, *arg; + zend_string *ct_str; + zend_ulong index; zend_hash_internal_pointer_reset(¶ms); - if (SUCCESS == zend_hash_get_current_data(¶ms, (void *) &cur) - && Z_TYPE_PP(cur) == IS_ARRAY - && HASH_KEY_IS_STRING == zend_hash_get_current_key(¶ms, &ct_str, NULL, 0) + if ((cur = zend_hash_get_current_data(¶ms)) + && (Z_TYPE_P(cur) == IS_ARRAY) + && (HASH_KEY_IS_STRING == zend_hash_get_current_key(¶ms, &ct_str, &index)) ) { - if (php_http_match(ct_str, "multipart", PHP_HTTP_MATCH_WORD)) { + if (php_http_match(ct_str->val, "multipart", PHP_HTTP_MATCH_WORD)) { is_multipart = 1; /* get boundary */ if (boundary - && SUCCESS == zend_hash_find(Z_ARRVAL_PP(cur), ZEND_STRS("arguments"), (void *) &arg) - && Z_TYPE_PP(arg) == IS_ARRAY + && (arg = zend_hash_str_find(Z_ARRVAL_P(cur), ZEND_STRL("arguments"))) + && Z_TYPE_P(arg) == IS_ARRAY ) { - zval **val; - HashPosition pos; - php_http_array_hashkey_t key = php_http_array_hashkey_init(0); + zval *val; + php_http_arrkey_t key; - FOREACH_KEYVAL(pos, *arg, key, val) { - if (key.type == HASH_KEY_IS_STRING && !strcasecmp(key.str, "boundary")) { - zval *bnd = php_http_ztyp(IS_STRING, *val); + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(arg), key.h, key.key, val) + { + if (key.key && key.key->len == lenof("boundary") && !strcasecmp(key.key->val, "boundary")) { + zend_string *bnd = zval_get_string(val); - if (Z_STRLEN_P(bnd)) { - *boundary = estrndup(Z_STRVAL_P(bnd), Z_STRLEN_P(bnd)); + if (bnd->len) { + *boundary = estrndup(bnd->val, bnd->len); } - zval_ptr_dtor(&bnd); + zend_string_release(bnd); } } + ZEND_HASH_FOREACH_END(); } } } } zend_hash_destroy(¶ms); - zval_ptr_dtor(&ct); + zend_string_release(ct); } return is_multipart; @@@ -270,44 -292,49 +270,44 @@@ void php_http_message_set_info(php_http void php_http_message_update_headers(php_http_message_t *msg) { - zval *h; + zval h; size_t size; + zend_string *cl; if (php_http_message_body_stream(msg->body)->readfilters.head) { /* if a read stream filter is attached to the body the caller must also care for the headers */ - } else if ((h = php_http_message_header(msg, ZEND_STRL("Content-Range"), 0))) { + } else if (php_http_message_header(msg, ZEND_STRL("Content-Range"))) { /* don't mess around with a Content-Range message */ - zval_ptr_dtor(&h); } else if ((size = php_http_message_body_size(msg->body))) { - MAKE_STD_ZVAL(h); - ZVAL_LONG(h, size); - zend_hash_update(&msg->hdrs, "Content-Length", sizeof("Content-Length"), &h, sizeof(zval *), NULL); + ZVAL_LONG(&h, size); + zend_hash_str_update(&msg->hdrs, "Content-Length", lenof("Content-Length"), &h); if (msg->body->boundary) { char *str; size_t len; + zend_string *ct; - if (!(h = php_http_message_header(msg, ZEND_STRL("Content-Type"), 1))) { + if (!(ct = php_http_message_header_string(msg, ZEND_STRL("Content-Type")))) { len = spprintf(&str, 0, "multipart/form-data; boundary=\"%s\"", msg->body->boundary); - MAKE_STD_ZVAL(h); - ZVAL_STRINGL(h, str, len, 0); - zend_hash_update(&msg->hdrs, "Content-Type", sizeof("Content-Type"), &h, sizeof(zval *), NULL); - } else if (!php_http_match(Z_STRVAL_P(h), "boundary=", PHP_HTTP_MATCH_WORD)) { - zval_dtor(h); - Z_STRLEN_P(h) = spprintf(&Z_STRVAL_P(h), 0, "%s; boundary=\"%s\"", Z_STRVAL_P(h), msg->body->boundary); - zend_hash_update(&msg->hdrs, "Content-Type", sizeof("Content-Type"), &h, sizeof(zval *), NULL); + ZVAL_STR(&h, php_http_cs2zs(str, len)); + zend_hash_str_update(&msg->hdrs, "Content-Type", lenof("Content-Type"), &h); + } else if (!php_http_match(ct->val, "boundary=", PHP_HTTP_MATCH_WORD)) { + len = spprintf(&str, 0, "%s; boundary=\"%s\"", ct->val, msg->body->boundary); + ZVAL_STR(&h, php_http_cs2zs(str, len)); + zend_hash_str_update(&msg->hdrs, "Content-Type", lenof("Content-Type"), &h); + zend_string_release(ct); } else { - zval_ptr_dtor(&h); + zend_string_release(ct); } } - } else if ((h = php_http_message_header(msg, ZEND_STRL("Content-Length"), 1))) { - zval *h_cpy = php_http_ztyp(IS_LONG, h); - - zval_ptr_dtor(&h); - if (Z_LVAL_P(h_cpy)) { + } else if ((cl = php_http_message_header_string(msg, ZEND_STRL("Content-Length")))) { + if (!zend_string_equals_literal(cl, "0")) { /* body->size == 0, so get rid of old Content-Length */ - zend_hash_del(&msg->hdrs, "Content-Length", sizeof("Content-Length")); + zend_hash_str_del(&msg->hdrs, ZEND_STRL("Content-Length")); } - zval_ptr_dtor(&h_cpy); + zend_string_release(cl); } else if (msg->type == PHP_HTTP_REQUEST) { - if ((h = php_http_message_header(msg, ZEND_STRL("Transfer-Encoding"), 0))) { - zval_ptr_dtor(&h); - } else { + if (!php_http_message_header(msg, ZEND_STRL("Transfer-Encoding"))) { /* no filter, no CR, no size, no TE, no CL */ if (0 <= php_http_select_str(msg->http.info.request.method, 3, "POST", "PUT", "PATCH")) { /* quoting RFC7230#section-3.3.2 @@@ -320,8 -347,9 +320,8 @@@ a payload body and the method semantics do not anticipate such a body. */ - MAKE_STD_ZVAL(h); - ZVAL_LONG(h, 0); - zend_hash_update(&msg->hdrs, "Content-Length", sizeof("Content-Length"), &h, sizeof(zval *), NULL); + ZVAL_LONG(&h, 0); + zend_hash_str_update(&msg->hdrs, "Content-Length", lenof("Content-Length"), &h); } } } @@@ -331,13 -359,14 +331,13 @@@ static void message_headers(php_http_me { char *tmp = NULL; size_t len = 0; - TSRMLS_FETCH_FROM_CTX(msg->ts); php_http_info_to_string((php_http_info_t *) msg, &tmp, &len, PHP_HTTP_CRLF TSRMLS_CC); php_http_message_update_headers(msg); php_http_buffer_append(str, tmp, len); - php_http_header_to_string(str, &msg->hdrs TSRMLS_CC); - STR_FREE(tmp); + php_http_header_to_string(str, &msg->hdrs); + PTR_FREE(tmp); } void php_http_message_to_callback(php_http_message_t *msg, php_http_pass_callback_t cb, void *cb_arg) @@@ -400,12 -429,14 +400,12 @@@ void php_http_message_serialize(php_htt php_http_message_t *php_http_message_reverse(php_http_message_t *msg) { - int i, c = 0; - - php_http_message_count(c, msg); + size_t i, c = php_http_message_count(msg); if (c > 1) { php_http_message_t *tmp = msg, **arr; - arr = ecalloc(c, sizeof(**arr)); + arr = ecalloc(c, sizeof(*arr)); for (i = 0; i < c; ++i) { arr[i] = tmp; tmp = tmp->parent; @@@ -422,11 -453,11 +422,11 @@@ return msg; } -php_http_message_t *php_http_message_zip(php_http_message_t *one, php_http_message_t *two) +php_http_message_t *php_http_message_zip(php_http_message_t *dst, php_http_message_t *src) { - php_http_message_t *dst = php_http_message_copy(one, NULL), *src = php_http_message_copy(two, NULL), *tmp_dst, *tmp_src, *ret = dst; + php_http_message_t *tmp_dst, *tmp_src, *ret = dst; - while(dst && src) { + while (dst && src) { tmp_dst = dst->parent; tmp_src = src->parent; dst->parent = src; @@@ -444,22 -475,23 +444,22 @@@ php_http_message_t *php_http_message_co { php_http_message_t *temp, *copy = NULL; php_http_info_t info; - TSRMLS_FETCH_FROM_CTX(from->ts); if (from) { info.type = from->type; info.http = from->http; - copy = temp = php_http_message_init(to, 0, php_http_message_body_copy(from->body, NULL) TSRMLS_CC); + copy = temp = php_http_message_init(to, 0, php_http_message_body_copy(from->body, NULL)); php_http_message_set_info(temp, &info); - zend_hash_copy(&temp->hdrs, &from->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); + array_copy(&from->hdrs, &temp->hdrs); if (parents) while (from->parent) { info.type = from->parent->type; info.http = from->parent->http; - temp->parent = php_http_message_init(NULL, 0, php_http_message_body_copy(from->parent->body, NULL) TSRMLS_CC); + temp->parent = php_http_message_init(NULL, 0, php_http_message_body_copy(from->parent->body, NULL)); php_http_message_set_info(temp->parent, &info); - zend_hash_copy(&temp->parent->hdrs, &from->parent->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); + array_copy(&from->parent->hdrs, &temp->parent->hdrs); temp = temp->parent; from = from->parent; @@@ -469,6 -501,11 +469,6 @@@ return copy; } -php_http_message_t *php_http_message_copy(php_http_message_t *from, php_http_message_t *to) -{ - return php_http_message_copy_ex(from, to, 1); -} - void php_http_message_dtor(php_http_message_t *message) { if (message) { @@@ -503,24 -540,14 +503,24 @@@ void php_http_message_free(php_http_mes } } -static zval *php_http_message_object_read_prop(zval *object, zval *member, int type PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC); -static void php_http_message_object_write_prop(zval *object, zval *member, zval *value PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC); -static HashTable *php_http_message_object_get_props(zval *object TSRMLS_DC); +static zend_class_entry *php_http_message_class_entry; +zend_class_entry *php_http_message_get_class_entry(void) +{ + return php_http_message_class_entry; +} + +static zval *php_http_message_object_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *rv); +static void php_http_message_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot); static zend_object_handlers php_http_message_object_handlers; static HashTable php_http_message_object_prophandlers; -typedef void (*php_http_message_object_prophandler_func_t)(php_http_message_object_t *o, zval *v TSRMLS_DC); +static void php_http_message_object_prophandler_hash_dtor(zval *pData) +{ + pefree(Z_PTR_P(pData), 1); +} + +typedef void (*php_http_message_object_prophandler_func_t)(php_http_message_object_t *o, zval *v); typedef struct php_http_message_object_prophandler { php_http_message_object_prophandler_func_t read; @@@ -529,133 -556,125 +529,133 @@@ static ZEND_RESULT_CODE php_http_message_object_add_prophandler(const char *prop_str, size_t prop_len, php_http_message_object_prophandler_func_t read, php_http_message_object_prophandler_func_t write) { php_http_message_object_prophandler_t h = { read, write }; - return zend_hash_add(&php_http_message_object_prophandlers, prop_str, prop_len + 1, (void *) &h, sizeof(h), NULL); + if (!zend_hash_str_add_mem(&php_http_message_object_prophandlers, prop_str, prop_len, (void *) &h, sizeof(h))) { + return FAILURE; + } + return SUCCESS; } -static ZEND_RESULT_CODE php_http_message_object_get_prophandler(const char *prop_str, size_t prop_len, php_http_message_object_prophandler_t **handler) { - return zend_hash_find(&php_http_message_object_prophandlers, prop_str, prop_len + 1, (void *) handler); +static php_http_message_object_prophandler_t *php_http_message_object_get_prophandler(zend_string *name_str) { + return zend_hash_str_find_ptr(&php_http_message_object_prophandlers, name_str->val, name_str->len); } -static void php_http_message_object_prophandler_get_type(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) { +static void php_http_message_object_prophandler_get_type(php_http_message_object_t *obj, zval *return_value) { RETVAL_LONG(obj->message->type); } -static void php_http_message_object_prophandler_set_type(php_http_message_object_t *obj, zval *value TSRMLS_DC) { - zval *cpy = php_http_ztyp(IS_LONG, value); - php_http_message_set_type(obj->message, Z_LVAL_P(cpy)); - zval_ptr_dtor(&cpy); +static void php_http_message_object_prophandler_set_type(php_http_message_object_t *obj, zval *value) { + php_http_message_set_type(obj->message, zval_get_long(value)); } -static void php_http_message_object_prophandler_get_request_method(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) { +static void php_http_message_object_prophandler_get_request_method(php_http_message_object_t *obj, zval *return_value) { if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message) && obj->message->http.info.request.method) { - RETVAL_STRING(obj->message->http.info.request.method, 1); + RETVAL_STRING(obj->message->http.info.request.method); } else { RETVAL_NULL(); } } -static void php_http_message_object_prophandler_set_request_method(php_http_message_object_t *obj, zval *value TSRMLS_DC) { +static void php_http_message_object_prophandler_set_request_method(php_http_message_object_t *obj, zval *value) { if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message)) { - zval *cpy = php_http_ztyp(IS_STRING, value); - PTR_SET(obj->message->http.info.request.method, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy))); - zval_ptr_dtor(&cpy); + zend_string *zs = zval_get_string(value); + PTR_SET(obj->message->http.info.request.method, estrndup(zs->val, zs->len)); + zend_string_release(zs); } } -static void php_http_message_object_prophandler_get_request_url(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) { +static void php_http_message_object_prophandler_get_request_url(php_http_message_object_t *obj, zval *return_value) { char *url_str; size_t url_len; if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message) && obj->message->http.info.request.url && php_http_url_to_string(obj->message->http.info.request.url, &url_str, &url_len, 0)) { - RETVAL_STRINGL(url_str, url_len, 0); + RETVAL_STR(php_http_cs2zs(url_str, url_len)); } else { RETVAL_NULL(); } } -static void php_http_message_object_prophandler_set_request_url(php_http_message_object_t *obj, zval *value TSRMLS_DC) { +static void php_http_message_object_prophandler_set_request_url(php_http_message_object_t *obj, zval *value) { if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message)) { - PTR_SET(obj->message->http.info.request.url, php_http_url_from_zval(value, PHP_HTTP_URL_STDFLAGS TSRMLS_CC)); + PTR_SET(obj->message->http.info.request.url, php_http_url_from_zval(value, PHP_HTTP_URL_STDFLAGS)); } } -static void php_http_message_object_prophandler_get_response_status(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) { +static void php_http_message_object_prophandler_get_response_status(php_http_message_object_t *obj, zval *return_value) { if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message) && obj->message->http.info.response.status) { - RETVAL_STRING(obj->message->http.info.response.status, 1); + RETVAL_STRING(obj->message->http.info.response.status); } else { RETVAL_NULL(); } } -static void php_http_message_object_prophandler_set_response_status(php_http_message_object_t *obj, zval *value TSRMLS_DC) { +static void php_http_message_object_prophandler_set_response_status(php_http_message_object_t *obj, zval *value) { if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message)) { - zval *cpy = php_http_ztyp(IS_STRING, value); - PTR_SET(obj->message->http.info.response.status, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy))); - zval_ptr_dtor(&cpy); + zend_string *zs = zval_get_string(value); + PTR_SET(obj->message->http.info.response.status, estrndup(zs->val, zs->len)); + zend_string_release(zs); } } -static void php_http_message_object_prophandler_get_response_code(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) { +static void php_http_message_object_prophandler_get_response_code(php_http_message_object_t *obj, zval *return_value) { if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message)) { RETVAL_LONG(obj->message->http.info.response.code); } else { RETVAL_NULL(); } } -static void php_http_message_object_prophandler_set_response_code(php_http_message_object_t *obj, zval *value TSRMLS_DC) { +static void php_http_message_object_prophandler_set_response_code(php_http_message_object_t *obj, zval *value) { if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message)) { - zval *cpy = php_http_ztyp(IS_LONG, value); - obj->message->http.info.response.code = Z_LVAL_P(cpy); + obj->message->http.info.response.code = zval_get_long(value); PTR_SET(obj->message->http.info.response.status, estrdup(php_http_env_get_response_status_for_code(obj->message->http.info.response.code))); - zval_ptr_dtor(&cpy); } } -static void php_http_message_object_prophandler_get_http_version(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) { +static void php_http_message_object_prophandler_get_http_version(php_http_message_object_t *obj, zval *return_value) { char *version_str; size_t version_len; - php_http_version_to_string(&obj->message->http.version, &version_str, &version_len, NULL, NULL TSRMLS_CC); - RETVAL_STRINGL(version_str, version_len, 0); + php_http_version_to_string(&obj->message->http.version, &version_str, &version_len, NULL, NULL); + RETVAL_STR(php_http_cs2zs(version_str, version_len)); } -static void php_http_message_object_prophandler_set_http_version(php_http_message_object_t *obj, zval *value TSRMLS_DC) { - zval *cpy = php_http_ztyp(IS_STRING, value); - php_http_version_parse(&obj->message->http.version, Z_STRVAL_P(cpy) TSRMLS_CC); - zval_ptr_dtor(&cpy); +static void php_http_message_object_prophandler_set_http_version(php_http_message_object_t *obj, zval *value) { + zend_string *zs = zval_get_string(value); + php_http_version_parse(&obj->message->http.version, zs->val); + zend_string_release(zs); } -static void php_http_message_object_prophandler_get_headers(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) { +static void php_http_message_object_prophandler_get_headers(php_http_message_object_t *obj, zval *return_value ) { array_init(return_value); - zend_hash_copy(Z_ARRVAL_P(return_value), &obj->message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); + array_copy(&obj->message->hdrs, Z_ARRVAL_P(return_value)); } -static void php_http_message_object_prophandler_set_headers(php_http_message_object_t *obj, zval *value TSRMLS_DC) { - zval *cpy = php_http_ztyp(IS_ARRAY, value); +static void php_http_message_object_prophandler_set_headers(php_http_message_object_t *obj, zval *value) { + HashTable *headers; + zval *orig_value = value; + + if (Z_TYPE_P(value) != IS_ARRAY && Z_TYPE_P(value) != IS_OBJECT) { + convert_to_array_ex(value); + } + headers = HASH_OF(value); zend_hash_clean(&obj->message->hdrs); - zend_hash_copy(&obj->message->hdrs, Z_ARRVAL_P(cpy), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); - zval_ptr_dtor(&cpy); + array_copy(headers, &obj->message->hdrs); + + if (orig_value != value) { + zval_ptr_dtor(value); + } } -static void php_http_message_object_prophandler_get_body(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) { +static void php_http_message_object_prophandler_get_body(php_http_message_object_t *obj, zval *return_value) { if (obj->body) { - RETVAL_OBJVAL(obj->body->zv, 1); + RETVAL_OBJECT(&obj->body->zo, 1); } else { RETVAL_NULL(); } } -static void php_http_message_object_prophandler_set_body(php_http_message_object_t *obj, zval *value TSRMLS_DC) { - php_http_message_object_set_body(obj, value TSRMLS_CC); +static void php_http_message_object_prophandler_set_body(php_http_message_object_t *obj, zval *value) { + php_http_message_object_set_body(obj, value); } -static void php_http_message_object_prophandler_get_parent_message(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) { +static void php_http_message_object_prophandler_get_parent_message(php_http_message_object_t *obj, zval *return_value) { if (obj->message->parent) { - RETVAL_OBJVAL(obj->parent->zv, 1); + RETVAL_OBJECT(&obj->parent->zo, 1); } else { RETVAL_NULL(); } } -static void php_http_message_object_prophandler_set_parent_message(php_http_message_object_t *obj, zval *value TSRMLS_DC) { - if (Z_TYPE_P(value) == IS_OBJECT && instanceof_function(Z_OBJCE_P(value), php_http_message_class_entry TSRMLS_CC)) { - php_http_message_object_t *parent_obj = zend_object_store_get_object(value TSRMLS_CC); +static void php_http_message_object_prophandler_set_parent_message(php_http_message_object_t *obj, zval *value) { + if (Z_TYPE_P(value) == IS_OBJECT && instanceof_function(Z_OBJCE_P(value), php_http_message_class_entry)) { + php_http_message_object_t *parent_obj = PHP_HTTP_OBJ(NULL, value); if (obj->message->parent) { - zend_objects_store_del_ref_by_handle(obj->parent->zv.handle TSRMLS_CC); + zend_object_release(&obj->parent->zo); } - Z_OBJ_ADDREF_P(value); + Z_ADDREF_P(value); obj->parent = parent_obj; obj->message->parent = parent_obj->message; } @@@ -664,26 -683,26 +664,26 @@@ #define PHP_HTTP_MESSAGE_OBJECT_INIT(obj) \ do { \ if (!obj->message) { \ - obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC); \ + obj->message = php_http_message_init(NULL, 0, NULL); \ } \ } while(0) -void php_http_message_object_reverse(zval *this_ptr, zval *return_value TSRMLS_DC) +void php_http_message_object_reverse(zval *zmsg, zval *return_value) { - int i = 0; - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + size_t i; + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, zmsg); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); /* count */ - php_http_message_count(i, obj->message); + i = php_http_message_count(obj->message); if (i > 1) { php_http_message_object_t **objects; int last; - objects = ecalloc(i, sizeof(**objects)); + objects = ecalloc(i, sizeof(*objects)); /* we are the first message */ objects[0] = obj; @@@ -703,21 -722,24 +703,21 @@@ objects[0]->parent = NULL; /* add ref, because we previously have not been a parent message */ - Z_OBJ_ADDREF_P(getThis()); - RETVAL_OBJVAL(objects[last]->zv, 0); + Z_ADDREF_P(zmsg); + /* no addref, because we've been a parent message previously */ + RETVAL_OBJECT(&objects[last]->zo, 0); efree(objects); } else { - RETURN_ZVAL(getThis(), 1, 0); + RETURN_ZVAL(zmsg, 1, 0); } } -void php_http_message_object_prepend(zval *this_ptr, zval *prepend, zend_bool top TSRMLS_DC) +void php_http_message_object_prepend(zval *this_ptr, zval *prepend, zend_bool top) { - zval m; php_http_message_t *save_parent_msg = NULL; - php_http_message_object_t *save_parent_obj = NULL, *obj = zend_object_store_get_object(this_ptr TSRMLS_CC); - php_http_message_object_t *prepend_obj = zend_object_store_get_object(prepend TSRMLS_CC); - - INIT_PZVAL(&m); - m.type = IS_OBJECT; + php_http_message_object_t *save_parent_obj = NULL, *obj = PHP_HTTP_OBJ(NULL, this_ptr); + php_http_message_object_t *prepend_obj = PHP_HTTP_OBJ(NULL, prepend); if (!top) { save_parent_obj = obj->parent; @@@ -734,7 -756,7 +734,7 @@@ obj->message->parent = prepend_obj->message; /* add ref */ - zend_objects_store_add_ref(prepend TSRMLS_CC); + Z_ADDREF_P(prepend); if (!top) { prepend_obj->parent = save_parent_obj; @@@ -742,16 -764,17 +742,16 @@@ } } -ZEND_RESULT_CODE php_http_message_object_set_body(php_http_message_object_t *msg_obj, zval *zbody TSRMLS_DC) +ZEND_RESULT_CODE php_http_message_object_set_body(php_http_message_object_t *msg_obj, zval *zbody) { - zval *tmp = NULL; php_stream *s; - zend_object_value ov; + zend_string *body_str; php_http_message_body_t *body; php_http_message_body_object_t *body_obj; switch (Z_TYPE_P(zbody)) { case IS_RESOURCE: - php_stream_from_zval_no_verify(s, &zbody); + php_stream_from_zval_no_verify(s, zbody); if (!s) { php_http_throw(unexpected_val, "The stream is not a valid resource", NULL); return FAILURE; @@@ -759,100 -782,112 +759,100 @@@ is_resource: - body = php_http_message_body_init(NULL, s TSRMLS_CC); - if (SUCCESS != php_http_new(&ov, php_http_message_body_class_entry, (php_http_new_t) php_http_message_body_object_new_ex, NULL, body, NULL TSRMLS_CC)) { + body = php_http_message_body_init(NULL, s); + if (!(body_obj = php_http_message_body_object_new_ex(php_http_get_message_body_class_entry(), body))) { php_http_message_body_free(&body); return FAILURE; } - MAKE_STD_ZVAL(tmp); - ZVAL_OBJVAL(tmp, ov, 0); - zbody = tmp; break; case IS_OBJECT: - if (instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_class_entry TSRMLS_CC)) { - Z_OBJ_ADDREF_P(zbody); + if (instanceof_function(Z_OBJCE_P(zbody), php_http_get_message_body_class_entry())) { + Z_ADDREF_P(zbody); + body_obj = PHP_HTTP_OBJ(NULL, zbody); break; } /* no break */ default: - tmp = php_http_ztyp(IS_STRING, zbody); + body_str = zval_get_string(zbody); s = php_stream_temp_new(); - php_stream_write(s, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); - zval_ptr_dtor(&tmp); - tmp = NULL; + php_stream_write(s, body_str->val, body_str->len); + zend_string_release(body_str); goto is_resource; } - body_obj = zend_object_store_get_object(zbody TSRMLS_CC); if (!body_obj->body) { - body_obj->body = php_http_message_body_init(NULL, NULL TSRMLS_CC); + body_obj->body = php_http_message_body_init(NULL, NULL); } if (msg_obj->body) { - zend_objects_store_del_ref_by_handle(msg_obj->body->zv.handle TSRMLS_CC); + zend_object_release(&msg_obj->body->zo); } if (msg_obj->message) { php_http_message_body_free(&msg_obj->message->body); - msg_obj->message->body = php_http_message_body_init(&body_obj->body, NULL TSRMLS_CC); + msg_obj->message->body = body_obj->body; } else { - msg_obj->message = php_http_message_init(NULL, 0, php_http_message_body_init(&body_obj->body, NULL TSRMLS_CC) TSRMLS_CC); + msg_obj->message = php_http_message_init(NULL, 0, body_obj->body); } + php_http_message_body_addref(body_obj->body); msg_obj->body = body_obj; - if (tmp) { - FREE_ZVAL(tmp); - } return SUCCESS; } ZEND_RESULT_CODE php_http_message_object_init_body_object(php_http_message_object_t *obj) { - TSRMLS_FETCH_FROM_CTX(obj->message->ts); - php_http_message_body_addref(obj->message->body); - return php_http_new(NULL, php_http_message_body_class_entry, (php_http_new_t) php_http_message_body_object_new_ex, NULL, obj->message->body, (void *) &obj->body TSRMLS_CC); + return php_http_new((void *) &obj->body, php_http_get_message_body_class_entry(), (php_http_new_t) php_http_message_body_object_new_ex, NULL, obj->message->body); } -zend_object_value php_http_message_object_new(zend_class_entry *ce TSRMLS_DC) +zend_object *php_http_message_object_new(zend_class_entry *ce) { - return php_http_message_object_new_ex(ce, NULL, NULL TSRMLS_CC); + return &php_http_message_object_new_ex(ce, NULL)->zo; } -zend_object_value php_http_message_object_new_ex(zend_class_entry *ce, php_http_message_t *msg, php_http_message_object_t **ptr TSRMLS_DC) +php_http_message_object_t *php_http_message_object_new_ex(zend_class_entry *ce, php_http_message_t *msg) { php_http_message_object_t *o; - o = ecalloc(1, sizeof(php_http_message_object_t)); - zend_object_std_init((zend_object *) o, ce TSRMLS_CC); - object_properties_init((zend_object *) o, ce); - - if (ptr) { - *ptr = o; - } + o = ecalloc(1, sizeof(*o) + zend_object_properties_size(ce)); + zend_object_std_init(&o->zo, ce); + object_properties_init(&o->zo, ce); if (msg) { o->message = msg; if (msg->parent) { - php_http_message_object_new_ex(ce, msg->parent, &o->parent TSRMLS_CC); + o->parent = php_http_message_object_new_ex(ce, msg->parent); } - php_http_message_body_object_new_ex(php_http_message_body_class_entry, php_http_message_body_init(&msg->body, NULL TSRMLS_CC), &o->body TSRMLS_CC); + o->body = php_http_message_body_object_new_ex(php_http_get_message_body_class_entry(), php_http_message_body_init(&msg->body, NULL)); } - o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_http_message_object_free, NULL TSRMLS_CC); - o->zv.handlers = &php_http_message_object_handlers; + o->zo.handlers = &php_http_message_object_handlers; - return o->zv; + return o; } -zend_object_value php_http_message_object_clone(zval *this_ptr TSRMLS_DC) +zend_object *php_http_message_object_clone(zval *this_ptr) { - zend_object_value new_ov; php_http_message_object_t *new_obj = NULL; - php_http_message_object_t *old_obj = zend_object_store_get_object(this_ptr TSRMLS_CC); + php_http_message_object_t *old_obj = PHP_HTTP_OBJ(NULL, this_ptr); - new_ov = php_http_message_object_new_ex(old_obj->zo.ce, php_http_message_copy(old_obj->message, NULL), &new_obj TSRMLS_CC); - zend_objects_clone_members(&new_obj->zo, new_ov, &old_obj->zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC); + new_obj = php_http_message_object_new_ex(old_obj->zo.ce, php_http_message_copy(old_obj->message, NULL)); + zend_objects_clone_members(&new_obj->zo, &old_obj->zo); - return new_ov; + return &new_obj->zo; } -void php_http_message_object_free(void *object TSRMLS_DC) +void php_http_message_object_free(zend_object *object) { - php_http_message_object_t *o = (php_http_message_object_t *) object; + php_http_message_object_t *o = PHP_HTTP_OBJ(object, NULL); - if (o->iterator) { + PTR_FREE(o->gc); + + if (!Z_ISUNDEF(o->iterator)) { zval_ptr_dtor(&o->iterator); - o->iterator = NULL; + ZVAL_UNDEF(&o->iterator); } if (o->message) { /* do NOT free recursivly */ @@@ -861,169 -896,148 +861,169 @@@ o->message = NULL; } if (o->parent) { - zend_objects_store_del_ref_by_handle(o->parent->zv.handle TSRMLS_CC); + zend_object_release(&o->parent->zo); o->parent = NULL; } if (o->body) { - zend_objects_store_del_ref_by_handle(o->body->zv.handle TSRMLS_CC); + zend_object_release(&o->body->zo); o->body = NULL; } - zend_object_std_dtor((zend_object *) o TSRMLS_CC); - efree(o); + zend_object_std_dtor(object); } -static zval *php_http_message_object_read_prop(zval *object, zval *member, int type PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC) +static zval *php_http_message_object_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *tmp) { - php_http_message_object_t *obj = zend_object_store_get_object(object TSRMLS_CC); - php_http_message_object_prophandler_t *handler; - zval *return_value, *copy = php_http_ztyp(IS_STRING, member); + zval *return_value; + zend_string *member_name = zval_get_string(member); + php_http_message_object_prophandler_t *handler = php_http_message_object_get_prophandler(member_name); - PHP_HTTP_MESSAGE_OBJECT_INIT(obj); + if (!handler || type == BP_VAR_R || type == BP_VAR_IS) { + return_value = zend_get_std_object_handlers()->read_property(object, member, type, cache_slot, tmp); - if (SUCCESS == php_http_message_object_get_prophandler(Z_STRVAL_P(copy), Z_STRLEN_P(copy), &handler)) { - ALLOC_ZVAL(return_value); - Z_SET_REFCOUNT_P(return_value, 0); - Z_UNSET_ISREF_P(return_value); + if (handler) { + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, object); - if (type == BP_VAR_R) { - handler->read(obj, return_value TSRMLS_CC); - } else { - php_property_proxy_t *proxy = php_property_proxy_init(object, Z_STRVAL_P(copy), Z_STRLEN_P(copy) TSRMLS_CC); - RETVAL_OBJVAL(php_property_proxy_object_new_ex(php_property_proxy_get_class_entry(), proxy, NULL TSRMLS_CC), 0); + PHP_HTTP_MESSAGE_OBJECT_INIT(obj); + handler->read(obj, tmp); + + zval_ptr_dtor(return_value); + ZVAL_COPY_VALUE(return_value, tmp); } + zend_string_release(member_name); + return return_value; } else { - return_value = zend_get_std_object_handlers()->read_property(object, member, type PHP_HTTP_ZEND_LITERAL_CC TSRMLS_CC); - } + php_property_proxy_t *proxy; + php_property_proxy_object_t *proxy_obj; - zval_ptr_dtor(©); + proxy = php_property_proxy_init(object, member_name); + proxy_obj = php_property_proxy_object_new_ex(NULL, proxy); - return return_value; + ZVAL_OBJ(tmp, &proxy_obj->zo); + zend_string_release(member_name); + return tmp; + } } -static void php_http_message_object_write_prop(zval *object, zval *member, zval *value PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC) +static void php_http_message_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot) { - php_http_message_object_t *obj = zend_object_store_get_object(object TSRMLS_CC); + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, object); php_http_message_object_prophandler_t *handler; - zval *copy = php_http_ztyp(IS_STRING, member); + zend_string *member_name = zval_get_string(member); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); - if (SUCCESS == php_http_message_object_get_prophandler(Z_STRVAL_P(copy), Z_STRLEN_P(copy), &handler)) { - handler->write(obj, value TSRMLS_CC); + if ((handler = php_http_message_object_get_prophandler(member_name))) { + handler->write(obj, value); } else { - zend_get_std_object_handlers()->write_property(object, member, value PHP_HTTP_ZEND_LITERAL_CC TSRMLS_CC); + zend_get_std_object_handlers()->write_property(object, member, value, cache_slot); } - zval_ptr_dtor(©); + zend_string_release(member_name); } -static HashTable *php_http_message_object_get_props(zval *object TSRMLS_DC) +static HashTable *php_http_message_object_get_debug_info(zval *object, int *is_temp) { - zval *headers; - php_http_message_object_t *obj = zend_object_store_get_object(object TSRMLS_CC); - HashTable *props = zend_get_std_object_handlers()->get_properties(object TSRMLS_CC); - zval array, *parent, *body; + zval tmp; + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, object); + HashTable *props = zend_get_std_object_handlers()->get_properties(object); char *ver_str, *url_str = NULL; size_t ver_len, url_len = 0; PHP_HTTP_MESSAGE_OBJECT_INIT(obj); - INIT_PZVAL_ARRAY(&array, props); + *is_temp = 0; -#define ASSOC_PROP(ptype, n, val) \ +#define UPDATE_PROP(name_str, action_with_tmp) \ do { \ zend_property_info *pi; \ - if (SUCCESS == zend_hash_find(&obj->zo.ce->properties_info, n, sizeof(n), (void *) &pi)) { \ - add_assoc_ ##ptype## _ex(&array, pi->name, pi->name_length + 1, val); \ - } \ - } while(0) \ - -#define ASSOC_STRING(name, val) ASSOC_STRINGL(name, val, strlen(val)) -#define ASSOC_STRINGL(name, val, len) ASSOC_STRINGL_EX(name, val, len, 1) -#define ASSOC_STRINGL_EX(n, val, len, cpy) \ - do { \ - zend_property_info *pi; \ - if (SUCCESS == zend_hash_find(&obj->zo.ce->properties_info, n, sizeof(n), (void *) &pi)) { \ - add_assoc_stringl_ex(&array, pi->name, pi->name_length + 1, val, len, cpy); \ + if ((pi = zend_hash_str_find_ptr(&obj->zo.ce->properties_info, name_str, lenof(name_str)))) { \ + action_with_tmp; \ + zend_hash_update_ind(props, pi->name, &tmp); \ } \ } while(0) - ASSOC_PROP(long, "type", obj->message->type); + UPDATE_PROP("type", ZVAL_LONG(&tmp, obj->message->type)); + ver_len = spprintf(&ver_str, 0, "%u.%u", obj->message->http.version.major, obj->message->http.version.minor); - ASSOC_STRINGL_EX("httpVersion", ver_str, ver_len, 0); + UPDATE_PROP("httpVersion", ZVAL_STR(&tmp, php_http_cs2zs(ver_str, ver_len))); switch (obj->message->type) { case PHP_HTTP_REQUEST: - ASSOC_PROP(long, "responseCode", 0); - ASSOC_STRINGL("responseStatus", "", 0); - ASSOC_STRING("requestMethod", STR_PTR(obj->message->http.info.request.method)); + UPDATE_PROP("responseCode", ZVAL_LONG(&tmp, 0)); + UPDATE_PROP("responseStatus", ZVAL_EMPTY_STRING(&tmp)); + UPDATE_PROP("requestMethod", ZVAL_STRING(&tmp, STR_PTR(obj->message->http.info.request.method))); if (obj->message->http.info.request.url) { php_http_url_to_string(obj->message->http.info.request.url, &url_str, &url_len, 0); - ASSOC_STRINGL_EX("requestUrl", url_str, url_len, 0); + UPDATE_PROP("requestUrl", ZVAL_STR(&tmp, php_http_cs2zs(url_str, url_len))); } else { - ASSOC_STRINGL("requestUrl", "", 0); + UPDATE_PROP("requestUrl", ZVAL_EMPTY_STRING(&tmp)); } break; case PHP_HTTP_RESPONSE: - ASSOC_PROP(long, "responseCode", obj->message->http.info.response.code); - ASSOC_STRING("responseStatus", STR_PTR(obj->message->http.info.response.status)); - ASSOC_STRINGL("requestMethod", "", 0); - ASSOC_STRINGL("requestUrl", "", 0); + UPDATE_PROP("responseCode", ZVAL_LONG(&tmp, obj->message->http.info.response.code)); + UPDATE_PROP("responseStatus", ZVAL_STRING(&tmp, STR_PTR(obj->message->http.info.response.status))); + UPDATE_PROP("requestMethod", ZVAL_EMPTY_STRING(&tmp)); + UPDATE_PROP("requestUrl", ZVAL_EMPTY_STRING(&tmp)); break; case PHP_HTTP_NONE: default: - ASSOC_PROP(long, "responseCode", 0); - ASSOC_STRINGL("responseStatus", "", 0); - ASSOC_STRINGL("requestMethod", "", 0); - ASSOC_STRINGL("requestUrl", "", 0); + UPDATE_PROP("responseCode", ZVAL_LONG(&tmp, 0)); + UPDATE_PROP("responseStatus", ZVAL_EMPTY_STRING(&tmp)); + UPDATE_PROP("requestMethod", ZVAL_EMPTY_STRING(&tmp)); + UPDATE_PROP("requestUrl", ZVAL_EMPTY_STRING(&tmp)); break; } - MAKE_STD_ZVAL(headers); - array_init(headers); - zend_hash_copy(Z_ARRVAL_P(headers), &obj->message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); - ASSOC_PROP(zval, "headers", headers); + UPDATE_PROP("headers", + array_init(&tmp); + array_copy(&obj->message->hdrs, Z_ARRVAL(tmp)); + ); + + UPDATE_PROP("body", + if (obj->body) { + ZVAL_OBJECT(&tmp, &obj->body->zo, 1); + } else { + ZVAL_NULL(&tmp); + } + ); + + UPDATE_PROP("parentMessage", + if (obj->message->parent) { + ZVAL_OBJECT(&tmp, &obj->parent->zo, 1); + } else { + ZVAL_NULL(&tmp); + } + ); + + return props; +} + +static HashTable *php_http_message_object_get_gc(zval *object, zval **table, int *n) +{ + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, object); + HashTable *props = Z_OBJPROP_P(object); + uint32_t count = 2 + zend_hash_num_elements(props); + zval *val; + + *n = 0; + *table = obj->gc = erealloc(obj->gc, count * sizeof(zval)); - MAKE_STD_ZVAL(body); if (obj->body) { - ZVAL_OBJVAL(body, obj->body->zv, 1); - } else { - ZVAL_NULL(body); + ZVAL_OBJ(&obj->gc[(*n)++], &obj->body->zo); + } + if (obj->parent) { + ZVAL_OBJ(&obj->gc[(*n)++], &obj->parent->zo); } - ASSOC_PROP(zval, "body", body); - MAKE_STD_ZVAL(parent); - if (obj->message->parent) { - ZVAL_OBJVAL(parent, obj->parent->zv, 1); - } else { - ZVAL_NULL(parent); + ZEND_HASH_FOREACH_VAL(props, val) + { + ZVAL_COPY_VALUE(&obj->gc[(*n)++], val); } - ASSOC_PROP(zval, "parentMessage", parent); + ZEND_HASH_FOREACH_END(); - return props; + return NULL; } ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage___construct, 0, 0, 0) @@@ -1035,22 -1049,22 +1035,22 @@@ static PHP_METHOD(HttpMessage, __constr zend_bool greedy = 1; zval *zmessage = NULL; php_http_message_t *msg = NULL; - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); zend_error_handling zeh; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!b", &zmessage, &greedy), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z!b", &zmessage, &greedy), invalid_arg, return); - zend_replace_error_handling(EH_THROW, php_http_exception_bad_message_class_entry, &zeh TSRMLS_CC); + zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_message_class_entry(), &zeh); if (zmessage && Z_TYPE_P(zmessage) == IS_RESOURCE) { php_stream *s; php_http_message_parser_t p; zend_error_handling zeh; - zend_replace_error_handling(EH_THROW, php_http_exception_unexpected_val_class_entry, &zeh TSRMLS_CC); - php_stream_from_zval(s, &zmessage); - zend_restore_error_handling(&zeh TSRMLS_CC); + zend_replace_error_handling(EH_THROW, php_http_get_exception_unexpected_val_class_entry(), &zeh); + php_stream_from_zval(s, zmessage); + zend_restore_error_handling(&zeh); - if (s && php_http_message_parser_init(&p TSRMLS_CC)) { + if (s && php_http_message_parser_init(&p)) { unsigned flags = (greedy ? PHP_HTTP_MESSAGE_PARSER_GREEDY : 0); php_http_buffer_t buf; @@@ -1068,24 -1082,23 +1068,24 @@@ php_http_throw(bad_message, "Empty message received from stream", NULL); } } else if (zmessage) { - zmessage = php_http_ztyp(IS_STRING, zmessage); - msg = php_http_message_parse(NULL, Z_STRVAL_P(zmessage), Z_STRLEN_P(zmessage), greedy TSRMLS_CC); + zend_string *zs_msg = zval_get_string(zmessage); + + msg = php_http_message_parse(NULL, zs_msg->val, zs_msg->len, greedy); if (!msg && !EG(exception)) { - php_http_throw(bad_message, "Could not parse message: %.*s", MIN(25, Z_STRLEN_P(zmessage)), Z_STRVAL_P(zmessage)); + php_http_throw(bad_message, "Could not parse message: %.*s", MIN(25, zs_msg->len), zs_msg->val); } - zval_ptr_dtor(&zmessage); + zend_string_release(zs_msg); } if (msg) { php_http_message_dtor(obj->message); obj->message = msg; if (obj->message->parent) { - php_http_message_object_new_ex(Z_OBJCE_P(getThis()), obj->message->parent, &obj->parent TSRMLS_CC); + obj->parent = php_http_message_object_new_ex(obj->zo.ce, obj->message->parent); } } - zend_restore_error_handling(&zeh TSRMLS_CC); + zend_restore_error_handling(&zeh); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); } @@@ -1097,7 -1110,8 +1097,7 @@@ static PHP_METHOD(HttpMessage, getBody php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return); - obj = zend_object_store_get_object(getThis() TSRMLS_CC); - + obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); if (!obj->body) { @@@ -1105,7 -1119,7 +1105,7 @@@ } if (obj->body) { - RETVAL_OBJVAL(obj->body->zv, 1); + RETVAL_OBJECT(&obj->body->zo, 1); } } @@@ -1116,11 -1130,11 +1116,11 @@@ static PHP_METHOD(HttpMessage, setBody { zval *zbody; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zbody, php_http_message_body_class_entry)) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zbody, php_http_get_message_body_class_entry())) { + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); - php_http_message_object_prophandler_set_body(obj, zbody TSRMLS_CC); + php_http_message_object_prophandler_set_body(obj, zbody); } RETVAL_ZVAL(getThis(), 1, 0); } @@@ -1132,9 -1146,9 +1132,9 @@@ static PHP_METHOD(HttpMessage, addBody { zval *new_body; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &new_body, php_http_message_body_class_entry)) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); - php_http_message_body_object_t *new_obj = zend_object_store_get_object(new_body TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &new_body, php_http_get_message_body_class_entry())) { + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); + php_http_message_body_object_t *new_obj = PHP_HTTP_OBJ(NULL, new_body); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); php_http_message_body_to_callback(new_obj->body, (php_http_pass_callback_t) php_http_message_body_append, obj->message->body, 0, 0); @@@ -1149,36 -1163,39 +1149,36 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpMessage, getHeader) { char *header_str; - int header_len; + size_t header_len; zend_class_entry *header_ce = NULL; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|C!", &header_str, &header_len, &header_ce)) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s|C!", &header_str, &header_len, &header_ce)) { + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); zval *header; PHP_HTTP_MESSAGE_OBJECT_INIT(obj); - if ((header = php_http_message_header(obj->message, header_str, header_len, 0))) { + if ((header = php_http_message_header(obj->message, header_str, header_len))) { if (!header_ce) { - RETURN_ZVAL(header, 1, 1); - } else if (instanceof_function(header_ce, php_http_header_class_entry TSRMLS_CC)) { + RETURN_ZVAL(header, 1, 0); + } else if (instanceof_function(header_ce, php_http_header_get_class_entry())) { php_http_object_method_t cb; - zval *header_name, **argv[2]; - - MAKE_STD_ZVAL(header_name); - ZVAL_STRINGL(header_name, header_str, header_len, 1); + zval argv[2]; - argv[0] = &header_name; - argv[1] = &header; + ZVAL_STRINGL(&argv[0], header_str, header_len); + ZVAL_COPY(&argv[1], header); object_init_ex(return_value, header_ce); - php_http_object_method_init(&cb, return_value, ZEND_STRL("__construct") TSRMLS_CC); - php_http_object_method_call(&cb, return_value, NULL, 2, argv TSRMLS_CC); + php_http_object_method_init(&cb, return_value, ZEND_STRL("__construct")); + php_http_object_method_call(&cb, return_value, NULL, 2, argv); php_http_object_method_dtor(&cb); - zval_ptr_dtor(&header_name); - zval_ptr_dtor(&header); + zval_ptr_dtor(&argv[0]); + zval_ptr_dtor(&argv[1]); return; } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Class '%s' is not as descendant of http\\Header", header_ce->name); + php_error_docref(NULL, E_WARNING, "Class '%s' is not as descendant of http\\Header", header_ce->name->val); } } } @@@ -1190,7 -1207,7 +1190,7 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpMessage, getHeaders) { if (SUCCESS == zend_parse_parameters_none()) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); @@@ -1207,19 -1224,19 +1207,19 @@@ static PHP_METHOD(HttpMessage, setHeade { zval *zvalue = NULL; char *name_str; - int name_len; + size_t name_len; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z!", &name_str, &name_len, &zvalue)) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s|z!", &name_str, &name_len, &zvalue)) { + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); char *name = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); if (!zvalue) { - zend_symtable_del(&obj->message->hdrs, name, name_len + 1); + zend_symtable_str_del(&obj->message->hdrs, name, name_len); } else { - Z_ADDREF_P(zvalue); - zend_symtable_update(&obj->message->hdrs, name, name_len + 1, &zvalue, sizeof(void *), NULL); + Z_TRY_ADDREF_P(zvalue); + zend_symtable_str_update(&obj->message->hdrs, name, name_len, zvalue); } efree(name); } @@@ -1233,8 -1250,8 +1233,8 @@@ static PHP_METHOD(HttpMessage, setHeade { zval *new_headers = NULL; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/!", &new_headers)) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "a/!", &new_headers)) { + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); @@@ -1246,34 -1263,34 +1246,34 @@@ RETVAL_ZVAL(getThis(), 1, 0); } -static inline void php_http_message_object_add_header(php_http_message_object_t *obj, const char *name_str, size_t name_len, zval *zvalue TSRMLS_DC) +static inline void php_http_message_object_add_header(php_http_message_object_t *obj, const char *name_str, size_t name_len, zval *zvalue) { char *name = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1); - zval *header, *cpy; + zend_string *hstr, *vstr; + zval *header, tmp; if (Z_TYPE_P(zvalue) == IS_NULL) { return; } - cpy = php_http_header_value_to_string(zvalue TSRMLS_CC); + vstr = php_http_header_value_to_string(zvalue); if ((name_len != lenof("Set-Cookie") && strcmp(name, "Set-Cookie")) - && (header = php_http_message_header(obj->message, name, name_len, 1))) { - zval *tmp; + && (hstr = php_http_message_header_string(obj->message, name, name_len))) { char *hdr_str; - size_t hdr_len = spprintf(&hdr_str, 0, "%s, %s", Z_STRVAL_P(header), Z_STRVAL_P(cpy)); - - MAKE_STD_ZVAL(tmp); - ZVAL_STRINGL(tmp, hdr_str, hdr_len, 0); - zend_symtable_update(&obj->message->hdrs, name, name_len + 1, &tmp, sizeof(void *), NULL); - zval_ptr_dtor(&header); - zval_ptr_dtor(&cpy); - } else if ((header = php_http_message_header(obj->message, name, name_len, 0))) { + size_t hdr_len = spprintf(&hdr_str, 0, "%s, %s", hstr->val, vstr->val); + + ZVAL_STR(&tmp, php_http_cs2zs(hdr_str, hdr_len)); + zend_symtable_str_update(&obj->message->hdrs, name, name_len, &tmp); + zend_string_release(hstr); + zend_string_release(vstr); + } else if ((header = php_http_message_header(obj->message, name, name_len))) { convert_to_array(header); - zend_hash_next_index_insert(Z_ARRVAL_P(header), &cpy, sizeof(void *), NULL); - zval_ptr_dtor(&header); + ZVAL_STR(&tmp, vstr); + zend_hash_next_index_insert(Z_ARRVAL_P(header), &tmp); } else { - zend_symtable_update(&obj->message->hdrs, name, name_len + 1, &cpy, sizeof(void *), NULL); + ZVAL_STR(&tmp, vstr); + zend_symtable_str_update(&obj->message->hdrs, name, name_len, &tmp); } efree(name); } @@@ -1286,14 -1303,14 +1286,14 @@@ static PHP_METHOD(HttpMessage, addHeade { zval *zvalue; char *name_str; - int name_len; + size_t name_len; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name_str, &name_len, &zvalue)) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &name_str, &name_len, &zvalue)) { + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); - php_http_message_object_add_header(obj, name_str, name_len, zvalue TSRMLS_CC); + php_http_message_object_add_header(obj, name_str, name_len, zvalue); } RETVAL_ZVAL(getThis(), 1, 0); } @@@ -1307,22 -1324,21 +1307,22 @@@ static PHP_METHOD(HttpMessage, addHeade zval *new_headers; zend_bool append = 0; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|b", &new_headers, &append)) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "a|b", &new_headers, &append)) { + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); if (append) { - HashPosition pos; - php_http_array_hashkey_t key = php_http_array_hashkey_init(0); - zval **val; - - FOREACH_KEYVAL(pos, new_headers, key, val) { - php_http_array_hashkey_stringify(&key); - php_http_message_object_add_header(obj, key.str, key.len-1, *val TSRMLS_CC); - php_http_array_hashkey_stringfree(&key); + php_http_arrkey_t key = {0}; + zval *val; + + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(new_headers), key.h, key.key, val) + { + php_http_arrkey_stringify(&key, NULL); + php_http_message_object_add_header(obj, key.key->val, key.key->len, val); + php_http_arrkey_dtor(&key); } + ZEND_HASH_FOREACH_END(); } else { array_join(Z_ARRVAL_P(new_headers), &obj->message->hdrs, 0, ARRAY_JOIN_PRETTIFY|ARRAY_JOIN_STRONLY); } @@@ -1335,7 -1351,7 +1335,7 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpMessage, getType) { if (SUCCESS == zend_parse_parameters_none()) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); @@@ -1348,10 -1364,10 +1348,10 @@@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_s ZEND_END_ARG_INFO(); static PHP_METHOD(HttpMessage, setType) { - long type; + zend_long type; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &type)) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "l", &type)) { + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); @@@ -1365,14 -1381,15 +1365,14 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpMessage, getInfo) { if (SUCCESS == zend_parse_parameters_none()) { + char *str = NULL; size_t len = 0; - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); + php_http_info_to_string((php_http_info_t *) obj->message, &str, &len, ""); - php_http_info_to_string((php_http_info_t *) obj->message, &Z_STRVAL_P(return_value), &len, "" TSRMLS_CC); - Z_STRLEN_P(return_value) = len; - Z_TYPE_P(return_value) = IS_STRING; - return; + RETVAL_STR(php_http_cs2zs(str, len)); } } @@@ -1382,16 -1399,16 +1382,16 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpMessage, setInfo) { char *str; - int len; + size_t len; php_http_message_object_t *obj; php_http_info_t inf; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str, &len), invalid_arg, return); - obj = zend_object_store_get_object(getThis() TSRMLS_CC); + obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); - if (!php_http_info_parse(&inf, str TSRMLS_CC)) { + if (!php_http_info_parse(&inf, str)) { php_http_throw(bad_header, "Could not parse message info '%s'", str); return; } @@@ -1409,12 -1426,12 +1409,12 @@@ static PHP_METHOD(HttpMessage, getHttpV if (SUCCESS == zend_parse_parameters_none()) { char *str; size_t len; - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); - php_http_version_to_string(&obj->message->http.version, &str, &len, NULL, NULL TSRMLS_CC); - RETURN_STRINGL(str, len, 0); + php_http_version_to_string(&obj->message->http.version, &str, &len, NULL, NULL); + RETURN_STR(php_http_cs2zs(str, len)); } } @@@ -1424,16 -1441,16 +1424,16 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpMessage, setHttpVersion) { char *v_str; - int v_len; + size_t v_len; php_http_version_t version; php_http_message_object_t *obj; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &v_str, &v_len), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &v_str, &v_len), invalid_arg, return); - obj = zend_object_store_get_object(getThis() TSRMLS_CC); + obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); - php_http_expect(php_http_version_parse(&version, v_str TSRMLS_CC), unexpected_val, return); + php_http_expect(php_http_version_parse(&version, v_str), unexpected_val, return); obj->message->http.version = version; @@@ -1445,12 -1462,12 +1445,12 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpMessage, getResponseCode) { if (SUCCESS == zend_parse_parameters_none()) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); if (obj->message->type != PHP_HTTP_RESPONSE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "http\\Message is not if type response"); + php_error_docref(NULL, E_WARNING, "http\\Message is not if type response"); RETURN_FALSE; } @@@ -1464,13 -1481,14 +1464,13 @@@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_s ZEND_END_ARG_INFO(); static PHP_METHOD(HttpMessage, setResponseCode) { - long code; + zend_long code; zend_bool strict = 1; php_http_message_object_t *obj; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|b", &code, &strict), invalid_arg, return); - - obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "l|b", &code, &strict), invalid_arg, return); + obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); if (obj->message->type != PHP_HTTP_RESPONSE) { @@@ -1494,16 -1512,16 +1494,16 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpMessage, getResponseStatus) { if (SUCCESS == zend_parse_parameters_none()) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); if (obj->message->type != PHP_HTTP_RESPONSE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "http\\Message is not of type response"); + php_error_docref(NULL, E_WARNING, "http\\Message is not of type response"); } if (obj->message->http.info.response.status) { - RETURN_STRING(obj->message->http.info.response.status, 1); + RETURN_STRING(obj->message->http.info.response.status); } else { RETURN_EMPTY_STRING(); } @@@ -1516,12 -1534,12 +1516,12 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpMessage, setResponseStatus) { char *status; - int status_len; + size_t status_len; php_http_message_object_t *obj; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &status, &status_len), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &status, &status_len), invalid_arg, return); - obj = zend_object_store_get_object(getThis() TSRMLS_CC); + obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); @@@ -1538,17 -1556,17 +1538,17 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpMessage, getRequestMethod) { if (SUCCESS == zend_parse_parameters_none()) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); if (obj->message->type != PHP_HTTP_REQUEST) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "http\\Message is not of type request"); + php_error_docref(NULL, E_WARNING, "http\\Message is not of type request"); RETURN_FALSE; } if (obj->message->http.info.request.method) { - RETURN_STRING(obj->message->http.info.request.method, 1); + RETURN_STRING(obj->message->http.info.request.method); } else { RETURN_EMPTY_STRING(); } @@@ -1561,12 -1579,12 +1561,12 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpMessage, setRequestMethod) { char *method; - int method_len; + size_t method_len; php_http_message_object_t *obj; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &method, &method_len), invalid_arg, return); - obj = zend_object_store_get_object(getThis() TSRMLS_CC); + obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); @@@ -1589,12 -1607,12 +1589,12 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpMessage, getRequestUrl) { if (SUCCESS == zend_parse_parameters_none()) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); if (obj->message->type != PHP_HTTP_REQUEST) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "http\\Message is not of type request"); + php_error_docref(NULL, E_WARNING, "http\\Message is not of type request"); RETURN_FALSE; } @@@ -1603,7 -1621,7 +1603,7 @@@ size_t url_len; php_http_url_to_string(obj->message->http.info.request.url, &url_str, &url_len, 0); - RETURN_STRINGL(url_str, url_len, 0); + RETURN_STR(php_http_cs2zs(url_str, url_len)); } else { RETURN_EMPTY_STRING(); } @@@ -1620,9 -1638,9 +1620,9 @@@ static PHP_METHOD(HttpMessage, setReque php_http_message_object_t *obj; zend_error_handling zeh; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zurl), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zurl), invalid_arg, return); - obj = zend_object_store_get_object(getThis() TSRMLS_CC); + obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); @@@ -1631,9 -1649,9 +1631,9 @@@ return; } - zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC); - url = php_http_url_from_zval(zurl, PHP_HTTP_URL_STDFLAGS TSRMLS_CC); - zend_restore_error_handling(&zeh TSRMLS_CC); + zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_url_class_entry(), &zeh); + url = php_http_url_from_zval(zurl, PHP_HTTP_URL_STDFLAGS); + zend_restore_error_handling(&zeh); if (url && php_http_url_is_empty(url)) { php_http_url_free(&url); @@@ -1653,7 -1671,8 +1653,7 @@@ static PHP_METHOD(HttpMessage, getParen php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return); - obj = zend_object_store_get_object(getThis() TSRMLS_CC); - + obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); if (!obj->message->parent) { @@@ -1661,7 -1680,7 +1661,7 @@@ return; } - RETVAL_OBJVAL(obj->parent->zv, 1); + RETVAL_OBJECT(&obj->parent->zo, 1); } ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage___toString, 0, 0, 0) @@@ -1673,8 -1692,8 +1673,8 @@@ static PHP_METHOD(HttpMessage, toString { zend_bool include_parent = 0; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &include_parent)) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &include_parent)) { + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); char *string; size_t length; @@@ -1686,12 -1705,22 +1686,12 @@@ php_http_message_to_string(obj->message, &string, &length); } if (string) { - RETURN_STRINGL(string, length, 0); + RETURN_STR(php_http_cs2zs(string, length)); } } RETURN_EMPTY_STRING(); } -#ifdef ZTS -static size_t write_to_stream(void *s, const char *str, size_t len) -{ - TSRMLS_FETCH(); - return php_stream_write(s, str, len); -} -#else -# define write_to_stream (php_http_pass_callback_t)_php_stream_write -#endif - ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toStream, 0, 0, 1) ZEND_ARG_INFO(0, stream) ZEND_END_ARG_INFO(); @@@ -1699,14 -1728,14 +1699,14 @@@ static PHP_METHOD(HttpMessage, toStream { zval *zstream; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream)) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zstream)) { + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); php_stream *s; PHP_HTTP_MESSAGE_OBJECT_INIT(obj); - php_stream_from_zval(s, &zstream); - php_http_message_to_callback(obj->message, write_to_stream, s); + php_stream_from_zval(s, zstream); + php_http_message_to_callback(obj->message, (php_http_pass_callback_t) _php_stream_write, s); } } @@@ -1717,17 -1746,20 +1717,17 @@@ static PHP_METHOD(HttpMessage, toCallba { php_http_pass_fcall_arg_t fcd; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f", &fcd.fci, &fcd.fcc)) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "f", &fcd.fci, &fcd.fcc)) { + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); - fcd.fcz = getThis(); - Z_ADDREF_P(fcd.fcz); - TSRMLS_SET_CTX(fcd.ts); - + ZVAL_COPY(&fcd.fcz, getThis()); php_http_message_to_callback(obj->message, php_http_pass_fcall_callback, &fcd); zend_fcall_info_args_clear(&fcd.fci, 1); - zval_ptr_dtor(&fcd.fcz); - RETURN_ZVAL(getThis(), 1, 0); + + RETURN_ZVAL(&fcd.fcz, 1, 0); } } @@@ -1736,14 -1768,14 +1736,14 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpMessage, serialize) { if (SUCCESS == zend_parse_parameters_none()) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); char *string; size_t length; PHP_HTTP_MESSAGE_OBJECT_INIT(obj); php_http_message_serialize(obj->message, &string, &length); - RETURN_STRINGL(string, length, 0); + RETURN_STR(php_http_cs2zs(string, length)); } RETURN_EMPTY_STRING(); } @@@ -1753,23 -1785,22 +1753,23 @@@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_u ZEND_END_ARG_INFO(); static PHP_METHOD(HttpMessage, unserialize) { - int length; + size_t length; char *serialized; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &serialized, &length)) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &length)) { + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); php_http_message_t *msg; if (obj->message) { + /* do not free recursively */ php_http_message_dtor(obj->message); efree(obj->message); } - if ((msg = php_http_message_parse(NULL, serialized, (size_t) length, 1 TSRMLS_CC))) { + if ((msg = php_http_message_parse(NULL, serialized, length, 1))) { obj->message = msg; } else { - obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC); - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not unserialize http\\Message"); + obj->message = php_http_message_init(NULL, 0, NULL); + php_error_docref(NULL, E_ERROR, "Could not unserialize http\\Message"); } } } @@@ -1778,18 -1809,15 +1778,18 @@@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_d ZEND_END_ARG_INFO(); static PHP_METHOD(HttpMessage, detach) { - php_http_message_object_t *obj; + php_http_message_object_t *obj, *new_obj; + php_http_message_t *msg_cpy; php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return); - obj = zend_object_store_get_object(getThis() TSRMLS_CC); - + obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); - RETVAL_OBJVAL(php_http_message_object_new_ex(obj->zo.ce, php_http_message_copy_ex(obj->message, NULL, 0), NULL TSRMLS_CC), 0); + msg_cpy = php_http_message_copy_ex(obj->message, NULL, 0); + new_obj = php_http_message_object_new_ex(obj->zo.ce, msg_cpy); + + RETVAL_OBJ(&new_obj->zo); } ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_prepend, 0, 0, 1) @@@ -1803,11 -1831,11 +1803,11 @@@ static PHP_METHOD(HttpMessage, prepend php_http_message_t *msg[2]; php_http_message_object_t *obj, *prepend_obj; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|b", &prepend, php_http_message_class_entry, &top), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O|b", &prepend, php_http_message_class_entry, &top), invalid_arg, return); - obj = zend_object_store_get_object(getThis() TSRMLS_CC); + obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); - prepend_obj = zend_object_store_get_object(prepend TSRMLS_CC); + prepend_obj = PHP_HTTP_OBJ(NULL, prepend); PHP_HTTP_MESSAGE_OBJECT_INIT(prepend_obj); /* safety check */ @@@ -1820,7 -1848,7 +1820,7 @@@ } } - php_http_message_object_prepend(getThis(), prepend, top TSRMLS_CC); + php_http_message_object_prepend(getThis(), prepend, top); RETURN_ZVAL(getThis(), 1, 0); } @@@ -1830,7 -1858,7 +1830,7 @@@ static PHP_METHOD(HttpMessage, reverse { php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return); - php_http_message_object_reverse(getThis(), return_value TSRMLS_CC); + php_http_message_object_reverse(getThis(), return_value); } ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_isMultipart, 0, 0, 0) @@@ -1840,22 -1868,17 +1840,22 @@@ static PHP_METHOD(HttpMessage, isMultip { zval *zboundary = NULL; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &zboundary)) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z!", &zboundary)) { + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); char *boundary = NULL; PHP_HTTP_MESSAGE_OBJECT_INIT(obj); - RETVAL_BOOL(php_http_message_is_multipart(obj->message, zboundary ? &boundary : NULL)); + if (php_http_message_is_multipart(obj->message, zboundary ? &boundary : NULL)) { + RETVAL_TRUE; + } else { + RETVAL_FALSE; + } if (zboundary && boundary) { + ZVAL_DEREF(zboundary); zval_dtor(zboundary); - ZVAL_STRING(zboundary, boundary, 0); + ZVAL_STR(zboundary, php_http_cs2zs(boundary, strlen(boundary))); } } } @@@ -1870,7 -1893,8 +1870,7 @@@ static PHP_METHOD(HttpMessage, splitMul php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return); - obj = zend_object_store_get_object(getThis() TSRMLS_CC); - + obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); if (!php_http_message_is_multipart(obj->message, &boundary)) { @@@ -1882,21 -1906,23 +1882,21 @@@ PTR_FREE(boundary); - RETURN_OBJVAL(php_http_message_object_new_ex(php_http_message_class_entry, msg, NULL TSRMLS_CC), 0); + RETURN_OBJ(&php_http_message_object_new_ex(obj->zo.ce, msg)->zo); } ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_count, 0, 0, 0) ZEND_END_ARG_INFO(); static PHP_METHOD(HttpMessage, count) { - long count_mode = -1; + zend_long count_mode = -1; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &count_mode)) { - long i = 0; - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &count_mode)) { + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); - php_http_message_count(i, obj->message); - RETURN_LONG(i); + RETURN_LONG(php_http_message_count(obj->message)); } } @@@ -1906,12 -1932,13 +1906,12 @@@ static PHP_METHOD(HttpMessage, rewind { if (SUCCESS == zend_parse_parameters_none()) { zval *zobj = getThis(); - php_http_message_object_t *obj = zend_object_store_get_object(zobj TSRMLS_CC); + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); - if (obj->iterator) { + if (!Z_ISUNDEF(obj->iterator)) { zval_ptr_dtor(&obj->iterator); } - Z_ADDREF_P(zobj); - obj->iterator = zobj; + ZVAL_COPY(&obj->iterator, zobj); } } @@@ -1920,9 -1947,9 +1920,9 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpMessage, valid) { if (SUCCESS == zend_parse_parameters_none()) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); - RETURN_BOOL(obj->iterator != NULL); + RETURN_BOOL(!Z_ISUNDEF(obj->iterator)); } } @@@ -1931,20 -1958,19 +1931,20 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpMessage, next) { if (SUCCESS == zend_parse_parameters_none()) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); + + if (!Z_ISUNDEF(obj->iterator)) { + php_http_message_object_t *itr = PHP_HTTP_OBJ(NULL, &obj->iterator); - if (obj->iterator) { - php_http_message_object_t *itr = zend_object_store_get_object(obj->iterator TSRMLS_CC); + if (itr->parent) { + zval tmp; - if (itr && itr->parent) { - zval *old = obj->iterator; - MAKE_STD_ZVAL(obj->iterator); - ZVAL_OBJVAL(obj->iterator, itr->parent->zv, 1); - zval_ptr_dtor(&old); + ZVAL_OBJECT(&tmp, &itr->parent->zo, 1); + zval_ptr_dtor(&obj->iterator); + obj->iterator = tmp; } else { zval_ptr_dtor(&obj->iterator); - obj->iterator = NULL; + ZVAL_UNDEF(&obj->iterator); } } } @@@ -1955,9 -1981,9 +1955,9 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpMessage, key) { if (SUCCESS == zend_parse_parameters_none()) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); - RETURN_LONG(obj->iterator ? obj->iterator->value.obj.handle:0); + RETURN_LONG(Z_ISUNDEF(obj->iterator) ? 0 : Z_OBJ_HANDLE(obj->iterator)); } } @@@ -1966,10 -1992,10 +1966,10 @@@ ZEND_END_ARG_INFO() static PHP_METHOD(HttpMessage, current) { if (SUCCESS == zend_parse_parameters_none()) { - php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); - if (obj->iterator) { - RETURN_ZVAL(obj->iterator, 1, 0); + if (!Z_ISUNDEF(obj->iterator)) { + RETURN_ZVAL(&obj->iterator, 1, 0); } } } @@@ -2030,48 -2056,47 +2030,48 @@@ static zend_function_entry php_http_mes EMPTY_FUNCTION_ENTRY }; -zend_class_entry *php_http_message_class_entry; - PHP_MINIT_FUNCTION(http_message) { zend_class_entry ce = {0}; INIT_NS_CLASS_ENTRY(ce, "http", "Message", php_http_message_methods); - php_http_message_class_entry = zend_register_internal_class(&ce TSRMLS_CC); + php_http_message_class_entry = zend_register_internal_class(&ce); php_http_message_class_entry->create_object = php_http_message_object_new; memcpy(&php_http_message_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); + php_http_message_object_handlers.offset = XtOffsetOf(php_http_message_object_t, zo); php_http_message_object_handlers.clone_obj = php_http_message_object_clone; + php_http_message_object_handlers.free_obj = php_http_message_object_free; php_http_message_object_handlers.read_property = php_http_message_object_read_prop; php_http_message_object_handlers.write_property = php_http_message_object_write_prop; - php_http_message_object_handlers.get_properties = php_http_message_object_get_props; + php_http_message_object_handlers.get_debug_info = php_http_message_object_get_debug_info; php_http_message_object_handlers.get_property_ptr_ptr = NULL; + php_http_message_object_handlers.get_gc = php_http_message_object_get_gc; - zend_class_implements(php_http_message_class_entry TSRMLS_CC, 3, spl_ce_Countable, zend_ce_serializable, zend_ce_iterator); + zend_class_implements(php_http_message_class_entry, 3, spl_ce_Countable, zend_ce_serializable, zend_ce_iterator); - zend_hash_init(&php_http_message_object_prophandlers, 9, NULL, NULL, 1); - zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("type"), PHP_HTTP_NONE, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_hash_init(&php_http_message_object_prophandlers, 9, NULL, php_http_message_object_prophandler_hash_dtor, 1); + zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("type"), PHP_HTTP_NONE, ZEND_ACC_PROTECTED); php_http_message_object_add_prophandler(ZEND_STRL("type"), php_http_message_object_prophandler_get_type, php_http_message_object_prophandler_set_type); - zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("body"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("body"), ZEND_ACC_PROTECTED); php_http_message_object_add_prophandler(ZEND_STRL("body"), php_http_message_object_prophandler_get_body, php_http_message_object_prophandler_set_body); - zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("requestMethod"), "", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("requestMethod"), "", ZEND_ACC_PROTECTED); php_http_message_object_add_prophandler(ZEND_STRL("requestMethod"), php_http_message_object_prophandler_get_request_method, php_http_message_object_prophandler_set_request_method); - zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("requestUrl"), "", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("requestUrl"), "", ZEND_ACC_PROTECTED); php_http_message_object_add_prophandler(ZEND_STRL("requestUrl"), php_http_message_object_prophandler_get_request_url, php_http_message_object_prophandler_set_request_url); - zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("responseStatus"), "", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("responseStatus"), "", ZEND_ACC_PROTECTED); php_http_message_object_add_prophandler(ZEND_STRL("responseStatus"), php_http_message_object_prophandler_get_response_status, php_http_message_object_prophandler_set_response_status); - zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("responseCode"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("responseCode"), 0, ZEND_ACC_PROTECTED); php_http_message_object_add_prophandler(ZEND_STRL("responseCode"), php_http_message_object_prophandler_get_response_code, php_http_message_object_prophandler_set_response_code); - zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("httpVersion"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("httpVersion"), ZEND_ACC_PROTECTED); php_http_message_object_add_prophandler(ZEND_STRL("httpVersion"), php_http_message_object_prophandler_get_http_version, php_http_message_object_prophandler_set_http_version); - zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("headers"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("headers"), ZEND_ACC_PROTECTED); php_http_message_object_add_prophandler(ZEND_STRL("headers"), php_http_message_object_prophandler_get_headers, php_http_message_object_prophandler_set_headers); - zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("parentMessage"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("parentMessage"), ZEND_ACC_PROTECTED); php_http_message_object_add_prophandler(ZEND_STRL("parentMessage"), php_http_message_object_prophandler_get_parent_message, php_http_message_object_prophandler_set_parent_message); - zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_NONE"), PHP_HTTP_NONE TSRMLS_CC); - zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_REQUEST"), PHP_HTTP_REQUEST TSRMLS_CC); - zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_RESPONSE"), PHP_HTTP_RESPONSE TSRMLS_CC); + zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_NONE"), PHP_HTTP_NONE); + zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_REQUEST"), PHP_HTTP_REQUEST); + zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_RESPONSE"), PHP_HTTP_RESPONSE); return SUCCESS; }