cvs: php4 /ext/standard file.c file.h /main/streams php_stream_context.h

From: Date: Wed, 21 May 2003 04:04:51 +0000
Subject: cvs: php4 /ext/standard file.c file.h /main/streams php_stream_context.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-21164@lists.php.net to get a copy of this message
pollita Wed May 21 00:04:51 2003 EDT Modified files: /php4/ext/standard file.c file.h /php4/main/streams php_stream_context.h Log: Implement default contexts. For the moment this is useless but it will be used soon for connection pooling.

Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.340 php4/ext/standard/file.c:1.341 --- php4/ext/standard/file.c:1.340 Wed May 14 11:12:06 2003 +++ php4/ext/standard/file.c Wed May 21 00:04:50 2003 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.340 2003/05/14 15:12:06 pollita Exp $ */ +/* $Id: file.c,v 1.341 2003/05/21 04:04:50 pollita Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -137,10 +137,15 @@ FG(pclose_ret) = 0; FG(user_stream_current_filename) = NULL; FG(def_chunk_size) = PHP_SOCK_CHUNK_SIZE; + FG(default_context) = NULL; } static void file_globals_dtor(php_file_globals *file_globals_p TSRMLS_DC) { + if (FG(default_context)) { + /* This is being automagically freed elsewhere */ + FG(default_context) = NULL; + } } @@ -181,9 +186,9 @@ REGISTER_LONG_CONSTANT("STREAM_NOTIFY_COMPLETED", PHP_STREAM_NOTIFY_COMPLETED, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_NOTIFY_RESOLVE", PHP_STREAM_NOTIFY_RESOLVE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_NOTIFY_SEVERITY_INFO", PHP_STREAM_NOTIFY_SEVERITY_INFO, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_NOTIFY_SEVERITY_WARN", PHP_STREAM_NOTIFY_SEVERITY_WARN, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_NOTIFY_SEVERITY_ERR", PHP_STREAM_NOTIFY_SEVERITY_ERR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("STREAM_NOTIFY_SEVERITY_INFO", PHP_STREAM_NOTIFY_SEVERITY_INFO, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("STREAM_NOTIFY_SEVERITY_WARN", PHP_STREAM_NOTIFY_SEVERITY_WARN, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("STREAM_NOTIFY_SEVERITY_ERR", PHP_STREAM_NOTIFY_SEVERITY_ERR, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_FILTER_READ", PHP_STREAM_FILTER_READ, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_FILTER_WRITE", PHP_STREAM_FILTER_WRITE, CONST_CS | CONST_PERSISTENT); @@ -195,10 +200,11 @@ REGISTER_LONG_CONSTANT("STREAM_SERVER_BIND", STREAM_XPORT_BIND, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_SERVER_LISTEN", STREAM_XPORT_LISTEN, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("FILE_USE_INCLUDE_PATH", PHP_FILE_USE_INCLUDE_PATH, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("FILE_IGNORE_NEW_LINES", PHP_FILE_IGNORE_NEW_LINES, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("FILE_SKIP_EMPTY_LINES", PHP_FILE_SKIP_EMPTY_LINES, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("FILE_APPEND", PHP_FILE_APPEND, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("FILE_USE_INCLUDE_PATH", PHP_FILE_USE_INCLUDE_PATH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("FILE_IGNORE_NEW_LINES", PHP_FILE_IGNORE_NEW_LINES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("FILE_SKIP_EMPTY_LINES", PHP_FILE_SKIP_EMPTY_LINES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("FILE_APPEND", PHP_FILE_APPEND, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("FILE_NO_DEFAULT_CONTEXT", PHP_FILE_NO_DEFAULT_CONTEXT, CONST_CS | CONST_PERSISTENT); #ifdef HAVE_FNMATCH REGISTER_LONG_CONSTANT("FNM_NOESCAPE", FNM_NOESCAPE, CONST_CS | CONST_PERSISTENT); @@ -439,9 +445,7 @@ return; } - if (zcontext) { - context = zend_fetch_resource(&zcontext TSRMLS_CC, -1, "Stream-Context", NULL, 1, php_le_stream_context()); - } + context = php_stream_context_from_zval(zcontext, 0); stream = php_stream_open_wrapper_ex(filename, "rb", (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, @@ -486,9 +490,7 @@ return; } - if (zcontext) { - context = zend_fetch_resource(&zcontext TSRMLS_CC, -1, "Stream-Context", NULL, 1, php_le_stream_context()); - } + context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT); stream = php_stream_open_wrapper_ex(filename, (flags & PHP_FILE_APPEND) ? "ab" : "wb", ((flags & PHP_FILE_USE_INCLUDE_PATH) ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); @@ -533,8 +535,8 @@ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lr!", &filename, &filename_len, &flags, &zcontext) == FAILURE) { return; } - if (flags < 0 || flags > (PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%l' flag is not supported.", flags); + if (flags < 0 || flags > (PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES | PHP_FILE_NO_DEFAULT_CONTEXT)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%d' flag is not supported.", flags); RETURN_FALSE; } @@ -542,9 +544,7 @@ include_new_line = !(flags & PHP_FILE_IGNORE_NEW_LINES); skip_blank_lines = flags & PHP_FILE_SKIP_EMPTY_LINES; - if (zcontext) { - context = zend_fetch_resource(&zcontext TSRMLS_CC, -1, "Stream-Context", NULL, 1, php_le_stream_context()); - } + context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT); stream = php_stream_open_wrapper_ex(filename, "rb", (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); if (!stream) { @@ -682,9 +682,8 @@ &mode, &mode_len, &use_include_path, &zcontext) == FAILURE) { RETURN_FALSE; } - if (zcontext) { - ZEND_FETCH_RESOURCE(context, php_stream_context*, &zcontext, -1, "stream-context", le_stream_context); - } + + context = php_stream_context_from_zval(zcontext, 0); stream = php_stream_open_wrapper_ex(filename, mode, (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); @@ -1308,9 +1307,7 @@ RETURN_FALSE; } - if (zcontext) { - context = zend_fetch_resource(&zcontext TSRMLS_CC, -1, "Stream-Context", NULL, 1, php_le_stream_context()); - } + context = php_stream_context_from_zval(zcontext, 0); stream = php_stream_open_wrapper_ex(filename, "rb", (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); if (stream) { @@ -1419,9 +1416,7 @@ RETURN_FALSE; } - if (zcontext) { - context = zend_fetch_resource(&zcontext TSRMLS_CC, -1, "Stream-Context", NULL, 1, php_le_stream_context()); - } + context = php_stream_context_from_zval(zcontext, 0); wrapper = php_stream_locate_url_wrapper(filename, NULL, 0 TSRMLS_CC); Index: php4/ext/standard/file.h diff -u php4/ext/standard/file.h:1.82 php4/ext/standard/file.h:1.83 --- php4/ext/standard/file.h:1.82 Tue Apr 8 19:24:53 2003 +++ php4/ext/standard/file.h Wed May 21 00:04:50 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.h,v 1.82 2003/04/08 23:24:53 pollita Exp $ */ +/* $Id: file.h,v 1.83 2003/05/21 04:04:50 pollita Exp $ */ /* Synced with php 3.0 revision 1.30 1999-06-16 [ssb] */ @@ -78,6 +78,7 @@ #define PHP_FILE_IGNORE_NEW_LINES 2 #define PHP_FILE_SKIP_EMPTY_LINES 4 #define PHP_FILE_APPEND 8 +#define PHP_FILE_NO_DEFAULT_CONTEXT 16 typedef enum _php_meta_tags_token { TOK_EOF = 0, @@ -110,6 +111,7 @@ long default_socket_timeout; char *user_agent; char *user_stream_current_filename; /* for simple recursion protection */ + php_stream_context *default_context; } php_file_globals; #ifdef ZTS Index: php4/main/streams/php_stream_context.h diff -u php4/main/streams/php_stream_context.h:1.2 php4/main/streams/php_stream_context.h:1.3 --- php4/main/streams/php_stream_context.h:1.2 Wed Feb 19 03:40:19 2003 +++ php4/main/streams/php_stream_context.h Wed May 21 00:04:50 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_stream_context.h,v 1.2 2003/02/19 08:40:19 sniper Exp $ */ +/* $Id: php_stream_context.h,v 1.3 2003/05/21 04:04:50 pollita Exp $ */ /* Stream context and status notification related definitions */ @@ -28,6 +28,15 @@ void * ptr TSRMLS_DC); #define PHP_STREAM_NOTIFIER_PROGRESS 1 + +/* Attempt to fetch context from the zval passed, + If no context was passed, use the default context + The the default context has not yet been created, do it now. */ +#define php_stream_context_from_zval(zcontext, nocontext) ( \ + (zcontext) ? zend_fetch_resource(&(zcontext) TSRMLS_CC, -1, "Stream-Context", NULL, 1, php_le_stream_context()) : \ + (nocontext) ? NULL : \ + FG(default_context) ? FG(default_context) : \ + (FG(default_context) = php_stream_context_alloc()) ) typedef struct _php_stream_notifier { php_stream_notification_func func;
« previous php.cvs (#21164) next »