-
-#include "php_http.h"
-#include "php_http_request.h"
-#include "php_http_request_pool.h"
+/*
+ +--------------------------------------------------------------------+
+ | PECL :: http |
+ +--------------------------------------------------------------------+
+ | Redistribution and use in source and binary forms, with or without |
+ | modification, are permitted provided that the conditions mentioned |
+ | in the accompanying LICENSE file are met. |
+ +--------------------------------------------------------------------+
+ | Copyright (c) 2004-2011, Michael Wallner <mike@php.net> |
+ +--------------------------------------------------------------------+
+*/
+
+#include "php_http_api.h"
+
+#if PHP_HTTP_HAVE_CURL
#include <curl/curl.h>
#define PHP_HTTP_CURL_VERSION(x, y, z) (LIBCURL_VERSION_NUM >= (((x)<<16) + ((y)<<8) + (z)))
-#ifdef PHP_HTTP_HAVE_EVENT
+#if PHP_HTTP_HAVE_EVENT
# include <event.h>
#endif
-#include <ext/spl/spl_iterators.h>
-#include <Zend/zend_interfaces.h>
-
-
typedef struct php_http_curl_request {
CURL *handle;
int unfinished; /* int because of curl_multi_perform() */
-#ifdef PHP_HTTP_HAVE_EVENT
+#if PHP_HTTP_HAVE_EVENT
struct event *timeout;
unsigned useevents:1;
unsigned runsocket:1;
php_http_request_t *h = ctx;
php_http_curl_request_t *curl = h->ctx;
unsigned flags = 0;
+ TSRMLS_FETCH_FROM_CTX(h->ts);
/* catch progress */
switch (type) {
break;
default: {
- const char *name = php_http_request_method_name(meth);
+ const char *name = php_http_request_method_name(meth TSRMLS_CC);
if (name) {
curl_easy_setopt(curl->handle, CURLOPT_CUSTOMREQUEST, name);
}
-#ifdef PHP_HTTP_HAVE_EVENT
+#if PHP_HTTP_HAVE_EVENT
typedef struct php_http_request_pool_event {
struct event evnt;
ev = ecalloc(1, sizeof(php_http_request_pool_event_t));
ev->pool = pool;
curl_multi_assign(curl->handle, sock, ev);
- event_base_set(PHP_HTTP_G->request_pool.event_base, &ev->evnt);
+ event_base_set(PHP_HTTP_G->curl.event_base, &ev->evnt);
} else {
event_del(&ev->evnt);
}
case CURL_POLL_REMOVE:
efree(ev);
+ /* no break */
case CURL_POLL_NONE:
return 0;
if (!event_initialized(curl->timeout)) {
event_set(curl->timeout, -1, 0, php_http_curl_request_pool_timeout_callback, pool);
- event_base_set(PHP_HTTP_G->request_pool.event_base, curl->timeout);
+ event_base_set(PHP_HTTP_G->curl.event_base, curl->timeout);
} else if (event_pending(curl->timeout, EV_TIMEOUT, NULL)) {
event_del(curl->timeout);
}
int range_req = 0;
php_http_curl_request_t *curl = h->ctx;
CURL *ch = curl->handle;
+ TSRMLS_FETCH_FROM_CTX(h->ts);
/* proxy */
if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("proxyhost"), IS_STRING))) {
zval *urlenc_cookies = NULL;
/* check whether cookies should not be urlencoded; default is to urlencode them */
if ((!(urlenc_cookies = get_option(&curl->options.cache, options, ZEND_STRS("encodecookies"), IS_BOOL))) || Z_BVAL_P(urlenc_cookies)) {
- if (SUCCESS == php_http_url_encode_hash_recursive(HASH_OF(zoption), &curl->options.cookies, "; ", lenof("; "), NULL, 0 TSRMLS_CC)) {
+ if (SUCCESS == php_http_url_encode_hash_ex(HASH_OF(zoption), &curl->options.cookies, ZEND_STRS(";"), ZEND_STRS("="), NULL, 0 TSRMLS_CC)) {
php_http_buffer_fix(&curl->options.cookies);
curl_easy_setopt(ch, CURLOPT_COOKIE, curl->options.cookies.data);
}
/* request datashare handler ops */
-static php_http_request_datashare_t *php_http_curl_request_datashare_init(php_http_request_datashare_t *h, void *handle TSRMLS_DC)
+static php_http_request_datashare_t *php_http_curl_request_datashare_init(php_http_request_datashare_t *h, void *handle)
{
php_http_curl_request_datashare_t *curl;
+ TSRMLS_FETCH_FROM_CTX(h->ts);
if (!handle && !(handle = php_http_resource_factory_handle_ctor(h->rf TSRMLS_CC))) {
php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_DATASHARE, "could not initialize curl share handle");
curl->handle = handle;
#ifdef ZTS
if (h->persistent) {
- curl->locks = php_http_request_datashare_locks_init();
+ curl->locks = php_http_curl_request_datashare_locks_init();
if (curl->locks) {
- curl_share_setopt(share->ch, CURLSHOPT_LOCKFUNC, php_http_curl_request_datashare_lock_func);
- curl_share_setopt(share->ch, CURLSHOPT_UNLOCKFUNC, php_http_curl_request_datashare_unlock_func);
- curl_share_setopt(share->ch, CURLSHOPT_USERDATA, curl->locks);
+ curl_share_setopt(curl->handle, CURLSHOPT_LOCKFUNC, php_http_curl_request_datashare_lock_func);
+ curl_share_setopt(curl->handle, CURLSHOPT_UNLOCKFUNC, php_http_curl_request_datashare_unlock_func);
+ curl_share_setopt(curl->handle, CURLSHOPT_USERDATA, curl->locks);
}
}
#endif
#ifdef ZTS
if (h->persistent) {
- http_request_datashare_locks_dtor(curl->locks);
+ php_http_curl_request_datashare_locks_dtor(curl->locks);
}
#endif
/* request pool handler ops */
-static php_http_request_pool_t *php_http_curl_request_pool_init(php_http_request_pool_t *h, void *handle TSRMLS_DC)
+static php_http_request_pool_t *php_http_curl_request_pool_init(php_http_request_pool_t *h, void *handle)
{
php_http_curl_request_pool_t *curl;
+ TSRMLS_FETCH_FROM_CTX(h->ts);
if (!handle && !(handle = php_http_resource_factory_handle_ctor(h->rf TSRMLS_CC))) {
php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_POOL, "could not initialize curl pool handle");
php_http_curl_request_pool_t *curl = h->ctx;
TSRMLS_FETCH_FROM_CTX(h->ts);
-#ifdef PHP_HTTP_HAVE_EVENT
+#if PHP_HTTP_HAVE_EVENT
if (curl->timeout) {
efree(curl->timeout);
curl->timeout = NULL;
curl->unfinished = 0;
php_http_request_pool_reset(h);
- php_http_resource_factory_handle_dtor(h->rf, curl->handle);
+ php_http_resource_factory_handle_dtor(h->rf, curl->handle TSRMLS_CC);
efree(curl);
h->ctx = NULL;
php_http_curl_request_pool_t *curl = h->ctx;
php_http_curl_request_t *recurl = r->ctx;
CURLMcode rs;
+ TSRMLS_FETCH_FROM_CTX(h->ts);
if (SUCCESS != php_http_curl_request_prepare(r, m, url, body)) {
return FAILURE;
php_http_curl_request_pool_t *curl = h->ctx;
php_http_curl_request_t *recurl = r->ctx;
CURLMcode rs = curl_multi_remove_handle(curl->handle, recurl->handle);
+ TSRMLS_FETCH_FROM_CTX(h->ts);
if (CURLM_OK == rs) {
return SUCCESS;
struct timeval timeout;
php_http_curl_request_pool_t *curl = h->ctx;
-#ifdef PHP_HTTP_HAVE_EVENT
+#if PHP_HTTP_HAVE_EVENT
if (curl->useevents) {
- TSRMLS_FETCH_FROM_CTX(pool->ts);
+ TSRMLS_FETCH_FROM_CTX(h->ts);
php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "not implemented");
return FAILURE;
static int php_http_curl_request_pool_once(php_http_request_pool_t *h)
{
php_http_curl_request_pool_t *curl = h->ctx;
- TSRMLS_FETCH_FROM_CTX(h->ts);
-#ifdef PHP_HTTP_HAVE_EVENT
+#if PHP_HTTP_HAVE_EVENT
if (curl->useevents) {
+ TSRMLS_FETCH_FROM_CTX(h->ts);
php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "not implemented");
return FAILURE;
}
return curl->unfinished;
}
-#ifdef PHP_HTTP_HAVE_EVENT
+#if PHP_HTTP_HAVE_EVENT
static void dolog(int i, const char *m) {
fprintf(stderr, "%d: %s\n", i, m);
}
#endif
static STATUS php_http_curl_request_pool_exec(php_http_request_pool_t *h)
{
-#ifdef PHP_HTTP_HAVE_EVENT
+ TSRMLS_FETCH_FROM_CTX(h->ts);
+
+#if PHP_HTTP_HAVE_EVENT
php_http_curl_request_pool_t *curl = h->ctx;
if (curl->useevents) {
#if DBG_EVENTS
fprintf(stderr, "X");
#endif
- event_base_dispatch(PHP_HTTP_G->request_pool.event_base);
+ event_base_dispatch(PHP_HTTP_G->curl.event_base);
} while (curl->unfinished);
} else
#endif
curl_easy_setopt(handle, CURLOPT_DEBUGDATA, h);
curl_easy_setopt(handle, CURLOPT_PROGRESSDATA, h);
- php_http_curl_request_reset(h TSRMLS_CC);
+ php_http_curl_request_reset(h);
return h;
}
static void php_http_curl_request_dtor(php_http_request_t *h)
{
php_http_curl_request_t *ctx = h->ctx;
+ TSRMLS_FETCH_FROM_CTX(h->ts);
curl_easy_setopt(ctx->handle, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(ctx->handle, CURLOPT_PROGRESSFUNCTION, NULL);
curl_slist_free_all(ctx->options.headers);
ctx->options.headers = NULL;
}
- php_http_request_progress_dtor(&ctx->progress);
+ php_http_request_progress_dtor(&ctx->progress TSRMLS_CC);
efree(ctx);
h->ctx = NULL;
static STATUS php_http_curl_request_setopt(php_http_request_t *h, php_http_request_setopt_opt_t opt, void *arg)
{
php_http_curl_request_t *curl = h->ctx;
+ TSRMLS_FETCH_FROM_CTX(h->ts);
switch (opt) {
case PHP_HTTP_REQUEST_OPT_SETTINGS:
PHP_RINIT_FUNCTION(http_curl)
{
-#ifdef PHP_HTTP_HAVE_EVENT
- if (!PHP_HTTP_G->request_pool.event_base && !(PHP_HTTP_G->request_pool.event_base = event_init())) {
+#if PHP_HTTP_HAVE_EVENT
+ if (!PHP_HTTP_G->curl.event_base && !(PHP_HTTP_G->curl.event_base = event_init())) {
return FAILURE;
}
#endif
return SUCCESS;
}
+
+#endif /* PHP_HTTP_HAVE_CURL */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
+