summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/standard/basic_functions.c4
-rw-r--r--ext/standard/file.c51
-rw-r--r--ext/standard/file.h2
-rw-r--r--ext/standard/ftp_fopen_wrapper.c3
-rw-r--r--ext/standard/http_fopen_wrapper.c39
-rw-r--r--ext/standard/php_fopen_wrapper.c8
-rw-r--r--ext/zlib/zlib_fopen_wrapper.c8
-rwxr-xr-xmain/php_streams.h3
8 files changed, 81 insertions, 37 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 43548224e1..999e9f2de2 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -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)
diff --git a/ext/standard/file.c b/ext/standard/file.c
index 322d6e0432..e7d865e6f2 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -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;
}
/* }}} */
diff --git a/ext/standard/file.h b/ext/standard/file.h
index 6b1209abf9..edaca259d6 100644
--- a/ext/standard/file.h
+++ b/ext/standard/file.h
@@ -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);
diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c
index 7c74cd1cac..f81f23f4cf 100644
--- a/ext/standard/ftp_fopen_wrapper.c
+++ b/ext/standard/ftp_fopen_wrapper.c
@@ -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 = {
diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c
index dc32f63774..3fb3f82705 100644
--- a/ext/standard/http_fopen_wrapper.c
+++ b/ext/standard/http_fopen_wrapper.c
@@ -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 = {
diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c
index 6f077a3813..0ca83d356a 100644
--- a/ext/standard/php_fopen_wrapper.c
+++ b/ext/standard/php_fopen_wrapper.c
@@ -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 = {
diff --git a/ext/zlib/zlib_fopen_wrapper.c b/ext/zlib/zlib_fopen_wrapper.c
index ee2222306d..1ccccc615a 100644
--- a/ext/zlib/zlib_fopen_wrapper.c
+++ b/ext/zlib/zlib_fopen_wrapper.c
@@ -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 = {
diff --git a/main/php_streams.h b/main/php_streams.h
index 411491c111..ff7861a452 100755
--- a/main/php_streams.h
+++ b/main/php_streams.h
@@ -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 {