mike Thu May 25 12:41:35 2006 UTC Modified files: (Branch: PHP_5_2) /php-src NEWS /php-src/ext/curl streams.c Log: - implement standard http stream wrapper options, fixes bug #34180 - skip empty headers in on_header_available() http://cvs.php.net/viewcvs.cgi/php-src/NEWS?r1=1.2027.2.547.2.52&r2=1.2027.2.547.2.53&diff_format=u Index: php-src/NEWS diff -u php-src/NEWS:1.2027.2.547.2.52 php-src/NEWS:1.2027.2.547.2.53 --- php-src/NEWS:1.2027.2.547.2.52 Thu May 25 10:20:56 2006 +++ php-src/NEWS Thu May 25 12:41:35 2006 @@ -90,6 +90,8 @@ - Fixed bug #36630 (umask not reset at the end of the request). (Ilia) - Fixed bug #35512 (Lack of read permission on main script results in E_WARNING rather then E_ERROR). (Ilia) +- Fixed bug #34180 (--with-curlwrappers causes PHP to disregard some HTTP + stream context options). (Mike) 04 May 2006, PHP 5.1.4 - Added "capture_peer_cert" and "capture_peer_cert_chain" context options http://cvs.php.net/viewcvs.cgi/php-src/ext/curl/streams.c?r1=1.14.2.2&r2=1.14.2.2.2.1&diff_format=u Index: php-src/ext/curl/streams.c diff -u php-src/ext/curl/streams.c:1.14.2.2 php-src/ext/curl/streams.c:1.14.2.2.2.1 --- php-src/ext/curl/streams.c:1.14.2.2 Sun Jan 1 12:50:01 2006 +++ php-src/ext/curl/streams.c Thu May 25 12:41:35 2006 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c,v 1.14.2.2 2006/01/01 12:50:01 sniper Exp $ */ +/* $Id: streams.c,v 1.14.2.2.2.1 2006/05/25 12:41:35 mike Exp $ */ /* This file implements cURL based wrappers. * NOTE: If you are implementing your own streams that are intended to @@ -87,31 +87,32 @@ php_curl_stream *curlstream = (php_curl_stream *) stream->abstract; TSRMLS_FETCH(); - MAKE_STD_ZVAL(header); - Z_STRLEN_P(header) = length; - Z_STRVAL_P(header) = estrndup(data, length); - if (Z_STRVAL_P(header)[length-1] == '\n') { - Z_STRVAL_P(header)[length-1] = '\0'; - Z_STRLEN_P(header)--; - - if (Z_STRVAL_P(header)[length-2] == '\r') { - Z_STRVAL_P(header)[length-2] = '\0'; + if (!(length == 2 && data[0] == '\r' && data[1] == '\n')) { + MAKE_STD_ZVAL(header); + Z_STRLEN_P(header) = length; + Z_STRVAL_P(header) = estrndup(data, length); + if (Z_STRVAL_P(header)[length-1] == '\n') { + Z_STRVAL_P(header)[length-1] = '\0'; Z_STRLEN_P(header)--; + + if (Z_STRVAL_P(header)[length-2] == '\r') { + Z_STRVAL_P(header)[length-2] = '\0'; + Z_STRLEN_P(header)--; + } + } + Z_TYPE_P(header) = IS_STRING; + zend_hash_next_index_insert(Z_ARRVAL_P(curlstream->headers), &header, sizeof(zval *), NULL); + + /* based on the header, we might need to trigger a notification */ + if (!strncasecmp(data, "Location: ", 10)) { + php_stream_notify_info(stream->context, PHP_STREAM_NOTIFY_REDIRECTED, data + 10, 0); + } else if (!strncasecmp(data, "Content-Type: ", 14)) { + php_stream_notify_info(stream->context, PHP_STREAM_NOTIFY_MIME_TYPE_IS, data + 14, 0); + } else if (!strncasecmp(data, "Context-Length: ", 16)) { + php_stream_notify_file_size(stream->context, atoi(data + 16), data, 0); + php_stream_notify_progress_init(stream->context, 0, 0); } } - Z_TYPE_P(header) = IS_STRING; - zend_hash_next_index_insert(Z_ARRVAL_P(curlstream->headers), &header, sizeof(zval *), NULL); - - /* based on the header, we might need to trigger a notification */ - if (!strncasecmp(data, "Location: ", 10)) { - php_stream_notify_info(stream->context, PHP_STREAM_NOTIFY_REDIRECTED, data + 10, 0); - } else if (!strncasecmp(data, "Content-Type: ", 14)) { - php_stream_notify_info(stream->context, PHP_STREAM_NOTIFY_MIME_TYPE_IS, data + 14, 0); - } else if (!strncasecmp(data, "Context-Length: ", 16)) { - php_stream_notify_file_size(stream->context, atoi(data + 16), data, 0); - php_stream_notify_progress_init(stream->context, 0, 0); - } - return length; } @@ -251,7 +252,7 @@ { php_stream *stream; php_curl_stream *curlstream; - zval *tmp; + zval *tmp, **ctx_opt = NULL; curlstream = emalloc(sizeof(php_curl_stream)); memset(curlstream, 0, sizeof(php_curl_stream)); @@ -288,9 +289,6 @@ curl_easy_setopt(curlstream->curl, CURLOPT_HEADERFUNCTION, on_header_available); curl_easy_setopt(curlstream->curl, CURLOPT_WRITEHEADER, stream); - /* currently buggy (bug is in curl) */ - curl_easy_setopt(curlstream->curl, CURLOPT_FOLLOWLOCATION, 1); - curl_easy_setopt(curlstream->curl, CURLOPT_ERRORBUFFER, curlstream->errstr); curl_easy_setopt(curlstream->curl, CURLOPT_VERBOSE, 0); @@ -302,6 +300,63 @@ curl_easy_setopt(curlstream->curl, CURLOPT_USERAGENT, FG(user_agent) ? FG(user_agent) : "PHP/" PHP_VERSION); /* TODO: read cookies and options from context */ + if (!strncasecmp(filename, "http", sizeof("http")-1)) { + /* HTTP(S) */ + if (SUCCESS == php_stream_context_get_option(context, "http", "user_agent", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_STRING) { + curl_easy_setopt(curlstream->curl, CURLOPT_USERAGENT, Z_STRVAL_PP(ctx_opt)); + } + if (SUCCESS == php_stream_context_get_option(context, "http", "header", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_ARRAY) { + HashPosition pos; + zval **header = NULL; + struct curl_slist *hl = NULL; + + for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(ctx_opt), &pos); + SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(ctx_opt), (void *)&header, &pos); + zend_hash_move_forward_ex(Z_ARRVAL_PP(ctx_opt), &pos)) { + if (Z_TYPE_PP(header) == IS_STRING) { + hl = curl_slist_append(hl, Z_STRVAL_PP(header)); + } + } + if (hl) { + curl_easy_setopt(curlstream->curl, CURLOPT_HTTPHEADER, hl); + } + } + if (SUCCESS == php_stream_context_get_option(context, "http", "method", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_STRING) { + if (strcasecmp(Z_STRVAL_PP(ctx_opt), "get")) { + if (!strcasecmp(Z_STRVAL_PP(ctx_opt), "head")) { + curl_easy_setopt(curlstream->curl, CURLOPT_NOBODY, 1); + } else { + if (!strcasecmp(Z_STRVAL_PP(ctx_opt), "post")) { + curl_easy_setopt(curlstream->curl, CURLOPT_POST, 1); + } else { + curl_easy_setopt(curlstream->curl, CURLOPT_CUSTOMREQUEST, Z_STRVAL_PP(ctx_opt)); + } + if (SUCCESS == php_stream_context_get_option(context, "http", "content", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_STRING) { + curl_easy_setopt(curlstream->curl, CURLOPT_POSTFIELDS, Z_STRVAL_PP(ctx_opt)); + curl_easy_setopt(curlstream->curl, CURLOPT_POSTFIELDSIZE, (long)Z_STRLEN_PP(ctx_opt)); + } + } + } + } + if (SUCCESS == php_stream_context_get_option(context, "http", "proxy", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_STRING) { + curl_easy_setopt(curlstream->curl, CURLOPT_PROXY, Z_STRVAL_PP(ctx_opt)); + } + if (SUCCESS == php_stream_context_get_option(context, "http", "max_redirects", &ctx_opt)) { + long mr = 20; + if (Z_TYPE_PP(ctx_opt) != IS_STRING || !is_numeric_string(Z_STRVAL_PP(ctx_opt), Z_STRLEN_PP(ctx_opt), &mr, NULL, 1)) { + if (Z_TYPE_PP(ctx_opt) == IS_LONG) { + mr = Z_LVAL_PP(ctx_opt); + } + } + if (mr > 1) { + curl_easy_setopt(curlstream->curl, CURLOPT_FOLLOWLOCATION, 1L); + curl_easy_setopt(curlstream->curl, CURLOPT_MAXREDIRS, mr); + } + } else { + curl_easy_setopt(curlstream->curl, CURLOPT_FOLLOWLOCATION, 1L); + curl_easy_setopt(curlstream->curl, CURLOPT_MAXREDIRS, 20L); + } + } /* prepare for "pull" mode */ curl_multi_add_handle(curlstream->multi, curlstream->curl);
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php