From 649aada485583ccac67928e0700cb5f1b963f4e8 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Tue, 13 Dec 2005 11:04:17 +0000 Subject: [PATCH] - implement more of those useful allocation relays - extend http_request_body API - adjust http_request_objects usage of http_request --- http_functions.c | 12 ++----- http_message_api.c | 11 +++--- http_request_api.c | 9 ++--- http_request_body_api.c | 39 ++++++++++---------- http_request_object.c | 71 +++++++++++++++++++++---------------- http_request_pool_api.c | 6 ++-- php_http_message_api.h | 12 +++---- php_http_request_api.h | 6 ++-- php_http_request_body_api.h | 13 ++++--- php_http_request_object.h | 2 +- tests/exceptions.phpt | 4 +-- 11 files changed, 96 insertions(+), 89 deletions(-) diff --git a/http_functions.c b/http_functions.c index 0231946..279e4ea 100644 --- a/http_functions.c +++ b/http_functions.c @@ -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); } /* }}} */ diff --git a/http_message_api.c b/http_message_api.c index 01aa0e3..cd9a951 100644 --- a/http_message_api.c +++ b/http_message_api.c @@ -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, diff --git a/http_request_api.c b/http_request_api.c index 42a1199..1574073 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -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); } /* }}} */ diff --git a/http_request_body_api.c b/http_request_body_api.c index 423dda0..467726b 100644 --- a/http_request_body_api.c +++ b/http_request_body_api.c @@ -28,14 +28,23 @@ 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: diff --git a/http_request_object.c b/http_request_object.c index ea4e9f6..8d6e798 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -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)); } diff --git a/http_request_pool_api.c b/http_request_pool_api.c index 7c37320..a24f732 100644 --- a/http_request_pool_api.c +++ b/http_request_pool_api.c @@ -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); diff --git a/php_http_message_api.h b/php_http_message_api.h index 3522685..8ce8b4c 100644 --- a/php_http_message_api.h +++ b/php_http_message_api.h @@ -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); diff --git a/php_http_request_api.h b/php_http_request_api.h index 9608611..d2172c5 100644 --- a/php_http_request_api.h +++ b/php_http_request_api.h @@ -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); diff --git a/php_http_request_body_api.h b/php_http_request_body_api.h index dbdcedf..0dc1252 100644 --- a/php_http_request_body_api.h +++ b/php_http_request_body_api.h @@ -21,17 +21,20 @@ #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); diff --git a/php_http_request_object.h b/php_http_request_object.h index c0aaebf..ca092ee 100644 --- a/php_http_request_object.h +++ b/php_http_request_object.h @@ -21,7 +21,7 @@ typedef struct { zend_object zo; - http_request request; + http_request *request; http_request_pool *pool; phpstr history; } http_request_object; diff --git a/tests/exceptions.phpt b/tests/exceptions.phpt index 8e9ea5d..48b9149 100644 --- a/tests/exceptions.phpt +++ b/tests/exceptions.phpt @@ -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 -- 2.30.2