From: Michael Wallner Date: Wed, 7 Sep 2005 18:45:35 +0000 (+0000) Subject: - ditch TSRMLS_FETCH() occurences X-Git-Tag: RELEASE_0_13_0~14 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=b0919f33875667baecb05888fba006d5652d68d1;p=m6w6%2Fext-http - ditch TSRMLS_FETCH() occurences --- diff --git a/KnownIssues.txt b/KnownIssues.txt index e448c97..53b3222 100644 --- a/KnownIssues.txt +++ b/KnownIssues.txt @@ -4,3 +4,4 @@ $Id$ HttpResponse class is only available for PHP >= 5.1 +Not all places where files are handled check for open_basedir and/or safe_mode. diff --git a/http.c b/http.c index 8d65cd1..b1039ad 100644 --- a/http.c +++ b/http.c @@ -150,8 +150,8 @@ static inline void http_globals_init(zend_http_globals *G) #ifdef HTTP_HAVE_CURL zend_llist_init(&G->request.copies.strings, sizeof(char *), http_request_data_free_string, 0); zend_llist_init(&G->request.copies.slists, sizeof(struct curl_slist *), http_request_data_free_slist, 0); - zend_llist_init(&G->request.copies.contexts, sizeof(http_curl_callback_ctx *), http_request_data_free_context, 0); - zend_llist_init(&G->request.copies.convs, sizeof(http_curl_conv *), http_request_data_free_conv, 0); + zend_llist_init(&G->request.copies.contexts, sizeof(http_request_callback_ctx *), http_request_data_free_context, 0); + zend_llist_init(&G->request.copies.convs, sizeof(http_request_conv *), http_request_data_free_conv, 0); #endif } diff --git a/http_api.c b/http_api.c index 8bbb34a..f59a7d0 100644 --- a/http_api.c +++ b/http_api.c @@ -164,10 +164,9 @@ STATUS _http_parse_key_list(const char *list, HashTable *items, char separator, /* }}} */ /* {{{ void http_error(long, long, char*) */ -void _http_error_ex(long type, long code, const char *format, ...) +void _http_error_ex(long type TSRMLS_DC, long code, const char *format, ...) { va_list args; - TSRMLS_FETCH(); va_start(args, format); #ifdef ZEND_ENGINE_2 diff --git a/http_message_object.c b/http_message_object.c index 3161b01..7e04bf0 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -234,7 +234,7 @@ static zval *_http_message_object_read_prop(zval *object, zval *member, int type fprintf(stderr, "Read HttpMessage::$%s\n", Z_STRVAL_P(member)); #endif if (!EG(scope) || !instanceof_function(EG(scope), obj->zo.ce TSRMLS_CC)) { - zend_error(HE_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); + zend_error(E_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); return EG(uninitialized_zval_ptr); } @@ -325,7 +325,7 @@ static void _http_message_object_write_prop(zval *object, zval *member, zval *va fprintf(stderr, "Write HttpMessage::$%s\n", Z_STRVAL_P(member)); #endif if (!EG(scope) || !instanceof_function(EG(scope), obj->zo.ce TSRMLS_CC)) { - zend_error(HE_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); + zend_error(E_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); } switch (zend_get_hash_value(Z_STRVAL_P(member), Z_STRLEN_P(member) + 1)) diff --git a/http_request_api.c b/http_request_api.c index 3aba703..aac75b3 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -108,14 +108,22 @@ static int http_curl_progress_callback(void *, double, double, double, double); static int http_curl_raw_callback(CURL *, curl_infotype, char *, size_t, void *); static int http_curl_dummy_callback(char *data, size_t n, size_t l, void *s) { return n*l; } -#define HTTP_CURL_CALLBACK_DATA(from, type, var) \ - http_curl_callback_ctx *__CTX = (http_curl_callback_ctx *) (from); \ - TSRMLS_FETCH_FROM_CTX(__CTX->tsrm_ctx); \ - type (var) = (type) (__CTX->data) - -#define http_curl_callback_data(data) _http_curl_callback_data((data) TSRMLS_CC) -static http_curl_callback_ctx *_http_curl_callback_data(void *data TSRMLS_DC); +/* {{{ http_request_callback_ctx http_request_callback_data(void *) */ +http_request_callback_ctx *_http_request_callback_data_ex(void *data, zend_bool cpy TSRMLS_DC) +{ + http_request_callback_ctx *ctx = emalloc(sizeof(http_request_callback_ctx)); + + TSRMLS_SET_CTX(ctx->tsrm_ctx); + ctx->data = data; + + if (cpy) { + return http_request_data_copy(COPY_CONTEXT, ctx); + } else { + return ctx; + } +} +/* }}} */ /* {{{ void *http_request_data_copy(int, void *) */ void *_http_request_data_copy(int type, void *data TSRMLS_DC) @@ -169,17 +177,17 @@ void _http_request_data_free_slist(void *list) } /* }}} */ -/* {{{ _http_request_data_free_context(http_curl_callback_ctx **) */ +/* {{{ _http_request_data_free_context(http_request_callback_ctx **) */ void _http_request_data_free_context(void *context) { - efree(*((http_curl_callback_ctx **) context)); + efree(*((http_request_callback_ctx **) context)); } /* }}} */ -/* {{{ _http_request_data_free_conv(http_curl_conv **) */ +/* {{{ _http_request_data_free_conv(http_request_conv **) */ void _http_request_data_free_conv(void *conv) { - efree(*((http_curl_conv **) conv)); + efree(*((http_request_conv **) conv)); } /* }}} */ @@ -339,7 +347,7 @@ PHP_HTTP_API STATUS _http_request_init(CURL *ch, http_request_method meth, char if (zoption = http_curl_getopt(options, "onprogress", 0)) { HTTP_CURL_OPT(NOPROGRESS, 0); HTTP_CURL_OPT(PROGRESSFUNCTION, http_curl_progress_callback); - HTTP_CURL_OPT(PROGRESSDATA, http_curl_callback_data(zoption)); + HTTP_CURL_OPT(PROGRESSDATA, http_request_callback_data(zoption)); } else { HTTP_CURL_OPT(NOPROGRESS, 1); } @@ -614,7 +622,7 @@ PHP_HTTP_API STATUS _http_request_init(CURL *ch, http_request_method meth, char break; case HTTP_REQUEST_BODY_UPLOADFILE: - curl_easy_setopt(ch, CURLOPT_READDATA, http_curl_callback_data(body)); + curl_easy_setopt(ch, CURLOPT_READDATA, http_request_callback_data(body)); curl_easy_setopt(ch, CURLOPT_INFILESIZE, body->size); break; @@ -633,11 +641,11 @@ PHP_HTTP_API STATUS _http_request_init(CURL *ch, http_request_method meth, char /* {{{ void http_request_conv(CURL *, phpstr *, phpstr *) */ void _http_request_conv(CURL *ch, phpstr* response, phpstr *request TSRMLS_DC) { - http_curl_conv *conv = emalloc(sizeof(http_curl_conv)); + http_request_conv *conv = emalloc(sizeof(http_request_conv)); conv->response = response; conv->request = request; conv->last_info = -1; - HTTP_CURL_OPT(DEBUGDATA, http_curl_callback_data(http_request_data_copy(COPY_CONV, conv))); + HTTP_CURL_OPT(DEBUGDATA, http_request_callback_data(http_request_data_copy(COPY_CONV, conv))); } /* }}} */ @@ -742,7 +750,7 @@ PHP_HTTP_API STATUS _http_request_ex(CURL *ch, http_request_method meth, char *u /* {{{ static size_t http_curl_read_callback(void *, size_t, size_t, void *) */ static size_t http_curl_read_callback(void *data, size_t len, size_t n, void *s) { - HTTP_CURL_CALLBACK_DATA(s, http_request_body *, body); + HTTP_REQUEST_CALLBACK_DATA(s, http_request_body *, body); if (body->type != HTTP_REQUEST_BODY_UPLOADFILE) { return 0; @@ -751,21 +759,11 @@ static size_t http_curl_read_callback(void *data, size_t len, size_t n, void *s) } /* }}} */ -/* {{{ http_curl_callback_ctx http_curl_callback_data(void *) */ -static http_curl_callback_ctx *_http_curl_callback_data(void *data TSRMLS_DC) -{ - http_curl_callback_ctx *ctx = emalloc(sizeof(http_curl_callback_ctx)); - TSRMLS_SET_CTX(ctx->tsrm_ctx); - ctx->data = data; - return http_request_data_copy(COPY_CONTEXT, ctx); -} -/* }}} */ - /* {{{ static int http_curl_progress_callback(void *, double, double, double, double) */ static int http_curl_progress_callback(void *data, double dltotal, double dlnow, double ultotal, double ulnow) { zval *params_pass[4], params_local[4], retval; - HTTP_CURL_CALLBACK_DATA(data, zval *, func); + HTTP_REQUEST_CALLBACK_DATA(data, zval *, func); params_pass[0] = ¶ms_local[0]; params_pass[1] = ¶ms_local[1]; @@ -788,7 +786,7 @@ static int http_curl_progress_callback(void *data, double dltotal, double dlnow, /* {{{ static int http_curl_raw_callback(CURL *, curl_infotype, char *, size_t, void *) */ static int http_curl_raw_callback(CURL *ch, curl_infotype type, char *data, size_t length, void *ctx) { - HTTP_CURL_CALLBACK_DATA(ctx, http_curl_conv *, conv); + HTTP_REQUEST_CALLBACK_DATA(ctx, http_request_conv *, conv); switch (type) { diff --git a/http_request_pool_api.c b/http_request_pool_api.c index 282fda9..b78e354 100644 --- a/http_request_pool_api.c +++ b/http_request_pool_api.c @@ -40,7 +40,7 @@ ZEND_EXTERN_MODULE_GLOBALS(http); # define curl_multi_strerror(dummy) "unknown error" #endif -static void http_request_pool_freebody(http_request_body **body); +static void http_request_pool_freebody(http_request_callback_ctx **body); static int http_request_pool_compare_handles(void *h1, void *h2); /* {{{ http_request_pool *http_request_pool_init(http_request_pool *) */ @@ -67,7 +67,7 @@ PHP_HTTP_API http_request_pool *_http_request_pool_init(http_request_pool *pool pool->unfinished = 0; zend_llist_init(&pool->handles, sizeof(zval *), (llist_dtor_func_t) ZVAL_PTR_DTOR, 0); - zend_llist_init(&pool->bodies, sizeof(http_request_body *), (llist_dtor_func_t) http_request_pool_freebody, 0); + zend_llist_init(&pool->bodies, sizeof(http_request_callback_ctx *), (llist_dtor_func_t) http_request_pool_freebody, 0); #if HTTP_DEBUG_REQPOOLS fprintf(stderr, "Initialized request pool %p\n", pool); #endif @@ -85,9 +85,9 @@ PHP_HTTP_API STATUS _http_request_pool_attach(http_request_pool *pool, zval *req if (req->pool) { http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "HttpRequest object(#%d) is already member of %s HttpRequestPool", Z_OBJ_HANDLE_P(request), req->pool == pool ? "this" : "another"); } else { - http_request_body *body = http_request_body_new(); + http_request_callback_ctx *body = http_request_callback_data_ex(http_request_body_new(), 0); - if (SUCCESS != http_request_pool_requesthandler(request, body)) { + if (SUCCESS != http_request_pool_requesthandler(request, body->data)) { http_error_ex(HE_WARNING, HTTP_E_REQUEST, "Could not initialize HttpRequest object for attaching to the HttpRequestPool"); } else { CURLMcode code = curl_multi_add_handle(pool->ch, req->ch); @@ -109,6 +109,7 @@ PHP_HTTP_API STATUS _http_request_pool_attach(http_request_pool *pool, zval *req return SUCCESS; } } + efree(body->data); efree(body); } return FAILURE; @@ -264,11 +265,12 @@ void _http_request_pool_responsehandler(zval **req TSRMLS_DC) /*#*/ -/* {{{ static void http_request_pool_freebody(http_request_body **) */ -static void http_request_pool_freebody(http_request_body **body) +/* {{{ static void http_request_pool_freebody(http_request_ctx **) */ +static void http_request_pool_freebody(http_request_callback_ctx **body) { - TSRMLS_FETCH(); - http_request_body_free(*body); + HTTP_REQUEST_CALLBACK_DATA(*body, http_request_body *, b); + http_request_body_free(b); + efree(*body); } /* }}} */ diff --git a/php_http_api.h b/php_http_api.h index 42a99e0..32ceed6 100644 --- a/php_http_api.h +++ b/php_http_api.h @@ -34,7 +34,7 @@ extern STATUS _http_parse_key_list(const char *list, HashTable *items, char sepa #define http_error(type, code, string) _http_error_ex(type, code, "%s", string) #define http_error_ex _http_error_ex -extern void _http_error_ex(long type, long code, const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4); +extern void _http_error_ex(long type TSRMLS_DC, long code, const char *format, ...); #define http_log(f, i, m) _http_log_ex((f), (i), (m) TSRMLS_CC) extern void http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC); diff --git a/php_http_request_api.h b/php_http_request_api.h index 202bb0b..3b773a3 100644 --- a/php_http_request_api.h +++ b/php_http_request_api.h @@ -42,13 +42,24 @@ typedef struct { typedef struct { void ***tsrm_ctx; void *data; -} http_curl_callback_ctx; +} http_request_callback_ctx; typedef struct { phpstr *response; phpstr *request; curl_infotype last_info; -} http_curl_conv; +} http_request_conv; + + +#define HTTP_REQUEST_CALLBACK_DATA(from, type, var) \ + http_request_callback_ctx *__CTX = (http_request_callback_ctx *) (from); \ + TSRMLS_FETCH_FROM_CTX(__CTX->tsrm_ctx); \ + type (var) = (type) (__CTX->data) + +#define http_request_callback_data(data) _http_request_callback_data_ex((data), 1 TSRMLS_CC) +#define http_request_callback_data_ex(data, copy) _http_request_callback_data_ex((data), (copy) TSRMLS_CC) +extern http_request_callback_ctx *_http_request_callback_data_ex(void *data, zend_bool cpy TSRMLS_DC); + #define COPY_STRING 1 #define COPY_SLIST 2 diff --git a/php_http_std_defs.h b/php_http_std_defs.h index 4aa0aa4..e16c845 100644 --- a/php_http_std_defs.h +++ b/php_http_std_defs.h @@ -271,17 +271,16 @@ typedef int STATUS; #ifndef E_THROW # define E_THROW 0 #endif -#define HE_THROW E_THROW #ifdef ZEND_ENGINE_2 -# define HE_THROW E_THROW -# define HE_NOTICE (HTTP_G(only_exceptions) ? E_THROW : E_NOTICE) -# define HE_WARNING (HTTP_G(only_exceptions) ? E_THROW : E_WARNING) -# define HE_ERROR (HTTP_G(only_exceptions) ? E_THROW : E_ERROR) +# define HE_THROW E_THROW TSRMLS_CC +# define HE_NOTICE (HTTP_G(only_exceptions) ? E_THROW : E_NOTICE) TSRMLS_CC +# define HE_WARNING (HTTP_G(only_exceptions) ? E_THROW : E_WARNING) TSRMLS_CC +# define HE_ERROR (HTTP_G(only_exceptions) ? E_THROW : E_ERROR) TSRMLS_CC #else -# define HE_THROW E_WARNING -# define HE_NOTICE E_NOTICE -# define HE_WARNING E_WARNING -# define HE_ERROR E_ERROR +# define HE_THROW E_WARNING TSRMLS_CC +# define HE_NOTICE E_NOTICE TSRMLS_CC +# define HE_WARNING E_WARNING TSRMLS_CC +# define HE_ERROR E_ERROR TSRMLS_CC #endif #define HTTP_E_RUNTIME 1L