cataphract                               Fri, 29 Oct 2010 15:29:15 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=304985

Log:
- Fixed bug #53198 (changing INI setting "from" with ini_set did not have any
  effect)
#Made "from" a proper INI setting and bound it to a global variable.
#Previously, it was simply read from the hash table with the parsed ini file
#by using cfg_get_string (I wonder why this mechanism still exists...)

Bug: http://bugs.php.net/53198 (Assigned) "From:" header sent on http request 
when using stream_context.
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/standard/file.c
    U   php/php-src/branches/PHP_5_3/ext/standard/file.h
    U   php/php-src/branches/PHP_5_3/ext/standard/ftp_fopen_wrapper.c
    U   php/php-src/branches/PHP_5_3/ext/standard/http_fopen_wrapper.c
    A   php/php-src/branches/PHP_5_3/ext/standard/tests/http/bug53198.phpt
    U   php/php-src/trunk/ext/standard/file.c
    U   php/php-src/trunk/ext/standard/file.h
    U   php/php-src/trunk/ext/standard/ftp_fopen_wrapper.c
    U   php/php-src/trunk/ext/standard/http_fopen_wrapper.c
    A   php/php-src/trunk/ext/standard/tests/http/bug53198.phpt

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS	2010-10-29 15:02:39 UTC (rev 304984)
+++ php/php-src/branches/PHP_5_3/NEWS	2010-10-29 15:29:15 UTC (rev 304985)
@@ -44,6 +44,8 @@
 - Fixed ReflectionProperty::isDefault() giving a wrong result for properties
   obtained with ReflectionClass::getProperties(). (Gustavo)

+- Fixed bug #53198 (changing INI setting "from" with ini_set did not have any
+  effect). (Gustavo)
 - Fixed bug #53180 (post_max_size=0 not disabling the limit when the content
   type is application/x-www-form-urlencoded or is not registered with PHP).
   (gm at tlink dot de, Gustavo)

Modified: php/php-src/branches/PHP_5_3/ext/standard/file.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/file.c	2010-10-29 15:02:39 UTC (rev 304984)
+++ php/php-src/branches/PHP_5_3/ext/standard/file.c	2010-10-29 15:29:15 UTC (rev 304985)
@@ -170,6 +170,7 @@

 PHP_INI_BEGIN()
 	STD_PHP_INI_ENTRY("user_agent", NULL, PHP_INI_ALL, OnUpdateString, user_agent, php_file_globals, file_globals)
+	STD_PHP_INI_ENTRY("from", NULL, PHP_INI_ALL, OnUpdateString, from_address, php_file_globals, file_globals)
 	STD_PHP_INI_ENTRY("default_socket_timeout", "60", PHP_INI_ALL, OnUpdateLong, default_socket_timeout, php_file_globals, file_globals)
 	STD_PHP_INI_ENTRY("auto_detect_line_endings", "0", PHP_INI_ALL, OnUpdateLong, auto_detect_line_endings, php_file_globals, file_globals)
 PHP_INI_END()

Modified: php/php-src/branches/PHP_5_3/ext/standard/file.h
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/file.h	2010-10-29 15:02:39 UTC (rev 304984)
+++ php/php-src/branches/PHP_5_3/ext/standard/file.h	2010-10-29 15:29:15 UTC (rev 304985)
@@ -118,7 +118,8 @@
 	size_t def_chunk_size;
 	long auto_detect_line_endings;
 	long default_socket_timeout;
-	char *user_agent;
+	char *user_agent; /* for the http wrapper */
+	char *from_address; /* for the ftp and http wrappers */
 	char *user_stream_current_filename; /* for simple recursion protection */
 	php_stream_context *default_context;
 	HashTable *stream_wrappers;			/* per-request copy of url_stream_wrappers_hash */

Modified: php/php-src/branches/PHP_5_3/ext/standard/ftp_fopen_wrapper.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/ftp_fopen_wrapper.c	2010-10-29 15:02:39 UTC (rev 304984)
+++ php/php-src/branches/PHP_5_3/ext/standard/ftp_fopen_wrapper.c	2010-10-29 15:29:15 UTC (rev 304985)
@@ -116,7 +116,6 @@
 	php_stream *stream = NULL, *reuseid = NULL;
 	php_url *resource = NULL;
 	int result, use_ssl, use_ssl_on_data = 0, tmp_len;
-	char *scratch;
 	char tmp_line[512];
 	char *transport;
 	int transport_len;
