]> granicus.if.org Git - php/commitdiff
Rename file_get_wrapper_data -> file_get_meta_data.
authorWez Furlong <wez@php.net>
Thu, 26 Sep 2002 10:14:41 +0000 (10:14 +0000)
committerWez Furlong <wez@php.net>
Thu, 26 Sep 2002 10:14:41 +0000 (10:14 +0000)
It now always returns useful information for all streams.
Unified that data with socket_get_status and made socket_get_status
an alias for file_get_meta_data.

Fix Location header following which was broken in this commit:
http://cvs.php.net/diff.php/php4/ext/standard/http_fopen_wrapper.c?r1=1.41&r2=1.42&ty=h

ext/standard/basic_functions.c
ext/standard/file.c
ext/standard/file.h
ext/standard/ftp_fopen_wrapper.c
ext/standard/http_fopen_wrapper.c
ext/standard/php_fopen_wrapper.c
ext/zlib/zlib_fopen_wrapper.c
main/php_streams.h

index 43548224e146ffe9f2860a78860188899806294c..999e9f2de2eb0242535d433fd8b20d9cc6851eab 100644 (file)
@@ -634,14 +634,14 @@ function_entry basic_functions[] = {
        PHP_FE(set_socket_blocking,                                                                                             NULL)
        PHP_FE(socket_set_blocking,                                                                                             NULL)
 
-       PHP_FE(file_get_wrapper_data,                                                                                   NULL)
+       PHP_FE(file_get_meta_data,                                                                                              NULL)
        PHP_FE(file_register_wrapper,                                                                                   NULL)
 
 #if HAVE_SYS_TIME_H || defined(PHP_WIN32)
        PHP_FE(socket_set_timeout,                                                                                              NULL)
 #endif
 
-       PHP_FE(socket_get_status,                                                                                               NULL)
+       PHP_FALIAS(socket_get_status, file_get_meta_data,                                               NULL)
 
 #if (!defined(PHP_WIN32) && !defined(__BEOS__) && !defined(NETWARE) && HAVE_REALPATH) || defined(ZTS)
        PHP_FE(realpath,                                                                                                                NULL)
index 322d6e043293b3a00f21c1a4d31fdfe19be5f1d3..e7d865e6f24393fdc40e3f8fd20511eaf321cf25 100644 (file)
@@ -581,24 +581,59 @@ PHP_NAMED_FUNCTION(php_if_tmpfile)
 }
 /* }}} */
 
