HttpResponse class is only available for PHP >= 5.1
+Not all places where files are handled check for open_basedir and/or safe_mode.
#ifdef HTTP_HAVE_CURL
zend_llist_init(&G->request.copies.strings, sizeof(char *), http_request_data_free_string, 0);
zend_llist_init(&G->request.copies.slists, sizeof(struct curl_slist *), http_request_data_free_slist, 0);
- zend_llist_init(&G->request.copies.contexts, sizeof(http_curl_callback_ctx *), http_request_data_free_context, 0);
- zend_llist_init(&G->request.copies.convs, sizeof(http_curl_conv *), http_request_data_free_conv, 0);
+ zend_llist_init(&G->request.copies.contexts, sizeof(http_request_callback_ctx *), http_request_data_free_context, 0);
+ zend_llist_init(&G->request.copies.convs, sizeof(http_request_conv *), http_request_data_free_conv, 0);
#endif
}
/* }}} */
/* {{{ void http_error(long, long, char*) */
-void _http_error_ex(long type, long code, const char *format, ...)
+void _http_error_ex(long type TSRMLS_DC, long code, const char *format, ...)
{
va_list args;
- TSRMLS_FETCH();
va_start(args, format);
#ifdef ZEND_ENGINE_2
fprintf(stderr, "Read HttpMessage::$%s\n", Z_STRVAL_P(member));
#endif
if (!EG(scope) || !instanceof_function(EG(scope), obj->zo.ce TSRMLS_CC)) {
- zend_error(HE_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member));
+ zend_error(E_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member));
return EG(uninitialized_zval_ptr);
}
fprintf(stderr, "Write HttpMessage::$%s\n", Z_STRVAL_P(member));
#endif
if (!EG(scope) || !instanceof_function(EG(scope), obj->zo.ce TSRMLS_CC)) {
- zend_error(HE_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member));
+ zend_error(E_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member));
}
switch (zend_get_hash_value(Z_STRVAL_P(member), Z_STRLEN_P(member) + 1))
static int http_curl_raw_callback(CURL *, curl_infotype, char *, size_t, void *);
static int http_curl_dummy_callback(char *data, size_t n, size_t l, void *s) { return n*l; }
-#define HTTP_CURL_CALLBACK_DATA(from, type, var) \
- http_curl_callback_ctx *__CTX = (http_curl_callback_ctx *) (from); \
- TSRMLS_FETCH_FROM_CTX(__CTX->tsrm_ctx); \
- type (var) = (type) (__CTX->data)
-
-#define http_curl_callback_data(data) _http_curl_callback_data((data) TSRMLS_CC)
-static http_curl_callback_ctx *_http_curl_callback_data(void *data TSRMLS_DC);
+/* {{{ http_request_callback_ctx http_request_callback_data(void *) */
+http_request_callback_ctx *_http_request_callback_data_ex(void *data, zend_bool cpy TSRMLS_DC)
+{
+ http_request_callback_ctx *ctx = emalloc(sizeof(http_request_callback_ctx));
+
+ TSRMLS_SET_CTX(ctx->tsrm_ctx);
+ ctx->data = data;
+
+ if (cpy) {
+ return http_request_data_copy(COPY_CONTEXT, ctx);
+ } else {
+ return ctx;
+ }
+}
+/* }}} */
/* {{{ void *http_request_data_copy(int, void *) */
void *_http_request_data_copy(int type, void *data TSRMLS_DC)
}
/* }}} */
-/* {{{ _http_request_data_free_context(http_curl_callback_ctx **) */
+/* {{{ _http_request_data_free_context(http_request_callback_ctx **) */
void _http_request_data_free_context(void *context)
{
- efree(*((http_curl_callback_ctx **) context));
+ efree(*((http_request_callback_ctx **) context));
}
/* }}} */
-/* {{{ _http_request_data_free_conv(http_curl_conv **) */
+/* {{{ _http_request_data_free_conv(http_request_conv **) */
void _http_request_data_free_conv(void *conv)
{
- efree(*((http_curl_conv **) conv));
+ efree(*((http_request_conv **) conv));
}
/* }}} */
if (zoption = http_curl_getopt(options, "onprogress", 0)) {
HTTP_CURL_OPT(NOPROGRESS, 0);
HTTP_CURL_OPT(PROGRESSFUNCTION, http_curl_progress_callback);
- HTTP_CURL_OPT(PROGRESSDATA, http_curl_callback_data(zoption));
+ HTTP_CURL_OPT(PROGRESSDATA, http_request_callback_data(zoption));
} else {
HTTP_CURL_OPT(NOPROGRESS, 1);
}
break;
case HTTP_REQUEST_BODY_UPLOADFILE:
- curl_easy_setopt(ch, CURLOPT_READDATA, http_curl_callback_data(body));
+ curl_easy_setopt(ch, CURLOPT_READDATA, http_request_callback_data(body));
curl_easy_setopt(ch, CURLOPT_INFILESIZE, body->size);
break;
/* {{{ void http_request_conv(CURL *, phpstr *, phpstr *) */
void _http_request_conv(CURL *ch, phpstr* response, phpstr *request TSRMLS_DC)
{
- http_curl_conv *conv = emalloc(sizeof(http_curl_conv));
+ http_request_conv *conv = emalloc(sizeof(http_request_conv));
conv->response = response;
conv->request = request;
conv->last_info = -1;
- HTTP_CURL_OPT(DEBUGDATA, http_curl_callback_data(http_request_data_copy(COPY_CONV, conv)));
+ HTTP_CURL_OPT(DEBUGDATA, http_request_callback_data(http_request_data_copy(COPY_CONV, conv)));
}
/* }}} */
/* {{{ static size_t http_curl_read_callback(void *, size_t, size_t, void *) */
static size_t http_curl_read_callback(void *data, size_t len, size_t n, void *s)
{
- HTTP_CURL_CALLBACK_DATA(s, http_request_body *, body);
+ HTTP_REQUEST_CALLBACK_DATA(s, http_request_body *, body);
if (body->type != HTTP_REQUEST_BODY_UPLOADFILE) {
return 0;
}
/* }}} */
-/* {{{ http_curl_callback_ctx http_curl_callback_data(void *) */
-static http_curl_callback_ctx *_http_curl_callback_data(void *data TSRMLS_DC)
-{
- http_curl_callback_ctx *ctx = emalloc(sizeof(http_curl_callback_ctx));
- TSRMLS_SET_CTX(ctx->tsrm_ctx);
- ctx->data = data;
- return http_request_data_copy(COPY_CONTEXT, ctx);
-}
-/* }}} */
-
/* {{{ static int http_curl_progress_callback(void *, double, double, double, double) */
static int http_curl_progress_callback(void *data, double dltotal, double dlnow, double ultotal, double ulnow)
{
zval *params_pass[4], params_local[4], retval;
- HTTP_CURL_CALLBACK_DATA(data, zval *, func);
+ HTTP_REQUEST_CALLBACK_DATA(data, zval *, func);
params_pass[0] = ¶ms_local[0];
params_pass[1] = ¶ms_local[1];
/* {{{ static int http_curl_raw_callback(CURL *, curl_infotype, char *, size_t, void *) */
static int http_curl_raw_callback(CURL *ch, curl_infotype type, char *data, size_t length, void *ctx)
{
- HTTP_CURL_CALLBACK_DATA(ctx, http_curl_conv *, conv);
+ HTTP_REQUEST_CALLBACK_DATA(ctx, http_request_conv *, conv);
switch (type)
{
# define curl_multi_strerror(dummy) "unknown error"
#endif
-static void http_request_pool_freebody(http_request_body **body);
+static void http_request_pool_freebody(http_request_callback_ctx **body);
static int http_request_pool_compare_handles(void *h1, void *h2);
/* {{{ http_request_pool *http_request_pool_init(http_request_pool *) */
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);
+ zend_llist_init(&pool->bodies, sizeof(http_request_callback_ctx *), (llist_dtor_func_t) http_request_pool_freebody, 0);
#if HTTP_DEBUG_REQPOOLS
fprintf(stderr, "Initialized request pool %p\n", pool);
#endif
if (req->pool) {
http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "HttpRequest object(#%d) is already member of %s HttpRequestPool", Z_OBJ_HANDLE_P(request), req->pool == pool ? "this" : "another");
} else {
- http_request_body *body = http_request_body_new();
+ http_request_callback_ctx *body = http_request_callback_data_ex(http_request_body_new(), 0);
- if (SUCCESS != http_request_pool_requesthandler(request, body)) {
+ if (SUCCESS != http_request_pool_requesthandler(request, body->data)) {
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->ch);
return SUCCESS;
}
}
+ efree(body->data);
efree(body);
}
return FAILURE;
/*#*/
-/* {{{ static void http_request_pool_freebody(http_request_body **) */
-static void http_request_pool_freebody(http_request_body **body)
+/* {{{ static void http_request_pool_freebody(http_request_ctx **) */
+static void http_request_pool_freebody(http_request_callback_ctx **body)
{
- TSRMLS_FETCH();
- http_request_body_free(*body);
+ HTTP_REQUEST_CALLBACK_DATA(*body, http_request_body *, b);
+ http_request_body_free(b);
+ efree(*body);
}
/* }}} */
#define http_error(type, code, string) _http_error_ex(type, code, "%s", string)
#define http_error_ex _http_error_ex
-extern void _http_error_ex(long type, long code, const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
+extern void _http_error_ex(long type TSRMLS_DC, long code, const char *format, ...);
#define http_log(f, i, m) _http_log_ex((f), (i), (m) TSRMLS_CC)
extern void http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC);
typedef struct {
void ***tsrm_ctx;
void *data;
-} http_curl_callback_ctx;
+} http_request_callback_ctx;
typedef struct {
phpstr *response;
phpstr *request;
curl_infotype last_info;
-} http_curl_conv;
+} http_request_conv;
+
+
+#define HTTP_REQUEST_CALLBACK_DATA(from, type, var) \
+ http_request_callback_ctx *__CTX = (http_request_callback_ctx *) (from); \
+ TSRMLS_FETCH_FROM_CTX(__CTX->tsrm_ctx); \
+ type (var) = (type) (__CTX->data)
+
+#define http_request_callback_data(data) _http_request_callback_data_ex((data), 1 TSRMLS_CC)
+#define http_request_callback_data_ex(data, copy) _http_request_callback_data_ex((data), (copy) TSRMLS_CC)
+extern http_request_callback_ctx *_http_request_callback_data_ex(void *data, zend_bool cpy TSRMLS_DC);
+
#define COPY_STRING 1
#define COPY_SLIST 2
#ifndef E_THROW
# define E_THROW 0
#endif
-#define HE_THROW E_THROW
#ifdef ZEND_ENGINE_2
-# define HE_THROW E_THROW
-# define HE_NOTICE (HTTP_G(only_exceptions) ? E_THROW : E_NOTICE)
-# define HE_WARNING (HTTP_G(only_exceptions) ? E_THROW : E_WARNING)
-# define HE_ERROR (HTTP_G(only_exceptions) ? E_THROW : E_ERROR)
+# define HE_THROW E_THROW TSRMLS_CC
+# define HE_NOTICE (HTTP_G(only_exceptions) ? E_THROW : E_NOTICE) TSRMLS_CC
+# define HE_WARNING (HTTP_G(only_exceptions) ? E_THROW : E_WARNING) TSRMLS_CC
+# define HE_ERROR (HTTP_G(only_exceptions) ? E_THROW : E_ERROR) TSRMLS_CC
#else
-# define HE_THROW E_WARNING
-# define HE_NOTICE E_NOTICE
-# define HE_WARNING E_WARNING
-# define HE_ERROR E_ERROR
+# define HE_THROW E_WARNING TSRMLS_CC
+# define HE_NOTICE E_NOTICE TSRMLS_CC
+# define HE_WARNING E_WARNING TSRMLS_CC
+# define HE_ERROR E_ERROR TSRMLS_CC
#endif
#define HTTP_E_RUNTIME 1L