X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_client_curl.c;h=501c2521e7aff2acd3773d71740c7731195c8cb6;hp=682e1eba2f64178eb8dba2884f115560fbfc1230;hb=805287392b6266d05533043509367d7e411e595c;hpb=1cd8f8ce93d77ceb115d80461322681e342fdd2c diff --git a/php_http_client_curl.c b/php_http_client_curl.c index 682e1eb..501c252 100644 --- a/php_http_client_curl.c +++ b/php_http_client_curl.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2013, Michael Wallner | + | Copyright (c) 2004-2014, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -16,16 +16,21 @@ #if PHP_HTTP_HAVE_CURL #if PHP_HTTP_HAVE_EVENT -# include # if !PHP_HTTP_HAVE_EVENT2 && /* just be really sure */ !(LIBEVENT_VERSION_NUMBER >= 0x02000000) +# include # define event_base_new event_init # define event_assign(e, b, s, a, cb, d) do {\ event_set(e, s, a, cb, d); \ event_base_set(b, e); \ } while(0) -# else -# include -# endif +# else +# if PHP_HTTP_HAVE_EVENT2 +# include +# include +# else +# error "libevent presence is unknown" +# endif +# endif # ifndef DBG_EVENTS # define DBG_EVENTS 0 # endif @@ -171,9 +176,13 @@ static size_t php_http_curle_read_callback(void *data, size_t len, size_t n, voi { php_http_message_body_t *body = ctx; - if (body) { - TSRMLS_FETCH_FROM_CTX(body->ts); - return php_stream_read(php_http_message_body_stream(body), data, len * n); + if (body && body->stream_id) { + php_stream *s = php_http_message_body_stream(body); + + if (s) { + TSRMLS_FETCH_FROM_CTX(body->ts); + return php_stream_read(s, data, len * n); + } else abort(); } return 0; } @@ -249,6 +258,8 @@ static int php_http_curle_raw_callback(CURL *ch, curl_infotype type, char *data, h->progress.info = "blacklist check"; } else if (php_memnstr(data, ZEND_STRL("SSL"), data + length)) { h->progress.info = "ssl negotiation"; + } else if (php_memnstr(data, ZEND_STRL("upload"), data + length)) { + h->progress.info = "uploaded"; } else if (php_memnstr(data, ZEND_STRL("left intact"), data + length)) { h->progress.info = "not disconnected"; } else if (php_memnstr(data, ZEND_STRL("closed"), data + length)) { @@ -260,6 +271,7 @@ static int php_http_curle_raw_callback(CURL *ch, curl_infotype type, char *data, } else { #if PHP_DEBUG h->progress.info = data; + data[length - 1] = '\0'; #endif } if (h->client->callback.progress.func) { @@ -1091,7 +1103,11 @@ static void php_http_curle_options_init(php_http_options_t *registry TSRMLS_DC) /* useragent */ if ((opt = php_http_option_register(registry, ZEND_STRL("useragent"), CURLOPT_USERAGENT, IS_STRING))) { /* don't check strlen, to allow sending no useragent at all */ - ZVAL_STRING(&opt->defval, "PECL::HTTP/" PHP_PECL_HTTP_VERSION " (PHP/" PHP_VERSION ")", 0); + ZVAL_STRING(&opt->defval, + "PECL_HTTP/" PHP_PECL_HTTP_VERSION " " + "PHP/" PHP_VERSION " " + "libcurl/" LIBCURL_VERSION + , 0); } /* resume */ @@ -1483,8 +1499,8 @@ static STATUS php_http_client_curl_handler_prepare(php_http_client_curl_handler_ } } php_http_buffer_dtor(&header); - curl_easy_setopt(curl->handle, CURLOPT_HTTPHEADER, curl->options.headers); } + curl_easy_setopt(curl->handle, CURLOPT_HTTPHEADER, curl->options.headers); /* attach request body */ if ((body_size = php_http_message_body_size(msg->body))) { @@ -1499,6 +1515,11 @@ static STATUS php_http_client_curl_handler_prepare(php_http_client_curl_handler_ curl_easy_setopt(curl->handle, CURLOPT_READDATA, msg->body); curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, body_size); curl_easy_setopt(curl->handle, CURLOPT_POSTFIELDSIZE, body_size); + } else { + curl_easy_setopt(curl->handle, CURLOPT_IOCTLDATA, NULL); + curl_easy_setopt(curl->handle, CURLOPT_READDATA, NULL); + curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, 0L); + curl_easy_setopt(curl->handle, CURLOPT_POSTFIELDSIZE, 0L); } php_http_options_apply(&php_http_curle_options, enqueue->options, curl); @@ -1764,11 +1785,12 @@ static int php_http_client_curl_once(php_http_client_t *h) static STATUS php_http_client_curl_exec(php_http_client_t *h) { - TSRMLS_FETCH_FROM_CTX(h->ts); - #if PHP_HTTP_HAVE_EVENT php_http_client_curl_t *curl = h->ctx; +#endif + TSRMLS_FETCH_FROM_CTX(h->ts); +#if PHP_HTTP_HAVE_EVENT if (curl->useevents) { php_http_curlm_timeout_callback(CURL_SOCKET_TIMEOUT, /*EV_READ|EV_WRITE*/0, h); do { @@ -1792,7 +1814,7 @@ static STATUS php_http_client_curl_exec(php_http_client_t *h) /* see http://msdn.microsoft.com/library/en-us/winsock/winsock/windows_sockets_error_codes_2.asp */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "WinSock error: %d", WSAGetLastError()); #else - php_error_docref(NULL TSRMLS_CC, E_WARNING, strerror(errno)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); #endif return FAILURE; } @@ -1974,7 +1996,11 @@ PHP_MINIT_FUNCTION(http_client_curl) PHP_MSHUTDOWN_FUNCTION(http_client_curl) { + php_persistent_handle_cleanup(ZEND_STRL("http\\Client\\Curl"), NULL, 0 TSRMLS_CC); + php_persistent_handle_cleanup(ZEND_STRL("http\\Client\\Curl\\Request"), NULL, 0 TSRMLS_CC); + php_http_options_dtor(&php_http_curle_options); + return SUCCESS; }