* }
* $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'
* );
* }
*/
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);
}
/* }}} */
{
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;
}
/* {{{ 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));
}
/* }}} */
/* }}} */
/* {{{ 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;
/* 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) {
/* }}} */
/* {{{ 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;
}
}
+ 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);
{
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");
#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);
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)) ||
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;
}
efree(scheme); \
} \
php_url_free(purl); \
+ efree(uri); \
return URL; \
} else { \
strcat(URL, add_string); \
efree(scheme);
}
php_url_free(purl);
+ efree(uri);
return URL;
}
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);
#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)
typedef struct {
CURLM *ch;
+ zend_bool sent;
zend_llist handles;
zend_llist bodies;
int unfinished;