- implement more of those useful allocation relays
authorMichael Wallner <mike@php.net>
Tue, 13 Dec 2005 11:04:17 +0000 (11:04 +0000)
committerMichael Wallner <mike@php.net>
Tue, 13 Dec 2005 11:04:17 +0000 (11:04 +0000)
- extend http_request_body API
- adjust http_request_objects usage of http_request

http_functions.c
http_message_api.c
http_request_api.c
http_request_body_api.c
http_request_object.c
http_request_pool_api.c
php_http_message_api.h
php_http_request_api.h
php_http_request_body_api.h
php_http_request_object.h
tests/exceptions.phpt

index 0231946501e01fa24777e9062cdfde2fe488b896..279e4ea02e97777d76feb1a820944bd9b9dd0f11 100644 (file)
@@ -1161,12 +1161,8 @@ PHP_FUNCTION(http_post_data)
 
        RETVAL_FALSE;
 
-       body.type = HTTP_REQUEST_BODY_CSTRING;
-       body.data = postdata;
-       body.size = postdata_len;
-
        http_request_init_ex(&request, NULL, HTTP_POST, URL);
-       request.body = &body;
+       request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_CSTRING, postdata, postdata_len, 0);
        if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
                http_request_exec(&request);
                if (info) {
@@ -1174,7 +1170,6 @@ PHP_FUNCTION(http_post_data)
                }
                RETVAL_RESPONSE_OR_BODY(request);
        }
-       request.body = NULL;
        http_request_dtor(&request);
 }
 /* }}} */
@@ -1200,7 +1195,7 @@ PHP_FUNCTION(http_post_fields)
                RETURN_FALSE;
        }
 
-       if (SUCCESS != http_request_body_fill(&body, Z_ARRVAL_P(fields), files ? Z_ARRVAL_P(files) : NULL)) {
+       if (!http_request_body_fill(&body, Z_ARRVAL_P(fields), files ? Z_ARRVAL_P(files) : NULL)) {
                RETURN_FALSE;
        }
 
@@ -1215,14 +1210,11 @@ PHP_FUNCTION(http_post_fields)
        request.body = &body;
        if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
                http_request_exec(&request);
-               http_request_body_dtor(&body);
                if (info) {
                        http_request_info(&request, Z_ARRVAL_P(info));
                }
                RETVAL_RESPONSE_OR_BODY(request);
        }
-       http_request_body_dtor(&body);
-       request.body = NULL;
        http_request_dtor(&request);
 }
 /* }}} */
index 01aa0e316110c56f47b403538ffdbb91fb4fe925..cd9a9514655f7107fcc5a0ed5c6fdd355086a04d 100644 (file)
@@ -84,10 +84,10 @@ static inline void _http_message_init_type(http_message *message, http_message_t
        }
 }
 
-PHP_HTTP_API http_message *_http_message_init_ex(http_message *message, http_message_type type)
+PHP_HTTP_API http_message *_http_message_init_ex(http_message *message, http_message_type type ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
 {
        if (!message) {
-               message = ecalloc(1, sizeof(http_message));
+               message = ecalloc_rel(1, sizeof(http_message));
        }
 
        http_message_init_type(message, type);
@@ -125,7 +125,7 @@ PHP_HTTP_API void _http_message_set_type(http_message *message, http_message_typ
        }
 }
 
-PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char *message, size_t message_length TSRMLS_DC)
+PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char *message, size_t message_length ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
 {
        const char *body = NULL;
        zend_bool free_msg = msg ? 0 : 1;
@@ -529,14 +529,13 @@ PHP_HTTP_API STATUS _http_message_send(http_message *message TSRMLS_DC)
                        }
 
                        if ((request.meth = http_request_method_exists(1, 0, message->http.info.request.method))) {
-                               http_request_body body = {HTTP_REQUEST_BODY_CSTRING, PHPSTR_VAL(message), PHPSTR_LEN(message)};
+                               http_request_body body;
                                
                                http_request_init_ex(&request, NULL, request.meth, uri);
-                               request.body = &body;
+                               request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_CSTRING, PHPSTR_VAL(message), PHPSTR_LEN(message), 0);
                                if (SUCCESS == (rs = http_request_prepare(&request, NULL))) {
                                        http_request_exec(&request);
                                }
