--- embedaddon/php/ext/curl/streams.c 2012/05/29 12:34:36 1.1.1.2 +++ embedaddon/php/ext/curl/streams.c 2013/07/22 01:31:38 1.1.1.3 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2012 The PHP Group | + | Copyright (c) 1997-2013 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c,v 1.1.1.2 2012/05/29 12:34:36 misho Exp $ */ +/* $Id: streams.c,v 1.1.1.3 2013/07/22 01:31:38 misho Exp $ */ /* This file implements cURL based wrappers. * NOTE: If you are implementing your own streams that are intended to @@ -162,6 +162,10 @@ static size_t php_curl_stream_read(php_stream *stream, } do { + FD_ZERO(&curlstream->readfds); + FD_ZERO(&curlstream->writefds); + FD_ZERO(&curlstream->excfds); + /* get the descriptors from curl */ curl_multi_fdset(curlstream->multi, &curlstream->readfds, &curlstream->writefds, &curlstream->excfds, &curlstream->maxfd); @@ -214,6 +218,10 @@ static int php_curl_stream_close(php_stream *stream, i curl_easy_cleanup(curlstream->curl); curl_multi_cleanup(curlstream->multi); + if (curlstream->headers_slist) { + curl_slist_free_all(curlstream->headers_slist); + } + /* we are not closing curlstream->readbuf here, because we export * it as a zval with the wrapperdata - the engine will garbage collect it */ @@ -264,7 +272,6 @@ php_stream *php_curl_stream_opener(php_stream_wrapper php_stream *stream; php_curl_stream *curlstream; zval *tmp, **ctx_opt = NULL; - struct curl_slist *slist = NULL; curlstream = emalloc(sizeof(php_curl_stream)); memset(curlstream, 0, sizeof(php_curl_stream)); @@ -275,6 +282,7 @@ php_stream *php_curl_stream_opener(php_stream_wrapper curlstream->curl = curl_easy_init(); curlstream->multi = curl_multi_init(); curlstream->pending = 1; + curlstream->headers_slist = NULL; /* if opening for an include statement, ensure that the local storage will * have a FILE* associated with it. @@ -323,7 +331,7 @@ php_stream *php_curl_stream_opener(php_stream_wrapper } if (SUCCESS == php_stream_context_get_option(context, "http", "curl_verify_ssl_host", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_BOOL && Z_LVAL_PP(ctx_opt) == 1) { - curl_easy_setopt(curlstream->curl, CURLOPT_SSL_VERIFYHOST, 1); + curl_easy_setopt(curlstream->curl, CURLOPT_SSL_VERIFYHOST, 2); } else { curl_easy_setopt(curlstream->curl, CURLOPT_SSL_VERIFYHOST, 0); } @@ -347,7 +355,7 @@ php_stream *php_curl_stream_opener(php_stream_wrapper zend_hash_move_forward_ex(Z_ARRVAL_PP(ctx_opt), &pos) ) { if (Z_TYPE_PP(header) == IS_STRING) { - slist = curl_slist_append(slist, Z_STRVAL_PP(header)); + curlstream->headers_slist = curl_slist_append(curlstream->headers_slist, Z_STRVAL_PP(header)); } } } else if (Z_TYPE_PP(ctx_opt) == IS_STRING && Z_STRLEN_PP(ctx_opt)) { @@ -357,14 +365,14 @@ php_stream *php_curl_stream_opener(php_stream_wrapper p = php_strtok_r(copy_ctx_opt, "\r\n", &token); while (p) { trimmed = php_trim(p, strlen(p), NULL, 0, NULL, 3 TSRMLS_CC); - slist = curl_slist_append(slist, trimmed); + curlstream->headers_slist = curl_slist_append(curlstream->headers_slist, trimmed); efree(trimmed); p = php_strtok_r(NULL, "\r\n", &token); } efree(copy_ctx_opt); } - if (slist) { - curl_easy_setopt(curlstream->curl, CURLOPT_HTTPHEADER, slist); + if (curlstream->headers_slist) { + curl_easy_setopt(curlstream->curl, CURLOPT_HTTPHEADER, curlstream->headers_slist); } } if (SUCCESS == php_stream_context_get_option(context, "http", "method", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_STRING) { @@ -412,7 +420,7 @@ php_stream *php_curl_stream_opener(php_stream_wrapper } } else if (context && !strncasecmp(filename, "ftps", sizeof("ftps")-1)) { if (SUCCESS == php_stream_context_get_option(context, "ftp", "curl_verify_ssl_host", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_BOOL && Z_LVAL_PP(ctx_opt) == 1) { - curl_easy_setopt(curlstream->curl, CURLOPT_SSL_VERIFYHOST, 1); + curl_easy_setopt(curlstream->curl, CURLOPT_SSL_VERIFYHOST, 2); } else { curl_easy_setopt(curlstream->curl, CURLOPT_SSL_VERIFYHOST, 0); } @@ -496,18 +504,10 @@ php_stream *php_curl_stream_opener(php_stream_wrapper } } - /* context headers are not needed anymore */ - if (slist) { - curl_easy_setopt(curlstream->curl, CURLOPT_HTTPHEADER, NULL); - curl_slist_free_all(slist); - } return stream; exit_fail: php_stream_close(stream); - if (slist) { - curl_slist_free_all(slist); - } return NULL; }