From: Michael Wallner Date: Tue, 14 Jun 2005 19:17:55 +0000 (+0000) Subject: - remove const qualifier from url param in http_request_*() X-Git-Tag: RELEASE_0_9_0~12 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=commitdiff_plain;h=77b24e0e5f85b64a168a4ea4ce83db9339b1f31b;ds=sidebyside - remove const qualifier from url param in http_request_*() - allow HttpRequestPools to be used only once --- diff --git a/http_methods.c b/http_methods.c index d71c2ca..94a4757 100644 --- a/http_methods.c +++ b/http_methods.c @@ -2156,8 +2156,8 @@ PHP_METHOD(HttpRequest, send) * } * $pool->send(); * foreach ($urls as $url) { - * printf("%s (%s) is %s\n", - * $url, $req[$url]->getResponseInfo('effective_url'), + * printf("%s (%s) is %s\n", + * $url, $req[$url]->getResponseInfo('effective_url'), * $r->getResponseCode() == 200 ? 'alive' : 'not alive' * ); * } @@ -2255,11 +2255,16 @@ PHP_METHOD(HttpRequestPool, detach) */ PHP_METHOD(HttpRequestPool, send) { + STATUS status; getObject(http_requestpool_object, obj); NO_ARGS; - RETURN_SUCCESS(http_request_pool_send(&obj->pool)); + SET_EH_THROW_HTTP(); + status = http_request_pool_send(&obj->pool); + SET_EH_NORMAL(); + + RETURN_SUCCESS(status); } /* }}} */ diff --git a/http_request_api.c b/http_request_api.c index 2a4884a..5bc0f8f 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -153,7 +153,8 @@ void *_http_request_data_copy(int type, void *data TSRMLS_DC) { case COPY_STRING: { - char *new_str = estrdup((const char*) data); + char *new_str = estrdup(data); + //fprintf(stderr, "COPY STRING: %p (%s)\n", new_str, new_str); zend_llist_add_element(&HTTP_G(request).copies.strings, &new_str); return new_str; } @@ -181,6 +182,7 @@ void *_http_request_data_copy(int type, void *data TSRMLS_DC) /* {{{ void http_request_data_free_string(char **) */ void _http_request_data_free_string(void *string) { + //fprintf(stderr, "FREE STRING %p (%s)\n", *((char **)string), *((char **)string)); efree(*((char **)string)); } /* }}} */ @@ -318,7 +320,7 @@ PHP_HTTP_API void _http_request_body_free(http_request_body *body TSRMLS_DC) /* }}} */ /* {{{ STATUS http_request_init(CURL *, http_request_method, char *, http_request_body *, HashTable *, phpstr *) */ -PHP_HTTP_API STATUS _http_request_init(CURL *ch, http_request_method meth, const char *url, http_request_body *body, HashTable *options, phpstr *response TSRMLS_DC) +PHP_HTTP_API STATUS _http_request_init(CURL *ch, http_request_method meth, char *url, http_request_body *body, HashTable *options, phpstr *response TSRMLS_DC) { zval *zoption; zend_bool range_req = 0; @@ -330,7 +332,7 @@ PHP_HTTP_API STATUS _http_request_init(CURL *ch, http_request_method meth, const /* set options */ if (url) { - HTTP_CURL_OPT(URL, http_request_data_copy(COPY_STRING, (void *) url)); + HTTP_CURL_OPT(URL, http_request_data_copy(COPY_STRING, url)); } if (response) { @@ -701,7 +703,7 @@ PHP_HTTP_API void _http_request_info(CURL *ch, HashTable *info TSRMLS_DC) /* }}} */ /* {{{ STATUS http_request_ex(CURL *, http_request_method, char *, http_request_body, HashTable, HashTable, phpstr *) */ -PHP_HTTP_API STATUS _http_request_ex(CURL *ch, http_request_method meth, const char *url, http_request_body *body, HashTable *options, HashTable *info, phpstr *response TSRMLS_DC) +PHP_HTTP_API STATUS _http_request_ex(CURL *ch, http_request_method meth, char *url, http_request_body *body, HashTable *options, HashTable *info, phpstr *response TSRMLS_DC) { STATUS status; zend_bool clean_curl; diff --git a/http_request_pool_api.c b/http_request_pool_api.c index 610412a..4375303 100644 --- a/http_request_pool_api.c +++ b/http_request_pool_api.c @@ -59,6 +59,7 @@ PHP_HTTP_API http_request_pool *_http_request_pool_init(http_request_pool *pool } } + pool->sent = 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); @@ -108,7 +109,7 @@ PHP_HTTP_API STATUS _http_request_pool_detach(http_request_pool *pool, zval *req { getObjectEx(http_request_object, req, request); #if HTTP_DEBUG_REQPOOLS - fprintf(stderr, "Detaching request %p (pool: %p) from pool %p\n", req, req->pool, pool); + fprintf(stderr, "Detaching request %p from pool %p\n", req, pool); #endif if (req->pool != pool) { http_error(E_WARNING, HTTP_E_CURL, "HttpRequest object is not attached to this HttpRequestPool"); @@ -161,6 +162,12 @@ PHP_HTTP_API STATUS _http_request_pool_send(http_request_pool *pool TSRMLS_DC) #if HTTP_DEBUG_REQPOOLS fprintf(stderr, "Attempt to send requests of pool %p\n", pool); #endif + if (pool->sent) { + http_error(E_WARNING, HTTP_E_CURL, "HttpRequestPools can only be used once"); + return FAILURE; + } else { + pool->sent = 1; + } while (http_request_pool_perform(pool)) { #if HTTP_DEBUG_REQPOOLS fprintf(stderr, "%d unfinished requests of pool %p remaining\n", pool->unfinished, pool); diff --git a/http_url_api.c b/http_url_api.c index 83d295a..288abe4 100644 --- a/http_url_api.c +++ b/http_url_api.c @@ -54,7 +54,7 @@ PHP_HTTP_API char *_http_absolute_url_ex( php_url *purl, furl = {NULL}; size_t full_len = 0; zval *zhost = NULL; - char *scheme = NULL, *URL = ecalloc(1, HTTP_URI_MAXLEN + 1); + char *scheme = NULL, *uri, *URL = ecalloc(1, HTTP_URI_MAXLEN + 1); if ((!url || !url_len) && ( (!(url = SG(request_info).request_uri)) || @@ -63,7 +63,8 @@ PHP_HTTP_API char *_http_absolute_url_ex( return NULL; } - if (!(purl = php_url_parse((char *) url))) { + uri = estrndup(url, url_len); + if (!(purl = php_url_parse(uri))) { http_error_ex(E_WARNING, HTTP_E_PARSE, "Could not parse supplied URL: %s", url); return NULL; } @@ -123,6 +124,7 @@ PHP_HTTP_API char *_http_absolute_url_ex( efree(scheme); \ } \ php_url_free(purl); \ + efree(uri); \ return URL; \ } else { \ strcat(URL, add_string); \ @@ -172,6 +174,7 @@ PHP_HTTP_API char *_http_absolute_url_ex( efree(scheme); } php_url_free(purl); + efree(uri); return URL; } diff --git a/php_http_request_api.h b/php_http_request_api.h index 2aee64d..c772b43 100644 --- a/php_http_request_api.h +++ b/php_http_request_api.h @@ -120,7 +120,7 @@ PHP_HTTP_API void _http_request_body_dtor(http_request_body *body TSRMLS_DC); PHP_HTTP_API void _http_request_body_free(http_request_body *body TSRMLS_DC); #define http_request_init(ch, meth, url, body, options, response) _http_request_init((ch), (meth), (url), (body), (options), (response) TSRMLS_CC) -PHP_HTTP_API STATUS _http_request_init(CURL *ch, http_request_method meth, const char *url, http_request_body *body, HashTable *options, phpstr *response TSRMLS_DC); +PHP_HTTP_API STATUS _http_request_init(CURL *ch, http_request_method meth, char *url, http_request_body *body, HashTable *options, phpstr *response TSRMLS_DC); #define http_request_exec(ch, i) _http_request_exec((ch), (i) TSRMLS_CC) PHP_HTTP_API STATUS _http_request_exec(CURL *ch, HashTable *info TSRMLS_DC); @@ -130,7 +130,7 @@ PHP_HTTP_API void _http_request_info(CURL *ch, HashTable *info TSRMLS_DC); #define http_request(meth, url, body, opt, info, resp) _http_request_ex(NULL, (meth), (url), (body), (opt), (info), (resp) TSRMLS_CC) #define http_request_ex(ch, meth, url, body, opt, info, resp) _http_request_ex((ch), (meth), (url), (body), (opt), (info), (resp) TSRMLS_CC) -PHP_HTTP_API STATUS _http_request_ex(CURL *ch, http_request_method meth, const char *URL, http_request_body *body, HashTable *options, HashTable *info, phpstr *response TSRMLS_DC); +PHP_HTTP_API STATUS _http_request_ex(CURL *ch, http_request_method meth, char *URL, http_request_body *body, HashTable *options, HashTable *info, phpstr *response TSRMLS_DC); #define http_get(u, o, i, r) _http_request_ex(NULL, HTTP_GET, (u), NULL, (o), (i), (r) TSRMLS_CC) #define http_get_ex(c, u, o, i, r) _http_request_ex((c), HTTP_GET, (u), NULL, (o), (i), (r) TSRMLS_CC) diff --git a/php_http_request_pool_api.h b/php_http_request_pool_api.h index 3243de9..115cd3d 100644 --- a/php_http_request_pool_api.h +++ b/php_http_request_pool_api.h @@ -29,6 +29,7 @@ typedef struct { CURLM *ch; + zend_bool sent; zend_llist handles; zend_llist bodies; int unfinished;