-                               request.body = NULL;
                                http_request_dtor(&request);
                        } else {
                                http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD,
index 42a1199bc8377537b18a74c41f2d0eea71e3d06e..15740732bd33d3cfe48069dbbb91b3e68b4a6ee8 100644 (file)
@@ -202,14 +202,14 @@ static curlioerr http_curl_ioctl_callback(CURL *, curliocmd, void *);
 /* }}} */
 
 /* {{{ http_request *http_request_init(http_request *) */
-PHP_HTTP_API http_request *_http_request_init_ex(http_request *request, CURL *ch, http_request_method meth, const char *url TSRMLS_DC)
+PHP_HTTP_API http_request *_http_request_init_ex(http_request *request, CURL *ch, http_request_method meth, const char *url ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
 {
        http_request *r;
        
        if (request) {
                r = request;
        } else {
-               r = emalloc(sizeof(http_request));
+               r = emalloc_rel(sizeof(http_request));
        }
        memset(r, 0, sizeof(http_request));
        
@@ -222,7 +222,7 @@ PHP_HTTP_API http_request *_http_request_init_ex(http_request *request, CURL *ch
        phpstr_init(&r->_cache.cookies);
        zend_hash_init(&r->_cache.options, 0, NULL, ZVAL_PTR_DTOR, 0);
        
-       TSRMLS_SET_CTX(request->tsrm_ls);
+       TSRMLS_SET_CTX(r->tsrm_ls);
        
        return r;
 }
@@ -263,6 +263,7 @@ PHP_HTTP_API void _http_request_free(http_request **request)
 {
        if (*request) {
                TSRMLS_FETCH_FROM_CTX((*request)->tsrm_ls);
+               http_request_body_free(&(*request)->body);
                http_request_dtor(*request);
                efree(*request);
                *request = NULL;
@@ -278,7 +279,7 @@ PHP_HTTP_API void _http_request_reset(http_request *request)
        request->conv.last_type = 0;
        phpstr_dtor(&request->conv.request);
        phpstr_dtor(&request->conv.response);
-       http_request_body_free(&request->body);
+       http_request_body_dtor(request->body);
 }
 /* }}} */
 
index 423dda00aa77e8b23ad72c42efca7df077fa1807..467726bd84fccb90542416f32092ebb656b6106a 100644 (file)
 ZEND_EXTERN_MODULE_GLOBALS(http);
 
 /* {{{ http_request_body *http_request_body_new() */
-PHP_HTTP_API http_request_body *_http_request_body_new(ZEND_FILE_LINE_D ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
+PHP_HTTP_API http_request_body *_http_request_body_init_ex(http_request_body *body, int type, void *data, size_t size, zend_bool free ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
 {
-       return (http_request_body *) ecalloc_rel(1, sizeof(http_request_body));
+       if (!body) {
+               body = emalloc_rel(sizeof(http_request_body));
+       }
+       
+       body->type = type;
+       body->free = free;
+       body->data = data;
+       body->size = size;
+       
+       return body;
 }
 /* }}} */
 
-/* {{{ STATUS http_request_body_fill(http_request_body *body, HashTable *, HashTable *) */
-PHP_HTTP_API STATUS _http_request_body_fill(http_request_body *body, HashTable *fields, HashTable *files TSRMLS_DC)
+/* {{{ http_request_body *http_request_body_fill(http_request_body *body, HashTable *, HashTable *) */
+PHP_HTTP_API http_request_body *_http_request_body_fill(http_request_body *body, HashTable *fields, HashTable *files ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
 {
        if (files && (zend_hash_num_elements(files) > 0)) {
                char *key = NULL;
@@ -65,7 +74,7 @@ PHP_HTTP_API STATUS _http_request_body_fill(http_request_body *body, HashTable *
                                if (CURLE_OK != err) {
                                        http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not encode post fields: %s", curl_easy_strerror(err));
                                        curl_formfree(http_post_data[0]);
-                                       return FAILURE;
+                                       return NULL;
                                }
 
                                /* reset */
@@ -93,14 +102,12 @@ PHP_HTTP_API STATUS _http_request_body_fill(http_request_body *body, HashTable *
                                if (CURLE_OK != err) {
                                        http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not encode post files: %s", curl_easy_strerror(err));
                                        curl_formfree(http_post_data[0]);
-                                       return FAILURE;
+                                       return NULL;
                                }
                        }
                }
-
-               body->type = HTTP_REQUEST_BODY_CURLPOST;
-               body->data = http_post_data[0];
-               body->size = 0;
+               
+               return http_request_body_init_ex(body, HTTP_REQUEST_BODY_CURLPOST, http_post_data[0], 0, 1);
 
        } else {
                char *encoded;
@@ -108,22 +115,18 @@ PHP_HTTP_API STATUS _http_request_body_fill(http_request_body *body, HashTable *
 
                if (SUCCESS != http_urlencode_hash_ex(fields, 1, NULL, 0, &encoded, &encoded_len)) {
                        http_error(HE_WARNING, HTTP_E_ENCODING, "Could not encode post data");
-                       return FAILURE;
+                       return NULL;
                }
-
-               body->type = HTTP_REQUEST_BODY_CSTRING;
-               body->data = encoded;
-               body->size = encoded_len;
+               
+               return http_request_body_init_ex(body, HTTP_REQUEST_BODY_CSTRING, encoded, encoded_len, 1);
        }
-
-       return SUCCESS;
 }
 /* }}} */
 
 /* {{{ void http_request_body_dtor(http_request_body *) */
 PHP_HTTP_API void _http_request_body_dtor(http_request_body *body TSRMLS_DC)
 {
-       if (body) {
+       if (body && body->free) {
                switch (body->type)
                {
                        case HTTP_REQUEST_BODY_CSTRING:
index ea4e9f64563a7ed7253e0262c5cdb67817811ac8..8d6e798ebefc95e2a4ac2089c380df375a3142a4 100644 (file)
@@ -306,7 +306,7 @@ zend_object_value _http_request_object_new_ex(zend_class_entry *ce, CURL *ch, ht
 
        o = ecalloc(1, sizeof(http_request_object));
        o->zo.ce = ce;
-       http_request_init_ex(&o->request, ch, 0, NULL);
+       o->request = http_request_init_ex(NULL, ch, 0, NULL);
        phpstr_init(&o->history);
        
        if (ptr) {
@@ -331,12 +331,12 @@ zend_object_value _http_request_object_clone_obj(zval *this_ptr TSRMLS_DC)
        getObject(http_request_object, old_obj);
        
        old_zo = zend_objects_get_address(this_ptr TSRMLS_CC);
-       new_ov = http_request_object_new_ex(old_zo->ce, curl_easy_duphandle(old_obj->request.ch), &new_obj);
+       new_ov = http_request_object_new_ex(old_zo->ce, curl_easy_duphandle(old_obj->request->ch), &new_obj);
        
        zend_objects_clone_members(&new_obj->zo, new_ov, old_zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
        phpstr_append(&new_obj->history, old_obj->history.data, old_obj->history.used);
-       phpstr_append(&new_obj->request.conv.request, old_obj->request.conv.request.data, old_obj->request.conv.request.used);
-       phpstr_append(&new_obj->request.conv.response, old_obj->request.conv.response.data, old_obj->request.conv.response.used);
+       phpstr_append(&new_obj->request->conv.request, old_obj->request->conv.request.data, old_obj->request->conv.request.used);
+       phpstr_append(&new_obj->request->conv.response, old_obj->request->conv.response.data, old_obj->request->conv.response.used);
        
        return new_ov;
 }
@@ -417,7 +417,7 @@ void _http_request_object_free(zend_object *object TSRMLS_DC)
                zend_hash_destroy(OBJ_PROP(o));
                FREE_HASHTABLE(OBJ_PROP(o));
        }
-       http_request_dtor(&o->request);
+       http_request_free(&o->request);
        phpstr_dtor(&o->history);
        efree(o);
 }
@@ -427,20 +427,20 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
        zval *URL, *URL_p, *meth_p;
        STATUS status = SUCCESS;
 
-       http_request_reset(&obj->request);
-       HTTP_CHECK_CURL_INIT(obj->request.ch, curl_easy_init(), return FAILURE);
+       http_request_reset(obj->request);
+       HTTP_CHECK_CURL_INIT(obj->request->ch, curl_easy_init(), return FAILURE);
        
        URL = convert_to_type_ex(IS_STRING, GET_PROP(obj, url), &URL_p);
-       obj->request.url = http_absolute_uri_ex(Z_STRVAL_P(URL), Z_STRLEN_P(URL), NULL, 0, NULL, 0, 0);
+       obj->request->url = http_absolute_uri_ex(Z_STRVAL_P(URL), Z_STRLEN_P(URL), NULL, 0, NULL, 0, 0);
        if (URL_p) {
                zval_ptr_dtor(&URL_p);
        }
        
-       if (!obj->request.url) {
+       if (!obj->request->url) {
                return FAILURE;
        }
        
-       switch (obj->request.meth = Z_LVAL_P(convert_to_type_ex(IS_LONG, GET_PROP(obj, method), &meth_p)))
+       switch (obj->request->meth = Z_LVAL_P(convert_to_type_ex(IS_LONG, GET_PROP(obj, method), &meth_p)))
        {
                case HTTP_GET:
                case HTTP_HEAD:
@@ -452,10 +452,7 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
                        php_stream *stream = php_stream_open_wrapper(Z_STRVAL_P(GET_PROP(obj, putFile)), "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL);
                        
                        if (stream && !php_stream_stat(stream, &ssb)) {
-                               obj->request.body = http_request_body_new();
-                               obj->request.body->type = HTTP_REQUEST_BODY_UPLOADFILE;
-                               obj->request.body->data = stream;
-                               obj->request.body->size = ssb.sb.st_size;
+                               http_request_body_init_ex(obj->request->body, HTTP_REQUEST_BODY_UPLOADFILE, stream, ssb.sb.st_size, 1);
                        } else {
                                status = FAILURE;
                        }
@@ -468,7 +465,6 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
                        /* check for raw post data */
                        zval *raw_data_p, *raw_data = convert_to_type_ex(IS_STRING, GET_PROP(obj, rawPostData), &raw_data_p);
                        
-                       obj->request.body = http_request_body_new();
                        if (Z_STRLEN_P(raw_data)) {
                                zval *ctype_p, *ctype = convert_to_type_ex(IS_STRING, GET_PROP(obj, contentType), &ctype_p);
                                
@@ -499,11 +495,24 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
                                        zval_ptr_dtor(&ctype_p);
                                }
                                
-                               obj->request.body->type = HTTP_REQUEST_BODY_CSTRING;
-                               obj->request.body->data = estrndup(Z_STRVAL_P(raw_data), Z_STRLEN_P(raw_data));
-                               obj->request.body->size = Z_STRLEN_P(raw_data);
+                               obj->request->body = http_request_body_init_ex(obj->request->body, HTTP_REQUEST_BODY_CSTRING,
+                                       estrndup(Z_STRVAL_P(raw_data), Z_STRLEN_P(raw_data)), Z_STRLEN_P(raw_data), 1);
+                               
                        } else {
-                               status = http_request_body_fill(obj->request.body, Z_ARRVAL_P(GET_PROP(obj, postFields)), Z_ARRVAL_P(GET_PROP(obj, postFiles)));
+                               zval *fields_cpy, *files_cpy;
+                               HashTable *fields = Z_ARRVAL_P(convert_to_type_ex(IS_ARRAY, GET_PROP(obj, postFields), &fields_cpy));
+                               HashTable *files = Z_ARRVAL_P(convert_to_type_ex(IS_ARRAY, GET_PROP(obj, postFiles), &files_cpy));
+                               
+                               if (!(obj->request->body = http_request_body_fill(obj->request->body, fields, files))) {
+                                       status = FAILURE;
+                               }
+                               
+                               if (fields_cpy) {
+                                       zval_ptr_dtor(&fields_cpy);
+                               }
+                               if (files_cpy) {
+                                       zval_ptr_dtor(&files_cpy);
+                               }
                        }
 
                        if (raw_data_p) {
@@ -522,15 +531,15 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
                zval *opt_p, *options = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, options), &opt_p);
                
                if (Z_STRLEN_P(qdata)) {
-                       if (!strchr(obj->request.url, '?')) {
-                               strlcat(obj->request.url, "?", HTTP_URI_MAXLEN);
+                       if (!strchr(obj->request->url, '?')) {
+                               strlcat(obj->request->url, "?", HTTP_URI_MAXLEN);
                        } else {
-                               strlcat(obj->request.url, "&", HTTP_URI_MAXLEN);
+                               strlcat(obj->request->url, "&", HTTP_URI_MAXLEN);
                        }
-                       strlcat(obj->request.url, Z_STRVAL_P(qdata), HTTP_URI_MAXLEN);
+                       strlcat(obj->request->url, Z_STRVAL_P(qdata), HTTP_URI_MAXLEN);
                }
                
-               http_request_prepare(&obj->request, Z_ARRVAL_P(options));
+               http_request_prepare(obj->request, Z_ARRVAL_P(options));
                
                if (opt_p) {
                        zval_ptr_dtor(&opt_p);
@@ -547,10 +556,10 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this
 {
        http_message *msg;
        
-       phpstr_fix(&obj->request.conv.request);
-       phpstr_fix(&obj->request.conv.response);
+       phpstr_fix(&obj->request->conv.request);
+       phpstr_fix(&obj->request->conv.response);
        
-       msg = http_message_parse(PHPSTR_VAL(&obj->request.conv.response), PHPSTR_LEN(&obj->request.conv.response));
+       msg = http_message_parse(PHPSTR_VAL(&obj->request->conv.response), PHPSTR_LEN(&obj->request->conv.response));
        
        if (!msg) {
                return FAILURE;
@@ -569,7 +578,7 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this
                         * the requests and the responses in separate chains
                         * for redirects
                         */
-                       http_message *response = msg, *request = http_message_parse(PHPSTR_VAL(&obj->request.conv.request), PHPSTR_LEN(&obj->request.conv.request));
+                       http_message *response = msg, *request = http_message_parse(PHPSTR_VAL(&obj->request->conv.request), PHPSTR_LEN(&obj->request->conv.request));
                        http_message *free_msg = request;
 
                        do {
@@ -607,7 +616,7 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this
                SET_PROP(obj, responseMessage, message);
                zval_ptr_dtor(&message);
 
-               http_request_info(&obj->request, Z_ARRVAL_P(info));
+               http_request_info(obj->request, Z_ARRVAL_P(info));
                SET_PROP(obj, responseInfo, info);
 
                return SUCCESS;
@@ -1864,7 +1873,7 @@ PHP_METHOD(HttpRequest, getRequestMessage)
                getObject(http_request_object, obj);
 
                SET_EH_THROW_HTTP();
-               if ((msg = http_message_parse(PHPSTR_VAL(&obj->request.conv.request), PHPSTR_LEN(&obj->request.conv.request)))) {
+               if ((msg = http_message_parse(PHPSTR_VAL(&obj->request->conv.request), PHPSTR_LEN(&obj->request->conv.request)))) {
                        ZVAL_OBJVAL(return_value, http_message_object_new_ex(http_message_object_ce, msg, NULL));
                }
                SET_EH_NORMAL();
@@ -1983,7 +1992,7 @@ PHP_METHOD(HttpRequest, send)
        RETVAL_NULL();
        
        if (SUCCESS == http_request_object_requesthandler(obj, getThis())) {
-               http_request_exec(&obj->request);
+               http_request_exec(obj->request);
                if (SUCCESS == http_request_object_responsehandler(obj, getThis())) {
                        RETVAL_OBJECT(GET_PROP(obj, responseMessage));
                }
index 7c3732004f71d784d69c4289745b648ab573e92f..a24f7328e26dffd5d64556d6cd8dcb92eace7a28 100644 (file)
@@ -88,7 +88,7 @@ PHP_HTTP_API STATUS _http_request_pool_attach(http_request_pool *pool, zval *req
        } else if (SUCCESS != http_request_object_requesthandler(req, request)) {
                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->request.ch);
+               CURLMcode code = curl_multi_add_handle(pool->ch, req->request->ch);
 
                if ((CURLM_OK != code) && (CURLM_CALL_MULTI_PERFORM != code)) {
                        http_error_ex(HE_WARNING, HTTP_E_REQUEST_POOL, "Could not attach HttpRequest object to the HttpRequestPool: %s", curl_multi_strerror(code));
@@ -125,7 +125,7 @@ PHP_HTTP_API STATUS _http_request_pool_detach(http_request_pool *pool, zval *req
 #endif
        } else if (req->pool != pool) {
                http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "HttpRequest object(#%d) is not attached to this HttpRequestPool", Z_OBJ_HANDLE_P(request));
-       } else if (CURLM_OK != (code = curl_multi_remove_handle(pool->ch, req->request.ch))) {
+       } else if (CURLM_OK != (code = curl_multi_remove_handle(pool->ch, req->request->ch))) {
                http_error_ex(HE_WARNING, HTTP_E_REQUEST_POOL, "Could not detach HttpRequest object from the HttpRequestPool: %s", curl_multi_strerror(code));
        } else {
                req->pool = NULL;
@@ -277,7 +277,7 @@ void _http_request_pool_responsehandler(zval **req, CURL *ch TSRMLS_DC)
 {
        getObjectEx(http_request_object, obj, *req);
        
-       if (obj->request.ch == ch) {
+       if (obj->request->ch == ch) {
                
 #if HTTP_DEBUG_REQPOOLS
                fprintf(stderr, "Fetching data from HttpRequest(#%d) %p of pool %p\n", Z_OBJ_HANDLE_PP(req), obj, obj->pool);
index 3522685e3eac46dc83207cb0042145619aa9211f..8ce8b4c473e7b28c99b5432d35506e150bd32c41 100644 (file)
@@ -39,10 +39,10 @@ struct _http_message {
 /* shorthand for type checks */
 #define HTTP_MSG_TYPE(TYPE, msg) ((msg) && ((msg)->type == HTTP_MSG_ ##TYPE))
 
-#define http_message_new() _http_message_init_ex(NULL, 0)
-#define http_message_init(m) _http_message_init_ex((m), 0)
-#define http_message_init_ex(m, t) _http_message_init_ex((m), (t))
-PHP_HTTP_API http_message *_http_message_init_ex(http_message *m, http_message_type t);
+#define http_message_new() http_message_init_ex(NULL, 0)
+#define http_message_init(m) http_message_init_ex((m), 0)
+#define http_message_init_ex(m, t) _http_message_init_ex((m), (t) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
+PHP_HTTP_API http_message *_http_message_init_ex(http_message *m, http_message_type t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
 
 #define http_message_set_type(m, t) _http_message_set_type((m), (t))
 PHP_HTTP_API void _http_message_set_type(http_message *m, http_message_type t);
@@ -59,8 +59,8 @@ static inline zval *_http_message_header_ex(http_message *msg, char *key_str, si
 }
 
 #define http_message_parse(m, l) http_message_parse_ex(NULL, (m), (l))
-#define http_message_parse_ex(h, m, l) _http_message_parse_ex((h), (m), (l) TSRMLS_CC)
-PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char *message, size_t length TSRMLS_DC);
+#define http_message_parse_ex(h, m, l) _http_message_parse_ex((h), (m), (l) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
+PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char *message, size_t length ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
 
 #define http_message_tostring(m, s, l) _http_message_tostring((m), (s), (l))
 PHP_HTTP_API void _http_message_tostring(http_message *msg, char **string, size_t *length);
index 9608611ab00a33bd2c720cf38f0180e4513d59e5..d2172c5a8277fd170719f8d9abe8f505d941155c 100644 (file)
@@ -50,9 +50,9 @@ typedef struct {
 
 } http_request;
 
-#define http_request_init(r) _http_request_init_ex((r), NULL, 0, NULL TSRMLS_CC)
-#define http_request_init_ex(r, c, m, u) _http_request_init_ex((r), (c), (m), (u) TSRMLS_CC)
-PHP_HTTP_API http_request *_http_request_init_ex(http_request *request, CURL *ch, http_request_method meth, const char *url TSRMLS_DC);
+#define http_request_init(r) _http_request_init_ex((r), NULL, 0, NULL ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
+#define http_request_init_ex(r, c, m, u) _http_request_init_ex((r), (c), (m), (u) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
+PHP_HTTP_API http_request *_http_request_init_ex(http_request *request, CURL *ch, http_request_method meth, const char *url ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
 
 #define http_request_dtor(r) _http_request_dtor((r))
 PHP_HTTP_API void _http_request_dtor(http_request *request);
index dbdcedfa00a6cb0f8fb683c9a9f6068b1baa8a4b..0dc12528f55f6d889a4ddf4b68dbe80613d3cbcd 100644 (file)
 #define HTTP_REQUEST_BODY_CURLPOST             2
 #define HTTP_REQUEST_BODY_UPLOADFILE   3
 typedef struct {
-       int type;
+       uint type:31;
+       uint free:1;
        void *data;
        size_t size;
 } http_request_body;
 
 
-PHP_HTTP_API http_request_body *_http_request_body_new(ZEND_FILE_LINE_D ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
-#define http_request_body_new() _http_request_body_new(ZEND_FILE_LINE_C ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
+#define http_request_body_new() http_request_body_init(NULL)
+#define http_request_body_init(b) http_request_body_init_ex((b), 0, NULL, 0, 0)
+#define http_request_body_init_ex(b, t, d, l, f) _http_request_body_init_ex((b), (t), (d), (l), (f) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
+PHP_HTTP_API http_request_body *_http_request_body_init_ex(http_request_body *body, int type, void *data, size_t len, zend_bool free ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
 
-#define http_request_body_fill(b, fields, files) _http_request_body_fill((b), (fields), (files) TSRMLS_CC)
-PHP_HTTP_API STATUS _http_request_body_fill(http_request_body *body, HashTable *fields, HashTable *files TSRMLS_DC);
+#define http_request_body_fill(b, fields, files) _http_request_body_fill((b), (fields), (files) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
+PHP_HTTP_API http_request_body *_http_request_body_fill(http_request_body *body, HashTable *fields, HashTable *files ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
 
 #define http_request_body_dtor(b) _http_request_body_dtor((b) TSRMLS_CC)
 PHP_HTTP_API void _http_request_body_dtor(http_request_body *body TSRMLS_DC);
index c0aaebf9a382804c5e1bb707f5851295833b65c6..ca092ee3b2f2cb610a90b56bc3cea990a03b8b4f 100644 (file)
@@ -21,7 +21,7 @@
 
 typedef struct {
        zend_object zo;
-       http_request request;
+       http_request *request;
        http_request_pool *pool;
        phpstr history;
 } http_request_object;
index 8e9ea5d1cd458c03002778bfbaeb050663563008..48b9149faae57e30c56c650a28b25f40a490ef27 100644 (file)
@@ -41,7 +41,7 @@ if (http_support(HTTP_SUPPORT_REQUESTS)) {
                printf("%s (%d)\n", $x->getMessage(), $x->getCode());
        }
 } else {
-       echo "URL using bad/illegal format or missing URL ((null)) (8)\n";
+       echo "URL using bad/illegal format or missing URL ((null)) (8)\n";
 }
 echo "Done\n";
 ?>
@@ -59,5 +59,5 @@ echo "Done\n";
 10: HttpSocketException
 11: HttpResponseException
 12: HttpUrlException
-URL using bad/illegal format or missing URL ((null)) (8)
+URL using bad/illegal format or missing URL ((null)) (8)
 Done