summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorMark A. Hershberger <mah@debian.(none)>2009-03-25 00:37:27 -0400
committerMark A. Hershberger <mah@debian.(none)>2009-03-25 00:37:27 -0400
commit2d4e5b09576bb4f0ba716cc82cdf29ea04d9184b (patch)
tree41ccc042009cba53e4ce43e727fcba4c1cfbf7f3 /main
parentd29a4fd2dd3b5d4cf6e80b602544d7b71d794e76 (diff)
downloadphp-upstream/5.2.2.tar.gz
Imported Upstream version 5.2.2upstream/5.2.2
Diffstat (limited to 'main')
-rw-r--r--main/SAPI.c92
-rw-r--r--main/SAPI.h4
-rw-r--r--main/build-defs.h.in4
-rw-r--r--main/config.w32.h4
-rw-r--r--main/fopen_wrappers.c126
-rw-r--r--main/fopen_wrappers.h4
-rw-r--r--main/internal_functions.c.in4
-rw-r--r--main/internal_functions_nw.c4
-rw-r--r--main/internal_functions_win32.c4
-rw-r--r--main/logos.h4
-rw-r--r--main/main.c100
-rw-r--r--main/network.c8
-rw-r--r--main/output.c33
-rw-r--r--main/php.h8
-rw-r--r--main/php3_compat.h4
-rw-r--r--main/php_compat.h23
-rw-r--r--main/php_config.h.in78
-rw-r--r--main/php_content_types.c6
-rw-r--r--main/php_content_types.h4
-rw-r--r--main/php_globals.h8
-rw-r--r--main/php_ini.c48
-rw-r--r--main/php_ini.h4
-rw-r--r--main/php_logos.c19
-rw-r--r--main/php_logos.h4
-rw-r--r--main/php_main.h5
-rw-r--r--main/php_memory_streams.h12
-rw-r--r--main/php_network.h4
-rw-r--r--main/php_open_temporary_file.c22
-rw-r--r--main/php_open_temporary_file.h5
-rw-r--r--main/php_output.h4
-rw-r--r--main/php_reentrancy.h4
-rw-r--r--main/php_regex.h4
-rw-r--r--main/php_scandir.c11
-rw-r--r--main/php_scandir.h4
-rw-r--r--main/php_sprintf.c4
-rwxr-xr-xmain/php_streams.h6
-rw-r--r--main/php_syslog.h4
-rw-r--r--main/php_ticks.c4
-rw-r--r--main/php_ticks.h4
-rw-r--r--main/php_variables.c39
-rw-r--r--main/php_variables.h4
-rw-r--r--main/php_version.h6
-rw-r--r--main/reentrancy.c8
-rw-r--r--main/rfc1867.c51
-rw-r--r--main/rfc1867.h4
-rw-r--r--main/safe_mode.c58
-rw-r--r--main/safe_mode.h4
-rw-r--r--main/snprintf.c611
-rw-r--r--main/snprintf.h53
-rw-r--r--main/spprintf.c38
-rw-r--r--main/spprintf.h4
-rw-r--r--main/streams/cast.c4
-rw-r--r--main/streams/filter.c18
-rw-r--r--main/streams/memory.c65
-rw-r--r--main/streams/mmap.c4
-rw-r--r--main/streams/php_stream_context.h4
-rw-r--r--main/streams/php_stream_filter_api.h4
-rw-r--r--main/streams/php_stream_mmap.h4
-rw-r--r--main/streams/php_stream_plain_wrapper.h4
-rw-r--r--main/streams/php_stream_transport.h19
-rw-r--r--main/streams/php_stream_userspace.h4
-rw-r--r--main/streams/php_streams_int.h4
-rw-r--r--main/streams/plain_wrapper.c197
-rwxr-xr-xmain/streams/streams.c36
-rw-r--r--main/streams/transports.c34
-rw-r--r--main/streams/userspace.c30
-rw-r--r--main/streams/xp_socket.c23
-rw-r--r--main/strlcat.c4
-rw-r--r--main/strlcpy.c4
-rw-r--r--main/win95nt.h4
70 files changed, 1277 insertions, 763 deletions
diff --git a/main/SAPI.c b/main/SAPI.c
index 0dda75c65..f2ba51ac6 100644
--- a/main/SAPI.c
+++ b/main/SAPI.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: SAPI.c,v 1.202.2.7.2.2 2006/09/19 20:33:11 dmitry Exp $ */
+/* $Id: SAPI.c,v 1.202.2.7.2.13 2007/04/25 14:18:01 dmitry Exp $ */
#include <ctype.h>
#include <sys/stat.h>
@@ -540,32 +540,32 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
}
switch (op) {
- case SAPI_HEADER_SET_STATUS:
- sapi_update_response_code((long) arg TSRMLS_CC);
- return SUCCESS;
+ case SAPI_HEADER_SET_STATUS:
+ sapi_update_response_code((int)(zend_intptr_t) arg TSRMLS_CC);
+ return SUCCESS;
+
+ case SAPI_HEADER_REPLACE:
+ case SAPI_HEADER_ADD: {
+ sapi_header_line *p = arg;
- case SAPI_HEADER_REPLACE:
- case SAPI_HEADER_ADD: {
- sapi_header_line *p = arg;
-
- if (!p->line || !p->line_len) {
+ if (!p->line || !p->line_len) {
+ return FAILURE;
+ }
+ header_line = p->line;
+ header_line_len = p->line_len;
+ http_response_code = p->response_code;
+ replace = (op == SAPI_HEADER_REPLACE);
+ break;
+ }
+
+ default:
return FAILURE;
- }
- header_line = p->line;
- header_line_len = p->line_len;
- http_response_code = p->response_code;
- replace = (op == SAPI_HEADER_REPLACE);
- break;
- }
-
- default:
- return FAILURE;
}
header_line = estrndup(header_line, header_line_len);
/* cut of trailing spaces, linefeeds and carriage-returns */
- while(isspace(header_line[header_line_len-1]))
+ while(header_line_len && isspace(header_line[header_line_len-1]))
header_line[--header_line_len]='\0';
/* new line safety check */
@@ -631,7 +631,9 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
SG(sapi_headers).http_response_code > 307) &&
SG(sapi_headers).http_response_code != 201) {
/* Return a Found Redirect if one is not already specified */
- if(SG(request_info).proto_num > 1000 &&
+ if (http_response_code) { /* user specified redirect code */
+ sapi_update_response_code(http_response_code TSRMLS_CC);
+ } else if (SG(request_info).proto_num > 1000 &&
SG(request_info).request_method &&
strcmp(SG(request_info).request_method, "HEAD") &&
strcmp(SG(request_info).request_method, "GET")) {
@@ -661,8 +663,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
ptr_len = strlen(ptr);
MAKE_STD_ZVAL(repl_temp);
Z_TYPE_P(repl_temp) = IS_STRING;
- Z_STRVAL_P(repl_temp) = emalloc(32);
- Z_STRLEN_P(repl_temp) = sprintf(Z_STRVAL_P(repl_temp), "realm=\"\\1-%ld\"", myuid);
+ Z_STRLEN_P(repl_temp) = spprintf(&Z_STRVAL_P(repl_temp), 0, "realm=\"\\1-%ld\"", myuid);
/* Modify quoted realm value */
result = php_pcre_replace("/realm=\"(.*?)\"/i", 16,
ptr, ptr_len,
@@ -670,7 +671,8 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
0, &result_len, -1, NULL TSRMLS_CC);
if(result_len==ptr_len) {
efree(result);
- sprintf(Z_STRVAL_P(repl_temp), "realm=\\1-%ld\\2", myuid);
+ efree(Z_STRVAL_P(repl_temp));
+ Z_STRLEN_P(repl_temp) = spprintf(&Z_STRVAL_P(repl_temp), 0, "realm=\\1-%ld\\2", myuid);
/* modify unquoted realm value */
result = php_pcre_replace("/realm=([^\\s]+)(.*)/i", 21,
ptr, ptr_len,
@@ -685,7 +687,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
/* If there is no realm string at all, append one */
if(!strstr(lower_temp,"realm")) {
efree(result);
- conv_len = sprintf(conv_temp, " realm=\"%ld\"",myuid);
+ conv_len = slprintf(conv_temp, sizeof(conv_temp), " realm=\"%ld\"",myuid);
result = emalloc(ptr_len+conv_len+1);
result_len = ptr_len+conv_len;
memcpy(result, ptr, ptr_len);
@@ -695,9 +697,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
efree(lower_temp);
}
}
- newlen = sizeof("WWW-Authenticate: ") - 1 + result_len;
- newheader = emalloc(newlen+1);
- sprintf(newheader,"WWW-Authenticate: %s", result);
+ newlen = spprintf(&newheader, 0, "WWW-Authenticate: %s", result);
efree(header_line);
sapi_header.header = newheader;
sapi_header.header_len = newlen;
@@ -774,7 +774,7 @@ SAPI_API int sapi_send_headers(TSRMLS_D)
assert(Z_STRVAL_P(uf_result) != NULL);
- len = snprintf(buf, sizeof(buf), "Content-Encoding: %s", Z_STRVAL_P(uf_result));
+ len = slprintf(buf, sizeof(buf), "Content-Encoding: %s", Z_STRVAL_P(uf_result));
if (len <= 0 || sapi_add_header(buf, len, 1) == FAILURE) {
return FAILURE;
}
@@ -818,7 +818,7 @@ SAPI_API int sapi_send_headers(TSRMLS_D)
http_status_line.header_len = strlen(SG(sapi_headers).http_status_line);
} else {
http_status_line.header = buf;
- http_status_line.header_len = sprintf(buf, "HTTP/1.0 %d X", SG(sapi_headers).http_response_code);
+ http_status_line.header_len = slprintf(buf, sizeof(buf), "HTTP/1.0 %d X", SG(sapi_headers).http_response_code);
}
sapi_module.send_header(&http_status_line, SG(server_context) TSRMLS_CC);
}
@@ -861,6 +861,9 @@ SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entries TSRMLS_DC)
SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry TSRMLS_DC)
{
+ if (SG(sapi_started) && EG(in_execution)) {
+ return FAILURE;
+ }
return zend_hash_add(&SG(known_post_content_types),
post_entry->content_type, post_entry->content_type_len+1,
(void *) post_entry, sizeof(sapi_post_entry), NULL);
@@ -868,6 +871,9 @@ SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry TSRMLS_DC)
SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry TSRMLS_DC)
{
+ if (SG(sapi_started) && EG(in_execution)) {
+ return;
+ }
zend_hash_del(&SG(known_post_content_types), post_entry->content_type,
post_entry->content_type_len+1);
}
@@ -875,6 +881,10 @@ SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry TSRMLS_DC)
SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRMLS_D))
{
+ TSRMLS_FETCH();
+ if (SG(sapi_started) && EG(in_execution)) {
+ return FAILURE;
+ }
sapi_module.default_post_reader = default_post_reader;
return SUCCESS;
}
@@ -882,12 +892,20 @@ SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRML
SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC))
{
+ TSRMLS_FETCH();
+ if (SG(sapi_started) && EG(in_execution)) {
+ return FAILURE;
+ }
sapi_module.treat_data = treat_data;
return SUCCESS;
}
SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, char *var, char **val, unsigned int val_len, unsigned int *new_val_len TSRMLS_DC))
{
+ TSRMLS_FETCH();
+ if (SG(sapi_started) && EG(in_execution)) {
+ return FAILURE;
+ }
sapi_module.input_filter = input_filter;
return SUCCESS;
}
@@ -918,13 +936,15 @@ SAPI_API char *sapi_getenv(char *name, size_t name_len TSRMLS_DC)
{
if (sapi_module.getenv) {
char *value, *tmp = sapi_module.getenv(name, name_len TSRMLS_CC);
- if(tmp) value = estrdup(tmp);
- else return NULL;
+ if (tmp) {
+ value = estrdup(tmp);
+ } else {
+ return NULL;
+ }
sapi_module.input_filter(PARSE_ENV, name, &value, strlen(value), NULL TSRMLS_CC);
return value;
- } else {
- return NULL;
- }
+ }
+ return NULL;
}
SAPI_API int sapi_get_fd(int *fd TSRMLS_DC)
diff --git a/main/SAPI.h b/main/SAPI.h
index 479376ad7..9fdeb8ba5 100644
--- a/main/SAPI.h
+++ b/main/SAPI.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: SAPI.h,v 1.114.2.1.2.1 2006/09/19 20:33:11 dmitry Exp $ */
+/* $Id: SAPI.h,v 1.114.2.1.2.2 2007/01/01 09:36:10 sebastian Exp $ */
#ifndef SAPI_H
#define SAPI_H
diff --git a/main/build-defs.h.in b/main/build-defs.h.in
index 240d2a578..d9f8f8211 100644
--- a/main/build-defs.h.in
+++ b/main/build-defs.h.in
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: build-defs.h.in,v 1.15.2.2 2006/04/08 17:53:11 andrei Exp $ */
+/* $Id: build-defs.h.in,v 1.15.2.2.2.1 2007/01/01 19:32:09 iliaa Exp $ */
#define CONFIGURE_COMMAND "@CONFIGURE_COMMAND@"
#define PHP_ADA_INCLUDE ""
diff --git a/main/config.w32.h b/main/config.w32.h
index 3998092c3..54be78a34 100644
--- a/main/config.w32.h
+++ b/main/config.w32.h
@@ -2,7 +2,7 @@
Build Configuration for Win32.
This has only been tested with MS VisualC++ 6 (and later).
- $Id: config.w32.h,v 1.85.4.1.2.1 2006/06/05 09:00:15 stas Exp $
+ $Id: config.w32.h,v 1.85.4.1.2.2 2006/11/10 09:56:16 dmitry Exp $
*/
/* Default PHP / PEAR directories */
@@ -162,7 +162,7 @@
#define HAVE_ASSERT_H 1
#define HAVE_FCNTL_H 1
#define HAVE_GRP_H 0
-#define HAVE_PWD_H 1
+#undef HAVE_PWD_H
#define HAVE_STRING_H 1
#undef HAVE_SYS_FILE_H
#undef HAVE_SYS_SOCKET_H
diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c
index 6df4ada7e..41b0f2033 100644
--- a/main/fopen_wrappers.c
+++ b/main/fopen_wrappers.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: fopen_wrappers.c,v 1.175.2.3.2.1 2006/07/01 11:35:34 nlopess Exp $ */
+/* $Id: fopen_wrappers.c,v 1.175.2.3.2.11 2007/04/18 11:58:40 dmitry Exp $ */
/* {{{ includes
*/
@@ -46,12 +46,8 @@
#include "php_network.h"
#if HAVE_PWD_H
-#ifdef PHP_WIN32
-#include "win32/pwd.h"
-#else
#include <pwd.h>
#endif
-#endif
#include <sys/types.h>
#if HAVE_SYS_SOCKET_H
@@ -94,8 +90,12 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path
char resolved_name[MAXPATHLEN];
char resolved_basedir[MAXPATHLEN];
char local_open_basedir[MAXPATHLEN];
+ char path_tmp[MAXPATHLEN];
+ char *path_file;
int resolved_basedir_len;
int resolved_name_len;
+ int path_len;
+ int nesting_level = 0;
/* Special case basedir==".": Use script-directory */
if (strcmp(basedir, ".") || !VCWD_GETCWD(local_open_basedir, MAXPATHLEN)) {
@@ -103,8 +103,66 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path
strlcpy(local_open_basedir, basedir, sizeof(local_open_basedir));
}
- /* Resolve the real path into resolved_name */
- if ((expand_filepath(path, resolved_name TSRMLS_CC) != NULL) && (expand_filepath(local_open_basedir, resolved_basedir TSRMLS_CC) != NULL)) {
+ path_len = strlen(path);
+ if (path_len > (MAXPATHLEN - 1)) {
+ /* empty and too long paths are invalid */
+ return -1;
+ }
+
+ /* normalize and expand path */
+ if (expand_filepath(path, resolved_name TSRMLS_CC) == NULL) {
+ return -1;
+ }
+
+ path_len = strlen(resolved_name);
+ memcpy(path_tmp, resolved_name, path_len + 1); /* safe */
+
+ while (VCWD_REALPATH(path_tmp, resolved_name) == NULL) {
+#ifdef HAVE_SYMLINK
+ if (nesting_level == 0) {
+ int ret;
+ char buf[MAXPATHLEN];
+
+ ret = readlink(path_tmp, buf, MAXPATHLEN - 1);
+ if (ret < 0) {
+ /* not a broken symlink, move along.. */
+ } else {
+ /* put the real path into the path buffer */
+ memcpy(path_tmp, buf, ret);
+ path_tmp[ret] = '\0';
+ }
+ }
+#endif
+
+#if defined(PHP_WIN32) || defined(NETWARE)
+ path_file = strrchr(path_tmp, DEFAULT_SLASH);
+ if (!path_file) {
+ path_file = strrchr(path_tmp, '/');
+ }
+#else
+ path_file = strrchr(path_tmp, DEFAULT_SLASH);
+#endif
+ if (!path_file) {
+ /* none of the path components exist. definitely not in open_basedir.. */
+ return -1;
+ } else {
+ path_len = path_file - path_tmp + 1;
+#if defined(PHP_WIN32) || defined(NETWARE)
+ if (path_len > 1 && path_tmp[path_len - 2] == ':') {
+ /* this is c:\, */
+ path_tmp[path_len] = '\0';
+ } else {
+ path_tmp[path_len - 1] = '\0';
+ }
+#else
+ path_tmp[path_len - 1] = '\0';
+#endif
+ }
+ nesting_level++;
+ }
+
+ /* Resolve open_basedir to resolved_basedir */
+ if (expand_filepath(local_open_basedir, resolved_basedir TSRMLS_CC) != NULL) {
/* Handler for basedirs that end with a / */
resolved_basedir_len = strlen(resolved_basedir);
if (basedir[strlen(basedir) - 1] == PHP_DIR_SEPARATOR) {
@@ -114,7 +172,7 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path
}
}
- if (path[strlen(path)-1] == PHP_DIR_SEPARATOR) {
+ if (path_tmp[path_len - 1] == PHP_DIR_SEPARATOR) {
resolved_name_len = strlen(resolved_name);
if (resolved_name[resolved_name_len - 1] != PHP_DIR_SEPARATOR) {
resolved_name[resolved_name_len] = PHP_DIR_SEPARATOR;
@@ -259,39 +317,56 @@ static FILE *php_fopen_and_set_opened_path(const char *path, const char *mode, c
PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle TSRMLS_DC)
{
FILE *fp;
+#ifndef PHP_WIN32
struct stat st;
+#endif
char *path_info, *filename;
int length;
filename = SG(request_info).path_translated;
path_info = SG(request_info).request_uri;
#if HAVE_PWD_H
- if (PG(user_dir) && *PG(user_dir)
- && path_info && '/' == path_info[0] && '~' == path_info[1]) {
-
- char user[32];
- struct passwd *pw;
+ if (PG(user_dir) && *PG(user_dir) && path_info && '/' == path_info[0] && '~' == path_info[1]) {
char *s = strchr(path_info + 2, '/');
filename = NULL; /* discard the original filename, it must not be used */
if (s) { /* if there is no path name after the file, do not bother */
- /* to try open the directory */
+ char user[32]; /* to try open the directory */
+ struct passwd *pw;
+#if defined(ZTS) && defined(HAVE_GETPWNAM_R) && defined(_SC_GETPW_R_SIZE_MAX)
+ struct passwd pwstruc;
+ long pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
+ char *pwbuf;
+
+ if (pwbuflen < 1) {
+ return FAILURE;
+ }
+
+ pwbuf = emalloc(pwbuflen);
+#endif
length = s - (path_info + 2);
- if (length > (int)sizeof(user) - 1)
+ if (length > (int)sizeof(user) - 1) {
length = sizeof(user) - 1;
+ }
memcpy(user, path_info + 2, length);
user[length] = '\0';
-
+#if defined(ZTS) && defined(HAVE_GETPWNAM_R) && defined(_SC_GETPW_R_SIZE_MAX)
+ if (getpwnam_r(user, &pwstruc, pwbuf, pwbuflen, &pw)) {
+ efree(pwbuf);
+ return FAILURE;
+ }
+#else
pw = getpwnam(user);
+#endif
if (pw && pw->pw_dir) {
- filename = emalloc(strlen(PG(user_dir)) + strlen(path_info) + strlen(pw->pw_dir) + 4);
- if (filename) {
- sprintf(filename, "%s%c%s%c%s", pw->pw_dir, PHP_DIR_SEPARATOR,
+ spprintf(&filename, 0, "%s%c%s%c%s", pw->pw_dir, PHP_DIR_SEPARATOR,
PG(user_dir), PHP_DIR_SEPARATOR, s+1); /* Safe */
- STR_FREE(SG(request_info).path_translated);
- SG(request_info).path_translated = filename;
- }
+ STR_FREE(SG(request_info).path_translated);
+ SG(request_info).path_translated = filename;
}
+#if defined(ZTS) && defined(HAVE_GETPWNAM_R) && defined(_SC_GETPW_R_SIZE_MAX)
+ efree(pwbuf);
+#endif
}
} else
#endif
@@ -325,11 +400,14 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle TSRMLS_DC)
}
fp = VCWD_FOPEN(filename, "rb");
+#ifndef PHP_WIN32
/* refuse to open anything that is not a regular file */
if (fp && (0 > fstat(fileno(fp), &st) || !S_ISREG(st.st_mode))) {
fclose(fp);
fp = NULL;
}
+#endif
+
if (!fp) {
STR_FREE(SG(request_info).path_translated); /* for same reason as above */
SG(request_info).path_translated = NULL;
@@ -530,7 +608,7 @@ PHPAPI char *expand_filepath(const char *filepath, char *real_path TSRMLS_DC)
new_state.cwd = strdup(cwd);
new_state.cwd_length = strlen(cwd);
- if(virtual_file_ex(&new_state, filepath, NULL, 1)) {
+ if(virtual_file_ex(&new_state, filepath, NULL, CWD_FILEPATH)) {
free(new_state.cwd);
return NULL;
}
diff --git a/main/fopen_wrappers.h b/main/fopen_wrappers.h
index 1aaba481f..e71d69ae4 100644
--- a/main/fopen_wrappers.h
+++ b/main/fopen_wrappers.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: fopen_wrappers.h,v 1.44.2.1.2.1 2006/07/01 11:35:34 nlopess Exp $ */
+/* $Id: fopen_wrappers.h,v 1.44.2.1.2.2 2007/01/01 09:36:10 sebastian Exp $ */
#ifndef FOPEN_WRAPPERS_H
#define FOPEN_WRAPPERS_H
diff --git a/main/internal_functions.c.in b/main/internal_functions.c.in
index 4d55ccb9b..2ee27f881 100644
--- a/main/internal_functions.c.in
+++ b/main/internal_functions.c.in
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: internal_functions.c.in,v 1.30.2.1.2.1 2006/08/12 19:33:54 nlopess Exp $ */
+/* $Id: internal_functions.c.in,v 1.30.2.1.2.2 2007/01/01 19:32:09 iliaa Exp $ */
#include "php.h"
#include "php_main.h"
diff --git a/main/internal_functions_nw.c b/main/internal_functions_nw.c
index d4756f382..53508deba 100644
--- a/main/internal_functions_nw.c
+++ b/main/internal_functions_nw.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: internal_functions_nw.c,v 1.9.2.1.2.1 2006/08/12 19:33:54 nlopess Exp $ */
+/* $Id: internal_functions_nw.c,v 1.9.2.1.2.2 2007/01/01 09:36:11 sebastian Exp $ */
/* {{{ includes
*/
diff --git a/main/internal_functions_win32.c b/main/internal_functions_win32.c
index b5e867810..6d24993c3 100644
--- a/main/internal_functions_win32.c
+++ b/main/internal_functions_win32.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: internal_functions_win32.c,v 1.87.2.1.2.2 2006/08/12 19:33:54 nlopess Exp $ */
+/* $Id: internal_functions_win32.c,v 1.87.2.1.2.3 2007/01/01 09:36:11 sebastian Exp $ */
/* {{{ includes
*/
diff --git a/main/logos.h b/main/logos.h
index 2ff6701b7..f045d9c82 100644
--- a/main/logos.h
+++ b/main/logos.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: logos.h,v 1.14.2.3.2.1 2006/07/07 23:32:14 nlopess Exp $ */
+/* $Id: logos.h,v 1.14.2.3.2.2 2007/01/01 09:36:11 sebastian Exp $ */
#define CONTEXT_TYPE_IMAGE_GIF "Content-Type: image/gif"
diff --git a/main/main.c b/main/main.c
index 66553ef68..b0822e362 100644
--- a/main/main.c
+++ b/main/main.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: main.c,v 1.640.2.23.2.16 2006/09/25 14:48:33 iliaa Exp $ */
+/* $Id: main.c,v 1.640.2.23.2.35 2007/04/18 09:38:56 rrichards Exp $ */
/* {{{ includes
*/
@@ -27,6 +27,7 @@
#include "php.h"
#include <stdio.h>
+#include <fcntl.h>
#ifdef PHP_WIN32
#include "win32/time.h"
#include "win32/signal.h"
@@ -61,8 +62,8 @@
#include "ext/standard/credits.h"
#ifdef PHP_WIN32
#include <io.h>
-#include <fcntl.h>
#include "win32/php_registry.h"
+#include "ext/standard/flock_compat.h"
#endif
#include "php_syslog.h"
#include "Zend/zend_exceptions.h"
@@ -83,6 +84,7 @@
#include "php_ticks.h"
#include "php_logos.h"
#include "php_streams.h"
+#include "php_open_temporary_file.h"
#include "SAPI.h"
#include "rfc1867.h"
@@ -100,12 +102,16 @@ PHPAPI int core_globals_id;
*/
static PHP_INI_MH(OnSetPrecision)
{
- EG(precision) = atoi(new_value);
- return SUCCESS;
+ int i = atoi(new_value);
+ if (i >= 0) {
+ EG(precision) = i;
+ return SUCCESS;
+ } else {
+ return FAILURE;
+ }
}
/* }}} */
-#if MEMORY_LIMIT
/* {{{ PHP_INI_MH
*/
static PHP_INI_MH(OnChangeMemoryLimit)
@@ -118,7 +124,6 @@ static PHP_INI_MH(OnChangeMemoryLimit)
return zend_set_memory_limit(PG(memory_limit));
}
/* }}} */
-#endif
/* {{{ php_disable_functions
@@ -281,7 +286,7 @@ PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("y2k_compliance", "1", PHP_INI_ALL, OnUpdateBool, y2k_compliance, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("unserialize_callback_func", NULL, PHP_INI_ALL, OnUpdateString, unserialize_callback_func, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("serialize_precision", "100", PHP_INI_ALL, OnUpdateLong, serialize_precision, php_core_globals, core_globals)
+ STD_PHP_INI_ENTRY("serialize_precision", "100", PHP_INI_ALL, OnUpdateLongGEZero, serialize_precision, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("arg_separator.output", "&", PHP_INI_ALL, OnUpdateStringUnempty, arg_separator.output, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("arg_separator.input", "&", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStringUnempty, arg_separator.input, php_core_globals, core_globals)
@@ -301,6 +306,7 @@ PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("upload_max_filesize", "2M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, upload_max_filesize, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("post_max_size", "8M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, post_max_size, sapi_globals_struct,sapi_globals)
STD_PHP_INI_ENTRY("upload_tmp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, upload_tmp_dir, php_core_globals, core_globals)
+ STD_PHP_INI_ENTRY("max_input_nesting_level", "64", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLongGEZero, max_input_nesting_level, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("user_dir", NULL, PHP_INI_SYSTEM, OnUpdateString, user_dir, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("variables_order", "EGPCS", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStringUnempty, variables_order, php_core_globals, core_globals)
@@ -311,9 +317,7 @@ PHP_INI_BEGIN()
PHP_INI_ENTRY("SMTP", "localhost",PHP_INI_ALL, NULL)
PHP_INI_ENTRY("smtp_port", "25", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("browscap", NULL, PHP_INI_SYSTEM, NULL)
-#if MEMORY_LIMIT
- PHP_INI_ENTRY("memory_limit", "16M", PHP_INI_ALL, OnChangeMemoryLimit)
-#endif
+ PHP_INI_ENTRY("memory_limit", "128M", PHP_INI_ALL, OnChangeMemoryLimit)
PHP_INI_ENTRY("precision", "14", PHP_INI_ALL, OnSetPrecision)
PHP_INI_ENTRY("sendmail_from", NULL, PHP_INI_ALL, NULL)
PHP_INI_ENTRY("sendmail_path", DEFAULT_SENDMAIL_PATH, PHP_INI_SYSTEM, NULL)
@@ -339,7 +343,7 @@ static int module_shutdown = 0;
*/
PHPAPI void php_log_err(char *log_message TSRMLS_DC)
{
- FILE *log_file;
+ int fd = -1;
char error_time_str[128];
struct tm tmbuf;
time_t error_time;
@@ -352,14 +356,19 @@ PHPAPI void php_log_err(char *log_message TSRMLS_DC)
return;
}
#endif
- log_file = VCWD_FOPEN(PG(error_log), "ab");
- if (log_file != NULL) {
+ fd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND | O_WRONLY, 0644);
+ if (fd != -1) {
+ char *tmp;
+ int len;
time(&error_time);
- strftime(error_time_str, sizeof(error_time_str), "%d-%b-%Y %H:%M:%S", php_localtime_r(&error_time, &tmbuf));
- fprintf(log_file, "[%s] ", error_time_str);
- fprintf(log_file, "%s", log_message);
- fprintf(log_file, "%s", PHP_EOL);
- fclose(log_file);
+ strftime(error_time_str, sizeof(error_time_str), "%d-%b-%Y %H:%M:%S", php_localtime_r(&error_time, &tmbuf));
+ len = spprintf(&tmp, 0, "[%s] %s%s", error_time_str, log_message, PHP_EOL);
+#ifdef PHP_WIN32
+ php_flock(fd, 2);
+#endif
+ write(fd, tmp, len);
+ efree(tmp);
+ close(fd);
return;
}
}
@@ -830,10 +839,8 @@ static void php_error_cb(int type, const char *error_filename, const uint error_
case E_USER_ERROR:
EG(exit_status) = 255;
if (module_initialized) {
-#if MEMORY_LIMIT
/* restore memory limit */
zend_set_memory_limit(PG(memory_limit));
-#endif
efree(buffer);
zend_objects_store_mark_destructed(&EG(objects_store) TSRMLS_CC);
zend_bailout();
@@ -905,9 +912,14 @@ static long stream_fteller_for_zend(void *handle TSRMLS_DC)
static int php_stream_open_for_zend(const char *filename, zend_file_handle *handle TSRMLS_DC)
{
+ return php_stream_open_for_zend_ex(filename, handle, ENFORCE_SAFE_MODE|USE_PATH|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE TSRMLS_CC);
+}
+
+PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *handle, int mode TSRMLS_DC)
+{
php_stream *stream;
- stream = php_stream_open_wrapper((char *)filename, "rb", ENFORCE_SAFE_MODE|USE_PATH|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE, &handle->opened_path);
+ stream = php_stream_open_wrapper((char *)filename, "rb", mode, &handle->opened_path);
if (stream) {
handle->type = ZEND_HANDLE_STREAM;
@@ -926,7 +938,6 @@ static int php_stream_open_for_zend(const char *filename, zend_file_handle *hand
return FAILURE;
}
-
/* {{{ php_get_configuration_directive_for_zend
*/
static int php_get_configuration_directive_for_zend(char *name, uint name_length, zval *contents)
@@ -962,20 +973,20 @@ static void php_message_handler_for_zend(long message, void *data)
case ZMSG_MEMORY_LEAK_REPEATED:
#if ZEND_DEBUG
if (EG(error_reporting) & E_WARNING) {
- char memory_leak_buf[512];
+ char memory_leak_buf[1024];
if (message==ZMSG_MEMORY_LEAK_DETECTED) {
zend_leak_info *t = (zend_leak_info *) data;
- snprintf(memory_leak_buf, 512, "%s(%d) : Freeing 0x%.8lX (%d bytes), script=%s\n", t->filename, t->lineno, (unsigned long)t->addr, t->size, SAFE_FILENAME(SG(request_info).path_translated));
+ snprintf(memory_leak_buf, 512, "%s(%d) : Freeing 0x%.8lX (%zu bytes), script=%s\n", t->filename, t->lineno, (zend_uintptr_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);
- strcat(memory_leak_buf, relay_buf);
+ strlcat(memory_leak_buf, relay_buf, sizeof(memory_leak_buf));
}
} else {
- unsigned long leak_count = (unsigned long) data;
+ 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":""));
}
@@ -1005,12 +1016,18 @@ static void php_message_handler_for_zend(long message, void *data)
struct tm *ta, tmbuf;
time_t curtime;
char *datetime_str, asctimebuf[52];
+ char memory_leak_buf[4096];
time(&curtime);
ta = php_localtime_r(&curtime, &tmbuf);
datetime_str = php_asctime_r(ta, asctimebuf);
datetime_str[strlen(datetime_str)-1]=0; /* get rid of the trailing newline */
- fprintf(stderr, "[%s] Script: '%s'\n", datetime_str, SAFE_FILENAME(SG(request_info).path_translated));
+ snprintf(memory_leak_buf, sizeof(memory_leak_buf), "[%s] Script: '%s'\n", datetime_str, SAFE_FILENAME(SG(request_info).path_translated));
+# if defined(PHP_WIN32)
+ OutputDebugString(memory_leak_buf);
+# else
+ fprintf(stderr, "%s", memory_leak_buf);
+# endif
}
break;
}
@@ -1073,7 +1090,7 @@ int php_request_startup(TSRMLS_D)
int retval = SUCCESS;
#ifdef PHP_WIN32
- CoInitialize(NULL);
+ PG(com_initialized) = 0;
#endif
#if PHP_SIGCHILD
@@ -1325,12 +1342,28 @@ void php_request_shutdown(void *dummy)
} zend_end_try();
#ifdef PHP_WIN32
- CoUninitialize();
+ if (PG(com_initialized)) {
+ CoUninitialize();
+ PG(com_initialized) = 0;
+ }
#endif
}
/* }}} */
+/* {{{ php_com_initialize
+ */
+PHPAPI void php_com_initialize(TSRMLS_D)
+{
+#ifdef PHP_WIN32
+ if (!PG(com_initialized)) {
+ CoInitialize(NULL);
+ PG(com_initialized) = 1;
+ }
+#endif
+}
+/* }}} */
+
/* {{{ php_body_write_wrapper
*/
static int php_body_write_wrapper(const char *str, uint str_length)
@@ -1458,7 +1491,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
ts_allocate_id(&core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, (ts_allocate_dtor) core_globals_dtor);
core_globals = ts_resource(core_globals_id);
#ifdef PHP_WIN32
- ts_allocate_id(&php_win32_core_globals_id, sizeof(php_win32_core_globals), (ts_allocate_ctor) php_win32_core_globals_ctor, NULL);
+ ts_allocate_id(&php_win32_core_globals_id, sizeof(php_win32_core_globals), (ts_allocate_ctor) php_win32_core_globals_ctor, (ts_allocate_dtor) php_win32_core_globals_dtor);
#endif
#endif
EG(bailout) = NULL;
@@ -1480,6 +1513,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
#if HAVE_SETLOCALE
setlocale(LC_CTYPE, "");
+ zend_update_current_locale();
#endif
#if HAVE_TZSET
@@ -1666,6 +1700,8 @@ void php_module_shutdown(TSRMLS_D)
ts_free_id(core_globals_id);
#endif
+ php_shutdown_temporary_directory();
+
module_initialized = 0;
}
/* }}} */
@@ -1871,7 +1907,7 @@ PHPAPI int php_handle_auth_data(const char *auth TSRMLS_DC)
PHPAPI int php_lint_script(zend_file_handle *file TSRMLS_DC)
{
zend_op_array *op_array;
- zend_bool retval = FAILURE;
+ int retval = FAILURE;
zend_try {
op_array = zend_compile_file(file, ZEND_INCLUDE TSRMLS_CC);
diff --git a/main/network.c b/main/network.c
index 674b7c727..ee42b8cb5 100644
--- a/main/network.c
+++ b/main/network.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: network.c,v 1.118.2.2.2.2 2006/09/11 19:18:07 pollita Exp $ */
+/* $Id: network.c,v 1.118.2.2.2.4 2007/01/11 15:51:37 tony2001 Exp $ */
/*#define DEBUG_MAIN_NETWORK 1*/
@@ -441,7 +441,7 @@ php_socket_t php_network_bind_socket_to_local_addr(const char *host, unsigned po
err = php_socket_errno();
}
- close(sock);
+ closesocket(sock);
}
sock = -1;
@@ -870,7 +870,7 @@ skip_bind:
#endif
}
- close(sock);
+ closesocket(sock);
}
sock = -1;
diff --git a/main/output.c b/main/output.c
index 4a1ee4052..76ad85655 100644
--- a/main/output.c
+++ b/main/output.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: output.c,v 1.167.2.3 2006/03/27 08:26:10 tony2001 Exp $ */
+/* $Id: output.c,v 1.167.2.3.2.3 2007/04/16 02:25:24 shire Exp $ */
#include "php.h"
#include "ext/standard/head.h"
@@ -112,7 +112,7 @@ void php_output_register_constants(TSRMLS_D)
/* }}} */
-/* {{{ php_body_wirte
+/* {{{ php_body_write
* Write body part */
PHPAPI int php_body_write(const char *str, uint str_length TSRMLS_DC)
{
@@ -120,7 +120,7 @@ PHPAPI int php_body_write(const char *str, uint str_length TSRMLS_DC)
}
/* }}} */
-/* {{{ php_header_wirte
+/* {{{ php_header_write
* Write HTTP header */
PHPAPI int php_header_write(const char *str, uint str_length TSRMLS_DC)
{
@@ -416,9 +416,23 @@ PHPAPI int php_ob_init_conflict(char *handler_new, char *handler_set TSRMLS_DC)
*/
static int php_ob_init_named(uint initial_size, uint block_size, char *handler_name, zval *output_handler, uint chunk_size, zend_bool erase TSRMLS_DC)
{
+ php_ob_buffer tmp_buf;
+
if (output_handler && !zend_is_callable(output_handler, 0, NULL)) {
return FAILURE;
}
+
+ tmp_buf.block_size = block_size;
+ tmp_buf.size = initial_size;
+ tmp_buf.buffer = (char *) emalloc(initial_size+1);
+ tmp_buf.text_length = 0;
+ tmp_buf.output_handler = output_handler;
+ tmp_buf.chunk_size = chunk_size;
+ tmp_buf.status = 0;
+ tmp_buf.internal_output_handler = NULL;
+ tmp_buf.handler_name = estrdup(handler_name&&handler_name[0]?handler_name:OB_DEFAULT_HANDLER_NAME);
+ tmp_buf.erase = erase;
+
if (OG(ob_nesting_level)>0) {
#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB)
if (!strncmp(handler_name, "ob_gzhandler", sizeof("ob_gzhandler")) && php_ob_gzhandler_check(TSRMLS_C)) {
@@ -431,16 +445,7 @@ static int php_ob_init_named(uint initial_size, uint block_size, char *handler_n
zend_stack_push(&OG(ob_buffers), &OG(active_ob_buffer), sizeof(php_ob_buffer));
}
OG(ob_nesting_level)++;
- OG(active_ob_buffer).block_size = block_size;
- OG(active_ob_buffer).size = initial_size;
- OG(active_ob_buffer).buffer = (char *) emalloc(initial_size+1);
- OG(active_ob_buffer).text_length = 0;
- OG(active_ob_buffer).output_handler = output_handler;
- OG(active_ob_buffer).chunk_size = chunk_size;
- OG(active_ob_buffer).status = 0;
- OG(active_ob_buffer).internal_output_handler = NULL;
- OG(active_ob_buffer).handler_name = estrdup(handler_name&&handler_name[0]?handler_name:OB_DEFAULT_HANDLER_NAME);
- OG(active_ob_buffer).erase = erase;
+ OG(active_ob_buffer) = tmp_buf;
OG(php_body_write) = php_b_body_write;
return SUCCESS;
}
diff --git a/main/php.h b/main/php.h
index efaeef88b..ff81a6304 100644
--- a/main/php.h
+++ b/main/php.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php.h,v 1.221.2.4.2.3 2006/09/04 08:18:15 dmitry Exp $ */
+/* $Id: php.h,v 1.221.2.4.2.7 2007/01/01 09:36:11 sebastian Exp $ */
#ifndef PHP_H
#define PHP_H
@@ -199,7 +199,6 @@ char *strerror(int);
#if HAVE_PWD_H
# ifdef PHP_WIN32
-#include "win32/pwd.h"
#include "win32/param.h"
# else
#include <pwd.h>
@@ -330,6 +329,8 @@ PHPAPI void php_register_pre_request_shutdown(void (*func)(void *), void *userda
PHPAPI int cfg_get_long(char *varname, long *result);
PHPAPI int cfg_get_double(char *varname, double *result);
PHPAPI int cfg_get_string(char *varname, char **result);
+
+PHPAPI void php_com_initialize(TSRMLS_D);
END_EXTERN_C()
/* PHP-named Zend macro wrappers */
@@ -339,6 +340,7 @@ END_EXTERN_C()
#define PHP_FUNCTION ZEND_FUNCTION
#define PHP_METHOD ZEND_METHOD
+#define PHP_RAW_NAMED_FE ZEND_RAW_NAMED_FE
#define PHP_NAMED_FE ZEND_NAMED_FE
#define PHP_FE ZEND_FE
#define PHP_DEP_FE ZEND_DEP_FE
diff --git a/main/php3_compat.h b/main/php3_compat.h
index fa140b38b..e0711b4a5 100644
--- a/main/php3_compat.h
+++ b/main/php3_compat.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php3_compat.h,v 1.20.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: php3_compat.h,v 1.20.2.1.2.1 2007/01/01 09:36:11 sebastian Exp $ */
#ifndef PHP3_COMPAT_H
#define PHP3_COMPAT_H
diff --git a/main/php_compat.h b/main/php_compat.h
index edea45ff1..e6744290e 100644
--- a/main/php_compat.h
+++ b/main/php_compat.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_compat.h,v 1.25.2.3.2.2 2006/08/23 20:39:11 andrei Exp $ */
+/* $Id: php_compat.h,v 1.25.2.3.2.4 2007/02/25 18:47:21 nlopess Exp $ */
#ifndef PHP_COMPAT_H
#define PHP_COMPAT_H
@@ -32,7 +32,7 @@
#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_substring
+#define pcre_get_substring php_pcre_get_substring
#define pcre_get_substring_list php_pcre_get_substring_list
#define pcre_info php_pcre_info
#define pcre_maketables php_pcre_maketables
@@ -43,7 +43,6 @@
#define pcre_malloc php_pcre_malloc
#define pcre_config php_pcre_config
#define pcre_copy_named_substring php_pcre_copy_named_substring
-#define pcre_dfa_exec php_pcre_dfa_exec
#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
@@ -55,6 +54,22 @@
#define _pcre_ucp_othercase php__pcre_ucp_othercase
#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
+/* this one doesn't work because pcre.h isn't included from the pcre_chartables.c file
+#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
#endif
#define lookup php_lookup
diff --git a/main/php_config.h.in b/main/php_config.h.in
index 19f4189b5..5155ccfcf 100644
--- a/main/php_config.h.in
+++ b/main/php_config.h.in
@@ -4,7 +4,7 @@
+----------------------------------------------------------------------+
| Zend Engine |
+----------------------------------------------------------------------+
- | Copyright (c) 1998-2006 Zend Technologies Ltd. (http://www.zend.com) |
+ | Copyright (c) 1998-2007 Zend Technologies Ltd. (http://www.zend.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 2.00 of the Zend license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: acconfig.h,v 1.40.2.1 2006/01/04 23:53:03 andi Exp $ */
+/* $Id: acconfig.h,v 1.40.2.1.2.1 2007/01/01 09:35:45 sebastian Exp $ */
#define ZEND_API
#define ZEND_DLEXPORT
@@ -182,6 +182,9 @@
/* Define if you have the crypt function. */
#undef HAVE_CRYPT
+/* Define if you have the crypt_r function. */
+#undef HAVE_CRYPT_R
+
/* Define if you have the ctermid function. */
#undef HAVE_CTERMID
@@ -224,6 +227,12 @@
/* Define if you have the getcwd function. */
#undef HAVE_GETCWD
+/* Define if you have the getgrgid_r function. */
+#undef HAVE_GETGRGID_R
+
+/* Define if you have the getgrnam_r function. */
+#undef HAVE_GETGRNAM_R
+
/* Define if you have the getgroups function. */
#undef HAVE_GETGROUPS
@@ -251,6 +260,12 @@
/* Define if you have the getprotobynumber function. */
#undef HAVE_GETPROTOBYNUMBER
+/* Define if you have the getpwnam_r function. */
+#undef HAVE_GETPWNAM_R
+
+/* Define if you have the getpwuid_r function. */
+#undef HAVE_GETPWUID_R
+
/* Define if you have the getrlimit function. */
#undef HAVE_GETRLIMIT
@@ -794,6 +809,9 @@
/* Enabling BIND8 compatibility for Panther */
#undef BIND_8_COMPAT
+/* Define if the target system has /dev/urandom device */
+#undef HAVE_DEV_URANDOM
+
/* Whether you have AOLserver */
#undef HAVE_AOLSERVER
@@ -917,9 +935,6 @@
/* Whether to use Roxen in ZTS mode */
#undef ROXEN_USE_ZTS
-/* whether write(2) works */
-#undef PHP_WRITE_STDOUT
-
/* */
#undef FORCE_CGI_REDIRECT
@@ -944,6 +959,9 @@
/* Define if processor uses big-endian word */
#undef WORDS_BIGENDIAN
+/* whether write(2) works */
+#undef PHP_WRITE_STDOUT
+
/* */
#undef HAVE_SOCKET
@@ -1133,6 +1151,15 @@
/* */
#undef in_addr_t
+/* Define if crypt_r has uses CRYPTD */
+#undef CRYPT_R_CRYPTD
+
+/* Define if crypt_r uses struct crypt_data */
+#undef CRYPT_R_STRUCT_CRYPT_DATA
+
+/* Define if struct crypt_data requires _GNU_SOURCE */
+#undef CRYPT_R_GNU_SOURCE
+
/* Whether you have gcov */
#undef HAVE_GCOV
@@ -1190,6 +1217,9 @@
/* Whether to build openssl as dynamic module */
#undef COMPILE_DL_OPENSSL
+/* OpenSSL 0.9.7 or later */
+#undef HAVE_DSA_DEFAULT_METHOD
+
/* */
#undef HAVE_OPENSSL_EXT
@@ -1491,6 +1521,9 @@
#undef HAVE_GD_FONTCACHESHUTDOWN
/* */
+#undef HAVE_GD_FONTMUTEX
+
+/* */
#undef HAVE_GD_DYNAMIC_CTX_EX
/* */
@@ -1596,6 +1629,9 @@
#undef HAVE_GD_FREEFONTCACHE
/* */
+#undef HAVE_GD_FONTMUTEX
+
+/* */
#undef HAVE_GD_DYNAMIC_CTX_EX
/* */
@@ -1706,7 +1742,7 @@
/* */
#undef HAVE_IMAP2004
-/* */
+/* Whether utf8_mime2text() has new signature */
#undef HAVE_NEW_MIME2TEXT
/* */
@@ -1728,18 +1764,6 @@
#undef HAVE_IMAP_AUTH_GSS
/* */
-#undef IFX_VERSION
-
-/* */
-#undef HAVE_IFX_IUS
-
-/* Whether to build informix as dynamic module */
-#undef COMPILE_DL_INFORMIX
-
-/* */
-#undef HAVE_IFX
-
-/* */
#undef HAVE_IBASE
/* Whether to build interbase as dynamic module */
@@ -1830,6 +1854,12 @@
#undef HAVE_SWFPREBUILTCLIP
/* */
+#undef HAVE_SWFMOVIE_NAMEDANCHOR
+
+/* */
+#undef HAVE_MING_SETSWFCOMPRESSION
+
+/* */
#undef HAVE_DESTROY_SWF_BLOCK
/* */
@@ -2361,6 +2391,9 @@
#undef HAVE_PQGETCOPYDATA
/* PostgreSQL 7.4 or later */
+#undef HAVE_PQFREEMEM
+
+/* PostgreSQL 7.4 or later */
#undef HAVE_PQSETERRORVERBOSITY
/* PostgreSQL 7.4 or later */
@@ -2384,6 +2417,9 @@
/* Whether to build posix as dynamic module */
#undef COMPILE_DL_POSIX
+/* Whether you have a working ttyname_r */
+#undef HAVE_TTYNAME_R
+
/* Whether to build pspell as dynamic module */
#undef COMPILE_DL_PSPELL
@@ -2822,12 +2858,6 @@
/* */
#undef ZTS
-/* Memory limit */
-#undef MEMORY_LIMIT
-
-/* Memory limit */
-#undef MEMORY_LIMIT
-
/* */
#undef ZEND_MULTIBYTE
diff --git a/main/php_content_types.c b/main/php_content_types.c
index 62fe20afd..f333d8706 100644
--- a/main/php_content_types.c
+++ b/main/php_content_types.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_content_types.c,v 1.32.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: php_content_types.c,v 1.32.2.1.2.2 2007/04/01 19:09:36 iliaa Exp $ */
#include "php.h"
#include "SAPI.h"
@@ -42,7 +42,7 @@ SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader)
/* $HTTP_RAW_POST_DATA registration */
if(!strcmp(SG(request_info).request_method, "POST")) {
- if(NULL == SG(request_info).post_entry) {
+ if(NULL == SG(request_info).post_entry && SG(request_info).post_data) {
/* no post handler registered, so we just swallow the data */
sapi_read_standard_form_data(TSRMLS_C);
length = SG(request_info).post_data_length;
diff --git a/main/php_content_types.h b/main/php_content_types.h
index 8d06da23a..caaed36e6 100644
--- a/main/php_content_types.h
+++ b/main/php_content_types.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_content_types.h,v 1.12.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: php_content_types.h,v 1.12.2.1.2.1 2007/01/01 09:36:11 sebastian Exp $ */
#ifndef PHP_CONTENT_TYPES_H
#define PHP_CONTENT_TYPES_H
diff --git a/main/php_globals.h b/main/php_globals.h
index 820bacfca..6c3edc90e 100644
--- a/main/php_globals.h
+++ b/main/php_globals.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_globals.h,v 1.98.2.1.2.2 2006/07/19 12:25:46 mike Exp $ */
+/* $Id: php_globals.h,v 1.98.2.1.2.5 2007/03/02 21:58:05 stas Exp $ */
#ifndef PHP_GLOBALS_H
#define PHP_GLOBALS_H
@@ -152,6 +152,10 @@ struct _php_core_globals {
char *disable_functions;
char *disable_classes;
zend_bool allow_url_include;
+#ifdef PHP_WIN32
+ zend_bool com_initialized;
+#endif
+ long max_input_nesting_level;
};
diff --git a/main/php_ini.c b/main/php_ini.c
index 88b0cf8d3..ead7ce1df 100644
--- a/main/php_ini.c
+++ b/main/php_ini.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_ini.c,v 1.136.2.4.2.4 2006/09/19 20:33:11 dmitry Exp $ */
+/* $Id: php_ini.c,v 1.136.2.4.2.8 2007/04/16 08:09:56 dmitry Exp $ */
#include "php.h"
#include "ext/standard/info.h"
@@ -142,7 +142,7 @@ PHPAPI void display_ini_entries(zend_module_entry *module)
}
php_info_print_table_start();
php_info_print_table_header(3, "Directive", "Local Value", "Master Value");
- zend_hash_apply_with_argument(EG(ini_directives), (apply_func_arg_t) php_ini_displayer, (void *) (long) module_number TSRMLS_CC);
+ zend_hash_apply_with_argument(EG(ini_directives), (apply_func_arg_t) php_ini_displayer, (void *) (zend_intptr_t) module_number TSRMLS_CC);
php_info_print_table_end();
}
/* }}} */
@@ -291,6 +291,7 @@ int php_init_config(TSRMLS_D)
php_ini_search_path = sapi_module.php_ini_path_override;
free_ini_search_path = 0;
} else if (!sapi_module.php_ini_ignore) {
+ int search_path_size;
char *default_location;
char *env_location;
char *binary_location;
@@ -308,16 +309,17 @@ int php_init_config(TSRMLS_D)
* Prepare search path
*/
- php_ini_search_path = (char *) emalloc(MAXPATHLEN * 4 + strlen(env_location) + 3 + 1);
+ search_path_size = MAXPATHLEN * 4 + strlen(env_location) + 3 + 1;
+ php_ini_search_path = (char *) emalloc(search_path_size);
free_ini_search_path = 1;
php_ini_search_path[0] = 0;
/* Add environment location */
if (env_location[0]) {
if (*php_ini_search_path) {
- strcat(php_ini_search_path, paths_separator);
+ strlcat(php_ini_search_path, paths_separator, search_path_size);
}
- strcat(php_ini_search_path, env_location);
+ strlcat(php_ini_search_path, env_location, search_path_size);
php_ini_file_name = env_location;
}
@@ -326,9 +328,9 @@ int php_init_config(TSRMLS_D)
reg_location = GetIniPathFromRegistry();
if (reg_location != NULL) {
if (*php_ini_search_path) {
- strcat(php_ini_search_path, paths_separator);
+ strlcat(php_ini_search_path, paths_separator, search_path_size);
}
- strcat(php_ini_search_path, reg_location);
+ strlcat(php_ini_search_path, reg_location, search_path_size);
efree(reg_location);
}
#endif
@@ -336,9 +338,9 @@ int php_init_config(TSRMLS_D)
/* Add cwd (not with CLI) */
if (strcmp(sapi_module.name, "cli") != 0) {
if (*php_ini_search_path) {
- strcat(php_ini_search_path, paths_separator);
+ strlcat(php_ini_search_path, paths_separator, search_path_size);
}
- strcat(php_ini_search_path, ".");
+ strlcat(php_ini_search_path, ".", search_path_size);
}
/* Add binary directory */
@@ -366,9 +368,9 @@ int php_init_config(TSRMLS_D)
*(separator_location) = 0;
}
if (*php_ini_search_path) {
- strcat(php_ini_search_path, paths_separator);
+ strlcat(php_ini_search_path, paths_separator, search_path_size);
}
- strcat(php_ini_search_path, binary_location);
+ strlcat(php_ini_search_path, binary_location, search_path_size);
efree(binary_location);
}
@@ -378,9 +380,9 @@ int php_init_config(TSRMLS_D)
if (0 < GetWindowsDirectory(default_location, MAXPATHLEN)) {
if (*php_ini_search_path) {
- strcat(php_ini_search_path, paths_separator);
+ strlcat(php_ini_search_path, paths_separator, search_path_size);
}
- strcat(php_ini_search_path, default_location);
+ strlcat(php_ini_search_path, default_location, search_path_size);
}
efree(default_location);
@@ -402,9 +404,9 @@ int php_init_config(TSRMLS_D)
default_location = (char *) emalloc(MAXPATHLEN + 1);
if (0 < get_system_windows_directory(default_location, MAXPATHLEN)) {
if (*php_ini_search_path) {
- strcat(php_ini_search_path, paths_separator);
+ strlcat(php_ini_search_path, paths_separator, search_path_size);
}
- strcat(php_ini_search_path, default_location);
+ strlcat(php_ini_search_path, default_location, search_path_size);
}
efree(default_location);
}
@@ -412,9 +414,9 @@ int php_init_config(TSRMLS_D)
#else
default_location = PHP_CONFIG_FILE_PATH;
if (*php_ini_search_path) {
- strcat(php_ini_search_path, paths_separator);
+ strlcat(php_ini_search_path, paths_separator, search_path_size);
}
- strcat(php_ini_search_path, default_location);
+ strlcat(php_ini_search_path, default_location, search_path_size);
#endif
}
@@ -439,8 +441,8 @@ int php_init_config(TSRMLS_D)
/* Search php-%sapi-module-name%.ini file in search path */
if (!fh.handle.fp) {
const char *fmt = "php-%s.ini";
- char *ini_fname = emalloc(strlen(fmt) + strlen(sapi_module.name));
- sprintf(ini_fname, fmt, sapi_module.name);
+ char *ini_fname;
+ spprintf(&ini_fname, 0, fmt, sapi_module.name);
fh.handle.fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
efree(ini_fname);
if (fh.handle.fp) {
@@ -522,8 +524,8 @@ int php_init_config(TSRMLS_D)
php_ini_scanned_files = (char *) malloc(total_l);
*php_ini_scanned_files = '\0';
for (element = scanned_ini_list.head; element; element = element->next) {
- strcat(php_ini_scanned_files, *(char **)element->data);
- strcat(php_ini_scanned_files, element->next ? ",\n" : "\n");
+ strlcat(php_ini_scanned_files, *(char **)element->data, total_l);
+ strlcat(php_ini_scanned_files, element->next ? ",\n" : "\n", total_l);
}
}
zend_llist_destroy(&scanned_ini_list);
@@ -588,7 +590,7 @@ PHPAPI int cfg_get_long(char *varname, long *result)
zval *tmp, var;
if (zend_hash_find(&configuration_hash, varname, strlen(varname) + 1, (void **) &tmp) == FAILURE) {
- *result = (long) NULL;
+ *result = 0;
return FAILURE;
}
var = *tmp;
diff --git a/main/php_ini.h b/main/php_ini.h
index 8adf726ab..dd46acbc6 100644
--- a/main/php_ini.h
+++ b/main/php_ini.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_ini.h,v 1.45.2.3 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: php_ini.h,v 1.45.2.3.2.1 2007/01/01 09:36:11 sebastian Exp $ */
#ifndef PHP_INI_H
#define PHP_INI_H
diff --git a/main/php_logos.c b/main/php_logos.c
index 476f8fe0d..3ac704af8 100644
--- a/main/php_logos.c
+++ b/main/php_logos.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_logos.c,v 1.19.2.1.2.2 2006/08/12 19:33:54 nlopess Exp $ */
+/* $Id: php_logos.c,v 1.19.2.1.2.5 2007/01/06 20:44:51 nlopess Exp $ */
#include "php.h"
#include "logos.h"
@@ -31,7 +31,7 @@ typedef struct _php_info_logo {
int size;
} php_info_logo;
-HashTable phpinfo_logo_hash;
+static HashTable phpinfo_logo_hash;
PHPAPI int php_register_info_logo(char *logo_string, const char *mimetype, const unsigned char *data, int size)
{
@@ -78,13 +78,12 @@ int php_info_logos(const char *logo_string TSRMLS_DC)
if(FAILURE==zend_hash_find(&phpinfo_logo_hash, (char *) logo_string, strlen(logo_string), (void **)&logo_image))
return 0;
- len=strlen(CONTENT_TYPE_HEADER)+logo_image->mimelen;
- content_header=malloc(len+1);
- if(!content_header) return 0;
- strcpy(content_header, CONTENT_TYPE_HEADER);
- strcat(content_header, logo_image->mimetype);
- sapi_add_header(content_header, len, 1);
- free(content_header);
+ len = sizeof(CONTENT_TYPE_HEADER) - 1 + logo_image->mimelen;
+ content_header = emalloc(len + 1);
+ memcpy(content_header, CONTENT_TYPE_HEADER, sizeof(CONTENT_TYPE_HEADER) - 1);
+ memcpy(content_header + sizeof(CONTENT_TYPE_HEADER) - 1 , logo_image->mimetype, logo_image->mimelen);
+ content_header[len] = '\0';
+ sapi_add_header(content_header, len, 0);
PHPWRITE(logo_image->data, logo_image->size);
return 1;
diff --git a/main/php_logos.h b/main/php_logos.h
index 77b62abfd..02ef8f9a4 100644
--- a/main/php_logos.h
+++ b/main/php_logos.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_logos.h,v 1.9.2.1.2.2 2006/08/12 19:33:54 nlopess Exp $ */
+/* $Id: php_logos.h,v 1.9.2.1.2.3 2007/01/01 09:36:11 sebastian Exp $ */
#ifndef _PHP_LOGOS_H
diff --git a/main/php_main.h b/main/php_main.h
index 15175713e..9e202a430 100644
--- a/main/php_main.h
+++ b/main/php_main.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_main.h,v 1.34.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: php_main.h,v 1.34.2.1.2.2 2007/01/08 03:39:09 iliaa Exp $ */
#ifndef PHP_MAIN_H
#define PHP_MAIN_H
@@ -47,6 +47,7 @@ PHPAPI void php_handle_aborted_connection(void);
PHPAPI int php_handle_auth_data(const char *auth TSRMLS_DC);
PHPAPI void php_html_puts(const char *str, uint siz TSRMLS_DC);
+PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *handle, int mode TSRMLS_DC);
extern void php_call_shutdown_functions(TSRMLS_D);
extern void php_free_shutdown_functions(TSRMLS_D);
diff --git a/main/php_memory_streams.h b/main/php_memory_streams.h
index 961dea115..816eb5993 100644
--- a/main/php_memory_streams.h
+++ b/main/php_memory_streams.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_memory_streams.h,v 1.13.2.1.2.1 2006/05/13 17:58:58 helly Exp $ */
+/* $Id: php_memory_streams.h,v 1.13.2.1.2.3 2007/02/03 16:40:05 helly Exp $ */
#ifndef PHP_MEMORY_STREAM_H
#define PHP_MEMORY_STREAM_H
@@ -48,10 +48,10 @@ PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STR
PHPAPI php_stream *_php_stream_temp_open(int mode, size_t max_memory_usage, char *buf, size_t length STREAMS_DC TSRMLS_DC);
END_EXTERN_C()
-extern php_stream_ops php_stream_memory_ops;
-extern php_stream_ops php_stream_temp_ops;
-extern php_stream_ops php_stream_rfc2397_ops;
-extern php_stream_wrapper php_stream_rfc2397_wrapper;
+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;
#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 8c03b42c7..6d0db6245 100644
--- a/main/php_network.h
+++ b/main/php_network.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_network.h,v 1.56.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: php_network.h,v 1.56.2.1.2.1 2007/01/01 09:36:11 sebastian Exp $ */
#ifndef _PHP_NETWORK_H
#define _PHP_NETWORK_H
diff --git a/main/php_open_temporary_file.c b/main/php_open_temporary_file.c
index 0a5c28828..7c0f8d4c4 100644
--- a/main/php_open_temporary_file.c
+++ b/main/php_open_temporary_file.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_open_temporary_file.c,v 1.34.2.1.2.4 2006/10/13 01:11:30 iliaa Exp $ */
+/* $Id: php_open_temporary_file.c,v 1.34.2.1.2.7 2007/02/07 21:07:31 tony2001 Exp $ */
#include "php.h"
@@ -148,14 +148,22 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, char **
}
/* }}} */
+/* Cache the chosen temporary directory. */
+static char* temporary_directory;
+
+PHPAPI void php_shutdown_temporary_directory()
+{
+ if (temporary_directory) {
+ free(temporary_directory);
+ temporary_directory = NULL;
+ }
+}
+
/*
* Determine where to place temporary files.
*/
PHPAPI const char* php_get_temporary_directory(void)
{
- /* Cache the chosen temporary directory. */
- static char* temporary_directory;
-
/* Did we determine the temporary directory already? */
if (temporary_directory) {
return temporary_directory;
@@ -186,12 +194,12 @@ PHPAPI const char* php_get_temporary_directory(void)
#ifdef P_tmpdir
/* Use the standard default temporary directory. */
if (P_tmpdir) {
- temporary_directory = P_tmpdir;
+ temporary_directory = strdup(P_tmpdir);
return temporary_directory;
}
#endif
/* Shouldn't ever(!) end up here ... last ditch default. */
- temporary_directory = "/tmp";
+ temporary_directory = strdup("/tmp");
return temporary_directory;
#endif
}
diff --git a/main/php_open_temporary_file.h b/main/php_open_temporary_file.h
index 6b33ae3a9..a6f008691 100644
--- a/main/php_open_temporary_file.h
+++ b/main/php_open_temporary_file.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_open_temporary_file.h,v 1.13.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: php_open_temporary_file.h,v 1.13.2.1.2.2 2007/02/07 21:01:06 helly Exp $ */
#ifndef PHP_OPEN_TEMPORARY_FILE_H
#define PHP_OPEN_TEMPORARY_FILE_H
@@ -25,6 +25,7 @@ BEGIN_EXTERN_C()
PHPAPI FILE *php_open_temporary_file(const char *dir, const char *pfx, char **opened_path_p TSRMLS_DC);
PHPAPI int php_open_temporary_fd(const char *dir, const char *pfx, char **opened_path_p TSRMLS_DC);
PHPAPI const char *php_get_temporary_directory(void);
+PHPAPI void php_shutdown_temporary_directory();
END_EXTERN_C()
#endif /* PHP_OPEN_TEMPORARY_FILE_H */
diff --git a/main/php_output.h b/main/php_output.h
index 8613e15e0..e4dc23a1b 100644
--- a/main/php_output.h
+++ b/main/php_output.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_output.h,v 1.53.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: php_output.h,v 1.53.2.1.2.1 2007/01/01 09:36:11 sebastian Exp $ */
#ifndef PHP_OUTPUT_H
#define PHP_OUTPUT_H
diff --git a/main/php_reentrancy.h b/main/php_reentrancy.h
index 119d6d4f7..45968d1c3 100644
--- a/main/php_reentrancy.h
+++ b/main/php_reentrancy.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_reentrancy.h,v 1.23.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: php_reentrancy.h,v 1.23.2.1.2.1 2007/01/01 09:36:11 sebastian Exp $ */
#ifndef PHP_REENTRANCY_H
#define PHP_REENTRANCY_H
diff --git a/main/php_regex.h b/main/php_regex.h
index 90884b733..6d68396fe 100644
--- a/main/php_regex.h
+++ b/main/php_regex.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_regex.h,v 1.16.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: php_regex.h,v 1.16.2.1.2.1 2007/01/01 09:36:11 sebastian Exp $ */
#ifndef PHP_REGEX_H
#define PHP_REGEX_H
diff --git a/main/php_scandir.c b/main/php_scandir.c
index 362d960b7..c51749a06 100644
--- a/main/php_scandir.c
+++ b/main/php_scandir.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -17,8 +17,9 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_scandir.c,v 1.12.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: php_scandir.c,v 1.12.2.1.2.5 2007/01/01 09:36:11 sebastian Exp $ */
+#include "php.h"
#include "php_scandir.h"
#ifdef HAVE_SYS_TYPES_H
@@ -32,6 +33,7 @@
#ifndef HAVE_SCANDIR
#ifdef PHP_WIN32
+#include "win32/param.h"
#include "win32/readdir.h"
#endif
@@ -59,9 +61,10 @@ int php_scandir(const char *dirname, struct dirent **namelist[], int (*selector)
{
DIR *dirp = NULL;
struct dirent **vector = NULL;
- struct dirent *dp = NULL;
int vector_size = 0;
int nfiles = 0;
+ char entry[sizeof(struct dirent)+MAXPATHLEN];
+ struct dirent *dp = (struct dirent *)&entry;
if (namelist == NULL) {
return -1;
@@ -71,7 +74,7 @@ int php_scandir(const char *dirname, struct dirent **namelist[], int (*selector)
return -1;
}
- while ((dp = readdir(dirp)) != NULL) {
+ while (!php_readdir_r(dirp, (struct dirent *)entry, &dp) && dp) {
int dsize = 0;
struct dirent *newdp = NULL;
diff --git a/main/php_scandir.h b/main/php_scandir.h
index 8e53d7f13..7d93278f5 100644
--- a/main/php_scandir.h
+++ b/main/php_scandir.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_scandir.h,v 1.12.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: php_scandir.h,v 1.12.2.1.2.1 2007/01/01 09:36:11 sebastian Exp $ */
#ifndef PHP_SCANDIR_H
#define PHP_SCANDIR_H
diff --git a/main/php_sprintf.c b/main/php_sprintf.c
index 427dfb179..d8cdc7722 100644
--- a/main/php_sprintf.c
+++ b/main/php_sprintf.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_sprintf.c,v 1.23.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: php_sprintf.c,v 1.23.2.1.2.1 2007/01/01 09:36:11 sebastian Exp $ */
#include <stdio.h>
#include <stdarg.h>
diff --git a/main/php_streams.h b/main/php_streams.h
index c4c1cdacb..df8849ffa 100755
--- a/main/php_streams.h
+++ b/main/php_streams.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_streams.h,v 1.103.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: php_streams.h,v 1.103.2.1.2.2 2007/02/21 21:57:21 tony2001 Exp $ */
#ifndef PHP_STREAMS_H
#define PHP_STREAMS_H
@@ -178,6 +178,8 @@ struct _php_stream_wrapper {
* might otherwise cause the read to block for much longer than
* is strictly required. */
#define PHP_STREAM_FLAG_AVOID_BLOCKING 16
+
+#define PHP_STREAM_FLAG_NO_CLOSE 32
struct _php_stream {
php_stream_ops *ops;
diff --git a/main/php_syslog.h b/main/php_syslog.h
index 0ef87ba00..447d32344 100644
--- a/main/php_syslog.h
+++ b/main/php_syslog.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_syslog.h,v 1.12.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: php_syslog.h,v 1.12.2.1.2.1 2007/01/01 09:36:11 sebastian Exp $ */
#ifndef PHP_SYSLOG_H
#define PHP_SYSLOG_H
diff --git a/main/php_ticks.c b/main/php_ticks.c
index d3f0937d3..cb637dded 100644
--- a/main/php_ticks.c
+++ b/main/php_ticks.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_ticks.c,v 1.20.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: php_ticks.c,v 1.20.2.1.2.1 2007/01/01 09:36:11 sebastian Exp $ */
#include "php.h"
#include "php_ticks.h"
diff --git a/main/php_ticks.h b/main/php_ticks.h
index 97021e1cf..7716b7dc6 100644
--- a/main/php_ticks.h
+++ b/main/php_ticks.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_ticks.h,v 1.14.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: php_ticks.h,v 1.14.2.1.2.1 2007/01/01 09:36:11 sebastian Exp $ */
#ifndef PHP_TICKS_H
#define PHP_TICKS_H
diff --git a/main/php_variables.c b/main/php_variables.c
index 42bc8f2d4..4b2640c59 100644
--- a/main/php_variables.c
+++ b/main/php_variables.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_variables.c,v 1.104.2.10.2.1 2006/07/27 15:37:56 iliaa Exp $ */
+/* $Id: php_variables.c,v 1.104.2.10.2.8 2007/04/17 15:06:50 iliaa Exp $ */
#include <stdio.h>
#include "php.h"
@@ -119,10 +119,16 @@ PHPAPI void php_register_variable_ex(char *var, zval *val, zval *track_vars_arra
index_len = var_len;
if (is_array) {
+ int nest_level = 0;
while (1) {
char *index_s;
int new_idx_len = 0;
+ if(++nest_level > PG(max_input_nesting_level)) {
+ /* too many levels of nesting */
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Input variable nesting level more than allowed %ld (change max_input_nesting_level in php.ini to increase the limit)", PG(max_input_nesting_level));
+ }
+
ip++;
index_s = ip;
if (isspace(*ip)) {
@@ -152,8 +158,7 @@ PHPAPI void php_register_variable_ex(char *var, zval *val, zval *track_vars_arra
array_init(gpc_element);
zend_hash_next_index_insert(symtable1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
} else {
- if (PG(magic_quotes_gpc) && (index != var)) {
- /* no need to addslashes() the index if it's the main variable name */
+ if (PG(magic_quotes_gpc)) {
escaped_index = php_addslashes(index, index_len, &index_len, 0 TSRMLS_CC);
} else {
escaped_index = index;
@@ -342,6 +347,17 @@ SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data)
while (var) {
val = strchr(var, '=');
+
+ if (arg == PARSE_COOKIE) {
+ /* Remove leading spaces from cookie names, needed for multi-cookie header where ; can be followed by a space */
+ while (isspace(*var)) {
+ var++;
+ }
+ if (var == val || *var == '\0') {
+ goto next_cookie;
+ }
+ }
+
if (val) { /* have a value */
int val_len;
unsigned int new_val_len;
@@ -366,6 +382,7 @@ SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data)
}
efree(val);
}
+next_cookie:
var = php_strtok_r(NULL, separator, &strtok_buf);
}
@@ -609,8 +626,6 @@ int php_hash_environment(TSRMLS_D)
{
char *p;
unsigned char _gpc_flags[5] = {0, 0, 0, 0, 0};
- zval *dummy_track_vars_array = NULL;
- zend_bool initialized_dummy_track_vars_array=0;
zend_bool jit_initialization = (PG(auto_globals_jit) && !PG(register_globals) && !PG(register_long_arrays));
struct auto_global_record {
char *name;
@@ -701,15 +716,9 @@ int php_hash_environment(TSRMLS_D)
continue;
}
if (!PG(http_globals)[i]) {
- if (!initialized_dummy_track_vars_array) {
- ALLOC_ZVAL(dummy_track_vars_array);
- array_init(dummy_track_vars_array);
- INIT_PZVAL(dummy_track_vars_array);
- initialized_dummy_track_vars_array = 1;
- } else {
- dummy_track_vars_array->refcount++;
- }
- PG(http_globals)[i] = dummy_track_vars_array;
+ ALLOC_ZVAL(PG(http_globals)[i]);
+ array_init(PG(http_globals)[i]);
+ INIT_PZVAL(PG(http_globals)[i]);
}
PG(http_globals)[i]->refcount++;
diff --git a/main/php_variables.h b/main/php_variables.h
index 9178065b7..4472c6766 100644
--- a/main/php_variables.h
+++ b/main/php_variables.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_variables.h,v 1.22.2.3.2.1 2006/05/10 21:10:45 rasmus Exp $ */
+/* $Id: php_variables.h,v 1.22.2.3.2.2 2007/01/01 09:36:11 sebastian Exp $ */
#ifndef PHP_VARIABLES_H
#define PHP_VARIABLES_H
diff --git a/main/php_version.h b/main/php_version.h
index 73c11eac6..1972edd44 100644
--- a/main/php_version.h
+++ b/main/php_version.h
@@ -2,7 +2,7 @@
/* edit configure.in to change version number */
#define PHP_MAJOR_VERSION 5
#define PHP_MINOR_VERSION 2
-#define PHP_RELEASE_VERSION 0
+#define PHP_RELEASE_VERSION 2
#define PHP_EXTRA_VERSION ""
-#define PHP_VERSION "5.2.0"
-#define PHP_VERSION_ID 50200
+#define PHP_VERSION "5.2.2"
+#define PHP_VERSION_ID 50202
diff --git a/main/reentrancy.c b/main/reentrancy.c
index fd83be4f2..b5ce11599 100644
--- a/main/reentrancy.c
+++ b/main/reentrancy.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: reentrancy.c,v 1.43.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: reentrancy.c,v 1.43.2.1.2.2 2007/01/01 09:36:11 sebastian Exp $ */
#include <sys/types.h>
#include <string.h>
@@ -25,10 +25,6 @@
#include <dirent.h>
#endif
-#ifdef PHP_WIN32
-#include "win32/readdir.h"
-#endif
-
#include "php_reentrancy.h"
#include "ext/standard/php_rand.h" /* for PHP_RAND_MAX */
diff --git a/main/rfc1867.c b/main/rfc1867.c
index edca8f97b..df5e882bf 100644
--- a/main/rfc1867.c
+++ b/main/rfc1867.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: rfc1867.c,v 1.173.2.1.2.5 2006/09/29 10:05:34 sesser Exp $ */
+/* $Id: rfc1867.c,v 1.173.2.1.2.8 2007/02/24 14:53:50 helly Exp $ */
/*
* This product includes software developed by the Apache Group
@@ -365,12 +365,9 @@ static multipart_buffer *multipart_buffer_new(char *boundary, int boundary_len)
self->buffer = (char *) ecalloc(1, minsize + 1);
self->bufsize = minsize;
- self->boundary = (char *) ecalloc(1, boundary_len + 3);
- sprintf(self->boundary, "--%s", boundary);
+ spprintf(&self->boundary, 0, "--%s", boundary);
- self->boundary_next = (char *) ecalloc(1, boundary_len + 4);
- sprintf(self->boundary_next, "\n--%s", boundary);
- self->boundary_next_len = boundary_len + 3;
+ self->boundary_next_len = spprintf(&self->boundary_next, 0, "\n--%s", boundary);
self->buf_begin = self->buffer;
self->bytes_in_buffer = 0;
@@ -797,6 +794,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler)
int fd=-1;
zend_llist header;
void *event_extra_data = NULL;
+ int llen = 0;
if (SG(request_info).content_length > SG(post_max_size)) {
sapi_module.sapi_error(E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes", SG(request_info).content_length, SG(post_max_size));
@@ -1159,17 +1157,18 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler)
}
/* Add $foo_name */
- if (lbuf) {
- efree(lbuf);
+ if (llen < strlen(param) + MAX_SIZE_OF_INDEX + 1) {
+ llen = strlen(param);
+ lbuf = (char *) safe_erealloc(lbuf, llen, 1, MAX_SIZE_OF_INDEX + 1);
+ llen += MAX_SIZE_OF_INDEX + 1;
}
- lbuf = (char *) emalloc(strlen(param) + MAX_SIZE_OF_INDEX + 1);
if (is_arr_upload) {
if (abuf) efree(abuf);
abuf = estrndup(param, strlen(param)-array_len);
- sprintf(lbuf, "%s_name[%s]", abuf, array_index);
+ snprintf(lbuf, llen, "%s_name[%s]", abuf, array_index);
} else {
- sprintf(lbuf, "%s_name", param);
+ snprintf(lbuf, llen, "%s_name", param);
}
#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
@@ -1227,9 +1226,9 @@ filedone:
/* Add $foo[name] */
if (is_arr_upload) {
- sprintf(lbuf, "%s[name][%s]", abuf, array_index);
+ snprintf(lbuf, llen, "%s[name][%s]", abuf, array_index);
} else {
- sprintf(lbuf, "%s[name]", param);
+ snprintf(lbuf, llen, "%s[name]", param);
}
if (s && s > filename) {
register_http_post_files_variable(lbuf, s+1, http_post_files, 0 TSRMLS_CC);
@@ -1252,9 +1251,9 @@ filedone:
/* Add $foo_type */
if (is_arr_upload) {
- sprintf(lbuf, "%s_type[%s]", abuf, array_index);
+ snprintf(lbuf, llen, "%s_type[%s]", abuf, array_index);
} else {
- sprintf(lbuf, "%s_type", param);
+ snprintf(lbuf, llen, "%s_type", param);
}
if (!is_anonymous) {
safe_php_register_variable(lbuf, cd, strlen(cd), NULL, 0 TSRMLS_CC);
@@ -1262,9 +1261,9 @@ filedone:
/* Add $foo[type] */
if (is_arr_upload) {
- sprintf(lbuf, "%s[type][%s]", abuf, array_index);
+ snprintf(lbuf, llen, "%s[type][%s]", abuf, array_index);
} else {
- sprintf(lbuf, "%s[type]", param);
+ snprintf(lbuf, llen, "%s[type]", param);
}
register_http_post_files_variable(lbuf, cd, http_post_files, 0 TSRMLS_CC);
@@ -1286,9 +1285,9 @@ filedone:
/* Add $foo[tmp_name] */
if (is_arr_upload) {
- sprintf(lbuf, "%s[tmp_name][%s]", abuf, array_index);
+ snprintf(lbuf, llen, "%s[tmp_name][%s]", abuf, array_index);
} else {
- sprintf(lbuf, "%s[tmp_name]", param);
+ snprintf(lbuf, llen, "%s[tmp_name]", param);
}
add_protected_variable(lbuf TSRMLS_CC);
register_http_post_files_variable(lbuf, temp_filename, http_post_files, 1 TSRMLS_CC);
@@ -1311,17 +1310,17 @@ filedone:
}
if (is_arr_upload) {
- sprintf(lbuf, "%s[error][%s]", abuf, array_index);
+ snprintf(lbuf, llen, "%s[error][%s]", abuf, array_index);
} else {
- sprintf(lbuf, "%s[error]", param);
+ snprintf(lbuf, llen, "%s[error]", param);
}
register_http_post_files_variable_ex(lbuf, &error_type, http_post_files, 0 TSRMLS_CC);
/* Add $foo_size */
if (is_arr_upload) {
- sprintf(lbuf, "%s_size[%s]", abuf, array_index);
+ snprintf(lbuf, llen, "%s_size[%s]", abuf, array_index);
} else {
- sprintf(lbuf, "%s_size", param);
+ snprintf(lbuf, llen, "%s_size", param);
}
if (!is_anonymous) {
safe_php_register_variable_ex(lbuf, &file_size, NULL, 0 TSRMLS_CC);
@@ -1329,9 +1328,9 @@ filedone:
/* Add $foo[size] */
if (is_arr_upload) {
- sprintf(lbuf, "%s[size][%s]", abuf, array_index);
+ snprintf(lbuf, llen, "%s[size][%s]", abuf, array_index);
} else {
- sprintf(lbuf, "%s[size]", param);
+ snprintf(lbuf, llen, "%s[size]", param);
}
register_http_post_files_variable_ex(lbuf, &file_size, http_post_files, 0 TSRMLS_CC);
}
diff --git a/main/rfc1867.h b/main/rfc1867.h
index 180079977..47aa32b1b 100644
--- a/main/rfc1867.h
+++ b/main/rfc1867.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: rfc1867.h,v 1.13.2.1.2.2 2006/07/26 13:22:06 tony2001 Exp $ */
+/* $Id: rfc1867.h,v 1.13.2.1.2.3 2007/01/01 09:36:11 sebastian Exp $ */
#ifndef RFC1867_H
#define RFC1867_H
diff --git a/main/safe_mode.c b/main/safe_mode.c
index 8b9886374..0c8fde9ce 100644
--- a/main/safe_mode.c
+++ b/main/safe_mode.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: safe_mode.c,v 1.62.2.1.2.2 2006/07/01 11:35:34 nlopess Exp $ */
+/* $Id: safe_mode.c,v 1.62.2.1.2.8 2007/01/12 12:11:18 bjori Exp $ */
#include "php.h"
@@ -55,6 +55,8 @@ PHPAPI int php_checkuid_ex(const char *filename, const char *fopen_mode, int mod
php_stream_wrapper *wrapper = NULL;
TSRMLS_FETCH();
+ path[0] = '\0';
+
if (!filename) {
return 0; /* path must be provided */
}
@@ -84,7 +86,7 @@ PHPAPI int php_checkuid_ex(const char *filename, const char *fopen_mode, int mod
* If that fails, passthrough and check directory...
*/
if (mode != CHECKUID_ALLOW_ONLY_DIR) {
- VCWD_REALPATH(filename, path);
+ expand_filepath(filename, path TSRMLS_CC);
ret = VCWD_STAT(path, &sb);
if (ret < 0) {
if (mode == CHECKUID_DISALLOW_FILE_NOT_EXISTS) {
@@ -197,7 +199,6 @@ PHPAPI int php_checkuid(const char *filename, const char *fopen_mode, int mode)
PHPAPI char *php_get_current_user()
{
- struct passwd *pwd;
struct stat *pstat;
TSRMLS_FETCH();
@@ -213,15 +214,48 @@ PHPAPI char *php_get_current_user()
if (!pstat) {
return "";
- }
+ } else {
+#ifdef PHP_WIN32
+ char name[256];
+ DWORD len = sizeof(name)-1;
- if ((pwd=getpwuid(pstat->st_uid))==NULL) {
- return "";
- }
- SG(request_info).current_user_length = strlen(pwd->pw_name);
- SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length);
-
- return SG(request_info).current_user;
+ if (!GetUserName(name, &len)) {
+ return "";
+ }
+ name[len] = '\0';
+ SG(request_info).current_user_length = len;
+ SG(request_info).current_user = estrndup(name, len);
+ return SG(request_info).current_user;
+#else
+ struct passwd *pwd;
+#if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX)
+ struct passwd _pw;
+ struct passwd *retpwptr = NULL;
+ int pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
+ char *pwbuf;
+
+ if (pwbuflen < 1) {
+ return "";
+ }
+ pwbuf = emalloc(pwbuflen);
+ if (getpwuid_r(pstat->st_uid, &_pw, pwbuf, pwbuflen, &retpwptr) != 0) {
+ efree(pwbuf);
+ return "";
+ }
+ pwd = &_pw;
+#else
+ if ((pwd=getpwuid(pstat->st_uid))==NULL) {
+ return "";
+ }
+#endif
+ SG(request_info).current_user_length = strlen(pwd->pw_name);
+ SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length);
+#if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX)
+ efree(pwbuf);
+#endif
+ return SG(request_info).current_user;
+#endif
+ }
}
/*
diff --git a/main/safe_mode.h b/main/safe_mode.h
index 9e38b07cf..002c3ebb8 100644
--- a/main/safe_mode.h
+++ b/main/safe_mode.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: safe_mode.h,v 1.13.2.1.2.1 2006/07/01 11:35:34 nlopess Exp $ */
+/* $Id: safe_mode.h,v 1.13.2.1.2.2 2007/01/01 09:36:11 sebastian Exp $ */
#ifndef SAFE_MODE_H
#define SAFE_MODE_H
diff --git a/main/snprintf.c b/main/snprintf.c
index ee834d3f1..a676a3c8d 100644
--- a/main/snprintf.c
+++ b/main/snprintf.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,8 +16,223 @@
+----------------------------------------------------------------------+
*/
-/* $Id: snprintf.c,v 1.37.2.4.2.1 2006/05/07 12:40:17 helly Exp $ */
+/* $Id: snprintf.c,v 1.37.2.4.2.11 2007/04/12 22:01:20 tony2001 Exp $ */
+
+#include "php.h"
+
+#include <zend_strtod.h>
+
+#include <stddef.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
+
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#define LCONV_DECIMAL_POINT (*lconv->decimal_point)
+#else
+#define LCONV_DECIMAL_POINT '.'
+#endif
+
+/*
+ * Copyright (c) 2002, 2006 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+
+static char * __cvt(double value, int ndigit, int *decpt, int *sign, int fmode, int pad) /* {{{ */
+{
+ register char *s = NULL;
+ char *p, *rve, c;
+ size_t siz;
+
+ if (ndigit < 0) {
+ siz = -ndigit + 1;
+ } else {
+ siz = ndigit + 1;
+ }
+
+ /* __dtoa() doesn't allocate space for 0 so we do it by hand */
+ if (value == 0.0) {
+ *decpt = 1 - fmode; /* 1 for 'e', 0 for 'f' */
+ *sign = 0;
+ if ((rve = s = (char *)malloc(ndigit?siz:2)) == NULL) {
+ return(NULL);
+ }
+ *rve++ = '0';
+ *rve = '\0';
+ if (!ndigit) {
+ return(s);
+ }
+ } else {
+ p = zend_dtoa(value, fmode + 2, ndigit, decpt, sign, &rve);
+ if (*decpt == 9999) {
+ /* Infinity or Nan, convert to inf or nan like printf */
+ *decpt = 0;
+ c = *p;
+ zend_freedtoa(p);
+ return(c == 'I' ? "INF" : "NAN");
+ }
+ /* Make a local copy and adjust rve to be in terms of s */
+ if (pad && fmode) {
+ siz += *decpt;
+ }
+ if ((s = (char *)malloc(siz+1)) == NULL) {
+ zend_freedtoa(p);
+ return(NULL);
+ }
+ (void) strlcpy(s, p, siz);
+ rve = s + (rve - p);
+ zend_freedtoa(p);
+ }
+
+ /* Add trailing zeros */
+ if (pad) {
+ siz -= rve - s;
+ while (--siz) {
+ *rve++ = '0';
+ }
+ *rve = '\0';
+ }
+
+ return(s);
+}
+/* }}} */
+
+static inline char *php_ecvt(double value, int ndigit, int *decpt, int *sign) /* {{{ */
+{
+ return(__cvt(value, ndigit, decpt, sign, 0, 1));
+}
+/* }}} */
+
+static inline char *php_fcvt(double value, int ndigit, int *decpt, int *sign) /* {{{ */
+{
+ return(__cvt(value, ndigit, decpt, sign, 1, 1));
+}
+/* }}} */
+
+PHPAPI char *php_gcvt(double value, int ndigit, char dec_point, char exponent, char *buf) /* {{{ */
+{
+ char *digits, *dst, *src;
+ int i, decpt, sign;
+
+ digits = zend_dtoa(value, 2, ndigit, &decpt, &sign, NULL);
+ if (decpt == 9999) {
+ /*
+ * Infinity or NaN, convert to inf or nan with sign.
+ * We assume the buffer is at least ndigit long.
+ */
+ snprintf(buf, ndigit + 1, "%s%s", (sign && *digits == 'I') ? "-" : "", *digits == 'I' ? "INF" : "NAN");
+ zend_freedtoa(digits);
+ return (buf);
+ }
+
+ dst = buf;
+ if (sign) {
+ *dst++ = '-';
+ }
+
+ for (i = 0; i < ndigit && digits[i] != '\0'; i++);
+
+ if ((decpt >= 0 && decpt - i > 4)
+ || (decpt < 0 && decpt < -3)) { /* use E-style */
+ /* exponential format (e.g. 1.2345e+13) */
+ if (--decpt < 0) {
+ sign = 1;
+ decpt = -decpt;
+ } else {
+ sign = 0;
+ }
+ src = digits;
+ *dst++ = *src++;
+ *dst++ = dec_point;
+ if (*src == '\0') {
+ *dst++ = '0';
+ } else {
+ do {
+ *dst++ = *src++;
+ } while (*src != '\0');
+ }
+ *dst++ = exponent;
+ if (sign) {
+ *dst++ = '-';
+ } else {
+ *dst++ = '+';
+ }
+ if (decpt < 10) {
+ *dst++ = '0' + decpt;
+ *dst = '\0';
+ } else {
+ /* XXX - optimize */
+ for (sign = decpt, i = 0; (sign /= 10) != 0; i++)
+ continue;
+ dst[i + 1] = '\0';
+ while (decpt != 0) {
+ dst[i--] = '0' + decpt % 10;
+ decpt /= 10;
+ }
+ }
+ } else if (decpt < 0) {
+ /* standard format 0. */
+ *dst++ = '0'; /* zero before decimal point */
+ *dst++ = dec_point;
+ do {
+ *dst++ = '0';
+ } while (++decpt < 0);
+ src = digits;
+ while (*src != '\0') {
+ *dst++ = *src++;
+ }
+ *dst = '\0';
+ } else {
+ /* standard format */
+ for (i = 0, src = digits; i < decpt; i++) {
+ if (*src != '\0') {
+ *dst++ = *src++;
+ } else {
+ *dst++ = '0';
+ }
+ }
+ if (*src != '\0') {
+ if (src == digits) {
+ *dst++ = '0'; /* zero before decimal point */
+ }
+ *dst++ = dec_point;
+ for (i = decpt; digits[i] != '\0'; i++) {
+ *dst++ = digits[i];
+ }
+ }
+ *dst = '\0';
+ }
+ zend_freedtoa(digits);
+ return (buf);
+}
+/* }}} */
+
+/* {{{ Apache license */
/* ====================================================================
* Copyright (c) 1995-1998 The Apache Group. All rights reserved.
*
@@ -72,20 +287,7 @@
* SIO stdio-replacement strx_* functions by Panos Tsirigotis
* <panos@alumni.cs.colorado.edu> for xinetd.
*/
-
-#include "php.h"
-
-#include <stddef.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <stdarg.h>
-#include <string.h>
-#include <stdlib.h>
-#include <math.h>
-#ifdef HAVE_INTTYPES_H
-#include <inttypes.h>
-#endif
+/* }}} */
#define FALSE 0
#define TRUE 1
@@ -111,6 +313,7 @@
* which is a pointer to the END of the buffer + 1 (i.e. if the buffer
* is declared as buf[ 100 ], buf_end should be &buf[ 100 ])
*/
+/* char * ap_php_conv_10() {{{ */
char * ap_php_conv_10(register wide_int num, register bool_int is_unsigned,
register bool_int * is_negative, char *buf_end, register int *len)
{
@@ -134,10 +337,10 @@ char * ap_php_conv_10(register wide_int num, register bool_int is_unsigned,
*/
if (*is_negative) {
wide_int t = num + 1;
-
magnitude = ((u_wide_int) - t) + 1;
- } else
+ } else {
magnitude = (u_wide_int) num;
+ }
}
/*
@@ -154,6 +357,7 @@ char * ap_php_conv_10(register wide_int num, register bool_int is_unsigned,
*len = buf_end - p;
return (p);
}
+/* }}} */
/* If you change this value then also change bug24640.phpt.
* Also NDIG must be reasonable smaller than NUM_BUF_SIZE.
@@ -167,18 +371,23 @@ char * ap_php_conv_10(register wide_int num, register bool_int is_unsigned,
* The sign is returned in the is_negative argument (and is not placed
* in buf).
*/
-char * ap_php_conv_fp(register char format, register double num,
- boolean_e add_dp, int precision, bool_int * is_negative, char *buf, int *len)
+/* PHPAPI char * php_conv_fp() {{{ */
+PHPAPI char * php_conv_fp(register char format, register double num,
+ boolean_e add_dp, int precision, char dec_point, bool_int * is_negative, char *buf, int *len)
{
register char *s = buf;
- register char *p;
+ register char *p, *p_orig;
int decimal_point;
- char buf1[NDIG];
- if (format == 'f')
- p = ap_php_fcvt(num, precision, &decimal_point, is_negative, buf1);
- else /* either e or E format */
- p = ap_php_ecvt(num, precision + 1, &decimal_point, is_negative, buf1);
+ if (precision >= NDIG - 1) {
+ precision = NDIG - 2;
+ }
+
+ if (format == 'F') {
+ p_orig = p = php_fcvt(num, precision, &decimal_point, is_negative);
+ } else { /* either e or E format */
+ p_orig = p = php_ecvt(num, precision + 1, &decimal_point, is_negative);
+ }
/*
* Check for Infinity and NaN
@@ -187,17 +396,21 @@ char * ap_php_conv_fp(register char format, register double num,
*len = strlen(p);
memcpy(buf, p, *len + 1);
*is_negative = FALSE;
+ free(p_orig);
return (buf);
}
- if (format == 'f') {
+ if (format == 'F') {
if (decimal_point <= 0) {
- *s++ = '0';
- if (precision > 0) {
- *s++ = '.';
- while (decimal_point++ < 0)
- *s++ = '0';
- } else if (add_dp) {
- *s++ = '.';
+ if (num != 0 || precision > 0) {
+ *s++ = '0';
+ if (precision > 0) {
+ *s++ = dec_point;
+ while (decimal_point++ < 0) {
+ *s++ = '0';
+ }
+ } else if (add_dp) {
+ *s++ = dec_point;
+ }
}
} else {
int addz = decimal_point >= NDIG ? decimal_point - NDIG + 1 : 0;
@@ -209,22 +422,24 @@ char * ap_php_conv_fp(register char format, register double num,
*s++ = '0';
}
if (precision > 0 || add_dp) {
- *s++ = '.';
+ *s++ = dec_point;
}
}
} else {
*s++ = *p++;
- if (precision > 0 || add_dp)
+ if (precision > 0 || add_dp) {
*s++ = '.';
+ }
}
/*
* copy the rest of p, the NUL is NOT copied
*/
- while (*p)
+ while (*p) {
*s++ = *p++;
+ }
- if (format != 'f') {
+ if (format != 'F') {
char temp[EXPONENT_LENGTH]; /* for exponent conversion */
int t_len;
bool_int exponent_is_negative;
@@ -232,27 +447,25 @@ char * ap_php_conv_fp(register char format, register double num,
*s++ = format; /* either e or E */
decimal_point--;
if (decimal_point != 0) {
- p = ap_php_conv_10((wide_int) decimal_point, FALSE, &exponent_is_negative,
- &temp[EXPONENT_LENGTH], &t_len);
+ p = ap_php_conv_10((wide_int) decimal_point, FALSE, &exponent_is_negative, &temp[EXPONENT_LENGTH], &t_len);
*s++ = exponent_is_negative ? '-' : '+';
/*
* Make sure the exponent has at least 2 digits
*/
- if (t_len == 1)
- *s++ = '0';
- while (t_len--)
+ while (t_len--) {
*s++ = *p++;
+ }
} else {
*s++ = '+';
*s++ = '0';
- *s++ = '0';
}
}
*len = s - buf;
+ free(p_orig);
return (buf);
}
-
+/* }}} */
/*
* Convert num to a base X number where X is a power of 2. nbits determines X.
@@ -264,8 +477,7 @@ char * ap_php_conv_fp(register char format, register double num,
* which is a pointer to the END of the buffer + 1 (i.e. if the buffer
* is declared as buf[ 100 ], buf_end should be &buf[ 100 ])
*/
-char * ap_php_conv_p2(register u_wide_int num, register int nbits,
- char format, char *buf_end, register int *len)
+char * ap_php_conv_p2(register u_wide_int num, register int nbits, char format, char *buf_end, register int *len) /* {{{ */
{
register int mask = (1 << nbits) - 1;
register char *p = buf_end;
@@ -282,190 +494,7 @@ char * ap_php_conv_p2(register u_wide_int num, register int nbits,
*len = buf_end - p;
return (p);
}
-
-/*
- * cvt.c - IEEE floating point formatting routines for FreeBSD
- * from GNU libc-4.6.27
- */
-
-/*
- * ap_php_ecvt converts to decimal
- * the number of digits is specified by ndigit
- * decpt is set to the position of the decimal point
- * sign is set to 0 for positive, 1 for negative
- */
-
-
-char * ap_php_cvt(double arg, int ndigits, int *decpt, int *sign, int eflag, char *buf)
-{
- register int r2;
- int mvl;
- double fi, fj;
- register char *p, *p1;
-
- if (ndigits >= NDIG - 1)
- ndigits = NDIG - 2;
- r2 = 0;
- *sign = 0;
- p = &buf[0];
- if (arg < 0) {
- *sign = 1;
- arg = -arg;
- }
- arg = modf(arg, &fi);
- p1 = &buf[NDIG];
- /*
- * Do integer part
- */
- if (fi != 0) {
- while (fi != 0) {
- fj = modf(fi / 10, &fi);
- if (p1 <= &buf[0]) {
- mvl = NDIG - ndigits;
- if (ndigits > 0) {
- memmove(&buf[mvl], &buf[0], NDIG-mvl-1);
- }
- p1 += mvl;
- }
- *--p1 = (int) ((fj + .03) * 10) + '0';
- r2++;
- }
- while (p1 < &buf[NDIG]) {
- *p++ = *p1++;
- }
- } else if (arg > 0) {
- while ((fj = arg * 10) < 1) {
- if (!eflag && (r2 * -1) < ndigits) {
- break;
- }
- arg = fj;
- r2--;
- }
- }
- p1 = &buf[ndigits];
- if (eflag == 0)
- p1 += r2;
- *decpt = r2;
- if (p1 < &buf[0]) {
- buf[0] = '\0';
- return (buf);
- }
- if (p <= p1 && p < &buf[NDIG]) {
- arg = modf(arg * 10, &fj);
- if ((int)fj==10) {
- *p++ = '1';
- fj = 0;
- *decpt = ++r2;
- }
- while (p <= p1 && p < &buf[NDIG]) {
- *p++ = (int) fj + '0';
- arg = modf(arg * 10, &fj);
- }
- }
- if (p1 >= &buf[NDIG]) {
- buf[NDIG - 1] = '\0';
- return (buf);
- }
- p = p1;
- *p1 += 5;
- while (*p1 > '9') {
- *p1 = '0';
- if (p1 > buf)
- ++ * --p1;
- else {
- *p1 = '1';
- (*decpt)++;
- if (eflag == 0) {
- if (p > buf)
- *p = '0';
- p++;
- }
- }
- }
- *p = '\0';
- return (buf);
-}
-
-char * ap_php_ecvt(double arg, int ndigits, int *decpt, int *sign, char *buf)
-{
- return (ap_php_cvt(arg, ndigits, decpt, sign, 1, buf));
-}
-
-char * ap_php_fcvt(double arg, int ndigits, int *decpt, int *sign, char *buf)
-{
- return (ap_php_cvt(arg, ndigits, decpt, sign, 0, buf));
-}
-
-/*
- * ap_php_gcvt - Floating output conversion to
- * minimal length string
- */
-
-char * ap_php_gcvt(double number, int ndigit, char *buf, boolean_e altform)
-{
- int sign, decpt;
- register char *p1, *p2;
- register int i;
- char buf1[NDIG];
-
- if (ndigit >= NDIG - 1) {
- ndigit = NDIG - 2;
- }
-
- p1 = ap_php_ecvt(number, ndigit, &decpt, &sign, buf1);
- p2 = buf;
- if (sign)
- *p2++ = '-';
- for (i = ndigit - 1; i > 0 && p1[i] == '0'; i--)
- ndigit--;
- if ((decpt >= 0 && decpt - ndigit > 4)
- || (decpt < 0 && decpt < -3)) { /* use E-style */
- decpt--;
- *p2++ = *p1++;
- *p2++ = '.';
- for (i = 1; i < ndigit; i++)
- *p2++ = *p1++;
- if (*(p2 - 1) == '.') {
- *p2++ = '0';
- }
- *p2++ = 'e';
- if (decpt < 0) {
- decpt = -decpt;
- *p2++ = '-';
- } else
- *p2++ = '+';
- if (decpt / 100 > 0)
- *p2++ = decpt / 100 + '0';
- if (decpt / 10 > 0)
- *p2++ = (decpt % 100) / 10 + '0';
- *p2++ = decpt % 10 + '0';
- } else {
- if (decpt <= 0) {
- if (*p1 != '0') {
- *p2++ = '0';
- *p2++ = '.';
- }
- while (decpt < 0) {
- decpt++;
- *p2++ = '0';
- }
- }
- for (i = 1; i <= ndigit; i++) {
- *p2++ = *p1++;
- if (i == decpt)
- *p2++ = '.';
- }
- if (ndigit < decpt) {
- while (ndigit++ < decpt)
- *p2++ = '0';
- *p2++ = '.';
- }
- }
- if (p2[-1] == '.' && !altform)
- p2--;
- *p2 = '\0';
- return (buf);
-}
+/* }}} */
/*
* NUM_BUF_SIZE is the size of the buffer used for arithmetic conversions
@@ -550,8 +579,7 @@ typedef struct buf_area buffy;
/*
* Do format conversion placing the output in buffer
*/
-static int format_converter(register buffy * odp, const char *fmt,
- va_list ap)
+static int format_converter(register buffy * odp, const char *fmt, va_list ap) /* {{{ */
{
register char *sp;
register char *bep;
@@ -577,6 +605,10 @@ static int format_converter(register buffy * odp, const char *fmt,
char num_buf[NUM_BUF_SIZE];
char char_buf[2]; /* for printing %% and %<unknown> */
+#ifdef HAVE_LOCALE_H
+ struct lconv *lconv = NULL;
+#endif
+
/*
* Flag variables
*/
@@ -676,6 +708,16 @@ static int format_converter(register buffy * odp, const char *fmt,
fmt++;
modifier = LM_LONG_DOUBLE;
break;
+ case 'I':
+ fmt++;
+#if SIZEOF_LONG_LONG
+ if (*fmt == '6' && *(fmt+1) == '4') {
+ fmt += 2;
+ modifier = LM_LONG_LONG;
+ } else
+#endif
+ modifier = LM_LONG;
+ break;
case 'l':
fmt++;
#if SIZEOF_LONG_LONG
@@ -806,12 +848,13 @@ static int format_converter(register buffy * odp, const char *fmt,
FIX_PRECISION(adjust_precision, precision, s, s_len);
if (*fmt != 'u') {
- if (is_negative)
+ if (is_negative) {
prefix_char = '-';
- else if (print_sign)
+ } else if (print_sign) {
prefix_char = '+';
- else if (print_blank)
+ } else if (print_blank) {
prefix_char = ' ';
+ }
}
break;
@@ -845,8 +888,7 @@ static int format_converter(register buffy * odp, const char *fmt,
break;
#endif
}
- s = ap_php_conv_p2(ui_num, 3, *fmt,
- &num_buf[NUM_BUF_SIZE], &s_len);
+ s = ap_php_conv_p2(ui_num, 3, *fmt, &num_buf[NUM_BUF_SIZE], &s_len);
FIX_PRECISION(adjust_precision, precision, s, s_len);
if (alternate_form && *s != '0') {
*--s = '0';
@@ -885,8 +927,7 @@ static int format_converter(register buffy * odp, const char *fmt,
break;
#endif
}
- s = ap_php_conv_p2(ui_num, 4, *fmt,
- &num_buf[NUM_BUF_SIZE], &s_len);
+ s = ap_php_conv_p2(ui_num, 4, *fmt, &num_buf[NUM_BUF_SIZE], &s_len);
FIX_PRECISION(adjust_precision, precision, s, s_len);
if (alternate_form && i_num != 0) {
*--s = *fmt; /* 'x' or 'X' */
@@ -901,8 +942,9 @@ static int format_converter(register buffy * odp, const char *fmt,
s = va_arg(ap, char *);
if (s != NULL) {
s_len = strlen(s);
- if (adjust_precision && precision < s_len)
+ if (adjust_precision && precision < s_len) {
s_len = precision;
+ }
} else {
s = S_NULL;
s_len = S_NULL_LEN;
@@ -910,8 +952,9 @@ static int format_converter(register buffy * odp, const char *fmt,
pad_char = ' ';
break;
-
+
case 'f':
+ case 'F':
case 'e':
case 'E':
switch(modifier) {
@@ -926,14 +969,20 @@ static int format_converter(register buffy * odp, const char *fmt,
}
if (zend_isnan(fp_num)) {
- s = "nan";
+ s = "NAN";
s_len = 3;
} else if (zend_isinf(fp_num)) {
- s = "inf";
+ s = "INF";
s_len = 3;
} else {
- s = ap_php_conv_fp(*fmt, fp_num, alternate_form,
+#ifdef HAVE_LOCALE_H
+ if (!lconv) {
+ lconv = localeconv();
+ }
+#endif
+ s = php_conv_fp((*fmt == 'f')?'F':*fmt, fp_num, alternate_form,
(adjust_precision == NO) ? FLOAT_DIGITS : precision,
+ (*fmt == 'f')?LCONV_DECIMAL_POINT:'.',
&is_negative, &num_buf[1], &s_len);
if (is_negative)
prefix_char = '-';
@@ -973,28 +1022,33 @@ static int format_converter(register buffy * odp, const char *fmt,
break;
}
- if (adjust_precision == NO)
+ if (adjust_precision == NO) {
precision = FLOAT_DIGITS;
- else if (precision == 0)
+ } else if (precision == 0) {
precision = 1;
+ }
/*
* * We use &num_buf[ 1 ], so that we have room for the sign
*/
- s = ap_php_gcvt(fp_num, precision, &num_buf[1],
- alternate_form);
- if (*s == '-')
+#ifdef HAVE_LOCALE_H
+ if (!lconv) {
+ lconv = localeconv();
+ }
+#endif
+ s = php_gcvt(fp_num, precision, LCONV_DECIMAL_POINT, (*fmt == 'G')?'E':'e', &num_buf[1]);
+ if (*s == '-') {
prefix_char = *s++;
- else if (print_sign)
+ } else if (print_sign) {
prefix_char = '+';
- else if (print_blank)
+ } else if (print_blank) {
prefix_char = ' ';
+ }
s_len = strlen(s);
- if (alternate_form && (q = strchr(s, '.')) == NULL)
+ if (alternate_form && (q = strchr(s, '.')) == NULL) {
s[s_len++] = '.';
- if (*fmt == 'G' && (q = strchr(s, 'e')) != NULL)
- *q = 'E';
+ }
break;
@@ -1103,13 +1157,12 @@ skip_output:
odp->nextb = sp;
return (cc);
}
-
+/* }}} */
/*
* This is the general purpose conversion function.
*/
-static void strx_printv(int *ccp, char *buf, size_t len, const char *format,
- va_list ap)
+static void strx_printv(int *ccp, char *buf, size_t len, const char *format, va_list ap) /* {{{ */
{
buffy od;
int cc;
@@ -1131,14 +1184,45 @@ static void strx_printv(int *ccp, char *buf, size_t len, const char *format,
* Do the conversion
*/
cc = format_converter(&od, format, ap);
- if (len != 0 && od.nextb <= od.buf_end)
+ if (len != 0 && od.nextb <= od.buf_end) {
*(od.nextb) = '\0';
- if (ccp)
+ }
+ if (ccp) {
*ccp = cc;
+ }
+}
+/* }}} */
+
+PHPAPI int ap_php_slprintf(char *buf, size_t len, const char *format,...) /* {{{ */
+{
+ int cc;
+ va_list ap;
+
+ va_start(ap, format);
+ strx_printv(&cc, buf, len, format, ap);
+ va_end(ap);
+ if (cc >= len) {
+ cc = len -1;
+ buf[cc] = '\0';
+ }
+ return cc;
}
+/* }}} */
+PHPAPI int ap_php_vslprintf(char *buf, size_t len, const char *format, va_list ap) /* {{{ */
+{
+ int cc;
+
+ strx_printv(&cc, buf, len, format, ap);
+ if (cc >= len) {
+ cc = len -1;
+ buf[cc] = '\0';
+ }
+ return cc;
+}
+/* }}} */
-PHPAPI int ap_php_snprintf(char *buf, size_t len, const char *format,...)
+PHPAPI int ap_php_snprintf(char *buf, size_t len, const char *format,...) /* {{{ */
{
int cc;
va_list ap;
@@ -1148,15 +1232,16 @@ PHPAPI int ap_php_snprintf(char *buf, size_t len, const char *format,...)
va_end(ap);
return (cc);
}
+/* }}} */
-
-PHPAPI int ap_php_vsnprintf(char *buf, size_t len, const char *format, va_list ap)
+PHPAPI int ap_php_vsnprintf(char *buf, size_t len, const char *format, va_list ap) /* {{{ */
{
int cc;
strx_printv(&cc, buf, len, format, ap);
return (cc);
}
+/* }}} */
/*
* Local variables:
diff --git a/main/snprintf.h b/main/snprintf.h
index ef505692a..b872e854a 100644
--- a/main/snprintf.h
+++ b/main/snprintf.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -17,11 +17,11 @@
+----------------------------------------------------------------------+
*/
-/* $Id: snprintf.h,v 1.32.2.3 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: snprintf.h,v 1.32.2.3.2.5 2007/04/06 19:25:52 andrei Exp $ */
/*
-Comparing: sprintf, snprintf, spprintf
+Comparing: sprintf, snprintf, slprintf, spprintf
sprintf offers the ability to make a lot of failures since it does not know
the size of the buffer it uses. Therefore usage of sprintf often
@@ -36,6 +36,11 @@ snprintf knows the buffers size and will not write behind it. But you will
A bad thing is having a big maximum while in most cases you would
only need a small buffer. If the size of the resulting string is
longer or equal to the buffer size than the buffer is not terminated.
+ The function also returns the number of chars not including the
+ terminating \0 that were needed to fully comply to the print request.
+
+slprintf same as snprintf with the difference that it actually returns the
+ length printed not including the terminating \0.
spprintf is the dynamical version of snprintf. It allocates the buffer in size
as needed and allows a maximum setting as snprintf (turn this feature
@@ -65,12 +70,35 @@ Example:
#ifndef SNPRINTF_H
#define SNPRINTF_H
+typedef int bool_int;
+
+typedef enum {
+ NO = 0, YES = 1
+} boolean_e;
+
+
BEGIN_EXTERN_C()
-PHPAPI int ap_php_snprintf(char *, size_t, const char *, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
-PHPAPI int ap_php_vsnprintf(char *, size_t, const char *, va_list ap) PHP_ATTRIBUTE_FORMAT(printf, 3, 0);
+PHPAPI int ap_php_slprintf(char *buf, size_t len, const char *format,...);
+PHPAPI int ap_php_vslprintf(char *buf, size_t len, const char *format, va_list ap);
+PHPAPI int ap_php_snprintf(char *, size_t, const char *, ...);
+PHPAPI int ap_php_vsnprintf(char *, size_t, const char *, va_list ap);
PHPAPI int php_sprintf (char* s, const char* format, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3);
+PHPAPI char * php_gcvt(double value, int ndigit, char dec_point, char exponent, char *buf);
+PHPAPI char * php_conv_fp(register char format, register double num,
+ boolean_e add_dp, int precision, char dec_point, bool_int * is_negative, char *buf, int *len);
+
END_EXTERN_C()
+#ifdef slprintf
+#undef slprintf
+#endif
+#define slprintf ap_php_slprintf
+
+#ifdef vslprintf
+#undef vslprintf
+#endif
+#define vslprintf ap_php_vslprintf
+
#ifdef snprintf
#undef snprintf
#endif
@@ -87,10 +115,6 @@ END_EXTERN_C()
#define sprintf php_sprintf
typedef enum {
- NO = 0, YES = 1
-} boolean_e;
-
-typedef enum {
LM_STD = 0,
#if SIZEOF_INTMAX_T
LM_INTMAX_T,
@@ -106,11 +130,6 @@ typedef enum {
LM_LONG_DOUBLE
} length_modifier_e;
-extern char * ap_php_cvt(double arg, int ndigits, int *decpt, int *sign, int eflag, char *buf);
-extern char * ap_php_ecvt(double arg, int ndigits, int *decpt, int *sign, char *buf);
-extern char * ap_php_fcvt(double arg, int ndigits, int *decpt, int *sign, char *buf);
-extern char * ap_php_gcvt(double number, int ndigit, char *buf, boolean_e altform);
-
#ifdef PHP_WIN32
# define WIDE_INT __int64
#elif SIZEOF_LONG_LONG_INT
@@ -123,18 +142,12 @@ extern char * ap_php_gcvt(double number, int ndigit, char *buf, boolean_e altfor
typedef WIDE_INT wide_int;
typedef unsigned WIDE_INT u_wide_int;
-typedef int bool_int;
-
extern char * ap_php_conv_10(register wide_int num, register bool_int is_unsigned,
register bool_int * is_negative, char *buf_end, register int *len);
-extern char * ap_php_conv_fp(register char format, register double num,
- boolean_e add_dp, int precision, bool_int * is_negative, char *buf, int *len);
-
extern char * ap_php_conv_p2(register u_wide_int num, register int nbits,
char format, char *buf_end, register int *len);
-
#endif /* SNPRINTF_H */
/*
diff --git a/main/spprintf.c b/main/spprintf.c
index 64543fe89..a13e6ffe2 100644
--- a/main/spprintf.c
+++ b/main/spprintf.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: spprintf.c,v 1.25.2.2.2.1 2006/05/07 12:40:17 helly Exp $ */
+/* $Id: spprintf.c,v 1.25.2.2.2.5 2007/01/01 09:36:11 sebastian Exp $ */
/* This is the spprintf implementation.
* It has emerged from apache snprintf. See original header:
@@ -76,7 +76,6 @@
* SIO stdio-replacement strx_* functions by Panos Tsirigotis
* <panos@alumni.cs.colorado.edu> for xinetd.
*/
-
#include "php.h"
#include <stddef.h>
@@ -91,6 +90,13 @@
#include <inttypes.h>
#endif
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#define LCONV_DECIMAL_POINT (*lconv->decimal_point)
+#else
+#define LCONV_DECIMAL_POINT '.'
+#endif
+
#include "snprintf.h"
#define FALSE 0
@@ -196,6 +202,10 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap)
char num_buf[NUM_BUF_SIZE];
char char_buf[2]; /* for printing %% and %<unknown> */
+#ifdef HAVE_LOCALE_H
+ struct lconv *lconv = NULL;
+#endif
+
/*
* Flag variables
*/
@@ -528,6 +538,7 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap)
case 'f':
+ case 'F':
case 'e':
case 'E':
switch(modifier) {
@@ -548,8 +559,14 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap)
s = "inf";
s_len = 3;
} else {
- s = ap_php_conv_fp(*fmt, fp_num, alternate_form,
- (adjust_precision == NO) ? FLOAT_DIGITS : precision,
+#ifdef HAVE_LOCALE_H
+ if (!lconv) {
+ lconv = localeconv();
+ }
+#endif
+ s = php_conv_fp((*fmt == 'f')?'F':*fmt, fp_num, alternate_form,
+ (adjust_precision == NO) ? FLOAT_DIGITS : precision,
+ (*fmt == 'f')?(*lconv->decimal_point):'.',
&is_negative, &num_buf[1], &s_len);
if (is_negative)
prefix_char = '-';
@@ -596,8 +613,12 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap)
/*
* * We use &num_buf[ 1 ], so that we have room for the sign
*/
- s = ap_php_gcvt(fp_num, precision, &num_buf[1],
- alternate_form);
+#ifdef HAVE_LOCALE_H
+ if (!lconv) {
+ lconv = localeconv();
+ }
+#endif
+ s = php_gcvt(fp_num, precision, *lconv->decimal_point, (*fmt == 'G')?'E':'e', &num_buf[1]);
if (*s == '-')
prefix_char = *s++;
else if (print_sign)
@@ -609,8 +630,6 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap)
if (alternate_form && (q = strchr(s, '.')) == NULL)
s[s_len++] = '.';
- if (*fmt == 'G' && (q = strchr(s, 'e')) != NULL)
- *q = 'E';
break;
@@ -747,7 +766,6 @@ PHPAPI int spprintf(char **pbuf, size_t max_len, const char *format, ...)
va_end(ap);
return (cc);
}
-
/*
* Local variables:
* tab-width: 4
diff --git a/main/spprintf.h b/main/spprintf.h
index 47dd6a25e..389a33a9a 100644
--- a/main/spprintf.h
+++ b/main/spprintf.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: spprintf.h,v 1.11.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: spprintf.h,v 1.11.2.1.2.1 2007/01/01 09:36:11 sebastian Exp $ */
/*
diff --git a/main/streams/cast.c b/main/streams/cast.c
index ac185aa5a..8e80fade0 100644
--- a/main/streams/cast.c
+++ b/main/streams/cast.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: cast.c,v 1.12.2.1 2006/01/01 12:50:18 sniper Exp $ */
+/* $Id: cast.c,v 1.12.2.1.2.1 2007/01/01 09:36:11 sebastian Exp $ */
#define _GNU_SOURCE
#include "php.h"
diff --git a/main/streams/filter.c b/main/streams/filter.c
index 0bb19c202..622e13201 100644
--- a/main/streams/filter.c
+++ b/main/streams/filter.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: filter.c,v 1.17.2.3.2.3 2006/10/11 23:11:26 pollita Exp $ */
+/* $Id: filter.c,v 1.17.2.3.2.9 2007/01/15 17:07:07 tony2001 Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -46,12 +46,12 @@ PHPAPI HashTable *_php_get_stream_filters_hash(TSRMLS_D)
/* API for registering GLOBAL filters */
PHPAPI int php_stream_filter_register_factory(const char *filterpattern, php_stream_filter_factory *factory TSRMLS_DC)
{
- return zend_hash_add(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern), factory, sizeof(*factory), NULL);
+ return zend_hash_add(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern) + 1, factory, sizeof(*factory), NULL);
}
PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern TSRMLS_DC)
{
- return zend_hash_del(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern));
+ return zend_hash_del(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern) + 1);
}
/* API for registering VOLATILE wrappers */
@@ -65,7 +65,7 @@ PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern
zend_hash_copy(FG(stream_filters), &stream_filters_hash, NULL, &tmpfactory, sizeof(php_stream_filter_factory));
}
- return zend_hash_add(FG(stream_filters), (char*)filterpattern, strlen(filterpattern), factory, sizeof(*factory), NULL);
+ return zend_hash_add(FG(stream_filters), (char*)filterpattern, strlen(filterpattern) + 1, factory, sizeof(*factory), NULL);
}
/* Buckets */
@@ -102,6 +102,7 @@ PHPAPI php_stream_bucket *php_stream_bucket_new(php_stream *stream, char *buf, s
}
bucket->is_persistent = is_persistent;
bucket->refcount = 1;
+ bucket->brigade = NULL;
return bucket;
}
@@ -258,18 +259,19 @@ PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval
n = strlen(filtername);
- if (SUCCESS == zend_hash_find(filter_hash, (char*)filtername, n, (void**)&factory)) {
+ if (SUCCESS == zend_hash_find(filter_hash, (char*)filtername, n + 1, (void**)&factory)) {
filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC);
} else if ((period = strrchr(filtername, '.'))) {
/* try a wildcard */
char *wildname;
- wildname = estrdup(filtername);
+ wildname = emalloc(n+3);
+ memcpy(wildname, filtername, n+1);
period = wildname + (period - filtername);
while (period && !filter) {
*period = '\0';
strcat(wildname, ".*");
- if (SUCCESS == zend_hash_find(filter_hash, wildname, strlen(wildname), (void**)&factory)) {
+ if (SUCCESS == zend_hash_find(filter_hash, wildname, strlen(wildname) + 1, (void**)&factory)) {
filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC);
}
diff --git a/main/streams/memory.c b/main/streams/memory.c
index 818e5a813..49469757d 100644
--- a/main/streams/memory.c
+++ b/main/streams/memory.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: memory.c,v 1.8.2.6.2.8 2006/06/29 14:40:49 bjori Exp $ */
+/* $Id: memory.c,v 1.8.2.6.2.17 2007/02/22 23:26:03 helly Exp $ */
#define _GNU_SOURCE
#include "php.h"
@@ -241,14 +241,48 @@ static int php_stream_memory_stat(php_stream *stream, php_stream_statbuf *ssb TS
}
/* }}} */
-php_stream_ops php_stream_memory_ops = {
+static int php_stream_memory_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC) /* {{{ */
+{
+ php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
+ size_t newsize;
+
+ switch(option) {
+ case PHP_STREAM_OPTION_TRUNCATE_API:
+ switch (value) {
+ case PHP_STREAM_TRUNCATE_SUPPORTED:
+ return PHP_STREAM_OPTION_RETURN_OK;
+
+ case PHP_STREAM_TRUNCATE_SET_SIZE:
+ if (ms->mode & TEMP_STREAM_READONLY) {
+ return PHP_STREAM_OPTION_RETURN_ERR;
+ }
+ newsize = *(size_t*)ptrparam;
+ if (newsize <= ms->fsize) {
+ if (newsize < ms->fpos) {
+ ms->fpos = newsize;
+ }
+ } else {
+ ms->data = erealloc(ms->data, newsize);
+ memset(ms->data+ms->fsize, 0, newsize - ms->fsize);
+ ms->fsize = newsize;
+ }
+ ms->fsize = newsize;
+ return PHP_STREAM_OPTION_RETURN_OK;
+ }
+ default:
+ return PHP_STREAM_OPTION_RETURN_NOTIMPL;
+ }
+}
+/* }}} */
+
+PHPAPI php_stream_ops php_stream_memory_ops = {
php_stream_memory_write, php_stream_memory_read,
php_stream_memory_close, php_stream_memory_flush,
"MEMORY",
php_stream_memory_seek,
php_stream_memory_cast,
php_stream_memory_stat,
- NULL /* set_option */
+ php_stream_memory_set_option
};
@@ -266,7 +300,7 @@ PHPAPI php_stream *_php_stream_memory_create(int mode STREAMS_DC TSRMLS_DC)
self->mode = mode;
self->owner_ptr = NULL;
- stream = php_stream_alloc(&php_stream_memory_ops, self, 0, mode & TEMP_STREAM_READONLY ? "r+b" : "w+b");
+ stream = php_stream_alloc_rel(&php_stream_memory_ops, self, 0, mode & TEMP_STREAM_READONLY ? "rb" : "w+b");
stream->flags |= PHP_STREAM_FLAG_NO_BUFFER;
return stream;
}
@@ -493,12 +527,15 @@ static int php_stream_temp_set_option(php_stream *stream, int option, int value,
}
return PHP_STREAM_OPTION_RETURN_OK;
default:
+ if (ts->innerstream) {
+ return php_stream_set_option(ts->innerstream, option, value, ptrparam);
+ }
return PHP_STREAM_OPTION_RETURN_NOTIMPL;
}
}
/* }}} */
-php_stream_ops php_stream_temp_ops = {
+PHPAPI php_stream_ops php_stream_temp_ops = {
php_stream_temp_write, php_stream_temp_read,
php_stream_temp_close, php_stream_temp_flush,
"TEMP",
@@ -520,9 +557,9 @@ PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STR
self->smax = max_memory_usage;
self->mode = mode;
self->meta = NULL;
- stream = php_stream_alloc(&php_stream_temp_ops, self, 0, mode & TEMP_STREAM_READONLY ? "r+b" : "w+b");
+ stream = php_stream_alloc_rel(&php_stream_temp_ops, self, 0, mode & TEMP_STREAM_READONLY ? "rb" : "w+b");
stream->flags |= PHP_STREAM_FLAG_NO_BUFFER;
- self->innerstream = php_stream_memory_create(mode);
+ self->innerstream = php_stream_memory_create_rel(mode);
((php_stream_memory_data*)self->innerstream->abstract)->owner_ptr = &self->innerstream;
return stream;
@@ -551,7 +588,7 @@ PHPAPI php_stream *_php_stream_temp_open(int mode, size_t max_memory_usage, char
}
/* }}} */
-php_stream_ops php_stream_rfc2397_ops = {
+PHPAPI php_stream_ops php_stream_rfc2397_ops = {
php_stream_temp_write, php_stream_temp_read,
php_stream_temp_close, php_stream_temp_flush,
"RFC2397",
@@ -673,7 +710,6 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, cha
if ((stream = php_stream_temp_create_rel(0, ~0u)) != NULL) {
/* store data */
php_stream_temp_write(stream, comma, ilen TSRMLS_CC);
- efree(comma);
php_stream_temp_seek(stream, 0, SEEK_SET, &newoffs TSRMLS_CC);
/* set special stream stuff (enforce exact mode) */
vlen = strlen(mode);
@@ -685,14 +721,15 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, cha
stream->ops = &php_stream_rfc2397_ops;
ts = (php_stream_temp_data*)stream->abstract;
assert(ts != NULL);
- ts->mode = mode && mode[0] == 'r' ? TEMP_STREAM_READONLY : 0;
+ ts->mode = mode && mode[0] == 'r' && mode[1] != '+' ? TEMP_STREAM_READONLY : 0;
ts->meta = meta;
}
+ efree(comma);
return stream;
}
-static php_stream_wrapper_ops php_stream_rfc2397_wops = {
+PHPAPI php_stream_wrapper_ops php_stream_rfc2397_wops = {
php_stream_url_wrap_rfc2397,
NULL, /* close */
NULL, /* fstat */
@@ -705,10 +742,10 @@ static php_stream_wrapper_ops php_stream_rfc2397_wops = {
NULL /* rmdir */
};
-php_stream_wrapper php_stream_rfc2397_wrapper = {
+PHPAPI php_stream_wrapper php_stream_rfc2397_wrapper = {
&php_stream_rfc2397_wops,
NULL,
- 0, /* is_url */
+ 1, /* is_url */
};
/*
diff --git a/main/streams/mmap.c b/main/streams/mmap.c
index 81642353b..5fee2bbad 100644
--- a/main/streams/mmap.c
+++ b/main/streams/mmap.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: mmap.c,v 1.8.2.1 2006/01/01 12:50:18 sniper Exp $ */
+/* $Id: mmap.c,v 1.8.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */
/* Memory Mapping interface for streams */
#include "php.h"
diff --git a/main/streams/php_stream_context.h b/main/streams/php_stream_context.h
index d840944af..e52e2bc56 100644
--- a/main/streams/php_stream_context.h
+++ b/main/streams/php_stream_context.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_stream_context.h,v 1.11.2.1 2006/01/01 12:50:18 sniper Exp $ */
+/* $Id: php_stream_context.h,v 1.11.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */
/* Stream context and status notification related definitions */
diff --git a/main/streams/php_stream_filter_api.h b/main/streams/php_stream_filter_api.h
index 6f40a1d4b..97b232053 100644
--- a/main/streams/php_stream_filter_api.h
+++ b/main/streams/php_stream_filter_api.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_stream_filter_api.h,v 1.13.2.1 2006/01/01 12:50:18 sniper Exp $ */
+/* $Id: php_stream_filter_api.h,v 1.13.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */
/* The filter API works on the principle of "Bucket-Brigades". This is
* partially inspired by the Apache 2 method of doing things, although
diff --git a/main/streams/php_stream_mmap.h b/main/streams/php_stream_mmap.h
index 407bbfcd8..5cd5c4155 100644
--- a/main/streams/php_stream_mmap.h
+++ b/main/streams/php_stream_mmap.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_stream_mmap.h,v 1.5.2.1 2006/01/01 12:50:18 sniper Exp $ */
+/* $Id: php_stream_mmap.h,v 1.5.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */
/* Memory Mapping interface for streams.
* The intention is to provide a uniform interface over the most common
diff --git a/main/streams/php_stream_plain_wrapper.h b/main/streams/php_stream_plain_wrapper.h
index 9c310e343..6ce262184 100644
--- a/main/streams/php_stream_plain_wrapper.h
+++ b/main/streams/php_stream_plain_wrapper.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_stream_plain_wrapper.h,v 1.7.2.2 2006/01/01 12:50:18 sniper Exp $ */
+/* $Id: php_stream_plain_wrapper.h,v 1.7.2.2.2.1 2007/01/01 09:36:12 sebastian Exp $ */
/* definitions for the plain files wrapper */
diff --git a/main/streams/php_stream_transport.h b/main/streams/php_stream_transport.h
index d8433831f..e797c1092 100644
--- a/main/streams/php_stream_transport.h
+++ b/main/streams/php_stream_transport.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_stream_transport.h,v 1.10.2.1 2006/01/01 12:50:18 sniper Exp $ */
+/* $Id: php_stream_transport.h,v 1.10.2.1.2.4 2007/02/05 05:15:16 andi Exp $ */
#if HAVE_SYS_SOCKET_H
# include <sys/socket.h>
@@ -104,8 +104,19 @@ PHPAPI int php_stream_xport_recvfrom(php_stream *stream, char *buf, size_t bufle
* sending it as OOB data */
PHPAPI int php_stream_xport_sendto(php_stream *stream, const char *buf, size_t buflen,
long flags, void *addr, socklen_t addrlen TSRMLS_DC);
+
+typedef enum {
+ STREAM_SHUT_RD,
+ STREAM_SHUT_WR,
+ STREAM_SHUT_RDWR
+} stream_shutdown_t;
+
+/* Similar to shutdown() system call; shut down part of a full-duplex
+ * connection */
+PHPAPI int php_stream_xport_shutdown(php_stream *stream, stream_shutdown_t how TSRMLS_DC);
END_EXTERN_C()
+
/* Structure definition for the set_option interface that the above functions wrap */
typedef struct _php_stream_xport_param {
@@ -116,11 +127,13 @@ typedef struct _php_stream_xport_param {
STREAM_XPORT_OP_GET_NAME,
STREAM_XPORT_OP_GET_PEER_NAME,
STREAM_XPORT_OP_RECV,
- STREAM_XPORT_OP_SEND
+ STREAM_XPORT_OP_SEND,
+ STREAM_XPORT_OP_SHUTDOWN
} op;
unsigned int want_addr:1;
unsigned int want_textaddr:1;
unsigned int want_errortext:1;
+ unsigned int how:2;
struct {
char *name;
diff --git a/main/streams/php_stream_userspace.h b/main/streams/php_stream_userspace.h
index f7acf113b..095f06c1b 100644
--- a/main/streams/php_stream_userspace.h
+++ b/main/streams/php_stream_userspace.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_stream_userspace.h,v 1.5.2.1 2006/01/01 12:50:18 sniper Exp $ */
+/* $Id: php_stream_userspace.h,v 1.5.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */
/* for user-space streams */
diff --git a/main/streams/php_streams_int.h b/main/streams/php_streams_int.h
index 1c037457a..f7e0c7b15 100644
--- a/main/streams/php_streams_int.h
+++ b/main/streams/php_streams_int.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_streams_int.h,v 1.7.2.2.2.1 2006/09/14 09:58:27 dmitry Exp $ */
+/* $Id: php_streams_int.h,v 1.7.2.2.2.2 2007/01/01 09:36:12 sebastian Exp $ */
#if ZEND_DEBUG
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index 6a62f021f..3ed947e9f 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: plain_wrapper.c,v 1.52.2.6.2.8 2006/10/19 09:49:44 dmitry Exp $ */
+/* $Id: plain_wrapper.c,v 1.52.2.6.2.21 2007/04/18 14:23:06 dmitry Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -39,6 +39,11 @@
#include "php_streams_int.h"
+#define php_stream_fopen_from_fd_int(fd, mode, persistent_id) _php_stream_fopen_from_fd_int((fd), (mode), (persistent_id) STREAMS_CC TSRMLS_CC)
+#define php_stream_fopen_from_fd_int_rel(fd, mode, persistent_id) _php_stream_fopen_from_fd_int((fd), (mode), (persistent_id) STREAMS_REL_CC TSRMLS_CC)
+#define php_stream_fopen_from_file_int(file, mode) _php_stream_fopen_from_file_int((file), (mode) STREAMS_CC TSRMLS_CC)
+#define php_stream_fopen_from_file_int_rel(file, mode) _php_stream_fopen_from_file_int((file), (mode) STREAMS_REL_CC TSRMLS_CC)
+
/* parse standard "fopen" modes into open() flags */
PHPAPI int php_stream_parse_fopen_modes(const char *mode, int *open_flags)
{
@@ -128,12 +133,44 @@ static int do_fstat(php_stdio_stream_data *d, int force)
return 0;
}
+static php_stream *_php_stream_fopen_from_fd_int(int fd, const char *mode, const char *persistent_id STREAMS_DC TSRMLS_DC)
+{
+ php_stdio_stream_data *self;
+
+ self = pemalloc_rel_orig(sizeof(*self), persistent_id);
+ memset(self, 0, sizeof(*self));
+ self->file = NULL;
+ self->is_pipe = 0;
+ self->lock_flag = LOCK_UN;
+ self->is_process_pipe = 0;
+ self->temp_file_name = NULL;
+ self->fd = fd;
+
+ return php_stream_alloc_rel(&php_stream_stdio_ops, self, persistent_id, mode);
+}
+
+static php_stream *_php_stream_fopen_from_file_int(FILE *file, const char *mode STREAMS_DC TSRMLS_DC)
+{
+ php_stdio_stream_data *self;
+
+ self = emalloc_rel_orig(sizeof(*self));
+ memset(self, 0, sizeof(*self));
+ self->file = file;
+ self->is_pipe = 0;
+ self->lock_flag = LOCK_UN;
+ self->is_process_pipe = 0;
+ self->temp_file_name = NULL;
+ self->fd = fileno(file);
+
+ return php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode);
+}
+
PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, char **opened_path STREAMS_DC TSRMLS_DC)
{
int fd = php_open_temporary_fd(dir, pfx, opened_path TSRMLS_CC);
if (fd != -1) {
- php_stream *stream = php_stream_fopen_from_fd_rel(fd, "r+b", NULL);
+ php_stream *stream = php_stream_fopen_from_fd_int_rel(fd, "r+b", NULL);
if (stream) {
return stream;
}
@@ -152,7 +189,7 @@ PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC TSRMLS_DC)
int fd = php_open_temporary_fd(NULL, "php", &opened_path TSRMLS_CC);
if (fd != -1) {
- php_stream *stream = php_stream_fopen_from_fd_rel(fd, "r+b", NULL);
+ php_stream *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;
@@ -174,36 +211,26 @@ PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC TSRMLS_DC)
PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const char *persistent_id STREAMS_DC TSRMLS_DC)
{
- php_stdio_stream_data *self;
- php_stream *stream;
-
- self = pemalloc_rel_orig(sizeof(*self), persistent_id);
- memset(self, 0, sizeof(*self));
- self->file = NULL;
- self->is_pipe = 0;
- self->lock_flag = LOCK_UN;
- self->is_process_pipe = 0;
- self->temp_file_name = NULL;
- self->fd = fd;
+ php_stream *stream = php_stream_fopen_from_fd_int_rel(fd, mode, persistent_id);
+
+ if (stream) {
+ php_stdio_stream_data *self = (php_stdio_stream_data*)stream->abstract;
#ifdef S_ISFIFO
- /* detect if this is a pipe */
- if (self->fd >= 0) {
- self->is_pipe = (do_fstat(self, 0) == 0 && S_ISFIFO(self->sb.st_mode)) ? 1 : 0;
- }
+ /* detect if this is a pipe */
+ if (self->fd >= 0) {
+ self->is_pipe = (do_fstat(self, 0) == 0 && S_ISFIFO(self->sb.st_mode)) ? 1 : 0;
+ }
#elif defined(PHP_WIN32)
- {
- long handle = _get_osfhandle(self->fd);
+ {
+ zend_uintptr_t handle = _get_osfhandle(self->fd);
- if (handle != 0xFFFFFFFF) {
- self->is_pipe = GetFileType((HANDLE)handle) == FILE_TYPE_PIPE;
+ if (handle != (zend_uintptr_t)INVALID_HANDLE_VALUE) {
+ self->is_pipe = GetFileType((HANDLE)handle) == FILE_TYPE_PIPE;
+ }
}
- }
#endif
- stream = php_stream_alloc_rel(&php_stream_stdio_ops, self, persistent_id, mode);
-
- if (stream) {
if (self->is_pipe) {
stream->flags |= PHP_STREAM_FLAG_NO_SEEK;
} else {
@@ -222,36 +249,26 @@ PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const cha
PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STREAMS_DC TSRMLS_DC)
{
- php_stdio_stream_data *self;
- php_stream *stream;
-
- self = emalloc_rel_orig(sizeof(*self));
- memset(self, 0, sizeof(*self));
- self->file = file;
- self->is_pipe = 0;
- self->lock_flag = LOCK_UN;
- self->is_process_pipe = 0;
- self->temp_file_name = NULL;
- self->fd = fileno(file);
+ php_stream *stream = php_stream_fopen_from_file_int_rel(file, mode);
+
+ if (stream) {
+ php_stdio_stream_data *self = (php_stdio_stream_data*)stream->abstract;
#ifdef S_ISFIFO
- /* detect if this is a pipe */
- if (self->fd >= 0) {
- self->is_pipe = (do_fstat(self, 0) == 0 && S_ISFIFO(self->sb.st_mode)) ? 1 : 0;
- }
+ /* detect if this is a pipe */
+ if (self->fd >= 0) {
+ self->is_pipe = (do_fstat(self, 0) == 0 && S_ISFIFO(self->sb.st_mode)) ? 1 : 0;
+ }
#elif defined(PHP_WIN32)
- {
- long handle = _get_osfhandle(self->fd);
+ {
+ zend_uintptr_t handle = _get_osfhandle(self->fd);
- if (handle != 0xFFFFFFFF) {
- self->is_pipe = GetFileType((HANDLE)handle) == FILE_TYPE_PIPE;
+ if (handle != (zend_uintptr_t)INVALID_HANDLE_VALUE) {
+ self->is_pipe = GetFileType((HANDLE)handle) == FILE_TYPE_PIPE;
+ }
}
- }
#endif
- stream = php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode);
-
- if (stream) {
if (self->is_pipe) {
stream->flags |= PHP_STREAM_FLAG_NO_SEEK;
} else {
@@ -312,9 +329,19 @@ static size_t php_stdiop_read(php_stream *stream, char *buf, size_t count TSRMLS
assert(data != NULL);
if (data->fd >= 0) {
+ if (stream->eof && !data->is_pipe) {
+ return 0;
+ }
ret = read(data->fd, buf, count);
-
- stream->eof = (ret == 0 || (ret == (size_t)-1 && errno != EWOULDBLOCK));
+
+ if (ret == (size_t)-1 && errno == EINTR) {
+ /* Read was interrupted, retry once,
+ If read still fails, giveup with feof==0
+ so script can retry if desired */
+ ret = read(data->fd, buf, count);
+ }
+
+ stream->eof = (ret == 0 || (ret == (size_t)-1 && errno != EWOULDBLOCK && errno != EINTR));
} else {
#if HAVE_FLUSHIO
@@ -372,16 +399,7 @@ static int php_stdiop_close(php_stream *stream, int close_handle TSRMLS_DC)
data->file = NULL;
}
} else if (data->fd != -1) {
-#if PHP_DEBUG
- if ((data->fd == 1 || data->fd == 2) && 0 == strcmp(sapi_module.name, "cli")) {
- /* don't close stdout or stderr in CLI in DEBUG mode, as we want to see any leaks */
- ret = 0;
- } else {
- ret = close(data->fd);
- }
-#else
ret = close(data->fd);
-#endif
data->fd = -1;
} else {
return 0; /* everything should be closed already -> success */
@@ -583,7 +601,7 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
return -1;
}
- if ((long) ptrparam == PHP_STREAM_LOCK_SUPPORTED) {
+ if ((zend_uintptr_t) ptrparam == PHP_STREAM_LOCK_SUPPORTED) {
return 0;
}
@@ -607,9 +625,16 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
case PHP_STREAM_MMAP_MAP_RANGE:
do_fstat(data, 1);
+ if (range->length == 0 && range->offset > 0 && range->offset < data->sb.st_size) {
+ range->length = data->sb.st_size - range->offset;
+ }
if (range->length == 0 || range->length > data->sb.st_size) {
range->length = data->sb.st_size;
}
+ if (range->offset >= data->sb.st_size) {
+ range->offset = data->sb.st_size;
+ range->length = 0;
+ }
switch (range->mode) {
case PHP_STREAM_MAP_MODE_READONLY:
prot = PROT_READ;
@@ -689,8 +714,16 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
return PHP_STREAM_OPTION_RETURN_ERR;
}
- if (range->length == 0) {
- range->length = GetFileSize(hfile, NULL) - range->offset;
+ size = GetFileSize(hfile, NULL);
+ if (range->length == 0 && range->offset > 0 && range->offset < size) {
+ range->length = size - range->offset;
+ }
+ if (range->length == 0 || range->length > size) {
+ range->length = size;
+ }
+ if (range->offset >= size) {
+ range->offset = size;
+ range->length = 0;
}
/* figure out how big a chunk to map to be able to view the part that we need */
@@ -740,8 +773,13 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
case PHP_STREAM_TRUNCATE_SUPPORTED:
return fd == -1 ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK;
- case PHP_STREAM_TRUNCATE_SET_SIZE:
- return ftruncate(fd, *(size_t*)ptrparam) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR;
+ case PHP_STREAM_TRUNCATE_SET_SIZE: {
+ ptrdiff_t new_size = *(ptrdiff_t*)ptrparam;
+ if (new_size < 0) {
+ return PHP_STREAM_OPTION_RETURN_ERR;
+ }
+ return ftruncate(fd, new_size) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR;
+ }
}
default:
@@ -862,12 +900,12 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha
*opened_path = realpath;
realpath = NULL;
}
- if (realpath) {
- efree(realpath);
- }
/* fall through */
case PHP_STREAM_PERSISTENT_FAILURE:
+ if (realpath) {
+ efree(realpath);
+ }
efree(persistent_id);;
return ret;
}
@@ -877,7 +915,11 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha
if (fd != -1) {
- ret = php_stream_fopen_from_fd_rel(fd, mode, persistent_id);
+ if (options & STREAM_OPEN_FOR_INCLUDE) {
+ ret = php_stream_fopen_from_fd_int_rel(fd, mode, persistent_id);
+ } else {
+ ret = php_stream_fopen_from_fd_rel(fd, mode, persistent_id);
+ }
if (ret) {
if (opened_path) {
@@ -891,6 +933,8 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha
efree(persistent_id);
}
+ /* WIN32 always set ISREG flag */
+#ifndef PHP_WIN32
/* sanity checks for include/require.
* We check these after opening the stream, so that we save
* on fstat() syscalls */
@@ -899,15 +943,16 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha
int r;
r = do_fstat(self, 0);
- if (
-#ifndef PHP_WIN32
- (r != 0) || /* it is OK for fstat to fail under win32 */
-#endif
- (r == 0 && !S_ISREG(self->sb.st_mode))) {
+ if ((r == 0 && !S_ISREG(self->sb.st_mode))) {
+ if (opened_path) {
+ efree(*opened_path);
+ *opened_path = NULL;
+ }
php_stream_close(ret);
return NULL;
}
}
+#endif
return ret;
}
@@ -1269,7 +1314,7 @@ not_relative_path:
#ifdef PHP_WIN32
if (IS_SLASH(filename[0])) {
- int cwd_len;
+ size_t cwd_len;
char *cwd;
cwd = virtual_getcwd_ex(&cwd_len TSRMLS_CC);
/* getcwd() will return always return [DRIVE_LETTER]:/) on windows. */
diff --git a/main/streams/streams.c b/main/streams/streams.c
index bd8901388..adc41beaa 100755
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: streams.c,v 1.82.2.6.2.8 2006/10/03 19:51:01 iliaa Exp $ */
+/* $Id: streams.c,v 1.82.2.6.2.12 2007/03/03 19:01:34 helly Exp $ */
#define _GNU_SOURCE
#include "php.h"
@@ -279,6 +279,10 @@ PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC) /*
int preserve_handle = close_options & PHP_STREAM_FREE_PRESERVE_HANDLE ? 1 : 0;
int release_cast = 1;
+ if (stream->flags & PHP_STREAM_FLAG_NO_CLOSE) {
+ preserve_handle = 1;
+ }
+
#if STREAM_DEBUG
fprintf(stderr, "stream_free: %s:%p[%s] in_free=%d opts=%08x\n", stream->ops->label, stream, stream->orig_path, stream->in_free, close_options);
#endif
@@ -1449,12 +1453,12 @@ PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *w
return FAILURE;
}
- return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len, &wrapper, sizeof(wrapper), NULL);
+ return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL);
}
PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC)
{
- return zend_hash_del(&url_stream_wrappers_hash, protocol, strlen(protocol));
+ return zend_hash_del(&url_stream_wrappers_hash, protocol, strlen(protocol) + 1);
}
static void clone_wrapper_hash(TSRMLS_D)
@@ -1479,7 +1483,7 @@ PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_w
clone_wrapper_hash(TSRMLS_C);
}
- return zend_hash_add(FG(stream_wrappers), protocol, protocol_len, &wrapper, sizeof(wrapper), NULL);
+ return zend_hash_add(FG(stream_wrappers), protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL);
}
PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC)
@@ -1488,7 +1492,7 @@ PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC)
clone_wrapper_hash(TSRMLS_C);
}
- return zend_hash_del(FG(stream_wrappers), protocol, strlen(protocol));
+ return zend_hash_del(FG(stream_wrappers), protocol, strlen(protocol) + 1);
}
/* }}} */
@@ -1521,11 +1525,11 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Use of \"zlib:\" wrapper is deprecated; please use \"compress.zlib://\" instead.");
}
- if (protocol) {
- if (FAILURE == zend_hash_find(wrapper_hash, (char*)protocol, n, (void**)&wrapperpp)) {
- char *tmp = estrndup(protocol, n);
+ if (protocol) {
+ char *tmp = estrndup(protocol, n);
+ if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n + 1, (void**)&wrapperpp)) {
php_strtolower(tmp, n);
- if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n, (void**)&wrapperpp)) {
+ if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n + 1, (void**)&wrapperpp)) {
char wrapper_name[32];
if (n >= sizeof(wrapper_name)) {
@@ -1538,8 +1542,8 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
wrapperpp = NULL;
protocol = NULL;
}
- efree(tmp);
}
+ efree(tmp);
}
/* TODO: curl based streams probably support file:// properly */
if (!protocol || !strncasecmp(protocol, "file", n)) {
@@ -1588,7 +1592,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
}
/* Check again, the original check might have not known the protocol name */
- if (zend_hash_find(wrapper_hash, "file", sizeof("file")-1, (void**)&wrapperpp) == SUCCESS) {
+ if (zend_hash_find(wrapper_hash, "file", sizeof("file"), (void**)&wrapperpp) == SUCCESS) {
return *wrapperpp;
}
@@ -1765,10 +1769,14 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int optio
}
if (wrapper) {
-
- stream = wrapper->wops->stream_opener(wrapper,
+ if (!wrapper->wops->stream_opener) {
+ php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS TSRMLS_CC,
+ "wrapper does not support stream open");
+ } else {
+ stream = wrapper->wops->stream_opener(wrapper,
path_to_open, mode, options ^ REPORT_ERRORS,
opened_path, context STREAMS_REL_CC TSRMLS_CC);
+ }
/* if the caller asked for a persistent stream but the wrapper did not
* return one, force an error here */
diff --git a/main/streams/transports.c b/main/streams/transports.c
index c0ec5ec1d..36cf85a9c 100644
--- a/main/streams/transports.c
+++ b/main/streams/transports.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: transports.c,v 1.16.2.1 2006/01/01 12:50:18 sniper Exp $ */
+/* $Id: transports.c,v 1.16.2.1.2.4 2007/02/24 15:48:40 iliaa Exp $ */
#include "php.h"
#include "php_streams_int.h"
@@ -31,12 +31,12 @@ PHPAPI HashTable *php_stream_xport_get_hash(void)
PHPAPI int php_stream_xport_register(char *protocol, php_stream_transport_factory factory TSRMLS_DC)
{
- return zend_hash_update(&xport_hash, protocol, strlen(protocol), &factory, sizeof(factory), NULL);
+ return zend_hash_update(&xport_hash, protocol, strlen(protocol) + 1, &factory, sizeof(factory), NULL);
}
PHPAPI int php_stream_xport_unregister(char *protocol TSRMLS_DC)
{
- return zend_hash_del(&xport_hash, protocol, strlen(protocol));
+ return zend_hash_del(&xport_hash, protocol, strlen(protocol) + 1);
}
#define ERR_REPORT(out_err, fmt, arg) \
@@ -106,7 +106,8 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int
}
if (protocol) {
- if (FAILURE == zend_hash_find(&xport_hash, (char*)protocol, n, (void**)&factory)) {
+ char *tmp = estrndup(protocol, n);
+ if (FAILURE == zend_hash_find(&xport_hash, (char*)tmp, n + 1, (void**)&factory)) {
char wrapper_name[32];
if (n >= sizeof(wrapper_name))
@@ -116,8 +117,10 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int
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) {
@@ -136,7 +139,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int
if ((flags & STREAM_XPORT_SERVER) == 0) {
/* client */
- if (flags & STREAM_XPORT_CONNECT) {
+ if (flags & (STREAM_XPORT_CONNECT|STREAM_XPORT_CONNECT_ASYNC)) {
if (-1 == php_stream_xport_connect(stream, name, namelen,
flags & STREAM_XPORT_CONNECT_ASYNC ? 1 : 0,
timeout, &error_text, error_code TSRMLS_CC)) {
@@ -486,6 +489,25 @@ PHPAPI int php_stream_xport_sendto(php_stream *stream, const char *buf, size_t b
return -1;
}
+/* Similar to shutdown() system call; shut down part of a full-duplex
+ * connection */
+PHPAPI int php_stream_xport_shutdown(php_stream *stream, stream_shutdown_t how TSRMLS_DC)
+{
+ php_stream_xport_param param;
+ int ret = 0;
+
+ memset(&param, 0, sizeof(param));
+
+ param.op = STREAM_XPORT_OP_SHUTDOWN;
+ param.how = how;
+
+ ret = php_stream_set_option(stream, PHP_STREAM_OPTION_XPORT_API, 0, &param);
+
+ if (ret == PHP_STREAM_OPTION_RETURN_OK) {
+ return param.outputs.returncode;
+ }
+ return -1;
+}
/*
* Local variables:
diff --git a/main/streams/userspace.c b/main/streams/userspace.c
index dc99c5c66..6bf110abc 100644
--- a/main/streams/userspace.c
+++ b/main/streams/userspace.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: userspace.c,v 1.31.2.3.2.1 2006/08/14 15:01:29 tony2001 Exp $ */
+/* $Id: userspace.c,v 1.31.2.3.2.4 2007/02/13 19:50:59 tony2001 Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -455,7 +455,7 @@ PHP_FUNCTION(stream_wrapper_register)
RETURN_TRUE;
} else {
/* We failed. But why? */
- if (zend_hash_exists(php_stream_get_url_stream_wrappers_hash(), protocol, protocol_len)) {
+ if (zend_hash_exists(php_stream_get_url_stream_wrappers_hash(), protocol, protocol_len + 1)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Protocol %s:// is already defined.", protocol);
} else {
/* Should never happen */
@@ -511,7 +511,7 @@ PHP_FUNCTION(stream_wrapper_restore)
RETURN_TRUE;
}
- if ((zend_hash_find(global_wrapper_hash, protocol, protocol_len, (void**)&wrapperpp) == FAILURE) || !wrapperpp) {
+ if ((zend_hash_find(global_wrapper_hash, protocol, protocol_len + 1, (void**)&wrapperpp) == FAILURE) || !wrapperpp) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s:// never existed, nothing to restore", protocol);
RETURN_FALSE;
}
@@ -759,6 +759,10 @@ static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, o
retval = NULL;
}
+ if (ret) {
+ return ret;
+ }
+
/* now determine where we are */
ZVAL_STRINGL(&func_name, USERSTREAM_TELL, sizeof(USERSTREAM_TELL)-1, 0);
@@ -768,16 +772,20 @@ static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, o
&retval,
0, NULL, 0, NULL TSRMLS_CC);
- if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_LONG)
+ if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_LONG) {
*newoffs = Z_LVAL_P(retval);
- else
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_TELL " is not implemented!",
- us->wrapper->classname);
+ ret = 0;
+ } else if (call_result == FAILURE) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_TELL " is not implemented!", us->wrapper->classname);
+ ret = -1;
+ } else {
+ ret = -1;
+ }
- if (retval)
+ if (retval) {
zval_ptr_dtor(&retval);
-
- return 0;
+ }
+ return ret;
}
/* parse the return value from one of the stat functions and store the
diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c
index 60084545d..63d6b3e1b 100644
--- a/main/streams/xp_socket.c
+++ b/main/streams/xp_socket.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: xp_socket.c,v 1.33.2.2.2.1 2006/10/11 12:53:56 tony2001 Exp $ */
+/* $Id: xp_socket.c,v 1.33.2.2.2.4 2007/01/01 09:36:12 sebastian Exp $ */
#include "php.h"
#include "ext/standard/file.h"
@@ -369,6 +369,24 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void
return PHP_STREAM_OPTION_RETURN_OK;
+#ifdef HAVE_SHUTDOWN
+# ifndef SHUT_RD
+# define SHUT_RD 0
+# endif
+# ifndef SHUT_WR
+# define SHUT_WR 1
+# endif
+# ifndef SHUT_RDWR
+# define SHUT_RDWR 2
+# endif
+ case STREAM_XPORT_OP_SHUTDOWN: {
+ static const int shutdown_how[] = {SHUT_RD, SHUT_WR, SHUT_RDWR};
+
+ xparam->outputs.returncode = shutdown(sock->socket, shutdown_how[xparam->how]);
+ return PHP_STREAM_OPTION_RETURN_OK;
+ }
+#endif
+
default:
return PHP_STREAM_OPTION_RETURN_NOTIMPL;
}
@@ -624,6 +642,7 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
if (xparam->want_errortext) {
spprintf(&xparam->outputs.error_text, 0, "local_addr context option is not a string.");
}
+ efree(host);
return -1;
}
bindto = parse_ip_address_ex(Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval), &bindport, xparam->want_errortext, &xparam->outputs.error_text TSRMLS_CC);
diff --git a/main/strlcat.c b/main/strlcat.c
index 6e50ecc35..c11298af1 100644
--- a/main/strlcat.c
+++ b/main/strlcat.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: strlcat.c,v 1.13.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: strlcat.c,v 1.13.2.1.2.1 2007/01/01 09:36:11 sebastian Exp $ */
#include "php.h"
diff --git a/main/strlcpy.c b/main/strlcpy.c
index 6dfd88e16..f6b80a0b3 100644
--- a/main/strlcpy.c
+++ b/main/strlcpy.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: strlcpy.c,v 1.13.2.1 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: strlcpy.c,v 1.13.2.1.2.1 2007/01/01 09:36:11 sebastian Exp $ */
#include "php.h"
diff --git a/main/win95nt.h b/main/win95nt.h
index ec30b428c..efcb02ac4 100644
--- a/main/win95nt.h
+++ b/main/win95nt.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: win95nt.h,v 1.20.2.2.2.1 2006/10/19 09:49:44 dmitry Exp $ */
+/* $Id: win95nt.h,v 1.20.2.2.2.2 2007/01/01 09:36:11 sebastian Exp $ */
/* Defines and types for Windows 95/NT */
#define HAVE_DECLARED_TIMEZONE