cvs: php4 / configure.in php.ini-dist php.ini-optimized /ext/standard Makefile.in basic_functions.c ftp_fopen_wrapper.c http_fopen_wrapper.c
php_fopen_wrapper.c php_fopen_wrappers.h /ext/zlib zlib.c /main fopen-wrappers.c fopen-wrappers.h main.c php_globals.h

From: Date: Fri, 13 Oct 2000 00:09:32 +0000
Subject: cvs: php4 / configure.in php.ini-dist php.ini-optimized /ext/standard Makefile.in basic_functions.c ftp_fopen_wrapper.c http_fopen_wrapper.c
php_fopen_wrapper.c php_fopen_wrappers.h /ext/zlib zlib.c /main fopen-wrappers.c fopen-wrappers.h main.c php_globals.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-2037@lists.php.net to get a copy of this message
hholzgra Thu Oct 12 17:09:32 2000 EDT Added files: /php4/ext/standard ftp_fopen_wrapper.c http_fopen_wrapper.c php_fopen_wrapper.c php_fopen_wrappers.h Modified files: /php4 configure.in php.ini-dist php.ini-optimized /php4/ext/standard Makefile.in basic_functions.c /php4/ext/zlib zlib.c /php4/main fopen-wrappers.c fopen-wrappers.h main.c php_globals.h Log: fopen wrappers cleanup - comfiguration is now done by an ini parameter instead of a compile time option - the implementations of the three standard wrappers now live in seperate files in ext/standard - the compiler is happy again, no more warnings Index: php4/configure.in diff -u php4/configure.in:1.186 php4/configure.in:1.187 --- php4/configure.in:1.186 Wed Oct 11 10:31:34 2000 +++ php4/configure.in Thu Oct 12 17:09:30 2000 @@ -1,4 +1,4 @@ -dnl ## $Id: configure.in,v 1.186 2000/10/11 17:31:34 zeev Exp $ -*- sh -*- +dnl ## $Id: configure.in,v 1.187 2000/10/13 00:09:30 hholzgra Exp $ -*- sh -*- dnl ## Process this file with autoconf to produce a configure script. divert(1) @@ -543,16 +543,6 @@ AC_DEFINE(DEFAULT_SHORT_OPEN_TAG,0,[ ]) fi -PHP_ARG_ENABLE(url-fopen-wrapper,whether to enable the URL-aware fopen wrapper, -[ --disable-url-fopen-wrapper - Disable the URL-aware fopen wrapper that allows - accessing files via http or ftp.], yes) - -if test "$PHP_URL_FOPEN_WRAPPER" = "yes"; then - AC_DEFINE(PHP_URL_FOPEN, 1, [ ]) -else - AC_DEFINE(PHP_URL_FOPEN, 0, [ ]) -fi PHP_ARG_ENABLE(pic,whether to enable PIC for shared objects, [ --disable-pic Disable PIC for shared objects], yes) Index: php4/php.ini-dist diff -u php4/php.ini-dist:1.54 php4/php.ini-dist:1.55 --- php4/php.ini-dist:1.54 Thu Oct 5 22:14:46 2000 +++ php4/php.ini-dist Thu Oct 12 17:09:30 2000 @@ -245,6 +245,12 @@ upload_max_filesize = 2M ; Maximum allowed size for uploaded files +;;;;;;;;;;;;;;;;;; +; Fopen wrappers ; +;;;;;;;;;;;;;;;;;; +allow_url_fopen = On ; Wheter to allow trating URLs like http:... or ftp:... like files + + ;;;;;;;;;;;;;;;;;;;;;; ; Dynamic Extensions ; ;;;;;;;;;;;;;;;;;;;;;; Index: php4/php.ini-optimized diff -u php4/php.ini-optimized:1.21 php4/php.ini-optimized:1.22 --- php4/php.ini-optimized:1.21 Thu Oct 5 22:14:46 2000 +++ php4/php.ini-optimized Thu Oct 12 17:09:30 2000 @@ -228,6 +228,12 @@ upload_max_filesize = 2M ; Maximum allowed size for uploaded files +;;;;;;;;;;;;;;;;;; +; Fopen wrappers ; +;;;;;;;;;;;;;;;;;; +allow_url_fopen = On ; Wheter to allow trating URLs like http:... or ftp:... like files + + ;;;;;;;;;;;;;;;;;;;;;; ; Dynamic Extensions ; ;;;;;;;;;;;;;;;;;;;;;; Index: php4/ext/standard/Makefile.in diff -u php4/ext/standard/Makefile.in:1.17 php4/ext/standard/Makefile.in:1.18 --- php4/ext/standard/Makefile.in:1.17 Tue Sep 19 10:32:27 2000 +++ php4/ext/standard/Makefile.in Thu Oct 12 17:09:30 2000 @@ -7,7 +7,8 @@ link.c mail.c math.c md5.c metaphone.c microtime.c pack.c pageinfo.c \ parsedate.c quot_print.c rand.c reg.c soundex.c string.c scanf.c \ syslog.c type.c uniqid.c url.c url_scanner.c var.c output.c assert.c \ - strnatcmp.c levenshtein.c incomplete_class.c url_scanner_ex.c + strnatcmp.c levenshtein.c incomplete_class.c url_scanner_ex.c \ + ftp_fopen_wrapper.c http_fopen_wrapper.c php_fopen_wrapper.c include $(top_srcdir)/build/dynlib.mk Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.262 php4/ext/standard/basic_functions.c:1.263 --- php4/ext/standard/basic_functions.c:1.262 Wed Oct 11 04:25:13 2000 +++ php4/ext/standard/basic_functions.c Thu Oct 12 17:09:31 2000 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.262 2000/10/11 11:25:13 hholzgra Exp $ */ +/* $Id: basic_functions.c,v 1.263 2000/10/13 00:09:31 hholzgra Exp $ */ #include "php.h" #include "php_main.h" @@ -62,6 +62,8 @@ php_basic_globals basic_globals; #endif +#include "php_fopen_wrappers.h" + static unsigned char second_and_third_args_force_ref[] = { 3, BYREF_NONE, BYREF_FORCE, BYREF_FORCE }; static unsigned char second_args_force_ref[] = { 2, BYREF_NONE, BYREF_FORCE }; static unsigned char third_argument_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE }; @@ -669,6 +671,8 @@ PHP_MINIT_FUNCTION(basic) { + PLS_FETCH(); + #ifdef ZTS basic_globals_id = ts_allocate_id(sizeof(php_basic_globals), (ts_allocate_ctor) basic_globals_ctor, (ts_allocate_dtor) basic_globals_dtor); #else @@ -714,6 +718,18 @@ PHP_MINIT(array)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(assert)(INIT_FUNC_ARGS_PASSTHRU); + if(PG(allow_url_fopen)) { + if(FAILURE==php_register_url_wrapper("http",php_fopen_url_wrap_http)) { + return FAILURE; + } + if(FAILURE==php_register_url_wrapper("ftp",php_fopen_url_wrap_ftp)) { + return FAILURE; + } + if(FAILURE==php_register_url_wrapper("php",php_fopen_url_wrap_ftp)) { + return FAILURE; + } + } + return SUCCESS; } @@ -735,6 +751,12 @@ PHP_MSHUTDOWN(browscap)(SHUTDOWN_FUNC_ARGS_PASSTHRU); PHP_MSHUTDOWN(array)(SHUTDOWN_FUNC_ARGS_PASSTHRU); PHP_MSHUTDOWN(assert)(SHUTDOWN_FUNC_ARGS_PASSTHRU); + + if(PG(allow_url_fopen)) { + php_unregister_url_wrapper("http"); + php_unregister_url_wrapper("ftp"); + php_unregister_url_wrapper("php"); + } return SUCCESS; } Index: php4/ext/zlib/zlib.c diff -u php4/ext/zlib/zlib.c:1.54 php4/ext/zlib/zlib.c:1.55 --- php4/ext/zlib/zlib.c:1.54 Wed Oct 11 15:40:22 2000 +++ php4/ext/zlib/zlib.c Thu Oct 12 17:09:31 2000 @@ -16,13 +16,14 @@ | Stefan Röhrich <sr@linux.de> | +----------------------------------------------------------------------+ */ -/* $Id: zlib.c,v 1.54 2000/10/11 22:40:22 hholzgra Exp $ */ +/* $Id: zlib.c,v 1.55 2000/10/13 00:09:31 hholzgra Exp $ */ #define IS_EXT_MODULE #include "php_config.h" #if HAVE_FOPENCOOKIE #define _GNU_SOURCE +#define __USE_GNU #include "libio.h" #endif @@ -84,7 +85,7 @@ #endif #if HAVE_FOPENCOOKIE -static FILE *zlib_fopen_wrapper(const char *path, char *mode, int options, int *issock, int *socketd, char **opened_path); +static FILE *zlib_fopen_wrapper(char *path, char *mode, int options, int *issock, int *socketd, char **opened_path); #endif /* True globals, no need for thread safety */ @@ -139,6 +140,8 @@ PHP_MINIT_FUNCTION(zlib) { + PLS_FETCH(); + #ifdef ZTS zlib_globals_id = ts_allocate_id(sizeof(php_zlib_globals), (ts_allocate_ctor) php_zlib_init_globals, NULL); #else @@ -147,7 +150,10 @@ le_zp = register_list_destructors(phpi_destructor_gzclose,NULL); #if HAVE_FOPENCOOKIE - php_register_url_wrapper("zlib",zlib_fopen_wrapper); + + if(PG(allow_url_fopen)) { + php_register_url_wrapper("zlib",zlib_fopen_wrapper); + } #endif return SUCCESS; @@ -156,7 +162,11 @@ PHP_MSHUTDOWN_FUNCTION(zlib) { #if HAVE_FOPENCOOKIE - php_unregister_url_wrapper("zlib"); + PLS_FETCH(); + + if(PG(allow_url_fopen)) { + php_unregister_url_wrapper("zlib"); + } #endif return SUCCESS; @@ -769,15 +779,15 @@ return gzread(((struct gz_cookie *)cookie)->gz_file,buffer,size); } -static ssize_t gz_writer(void *cookie, char *buffer, size_t size) { - return gzwrite(((struct gz_cookie *)cookie)->gz_file,buffer,size); +static ssize_t gz_writer(void *cookie, const char *buffer, size_t size) { + return gzwrite(((struct gz_cookie *)cookie)->gz_file,(char *)buffer,size); } -static int gz_seeker(void *cookie,fpos_t *position, int whence) { - return (*position=gzseek(((struct gz_cookie *)cookie)->gz_file,*position,whence)); +static int gz_seeker(void *cookie,fpos_t position, int whence) { + return gzseek(((struct gz_cookie *)cookie)->gz_file,position,whence); } -static int gz_cleaner(void *cookie) { +static int gz_closer(void *cookie) { gzclose(((struct gz_cookie *)cookie)->gz_file); efree(cookie); cookie=NULL; @@ -788,12 +798,14 @@ { gz_reader , gz_writer , gz_seeker -, gz_cleaner +, gz_closer }; -static FILE *zlib_fopen_wrapper(const char *path, char *mode, int options, int *issock, int *socketd, char **opened_path) +static FILE *zlib_fopen_wrapper(char *path, char *mode, int options, int *issock, int *socketd, char **opened_path) { struct gz_cookie *gc = NULL; + FILE *fp; + int fissock=0, fsocketd=0; gc = (struct gz_cookie *)emalloc(sizeof(struct gz_cookie)); @@ -805,8 +817,15 @@ path++; - gc->gz_file = gzopen(path,mode); + fp = php_fopen_wrapper(path, mode, options|IGNORE_URL, &fissock, &fsocketd, NULL); + + if (!fp) { + efree(gc); + return NULL; + } + gc->gz_file = gzdopen(fileno(fp), mode); + if(gc->gz_file) { return fopencookie(gc,mode,gz_cookie_functions); } else { Index: php4/main/fopen-wrappers.c diff -u php4/main/fopen-wrappers.c:1.95 php4/main/fopen-wrappers.c:1.96 --- php4/main/fopen-wrappers.c:1.95 Thu Oct 12 12:58:20 2000 +++ php4/main/fopen-wrappers.c Thu Oct 12 17:09:31 2000 @@ -16,7 +16,7 @@ | Jim Winstead <jimw@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: fopen-wrappers.c,v 1.95 2000/10/12 19:58:20 andi Exp $ */ +/* $Id: fopen-wrappers.c,v 1.96 2000/10/13 00:09:31 hholzgra Exp $ */ #include "php.h" #include "php_globals.h" @@ -80,64 +80,52 @@ typedef FILE * (*php_fopen_url_wrapper_t) (const char *, char *, int, int *, int *, char **) ; static FILE *php_fopen_url_wrapper(const char *, char *, int, int *, int *, char **); -static FILE *php_fopen_url_wrap_http(const char *, char *, int, int *, int *, char **); -static FILE *php_fopen_url_wrap_ftp(const char *, char *, int, int *, int *, char **); -static FILE *php_fopen_url_wrap_php(const char *, char *, int, int *, int *, char **); -int php_get_ftp_result(int socketd); +PHPAPI char *expand_filepath(const char *filepath, char *real_path); - HashTable fopen_url_wrappers_hash; -PHPAPI int php_register_url_wrapper(char *protocol, FILE * (*wrapper)(const char *path, char *mode, int options, int *issock, int *socketd, char **opened_path)) +PHPAPI int php_register_url_wrapper(char *protocol, FILE * (*wrapper)(char *path, char *mode, int options, int *issock, int *socketd, char **opened_path)) { -#if PHP_URL_FOPEN - return zend_hash_add(&fopen_url_wrappers_hash, protocol, strlen(protocol)+1, &wrapper, sizeof(wrapper), NULL); -#else - return FAILURE; -#endif + PLS_FETCH(); + + if(PG(allow_url_fopen)) { + return zend_hash_add(&fopen_url_wrappers_hash, protocol, strlen(protocol)+1, &wrapper, sizeof(wrapper), NULL); + } else { + return FAILURE; + } } PHPAPI int php_unregister_url_wrapper(char *protocol) { -#if PHP_URL_FOPEN - return zend_hash_del(&fopen_url_wrappers_hash, protocol, strlen(protocol)+1); -#else - return SUCCESS; -#endif + PLS_FETCH(); + + if(PG(allow_url_fopen)) { + return zend_hash_del(&fopen_url_wrappers_hash, protocol, strlen(protocol)+1); + } else { + return SUCCESS; + } } int php_init_fopen_wrappers(void) { int status = SUCCESS; -#if PHP_URL_FOPEN - if (zend_hash_init(&fopen_url_wrappers_hash, 0, NULL, NULL, 1)==FAILURE) { - return FAILURE; - } - if(FAILURE==php_register_url_wrapper("http",php_fopen_url_wrap_http)) { - status = FAILURE; - } else - if(FAILURE==php_register_url_wrapper("ftp",php_fopen_url_wrap_ftp)) { - status = FAILURE; - } else - if(FAILURE==php_register_url_wrapper("php",php_fopen_url_wrap_php)) { - status = FAILURE; + if(PG(allow_url_fopen)) { + if (zend_hash_init(&fopen_url_wrappers_hash, 0, NULL, NULL, 1)==FAILURE) { + return FAILURE; + } } - if(FAILURE==status) { - zend_hash_destroy(&fopen_url_wrappers_hash); - } -#endif return status; } int php_shutdown_fopen_wrappers(void) { -#if PHP_URL_FOPEN + if(PG(allow_url_fopen)) { zend_hash_destroy(&fopen_url_wrappers_hash); -#endif + } return SUCCESS; } @@ -260,11 +248,11 @@ /* FIXME Lets not get in the habit of doing stuff like this. This should be runtime enabled, NOT compile time. */ -#if PHP_URL_FOPEN - if (!(options & IGNORE_URL)) { - return php_fopen_url_wrapper(path, mode, options, issock, socketd, opened_path); + if(PG(allow_url_fopen)) { + if (!(options & IGNORE_URL)) { + return php_fopen_url_wrapper(path, mode, options, issock, socketd, opened_path); + } } -#endif if (options & USE_PATH && PG(include_path) != NULL) { return php_fopen_with_path(path, mode, PG(include_path), opened_path); @@ -430,426 +418,8 @@ return NULL; } -/* - * If the specified path starts with "http://" (insensitive to case), - * a socket is opened to the specified web server and a file pointer is - * position at the start of the body of the response (past any headers). - * This makes a HTTP/1.0 request, and knows how to pass on the username - * and password for basic authentication. - * - * If the specified path starts with "ftp://" (insensitive to case), - * a pair of sockets are used to request the specified file and a file - * pointer to the requested file is returned. Passive mode ftp is used, - * so if the server doesn't support this, it will fail! - * - * Otherwise, fopen is called as usual and the file pointer is returned. - */ - - -static FILE *php_fopen_url_wrap_http(const char *path, char *mode, int options, int *issock, int *socketd, char **opened_path) -{ - FILE *fp=NULL; - php_url *resource=NULL; - char tmp_line[512]; - char location[512]; - char hdr_line[8192]; - int body = 0; - char *scratch; - unsigned char *tmp; - int len; - int reqok = 0; - - resource = url_parse((char *) path); - if (resource == NULL) { - php_error(E_WARNING, "Invalid URL specified, %s", path); - *issock = BAD_URL; - return NULL; - } - /* use port 80 if one wasn't specified */ - if (resource->port == 0) - resource->port = 80; - - *socketd = php_hostconnect(resource->host, resource->port, SOCK_STREAM, 0); - if (*socketd == -1) { - SOCK_FCLOSE(*socketd); - *socketd = 0; - free_url(resource); - return NULL; - } -#if 0 - if ((fp = fdopen(*socketd, "r+")) == NULL) { - free_url(resource); - return NULL; - } -#ifdef HAVE_SETVBUF - if ((setvbuf(fp, NULL, _IONBF, 0)) != 0) { - free_url(resource); - return NULL; - } -#endif -#endif /*win32 */ - - strcpy(hdr_line, "GET "); - - /* tell remote http which file to get */ - if (resource->path != NULL) { - strlcat(hdr_line, resource->path, sizeof(hdr_line)); - } else { - strlcat(hdr_line, "/", sizeof(hdr_line)); - } - /* append the query string, if any */ - if (resource->query != NULL) { - strlcat(hdr_line, "?", sizeof(hdr_line)); - strlcat(hdr_line, resource->query, sizeof(hdr_line)); - } - strlcat(hdr_line, " HTTP/1.0\r\n", sizeof(hdr_line)); - SOCK_WRITE(hdr_line, *socketd); - - /* send authorization header if we have user/pass */ - if (resource->user != NULL && resource->pass != NULL) { - scratch = (char *) emalloc(strlen(resource->user) + strlen(resource->pass) + 2); - if (!scratch) { - free_url(resource); - return NULL; - } - strcpy(scratch, resource->user); - strcat(scratch, ":"); - strcat(scratch, resource->pass); - tmp = php_base64_encode((unsigned char *)scratch, strlen(scratch), NULL); - - if (snprintf(hdr_line, sizeof(hdr_line), - "Authorization: Basic %s\r\n", tmp) > 0) { - SOCK_WRITE(hdr_line, *socketd); - } - - efree(scratch); - efree(tmp); - } - /* if the user has configured who they are, send a From: line */ - if (cfg_get_string("from", &scratch) == SUCCESS) { - if (snprintf(hdr_line, sizeof(hdr_line), - "From: %s\r\n", scratch) > 0) { - SOCK_WRITE(hdr_line, *socketd); - } - - } - /* send a Host: header so name-based virtual hosts work */ - if (resource->port != 80) { - len = snprintf(hdr_line, sizeof(hdr_line), - "Host: %s:%i\r\n", resource->host, resource->port); - } else { - len = snprintf(hdr_line, sizeof(hdr_line), - "Host: %s\r\n", resource->host); - } - if(len > sizeof(hdr_line) - 1) { - len = sizeof(hdr_line) - 1; - } - if (len > 0) { - SOCK_WRITE(hdr_line, *socketd); - } - - /* identify ourselves and end the headers */ - SOCK_WRITE("User-Agent: PHP/" PHP_VERSION "\r\n\r\n", *socketd); - - body = 0; - location[0] = '\0'; - if (!SOCK_FEOF(*socketd)) { - /* get response header */ - if (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, *socketd) != NULL) { - if (strncmp(tmp_line + 8, " 200 ", 5) == 0) { - reqok = 1; - } - } - } - /* Read past HTTP headers */ - while (!body && !SOCK_FEOF(*socketd)) { - if (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, *socketd) != NULL) { - char *p = tmp_line; - - tmp_line[sizeof(tmp_line)-1] = '\0'; - - while (*p) { - if (*p == '\n' || *p == '\r') { - *p = '\0'; - } - p++; - } - - if (!strncasecmp(tmp_line, "Location: ", 10)) { - strlcpy(location, tmp_line + 10, sizeof(location)); - } - - if (tmp_line[0] == '\0') { - body = 1; - } - } - } - if (!reqok) { - SOCK_FCLOSE(*socketd); - *socketd = 0; - free_url(resource); - if (location[0] != '\0') { - return php_fopen_url_wrapper(location, mode, options, issock, socketd, opened_path); - } else { - return NULL; - } - } - free_url(resource); - *issock = 1; - return (fp); -} - static FILE *php_fopen_url_wrap_ftp(const char *path, char *mode, int options, int *issock, int *socketd, char **opened_path) -{ - FILE *fp=NULL; - php_url *resource=NULL; - char tmp_line[512]; - unsigned short portno; - char *scratch; - int result; - int i; - char *tpath, *ttpath; - - resource = url_parse((char *) path); - if (resource == NULL) { - php_error(E_WARNING, "Invalid URL specified, %s", path); - *issock = BAD_URL; - return NULL; - } else if (resource->path == NULL) { - php_error(E_WARNING, "No file-path specified"); - free_url(resource); - *issock = BAD_URL; - return NULL; - } - /* use port 21 if one wasn't specified */ - if (resource->port == 0) - resource->port = 21; - - *socketd = php_hostconnect(resource->host, resource->port, SOCK_STREAM, 0); - if (*socketd == -1) - goto errexit; -#if 0 - if ((fpc = fdopen(*socketd, "r+")) == NULL) { - free_url(resource); - return NULL; - } -#ifdef HAVE_SETVBUF - if ((setvbuf(fpc, NULL, _IONBF, 0)) != 0) { - free_url(resource); - fclose(fpc); - return NULL; - } -#endif -#endif - - /* Start talking to ftp server */ - result = php_get_ftp_result(*socketd); - if (result > 299 || result < 200) - goto errexit; - - /* send the user name */ - SOCK_WRITE("USER ", *socketd); - if (resource->user != NULL) { - php_raw_url_decode(resource->user, strlen(resource->user)); - SOCK_WRITE(resource->user, *socketd); - } else { - SOCK_WRITE("anonymous", *socketd); - } - SOCK_WRITE("\r\n", *socketd); - - /* get the response */ - result = php_get_ftp_result(*socketd); - - /* if a password is required, send it */ - if (result >= 300 && result <= 399) { - SOCK_WRITE("PASS ", *socketd); - if (resource->pass != NULL) { - php_raw_url_decode(resource->pass, strlen(resource->pass)); - SOCK_WRITE(resource->pass, *socketd); - } else { - /* if the user has configured who they are, - send that as the password */ - if (cfg_get_string("from", &scratch) == SUCCESS) { - SOCK_WRITE(scratch, *socketd); - } else { - SOCK_WRITE("anonymous", *socketd); - } - } - SOCK_WRITE("\r\n", *socketd); - - /* read the response */ - result = php_get_ftp_result(*socketd); - } - if (result > 299 || result < 200) - goto errexit; - - /* set the connection to be binary */ - SOCK_WRITE("TYPE I\r\n", *socketd); - result = php_get_ftp_result(*socketd); - if (result > 299 || result < 200) - goto errexit; - - /* find out the size of the file (verifying it exists) */ - SOCK_WRITE("SIZE ", *socketd); - SOCK_WRITE(resource->path, *socketd); - SOCK_WRITE("\r\n", *socketd); - - /* read the response */ - result = php_get_ftp_result(*socketd); - if (mode[0] == 'r') { - /* when reading file, it must exist */ - if (result > 299 || result < 200) { - php_error(E_WARNING, "File not found"); - free_url(resource); - SOCK_FCLOSE(*socketd); - *socketd = 0; - errno = ENOENT; - return NULL; - } - } else { - /* when writing file, it must NOT exist */ - if (result <= 299 && result >= 200) { - php_error(E_WARNING, "File already exists"); - free_url(resource); - SOCK_FCLOSE(*socketd); - *socketd = 0; - errno = EEXIST; - return NULL; - } - } - - /* set up the passive connection */ - - /* We try EPSV first, needed for IPv6 and works on some IPv4 servers */ - SOCK_WRITE("EPSV\r\n", *socketd); - while (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, *socketd) && - !(isdigit((int) tmp_line[0]) && isdigit((int) tmp_line[1]) && - isdigit((int) tmp_line[2]) && tmp_line[3] == ' ')); - - /* check if we got a 229 response */ - if (strncmp(tmp_line, "229", 3)) { - /* EPSV failed, let's try PASV */ - SOCK_WRITE("PASV\r\n", *socketd); - while (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, *socketd) && - !(isdigit((int) tmp_line[0]) && isdigit((int) tmp_line[1]) && - isdigit((int) tmp_line[2]) && tmp_line[3] == ' ')); - /* make sure we got a 227 response */ - if (strncmp(tmp_line, "227", 3)) - goto errexit; - /* parse pasv command (129,80,95,25,13,221) */ - tpath = tmp_line; - /* skip over the "227 Some message " part */ - for (tpath += 4; *tpath && !isdigit((int) *tpath); tpath++); - if (!*tpath) - goto errexit; - /* skip over the host ip, we just assume it's the same */ - for (i = 0; i < 4; i++) { - for (; isdigit((int) *tpath); tpath++); - if (*tpath != ',') - goto errexit; - tpath++; - } - /* pull out the MSB of the port */ - portno = (unsigned short) strtol(tpath, &ttpath, 10) * 256; - if (ttpath == NULL) { - /* didn't get correct response from PASV */ - goto errexit; - } - tpath = ttpath; - if (*tpath != ',') - goto errexit; - tpath++; - /* pull out the LSB of the port */ - portno += (unsigned short) strtol(tpath, &ttpath, 10); - } else { - /* parse epsv command (|||6446|) */ - for (i = 0, tpath = tmp_line + 4; *tpath; tpath++) { - if (*tpath == '|') { - i++; - if (i == 3) - break; - } - } - if (i < 3) - goto errexit; - /* pull out the port */ - portno = (unsigned short) strtol(tpath + 1, &ttpath, 10); - } - - if (ttpath == NULL) { - /* didn't get correct response from EPSV/PASV */ - goto errexit; - } - - if (mode[0] == 'r') { - /* retrieve file */ - SOCK_WRITE("RETR ", *socketd); - } else { - /* store file */ - SOCK_WRITE("STOR ", *socketd); - } - if (resource->path != NULL) { - SOCK_WRITE(resource->path, *socketd); - } else { - SOCK_WRITE("/", *socketd); - } - - /* close control connection */ - SOCK_WRITE("\r\nQUIT\r\n", *socketd); - SOCK_FCLOSE(*socketd); - - /* open the data channel */ - *socketd = php_hostconnect(resource->host, portno, SOCK_STREAM, 0); - if (*socketd == -1) - goto errexit; -#if 0 - if (mode[0] == 'r') { - if ((fp = fdopen(*socketd, "r+")) == NULL) { - free_url(resource); - return NULL; - } - } else { - if ((fp = fdopen(*socketd, "w+")) == NULL) { - free_url(resource); - return NULL; - } - } -#ifdef HAVE_SETVBUF - if ((setvbuf(fp, NULL, _IONBF, 0)) != 0) { - free_url(resource); - fclose(fp); - return NULL; - } -#endif -#endif - free_url(resource); - *issock = 1; - return (fp); - - errexit: - free_url(resource); - SOCK_FCLOSE(*socketd); - *socketd = 0; - return NULL; -} -static FILE *php_fopen_url_wrap_php(const char *path, char *mode, int options, int *issock, int *socketd, char **opened_path) -{ - const char *res = path + 6; - - *issock = 0; - - if (!strcasecmp(res, "stdin")) { - return fdopen(STDIN_FILENO, mode); - } else if (!strcasecmp(res, "stdout")) { - return fdopen(STDOUT_FILENO, mode); - } else if (!strcasecmp(res, "stderr")) { - return fdopen(STDERR_FILENO, mode); - } - - return NULL; -} - static FILE *php_fopen_url_wrapper(const char *path, char *mode, int options, int *issock, int *socketd, char **opened_path) { FILE *fp = NULL; @@ -857,6 +427,7 @@ const char *protocol=NULL; int n=0; + for(p=path;isalnum((int)*p);p++) n++; if((*p==':')&&(n>1)) { @@ -909,17 +480,6 @@ php_error(E_WARNING, "Invalid URL specified, %s", path); return NULL; -} - -int php_get_ftp_result(int socketd) -{ - char tmp_line[513]; - - while (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, socketd) && - !(isdigit((int) tmp_line[0]) && isdigit((int) tmp_line[1]) && - isdigit((int) tmp_line[2]) && tmp_line[3] == ' ')); - - return strtol(tmp_line, NULL, 10); } PHPAPI int php_is_url(char *path) Index: php4/main/fopen-wrappers.h diff -u php4/main/fopen-wrappers.h:1.22 php4/main/fopen-wrappers.h:1.23 --- php4/main/fopen-wrappers.h:1.22 Wed Aug 16 12:26:21 2000 +++ php4/main/fopen-wrappers.h Thu Oct 12 17:09:31 2000 @@ -15,7 +15,7 @@ | Authors: Jim Winstead <jimw@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: fopen-wrappers.h,v 1.22 2000/08/16 19:26:21 andi Exp $ */ +/* $Id: fopen-wrappers.h,v 1.23 2000/10/13 00:09:31 hholzgra Exp $ */ #ifndef FOPEN_WRAPPERS_H #define FOPEN_WRAPPERS_H @@ -76,11 +76,10 @@ PHPAPI int php_is_url(char *path); PHPAPI char *php_strip_url_passwd(char *path); -PHPAPI char *expand_filepath(const char *filepath,char *real_path); int php_init_fopen_wrappers(void); int php_shutdown_fopen_wrappers(void); -PHPAPI int php_register_url_wrapper(char *protocol, FILE * (*wrapper)(const char *path, char *mode, int options, int *issock, int *socketd, char **opened_path)); +PHPAPI int php_register_url_wrapper(char *protocol, FILE * (*wrapper)(char *path, char *mode, int options, int *issock, int *socketd, char **opened_path)); PHPAPI int php_unregister_url_wrapper(char *protocol); #endif Index: php4/main/main.c diff -u php4/main/main.c:1.322 php4/main/main.c:1.323 --- php4/main/main.c:1.322 Tue Oct 3 07:43:04 2000 +++ php4/main/main.c Thu Oct 12 17:09:31 2000 @@ -19,7 +19,7 @@ */ -/* $Id: main.c,v 1.322 2000/10/03 14:43:04 andi Exp $ */ +/* $Id: main.c,v 1.323 2000/10/13 00:09:31 hholzgra Exp $ */ #include <stdio.h> @@ -260,6 +260,9 @@ PHP_INI_ENTRY("sendmail_path", DEFAULT_SENDMAIL_PATH, PHP_INI_SYSTEM, NULL) PHP_INI_ENTRY("disable_functions", "", PHP_INI_SYSTEM, NULL) + + STD_PHP_INI_ENTRY("allow_url_fopen", "1", PHP_INI_ALL, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals) + PHP_INI_END() @@ -855,16 +858,16 @@ php_ini_mstartup(); - if (php_init_fopen_wrappers() == FAILURE) { - php_printf("PHP: Unable to initialize fopen url wrappers.\n"); - return FAILURE; - } - if (php_config_ini_startup() == FAILURE) { return FAILURE; } REGISTER_INI_ENTRIES(); + + if (php_init_fopen_wrappers() == FAILURE) { + php_printf("PHP: Unable to initialize fopen url wrappers.\n"); + return FAILURE; + } zuv.import_use_extension = ".php"; zend_set_utility_values(&zuv); Index: php4/main/php_globals.h diff -u php4/main/php_globals.h:1.57 php4/main/php_globals.h:1.58 --- php4/main/php_globals.h:1.57 Sat Sep 9 08:02:15 2000 +++ php4/main/php_globals.h Thu Oct 12 17:09:31 2000 @@ -119,6 +119,8 @@ zend_bool file_uploads; zend_bool during_request_startup; + + zend_bool allow_url_fopen; }; Index: php4/ext/standard/ftp_fopen_wrapper.c +++ php4/ext/standard/ftp_fopen_wrapper.c /* +----------------------------------------------------------------------+ | PHP version 4.0 | +----------------------------------------------------------------------+ | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | | Jim Winstead <jimw@php.net> | | Hartmut Holzgraefe <hholzgra@php.net> | +----------------------------------------------------------------------+ */ /* $Id: ftp_fopen_wrapper.c,v 1.1 2000/10/13 00:09:31 hholzgra Exp $ */ #include "php.h" #include "php_globals.h" #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #ifdef PHP_WIN32 #include <windows.h> #include <winsock.h> #define O_RDONLY _O_RDONLY #include "win32/param.h" #else #include <sys/param.h> #endif #include "php_standard.h" #include <sys/types.h> #if HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif #ifdef PHP_WIN32 #include <winsock.h> #else #include <netinet/in.h> #include <netdb.h> #include <arpa/inet.h> #endif #ifdef PHP_WIN32 #undef AF_UNIX #endif #if defined(AF_UNIX) #include <sys/un.h> #endif #include "php_fopen_wrappers.h" static int php_get_ftp_result(int socketd) { char tmp_line[513]; while (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, socketd) && !(isdigit((int) tmp_line[0]) && isdigit((int) tmp_line[1]) && isdigit((int) tmp_line[2]) && tmp_line[3] == ' ')); return strtol(tmp_line, NULL, 10); } FILE *php_fopen_url_wrap_ftp(char *path, char *mode, int options, int *issock, int *socketd, char **opened_path) { FILE *fp=NULL; php_url *resource=NULL; char tmp_line[512]; unsigned short portno; char *scratch; int result; int i; char *tpath, *ttpath; resource = url_parse((char *) path); if (resource == NULL) { php_error(E_WARNING, "Invalid URL specified, %s", path); *issock = BAD_URL; return NULL; } else if (resource->path == NULL) { php_error(E_WARNING, "No file-path specified"); free_url(resource); *issock = BAD_URL; return NULL; } /* use port 21 if one wasn't specified */ if (resource->port == 0) resource->port = 21; *socketd = php_hostconnect(resource->host, resource->port, SOCK_STREAM, 0); if (*socketd == -1) goto errexit; #if 0 if ((fpc = fdopen(*socketd, "r+")) == NULL) { free_url(resource); return NULL; } #ifdef HAVE_SETVBUF if ((setvbuf(fpc, NULL, _IONBF, 0)) != 0) { free_url(resource); fclose(fpc); return NULL; } #endif #endif /* Start talking to ftp server */ result = php_get_ftp_result(*socketd); if (result > 299 || result < 200) goto errexit; /* send the user name */ SOCK_WRITE("USER ", *socketd); if (resource->user != NULL) { php_raw_url_decode(resource->user, strlen(resource->user)); SOCK_WRITE(resource->user, *socketd); } else { SOCK_WRITE("anonymous", *socketd); } SOCK_WRITE("\r\n", *socketd); /* get the response */ result = php_get_ftp_result(*socketd); /* if a password is required, send it */ if (result >= 300 && result <= 399) { SOCK_WRITE("PASS ", *socketd); if (resource->pass != NULL) { php_raw_url_decode(resource->pass, strlen(resource->pass)); SOCK_WRITE(resource->pass, *socketd); } else { /* if the user has configured who they are, send that as the password */ if (cfg_get_string("from", &scratch) == SUCCESS) { SOCK_WRITE(scratch, *socketd); } else { SOCK_WRITE("anonymous", *socketd); } } SOCK_WRITE("\r\n", *socketd); /* read the response */ result = php_get_ftp_result(*socketd); } if (result > 299 || result < 200) goto errexit; /* set the connection to be binary */ SOCK_WRITE("TYPE I\r\n", *socketd); result = php_get_ftp_result(*socketd); if (result > 299 || result < 200) goto errexit; /* find out the size of the file (verifying it exists) */ SOCK_WRITE("SIZE ", *socketd); SOCK_WRITE(resource->path, *socketd); SOCK_WRITE("\r\n", *socketd); /* read the response */ result = php_get_ftp_result(*socketd); if (mode[0] == 'r') { /* when reading file, it must exist */ if (result > 299 || result < 200) { php_error(E_WARNING, "File not found"); free_url(resource); SOCK_FCLOSE(*socketd); *socketd = 0; errno = ENOENT; return NULL; } } else { /* when writing file, it must NOT exist */ if (result <= 299 && result >= 200) { php_error(E_WARNING, "File already exists"); free_url(resource); SOCK_FCLOSE(*socketd); *socketd = 0; errno = EEXIST; return NULL; } } /* set up the passive connection */ /* We try EPSV first, needed for IPv6 and works on some IPv4 servers */ SOCK_WRITE("EPSV\r\n", *socketd); while (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, *socketd) && !(isdigit((int) tmp_line[0]) && isdigit((int) tmp_line[1]) && isdigit((int) tmp_line[2]) && tmp_line[3] == ' ')); /* check if we got a 229 response */ if (strncmp(tmp_line, "229", 3)) { /* EPSV failed, let's try PASV */ SOCK_WRITE("PASV\r\n", *socketd); while (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, *socketd) && !(isdigit((int) tmp_line[0]) && isdigit((int) tmp_line[1]) && isdigit((int) tmp_line[2]) && tmp_line[3] == ' ')); /* make sure we got a 227 response */ if (strncmp(tmp_line, "227", 3)) goto errexit; /* parse pasv command (129,80,95,25,13,221) */ tpath = tmp_line; /* skip over the "227 Some message " part */ for (tpath += 4; *tpath && !isdigit((int) *tpath); tpath++); if (!*tpath) goto errexit; /* skip over the host ip, we just assume it's the same */ for (i = 0; i < 4; i++) { for (; isdigit((int) *tpath); tpath++); if (*tpath != ',') goto errexit; tpath++; } /* pull out the MSB of the port */ portno = (unsigned short) strtol(tpath, &ttpath, 10) * 256; if (ttpath == NULL) { /* didn't get correct response from PASV */ goto errexit; } tpath = ttpath; if (*tpath != ',') goto errexit; tpath++; /* pull out the LSB of the port */ portno += (unsigned short) strtol(tpath, &ttpath, 10); } else { /* parse epsv command (|||6446|) */ for (i = 0, tpath = tmp_line + 4; *tpath; tpath++) { if (*tpath == '|') { i++; if (i == 3) break; } } if (i < 3) goto errexit; /* pull out the port */ portno = (unsigned short) strtol(tpath + 1, &ttpath, 10); } if (ttpath == NULL) { /* didn't get correct response from EPSV/PASV */ goto errexit; } if (mode[0] == 'r') { /* retrieve file */ SOCK_WRITE("RETR ", *socketd); } else { /* store file */ SOCK_WRITE("STOR ", *socketd); } if (resource->path != NULL) { SOCK_WRITE(resource->path, *socketd); } else { SOCK_WRITE("/", *socketd); } /* close control connection */ SOCK_WRITE("\r\nQUIT\r\n", *socketd); SOCK_FCLOSE(*socketd); /* open the data channel */ *socketd = php_hostconnect(resource->host, portno, SOCK_STREAM, 0); if (*socketd == -1) goto errexit; #if 0 if (mode[0] == 'r') { if ((fp = fdopen(*socketd, "r+")) == NULL) { free_url(resource); return NULL; } } else { if ((fp = fdopen(*socketd, "w+")) == NULL) { free_url(resource); return NULL; } } #ifdef HAVE_SETVBUF if ((setvbuf(fp, NULL, _IONBF, 0)) != 0) { free_url(resource); fclose(fp); return NULL; } #endif #endif free_url(resource); *issock = 1; return (fp); errexit: free_url(resource); SOCK_FCLOSE(*socketd); *socketd = 0; return NULL; } Index: php4/ext/standard/http_fopen_wrapper.c +++ php4/ext/standard/http_fopen_wrapper.c /* +----------------------------------------------------------------------+ | PHP version 4.0 | +----------------------------------------------------------------------+ | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | | Jim Winstead <jimw@php.net> | | Hartmut Holzgraefe <hholzgra@php.net> | +----------------------------------------------------------------------+ */ /* $Id: http_fopen_wrapper.c,v 1.1 2000/10/13 00:09:31 hholzgra Exp $ */ #include "php.h" #include "php_globals.h" #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #ifdef PHP_WIN32 #include <windows.h> #include <winsock.h> #define O_RDONLY _O_RDONLY #include "win32/param.h" #else #include <sys/param.h> #endif #include "php_standard.h" #include <sys/types.h> #if HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif #ifdef PHP_WIN32 #include <winsock.h> #else #include <netinet/in.h> #include <netdb.h> #include <arpa/inet.h> #endif #ifdef PHP_WIN32 #undef AF_UNIX #endif #if defined(AF_UNIX) #include <sys/un.h> #endif #include "php_fopen_wrappers.h" FILE *php_fopen_url_wrap_http(char *path, char *mode, int options, int *issock, int *socketd, char **opened_path) { FILE *fp=NULL; php_url *resource=NULL; char tmp_line[512]; char location[512]; char hdr_line[8192]; int body = 0; char *scratch; unsigned char *tmp; int len; int reqok = 0; resource = url_parse((char *) path); if (resource == NULL) { php_error(E_WARNING, "Invalid URL specified, %s", path); *issock = BAD_URL; return NULL; } /* use port 80 if one wasn't specified */ if (resource->port == 0) resource->port = 80; *socketd = php_hostconnect(resource->host, resource->port, SOCK_STREAM, 0); if (*socketd == -1) { SOCK_FCLOSE(*socketd); *socketd = 0; free_url(resource); return NULL; } #if 0 if ((fp = fdopen(*socketd, "r+")) == NULL) { free_url(resource); return NULL; } #ifdef HAVE_SETVBUF if ((setvbuf(fp, NULL, _IONBF, 0)) != 0) { free_url(resource); return NULL; } #endif #endif /*win32 */ strcpy(hdr_line, "GET "); /* tell remote http which file to get */ if (resource->path != NULL) { strlcat(hdr_line, resource->path, sizeof(hdr_line)); } else { strlcat(hdr_line, "/", sizeof(hdr_line)); } /* append the query string, if any */ if (resource->query != NULL) { strlcat(hdr_line, "?", sizeof(hdr_line)); strlcat(hdr_line, resource->query, sizeof(hdr_line)); } strlcat(hdr_line, " HTTP/1.0\r\n", sizeof(hdr_line)); SOCK_WRITE(hdr_line, *socketd); /* send authorization header if we have user/pass */ if (resource->user != NULL && resource->pass != NULL) { scratch = (char *) emalloc(strlen(resource->user) + strlen(resource->pass) + 2); if (!scratch) { free_url(resource); return NULL; } strcpy(scratch, resource->user); strcat(scratch, ":"); strcat(scratch, resource->pass); tmp = php_base64_encode((unsigned char *)scratch, strlen(scratch), NULL); if (snprintf(hdr_line, sizeof(hdr_line), "Authorization: Basic %s\r\n", tmp) > 0) { SOCK_WRITE(hdr_line, *socketd); } efree(scratch); efree(tmp); } /* if the user has configured who they are, send a From: line */ if (cfg_get_string("from", &scratch) == SUCCESS) { if (snprintf(hdr_line, sizeof(hdr_line), "From: %s\r\n", scratch) > 0) { SOCK_WRITE(hdr_line, *socketd); } } /* send a Host: header so name-based virtual hosts work */ if (resource->port != 80) { len = snprintf(hdr_line, sizeof(hdr_line), "Host: %s:%i\r\n", resource->host, resource->port); } else { len = snprintf(hdr_line, sizeof(hdr_line), "Host: %s\r\n", resource->host); } if(len > sizeof(hdr_line) - 1) { len = sizeof(hdr_line) - 1; } if (len > 0) { SOCK_WRITE(hdr_line, *socketd); } /* identify ourselves and end the headers */ SOCK_WRITE("User-Agent: PHP/" PHP_VERSION "\r\n\r\n", *socketd); body = 0; location[0] = '\0'; if (!SOCK_FEOF(*socketd)) { /* get response header */ if (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, *socketd) != NULL) { if (strncmp(tmp_line + 8, " 200 ", 5) == 0) { reqok = 1; } } } /* Read past HTTP headers */ while (!body && !SOCK_FEOF(*socketd)) { if (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, *socketd) != NULL) { char *p = tmp_line; tmp_line[sizeof(tmp_line)-1] = '\0'; while (*p) { if (*p == '\n' || *p == '\r') { *p = '\0'; } p++; } if (!strncasecmp(tmp_line, "Location: ", 10)) { strlcpy(location, tmp_line + 10, sizeof(location)); } if (tmp_line[0] == '\0') { body = 1; } } } if (!reqok) { SOCK_FCLOSE(*socketd); *socketd = 0; free_url(resource); #if 0 if (location[0] != '\0') { return php_fopen_url_wrapper(location, mode, options, issock, socketd, opened_path); } else { return NULL; } #else return NULL; #endif } free_url(resource); *issock = 1; return (fp); } Index: php4/ext/standard/php_fopen_wrapper.c +++ php4/ext/standard/php_fopen_wrapper.c /* +----------------------------------------------------------------------+ | PHP version 4.0 | +----------------------------------------------------------------------+ | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | | Jim Winstead <jimw@php.net> | | Hartmut Holzgraefe <hholzgra@php.net> | +----------------------------------------------------------------------+ */ /* $Id: php_fopen_wrapper.c,v 1.1 2000/10/13 00:09:31 hholzgra Exp $ */ #include <stdio.h> #include <stdlib.h> #include "php.h" #include "php_globals.h" #include "php_standard.h" #include "php_fopen_wrappers.h" FILE *php_fopen_url_wrap_php(char *path, char *mode, int options, int *issock, int *socketd, char **opened_path) { const char *res = path + 6; *issock = 0; if (!strcasecmp(res, "stdin")) { return fdopen(STDIN_FILENO, mode); } else if (!strcasecmp(res, "stdout")) { return fdopen(STDOUT_FILENO, mode); } else if (!strcasecmp(res, "stderr")) { return fdopen(STDERR_FILENO, mode); } return NULL; } Index: php4/ext/standard/php_fopen_wrappers.h +++ php4/ext/standard/php_fopen_wrappers.h /* +----------------------------------------------------------------------+ | PHP version 4.0 | +----------------------------------------------------------------------+ | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | | Jim Winstead <jimw@php.net> | | Hartmut Holzgraefe <hholzgra@php.net> | +----------------------------------------------------------------------+ */ /* $Id: php_fopen_wrappers.h,v 1.1 2000/10/13 00:09:31 hholzgra Exp $ */ #ifndef PHP_FOPEN_WRAPPERS_H #define PHP_FOPEN_WRAPPERS_H extern FILE *php_fopen_url_wrap_http(char *, char *, int, int *, int *, char **); extern FILE *php_fopen_url_wrap_ftp(char *, char *, int, int *, int *, char **); extern FILE *php_fopen_url_wrap_php(char *, char *, int, int *, int *, char **); #endif

« previous php.cvs (#2037) next »