jani Tue May 5 00:30:40 2009 UTC
Modified files:
/php-src/ext/curl streams.c
/php-src/ext/standard http_fopen_wrapper.c
Log:
- Fixed bug #45092 (header HTTP context option not being used with
--with-curlwrappers)
[DOC] Synced regular and cURL http wrapper "header" option to accept
[DOC] either string or array.
http://cvs.php.net/viewvc.cgi/php-src/ext/curl/streams.c?r1=1.32&r2=1.33&diff_format=u
Index: php-src/ext/curl/streams.c
diff -u php-src/ext/curl/streams.c:1.32 php-src/ext/curl/streams.c:1.33
--- php-src/ext/curl/streams.c:1.32 Tue Mar 10 23:39:11 2009
+++ php-src/ext/curl/streams.c Tue May 5 00:30:40 2009
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: streams.c,v 1.32 2009/03/10 23:39:11 helly Exp $ */
+/* $Id: streams.c,v 1.33 2009/05/05 00:30:40 jani Exp $ */
/* This file implements cURL based wrappers.
* NOTE: If you are implementing your own streams that are intended to
@@ -48,6 +48,7 @@
#include "ext/standard/php_smart_str.h"
#include "ext/standard/info.h"
#include "ext/standard/file.h"
+#include "ext/standard/php_string.h"
#include "php_curl.h"
static size_t on_data_available(char *data, size_t size, size_t nmemb, void
*ctx)
@@ -263,6 +264,7 @@
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));
@@ -311,6 +313,15 @@
/* TODO: read cookies and options from context */
if (context && !strncasecmp(filename, "http", sizeof("http")-1)) {
+ /* Protocol version */
+ if (SUCCESS == php_stream_context_get_option(context, "http",
"protocol_version", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_DOUBLE) {
+ if (Z_DVAL_PP(ctx_opt) == 1.1) {
+ curl_easy_setopt(curlstream->curl,
CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
+ } else {
+ curl_easy_setopt(curlstream->curl,
CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
+ }
+ }
+
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);
} else {
@@ -326,20 +337,34 @@
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;
+ if (SUCCESS == php_stream_context_get_option(context, "http",
"header", &ctx_opt)) {
+ if (Z_TYPE_PP(ctx_opt) == IS_ARRAY) {
+ HashPosition pos;
+ zval **header = 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));
+ 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) {
+ slist =
curl_slist_append(slist, Z_STRVAL_PP(header));
+ }
}
+ } else if (Z_TYPE_PP(ctx_opt) == IS_STRING &&
Z_STRLEN_PP(ctx_opt)) {
+ char *p, *token, *trimmed, *copy_ctx_opt;
+
+ copy_ctx_opt = php_trim(Z_STRVAL_PP(ctx_opt),
Z_STRLEN_PP(ctx_opt), NULL, 0, NULL, 3 TSRMLS_CC);
+ 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);
+ efree(trimmed);
+ p = php_strtok_r(NULL, "\r\n", &token);
+ }
+ efree(copy_ctx_opt);
}
- if (hl) {
- curl_easy_setopt(curlstream->curl,
CURLOPT_HTTPHEADER, hl);
+ if (slist) {
+ curl_easy_setopt(curlstream->curl,
CURLOPT_HTTPHEADER, slist);
}
}
if (SUCCESS == php_stream_context_get_option(context, "http",
"method", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_STRING) {
@@ -472,7 +497,9 @@
return NULL;
}
}
-
+ if (slist) {
+ curl_slist_free_all(slist);
+ }
return stream;
}
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/http_fopen_wrapper.c?r1=1.141&r2=1.142&diff_format=u
Index: php-src/ext/standard/http_fopen_wrapper.c
diff -u php-src/ext/standard/http_fopen_wrapper.c:1.141
php-src/ext/standard/http_fopen_wrapper.c:1.142
--- php-src/ext/standard/http_fopen_wrapper.c:1.141 Thu Apr 16 10:34:15 2009
+++ php-src/ext/standard/http_fopen_wrapper.c Tue May 5 00:30:40 2009
@@ -19,7 +19,7 @@
| Sara Golemon <[email protected]> |
+----------------------------------------------------------------------+
*/
-/* $Id: http_fopen_wrapper.c,v 1.141 2009/04/16 10:34:15 dmitry Exp $ */
+/* $Id: http_fopen_wrapper.c,v 1.142 2009/05/05 00:30:40 jani Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -373,13 +373,31 @@
/* send it */
php_stream_write(stream, scratch, strlen(scratch));
- if (context &&
- php_stream_context_get_option(context, "http", "header",
&tmpzval) == SUCCESS &&
- Z_TYPE_PP(tmpzval) == IS_STRING && Z_STRLEN_PP(tmpzval)) {
- /* Remove newlines and spaces from start and end,
- php_trim will estrndup() */
- tmp = php_trim(Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval),
NULL, 0, NULL, 3 TSRMLS_CC);
- if (strlen(tmp) > 0) {
+ if (context && php_stream_context_get_option(context, "http", "header",
&tmpzval) == SUCCESS) {
+ tmp = NULL;
+
+ if (Z_TYPE_PP(tmpzval) == IS_ARRAY) {
+ HashPosition pos;
+ zval **tmpheader = NULL;
+ smart_str tmpstr = {0};
+
+ for
(zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(tmpzval), &pos);
+ SUCCESS ==
zend_hash_get_current_data_ex(Z_ARRVAL_PP(tmpzval), (void *)&tmpheader, &pos);
+ zend_hash_move_forward_ex(Z_ARRVAL_PP(tmpzval),
&pos)
+ ) {
+ if (Z_TYPE_PP(tmpheader) == IS_STRING) {
+ smart_str_appendl(&tmpstr,
Z_STRVAL_PP(tmpheader), Z_STRLEN_PP(tmpheader));
+ smart_str_appendl(&tmpstr, "\r\n",
sizeof("\r\n") - 1);
+ }
+ }
+ smart_str_0(&tmpstr);
+ tmp = tmpstr.c;
+ }
+ if (Z_TYPE_PP(tmpzval) == IS_STRING && Z_STRLEN_PP(tmpzval)) {
+ /* Remove newlines and spaces from start and end
php_trim will estrndup() */
+ tmp = php_trim(Z_STRVAL_PP(tmpzval),
Z_STRLEN_PP(tmpzval), NULL, 0, NULL, 3 TSRMLS_CC);
+ }
+ if (tmp && strlen(tmp) > 0) {
if (!header_init) { /* Remove post headers for
redirects */
int l = strlen(tmp);
char *s, *s2, *tmp_c = estrdup(tmp);