#ifdef ZTS
# include "TSRM/TSRM.h"
-# define PHP_HTTP_G ((php_http_globals *) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(php_http_globals_id)])
+# define PHP_HTTP_G ((zend_php_http_globals *) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(php_http_globals_id)])
# undef TSRMLS_FETCH_FROM_CTX
-# define TSRMLS_FETCH_FROM_CTX(ctx) ((ctx)?(ctx):ts_resource_ex(0, NULL))
+# define TSRMLS_FETCH_FROM_CTX(ctx) void ***tsrm_ls = ((ctx)?(ctx):ts_resource_ex(0, NULL))
#else
# define PHP_HTTP_G (&php_http_globals)
#endif
list->expires = 0;
list->flags = 0;
+ TSRMLS_SET_CTX(list->ts);
+
return list;
}
-PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_copy(php_http_cookie_list_t *from, php_http_cookie_list_t *to TSRMLS_DC)
+PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_copy(php_http_cookie_list_t *from, php_http_cookie_list_t *to)
{
+ TSRMLS_FETCH_FROM_CTX(from->ts);
+
to = php_http_cookie_list_init(to TSRMLS_CC);
array_copy(&from->cookies, &to->cookies);
return to;
}
-PHP_HTTP_API void php_http_cookie_list_dtor(php_http_cookie_list_t *list TSRMLS_DC)
+PHP_HTTP_API void php_http_cookie_list_dtor(php_http_cookie_list_t *list)
{
if (list) {
zend_hash_destroy(&list->cookies);
-PHP_HTTP_API void php_http_cookie_list_free(php_http_cookie_list_t **list TSRMLS_DC)
+PHP_HTTP_API void php_http_cookie_list_free(php_http_cookie_list_t **list)
{
if (*list) {
php_http_cookie_list_dtor(*list);
-PHP_HTTP_API const char *php_http_cookie_list_get_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len TSRMLS_DC)
+PHP_HTTP_API const char *php_http_cookie_list_get_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len)
{
zval **cookie = NULL;
if ((SUCCESS != zend_hash_find(&list->cookies, name, name_len + 1, (void *) &cookie)) || (Z_TYPE_PP(cookie) != IS_STRING)) {
-PHP_HTTP_API const char *php_http_cookie_list_get_extra(php_http_cookie_list_t *list, const char *name, size_t name_len TSRMLS_DC)
+PHP_HTTP_API const char *php_http_cookie_list_get_extra(php_http_cookie_list_t *list, const char *name, size_t name_len)
{
zval **extra = NULL;
if ((SUCCESS != zend_hash_find(&list->extras, name, name_len + 1, (void *) &extra)) || (Z_TYPE_PP(extra) != IS_STRING)) {
-PHP_HTTP_API void php_http_cookie_list_add_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len TSRMLS_DC)
+PHP_HTTP_API void php_http_cookie_list_add_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len)
{
zval *cookie_value;
- char *key = estrndup(name, name_len);
+
MAKE_STD_ZVAL(cookie_value);
ZVAL_STRINGL(cookie_value, estrndup(value, value_len), value_len, 0);
- zend_hash_update(&list->cookies, key, name_len + 1, (void *) &cookie_value, sizeof(zval *), NULL);
- efree(key);
+ zend_hash_update(&list->cookies, name, name_len + 1, (void *) &cookie_value, sizeof(zval *), NULL);
}
-PHP_HTTP_API void php_http_cookie_list_add_extra(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len TSRMLS_DC)
+PHP_HTTP_API void php_http_cookie_list_add_extra(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len)
{
zval *cookie_value;
- char *key = estrndup(name, name_len);
+
MAKE_STD_ZVAL(cookie_value);
ZVAL_STRINGL(cookie_value, estrndup(value, value_len), value_len, 0);
- zend_hash_update(&list->extras, key, name_len + 1, (void *) &cookie_value, sizeof(zval *), NULL);
- efree(key);
+ zend_hash_update(&list->extras, name, name_len + 1, (void *) &cookie_value, sizeof(zval *), NULL);
}
STR_SET(arg->list->domain, estrndup(val, vallen));
} else if _KEY_IS("expires") {
char *date = estrndup(val, vallen);
- arg->list->expires = php_parse_date(date, NULL TSRMLS_CC);
+ arg->list->expires = php_parse_date(date, NULL);
efree(date);
} else if _KEY_IS("secure") {
arg->list->flags |= PHP_HTTP_COOKIE_SECURE;
for (; *ae; ++ae) {
if ((size_t) keylen == strlen(*ae) && !strncasecmp(key, *ae, keylen)) {
if (arg->flags & PHP_HTTP_COOKIE_PARSE_RAW) {
- php_http_cookie_list_add_extra(arg->list, key, keylen, val, vallen TSRMLS_CC);
+ php_http_cookie_list_add_extra(arg->list, key, keylen, val, vallen);
} else {
char *dec = estrndup(val, vallen);
int declen = php_url_decode(dec, vallen);
- php_http_cookie_list_add_extra(arg->list, key, keylen, dec, declen TSRMLS_CC);
+ php_http_cookie_list_add_extra(arg->list, key, keylen, dec, declen);
efree(dec);
}
return;
}
/* new cookie */
if (arg->flags & PHP_HTTP_COOKIE_PARSE_RAW) {
- php_http_cookie_list_add_cookie(arg->list, key, keylen, val, vallen TSRMLS_CC);
+ php_http_cookie_list_add_cookie(arg->list, key, keylen, val, vallen);
} else {
char *dec = estrndup(val, vallen);
int declen = php_url_decode(dec, vallen);
- php_http_cookie_list_add_cookie(arg->list, key, keylen, dec, declen TSRMLS_CC);
+ php_http_cookie_list_add_cookie(arg->list, key, keylen, dec, declen);
efree(dec);
}
}
if (SUCCESS != php_http_params_parse(string, PHP_HTTP_PARAMS_RAISE_ERROR, php_http_cookie_parse_callback, &arg TSRMLS_CC)) {
if (free_list) {
- php_http_cookie_list_free(&list TSRMLS_CC);
+ php_http_cookie_list_free(&list);
} else {
- php_http_cookie_list_dtor(list TSRMLS_CC);
+ php_http_cookie_list_dtor(list);
}
list = NULL;
}
-PHP_HTTP_API void php_http_cookie_list_to_struct(php_http_cookie_list_t *list, zval *strct TSRMLS_DC)
+PHP_HTTP_API void php_http_cookie_list_to_struct(php_http_cookie_list_t *list, zval *strct)
{
zval array, *cookies, *extras;
+ TSRMLS_FETCH_FROM_CTX(list->ts);
INIT_PZVAL_ARRAY(&array, HASH_OF(strct));
if (Z_LVAL_P(cpy)) {
list->expires = Z_LVAL_P(cpy);
} else {
- time_t expires = php_parse_date(Z_STRVAL_PP(tmp), NULL TSRMLS_CC);
+ time_t expires = php_parse_date(Z_STRVAL_PP(tmp), NULL);
if (expires > 0) {
list->expires = expires;
}
-PHP_HTTP_API void php_http_cookie_list_to_string(php_http_cookie_list_t *list, char **str, size_t *len TSRMLS_DC)
+PHP_HTTP_API void php_http_cookie_list_to_string(php_http_cookie_list_t *list, char **str, size_t *len)
{
php_http_buffer_t buf;
zval **val;
php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
HashPosition pos;
+ TSRMLS_FETCH_FROM_CTX(list->ts);
php_http_buffer_init(&buf);
return ov;
}
-zend_object_value php_http_cookie_object_clone(zval *this_ptr TSRMLS_CC)
+zend_object_value php_http_cookie_object_clone(zval *this_ptr TSRMLS_DC)
{
php_http_cookie_object_t *new_obj, *old_obj = zend_object_store_get_object(getThis() TSRMLS_CC);
zend_object_value ov;
- ov = php_http_cookie_object_new_ex(old_obj->o.ce, php_http_cookie_list_copy(old_obj->list, NULL TSRMLS_CC), &new_obj TSRMLS_CC);
+ if (!old_obj->list) {
+ old_obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
+ }
+ ov = php_http_cookie_object_new_ex(old_obj->o.ce, php_http_cookie_list_copy(old_obj->list, NULL), &new_obj TSRMLS_CC);
zend_objects_clone_members((zend_object *) new_obj, ov, (zend_object *) old_obj, Z_OBJ_HANDLE_P(getThis()) TSRMLS_CC);
return ov;
}
-void php_http_cookie_object_free(void *object TSRMLS_CC)
+void php_http_cookie_object_free(void *object TSRMLS_DC)
{
php_http_cookie_object_t *obj = object;
- php_http_cookie_list_free(&obj->list TSRMLS_CC);
+ php_http_cookie_list_free(&obj->list);
zend_object_std_dtor((zend_object *) obj TSRMLS_CC);
efree(obj);
}
if (!obj->list) {
obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
}
- php_http_cookie_list_to_string(obj->list, &str, &len TSRMLS_CC);
+ php_http_cookie_list_to_string(obj->list, &str, &len);
RETURN_STRINGL(str, len, 0);
}
RETURN_EMPTY_STRING();
obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
}
array_init(return_value);
- php_http_cookie_list_to_struct(obj->list, return_value TSRMLS_CC);
+ php_http_cookie_list_to_struct(obj->list, return_value);
}
}
char *path;
char *domain;
time_t expires;
+
+#ifdef ZTS
+ void ***ts;
+#endif
} php_http_cookie_list_t;
PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_init(php_http_cookie_list_t *list TSRMLS_DC);
-PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_parse(php_http_cookie_list_t * list, const char *string, long flags, char **allowed_extras TSRMLS_DC);
-PHP_HTTP_API void php_http_cookie_list_dtor(php_http_cookie_list_t *list TSRMLS_DC);
-PHP_HTTP_API void php_http_cookie_list_free(php_http_cookie_list_t **list TSRMLS_DC);
+PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_parse(php_http_cookie_list_t *list, const char *string, long flags, char **allowed_extras TSRMLS_DC);
+PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_copy(php_http_cookie_list_t *from, php_http_cookie_list_t *to);
+PHP_HTTP_API void php_http_cookie_list_dtor(php_http_cookie_list_t *list);
+PHP_HTTP_API void php_http_cookie_list_free(php_http_cookie_list_t **list);
#define php_http_cookie_list_has_cookie(list, name, name_len) zend_hash_exists(&(list)->cookies, (name), (name_len)+1)
-PHP_HTTP_API void php_http_cookie_list_add_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len TSRMLS_DC);
-PHP_HTTP_API const char *php_http_cookie_list_get_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len TSRMLS_DC);
+PHP_HTTP_API void php_http_cookie_list_add_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len);
+PHP_HTTP_API const char *php_http_cookie_list_get_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len);
#define php_http_cookie_list_has_extra(list, name, name_len) zend_hash_exists(&(list)->extras, (name), (name_len)+1)
-PHP_HTTP_API void php_http_cookie_list_add_extra(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len TSRMLS_DC);
-PHP_HTTP_API const char *php_http_cookie_list_get_extra(php_http_cookie_list_t *list, const char *name, size_t name_len TSRMLS_DC);
+PHP_HTTP_API void php_http_cookie_list_add_extra(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len);
+PHP_HTTP_API const char *php_http_cookie_list_get_extra(php_http_cookie_list_t *list, const char *name, size_t name_len);
-PHP_HTTP_API void php_http_cookie_list_to_string(php_http_cookie_list_t *list, char **str, size_t *len TSRMLS_DC);
+PHP_HTTP_API void php_http_cookie_list_to_string(php_http_cookie_list_t *list, char **str, size_t *len);
PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_from_struct(php_http_cookie_list_t *list, zval *strct TSRMLS_DC);
-PHP_HTTP_API void php_http_cookie_list_to_struct(php_http_cookie_list_t *list, zval *strct TSRMLS_DC);
+PHP_HTTP_API void php_http_cookie_list_to_struct(php_http_cookie_list_t *list, zval *strct);
extern zend_class_entry *php_http_cookie_class_entry;
php_http_request_t *h = ctx;
php_http_curl_request_t *curl = h->ctx;
unsigned flags = 0;
+ TSRMLS_FETCH_FROM_CTX(h->ts);
/* catch progress */
switch (type) {
break;
default: {
- const char *name = php_http_request_method_name(meth);
+ const char *name = php_http_request_method_name(meth TSRMLS_CC);
if (name) {
curl_easy_setopt(curl->handle, CURLOPT_CUSTOMREQUEST, name);
int range_req = 0;
php_http_curl_request_t *curl = h->ctx;
CURL *ch = curl->handle;
+ TSRMLS_FETCH_FROM_CTX(h->ts);
/* proxy */
if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("proxyhost"), IS_STRING))) {
/* request datashare handler ops */
-static php_http_request_datashare_t *php_http_curl_request_datashare_init(php_http_request_datashare_t *h, void *handle TSRMLS_DC)
+static php_http_request_datashare_t *php_http_curl_request_datashare_init(php_http_request_datashare_t *h, void *handle)
{
php_http_curl_request_datashare_t *curl;
+ TSRMLS_FETCH_FROM_CTX(h->ts);
if (!handle && !(handle = php_http_resource_factory_handle_ctor(h->rf TSRMLS_CC))) {
php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_DATASHARE, "could not initialize curl share handle");
curl->handle = handle;
#ifdef ZTS
if (h->persistent) {
- curl->locks = php_http_request_datashare_locks_init();
+ curl->locks = php_http_curl_request_datashare_locks_init();
if (curl->locks) {
- curl_share_setopt(share->ch, CURLSHOPT_LOCKFUNC, php_http_curl_request_datashare_lock_func);
- curl_share_setopt(share->ch, CURLSHOPT_UNLOCKFUNC, php_http_curl_request_datashare_unlock_func);
- curl_share_setopt(share->ch, CURLSHOPT_USERDATA, curl->locks);
+ curl_share_setopt(curl->handle, CURLSHOPT_LOCKFUNC, php_http_curl_request_datashare_lock_func);
+ curl_share_setopt(curl->handle, CURLSHOPT_UNLOCKFUNC, php_http_curl_request_datashare_unlock_func);
+ curl_share_setopt(curl->handle, CURLSHOPT_USERDATA, curl->locks);
}
}
#endif
#ifdef ZTS
if (h->persistent) {
- http_request_datashare_locks_dtor(curl->locks);
+ php_http_curl_request_datashare_locks_dtor(curl->locks);
}
#endif
/* request pool handler ops */
-static php_http_request_pool_t *php_http_curl_request_pool_init(php_http_request_pool_t *h, void *handle TSRMLS_DC)
+static php_http_request_pool_t *php_http_curl_request_pool_init(php_http_request_pool_t *h, void *handle)
{
php_http_curl_request_pool_t *curl;
+ TSRMLS_FETCH_FROM_CTX(h->ts);
if (!handle && !(handle = php_http_resource_factory_handle_ctor(h->rf TSRMLS_CC))) {
php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_POOL, "could not initialize curl pool handle");
curl->unfinished = 0;
php_http_request_pool_reset(h);
- php_http_resource_factory_handle_dtor(h->rf, curl->handle);
+ php_http_resource_factory_handle_dtor(h->rf, curl->handle TSRMLS_CC);
efree(curl);
h->ctx = NULL;
php_http_curl_request_pool_t *curl = h->ctx;
php_http_curl_request_t *recurl = r->ctx;
CURLMcode rs;
+ TSRMLS_FETCH_FROM_CTX(h->ts);
if (SUCCESS != php_http_curl_request_prepare(r, m, url, body)) {
return FAILURE;
php_http_curl_request_pool_t *curl = h->ctx;
php_http_curl_request_t *recurl = r->ctx;
CURLMcode rs = curl_multi_remove_handle(curl->handle, recurl->handle);
+ TSRMLS_FETCH_FROM_CTX(h->ts);
if (CURLM_OK == rs) {
return SUCCESS;
#ifdef PHP_HTTP_HAVE_EVENT
if (curl->useevents) {
- TSRMLS_FETCH_FROM_CTX(pool->ts);
+ TSRMLS_FETCH_FROM_CTX(h->ts);
php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "not implemented");
return FAILURE;
#endif
static STATUS php_http_curl_request_pool_exec(php_http_request_pool_t *h)
{
+ TSRMLS_FETCH_FROM_CTX(h->ts);
+
#ifdef PHP_HTTP_HAVE_EVENT
php_http_curl_request_pool_t *curl = h->ctx;
curl_easy_setopt(handle, CURLOPT_DEBUGDATA, h);
curl_easy_setopt(handle, CURLOPT_PROGRESSDATA, h);
- php_http_curl_request_reset(h TSRMLS_CC);
+ php_http_curl_request_reset(h);
return h;
}
static void php_http_curl_request_dtor(php_http_request_t *h)
{
php_http_curl_request_t *ctx = h->ctx;
+ TSRMLS_FETCH_FROM_CTX(h->ts);
curl_easy_setopt(ctx->handle, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(ctx->handle, CURLOPT_PROGRESSFUNCTION, NULL);
curl_slist_free_all(ctx->options.headers);
ctx->options.headers = NULL;
}
- php_http_request_progress_dtor(&ctx->progress);
+ php_http_request_progress_dtor(&ctx->progress TSRMLS_CC);
efree(ctx);
h->ctx = NULL;
static STATUS php_http_curl_request_setopt(php_http_request_t *h, php_http_request_setopt_opt_t opt, void *arg)
{
php_http_curl_request_t *curl = h->ctx;
+ TSRMLS_FETCH_FROM_CTX(h->ts);
switch (opt) {
case PHP_HTTP_REQUEST_OPT_SETTINGS:
static php_http_encoding_stream_t *dechunk_init(php_http_encoding_stream_t *s)
{
struct dechunk_ctx *ctx = pecalloc(1, sizeof(*ctx), (s->flags & PHP_HTTP_ENCODING_STREAM_PERSISTENT));
- TSRMLS_FETCH_FROM_CTX(s->ts);
if (!php_http_buffer_init_ex(&ctx->buffer, PHP_HTTP_BUFFER_DEFAULT_SIZE, (s->flags & PHP_HTTP_ENCODING_STREAM_PERSISTENT) ? PHP_HTTP_BUFFER_INIT_PERSISTENT : 0)) {
return NULL;
php_http_encoding_stream_object_t *o = (php_http_encoding_stream_object_t *) object;
if (o->stream) {
- php_http_encoding_stream_free(&o->stream TSRMLS_CC);
+ php_http_encoding_stream_free(&o->stream);
}
zend_object_std_dtor((zend_object *) o TSRMLS_CC);
efree(o);
size_t encoded_len;
char *encoded_str;
- if (SUCCESS == php_http_encoding_stream_update(obj->stream, data_str, data_len, &encoded_str, &encoded_len TSRMLS_CC)) {
+ if (SUCCESS == php_http_encoding_stream_update(obj->stream, data_str, data_len, &encoded_str, &encoded_len)) {
RETURN_STRINGL(encoded_str, encoded_len, 0);
}
}
char *encoded_str;
size_t encoded_len;
- if (SUCCESS == php_http_encoding_stream_flush(obj->stream, &encoded_str, &encoded_len TSRMLS_CC)) {
+ if (SUCCESS == php_http_encoding_stream_flush(obj->stream, &encoded_str, &encoded_len)) {
RETURN_STRINGL(encoded_str, encoded_len, 0);
}
}
char *encoded_str;
size_t encoded_len;
- if (SUCCESS == php_http_encoding_stream_finish(obj->stream, &encoded_str, &encoded_len TSRMLS_CC)) {
+ if (SUCCESS == php_http_encoding_stream_finish(obj->stream, &encoded_str, &encoded_len)) {
if (SUCCESS == php_http_encoding_stream_reset(&obj->stream)) {
RETURN_STRINGL(encoded_str, encoded_len, 0);
} else {
#define PHP_HTTP_DO_NEGOTIATE(type, supported, rs_array) \
{ \
HashTable *result; \
- if ((result = php_http_negotiate_ ##type(supported))) { \
+ if ((result = php_http_negotiate_ ##type(supported TSRMLS_CC))) { \
PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(result, supported, rs_array); \
} else { \
PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array); \
array_init(rs_array);
}
- if ((rs = php_http_negotiate(value_str, supported, php_http_negotiate_default_func))) {
+ if ((rs = php_http_negotiate(value_str, supported, php_http_negotiate_default_func TSRMLS_CC))) {
PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs, supported, rs_array);
} else {
PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array);
{
if (SUCCESS == zend_parse_parameters_none()) {
object_init(return_value);
- if (php_http_persistent_handle_statall(HASH_OF(return_value))) {
+ if (php_http_persistent_handle_statall(HASH_OF(return_value) TSRMLS_CC)) {
return;
}
zval_dtor(return_value);
}
}
}
-static zval *get_option(zval *options, const char *name_str, size_t name_len TSRMLS_CC)
+static zval *get_option(zval *options, const char *name_str, size_t name_len TSRMLS_DC)
{
zval *val, **valptr;
zval_ptr_dtor(&zlm);
}
- ums = php_parse_date(header, NULL TSRMLS_CC);
+ ums = php_parse_date(header, NULL);
efree(header);
if (ums > 0 && ums <= lm) {
static size_t output(void *context, const char *buf, size_t len TSRMLS_DC)
{
php_http_env_response_t *r = context;
- TSRMLS_FETCH_FROM_CTX(r->ts);
PHPWRITE(buf, len);
ret = php_http_env_set_response_header_format(206, 1 TSRMLS_CC, "Content-Range: bytes %ld-%ld/%zu", Z_LVAL_PP(begin), Z_LVAL_PP(end), r->content.length);
}
} else {
- php_http_boundary(r->range.boundary, sizeof(r->range.boundary));
+ php_http_boundary(r->range.boundary, sizeof(r->range.boundary) TSRMLS_CC);
ret = php_http_env_set_response_header_format(206, 1 TSRMLS_CC, "Content-Type: multipart/byteranges; boundary=%s", r->range.boundary);
}
} else {
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))) {
+ if (!(r->content.encoder = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), PHP_HTTP_DEFLATE_TYPE_GZIP TSRMLS_CC))) {
ret = FAILURE;
} else if (SUCCESS == (ret = php_http_env_set_response_header(0, ZEND_STRL("Content-Encoding: gzip"), 1 TSRMLS_CC))) {
r->content.encoding = estrndup(key_str, key_len - 1);
}
} 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))) {
+ if (!(r->content.encoder = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), PHP_HTTP_DEFLATE_TYPE_ZLIB TSRMLS_CC))) {
ret = FAILURE;
} else if (SUCCESS == (ret = php_http_env_set_response_header(0, ZEND_STRL("Content-Encoding: deflate"), 1 TSRMLS_CC))) {
r->content.encoding = estrndup(key_str, key_len - 1);
return ret;
}
- switch (php_http_env_is_response_cached_by_etag(options, ZEND_STRL("If-None-Match"))) {
+ switch (php_http_env_is_response_cached_by_etag(options, ZEND_STRL("If-None-Match") TSRMLS_CC)) {
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"))) {
+ if (PHP_HTTP_CACHE_HIT != php_http_env_is_response_cached_by_last_modified(options, ZEND_STRL("If-Modified-Since") TSRMLS_CC)) {
break;
}
{
STATUS ret = SUCCESS;
zval *zbody;
+ TSRMLS_FETCH_FROM_CTX(r->ts);
if (r->done) {
return ret;
PHP_HTTP_API STATUS php_http_env_response_send(php_http_env_response_t *r)
{
zval *zbody;
+ TSRMLS_FETCH_FROM_CTX(r->ts);
/* check for ranges */
if ( (zbody = get_option(r->options, ZEND_STRL("body") TSRMLS_CC))
if (file_len) {
add_assoc_stringl_ex(arr, ZEND_STRS("filename"), file_str, file_len, 1);
}
- zend_update_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL("contentDisposition"), arr);
+ zend_update_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL("contentDisposition"), arr TSRMLS_CC);
zval_ptr_dtor(&arr);
}
}
char *header_name_str = NULL;
int 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() TSRMLS_CC, "|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");
} php_http_env_response_t;
PHP_HTTP_API php_http_env_response_t *php_http_env_response_init(php_http_env_response_t *r, zval *options TSRMLS_DC);
-PHP_HTTP_API STATUS php_Http_env_response_send(php_http_env_response_t *r);
+PHP_HTTP_API STATUS php_http_env_response_send(php_http_env_response_t *r);
PHP_HTTP_API void php_http_env_response_dtor(php_http_env_response_t *r);
PHP_HTTP_API void php_http_env_response_free(php_http_env_response_t **r);
#include <ext/standard/sha1.h>
#include <ext/standard/md5.h>
-PHP_HTTP_API void *php_http_etag_init(TSRMLS_D)
+PHP_HTTP_API php_http_etag_t *php_http_etag_init(const char *mode TSRMLS_DC)
{
- void *ctx = NULL;
- char *mode = PHP_HTTP_G->env.etag_mode;
+ void *ctx;
+ php_http_etag_t *e;
#ifdef PHP_HTTP_HAVE_HASH
const php_hash_ops *eho = NULL;
*((uint *) ctx) = ~0;
} else if (mode && !strcasecmp(mode, "sha1")) {
PHP_SHA1Init(ctx = emalloc(sizeof(PHP_SHA1_CTX)));
- } else {
+ } else if (mode && !strcasecmp(mode, "md5")) {
PHP_MD5Init(ctx = emalloc(sizeof(PHP_MD5_CTX)));
+ } else {
+ return NULL;
}
- return ctx;
+ e = emalloc(sizeof(*e));
+ e->ctx = ctx;
+ e->mode = estrdup(mode);
+ TSRMLS_SET_CTX(e->ts);
+
+ return e;
}
-PHP_HTTP_API char *php_http_etag_finish(void *ctx TSRMLS_DC)
+PHP_HTTP_API char *php_http_etag_finish(php_http_etag_t *e)
{
unsigned char digest[128] = {0};
- char *etag = NULL, *mode = PHP_HTTP_G->env.etag_mode;
+ char *etag = NULL;
#ifdef PHP_HTTP_HAVE_HASH
const php_hash_ops *eho = NULL;
- if (mode && (eho = php_hash_fetch_ops(mode, strlen(mode)))) {
- eho->hash_final(digest, ctx);
+ if (mode && (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);
} else
#endif
- if (mode && ((!strcasecmp(mode, "crc32")) || (!strcasecmp(mode, "crc32b")))) {
- *((uint *) ctx) = ~*((uint *) ctx);
- etag = php_http_etag_digest((const unsigned char *) ctx, sizeof(uint));
- } else if (mode && (!strcasecmp(mode, "sha1"))) {
- PHP_SHA1Final(digest, ctx);
+ if (((!strcasecmp(e->mode, "crc32")) || (!strcasecmp(e->mode, "crc32b")))) {
+ *((uint *) e->ctx) = ~*((uint *) e->ctx);
+ etag = php_http_etag_digest((const unsigned char *) e->ctx, sizeof(uint));
+ } else if ((!strcasecmp(e->mode, "sha1"))) {
+ PHP_SHA1Final(digest, e->ctx);
etag = php_http_etag_digest(digest, 20);
} else {
- PHP_MD5Final(digest, ctx);
+ PHP_MD5Final(digest, e->ctx);
etag = php_http_etag_digest(digest, 16);
}
- efree(ctx);
+ efree(e->ctx);
+ efree(e->mode);
+ efree(e);
return etag;
}
-PHP_HTTP_API size_t php_http_etag_update(void *ctx, const char *data_ptr, size_t data_len TSRMLS_DC)
+PHP_HTTP_API size_t php_http_etag_update(php_http_etag_t *e, const char *data_ptr, size_t data_len)
{
- char *mode = PHP_HTTP_G->env.etag_mode;
#ifdef PHP_HTTP_HAVE_HASH
const php_hash_ops *eho = NULL;
- if (mode && (eho = php_hash_fetch_ops(mode, strlen(mode)))) {
- eho->hash_update(ctx, (const unsigned char *) data_ptr, data_len);
+ if (mode && (eho = php_hash_fetch_ops(e->mode, strlen(e->mode)))) {
+ eho->hash_update(e->ctx, (const unsigned char *) data_ptr, data_len);
} else
#endif
- if (mode && ((!strcasecmp(mode, "crc32")) || (!strcasecmp(mode, "crc32b")))) {
- uint i, c = *((uint *) ctx);
+ if (((!strcasecmp(e->mode, "crc32")) || (!strcasecmp(e->mode, "crc32b")))) {
+ uint i, c = *((uint *) e->ctx);
for (i = 0; i < data_len; ++i) {
CRC32(c, data_ptr[i]);
}
- *((uint *)ctx) = c;
- } else if (mode && (!strcasecmp(mode, "sha1"))) {
- PHP_SHA1Update(ctx, (const unsigned char *) data_ptr, data_len);
+ *((uint *) e->ctx) = c;
+ } else if ((!strcasecmp(e->mode, "sha1"))) {
+ PHP_SHA1Update(e->ctx, (const unsigned char *) data_ptr, data_len);
} else {
- PHP_MD5Update(ctx, (const unsigned char *) data_ptr, data_len);
+ PHP_MD5Update(e->ctx, (const unsigned char *) data_ptr, data_len);
}
return data_len;
#ifndef PHP_HTTP_ETAG_H
#define PHP_HTTP_ETAG_H
-PHP_HTTP_API void *php_http_etag_init(TSRMLS_D);
-PHP_HTTP_API size_t php_http_etag_update(void *ctx, const char *data_ptr, size_t data_len TSRMLS_DC);
-PHP_HTTP_API char *php_http_etag_finish(void *ctx TSRMLS_DC);
+typedef struct php_http_etag {
+ void *ctx;
+ char *mode;
+
+#ifdef ZTS
+ void ***ts;
+#endif
+} php_http_etag_t;
+
+PHP_HTTP_API php_http_etag_t *php_http_etag_init(const char *mode TSRMLS_DC);
+PHP_HTTP_API size_t php_http_etag_update(php_http_etag_t *e, const char *data_ptr, size_t data_len);
+PHP_HTTP_API char *php_http_etag_finish(php_http_etag_t *e);
static inline char *php_http_etag_digest(const unsigned char *digest, int len)
{
}
if (ptr->buflen) {
- php_http_encoding_stream_update(buffer, ptr->buf, ptr->buflen, &encoded, &encoded_len TSRMLS_CC);
+ php_http_encoding_stream_update(buffer, ptr->buf, ptr->buflen, &encoded, &encoded_len);
if (encoded) {
if (encoded_len) {
out_avail = 1;
char *encoded = NULL;
size_t encoded_len = 0;
- php_http_encoding_stream_flush(buffer, &encoded, &encoded_len TSRMLS_CC);
+ php_http_encoding_stream_flush(buffer, &encoded, &encoded_len);
if (encoded) {
if (encoded_len) {
out_avail = 1;
char *encoded = NULL;
size_t encoded_len = 0;
- php_http_encoding_stream_finish(buffer, &encoded, &encoded_len TSRMLS_CC);
+ php_http_encoding_stream_finish(buffer, &encoded, &encoded_len);
if (encoded) {
if (encoded_len) {
out_avail = 1;
static PHP_HTTP_FILTER_DESTRUCTOR(zlib)
{
PHP_HTTP_FILTER_BUFFER(zlib) *buffer = (PHP_HTTP_FILTER_BUFFER(zlib) *) this->abstract;
- php_http_encoding_stream_free(&buffer TSRMLS_CC);
+ php_http_encoding_stream_free(&buffer);
}
static PHP_HTTP_FILTER_OPS(deflate) = {
if ((b = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_inflate_ops(), flags TSRMLS_CC))) {
if (!(f = php_stream_filter_alloc(&PHP_HTTP_FILTER_OP(inflate), b, p))) {
- php_http_encoding_stream_free(&b TSRMLS_CC);
+ php_http_encoding_stream_free(&b);
}
}
} else
}
if ((b = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), flags TSRMLS_CC))) {
if (!(f = php_stream_filter_alloc(&PHP_HTTP_FILTER_OP(deflate), b, p))) {
- php_http_encoding_stream_free(&b TSRMLS_CC);
+ php_http_encoding_stream_free(&b);
}
}
}
};
-PHP_HTTP_API php_http_header_parser_t *php_http_header_parser_init(php_http_header_parser_t *parser TSRMLS_CC)
+PHP_HTTP_API php_http_header_parser_t *php_http_header_parser_init(php_http_header_parser_t *parser TSRMLS_DC)
{
if (!parser) {
parser = emalloc(sizeof(*parser));
/* advance message */
if (old->type || zend_hash_num_elements(&old->hdrs) || PHP_HTTP_BUFFER_LEN(old)) {
- (*message) = php_http_message_init(NULL, 0);
+ (*message) = php_http_message_init(NULL, 0 TSRMLS_CC);
(*message)->parent = old;
(*headers) = &((*message)->hdrs);
}
switch (type) {
case PHP_HTTP_REQUEST:
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));
+ php_http_version_parse(&message->http.version, Z_STRVAL_P(sval) TSRMLS_CC);
} else {
message->http.version.major = 1;
message->http.version.minor = 1;
if ((mbody = php_http_env_get_request_body(TSRMLS_C))) {
php_http_message_body_dtor(&message->body);
- php_http_message_body_copy(mbody, &message->body, 0 TSRMLS_CC);
+ php_http_message_body_copy(mbody, &message->body, 0);
}
break;
php_http_env_get_response_headers(&message->hdrs TSRMLS_CC);
- if (php_output_get_level()) {
+ if (php_output_get_level(TSRMLS_C)) {
if (php_output_get_status(TSRMLS_C) & PHP_OUTPUT_SENT) {
php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "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;
zval *header_str, **val;
HashPosition pos;
php_http_buffer_t str;
+ TSRMLS_FETCH_FROM_CTX(msg->ts);
php_http_buffer_init(&str);
MAKE_STD_ZVAL(header_str);
HashPosition pos1;
zval **header, *h;
size_t size;
+ TSRMLS_FETCH_FROM_CTX(msg->ts);
switch (msg->type) {
case PHP_HTTP_REQUEST:
PHP_HTTP_API void php_http_message_to_callback(php_http_message_t *msg, php_http_pass_callback_t cb, void *cb_arg)
{
php_http_buffer_t str;
- TSRMLS_FETCH_FROM_CTX(msg->ts);
php_http_buffer_init_ex(&str, 0x1000, 0);
message_headers(msg, &str);
php_http_buffer_dtor(&str);
if (php_http_message_body_size(&msg->body)) {
- cb(cb_arg, ZEND_STRL(PHP_HTTP_CRLF) TSRMLS_CC);
+ cb(cb_arg, ZEND_STRL(PHP_HTTP_CRLF));
php_http_message_body_to_callback(&msg->body, cb, cb_arg, 0, 0);
- cb(cb_arg, ZEND_STRL(PHP_HTTP_CRLF) TSRMLS_CC);
+ cb(cb_arg, ZEND_STRL(PHP_HTTP_CRLF));
}
}
return m1;
}
-PHP_HTTP_API void php_http_message_to_struct(php_http_message_t *msg, zval *obj TSRMLS_DC)
+PHP_HTTP_API void php_http_message_to_struct(php_http_message_t *msg, zval *obj)
{
zval strct;
zval *headers;
char *version;
+ TSRMLS_FETCH_FROM_CTX(msg->ts);
INIT_PZVAL_ARRAY(&strct, HASH_OF(obj));
info.type = from->type;
info.http = from->http;
- copy = temp = php_http_message_init(to, 0);
+ copy = temp = php_http_message_init(to, 0 TSRMLS_CC);
php_http_message_set_info(temp, &info);
zend_hash_copy(&temp->hdrs, &from->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
php_http_message_body_copy(&from->body, &temp->body, 1);
info.type = from->parent->type;
info.http = from->parent->http;
- temp->parent = php_http_message_init(NULL, 0);
+ temp->parent = php_http_message_init(NULL, 0 TSRMLS_CC);
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 *));
php_http_message_body_copy(&from->body, &temp->body, 1);
php_http_message_object_t *new_obj = NULL;
php_http_message_object_t *old_obj = zend_object_store_get_object(this_ptr TSRMLS_CC);
- new_ov = php_http_message_object_new_ex(old_obj->zo.ce, php_http_message_copy(old_obj->message, NULL), &new_obj);
+ 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);
return new_ov;
php_http_message_dtor(msg);
with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if ((obj->message = php_http_message_parse(msg, message, length))) {
+ if ((obj->message = php_http_message_parse(msg, message, length TSRMLS_CC))) {
if (obj->message->parent) {
obj->parent = php_http_message_object_new_ex(Z_OBJCE_P(getThis()), obj->message->parent, NULL TSRMLS_CC);
}
PHP_HTTP_API void php_http_message_body_dtor(php_http_message_body_t *body)
{
+ TSRMLS_FETCH_FROM_CTX(body->ts);
/* NO FIXME: shows leakinfo in DEBUG mode */
zend_list_delete(body->stream_id);
STR_FREE(body->boundary);
PHP_HTTP_API char *php_http_message_body_etag(php_http_message_body_t *body)
{
TSRMLS_FETCH_FROM_CTX(body->ts);
- php_stream_statbuf *ssb = php_http_message_body_stat(body);
+ const php_stream_statbuf *ssb = php_http_message_body_stat(body);
/* real file or temp buffer ? */
if (body->ssb.sb.st_mtime) {
spprintf(&etag, 0, "%lx-%lx-%lx", ssb->sb.st_ino, ssb->sb.st_mtime, ssb->sb.st_size);
return etag;
} else {
- void *ctx = php_http_etag_init(TSRMLS_C);
+ php_http_etag_t *etag = php_http_etag_init(PHP_HTTP_G->env.etag_mode TSRMLS_CC);
- php_http_message_body_to_callback(body, php_http_etag_update, ctx, 0, 0);
- return php_http_etag_finish(ctx TSRMLS_CC);
+ php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_etag_update, etag, 0, 0);
+ return php_http_etag_finish(etag);
}
}
PHP_HTTP_API STATUS php_http_message_body_add(php_http_message_body_t *body, HashTable *fields, HashTable *files)
{
zval tmp;
- TSRMLS_FETCH_FROM_CTX(body->ts);
if (fields) {
INIT_PZVAL_ARRAY(&tmp, fields);
PHP_HTTP_API STATUS php_http_message_body_add_field(php_http_message_body_t *body, const char *name, const char *value_str, size_t value_len)
{
- char *safe_name = php_addslashes(estrdup(name), strlen(name), NULL, 1 TSRMLS_CC);
+ char *safe_name;
+ TSRMLS_FETCH_FROM_CTX(body->ts);
+
+ safe_name = php_addslashes(estrdup(name), strlen(name), NULL, 1 TSRMLS_CC);
BOUNDARY_OPEN(body);
php_http_message_body_appendf(
zval **val;
HashPosition pos;
php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
+ TSRMLS_FETCH_FROM_CTX(body->ts);
if (!HASH_OF(value)->nApplyCount) {
++HASH_OF(value)->nApplyCount;
{
if (Z_TYPE_P(value) == IS_ARRAY || Z_TYPE_P(value) == IS_OBJECT) {
zval **zfile, **zname, **ztype;
+ TSRMLS_FETCH_FROM_CTX(body->ts);
if ((SUCCESS == zend_hash_find(HASH_OF(value), ZEND_STRS("name"), (void *) &zname))
&& (SUCCESS == zend_hash_find(HASH_OF(value), ZEND_STRS("file"), (void *) &zfile))
}
}
} else {
+ TSRMLS_FETCH_FROM_CTX(body->ts);
php_http_error(HE_WARNING, PHP_HTTP_E_MESSAGE_BODY, "Unrecognized array format for message body file to add");
return FAILURE;
}
php_http_message_body_object_t *new_obj = NULL;
php_http_message_body_object_t *old_obj = zend_object_store_get_object(object TSRMLS_CC);
- new_ov = php_http_message_body_object_new_ex(old_obj->zo.ce, php_http_message_body_copy(old_obj->body, NULL, 1), &new_obj);
+ new_ov = php_http_message_body_object_new_ex(old_obj->zo.ce, php_http_message_body_copy(old_obj->body, NULL, 1), &new_obj TSRMLS_CC);
zend_objects_clone_members(&new_obj->zo, new_ov, &old_obj->zo, Z_OBJ_HANDLE_P(object) TSRMLS_CC);
return new_ov;
zval *fcz;
zend_fcall_info *fci;
zend_fcall_info_cache *fcc;
+#ifdef ZTS
+ void ***ts;
+#endif
};
-static size_t pass(void *cb_arg, const char *str, size_t len TSRMLS_DC)
+static size_t pass(void *cb_arg, const char *str, size_t len)
{
struct fcd *fcd = cb_arg;
zval *zdata;
+ TSRMLS_FETCH_FROM_CTX(fcd->ts);
MAKE_STD_ZVAL(zdata);
ZVAL_STRINGL(zdata, str, len, 1);
} php_http_message_body_t;
PHP_HTTP_API php_http_message_body_t *php_http_message_body_init(php_http_message_body_t *body, php_stream *stream TSRMLS_DC);
-PHP_HTTP_API php_http_message_body_t *php_http_message_body_copy(php_http_message_body_t *from, php_http_message_body_t *to, zend_bool dup_internal_stream_and_contents TSRMLS_DC);
+PHP_HTTP_API php_http_message_body_t *php_http_message_body_copy(php_http_message_body_t *from, php_http_message_body_t *to, zend_bool dup_internal_stream_and_contents);
PHP_HTTP_API STATUS php_http_message_body_add(php_http_message_body_t *body, HashTable *fields, HashTable *files);
PHP_HTTP_API STATUS php_http_message_body_add_field(php_http_message_body_t *body, const char *name, const char *value_str, size_t value_len);
PHP_HTTP_API STATUS php_http_message_body_add_file(php_http_message_body_t *body, const char *name, const char *path, const char *ctype);
php_http_header_parser_dtor(&parser->header);
zend_stack_destroy(&parser->stack);
if (parser->dechunk) {
- php_http_encoding_stream_free(&parser->dechunk TSRMLS_CC);
+ php_http_encoding_stream_free(&parser->dechunk);
}
if (parser->inflate) {
- php_http_encoding_stream_free(&parser->inflate TSRMLS_CC);
+ php_http_encoding_stream_free(&parser->inflate);
}
}
char *dec_str = NULL;
size_t dec_len;
- if (SUCCESS != php_http_encoding_stream_update(parser->inflate, str, len, &dec_str, &dec_len TSRMLS_CC)) {
+ if (SUCCESS != php_http_encoding_stream_update(parser->inflate, str, len, &dec_str, &dec_len)) {
return php_http_message_parser_state_push(parser, 1, PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE);
}
char *dec_str = NULL;
size_t dec_len;
- if (SUCCESS != php_http_encoding_stream_update(parser->dechunk, buffer->data, buffer->used, &dec_str, &dec_len TSRMLS_CC)) {
+ if (SUCCESS != php_http_encoding_stream_update(parser->dechunk, buffer->data, buffer->used, &dec_str, &dec_len)) {
return FAILURE;
}
char *dec_str = NULL;
size_t dec_len;
- if (SUCCESS != php_http_encoding_stream_finish(parser->dechunk, &dec_str, &dec_len TSRMLS_CC)) {
+ if (SUCCESS != php_http_encoding_stream_finish(parser->dechunk, &dec_str, &dec_len)) {
return php_http_message_parser_state_push(parser, 1, PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE);
}
php_http_encoding_stream_dtor(parser->dechunk);
return EH_THROW;
}
- if (EG(This) && instanceof_function(Z_OBJCE_P(EG(This)), php_http_object_class_entry)) {
+ if (EG(This) && instanceof_function(Z_OBJCE_P(EG(This)), php_http_object_class_entry TSRMLS_CC)) {
return php_http_object_get_error_handling(EG(This) TSRMLS_CC);
}
char *message;
zend_class_entry *ce = php_http_exception_class_entry;
- if (0&& EG(exception_class) && instanceof_function(EG(exception_class), php_http_exception_class_entry)) {
+ if (0&& EG(exception_class) && instanceof_function(EG(exception_class), php_http_exception_class_entry TSRMLS_CC)) {
ce = EG(exception_class);
}
zval *zoption;
int range_req = 0;
php_http_neon_request_t *neon = h->ctx;
+ TSRMLS_FETCH_FROM_CTX(h->ts);
/* proxy */
if ((zoption = get_option(&neon->options.cache, options, ZEND_STRS("proxyhost"), IS_STRING))) {
if (PHP_HTTP_BUFFER_LEN(&rs)) {
/* ignore last comma */
- php_http_buffer_appendf(&neon->options.headers, "Range: bytes=%.*s" PHP_HTTP_CRLF, rs.used - 1, rs.data);
+ int used = rs.used > INT_MAX ? INT_MAX : rs.used;
+ php_http_buffer_appendf(&neon->options.headers, "Range: bytes=%.*s" PHP_HTTP_CRLF, used - 1, rs.data);
range_req = 1;
}
php_http_buffer_dtor(&rs);
static void php_http_neon_request_dtor(php_http_request_t *h)
{
php_http_neon_request_t *ctx = h->ctx;
+ TSRMLS_FETCH_FROM_CTX(h->ts);
php_http_neon_request_reset(h);
php_http_buffer_dtor(&ctx->options.headers);
zend_hash_destroy(&ctx->options.cache);
- php_http_request_progress_dtor(&ctx->progress);
+ php_http_request_progress_dtor(&ctx->progress TSRMLS_CC);
efree(ctx);
h->ctx = NULL;
static STATUS php_http_neon_request_reset(php_http_request_t *h)
{
php_http_neon_request_t *neon = h->ctx;
+ TSRMLS_FETCH_FROM_CTX(h->ts);
php_http_buffer_reset(&neon->options.headers);
STR_SET(neon->options.useragent, NULL);
neon->options.timeout.read = 0;
neon->options.timeout.connect = 0;
- php_http_request_progress_dtor(&neon->progress);
+ php_http_request_progress_dtor(&neon->progress TSRMLS_CC);
return SUCCESS;
}
php_http_neon_request_t *neon = h->ctx;
TSRMLS_FETCH_FROM_CTX(h->ts);
- if (!(meth = php_http_request_method_name(meth_id))) {
+ if (!(meth = php_http_request_method_name(meth_id TSRMLS_CC))) {
php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_METHOD, "Unsupported request method: %d (%s)", meth, url);
return FAILURE;
}
static STATUS php_http_neon_request_setopt(php_http_request_t *h, php_http_request_setopt_opt_t opt, void *arg)
{
php_http_neon_request_t *neon = h->ctx;
+ TSRMLS_FETCH_FROM_CTX(h->ts);
switch (opt) {
case PHP_HTTP_REQUEST_OPT_SETTINGS:
PHP_HTTP_API void php_http_params_parse_default_func(void *arg, const char *key, int keylen, const char *val, int vallen TSRMLS_DC)
{
- char *kdup;
zval tmp, *entry;
HashTable *ht = (HashTable *) arg;
MAKE_STD_ZVAL(entry);
array_init(entry);
if (keylen) {
- kdup = estrndup(key, keylen);
- add_assoc_stringl_ex(entry, kdup, keylen + 1, (char *) val, vallen, 1);
- efree(kdup);
+ add_assoc_stringl_ex(entry, key, keylen + 1, estrndup(val, vallen), vallen, 0);
} else {
- add_next_index_stringl(entry, (char *) val, vallen, 1);
+ add_next_index_stringl(entry, val, vallen, 1);
}
add_next_index_zval(&tmp, entry);
} else {
- add_next_index_stringl(&tmp, (char *) key, keylen, 1);
+ add_next_index_stringl(&tmp, key, keylen, 1);
}
}
}
php_http_persistent_handle_provider_t *provider = (php_http_persistent_handle_provider_t *) p;
php_http_persistent_handle_list_t **list, *list_tmp;
HashPosition pos;
+ TSRMLS_FETCH();
FOREACH_HASH_VAL(pos, &provider->list.free, list) {
/* fix shutdown crash in PHP4 */
PHP_HTTP_API void php_http_persistent_handle_release(php_http_persistent_handle_factory_t *a, void *handle TSRMLS_DC)
{
LOCK();
- php_http_persistent_handle_do_release(a->provider, a->ident.str, a->ident.len, &handle);
+ php_http_persistent_handle_do_release(a->provider, a->ident.str, a->ident.len, &handle TSRMLS_CC);
UNLOCK();
}
memset(h, 0, sizeof(*h));
h->ops = ops;
- h->rf = rf ? rf : php_http_resource_factory_init(NULL, h->ops->rsrc, NULL, NULL TSRMLS_CC);
- h->buffer = php_http_buffer_init(NULL TSRMLS_CC);
+ h->rf = rf ? rf : php_http_resource_factory_init(NULL, h->ops->rsrc, NULL, NULL);
+ h->buffer = php_http_buffer_init(NULL);
h->parser = php_http_message_parser_init(NULL TSRMLS_CC);
h->message = php_http_message_init(NULL, 0 TSRMLS_CC);
return ret;
}
-static int apply_pretty_key(void *pDest, int num_args, va_list args, zend_hash_key *hash_key)
+static int apply_pretty_key(void *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
{
if (hash_key->arKey && hash_key->nKeyLength > 1) {
hash_key->h = zend_hash_func(php_http_pretty_key(hash_key->arKey, hash_key->nKeyLength - 1, 1, 0), hash_key->nKeyLength);
#include "php_http.h"
+#include <curl/curl.h>
#include <ext/standard/php_string.h>
#include <ext/spl/spl_iterators.h>
TSRMLS_SET_CTX(h->ts);
}
h->ops = ops;
- h->rf = rf ? rf : php_http_resource_factory_init(NULL, h->ops->rsrc, NULL, NULL TSRMLS_CC);
+ h->rf = rf ? rf : php_http_resource_factory_init(NULL, h->ops->rsrc, NULL, NULL);
if (h->ops->init) {
if (!(h = h->ops->init(h, init_arg))) {
PHP_HTTP_API void php_http_request_datashare_reset(php_http_request_datashare_t *h)
{
+ TSRMLS_FETCH_FROM_CTX(h->ts);
+
if (h->ops->reset) {
h->ops->reset(h);
} else if (h->ops->detach) {
- TSRMLS_FETCH_FROM_CTX(h->ts);
-
zend_llist_apply_with_argument(PHP_HTTP_REQUEST_DATASHARE_REQUESTS(h), detach, h TSRMLS_CC);
}
if (!o->share->persistent) {
php_http_request_datashare_free(&o->share);
}
- zend_object_std_dtor((zend_object *) o);
+ zend_object_std_dtor((zend_object *) o TSRMLS_CC);
efree(o);
}
FOREACH_HASH_KEYVAL(pos, options, key, val) {
if (key.type == HASH_KEY_IS_STRING) {
zval *newval = php_http_zsep(1, Z_TYPE_PP(val), *val);
- zend_update_property(php_http_request_factory_class_entry, getThis(), key.str, key.len - 1, newval);
+ zend_update_property(php_http_request_factory_class_entry, getThis(), key.str, key.len - 1, newval TSRMLS_CC);
zval_ptr_dtor(&newval);
}
}
(php_http_resource_factory_handle_dtor_t) php_http_persistent_handle_release
};
- rf = php_http_resource_factory_init(NULL, &ops, pf, (void (*)(void *)) php_http_persistent_handle_abandon TSRMLS_CC);
+ rf = php_http_resource_factory_init(NULL, &ops, pf, (void (*)(void *)) php_http_persistent_handle_abandon);
}
efree(name_str);
(php_http_resource_factory_handle_dtor_t) php_http_persistent_handle_release
};
- rf = php_http_resource_factory_init(NULL, &ops, pf, (void (*)(void *)) php_http_persistent_handle_abandon TSRMLS_CC);
+ rf = php_http_resource_factory_init(NULL, &ops, pf, (void (*)(void *)) php_http_persistent_handle_abandon);
}
efree(name_str);
(php_http_resource_factory_handle_dtor_t) php_http_persistent_handle_release
};
- rf = php_http_resource_factory_init(NULL, &ops, pf, (void (*)(void *)) php_http_persistent_handle_abandon TSRMLS_CC);
+ rf = php_http_resource_factory_init(NULL, &ops, pf, (void (*)(void *)) php_http_persistent_handle_abandon);
}
efree(name_str);
PHP_HTTP_STRLIST_STOP
;
-PHP_HTTP_API const char *php_http_request_method_name(php_http_request_method_t meth)
+PHP_HTTP_API const char *php_http_request_method_name(php_http_request_method_t meth TSRMLS_DC)
{
if (meth > PHP_HTTP_NO_REQUEST_METHOD && meth < PHP_HTTP_MAX_REQUEST_METHOD) {
return php_http_strlist_find(php_http_request_methods, 0, meth);
PHP_HTTP_MAX_REQUEST_METHOD = 28
} php_http_request_method_t;
-PHP_HTTP_API const char *php_http_request_method_name(php_http_request_method_t meth);
+PHP_HTTP_API const char *php_http_request_method_name(php_http_request_method_t meth TSRMLS_DC);
PHP_HTTP_API STATUS php_http_request_method_register(const char *meth_str, size_t meth_len, long *id TSRMLS_DC);
extern zend_class_entry *php_http_request_method_class_entry;
memset(h, 0, sizeof(*h));
h->ops = ops;
- h->rf = rf ? rf : php_http_resource_factory_init(NULL, h->ops->rsrc, NULL, NULL TSRMLS_CC);
+ h->rf = rf ? rf : php_http_resource_factory_init(NULL, h->ops->rsrc, NULL, NULL);
zend_llist_init(&h->requests.attached, sizeof(zval *), (llist_dtor_func_t) ZVAL_PTR_DTOR, 0);
zend_llist_init(&h->requests.finished, sizeof(zval *), (llist_dtor_func_t) ZVAL_PTR_DTOR, 0);
TSRMLS_SET_CTX(h->ts);
php_http_message_body_t *body = NULL;
php_http_request_object_t *obj = zend_object_store_get_object(request TSRMLS_CC);
- if (SUCCESS != php_http_request_object_requesthandler(obj, request, &m, &url, &body)) {
+ if (SUCCESS != php_http_request_object_requesthandler(obj, request, &m, &url, &body TSRMLS_CC)) {
return FAILURE;
}
if (SUCCESS == h->ops->attach(h, obj->request, m, url, body)) {
PHP_HTTP_API STATUS php_http_request_pool_exec(php_http_request_pool_t *h)
{
- TSRMLS_FETCH_FROM_CTX(h->ts);
-
if (h->ops->exec) {
return h->ops->exec(h);
}
php_http_buffer_append(qstr, pre_encoded_data, pre_encoded_len);
}
- if (SUCCESS != php_http_url_encode_hash_recursive(hash, qstr, arg_sep, arg_sep_len, NULL, 0)) {
+ if (SUCCESS != php_http_url_encode_hash_recursive(hash, qstr, arg_sep, arg_sep_len, NULL, 0 TSRMLS_CC)) {
php_http_buffer_free(&qstr);
return FAILURE;
}