[PHP-CVS] cvs: php4 /ext/standard http_fopen_wrapper.c
pollita Fri Jun 13 15:27:26 2003 EDT Modified files: /php4/ext/standard http_fopen_wrapper.c Log: Loosen restrictions on method used with http_fopen_wrapper, still default to GET though. Index: php4/ext/standard/http_fopen_wrapper.c diff -u php4/ext/standard/http_fopen_wrapper.c:1.74 php4/ext/standard/http_fopen_wrapper.c:1.75 --- php4/ext/standard/http_fopen_wrapper.c:1.74 Tue Jun 10 16:03:37 2003 +++ php4/ext/standard/http_fopen_wrapper.c Fri Jun 13 15:27:26 2003 @@ -18,7 +18,7 @@ | Wez Furlong [EMAIL PROTECTED] | +--+ */ -/* $Id: http_fopen_wrapper.c,v 1.74 2003/06/10 20:03:37 imajes Exp $ */ +/* $Id: http_fopen_wrapper.c,v 1.75 2003/06/13 19:27:26 pollita Exp $ */ #include php.h #include php_globals.h @@ -164,15 +164,19 @@ php_stream_notify_info(context, PHP_STREAM_NOTIFY_CONNECT, NULL, 0); - scratch_len = strlen(path) + 32; - scratch = emalloc(scratch_len); - if (context - php_stream_context_get_option(context, http, method, tmpzval) == SUCCESS - Z_STRLEN_PP(tmpzval) 0 - strncasecmp(Z_STRVAL_PP(tmpzval), POST, Z_STRLEN_PP(tmpzval)) == 0) { - strcpy(scratch, POST ); - } else { + php_stream_context_get_option(context, http, method, tmpzval) == SUCCESS) { + if (Z_TYPE_PP(tmpzval) == IS_STRING Z_STRLEN_PP(tmpzval) 0) { + scratch_len = strlen(path) + 29 + Z_STRLEN_PP(tmpzval); + scratch = emalloc(scratch_len); + strlcpy(scratch, Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval) + 1); + strcat(scratch, ); + } + } + + if (!scratch) { + scratch_len = strlen(path) + 32; + scratch = emalloc(scratch_len); strcpy(scratch, GET ); } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard http_fopen_wrapper.c
iliaa Tue Mar 4 11:04:07 2003 EDT Modified files: /php4/ext/standard http_fopen_wrapper.c Log: Added support for http redirects to ftp. Fixed bug #22508 (Added protection against circular HTML redirects). Index: php4/ext/standard/http_fopen_wrapper.c diff -u php4/ext/standard/http_fopen_wrapper.c:1.68 php4/ext/standard/http_fopen_wrapper.c:1.69 --- php4/ext/standard/http_fopen_wrapper.c:1.68 Thu Feb 27 13:16:34 2003 +++ php4/ext/standard/http_fopen_wrapper.c Tue Mar 4 11:04:05 2003 @@ -18,7 +18,7 @@ | Wez Furlong [EMAIL PROTECTED] | +--+ */ -/* $Id: http_fopen_wrapper.c,v 1.68 2003/02/27 18:16:34 wez Exp $ */ +/* $Id: http_fopen_wrapper.c,v 1.69 2003/03/04 16:04:05 iliaa Exp $ */ #include php.h #include php_globals.h @@ -80,8 +80,10 @@ #include php_fopen_wrappers.h #define HTTP_HEADER_BLOCK_SIZE 1024 +#define PHP_URL_REDIRECT_MAX 20 -php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) + +php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context, int redirect_max STREAMS_DC TSRMLS_DC) { php_stream *stream = NULL; php_url *resource = NULL; @@ -102,14 +104,25 @@ char *transport_string, *errstr = NULL; int transport_len; + if (redirect_max 1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, Circular redirect, aborting.); + return NULL; + } + if (strpbrk(mode, awx+)) { php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, HTTP wrapper does not support writeable connections.); return NULL; } resource = php_url_parse(path); - if (resource == NULL) + if (resource == NULL) { return NULL; + } + + if (strncasecmp(resource-scheme, http, sizeof(http)) strncasecmp(resource-scheme, https, sizeof(https))) { + php_url_free(resource); + return php_stream_open_wrapper_ex(path, mode, ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); + } use_ssl = resource-scheme (strlen(resource-scheme) 4) resource-scheme[4] == 's'; /* choose default ports */ @@ -349,7 +362,11 @@ char loc_path[HTTP_HEADER_BLOCK_SIZE]; *new_path='\0'; - if (strlen(location)8 || (strncasecmp(location, http://;, sizeof(http://;)-1) strncasecmp(location, https://;, sizeof(https://;)-1))) { + if (strlen(location)8 || (strncasecmp(location, http://;, sizeof(http://;)-1) + strncasecmp(location, https://;, sizeof(https://;)-1) + strncasecmp(location, ftp://;, sizeof(ftp://;)-1) + strncasecmp(location, ftps://, sizeof(ftps://)-1))) + { if (*location != '/') { if (*(location+1) != '\0' resource-path) { char *s = strrchr(resource-path, '/'); @@ -377,7 +394,7 @@ } else { strlcpy(new_path, location, sizeof(new_path)); } - stream = php_stream_url_wrap_http(NULL, new_path, mode, options, opened_path, context STREAMS_CC TSRMLS_CC); + stream = php_stream_url_wrap_http_ex(NULL, new_path, mode, options, opened_path, context, --redirect_max STREAMS_CC TSRMLS_CC); if (stream stream-wrapperdata) { entryp = entry; MAKE_STD_ZVAL(entry); @@ -433,6 +450,11 @@ } return stream; +} + +php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) +{ + return php_stream_url_wrap_http_ex(wrapper, path, mode, options, opened_path, context, PHP_URL_REDIRECT_MAX STREAMS_CC TSRMLS_CC); } static int php_stream_http_stream_stat(php_stream_wrapper *wrapper, -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard http_fopen_wrapper.c
iliaa Wed Feb 19 19:34:04 2003 EDT Modified files: /php4/ext/standard http_fopen_wrapper.c Log: Revert accidental commit. Index: php4/ext/standard/http_fopen_wrapper.c diff -u php4/ext/standard/http_fopen_wrapper.c:1.65 php4/ext/standard/http_fopen_wrapper.c:1.66 --- php4/ext/standard/http_fopen_wrapper.c:1.65 Wed Feb 19 19:32:51 2003 +++ php4/ext/standard/http_fopen_wrapper.c Wed Feb 19 19:34:03 2003 @@ -18,7 +18,7 @@ | Wez Furlong [EMAIL PROTECTED] | +--+ */ -/* $Id: http_fopen_wrapper.c,v 1.65 2003/02/20 00:32:51 iliaa Exp $ */ +/* $Id: http_fopen_wrapper.c,v 1.66 2003/02/20 00:34:03 iliaa Exp $ */ #include php.h #include php_globals.h @@ -354,7 +354,7 @@ s = resource-path; *s = '/'; } - *(s + 1) = '\0'; + s[1] = '\0'; if (resource-path *(resource-path) == '/' *(resource-path + 1) == '\0') { snprintf(loc_path, sizeof(loc_path) - 1, %s%s, resource-path, location); } else { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard http_fopen_wrapper.c
wez Thu Feb 13 08:38:20 2003 EDT Modified files: /php4/ext/standard http_fopen_wrapper.c Log: Avoid problems with chunk_size and auto_detect_line_endings. Index: php4/ext/standard/http_fopen_wrapper.c diff -u php4/ext/standard/http_fopen_wrapper.c:1.59 php4/ext/standard/http_fopen_wrapper.c:1.60 --- php4/ext/standard/http_fopen_wrapper.c:1.59 Fri Feb 7 18:44:58 2003 +++ php4/ext/standard/http_fopen_wrapper.c Thu Feb 13 08:38:20 2003 @@ -18,7 +18,7 @@ | Wez Furlong [EMAIL PROTECTED] | +--+ */ -/* $Id: http_fopen_wrapper.c,v 1.59 2003/02/07 23:44:58 pollita Exp $ */ +/* $Id: http_fopen_wrapper.c,v 1.60 2003/02/13 13:38:20 wez Exp $ */ #include php.h #include php_globals.h @@ -100,6 +100,7 @@ char *http_header_line = NULL; char tmp_line[128]; size_t chunk_size = 0, file_size = 0; + int eol_detect; if (strchr(mode, 'a') || strchr(mode, '+') || strchr(mode, 'w')) { php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, HTTP wrapper does not support writeable connections.); @@ -123,8 +124,14 @@ goto out; /* avoid buffering issues while reading header */ - chunk_size = php_stream_set_chunk_size(stream, 1); + if (options STREAM_WILL_CAST) + chunk_size = php_stream_set_chunk_size(stream, 1); + /* avoid problems with auto-detecting when reading the headers - the headers +* are always in canonical \r\n format */ + eol_detect = stream-flags (PHP_STREAM_FLAG_DETECT_EOL | +PHP_STREAM_FLAG_EOL_MAC); + stream-flags = ~(PHP_STREAM_FLAG_DETECT_EOL | PHP_STREAM_FLAG_EOL_MAC); + php_stream_context_set(stream, context); php_stream_notify_info(context, PHP_STREAM_NOTIFY_CONNECT, NULL, 0); @@ -400,7 +407,12 @@ stream-wrapperdata = response_header; php_stream_notify_progress_init(context, 0, file_size); /* Restore original chunk size now that we're done with headers */ - php_stream_set_chunk_size(stream, chunk_size); + if (options STREAM_WILL_CAST) + php_stream_set_chunk_size(stream, chunk_size); + + /* restore the users auto-detect-line-endings setting */ + stream-flags |= eol_detect; + /* as far as streams are concerned, we are now at the start of * the stream */ stream-position = 0; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard http_fopen_wrapper.c
On Fri, Jan 03, 2003 at 05:12:36PM -, Ilia Alshanetsky wrote: iliaa Fri Jan 3 12:12:36 2003 EDT Modified files: /php4/ext/standardhttp_fopen_wrapper.c Log: Fixed a memory leak that occurs if the location specified by redirect header cannot be opened. Please avoid mixing style-related commits with behavioral changes. Your fix adds two new lines, but one needs to read through about ten lines of changes to find those two lines. -- Jon Parise ([EMAIL PROTECTED]) :: The PHP Project (http://www.php.net/) -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard http_fopen_wrapper.c
iliaa Fri Jan 3 12:12:36 2003 EDT Modified files: /php4/ext/standard http_fopen_wrapper.c Log: Fixed a memory leak that occurs if the location specified by redirect header cannot be opened. Index: php4/ext/standard/http_fopen_wrapper.c diff -u php4/ext/standard/http_fopen_wrapper.c:1.57 php4/ext/standard/http_fopen_wrapper.c:1.58 --- php4/ext/standard/http_fopen_wrapper.c:1.57 Fri Jan 3 12:05:16 2003 +++ php4/ext/standard/http_fopen_wrapper.c Fri Jan 3 12:12:35 2003 @@ -18,7 +18,7 @@ | Wez Furlong [EMAIL PROTECTED] | +--+ */ -/* $Id: http_fopen_wrapper.c,v 1.57 2003/01/03 17:05:16 iliaa Exp $ */ +/* $Id: http_fopen_wrapper.c,v 1.58 2003/01/03 17:12:35 iliaa Exp $ */ #include php.h #include php_globals.h @@ -311,9 +311,9 @@ php_stream_notify_file_size(context, file_size, http_header_line, 0); } - if (http_header_line[0] == '\0') + if (http_header_line[0] == '\0') { body = 1; - else{ + } else { zval *http_header; MAKE_STD_ZVAL(http_header); @@ -322,9 +322,9 @@ zend_hash_next_index_insert(Z_ARRVAL_P(response_header), http_header, sizeof(zval *), NULL); } - } - else + } else { break; + } } } @@ -379,9 +379,11 @@ } zval_dtor(stream-wrapperdata); FREE_ZVAL(stream-wrapperdata); + } else { + zval_dtor(response_header); + FREE_ZVAL(response_header); } } else { - zval_dtor(response_header); FREE_ZVAL(response_header); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard http_fopen_wrapper.c
iliaa Sun Dec 29 15:01:34 2002 EDT Modified files: /php4/ext/standard http_fopen_wrapper.c Log: Fixed bug #21267 (opening URLs that result in redirection to a relative path was failing). Index: php4/ext/standard/http_fopen_wrapper.c diff -u php4/ext/standard/http_fopen_wrapper.c:1.54 php4/ext/standard/http_fopen_wrapper.c:1.55 --- php4/ext/standard/http_fopen_wrapper.c:1.54 Thu Dec 5 15:59:49 2002 +++ php4/ext/standard/http_fopen_wrapper.c Sun Dec 29 15:01:33 2002 @@ -18,7 +18,7 @@ | Wez Furlong [EMAIL PROTECTED] | +--+ */ -/* $Id: http_fopen_wrapper.c,v 1.54 2002/12/05 20:59:49 helly Exp $ */ +/* $Id: http_fopen_wrapper.c,v 1.55 2002/12/29 20:01:33 iliaa Exp $ */ #include php.h #include php_globals.h @@ -339,19 +339,25 @@ zval *entry, **entryp; char new_path[HTTP_HEADER_BLOCK_SIZE]; + char loc_path[HTTP_HEADER_BLOCK_SIZE]; *new_path='\0'; - if (strlen(location)8 || (strncasecmp(location, http://;, 7) strncasecmp(location, https://;, 8))) { - strcpy(new_path, resource-scheme); - strlcat(new_path, resource-host, sizeof(new_path)); - if ((use_ssl resource-port != 443) || (!use_ssl resource-port != 80)) { - snprintf(new_path+strlen(new_path), sizeof(new_path)-strlen(new_path)-1, :%d, resource-port); - } + if (strlen(location)8 || (strncasecmp(location, http://;, +sizeof(http://;)-1) strncasecmp(location, https://;, sizeof(https://;)-1))) { if (*location != '/') { - php_dirname(resource-path, strlen(resource-path)); - snprintf (new_path+strlen(new_path), sizeof(new_path)-strlen(new_path)-1, %s/, resource-path); + if (*(location+1) != '\0') { + + php_dirname(resource-path, +strlen(resource-path)); + snprintf(loc_path, sizeof(loc_path) - +1, %s%s, resource-path, location); + } else { + snprintf(loc_path, sizeof(loc_path) - +1, /%s, location); + } + } else { + strlcpy(loc_path, location, sizeof(loc_path)); + } + if ((use_ssl resource-port != 443) || (!use_ssl +resource-port != 80)) { + snprintf(new_path, sizeof(new_path) - 1, +%s://%s:%d%s, resource-scheme, resource-host, resource-port, loc_path); + } else { + snprintf(new_path, sizeof(new_path) - 1, +%s://%s%s, resource-scheme, resource-host, loc_path); } - strlcat(new_path, location, sizeof(new_path)); } else { strlcpy(new_path, location, sizeof(new_path)); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard http_fopen_wrapper.c
Are you going to merge this into PHP_4_3? On Sun, 29 Dec 2002, Ilia Alshanetsky wrote: iliaa Sun Dec 29 15:01:34 2002 EDT Modified files: /php4/ext/standardhttp_fopen_wrapper.c Log: Fixed bug #21267 (opening URLs that result in redirection to a relative path was failing). -Andrei http://www.gravitonic.com/ For every complex problem, there is a solution that is simple, neat, and wrong. -- H. L. Mencken -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard http_fopen_wrapper.c
wez Sat Oct 12 21:03:44 2002 EDT Modified files: /php4/ext/standard http_fopen_wrapper.c Log: Make PHP follow 301 correctly. # There may be other cases that need handling properly; I'll have to spend # some time investigating why we even need special cases now; it's got # something to do with Ilia's patch to fix memory leaks. Index: php4/ext/standard/http_fopen_wrapper.c diff -u php4/ext/standard/http_fopen_wrapper.c:1.52 php4/ext/standard/http_fopen_wrapper.c:1.53 --- php4/ext/standard/http_fopen_wrapper.c:1.52 Sat Sep 28 18:14:21 2002 +++ php4/ext/standard/http_fopen_wrapper.c Sat Oct 12 21:03:43 2002 @@ -18,7 +18,7 @@ | Wez Furlong [EMAIL PROTECTED] | +--+ */ -/* $Id: http_fopen_wrapper.c,v 1.52 2002/09/28 22:14:21 wez Exp $ */ +/* $Id: http_fopen_wrapper.c,v 1.53 2002/10/13 01:03:43 wez Exp $ */ #include php.h #include php_globals.h @@ -249,6 +249,7 @@ switch(response_code) { case 200: case 302: + case 301: reqok = 1; break; case 403: -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php