-/* {{{ proto resource file_get_wrapper_data(resource fp)
-    Retrieves header/meta data from "wrapped" file pointers */
-PHP_FUNCTION(file_get_wrapper_data)
+/* {{{ proto resource file_get_meta_data(resource fp)
+    Retrieves header/meta data from streams/file pointers */
+PHP_FUNCTION(file_get_meta_data)
 {
        zval **arg1;
        php_stream *stream;
+       zval *newval;
 
        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
        php_stream_from_zval(stream, arg1);
 
-       if (stream->wrapperdata)        {
-               *return_value = *(stream->wrapperdata);
-               zval_copy_ctor(return_value);
+       array_init(return_value);
+       
+       if (stream->wrapperdata) {
+               MAKE_STD_ZVAL(newval);
+               *newval = *(stream->wrapperdata);
+               zval_copy_ctor(newval);
+
+               add_assoc_zval(return_value, "wrapper_data", newval);
+       }
+       if (stream->wrapper) {
+               add_assoc_string(return_value, "wrapper_type", (char *)stream->wrapper->wops->label, 1);
+       }
+       add_assoc_string(return_value, "stream_type", (char *)stream->ops->label, 1);
+
+       if (stream->filterhead) {
+               php_stream_filter *filter;
+               
+               MAKE_STD_ZVAL(newval);
+               array_init(newval);
+               
+               for (filter = stream->filterhead; filter != NULL; filter = filter->next) {
+                       add_next_index_string(newval, (char *)filter->fops->label, 1);
+               }
+
+               add_assoc_zval(return_value, "filters", newval);
+       }
+       
+       add_assoc_long(return_value, "unread_bytes", stream->writepos - stream->readpos);
+       
+       if (php_stream_is(stream, PHP_STREAM_IS_SOCKET))        {
+               php_netstream_data_t *sock = PHP_NETSTREAM_DATA_FROM_STREAM(stream);
+
+               add_assoc_bool(return_value, "timed_out", sock->timeout_event);
+               add_assoc_bool(return_value, "blocked", sock->is_blocked);
+               add_assoc_bool(return_value, "eof", sock->eof);
+       } else {
+               add_assoc_bool(return_value, "timed_out", 0);
+               add_assoc_bool(return_value, "blocked", 1);
+               add_assoc_bool(return_value, "eof", php_stream_eof(stream));
        }
-       else
-               RETURN_FALSE;
 
 }
 /* }}} */
index 6b1209abf900d19a41d1b861be983ebf123c9126..edaca259d6c32d397563ebed0f6acbb13c21fadc 100644 (file)
@@ -71,7 +71,7 @@ PHP_FUNCTION(fnmatch);
 PHP_NAMED_FUNCTION(php_if_ftruncate);
 PHP_NAMED_FUNCTION(php_if_fstat);
 
-PHP_FUNCTION(file_get_wrapper_data);
+PHP_FUNCTION(file_get_meta_data);
 PHP_FUNCTION(file_register_wrapper);
 PHP_FUNCTION(stream_context_create);
 PHP_FUNCTION(stream_context_set_params);
index 7c74cd1cacbb8cbbee3ea3f74f5c1f6a1a7014f3..f81f23f4cf33f8c031337a983e72d15c239df329 100644 (file)
@@ -120,7 +120,8 @@ static php_stream_wrapper_ops ftp_stream_wops = {
        php_stream_ftp_stream_close, /* stream_close */
        php_stream_ftp_stream_stat,
        NULL, /* stat_url */
-       NULL  /* opendir */
+       NULL, /* opendir */
+       "FTP"
 };
 
 php_stream_wrapper php_stream_ftp_wrapper =    {
index dc32f6377481536c5dfa9fd57b4b6e0d7b581ca9..3fb3f827056ab570c6852b7452c9928029b1e9cf 100644 (file)
@@ -246,18 +246,18 @@ php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, char *path, ch
 
                        MAKE_STD_ZVAL(http_response);
                        response_code = atoi(tmp_line + 9);
-                       if (response_code == 200) {
-                               reqok = 1;
-                       } else {
-                               switch(response_code) {
-                                       case 403:
-                                               php_stream_notify_error(context, PHP_STREAM_NOTIFY_AUTH_RESULT,
-                                                               tmp_line, response_code);
-                                               break;
-                                       default:
-                                               php_stream_notify_error(context, PHP_STREAM_NOTIFY_FAILURE,
-                                                               tmp_line, response_code);
-                               }
+                       switch(response_code) {
+                               case 200:
+                               case 302:
+                                       reqok = 1;
+                                       break;
+                               case 403:
+                                       php_stream_notify_error(context, PHP_STREAM_NOTIFY_AUTH_RESULT,
+                                                       tmp_line, response_code);
+                                       break;
+                               default:
+                                       php_stream_notify_error(context, PHP_STREAM_NOTIFY_FAILURE,
+                                                       tmp_line, response_code);
                        }
                        
                        Z_STRLEN_P(http_response) = strlen(tmp_line);
@@ -283,7 +283,7 @@ php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, char *path, ch
                while (!body && !php_stream_eof(stream))        {
                
                        if (php_stream_gets(stream, http_header_line, HTTP_HEADER_BLOCK_SIZE-1) != NULL)        {
-                               char *p;
+                               char *p, *ws;
                                int found_eol = 0;
                                int http_header_line_length;
                        
@@ -309,7 +309,7 @@ php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, char *path, ch
                                        file_size = atoi(http_header_line + 16);
                                        php_stream_notify_file_size(context, file_size, http_header_line, 0);
                                }
-       
+
                                if (http_header_line[0] == '\0')
                                        body = 1;
                                else    {
@@ -327,14 +327,12 @@ php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, char *path, ch
                }
        } 
        
-       if (!reqok)     {               
+       if (!reqok || location[0] != '\0')      {               
                if (location[0] != '\0')
                        php_stream_notify_info(context, PHP_STREAM_NOTIFY_REDIRECTED, location, 0);
 
                php_stream_close(stream);
                stream = NULL;
-               zval_dtor(response_header);
-               FREE_ZVAL(response_header);
 
                if (location[0] != '\0')        {
 
@@ -373,6 +371,10 @@ php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, char *path, ch
                                FREE_ZVAL(stream->wrapperdata);
                        }
                } else {
+
+                       zval_dtor(response_header);
+                       FREE_ZVAL(response_header);
+
                        php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "HTTP request failed! %s", tmp_line);
                }
        }
@@ -420,7 +422,8 @@ static php_stream_wrapper_ops http_stream_wops = {
        NULL, /* stream_close */
        php_stream_http_stream_stat,
        NULL, /* stat_url */
-       NULL  /* opendir */
+       NULL, /* opendir */
+       "HTTP"
 };
 
 php_stream_wrapper php_stream_http_wrapper =   {
index 6f077a38131b47d15611a519f31d00a4b28c4258..0ca83d356af20e9e5a384a195d549fb905a2f0ce 100644 (file)
@@ -95,9 +95,11 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch
 
 static php_stream_wrapper_ops php_stdio_wops = {
        php_stream_url_wrap_php,
-       NULL,
-       NULL,
-       NULL
+       NULL, /* close */
+       NULL, /* fstat */
+       NULL, /* stat */
+       NULL, /* opendir */
+       "PHP"
 };
 
 php_stream_wrapper php_stream_php_wrapper =    {
index ee2222306d58e7365b6d138a647475f2f07c4d67..1ccccc615ac4cb56ab6396ad2b06d8100b531d8f 100644 (file)
@@ -131,9 +131,11 @@ php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, char *path, char *mod
 
 static php_stream_wrapper_ops gzip_stream_wops = {
        php_stream_gzopen,
-       NULL,
-       NULL,
-       NULL
+       NULL, /* close */
+       NULL, /* stat */
+       NULL, /* stat_url */
+       NULL, /* opendir */
+       "ZLIB"
 };
 
 php_stream_wrapper php_stream_gzip_wrapper =   {
index 411491c1112c7429bb5ef116d087c0468ede1d1f..ff7861a452a51bbf673697d384f838d09e6ceca7 100755 (executable)
@@ -168,7 +168,8 @@ typedef struct _php_stream_wrapper_ops {
        /* open a "directory" stream */
        php_stream *(*dir_opener)(php_stream_wrapper *wrapper, char *filename, char *mode,
                        int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
-
+       
+       const char *label;
 } php_stream_wrapper_ops;
 
 struct _php_stream_wrapper     {