@@ -250,8 +249,8 @@
 		} else {
 			/* if the user has configured who they are,
 			   send that as the password */
-			if (cfg_get_string("from", &scratch) == SUCCESS) {
-				php_stream_printf(stream TSRMLS_CC, "PASS %s\r\n", scratch);
+			if (FG(from_address)) {
+				php_stream_printf(stream TSRMLS_CC, "PASS %s\r\n", FG(from_address));
 			} else {
 				php_stream_write_string(stream, "PASS anonymous\r\n");
 			}

Modified: php/php-src/branches/PHP_5_3/ext/standard/http_fopen_wrapper.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/http_fopen_wrapper.c	2010-10-29 15:02:39 UTC (rev 304984)
+++ php/php-src/branches/PHP_5_3/ext/standard/http_fopen_wrapper.c	2010-10-29 15:29:15 UTC (rev 304985)
@@ -443,8 +443,8 @@
 	}

 	/* if the user has configured who they are, send a From: line */
-	if (((have_header & HTTP_HEADER_FROM) == 0) && cfg_get_string("from", &tmp) == SUCCESS) {
-		if (snprintf(scratch, scratch_len, "From: %s\r\n", tmp) > 0)
+	if (((have_header & HTTP_HEADER_FROM) == 0) && FG(from_address)) {
+		if (snprintf(scratch, scratch_len, "From: %s\r\n", FG(from_address)) > 0)
 			php_stream_write(stream, scratch, strlen(scratch));
 	}


Added: php/php-src/branches/PHP_5_3/ext/standard/tests/http/bug53198.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/tests/http/bug53198.phpt	                        (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/standard/tests/http/bug53198.phpt	2010-10-29 15:29:15 UTC (rev 304985)
@@ -0,0 +1,56 @@
+--TEST--
+Bug #53198 (From: header cannot be changed with ini_set)
+--SKIPIF--
+<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
+--INI--
+from=te...@teste.pt
+--FILE--
+<?php
+require 'server.inc';
+
+function do_test() {
+
+	$responses = array(
+		"data://text/plain,HTTP/1.0 200 OK\r\n\r\n",
+	);
+
+	$pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
+
+	foreach($responses as $r) {
+
+		$fd = fopen('http://127.0.0.1:12342/', 'rb', false);
+
+		fseek($output, 0, SEEK_SET);
+		var_dump(stream_get_contents($output));
+		fseek($output, 0, SEEK_SET);
+	}
+
+	http_server_kill($pid);
+
+}
+
+echo "-- Test: leave default --\n";
+
+do_test();
+
+echo "-- Test: after ini_set --\n";
+
+ini_set('from', 'j...@junk.com');
+
+do_test();
+
+?>
+--EXPECT--
+-- Test: leave default --
+string(63) "GET / HTTP/1.0
+From: te...@teste.pt
+Host: 127.0.0.1:12342
+
+"
+-- Test: after ini_set --
+string(62) "GET / HTTP/1.0
+From: j...@junk.com
+Host: 127.0.0.1:12342
+
+"
+

Modified: php/php-src/trunk/ext/standard/file.c
===================================================================
--- php/php-src/trunk/ext/standard/file.c	2010-10-29 15:02:39 UTC (rev 304984)
+++ php/php-src/trunk/ext/standard/file.c	2010-10-29 15:29:15 UTC (rev 304985)
@@ -169,6 +169,7 @@

 PHP_INI_BEGIN()
 	STD_PHP_INI_ENTRY("user_agent", NULL, PHP_INI_ALL, OnUpdateString, user_agent, php_file_globals, file_globals)
+	STD_PHP_INI_ENTRY("from", NULL, PHP_INI_ALL, OnUpdateString, from_address, php_file_globals, file_globals)
 	STD_PHP_INI_ENTRY("default_socket_timeout", "60", PHP_INI_ALL, OnUpdateLong, default_socket_timeout, php_file_globals, file_globals)
 	STD_PHP_INI_ENTRY("auto_detect_line_endings", "0", PHP_INI_ALL, OnUpdateLong, auto_detect_line_endings, php_file_globals, file_globals)
 PHP_INI_END()

Modified: php/php-src/trunk/ext/standard/file.h
===================================================================
--- php/php-src/trunk/ext/standard/file.h	2010-10-29 15:02:39 UTC (rev 304984)
+++ php/php-src/trunk/ext/standard/file.h	2010-10-29 15:29:15 UTC (rev 304985)
@@ -118,7 +118,8 @@
 	size_t def_chunk_size;
 	long auto_detect_line_endings;
 	long default_socket_timeout;
-	char *user_agent;
+	char *user_agent; /* for the http wrapper */
+	char *from_address; /* for the ftp and http wrappers */
 	char *user_stream_current_filename; /* for simple recursion protection */
 	php_stream_context *default_context;
 	HashTable *stream_wrappers;			/* per-request copy of url_stream_wrappers_hash */

Modified: php/php-src/trunk/ext/standard/ftp_fopen_wrapper.c
===================================================================
--- php/php-src/trunk/ext/standard/ftp_fopen_wrapper.c	2010-10-29 15:02:39 UTC (rev 304984)
+++ php/php-src/trunk/ext/standard/ftp_fopen_wrapper.c	2010-10-29 15:29:15 UTC (rev 304985)
@@ -116,7 +116,6 @@
 	php_stream *stream = NULL, *reuseid = NULL;
 	php_url *resource = NULL;
 	int result, use_ssl, use_ssl_on_data = 0, tmp_len;
-	char *scratch;
 	char tmp_line[512];
 	char *transport;
 	int transport_len;
@@ -250,8 +249,8 @@
 		} else {
 			/* if the user has configured who they are,
 			   send that as the password */
-			if (cfg_get_string("from", &scratch) == SUCCESS) {
-				php_stream_printf(stream TSRMLS_CC, "PASS %s\r\n", scratch);
+			if (FG(from_address)) {
+				php_stream_printf(stream TSRMLS_CC, "PASS %s\r\n", FG(from_address));
 			} else {
 				php_stream_write_string(stream, "PASS anonymous\r\n");
 			}

Modified: php/php-src/trunk/ext/standard/http_fopen_wrapper.c
===================================================================
--- php/php-src/trunk/ext/standard/http_fopen_wrapper.c	2010-10-29 15:02:39 UTC (rev 304984)
+++ php/php-src/trunk/ext/standard/http_fopen_wrapper.c	2010-10-29 15:29:15 UTC (rev 304985)
@@ -443,8 +443,8 @@
 	}

 	/* if the user has configured who they are, send a From: line */
-	if (((have_header & HTTP_HEADER_FROM) == 0) && cfg_get_string("from", &tmp) == SUCCESS) {
-		if (snprintf(scratch, scratch_len, "From: %s\r\n", tmp) > 0)
+	if (((have_header & HTTP_HEADER_FROM) == 0) && FG(from_address)) {
+		if (snprintf(scratch, scratch_len, "From: %s\r\n", FG(from_address)) > 0)
 			php_stream_write(stream, scratch, strlen(scratch));
 	}


Added: php/php-src/trunk/ext/standard/tests/http/bug53198.phpt
===================================================================
--- php/php-src/trunk/ext/standard/tests/http/bug53198.phpt	                        (rev 0)
+++ php/php-src/trunk/ext/standard/tests/http/bug53198.phpt	2010-10-29 15:29:15 UTC (rev 304985)
@@ -0,0 +1,56 @@
+--TEST--
+Bug #53198 (From: header cannot be changed with ini_set)
+--SKIPIF--
+<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
+--INI--
+from=te...@teste.pt
+--FILE--
+<?php
+require 'server.inc';
+
+function do_test() {
+
+	$responses = array(
+		"data://text/plain,HTTP/1.0 200 OK\r\n\r\n",
+	);
+
+	$pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
+
+	foreach($responses as $r) {
+
+		$fd = fopen('http://127.0.0.1:12342/', 'rb', false);
+
+		fseek($output, 0, SEEK_SET);
+		var_dump(stream_get_contents($output));
+		fseek($output, 0, SEEK_SET);
+	}
+
+	http_server_kill($pid);
+
+}
+
+echo "-- Test: leave default --\n";
+
+do_test();
+
+echo "-- Test: after ini_set --\n";
+
+ini_set('from', 'j...@junk.com');
+
+do_test();
+
+?>
+--EXPECT--
+-- Test: leave default --
+string(63) "GET / HTTP/1.0
+From: te...@teste.pt
+Host: 127.0.0.1:12342
+
+"
+-- Test: after ini_set --
+string(62) "GET / HTTP/1.0
+From: j...@junk.com
+Host: 127.0.0.1:12342
+
+"
+
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to