diff options
Diffstat (limited to 'main')
70 files changed, 949 insertions, 779 deletions
diff --git a/main/SAPI.c b/main/SAPI.c index 6216fd8176..afb0c77276 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -13,13 +13,11 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Original design: Shane Caraveo <shane@caraveo.com> | - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | + | Authors: Andi Gutmans <andi@php.net> | + | Zeev Suraski <zeev@php.net> | +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include <ctype.h> #include <sys/stat.h> @@ -780,7 +778,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg) if (!strncmp(ptr, "image/", sizeof("image/")-1)) { zend_string *key = zend_string_init("zlib.output_compression", sizeof("zlib.output_compression")-1, 0); zend_alter_ini_entry_chars(key, "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - zend_string_release(key); + zend_string_release_ex(key, 0); } mimetype = estrdup(ptr); @@ -809,7 +807,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg) zend_string *key = zend_string_init("zlib.output_compression", sizeof("zlib.output_compression")-1, 0); zend_alter_ini_entry_chars(key, "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - zend_string_release(key); + zend_string_release_ex(key, 0); } else if (!strcasecmp(header_line, "Location")) { if ((SG(sapi_headers).http_response_code < 300 || SG(sapi_headers).http_response_code > 399) && @@ -932,9 +930,9 @@ SAPI_API int sapi_send_headers(void) } -SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entries) +SAPI_API int sapi_register_post_entries(const sapi_post_entry *post_entries) { - sapi_post_entry *p=post_entries; + const sapi_post_entry *p=post_entries; while (p->content_type) { if (sapi_register_post_entry(p) == FAILURE) { @@ -946,17 +944,22 @@ SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entries) } -SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry) +SAPI_API int sapi_register_post_entry(const sapi_post_entry *post_entry) { + int ret; + zend_string *key; if (SG(sapi_started) && EG(current_execute_data)) { return FAILURE; } - return zend_hash_str_add_mem(&SG(known_post_content_types), - post_entry->content_type, post_entry->content_type_len, + key = zend_string_init(post_entry->content_type, post_entry->content_type_len, 1); + GC_MAKE_PERSISTENT_LOCAL(key); + ret = zend_hash_add_mem(&SG(known_post_content_types), key, (void *) post_entry, sizeof(sapi_post_entry)) ? SUCCESS : FAILURE; + zend_string_release_ex(key, 1); + return ret; } -SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry) +SAPI_API void sapi_unregister_post_entry(const sapi_post_entry *post_entry) { if (SG(sapi_started) && EG(current_execute_data)) { return; @@ -1104,6 +1107,56 @@ SAPI_API void sapi_terminate_process(void) { } } +SAPI_API void sapi_add_request_header(char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg) /* {{{ */ +{ + zval *return_value = (zval*)arg; + char *str = NULL; + + ALLOCA_FLAG(use_heap) + + if (var_len > 5 && + var[0] == 'H' && + var[1] == 'T' && + var[2] == 'T' && + var[3] == 'P' && + var[4] == '_') { + + char *p; + + var_len -= 5; + p = var + 5; + var = str = do_alloca(var_len + 1, use_heap); + *str++ = *p++; + while (*p) { + if (*p == '_') { + *str++ = '-'; + p++; + if (*p) { + *str++ = *p++; + } + } else if (*p >= 'A' && *p <= 'Z') { + *str++ = (*p++ - 'A' + 'a'); + } else { + *str++ = *p++; + } + } + *str = 0; + } else if (var_len == sizeof("CONTENT_TYPE")-1 && + memcmp(var, "CONTENT_TYPE", sizeof("CONTENT_TYPE")-1) == 0) { + var = "Content-Type"; + } else if (var_len == sizeof("CONTENT_LENGTH")-1 && + memcmp(var, "CONTENT_LENGTH", sizeof("CONTENT_LENGTH")-1) == 0) { + var = "Content-Length"; + } else { + return; + } + add_assoc_stringl_ex(return_value, var, var_len, val, val_len); + if (str) { + free_alloca(var, use_heap); + } +} +/* }}} */ + /* * Local variables: * tab-width: 4 diff --git a/main/SAPI.h b/main/SAPI.h index 5a5620bf0c..94612afd64 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -12,12 +12,10 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Author: Zeev Suraski <zeev@zend.com> | + | Author: Zeev Suraski <zeev@php.net> | +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef SAPI_H #define SAPI_H @@ -151,6 +149,7 @@ SAPI_API void sapi_shutdown(void); SAPI_API void sapi_activate(void); SAPI_API void sapi_deactivate(void); SAPI_API void sapi_initialize_empty_request(void); +SAPI_API void sapi_add_request_header(char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg); END_EXTERN_C() /* @@ -190,9 +189,9 @@ SAPI_API int sapi_send_headers(void); SAPI_API void sapi_free_header(sapi_header_struct *sapi_header); SAPI_API void sapi_handle_post(void *arg); SAPI_API size_t sapi_read_post_block(char *buffer, size_t buflen); -SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entry); -SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry); -SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry); +SAPI_API int sapi_register_post_entries(const sapi_post_entry *post_entry); +SAPI_API int sapi_register_post_entry(const sapi_post_entry *post_entry); +SAPI_API void sapi_unregister_post_entry(const sapi_post_entry *post_entry); SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(void)); SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray)); SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, char *var, char **val, size_t val_len, size_t *new_val_len), unsigned int (*input_filter_init)(void)); diff --git a/main/alloca.c b/main/alloca.c index 401649cee0..66e001b900 100644 --- a/main/alloca.c +++ b/main/alloca.c @@ -21,8 +21,6 @@ allocating any. It is a good idea to use alloca(0) in your main control loop, etc. to force garbage collection. */ -/* $Id$ */ - #include <php_config.h> #if !HAVE_ALLOCA diff --git a/main/build-defs.h.in b/main/build-defs.h.in index 50849a115f..67712b7b69 100644 --- a/main/build-defs.h.in +++ b/main/build-defs.h.in @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #define CONFIGURE_COMMAND "@CONFIGURE_COMMAND@" #define PHP_ADA_INCLUDE "" #define PHP_ADA_LFLAGS "" @@ -73,8 +71,6 @@ #define PHP_LDAP_LFLAGS "" #define PHP_LDAP_INCLUDE "" #define PHP_LDAP_LIBS "" -#define PHP_BIRDSTEP_INCLUDE "" -#define PHP_BIRDSTEP_LIBS "" #define PEAR_INSTALLDIR "@EXPANDED_PEAR_INSTALLDIR@" #define PHP_INCLUDE_PATH "@INCLUDE_PATH@" #define PHP_EXTENSION_DIR "@EXPANDED_EXTENSION_DIR@" diff --git a/main/explicit_bzero.c b/main/explicit_bzero.c index e44fb433df..990a8047bc 100644 --- a/main/explicit_bzero.c +++ b/main/explicit_bzero.c @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include "php.h" #ifndef HAVE_EXPLICIT_BZERO @@ -30,15 +28,22 @@ #include <string.h> -__attribute__((weak)) void -__explicit_bzero_hook(void *dst, size_t siz) -{ -} - PHPAPI void php_explicit_bzero(void *dst, size_t siz) { +#if HAVE_EXPLICIT_MEMSET + explicit_memset(dst, 0, siz); +#elif defined(PHP_WIN32) + RtlSecureZeroMemory(dst, siz); +#elif defined(__GNUC__) memset(dst, 0, siz); - __explicit_bzero_hook(dst, siz); + asm __volatile__("" :: "r"(dst) : "memory"); +#else + size_t i = 0; + volatile unsigned char *buf = (volatile unsigned char *)dst; + + for (; i < siz; i ++) + buf[i] = 0; +#endif } #endif /* diff --git a/main/fastcgi.c b/main/fastcgi.c index 3181661877..a255baedc7 100644 --- a/main/fastcgi.c +++ b/main/fastcgi.c @@ -12,12 +12,10 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Authors: Dmitry Stogov <dmitry@zend.com> | + | Authors: Dmitry Stogov <dmitry@php.net> | +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include "php.h" #include "php_network.h" @@ -739,9 +737,9 @@ int fcgi_listen(const char *path, int backlog) return listen_socket; #else - int path_len = strlen(path); + size_t path_len = strlen(path); - if (path_len >= (int)sizeof(sa.sa_unix.sun_path)) { + if (path_len >= sizeof(sa.sa_unix.sun_path)) { fcgi_log(FCGI_ERROR, "Listening socket's path name is too long.\n"); return -1; } @@ -1734,8 +1732,12 @@ void fcgi_impersonate(void) void fcgi_set_mgmt_var(const char * name, size_t name_len, const char * value, size_t value_len) { zval zvalue; + zend_string *key = zend_string_init(name, name_len, 1); ZVAL_NEW_STR(&zvalue, zend_string_init(value, value_len, 1)); - zend_hash_str_add(&fcgi_mgmt_vars, name, name_len, &zvalue); + GC_MAKE_PERSISTENT_LOCAL(key); + GC_MAKE_PERSISTENT_LOCAL(Z_STR(zvalue)); + zend_hash_add(&fcgi_mgmt_vars, key, &zvalue); + zend_string_release_ex(key, 1); } void fcgi_free_mgmt_var_cb(zval *zv) diff --git a/main/fastcgi.h b/main/fastcgi.h index 3ae3e8844f..aa7a8578f4 100644 --- a/main/fastcgi.h +++ b/main/fastcgi.h @@ -12,12 +12,10 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Authors: Dmitry Stogov <dmitry@zend.com> | + | Authors: Dmitry Stogov <dmitry@php.net> | +----------------------------------------------------------------------+ */ -/* $Id$ */ - /* FastCGI protocol */ #define FCGI_VERSION_1 1 diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index 520edfadbb..1509c006d7 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -17,8 +17,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - /* {{{ includes */ #include "php.h" @@ -168,11 +166,11 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path while (VCWD_REALPATH(path_tmp, resolved_name) == NULL) { #if defined(PHP_WIN32) || defined(HAVE_SYMLINK) if (nesting_level == 0) { - int ret; + ssize_t ret; char buf[MAXPATHLEN]; ret = php_sys_readlink(path_tmp, buf, MAXPATHLEN - 1); - if (ret < 0) { + if (ret == -1) { /* not a broken symlink, move along.. */ } else { /* put the real path into the path buffer */ @@ -355,7 +353,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle) char *path_info; char *filename = NULL; zend_string *resolved_path = NULL; - int length; + size_t length; zend_bool orig_display_errors; path_info = SG(request_info).request_uri; @@ -378,7 +376,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle) pwbuf = emalloc(pwbuflen); #endif length = s - (path_info + 2); - if (length > (int)sizeof(user) - 1) { + if (length > sizeof(user) - 1) { length = sizeof(user) - 1; } memcpy(user, path_info + 2, length); @@ -402,9 +400,9 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle) } } else #endif - if (PG(doc_root) && path_info && (length = (int)strlen(PG(doc_root))) && + if (PG(doc_root) && path_info && (length = strlen(PG(doc_root))) && IS_ABSOLUTE_PATH(PG(doc_root), length)) { - int path_len = (int)strlen(path_info); + size_t path_len = strlen(path_info); filename = emalloc(length + path_len + 2); memcpy(filename, PG(doc_root), length); if (!IS_SLASH(filename[length - 1])) { /* length is never 0 */ @@ -420,7 +418,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle) if (filename) { - resolved_path = zend_resolve_path(filename, (int)strlen(filename)); + resolved_path = zend_resolve_path(filename, strlen(filename)); } if (!resolved_path) { @@ -439,7 +437,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle) } return FAILURE; } - zend_string_release(resolved_path); + zend_string_release_ex(resolved_path, 0); orig_display_errors = PG(display_errors); PG(display_errors) = 0; @@ -472,7 +470,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle) /* {{{ php_resolve_path * Returns the realpath for given filename according to include path */ -PHPAPI zend_string *php_resolve_path(const char *filename, int filename_length, const char *path) +PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_length, const char *path) { char resolved_path[MAXPATHLEN]; char trypath[MAXPATHLEN]; @@ -532,7 +530,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, int filename_length, } end = strchr(p, DEFAULT_DIR_SEPARATOR); if (end) { - if (filename_length > (MAXPATHLEN - 2) || (end-ptr) > MAXPATHLEN || (end-ptr) + 1 + (size_t)filename_length + 1 >= MAXPATHLEN) { + if (filename_length > (MAXPATHLEN - 2) || (end-ptr) > MAXPATHLEN || (end-ptr) + 1 + filename_length + 1 >= MAXPATHLEN) { ptr = end + 1; continue; } @@ -543,7 +541,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, int filename_length, } else { size_t len = strlen(ptr); - if (filename_length > (MAXPATHLEN - 2) || len > MAXPATHLEN || len + 1 + (size_t)filename_length + 1 >= MAXPATHLEN) { + if (filename_length > (MAXPATHLEN - 2) || len > MAXPATHLEN || len + 1 + filename_length + 1 >= MAXPATHLEN) { break; } memcpy(trypath, ptr, len); @@ -624,7 +622,7 @@ PHPAPI FILE *php_fopen_with_path(const char *filename, const char *mode, const c char *pathbuf, *ptr, *end; char trypath[MAXPATHLEN]; FILE *fp; - int filename_length; + size_t filename_length; zend_string *exec_filename; if (opened_path) { @@ -635,7 +633,7 @@ PHPAPI FILE *php_fopen_with_path(const char *filename, const char *mode, const c return NULL; } - filename_length = (int)strlen(filename); + filename_length = strlen(filename); #ifndef PHP_WIN32 (void) filename_length; #endif @@ -761,14 +759,14 @@ PHPAPI char *expand_filepath_with_mode(const char *filepath, char *real_path, co { cwd_state new_state; char cwd[MAXPATHLEN]; - int copy_len; - int path_len; + size_t copy_len; + size_t path_len; if (!filepath[0]) { return NULL; } - path_len = (int)strlen(filepath); + path_len = strlen(filepath); if (IS_ABSOLUTE_PATH(filepath, path_len)) { cwd[0] = '\0'; @@ -811,7 +809,7 @@ PHPAPI char *expand_filepath_with_mode(const char *filepath, char *real_path, co } new_state.cwd = estrdup(cwd); - new_state.cwd_length = (int)strlen(cwd); + new_state.cwd_length = strlen(cwd); if (virtual_file_ex(&new_state, filepath, NULL, realpath_mode)) { efree(new_state.cwd); diff --git a/main/fopen_wrappers.h b/main/fopen_wrappers.h index b39be4a0db..bf5d8b2627 100644 --- a/main/fopen_wrappers.h +++ b/main/fopen_wrappers.h @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef FOPEN_WRAPPERS_H #define FOPEN_WRAPPERS_H @@ -39,7 +37,7 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path PHPAPI int php_check_safe_mode_include_dir(const char *path); -PHPAPI zend_string *php_resolve_path(const char *filename, int filename_len, const char *path); +PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_len, const char *path); PHPAPI FILE *php_fopen_with_path(const char *filename, const char *mode, const char *path, zend_string **opened_path); diff --git a/main/getopt.c b/main/getopt.c index f978169173..3af45e0e96 100644 --- a/main/getopt.c +++ b/main/getopt.c @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include <stdio.h> #include <string.h> #include <assert.h> diff --git a/main/http_status_codes.h b/main/http_status_codes.h index 03a1272996..8966b433e5 100644 --- a/main/http_status_codes.h +++ b/main/http_status_codes.h @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id: $ */ - #ifndef HTTP_STATUS_CODES_H #define HTTP_STATUS_CODES_H @@ -26,7 +24,7 @@ typedef struct _http_response_status_code_pair { const char *str; } http_response_status_code_pair; -static http_response_status_code_pair http_status_map[] = { +static const http_response_status_code_pair http_status_map[] = { { 100, "Continue" }, { 101, "Switching Protocols" }, { 200, "OK" }, diff --git a/main/internal_functions.c.in b/main/internal_functions.c.in index 2f93dc0a70..6592824baf 100644 --- a/main/internal_functions.c.in +++ b/main/internal_functions.c.in @@ -12,13 +12,11 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | + | Authors: Andi Gutmans <andi@php.net> | + | Zeev Suraski <zeev@php.net> | +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include "php.h" #include "php_main.h" #include "zend_modules.h" @@ -29,7 +27,7 @@ @EXT_INCLUDE_CODE@ -static zend_module_entry *php_builtin_extensions[] = { +static zend_module_entry * const php_builtin_extensions[] = { @EXT_MODULE_PTRS@ }; diff --git a/main/internal_functions_win32.c b/main/internal_functions_win32.c index b158cdce65..affbb39286 100644 --- a/main/internal_functions_win32.c +++ b/main/internal_functions_win32.c @@ -12,13 +12,11 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | + | Authors: Andi Gutmans <andi@php.net> | + | Zeev Suraski <zeev@php.net> | +----------------------------------------------------------------------+ */ -/* $Id$ */ - /* {{{ includes */ #include "php.h" @@ -111,7 +109,7 @@ /* {{{ php_builtin_extensions[] */ -static zend_module_entry *php_builtin_extensions[] = { +static zend_module_entry * const php_builtin_extensions[] = { phpext_standard_ptr #if HAVE_BCMATH ,phpext_bcmath_ptr diff --git a/main/main.c b/main/main.c index d68cb6eca4..ee422db52f 100644 --- a/main/main.c +++ b/main/main.c @@ -12,14 +12,12 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | + | Authors: Andi Gutmans <andi@php.net> | | Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - | Zeev Suraski <zeev@zend.com> | + | Zeev Suraski <zeev@php.net> | +----------------------------------------------------------------------+ */ -/* $Id$ */ - /* {{{ includes */ @@ -53,6 +51,7 @@ #include "php_ini.h" #include "php_globals.h" #include "php_main.h" +#include "php_syslog.h" #include "fopen_wrappers.h" #include "ext/standard/php_standard.h" #include "ext/standard/php_string.h" @@ -148,6 +147,143 @@ static char *get_safe_charset_hint(void) { /* {{{ PHP_INI_MH */ +static PHP_INI_MH(OnSetFacility) +{ + const char *facility = ZSTR_VAL(new_value); + +#ifdef LOG_AUTH + if (!strcmp(facility, "LOG_AUTH") || !strcmp(facility, "auth") || !strcmp(facility, "security")) { + PG(syslog_facility) = LOG_AUTH; + return SUCCESS; + } +#endif +#ifdef LOG_AUTHPRIV + if (!strcmp(facility, "LOG_AUTHPRIV") || !strcmp(facility, "authpriv")) { + PG(syslog_facility) = LOG_AUTHPRIV; + return SUCCESS; + } +#endif +#ifdef LOG_CRON + if (!strcmp(facility, "LOG_CRON") || !strcmp(facility, "cron")) { + PG(syslog_facility) = LOG_CRON; + return SUCCESS; + } +#endif +#ifdef LOG_DAEMON + if (!strcmp(facility, "LOG_DAEMON") || !strcmp(facility, "daemon")) { + PG(syslog_facility) = LOG_DAEMON; + return SUCCESS; + } +#endif +#ifdef LOG_FTP + if (!strcmp(facility, "LOG_FTP") || !strcmp(facility, "ftp")) { + PG(syslog_facility) = LOG_FTP; + return SUCCESS; + } +#endif +#ifdef LOG_KERN + if (!strcmp(facility, "LOG_KERN") || !strcmp(facility, "kern")) { + PG(syslog_facility) = LOG_KERN; + return SUCCESS; + } +#endif +#ifdef LOG_LPR + if (!strcmp(facility, "LOG_LPR") || !strcmp(facility, "lpr")) { + PG(syslog_facility) = LOG_LPR; + return SUCCESS; + } +#endif +#ifdef LOG_MAIL + if (!strcmp(facility, "LOG_MAIL") || !strcmp(facility, "mail")) { + PG(syslog_facility) = LOG_MAIL; + return SUCCESS; + } +#endif +#ifdef LOG_INTERNAL_MARK + if (!strcmp(facility, "LOG_INTERNAL_MARK") || !strcmp(facility, "mark")) { + PG(syslog_facility) = LOG_INTERNAL_MARK; + return SUCCESS; + } +#endif +#ifdef LOG_NEWS + if (!strcmp(facility, "LOG_NEWS") || !strcmp(facility, "news")) { + PG(syslog_facility) = LOG_NEWS; + return SUCCESS; + } +#endif +#ifdef LOG_SYSLOG + if (!strcmp(facility, "LOG_SYSLOG") || !strcmp(facility, "syslog")) { + PG(syslog_facility) = LOG_SYSLOG; + return SUCCESS; + } +#endif +#ifdef LOG_USER + if (!strcmp(facility, "LOG_USER") || !strcmp(facility, "user")) { + PG(syslog_facility) = LOG_USER; + return SUCCESS; + } +#endif +#ifdef LOG_UUCP + if (!strcmp(facility, "LOG_UUCP") || !strcmp(facility, "uucp")) { + PG(syslog_facility) = LOG_UUCP; + return SUCCESS; + } +#endif +#ifdef LOG_LOCAL0 + if (!strcmp(facility, "LOG_LOCAL0") || !strcmp(facility, "local0")) { + PG(syslog_facility) = LOG_LOCAL0; + return SUCCESS; + } +#endif +#ifdef LOG_LOCAL1 + if (!strcmp(facility, "LOG_LOCAL1") || !strcmp(facility, "local1")) { + PG(syslog_facility) = LOG_LOCAL1; + return SUCCESS; + } +#endif +#ifdef LOG_LOCAL2 + if (!strcmp(facility, "LOG_LOCAL2") || !strcmp(facility, "local2")) { + PG(syslog_facility) = LOG_LOCAL2; + return SUCCESS; + } +#endif +#ifdef LOG_LOCAL3 + if (!strcmp(facility, "LOG_LOCAL3") || !strcmp(facility, "local3")) { + PG(syslog_facility) = LOG_LOCAL3; + return SUCCESS; + } +#endif +#ifdef LOG_LOCAL4 + if (!strcmp(facility, "LOG_LOCAL4") || !strcmp(facility, "local4")) { + PG(syslog_facility) = LOG_LOCAL4; + return SUCCESS; + } +#endif +#ifdef LOG_LOCAL5 + if (!strcmp(facility, "LOG_LOCAL5") || !strcmp(facility, "local5")) { + PG(syslog_facility) = LOG_LOCAL5; + return SUCCESS; + } +#endif +#ifdef LOG_LOCAL6 + if (!strcmp(facility, "LOG_LOCAL6") || !strcmp(facility, "local6")) { + PG(syslog_facility) = LOG_LOCAL6; + return SUCCESS; + } +#endif +#ifdef LOG_LOCAL7 + if (!strcmp(facility, "LOG_LOCAL7") || !strcmp(facility, "local7")) { + PG(syslog_facility) = LOG_LOCAL7; + return SUCCESS; + } +#endif + + return FAILURE; +} +/* }}} */ + +/* {{{ PHP_INI_MH + */ static PHP_INI_MH(OnSetPrecision) { zend_long i; @@ -184,14 +320,36 @@ static PHP_INI_MH(OnSetSerializePrecision) static PHP_INI_MH(OnChangeMemoryLimit) { if (new_value) { - PG(memory_limit) = zend_atol(ZSTR_VAL(new_value), (int)ZSTR_LEN(new_value)); + PG(memory_limit) = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value)); } else { - PG(memory_limit) = 1<<30; /* effectively, no limit */ + PG(memory_limit) = Z_L(1)<<30; /* effectively, no limit */ } return zend_set_memory_limit(PG(memory_limit)); } /* }}} */ +/* {{{ PHP_INI_MH + */ +static PHP_INI_MH(OnSetLogFilter) +{ + const char *filter = ZSTR_VAL(new_value); + + if (!strcmp(filter, "all")) { + PG(syslog_filter) = PHP_SYSLOG_FILTER_ALL; + return SUCCESS; + } + if (!strcmp(filter, "no-ctrl")) { + PG(syslog_filter) = PHP_SYSLOG_FILTER_NO_CTRL; + return SUCCESS; + } + if (!strcmp(filter, "ascii")) { + PG(syslog_filter) = PHP_SYSLOG_FILTER_ASCII; + return SUCCESS; + } + + return FAILURE; +} +/* }}} */ /* {{{ php_disable_functions */ @@ -335,7 +493,7 @@ static PHP_INI_MH(OnUpdateTimeout) /* {{{ php_get_display_errors_mode() helper function */ -static int php_get_display_errors_mode(char *value, int value_length) +static int php_get_display_errors_mode(char *value, size_t value_length) { int mode; @@ -368,7 +526,7 @@ static int php_get_display_errors_mode(char *value, int value_length) */ static PHP_INI_MH(OnUpdateDisplayErrors) { - PG(display_errors) = (zend_bool) php_get_display_errors_mode(ZSTR_VAL(new_value), (int)ZSTR_LEN(new_value)); + PG(display_errors) = (zend_bool) php_get_display_errors_mode(ZSTR_VAL(new_value), ZSTR_LEN(new_value)); return SUCCESS; } @@ -378,15 +536,16 @@ static PHP_INI_MH(OnUpdateDisplayErrors) */ static PHP_INI_DISP(display_errors_mode) { - int mode, tmp_value_length, cgi_or_cli; + int mode, cgi_or_cli; + size_t tmp_value_length; char *tmp_value; if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) { tmp_value = (ini_entry->orig_value ? ZSTR_VAL(ini_entry->orig_value) : NULL ); - tmp_value_length = (int)(ini_entry->orig_value? ZSTR_LEN(ini_entry->orig_value) : 0); + tmp_value_length = (ini_entry->orig_value? ZSTR_LEN(ini_entry->orig_value) : 0); } else if (ini_entry->value) { tmp_value = ZSTR_VAL(ini_entry->value); - tmp_value_length = (int)ZSTR_LEN(ini_entry->value); + tmp_value_length = ZSTR_LEN(ini_entry->value); } else { tmp_value = NULL; tmp_value_length = 0; @@ -635,6 +794,9 @@ PHP_INI_BEGIN() #ifdef PHP_WIN32 STD_PHP_INI_BOOLEAN("windows.show_crt_warning", "0", PHP_INI_ALL, OnUpdateBool, windows_show_crt_warning, php_core_globals, core_globals) #endif + STD_PHP_INI_ENTRY("syslog.facility", "LOG_USER", PHP_INI_SYSTEM, OnSetFacility, syslog_facility, php_core_globals, core_globals) + STD_PHP_INI_ENTRY("syslog.ident", "php", PHP_INI_SYSTEM, OnUpdateString, syslog_ident, php_core_globals, core_globals) + STD_PHP_INI_ENTRY("syslog.filter", "no-ctrl", PHP_INI_ALL, OnSetLogFilter, syslog_filter, php_core_globals, core_globals) PHP_INI_END() /* }}} */ @@ -1006,10 +1168,10 @@ PHPAPI ZEND_COLD void php_win32_docref2_from_error(DWORD error, const char *para php_error_docref2(NULL, param1, param2, E_WARNING, "%s", strerror(errno)); } else { char buf[PHP_WIN32_ERROR_MSG_BUFFER_SIZE + 1]; - int buf_len; + size_t buf_len; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, buf, PHP_WIN32_ERROR_MSG_BUFFER_SIZE, NULL); - buf_len = (int)strlen(buf); + buf_len = strlen(buf); if (buf_len >= 2) { buf[buf_len - 1] = '\0'; buf[buf_len - 2] = '\0'; @@ -1052,29 +1214,8 @@ static ZEND_COLD void php_error_cb(int type, const char *error_filename, const u display = 1; } - /* store the error if it has changed */ - if (display) { - if (PG(last_error_message)) { - char *s = PG(last_error_message); - PG(last_error_message) = NULL; - free(s); - } - if (PG(last_error_file)) { - char *s = PG(last_error_file); - PG(last_error_file) = NULL; - free(s); - } - if (!error_filename) { - error_filename = "Unknown"; - } - PG(last_error_type) = type; - PG(last_error_message) = strdup(buffer); - PG(last_error_file) = strdup(error_filename); - PG(last_error_lineno) = error_lineno; - } - - /* according to error handling mode, suppress error, throw exception or show it */ - if (EG(error_handling) != EH_NORMAL) { + /* according to error handling mode, throw exception or show it */ + if (EG(error_handling) == EH_THROW) { switch (type) { case E_ERROR: case E_CORE_ERROR: @@ -1096,7 +1237,7 @@ static ZEND_COLD void php_error_cb(int type, const char *error_filename, const u /* throw an exception if we are in EH_THROW mode * but DO NOT overwrite a pending exception */ - if (EG(error_handling) == EH_THROW && !EG(exception)) { + if (!EG(exception)) { zend_throw_error_exception(EG(exception_class), buffer, 0, type); } efree(buffer); @@ -1104,6 +1245,27 @@ static ZEND_COLD void php_error_cb(int type, const char *error_filename, const u } } + /* store the error if it has changed */ + if (display) { + if (PG(last_error_message)) { + char *s = PG(last_error_message); + PG(last_error_message) = NULL; + free(s); + } + if (PG(last_error_file)) { + char *s = PG(last_error_file); + PG(last_error_file) = NULL; + free(s); + } + if (!error_filename) { + error_filename = "Unknown"; + } + PG(last_error_type) = type; + PG(last_error_message) = strdup(buffer); + PG(last_error_file) = strdup(error_filename); + PG(last_error_lineno) = error_lineno; + } + /* display/log the error if necessary */ if (display && (EG(error_reporting) & type || (type & E_CORE)) && (PG(log_errors) || PG(display_errors) || (!module_initialized))) { @@ -1159,14 +1321,14 @@ static ZEND_COLD void php_error_cb(int type, const char *error_filename, const u syslog(LOG_ALERT, "PHP %s: %s (%s)", error_type_str, buffer, GetCommandLine()); } #endif - spprintf(&log_buffer, 0, "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno); + spprintf(&log_buffer, 0, "PHP %s: %s in %s on line %" PRIu32, error_type_str, buffer, error_filename, error_lineno); php_log_err_with_severity(log_buffer, syslog_type_int); efree(log_buffer); } if (PG(display_errors) && ((module_initialized && !PG(during_request_startup)) || (PG(display_startup_errors)))) { if (PG(xmlrpc_errors)) { - php_printf("<?xml version=\"1.0\"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>" ZEND_LONG_FMT "</int></value></member><member><name>faultString</name><value><string>%s:%s in %s on line %d</string></value></member></struct></value></fault></methodResponse>", PG(xmlrpc_error_number), error_type_str, buffer, error_filename, error_lineno); + php_printf("<?xml version=\"1.0\"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>" ZEND_LONG_FMT "</int></value></member><member><name>faultString</name><value><string>%s:%s in %s on line %" PRIu32 "</string></value></member></struct></value></fault></methodResponse>", PG(xmlrpc_error_number), error_type_str, buffer, error_filename, error_lineno); } else { char *prepend_string = INI_STR("error_prepend_string"); char *append_string = INI_STR("error_append_string"); @@ -1174,22 +1336,22 @@ static ZEND_COLD void php_error_cb(int type, const char *error_filename, const u if (PG(html_errors)) { if (type == E_ERROR || type == E_PARSE) { zend_string *buf = php_escape_html_entities((unsigned char*)buffer, buffer_len, 0, ENT_COMPAT, get_safe_charset_hint()); - php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, ZSTR_VAL(buf), error_filename, error_lineno, STR_PRINT(append_string)); + php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%" PRIu32 "</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, ZSTR_VAL(buf), error_filename, error_lineno, STR_PRINT(append_string)); zend_string_free(buf); } else { - php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); + php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%" PRIu32 "</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); } } else { /* Write CLI/CGI errors to stderr if display_errors = "stderr" */ if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "phpdbg")) && PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR ) { - fprintf(stderr, "%s: %s in %s on line %u\n", error_type_str, buffer, error_filename, error_lineno); + fprintf(stderr, "%s: %s in %s on line %" PRIu32 "\n", error_type_str, buffer, error_filename, error_lineno); #ifdef PHP_WIN32 fflush(stderr); #endif } else { - php_printf("%s\n%s: %s in %s on line %d\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); + php_printf("%s\n%s: %s in %s on line %" PRIu32 "\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); } } } @@ -1209,7 +1371,7 @@ static ZEND_COLD void php_error_cb(int type, const char *error_filename, const u trigger_break=0; break; } - zend_output_debug_string(trigger_break, "%s(%d) : %s - %s", error_filename, error_lineno, error_type_str, buffer); + zend_output_debug_string(trigger_break, "%s(%" PRIu32 ") : %s - %s", error_filename, error_lineno, error_type_str, buffer); } #endif } @@ -1365,7 +1527,7 @@ PHP_FUNCTION(set_time_limit) } else { RETVAL_FALSE; } - zend_string_release(key); + zend_string_release_ex(key, 0); efree(new_timeout_str); } /* }}} */ @@ -1450,7 +1612,7 @@ PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *h } /* }}} */ -static zend_string *php_resolve_path_for_zend(const char *filename, int filename_len) /* {{{ */ +static zend_string *php_resolve_path_for_zend(const char *filename, size_t filename_len) /* {{{ */ { return php_resolve_path(filename, filename_len, PG(include_path)); } @@ -1506,17 +1668,17 @@ static ZEND_COLD void php_message_handler_for_zend(zend_long message, const void if (message==ZMSG_MEMORY_LEAK_DETECTED) { zend_leak_info *t = (zend_leak_info *) data; - snprintf(memory_leak_buf, 512, "%s(%d) : Freeing " ZEND_ADDR_FMT " (%zu bytes), script=%s\n", t->filename, t->lineno, (size_t)t->addr, t->size, SAFE_FILENAME(SG(request_info).path_translated)); + snprintf(memory_leak_buf, 512, "%s(%" PRIu32 ") : Freeing " ZEND_ADDR_FMT " (%zu bytes), script=%s\n", t->filename, t->lineno, (size_t)t->addr, t->size, SAFE_FILENAME(SG(request_info).path_translated)); if (t->orig_filename) { char relay_buf[512]; - snprintf(relay_buf, 512, "%s(%d) : Actual location (location was relayed)\n", t->orig_filename, t->orig_lineno); + snprintf(relay_buf, 512, "%s(%" PRIu32 ") : Actual location (location was relayed)\n", t->orig_filename, t->orig_lineno); strlcat(memory_leak_buf, relay_buf, sizeof(memory_leak_buf)); } } else { unsigned long leak_count = (zend_uintptr_t) data; - snprintf(memory_leak_buf, 512, "Last leak repeated %ld time%s\n", leak_count, (leak_count>1?"s":"")); + snprintf(memory_leak_buf, 512, "Last leak repeated %lu time%s\n", leak_count, (leak_count>1?"s":"")); } # if defined(PHP_WIN32) OutputDebugString(memory_leak_buf); @@ -1587,39 +1749,8 @@ static void sigchld_handler(int apar) /* }}} */ #endif -/* {{{ php_start_sapi() - */ -static int php_start_sapi(void) -{ - int retval = SUCCESS; - - if(!SG(sapi_started)) { - zend_try { - PG(during_request_startup) = 1; - - /* initialize global variables */ - PG(modules_activated) = 0; - PG(header_is_being_sent) = 0; - PG(connection_status) = PHP_CONNECTION_NORMAL; - - zend_activate(); - zend_set_timeout(EG(timeout_seconds), 1); - zend_activate_modules(); - PG(modules_activated)=1; - } zend_catch { - retval = FAILURE; - } zend_end_try(); - - SG(sapi_started) = 1; - } - return retval; -} - -/* }}} */ - /* {{{ php_request_startup */ -#ifndef APACHE_HOOKS int php_request_startup(void) { int retval = SUCCESS; @@ -1701,61 +1832,6 @@ int php_request_startup(void) return retval; } -# else -int php_request_startup(void) -{ - int retval = SUCCESS; - - zend_interned_strings_activate(); - -#if PHP_SIGCHILD - signal(SIGCHLD, sigchld_handler); -#endif - - if (php_start_sapi() == FAILURE) { - return FAILURE; - } - - php_output_activate(); - sapi_activate(); - php_hash_environment(); - - zend_try { - PG(during_request_startup) = 1; - if (PG(expose_php)) { - sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1); - } - } zend_catch { - retval = FAILURE; - } zend_end_try(); - - return retval; -} -# endif -/* }}} */ - -/* {{{ php_request_startup_for_hook - */ -int php_request_startup_for_hook(void) -{ - int retval = SUCCESS; - - zend_interned_strings_activate(); - -#if PHP_SIGCHLD - signal(SIGCHLD, sigchld_handler); -#endif - - if (php_start_sapi() == FAILURE) { - return FAILURE; - } - - php_output_activate(); - sapi_activate_headers_only(); - php_hash_environment(); - - return retval; -} /* }}} */ /* {{{ php_request_shutdown_for_exec @@ -1770,60 +1846,6 @@ void php_request_shutdown_for_exec(void *dummy) } /* }}} */ -/* {{{ php_request_shutdown_for_hook - */ -void php_request_shutdown_for_hook(void *dummy) -{ - - if (PG(modules_activated)) zend_try { - php_call_shutdown_functions(); - } zend_end_try(); - - if (PG(modules_activated)) { - zend_deactivate_modules(); - } - - if (PG(modules_activated)) { - php_free_shutdown_functions(); - } - - zend_try { - zend_unset_timeout(); - } zend_end_try(); - - zend_try { - int i; - - for (i = 0; i < NUM_TRACK_VARS; i++) { - zval_ptr_dtor(&PG(http_globals)[i]); - } - } zend_end_try(); - - zend_deactivate(); - - zend_try { - sapi_deactivate(); - } zend_end_try(); - - zend_try { - php_shutdown_stream_hashes(); - } zend_end_try(); - - zend_interned_strings_deactivate(); - - zend_try { - shutdown_memory_manager(CG(unclean_shutdown), 0); - } zend_end_try(); - -#ifdef ZEND_SIGNALS - zend_try { - zend_signal_deactivate(); - } zend_end_try(); -#endif -} - -/* }}} */ - /* {{{ php_request_shutdown */ void php_request_shutdown(void *dummy) @@ -2012,9 +2034,9 @@ PHP_MINFO_FUNCTION(php_core) { /* {{{ */ /* {{{ php_register_extensions */ -int php_register_extensions(zend_module_entry **ptr, int count) +int php_register_extensions(zend_module_entry * const * ptr, int count) { - zend_module_entry **end = ptr + count; + zend_module_entry * const * end = ptr + count; while (ptr < end) { if (*ptr) { @@ -2190,7 +2212,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod REGISTER_MAIN_LONG_CONSTANT("PHP_DEBUG", PHP_DEBUG, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS", php_os, strlen(php_os), CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS_FAMILY", PHP_OS_FAMILY, sizeof(PHP_OS_FAMILY)-1, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_STRINGL_CONSTANT("PHP_SAPI", sapi_module.name, strlen(sapi_module.name), CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_STRINGL_CONSTANT("PHP_SAPI", sapi_module.name, strlen(sapi_module.name), CONST_PERSISTENT | CONST_CS | CONST_NO_FILE_CACHE); REGISTER_MAIN_STRINGL_CONSTANT("DEFAULT_INCLUDE_PATH", PHP_INCLUDE_PATH, sizeof(PHP_INCLUDE_PATH)-1, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_STRINGL_CONSTANT("PEAR_INSTALL_DIR", PEAR_INSTALLDIR, sizeof(PEAR_INSTALLDIR)-1, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_STRINGL_CONSTANT("PEAR_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS); @@ -2234,9 +2256,9 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod php_binary_init(); if (PG(php_binary)) { - REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", PG(php_binary), strlen(PG(php_binary)), CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", PG(php_binary), strlen(PG(php_binary)), CONST_PERSISTENT | CONST_CS | CONST_NO_FILE_CACHE); } else { - REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", "", 0, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", "", 0, CONST_PERSISTENT | CONST_CS | CONST_NO_FILE_CACHE); } php_output_register_constants(); @@ -2274,6 +2296,8 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod CWDG(realpath_cache_size_limit) = 0; } + PG(have_called_openlog) = 0; + /* initialize stream wrappers registry * (this uses configuration parameters from php.ini) */ @@ -2332,7 +2356,9 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod module->info_func = PHP_MINFO(php_core); } - zend_post_startup(); + if (zend_post_startup() != SUCCESS) { + return FAILURE; + } module_initialized = 1; @@ -2407,7 +2433,11 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod shutdown_memory_manager(1, 0); virtual_cwd_activate(); - zend_interned_strings_switch_storage(); + zend_interned_strings_switch_storage(1); + +#if ZEND_RC_DEBUG + zend_rc_debug = 1; +#endif /* we're done */ return retval; @@ -2440,10 +2470,16 @@ void php_module_shutdown(void) return; } + zend_interned_strings_switch_storage(0); + #ifdef ZTS ts_free_worker_threads(); #endif +#if ZEND_RC_DEBUG + zend_rc_debug = 0; +#endif + #ifdef PHP_WIN32 (void)php_win32_shutdown_random_bytes(); #endif diff --git a/main/mergesort.c b/main/mergesort.c index a482f5b0fe..d187635367 100644 --- a/main/mergesort.c +++ b/main/mergesort.c @@ -34,8 +34,6 @@ * SUCH DAMAGE. */ -/* $Id$ */ - #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)merge.c 8.2 (Berkeley) 2/14/94"; #endif /* LIBC_SCCS and not lint */ diff --git a/main/network.c b/main/network.c index 13964e34f8..7eccb36047 100644 --- a/main/network.c +++ b/main/network.c @@ -17,8 +17,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - /*#define DEBUG_MAIN_NETWORK 1*/ #include "php.h" @@ -271,22 +269,19 @@ PHPAPI int php_network_getaddresses(const char *host, int socktype, struct socka #define O_NONBLOCK O_NDELAY #endif -#if !defined(__BEOS__) -# define HAVE_NON_BLOCKING_CONNECT 1 -# ifdef PHP_WIN32 +#ifdef PHP_WIN32 typedef u_long php_non_blocking_flags_t; # define SET_SOCKET_BLOCKING_MODE(sock, save) \ save = TRUE; ioctlsocket(sock, FIONBIO, &save) # define RESTORE_SOCKET_BLOCKING_MODE(sock, save) \ ioctlsocket(sock, FIONBIO, &save) -# else +#else typedef int php_non_blocking_flags_t; # define SET_SOCKET_BLOCKING_MODE(sock, save) \ save = fcntl(sock, F_GETFL, 0); \ fcntl(sock, F_SETFL, save | O_NONBLOCK) # define RESTORE_SOCKET_BLOCKING_MODE(sock, save) \ fcntl(sock, F_SETFL, save) -# endif #endif /* Connect to a socket using an interruptible connect with optional timeout. @@ -302,7 +297,6 @@ PHPAPI int php_network_connect_socket(php_socket_t sockfd, zend_string **error_string, int *error_code) { -#if HAVE_NON_BLOCKING_CONNECT php_non_blocking_flags_t orig_flags; int n; int error = 0; @@ -380,12 +374,6 @@ ok: } } return ret; -#else - if (asynchronous) { - php_error_docref(NULL, E_WARNING, "Asynchronous connect() not supported on this platform"); - } - return (connect(sockfd, addr, addrlen) == 0) ? 0 : -1; -#endif } /* }}} */ @@ -568,7 +556,7 @@ PHPAPI int php_network_parse_network_address_with_port(const char *addr, zend_lo if (n == 0) { if (errstr) { php_error_docref(NULL, E_WARNING, "Failed to resolve `%s': %s", tmp, ZSTR_VAL(errstr)); - zend_string_release(errstr); + zend_string_release_ex(errstr, 0); } goto out; } @@ -636,7 +624,7 @@ PHPAPI void php_network_populate_name_from_sockaddr( case AF_INET6: buf = (char*)inet_ntop(sa->sa_family, &((struct sockaddr_in6*)sa)->sin6_addr, (char *)&abuf, sizeof(abuf)); if (buf) { - *textaddr = strpprintf(0, "%s:%d", + *textaddr = strpprintf(0, "[%s]:%d", buf, ntohs(((struct sockaddr_in6*)sa)->sin6_port)); } @@ -893,7 +881,7 @@ skip_bind: } /* free error string received during previous iteration (if any) */ if (error_string && *error_string) { - zend_string_release(*error_string); + zend_string_release_ex(*error_string, 0); *error_string = NULL; } diff --git a/main/output.c b/main/output.c index 0ef41c10a7..631c08178b 100644 --- a/main/output.c +++ b/main/output.c @@ -12,15 +12,13 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Authors: Zeev Suraski <zeev@zend.com> | + | Authors: Zeev Suraski <zeev@php.net> | | Thies C. Arntzen <thies@thieso.net> | | Marcus Boerger <helly@php.net> | | New API: Michael Wallner <mike@php.net> | +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef PHP_OUTPUT_DEBUG # define PHP_OUTPUT_DEBUG 0 #endif @@ -504,7 +502,7 @@ PHPAPI php_output_handler *php_output_handler_create_user(zval *output_handler, efree(error); } if (handler_name) { - zend_string_release(handler_name); + zend_string_release_ex(handler_name, 0); } } @@ -521,7 +519,7 @@ PHPAPI php_output_handler *php_output_handler_create_internal(const char *name, handler = php_output_handler_init(str, chunk_size, (flags & ~0xf) | PHP_OUTPUT_HANDLER_INTERNAL); handler->func.internal = output_handler; - zend_string_release(str); + zend_string_release_ex(str, 0); return handler; } @@ -609,11 +607,16 @@ PHPAPI int php_output_handler_conflict(const char *handler_new, size_t handler_n * Register a conflict checking function on MINIT */ PHPAPI int php_output_handler_conflict_register(const char *name, size_t name_len, php_output_handler_conflict_check_t check_func) { + zend_string *str; + if (!EG(current_module)) { zend_error(E_ERROR, "Cannot register an output handler conflict outside of MINIT"); return FAILURE; } - return zend_hash_str_update_ptr(&php_output_handler_conflicts, name, name_len, check_func) ? SUCCESS : FAILURE; + str = zend_string_init_interned(name, name_len, 1); + zend_hash_update_ptr(&php_output_handler_conflicts, str, check_func); + zend_string_release_ex(str, 1); + return SUCCESS; } /* }}} */ @@ -631,15 +634,16 @@ PHPAPI int php_output_handler_reverse_conflict_register(const char *name, size_t if (NULL != (rev_ptr = zend_hash_str_find_ptr(&php_output_handler_reverse_conflicts, name, name_len))) { return zend_hash_next_index_insert_ptr(rev_ptr, check_func) ? SUCCESS : FAILURE; } else { + zend_string *str; + zend_hash_init(&rev, 8, NULL, NULL, 1); if (NULL == zend_hash_next_index_insert_ptr(&rev, check_func)) { zend_hash_destroy(&rev); return FAILURE; } - if (NULL == zend_hash_str_update_mem(&php_output_handler_reverse_conflicts, name, name_len+1, &rev, sizeof(HashTable))) { - zend_hash_destroy(&rev); - return FAILURE; - } + str = zend_string_init_interned(name, name_len, 1); + zend_hash_update_mem(&php_output_handler_reverse_conflicts, str, &rev, sizeof(HashTable)); + zend_string_release_ex(str, 1); return SUCCESS; } } @@ -657,11 +661,16 @@ PHPAPI php_output_handler_alias_ctor_t php_output_handler_alias(const char *name * Registers an internal output handler as alias for a user handler */ PHPAPI int php_output_handler_alias_register(const char *name, size_t name_len, php_output_handler_alias_ctor_t func) { + zend_string *str; + if (!EG(current_module)) { zend_error(E_ERROR, "Cannot register an output handler alias outside of MINIT"); return FAILURE; } - return zend_hash_str_update_ptr(&php_output_handler_aliases, name, name_len, func) ? SUCCESS : FAILURE; + str = zend_string_init_interned(name, name_len, 1); + zend_hash_update_ptr(&php_output_handler_aliases, str, func); + zend_string_release_ex(str, 1); + return SUCCESS; } /* }}} */ @@ -699,7 +708,7 @@ PHPAPI int php_output_handler_hook(php_output_handler_hook_t type, void *arg) PHPAPI void php_output_handler_dtor(php_output_handler *handler) { if (handler->name) { - zend_string_release(handler->name); + zend_string_release_ex(handler->name, 0); } if (handler->buffer.data) { efree(handler->buffer.data); @@ -1298,7 +1307,7 @@ PHP_FUNCTION(ob_start) zend_long chunk_size = 0; zend_long flags = PHP_OUTPUT_HANDLER_STDFLAGS; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z/ll", &output_handler, &chunk_size, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|zll", &output_handler, &chunk_size, &flags) == FAILURE) { return; } @@ -1532,6 +1541,10 @@ PHP_FUNCTION(ob_implicit_flush) Reset(clear) URL rewriter values */ PHP_FUNCTION(output_reset_rewrite_vars) { + if (zend_parse_parameters_none() == FAILURE) { + return; + } + if (php_url_scanner_reset_vars() == SUCCESS) { RETURN_TRUE; } else { diff --git a/main/php.h b/main/php.h index 3b0b896563..0b5a904b2c 100644 --- a/main/php.h +++ b/main/php.h @@ -12,13 +12,11 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | + | Authors: Andi Gutmans <andi@php.net> | + | Zeev Suraski <zeev@php.net> | +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef PHP_H #define PHP_H @@ -26,7 +24,7 @@ #include <dmalloc.h> #endif -#define PHP_API_VERSION 20170718 +#define PHP_API_VERSION 20180731 #define PHP_HAVE_STREAMS #define YYDEBUG 0 #define PHP_DEFAULT_CHARSET "UTF-8" @@ -41,7 +39,7 @@ #undef sprintf #define sprintf php_sprintf -/* Operating system family defintion */ +/* Operating system family definition */ #ifdef PHP_WIN32 # define PHP_OS_FAMILY "Windows" #elif defined(BSD) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) @@ -101,9 +99,7 @@ typedef int gid_t; typedef char * caddr_t; typedef unsigned int uint; typedef unsigned long ulong; -# if !NSAPI typedef int pid_t; -# endif # ifndef PHP_DEBUG # ifdef inline diff --git a/main/php_compat.h b/main/php_compat.h index d9e4718bd5..fe3b87f7d9 100644 --- a/main/php_compat.h +++ b/main/php_compat.h @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef PHP_COMPAT_H #define PHP_COMPAT_H @@ -28,69 +26,75 @@ #endif #if defined(HAVE_BUNDLED_PCRE) || !defined(PHP_VERSION) -#define pcre_compile php_pcre_compile -#define pcre_compile2 php_pcre_compile2 -#define pcre_copy_substring php_pcre_copy_substring -#define pcre_exec php_pcre_exec -#define pcre_get_substring php_pcre_get_substring -#define pcre_get_substring_list php_pcre_get_substring_list -#define pcre_maketables php_pcre_maketables -#define pcre_study php_pcre_study -#define pcre_version php_pcre_version -#define pcre_fullinfo php_pcre_fullinfo -#define pcre_free php_pcre_free -#define pcre_malloc php_pcre_malloc -#define pcre_config php_pcre_config -#define pcre_copy_named_substring php_pcre_copy_named_substring -#define pcre_free_substring php_pcre_free_substring -#define pcre_free_substring_list php_pcre_free_substring_list -#define pcre_get_named_substring php_pcre_get_named_substring -#define pcre_get_stringnumber php_pcre_get_stringnumber -#define pcre_refcount php_pcre_refcount -#define _pcre_ord2utf8 php__pcre_ord2utf8 -#define _pcre_try_flipped php__pcre_try_flipped -#define _pcre_valid_utf8 php__pcre_valid_utf8 -#define _pcre_xclass php__pcre_xclass -#define pcre_callout php_pcre_callout -#define _pcre_OP_lengths php__pcre_OP_lengths -#define _pcre_utt_names php__pcre_utt_names -#define _pcre_default_tables php__pcre_default_tables -#define pcre_get_stringtable_entries php_pcre_get_stringtable_entries -#define _pcre_is_newline php__pcre_is_newline -#define pcre_stack_free php_pcre_stack_free -#define pcre_stack_malloc php_pcre_stack_malloc -#define _pcre_utf8_table1 php__pcre_utf8_table1 -#define _pcre_utf8_table1_size php__pcre_utf8_table1_size -#define _pcre_utf8_table2 php__pcre_utf8_table2 -#define _pcre_utf8_table3 php__pcre_utf8_table3 -#define _pcre_utf8_table4 php__pcre_utf8_table4 -#define _pcre_utt php__pcre_utt -#define _pcre_utt_size php__pcre_utt_size -#define _pcre_was_newline php__pcre_was_newline -#define _pcre_ucd_records php__pcre_ucd_records -#define _pcre_ucd_stage1 php__pcre_ucd_stage1 -#define _pcre_ucd_stage2 php__pcre_ucd_stage2 -#define _pcre_ucp_gentype php__pcre_ucp_gentype -#define pcre_free_study php_pcre_free_study -#define pcre_assign_jit_stack php_pcre_assign_jit_stack -#define pcre_stack_guard php_pcre_stack_guard -#define pcre_jit_stack_alloc php_pcre_jit_stack_alloc -#define pcre_jit_stack_free php_pcre_jit_stack_free -#define pcre_jit_exec php_pcre_jit_exec -#define pcre_jit_free_unused_memory php_pcre_jit_free_unused_memory -#define _pcre_jit_exec php__pcre_jit_exec -#define _pcre_jit_compile php__pcre_jit_compile -#define _pcre_jit_get_size php__pcre_jit_get_size -#define _pcre_jit_get_target php__pcre_jit_get_target -#define _pcre_jit_free php__pcre_jit_free -#define _pcre_ucp_typerange php__pcre_ucp_typerange -#define _pcre_ucd_caseless_sets php__pcre_ucd_caseless_sets -#define _pcre_find_bracket php__pcre_find_bracket -#define _pcre_hspace_list php__pcre_hspace_list -#define _pcre_ord2utf php__pcre_ord2utf -#define _pcre_ucp_gbtable php__pcre_ucp_gbtable -#define _pcre_valid_utf php__pcre_valid_utf -#define _pcre_vspace_list php__pcre_vspace_list +#define pcre2_jit_callback_8 php_pcre2_jit_callback +#define pcre2_callout_enumerate_8 php_pcre2_callout_enumerate +#define pcre2_code_copy_8 php_pcre2_code_copy +#define pcre2_code_copy_with_tables_8 php_pcre2_code_copy_with_tables +#define pcre2_code_free_8 php_pcre2_code_free +#define pcre2_compile_8 php_pcre2_compile +#define pcre2_compile_context_copy_8 php_pcre2_compile_context_copy +#define pcre2_compile_context_create_8 php_pcre2_compile_context_create +#define pcre2_compile_context_free_8 php_pcre2_compile_context_free +#define pcre2_config_8 php_pcre2_config +#define pcre2_convert_context_copy_8 php_pcre2_convert_context_copy +#define pcre2_convert_context_create_8 php_pcre2_convert_context_create +#define pcre2_convert_context_free_8 php_pcre2_convert_context_free +#define pcre2_dfa_match_8 php_pcre2_dfa_match +#define pcre2_general_context_copy_8 php_pcre2_general_context_copy +#define pcre2_general_context_create_8 php_pcre2_general_context_create +#define pcre2_general_context_free_8 php_pcre2_general_context_free +#define pcre2_get_error_message_8 php_pcre2_get_error_message +#define pcre2_get_mark_8 php_pcre2_get_mark +#define pcre2_get_ovector_pointer_8 php_pcre2_get_ovector_pointer +#define pcre2_get_ovector_count_8 php_pcre2_get_ovector_count +#define pcre2_get_startchar_8 php_pcre2_get_startchar +#define pcre2_jit_compile_8 php_pcre2_jit_compile +#define pcre2_jit_match_8 php_pcre2_jit_match +#define pcre2_jit_free_unused_memory_8 php_pcre2_jit_free_unused_memory +#define pcre2_jit_stack_assign_8 php_pcre2_jit_stack_assign +#define pcre2_jit_stack_create_8 php_pcre2_jit_stack_create +#define pcre2_jit_stack_free_8 php_pcre2_jit_stack_free +#define pcre2_maketables_8 php_pcre2_maketables +#define pcre2_match_8 php_pcre2_match +#define pcre2_match_context_copy_8 php_pcre2_match_context_copy +#define pcre2_match_context_create_8 php_pcre2_match_context_create +#define pcre2_match_context_free_8 php_pcre2_match_context_free +#define pcre2_match_data_create_8 php_pcre2_match_data_create +#define pcre2_match_data_create_from_pattern_8 php_pcre2_match_data_create_from_pattern +#define pcre2_match_data_free_8 php_pcre2_match_data_free +#define pcre2_pattern_info_8 php_pcre2_pattern_info +#define pcre2_serialize_decode_8 php_pcre2_serialize_decode +#define pcre2_serialize_encode_8 php_pcre2_serialize_encode +#define pcre2_serialize_free_8 php_pcre2_serialize_free +#define pcre2_serialize_get_number_of_codes_8 php_pcre2_serialize_get_number_of_codes +#define pcre2_set_bsr_8 php_pcre2_set_bsr +#define pcre2_set_callout_8 php_pcre2_set_callout +#define pcre2_set_character_tables_8 php_pcre2_set_character_tables +#define pcre2_set_compile_extra_options_8 php_pcre2_set_compile_extra_options +#define pcre2_set_compile_recursion_guard_8 php_pcre2_set_compile_recursion_guard +#define pcre2_set_depth_limit_8 php_pcre2_set_depth_limit +#define pcre2_set_glob_escape_8 php_pcre2_set_glob_escape +#define pcre2_set_glob_separator_8 php_pcre2_set_glob_separator +#define pcre2_set_heap_limit_8 php_pcre2_set_heap_limit +#define pcre2_set_match_limit_8 php_pcre2_set_match_limit +#define pcre2_set_max_pattern_length_8 php_pcre2_set_max_pattern_length +#define pcre2_set_newline_8 php_pcre2_set_newline +#define pcre2_set_parens_nest_limit_8 php_pcre2_set_parens_nest_limit +#define pcre2_set_offset_limit_8 php_pcre2_set_offset_limit +#define pcre2_substitute_8 php_pcre2_substitute +#define pcre2_substring_copy_byname_8 php_pcre2_substring_copy_byname +#define pcre2_substring_copy_bynumber_8 php_pcre2_substring_copy_bynumber +#define pcre2_substring_free_8 php_pcre2_substring_free +#define pcre2_substring_get_byname_8 php_pcre2_substring_get_byname +#define pcre2_substring_get_bynumber_8 php_pcre2_substring_get_bynumber +#define pcre2_substring_length_byname_8 php_pcre2_substring_length_byname +#define pcre2_substring_length_bynumber_8 php_pcre2_substring_length_bynumber +#define pcre2_substring_list_get_8 php_pcre2_substring_list_get +#define pcre2_substring_list_free_8 php_pcre2_substring_list_free +#define pcre2_substring_nametable_scan_8 php_pcre2_substring_nametable_scan +#define pcre2_substring_number_from_name_8 php_pcre2_substring_number_from_name +#define pcre2_set_recursion_limit_8 php_pcre2_set_recursion_limit +#define pcre2_set_recursion_memory_management_8 php_pcre2_set_recursion_memory_management #endif #define lookup php_lookup diff --git a/main/php_content_types.c b/main/php_content_types.c index 5a59ee6f83..5f2faa9886 100644 --- a/main/php_content_types.c +++ b/main/php_content_types.c @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include "php.h" #include "SAPI.h" #include "rfc1867.h" @@ -26,7 +24,7 @@ /* {{{ php_post_entries[] */ -static sapi_post_entry php_post_entries[] = { +static const sapi_post_entry php_post_entries[] = { { DEFAULT_POST_CONTENT_TYPE, sizeof(DEFAULT_POST_CONTENT_TYPE)-1, sapi_read_standard_form_data, php_std_post_handler }, { MULTIPART_CONTENT_TYPE, sizeof(MULTIPART_CONTENT_TYPE)-1, NULL, rfc1867_post_handler }, { NULL, 0, NULL, NULL } diff --git a/main/php_content_types.h b/main/php_content_types.h index 8e70c2b151..d907d84d9d 100644 --- a/main/php_content_types.h +++ b/main/php_content_types.h @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef PHP_CONTENT_TYPES_H #define PHP_CONTENT_TYPES_H diff --git a/main/php_getopt.h b/main/php_getopt.h index 120f8c0409..a8b2f89b4c 100644 --- a/main/php_getopt.h +++ b/main/php_getopt.h @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef PHP_GETOPT_H #define PHP_GETOPT_H diff --git a/main/php_globals.h b/main/php_globals.h index 5b499cad65..077fa1f4bb 100644 --- a/main/php_globals.h +++ b/main/php_globals.h @@ -12,12 +12,10 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Author: Zeev Suraski <zeev@zend.com> | + | Author: Zeev Suraski <zeev@php.net> | +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef PHP_GLOBALS_H #define PHP_GLOBALS_H @@ -106,12 +104,7 @@ struct _php_core_globals { HashTable rfc1867_protected_variables; short connection_status; - - /* In 7.1/7.2 branches, this was initially a short, - * maintain struct alignment with subsequent padding. - */ zend_bool ignore_user_abort; - char ignore_user_abort_reserved_padding; unsigned char header_is_being_sent; @@ -171,6 +164,11 @@ struct _php_core_globals { #ifdef PHP_WIN32 zend_bool windows_show_crt_warning; #endif + + zend_long syslog_facility; + char *syslog_ident; + zend_bool have_called_openlog; + zend_long syslog_filter; }; diff --git a/main/php_ini.c b/main/php_ini.c index fca263e5f0..d5d920a807 100644 --- a/main/php_ini.c +++ b/main/php_ini.c @@ -12,12 +12,10 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Author: Zeev Suraski <zeev@zend.com> | + | Author: Zeev Suraski <zeev@php.net> | +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include "php.h" #include "ext/standard/info.h" #include "zend_ini.h" @@ -196,7 +194,7 @@ PHPAPI void config_zval_dtor(zval *zvalue) zend_hash_destroy(Z_ARRVAL_P(zvalue)); free(Z_ARR_P(zvalue)); } else if (Z_TYPE_P(zvalue) == IS_STRING) { - zend_string_release(Z_STR_P(zvalue)); + zend_string_release_ex(Z_STR_P(zvalue), 1); } } /* Reset / free active_ini_sectin global */ @@ -637,7 +635,7 @@ int php_init_config(void) ZVAL_NEW_STR(&tmp, zend_string_init(fh.filename, strlen(fh.filename), 1)); zend_hash_str_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path")-1, &tmp); if (opened_path) { - zend_string_release(opened_path); + zend_string_release_ex(opened_path, 0); } else { efree((char *)fh.filename); } diff --git a/main/php_ini.h b/main/php_ini.h index cfa1cdc1fc..57a6427ab6 100644 --- a/main/php_ini.h +++ b/main/php_ini.h @@ -12,12 +12,10 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Author: Zeev Suraski <zeev@zend.com> | + | Author: Zeev Suraski <zeev@php.net> | +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef PHP_INI_H #define PHP_INI_H diff --git a/main/php_main.h b/main/php_main.h index 618136f3a3..82d6e0fe18 100644 --- a/main/php_main.h +++ b/main/php_main.h @@ -12,13 +12,11 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | + | Authors: Andi Gutmans <andi@php.net> | + | Zeev Suraski <zeev@php.net> | +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef PHP_MAIN_H #define PHP_MAIN_H @@ -34,10 +32,8 @@ PHPAPI int php_module_startup(sapi_module_struct *sf, zend_module_entry *additio PHPAPI void php_module_shutdown(void); PHPAPI void php_module_shutdown_for_exec(void); PHPAPI int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals); -PHPAPI int php_request_startup_for_hook(void); -PHPAPI void php_request_shutdown_for_hook(void *dummy); -PHPAPI int php_register_extensions(zend_module_entry **ptr, int count); +PHPAPI int php_register_extensions(zend_module_entry * const * ptr, int count); PHPAPI int php_execute_script(zend_file_handle *primary_file); PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval *ret); diff --git a/main/php_memory_streams.h b/main/php_memory_streams.h index 393572a988..4de8288dd5 100644 --- a/main/php_memory_streams.h +++ b/main/php_memory_streams.h @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef PHP_MEMORY_STREAM_H #define PHP_MEMORY_STREAM_H @@ -25,9 +23,10 @@ #define PHP_STREAM_MAX_MEM 2 * 1024 * 1024 -#define TEMP_STREAM_DEFAULT 0 -#define TEMP_STREAM_READONLY 1 -#define TEMP_STREAM_TAKE_BUFFER 2 +#define TEMP_STREAM_DEFAULT 0x0 +#define TEMP_STREAM_READONLY 0x1 +#define TEMP_STREAM_TAKE_BUFFER 0x2 +#define TEMP_STREAM_APPEND 0x4 #define php_stream_memory_create(mode) _php_stream_memory_create((mode) STREAMS_CC) #define php_stream_memory_create_rel(mode) _php_stream_memory_create((mode) STREAMS_REL_CC) @@ -41,6 +40,7 @@ #define php_stream_temp_open(mode, max_memory_usage, buf, length) _php_stream_temp_open((mode), (max_memory_usage), (buf), (length) STREAMS_CC) BEGIN_EXTERN_C() + PHPAPI php_stream *_php_stream_memory_create(int mode STREAMS_DC); PHPAPI php_stream *_php_stream_memory_open(int mode, char *buf, size_t length STREAMS_DC); PHPAPI char *_php_stream_memory_get_buffer(php_stream *stream, size_t *length STREAMS_DC); @@ -48,12 +48,16 @@ PHPAPI char *_php_stream_memory_get_buffer(php_stream *stream, size_t *length ST PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STREAMS_DC); PHPAPI php_stream *_php_stream_temp_create_ex(int mode, size_t max_memory_usage, const char *tmpdir STREAMS_DC); PHPAPI php_stream *_php_stream_temp_open(int mode, size_t max_memory_usage, char *buf, size_t length STREAMS_DC); + +PHPAPI int php_stream_mode_from_str(const char *mode); +PHPAPI const char *_php_stream_mode_to_str(int mode); + END_EXTERN_C() -extern PHPAPI php_stream_ops php_stream_memory_ops; -extern PHPAPI php_stream_ops php_stream_temp_ops; -extern PHPAPI php_stream_ops php_stream_rfc2397_ops; -extern PHPAPI php_stream_wrapper php_stream_rfc2397_wrapper; +extern PHPAPI const php_stream_ops php_stream_memory_ops; +extern PHPAPI const php_stream_ops php_stream_temp_ops; +extern PHPAPI const php_stream_ops php_stream_rfc2397_ops; +extern PHPAPI const php_stream_wrapper php_stream_rfc2397_wrapper; #define PHP_STREAM_IS_MEMORY &php_stream_memory_ops #define PHP_STREAM_IS_TEMP &php_stream_temp_ops diff --git a/main/php_network.h b/main/php_network.h index 9dbb319221..4d6b18f43a 100644 --- a/main/php_network.h +++ b/main/php_network.h @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef _PHP_NETWORK_H #define _PHP_NETWORK_H @@ -299,8 +297,8 @@ struct _php_netstream_data_t { size_t ownsize; }; typedef struct _php_netstream_data_t php_netstream_data_t; -PHPAPI extern php_stream_ops php_stream_socket_ops; -extern php_stream_ops php_stream_generic_socket_ops; +PHPAPI extern const php_stream_ops php_stream_socket_ops; +extern const php_stream_ops php_stream_generic_socket_ops; #define PHP_STREAM_IS_SOCKET (&php_stream_socket_ops) BEGIN_EXTERN_C() diff --git a/main/php_open_temporary_file.c b/main/php_open_temporary_file.c index 8961692c24..448c0c19a1 100644 --- a/main/php_open_temporary_file.c +++ b/main/php_open_temporary_file.c @@ -12,12 +12,10 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Author: Zeev Suraski <zeev@zend.com> | + | Author: Zeev Suraski <zeev@php.net> | +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include "php.h" #include "php_open_temporary_file.h" @@ -125,7 +123,7 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, zend_st } new_state.cwd = estrdup(cwd); - new_state.cwd_length = (int)strlen(cwd); + new_state.cwd_length = strlen(cwd); if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH)) { efree(new_state.cwd); @@ -216,7 +214,7 @@ PHPAPI const char* php_get_temporary_directory(void) { char *sys_temp_dir = PG(sys_temp_dir); if (sys_temp_dir) { - int len = (int)strlen(sys_temp_dir); + size_t len = strlen(sys_temp_dir); if (len >= 2 && sys_temp_dir[len - 1] == DEFAULT_SLASH) { PG(php_sys_temp_dir) = estrndup(sys_temp_dir, len - 1); return PG(php_sys_temp_dir); @@ -237,7 +235,10 @@ PHPAPI const char* php_get_temporary_directory(void) wchar_t sTemp[MAXPATHLEN]; char *tmp; size_t len = GetTempPathW(MAXPATHLEN, sTemp); - assert(0 < len); /* should *never* fail! */ + + if (!len) { + return NULL; + } if (NULL == (tmp = php_win32_ioutil_conv_w_to_any(sTemp, len, &len))) { return NULL; @@ -253,7 +254,7 @@ PHPAPI const char* php_get_temporary_directory(void) { char* s = getenv("TMPDIR"); if (s && *s) { - int len = strlen(s); + size_t len = strlen(s); if (s[len - 1] == DEFAULT_SLASH) { PG(php_sys_temp_dir) = estrndup(s, len - 1); diff --git a/main/php_open_temporary_file.h b/main/php_open_temporary_file.h index a7d6b83309..8d7c14cdd1 100644 --- a/main/php_open_temporary_file.h +++ b/main/php_open_temporary_file.h @@ -12,12 +12,10 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Author: Zeev Suraski <zeev@zend.com> | + | Author: Zeev Suraski <zeev@php.net> | +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef PHP_OPEN_TEMPORARY_FILE_H #define PHP_OPEN_TEMPORARY_FILE_H diff --git a/main/php_output.h b/main/php_output.h index 70035de21a..a7384a6216 100644 --- a/main/php_output.h +++ b/main/php_output.h @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef PHP_OUTPUT_H #define PHP_OUTPUT_H diff --git a/main/php_reentrancy.h b/main/php_reentrancy.h index 5812ba8128..c4d6a61e2a 100644 --- a/main/php_reentrancy.h +++ b/main/php_reentrancy.h @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef PHP_REENTRANCY_H #define PHP_REENTRANCY_H @@ -91,7 +89,7 @@ char *asctime_r(const struct tm *tm, char *buf); #endif -#if !defined(HAVE_GMTIME_R) && defined(HAVE_GMTIME) || defined(__BEOS__) +#if !defined(HAVE_GMTIME_R) && defined(HAVE_GMTIME) #define PHP_NEED_REENTRANCY 1 PHPAPI struct tm *php_gmtime_r(const time_t *const timep, struct tm *p_tm); #else diff --git a/main/php_scandir.c b/main/php_scandir.c index 94d4b28b2c..76628528a4 100644 --- a/main/php_scandir.c +++ b/main/php_scandir.c @@ -17,8 +17,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include "php.h" #include "php_scandir.h" @@ -73,7 +71,7 @@ PHPAPI int php_scandir(const char *dirname, struct dirent **namelist[], int (*se } while (!php_readdir_r(dirp, (struct dirent *)entry, &dp) && dp) { - int dsize = 0; + size_t dsize = 0; struct dirent *newdp = NULL; if (selector && (*selector)(dp) == 0) { @@ -95,7 +93,7 @@ PHPAPI int php_scandir(const char *dirname, struct dirent **namelist[], int (*se vector = newv; } - dsize = sizeof (struct dirent) + (((int)strlen(dp->d_name) + 1) * sizeof(char)); + dsize = sizeof (struct dirent) + ((strlen(dp->d_name) + 1) * sizeof(char)); newdp = (struct dirent *) malloc(dsize); if (newdp == NULL) { diff --git a/main/php_scandir.h b/main/php_scandir.h index aac67bcc76..ce31bc200c 100644 --- a/main/php_scandir.h +++ b/main/php_scandir.h @@ -17,8 +17,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef PHP_SCANDIR_H #define PHP_SCANDIR_H diff --git a/main/php_sprintf.c b/main/php_sprintf.c index b104fb3486..2581e4575d 100644 --- a/main/php_sprintf.c +++ b/main/php_sprintf.c @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include <stdio.h> #include <stdarg.h> #include "php.h" diff --git a/main/php_stdint.h b/main/php_stdint.h index bb6b1e63b9..811725acef 100644 --- a/main/php_stdint.h +++ b/main/php_stdint.h @@ -36,6 +36,9 @@ # ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS # endif +# ifndef __STDC_FORMAT_MACROS +# define __STDC_FORMAT_MACROS +# endif #endif #if defined(_MSC_VER) diff --git a/main/php_streams.h b/main/php_streams.h index 9a5812a909..a5e89bf96a 100644 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef PHP_STREAMS_H #define PHP_STREAMS_H @@ -161,7 +159,7 @@ typedef struct _php_stream_wrapper_ops { } php_stream_wrapper_ops; struct _php_stream_wrapper { - php_stream_wrapper_ops *wops; /* operations the wrapper can perform */ + const php_stream_wrapper_ops *wops; /* operations the wrapper can perform */ void *abstract; /* context for the wrapper */ int is_url; /* so that PG(allow_url_fopen) can be respected */ }; @@ -188,7 +186,7 @@ struct _php_stream_wrapper { #define PHP_STREAM_FLAG_WAS_WRITTEN 0x80000000 struct _php_stream { - php_stream_ops *ops; + const php_stream_ops *ops; void *abstract; /* convenience pointer for abstraction */ php_stream_filter_chain readfilters, writefilters; @@ -246,7 +244,7 @@ struct _php_stream { /* allocate a new stream for a particular ops */ BEGIN_EXTERN_C() -PHPAPI php_stream *_php_stream_alloc(php_stream_ops *ops, void *abstract, +PHPAPI php_stream *_php_stream_alloc(const php_stream_ops *ops, void *abstract, const char *persistent_id, const char *mode STREAMS_DC); END_EXTERN_C() #define php_stream_alloc(ops, thisptr, persistent_id, mode) _php_stream_alloc((ops), (thisptr), (persistent_id), (mode) STREAMS_CC) @@ -413,7 +411,7 @@ END_EXTERN_C() /* whether or not locking is supported */ #define PHP_STREAM_LOCK_SUPPORTED 1 -#define php_stream_supports_lock(stream) _php_stream_set_option((stream), PHP_STREAM_OPTION_LOCKING, 0, (void *) PHP_STREAM_LOCK_SUPPORTED) == 0 ? 1 : 0 +#define php_stream_supports_lock(stream) (_php_stream_set_option((stream), PHP_STREAM_OPTION_LOCKING, 0, (void *) PHP_STREAM_LOCK_SUPPORTED) == 0 ? 1 : 0) #define php_stream_lock(stream, mode) _php_stream_set_option((stream), PHP_STREAM_OPTION_LOCKING, (mode), (void *) NULL) /* option code used by the php_stream_xport_XXX api */ @@ -561,10 +559,10 @@ void php_shutdown_stream_hashes(void); PHP_RSHUTDOWN_FUNCTION(streams); BEGIN_EXTERN_C() -PHPAPI int php_register_url_stream_wrapper(const char *protocol, php_stream_wrapper *wrapper); +PHPAPI int php_register_url_stream_wrapper(const char *protocol, const php_stream_wrapper *wrapper); PHPAPI int php_unregister_url_stream_wrapper(const char *protocol); -PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_stream_wrapper *wrapper); -PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol); +PHPAPI int php_register_url_stream_wrapper_volatile(zend_string *protocol, php_stream_wrapper *wrapper); +PHPAPI int php_unregister_url_stream_wrapper_volatile(zend_string *protocol); PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC); PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const char **path_for_open, int options); PHPAPI const char *php_stream_locate_eol(php_stream *stream, zend_string *buf); @@ -573,7 +571,7 @@ PHPAPI const char *php_stream_locate_eol(php_stream *stream, zend_string *buf); #define php_stream_open_wrapper_ex(path, mode, options, opened, context) _php_stream_open_wrapper_ex((path), (mode), (options), (opened), (context) STREAMS_CC) /* pushes an error message onto the stack for a wrapper instance */ -PHPAPI void php_stream_wrapper_log_error(php_stream_wrapper *wrapper, int options, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4); +PHPAPI void php_stream_wrapper_log_error(const php_stream_wrapper *wrapper, int options, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4); #define PHP_STREAM_UNCHANGED 0 /* orig stream was seekable anyway */ #define PHP_STREAM_RELEASED 1 /* newstream should be used; origstream is no longer valid */ @@ -593,7 +591,7 @@ PHPAPI HashTable *php_stream_get_url_stream_wrappers_hash_global(void); PHPAPI HashTable *_php_get_stream_filters_hash(void); #define php_get_stream_filters_hash() _php_get_stream_filters_hash() PHPAPI HashTable *php_get_stream_filters_hash_global(void); -extern php_stream_wrapper_ops *php_stream_user_wrapper_ops; +extern const php_stream_wrapper_ops *php_stream_user_wrapper_ops; END_EXTERN_C() #endif diff --git a/main/php_syslog.c b/main/php_syslog.c new file mode 100644 index 0000000000..dd16f05217 --- /dev/null +++ b/main/php_syslog.c @@ -0,0 +1,120 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) 2017-2018 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: Philip Prindeville <philipp@redfish-solutions.com> | + +----------------------------------------------------------------------+ +*/ + +#include <stdio.h> +#include <string.h> +#include <assert.h> +#include <stdlib.h> +#include "php.h" +#include "php_syslog.h" + +#include "zend.h" +#include "zend_smart_string.h" + +/* + * The SCO OpenServer 5 Development System (not the UDK) + * defines syslog to std_syslog. + */ + +#ifdef HAVE_STD_SYSLOG +#define syslog std_syslog +#endif + +#ifdef PHP_WIN32 +PHPAPI void php_syslog(int priority, const char *format, ...) /* {{{ */ +{ + va_list args; + + /* + * don't rely on openlog() being called by syslog() if it's + * not already been done; call it ourselves and pass the + * correct parameters! + */ + if (!PG(have_called_openlog)) { + php_openlog(PG(syslog_ident), 0, PG(syslog_facility)); + } + + va_start(args, format); + vsyslog(priority, format, args); + va_end(args); +} +/* }}} */ +#else +PHPAPI void php_syslog(int priority, const char *format, ...) /* {{{ */ +{ + const char *ptr; + unsigned char c; + smart_string fbuf = {0}; + smart_string sbuf = {0}; + va_list args; + + /* + * don't rely on openlog() being called by syslog() if it's + * not already been done; call it ourselves and pass the + * correct parameters! + */ + if (!PG(have_called_openlog)) { + php_openlog(PG(syslog_ident), 0, PG(syslog_facility)); + } + + va_start(args, format); + zend_printf_to_smart_string(&fbuf, format, args); + smart_string_0(&fbuf); + va_end(args); + + for (ptr = fbuf.c; ; ++ptr) { + c = *ptr; + if (c == '\0') { + syslog(priority, "%.*s", (int)sbuf.len, sbuf.c); + break; + } + + /* check for NVT ASCII only unless test disabled */ + if (((0x20 <= c) && (c <= 0x7e))) + smart_string_appendc(&sbuf, c); + else if ((c >= 0x80) && (PG(syslog_filter) != PHP_SYSLOG_FILTER_ASCII)) + smart_string_appendc(&sbuf, c); + else if (c == '\n') { + syslog(priority, "%.*s", (int)sbuf.len, sbuf.c); + smart_string_reset(&sbuf); + } else if ((c < 0x20) && (PG(syslog_filter) == PHP_SYSLOG_FILTER_ALL)) + smart_string_appendc(&sbuf, c); + else { + const char xdigits[] = "0123456789abcdef"; + + smart_string_appendl(&sbuf, "\\x", 2); + smart_string_appendc(&sbuf, xdigits[(c / 0x10)]); + c &= 0x0f; + smart_string_appendc(&sbuf, xdigits[c]); + } + } + + smart_string_free(&fbuf); + smart_string_free(&sbuf); +} +/* }}} */ +#endif + +/* + * 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_syslog.h b/main/php_syslog.h index 673f14cec2..dee0e5aaa3 100644 --- a/main/php_syslog.h +++ b/main/php_syslog.h @@ -16,11 +16,11 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef PHP_SYSLOG_H #define PHP_SYSLOG_H +#include "php.h" + #ifdef PHP_WIN32 #include "win32/syslog.h" #else @@ -30,26 +30,18 @@ #endif #endif -/* - * The SCO OpenServer 5 Development System (not the UDK) - * defines syslog to std_syslog. - */ - -#ifdef syslog - -#ifdef HAVE_STD_SYSLOG -#define php_syslog std_syslog -#endif - -#undef syslog +/* Syslog filters */ +#define PHP_SYSLOG_FILTER_ALL 0 +#define PHP_SYSLOG_FILTER_NO_CTRL 1 +#define PHP_SYSLOG_FILTER_ASCII 2 -#endif +BEGIN_EXTERN_C() +PHPAPI void php_syslog(int, const char *format, ...); +PHPAPI void php_openlog(const char *, int, int); +END_EXTERN_C() -#ifndef php_syslog -#define php_syslog syslog #endif -#endif /* * Local variables: * tab-width: 4 diff --git a/main/php_ticks.c b/main/php_ticks.c index 318cbe348d..4a284eac5d 100644 --- a/main/php_ticks.c +++ b/main/php_ticks.c @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include "php.h" #include "php_ticks.h" diff --git a/main/php_ticks.h b/main/php_ticks.h index 8cb52fc239..d1e1c13914 100644 --- a/main/php_ticks.h +++ b/main/php_ticks.h @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef PHP_TICKS_H #define PHP_TICKS_H diff --git a/main/php_variables.c b/main/php_variables.c index 916fc1295b..5ac61a4fa0 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -13,12 +13,10 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - | Zeev Suraski <zeev@zend.com> | + | Zeev Suraski <zeev@php.net> | +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include <stdio.h> #include "php.h" #include "ext/standard/php_standard.h" @@ -59,6 +57,14 @@ PHPAPI void php_register_variable_safe(char *var, char *strval, size_t str_len, php_register_variable_ex(var, &new_entry, track_vars_array); } +static zend_always_inline void php_register_variable_quick(const char *name, size_t name_len, zval *val, HashTable *ht) +{ + zend_string *key = zend_string_init_interned(name, name_len, 0); + + zend_hash_update_ind(ht, key, val); + zend_string_release_ex(key, 0); +} + PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars_array) { char *p = NULL; @@ -79,7 +85,7 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars if (!symtable1) { /* Nothing to do */ - zval_dtor(val); + zval_ptr_dtor_nogc(val); return; } @@ -110,7 +116,7 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars var_len = p - var; if (var_len==0) { /* empty variable name, or variable name with a space in it */ - zval_dtor(val); + zval_ptr_dtor_nogc(val); free_alloca(var_orig, use_heap); return; } @@ -124,7 +130,7 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars && ex->symbol_table == symtable1) { if (memcmp(var, "this", sizeof("this")-1) == 0) { zend_throw_error(NULL, "Cannot re-assign $this"); - zval_dtor(val); + zval_ptr_dtor_nogc(val); free_alloca(var_orig, use_heap); return; } @@ -139,7 +145,7 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars if (symtable1 == &EG(symbol_table) && var_len == sizeof("GLOBALS")-1 && !memcmp(var, "GLOBALS", sizeof("GLOBALS")-1)) { - zval_dtor(val); + zval_ptr_dtor_nogc(val); free_alloca(var_orig, use_heap); return; } @@ -162,7 +168,7 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars zend_symtable_str_del(ht, var, var_len); } - zval_dtor(val); + zval_ptr_dtor_nogc(val); /* do not output the error message to the screen, this helps us to to avoid "information disclosure" */ @@ -200,8 +206,8 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars if (!index) { array_init(&gpc_element); if ((gpc_element_p = zend_hash_next_index_insert(symtable1, &gpc_element)) == NULL) { - zval_ptr_dtor(&gpc_element); - zval_dtor(val); + zend_array_destroy(Z_ARR(gpc_element)); + zval_ptr_dtor_nogc(val); free_alloca(var_orig, use_heap); return; } @@ -216,7 +222,7 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars gpc_element_p = Z_INDIRECT_P(gpc_element_p); } if (Z_TYPE_P(gpc_element_p) != IS_ARRAY) { - zval_ptr_dtor(gpc_element_p); + zval_ptr_dtor_nogc(gpc_element_p); array_init(gpc_element_p); } else { SEPARATE_ARRAY(gpc_element_p); @@ -238,12 +244,13 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars } } else { plain_var: - ZVAL_COPY_VALUE(&gpc_element, val); if (!index) { - if ((gpc_element_p = zend_hash_next_index_insert(symtable1, &gpc_element)) == NULL) { - zval_ptr_dtor(&gpc_element); + if (zend_hash_next_index_insert(symtable1, val) == NULL) { + zval_ptr_dtor_nogc(val); } } else { + zend_ulong idx; + /* * According to rfc2965, more specific paths are listed above the less specific ones. * If we encounter a duplicate cookie name, we should skip it, since it is not possible @@ -253,9 +260,11 @@ plain_var: if (Z_TYPE(PG(http_globals)[TRACK_VARS_COOKIE]) != IS_UNDEF && symtable1 == Z_ARRVAL(PG(http_globals)[TRACK_VARS_COOKIE]) && zend_symtable_str_exists(symtable1, index, index_len)) { - zval_ptr_dtor(&gpc_element); + zval_ptr_dtor_nogc(val); + } else if (ZEND_HANDLE_NUMERIC_STR(index, index_len, idx)) { + zend_hash_index_update(symtable1, idx, val); } else { - gpc_element_p = zend_symtable_str_update_ind(symtable1, index, index_len, &gpc_element); + php_register_variable_quick(index, index_len, val, symtable1); } } } @@ -409,15 +418,15 @@ SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data) array_init(&array); switch (arg) { case PARSE_POST: - zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_POST]); + zval_ptr_dtor_nogc(&PG(http_globals)[TRACK_VARS_POST]); ZVAL_COPY_VALUE(&PG(http_globals)[TRACK_VARS_POST], &array); break; case PARSE_GET: - zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_GET]); + zval_ptr_dtor_nogc(&PG(http_globals)[TRACK_VARS_GET]); ZVAL_COPY_VALUE(&PG(http_globals)[TRACK_VARS_GET], &array); break; case PARSE_COOKIE: - zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_COOKIE]); + zval_ptr_dtor_nogc(&PG(http_globals)[TRACK_VARS_COOKIE]); ZVAL_COPY_VALUE(&PG(http_globals)[TRACK_VARS_COOKIE], &array); break; } @@ -520,29 +529,48 @@ next_cookie: } } +static zend_always_inline int valid_environment_name(const char *name, const char *end) +{ + const char *s; + + for (s = name; s < end; s++) { + if (*s == ' ' || *s == '.' || *s == '[') { + return 0; + } + } + return 1; +} + void _php_import_environment_variables(zval *array_ptr) { - char buf[128]; - char **env, *p, *t = buf; - size_t alloc_size = sizeof(buf); - unsigned long nlen; /* ptrdiff_t is not portable */ + char **env, *p; + size_t name_len, len; + zval val; + zend_ulong idx; for (env = environ; env != NULL && *env != NULL; env++) { p = strchr(*env, '='); - if (!p) { /* malformed entry? */ + if (!p + || p == *env + || !valid_environment_name(*env, p)) { + /* malformed entry? */ continue; } - nlen = p - *env; - if (nlen >= alloc_size) { - alloc_size = nlen + 64; - t = (t == buf ? emalloc(alloc_size): erealloc(t, alloc_size)); + name_len = p - *env; + p++; + len = strlen(p); + if (len == 0) { + ZVAL_EMPTY_STRING(&val); + } else if (len == 1) { + ZVAL_INTERNED_STR(&val, ZSTR_CHAR((zend_uchar)*p)); + } else { + ZVAL_NEW_STR(&val, zend_string_init(p, len, 0)); + } + if (ZEND_HANDLE_NUMERIC_STR(*env, name_len, idx)) { + zend_hash_index_update(Z_ARRVAL_P(array_ptr), idx, &val); + } else { + php_register_variable_quick(*env, name_len, &val, Z_ARRVAL_P(array_ptr)); } - memcpy(t, *env, nlen); - t[nlen] = '\0'; - php_register_variable(t, p + 1, array_ptr); - } - if (t != buf && t != NULL) { - efree(t); } } @@ -572,7 +600,7 @@ PHPAPI void php_build_argv(char *s, zval *track_vars_array) for (i = 0; i < SG(request_info).argc; i++) { ZVAL_STRING(&tmp, SG(request_info).argv[i]); if (zend_hash_next_index_insert(Z_ARRVAL(arr), &tmp) == NULL) { - zend_string_free(Z_STR(tmp)); + zend_string_efree(Z_STR(tmp)); } } } else if (s && *s) { @@ -586,7 +614,7 @@ PHPAPI void php_build_argv(char *s, zval *track_vars_array) ZVAL_STRING(&tmp, ss); count++; if (zend_hash_next_index_insert(Z_ARRVAL(arr), &tmp) == NULL) { - zend_string_free(Z_STR(tmp)); + zend_string_efree(Z_STR(tmp)); } if (space) { *space = '+'; @@ -606,13 +634,13 @@ PHPAPI void php_build_argv(char *s, zval *track_vars_array) if (SG(request_info).argc) { Z_ADDREF(arr); - zend_hash_str_update(&EG(symbol_table), "argv", sizeof("argv")-1, &arr); - zend_hash_str_add(&EG(symbol_table), "argc", sizeof("argc")-1, &argc); + zend_hash_update(&EG(symbol_table), ZSTR_KNOWN(ZEND_STR_ARGV), &arr); + zend_hash_update(&EG(symbol_table), ZSTR_KNOWN(ZEND_STR_ARGC), &argc); } if (track_vars_array && Z_TYPE_P(track_vars_array) == IS_ARRAY) { Z_ADDREF(arr); - zend_hash_str_update(Z_ARRVAL_P(track_vars_array), "argv", sizeof("argv")-1, &arr); - zend_hash_str_update(Z_ARRVAL_P(track_vars_array), "argc", sizeof("argc")-1, &argc); + zend_hash_update(Z_ARRVAL_P(track_vars_array), ZSTR_KNOWN(ZEND_STR_ARGV), &arr); + zend_hash_update(Z_ARRVAL_P(track_vars_array), ZSTR_KNOWN(ZEND_STR_ARGC), &argc); } zval_ptr_dtor_nogc(&arr); } @@ -622,32 +650,38 @@ PHPAPI void php_build_argv(char *s, zval *track_vars_array) */ static inline void php_register_server_variables(void) { - zval request_time_float, request_time_long; + zval tmp; + zval *arr = &PG(http_globals)[TRACK_VARS_SERVER]; + HashTable *ht; - zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_SERVER]); - array_init(&PG(http_globals)[TRACK_VARS_SERVER]); + zval_ptr_dtor_nogc(arr); + array_init(arr); /* Server variables */ if (sapi_module.register_server_variables) { - sapi_module.register_server_variables(&PG(http_globals)[TRACK_VARS_SERVER]); + sapi_module.register_server_variables(arr); } + ht = Z_ARRVAL_P(arr); /* PHP Authentication support */ if (SG(request_info).auth_user) { - php_register_variable("PHP_AUTH_USER", SG(request_info).auth_user, &PG(http_globals)[TRACK_VARS_SERVER]); + ZVAL_STRING(&tmp, SG(request_info).auth_user); + php_register_variable_quick("PHP_AUTH_USER", sizeof("PHP_AUTH_USER")-1, &tmp, ht); } if (SG(request_info).auth_password) { - php_register_variable("PHP_AUTH_PW", SG(request_info).auth_password, &PG(http_globals)[TRACK_VARS_SERVER]); + ZVAL_STRING(&tmp, SG(request_info).auth_password); + php_register_variable_quick("PHP_AUTH_PW", sizeof("PHP_AUTH_PW")-1, &tmp, ht); } if (SG(request_info).auth_digest) { - php_register_variable("PHP_AUTH_DIGEST", SG(request_info).auth_digest, &PG(http_globals)[TRACK_VARS_SERVER]); + ZVAL_STRING(&tmp, SG(request_info).auth_digest); + php_register_variable_quick("PHP_AUTH_DIGEST", sizeof("PHP_AUTH_DIGEST")-1, &tmp, ht); } /* store request init time */ - ZVAL_DOUBLE(&request_time_float, sapi_get_request_time()); - php_register_variable_ex("REQUEST_TIME_FLOAT", &request_time_float, &PG(http_globals)[TRACK_VARS_SERVER]); - ZVAL_LONG(&request_time_long, zend_dval_to_lval(Z_DVAL(request_time_float))); - php_register_variable_ex("REQUEST_TIME", &request_time_long, &PG(http_globals)[TRACK_VARS_SERVER]); + ZVAL_DOUBLE(&tmp, sapi_get_request_time()); + php_register_variable_quick("REQUEST_TIME_FLOAT", sizeof("REQUEST_TIME_FLOAT")-1, &tmp, ht); + ZVAL_LONG(&tmp, zend_dval_to_lval(Z_DVAL(tmp))); + php_register_variable_quick("REQUEST_TIME", sizeof("REQUEST_TIME")-1, &tmp, ht); } /* }}} */ @@ -665,15 +699,13 @@ static void php_autoglobal_merge(HashTable *dest, HashTable *src) || (string_key && (dest_entry = zend_hash_find(dest, string_key)) == NULL) || (string_key == NULL && (dest_entry = zend_hash_index_find(dest, num_key)) == NULL) || Z_TYPE_P(dest_entry) != IS_ARRAY) { - if (Z_REFCOUNTED_P(src_entry)) { - Z_ADDREF_P(src_entry); - } + Z_TRY_ADDREF_P(src_entry); if (string_key) { if (!globals_check || ZSTR_LEN(string_key) != sizeof("GLOBALS") - 1 || memcmp(ZSTR_VAL(string_key), "GLOBALS", sizeof("GLOBALS") - 1)) { zend_hash_update(dest, string_key, src_entry); - } else if (Z_REFCOUNTED_P(src_entry)) { - Z_DELREF_P(src_entry); + } else { + Z_TRY_DELREF_P(src_entry); } } else { zend_hash_index_update(dest, num_key, src_entry); @@ -704,7 +736,7 @@ static zend_bool php_auto_globals_create_get(zend_string *name) if (PG(variables_order) && (strchr(PG(variables_order),'G') || strchr(PG(variables_order),'g'))) { sapi_module.treat_data(PARSE_GET, NULL, NULL); } else { - zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_GET]); + zval_ptr_dtor_nogc(&PG(http_globals)[TRACK_VARS_GET]); array_init(&PG(http_globals)[TRACK_VARS_GET]); } @@ -723,7 +755,7 @@ static zend_bool php_auto_globals_create_post(zend_string *name) !strcasecmp(SG(request_info).request_method, "POST")) { sapi_module.treat_data(PARSE_POST, NULL, NULL); } else { - zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_POST]); + zval_ptr_dtor_nogc(&PG(http_globals)[TRACK_VARS_POST]); array_init(&PG(http_globals)[TRACK_VARS_POST]); } @@ -738,7 +770,7 @@ static zend_bool php_auto_globals_create_cookie(zend_string *name) if (PG(variables_order) && (strchr(PG(variables_order),'C') || strchr(PG(variables_order),'c'))) { sapi_module.treat_data(PARSE_COOKIE, NULL, NULL); } else { - zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_COOKIE]); + zval_ptr_dtor_nogc(&PG(http_globals)[TRACK_VARS_COOKIE]); array_init(&PG(http_globals)[TRACK_VARS_COOKIE]); } @@ -785,11 +817,11 @@ static zend_bool php_auto_globals_create_server(zend_string *name) if (SG(request_info).argc) { zval *argc, *argv; - if ((argc = zend_hash_str_find_ind(&EG(symbol_table), "argc", sizeof("argc")-1)) != NULL && - (argv = zend_hash_str_find_ind(&EG(symbol_table), "argv", sizeof("argv")-1)) != NULL) { + if ((argc = zend_hash_find_ex_ind(&EG(symbol_table), ZSTR_KNOWN(ZEND_STR_ARGC), 1)) != NULL && + (argv = zend_hash_find_ex_ind(&EG(symbol_table), ZSTR_KNOWN(ZEND_STR_ARGV), 1)) != NULL) { Z_ADDREF_P(argv); - zend_hash_str_update(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "argv", sizeof("argv")-1, argv); - zend_hash_str_update(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "argc", sizeof("argc")-1, argc); + zend_hash_update(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), ZSTR_KNOWN(ZEND_STR_ARGV), argv); + zend_hash_update(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), ZSTR_KNOWN(ZEND_STR_ARGC), argc); } } else { php_build_argv(SG(request_info).query_string, &PG(http_globals)[TRACK_VARS_SERVER]); @@ -797,7 +829,7 @@ static zend_bool php_auto_globals_create_server(zend_string *name) } } else { - zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_SERVER]); + zval_ptr_dtor_nogc(&PG(http_globals)[TRACK_VARS_SERVER]); array_init(&PG(http_globals)[TRACK_VARS_SERVER]); } @@ -815,7 +847,7 @@ static zend_bool php_auto_globals_create_server(zend_string *name) static zend_bool php_auto_globals_create_env(zend_string *name) { - zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_ENV]); + zval_ptr_dtor_nogc(&PG(http_globals)[TRACK_VARS_ENV]); array_init(&PG(http_globals)[TRACK_VARS_ENV]); if (PG(variables_order) && (strchr(PG(variables_order),'E') || strchr(PG(variables_order),'e'))) { @@ -875,13 +907,13 @@ static zend_bool php_auto_globals_create_request(zend_string *name) void php_startup_auto_globals(void) { - zend_register_auto_global(zend_string_init("_GET", sizeof("_GET")-1, 1), 0, php_auto_globals_create_get); - zend_register_auto_global(zend_string_init("_POST", sizeof("_POST")-1, 1), 0, php_auto_globals_create_post); - zend_register_auto_global(zend_string_init("_COOKIE", sizeof("_COOKIE")-1, 1), 0, php_auto_globals_create_cookie); - zend_register_auto_global(zend_string_init("_SERVER", sizeof("_SERVER")-1, 1), PG(auto_globals_jit), php_auto_globals_create_server); - zend_register_auto_global(zend_string_init("_ENV", sizeof("_ENV")-1, 1), PG(auto_globals_jit), php_auto_globals_create_env); - zend_register_auto_global(zend_string_init("_REQUEST", sizeof("_REQUEST")-1, 1), PG(auto_globals_jit), php_auto_globals_create_request); - zend_register_auto_global(zend_string_init("_FILES", sizeof("_FILES")-1, 1), 0, php_auto_globals_create_files); + zend_register_auto_global(zend_string_init_interned("_GET", sizeof("_GET")-1, 1), 0, php_auto_globals_create_get); + zend_register_auto_global(zend_string_init_interned("_POST", sizeof("_POST")-1, 1), 0, php_auto_globals_create_post); + zend_register_auto_global(zend_string_init_interned("_COOKIE", sizeof("_COOKIE")-1, 1), 0, php_auto_globals_create_cookie); + zend_register_auto_global(zend_string_init_interned("_SERVER", sizeof("_SERVER")-1, 1), PG(auto_globals_jit), php_auto_globals_create_server); + zend_register_auto_global(zend_string_init_interned("_ENV", sizeof("_ENV")-1, 1), PG(auto_globals_jit), php_auto_globals_create_env); + zend_register_auto_global(zend_string_init_interned("_REQUEST", sizeof("_REQUEST")-1, 1), PG(auto_globals_jit), php_auto_globals_create_request); + zend_register_auto_global(zend_string_init_interned("_FILES", sizeof("_FILES")-1, 1), 0, php_auto_globals_create_files); } /* diff --git a/main/php_variables.h b/main/php_variables.h index 54153b2cf7..bc2da53732 100644 --- a/main/php_variables.h +++ b/main/php_variables.h @@ -13,12 +13,10 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - | Zeev Suraski <zeev@zend.com> | + | Zeev Suraski <zeev@php.net> | +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef PHP_VARIABLES_H #define PHP_VARIABLES_H diff --git a/main/php_version.h b/main/php_version.h index 7fd60db3bc..1be23ec4fd 100644 --- a/main/php_version.h +++ b/main/php_version.h @@ -1,8 +1,8 @@ /* automatically generated by configure */ /* edit configure.ac to change version number */ #define PHP_MAJOR_VERSION 7 -#define PHP_MINOR_VERSION 2 -#define PHP_RELEASE_VERSION 17 +#define PHP_MINOR_VERSION 3 +#define PHP_RELEASE_VERSION 4 #define PHP_EXTRA_VERSION "-dev" -#define PHP_VERSION "7.2.17-dev" -#define PHP_VERSION_ID 70217 +#define PHP_VERSION "7.3.4-dev" +#define PHP_VERSION_ID 70304 diff --git a/main/reentrancy.c b/main/reentrancy.c index f0c6dacc7b..213e82bd8c 100644 --- a/main/reentrancy.c +++ b/main/reentrancy.c @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include <sys/types.h> #include <string.h> #include <errno.h> @@ -111,18 +109,6 @@ PHPAPI struct tm *php_gmtime_r(const time_t *const timep, struct tm *p_tm) #endif -#if defined(__BEOS__) - -PHPAPI struct tm *php_gmtime_r(const time_t *const timep, struct tm *p_tm) -{ - /* Modified according to LibC definition */ - if (((struct tm*)gmtime_r(timep, p_tm)) == p_tm) - return (p_tm); - return (NULL); -} - -#endif /* BEOS */ - #if !defined(HAVE_POSIX_READDIR_R) PHPAPI int php_readdir_r(DIR *dirp, struct dirent *entry, diff --git a/main/rfc1867.c b/main/rfc1867.c index bd01b34cf0..8a8e335ef4 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -17,8 +17,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - /* * This product includes software developed by the Apache Group * for use in the Apache HTTP server project (http://www.apache.org/). @@ -203,7 +201,7 @@ static int unlink_filename(zval *el) /* {{{ */ static void free_filename(zval *el) { zend_string *filename = Z_STR_P(el); - zend_string_release(filename); + zend_string_release_ex(filename, 0); } PHPAPI void destroy_uploaded_files_hash(void) /* {{{ */ @@ -394,7 +392,7 @@ static int find_boundary(multipart_buffer *self, char *boundary) { char *line; - /* loop thru lines */ + /* loop through lines */ while( (line = get_line(self)) ) { /* finished if we found the boundary */ @@ -1113,7 +1111,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ if (cancel_upload != UPLOAD_ERROR_E) { /* file creation failed */ unlink(ZSTR_VAL(temp_filename)); } - zend_string_release(temp_filename); + zend_string_release_ex(temp_filename, 0); } temp_filename = NULL; } else { diff --git a/main/rfc1867.h b/main/rfc1867.h index eaddd17f16..ae8058d81b 100644 --- a/main/rfc1867.h +++ b/main/rfc1867.h @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifndef RFC1867_H #define RFC1867_H diff --git a/main/snprintf.c b/main/snprintf.c index fef2b95e7a..5990e3df91 100644 --- a/main/snprintf.c +++ b/main/snprintf.c @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #define _GNU_SOURCE #include "php.h" @@ -487,9 +485,9 @@ PHPAPI char * ap_php_conv_p2(register u_wide_int num, register int nbits, char f { register int mask = (1 << nbits) - 1; register char *p = buf_end; - static char low_digits[] = "0123456789abcdef"; - static char upper_digits[] = "0123456789ABCDEF"; - register char *digits = (format == 'X') ? upper_digits : low_digits; + static const char low_digits[] = "0123456789abcdef"; + static const char upper_digits[] = "0123456789ABCDEF"; + register const char *digits = (format == 'X') ? upper_digits : low_digits; do { *--p = digits[num & mask]; @@ -1214,7 +1212,7 @@ fmt_error: if (adjust_width && adjust == LEFT && (size_t)min_width > s_len) PAD((size_t)min_width, s_len, pad_char); if (free_zcopy) { - zval_dtor(&zcopy); + zval_ptr_dtor_str(&zcopy); } } skip_output: diff --git a/main/snprintf.h b/main/snprintf.h index e98711fe16..9dd27e662a 100644 --- a/main/snprintf.h +++ b/main/snprintf.h @@ -17,8 +17,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - /* Comparing: sprintf, snprintf, slprintf, spprintf diff --git a/main/spprintf.c b/main/spprintf.c index 10bce9d247..464dda492b 100644 --- a/main/spprintf.c +++ b/main/spprintf.c @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - /* This is the spprintf implementation. * It has emerged from apache snprintf. See original header: */ @@ -817,7 +815,7 @@ fmt_error: } if (free_zcopy) { - zval_dtor(&zcopy); + zval_ptr_dtor_str(&zcopy); } } skip_output: diff --git a/main/streams/cast.c b/main/streams/cast.c index 9ef542086c..6cfa651977 100644 --- a/main/streams/cast.c +++ b/main/streams/cast.c @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #define _GNU_SOURCE #include "php.h" #include "php_globals.h" @@ -356,7 +354,7 @@ PHPAPI FILE * _php_stream_open_wrapper_as_file(char *path, char *mode, int optio if (php_stream_cast(stream, PHP_STREAM_AS_STDIO|PHP_STREAM_CAST_TRY_HARD|PHP_STREAM_CAST_RELEASE, (void**)&fp, REPORT_ERRORS) == FAILURE) { php_stream_close(stream); if (opened_path && *opened_path) { - zend_string_release(*opened_path); + zend_string_release_ex(*opened_path, 0); } return NULL; } diff --git a/main/streams/filter.c b/main/streams/filter.c index 6ccd2b6bd4..73fca3dd6a 100644 --- a/main/streams/filter.c +++ b/main/streams/filter.c @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include "php.h" #include "php_globals.h" #include "php_network.h" @@ -44,9 +42,13 @@ PHPAPI HashTable *_php_get_stream_filters_hash(void) } /* API for registering GLOBAL filters */ -PHPAPI int php_stream_filter_register_factory(const char *filterpattern, php_stream_filter_factory *factory) +PHPAPI int php_stream_filter_register_factory(const char *filterpattern, const php_stream_filter_factory *factory) { - return zend_hash_str_add_ptr(&stream_filters_hash, filterpattern, strlen(filterpattern), factory) ? SUCCESS : FAILURE; + int ret; + zend_string *str = zend_string_init_interned(filterpattern, strlen(filterpattern), 1); + ret = zend_hash_add_ptr(&stream_filters_hash, str, (void*)factory) ? SUCCESS : FAILURE; + zend_string_release_ex(str, 1); + return ret; } PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern) @@ -55,15 +57,15 @@ PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern) } /* API for registering VOLATILE wrappers */ -PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern, php_stream_filter_factory *factory) +PHPAPI int php_stream_filter_register_factory_volatile(zend_string *filterpattern, const php_stream_filter_factory *factory) { if (!FG(stream_filters)) { ALLOC_HASHTABLE(FG(stream_filters)); - zend_hash_init(FG(stream_filters), zend_hash_num_elements(&stream_filters_hash), NULL, NULL, 1); + zend_hash_init(FG(stream_filters), zend_hash_num_elements(&stream_filters_hash) + 1, NULL, NULL, 0); zend_hash_copy(FG(stream_filters), &stream_filters_hash, NULL); } - return zend_hash_str_add_ptr(FG(stream_filters), (char*)filterpattern, strlen(filterpattern), factory) ? SUCCESS : FAILURE; + return zend_hash_add_ptr(FG(stream_filters), filterpattern, (void*)factory) ? SUCCESS : FAILURE; } /* Buckets */ @@ -220,7 +222,7 @@ PHPAPI void php_stream_bucket_unlink(php_stream_bucket *bucket) PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval *filterparams, uint8_t persistent) { HashTable *filter_hash = (FG(stream_filters) ? FG(stream_filters) : &stream_filters_hash); - php_stream_filter_factory *factory = NULL; + const php_stream_filter_factory *factory = NULL; php_stream_filter *filter = NULL; size_t n; char *period; @@ -260,7 +262,7 @@ PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval return filter; } -PHPAPI php_stream_filter *_php_stream_filter_alloc(php_stream_filter_ops *fops, void *abstract, uint8_t persistent STREAMS_DC) +PHPAPI php_stream_filter *_php_stream_filter_alloc(const php_stream_filter_ops *fops, void *abstract, uint8_t persistent STREAMS_DC) { php_stream_filter *filter; diff --git a/main/streams/glob_wrapper.c b/main/streams/glob_wrapper.c index b10318fef2..dcdbabf185 100644 --- a/main/streams/glob_wrapper.c +++ b/main/streams/glob_wrapper.c @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include "php.h" #include "php_streams_int.h" @@ -195,7 +193,7 @@ static int php_glob_stream_rewind(php_stream *stream, zend_off_t offset, int whe } /* }}} */ -php_stream_ops php_glob_stream_ops = { +const php_stream_ops php_glob_stream_ops = { NULL, php_glob_stream_read, php_glob_stream_close, NULL, "glob", @@ -261,7 +259,7 @@ static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, const cha } /* }}} */ -static php_stream_wrapper_ops php_glob_stream_wrapper_ops = { +static const php_stream_wrapper_ops php_glob_stream_wrapper_ops = { NULL, NULL, NULL, @@ -275,7 +273,7 @@ static php_stream_wrapper_ops php_glob_stream_wrapper_ops = { NULL }; -php_stream_wrapper php_glob_stream_wrapper = { +const php_stream_wrapper php_glob_stream_wrapper = { &php_glob_stream_wrapper_ops, NULL, 0 diff --git a/main/streams/memory.c b/main/streams/memory.c index 7011cff335..d088f43c2f 100644 --- a/main/streams/memory.c +++ b/main/streams/memory.c @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #define _GNU_SOURCE #include "php.h" #include "ext/standard/base64.h" @@ -53,10 +51,11 @@ static size_t php_stream_memory_write(php_stream *stream, const char *buf, size_ if (ms->mode & TEMP_STREAM_READONLY) { return 0; + } else if (ms->mode & TEMP_STREAM_APPEND) { + ms->fpos = ms->fsize; } if (ms->fpos + count > ms->fsize) { char *tmp; - if (!ms->data) { tmp = emalloc(ms->fpos + count); } else { @@ -222,9 +221,6 @@ static int php_stream_memory_stat(php_stream *stream, php_stream_statbuf *ssb) / #ifndef PHP_WIN32 ssb->sb.st_blksize = -1; -#endif - -#if !defined(PHP_WIN32) && !defined(__BEOS__) ssb->sb.st_blocks = -1; #endif @@ -266,7 +262,7 @@ static int php_stream_memory_set_option(php_stream *stream, int option, int valu } /* }}} */ -PHPAPI php_stream_ops php_stream_memory_ops = { +PHPAPI const php_stream_ops php_stream_memory_ops = { php_stream_memory_write, php_stream_memory_read, php_stream_memory_close, php_stream_memory_flush, "MEMORY", @@ -276,6 +272,29 @@ PHPAPI php_stream_ops php_stream_memory_ops = { php_stream_memory_set_option }; +/* {{{ */ +PHPAPI int php_stream_mode_from_str(const char *mode) +{ + if (strpbrk(mode, "a")) { + return TEMP_STREAM_APPEND; + } else if (strpbrk(mode, "w+")) { + return TEMP_STREAM_DEFAULT; + } + return TEMP_STREAM_READONLY; +} +/* }}} */ + +/* {{{ */ +PHPAPI const char *_php_stream_mode_to_str(int mode) +{ + if (mode == TEMP_STREAM_READONLY) { + return "rb"; + } else if (mode == TEMP_STREAM_APPEND) { + return "a+b"; + } + return "w+b"; +} +/* }}} */ /* {{{ */ PHPAPI php_stream *_php_stream_memory_create(int mode STREAMS_DC) @@ -290,7 +309,7 @@ PHPAPI php_stream *_php_stream_memory_create(int mode STREAMS_DC) self->smax = ~0u; self->mode = mode; - stream = php_stream_alloc_rel(&php_stream_memory_ops, self, 0, mode & TEMP_STREAM_READONLY ? "rb" : "w+b"); + stream = php_stream_alloc_rel(&php_stream_memory_ops, self, 0, _php_stream_mode_to_str(mode)); stream->flags |= PHP_STREAM_FLAG_NO_BUFFER; return stream; } @@ -539,7 +558,7 @@ static int php_stream_temp_set_option(php_stream *stream, int option, int value, } /* }}} */ -PHPAPI php_stream_ops php_stream_temp_ops = { +PHPAPI const php_stream_ops php_stream_temp_ops = { php_stream_temp_write, php_stream_temp_read, php_stream_temp_close, php_stream_temp_flush, "TEMP", @@ -564,7 +583,7 @@ PHPAPI php_stream *_php_stream_temp_create_ex(int mode, size_t max_memory_usage, 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 = php_stream_alloc_rel(&php_stream_temp_ops, self, 0, _php_stream_mode_to_str(mode)); stream->flags |= PHP_STREAM_FLAG_NO_BUFFER; self->innerstream = php_stream_memory_create_rel(mode); php_stream_encloses(stream, self->innerstream); @@ -601,7 +620,7 @@ PHPAPI php_stream *_php_stream_temp_open(int mode, size_t max_memory_usage, char } /* }}} */ -PHPAPI php_stream_ops php_stream_rfc2397_ops = { +PHPAPI const php_stream_ops php_stream_rfc2397_ops = { php_stream_temp_write, php_stream_temp_read, php_stream_temp_close, php_stream_temp_flush, "RFC2397", @@ -617,7 +636,7 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con { php_stream *stream; php_stream_temp_data *ts; - char *comma, *semi, *sep, *key; + char *comma, *semi, *sep; size_t mlen, dlen, plen, vlen, ilen; zend_off_t newoffs; zval meta; @@ -689,11 +708,9 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con /* found parameter ... the heart of cs ppl lies in +1/-1 or was it +2 this time? */ plen = sep - path; vlen = (semi ? (size_t)(semi - sep) : (mlen - plen)) - 1 /* '=' */; - key = estrndup(path, plen); - if (plen != sizeof("mediatype")-1 || memcmp(key, "mediatype", sizeof("mediatype")-1)) { - add_assoc_stringl_ex(&meta, key, plen, sep + 1, vlen); + if (plen != sizeof("mediatype")-1 || memcmp(path, "mediatype", sizeof("mediatype")-1)) { + add_assoc_stringl_ex(&meta, path, plen, sep + 1, vlen); } - efree(key); plen += vlen + 1; mlen -= plen; path += plen; @@ -753,7 +770,7 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con return stream; } -PHPAPI php_stream_wrapper_ops php_stream_rfc2397_wops = { +PHPAPI const php_stream_wrapper_ops php_stream_rfc2397_wops = { php_stream_url_wrap_rfc2397, NULL, /* close */ NULL, /* fstat */ @@ -767,7 +784,7 @@ PHPAPI php_stream_wrapper_ops php_stream_rfc2397_wops = { NULL, /* stream_metadata */ }; -PHPAPI php_stream_wrapper php_stream_rfc2397_wrapper = { +PHPAPI const php_stream_wrapper php_stream_rfc2397_wrapper = { &php_stream_rfc2397_wops, NULL, 1, /* is_url */ diff --git a/main/streams/mmap.c b/main/streams/mmap.c index c731b51532..94c80a9dc5 100644 --- a/main/streams/mmap.c +++ b/main/streams/mmap.c @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - /* Memory Mapping interface for streams */ #include "php.h" #include "php_streams_int.h" @@ -32,7 +30,7 @@ PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t le range.mapped = NULL; /* For now, we impose an arbitrary limit to avoid - * runaway swapping when large files are passed thru. */ + * runaway swapping when large files are passed through. */ if (length > 4 * 1024 * 1024) { return NULL; } diff --git a/main/streams/php_stream_context.h b/main/streams/php_stream_context.h index 684159ed72..083178b23a 100644 --- a/main/streams/php_stream_context.h +++ b/main/streams/php_stream_context.h @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - /* Stream context and status notification related definitions */ /* callback for status notifications */ @@ -38,7 +36,7 @@ typedef void (*php_stream_notification_func)(php_stream_context *context, FG(default_context) ? FG(default_context) : \ (FG(default_context) = php_stream_context_alloc()) ) -#define php_stream_context_to_zval(context, zval) { ZVAL_RES(zval, (context)->res); GC_REFCOUNT((context)->res)++; } +#define php_stream_context_to_zval(context, zval) { ZVAL_RES(zval, (context)->res); GC_ADDREF((context)->res); } typedef struct _php_stream_notifier php_stream_notifier; diff --git a/main/streams/php_stream_filter_api.h b/main/streams/php_stream_filter_api.h index 51c9c6621a..09714249b8 100644 --- a/main/streams/php_stream_filter_api.h +++ b/main/streams/php_stream_filter_api.h @@ -19,8 +19,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - /* The filter API works on the principle of "Bucket-Brigades". This is * partially inspired by the Apache 2 method of doing things, although * it is intentially a light-weight implementation. @@ -106,7 +104,7 @@ typedef struct _php_stream_filter_chain { } php_stream_filter_chain; struct _php_stream_filter { - php_stream_filter_ops *fops; + const php_stream_filter_ops *fops; zval abstract; /* for use by filter implementation */ php_stream_filter *next; php_stream_filter *prev; @@ -131,7 +129,7 @@ PHPAPI int php_stream_filter_append_ex(php_stream_filter_chain *chain, php_strea PHPAPI int _php_stream_filter_flush(php_stream_filter *filter, int finish); PHPAPI php_stream_filter *php_stream_filter_remove(php_stream_filter *filter, int call_dtor); PHPAPI void php_stream_filter_free(php_stream_filter *filter); -PHPAPI php_stream_filter *_php_stream_filter_alloc(php_stream_filter_ops *fops, void *abstract, uint8_t persistent STREAMS_DC); +PHPAPI php_stream_filter *_php_stream_filter_alloc(const php_stream_filter_ops *fops, void *abstract, uint8_t persistent STREAMS_DC); END_EXTERN_C() #define php_stream_filter_alloc(fops, thisptr, persistent) _php_stream_filter_alloc((fops), (thisptr), (persistent) STREAMS_CC) #define php_stream_filter_alloc_rel(fops, thisptr, persistent) _php_stream_filter_alloc((fops), (thisptr), (persistent) STREAMS_REL_CC) @@ -146,9 +144,9 @@ typedef struct _php_stream_filter_factory { } php_stream_filter_factory; BEGIN_EXTERN_C() -PHPAPI int php_stream_filter_register_factory(const char *filterpattern, php_stream_filter_factory *factory); +PHPAPI int php_stream_filter_register_factory(const char *filterpattern, const php_stream_filter_factory *factory); PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern); -PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern, php_stream_filter_factory *factory); +PHPAPI int php_stream_filter_register_factory_volatile(zend_string *filterpattern, const php_stream_filter_factory *factory); PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval *filterparams, uint8_t persistent); END_EXTERN_C() diff --git a/main/streams/php_stream_glob_wrapper.h b/main/streams/php_stream_glob_wrapper.h index 66373776c9..174fb4f395 100644 --- a/main/streams/php_stream_glob_wrapper.h +++ b/main/streams/php_stream_glob_wrapper.h @@ -16,10 +16,8 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - -PHPAPI extern php_stream_wrapper php_glob_stream_wrapper; -PHPAPI extern php_stream_ops php_glob_stream_ops; +PHPAPI extern const php_stream_wrapper php_glob_stream_wrapper; +PHPAPI extern const php_stream_ops php_glob_stream_ops; BEGIN_EXTERN_C() diff --git a/main/streams/php_stream_mmap.h b/main/streams/php_stream_mmap.h index 69e888eae2..6db0bdcb90 100644 --- a/main/streams/php_stream_mmap.h +++ b/main/streams/php_stream_mmap.h @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - /* Memory Mapping interface for streams. * The intention is to provide a uniform interface over the most common * operations that are used within PHP itself, rather than a complete diff --git a/main/streams/php_stream_plain_wrapper.h b/main/streams/php_stream_plain_wrapper.h index 84cf175cae..17c0e72082 100644 --- a/main/streams/php_stream_plain_wrapper.h +++ b/main/streams/php_stream_plain_wrapper.h @@ -16,13 +16,11 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - /* definitions for the plain files wrapper */ /* operations for a plain file; use the php_stream_fopen_XXX funcs below */ PHPAPI extern php_stream_ops php_stream_stdio_ops; -PHPAPI extern php_stream_wrapper php_plain_files_wrapper; +PHPAPI extern /*const*/ php_stream_wrapper php_plain_files_wrapper; BEGIN_EXTERN_C() @@ -54,6 +52,9 @@ PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char PHPAPI FILE * _php_stream_open_wrapper_as_file(char * path, char * mode, int options, zend_string **opened_path STREAMS_DC); #define php_stream_open_wrapper_as_file(path, mode, options, opened_path) _php_stream_open_wrapper_as_file((path), (mode), (options), (opened_path) STREAMS_CC) +/* parse standard "fopen" modes into open() flags */ +PHPAPI int php_stream_parse_fopen_modes(const char *mode, int *open_flags); + END_EXTERN_C() /* diff --git a/main/streams/php_stream_transport.h b/main/streams/php_stream_transport.h index 8459e711ed..a4a851b399 100644 --- a/main/streams/php_stream_transport.h +++ b/main/streams/php_stream_transport.h @@ -16,7 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ #ifdef PHP_WIN32 #include "config.w32.h" #include <Ws2tcpip.h> diff --git a/main/streams/php_stream_userspace.h b/main/streams/php_stream_userspace.h index 19eb1d8353..1324d70da0 100644 --- a/main/streams/php_stream_userspace.h +++ b/main/streams/php_stream_userspace.h @@ -16,12 +16,9 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - - /* for user-space streams */ -PHPAPI extern php_stream_ops php_stream_userspace_ops; -PHPAPI extern php_stream_ops php_stream_userspace_dir_ops; +PHPAPI extern const php_stream_ops php_stream_userspace_ops; +PHPAPI extern const php_stream_ops php_stream_userspace_dir_ops; #define PHP_STREAM_IS_USERSPACE &php_stream_userspace_ops #define PHP_STREAM_IS_USERSPACE_DIR &php_stream_userspace_dir_ops diff --git a/main/streams/php_streams_int.h b/main/streams/php_streams_int.h index 5d2fa9f352..addaf0ce7b 100644 --- a/main/streams/php_streams_int.h +++ b/main/streams/php_streams_int.h @@ -16,9 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - - #if ZEND_DEBUG #define emalloc_rel_orig(size) \ diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 9b36d00ec8..ed52249637 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include "php.h" #include "php_globals.h" #include "php_network.h" @@ -221,7 +219,7 @@ PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char 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; + stream->wrapper = (php_stream_wrapper*)&php_plain_files_wrapper; stream->orig_path = estrndup(ZSTR_VAL(opened_path), ZSTR_LEN(opened_path)); self->temp_name = opened_path; @@ -479,7 +477,7 @@ static int php_stdiop_close(php_stream *stream, int close_handle) unlink(ZSTR_VAL(data->temp_name)); #endif /* temporary streams are never persistent */ - zend_string_release(data->temp_name); + zend_string_release_ex(data->temp_name, 0); data->temp_name = NULL; } } else { @@ -854,7 +852,38 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void if (new_size < 0) { return PHP_STREAM_OPTION_RETURN_ERR; } +#ifdef PHP_WIN32 + HANDLE h = (HANDLE) _get_osfhandle(fd); + if (INVALID_HANDLE_VALUE == h) { + return PHP_STREAM_OPTION_RETURN_ERR; + } + + LARGE_INTEGER sz, old_sz; + sz.QuadPart = 0; + + if (!SetFilePointerEx(h, sz, &old_sz, FILE_CURRENT)) { + return PHP_STREAM_OPTION_RETURN_ERR; + } + +#if defined(_WIN64) + sz.QuadPart = new_size; +#else + sz.HighPart = 0; + sz.LowPart = new_size; +#endif + if (!SetFilePointerEx(h, sz, NULL, FILE_BEGIN)) { + return PHP_STREAM_OPTION_RETURN_ERR; + } + if (0 == SetEndOfFile(h)) { + return PHP_STREAM_OPTION_RETURN_ERR; + } + if (!SetFilePointerEx(h, old_sz, NULL, FILE_BEGIN)) { + return PHP_STREAM_OPTION_RETURN_ERR; + } + return PHP_STREAM_OPTION_RETURN_OK; +#else return ftruncate(fd, new_size) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR; +#endif } } @@ -881,6 +910,7 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void } } +/* This should be "const", but phpdbg overwrite it */ PHPAPI php_stream_ops php_stream_stdio_ops = { php_stdiop_write, php_stdiop_read, php_stdiop_close, php_stdiop_flush, @@ -923,7 +953,7 @@ static int php_plain_files_dirstream_rewind(php_stream *stream, zend_off_t offse return 0; } -static php_stream_ops php_plain_files_dirstream_ops = { +static const php_stream_ops php_plain_files_dirstream_ops = { NULL, php_plain_files_dirstream_read, php_plain_files_dirstream_close, NULL, "dir", @@ -941,7 +971,7 @@ static php_stream *php_plain_files_dir_opener(php_stream_wrapper *wrapper, const #ifdef HAVE_GLOB if (options & STREAM_USE_GLOB_DIR_OPEN) { - return php_glob_stream_wrapper.wops->dir_opener(&php_glob_stream_wrapper, path, mode, options, opened_path, context STREAMS_REL_CC); + return php_glob_stream_wrapper.wops->dir_opener((php_stream_wrapper*)&php_glob_stream_wrapper, path, mode, options, opened_path, context STREAMS_REL_CC); } #endif @@ -1044,7 +1074,7 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, zen r = do_fstat(self, 0); if ((r == 0 && !S_ISREG(self->sb.st_mode))) { if (opened_path) { - zend_string_release(*opened_path); + zend_string_release_ex(*opened_path, 0); *opened_path = NULL; } php_stream_close(ret); @@ -1409,7 +1439,7 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url } -static php_stream_wrapper_ops php_plain_files_wrapper_ops = { +static const php_stream_wrapper_ops php_plain_files_wrapper_ops = { php_plain_files_stream_opener, NULL, NULL, @@ -1423,7 +1453,8 @@ static php_stream_wrapper_ops php_plain_files_wrapper_ops = { php_plain_files_metadata }; -PHPAPI php_stream_wrapper php_plain_files_wrapper = { +/* TODO: We have to make php_plain_files_wrapper writable to support SWOOLE */ +PHPAPI /*const*/ php_stream_wrapper php_plain_files_wrapper = { &php_plain_files_wrapper_ops, NULL, 0 diff --git a/main/streams/streams.c b/main/streams/streams.c index 9daae57433..626c7f6a54 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -19,8 +19,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #define _GNU_SOURCE #include "php.h" #include "php_globals.h" @@ -121,12 +119,12 @@ PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream * *stream = (php_stream*)le->ptr; ZEND_HASH_FOREACH_PTR(&EG(regular_list), regentry) { if (regentry->ptr == le->ptr) { - GC_REFCOUNT(regentry)++; + GC_ADDREF(regentry); (*stream)->res = regentry; return PHP_STREAM_PERSISTENT_SUCCESS; } } ZEND_HASH_FOREACH_END(); - GC_REFCOUNT(le)++; + GC_ADDREF(le); (*stream)->res = zend_register_resource(*stream, le_pstream); } return PHP_STREAM_PERSISTENT_SUCCESS; @@ -230,7 +228,7 @@ static void wrapper_list_dtor(zval *item) { efree(list); } -PHPAPI void php_stream_wrapper_log_error(php_stream_wrapper *wrapper, int options, const char *fmt, ...) +PHPAPI void php_stream_wrapper_log_error(const php_stream_wrapper *wrapper, int options, const char *fmt, ...) { va_list args; char *buffer = NULL; @@ -267,7 +265,7 @@ PHPAPI void php_stream_wrapper_log_error(php_stream_wrapper *wrapper, int option /* }}} */ /* allocate a new stream for a particular ops */ -PHPAPI php_stream *_php_stream_alloc(php_stream_ops *ops, void *abstract, const char *persistent_id, const char *mode STREAMS_DC) /* {{{ */ +PHPAPI php_stream *_php_stream_alloc(const php_stream_ops *ops, void *abstract, const char *persistent_id, const char *mode STREAMS_DC) /* {{{ */ { php_stream *ret; @@ -297,12 +295,7 @@ fprintf(stderr, "stream_alloc: %s:%p persistent=%s\n", ops->label, ret, persiste } if (persistent_id) { - zval tmp; - - ZVAL_NEW_PERSISTENT_RES(&tmp, -1, ret, le_pstream); - - if (NULL == zend_hash_str_update(&EG(persistent_list), persistent_id, - strlen(persistent_id), &tmp)) { + if (NULL == zend_register_persistent_resource(persistent_id, strlen(persistent_id), ret, le_pstream)) { pefree(ret, 1); return NULL; } @@ -629,7 +622,9 @@ PHPAPI void _php_stream_fill_read_buffer(php_stream *stream, size_t size) /* reduce buffer memory consumption if possible, to avoid a realloc */ if (stream->readbuf && stream->readbuflen - stream->writepos < stream->chunk_size) { - memmove(stream->readbuf, stream->readbuf + stream->readpos, stream->readbuflen - stream->readpos); + if (stream->writepos > stream->readpos) { + memmove(stream->readbuf, stream->readbuf + stream->readpos, stream->writepos - stream->readpos); + } stream->writepos -= stream->readpos; stream->readpos = 0; } @@ -1670,15 +1665,20 @@ static inline int php_stream_wrapper_scheme_validate(const char *protocol, unsig } /* API for registering GLOBAL wrappers */ -PHPAPI int php_register_url_stream_wrapper(const char *protocol, php_stream_wrapper *wrapper) +PHPAPI int php_register_url_stream_wrapper(const char *protocol, const php_stream_wrapper *wrapper) { unsigned int protocol_len = (unsigned int)strlen(protocol); + int ret; + zend_string *str; if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) { return FAILURE; } - return zend_hash_add_ptr(&url_stream_wrappers_hash, zend_string_init_interned(protocol, protocol_len, 1), wrapper) ? SUCCESS : FAILURE; + str = zend_string_init_interned(protocol, protocol_len, 1); + ret = zend_hash_add_ptr(&url_stream_wrappers_hash, str, (void*)wrapper) ? SUCCESS : FAILURE; + zend_string_release_ex(str, 1); + return ret; } PHPAPI int php_unregister_url_stream_wrapper(const char *protocol) @@ -1689,16 +1689,14 @@ PHPAPI int php_unregister_url_stream_wrapper(const char *protocol) static void clone_wrapper_hash(void) { ALLOC_HASHTABLE(FG(stream_wrappers)); - zend_hash_init(FG(stream_wrappers), zend_hash_num_elements(&url_stream_wrappers_hash), NULL, NULL, 1); + zend_hash_init(FG(stream_wrappers), zend_hash_num_elements(&url_stream_wrappers_hash), NULL, NULL, 0); zend_hash_copy(FG(stream_wrappers), &url_stream_wrappers_hash, NULL); } /* API for registering VOLATILE wrappers */ -PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_stream_wrapper *wrapper) +PHPAPI int php_register_url_stream_wrapper_volatile(zend_string *protocol, php_stream_wrapper *wrapper) { - unsigned int protocol_len = (unsigned int)strlen(protocol); - - if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) { + if (php_stream_wrapper_scheme_validate(ZSTR_VAL(protocol), ZSTR_LEN(protocol)) == FAILURE) { return FAILURE; } @@ -1706,16 +1704,16 @@ PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_st clone_wrapper_hash(); } - return zend_hash_str_add_ptr(FG(stream_wrappers), protocol, protocol_len, wrapper) ? SUCCESS : FAILURE; + return zend_hash_add_ptr(FG(stream_wrappers), protocol, wrapper) ? SUCCESS : FAILURE; } -PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol) +PHPAPI int php_unregister_url_stream_wrapper_volatile(zend_string *protocol) { if (!FG(stream_wrappers)) { clone_wrapper_hash(); } - return zend_hash_str_del(FG(stream_wrappers), protocol, strlen(protocol)); + return zend_hash_del(FG(stream_wrappers), protocol); } /* }}} */ @@ -1732,7 +1730,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const } if (options & IGNORE_URL) { - return (options & STREAM_LOCATE_WRAPPERS_ONLY) ? NULL : &php_plain_files_wrapper; + return (php_stream_wrapper*)((options & STREAM_LOCATE_WRAPPERS_ONLY) ? NULL : &php_plain_files_wrapper); } for (p = path; isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'; p++) { @@ -1744,10 +1742,11 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const } if (protocol) { - char *tmp = estrndup(protocol, n); - if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, (char*)tmp, n))) { + if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, protocol, n))) { + char *tmp = estrndup(protocol, n); + php_strtolower(tmp, n); - if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, (char*)tmp, n))) { + if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, tmp, n))) { char wrapper_name[32]; if (n >= sizeof(wrapper_name)) { @@ -1760,13 +1759,13 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const wrapper = NULL; protocol = NULL; } + efree(tmp); } - efree(tmp); } /* TODO: curl based streams probably support file:// properly */ if (!protocol || !strncasecmp(protocol, "file", n)) { /* fall back on regular file access */ - php_stream_wrapper *plain_files_wrapper = &php_plain_files_wrapper; + php_stream_wrapper *plain_files_wrapper = (php_stream_wrapper*)&php_plain_files_wrapper; if (protocol) { int localhost = 0; @@ -1815,7 +1814,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const } /* Check again, the original check might have not known the protocol name */ - if ((wrapper = zend_hash_str_find_ptr(wrapper_hash, "file", sizeof("file")-1)) != NULL) { + if ((wrapper = zend_hash_find_ex_ptr(wrapper_hash, ZSTR_KNOWN(ZEND_STR_FILE), 1)) != NULL) { return wrapper; } @@ -1835,13 +1834,11 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const PG(in_user_include)) && !PG(allow_url_include)))) { if (options & REPORT_ERRORS) { /* protocol[n] probably isn't '\0' */ - char *protocol_dup = estrndup(protocol, n); if (!PG(allow_url_fopen)) { - php_error_docref(NULL, E_WARNING, "%s:// wrapper is disabled in the server configuration by allow_url_fopen=0", protocol_dup); + php_error_docref(NULL, E_WARNING, "%.*s:// wrapper is disabled in the server configuration by allow_url_fopen=0", (int)n, protocol); } else { - php_error_docref(NULL, E_WARNING, "%s:// wrapper is disabled in the server configuration by allow_url_include=0", protocol_dup); + php_error_docref(NULL, E_WARNING, "%.*s:// wrapper is disabled in the server configuration by allow_url_include=0", (int)n, protocol); } - efree(protocol_dup); } return NULL; } @@ -2001,7 +1998,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod } if (options & USE_PATH) { - resolved_path = zend_resolve_path(path, (int)strlen(path)); + resolved_path = zend_resolve_path(path, strlen(path)); if (resolved_path) { path = ZSTR_VAL(resolved_path); /* we've found this file, don't re-check include_path or run realpath */ @@ -2016,7 +2013,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod if (options & STREAM_USE_URL && (!wrapper || !wrapper->is_url)) { php_error_docref(NULL, E_WARNING, "This function may only be used against URLs"); if (resolved_path) { - zend_string_release(resolved_path); + zend_string_release_ex(resolved_path, 0); } return NULL; } @@ -2069,7 +2066,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod ? PHP_STREAM_PREFER_STDIO : PHP_STREAM_NO_PREFERENCE)) { case PHP_STREAM_UNCHANGED: if (resolved_path) { - zend_string_release(resolved_path); + zend_string_release_ex(resolved_path, 0); } return stream; case PHP_STREAM_RELEASED: @@ -2078,7 +2075,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod } newstream->orig_path = pestrdup(path, persistent); if (resolved_path) { - zend_string_release(resolved_path); + zend_string_release_ex(resolved_path, 0); } return newstream; default: @@ -2108,7 +2105,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod if (stream == NULL && (options & REPORT_ERRORS)) { php_stream_display_wrapper_errors(wrapper, path, "failed to open stream"); if (opened_path && *opened_path) { - zend_string_release(*opened_path); + zend_string_release_ex(*opened_path, 0); *opened_path = NULL; } } @@ -2119,7 +2116,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod } #endif if (resolved_path) { - zend_string_release(resolved_path); + zend_string_release_ex(resolved_path, 0); } return stream; } @@ -2132,7 +2129,7 @@ PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream if (context) { stream->ctx = context->res; - GC_REFCOUNT(context->res)++; + GC_ADDREF(context->res); } else { stream->ctx = NULL; } @@ -2210,14 +2207,12 @@ PHPAPI int php_stream_context_set_option(php_stream_context *context, if (NULL == wrapperhash) { array_init(&category); wrapperhash = zend_hash_str_update(Z_ARRVAL(context->options), (char*)wrappername, strlen(wrappername), &category); - if (NULL == wrapperhash) { - return FAILURE; - } } ZVAL_DEREF(optionvalue); Z_TRY_ADDREF_P(optionvalue); SEPARATE_ARRAY(wrapperhash); - return zend_hash_str_update(Z_ARRVAL_P(wrapperhash), optionname, strlen(optionname), optionvalue) ? SUCCESS : FAILURE; + zend_hash_str_update(Z_ARRVAL_P(wrapperhash), optionname, strlen(optionname), optionvalue); + return SUCCESS; } /* }}} */ diff --git a/main/streams/transports.c b/main/streams/transports.c index c8925d5d37..1853f3ea9e 100644 --- a/main/streams/transports.c +++ b/main/streams/transports.c @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include "php.h" #include "php_streams_int.h" #include "ext/standard/file.h" @@ -31,7 +29,11 @@ PHPAPI HashTable *php_stream_xport_get_hash(void) PHPAPI int php_stream_xport_register(const char *protocol, php_stream_transport_factory factory) { - return zend_hash_str_update_ptr(&xport_hash, protocol, strlen(protocol), factory) ? SUCCESS : FAILURE; + zend_string *str = zend_string_init_interned(protocol, strlen(protocol), 1); + + zend_hash_update_ptr(&xport_hash, str, factory); + zend_string_release_ex(str, 1); + return SUCCESS; } PHPAPI int php_stream_xport_unregister(const char *protocol) @@ -46,7 +48,7 @@ PHPAPI int php_stream_xport_unregister(const char *protocol) #define ERR_RETURN(out_err, local_err, fmt) \ if (out_err) { *out_err = local_err; } \ else { php_error_docref(NULL, E_WARNING, fmt, local_err ? ZSTR_VAL(local_err) : "Unspecified error"); \ - if (local_err) { zend_string_release(local_err); local_err = NULL; } \ + if (local_err) { zend_string_release_ex(local_err, 0); local_err = NULL; } \ } PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, int options, @@ -107,8 +109,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in } if (protocol) { - char *tmp = estrndup(protocol, n); - if (NULL == (factory = zend_hash_str_find_ptr(&xport_hash, tmp, n))) { + if (NULL == (factory = zend_hash_str_find_ptr(&xport_hash, protocol, n))) { char wrapper_name[32]; if (n >= sizeof(wrapper_name)) @@ -118,10 +119,8 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in ERR_REPORT(error_string, "Unable to find the socket transport \"%s\" - did you forget to enable it when you configured PHP?", wrapper_name); - efree(tmp); return NULL; } - efree(tmp); } if (factory == NULL) { @@ -162,13 +161,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in int backlog = 32; if (PHP_STREAM_CONTEXT(stream) && (zbacklog = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "socket", "backlog")) != NULL) { - zval *ztmp = zbacklog; - - convert_to_long_ex(ztmp); - backlog = Z_LVAL_P(ztmp); - if (ztmp != zbacklog) { - zval_ptr_dtor(ztmp); - } + backlog = zval_get_long(zbacklog); } if (0 != php_stream_xport_listen(stream, backlog, &error_text)) { diff --git a/main/streams/userspace.c b/main/streams/userspace.c index 4925e41ac3..3b513cb7f1 100644 --- a/main/streams/userspace.c +++ b/main/streams/userspace.c @@ -17,8 +17,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include "php.h" #include "php_globals.h" #include "ext/standard/file.h" @@ -55,7 +53,7 @@ static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, i static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char *filename, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC); -static php_stream_wrapper_ops user_stream_wops = { +static const php_stream_wrapper_ops user_stream_wops = { user_wrapper_opener, NULL, /* close - the streams themselves know how */ NULL, /* stat - the streams themselves know how */ @@ -296,7 +294,7 @@ static void user_stream_create_object(struct php_user_stream_wrapper *uwrap, php if (context) { add_property_resource(object, "context", context->res); - GC_REFCOUNT(context->res)++; + GC_ADDREF(context->res); } else { add_property_null(object, "context"); } @@ -314,15 +312,13 @@ static void user_stream_create_object(struct php_user_stream_wrapper *uwrap, php fci.params = NULL; fci.no_separation = 1; - fcc.initialized = 1; fcc.function_handler = uwrap->ce->constructor; - fcc.calling_scope = zend_get_executed_scope(); fcc.called_scope = Z_OBJCE_P(object); fcc.object = Z_OBJ_P(object); if (zend_call_function(&fci, &fcc) == FAILURE) { php_error_docref(NULL, E_WARNING, "Could not execute %s::%s()", ZSTR_VAL(uwrap->ce->name), ZSTR_VAL(uwrap->ce->constructor->common.function_name)); - zval_dtor(object); + zval_ptr_dtor(object); ZVAL_UNDEF(object); } else { zval_ptr_dtor(&retval); @@ -494,7 +490,7 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char } -/* {{{ proto bool stream_wrapper_register(string protocol, string classname[, integer flags]) +/* {{{ proto bool stream_wrapper_register(string protocol, string classname[, int flags]) Registers a custom URL protocol handler class */ PHP_FUNCTION(stream_wrapper_register) { @@ -517,7 +513,7 @@ PHP_FUNCTION(stream_wrapper_register) rsrc = zend_register_resource(uwrap, le_protocols); if ((uwrap->ce = zend_lookup_class(classname)) != NULL) { - if (php_register_url_stream_wrapper_volatile(ZSTR_VAL(protocol), &uwrap->wrapper) == SUCCESS) { + if (php_register_url_stream_wrapper_volatile(protocol, &uwrap->wrapper) == SUCCESS) { RETURN_TRUE; } else { /* We failed. But why? */ @@ -541,16 +537,15 @@ PHP_FUNCTION(stream_wrapper_register) Unregister a wrapper for the life of the current request. */ PHP_FUNCTION(stream_wrapper_unregister) { - char *protocol; - size_t protocol_len; + zend_string *protocol; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &protocol, &protocol_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &protocol) == FAILURE) { RETURN_FALSE; } if (php_unregister_url_stream_wrapper_volatile(protocol) == FAILURE) { /* We failed */ - php_error_docref(NULL, E_WARNING, "Unable to unregister protocol %s://", protocol); + php_error_docref(NULL, E_WARNING, "Unable to unregister protocol %s://", ZSTR_VAL(protocol)); RETURN_FALSE; } @@ -582,9 +577,9 @@ PHP_FUNCTION(stream_wrapper_restore) } /* A failure here could be okay given that the protocol might have been merely unregistered */ - php_unregister_url_stream_wrapper_volatile(ZSTR_VAL(protocol)); + php_unregister_url_stream_wrapper_volatile(protocol); - if (php_register_url_stream_wrapper_volatile(ZSTR_VAL(protocol), wrapper) == FAILURE) { + if (php_register_url_stream_wrapper_volatile(protocol, wrapper) == FAILURE) { php_error_docref(NULL, E_WARNING, "Unable to restore original %s:// wrapper", ZSTR_VAL(protocol)); RETURN_FALSE; } @@ -695,11 +690,11 @@ static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count) ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1); - call_result = call_user_function_ex(NULL, + call_result = call_user_function(NULL, Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, - 0, NULL, 0, NULL); + 0, NULL); if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF && zval_is_true(&retval)) { stream->eof = 1; @@ -727,11 +722,11 @@ static int php_userstreamop_close(php_stream *stream, int close_handle) ZVAL_STRINGL(&func_name, USERSTREAM_CLOSE, sizeof(USERSTREAM_CLOSE)-1); - call_user_function_ex(NULL, + call_user_function(NULL, Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, - 0, NULL, 0, NULL); + 0, NULL); zval_ptr_dtor(&retval); zval_ptr_dtor(&func_name); @@ -755,11 +750,11 @@ static int php_userstreamop_flush(php_stream *stream) ZVAL_STRINGL(&func_name, USERSTREAM_FLUSH, sizeof(USERSTREAM_FLUSH)-1); - call_result = call_user_function_ex(NULL, + call_result = call_user_function(NULL, Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, - 0, NULL, 0, NULL); + 0, NULL); if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF && zval_is_true(&retval)) call_result = 0; @@ -822,11 +817,11 @@ static int php_userstreamop_seek(php_stream *stream, zend_off_t offset, int when /* now determine where we are */ ZVAL_STRINGL(&func_name, USERSTREAM_TELL, sizeof(USERSTREAM_TELL)-1); - call_result = call_user_function_ex(NULL, + call_result = call_user_function(NULL, Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, - 0, NULL, 0, NULL); + 0, NULL); if (call_result == SUCCESS && Z_TYPE(retval) == IS_LONG) { *newoffs = Z_LVAL(retval); @@ -863,14 +858,14 @@ static int statbuf_from_array(zval *array, php_stream_statbuf *ssb) STAT_PROP_ENTRY(nlink); STAT_PROP_ENTRY(uid); STAT_PROP_ENTRY(gid); -#if HAVE_ST_RDEV +#if HAVE_STRUCT_STAT_ST_RDEV STAT_PROP_ENTRY(rdev); #endif STAT_PROP_ENTRY(size); STAT_PROP_ENTRY(atime); STAT_PROP_ENTRY(mtime); STAT_PROP_ENTRY(ctime); -#ifdef HAVE_ST_BLKSIZE +#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE STAT_PROP_ENTRY(blksize); #endif #ifdef HAVE_ST_BLOCKS @@ -892,11 +887,11 @@ static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb) ZVAL_STRINGL(&func_name, USERSTREAM_STAT, sizeof(USERSTREAM_STAT)-1); - call_result = call_user_function_ex(NULL, + call_result = call_user_function(NULL, Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, - 0, NULL, 0, NULL); + 0, NULL); if (call_result == SUCCESS && Z_TYPE(retval) == IS_ARRAY) { if (SUCCESS == statbuf_from_array(&retval, ssb)) @@ -926,7 +921,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value switch (option) { case PHP_STREAM_OPTION_CHECK_LIVENESS: ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1); - call_result = call_user_function_ex(NULL, Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 0, NULL, 0, NULL); + call_result = call_user_function(NULL, Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 0, NULL); if (call_result == SUCCESS && (Z_TYPE(retval) == IS_FALSE || Z_TYPE(retval) == IS_TRUE)) { ret = zval_is_true(&retval) ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK; } else { @@ -1075,7 +1070,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_SET_OPTION " is not implemented!", us->wrapper->classname); ret = PHP_STREAM_OPTION_RETURN_ERR; - } else if (Z_TYPE(retval) != IS_UNDEF && zend_is_true(&retval)) { + } else if (zend_is_true(&retval)) { ret = PHP_STREAM_OPTION_RETURN_OK; } else { ret = PHP_STREAM_OPTION_RETURN_ERR; @@ -1418,11 +1413,10 @@ static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t cou ZVAL_STRINGL(&func_name, USERSTREAM_DIR_READ, sizeof(USERSTREAM_DIR_READ)-1); - call_result = call_user_function_ex(NULL, + call_result = call_user_function(NULL, Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, - 0, NULL, 0, NULL); if (call_result == SUCCESS && Z_TYPE(retval) != IS_FALSE && Z_TYPE(retval) != IS_TRUE) { @@ -1451,11 +1445,11 @@ static int php_userstreamop_closedir(php_stream *stream, int close_handle) ZVAL_STRINGL(&func_name, USERSTREAM_DIR_CLOSE, sizeof(USERSTREAM_DIR_CLOSE)-1); - call_user_function_ex(NULL, + call_user_function(NULL, Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, - 0, NULL, 0, NULL); + 0, NULL); zval_ptr_dtor(&retval); zval_ptr_dtor(&func_name); @@ -1475,11 +1469,11 @@ static int php_userstreamop_rewinddir(php_stream *stream, zend_off_t offset, int ZVAL_STRINGL(&func_name, USERSTREAM_DIR_REWIND, sizeof(USERSTREAM_DIR_REWIND)-1); - call_user_function_ex(NULL, + call_user_function(NULL, Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, - 0, NULL, 0, NULL); + 0, NULL); zval_ptr_dtor(&retval); zval_ptr_dtor(&func_name); @@ -1521,7 +1515,7 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr) us->wrapper->classname); break; } - if (Z_ISUNDEF(retval) || !zend_is_true(&retval)) { + if (!zend_is_true(&retval)) { break; } php_stream_from_zval_no_verify(intstream, &retval); @@ -1546,7 +1540,7 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr) return ret; } -php_stream_ops php_stream_userspace_ops = { +const php_stream_ops php_stream_userspace_ops = { php_userstreamop_write, php_userstreamop_read, php_userstreamop_close, php_userstreamop_flush, "user-space", @@ -1556,7 +1550,7 @@ php_stream_ops php_stream_userspace_ops = { php_userstreamop_set_option, }; -php_stream_ops php_stream_userspace_dir_ops = { +const php_stream_ops php_stream_userspace_dir_ops = { NULL, /* write */ php_userstreamop_readdir, php_userstreamop_closedir, diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index f0f45f76e0..acdb1f8876 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include "php.h" #include "ext/standard/file.h" #include "streams/php_streams_int.h" @@ -46,12 +44,12 @@ # define XP_SOCK_BUF_SIZE(sz) (sz) #endif -php_stream_ops php_stream_generic_socket_ops; -PHPAPI php_stream_ops php_stream_socket_ops; -php_stream_ops php_stream_udp_socket_ops; +const php_stream_ops php_stream_generic_socket_ops; +PHPAPI const php_stream_ops php_stream_socket_ops; +const php_stream_ops php_stream_udp_socket_ops; #ifdef AF_UNIX -php_stream_ops php_stream_unix_socket_ops; -php_stream_ops php_stream_unixdg_socket_ops; +const php_stream_ops php_stream_unix_socket_ops; +const php_stream_ops php_stream_unixdg_socket_ops; #endif @@ -484,7 +482,7 @@ static int php_sockop_cast(php_stream *stream, int castas, void **ret) * A "useful" side-effect is that the user's scripts can then * make similar decisions using stream_get_meta_data. * */ -php_stream_ops php_stream_generic_socket_ops = { +const php_stream_ops php_stream_generic_socket_ops = { php_sockop_write, php_sockop_read, php_sockop_close, php_sockop_flush, "generic_socket", @@ -495,7 +493,7 @@ php_stream_ops php_stream_generic_socket_ops = { }; -php_stream_ops php_stream_socket_ops = { +const php_stream_ops php_stream_socket_ops = { php_sockop_write, php_sockop_read, php_sockop_close, php_sockop_flush, "tcp_socket", @@ -505,7 +503,7 @@ php_stream_ops php_stream_socket_ops = { php_tcp_sockop_set_option, }; -php_stream_ops php_stream_udp_socket_ops = { +const php_stream_ops php_stream_udp_socket_ops = { php_sockop_write, php_sockop_read, php_sockop_close, php_sockop_flush, "udp_socket", @@ -516,7 +514,7 @@ php_stream_ops php_stream_udp_socket_ops = { }; #ifdef AF_UNIX -php_stream_ops php_stream_unix_socket_ops = { +const php_stream_ops php_stream_unix_socket_ops = { php_sockop_write, php_sockop_read, php_sockop_close, php_sockop_flush, "unix_socket", @@ -525,7 +523,7 @@ php_stream_ops php_stream_unix_socket_ops = { php_sockop_stat, php_tcp_sockop_set_option, }; -php_stream_ops php_stream_unixdg_socket_ops = { +const php_stream_ops php_stream_unixdg_socket_ops = { php_sockop_write, php_sockop_read, php_sockop_close, php_sockop_flush, "udg_socket", @@ -835,7 +833,7 @@ static inline int php_tcp_sockop_accept(php_stream *stream, php_netstream_data_t if (xparam->outputs.client) { xparam->outputs.client->ctx = stream->ctx; if (stream->ctx) { - GC_REFCOUNT(stream->ctx)++; + GC_ADDREF(stream->ctx); } } } @@ -883,7 +881,7 @@ PHPAPI php_stream *php_stream_generic_socket_factory(const char *proto, size_t p { php_stream *stream = NULL; php_netstream_data_t *sock; - php_stream_ops *ops; + const php_stream_ops *ops; /* which type of socket ? */ if (strncmp(proto, "tcp", protolen) == 0) { diff --git a/main/strlcat.c b/main/strlcat.c index f138c86c73..2050c67070 100644 --- a/main/strlcat.c +++ b/main/strlcat.c @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include "php.h" #ifdef USE_STRLCAT_PHP_IMPL diff --git a/main/strlcpy.c b/main/strlcpy.c index 403dfe6c86..5c19ced513 100644 --- a/main/strlcpy.c +++ b/main/strlcpy.c @@ -16,8 +16,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include "php.h" #ifdef USE_STRLCPY_PHP_IMPL |
