summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/SAPI.c122
-rw-r--r--main/SAPI.h17
-rw-r--r--main/fopen_wrappers.c8
-rw-r--r--main/main.c92
-rw-r--r--main/php.h7
-rw-r--r--main/php_content_types.c53
-rw-r--r--main/php_globals.h6
-rw-r--r--main/php_memory_streams.h2
-rw-r--r--main/php_open_temporary_file.c10
-rw-r--r--main/php_stdint.h206
-rw-r--r--main/php_streams.h46
-rw-r--r--main/php_variables.c132
-rw-r--r--main/php_version.h8
-rw-r--r--main/rfc1867.c53
-rw-r--r--main/streams/glob_wrapper.c10
-rw-r--r--main/streams/memory.c29
-rw-r--r--main/streams/php_stream_plain_wrapper.h2
-rw-r--r--main/streams/php_stream_transport.h47
-rw-r--r--main/streams/plain_wrapper.c69
-rw-r--r--main/streams/streams.c62
-rw-r--r--main/streams/transports.c10
-rw-r--r--main/streams/userspace.c38
-rw-r--r--main/streams/xp_socket.c8
23 files changed, 741 insertions, 296 deletions
diff --git a/main/SAPI.c b/main/SAPI.c
index 994aff38bf..f9e9ccb049 100644
--- a/main/SAPI.c
+++ b/main/SAPI.c
@@ -91,8 +91,6 @@ SAPI_API void sapi_startup(sapi_module_struct *sf)
sapi_globals_ctor(&sapi_globals);
#endif
- virtual_cwd_startup(); /* Could use shutdown to free the main cwd but it would just slow it down for CGI */
-
#ifdef PHP_WIN32
tsrm_win32_startup();
#endif
@@ -110,8 +108,6 @@ SAPI_API void sapi_shutdown(void)
reentrancy_shutdown();
- virtual_cwd_shutdown();
-
#ifdef PHP_WIN32
tsrm_win32_shutdown();
#endif
@@ -187,10 +183,6 @@ SAPI_API void sapi_handle_post(void *arg TSRMLS_DC)
{
if (SG(request_info).post_entry && SG(request_info).content_type_dup) {
SG(request_info).post_entry->post_handler(SG(request_info).content_type_dup, arg TSRMLS_CC);
- if (SG(request_info).post_data) {
- efree(SG(request_info).post_data);
- SG(request_info).post_data = NULL;
- }
efree(SG(request_info).content_type_dup);
SG(request_info).content_type_dup = NULL;
}
@@ -256,39 +248,63 @@ static void sapi_read_post_data(TSRMLS_D)
}
}
-
-SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data)
+SAPI_API int sapi_read_post_block(char *buffer, size_t buflen TSRMLS_DC)
{
int read_bytes;
- int allocated_bytes=SAPI_POST_BLOCK_SIZE+1;
+ if (!sapi_module.read_post) {
+ return -1;
+ }
+
+ read_bytes = sapi_module.read_post(buffer, buflen TSRMLS_CC);
+
+ if (read_bytes > 0) {
+ /* gogo */
+ SG(read_post_bytes) += read_bytes;
+ }
+ if (read_bytes < buflen) {
+ /* done */
+ SG(post_read) = 1;
+ }
+
+ return read_bytes;
+}
+
+SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data)
+{
if ((SG(post_max_size) > 0) && (SG(request_info).content_length > SG(post_max_size))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes",
SG(request_info).content_length, SG(post_max_size));
return;
}
- SG(request_info).post_data = emalloc(allocated_bytes);
- for (;;) {
- read_bytes = sapi_module.read_post(SG(request_info).post_data+SG(read_post_bytes), SAPI_POST_BLOCK_SIZE TSRMLS_CC);
- if (read_bytes<=0) {
- break;
- }
- SG(read_post_bytes) += read_bytes;
- if ((SG(post_max_size) > 0) && (SG(read_post_bytes) > SG(post_max_size))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Actual POST length does not match Content-Length, and exceeds %ld bytes", SG(post_max_size));
- break;
- }
- if (read_bytes < SAPI_POST_BLOCK_SIZE) {
- break;
- }
- if (SG(read_post_bytes)+SAPI_POST_BLOCK_SIZE >= allocated_bytes) {
- allocated_bytes = SG(read_post_bytes)+SAPI_POST_BLOCK_SIZE+1;
- SG(request_info).post_data = erealloc(SG(request_info).post_data, allocated_bytes);
+
+ SG(request_info).request_body = php_stream_temp_create_ex(TEMP_STREAM_DEFAULT, SAPI_POST_BLOCK_SIZE, PG(upload_tmp_dir));
+
+ if (sapi_module.read_post) {
+ int read_bytes;
+
+ for (;;) {
+ char buffer[SAPI_POST_BLOCK_SIZE];
+
+ read_bytes = sapi_read_post_block(buffer, SAPI_POST_BLOCK_SIZE TSRMLS_CC);
+
+ if (read_bytes > 0) {
+ php_stream_write(SG(request_info).request_body, buffer, read_bytes);
+ }
+
+ if ((SG(post_max_size) > 0) && (SG(read_post_bytes) > SG(post_max_size))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Actual POST length does not match Content-Length, and exceeds %ld bytes", SG(post_max_size));
+ break;
+ }
+
+ if (read_bytes < SAPI_POST_BLOCK_SIZE) {
+ /* done */
+ break;
+ }
}
+ php_stream_rewind(SG(request_info).request_body);
}
- SG(request_info).post_data[SG(read_post_bytes)] = 0; /* terminating NULL */
- SG(request_info).post_data_length = SG(read_post_bytes);
}
@@ -394,8 +410,7 @@ SAPI_API void sapi_activate_headers_only(TSRMLS_D)
SG(sapi_headers).http_status_line = NULL;
SG(sapi_headers).mimetype = NULL;
SG(read_post_bytes) = 0;
- SG(request_info).post_data = NULL;
- SG(request_info).raw_post_data = NULL;
+ SG(request_info).request_body = NULL;
SG(request_info).current_user = NULL;
SG(request_info).current_user_length = 0;
SG(request_info).no_headers = 0;
@@ -440,15 +455,14 @@ SAPI_API void sapi_activate(TSRMLS_D)
SG(callback_run) = 0;
SG(callback_func) = NULL;
SG(read_post_bytes) = 0;
- SG(request_info).post_data = NULL;
- SG(request_info).raw_post_data = NULL;
+ SG(request_info).request_body = NULL;
SG(request_info).current_user = NULL;
SG(request_info).current_user_length = 0;
SG(request_info).no_headers = 0;
SG(request_info).post_entry = NULL;
SG(request_info).proto_num = 1000; /* Default to HTTP 1.0 */
SG(global_request_time) = 0;
-
+ SG(post_read) = 0;
/* It's possible to override this general case in the activate() callback, if necessary. */
if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) {
SG(request_info).headers_only = 1;
@@ -459,20 +473,13 @@ SAPI_API void sapi_activate(TSRMLS_D)
/* Handle request method */
if (SG(server_context)) {
- if (PG(enable_post_data_reading) && SG(request_info).request_method) {
- if (SG(request_info).content_type && !strcmp(SG(request_info).request_method, "POST")) {
- /* HTTP POST may contain form data to be processed into variables
- * depending on given content type */
- sapi_read_post_data(TSRMLS_C);
- } else {
- /* Any other method with content payload will fill $HTTP_RAW_POST_DATA
- * if it is enabled by always_populate_raw_post_data.
- * It's up to the webserver to decide whether to allow a method or not. */
- SG(request_info).content_type_dup = NULL;
- if (sapi_module.default_post_reader) {
- sapi_module.default_post_reader(TSRMLS_C);
- }
- }
+ if (PG(enable_post_data_reading)
+ && SG(request_info).content_type
+ && SG(request_info).request_method
+ && !strcmp(SG(request_info).request_method, "POST")) {
+ /* HTTP POST may contain form data to be processed into variables
+ * depending on given content type */
+ sapi_read_post_data(TSRMLS_C);
} else {
SG(request_info).content_type_dup = NULL;
}
@@ -501,22 +508,19 @@ static void sapi_send_headers_free(TSRMLS_D)
SAPI_API void sapi_deactivate(TSRMLS_D)
{
zend_llist_destroy(&SG(sapi_headers).headers);
- if (SG(request_info).post_data) {
- efree(SG(request_info).post_data);
- } else if (SG(server_context)) {
- if(sapi_module.read_post) {
+ if (SG(request_info).request_body) {
+ SG(request_info).request_body = NULL;
+ } else if (SG(server_context)) {
+ if (!SG(post_read)) {
/* make sure we've consumed all request input data */
char dummy[SAPI_POST_BLOCK_SIZE];
int read_bytes;
- while((read_bytes = sapi_module.read_post(dummy, sizeof(dummy)-1 TSRMLS_CC)) > 0) {
- SG(read_post_bytes) += read_bytes;
- }
+ do {
+ read_bytes = sapi_read_post_block(dummy, SAPI_POST_BLOCK_SIZE TSRMLS_CC);
+ } while (SAPI_POST_BLOCK_SIZE == read_bytes);
}
}
- if (SG(request_info).raw_post_data) {
- efree(SG(request_info).raw_post_data);
- }
if (SG(request_info).auth_user) {
efree(SG(request_info).auth_user);
}
diff --git a/main/SAPI.h b/main/SAPI.h
index c86ef6735c..990ca6990c 100644
--- a/main/SAPI.h
+++ b/main/SAPI.h
@@ -21,18 +21,19 @@
#ifndef SAPI_H
#define SAPI_H
+#include "php.h"
#include "zend.h"
#include "zend_API.h"
#include "zend_llist.h"
#include "zend_operators.h"
#ifdef PHP_WIN32
#include "win95nt.h"
+#include "win32/php_stdint.h"
#endif
#include <sys/stat.h>
#define SAPI_OPTION_NO_CHDIR 1
-
-#define SAPI_POST_BLOCK_SIZE 4000
+#define SAPI_POST_BLOCK_SIZE 0x4000
#ifdef PHP_WIN32
# ifdef SAPI_EXPORTS
@@ -79,14 +80,15 @@ END_EXTERN_C()
typedef struct {
const char *request_method;
char *query_string;
- char *post_data, *raw_post_data;
char *cookie_data;
long content_length;
- uint post_data_length, raw_post_data_length;
char *path_translated;
char *request_uri;
+ /* Do not use request_body directly, but the php://input stream wrapper instead */
+ struct _php_stream *request_body;
+
const char *content_type;
zend_bool headers_only;
@@ -119,7 +121,8 @@ typedef struct _sapi_globals_struct {
void *server_context;
sapi_request_info request_info;
sapi_headers_struct sapi_headers;
- int read_post_bytes;
+ int64_t read_post_bytes;
+ unsigned char post_read;
unsigned char headers_sent;
struct stat global_stat;
char *default_mimetype;
@@ -188,7 +191,7 @@ SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bo
SAPI_API int sapi_send_headers(TSRMLS_D);
SAPI_API void sapi_free_header(sapi_header_struct *sapi_header);
SAPI_API void sapi_handle_post(void *arg TSRMLS_DC);
-
+SAPI_API int sapi_read_post_block(char *buffer, size_t buflen TSRMLS_DC);
SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entry TSRMLS_DC);
SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry TSRMLS_DC);
SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry TSRMLS_DC);
@@ -289,7 +292,7 @@ struct _sapi_post_entry {
#define SAPI_HEADER_SEND_FAILED 3
#define SAPI_DEFAULT_MIMETYPE "text/html"
-#define SAPI_DEFAULT_CHARSET ""
+#define SAPI_DEFAULT_CHARSET PHP_DEFAULT_CHARSET
#define SAPI_PHP_VERSION_HEADER "X-Powered-By: PHP/" PHP_VERSION
#define SAPI_POST_READER_FUNC(post_reader) void post_reader(TSRMLS_D)
diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c
index 4f6c79da1d..3be7b5f206 100644
--- a/main/fopen_wrappers.c
+++ b/main/fopen_wrappers.c
@@ -475,7 +475,7 @@ PHPAPI char *php_resolve_path(const char *filename, int filename_length, const c
char resolved_path[MAXPATHLEN];
char trypath[MAXPATHLEN];
const char *ptr, *end, *p;
- char *actual_path;
+ const char *actual_path;
php_stream_wrapper *wrapper;
if (!filename || CHECK_NULL_PATH(filename, filename_length)) {
@@ -791,11 +791,11 @@ PHPAPI char *expand_filepath_with_mode(const char *filepath, char *real_path, co
}
}
- new_state.cwd = strdup(cwd);
+ new_state.cwd = estrdup(cwd);
new_state.cwd_length = strlen(cwd);
if (virtual_file_ex(&new_state, filepath, NULL, realpath_mode TSRMLS_CC)) {
- free(new_state.cwd);
+ efree(new_state.cwd);
return NULL;
}
@@ -806,7 +806,7 @@ PHPAPI char *expand_filepath_with_mode(const char *filepath, char *real_path, co
} else {
real_path = estrndup(new_state.cwd, new_state.cwd_length);
}
- free(new_state.cwd);
+ efree(new_state.cwd);
return real_path;
}
diff --git a/main/main.c b/main/main.c
index 3eaecf0fe4..4adc5e96b2 100644
--- a/main/main.c
+++ b/main/main.c
@@ -417,6 +417,45 @@ static PHP_INI_DISP(display_errors_mode)
/* {{{ PHP_INI_MH
*/
+static PHP_INI_MH(OnUpdateInternalEncoding)
+{
+ if (new_value) {
+ OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+ } else {
+ OnUpdateString(entry, SG(default_charset), strlen(SG(default_charset))+1, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+ }
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ PHP_INI_MH
+ */
+static PHP_INI_MH(OnUpdateInputEncoding)
+{
+ if (new_value) {
+ OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+ } else {
+ OnUpdateString(entry, SG(default_charset), strlen(SG(default_charset))+1, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+ }
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ PHP_INI_MH
+ */
+static PHP_INI_MH(OnUpdateOutputEncoding)
+{
+ if (new_value) {
+ OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+ } else {
+ OnUpdateString(entry, SG(default_charset), strlen(SG(default_charset))+1, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+ }
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ PHP_INI_MH
+ */
static PHP_INI_MH(OnUpdateErrorLog)
{
/* Only do the safemode/open_basedir check at runtime */
@@ -460,6 +499,40 @@ static PHP_INI_MH(OnChangeMailForceExtra)
/* defined in browscap.c */
PHP_INI_MH(OnChangeBrowscap);
+/* {{{ PHP_INI_MH
+ */
+static PHP_INI_MH(OnChangeAlwaysPopulateRawPostData)
+{
+ signed char *p;
+#ifndef ZTS
+ char *base = (char *) mh_arg2;
+#else
+ char *base;
+
+ base = (char *) ts_resource(*((int *) mh_arg2));
+#endif
+
+ p = (signed char *) (base+(size_t) mh_arg1);
+
+ *p = zend_atol(new_value, new_value_length);
+ if (new_value_length == 2 && strcasecmp("on", new_value) == 0) {
+ *p = (signed char) 1;
+ }
+ else if (new_value_length == 3 && strcasecmp("yes", new_value) == 0) {
+ *p = (signed char) 1;
+ }
+ else if (new_value_length == 4 && strcasecmp("true", new_value) == 0) {
+ *p = (signed char) 1;
+ }
+ else if (new_value_length == 5 && strcasecmp("never", new_value) == 0) {
+ *p = (signed char) -1;
+ }
+ else {
+ *p = (signed char) atoi(new_value);
+ }
+ return SUCCESS;
+}
+/* }}} */
/* Need to be read from the environment (?):
* PHP_AUTO_PREPEND_FILE
@@ -522,8 +595,11 @@ PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("auto_append_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_append_file, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("auto_prepend_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_prepend_file, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("doc_root", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, doc_root, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("default_charset", SAPI_DEFAULT_CHARSET, PHP_INI_ALL, OnUpdateString, default_charset, sapi_globals_struct,sapi_globals)
- STD_PHP_INI_ENTRY("default_mimetype", SAPI_DEFAULT_MIMETYPE, PHP_INI_ALL, OnUpdateString, default_mimetype, sapi_globals_struct,sapi_globals)
+ STD_PHP_INI_ENTRY("default_charset", PHP_DEFAULT_CHARSET, PHP_INI_ALL, OnUpdateString, default_charset, sapi_globals_struct, sapi_globals)
+ STD_PHP_INI_ENTRY("default_mimetype", SAPI_DEFAULT_MIMETYPE, PHP_INI_ALL, OnUpdateString, default_mimetype, sapi_globals_struct, sapi_globals)
+ STD_PHP_INI_ENTRY("internal_encoding", NULL, PHP_INI_ALL, OnUpdateInternalEncoding, internal_encoding, php_core_globals, core_globals)
+ STD_PHP_INI_ENTRY("input_encoding", NULL, PHP_INI_ALL, OnUpdateInputEncoding, input_encoding, php_core_globals, core_globals)
+ STD_PHP_INI_ENTRY("output_encoding", NULL, PHP_INI_ALL, OnUpdateOutputEncoding, output_encoding, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("error_log", NULL, PHP_INI_ALL, OnUpdateErrorLog, error_log, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("extension_dir", PHP_EXTENSION_DIR, PHP_INI_SYSTEM, OnUpdateStringUnempty, extension_dir, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("sys_temp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, sys_temp_dir, php_core_globals, core_globals)
@@ -562,7 +638,7 @@ PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("allow_url_fopen", "1", PHP_INI_SYSTEM, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("allow_url_include", "0", PHP_INI_SYSTEM, OnUpdateBool, allow_url_include, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("enable_post_data_reading", "1", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, enable_post_data_reading, php_core_globals, core_globals)
- STD_PHP_INI_BOOLEAN("always_populate_raw_post_data", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, always_populate_raw_post_data, php_core_globals, core_globals)
+ STD_PHP_INI_ENTRY("always_populate_raw_post_data", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnChangeAlwaysPopulateRawPostData, always_populate_raw_post_data, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("realpath_cache_size", "16K", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_size_limit, virtual_cwd_globals, cwd_globals)
STD_PHP_INI_ENTRY("realpath_cache_ttl", "120", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_ttl, virtual_cwd_globals, cwd_globals)
@@ -1340,7 +1416,7 @@ PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *h
handle->handle.stream.reader = (zend_stream_reader_t)_php_stream_read;
handle->handle.stream.fsizer = php_zend_stream_fsizer;
handle->handle.stream.isatty = 0;
- /* can we mmap immeadiately? */
+ /* can we mmap immediately? */
memset(&handle->handle.stream.mmap, 0, sizeof(handle->handle.stream.mmap));
len = php_zend_stream_fsizer(stream TSRMLS_CC);
if (len != 0
@@ -1823,6 +1899,9 @@ void php_request_shutdown(void *dummy)
sapi_deactivate(TSRMLS_C);
} zend_end_try();
+ /* 9.5 free virtual CWD memory */
+ virtual_cwd_deactivate(TSRMLS_C);
+
/* 10. Destroy stream hashes */
zend_try {
php_shutdown_stream_hashes(TSRMLS_C);
@@ -2215,7 +2294,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
zend_set_utility_values(&zuv);
php_startup_sapi_content_types(TSRMLS_C);
- /* startup extensions staticly compiled in */
+ /* startup extensions statically compiled in */
if (php_register_internal_extensions_func(TSRMLS_C) == FAILURE) {
php_printf("Unable to start builtin modules\n");
return FAILURE;
@@ -2267,9 +2346,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
}
#endif
-#ifdef ZTS
zend_post_startup(TSRMLS_C);
-#endif
module_initialized = 1;
@@ -2339,6 +2416,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
shutdown_memory_manager(1, 0 TSRMLS_CC);
zend_interned_strings_snapshot(TSRMLS_C);
+ virtual_cwd_activate(TSRMLS_C);
/* we're done */
return retval;
diff --git a/main/php.h b/main/php.h
index eff66d00b8..4330479d50 100644
--- a/main/php.h
+++ b/main/php.h
@@ -26,9 +26,10 @@
#include <dmalloc.h>
#endif
-#define PHP_API_VERSION 20121113
+#define PHP_API_VERSION 20131106
#define PHP_HAVE_STREAMS
#define YYDEBUG 0
+#define PHP_DEFAULT_CHARSET "UTF-8"
#include "php_version.h"
#include "zend.h"
@@ -180,6 +181,8 @@ typedef unsigned int socklen_t;
# endif
#endif
+#include "php_stdint.h"
+
#include "zend_hash.h"
#include "zend_alloc.h"
#include "zend_stack.h"
@@ -398,7 +401,7 @@ END_EXTERN_C()
/* Virtual current working directory support */
-#include "tsrm_virtual_cwd.h"
+#include "zend_virtual_cwd.h"
#include "zend_constants.h"
diff --git a/main/php_content_types.c b/main/php_content_types.c
index c36812f101..ca47e15285 100644
--- a/main/php_content_types.c
+++ b/main/php_content_types.c
@@ -33,38 +33,51 @@ static sapi_post_entry php_post_entries[] = {
};
/* }}} */
+static zend_bool populate_raw_post_data(TSRMLS_D)
+{
+ if (!SG(request_info).request_body) {
+ return (zend_bool) 0;
+ }
+
+ if (!PG(always_populate_raw_post_data)) {
+ return (zend_bool) !SG(request_info).post_entry;
+ }
+
+ return (zend_bool) (PG(always_populate_raw_post_data) > 0);
+}
+
/* {{{ SAPI_POST_READER_FUNC
*/
SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader)
{
- char *data;
- int length;
-
- /* $HTTP_RAW_POST_DATA registration */
if (!strcmp(SG(request_info).request_method, "POST")) {
if (NULL == SG(request_info).post_entry) {
/* no post handler registered, so we just swallow the data */
sapi_read_standard_form_data(TSRMLS_C);
}
- /* For unknown content types we create HTTP_RAW_POST_DATA even if always_populate_raw_post_data off,
- * this is in-effecient, but we need to keep doing it for BC reasons (for now) */
- if ((PG(always_populate_raw_post_data) || NULL == SG(request_info).post_entry) && SG(request_info).post_data) {
- length = SG(request_info).post_data_length;
- data = estrndup(SG(request_info).post_data, length);
+ if (populate_raw_post_data(TSRMLS_C)) {
+ size_t length;
+ char *data = NULL;
+
+ php_stream_rewind(SG(request_info).request_body);
+ length = php_stream_copy_to_mem(SG(request_info).request_body, &data, PHP_STREAM_COPY_ALL, 0);
+ php_stream_rewind(SG(request_info).request_body);
+
+ if (length > INT_MAX) {
+ sapi_module.sapi_error(E_WARNING,
+ "HTTP_RAW_POST_DATA truncated from %lu to %d bytes",
+ (unsigned long) length, INT_MAX);
+ length = INT_MAX;
+ }
SET_VAR_STRINGL("HTTP_RAW_POST_DATA", data, length);
- }
- }
- /* for php://input stream:
- some post handlers modify the content of request_info.post_data
- so for now we need a copy for the php://input stream
- in the long run post handlers should be changed to not touch
- request_info.post_data for memory preservation reasons
- */
- if (SG(request_info).post_data) {
- SG(request_info).raw_post_data = estrndup(SG(request_info).post_data, SG(request_info).post_data_length);
- SG(request_info).raw_post_data_length = SG(request_info).post_data_length;
+ sapi_module.sapi_error(E_DEPRECATED,
+ "Automatically populating $HTTP_RAW_POST_DATA is deprecated and "
+ "will be removed in a future version. To avoid this warning set "
+ "'always_populate_raw_post_data' to '-1' in php.ini and use the "
+ "php://input stream instead.");
+ }
}
}
/* }}} */
diff --git a/main/php_globals.h b/main/php_globals.h
index b65499f1b3..e135d61865 100644
--- a/main/php_globals.h
+++ b/main/php_globals.h
@@ -96,6 +96,10 @@ struct _php_core_globals {
char *auto_prepend_file;
char *auto_append_file;
+ char *input_encoding;
+ char *internal_encoding;
+ char *output_encoding;
+
arg_separators arg_separator;
char *variables_order;
@@ -131,7 +135,7 @@ struct _php_core_globals {
zend_bool during_request_startup;
zend_bool allow_url_fopen;
zend_bool enable_post_data_reading;
- zend_bool always_populate_raw_post_data;
+ signed char always_populate_raw_post_data;
zend_bool report_zend_debug;
int last_error_type;
diff --git a/main/php_memory_streams.h b/main/php_memory_streams.h
index 3c4c3280eb..229ed1902e 100644
--- a/main/php_memory_streams.h
+++ b/main/php_memory_streams.h
@@ -36,6 +36,7 @@
#define php_stream_temp_new() php_stream_temp_create(TEMP_STREAM_DEFAULT, PHP_STREAM_MAX_MEM)
#define php_stream_temp_create(mode, max_memory_usage) _php_stream_temp_create((mode), (max_memory_usage) STREAMS_CC TSRMLS_CC)
+#define php_stream_temp_create_ex(mode, max_memory_usage, tmpdir) _php_stream_temp_create_ex((mode), (max_memory_usage), (tmpdir) STREAMS_CC TSRMLS_CC)
#define php_stream_temp_create_rel(mode, max_memory_usage) _php_stream_temp_create((mode), (max_memory_usage) STREAMS_REL_CC TSRMLS_CC)
#define php_stream_temp_open(mode, max_memory_usage, buf, length) _php_stream_temp_open((mode), (max_memory_usage), (buf), (length) STREAMS_CC TSRMLS_CC)
@@ -45,6 +46,7 @@ PHPAPI php_stream *_php_stream_memory_open(int mode, char *buf, size_t length ST
PHPAPI char *_php_stream_memory_get_buffer(php_stream *stream, size_t *length STREAMS_DC TSRMLS_DC);
PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STREAMS_DC TSRMLS_DC);
+PHPAPI php_stream *_php_stream_temp_create_ex(int mode, size_t max_memory_usage, const char *tmpdir STREAMS_DC TSRMLS_DC);
PHPAPI php_stream *_php_stream_temp_open(int mode, size_t max_memory_usage, char *buf, size_t length STREAMS_DC TSRMLS_DC);
END_EXTERN_C()
diff --git a/main/php_open_temporary_file.c b/main/php_open_temporary_file.c
index 16b61b8ba7..ebe5350ef2 100644
--- a/main/php_open_temporary_file.c
+++ b/main/php_open_temporary_file.c
@@ -124,11 +124,11 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, char **
cwd[0] = '\0';
}
- new_state.cwd = strdup(cwd);
+ new_state.cwd = estrdup(cwd);
new_state.cwd_length = strlen(cwd);
if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH TSRMLS_CC)) {
- free(new_state.cwd);
+ efree(new_state.cwd);
return -1;
}
@@ -140,7 +140,7 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, char **
if (spprintf(&opened_path, 0, "%s%s%sXXXXXX", new_state.cwd, trailing_slash, pfx) >= MAXPATHLEN) {
efree(opened_path);
- free(new_state.cwd);
+ efree(new_state.cwd);
return -1;
}
@@ -151,7 +151,7 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, char **
* which means that opening it will fail... */
if (VCWD_CHMOD(opened_path, 0600)) {
efree(opened_path);
- free(new_state.cwd);
+ efree(new_state.cwd);
return -1;
}
fd = VCWD_OPEN_MODE(opened_path, open_flags, 0600);
@@ -170,7 +170,7 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, char **
} else {
*opened_path_p = opened_path;
}
- free(new_state.cwd);
+ efree(new_state.cwd);
return fd;
}
/* }}} */
diff --git a/main/php_stdint.h b/main/php_stdint.h
new file mode 100644
index 0000000000..14b32d7ca4
--- /dev/null
+++ b/main/php_stdint.h
@@ -0,0 +1,206 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2014 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.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. |
+ +----------------------------------------------------------------------+
+ | Author: Michael Wallner <mike@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+#ifndef PHP_STDINT_H
+#define PHP_STDINT_H
+
+#if defined(_MSC_VER)
+/* Make sure the regular stdint.h wasn't included already and prevent it to be
+ included afterwards. Though if some other library needs some stuff from
+ stdint.h included afterwards and misses it, we'd have to extend ours. On
+ the other hand, if stdint.h was included before, some conflicts might
+ happen so we'd likewise have to fix ours. */
+# if !defined(_STDINT)
+# define _STDINT
+# include "win32/php_stdint.h"
+# endif
+# define HAVE_INT8_T 1
+# define HAVE_UINT8_T 1
+# define HAVE_INT16_T 1
+# define HAVE_UINT16_T 1
+# define HAVE_INT32_T 1
+# define HAVE_UINT32_T 1
+# define HAVE_INT64_T 1
+# define HAVE_UINT64_T 1
+#else
+
+#include "php_config.h"
+
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+
+#if HAVE_STDINT_H
+# include <stdint.h>
+#endif
+
+#ifndef HAVE_INT8_T
+# ifdef HAVE_INT8
+typedef int8 int8_t;
+# else
+typedef signed char int8_t;
+# endif
+#endif
+
+#ifndef INT8_C
+# define INT8_C(c) c
+#endif
+
+#ifndef HAVE_UINT8_T
+# ifdef HAVE_UINT8
+typedef uint8 uint8_t
+# elif HAVE_U_INT8_T
+typedef u_int8_t uint8_t;
+# else
+typedef unsigned char uint8_t;
+# endif
+#endif
+
+#ifndef UINT8_C
+# define UINT8_C(c) c
+#endif
+
+#ifndef HAVE_INT16_T
+# ifdef HAVE_INT16
+typedef int16 int16_t;
+# elif SIZEOF_SHORT >= 2
+typedef signed short int16_t;
+# else
+# error "No suitable 16bit integer type found"
+# endif
+#endif
+
+#ifndef INT16_C
+# define INT16_C(c) c
+#endif
+
+#ifndef HAVE_UINT16_T
+# ifdef HAVE_UINT16
+typedef uint16 uint16_t
+# elif HAVE_U_INT16_T
+typedef u_int16_t uint16_t;
+# elif SIZEOF_SHORT >= 2
+typedef unsigned short uint16_t;
+# else
+# error "No suitable 16bit integer type found"
+# endif
+#endif
+
+#ifndef UINT16_C
+# define UINT16_C(c) c
+#endif
+
+#ifndef HAVE_INT32_T
+# ifdef HAVE_INT32
+typedef int32 int32_t;
+# elif SIZEOF_INT >= 4
+typedef int int32_t;
+# elif SIZEOF_LONG >= 4
+typedef long int32_t;
+# else
+# error "No suitable 32bit integer type found"
+# endif
+#endif
+
+#ifndef INT32_C
+# define INT32_C(c) c
+#endif
+
+#ifndef HAVE_UINT32_T
+# ifdef HAVE_UINT32
+typedef uint32 uint32_t
+# elif HAVE_U_INT32_T
+typedef u_int32_t uint32_t;
+# elif SIZEOF_INT >= 4
+typedef unsigned int uint32_t;
+# elif SIZEOF_LONG >= 4
+typedef unsigned long uint32_t;
+# else
+# error "No suitable 32bit integer type found"
+# endif
+#endif
+
+#ifndef UINT32_C
+# define UINT32_C(c) c ## U
+#endif
+
+#ifndef HAVE_INT64_T
+# ifdef HAVE_INT64
+typedef int64 int64_t;
+# elif SIZEOF_INT >= 8
+typedef int int64_t;
+# elif SIZEOF_LONG >= 8
+typedef long int64_t;
+# elif SIZEOF_LONG_LONG >= 8
+typedef long long int64_t;
+# else
+# error "No suitable 64bit integer type found"
+# endif
+#endif
+
+#ifndef INT64_C
+# if SIZEOF_INT >= 8
+# define INT64_C(c) c
+# elif SIZEOF_LONG >= 8
+# define INT64_C(c) c ## L
+# elif SIZEOF_LONG_LONG >= 8
+# define INT64_C(c) c ## LL
+# endif
+#endif
+
+#ifndef HAVE_UINT64_T
+# ifdef HAVE_UINT64
+typedef uint64 uint64_t
+# elif HAVE_U_INT64_T
+typedef u_int64_t uint64_t;
+# elif SIZEOF_INT >= 8
+typedef unsigned int uint64_t;
+# elif SIZEOF_LONG >= 8
+typedef unsigned long uint64_t;
+# elif SIZEOF_LONG_LONG >= 8
+typedef unsigned long long uint64_t;
+# else
+# error "No suitable 64bit integer type found"
+# endif
+#endif
+
+#ifndef UINT64_C
+# if SIZEOF_INT >= 8
+# define UINT64_C(c) c ## U
+# elif SIZEOF_LONG >= 8
+# define UINT64_C(c) c ## UL
+# elif SIZEOF_LONG_LONG >= 8
+# define UINT64_C(c) c ## ULL
+# endif
+#endif
+
+#endif /* !PHP_WIN32 */
+#endif /* PHP_STDINT_H */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
diff --git a/main/php_streams.h b/main/php_streams.h
index d08c2295be..e90976cdca 100644
--- a/main/php_streams.h
+++ b/main/php_streams.h
@@ -131,31 +131,31 @@ typedef struct _php_stream_ops {
typedef struct _php_stream_wrapper_ops {
/* open/create a wrapped stream */
- php_stream *(*stream_opener)(php_stream_wrapper *wrapper, char *filename, char *mode,
+ php_stream *(*stream_opener)(php_stream_wrapper *wrapper, const char *filename, const char *mode,
int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
/* close/destroy a wrapped stream */
int (*stream_closer)(php_stream_wrapper *wrapper, php_stream *stream TSRMLS_DC);
/* stat a wrapped stream */
int (*stream_stat)(php_stream_wrapper *wrapper, php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC);
/* stat a URL */
- int (*url_stat)(php_stream_wrapper *wrapper, char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC);
+ int (*url_stat)(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC);
/* open a "directory" stream */
- php_stream *(*dir_opener)(php_stream_wrapper *wrapper, char *filename, char *mode,
+ php_stream *(*dir_opener)(php_stream_wrapper *wrapper, const char *filename, const char *mode,
int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
const char *label;
/* delete a file */
- int (*unlink)(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC);
+ int (*unlink)(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC);
/* rename a file */
- int (*rename)(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC);
+ int (*rename)(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context TSRMLS_DC);
/* Create/Remove directory */
- int (*stream_mkdir)(php_stream_wrapper *wrapper, char *url, int mode, int options, php_stream_context *context TSRMLS_DC);
- int (*stream_rmdir)(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC);
+ int (*stream_mkdir)(php_stream_wrapper *wrapper, const char *url, int mode, int options, php_stream_context *context TSRMLS_DC);
+ int (*stream_rmdir)(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC);
/* Metadata handling */
- int (*stream_metadata)(php_stream_wrapper *wrapper, char *url, int options, void *value, php_stream_context *context TSRMLS_DC);
+ int (*stream_metadata)(php_stream_wrapper *wrapper, const char *url, int options, void *value, php_stream_context *context TSRMLS_DC);
} php_stream_wrapper_ops;
struct _php_stream_wrapper {
@@ -242,7 +242,7 @@ PHPAPI php_stream *_php_stream_alloc(php_stream_ops *ops, void *abstract,
END_EXTERN_C()
#define php_stream_alloc(ops, thisptr, persistent_id, mode) _php_stream_alloc((ops), (thisptr), (persistent_id), (mode) STREAMS_CC TSRMLS_CC)
-#define php_stream_get_resource_id(stream) (stream)->rsrc_id
+#define php_stream_get_resource_id(stream) ((php_stream *)(stream))->rsrc_id
#if ZEND_DEBUG
/* use this to tell the stream that it is OK if we don't explicitly close it */
# define php_stream_auto_cleanup(stream) { (stream)->__exposed++; }
@@ -325,26 +325,26 @@ PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen,
#define php_stream_gets(stream, buf, maxlen) _php_stream_get_line((stream), (buf), (maxlen), NULL TSRMLS_CC)
#define php_stream_get_line(stream, buf, maxlen, retlen) _php_stream_get_line((stream), (buf), (maxlen), (retlen) TSRMLS_CC)
-PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, char *delim, size_t delim_len TSRMLS_DC);
+PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, const char *delim, size_t delim_len TSRMLS_DC);
/* CAREFUL! this is equivalent to puts NOT fputs! */
-PHPAPI int _php_stream_puts(php_stream *stream, char *buf TSRMLS_DC);
+PHPAPI int _php_stream_puts(php_stream *stream, const char *buf TSRMLS_DC);
#define php_stream_puts(stream, buf) _php_stream_puts((stream), (buf) TSRMLS_CC)
PHPAPI int _php_stream_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC);
#define php_stream_stat(stream, ssb) _php_stream_stat((stream), (ssb) TSRMLS_CC)
-PHPAPI int _php_stream_stat_path(char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC);
+PHPAPI int _php_stream_stat_path(const char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC);
#define php_stream_stat_path(path, ssb) _php_stream_stat_path((path), 0, (ssb), NULL TSRMLS_CC)
#define php_stream_stat_path_ex(path, flags, ssb, context) _php_stream_stat_path((path), (flags), (ssb), (context) TSRMLS_CC)
-PHPAPI int _php_stream_mkdir(char *path, int mode, int options, php_stream_context *context TSRMLS_DC);
+PHPAPI int _php_stream_mkdir(const char *path, int mode, int options, php_stream_context *context TSRMLS_DC);
#define php_stream_mkdir(path, mode, options, context) _php_stream_mkdir(path, mode, options, context TSRMLS_CC)
-PHPAPI int _php_stream_rmdir(char *path, int options, php_stream_context *context TSRMLS_DC);
+PHPAPI int _php_stream_rmdir(const char *path, int options, php_stream_context *context TSRMLS_DC);
#define php_stream_rmdir(path, options, context) _php_stream_rmdir(path, options, context TSRMLS_CC)
-PHPAPI php_stream *_php_stream_opendir(char *path, int options, php_stream_context *context STREAMS_DC TSRMLS_DC);
+PHPAPI php_stream *_php_stream_opendir(const char *path, int options, php_stream_context *context STREAMS_DC TSRMLS_DC);
#define php_stream_opendir(path, options, context) _php_stream_opendir((path), (options), (context) STREAMS_CC TSRMLS_CC)
PHPAPI php_stream_dirent *_php_stream_readdir(php_stream *dirstream, php_stream_dirent *ent TSRMLS_DC);
#define php_stream_readdir(dirstream, dirent) _php_stream_readdir((dirstream), (dirent) TSRMLS_CC)
@@ -354,7 +354,7 @@ PHPAPI php_stream_dirent *_php_stream_readdir(php_stream *dirstream, php_stream_
PHPAPI int php_stream_dirent_alphasort(const char **a, const char **b);
PHPAPI int php_stream_dirent_alphasortr(const char **a, const char **b);
-PHPAPI int _php_stream_scandir(char *dirname, char **namelist[], int flags, php_stream_context *context,
+PHPAPI int _php_stream_scandir(const char *dirname, char **namelist[], int flags, php_stream_context *context,
int (*compare) (const char **a, const char **b) TSRMLS_DC);
#define php_stream_scandir(dirname, namelist, context, compare) _php_stream_scandir((dirname), (namelist), 0, (context), (compare) TSRMLS_CC)
@@ -544,13 +544,13 @@ void php_shutdown_stream_hashes(TSRMLS_D);
PHP_RSHUTDOWN_FUNCTION(streams);
BEGIN_EXTERN_C()
-PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC);
-PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC);
-PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC);
-PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC);
-PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
-PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char **path_for_open, int options TSRMLS_DC);
-PHPAPI char *php_stream_locate_eol(php_stream *stream, char *buf, size_t buf_len TSRMLS_DC);
+PHPAPI int php_register_url_stream_wrapper(const char *protocol, php_stream_wrapper *wrapper TSRMLS_DC);
+PHPAPI int php_unregister_url_stream_wrapper(const char *protocol TSRMLS_DC);
+PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_stream_wrapper *wrapper TSRMLS_DC);
+PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol TSRMLS_DC);
+PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
+PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const char **path_for_open, int options TSRMLS_DC);
+PHPAPI const char *php_stream_locate_eol(php_stream *stream, const char *buf, size_t buf_len TSRMLS_DC);
#define php_stream_open_wrapper(path, mode, options, opened) _php_stream_open_wrapper_ex((path), (mode), (options), (opened), NULL STREAMS_CC TSRMLS_CC)
#define php_stream_open_wrapper_ex(path, mode, options, opened, context) _php_stream_open_wrapper_ex((path), (mode), (options), (opened), (context) STREAMS_CC TSRMLS_CC)
diff --git a/main/php_variables.c b/main/php_variables.c
index d751ef5d5d..90cfcb20bc 100644
--- a/main/php_variables.c
+++ b/main/php_variables.c
@@ -23,11 +23,15 @@
#include "php.h"
#include "ext/standard/php_standard.h"
#include "ext/standard/credits.h"
+#include "ext/standard/php_smart_str.h"
#include "php_variables.h"
#include "php_globals.h"
#include "php_content_types.h"
#include "SAPI.h"
#include "zend_globals.h"
+#ifdef PHP_WIN32
+# include "win32/php_inttypes.h"
+#endif
/* for systems that need to override reading of environment variables */
void _php_import_environment_variables(zval *array_ptr TSRMLS_DC);
@@ -228,44 +232,115 @@ plain_var:
free_alloca(var_orig, use_heap);
}
+typedef struct post_var_data {
+ smart_str str;
+ char *ptr;
+ char *end;
+ uint64_t cnt;
+} post_var_data_t;
+
+static zend_bool add_post_var(zval *arr, post_var_data_t *var, zend_bool eof TSRMLS_DC)
+{
+ char *ksep, *vsep;
+ size_t klen, vlen;
+ /* FIXME: string-size_t */
+ unsigned int new_vlen;
+
+ if (var->ptr >= var->end) {
+ return 0;
+ }
+
+ vsep = memchr(var->ptr, '&', var->end - var->ptr);
+ if (!vsep) {
+ if (!eof) {
+ return 0;
+ } else {
+ vsep = var->end;
+ }
+ }
+
+ ksep = memchr(var->ptr, '=', vsep - var->ptr);
+ if (ksep) {
+ *ksep = '\0';
+ /* "foo=bar&" or "foo=&" */
+ klen = ksep - var->ptr;
+ vlen = vsep - ++ksep;
+ } else {
+ ksep = "";
+ /* "foo&" */
+ klen = vsep - var->ptr;
+ vlen = 0;
+ }
+
+
+ php_url_decode(var->ptr, klen);
+ if (vlen) {
+ vlen = php_url_decode(ksep, vlen);
+ }
+
+ if (sapi_module.input_filter(PARSE_POST, var->ptr, &ksep, vlen, &new_vlen TSRMLS_CC)) {
+ php_register_variable_safe(var->ptr, ksep, new_vlen, arr TSRMLS_CC);
+ }
+
+ var->ptr = vsep + (vsep != var->end);
+ return 1;
+}
+
+static inline int add_post_vars(zval *arr, post_var_data_t *vars, zend_bool eof TSRMLS_DC)
+{
+ uint64_t max_vars = PG(max_input_vars);
+
+ vars->ptr = vars->str.c;
+ vars->end = vars->str.c + vars->str.len;
+ while (add_post_var(arr, vars, eof TSRMLS_CC)) {
+ if (++vars->cnt > max_vars) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ "Input variables exceeded %" PRIu64 ". "
+ "To increase the limit change max_input_vars in php.ini.",
+ max_vars);
+ return FAILURE;
+ }
+ }
+
+ if (!eof) {
+ memmove(vars->str.c, vars->ptr, vars->str.len = vars->end - vars->ptr);
+ }
+ return SUCCESS;
+}
+
SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler)
{
- char *var, *val, *e, *s, *p;
- zval *array_ptr = (zval *) arg;
- long count = 0;
+ zval *arr = (zval *) arg;
+ php_stream *s = SG(request_info).request_body;
+ post_var_data_t post_data;
- if (SG(request_info).post_data == NULL) {
- return;
- }
+ if (s && SUCCESS == php_stream_rewind(s)) {
+ memset(&post_data, 0, sizeof(post_data));
- s = SG(request_info).post_data;
- e = s + SG(request_info).post_data_length;
+ while (!php_stream_eof(s)) {
+ char buf[BUFSIZ] = {0};
+ size_t len = php_stream_read(s, buf, BUFSIZ);
- while (s < e && (p = memchr(s, '&', (e - s)))) {
-last_value:
- if ((val = memchr(s, '=', (p - s)))) { /* have a value */
- unsigned int val_len, new_val_len;
+ if (len && len != (size_t) -1) {
+ smart_str_appendl(&post_data.str, buf, len);
- if (++count > PG(max_input_vars)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Input variables exceeded %ld. To increase the limit change max_input_vars in php.ini.", PG(max_input_vars));
- return;
+ if (SUCCESS != add_post_vars(arr, &post_data, 0 TSRMLS_CC)) {
+ if (post_data.str.c) {
+ efree(post_data.str.c);
+ }
+ return;
+ }
}
- var = s;
- php_url_decode(var, (val - s));
- val++;
- val_len = php_url_decode(val, (p - val));
- val = estrndup(val, val_len);
- if (sapi_module.input_filter(PARSE_POST, var, &val, val_len, &new_val_len TSRMLS_CC)) {
- php_register_variable_safe(var, val, new_val_len, array_ptr TSRMLS_CC);
+ if (len != BUFSIZ){
+ break;
}
- efree(val);
}
- s = p + 1;
- }
- if (s < e) {
- p = e;
- goto last_value;
+
+ add_post_vars(arr, &post_data, 1 TSRMLS_CC);
+ if (post_data.str.c) {
+ efree(post_data.str.c);
+ }
}
}
@@ -659,7 +734,6 @@ static zend_bool php_auto_globals_create_post(const char *name, uint name_len TS
if (PG(variables_order) &&
(strchr(PG(variables_order),'P') || strchr(PG(variables_order),'p')) &&
- !SG(headers_sent) &&
SG(request_info).request_method &&
!strcasecmp(SG(request_info).request_method, "POST")) {
sapi_module.treat_data(PARSE_POST, NULL, NULL TSRMLS_CC);
diff --git a/main/php_version.h b/main/php_version.h
index ec355c3387..8e6b2b86ac 100644
--- a/main/php_version.h
+++ b/main/php_version.h
@@ -1,8 +1,8 @@
/* automatically generated by configure */
/* edit configure.in to change version number */
#define PHP_MAJOR_VERSION 5
-#define PHP_MINOR_VERSION 5
-#define PHP_RELEASE_VERSION 17
+#define PHP_MINOR_VERSION 6
+#define PHP_RELEASE_VERSION 1
#define PHP_EXTRA_VERSION "-dev"
-#define PHP_VERSION "5.5.17-dev"
-#define PHP_VERSION_ID 50517
+#define PHP_VERSION "5.6.1-dev"
+#define PHP_VERSION_ID 50601
diff --git a/main/rfc1867.c b/main/rfc1867.c
index ab1eb75e7d..806a292872 100644
--- a/main/rfc1867.c
+++ b/main/rfc1867.c
@@ -34,6 +34,11 @@
#include "rfc1867.h"
#include "ext/standard/php_string.h"
+#if defined(PHP_WIN32) && !defined(HAVE_ATOLL)
+# define atoll(s) _atoi64(s)
+# define HAVE_ATOLL 1
+#endif
+
#define DEBUG_FILE_UPLOAD ZEND_DEBUG
static int dummy_encoding_translation(TSRMLS_D)
@@ -676,8 +681,9 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
{
char *boundary, *s = NULL, *boundary_end = NULL, *start_arr = NULL, *array_index = NULL;
char *temp_filename = NULL, *lbuf = NULL, *abuf = NULL;
- int boundary_len = 0, total_bytes = 0, cancel_upload = 0, is_arr_upload = 0, array_len = 0;
- int max_file_size = 0, skip_upload = 0, anonindex = 0, is_anonymous;
+ int boundary_len = 0, cancel_upload = 0, is_arr_upload = 0, array_len = 0;
+ int64_t total_bytes = 0, max_file_size = 0;
+ int skip_upload = 0, anonindex = 0, is_anonymous;
zval *http_post_files = NULL;
HashTable *uploaded_files = NULL;
multipart_buffer *mbuff;
@@ -898,7 +904,11 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
}
if (!strcasecmp(param, "MAX_FILE_SIZE")) {
- max_file_size = atol(value);
+#ifdef HAVE_ATOLL
+ max_file_size = atoll(value);
+#else
+ max_file_size = strtoll(value, NULL, 10);
+#endif
}
efree(param);
@@ -1210,17 +1220,32 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
{
zval file_size, error_type;
+ int size_overflow = 0;
+ char file_size_buf[65];
- error_type.value.lval = cancel_upload;
- error_type.type = IS_LONG;
+ ZVAL_LONG(&error_type, cancel_upload);
/* Add $foo[error] */
if (cancel_upload) {
- file_size.value.lval = 0;
- file_size.type = IS_LONG;
+ ZVAL_LONG(&file_size, 0);
} else {
- file_size.value.lval = total_bytes;
- file_size.type = IS_LONG;
+ if (total_bytes > LONG_MAX) {
+#ifdef PHP_WIN32
+ if (_i64toa_s(total_bytes, file_size_buf, 65, 10)) {
+ file_size_buf[0] = '0';
+ file_size_buf[1] = '\0';
+ }
+#else
+ {
+ int __len = snprintf(file_size_buf, 65, "%lld", total_bytes);
+ file_size_buf[__len] = '\0';
+ }
+#endif
+ size_overflow = 1;
+
+ } else {
+ ZVAL_LONG(&file_size, total_bytes);
+ }
}
if (is_arr_upload) {
@@ -1237,7 +1262,10 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
snprintf(lbuf, llen, "%s_size", param);
}
if (!is_anonymous) {
- safe_php_register_variable_ex(lbuf, &file_size, NULL, 0 TSRMLS_CC);
+ if (size_overflow) {
+ ZVAL_STRING(&file_size, file_size_buf, 1);
+ }
+ safe_php_register_variable_ex(lbuf, &file_size, NULL, size_overflow TSRMLS_CC);
}
/* Add $foo[size] */
@@ -1246,7 +1274,10 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
} else {
snprintf(lbuf, llen, "%s[size]", param);
}
- register_http_post_files_variable_ex(lbuf, &file_size, http_post_files, 0 TSRMLS_CC);
+ if (size_overflow) {
+ ZVAL_STRING(&file_size, file_size_buf, 1);
+ }
+ register_http_post_files_variable_ex(lbuf, &file_size, http_post_files, size_overflow TSRMLS_CC);
}
efree(param);
}
diff --git a/main/streams/glob_wrapper.c b/main/streams/glob_wrapper.c
index e0a1561fc3..5a48584f4e 100644
--- a/main/streams/glob_wrapper.c
+++ b/main/streams/glob_wrapper.c
@@ -109,9 +109,9 @@ PHPAPI int _php_glob_stream_get_count(php_stream *stream, int *pflags STREAMS_DC
}
/* }}} */
-static void php_glob_stream_path_split(glob_s_t *pglob, char *path, int get_path, char **p_file TSRMLS_DC) /* {{{ */
+static void php_glob_stream_path_split(glob_s_t *pglob, const char *path, int get_path, const char **p_file TSRMLS_DC) /* {{{ */
{
- char *pos, *gpath = path;
+ const char *pos, *gpath = path;
if ((pos = strrchr(path, '/')) != NULL) {
path = pos+1;
@@ -141,7 +141,7 @@ static size_t php_glob_stream_read(php_stream *stream, char *buf, size_t count T
{
glob_s_t *pglob = (glob_s_t *)stream->abstract;
php_stream_dirent *ent = (php_stream_dirent*)buf;
- char *path;
+ const char *path;
/* avoid problems if someone mis-uses the stream */
if (count == sizeof(php_stream_dirent) && pglob) {
@@ -206,12 +206,12 @@ php_stream_ops php_glob_stream_ops = {
};
/* {{{ php_glob_stream_opener */
-static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, char *path, char *mode,
+static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, const char *path, const char *mode,
int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
{
glob_s_t *pglob;
int ret;
- char *tmp, *pos;
+ const char *tmp, *pos;
if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path TSRMLS_CC)) {
return NULL;
diff --git a/main/streams/memory.c b/main/streams/memory.c
index e6d0baaa86..09421ea49d 100644
--- a/main/streams/memory.c
+++ b/main/streams/memory.c
@@ -352,6 +352,7 @@ typedef struct {
size_t smax;
int mode;
zval* meta;
+ char* tmpdir;
} php_stream_temp_data;
@@ -369,7 +370,7 @@ static size_t php_stream_temp_write(php_stream *stream, const char *buf, size_t
char *membuf = php_stream_memory_get_buffer(ts->innerstream, &memsize);
if (memsize + count >= ts->smax) {
- php_stream *file = php_stream_fopen_tmpfile();
+ php_stream *file = php_stream_fopen_temporary_file(ts->tmpdir, "php", NULL);
php_stream_write(file, membuf, memsize);
php_stream_free_enclosed(ts->innerstream, PHP_STREAM_FREE_CLOSE);
ts->innerstream = file;
@@ -420,6 +421,10 @@ static int php_stream_temp_close(php_stream *stream, int close_handle TSRMLS_DC)
zval_ptr_dtor(&ts->meta);
}
+ if (ts->tmpdir) {
+ efree(ts->tmpdir);
+ }
+
efree(ts);
return ret;
@@ -547,8 +552,8 @@ PHPAPI php_stream_ops php_stream_temp_ops = {
/* }}} */
-/* {{{ _php_stream_temp_create */
-PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STREAMS_DC TSRMLS_DC)
+/* {{{ _php_stream_temp_create_ex */
+PHPAPI php_stream *_php_stream_temp_create_ex(int mode, size_t max_memory_usage, const char *tmpdir STREAMS_DC TSRMLS_DC)
{
php_stream_temp_data *self;
php_stream *stream;
@@ -556,7 +561,9 @@ PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STR
self = ecalloc(1, sizeof(*self));
self->smax = max_memory_usage;
self->mode = mode;
- self->meta = NULL;
+ if (tmpdir) {
+ self->tmpdir = estrdup(tmpdir);
+ }
stream = php_stream_alloc_rel(&php_stream_temp_ops, self, 0, mode & TEMP_STREAM_READONLY ? "rb" : "w+b");
stream->flags |= PHP_STREAM_FLAG_NO_BUFFER;
self->innerstream = php_stream_memory_create_rel(mode);
@@ -566,6 +573,12 @@ PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STR
}
/* }}} */
+/* {{{ _php_stream_temp_create */
+PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STREAMS_DC TSRMLS_DC)
+{
+ return php_stream_temp_create_ex(mode, max_memory_usage, NULL);
+}
+/* }}} */
/* {{{ _php_stream_temp_open */
PHPAPI php_stream *_php_stream_temp_open(int mode, size_t max_memory_usage, char *buf, size_t length STREAMS_DC TSRMLS_DC)
@@ -598,7 +611,9 @@ PHPAPI php_stream_ops php_stream_rfc2397_ops = {
php_stream_temp_set_option
};
-static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) /* {{{ */
+static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, const char *path,
+ const char *mode, int options, char **opened_path,
+ php_stream_context *context STREAMS_DC TSRMLS_DC) /* {{{ */
{
php_stream *stream;
php_stream_temp_data *ts;
@@ -640,11 +655,11 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, cha
MAKE_STD_ZVAL(meta);
array_init(meta);
if (!semi) { /* there is only a mime type */
- add_assoc_stringl(meta, "mediatype", path, mlen, 1);
+ add_assoc_stringl(meta, "mediatype", (char *) path, mlen, 1);
mlen = 0;
} else if (sep && sep < semi) { /* there is a mime type */
plen = semi - path;
- add_assoc_stringl(meta, "mediatype", path, plen, 1);
+ add_assoc_stringl(meta, "mediatype", (char *) path, plen, 1);
mlen -= plen;
path += plen;
} else if (semi != path || mlen != sizeof(";base64")-1 || memcmp(path, ";base64", sizeof(";base64")-1)) { /* must be error since parameters are only allowed after mediatype */
diff --git a/main/streams/php_stream_plain_wrapper.h b/main/streams/php_stream_plain_wrapper.h
index f27dde2e55..4370867995 100644
--- a/main/streams/php_stream_plain_wrapper.h
+++ b/main/streams/php_stream_plain_wrapper.h
@@ -30,7 +30,7 @@ BEGIN_EXTERN_C()
PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, char **opened_path, int options STREAMS_DC TSRMLS_DC);
#define php_stream_fopen(filename, mode, opened) _php_stream_fopen((filename), (mode), (opened), 0 STREAMS_CC TSRMLS_CC)
-PHPAPI php_stream *_php_stream_fopen_with_path(char *filename, char *mode, char *path, char **opened_path, int options STREAMS_DC TSRMLS_DC);
+PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char *mode, const char *path, char **opened_path, int options STREAMS_DC TSRMLS_DC);
#define php_stream_fopen_with_path(filename, mode, path, opened) _php_stream_fopen_with_path((filename), (mode), (path), (opened), 0 STREAMS_CC TSRMLS_CC)
PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STREAMS_DC TSRMLS_DC);
diff --git a/main/streams/php_stream_transport.h b/main/streams/php_stream_transport.h
index 072625b701..dc10eb4e92 100644
--- a/main/streams/php_stream_transport.h
+++ b/main/streams/php_stream_transport.h
@@ -26,16 +26,16 @@
# include <sys/socket.h>
#endif
-typedef php_stream *(php_stream_transport_factory_func)(const char *proto, long protolen,
- char *resourcename, long resourcenamelen,
+typedef php_stream *(php_stream_transport_factory_func)(const char *proto, size_t protolen,
+ const char *resourcename, size_t resourcenamelen,
const char *persistent_id, int options, int flags,
struct timeval *timeout,
php_stream_context *context STREAMS_DC TSRMLS_DC);
typedef php_stream_transport_factory_func *php_stream_transport_factory;
BEGIN_EXTERN_C()
-PHPAPI int php_stream_xport_register(char *protocol, php_stream_transport_factory factory TSRMLS_DC);
-PHPAPI int php_stream_xport_unregister(char *protocol TSRMLS_DC);
+PHPAPI int php_stream_xport_register(const char *protocol, php_stream_transport_factory factory TSRMLS_DC);
+PHPAPI int php_stream_xport_unregister(const char *protocol TSRMLS_DC);
#define STREAM_XPORT_CLIENT 0
#define STREAM_XPORT_SERVER 1
@@ -46,7 +46,7 @@ PHPAPI int php_stream_xport_unregister(char *protocol TSRMLS_DC);
#define STREAM_XPORT_CONNECT_ASYNC 16
/* Open a client or server socket connection */
-PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int options,
+PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, int options,
int flags, const char *persistent_id,
struct timeval *timeout,
php_stream_context *context,
@@ -59,13 +59,13 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int
/* Bind the stream to a local address */
PHPAPI int php_stream_xport_bind(php_stream *stream,
- const char *name, long namelen,
+ const char *name, size_t namelen,
char **error_text
TSRMLS_DC);
/* Connect to a remote address */
PHPAPI int php_stream_xport_connect(php_stream *stream,
- const char *name, long namelen,
+ const char *name, size_t namelen,
int asynchronous,
struct timeval *timeout,
char **error_text,
@@ -141,7 +141,7 @@ typedef struct _php_stream_xport_param {
struct {
char *name;
- long namelen;
+ size_t namelen;
int backlog;
struct timeval *timeout;
struct sockaddr *addr;
@@ -163,19 +163,30 @@ typedef struct _php_stream_xport_param {
} outputs;
} php_stream_xport_param;
-
-/* These functions provide crypto support on the underlying transport */
+/* Because both client and server streams use the same mechanisms
+ for encryption we use the LSB to denote clients.
+*/
typedef enum {
- STREAM_CRYPTO_METHOD_SSLv2_CLIENT,
- STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
- STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
- STREAM_CRYPTO_METHOD_TLS_CLIENT,
- STREAM_CRYPTO_METHOD_SSLv2_SERVER,
- STREAM_CRYPTO_METHOD_SSLv3_SERVER,
- STREAM_CRYPTO_METHOD_SSLv23_SERVER,
- STREAM_CRYPTO_METHOD_TLS_SERVER
+ STREAM_CRYPTO_METHOD_SSLv2_CLIENT = (1 << 1 | 1),
+ STREAM_CRYPTO_METHOD_SSLv3_CLIENT = (1 << 2 | 1),
+ STREAM_CRYPTO_METHOD_SSLv23_CLIENT = ((1 << 1) | (1 << 2) | 1),
+ STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT = (1 << 3 | 1),
+ STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT = (1 << 4 | 1),
+ STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT = (1 << 5 | 1),
+ STREAM_CRYPTO_METHOD_TLS_CLIENT = ((1 << 3) | (1 << 4) | (1 << 5) | 1),
+ STREAM_CRYPTO_METHOD_ANY_CLIENT = ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | 1),
+ STREAM_CRYPTO_METHOD_SSLv2_SERVER = (1 << 1),
+ STREAM_CRYPTO_METHOD_SSLv3_SERVER = (1 << 2),
+ STREAM_CRYPTO_METHOD_SSLv23_SERVER = ((1 << 1) | (1 << 2)),
+ STREAM_CRYPTO_METHOD_TLSv1_0_SERVER = (1 << 3),
+ STREAM_CRYPTO_METHOD_TLSv1_1_SERVER = (1 << 4),
+ STREAM_CRYPTO_METHOD_TLSv1_2_SERVER = (1 << 5),
+ STREAM_CRYPTO_METHOD_TLS_SERVER = ((1 << 3) | (1 << 4) | (1 << 5)),
+ STREAM_CRYPTO_METHOD_ANY_SERVER = ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5))
} php_stream_xport_crypt_method_t;
+/* These functions provide crypto support on the underlying transport */
+
BEGIN_EXTERN_C()
PHPAPI int php_stream_xport_crypto_setup(php_stream *stream, php_stream_xport_crypt_method_t crypto_method, php_stream *session_stream TSRMLS_DC);
PHPAPI int php_stream_xport_crypto_enable(php_stream *stream, int activate TSRMLS_DC);
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index a50662b78e..87312b9ef8 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -183,31 +183,20 @@ static php_stream *_php_stream_fopen_from_file_int(FILE *file, const char *mode
return php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode);
}
-PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, char **opened_path STREAMS_DC TSRMLS_DC)
+PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, char **opened_path_ptr STREAMS_DC TSRMLS_DC)
{
- int fd = php_open_temporary_fd(dir, pfx, opened_path TSRMLS_CC);
+ char *opened_path = NULL;
+ int fd;
+ fd = php_open_temporary_fd(dir, pfx, &opened_path TSRMLS_CC);
if (fd != -1) {
- php_stream *stream = php_stream_fopen_from_fd_int_rel(fd, "r+b", NULL);
- if (stream) {
- return stream;
- }
- close(fd);
+ php_stream *stream;
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to allocate stream");
-
- return NULL;
- }
- return NULL;
-}
-
-PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC TSRMLS_DC)
-{
- char *opened_path = NULL;
- int fd = php_open_temporary_fd(NULL, "php", &opened_path TSRMLS_CC);
+ if (opened_path_ptr) {
+ *opened_path_ptr = opened_path;
+ }
- if (fd != -1) {
- php_stream *stream = php_stream_fopen_from_fd_int_rel(fd, "r+b", NULL);
+ stream = php_stream_fopen_from_fd_int_rel(fd, "r+b", NULL);
if (stream) {
php_stdio_stream_data *self = (php_stdio_stream_data*)stream->abstract;
stream->wrapper = &php_plain_files_wrapper;
@@ -227,6 +216,11 @@ PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC TSRMLS_DC)
return NULL;
}
+PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC TSRMLS_DC)
+{
+ return php_stream_fopen_temporary_file(NULL, "php", NULL);
+}
+
PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const char *persistent_id STREAMS_DC TSRMLS_DC)
{
php_stream *stream = php_stream_fopen_from_fd_int_rel(fd, mode, persistent_id);
@@ -482,7 +476,7 @@ static int php_stdiop_seek(php_stream *stream, off_t offset, int whence, off_t *
static int php_stdiop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
{
- int fd;
+ php_socket_t fd;
php_stdio_stream_data *data = (php_stdio_stream_data*) stream->abstract;
assert(data != NULL);
@@ -506,31 +500,31 @@ static int php_stdiop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
}
*(FILE**)ret = data->file;
- data->fd = -1;
+ data->fd = SOCK_ERR;
}
return SUCCESS;
case PHP_STREAM_AS_FD_FOR_SELECT:
PHP_STDIOP_GET_FD(fd, data);
- if (fd < 0) {
+ if (SOCK_ERR == fd) {
return FAILURE;
}
if (ret) {
- *(int*)ret = fd;
+ *(php_socket_t *)ret = fd;
}
return SUCCESS;
case PHP_STREAM_AS_FD:
PHP_STDIOP_GET_FD(fd, data);
- if (fd < 0) {
+ if (SOCK_ERR == fd) {
return FAILURE;
}
if (data->file) {
fflush(data->file);
}
if (ret) {
- *(int*)ret = fd;
+ *(php_socket_t *)ret = fd;
}
return SUCCESS;
default:
@@ -853,7 +847,7 @@ static php_stream_ops php_plain_files_dirstream_ops = {
NULL /* set_option */
};
-static php_stream *php_plain_files_dir_opener(php_stream_wrapper *wrapper, char *path, char *mode,
+static php_stream *php_plain_files_dir_opener(php_stream_wrapper *wrapper, const char *path, const char *mode,
int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
{
DIR *dir = NULL;
@@ -991,7 +985,7 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha
/* }}} */
-static php_stream *php_plain_files_stream_opener(php_stream_wrapper *wrapper, char *path, char *mode,
+static php_stream *php_plain_files_stream_opener(php_stream_wrapper *wrapper, const char *path, const char *mode,
int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
{
if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path TSRMLS_CC)) {
@@ -1001,7 +995,7 @@ static php_stream *php_plain_files_stream_opener(php_stream_wrapper *wrapper, ch
return php_stream_fopen_rel(path, mode, opened_path, options);
}
-static int php_plain_files_url_stater(php_stream_wrapper *wrapper, char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC)
+static int php_plain_files_url_stater(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC)
{
char *p;
@@ -1031,7 +1025,7 @@ static int php_plain_files_url_stater(php_stream_wrapper *wrapper, char *url, in
return VCWD_STAT(url, &ssb->sb);
}
-static int php_plain_files_unlink(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC)
+static int php_plain_files_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC)
{
char *p;
int ret;
@@ -1060,7 +1054,7 @@ static int php_plain_files_unlink(php_stream_wrapper *wrapper, char *url, int op
return 1;
}
-static int php_plain_files_rename(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC)
+static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context TSRMLS_DC)
{
char *p;
int ret;
@@ -1149,7 +1143,7 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, char *url_from, c
return 1;
}
-static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mode, int options, php_stream_context *context TSRMLS_DC)
+static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, int mode, int options, php_stream_context *context TSRMLS_DC)
{
int ret, recursive = options & PHP_STREAM_MKDIR_RECURSIVE;
char *p;
@@ -1237,7 +1231,7 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mod
}
}
-static int php_plain_files_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC)
+static int php_plain_files_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC)
{
#if PHP_WIN32
int url_len = strlen(url);
@@ -1264,7 +1258,7 @@ static int php_plain_files_rmdir(php_stream_wrapper *wrapper, char *url, int opt
return 1;
}
-static int php_plain_files_metadata(php_stream_wrapper *wrapper, char *url, int option, void *value, php_stream_context *context TSRMLS_DC)
+static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url, int option, void *value, php_stream_context *context TSRMLS_DC)
{
struct utimbuf *newtime;
char *p;
@@ -1373,10 +1367,11 @@ php_stream_wrapper php_plain_files_wrapper = {
};
/* {{{ php_stream_fopen_with_path */
-PHPAPI php_stream *_php_stream_fopen_with_path(char *filename, char *mode, char *path, char **opened_path, int options STREAMS_DC TSRMLS_DC)
+PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char *mode, const char *path, char **opened_path, int options STREAMS_DC TSRMLS_DC)
{
/* code ripped off from fopen_wrappers.c */
- char *pathbuf, *ptr, *end;
+ char *pathbuf, *end;
+ const char *ptr;
const char *exec_fname;
char trypath[MAXPATHLEN];
php_stream *stream;
@@ -1437,7 +1432,7 @@ not_relative_path:
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s/%s path was truncated to %d", cwd, filename, MAXPATHLEN);
}
- free(cwd);
+ efree(cwd);
if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(trypath TSRMLS_CC)) {
return NULL;
diff --git a/main/streams/streams.c b/main/streams/streams.c
index 3c57b405c5..d0d4fffa0a 100644
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -807,7 +807,7 @@ PHPAPI int _php_stream_getc(php_stream *stream TSRMLS_DC)
return EOF;
}
-PHPAPI int _php_stream_puts(php_stream *stream, char *buf TSRMLS_DC)
+PHPAPI int _php_stream_puts(php_stream *stream, const char *buf TSRMLS_DC)
{
int len;
char newline[2] = "\n"; /* is this OK for Win? */
@@ -839,11 +839,11 @@ PHPAPI int _php_stream_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_D
return (stream->ops->stat)(stream, ssb TSRMLS_CC);
}
-PHPAPI char *php_stream_locate_eol(php_stream *stream, char *buf, size_t buf_len TSRMLS_DC)
+PHPAPI const char *php_stream_locate_eol(php_stream *stream, const char *buf, size_t buf_len TSRMLS_DC)
{
size_t avail;
- char *cr, *lf, *eol = NULL;
- char *readptr;
+ const char *cr, *lf, *eol = NULL;
+ const char *readptr;
if (!buf) {
readptr = stream->readbuf + stream->readpos;
@@ -915,7 +915,7 @@ PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen,
if (avail > 0) {
size_t cpysz = 0;
char *readptr;
- char *eol;
+ const char *eol;
int done = 0;
readptr = stream->readbuf + stream->readpos;
@@ -998,11 +998,11 @@ PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen,
#define STREAM_BUFFERED_AMOUNT(stream) \
((size_t)(((stream)->writepos) - (stream)->readpos))
-static char *_php_stream_search_delim(php_stream *stream,
- size_t maxlen,
- size_t skiplen,
- char *delim, /* non-empty! */
- size_t delim_len TSRMLS_DC)
+static const char *_php_stream_search_delim(php_stream *stream,
+ size_t maxlen,
+ size_t skiplen,
+ const char *delim, /* non-empty! */
+ size_t delim_len TSRMLS_DC)
{
size_t seek_len;
@@ -1022,10 +1022,10 @@ static char *_php_stream_search_delim(php_stream *stream,
}
}
-PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, char *delim, size_t delim_len TSRMLS_DC)
+PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, const char *delim, size_t delim_len TSRMLS_DC)
{
- char *ret_buf, /* returned buffer */
- *found_delim = NULL;
+ char *ret_buf; /* returned buffer */
+ const char *found_delim = NULL;
size_t buffered_len,
tent_ret_len; /* tentative returned length */
int has_delim = delim_len > 0;
@@ -1685,9 +1685,9 @@ int php_shutdown_stream_wrappers(int module_number TSRMLS_DC)
/* Validate protocol scheme names during registration
* Must conform to /^[a-zA-Z0-9+.-]+$/
*/
-static inline int php_stream_wrapper_scheme_validate(char *protocol, int protocol_len)
+static inline int php_stream_wrapper_scheme_validate(const char *protocol, unsigned int protocol_len)
{
- int i;
+ unsigned int i;
for(i = 0; i < protocol_len; i++) {
if (!isalnum((int)protocol[i]) &&
@@ -1702,9 +1702,9 @@ static inline int php_stream_wrapper_scheme_validate(char *protocol, int protoco
}
/* API for registering GLOBAL wrappers */
-PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC)
+PHPAPI int php_register_url_stream_wrapper(const char *protocol, php_stream_wrapper *wrapper TSRMLS_DC)
{
- int protocol_len = strlen(protocol);
+ unsigned int protocol_len = strlen(protocol);
if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) {
return FAILURE;
@@ -1713,7 +1713,7 @@ PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *w
return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL);
}
-PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC)
+PHPAPI int php_unregister_url_stream_wrapper(const char *protocol TSRMLS_DC)
{
return zend_hash_del(&url_stream_wrappers_hash, protocol, strlen(protocol) + 1);
}
@@ -1728,9 +1728,9 @@ static void clone_wrapper_hash(TSRMLS_D)
}
/* API for registering VOLATILE wrappers */
-PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC)
+PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_stream_wrapper *wrapper TSRMLS_DC)
{
- int protocol_len = strlen(protocol);
+ unsigned int protocol_len = strlen(protocol);
if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) {
return FAILURE;
@@ -1743,7 +1743,7 @@ PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_w
return zend_hash_add(FG(stream_wrappers), protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL);
}
-PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC)
+PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol TSRMLS_DC)
{
if (!FG(stream_wrappers)) {
clone_wrapper_hash(TSRMLS_C);
@@ -1754,7 +1754,7 @@ PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC)
/* }}} */
/* {{{ php_stream_locate_url_wrapper */
-PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char **path_for_open, int options TSRMLS_DC)
+PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const char **path_for_open, int options TSRMLS_DC)
{
HashTable *wrapper_hash = (FG(stream_wrappers) ? FG(stream_wrappers) : &url_stream_wrappers_hash);
php_stream_wrapper **wrapperpp = NULL;
@@ -1889,7 +1889,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
/* {{{ _php_stream_mkdir
*/
-PHPAPI int _php_stream_mkdir(char *path, int mode, int options, php_stream_context *context TSRMLS_DC)
+PHPAPI int _php_stream_mkdir(const char *path, int mode, int options, php_stream_context *context TSRMLS_DC)
{
php_stream_wrapper *wrapper = NULL;
@@ -1904,7 +1904,7 @@ PHPAPI int _php_stream_mkdir(char *path, int mode, int options, php_stream_conte
/* {{{ _php_stream_rmdir
*/
-PHPAPI int _php_stream_rmdir(char *path, int options, php_stream_context *context TSRMLS_DC)
+PHPAPI int _php_stream_rmdir(const char *path, int options, php_stream_context *context TSRMLS_DC)
{
php_stream_wrapper *wrapper = NULL;
@@ -1918,10 +1918,10 @@ PHPAPI int _php_stream_rmdir(char *path, int options, php_stream_context *contex
/* }}} */
/* {{{ _php_stream_stat_path */
-PHPAPI int _php_stream_stat_path(char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC)
+PHPAPI int _php_stream_stat_path(const char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC)
{
php_stream_wrapper *wrapper = NULL;
- char *path_to_open = path;
+ const char *path_to_open = path;
int ret;
if (!(flags & PHP_STREAM_URL_STAT_NOCACHE)) {
@@ -1967,12 +1967,12 @@ PHPAPI int _php_stream_stat_path(char *path, int flags, php_stream_statbuf *ssb,
/* }}} */
/* {{{ php_stream_opendir */
-PHPAPI php_stream *_php_stream_opendir(char *path, int options,
+PHPAPI php_stream *_php_stream_opendir(const char *path, int options,
php_stream_context *context STREAMS_DC TSRMLS_DC)
{
php_stream *stream = NULL;
php_stream_wrapper *wrapper = NULL;
- char *path_to_open;
+ const char *path_to_open;
if (!path || !*path) {
return NULL;
@@ -2016,12 +2016,12 @@ PHPAPI php_stream_dirent *_php_stream_readdir(php_stream *dirstream, php_stream_
/* }}} */
/* {{{ php_stream_open_wrapper_ex */
-PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int options,
+PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mode, int options,
char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
{
php_stream *stream = NULL;
php_stream_wrapper *wrapper = NULL;
- char *path_to_open;
+ const char *path_to_open;
int persistent = options & STREAM_OPEN_PERSISTENT;
char *resolved_path = NULL;
char *copy_of_path = NULL;
@@ -2277,7 +2277,7 @@ PHPAPI int php_stream_dirent_alphasortr(const char **a, const char **b)
/* {{{ php_stream_scandir
*/
-PHPAPI int _php_stream_scandir(char *dirname, char **namelist[], int flags, php_stream_context *context,
+PHPAPI int _php_stream_scandir(const char *dirname, char **namelist[], int flags, php_stream_context *context,
int (*compare) (const char **a, const char **b) TSRMLS_DC)
{
php_stream *stream;
diff --git a/main/streams/transports.c b/main/streams/transports.c
index 1bf096efb2..a633b059fa 100644
--- a/main/streams/transports.c
+++ b/main/streams/transports.c
@@ -29,12 +29,12 @@ PHPAPI HashTable *php_stream_xport_get_hash(void)
return &xport_hash;
}
-PHPAPI int php_stream_xport_register(char *protocol, php_stream_transport_factory factory TSRMLS_DC)
+PHPAPI int php_stream_xport_register(const char *protocol, php_stream_transport_factory factory TSRMLS_DC)
{
return zend_hash_update(&xport_hash, protocol, strlen(protocol) + 1, &factory, sizeof(factory), NULL);
}
-PHPAPI int php_stream_xport_unregister(char *protocol TSRMLS_DC)
+PHPAPI int php_stream_xport_unregister(const char *protocol TSRMLS_DC)
{
return zend_hash_del(&xport_hash, protocol, strlen(protocol) + 1);
}
@@ -49,7 +49,7 @@ PHPAPI int php_stream_xport_unregister(char *protocol TSRMLS_DC)
if (local_err) { efree(local_err); local_err = NULL; } \
}
-PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int options,
+PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, int options,
int flags, const char *persistent_id,
struct timeval *timeout,
php_stream_context *context,
@@ -194,7 +194,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int
/* Bind the stream to a local address */
PHPAPI int php_stream_xport_bind(php_stream *stream,
- const char *name, long namelen,
+ const char *name, size_t namelen,
char **error_text
TSRMLS_DC)
{
@@ -222,7 +222,7 @@ PHPAPI int php_stream_xport_bind(php_stream *stream,
/* Connect to a remote address */
PHPAPI int php_stream_xport_connect(php_stream *stream,
- const char *name, long namelen,
+ const char *name, size_t namelen,
int asynchronous,
struct timeval *timeout,
char **error_text,
diff --git a/main/streams/userspace.c b/main/streams/userspace.c
index b14efdd6a5..5990464a6e 100644
--- a/main/streams/userspace.c
+++ b/main/streams/userspace.c
@@ -45,14 +45,14 @@ struct php_user_stream_wrapper {
php_stream_wrapper wrapper;
};
-static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filename, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
-static int user_wrapper_stat_url(php_stream_wrapper *wrapper, char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC);
-static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC);
-static int user_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC);
-static int user_wrapper_mkdir(php_stream_wrapper *wrapper, char *url, int mode, int options, php_stream_context *context TSRMLS_DC);
-static int user_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC);
-static int user_wrapper_metadata(php_stream_wrapper *wrapper, char *url, int option, void *value, php_stream_context *context TSRMLS_DC);
-static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, char *filename, char *mode,
+static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *filename, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
+static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC);
+static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC);
+static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context TSRMLS_DC);
+static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int mode, int options, php_stream_context *context TSRMLS_DC);
+static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC);
+static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, int option, void *value, php_stream_context *context TSRMLS_DC);
+static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char *filename, const char *mode,
int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
static php_stream_wrapper_ops user_stream_wops = {
@@ -332,7 +332,8 @@ static zval *user_stream_create_object(struct php_user_stream_wrapper *uwrap, ph
return object;
}
-static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filename, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
+static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *filename, const char *mode,
+ int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
php_userstream_data_t *us;
@@ -437,7 +438,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filena
return stream;
}
-static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, char *filename, char *mode,
+static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char *filename, const char *mode,
int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
@@ -1151,7 +1152,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
}
-static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC)
+static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
zval *zfilename, *zfuncname, *zretval;
@@ -1198,7 +1199,8 @@ static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int optio
return ret;
}
-static int user_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC)
+static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to,
+ int options, php_stream_context *context TSRMLS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
zval *zold_name, *znew_name, *zfuncname, *zretval;
@@ -1250,7 +1252,8 @@ static int user_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char
return ret;
}
-static int user_wrapper_mkdir(php_stream_wrapper *wrapper, char *url, int mode, int options, php_stream_context *context TSRMLS_DC)
+static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int mode,
+ int options, php_stream_context *context TSRMLS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
zval *zfilename, *zmode, *zoptions, *zfuncname, *zretval;
@@ -1308,7 +1311,8 @@ static int user_wrapper_mkdir(php_stream_wrapper *wrapper, char *url, int mode,
return ret;
}
-static int user_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC)
+static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url,
+ int options, php_stream_context *context TSRMLS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
zval *zfilename, *zoptions, *zfuncname, *zretval;
@@ -1361,7 +1365,8 @@ static int user_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int option
return ret;
}
-static int user_wrapper_metadata(php_stream_wrapper *wrapper, char *url, int option, void *value, php_stream_context *context TSRMLS_DC)
+static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, int option,
+ void *value, php_stream_context *context TSRMLS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
zval *zfilename, *zoption, *zvalue, *zfuncname, *zretval;
@@ -1444,7 +1449,8 @@ static int user_wrapper_metadata(php_stream_wrapper *wrapper, char *url, int opt
}
-static int user_wrapper_stat_url(php_stream_wrapper *wrapper, char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC)
+static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, int flags,
+ php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
zval *zfilename, *zfuncname, *zretval, *zflags;
diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c
index b44d5bb98e..a6dc115962 100644
--- a/main/streams/xp_socket.c
+++ b/main/streams/xp_socket.c
@@ -230,7 +230,7 @@ static int php_sockop_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC
#endif
}
-static inline int sock_sendto(php_netstream_data_t *sock, char *buf, size_t buflen, int flags,
+static inline int sock_sendto(php_netstream_data_t *sock, const char *buf, size_t buflen, int flags,
struct sockaddr *addr, socklen_t addrlen
TSRMLS_DC)
{
@@ -521,7 +521,7 @@ static inline int parse_unix_address(php_stream_xport_param *xparam, struct sock
}
#endif
-static inline char *parse_ip_address_ex(const char *str, int str_len, int *portno, int get_err, char **err TSRMLS_DC)
+static inline char *parse_ip_address_ex(const char *str, size_t str_len, int *portno, int get_err, char **err TSRMLS_DC)
{
char *colon;
char *host = NULL;
@@ -775,8 +775,8 @@ static int php_tcp_sockop_set_option(php_stream *stream, int option, int value,
}
-PHPAPI php_stream *php_stream_generic_socket_factory(const char *proto, long protolen,
- char *resourcename, long resourcenamelen,
+PHPAPI php_stream *php_stream_generic_socket_factory(const char *proto, size_t protolen,
+ const char *resourcename, size_t resourcenamelen,
const char *persistent_id, int options, int flags,
struct timeval *timeout,
php_stream_context *context STREAMS_DC TSRMLS_DC)