- ditch TSRMLS_FETCH() occurences
authorMichael Wallner <mike@php.net>
Wed, 7 Sep 2005 18:45:35 +0000 (18:45 +0000)
committerMichael Wallner <mike@php.net>
Wed, 7 Sep 2005 18:45:35 +0000 (18:45 +0000)
KnownIssues.txt
http.c
http_api.c
http_message_object.c
http_request_api.c
http_request_pool_api.c
php_http_api.h
php_http_request_api.h
php_http_std_defs.h

index e448c975276e8ffa951356815f6d198d42d71c22..53b3222e288eec62429e493932b4ce9d120150f5 100644 (file)
@@ -4,3 +4,4 @@ $Id$
 
 HttpResponse class is only available for PHP >= 5.1
 
 
 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 8d65cd155ea50d3a7f0803eb5f8acedbd08a502c..b1039ade5fa4024e3cb741a5afa0aaa5905436eb 100644 (file)
--- 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);
 #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
 }
 
 #endif
 }
 
index 8bbb34ac785fd6cd636b664628c15e99bf84ec4f..f59a7d0a75cf2d7fd7561b624d2068ff9406d840 100644 (file)
@@ -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(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;
 {
        va_list args;
-       TSRMLS_FETCH();
        
        va_start(args, format);
 #ifdef ZEND_ENGINE_2
        
        va_start(args, format);
 #ifdef ZEND_ENGINE_2
index 3161b01f0652e8eae925f60a295b0173cf6ebb72..7e04bf0537994cd7d3125c8d07e9d00a62b225ba 100644 (file)
@@ -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)) {
        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);
        }
 
                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)) {
        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))
        }
 
        switch (zend_get_hash_value(Z_STRVAL_P(member), Z_STRLEN_P(member) + 1))
index 3aba703820fc8f0d6484f29d3f8ce83af12b269c..aac75b3d217a2d213f29c21165338bdbd7755448 100644 (file)
@@ -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; }
 
 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)
 
 /* {{{ 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)
 {
 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)
 {
 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);
        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);
        }
        } 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:
                        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;
 
                                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)
 {
 /* {{{ 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;
        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)
 {
 /* {{{ 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;
 
        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;
 /* {{{ 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] = &params_local[0];
        params_pass[1] = &params_local[1];
 
        params_pass[0] = &params_local[0];
        params_pass[1] = &params_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)
 {
 /* {{{ 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)
        {
 
        switch (type)
        {
index 282fda9ed2df25b2becac2c64ccd09e617642fb0..b78e354174ab5e358195a662bd265499cd123bfe 100644 (file)
@@ -40,7 +40,7 @@ ZEND_EXTERN_MODULE_GLOBALS(http);
 #      define curl_multi_strerror(dummy) "unknown error"
 #endif
 
 #      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 *) */
 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);
 
        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
 #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 {
        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);
                        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;
                        }
                }
                                return SUCCESS;
                        }
                }
+               efree(body->data);
                efree(body);
        }
        return FAILURE;
                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);
 }
 /* }}} */
 
 }
 /* }}} */
 
index 42a99e0adff6c013a3f7fd51e8882770fb5c48e3..32ceed6986c173f703f3ca2206d1983308df621f 100644 (file)
@@ -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
 
 #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);
 
 #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);
index 202bb0b9d8f5e91f9fe144106193bf0bcd1480fb..3b773a3edbb939ba9d036449d7f81ef31526be68 100644 (file)
@@ -42,13 +42,24 @@ typedef struct {
 typedef struct {
        void ***tsrm_ctx;
        void *data;
 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;
 
 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
 
 #define COPY_STRING            1
 #define        COPY_SLIST              2
index 4aa0aa43d213330011df953090c0c7e0ca7225b2..e16c8454e7c5dc1eef434995edca85e7d8b080a8 100644 (file)
@@ -271,17 +271,16 @@ typedef int STATUS;
 #ifndef E_THROW
 #      define E_THROW 0
 #endif
 #ifndef E_THROW
 #      define E_THROW 0
 #endif
-#define HE_THROW       E_THROW
 #ifdef ZEND_ENGINE_2
 #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
 #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
 #endif
 
 #define HTTP_E_RUNTIME                         1L