diff options
Diffstat (limited to 'main')
74 files changed, 0 insertions, 25679 deletions
diff --git a/main/SAPI.c b/main/SAPI.c deleted file mode 100644 index 722c83e978..0000000000 --- a/main/SAPI.c +++ /dev/null @@ -1,917 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Original design: Shane Caraveo <shane@caraveo.com> | - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include <ctype.h> -#include <sys/stat.h> - -#include "php.h" -#include "SAPI.h" -#include "php_ini.h" -#include "ext/standard/php_string.h" -#include "ext/standard/pageinfo.h" -#if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE) -#include "ext/pcre/php_pcre.h" -#endif -#if HAVE_ZLIB -#include "ext/zlib/php_zlib.h" -#endif -#ifdef ZTS -#include "TSRM.h" -#endif - -#include "rfc1867.h" - -#ifdef PHP_WIN32 -#define STRCASECMP stricmp -#else -#define STRCASECMP strcasecmp -#endif - -#include "php_content_types.h" - -static HashTable known_post_content_types; - -#ifdef ZTS -SAPI_API int sapi_globals_id; -#else -sapi_globals_struct sapi_globals; -#endif - -static void sapi_globals_ctor(sapi_globals_struct *sapi_globals TSRMLS_DC) -{ - memset(sapi_globals, 0, sizeof(*sapi_globals)); -} - -/* True globals (no need for thread safety) */ -SAPI_API sapi_module_struct sapi_module; - - -SAPI_API void sapi_startup(sapi_module_struct *sf) -{ - sapi_module = *sf; - zend_hash_init_ex(&known_post_content_types, 5, NULL, NULL, 1, 0); - -#ifdef ZTS - ts_allocate_id(&sapi_globals_id, sizeof(sapi_globals_struct), (ts_allocate_ctor) sapi_globals_ctor, NULL); -#else - sapi_globals_ctor(&sapi_globals TSRMLS_CC); -#endif - -#ifdef VIRTUAL_DIR - virtual_cwd_startup(); /* Could use shutdown to free the main cwd but it would just slow it down for CGI */ -#endif - -#ifdef PHP_WIN32 - tsrm_win32_startup(); -#endif - - reentrancy_startup(); -} - -SAPI_API void sapi_shutdown(void) -{ - reentrancy_shutdown(); -#ifdef VIRTUAL_DIR - virtual_cwd_shutdown(); -#endif - -#ifdef PHP_WIN32 - tsrm_win32_shutdown(); -#endif - - zend_hash_destroy(&known_post_content_types); -} - - -SAPI_API void sapi_free_header(sapi_header_struct *sapi_header) -{ - efree(sapi_header->header); -} - - -SAPI_API void sapi_handle_post(void *arg TSRMLS_DC) -{ - if (SG(request_info).post_entry && SG(request_info).content_type_dup) { - SG(request_info).post_entry->post_handler(SG(request_info).content_type_dup, arg TSRMLS_CC); - if (SG(request_info).post_data) { - efree(SG(request_info).post_data); - SG(request_info).post_data = NULL; - } - efree(SG(request_info).content_type_dup); - SG(request_info).content_type_dup = NULL; - } -} - -static void sapi_read_post_data(TSRMLS_D) -{ - sapi_post_entry *post_entry; - uint content_type_length = strlen(SG(request_info).content_type); - char *content_type = estrndup(SG(request_info).content_type, content_type_length); - char *p; - char oldchar=0; - void (*post_reader_func)(TSRMLS_D) = NULL; - - - /* dedicated implementation for increased performance: - * - Make the content type lowercase - * - Trim descriptive data, stay with the content-type only - */ - for (p=content_type; p<content_type+content_type_length; p++) { - switch (*p) { - case ';': - case ',': - case ' ': - content_type_length = p-content_type; - oldchar = *p; - *p = 0; - break; - default: - *p = tolower(*p); - break; - } - } - - /* now try to find an appropriate POST content handler */ - if (zend_hash_find(&known_post_content_types, content_type, content_type_length+1, (void **) &post_entry) == SUCCESS) { - /* found one, register it for use */ - SG(request_info).post_entry = post_entry; - post_reader_func = post_entry->post_reader; - } else { - /* fallback */ - SG(request_info).post_entry = NULL; - if (!sapi_module.default_post_reader) { - /* no default reader ? */ - SG(request_info).content_type_dup = NULL; - sapi_module.sapi_error(E_WARNING, "Unsupported content type: '%s'", content_type); - return; - } - } - if (oldchar) { - *(p-1) = oldchar; - } - - SG(request_info).content_type_dup = content_type; - - if(post_reader_func) { - post_reader_func(TSRMLS_C); - } - - if(sapi_module.default_post_reader) { - sapi_module.default_post_reader(TSRMLS_C); - } -} - - -SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data) -{ - int read_bytes; - int allocated_bytes=SAPI_POST_BLOCK_SIZE+1; - - if (SG(request_info).content_length > SG(post_max_size)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes", - SG(request_info).content_length, SG(post_max_size)); - return; - } - SG(request_info).post_data = emalloc(allocated_bytes); - - for (;;) { - read_bytes = sapi_module.read_post(SG(request_info).post_data+SG(read_post_bytes), SAPI_POST_BLOCK_SIZE TSRMLS_CC); - if (read_bytes<=0) { - break; - } - SG(read_post_bytes) += read_bytes; - if (SG(read_post_bytes) > SG(post_max_size)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Actual POST length does not match Content-Length, and exceeds %ld bytes", SG(post_max_size)); - return; - } - if (read_bytes < SAPI_POST_BLOCK_SIZE) { - break; - } - if (SG(read_post_bytes)+SAPI_POST_BLOCK_SIZE >= allocated_bytes) { - allocated_bytes = SG(read_post_bytes)+SAPI_POST_BLOCK_SIZE+1; - SG(request_info).post_data = erealloc(SG(request_info).post_data, allocated_bytes); - } - } - SG(request_info).post_data[SG(read_post_bytes)] = 0; /* terminating NULL */ - SG(request_info).post_data_length = SG(read_post_bytes); -} - - -SAPI_API char *sapi_get_default_content_type(TSRMLS_D) -{ - char *mimetype, *charset, *content_type; - - mimetype = SG(default_mimetype) ? SG(default_mimetype) : SAPI_DEFAULT_MIMETYPE; - charset = SG(default_charset) ? SG(default_charset) : SAPI_DEFAULT_CHARSET; - - if (strncasecmp(mimetype, "text/", 5) == 0 && *charset) { - int len = strlen(mimetype) + sizeof("; charset=") + strlen(charset); /* sizeof() includes \0 */ - content_type = emalloc(len); - snprintf(content_type, len, "%s; charset=%s", mimetype, charset); - } else { - content_type = estrdup(mimetype); - } - return content_type; -} - - -SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_header TSRMLS_DC) -{ - char *default_content_type = sapi_get_default_content_type(TSRMLS_C); - int default_content_type_len = strlen(default_content_type); - - default_header->header_len = (sizeof("Content-type: ")-1) + default_content_type_len; - default_header->header = emalloc(default_header->header_len+1); - memcpy(default_header->header, "Content-type: ", sizeof("Content-type: ")); - memcpy(default_header->header+sizeof("Content-type: ")-1, default_content_type, default_content_type_len); - default_header->header[default_header->header_len] = 0; - efree(default_content_type); -} - -/* - * Add charset on content-type header if the MIME type starts with - * "text/", the default_charset directive is not empty and - * there is not already a charset option in there. - * - * If "mimetype" is non-NULL, it should point to a pointer allocated - * with emalloc(). If a charset is added, the string will be - * re-allocated and the new length is returned. If mimetype is - * unchanged, 0 is returned. - * - */ -SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len TSRMLS_DC) -{ - char *charset, *newtype; - size_t newlen; - charset = SG(default_charset) ? SG(default_charset) : SAPI_DEFAULT_CHARSET; - - if (*mimetype != NULL) { - if (*charset && strncmp(*mimetype, "text/", 5) == 0 && strstr(*mimetype, "charset=") == NULL) { - newlen = len + (sizeof(";charset=")-1) + strlen(charset); - newtype = emalloc(newlen + 1); - PHP_STRLCPY(newtype, *mimetype, newlen + 1, len); - strlcat(newtype, ";charset=", newlen + 1); - strlcat(newtype, charset, newlen + 1); - efree(*mimetype); - *mimetype = newtype; - return newlen; - } - } - return 0; -} - -SAPI_API void sapi_activate_headers_only(TSRMLS_D) -{ - if (SG(request_info).headers_read == 1) - return; - SG(request_info).headers_read = 1; - zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct), - (void (*)(void *)) sapi_free_header, 0); - SG(sapi_headers).send_default_content_type = 1; - - /* SG(sapi_headers).http_response_code = 200; */ - SG(sapi_headers).http_status_line = NULL; - SG(request_info).current_user = NULL; - SG(request_info).current_user_length = 0; - SG(request_info).no_headers = 0; - - /* - * It's possible to override this general case in the activate() callback, - * if necessary. - */ - if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) { - SG(request_info).headers_only = 1; - } else { - SG(request_info).headers_only = 0; - } - if (SG(server_context)) { - SG(request_info).cookie_data = sapi_module.read_cookies(TSRMLS_C); - if (sapi_module.activate) { - sapi_module.activate(TSRMLS_C); - } - } -} - -/* - * Called from php_request_startup() for every request. - */ - -SAPI_API void sapi_activate(TSRMLS_D) -{ - zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct), (void (*)(void *)) sapi_free_header, 0); - SG(sapi_headers).send_default_content_type = 1; - - /* - SG(sapi_headers).http_response_code = 200; - */ - SG(sapi_headers).http_status_line = NULL; - SG(headers_sent) = 0; - SG(read_post_bytes) = 0; - SG(request_info).post_data = NULL; - SG(request_info).raw_post_data = NULL; - SG(request_info).current_user = NULL; - SG(request_info).current_user_length = 0; - SG(request_info).no_headers = 0; - - /* It's possible to override this general case in the activate() callback, if - * necessary. - */ - if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) { - SG(request_info).headers_only = 1; - } else { - SG(request_info).headers_only = 0; - } - SG(rfc1867_uploaded_files) = NULL; - - /* handle request mehtod */ - if (SG(server_context)) { - if ( SG(request_info).request_method) { - if(!strcmp(SG(request_info).request_method, "POST") - && (SG(request_info).content_type)) { - /* HTTP POST -> may contain form data to be read into variables - depending on content type given - */ - sapi_read_post_data(TSRMLS_C); - } else { - /* any other method with content payload will fill - $HTTP_RAW_POST_DATA if enabled by always_populate_raw_post_data - it is up to the webserver to decide whether to allow a method or not - */ - SG(request_info).content_type_dup = NULL; - if(sapi_module.default_post_reader) { - sapi_module.default_post_reader(TSRMLS_C); - } - } - } else { - SG(request_info).content_type_dup = NULL; - } - - /* Cookies */ - SG(request_info).cookie_data = sapi_module.read_cookies(TSRMLS_C); - if (sapi_module.activate) { - sapi_module.activate(TSRMLS_C); - } - } -} - - -static void sapi_send_headers_free(TSRMLS_D) -{ - if (SG(sapi_headers).http_status_line) { - efree(SG(sapi_headers).http_status_line); - SG(sapi_headers).http_status_line = NULL; - } -} - -SAPI_API void sapi_deactivate(TSRMLS_D) -{ - zend_llist_destroy(&SG(sapi_headers).headers); - if (SG(request_info).post_data) { - efree(SG(request_info).post_data); - } else if (SG(server_context)) { - if(sapi_module.read_post) { - /* make sure we've consumed all request input data */ - char dummy[SAPI_POST_BLOCK_SIZE]; - int read_bytes; - - while((read_bytes = sapi_module.read_post(dummy, sizeof(dummy)-1 TSRMLS_CC)) > 0) { - SG(read_post_bytes) += read_bytes; - } - } - } - if (SG(request_info).raw_post_data) { - efree(SG(request_info).raw_post_data); - } - if (SG(request_info).auth_user) { - efree(SG(request_info).auth_user); - } - if (SG(request_info).auth_password) { - efree(SG(request_info).auth_password); - } - if (SG(request_info).content_type_dup) { - efree(SG(request_info).content_type_dup); - } - if (SG(request_info).current_user) { - efree(SG(request_info).current_user); - } - if (sapi_module.deactivate) { - sapi_module.deactivate(TSRMLS_C); - } - if (SG(rfc1867_uploaded_files)) { - destroy_uploaded_files_hash(TSRMLS_C); - } - if (SG(sapi_headers).mimetype) { - efree(SG(sapi_headers).mimetype); - SG(sapi_headers).mimetype = NULL; - } - sapi_send_headers_free(TSRMLS_C); - SG(sapi_started) = 0; - SG(headers_sent) = 0; - SG(request_info).headers_read = 0; -} - - -SAPI_API void sapi_initialize_empty_request(TSRMLS_D) -{ - SG(server_context) = NULL; - SG(request_info).request_method = NULL; - SG(request_info).auth_user = SG(request_info).auth_password = NULL; - SG(request_info).content_type_dup = NULL; -} - - -static int sapi_extract_response_code(const char *header_line) -{ - int code = 200; - const char *ptr; - - for (ptr = header_line; *ptr; ptr++) { - if (*ptr == ' ' && *(ptr + 1) != ' ') { - code = atoi(ptr + 1); - break; - } - } - - return code; -} - - -static void sapi_update_response_code(int ncode TSRMLS_DC) -{ - /* if the status code did not change, we do not want - to change the status line, and no need to change the code */ - if (SG(sapi_headers).http_response_code == ncode) { - return; - } - - if (SG(sapi_headers).http_status_line) { - efree(SG(sapi_headers).http_status_line); - SG(sapi_headers).http_status_line = NULL; - } - SG(sapi_headers).http_response_code = ncode; -} - -static int sapi_find_matching_header(void *element1, void *element2) -{ - return strncasecmp(((sapi_header_struct*)element1)->header, (char*)element2, strlen((char*)element2)) == 0; -} - -SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bool duplicate, zend_bool replace TSRMLS_DC) -{ - sapi_header_line ctr = {0}; - int r; - - ctr.line = header_line; - ctr.line_len = header_line_len; - - r = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, - &ctr TSRMLS_CC); - - if (!duplicate) - efree(header_line); - - return r; -} - -SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC) -{ - int retval; - sapi_header_struct sapi_header; - char *colon_offset; - long myuid = 0L; - char *header_line; - uint header_line_len; - zend_bool replace; - int http_response_code; - - if (SG(headers_sent) && !SG(request_info).no_headers) { - char *output_start_filename = php_get_output_start_filename(TSRMLS_C); - int output_start_lineno = php_get_output_start_lineno(TSRMLS_C); - - if (output_start_filename) { - sapi_module.sapi_error(E_WARNING, "Cannot modify header information - headers already sent by (output started at %s:%d)", - output_start_filename, output_start_lineno); - } else { - sapi_module.sapi_error(E_WARNING, "Cannot modify header information - headers already sent"); - } - return FAILURE; - } - - switch (op) { - case SAPI_HEADER_SET_STATUS: - sapi_update_response_code((long) arg TSRMLS_CC); - return SUCCESS; - - case SAPI_HEADER_REPLACE: - case SAPI_HEADER_ADD: { - sapi_header_line *p = arg; - 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])) - header_line[--header_line_len]='\0'; - - - sapi_header.header = header_line; - sapi_header.header_len = header_line_len; - sapi_header.replace = replace; - - /* Check the header for a few cases that we have special support for in SAPI */ - if (header_line_len>=5 - && !strncasecmp(header_line, "HTTP/", 5)) { - /* filter out the response code */ - sapi_update_response_code(sapi_extract_response_code(header_line) TSRMLS_CC); - SG(sapi_headers).http_status_line = header_line; - return SUCCESS; - } else { - colon_offset = strchr(header_line, ':'); - if (colon_offset) { - *colon_offset = 0; - if (!STRCASECMP(header_line, "Content-Type")) { - char *ptr = colon_offset+1, *mimetype = NULL, *newheader; - size_t len = header_line_len - (ptr - header_line), newlen; - while (*ptr == ' ' && *ptr != '\0') { - ptr++; - } -#if HAVE_ZLIB - if(!strncmp(ptr, "image/", sizeof("image/")-1)) { - zend_alter_ini_entry("zlib.output_compression", sizeof("zlib.output_compression"), "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - } -#endif - mimetype = estrdup(ptr); - newlen = sapi_apply_default_charset(&mimetype, len TSRMLS_CC); - if (!SG(sapi_headers).mimetype){ - SG(sapi_headers).mimetype = estrdup(mimetype); - } - - if (newlen != 0) { - newlen += sizeof("Content-type: "); - newheader = emalloc(newlen); - PHP_STRLCPY(newheader, "Content-type: ", newlen, sizeof("Content-type: ")-1); - strlcat(newheader, mimetype, newlen); - sapi_header.header = newheader; - sapi_header.header_len = newlen - 1; - efree(header_line); - } - efree(mimetype); - SG(sapi_headers).send_default_content_type = 0; - } else if (!STRCASECMP(header_line, "Location")) { - if ((SG(sapi_headers).http_response_code < 300 || - SG(sapi_headers).http_response_code > 307) && - SG(sapi_headers).http_response_code != 201) { - /* Return a Found Redirect if one is not already specified */ - sapi_update_response_code(302 TSRMLS_CC); - } - } else if (!STRCASECMP(header_line, "WWW-Authenticate")) { /* HTTP Authentication */ - int newlen; - char *result, *newheader; - - sapi_update_response_code(401 TSRMLS_CC); /* authentication-required */ - - if(PG(safe_mode)) -#if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE) - { - zval *repl_temp; - char *ptr = colon_offset+1; - int ptr_len=0, result_len = 0; - - myuid = php_getuid(); - - 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); - /* Modify quoted realm value */ - result = php_pcre_replace("/realm=\"(.*?)\"/i", 16, - ptr, ptr_len, - repl_temp, - 0, &result_len, -1 TSRMLS_CC); - if(result_len==ptr_len) { - efree(result); - sprintf(Z_STRVAL_P(repl_temp), "realm=\\1-%ld\\2", myuid); - /* modify unquoted realm value */ - result = php_pcre_replace("/realm=([^\\s]+)(.*)/i", 21, - ptr, ptr_len, - repl_temp, - 0, &result_len, -1 TSRMLS_CC); - if(result_len==ptr_len) { - char *lower_temp = estrdup(ptr); - char conv_temp[32]; - int conv_len; - - php_strtolower(lower_temp,strlen(lower_temp)); - /* 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); - result = emalloc(ptr_len+conv_len+1); - result_len = ptr_len+conv_len; - memcpy(result, ptr, ptr_len); - memcpy(result+ptr_len, conv_temp, conv_len); - *(result+ptr_len+conv_len) = '\0'; - } - efree(lower_temp); - } - } - newlen = sizeof("WWW-Authenticate: ") + result_len; - newheader = emalloc(newlen+1); - sprintf(newheader,"WWW-Authenticate: %s", result); - efree(header_line); - sapi_header.header = newheader; - sapi_header.header_len = newlen; - efree(result); - efree(Z_STRVAL_P(repl_temp)); - efree(repl_temp); - } -#else - { - myuid = php_getuid(); - result = emalloc(sizeof("WWW-Authenticate: ")+20); - newlen = sprintf(result, "WWW-Authenticate: %ld", myuid); - newheader = estrndup(result,newlen); - efree(header_line); - sapi_header.header = newheader; - sapi_header.header_len = newlen; - efree(result); - } -#endif - } - if (sapi_header.header==header_line) { - *colon_offset = ':'; - } - } - } - if (http_response_code) { - sapi_update_response_code(http_response_code TSRMLS_CC); - } - if (sapi_module.header_handler) { - retval = sapi_module.header_handler(&sapi_header, &SG(sapi_headers) TSRMLS_CC); - } else { - retval = SAPI_HEADER_ADD; - } - if (retval & SAPI_HEADER_DELETE_ALL) { - zend_llist_clean(&SG(sapi_headers).headers); - } - if (retval & SAPI_HEADER_ADD) { - /* in replace mode first remove the header if it already exists in the headers llist */ - if (replace) { - colon_offset = strchr(sapi_header.header, ':'); - if (colon_offset) { - char sav; - colon_offset++; - sav = *colon_offset; - *colon_offset = 0; - zend_llist_del_element(&SG(sapi_headers).headers, sapi_header.header, (int(*)(void*, void*))sapi_find_matching_header); - *colon_offset = sav; - } - } - - zend_llist_add_element(&SG(sapi_headers).headers, (void *) &sapi_header); - } - return SUCCESS; -} - - -SAPI_API int sapi_send_headers(TSRMLS_D) -{ - int retval; - int ret = FAILURE; - - if (SG(headers_sent) || SG(request_info).no_headers) { - return SUCCESS; - } - -#if HAVE_ZLIB - /* Add output compression headers at this late stage in order to make - it possible to switch it off inside the script. */ - - if (zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0)) { - zval nm_zlib_get_coding_type; - zval *uf_result = NULL; - - ZVAL_STRINGL(&nm_zlib_get_coding_type, "zlib_get_coding_type", sizeof("zlib_get_coding_type") - 1, 0); - - if (call_user_function_ex(CG(function_table), NULL, &nm_zlib_get_coding_type, &uf_result, 0, NULL, 1, NULL TSRMLS_CC) != FAILURE && uf_result != NULL && Z_TYPE_P(uf_result) == IS_STRING) { - char buf[128]; - int len; - - assert(Z_STRVAL_P(uf_result) != NULL); - - len = snprintf(buf, sizeof(buf), "Content-Encoding: %s", Z_STRVAL_P(uf_result)); - if (len <= 0 || sapi_add_header(buf, len, 1) == FAILURE) { - return FAILURE; - } - if (sapi_add_header_ex("Vary: Accept-Encoding", sizeof("Vary: Accept-Encoding") - 1, 1, 0 TSRMLS_CC) == FAILURE) { - return FAILURE; - } - } - if (uf_result != NULL) { - zval_ptr_dtor(&uf_result); - } - } -#endif - - /* Success-oriented. We set headers_sent to 1 here to avoid an infinite loop - * in case of an error situation. - */ - SG(headers_sent) = 1; - - if (sapi_module.send_headers) { - retval = sapi_module.send_headers(&SG(sapi_headers) TSRMLS_CC); - } else { - retval = SAPI_HEADER_DO_SEND; - } - - switch (retval) { - case SAPI_HEADER_SENT_SUCCESSFULLY: - ret = SUCCESS; - break; - case SAPI_HEADER_DO_SEND: { - sapi_header_struct http_status_line; - char buf[255]; - - if (SG(sapi_headers).http_status_line) { - http_status_line.header = SG(sapi_headers).http_status_line; - 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); - } - sapi_module.send_header(&http_status_line, SG(server_context) TSRMLS_CC); - } - zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) sapi_module.send_header, SG(server_context) TSRMLS_CC); - if(SG(sapi_headers).send_default_content_type) { - sapi_header_struct default_header; - - sapi_get_default_content_type_header(&default_header TSRMLS_CC); - sapi_module.send_header(&default_header, SG(server_context) TSRMLS_CC); - sapi_free_header(&default_header); - } - sapi_module.send_header(NULL, SG(server_context) TSRMLS_CC); - ret = SUCCESS; - break; - case SAPI_HEADER_SEND_FAILED: - SG(headers_sent) = 0; - ret = FAILURE; - break; - } - - sapi_send_headers_free(TSRMLS_C); - - return ret; -} - - -SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entries) -{ - sapi_post_entry *p=post_entries; - - while (p->content_type) { - if (sapi_register_post_entry(p) == FAILURE) { - return FAILURE; - } - p++; - } - return SUCCESS; -} - - -SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry) -{ - return zend_hash_add(&known_post_content_types, post_entry->content_type, post_entry->content_type_len+1, (void *) post_entry, sizeof(sapi_post_entry), NULL); -} - -SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry) -{ - zend_hash_del(&known_post_content_types, post_entry->content_type, post_entry->content_type_len+1); -} - - -SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRMLS_D)) -{ - sapi_module.default_post_reader = default_post_reader; - return SUCCESS; -} - - -SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC)) -{ - 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)) -{ - sapi_module.input_filter = input_filter; - return SUCCESS; -} - -SAPI_API int sapi_flush(TSRMLS_D) -{ - if (sapi_module.flush) { - sapi_module.flush(SG(server_context)); - return SUCCESS; - } else { - return FAILURE; - } -} - -SAPI_API struct stat *sapi_get_stat(TSRMLS_D) -{ - if (sapi_module.get_stat) { - return sapi_module.get_stat(TSRMLS_C); - } else { - if (!SG(request_info).path_translated || (VCWD_STAT(SG(request_info).path_translated, &SG(global_stat)) == -1)) { - return NULL; - } - return &SG(global_stat); - } -} - - -SAPI_API char *sapi_getenv(char *name, size_t name_len TSRMLS_DC) -{ - if (sapi_module.getenv) { - return sapi_module.getenv(name, name_len TSRMLS_CC); - } else { - return NULL; - } -} - -SAPI_API int sapi_get_fd(int *fd TSRMLS_DC) -{ - if (sapi_module.get_fd) { - return sapi_module.get_fd(fd TSRMLS_CC); - } else { - return FAILURE; - } -} - -SAPI_API int sapi_force_http_10(TSRMLS_D) -{ - if (sapi_module.force_http_10) { - return sapi_module.force_http_10(TSRMLS_C); - } else { - return FAILURE; - } -} - - -SAPI_API int sapi_get_target_uid(uid_t *obj TSRMLS_DC) -{ - if (sapi_module.get_target_uid) { - return sapi_module.get_target_uid(obj TSRMLS_CC); - } else { - return FAILURE; - } -} - -SAPI_API int sapi_get_target_gid(gid_t *obj TSRMLS_DC) -{ - if (sapi_module.get_target_gid) { - return sapi_module.get_target_gid(obj TSRMLS_CC); - } else { - return FAILURE; - } -} - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/SAPI.h b/main/SAPI.h deleted file mode 100644 index d740eb9061..0000000000 --- a/main/SAPI.h +++ /dev/null @@ -1,297 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef SAPI_H -#define SAPI_H - -#include "zend.h" -#include "zend_llist.h" -#include "zend_operators.h" -#include <sys/stat.h> - -#define SAPI_OPTION_NO_CHDIR 1 - -#define SAPI_POST_BLOCK_SIZE 4000 - -#ifdef PHP_WIN32 -# ifdef SAPI_EXPORTS -# define SAPI_API __declspec(dllexport) -# else -# define SAPI_API __declspec(dllimport) -# endif -#else -#define SAPI_API -#endif - -#undef shutdown - -typedef struct { - char *header; - uint header_len; - zend_bool replace; -} sapi_header_struct; - - -typedef struct { - zend_llist headers; - int http_response_code; - unsigned char send_default_content_type; - char *mimetype; - char *http_status_line; -} sapi_headers_struct; - - -typedef struct _sapi_post_entry sapi_post_entry; -typedef struct _sapi_module_struct sapi_module_struct; - -BEGIN_EXTERN_C() -extern SAPI_API sapi_module_struct sapi_module; /* true global */ -END_EXTERN_C() - -/* Some values in this structure needs to be filled in before - * calling sapi_activate(). We WILL change the `char *' entries, - * so make sure that you allocate a separate buffer for them - * and that you free them after sapi_deactivate(). - */ - -typedef struct { - const char *request_method; - char *query_string; - char *post_data, *raw_post_data; - char *cookie_data; - long content_length; - uint post_data_length, raw_post_data_length; - - char *path_translated; - char *request_uri; - - const char *content_type; - - zend_bool headers_only; - zend_bool no_headers; - zend_bool headers_read; - - sapi_post_entry *post_entry; - - char *content_type_dup; - - /* for HTTP authentication */ - char *auth_user; - char *auth_password; - - /* this is necessary for the CGI SAPI module */ - char *argv0; - - /* this is necessary for Safe Mode */ - char *current_user; - int current_user_length; - - /* this is necessary for CLI module */ - int argc; - char **argv; -} sapi_request_info; - - -typedef struct _sapi_globals_struct { - void *server_context; - sapi_request_info request_info; - sapi_headers_struct sapi_headers; - int read_post_bytes; - unsigned char headers_sent; - struct stat global_stat; - char *default_mimetype; - char *default_charset; - HashTable *rfc1867_uploaded_files; - long post_max_size; - int options; - zend_bool sapi_started; -} sapi_globals_struct; - - -BEGIN_EXTERN_C() -#ifdef ZTS -# define SG(v) TSRMG(sapi_globals_id, sapi_globals_struct *, v) -SAPI_API extern int sapi_globals_id; -#else -# define SG(v) (sapi_globals.v) -extern SAPI_API sapi_globals_struct sapi_globals; -#endif - -SAPI_API void sapi_startup(sapi_module_struct *sf); -SAPI_API void sapi_shutdown(void); -SAPI_API void sapi_activate(TSRMLS_D); -SAPI_API void sapi_deactivate(TSRMLS_D); -SAPI_API void sapi_initialize_empty_request(TSRMLS_D); -END_EXTERN_C() - -/* - * This is the preferred and maintained API for - * operating on HTTP headers. - */ - -/* - * Always specify a sapi_header_line this way: - * - * sapi_header_line ctr = {0}; - */ - -typedef struct { - char *line; /* If you allocated this, you need to free it yourself */ - uint line_len; - long response_code; /* long due to zend_parse_parameters compatibility */ -} sapi_header_line; - -typedef enum { /* Parameter: */ - SAPI_HEADER_REPLACE, /* sapi_header_line* */ - SAPI_HEADER_ADD, /* sapi_header_line* */ - SAPI_HEADER_SET_STATUS /* int */ -} sapi_header_op_enum; - -BEGIN_EXTERN_C() -SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC); - -/* Deprecated functions. Use sapi_header_op instead. */ -SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bool duplicate, zend_bool replace TSRMLS_DC); -#define sapi_add_header(a, b, c) sapi_add_header_ex((a),(b),(c),1 TSRMLS_CC) - - -SAPI_API int sapi_send_headers(TSRMLS_D); -SAPI_API void sapi_free_header(sapi_header_struct *sapi_header); -SAPI_API void sapi_handle_post(void *arg TSRMLS_DC); - -SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entry); -SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry); -SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry); -SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRMLS_D)); -SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC)); -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)); - -SAPI_API int sapi_flush(TSRMLS_D); -SAPI_API struct stat *sapi_get_stat(TSRMLS_D); -SAPI_API char *sapi_getenv(char *name, size_t name_len TSRMLS_DC); - -SAPI_API char *sapi_get_default_content_type(TSRMLS_D); -SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_header TSRMLS_DC); -SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len TSRMLS_DC); -SAPI_API void sapi_activate_headers_only(TSRMLS_D); - -SAPI_API int sapi_get_fd(int *fd TSRMLS_DC); -SAPI_API int sapi_force_http_10(TSRMLS_D); - -SAPI_API int sapi_get_target_uid(uid_t * TSRMLS_DC); -SAPI_API int sapi_get_target_gid(gid_t * TSRMLS_DC); -END_EXTERN_C() - -struct _sapi_module_struct { - char *name; - char *pretty_name; - - int (*startup)(struct _sapi_module_struct *sapi_module); - int (*shutdown)(struct _sapi_module_struct *sapi_module); - - int (*activate)(TSRMLS_D); - int (*deactivate)(TSRMLS_D); - - int (*ub_write)(const char *str, unsigned int str_length TSRMLS_DC); - void (*flush)(void *server_context); - struct stat *(*get_stat)(TSRMLS_D); - char *(*getenv)(char *name, size_t name_len TSRMLS_DC); - - void (*sapi_error)(int type, const char *error_msg, ...); - - int (*header_handler)(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC); - int (*send_headers)(sapi_headers_struct *sapi_headers TSRMLS_DC); - void (*send_header)(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC); - - int (*read_post)(char *buffer, uint count_bytes TSRMLS_DC); - char *(*read_cookies)(TSRMLS_D); - - void (*register_server_variables)(zval *track_vars_array TSRMLS_DC); - void (*log_message)(char *message); - - char *php_ini_path_override; - - void (*block_interruptions)(void); - void (*unblock_interruptions)(void); - - void (*default_post_reader)(TSRMLS_D); - void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC); - char *executable_location; - - int php_ini_ignore; - - int (*get_fd)(int *fd TSRMLS_DC); - - int (*force_http_10)(TSRMLS_D); - - int (*get_target_uid)(uid_t * TSRMLS_DC); - int (*get_target_gid)(gid_t * TSRMLS_DC); - - unsigned int (*input_filter)(int arg, char *var, char **val, unsigned int val_len, unsigned int *new_val_len TSRMLS_DC); - - void (*ini_defaults)(HashTable *configuration_hash); - int phpinfo_as_text; -}; - - -struct _sapi_post_entry { - char *content_type; - uint content_type_len; - void (*post_reader)(TSRMLS_D); - void (*post_handler)(char *content_type_dup, void *arg TSRMLS_DC); -}; - -/* header_handler() constants */ -#define SAPI_HEADER_ADD (1<<0) -#define SAPI_HEADER_DELETE_ALL (1<<1) -#define SAPI_HEADER_SEND_NOW (1<<2) - - -#define SAPI_HEADER_SENT_SUCCESSFULLY 1 -#define SAPI_HEADER_DO_SEND 2 -#define SAPI_HEADER_SEND_FAILED 3 - -#define SAPI_DEFAULT_MIMETYPE "text/html" -#define SAPI_DEFAULT_CHARSET "" -#define SAPI_PHP_VERSION_HEADER "X-Powered-By: PHP/" PHP_VERSION - -#define SAPI_POST_READER_FUNC(post_reader) void post_reader(TSRMLS_D) -#define SAPI_POST_HANDLER_FUNC(post_handler) void post_handler(char *content_type_dup, void *arg TSRMLS_DC) - -#define SAPI_TREAT_DATA_FUNC(treat_data) void treat_data(int arg, char *str, zval* destArray TSRMLS_DC) -#define SAPI_INPUT_FILTER_FUNC(input_filter) unsigned int input_filter(int arg, char *var, char **val, unsigned int val_len, unsigned int *new_val_len TSRMLS_DC) - -BEGIN_EXTERN_C() -SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data); -SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader); -SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data); -SAPI_API SAPI_INPUT_FILTER_FUNC(php_default_input_filter); -END_EXTERN_C() - -#define STANDARD_SAPI_MODULE_PROPERTIES - -#endif /* SAPI_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/main/alloca.c b/main/alloca.c deleted file mode 100644 index ae28159913..0000000000 --- a/main/alloca.c +++ /dev/null @@ -1,501 +0,0 @@ -/* alloca.c -- allocate automatically reclaimed memory - (Mostly) portable public-domain implementation -- D A Gwyn - - This implementation of the PWB library alloca function, - which is used to allocate space off the run-time stack so - that it is automatically reclaimed upon procedure exit, - was inspired by discussions with J. Q. Johnson of Cornell. - J.Otto Tennant <jot@cray.com> contributed the Cray support. - - There are some preprocessor constants that can - be defined when compiling for your specific system, for - improved efficiency; however, the defaults should be okay. - - The general concept of this implementation is to keep - track of all alloca-allocated blocks, and reclaim any - that are found to be deeper in the stack than the current - invocation. This heuristic does not reclaim storage as - soon as it becomes invalid, but it will do so eventually. - - As a special case, alloca(0) reclaims storage without - allocating any. It is a good idea to use alloca(0) in - your main control loop, etc. to force garbage collection. */ - -/* $Id$ */ - -#include "php_config.h" - -#if !HAVE_ALLOCA - -#ifdef HAVE_STRING_H -#include <string.h> -#endif -#ifdef HAVE_STDLIB_H -#include <stdlib.h> -#endif - -#ifdef emacs -#include "blockinput.h" -#endif - -/* If compiling with GCC 2, this file's not needed. */ -#if !defined (__GNUC__) || __GNUC__ < 2 - -/* If someone has defined alloca as a macro, - there must be some other way alloca is supposed to work. */ -#ifndef alloca - -#ifdef emacs -#ifdef static -/* actually, only want this if static is defined as "" - -- this is for usg, in which emacs must undefine static - in order to make unexec workable - */ -#ifndef STACK_DIRECTION -you -lose --- must know STACK_DIRECTION at compile-time -#endif /* STACK_DIRECTION undefined */ -#endif /* static */ -#endif /* emacs */ - -/* If your stack is a linked list of frames, you have to - provide an "address metric" ADDRESS_FUNCTION macro. */ - -#if defined (CRAY) && defined (CRAY_STACKSEG_END) -long i00afunc (); -#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg)) -#else -#define ADDRESS_FUNCTION(arg) &(arg) -#endif - -#if __STDC__ -typedef void *pointer; -#else -typedef char *pointer; -#endif - -#ifndef NULL -#define NULL 0 -#endif - -/* Define STACK_DIRECTION if you know the direction of stack - growth for your system; otherwise it will be automatically - deduced at run-time. - - STACK_DIRECTION > 0 => grows toward higher addresses - STACK_DIRECTION < 0 => grows toward lower addresses - STACK_DIRECTION = 0 => direction of growth unknown */ - -#ifndef STACK_DIRECTION -#define STACK_DIRECTION 0 /* Direction unknown. */ -#endif - -#if STACK_DIRECTION != 0 - -#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */ - -#else /* STACK_DIRECTION == 0; need run-time code. */ - -static int stack_dir; /* 1 or -1 once known. */ -#define STACK_DIR stack_dir - -static void -find_stack_direction () -{ - static char *addr = NULL; /* Address of first `dummy', once known. */ - auto char dummy; /* To get stack address. */ - - if (addr == NULL) - { /* Initial entry. */ - addr = ADDRESS_FUNCTION (dummy); - - find_stack_direction (); /* Recurse once. */ - } - else - { - /* Second entry. */ - if (ADDRESS_FUNCTION (dummy) > addr) - stack_dir = 1; /* Stack grew upward. */ - else - stack_dir = -1; /* Stack grew downward. */ - } -} - -#endif /* STACK_DIRECTION == 0 */ - -/* An "alloca header" is used to: - (a) chain together all alloca'ed blocks; - (b) keep track of stack depth. - - It is very important that sizeof(header) agree with malloc - alignment chunk size. The following default should work okay. */ - -#ifndef ALIGN_SIZE -#define ALIGN_SIZE sizeof(double) -#endif - -typedef union hdr -{ - char align[ALIGN_SIZE]; /* To force sizeof(header). */ - struct - { - union hdr *next; /* For chaining headers. */ - char *deep; /* For stack depth measure. */ - } h; -} header; - -static header *last_alloca_header = NULL; /* -> last alloca header. */ - -/* Return a pointer to at least SIZE bytes of storage, - which will be automatically reclaimed upon exit from - the procedure that called alloca. Originally, this space - was supposed to be taken from the current stack frame of the - caller, but that method cannot be made to work for some - implementations of C, for example under Gould's UTX/32. */ - -pointer -alloca (size) - size_t size; -{ - auto char probe; /* Probes stack depth: */ - register char *depth = ADDRESS_FUNCTION (probe); - -#if STACK_DIRECTION == 0 - if (STACK_DIR == 0) /* Unknown growth direction. */ - find_stack_direction (); -#endif - - /* Reclaim garbage, defined as all alloca'd storage that - was allocated from deeper in the stack than currently. */ - - { - register header *hp; /* Traverses linked list. */ - -#ifdef emacs - BLOCK_INPUT; -#endif - - for (hp = last_alloca_header; hp != NULL;) - if ((STACK_DIR > 0 && hp->h.deep > depth) - || (STACK_DIR < 0 && hp->h.deep < depth)) - { - register header *np = hp->h.next; - - free ((pointer) hp); /* Collect garbage. */ - - hp = np; /* -> next header. */ - } - else - break; /* Rest are not deeper. */ - - last_alloca_header = hp; /* -> last valid storage. */ - -#ifdef emacs - UNBLOCK_INPUT; -#endif - } - - if (size == 0) - return NULL; /* No allocation required. */ - - /* Allocate combined header + user data storage. */ - - { - register pointer new = malloc (sizeof (header) + size); - /* Address of header. */ - - if (new == 0) - abort(); - - ((header *) new)->h.next = last_alloca_header; - ((header *) new)->h.deep = depth; - - last_alloca_header = (header *) new; - - /* User storage begins just after header. */ - - return (pointer) ((char *) new + sizeof (header)); - } -} - -#if defined (CRAY) && defined (CRAY_STACKSEG_END) - -#ifdef DEBUG_I00AFUNC -#include <stdio.h> -#endif - -#ifndef CRAY_STACK -#define CRAY_STACK -#ifndef CRAY2 -/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */ -struct stack_control_header - { - long shgrow:32; /* Number of times stack has grown. */ - long shaseg:32; /* Size of increments to stack. */ - long shhwm:32; /* High water mark of stack. */ - long shsize:32; /* Current size of stack (all segments). */ - }; - -/* The stack segment linkage control information occurs at - the high-address end of a stack segment. (The stack - grows from low addresses to high addresses.) The initial - part of the stack segment linkage control information is - 0200 (octal) words. This provides for register storage - for the routine which overflows the stack. */ - -struct stack_segment_linkage - { - long ss[0200]; /* 0200 overflow words. */ - long sssize:32; /* Number of words in this segment. */ - long ssbase:32; /* Offset to stack base. */ - long:32; - long sspseg:32; /* Offset to linkage control of previous - segment of stack. */ - long:32; - long sstcpt:32; /* Pointer to task common address block. */ - long sscsnm; /* Private control structure number for - microtasking. */ - long ssusr1; /* Reserved for user. */ - long ssusr2; /* Reserved for user. */ - long sstpid; /* Process ID for pid based multi-tasking. */ - long ssgvup; /* Pointer to multitasking thread giveup. */ - long sscray[7]; /* Reserved for Cray Research. */ - long ssa0; - long ssa1; - long ssa2; - long ssa3; - long ssa4; - long ssa5; - long ssa6; - long ssa7; - long sss0; - long sss1; - long sss2; - long sss3; - long sss4; - long sss5; - long sss6; - long sss7; - }; - -#else /* CRAY2 */ -/* The following structure defines the vector of words - returned by the STKSTAT library routine. */ -struct stk_stat - { - long now; /* Current total stack size. */ - long maxc; /* Amount of contiguous space which would - be required to satisfy the maximum - stack demand to date. */ - long high_water; /* Stack high-water mark. */ - long overflows; /* Number of stack overflow ($STKOFEN) calls. */ - long hits; /* Number of internal buffer hits. */ - long extends; /* Number of block extensions. */ - long stko_mallocs; /* Block allocations by $STKOFEN. */ - long underflows; /* Number of stack underflow calls ($STKRETN). */ - long stko_free; /* Number of deallocations by $STKRETN. */ - long stkm_free; /* Number of deallocations by $STKMRET. */ - long segments; /* Current number of stack segments. */ - long maxs; /* Maximum number of stack segments so far. */ - long pad_size; /* Stack pad size. */ - long current_address; /* Current stack segment address. */ - long current_size; /* Current stack segment size. This - number is actually corrupted by STKSTAT to - include the fifteen word trailer area. */ - long initial_address; /* Address of initial segment. */ - long initial_size; /* Size of initial segment. */ - }; - -/* The following structure describes the data structure which trails - any stack segment. I think that the description in 'asdef' is - out of date. I only describe the parts that I am sure about. */ - -struct stk_trailer - { - long this_address; /* Address of this block. */ - long this_size; /* Size of this block (does not include - this trailer). */ - long unknown2; - long unknown3; - long link; /* Address of trailer block of previous - segment. */ - long unknown5; - long unknown6; - long unknown7; - long unknown8; - long unknown9; - long unknown10; - long unknown11; - long unknown12; - long unknown13; - long unknown14; - }; - -#endif /* CRAY2 */ -#endif /* not CRAY_STACK */ - -#ifdef CRAY2 -/* Determine a "stack measure" for an arbitrary ADDRESS. - I doubt that "lint" will like this much. */ - -static long -i00afunc (long *address) -{ - struct stk_stat status; - struct stk_trailer *trailer; - long *block, size; - long result = 0; - - /* We want to iterate through all of the segments. The first - step is to get the stack status structure. We could do this - more quickly and more directly, perhaps, by referencing the - $LM00 common block, but I know that this works. */ - - STKSTAT (&status); - - /* Set up the iteration. */ - - trailer = (struct stk_trailer *) (status.current_address - + status.current_size - - 15); - - /* There must be at least one stack segment. Therefore it is - a fatal error if "trailer" is null. */ - - if (trailer == 0) - abort (); - - /* Discard segments that do not contain our argument address. */ - - while (trailer != 0) - { - block = (long *) trailer->this_address; - size = trailer->this_size; - if (block == 0 || size == 0) - abort (); - trailer = (struct stk_trailer *) trailer->link; - if ((block <= address) && (address < (block + size))) - break; - } - - /* Set the result to the offset in this segment and add the sizes - of all predecessor segments. */ - - result = address - block; - - if (trailer == 0) - { - return result; - } - - do - { - if (trailer->this_size <= 0) - abort (); - result += trailer->this_size; - trailer = (struct stk_trailer *) trailer->link; - } - while (trailer != 0); - - /* We are done. Note that if you present a bogus address (one - not in any segment), you will get a different number back, formed - from subtracting the address of the first block. This is probably - not what you want. */ - - return (result); -} - -#else /* not CRAY2 */ -/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP. - Determine the number of the cell within the stack, - given the address of the cell. The purpose of this - routine is to linearize, in some sense, stack addresses - for alloca. */ - -static long -i00afunc (long address) -{ - long stkl = 0; - - long size, pseg, this_segment, stack; - long result = 0; - - struct stack_segment_linkage *ssptr; - - /* Register B67 contains the address of the end of the - current stack segment. If you (as a subprogram) store - your registers on the stack and find that you are past - the contents of B67, you have overflowed the segment. - - B67 also points to the stack segment linkage control - area, which is what we are really interested in. */ - - stkl = CRAY_STACKSEG_END (); - ssptr = (struct stack_segment_linkage *) stkl; - - /* If one subtracts 'size' from the end of the segment, - one has the address of the first word of the segment. - - If this is not the first segment, 'pseg' will be - nonzero. */ - - pseg = ssptr->sspseg; - size = ssptr->sssize; - - this_segment = stkl - size; - - /* It is possible that calling this routine itself caused - a stack overflow. Discard stack segments which do not - contain the target address. */ - - while (!(this_segment <= address && address <= stkl)) - { -#ifdef DEBUG_I00AFUNC - fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl); -#endif - if (pseg == 0) - break; - stkl = stkl - pseg; - ssptr = (struct stack_segment_linkage *) stkl; - size = ssptr->sssize; - pseg = ssptr->sspseg; - this_segment = stkl - size; - } - - result = address - this_segment; - - /* If you subtract pseg from the current end of the stack, - you get the address of the previous stack segment's end. - This seems a little convoluted to me, but I'll bet you save - a cycle somewhere. */ - - while (pseg != 0) - { -#ifdef DEBUG_I00AFUNC - fprintf (stderr, "%011o %011o\n", pseg, size); -#endif - stkl = stkl - pseg; - ssptr = (struct stack_segment_linkage *) stkl; - size = ssptr->sssize; - pseg = ssptr->sspseg; - result += size; - } - return (result); -} - -#endif /* not CRAY2 */ -#endif /* CRAY */ - -#endif /* no alloca */ -#endif /* not GCC version 2 */ -#endif /* HAVE_ALLOCA */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/build-defs.h.in b/main/build-defs.h.in deleted file mode 100644 index ba1f8e4c8d..0000000000 --- a/main/build-defs.h.in +++ /dev/null @@ -1,91 +0,0 @@ -/* -*- C -*- - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Stig Sæther Bakken <ssb@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#define CONFIGURE_COMMAND "@CONFIGURE_COMMAND@" -#define PHP_ADA_INCLUDE "" -#define PHP_ADA_LFLAGS "" -#define PHP_ADA_LIBS "" -#define PHP_APACHE_INCLUDE "" -#define PHP_APACHE_TARGET "" -#define PHP_FHTTPD_INCLUDE "" -#define PHP_FHTTPD_LIB "" -#define PHP_FHTTPD_TARGET "" -#define PHP_CFLAGS "@CFLAGS@" -#define PHP_DBASE_LIB "" -#define PHP_BUILD_DEBUG "@DEBUG_CFLAGS@" -#define PHP_GDBM_INCLUDE "" -#define PHP_HSREGEX "" -#define PHP_IBASE_INCLUDE "" -#define PHP_IBASE_LFLAGS "" -#define PHP_IBASE_LIBS "" -#define PHP_IFX_INCLUDE "" -#define PHP_IFX_LFLAGS "" -#define PHP_IFX_LIBS "" -#define PHP_INSTALL_IT "@INSTALL_IT@" -#define PHP_IODBC_INCLUDE "" -#define PHP_IODBC_LFLAGS "" -#define PHP_IODBC_LIBS "" -#define PHP_MSQL_INCLUDE "" -#define PHP_MSQL_LFLAGS "" -#define PHP_MSQL_LIBS "" -#define PHP_MYSQL_INCLUDE "@MYSQL_INCLUDE@" -#define PHP_MYSQL_LIBS "@MYSQL_LIBS@" -#define PHP_MYSQL_TYPE "@MYSQL_MODULE_TYPE@" -#define PHP_ODBC_INCLUDE "@ODBC_INCLUDE@" -#define PHP_ODBC_LFLAGS "@ODBC_LFLAGS@" -#define PHP_ODBC_LIBS "@ODBC_LIBS@" -#define PHP_ODBC_TYPE "@ODBC_TYPE@" -#define PHP_OCI8_SHARED_LIBADD "@OCI8_SHARED_LIBADD@" -#define PHP_OCI8_DIR "@OCI8_DIR@" -#define PHP_OCI8_VERSION "@OCI8_VERSION@" -#define PHP_ORACLE_SHARED_LIBADD "@ORACLE_SHARED_LIBADD@" -#define PHP_ORACLE_DIR "@ORACLE_DIR@" -#define PHP_ORACLE_VERSION "@ORACLE_VERSION@" -#define PHP_PGSQL_INCLUDE "" -#define PHP_PGSQL_LFLAGS "" -#define PHP_PGSQL_LIBS "" -#define PHP_PROG_SENDMAIL "@PROG_SENDMAIL@" -#define PHP_REGEX_LIB "" -#define PHP_SOLID_INCLUDE "" -#define PHP_SOLID_LIBS "" -#define PHP_EMPRESS_INCLUDE "" -#define PHP_EMPRESS_LIBS "" -#define PHP_SYBASE_INCLUDE "" -#define PHP_SYBASE_LFLAGS "" -#define PHP_SYBASE_LIBS "" -#define PHP_DBM_TYPE "" -#define PHP_DBM_LIB "" -#define PHP_LDAP_LFLAGS "" -#define PHP_LDAP_INCLUDE "" -#define PHP_LDAP_LIBS "" -#define PHP_BIRDSTEP_INCLUDE "" -#define PHP_BIRDSTEP_LIBS "" -#define PEAR_INSTALLDIR "@EXPANDED_PEAR_INSTALLDIR@" -#define PHP_INCLUDE_PATH "@INCLUDE_PATH@" -#define PHP_EXTENSION_DIR "@EXPANDED_EXTENSION_DIR@" -#define PHP_PREFIX "@prefix@" -#define PHP_BINDIR "@EXPANDED_BINDIR@" -#define PHP_LIBDIR "@EXPANDED_LIBDIR@" -#define PHP_DATADIR "@EXPANDED_DATADIR@" -#define PHP_SYSCONFDIR "@EXPANDED_SYSCONFDIR@" -#define PHP_LOCALSTATEDIR "@EXPANDED_LOCALSTATEDIR@" -#define PHP_CONFIG_FILE_PATH "@EXPANDED_PHP_CONFIG_FILE_PATH@" -#define PHP_CONFIG_FILE_SCAN_DIR "@EXPANDED_PHP_CONFIG_FILE_SCAN_DIR@" -#define PHP_SHLIB_SUFFIX "@SHLIB_SUFFIX_NAME@" diff --git a/main/config.nw.h b/main/config.nw.h deleted file mode 100644 index 1329c4f244..0000000000 --- a/main/config.nw.h +++ /dev/null @@ -1,316 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* config.nw.h. Configure file for NetWare platform */ - - -/* Define if PHP to setup it's own SIGCHLD handler (not needed on NetWare) */ -#define PHP_SIGCHILD 0 - -/* dns functions found in resolv.lib */ -#define HAVE_LIBBIND 1 - -#define HAVE_GETSERVBYNAME 1 -#define HAVE_GETSERVBYPORT 1 -#define HAVE_GETPROTOBYNAME 1 -#define HAVE_GETPROTOBYNUMBER 1 - -/* set to enable bcmath */ -#define HAVE_BCMATH 1 - -/* set to enable mysql */ -#define HAVE_MYSQL 1 - -/* set to enable FTP support */ -#define HAVE_FTP 1 - -/* set to enable SNMP */ -/*#define HAVE_SNMP 1*/ - -/* defines for PostgreSQL extension */ -#define HAVE_PGSQL 1 -#define PHP_PGSQL_PRIVATE 1 -#define HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT 1 -#define HAVE_PQCLIENTENCODING 1 -#define HAVE_PQCMDTUPLES 1 -#define HAVE_PQOIDVALUE 1 - -/* set to enable bundled PCRE library */ -#define HAVE_BUNDLED_PCRE 1 - -/* set to enable bundled expat library */ -/* #define HAVE_LIBEXPAT 1 */ /* For now */ -#define HAVE_WDDX 0 - -/* set to enable the crypt command */ -/* #define HAVE_CRYPT 1 */ -/* #define HAVE_CRYPT_H 1 */ - -/* set to enable force cgi redirect */ -#define FORCE_CGI_REDIRECT 0 - -/* should be added to runtime config*/ -#define PHP_URL_FOPEN 1 - -#define STDIN_FILENO 0 -#define STDOUT_FILENO 1 -#define STDERR_FILENO 2 - -/* ---------------------------------------------------------------- - The following are defaults for run-time configuration - ---------------------------------------------------------------*/ - -#define PHP_SAFE_MODE 0 -#define MAGIC_QUOTES 0 - - -/* Undefine if you want stricter XML/SGML compliance by default */ -/* this disables "<?expression?>" and "<?=expression?>" */ -#define DEFAULT_SHORT_OPEN_TAG "1" - - -/* ---------------------------------------------------------------- - The following defines are for those modules which require - external libraries to compile. These will be removed from - here in a future beta, as these modules will be moved out to dll's - ---------------------------------------------------------------*/ -#define HAVE_ERRMSG_H 0 /*needed for mysql 3.21.17 and up*/ -#undef HAVE_ADABAS -#undef HAVE_SOLID - - -/* ---------------------------------------------------------------- - The following may or may not be (or need to be) ported to the - windows environment. - ---------------------------------------------------------------*/ - -/* Define if you have the link function. */ -#undef HAVE_LINK - -/* Define if you have the symlink function. */ -#undef HAVE_SYMLINK - -/* Define if you have the usleep function. */ -#undef HAVE_USLEEP - -#define HAVE_GETCWD 1 -/* #define HAVE_POSIX_READDIR_R 1 */ /* We will use readdir() from LibC */ - -#define NEED_ISBLANK 1 - -/* ---------------------------------------------------------------- - The following should never need to be played with - Functions defined to 0 or remarked out are either already - handled by the standard VC libraries, or are no longer needed, or - simply will/can not be ported. - - DONT TOUCH!!!!! Unless you realy know what your messing with! - ---------------------------------------------------------------*/ - -#define DISCARD_PATH 0 -#undef HAVE_SETITIMER -#undef HAVE_IODBC -#define HAVE_UODBC 1 -#define HAVE_LIBDL 1 -#define HAVE_SENDMAIL 1 - -/* Define if you have the gettimeofday function. */ -#define HAVE_GETTIMEOFDAY 1 - -/* Define if you have the putenv function. */ -#define HAVE_PUTENV 1 - -#define HAVE_LIMITS_H 1 - -#define HAVE_TZSET 1 -#define HAVE_TZNAME 1 - -/* Define if you have the flock function. */ -#undef HAVE_FLOCK - -/* Define if you have alloca, as a function or macro. */ -/* Though we have alloca(), this seems to be causing some problem with the stack pointer -- hence not using it */ -/* #define HAVE_ALLOCA 1 */ - -/* Define if you have <sys/time.h> */ -#undef HAVE_SYS_TIME_H - -/* Define if you have <signal.h> */ -#define HAVE_SIGNAL_H 1 - -/* Define if your struct stat has st_blksize. */ -#define HAVE_ST_BLKSIZE - -/* Define if your struct stat has st_blocks. */ -#define HAVE_ST_BLOCKS - -/* Define if your struct stat has st_rdev. */ -#define HAVE_ST_RDEV 1 - -/* Define if utime(file, NULL) sets file's timestamp to the present. */ -#define HAVE_UTIME_NULL 1 - -/* Define if you have the vprintf function. */ -#define HAVE_VPRINTF 1 - -/* Define if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Define both of these if you want the bundled REGEX library */ -#define REGEX 1 -#define HSREGEX 1 - -#define HAVE_PCRE 1 - -#define HAVE_LDAP 1 - -/* Define if you have the gcvt function. */ -/* #define HAVE_GCVT 1 */ - -/* Define if you have the getlogin function. */ -/* #define HAVE_GETLOGIN 1 */ - -/* Define if you have the memcpy function. */ -#define HAVE_MEMCPY 1 - -/* Define if you have the memmove function. */ -#define HAVE_MEMMOVE 1 - -/* Define if you have the regcomp function. */ -#define HAVE_REGCOMP 1 - -/* Define if you have the setlocale function. */ -/* #define HAVE_SETLOCALE 1 */ /* LibC doesn't seem to be supporting fully -- hence commenting for now */ - -#define HAVE_LOCALECONV 1 - -#define HAVE_LOCALE_H 1 - -/* Define if you have the setvbuf function. */ -#ifndef HAVE_LIBBIND -#define HAVE_SETVBUF 1 -#endif - -/* Define if you have the snprintf function. */ -#define HAVE_SNPRINTF 1 -#define HAVE_VSNPRINTF 1 -/* Define if you have the strcasecmp function. */ -#define HAVE_STRCASECMP 1 - -/* Define if you have the strdup function. */ -#define HAVE_STRDUP 1 - -/* Define if you have the strerror function. */ -#define HAVE_STRERROR 1 - -/* Define if you have the strstr function. */ -#define HAVE_STRSTR 1 - -/* Define if you have the tempnam function. */ -#define HAVE_TEMPNAM 1 - -/* Define if you have the utime function. */ -#define HAVE_UTIME 1 - -/* Define if you have the <dirent.h> header file. */ -#define HAVE_DIRENT_H 1 - -/* Define if you have the <fcntl.h> header file. */ -#define HAVE_FCNTL_H 1 - -/* Define if you have the <grp.h> header file. */ -#define HAVE_GRP_H 0 - -/* Define if you have the <pwd.h> header file. */ -#define HAVE_PWD_H 1 - -/* Define if you have the <string.h> header file. */ -#define HAVE_STRING_H 1 - -/* Define if you have the <sys/file.h> header file. */ -#undef HAVE_SYS_FILE_H - -/* Define if you have the <sys/socket.h> header file. */ -#ifdef USE_WINSOCK -#undef HAVE_SYS_SOCKET_H -#else -#define HAVE_SYS_SOCKET_H 1 /* Added '1' for '#if' to work */ -#endif - -/* Define if you have the <sys/wait.h> header file. */ -#undef HAVE_SYS_WAIT_H - -/* Define if you have the <syslog.h> header file. */ -/* #define HAVE_SYSLOG_H 1 */ - -/* Define if you have the <unistd.h> header file. */ -#define HAVE_UNISTD_H 1 /* Added '1' for '#if' to work */ - -/* Define if you have the dl library (-ldl). */ -#define HAVE_LIBDL 1 - -/* Define if you have the m library (-lm). */ -#define HAVE_LIBM 1 - -/* Define if you have the cuserid function. */ -#define HAVE_CUSERID 0 - -/* Define if you have the rint function. */ -#undef HAVE_RINT - -#define HAVE_STRFTIME 1 - -/* Defined since unsetenv function is defined in LibC. - * This is used to destroy env values in the function php_putenv_destructor. - * If we do not use unsetenv, then the environment variables are directlt manipulated. - * This will then result in LibC not being able to do the maintenance - * that is required for NetWare. - */ -#define HAVE_UNSETENV 1 - -/* Default directory for loading extensions. */ -#define PHP_EXTENSION_DIR "sys:/php/ext" - -#define SIZEOF_INT 4 - -/* Define directory constants for PHP and PEAR */ - -/* This is the default configuration file to read */ -#define CONFIGURATION_FILE_PATH "php.ini" - -#define APACHE_MODULE_DIR "sys:/apache/modules" -#define PHP_BINDIR "sys:/php" -#define PHP_LIBDIR PHP_BINDIR -#define PHP_DATADIR PHP_BINDIR -#define PHP_SYSCONFDIR PHP_BINDIR -#define PHP_LOCALSTATEDIR PHP_BINDIR -#define PHP_CONFIG_FILE_PATH "sys:/php" -#define PEAR_INSTALLDIR "sys:/php/pear" - -#define PHP_CONFIG_FILE_SCAN_DIR NULL -#define PHP_EXTENSION_DIR "sys:/php/ext" - -#define PHP_INCLUDE_PATH NULL - -#define PHP_PREFIX "sys:/php" -#define PHP_SHLIB_SUFFIX "nlm" - -#define USE_CONFIG_FILE 1 - diff --git a/main/config.w32.h b/main/config.w32.h deleted file mode 100644 index fcaa7218aa..0000000000 --- a/main/config.w32.h +++ /dev/null @@ -1,199 +0,0 @@ -/* - Build Configuration for Win32. - This has only been tested with MS VisualC++ 6 (and later). - - $Id$ -*/ - -/* Default PHP / PEAR directories */ -#define CONFIGURATION_FILE_PATH "php.ini" -#define PEAR_INSTALLDIR "c:\\php5\\pear" -#define PHP_BINDIR "c:\\php5" -#define PHP_CONFIG_FILE_PATH (getenv("SystemRoot"))?getenv("SystemRoot"):"" -#define PHP_CONFIG_FILE_SCAN_DIR "" -#define PHP_DATADIR "c:\\php5" -#define PHP_EXTENSION_DIR "c:\\php5" -#define PHP_INCLUDE_PATH ".;c:\\php5\\pear" -#define PHP_LIBDIR "c:\\php5" -#define PHP_LOCALSTATEDIR "c:\\php5" -#define PHP_PREFIX "c:\\php5" -#define PHP_SYSCONFDIR "c:\\php5" - -/* Enable / Disable BCMATH extension (default: enabled) */ -#define HAVE_BCMATH 1 - -/* Enable / Disable crypt() function (default: enabled) */ -#define HAVE_CRYPT 1 -#define PHP_STD_DES_CRYPT 1 -#define PHP_EXT_DES_CRYPT 0 -#define PHP_MD5_CRYPT 1 -#define PHP_BLOWFISH_CRYPT 0 - -/* Enable / Disable CALENDAR extension (default: enabled) */ -#define HAVE_CALENDAR 1 - -/* Enable / Disable CTYPE extension (default: enabled) */ -#define HAVE_CTYPE 1 - -/* Enable / Disable FTP extension (default: enabled) */ -#define HAVE_FTP 1 - -/* Enable / Disable MBSTRING extension (default: disabled) */ -/* #define HAVE_MBSTRING 0 */ -/* #define HAVE_MBREGEX 0 */ -/* #define HAVE_MBSTR_CN 0 */ -/* #define HAVE_MBSTR_JA 0 */ -/* #define HAVE_MBSTR_KR 0 */ -/* #define HAVE_MBSTR_RU 0 */ -/* #define HAVE_MBSTR_TW 0 */ - -/* If you have the .Net SDK in your include path, define this - * to compile .Net support into your COM extension. */ -#define HAVE_MSCOREE_H 0 - -/* Enable / Disable ODBC extension (default: enabled) */ -#define HAVE_UODBC 1 - -/* Enable / Disable PCRE extension (default: enabled) */ -#define HAVE_BUNDLED_PCRE 1 -#define HAVE_PCRE 1 - -/* Enable / Disable SESSION extension (default: enabled) */ -#define HAVE_PHP_SESSION 1 - -/* Enable / Disable TOKENIZER extension (default: enabled) */ -#define HAVE_TOKENIZER 1 - -/* Enable / Disable WDDX extension (default: enabled) */ -#define HAVE_WDDX 1 - -/* Enable / Disable XML extensions (default: enabled) */ -#define HAVE_LIBXML 1 -#define HAVE_DOM 1 -#define HAVE_SIMPLEXML 1 -#define HAVE_XML 1 - -/* Enable / Disable ZLIB extension (default: enabled) */ -#define HAVE_ZLIB 1 - -/* Enable / Disable SQLite extension (default: enabled) */ -#define HAVE_SQLITE 1 - -/* PHP Runtime Configuration */ -#define FORCE_CGI_REDIRECT 1 -#define PHP_URL_FOPEN 1 -#define PHP_SAFE_MODE 0 -#define MAGIC_QUOTES 0 -#define USE_CONFIG_FILE 1 -#define DEFAULT_SHORT_OPEN_TAG "1" -#define ENABLE_PATHINFO_CHECK 1 - -/* Platform-Specific Configuration. Should not be changed. */ -#define PHP_SIGCHILD 0 -#define HAVE_LIBBIND 1 -#define HAVE_GETSERVBYNAME 1 -#define HAVE_GETSERVBYPORT 1 -#define HAVE_GETPROTOBYNAME 1 -#define HAVE_GETPROTOBYNUMBER 1 -#define STDIN_FILENO 0 -#define STDOUT_FILENO 1 -#define STDERR_FILENO 2 -#define HAVE_ERRMSG_H 0 -#undef HAVE_ADABAS -#undef HAVE_SOLID -#undef HAVE_LINK -#undef HAVE_SYMLINK - -/* its in win32/time.c */ -#define HAVE_USLEEP 1 - -#define HAVE_GETCWD 1 -#define HAVE_POSIX_READDIR_R 1 -#define NEED_ISBLANK 1 -#define DISCARD_PATH 0 -#undef HAVE_SETITIMER -#undef HAVE_IODBC -#define HAVE_LIBDL 1 -#define HAVE_SENDMAIL 1 -#define HAVE_GETTIMEOFDAY 1 -#define HAVE_PUTENV 1 -#define HAVE_LIMITS_H 1 -#define HAVE_TZSET 1 -#define HAVE_TZNAME 1 -#undef HAVE_FLOCK -#define HAVE_ALLOCA 1 -#undef HAVE_SYS_TIME_H -#define HAVE_SIGNAL_H 1 -#undef HAVE_ST_BLKSIZE -#undef HAVE_ST_BLOCKS -#define HAVE_ST_RDEV 1 -#define HAVE_UTIME_NULL 1 -#define HAVE_VPRINTF 1 -#define STDC_HEADERS 1 -#define REGEX 1 -#define HSREGEX 1 -#define HAVE_GCVT 1 -#define HAVE_GETLOGIN 1 -#define HAVE_GETTIMEOFDAY 1 -#define HAVE_MEMCPY 1 -#define HAVE_MEMMOVE 1 -#define HAVE_PUTENV 1 -#define HAVE_REGCOMP 1 -#define HAVE_SETLOCALE 1 -#define HAVE_LOCALECONV 1 -#define HAVE_LOCALE_H 1 -#ifndef HAVE_LIBBIND -#define HAVE_SETVBUF 1 -#endif -#define HAVE_SHUTDOWN 1 -#define HAVE_SNPRINTF 1 -#define HAVE_VSNPRINTF 1 -#define HAVE_STRCASECMP 1 -#define HAVE_STRDUP 1 -#define HAVE_STRERROR 1 -#define HAVE_STRSTR 1 -#define HAVE_TEMPNAM 1 -#define HAVE_UTIME 1 -#undef HAVE_DIRENT_H -#define HAVE_ASSERT_H 1 -#define HAVE_FCNTL_H 1 -#define HAVE_GRP_H 0 -#define HAVE_PWD_H 1 -#define HAVE_STRING_H 1 -#undef HAVE_SYS_FILE_H -#undef HAVE_SYS_SOCKET_H -#undef HAVE_SYS_WAIT_H -#define HAVE_SYSLOG_H 1 -#undef HAVE_UNISTD_H -#define HAVE_LIBDL 1 -#define HAVE_LIBM 1 -#define HAVE_CUSERID 0 -#undef HAVE_RINT -#define HAVE_STRFTIME 1 -/* int and long are stll 32bit in 64bit compiles */ -#define SIZEOF_INT 4 -#define SIZEOF_LONG 4 -/* MSVC.6/NET don't allow 'long long' or know 'intmax_t' */ -#define SIZEOF_LONG_LONG_INT 0 -#define SIZEOF_LONG_LONG 0 -#define SIZEOF_INTMAX_T 0 -#define ssize_t SSIZE_T -#ifdef _WIN64 -# define SIZEOF_SIZE_T 8 -# define SIZEOF_PTRDIFF_T 8 -#else -# define SIZEOF_SIZE_T 4 -# define SIZEOF_PTRDIFF_T 4 -#endif -#define HAVE_GLOB -#define PHP_SHLIB_SUFFIX "dll" -#define HAVE_SQLDATASOURCES -#define POSIX_MALLOC_THRESHOLD 10 - -/* Win32 supports strcoll */ -#define HAVE_STRCOLL 1 - -/* Win32 support proc_open */ -#define PHP_CAN_SUPPORT_PROC_OPEN 1 - -#define HAVE_MBLEN diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c deleted file mode 100644 index b93b15a7d0..0000000000 --- a/main/fopen_wrappers.c +++ /dev/null @@ -1,576 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - | Jim Winstead <jimw@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* {{{ includes - */ -#include "php.h" -#include "php_globals.h" -#include "SAPI.h" - -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - -#ifdef PHP_WIN32 -#define O_RDONLY _O_RDONLY -#include "win32/param.h" -#elif defined(NETWARE) -/*#include <ws2nlm.h>*/ -/*#include <sys/socket.h>*/ -#ifdef NEW_LIBC -#include <sys/param.h> -#else -#include "netware/param.h" -#endif -#else -#include <sys/param.h> -#endif - -#include "safe_mode.h" -#include "ext/standard/head.h" -#include "ext/standard/php_standard.h" -#include "zend_compile.h" -#include "php_network.h" - -#if HAVE_PWD_H -#ifdef PHP_WIN32 -#include "win32/pwd.h" -#elif defined(NETWARE) -#include "netware/pwd.h" -#else -#include <pwd.h> -#endif -#endif - -#include <sys/types.h> -#if HAVE_SYS_SOCKET_H -#include <sys/socket.h> -#endif - -#ifndef S_ISREG -#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) -#endif - -#ifdef PHP_WIN32 -#include <winsock2.h> -#elif defined(NETWARE) && defined(USE_WINSOCK) -/*#include <ws2nlm.h>*/ -#include <novsock2.h> -#else -#include <netinet/in.h> -#include <netdb.h> -#if HAVE_ARPA_INET_H -#include <arpa/inet.h> -#endif -#endif - -#if defined(PHP_WIN32) || defined(__riscos__) || defined(NETWARE) -#undef AF_UNIX -#endif - -#if defined(AF_UNIX) -#include <sys/un.h> -#endif -/* }}} */ - -/* {{{ php_check_specific_open_basedir - When open_basedir is not NULL, check if the given filename is located in - open_basedir. Returns -1 if error or not in the open_basedir, else 0 - - When open_basedir is NULL, always return 0 -*/ -PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path TSRMLS_DC) -{ - char resolved_name[MAXPATHLEN]; - char resolved_basedir[MAXPATHLEN]; - char local_open_basedir[MAXPATHLEN]; - int local_open_basedir_pos; - int resolved_basedir_len; - int resolved_name_len; - - /* Special case basedir==".": Use script-directory */ - if ((strcmp(basedir, ".") == 0) && - SG(request_info).path_translated && - *SG(request_info).path_translated - ) { - strlcpy(local_open_basedir, SG(request_info).path_translated, sizeof(local_open_basedir)); - local_open_basedir_pos = strlen(local_open_basedir) - 1; - - /* Strip filename */ - while (!IS_SLASH(local_open_basedir[local_open_basedir_pos]) - && (local_open_basedir_pos >= 0)) { - local_open_basedir[local_open_basedir_pos--] = 0; - } - } else { - /* Else use the unmodified 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)) { - /* Handler for basedirs that end with a / */ - resolved_basedir_len = strlen(resolved_basedir); - if (basedir[strlen(basedir)-1] == PHP_DIR_SEPARATOR && resolved_basedir[resolved_basedir_len -1] != PHP_DIR_SEPARATOR) { - resolved_basedir[resolved_basedir_len] = '/'; - resolved_basedir[++resolved_basedir_len] = '\0'; - } - - if (path[strlen(path)-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] = '/'; - resolved_name[++resolved_name_len] = '\0'; - } - } - - /* Check the path */ -#ifdef PHP_WIN32 - if (strncasecmp(resolved_basedir, resolved_name, resolved_basedir_len) == 0) { -#else - if (strncmp(resolved_basedir, resolved_name, resolved_basedir_len) == 0) { -#endif - /* File is in the right directory */ - return 0; - } else { - return -1; - } - } else { - /* Unable to resolve the real path, return -1 */ - return -1; - } -} -/* }}} */ - -PHPAPI int php_check_open_basedir(const char *path TSRMLS_DC) -{ - return php_check_open_basedir_ex(path, 1 TSRMLS_CC); -} - -/* {{{ php_check_open_basedir - */ -PHPAPI int php_check_open_basedir_ex(const char *path, int warn TSRMLS_DC) -{ - /* Only check when open_basedir is available */ - if (PG(open_basedir) && *PG(open_basedir)) { - char *pathbuf; - char *ptr; - char *end; - - pathbuf = estrdup(PG(open_basedir)); - - ptr = pathbuf; - - while (ptr && *ptr) { - end = strchr(ptr, DEFAULT_DIR_SEPARATOR); - if (end != NULL) { - *end = '\0'; - end++; - } - - if (php_check_specific_open_basedir(ptr, path TSRMLS_CC) == 0) { - efree(pathbuf); - return 0; - } - - ptr = end; - } - if (warn) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, - "open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s)", path, PG(open_basedir)); - } - efree(pathbuf); - errno = EPERM; /* we deny permission to open it */ - return -1; - } - - /* Nothing to check... */ - return 0; -} -/* }}} */ - -/* {{{ php_check_safe_mode_include_dir - */ -PHPAPI int php_check_safe_mode_include_dir(char *path TSRMLS_DC) -{ - if (PG(safe_mode)) { - if (PG(safe_mode_include_dir) && *PG(safe_mode_include_dir)) { - char *pathbuf; - char *ptr; - char *end; - char resolved_name[MAXPATHLEN]; - - /* Resolve the real path into resolved_name */ - if (expand_filepath(path, resolved_name TSRMLS_CC) == NULL) - return -1; - - pathbuf = estrdup(PG(safe_mode_include_dir)); - - ptr = pathbuf; - - while (ptr && *ptr) { - end = strchr(ptr, DEFAULT_DIR_SEPARATOR); - if (end != NULL) { - *end = '\0'; - end++; - } - - /* Check the path */ -#ifdef PHP_WIN32 - if (strncasecmp(ptr, resolved_name, strlen(ptr)) == 0) -#else - if (strncmp(ptr, resolved_name, strlen(ptr)) == 0) -#endif - { - /* File is in the right directory */ - efree(pathbuf); - return 0; - } - - ptr = end; - } - efree(pathbuf); - } - return -1; - } - - /* Nothing to check... */ - return 0; -} -/* }}} */ - -/* {{{ php_fopen_and_set_opened_path - */ -static FILE *php_fopen_and_set_opened_path(const char *path, char *mode, char **opened_path TSRMLS_DC) -{ - FILE *fp; - - if (php_check_open_basedir((char *)path TSRMLS_CC)) { - return NULL; - } - fp = VCWD_FOPEN(path, mode); - if (fp && opened_path) { - *opened_path = expand_filepath(path, NULL TSRMLS_CC); - } - return fp; -} -/* }}} */ - -/* {{{ php_fopen_primary_script - */ -PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle TSRMLS_DC) -{ - FILE *fp; - struct stat st; - 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; - 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 */ - length = s - (path_info + 2); - if (length > (int)sizeof(user) - 1) - length = sizeof(user) - 1; - memcpy(user, path_info + 2, length); - user[length] = '\0'; - - pw = getpwnam(user); - 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, - PG(user_dir), PHP_DIR_SEPARATOR, s+1); /* Safe */ - STR_FREE(SG(request_info).path_translated); - SG(request_info).path_translated = filename; - } - } - } - } else -#endif - if (PG(doc_root) && path_info) { - length = strlen(PG(doc_root)); - if (IS_ABSOLUTE_PATH(PG(doc_root), length)) { - filename = emalloc(length + strlen(path_info) + 2); - if (filename) { - memcpy(filename, PG(doc_root), length); - if (!IS_SLASH(filename[length - 1])) { /* length is never 0 */ - filename[length++] = PHP_DIR_SEPARATOR; - } - if (IS_SLASH(path_info[0])) { - length--; - } - strcpy(filename + length, path_info); - STR_FREE(SG(request_info).path_translated); - SG(request_info).path_translated = filename; - } - } - } /* if doc_root && path_info */ - - if (!filename) { - /* we have to free SG(request_info).path_translated here because - php_destroy_request_info assumes that it will get - freed when the include_names hash is emptied, but - we're not adding it in this case */ - STR_FREE(SG(request_info).path_translated); - SG(request_info).path_translated = NULL; - return FAILURE; - } - fp = VCWD_FOPEN(filename, "rb"); - - /* 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; - } - if (!fp) { - STR_FREE(SG(request_info).path_translated); /* for same reason as above */ - SG(request_info).path_translated = NULL; - return FAILURE; - } - - file_handle->opened_path = expand_filepath(filename, NULL TSRMLS_CC); - - if (!(SG(options) & SAPI_OPTION_NO_CHDIR)) { - VCWD_CHDIR_FILE(filename); - } - SG(request_info).path_translated = filename; - - file_handle->filename = SG(request_info).path_translated; - file_handle->free_filename = 0; - file_handle->handle.fp = fp; - file_handle->type = ZEND_HANDLE_FP; - - return SUCCESS; -} -/* }}} */ - -/* {{{ php_fopen_with_path - * Tries to open a file with a PATH-style list of directories. - * If the filename starts with "." or "/", the path is ignored. - */ -PHPAPI FILE *php_fopen_with_path(char *filename, char *mode, char *path, char **opened_path TSRMLS_DC) -{ - char *pathbuf, *ptr, *end; - char *exec_fname; - char trypath[MAXPATHLEN]; - struct stat sb; - FILE *fp; - int path_length; - int filename_length; - int exec_fname_length; - - if (opened_path) { - *opened_path = NULL; - } - - if(!filename) { - return NULL; - } - - filename_length = strlen(filename); - - /* Relative path open */ - if (*filename == '.') { - if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM))) { - return NULL; - } - return php_fopen_and_set_opened_path(filename, mode, opened_path TSRMLS_CC); - } - - /* - * files in safe_mode_include_dir (or subdir) are excluded from - * safe mode GID/UID checks - */ - - /* Absolute path open */ - if (IS_ABSOLUTE_PATH(filename, filename_length)) { - if ((php_check_safe_mode_include_dir(filename TSRMLS_CC)) == 0) - /* filename is in safe_mode_include_dir (or subdir) */ - return php_fopen_and_set_opened_path(filename, mode, opened_path TSRMLS_CC); - - if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM))) - return NULL; - - return php_fopen_and_set_opened_path(filename, mode, opened_path TSRMLS_CC); - } - - if (!path || (path && !*path)) { - if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM))) { - return NULL; - } - return php_fopen_and_set_opened_path(filename, mode, opened_path TSRMLS_CC); - } - - /* check in provided path */ - /* append the calling scripts' current working directory - * as a fall back case - */ - if (zend_is_executing(TSRMLS_C)) { - exec_fname = zend_get_executed_filename(TSRMLS_C); - exec_fname_length = strlen(exec_fname); - path_length = strlen(path); - - while ((--exec_fname_length >= 0) && !IS_SLASH(exec_fname[exec_fname_length])); - if ((exec_fname && exec_fname[0] == '[') - || exec_fname_length<=0) { - /* [no active file] or no path */ - pathbuf = estrdup(path); - } else { - pathbuf = (char *) emalloc(exec_fname_length + path_length +1 +1); - memcpy(pathbuf, path, path_length); - pathbuf[path_length] = DEFAULT_DIR_SEPARATOR; - memcpy(pathbuf+path_length+1, exec_fname, exec_fname_length); - pathbuf[path_length + exec_fname_length +1] = '\0'; - } - } else { - pathbuf = estrdup(path); - } - - ptr = pathbuf; - - while (ptr && *ptr) { - end = strchr(ptr, DEFAULT_DIR_SEPARATOR); - if (end != NULL) { - *end = '\0'; - end++; - } - snprintf(trypath, MAXPATHLEN, "%s/%s", ptr, filename); - if (PG(safe_mode)) { - if (VCWD_STAT(trypath, &sb) == 0) { - /* file exists ... check permission */ - if ((php_check_safe_mode_include_dir(trypath TSRMLS_CC) == 0) || - php_checkuid(trypath, mode, CHECKUID_CHECK_MODE_PARAM)) - /* UID ok, or trypath is in safe_mode_include_dir */ - fp = php_fopen_and_set_opened_path(trypath, mode, opened_path TSRMLS_CC); - else - fp = NULL; - - efree(pathbuf); - return fp; - } - } - fp = php_fopen_and_set_opened_path(trypath, mode, opened_path TSRMLS_CC); - if (fp) { - efree(pathbuf); - return fp; - } - ptr = end; - } /* end provided path */ - - efree(pathbuf); - return NULL; -} -/* }}} */ - -/* {{{ php_strip_url_passwd - */ -PHPAPI char *php_strip_url_passwd(char *url) -{ - register char *p, *url_start; - - if (url == NULL) { - return ""; - } - - p = url; - - while (*p) { - if (*p==':' && *(p+1)=='/' && *(p+2)=='/') { - /* found protocol */ - url_start = p = p+3; - - while (*p) { - if (*p=='@') { - int i; - - for (i=0; i<3 && url_start<p; i++, url_start++) { - *url_start = '.'; - } - for (; *p; p++) { - *url_start++ = *p; - } - *url_start=0; - break; - } - p++; - } - return url; - } - p++; - } - return url; -} -/* }}} */ - -/* {{{ expand_filepath - */ -PHPAPI char *expand_filepath(const char *filepath, char *real_path TSRMLS_DC) -{ - cwd_state new_state; - char cwd[MAXPATHLEN]; - char *result; - - result = VCWD_GETCWD(cwd, MAXPATHLEN); - if (!result) { - cwd[0] = '\0'; - } - - new_state.cwd = strdup(cwd); - new_state.cwd_length = strlen(cwd); - - if(virtual_file_ex(&new_state, filepath, NULL, 1)) { - free(new_state.cwd); - return NULL; - } - - if(real_path) { - int copy_len = new_state.cwd_length>MAXPATHLEN-1?MAXPATHLEN-1:new_state.cwd_length; - memcpy(real_path, new_state.cwd, copy_len); - real_path[copy_len]='\0'; - } else { - real_path = estrndup(new_state.cwd, new_state.cwd_length); - } - free(new_state.cwd); - - return real_path; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/fopen_wrappers.h b/main/fopen_wrappers.h deleted file mode 100644 index d8ea946dae..0000000000 --- a/main/fopen_wrappers.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Jim Winstead <jimw@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef FOPEN_WRAPPERS_H -#define FOPEN_WRAPPERS_H - -BEGIN_EXTERN_C() -#include "php_globals.h" - -PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle TSRMLS_DC); -PHPAPI char *expand_filepath(const char *filepath, char *real_path TSRMLS_DC); - -PHPAPI int php_check_open_basedir(const char *path TSRMLS_DC); -PHPAPI int php_check_open_basedir_ex(const char *path, int warn TSRMLS_DC); -PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path TSRMLS_DC); - -PHPAPI int php_check_safe_mode_include_dir(char *path TSRMLS_DC); - -PHPAPI FILE *php_fopen_with_path(char *filename, char *mode, char *path, char **opened_path TSRMLS_DC); - -PHPAPI int php_is_url(char *path); -PHPAPI char *php_strip_url_passwd(char *path); -END_EXTERN_C() - -#endif -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/main/internal_functions.c.in b/main/internal_functions.c.in deleted file mode 100644 index cd9bd50644..0000000000 --- a/main/internal_functions.c.in +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- C -*- - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" -#include "php_main.h" -#include "zend_modules.h" -#include "internal_functions_registry.h" -#include "zend_compile.h" -#include <stdarg.h> -#include <stdlib.h> -#include <stdio.h> - -@EXT_INCLUDE_CODE@ - -zend_module_entry *php_builtin_extensions[] = { -@EXT_MODULE_PTRS@ -}; - -#define EXTCOUNT (sizeof(php_builtin_extensions)/sizeof(zend_module_entry *)) - - -int php_startup_internal_extensions(void) -{ - return php_startup_extensions(php_builtin_extensions, EXTCOUNT); -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/main/internal_functions_nw.c b/main/internal_functions_nw.c deleted file mode 100644 index 3ca4854973..0000000000 --- a/main/internal_functions_nw.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | - | Modified for NetWare: Novell, Inc. | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* {{{ includes - */ -#include "php.h" -#include "php_main.h" -#include "zend_modules.h" -#include "internal_functions_registry.h" -#include "zend_compile.h" -#include <stdarg.h> -#include <stdlib.h> -#include <stdio.h> - -#include "ext/bcmath/php_bcmath.h" -#include "ext/gd/php_gd.h" -#include "ext/standard/dl.h" -#include "ext/standard/file.h" -#include "ext/standard/fsock.h" -#include "ext/standard/head.h" -#include "ext/standard/pack.h" -#include "ext/standard/php_browscap.h" -/*#include "ext/standard/php_crypt.h"*/ -#include "ext/standard/php_dir.h" -#include "ext/standard/php_filestat.h" -#include "ext/standard/php_mail.h" -/*#include "ext/standard/php_ext_syslog.h"*/ -#include "ext/standard/php_standard.h" -#include "ext/standard/php_lcg.h" -#include "ext/standard/php_array.h" -#include "ext/standard/php_assert.h" -#include "ext/calendar/php_calendar.h" -/*#include "ext/com/php_COM.h" -#include "ext/com/php_VARIANT.h"*/ -#include "ext/ftp/php_ftp.h" -#include "ext/standard/reg.h" -#include "ext/pcre/php_pcre.h" -/*#include "ext/odbc/php_odbc.h"*/ /* Commented out for now */ -#include "ext/session/php_session.h" -/*#include "ext/xml/php_xml.h" -#include "ext/wddx/php_wddx.h" -#include "ext/mysql/php_mysql.h"*/ /* Commented out for now */ -/* }}} */ - -/* {{{ php_builtin_extensions[] - */ -zend_module_entry *php_builtin_extensions[] = { - phpext_standard_ptr, -#if HAVE_BCMATH - phpext_bcmath_ptr, -#endif - phpext_calendar_ptr, -/* COM_module_ptr,*/ - phpext_ftp_ptr, -#if defined(MBSTR_ENC_TRANS) - phpext_mbstring_ptr, -#endif -/* phpext_mysql_ptr,*/ /* Commented out for now */ -/* phpext_odbc_ptr, */ /* Commented out for now */ - phpext_pcre_ptr, - phpext_session_ptr, -/* phpext_xml_ptr, - phpext_wddx_ptr */ /* Commented out for now */ -}; -/* }}} */ - -#define EXTCOUNT (sizeof(php_builtin_extensions)/sizeof(zend_module_entry *)) - - -int php_startup_internal_extensions(void) -{ - return php_startup_extensions(php_builtin_extensions, EXTCOUNT); -} - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/internal_functions_registry.h b/main/internal_functions_registry.h deleted file mode 100644 index 86980b4127..0000000000 --- a/main/internal_functions_registry.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef INTERNAL_FUNCTIONS_REGISTRY_H -#define INTERNAL_FUNCTIONS_REGISTRY_H - -extern int php_init_mime(INIT_FUNC_ARGS); - -/* environment functions */ -extern int php_init_environment(void); - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/main/internal_functions_win32.c b/main/internal_functions_win32.c deleted file mode 100644 index edcf82cccf..0000000000 --- a/main/internal_functions_win32.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* {{{ includes - */ -#include "php.h" -#include "php_main.h" -#include "zend_modules.h" -#include "internal_functions_registry.h" -#include "zend_compile.h" -#include <stdarg.h> -#include <stdlib.h> -#include <stdio.h> - -#ifndef ZEND_ENGINE_2 -#error HEAD does not work with ZendEngine1 anymore -#endif - -#include "ext/standard/dl.h" -#include "ext/standard/file.h" -#include "ext/standard/fsock.h" -#include "ext/standard/head.h" -#include "ext/standard/pack.h" -#include "ext/standard/php_browscap.h" -#include "ext/standard/php_crypt.h" -#include "ext/standard/php_dir.h" -#include "ext/standard/php_filestat.h" -#include "ext/standard/php_mail.h" -#include "ext/standard/php_ext_syslog.h" -#include "ext/standard/php_standard.h" -#include "ext/standard/php_lcg.h" -#include "ext/standard/php_array.h" -#include "ext/standard/php_assert.h" -#if HAVE_BCMATH -#include "ext/bcmath/php_bcmath.h" -#endif -#if HAVE_CALENDAR -#include "ext/calendar/php_calendar.h" -#endif -#if HAVE_CTYPE -#include "ext/ctype/php_ctype.h" -#endif -#if HAVE_FTP -#include "ext/ftp/php_ftp.h" -#endif -#include "ext/standard/reg.h" -#if HAVE_PCRE || HAVE_BUNDLED_PCRE -#include "ext/pcre/php_pcre.h" -#endif -#if HAVE_UODBC -#include "ext/odbc/php_odbc.h" -#endif -#if HAVE_PHP_SESSION -#include "ext/session/php_session.h" -#endif -#if HAVE_MBSTRING -#include "ext/mbstring/mbstring.h" -#endif -#if HAVE_TOKENIZER -#include "ext/tokenizer/php_tokenizer.h" -#endif -#if HAVE_ZLIB -#include "ext/zlib/php_zlib.h" -#endif -#if HAVE_LIBXML -#include "ext/libxml/php_libxml.h" -#if HAVE_DOM -#include "ext/dom/php_dom.h" -#endif -#if HAVE_SIMPLEXML -#include "ext/simplexml/php_simplexml.h" -#endif -#endif -#if HAVE_XML -#include "ext/xml/php_xml.h" -#endif -#if HAVE_XML && HAVE_WDDX -#include "ext/wddx/php_wddx.h" -#endif -#ifdef HAVE_SQLITE -#include "ext/sqlite/php_sqlite.h" -#endif -#include "ext/com_dotnet/php_com_dotnet.h" -/* }}} */ - -/* {{{ php_builtin_extensions[] - */ -zend_module_entry *php_builtin_extensions[] = { - phpext_standard_ptr -#if HAVE_BCMATH - ,phpext_bcmath_ptr -#endif -#if HAVE_CALENDAR - ,phpext_calendar_ptr -#endif - ,phpext_com_dotnet_ptr -#if HAVE_CTYPE - ,phpext_ctype_ptr -#endif -#if HAVE_FTP - ,phpext_ftp_ptr -#endif -#if HAVE_MBSTRING - ,phpext_mbstring_ptr -#endif -#if HAVE_UODBC - ,phpext_odbc_ptr -#endif -#if HAVE_PCRE || HAVE_BUNDLED_PCRE - ,phpext_pcre_ptr -#endif -#if HAVE_PHP_SESSION - ,phpext_session_ptr -#endif -#if HAVE_TOKENIZER - ,phpext_tokenizer_ptr -#endif -#if HAVE_ZLIB - ,phpext_zlib_ptr -#endif -#if HAVE_LIBXML - ,phpext_libxml_ptr -#if HAVE_DOM - ,phpext_dom_ptr -#endif -#if HAVE_SIMPLEXML - ,phpext_simplexml_ptr -#endif -#endif -#if HAVE_XML - ,phpext_xml_ptr -#endif -#if HAVE_XML && HAVE_WDDX - ,phpext_wddx_ptr -#endif -#if HAVE_SQLITE - ,phpext_sqlite_ptr -#endif -}; -/* }}} */ - -#define EXTCOUNT (sizeof(php_builtin_extensions)/sizeof(zend_module_entry *)) - -int php_startup_internal_extensions(void) -{ - return php_startup_extensions(php_builtin_extensions, EXTCOUNT); -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/logos.h b/main/logos.h deleted file mode 100644 index a67ee2d762..0000000000 --- a/main/logos.h +++ /dev/null @@ -1,1314 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#define CONTEXT_TYPE_IMAGE_GIF "Content-Type: image/gif" - -unsigned char zend_logo[] = { - 71, 73, 70, 56, 57, 97, 113, 0, 72, 0, - 213, 0, 0, 13, 13, 14, 1, 3, 6, 2, - 5, 9, 46, 68, 94, 21, 29, 39, 5, 15, - 26, 4, 10, 17, 29, 43, 58, 0, 1, 2, - 9, 25, 42, 38, 105, 171, 24, 67, 109, 13, - 36, 59, 10, 27, 45, 9, 25, 41, 35, 96, - 157, 32, 87, 142, 29, 79, 130, 26, 70, 114, - 20, 54, 87, 29, 77, 124, 10, 26, 42, 34, - 88, 141, 10, 24, 38, 11, 26, 41, 1, 2, - 3, 55, 80, 105, 45, 63, 81, 49, 53, 57, - 5, 15, 24, 9, 26, 42, 30, 85, 138, 33, - 92, 149, 26, 73, 117, 10, 28, 45, 32, 89, - 142, 30, 84, 134, 26, 72, 115, 15, 42, 67, - 23, 62, 99, 12, 32, 51, 7, 21, 33, 9, - 26, 41, 8, 23, 35, 7, 25, 37, 51, 58, - 63, 2, 4, 5, 25, 26, 26, 49, 50, 50, - 255, 102, 0, 255, 255, 255, 204, 204, 204, 199, - 199, 199, 191, 191, 191, 171, 171, 171, 146, 146, - 146, 115, 115, 115, 85, 85, 85, 60, 60, 60, - 55, 55, 55, 38, 38, 38, 7, 7, 7, 3, - 3, 3, 0, 0, 0, 44, 0, 0, 0, 0, - 113, 0, 72, 0, 0, 6, 255, 192, 153, 112, - 72, 44, 26, 143, 200, 164, 114, 121, 252, 49, - 159, 208, 168, 148, 248, 171, 58, 167, 210, 171, - 208, 170, 197, 122, 191, 70, 109, 23, 140, 236, - 138, 201, 232, 239, 121, 102, 221, 186, 217, 219, - 171, 83, 46, 110, 15, 207, 235, 180, 190, 124, - 135, 187, 229, 127, 127, 128, 112, 121, 108, 118, - 132, 123, 137, 77, 118, 120, 136, 115, 109, 117, - 85, 126, 147, 147, 128, 99, 138, 137, 99, 107, - 146, 146, 148, 133, 159, 125, 136, 152, 163, 151, - 135, 121, 144, 84, 157, 92, 169, 157, 111, 163, - 175, 176, 83, 151, 177, 180, 181, 161, 182, 184, - 185, 186, 187, 188, 189, 67, 54, 56, 58, 56, - 53, 190, 197, 88, 55, 57, 60, 63, 2, 43, - 2, 56, 198, 208, 74, 192, 58, 0, 63, 5, - 12, 11, 35, 35, 12, 47, 209, 222, 67, 53, - 201, 203, 34, 19, 20, 218, 231, 37, 63, 54, - 223, 222, 60, 2, 216, 231, 241, 231, 206, 76, - 193, 55, 236, 176, 63, 39, 242, 252, 35, 40, - 58, 75, 114, 8, 40, 240, 227, 25, 62, 76, - 60, 24, 244, 147, 55, 161, 202, 11, 24, 57, - 134, 17, 201, 241, 99, 130, 191, 130, 7, 21, - 225, 48, 176, 48, 30, 137, 5, 11, 38, 48, - 88, 81, 5, 198, 51, 138, 22, 181, 53, 52, - 152, 49, 141, 141, 31, 230, 58, 46, 60, 129, - 194, 74, 202, 115, 43, 91, 234, 1, 112, 83, - 102, 63, 255, 18, 38, 122, 226, 252, 145, 67, - 39, 153, 26, 47, 68, 248, 92, 186, 176, 97, - 81, 163, 88, 108, 188, 48, 80, 130, 169, 85, - 134, 68, 161, 74, 177, 1, 160, 0, 137, 171, - 96, 135, 62, 213, 186, 132, 171, 215, 176, 104, - 71, 52, 188, 71, 54, 9, 210, 179, 105, 195, - 166, 99, 219, 214, 198, 58, 34, 48, 12, 124, - 213, 38, 163, 175, 223, 191, 50, 22, 132, 216, - 139, 182, 132, 0, 30, 196, 250, 218, 37, 70, - 198, 198, 141, 199, 144, 31, 223, 253, 114, 163, - 10, 0, 97, 192, 126, 100, 59, 7, 24, 176, - 10, 20, 229, 210, 146, 48, 128, 88, 72, 223, - 28, 57, 38, 111, 197, 17, 163, 181, 235, 215, - 58, 116, 68, 100, 60, 5, 134, 136, 18, 19, - 80, 24, 168, 162, 48, 94, 95, 21, 6, 82, - 168, 80, 209, 215, 128, 1, 20, 39, 8, 95, - 37, 81, 160, 180, 105, 25, 177, 233, 62, 1, - 246, 186, 186, 245, 24, 209, 177, 84, 140, 71, - 97, 130, 114, 109, 33, 76, 48, 152, 176, 192, - 111, 135, 20, 222, 211, 54, 167, 61, 163, 111, - 246, 39, 55, 174, 203, 175, 254, 30, 74, 229, - 152, 62, 73, 132, 24, 60, 162, 47, 131, 14, - 12, 132, 224, 155, 95, 130, 145, 208, 89, 129, - 40, 116, 211, 25, 12, 58, 72, 135, 68, 124, - 214, 197, 38, 161, 14, 243, 73, 200, 222, 18, - 27, 161, 213, 215, 4, 159, 37, 199, 255, 25, - 96, 12, 116, 230, 223, 9, 11, 252, 32, 226, - 11, 13, 74, 35, 223, 132, 19, 174, 24, 27, - 75, 76, 192, 128, 66, 88, 126, 161, 160, 66, - 122, 124, 201, 112, 2, 3, 195, 125, 54, 65, - 95, 29, 4, 87, 227, 9, 126, 233, 192, 3, - 12, 125, 161, 232, 160, 93, 207, 184, 200, 98, - 139, 17, 74, 24, 197, 118, 96, 249, 7, 160, - 128, 31, 242, 72, 30, 72, 33, 244, 149, 2, - 122, 229, 201, 0, 224, 105, 60, 52, 216, 23, - 131, 14, 226, 96, 194, 1, 78, 74, 152, 195, - 13, 196, 208, 192, 90, 148, 177, 217, 7, 83, - 149, 50, 112, 136, 220, 94, 34, 22, 216, 159, - 12, 195, 101, 227, 37, 113, 50, 192, 0, 3, - 156, 238, 165, 72, 196, 11, 21, 178, 184, 228, - 117, 19, 66, 145, 225, 85, 53, 222, 72, 152, - 136, 42, 152, 32, 224, 111, 42, 8, 10, 40, - 161, 101, 222, 96, 67, 95, 61, 40, 58, 3, - 13, 55, 24, 112, 221, 101, 19, 226, 64, 131, - 17, 54, 64, 42, 229, 19, 50, 226, 249, 95, - 128, 127, 238, 23, 166, 113, 194, 105, 250, 103, - 160, 191, 18, 90, 232, 13, 59, 0, 249, 130, - 168, 56, 160, 198, 195, 10, 214, 161, 144, 1, - 131, 245, 21, 1, 33, 125, 177, 141, 181, 4, - 149, 76, 137, 232, 23, 3, 38, 132, 9, 216, - 9, 93, 126, 234, 105, 160, 34, 94, 208, 129, - 14, 7, 152, 112, 255, 2, 4, 40, 84, 80, - 157, 8, 30, 176, 154, 195, 133, 68, 200, 250, - 34, 124, 119, 102, 171, 109, 113, 157, 142, 16, - 238, 111, 160, 113, 58, 110, 167, 38, 252, 213, - 192, 193, 12, 72, 32, 193, 3, 15, 128, 192, - 128, 7, 175, 121, 32, 66, 7, 101, 230, 240, - 42, 18, 53, 216, 171, 131, 106, 73, 224, 32, - 0, 88, 221, 217, 216, 227, 200, 190, 234, 39, - 210, 112, 12, 36, 23, 158, 175, 254, 154, 160, - 105, 9, 5, 236, 88, 129, 7, 41, 83, 240, - 65, 195, 32, 56, 236, 128, 107, 14, 36, 208, - 64, 10, 24, 41, 161, 177, 181, 74, 84, 182, - 194, 4, 85, 45, 181, 239, 134, 11, 236, 165, - 31, 151, 95, 233, 199, 223, 8, 82, 27, 40, - 3, 9, 39, 144, 56, 24, 4, 92, 119, 61, - 129, 3, 96, 135, 221, 128, 8, 12, 0, 64, - 239, 47, 26, 59, 88, 52, 53, 227, 132, 182, - 208, 210, 128, 178, 76, 163, 12, 46, 135, 208, - 245, 221, 92, 3, 21, 54, 216, 9, 152, 208, - 48, 64, 72, 12, 237, 197, 52, 0, 152, 208, - 209, 111, 193, 141, 204, 239, 102, 104, 45, 96, - 128, 9, 20, 224, 45, 249, 215, 97, 51, 240, - 1, 8, 10, 152, 80, 20, 14, 56, 208, 213, - 38, 199, 181, 245, 214, 207, 111, 96, 130, 4, - 146, 72, 114, 135, 69, 194, 10, 38, 64, 0, - 130, 228, 120, 71, 240, 181, 8, 145, 67, 240, - 255, 128, 2, 44, 164, 0, 26, 2, 66, 180, - 9, 163, 23, 56, 20, 112, 184, 184, 242, 232, - 119, 224, 212, 127, 18, 56, 152, 95, 14, 252, - 8, 88, 129, 120, 255, 37, 216, 205, 17, 68, - 160, 192, 3, 24, 212, 64, 131, 198, 58, 92, - 12, 70, 101, 223, 125, 8, 172, 60, 218, 166, - 252, 149, 136, 41, 251, 21, 64, 249, 201, 117, - 221, 89, 202, 151, 131, 112, 251, 9, 211, 194, - 54, 161, 218, 88, 212, 128, 237, 128, 207, 35, - 15, 164, 144, 125, 65, 78, 141, 206, 3, 164, - 0, 245, 69, 0, 34, 248, 95, 10, 134, 68, - 2, 8, 244, 101, 71, 97, 3, 77, 237, 70, - 240, 0, 18, 248, 110, 15, 58, 80, 10, 63, - 48, 37, 55, 47, 129, 169, 128, 86, 10, 152, - 12, 132, 19, 166, 2, 36, 112, 132, 31, 20, - 83, 128, 28, 40, 3, 6, 52, 207, 116, 91, - 227, 218, 3, 218, 68, 52, 50, 224, 32, 95, - 228, 147, 1, 175, 134, 211, 65, 226, 13, 138, - 116, 222, 249, 77, 1, 10, 38, 3, 7, 52, - 160, 47, 96, 91, 0, 11, 83, 224, 128, 62, - 197, 176, 107, 32, 224, 222, 217, 192, 240, 130, - 25, 109, 16, 133, 91, 242, 159, 15, 63, 37, - 176, 63, 25, 64, 0, 68, 108, 128, 7, 144, - 232, 0, 37, 146, 81, 68, 14, 208, 20, 20, - 163, 72, 167, 216, 128, 14, 85, 201, 66, 205, - 155, 110, 224, 61, 37, 220, 255, 16, 63, 226, - 235, 215, 135, 194, 5, 44, 78, 249, 5, 61, - 86, 251, 65, 5, 36, 208, 23, 15, 52, 177, - 136, 101, 100, 97, 18, 195, 197, 171, 52, 218, - 205, 117, 51, 108, 163, 169, 132, 16, 171, 54, - 118, 174, 142, 69, 48, 75, 248, 224, 22, 162, - 45, 146, 171, 51, 8, 160, 221, 25, 17, 105, - 70, 82, 90, 237, 91, 131, 137, 164, 37, 137, - 80, 73, 238, 221, 11, 86, 93, 9, 95, 242, - 180, 101, 128, 46, 10, 236, 148, 126, 177, 6, - 5, 70, 153, 68, 69, 38, 18, 2, 255, 42, - 34, 104, 34, 160, 74, 106, 9, 99, 8, 245, - 51, 230, 147, 126, 55, 131, 26, 196, 178, 35, - 225, 25, 153, 52, 131, 82, 55, 240, 84, 19, - 107, 60, 234, 11, 0, 12, 16, 1, 16, 148, - 160, 110, 43, 123, 100, 56, 243, 22, 2, 145, - 128, 45, 101, 16, 152, 15, 118, 44, 54, 131, - 100, 218, 239, 73, 111, 58, 66, 13, 120, 0, - 151, 133, 60, 205, 116, 248, 20, 12, 5, 246, - 227, 52, 126, 106, 195, 120, 50, 56, 146, 1, - 46, 247, 1, 126, 86, 141, 156, 79, 132, 192, - 61, 67, 240, 1, 117, 182, 6, 85, 141, 90, - 38, 232, 134, 176, 17, 89, 198, 165, 35, 134, - 17, 70, 14, 92, 32, 63, 134, 141, 224, 117, - 176, 11, 105, 215, 44, 232, 208, 136, 178, 72, - 34, 118, 212, 203, 69, 173, 226, 148, 26, 216, - 133, 7, 255, 39, 80, 192, 4, 102, 42, 191, - 17, 136, 52, 164, 37, 109, 211, 253, 48, 137, - 49, 122, 90, 116, 165, 255, 100, 64, 86, 40, - 74, 128, 22, 0, 224, 6, 48, 152, 128, 2, - 64, 122, 211, 187, 229, 84, 153, 142, 226, 169, - 18, 230, 41, 128, 164, 1, 149, 31, 37, 98, - 166, 93, 134, 192, 129, 133, 49, 181, 169, 36, - 125, 234, 147, 36, 68, 71, 47, 80, 213, 170, - 252, 32, 79, 92, 232, 177, 4, 14, 80, 32, - 103, 77, 229, 218, 83, 177, 51, 214, 6, 73, - 53, 10, 103, 237, 71, 67, 126, 96, 0, 164, - 133, 69, 4, 128, 147, 134, 15, 72, 240, 85, - 174, 229, 236, 176, 175, 203, 105, 93, 223, 116, - 215, 41, 228, 53, 30, 43, 177, 65, 14, 94, - 80, 133, 21, 160, 64, 93, 75, 153, 0, 0, - 158, 224, 130, 19, 60, 224, 110, 57, 99, 216, - 237, 74, 0, 130, 8, 120, 192, 3, 99, 243, - 192, 97, 234, 58, 161, 120, 42, 226, 177, 106, - 9, 26, 37, 57, 167, 131, 23, 8, 207, 39, - 20, 248, 1, 254, 136, 80, 3, 20, 44, 21, - 180, 32, 32, 79, 4, 80, 16, 128, 11, 64, - 64, 4, 34, 80, 65, 7, 94, 80, 38, 214, - 202, 102, 183, 105, 168, 1, 12, 170, 26, 219, - 26, 34, 19, 135, 29, 41, 128, 117, 137, 128, - 3, 9, 252, 214, 176, 15, 24, 64, 15, 56, - 247, 12, 24, 168, 75, 4, 6, 0, 135, 192, - 14, 156, 139, 82, 90, 8, 164, 38, 219, 29, - 2, 79, 150, 194, 0, 24, 44, 97, 7, 22, - 184, 29, 195, 58, 106, 223, 58, 230, 160, 156, - 68, 89, 108, 89, 115, 145, 3, 147, 48, 33, - 131, 50, 89, 0, 3, 4, 16, 95, 33, 220, - 224, 5, 26, 64, 193, 91, 111, 167, 57, 35, - 132, 35, 53, 148, 116, 12, 100, 166, 248, 13, - 143, 241, 163, 59, 34, 16, 192, 15, 120, 208, - 222, 36, 208, 192, 49, 63, 216, 192, 9, 36, - 192, 128, 137, 114, 152, 44, 47, 217, 140, 130, - 9, 114, 25, 28, 76, 148, 9, 162, 2, 128, - 141, 219, 50, 5, 122, 134, 120, 196, 174, 141, - 46, 143, 167, 96, 131, 23, 221, 120, 200, 72, - 214, 74, 16, 0, 0, 59 }; - -unsigned char php_logo[] = { - 71, 73, 70, 56, 57, 97, 120, 0, 67, 0, - 247, 255, 0, 0, 0, 0, 73, 72, 73, 233, - 231, 234, 228, 224, 232, 65, 64, 67, 228, 227, - 230, 80, 78, 86, 61, 60, 64, 215, 213, 223, - 201, 199, 213, 99, 97, 116, 84, 83, 92, 192, - 190, 208, 105, 103, 127, 102, 100, 123, 183, 181, - 203, 216, 215, 225, 143, 141, 174, 89, 88, 104, - 160, 158, 186, 95, 94, 109, 106, 105, 133, 98, - 97, 121, 165, 164, 189, 175, 174, 199, 151, 150, - 196, 145, 144, 178, 161, 160, 194, 152, 151, 183, - 7, 7, 10, 28, 28, 38, 14, 14, 19, 138, - 138, 185, 129, 129, 173, 102, 102, 137, 151, 151, - 202, 146, 146, 195, 145, 145, 194, 130, 130, 174, - 116, 116, 155, 97, 97, 130, 152, 152, 202, 151, - 151, 201, 149, 149, 198, 148, 148, 197, 147, 147, - 196, 145, 145, 193, 142, 142, 189, 140, 140, 186, - 137, 137, 182, 136, 136, 181, 133, 133, 177, 128, - 128, 170, 113, 113, 150, 106, 106, 141, 101, 101, - 134, 90, 90, 120, 3, 3, 4, 127, 127, 168, - 99, 99, 131, 40, 40, 53, 146, 146, 192, 133, - 133, 174, 120, 120, 157, 96, 96, 126, 48, 48, - 63, 131, 131, 171, 101, 101, 130, 100, 100, 127, - 135, 135, 170, 155, 155, 194, 138, 138, 172, 101, - 101, 126, 113, 113, 140, 100, 100, 124, 170, 170, - 199, 222, 222, 239, 217, 217, 234, 206, 206, 220, - 58, 58, 61, 211, 211, 220, 231, 231, 238, 220, - 220, 227, 215, 215, 220, 196, 196, 199, 209, 209, - 211, 183, 183, 185, 253, 253, 254, 102, 103, 143, - 138, 139, 188, 98, 99, 134, 124, 125, 168, 108, - 109, 147, 133, 134, 180, 103, 104, 139, 99, 100, - 134, 122, 123, 163, 144, 145, 188, 149, 150, 193, - 127, 128, 165, 131, 132, 169, 157, 158, 199, 111, - 115, 176, 113, 117, 178, 93, 96, 144, 116, 119, - 178, 127, 131, 192, 118, 121, 178, 107, 110, 162, - 120, 123, 180, 118, 121, 176, 115, 118, 171, 126, - 129, 186, 120, 123, 177, 117, 120, 173, 106, 109, - 155, 75, 77, 109, 113, 115, 163, 127, 130, 182, - 110, 112, 157, 99, 101, 140, 98, 100, 137, 148, - 151, 203, 119, 121, 163, 145, 148, 198, 139, 142, - 189, 148, 151, 199, 55, 56, 74, 152, 155, 203, - 153, 156, 203, 150, 153, 200, 154, 157, 204, 102, - 104, 135, 76, 77, 100, 71, 72, 90, 194, 196, - 227, 211, 212, 236, 207, 208, 231, 217, 218, 239, - 223, 224, 242, 215, 216, 234, 212, 213, 229, 89, - 93, 142, 112, 116, 176, 114, 118, 178, 113, 117, - 177, 114, 118, 177, 116, 120, 179, 115, 120, 178, - 115, 119, 178, 109, 113, 169, 117, 121, 180, 119, - 123, 182, 118, 122, 180, 117, 122, 179, 124, 128, - 188, 123, 127, 187, 122, 126, 185, 120, 124, 182, - 119, 124, 181, 118, 122, 179, 102, 106, 155, 126, - 130, 190, 124, 128, 187, 123, 127, 186, 121, 125, - 183, 120, 124, 181, 119, 123, 180, 81, 84, 122, - 118, 122, 177, 117, 121, 176, 125, 129, 185, 124, - 128, 184, 123, 127, 183, 120, 124, 178, 123, 127, - 181, 127, 131, 186, 96, 99, 141, 127, 131, 185, - 102, 105, 149, 33, 34, 48, 132, 136, 190, 130, - 134, 188, 63, 65, 91, 96, 99, 137, 136, 140, - 192, 141, 145, 196, 146, 150, 200, 149, 153, 202, - 146, 149, 193, 160, 163, 207, 167, 170, 212, 174, - 177, 216, 186, 189, 224, 181, 184, 218, 200, 202, - 231, 192, 194, 222, 203, 205, 233, 199, 201, 227, - 203, 205, 228, 220, 221, 236, 231, 232, 247, 219, - 220, 234, 220, 221, 234, 223, 224, 235, 97, 102, - 150, 222, 223, 233, 226, 227, 237, 20, 21, 28, - 216, 217, 224, 235, 236, 239, 217, 218, 219, 192, - 192, 192, 4, 4, 2, 2, 2, 1, 3, 3, - 2, 7, 7, 6, 21, 21, 19, 13, 13, 12, - 28, 28, 26, 34, 34, 32, 16, 16, 15, 58, - 58, 55, 93, 93, 89, 66, 66, 63, 23, 23, - 22, 85, 85, 82, 88, 88, 85, 60, 60, 58, - 58, 58, 56, 109, 109, 106, 104, 104, 101, 99, - 99, 96, 80, 80, 78, 49, 49, 48, 46, 46, - 45, 52, 52, 51, 152, 152, 150, 144, 144, 142, - 169, 169, 168, 160, 160, 159, 122, 121, 119, 115, - 114, 112, 137, 136, 134, 129, 128, 126, 55, 54, - 53, 31, 30, 30, 62, 61, 61, 176, 176, 176, - 39, 39, 39, 10, 10, 10, 8, 8, 8, 5, - 5, 5, 1, 1, 1, 255, 255, 255, 0, 0, - 0, 33, 249, 4, 1, 0, 0, 212, 0, 44, - 0, 0, 0, 0, 120, 0, 67, 0, 64, 8, - 255, 0, 169, 9, 28, 72, 176, 160, 193, 131, - 8, 19, 42, 92, 200, 176, 161, 195, 135, 16, - 9, 142, 88, 209, 194, 8, 134, 4, 80, 162, - 33, 72, 240, 192, 8, 43, 72, 145, 42, 93, - 202, 116, 170, 164, 201, 147, 39, 51, 93, 90, - 201, 114, 36, 202, 151, 48, 79, 98, 50, 229, - 201, 211, 169, 58, 92, 42, 40, 160, 192, 211, - 193, 15, 24, 44, 84, 164, 136, 152, 48, 5, - 11, 24, 71, 52, 112, 128, 97, 234, 82, 204, - 83, 160, 162, 74, 157, 74, 245, 41, 168, 82, - 78, 212, 1, 216, 186, 181, 27, 20, 88, 105, - 166, 146, 124, 10, 149, 170, 89, 169, 100, 79, - 117, 242, 132, 67, 29, 183, 117, 92, 90, 140, - 64, 168, 226, 197, 157, 59, 117, 210, 158, 188, - 100, 43, 10, 55, 174, 91, 243, 77, 153, 2, - 165, 112, 2, 43, 237, 196, 237, 3, 220, 181, - 10, 162, 119, 140, 1, 152, 171, 66, 165, 50, - 21, 43, 240, 208, 233, 139, 156, 46, 81, 173, - 4, 155, 1, 171, 155, 70, 216, 176, 21, 119, - 1, 172, 69, 222, 54, 37, 215, 164, 152, 152, - 68, 253, 1, 240, 97, 207, 10, 106, 38, 208, - 56, 98, 83, 74, 175, 201, 71, 136, 230, 69, - 182, 242, 43, 210, 75, 51, 193, 220, 69, 86, - 39, 45, 31, 227, 122, 199, 60, 129, 58, 25, - 9, 88, 187, 200, 237, 134, 17, 251, 198, 248, - 154, 149, 93, 105, 142, 27, 255, 19, 206, 56, - 0, 179, 82, 211, 201, 114, 66, 147, 163, 131, - 137, 21, 49, 106, 228, 137, 197, 198, 38, 217, - 74, 130, 160, 132, 142, 204, 31, 64, 191, 124, - 243, 84, 81, 76, 45, 102, 152, 145, 136, 114, - 140, 225, 3, 72, 37, 123, 193, 2, 69, 54, - 140, 173, 195, 204, 47, 248, 244, 103, 225, 53, - 234, 184, 35, 197, 48, 176, 24, 231, 219, 41, - 106, 160, 178, 21, 29, 51, 176, 80, 144, 10, - 46, 152, 80, 131, 22, 121, 224, 130, 197, 27, - 165, 152, 2, 74, 38, 140, 140, 195, 152, 54, - 211, 240, 193, 224, 135, 60, 146, 5, 74, 43, - 77, 120, 195, 88, 54, 209, 212, 226, 84, 143, - 40, 121, 162, 6, 27, 180, 108, 197, 131, 23, - 52, 188, 112, 27, 81, 212, 164, 176, 130, 11, - 49, 208, 112, 130, 13, 59, 160, 240, 133, 22, - 90, 224, 49, 203, 29, 114, 96, 82, 147, 41, - 72, 166, 201, 163, 39, 157, 108, 210, 73, 29, - 56, 24, 194, 14, 55, 219, 108, 195, 195, 45, - 64, 212, 176, 133, 12, 82, 206, 69, 229, 159, - 12, 165, 160, 130, 10, 43, 176, 64, 130, 11, - 47, 192, 0, 66, 12, 50, 204, 224, 168, 9, - 144, 70, 42, 233, 164, 144, 58, 42, 131, 12, - 32, 192, 240, 130, 11, 36, 176, 176, 194, 10, - 42, 248, 9, 232, 168, 163, 166, 48, 2, 161, - 44, 148, 177, 196, 3, 12, 64, 1, 1, 2, - 176, 66, 255, 145, 64, 2, 12, 60, 128, 193, - 18, 27, 24, 193, 65, 24, 97, 192, 192, 104, - 23, 93, 204, 96, 66, 8, 91, 20, 187, 71, - 29, 117, 204, 17, 74, 51, 186, 57, 226, 72, - 44, 177, 228, 33, 2, 23, 39, 108, 49, 195, - 11, 65, 141, 48, 20, 169, 68, 9, 74, 66, - 24, 19, 96, 240, 192, 18, 98, 180, 2, 201, - 145, 106, 162, 148, 70, 46, 2, 108, 195, 88, - 58, 140, 200, 152, 174, 111, 152, 116, 114, 10, - 23, 18, 4, 160, 111, 5, 82, 110, 219, 144, - 81, 50, 128, 49, 6, 13, 109, 140, 245, 84, - 26, 124, 88, 81, 141, 133, 253, 113, 227, 206, - 51, 197, 101, 98, 198, 33, 241, 48, 220, 223, - 58, 239, 32, 147, 75, 37, 146, 248, 98, 133, - 197, 252, 229, 3, 207, 51, 190, 68, 98, 240, - 73, 157, 128, 242, 71, 53, 252, 0, 33, 215, - 64, 46, 212, 129, 70, 40, 233, 249, 150, 73, - 38, 199, 128, 195, 216, 62, 9, 232, 18, 30, - 74, 102, 12, 115, 29, 99, 227, 84, 177, 24, - 96, 241, 32, 226, 161, 73, 102, 32, 130, 32, - 96, 237, 252, 146, 72, 61, 140, 217, 35, 77, - 45, 175, 1, 109, 140, 57, 145, 153, 51, 140, - 25, 100, 153, 82, 74, 147, 127, 188, 32, 3, - 22, 104, 52, 195, 227, 35, 192, 60, 205, 85, - 58, 86, 224, 35, 55, 62, 240, 208, 35, 14, - 132, 145, 137, 131, 12, 35, 1, 84, 255, 125, - 245, 207, 37, 85, 226, 199, 20, 218, 188, 75, - 140, 48, 228, 1, 38, 15, 21, 114, 199, 221, - 78, 60, 233, 20, 222, 117, 50, 112, 100, 29, - 118, 39, 65, 0, 192, 195, 12, 2, 173, 0, - 3, 24, 55, 180, 88, 31, 76, 151, 56, 136, - 55, 87, 219, 64, 49, 202, 36, 55, 183, 174, - 87, 235, 176, 147, 5, 251, 205, 147, 216, 146, - 64, 55, 140, 129, 243, 76, 43, 172, 199, 158, - 174, 41, 33, 246, 163, 249, 15, 49, 176, 224, - 239, 65, 35, 176, 240, 130, 9, 39, 220, 128, - 66, 139, 120, 204, 161, 10, 38, 152, 160, 53, - 239, 245, 37, 157, 149, 102, 41, 155, 168, 66, - 135, 7, 91, 65, 99, 72, 13, 58, 128, 240, - 50, 183, 7, 9, 186, 2, 9, 102, 135, 0, - 198, 150, 206, 3, 129, 194, 16, 244, 15, 65, - 4, 253, 132, 120, 97, 3, 23, 92, 220, 133, - 236, 27, 114, 144, 131, 27, 82, 65, 64, 2, - 186, 193, 13, 114, 120, 3, 178, 238, 192, 5, - 27, 16, 130, 8, 22, 160, 128, 4, 22, 96, - 128, 116, 232, 235, 130, 134, 144, 0, 14, 108, - 80, 131, 61, 208, 160, 11, 48, 40, 1, 168, - 142, 135, 190, 18, 166, 239, 84, 159, 42, 148, - 24, 140, 192, 194, 13, 108, 96, 2, 48, 156, - 0, 7, 102, 168, 129, 8, 28, 161, 8, 100, - 208, 193, 22, 192, 176, 135, 30, 110, 33, 4, - 93, 200, 130, 11, 255, 90, 224, 169, 65, 145, - 208, 132, 72, 28, 136, 169, 40, 98, 145, 4, - 72, 97, 0, 2, 16, 192, 0, 164, 64, 140, - 37, 244, 66, 22, 166, 200, 68, 26, 206, 0, - 137, 73, 204, 232, 102, 243, 50, 133, 216, 74, - 17, 163, 76, 172, 65, 129, 92, 240, 194, 13, - 144, 160, 4, 37, 56, 160, 1, 53, 240, 129, - 8, 133, 146, 196, 133, 36, 175, 7, 27, 96, - 21, 173, 48, 208, 135, 83, 72, 34, 13, 39, - 67, 146, 36, 132, 33, 141, 66, 26, 82, 26, - 141, 144, 23, 246, 76, 98, 166, 82, 120, 226, - 13, 54, 160, 192, 2, 40, 168, 0, 33, 4, - 165, 132, 42, 32, 129, 82, 38, 112, 1, 14, - 188, 130, 117, 139, 60, 78, 48, 134, 6, 152, - 119, 4, 3, 108, 161, 212, 139, 41, 236, 133, - 2, 2, 212, 131, 29, 18, 120, 1, 29, 27, - 50, 130, 22, 116, 129, 12, 71, 56, 194, 43, - 2, 153, 146, 52, 8, 227, 25, 203, 8, 166, - 48, 135, 25, 76, 100, 52, 33, 17, 198, 248, - 133, 45, 206, 64, 9, 147, 84, 98, 16, 86, - 16, 30, 96, 204, 113, 5, 101, 12, 115, 111, - 137, 56, 132, 47, 86, 241, 136, 35, 101, 2, - 20, 196, 96, 6, 49, 199, 185, 12, 99, 34, - 243, 23, 29, 106, 38, 76, 56, 33, 135, 63, - 100, 35, 27, 116, 32, 129, 10, 14, 130, 162, - 61, 156, 96, 15, 113, 192, 132, 111, 30, 49, - 255, 12, 174, 129, 172, 63, 249, 200, 81, 39, - 30, 244, 207, 254, 224, 195, 23, 102, 32, 134, - 141, 10, 26, 153, 117, 20, 192, 15, 146, 136, - 9, 41, 222, 0, 13, 0, 120, 64, 6, 243, - 164, 134, 10, 96, 16, 138, 89, 176, 65, 159, - 31, 98, 27, 60, 176, 83, 12, 51, 180, 36, - 13, 102, 192, 196, 34, 184, 195, 152, 115, 248, - 99, 161, 92, 9, 7, 4, 224, 240, 199, 52, - 216, 212, 12, 20, 138, 204, 55, 140, 113, 8, - 82, 114, 5, 30, 192, 48, 41, 75, 80, 10, - 139, 40, 220, 35, 50, 241, 248, 26, 89, 68, - 113, 11, 218, 188, 71, 6, 186, 25, 221, 135, - 42, 1, 8, 42, 240, 131, 49, 226, 48, 6, - 36, 94, 2, 10, 76, 52, 65, 28, 145, 169, - 27, 99, 172, 97, 5, 95, 68, 212, 36, 151, - 88, 133, 50, 254, 2, 152, 117, 52, 194, 23, - 35, 101, 140, 57, 142, 241, 136, 151, 164, 245, - 25, 84, 99, 12, 80, 151, 22, 19, 81, 208, - 129, 54, 93, 48, 65, 44, 118, 211, 27, 223, - 92, 2, 14, 82, 176, 71, 132, 158, 193, 138, - 154, 74, 194, 12, 144, 216, 69, 50, 228, 17, - 153, 110, 20, 224, 99, 140, 105, 135, 48, 234, - 106, 146, 174, 50, 34, 29, 59, 163, 130, 47, - 10, 112, 186, 173, 4, 128, 17, 151, 168, 132, - 77, 35, 97, 6, 170, 74, 3, 29, 171, 145, - 130, 46, 118, 68, 150, 77, 255, 136, 72, 27, - 38, 120, 1, 24, 160, 37, 85, 31, 97, 226, - 179, 12, 141, 76, 0, 164, 225, 139, 92, 36, - 224, 104, 92, 57, 71, 34, 182, 122, 146, 137, - 209, 35, 50, 248, 0, 6, 49, 156, 19, 92, - 192, 140, 131, 184, 168, 212, 139, 40, 68, 132, - 13, 47, 192, 128, 26, 240, 57, 1, 46, 112, - 49, 139, 83, 128, 20, 38, 19, 171, 24, 99, - 222, 145, 140, 99, 36, 226, 189, 239, 61, 198, - 33, 132, 193, 139, 85, 68, 130, 185, 167, 168, - 68, 25, 224, 11, 223, 70, 0, 195, 37, 157, - 53, 133, 48, 248, 11, 95, 93, 20, 131, 178, - 128, 225, 7, 21, 22, 225, 94, 254, 202, 87, - 24, 187, 96, 69, 72, 122, 228, 9, 81, 100, - 142, 31, 56, 152, 65, 11, 252, 53, 2, 18, - 204, 224, 4, 44, 194, 5, 27, 196, 120, 146, - 71, 8, 163, 66, 140, 137, 199, 33, 178, 155, - 74, 189, 152, 248, 185, 140, 153, 199, 138, 67, - 89, 138, 237, 94, 21, 26, 55, 48, 129, 11, - 50, 74, 151, 18, 116, 225, 7, 34, 8, 241, - 44, 222, 128, 137, 112, 18, 243, 25, 194, 0, - 100, 139, 125, 115, 21, 99, 136, 115, 152, 81, - 0, 6, 109, 145, 84, 99, 75, 100, 14, 0, - 250, 48, 196, 9, 174, 197, 99, 136, 36, 239, - 5, 51, 248, 129, 13, 80, 192, 162, 60, 68, - 175, 76, 158, 64, 211, 146, 215, 140, 18, 76, - 112, 175, 255, 20, 108, 40, 68, 62, 186, 161, - 13, 125, 240, 0, 8, 39, 8, 1, 12, 90, - 208, 101, 19, 78, 132, 4, 48, 152, 193, 22, - 182, 212, 165, 29, 124, 97, 7, 134, 158, 214, - 29, 222, 144, 138, 83, 212, 164, 38, 212, 59, - 239, 245, 168, 247, 9, 154, 116, 162, 19, 189, - 113, 195, 29, 242, 144, 175, 3, 212, 67, 29, - 160, 126, 66, 33, 110, 80, 3, 48, 152, 0, - 6, 46, 0, 85, 29, 187, 133, 42, 68, 129, - 96, 6, 52, 120, 95, 13, 210, 248, 5, 20, - 0, 225, 214, 22, 200, 181, 174, 21, 192, 235, - 94, 243, 228, 215, 18, 148, 128, 176, 135, 45, - 108, 28, 0, 65, 4, 28, 188, 167, 14, 102, - 16, 131, 77, 181, 96, 132, 171, 142, 182, 180, - 167, 77, 237, 36, 166, 192, 84, 131, 74, 33, - 11, 182, 189, 237, 22, 120, 155, 136, 220, 246, - 212, 167, 6, 165, 173, 35, 86, 251, 220, 216, - 46, 84, 6, 54, 176, 4, 113, 177, 138, 1, - 240, 174, 149, 173, 110, 117, 129, 11, 200, 144, - 3, 53, 188, 225, 24, 120, 120, 130, 59, 204, - 97, 22, 205, 96, 86, 51, 102, 49, 135, 59, - 236, 33, 183, 69, 212, 214, 185, 185, 181, 196, - 21, 168, 170, 85, 79, 44, 64, 1, 164, 176, - 17, 6, 96, 96, 3, 98, 200, 130, 29, 94, - 97, 138, 130, 177, 100, 18, 147, 104, 73, 235, - 34, 125, 94, 80, 172, 65, 18, 150, 255, 96, - 67, 40, 58, 138, 135, 60, 104, 97, 7, 55, - 24, 66, 5, 74, 61, 131, 84, 207, 114, 225, - 69, 81, 1, 11, 50, 128, 1, 136, 15, 96, - 0, 16, 16, 134, 47, 92, 96, 7, 77, 132, - 68, 19, 51, 98, 115, 155, 103, 226, 72, 80, - 200, 161, 14, 53, 168, 128, 3, 122, 237, 128, - 36, 8, 225, 217, 162, 58, 119, 242, 196, 144, - 199, 4, 56, 193, 9, 12, 88, 66, 31, 76, - 1, 9, 73, 160, 139, 71, 55, 179, 69, 45, - 214, 206, 246, 82, 240, 82, 77, 141, 196, 132, - 28, 184, 48, 132, 96, 75, 160, 2, 150, 188, - 57, 18, 173, 212, 3, 139, 176, 170, 35, 178, - 152, 132, 146, 175, 167, 137, 86, 48, 35, 29, - 217, 168, 211, 54, 194, 81, 15, 41, 192, 226, - 236, 169, 108, 228, 220, 41, 80, 65, 3, 40, - 160, 68, 89, 7, 84, 242, 194, 192, 129, 11, - 44, 225, 2, 97, 48, 69, 200, 151, 220, 49, - 42, 228, 128, 49, 244, 64, 4, 103, 149, 110, - 146, 85, 154, 130, 11, 11, 32, 192, 61, 2, - 80, 131, 243, 69, 196, 74, 47, 136, 0, 7, - 100, 216, 5, 0, 179, 249, 17, 135, 128, 45, - 96, 170, 65, 133, 65, 76, 153, 245, 39, 241, - 4, 41, 234, 80, 136, 117, 172, 227, 0, 96, - 48, 158, 67, 146, 23, 131, 35, 68, 64, 3, - 118, 240, 61, 74, 84, 194, 138, 238, 123, 255, - 251, 223, 47, 197, 255, 37, 204, 96, 118, 148, - 92, 162, 22, 85, 144, 28, 87, 200, 145, 136, - 81, 180, 194, 251, 173, 240, 68, 37, 200, 95, - 179, 146, 104, 17, 252, 248, 247, 126, 41, 38, - 65, 126, 200, 155, 196, 19, 155, 16, 10, 127, - 176, 13, 246, 128, 3, 242, 164, 16, 70, 49, - 3, 99, 64, 6, 62, 144, 69, 100, 113, 88, - 82, 16, 0, 245, 80, 14, 20, 88, 129, 22, - 88, 14, 228, 0, 14, 227, 32, 15, 240, 32, - 5, 136, 144, 11, 156, 85, 29, 62, 181, 21, - 219, 64, 14, 23, 8, 14, 1, 240, 13, 241, - 128, 15, 204, 80, 12, 112, 96, 28, 235, 82, - 0, 224, 48, 129, 23, 104, 129, 222, 48, 123, - 227, 16, 15, 239, 240, 12, 137, 144, 11, 44, - 134, 50, 167, 240, 7, 117, 22, 79, 153, 215, - 57, 48, 176, 7, 96, 176, 5, 174, 32, 105, - 49, 97, 98, 110, 19, 92, 235, 80, 5, 193, - 208, 77, 57, 83, 93, 92, 17, 15, 76, 128, - 9, 200, 145, 56, 213, 117, 15, 5, 0, 12, - 171, 135, 18, 157, 160, 10, 60, 64, 27, 39, - 32, 125, 2, 145, 2, 45, 64, 3, 119, 112, - 2, 101, 194, 100, 165, 160, 12, 125, 3, 24, - 253, 160, 15, 218, 112, 135, 117, 118, 13, 22, - 242, 13, 77, 192, 11, 86, 53, 86, 252, 16, - 136, 129, 168, 135, 253, 97, 14, 198, 112, 9, - 78, 192, 86, 128, 129, 135, 119, 168, 15, 132, - 255, 200, 31, 244, 160, 8, 131, 247, 18, 155, - 224, 8, 167, 87, 8, 37, 48, 23, 41, 64, - 2, 123, 64, 112, 111, 232, 27, 149, 16, 8, - 70, 211, 82, 76, 160, 118, 108, 199, 7, 194, - 176, 8, 240, 112, 122, 140, 225, 14, 254, 192, - 133, 0, 64, 86, 191, 160, 11, 124, 80, 139, - 187, 240, 11, 201, 0, 139, 0, 208, 25, 57, - 197, 24, 242, 48, 12, 112, 192, 118, 181, 224, - 7, 193, 176, 8, 79, 184, 21, 64, 21, 134, - 40, 65, 10, 108, 80, 56, 127, 224, 2, 201, - 19, 2, 1, 247, 6, 106, 230, 27, 19, 131, - 96, 128, 17, 93, 202, 120, 10, 102, 80, 12, - 199, 152, 14, 87, 160, 136, 166, 213, 4, 232, - 209, 92, 194, 0, 25, 41, 22, 12, 199, 112, - 14, 59, 83, 5, 129, 112, 86, 37, 54, 12, - 236, 40, 87, 195, 176, 141, 40, 195, 6, 29, - 0, 0, 6, 8, 3, 204, 18, 10, 61, 194, - 23, 80, 128, 59, 128, 97, 15, 141, 192, 10, - 245, 87, 18, 192, 1, 99, 72, 19, 87, 128, - 1, 15, 196, 192, 98, 51, 210, 4, 48, 181, - 21, 250, 64, 5, 122, 144, 0, 234, 103, 90, - 202, 80, 142, 41, 49, 9, 137, 48, 145, 91, - 65, 15, 51, 182, 84, 179, 225, 1, 175, 22, - 85, 133, 101, 141, 193, 128, 142, 128, 49, 15, - 15, 105, 87, 181, 0, 5, 225, 192, 24, 216, - 80, 5, 96, 181, 136, 80, 255, 96, 36, 39, - 145, 6, 186, 64, 5, 216, 192, 24, 232, 144, - 8, 194, 160, 94, 128, 225, 14, 155, 245, 18, - 146, 224, 7, 211, 32, 144, 92, 161, 15, 85, - 224, 51, 105, 49, 10, 142, 0, 0, 29, 32, - 44, 40, 249, 33, 93, 245, 85, 140, 209, 13, - 82, 64, 2, 199, 247, 8, 186, 16, 5, 121, - 165, 56, 2, 176, 31, 91, 113, 14, 135, 160, - 140, 215, 8, 93, 194, 208, 8, 99, 185, 21, - 50, 245, 120, 64, 3, 8, 83, 224, 46, 122, - 85, 12, 246, 136, 18, 82, 217, 15, 238, 49, - 3, 177, 48, 51, 213, 152, 22, 60, 249, 135, - 128, 33, 14, 139, 176, 11, 136, 201, 11, 191, - 64, 12, 136, 0, 5, 194, 215, 138, 254, 64, - 148, 91, 161, 96, 102, 213, 32, 81, 64, 93, - 168, 227, 4, 191, 96, 5, 170, 1, 24, 244, - 176, 8, 186, 128, 152, 128, 240, 11, 135, 192, - 8, 85, 0, 90, 145, 241, 14, 105, 233, 27, - 106, 208, 84, 208, 48, 3, 32, 80, 3, 127, - 41, 7, 129, 249, 20, 143, 96, 12, 216, 200, - 21, 253, 176, 155, 188, 201, 48, 247, 32, 0, - 190, 224, 4, 118, 201, 21, 224, 192, 12, 173, - 80, 127, 213, 193, 146, 92, 65, 15, 193, 32, - 12, 44, 69, 135, 254, 209, 155, 22, 34, 14, - 81, 64, 2, 124, 245, 20, 165, 32, 7, 21, - 117, 11, 50, 64, 2, 38, 128, 5, 208, 162, - 10, 181, 255, 105, 87, 125, 129, 153, 193, 213, - 13, 243, 192, 12, 190, 96, 9, 192, 128, 98, - 45, 121, 74, 40, 49, 9, 198, 48, 135, 92, - 129, 35, 190, 128, 145, 86, 8, 0, 217, 208, - 14, 201, 32, 8, 63, 248, 20, 210, 1, 62, - 30, 160, 3, 208, 232, 2, 58, 32, 2, 208, - 242, 6, 246, 17, 19, 201, 185, 28, 223, 48, - 14, 16, 26, 161, 231, 32, 15, 243, 96, 5, - 206, 128, 8, 131, 240, 8, 225, 81, 9, 136, - 0, 15, 233, 16, 161, 226, 128, 14, 209, 32, - 151, 38, 177, 46, 82, 240, 13, 226, 16, 161, - 233, 48, 15, 199, 48, 74, 145, 81, 15, 15, - 26, 161, 16, 122, 14, 241, 224, 14, 84, 192, - 12, 136, 224, 7, 143, 96, 57, 122, 209, 9, - 150, 80, 81, 180, 0, 6, 178, 68, 13, 35, - 144, 34, 54, 48, 94, 115, 96, 10, 76, 104, - 127, 151, 48, 159, 52, 73, 5, 124, 176, 163, - 32, 7, 114, 103, 96, 6, 143, 32, 18, 47, - 81, 9, 149, 48, 165, 83, 10, 143, 41, 33, - 9, 92, 10, 114, 146, 144, 9, 141, 64, 14, - 140, 177, 13, 210, 144, 11, 145, 16, 166, 85, - 170, 161, 7, 169, 23, 152, 176, 9, 127, 5, - 0, 183, 176, 5, 67, 154, 134, 44, 32, 3, - 63, 240, 5, 162, 179, 160, 206, 180, 11, 62, - 89, 30, 198, 0, 74, 200, 247, 18, 148, 192, - 11, 202, 121, 150, 136, 80, 9, 111, 255, 151, - 38, 166, 176, 93, 249, 232, 1, 92, 48, 3, - 36, 80, 132, 40, 162, 34, 33, 54, 7, 160, - 176, 160, 6, 114, 140, 239, 0, 12, 215, 89, - 168, 37, 17, 9, 198, 240, 152, 92, 113, 80, - 94, 154, 46, 164, 80, 10, 183, 32, 60, 56, - 22, 37, 125, 118, 34, 46, 240, 97, 124, 106, - 102, 121, 145, 9, 172, 224, 12, 223, 192, 14, - 21, 200, 14, 227, 16, 5, 36, 42, 170, 38, - 49, 9, 181, 32, 13, 233, 64, 131, 229, 192, - 14, 231, 176, 145, 111, 202, 35, 164, 208, 9, - 168, 240, 1, 0, 144, 3, 65, 192, 5, 185, - 181, 2, 230, 102, 16, 29, 22, 3, 96, 192, - 5, 207, 131, 11, 209, 163, 10, 112, 0, 126, - 173, 160, 125, 194, 154, 61, 151, 128, 127, 229, - 170, 38, 220, 163, 10, 183, 32, 173, 0, 64, - 11, 64, 240, 3, 50, 80, 2, 177, 26, 40, - 40, 18, 48, 92, 176, 3, 101, 134, 5, 119, - 160, 10, 53, 113, 174, 172, 87, 47, 155, 96, - 9, 168, 64, 11, 216, 80, 135, 65, 112, 3, - 123, 112, 45, 216, 74, 42, 222, 2, 3, 33, - 112, 2, 94, 64, 102, 46, 39, 38, 117, 48, - 61, 1, 43, 176, 105, 226, 102, 156, 80, 10, - 111, 128, 3, 127, 144, 15, 225, 144, 13, 225, - 16, 4, 56, 64, 62, 49, 144, 106, 217, 58, - 42, 19, 225, 2, 32, 96, 2, 63, 192, 5, - 181, 102, 104, 96, 255, 146, 7, 99, 242, 6, - 170, 240, 9, 142, 180, 164, 133, 74, 61, 98, - 243, 177, 111, 48, 7, 40, 80, 8, 79, 176, - 14, 249, 144, 180, 65, 80, 8, 54, 240, 3, - 52, 208, 108, 151, 132, 110, 42, 208, 2, 47, - 16, 3, 38, 0, 6, 53, 224, 5, 93, 130, - 2, 48, 135, 104, 55, 160, 63, 253, 83, 7, - 140, 86, 18, 102, 242, 104, 143, 246, 9, 36, - 151, 182, 143, 86, 10, 151, 182, 22, 213, 163, - 10, 56, 113, 3, 22, 32, 1, 6, 16, 0, - 4, 112, 0, 7, 240, 4, 7, 96, 8, 133, - 0, 4, 92, 224, 180, 124, 66, 2, 43, 80, - 132, 56, 151, 134, 132, 194, 62, 175, 166, 3, - 246, 196, 5, 34, 96, 107, 183, 70, 4, 68, - 128, 4, 146, 219, 70, 148, 91, 185, 14, 224, - 0, 72, 112, 185, 83, 199, 107, 191, 54, 108, - 147, 52, 73, 6, 16, 186, 161, 91, 8, 18, - 0, 4, 28, 244, 3, 91, 96, 2, 205, 86, - 2, 65, 209, 178, 133, 171, 16, 40, 196, 2, - 37, 144, 40, 141, 98, 2, 58, 0, 6, 63, - 112, 2, 179, 214, 64, 94, 224, 5, 34, 240, - 187, 192, 27, 188, 193, 219, 187, 54, 176, 63, - 53, 80, 3, 63, 176, 7, 58, 96, 2, 51, - 128, 41, 155, 146, 112, 174, 251, 186, 16, 43, - 40, 132, 242, 41, 225, 246, 109, 216, 155, 189, - 222, 22, 110, 41, 68, 110, 209, 187, 106, 1, - 1, 1, 0, 59 }; - -unsigned char php_egg_logo[] = { - 71, 73, 70, 56, 57, 97, 120, 0, 67, 0, - 247, 255, 0, 0, 0, 0, 177, 156, 157, 205, - 169, 172, 148, 134, 135, 134, 109, 112, 169, 155, - 157, 182, 169, 171, 165, 153, 155, 119, 79, 87, - 167, 152, 155, 167, 157, 159, 195, 159, 167, 170, - 156, 161, 160, 150, 154, 153, 129, 143, 118, 109, - 115, 3, 1, 3, 74, 60, 74, 6, 5, 6, - 183, 173, 184, 101, 93, 102, 148, 142, 150, 5, - 3, 6, 9, 7, 10, 83, 74, 88, 168, 159, - 174, 156, 150, 166, 222, 219, 229, 172, 166, 187, - 215, 212, 225, 206, 203, 220, 123, 120, 139, 134, - 132, 155, 195, 193, 216, 182, 181, 209, 187, 186, - 214, 174, 173, 208, 1, 1, 3, 3, 3, 5, - 11, 11, 16, 14, 14, 20, 7, 7, 10, 34, - 34, 48, 22, 22, 31, 28, 28, 39, 85, 85, - 115, 153, 153, 205, 153, 153, 203, 9, 9, 12, - 156, 156, 205, 160, 160, 206, 170, 170, 206, 177, - 177, 208, 142, 144, 195, 149, 150, 202, 150, 151, - 199, 157, 158, 202, 161, 162, 201, 165, 166, 204, - 80, 82, 122, 75, 77, 112, 112, 115, 165, 97, - 99, 143, 91, 93, 134, 69, 71, 102, 105, 107, - 154, 41, 42, 60, 127, 130, 185, 86, 88, 125, - 51, 52, 74, 136, 139, 192, 133, 135, 184, 146, - 148, 197, 153, 155, 199, 155, 157, 200, 119, 123, - 178, 61, 63, 90, 16, 17, 24, 192, 192, 192, - 132, 89, 62, 139, 94, 66, 143, 105, 82, 222, - 180, 157, 132, 77, 50, 113, 74, 54, 115, 87, - 73, 125, 66, 39, 126, 83, 64, 122, 82, 63, - 102, 71, 57, 113, 85, 72, 197, 160, 142, 204, - 168, 152, 89, 54, 39, 93, 57, 42, 82, 50, - 37, 121, 75, 56, 95, 60, 45, 105, 68, 53, - 89, 58, 45, 97, 67, 55, 113, 79, 65, 104, - 73, 60, 99, 70, 58, 111, 81, 69, 118, 88, - 75, 115, 85, 73, 115, 87, 75, 116, 90, 79, - 181, 143, 127, 207, 174, 160, 94, 51, 35, 78, - 45, 33, 105, 62, 47, 98, 62, 48, 100, 65, - 52, 107, 71, 58, 108, 74, 62, 216, 182, 170, - 210, 177, 165, 227, 193, 180, 219, 188, 177, 118, - 60, 40, 106, 56, 39, 111, 62, 45, 68, 39, - 29, 55, 34, 27, 83, 53, 43, 71, 45, 37, - 94, 64, 54, 10, 7, 6, 93, 67, 59, 116, - 85, 75, 149, 110, 97, 12, 9, 8, 111, 84, - 75, 102, 66, 56, 101, 69, 60, 103, 71, 62, - 93, 65, 57, 95, 67, 59, 99, 70, 62, 91, - 65, 58, 117, 88, 80, 118, 93, 86, 183, 150, - 140, 188, 158, 149, 236, 203, 194, 198, 171, 163, - 190, 164, 157, 41, 26, 22, 91, 61, 53, 98, - 66, 58, 95, 65, 57, 84, 59, 53, 114, 82, - 74, 109, 81, 74, 102, 79, 73, 158, 127, 119, - 123, 100, 94, 163, 133, 126, 194, 167, 160, 204, - 179, 173, 171, 159, 156, 95, 65, 59, 71, 49, - 44, 97, 67, 61, 93, 65, 59, 76, 54, 49, - 126, 91, 83, 19, 14, 13, 112, 86, 80, 87, - 69, 65, 133, 107, 101, 144, 119, 114, 137, 114, - 109, 177, 150, 144, 164, 139, 134, 181, 155, 149, - 209, 183, 177, 200, 176, 171, 223, 197, 191, 211, - 187, 182, 167, 157, 155, 165, 155, 153, 32, 20, - 18, 82, 55, 50, 90, 63, 58, 119, 83, 77, - 94, 66, 61, 60, 43, 40, 95, 74, 70, 171, - 145, 140, 247, 212, 206, 235, 209, 204, 167, 155, - 153, 255, 244, 242, 86, 61, 57, 247, 220, 216, - 155, 142, 140, 170, 157, 155, 149, 124, 121, 187, - 160, 157, 172, 149, 146, 216, 192, 189, 147, 131, - 129, 147, 138, 137, 91, 65, 63, 46, 33, 32, - 155, 132, 130, 157, 137, 135, 181, 159, 157, 224, - 202, 200, 132, 121, 120, 248, 228, 226, 165, 152, - 151, 140, 130, 129, 156, 145, 144, 162, 151, 150, - 151, 141, 140, 186, 176, 175, 103, 85, 84, 174, - 156, 155, 163, 147, 146, 176, 151, 150, 166, 143, - 142, 188, 165, 164, 194, 171, 170, 198, 177, 176, - 210, 189, 188, 229, 207, 206, 236, 215, 214, 22, - 17, 17, 176, 153, 153, 203, 181, 181, 174, 159, - 159, 168, 153, 153, 169, 155, 155, 171, 157, 157, - 191, 177, 177, 176, 163, 163, 169, 157, 157, 167, - 155, 155, 165, 153, 153, 171, 159, 159, 158, 148, - 148, 169, 159, 159, 165, 155, 155, 163, 153, 153, - 161, 153, 153, 3, 3, 3, 1, 1, 1, 255, - 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 33, 249, 4, 1, 0, 0, 78, 0, 44, - 0, 0, 0, 0, 120, 0, 67, 0, 64, 8, - 255, 0, 157, 8, 28, 72, 176, 160, 193, 131, - 8, 19, 42, 92, 200, 176, 161, 195, 135, 16, - 9, 186, 112, 177, 164, 133, 144, 20, 48, 78, - 160, 64, 209, 100, 197, 10, 22, 44, 84, 64, - 243, 229, 171, 20, 170, 82, 38, 53, 53, 130, - 180, 173, 94, 182, 1, 216, 176, 57, 203, 182, - 141, 102, 180, 100, 174, 114, 186, 218, 118, 108, - 219, 54, 103, 206, 154, 37, 147, 38, 205, 83, - 178, 106, 213, 30, 40, 85, 234, 35, 72, 143, - 37, 80, 163, 70, 29, 98, 4, 201, 68, 23, - 17, 19, 78, 252, 193, 2, 128, 87, 0, 130, - 114, 149, 68, 117, 9, 211, 25, 50, 166, 26, - 169, 29, 116, 234, 212, 32, 76, 138, 234, 208, - 17, 51, 71, 140, 24, 58, 117, 204, 32, 42, - 3, 233, 27, 55, 122, 217, 142, 101, 203, 118, - 11, 215, 60, 109, 223, 200, 217, 42, 103, 142, - 153, 55, 109, 218, 188, 81, 35, 102, 141, 90, - 57, 101, 201, 142, 221, 26, 134, 172, 29, 50, - 119, 237, 66, 15, 19, 141, 203, 240, 129, 210, - 134, 33, 107, 171, 183, 13, 91, 181, 15, 75, - 140, 200, 150, 109, 21, 235, 65, 23, 71, 84, - 124, 69, 87, 82, 211, 174, 94, 167, 122, 177, - 117, 107, 74, 145, 153, 185, 115, 146, 7, 202, - 132, 41, 19, 25, 51, 104, 228, 120, 153, 62, - 134, 250, 152, 49, 156, 164, 113, 91, 39, 205, - 85, 44, 74, 121, 236, 216, 255, 185, 227, 166, - 252, 150, 72, 231, 183, 216, 169, 197, 158, 82, - 44, 88, 162, 68, 77, 187, 229, 142, 158, 253, - 251, 244, 220, 233, 119, 135, 172, 127, 231, 97, - 240, 192, 3, 26, 59, 184, 92, 115, 13, 62, - 249, 36, 168, 32, 100, 245, 56, 3, 194, 13, - 72, 68, 248, 2, 86, 46, 148, 240, 149, 47, - 168, 236, 210, 72, 34, 136, 32, 50, 7, 25, - 129, 44, 34, 98, 38, 153, 244, 178, 200, 37, - 151, 236, 130, 162, 138, 127, 124, 1, 7, 32, - 128, 244, 97, 73, 46, 52, 230, 98, 137, 31, - 125, 0, 114, 73, 35, 191, 60, 82, 8, 40, - 177, 172, 195, 205, 59, 234, 148, 67, 141, 57, - 212, 28, 73, 13, 37, 161, 76, 70, 12, 51, - 145, 180, 17, 73, 37, 148, 208, 66, 78, 37, - 110, 228, 33, 201, 43, 159, 180, 66, 64, 53, - 205, 28, 115, 205, 48, 244, 172, 99, 102, 126, - 241, 32, 168, 224, 154, 108, 174, 169, 77, 54, - 57, 228, 128, 3, 14, 87, 229, 246, 85, 46, - 168, 20, 179, 203, 41, 142, 56, 178, 139, 138, - 41, 234, 185, 75, 159, 142, 160, 168, 137, 46, - 46, 194, 161, 168, 162, 95, 52, 242, 9, 27, - 99, 244, 225, 7, 32, 186, 112, 146, 204, 50, - 202, 136, 35, 78, 56, 201, 180, 210, 202, 43, - 159, 70, 3, 76, 44, 192, 68, 19, 77, 56, - 227, 216, 66, 11, 45, 204, 48, 99, 11, 53, - 181, 168, 255, 51, 142, 56, 202, 216, 145, 199, - 29, 177, 180, 162, 198, 38, 155, 160, 225, 171, - 175, 106, 4, 171, 134, 22, 196, 22, 107, 108, - 21, 105, 176, 193, 6, 36, 173, 184, 146, 1, - 13, 52, 144, 48, 67, 12, 19, 21, 116, 149, - 11, 92, 73, 144, 130, 70, 43, 248, 162, 73, - 32, 152, 32, 114, 87, 28, 111, 132, 241, 72, - 42, 96, 232, 161, 238, 186, 234, 242, 225, 110, - 24, 127, 232, 162, 231, 42, 175, 184, 18, 77, - 58, 182, 24, 99, 141, 40, 146, 84, 178, 76, - 52, 177, 132, 179, 204, 52, 227, 88, 41, 142, - 58, 204, 144, 163, 169, 56, 149, 204, 210, 42, - 123, 179, 132, 71, 137, 39, 88, 80, 97, 49, - 21, 117, 148, 161, 49, 26, 85, 84, 97, 172, - 177, 205, 76, 224, 193, 200, 30, 132, 48, 195, - 181, 89, 9, 116, 109, 157, 62, 0, 81, 196, - 203, 76, 196, 204, 4, 16, 52, 99, 16, 193, - 51, 113, 88, 49, 133, 206, 86, 232, 241, 134, - 28, 127, 168, 98, 73, 41, 159, 128, 2, 75, - 191, 253, 82, 162, 76, 40, 149, 244, 27, 138, - 40, 118, 48, 89, 229, 44, 179, 208, 66, 235, - 52, 203, 120, 18, 5, 20, 133, 120, 2, 140, - 1, 35, 144, 236, 65, 7, 100, 111, 176, 129, - 7, 35, 232, 176, 114, 181, 41, 183, 205, 208, - 218, 112, 199, 45, 247, 220, 107, 187, 109, 247, - 221, 78, 92, 107, 68, 16, 68, 184, 255, 172, - 194, 223, 66, 4, 254, 242, 224, 50, 199, 76, - 51, 205, 60, 36, 206, 195, 14, 59, 16, 225, - 248, 15, 144, 255, 224, 195, 228, 148, 55, 229, - 212, 18, 84, 217, 128, 50, 222, 17, 77, 116, - 4, 16, 77, 120, 181, 143, 62, 22, 92, 128, - 142, 37, 36, 153, 164, 139, 38, 197, 44, 114, - 70, 94, 89, 40, 66, 71, 25, 117, 100, 113, - 198, 28, 89, 96, 17, 133, 43, 246, 208, 211, - 83, 54, 165, 93, 131, 152, 58, 230, 156, 51, - 139, 44, 223, 8, 47, 252, 52, 204, 192, 90, - 139, 40, 210, 124, 51, 204, 60, 243, 224, 194, - 206, 245, 6, 30, 184, 26, 77, 206, 184, 246, - 90, 15, 67, 132, 47, 254, 17, 53, 104, 110, - 91, 67, 91, 161, 240, 149, 33, 168, 163, 194, - 250, 158, 167, 48, 146, 8, 236, 89, 32, 98, - 134, 34, 152, 144, 66, 74, 38, 243, 203, 17, - 134, 28, 0, 12, 131, 23, 252, 39, 135, 58, - 188, 130, 27, 127, 105, 70, 43, 32, 209, 137, - 95, 116, 131, 0, 201, 136, 6, 40, 218, 192, - 5, 41, 72, 193, 13, 118, 192, 131, 6, 241, - 240, 42, 106, 144, 3, 28, 236, 216, 207, 125, - 244, 227, 159, 208, 20, 102, 24, 195, 144, 71, - 1, 218, 177, 153, 234, 29, 96, 30, 248, 192, - 135, 54, 26, 224, 146, 1, 124, 128, 124, 53, - 200, 161, 249, 6, 226, 2, 30, 124, 69, 21, - 24, 218, 5, 41, 255, 24, 209, 139, 33, 50, - 130, 20, 110, 89, 4, 255, 200, 240, 63, 57, - 4, 226, 137, 39, 186, 206, 24, 200, 224, 5, - 69, 245, 161, 15, 46, 186, 226, 23, 90, 241, - 141, 111, 28, 163, 27, 225, 96, 134, 40, 142, - 100, 11, 74, 72, 34, 18, 89, 194, 195, 36, - 172, 193, 70, 125, 25, 35, 26, 24, 8, 71, - 45, 66, 65, 9, 46, 68, 2, 24, 253, 241, - 76, 104, 218, 193, 142, 121, 92, 99, 30, 163, - 185, 94, 59, 214, 65, 143, 118, 76, 47, 134, - 106, 106, 83, 130, 86, 179, 13, 13, 36, 33, - 9, 55, 152, 80, 15, 119, 83, 138, 214, 93, - 226, 137, 80, 60, 17, 138, 46, 33, 34, 66, - 237, 66, 19, 39, 241, 3, 52, 44, 1, 141, - 43, 94, 145, 81, 95, 248, 2, 235, 52, 129, - 134, 84, 184, 226, 27, 177, 0, 85, 50, 194, - 17, 142, 128, 197, 34, 26, 210, 8, 71, 0, - 188, 1, 143, 105, 80, 98, 18, 198, 8, 198, - 36, 134, 57, 76, 246, 144, 131, 18, 179, 168, - 132, 39, 30, 181, 138, 67, 112, 130, 19, 135, - 88, 5, 36, 32, 161, 172, 106, 118, 233, 83, - 174, 104, 134, 52, 234, 145, 15, 68, 186, 169, - 30, 25, 208, 129, 56, 233, 164, 178, 244, 121, - 165, 4, 64, 244, 205, 160, 254, 4, 63, 253, - 97, 2, 19, 115, 8, 195, 30, 248, 176, 135, - 55, 4, 34, 13, 105, 160, 103, 28, 246, 25, - 255, 7, 39, 106, 226, 18, 157, 72, 198, 56, - 200, 65, 14, 90, 0, 195, 40, 177, 144, 5, - 40, 94, 129, 75, 105, 12, 12, 107, 211, 80, - 135, 58, 86, 85, 14, 87, 169, 67, 28, 1, - 80, 198, 29, 194, 195, 5, 46, 84, 194, 21, - 179, 43, 131, 175, 54, 65, 172, 52, 120, 236, - 99, 40, 45, 86, 43, 50, 16, 130, 17, 140, - 64, 4, 106, 187, 138, 66, 86, 118, 132, 22, - 168, 224, 35, 33, 81, 129, 16, 124, 241, 135, - 61, 176, 235, 167, 244, 244, 169, 207, 190, 80, - 10, 64, 148, 68, 23, 207, 40, 198, 47, 46, - 129, 138, 222, 116, 130, 89, 205, 114, 5, 1, - 90, 1, 48, 89, 60, 205, 22, 182, 112, 85, - 86, 153, 81, 11, 102, 172, 138, 18, 176, 40, - 196, 21, 192, 0, 134, 43, 60, 225, 172, 80, - 184, 2, 22, 202, 80, 5, 72, 36, 195, 0, - 30, 48, 155, 92, 59, 48, 2, 25, 172, 140, - 115, 183, 153, 91, 13, 134, 208, 131, 32, 248, - 32, 114, 147, 11, 130, 96, 123, 64, 216, 169, - 136, 111, 54, 57, 172, 1, 18, 110, 112, 131, - 36, 40, 1, 7, 113, 18, 231, 12, 102, 64, - 2, 18, 208, 64, 4, 34, 120, 105, 180, 116, - 64, 173, 185, 225, 245, 179, 90, 89, 153, 17, - 150, 208, 215, 191, 18, 161, 5, 60, 56, 156, - 106, 19, 215, 56, 34, 72, 206, 41, 79, 57, - 66, 85, 234, 6, 218, 218, 255, 90, 107, 34, - 70, 104, 153, 16, 154, 208, 17, 156, 254, 77, - 167, 129, 19, 2, 225, 48, 64, 92, 226, 118, - 131, 2, 200, 77, 110, 55, 126, 225, 192, 228, - 38, 183, 5, 174, 13, 172, 96, 167, 75, 216, - 234, 86, 23, 115, 70, 48, 223, 249, 108, 155, - 215, 32, 20, 225, 2, 16, 48, 129, 182, 50, - 130, 130, 21, 144, 114, 44, 154, 208, 196, 24, - 22, 65, 134, 58, 212, 46, 17, 115, 16, 23, - 21, 90, 113, 0, 120, 208, 100, 27, 218, 40, - 208, 60, 190, 33, 11, 101, 208, 18, 24, 217, - 80, 13, 100, 194, 1, 139, 101, 0, 163, 18, - 178, 144, 134, 106, 190, 225, 18, 154, 192, 196, - 53, 74, 249, 192, 83, 196, 71, 225, 217, 110, - 215, 110, 184, 97, 130, 4, 190, 2, 0, 11, - 160, 99, 36, 170, 43, 134, 35, 22, 193, 167, - 224, 20, 199, 12, 102, 200, 66, 22, 240, 50, - 23, 15, 209, 1, 10, 187, 235, 29, 77, 128, - 231, 199, 121, 28, 163, 18, 141, 153, 133, 56, - 178, 87, 15, 120, 152, 195, 26, 231, 48, 71, - 45, 100, 17, 141, 107, 176, 3, 133, 9, 64, - 161, 146, 135, 129, 26, 234, 169, 198, 37, 221, - 123, 205, 7, 168, 34, 27, 217, 150, 143, 109, - 111, 115, 65, 11, 82, 240, 21, 9, 136, 37, - 37, 187, 144, 159, 123, 109, 151, 8, 69, 40, - 194, 20, 192, 33, 69, 34, 204, 32, 23, 49, - 200, 161, 255, 159, 97, 136, 51, 34, 32, 225, - 10, 120, 24, 0, 30, 245, 104, 70, 53, 64, - 245, 9, 2, 96, 35, 26, 234, 96, 15, 51, - 40, 1, 142, 79, 124, 98, 25, 204, 56, 135, - 49, 144, 36, 142, 8, 126, 102, 63, 252, 233, - 207, 10, 219, 113, 0, 20, 150, 38, 201, 46, - 44, 205, 97, 182, 231, 140, 215, 144, 111, 54, - 181, 185, 13, 18, 138, 240, 21, 65, 180, 207, - 55, 109, 73, 53, 35, 226, 146, 226, 44, 176, - 217, 12, 137, 216, 223, 115, 162, 211, 196, 56, - 199, 121, 12, 114, 64, 195, 91, 233, 113, 141, - 106, 124, 162, 27, 171, 104, 69, 44, 36, 113, - 30, 244, 108, 129, 11, 110, 232, 40, 23, 204, - 8, 11, 101, 136, 2, 171, 228, 128, 71, 59, - 234, 115, 166, 252, 236, 167, 132, 74, 38, 36, - 50, 10, 32, 15, 234, 193, 16, 31, 13, 104, - 64, 62, 86, 211, 32, 16, 40, 22, 9, 138, - 101, 155, 11, 110, 160, 27, 175, 136, 37, 79, - 142, 56, 133, 254, 136, 216, 22, 37, 134, 11, - 17, 115, 113, 226, 19, 81, 36, 135, 249, 133, - 33, 149, 169, 244, 66, 42, 199, 16, 6, 78, - 28, 3, 30, 195, 24, 128, 43, 68, 49, 9, - 97, 8, 163, 22, 228, 73, 246, 29, 236, 144, - 165, 96, 0, 185, 22, 230, 48, 71, 124, 200, - 1, 139, 54, 180, 33, 22, 200, 40, 147, 153, - 206, 100, 38, 253, 216, 199, 29, 220, 255, 14, - 144, 126, 228, 97, 24, 111, 182, 137, 145, 21, - 96, 44, 99, 175, 210, 21, 175, 64, 163, 20, - 154, 144, 31, 38, 200, 240, 78, 83, 152, 130, - 45, 74, 236, 69, 32, 80, 20, 8, 21, 45, - 34, 16, 99, 72, 37, 28, 146, 110, 69, 63, - 56, 221, 18, 80, 167, 17, 52, 88, 241, 12, - 175, 85, 98, 162, 161, 144, 69, 179, 199, 40, - 12, 99, 212, 98, 22, 212, 176, 6, 63, 4, - 64, 0, 165, 72, 34, 235, 176, 176, 195, 36, - 66, 177, 140, 145, 187, 157, 29, 94, 140, 9, - 54, 182, 49, 140, 2, 204, 67, 145, 120, 31, - 119, 61, 42, 128, 3, 37, 40, 33, 9, 19, - 169, 57, 0, 160, 145, 161, 76, 4, 34, 57, - 115, 200, 228, 37, 73, 172, 34, 118, 166, 87, - 19, 95, 144, 20, 41, 161, 126, 35, 28, 153, - 242, 15, 43, 49, 244, 43, 248, 248, 13, 3, - 188, 99, 26, 233, 16, 199, 52, 100, 65, 139, - 139, 18, 204, 26, 196, 8, 134, 48, 55, 136, - 135, 86, 205, 34, 20, 119, 184, 3, 40, 216, - 128, 6, 78, 160, 65, 11, 107, 88, 22, 36, - 62, 241, 10, 109, 74, 35, 26, 3, 104, 73, - 55, 19, 153, 247, 25, 234, 32, 78, 116, 90, - 119, 187, 1, 128, 167, 98, 112, 178, 147, 187, - 208, 228, 37, 244, 228, 201, 98, 232, 226, 36, - 49, 2, 196, 23, 152, 190, 168, 62, 252, 161, - 19, 214, 239, 69, 255, 29, 90, 33, 141, 100, - 36, 131, 0, 246, 74, 198, 43, 112, 98, 175, - 88, 132, 94, 83, 179, 146, 69, 37, 242, 144, - 7, 53, 178, 39, 73, 234, 144, 133, 40, 106, - 33, 9, 79, 164, 226, 16, 107, 112, 8, 209, - 36, 128, 2, 152, 82, 90, 48, 44, 90, 80, - 5, 202, 178, 126, 216, 16, 38, 217, 0, 78, - 210, 50, 3, 49, 149, 55, 46, 48, 106, 165, - 6, 13, 190, 65, 40, 126, 34, 40, 131, 66, - 98, 164, 48, 116, 213, 225, 5, 111, 80, 79, - 93, 64, 6, 108, 176, 10, 97, 240, 6, 113, - 32, 6, 152, 144, 34, 189, 64, 0, 239, 87, - 48, 178, 224, 9, 174, 224, 9, 92, 146, 12, - 224, 144, 14, 211, 224, 13, 58, 8, 127, 171, - 242, 108, 18, 37, 81, 227, 176, 52, 226, 225, - 6, 146, 208, 10, 104, 16, 44, 248, 164, 6, - 29, 131, 79, 6, 248, 132, 4, 192, 1, 152, - 37, 2, 39, 35, 83, 229, 52, 17, 91, 86, - 2, 226, 165, 10, 24, 168, 39, 245, 198, 8, - 247, 22, 7, 244, 84, 46, 132, 128, 46, 236, - 226, 46, 251, 4, 47, 48, 242, 11, 4, 128, - 42, 3, 197, 12, 93, 39, 12, 202, 16, 11, - 160, 0, 48, 164, 50, 13, 4, 101, 37, 138, - 193, 12, 229, 80, 14, 234, 160, 48, 226, 32, - 10, 26, 20, 30, 110, 64, 9, 192, 160, 49, - 136, 184, 49, 183, 247, 132, 32, 35, 2, 33, - 255, 240, 136, 35, 80, 133, 88, 150, 87, 158, - 3, 58, 28, 225, 17, 44, 192, 83, 95, 224, - 5, 106, 96, 134, 63, 197, 46, 123, 48, 79, - 124, 240, 6, 128, 80, 10, 108, 129, 18, 157, - 208, 37, 16, 20, 13, 203, 240, 14, 192, 144, - 19, 67, 17, 65, 225, 0, 14, 224, 48, 122, - 176, 208, 48, 88, 213, 42, 92, 85, 11, 182, - 64, 127, 238, 81, 8, 103, 165, 86, 88, 48, - 140, 136, 136, 44, 198, 210, 10, 242, 48, 54, - 100, 211, 1, 30, 32, 2, 118, 101, 133, 157, - 179, 50, 61, 0, 4, 128, 35, 56, 47, 19, - 1, 197, 32, 79, 235, 18, 138, 62, 101, 5, - 86, 192, 7, 47, 226, 7, 55, 226, 11, 78, - 119, 9, 175, 96, 20, 157, 178, 64, 244, 2, - 48, 192, 0, 11, 148, 32, 53, 161, 64, 11, - 207, 214, 42, 170, 34, 14, 76, 2, 12, 133, - 0, 5, 83, 176, 143, 251, 8, 6, 84, 16, - 5, 209, 96, 0, 29, 32, 87, 4, 25, 2, - 36, 64, 91, 181, 21, 55, 53, 208, 3, 62, - 192, 3, 51, 3, 4, 172, 213, 56, 144, 67, - 57, 126, 229, 3, 15, 64, 1, 76, 80, 4, - 66, 128, 1, 4, 112, 42, 177, 64, 42, 145, - 32, 11, 253, 162, 12, 153, 34, 14, 6, 96, - 0, 25, 144, 1, 28, 176, 146, 58, 96, 89, - 151, 149, 89, 35, 240, 136, 143, 72, 50, 45, - 69, 2, 207, 136, 144, 220, 255, 229, 16, 116, - 179, 50, 232, 86, 101, 20, 22, 62, 178, 133, - 88, 138, 197, 88, 143, 244, 88, 115, 130, 3, - 49, 208, 89, 59, 57, 137, 57, 217, 148, 78, - 249, 148, 80, 217, 54, 75, 57, 149, 208, 24, - 149, 86, 73, 129, 19, 241, 2, 71, 208, 3, - 63, 208, 2, 46, 99, 141, 48, 83, 56, 171, - 165, 56, 140, 211, 90, 174, 21, 57, 63, 48, - 88, 67, 64, 62, 119, 117, 149, 110, 115, 21, - 72, 208, 3, 45, 192, 4, 55, 5, 18, 191, - 21, 92, 194, 69, 56, 98, 121, 56, 100, 201, - 56, 142, 115, 150, 19, 89, 57, 211, 53, 152, - 176, 181, 4, 228, 163, 93, 110, 25, 90, 72, - 16, 4, 212, 168, 17, 188, 133, 137, 57, 5, - 92, 36, 49, 22, 172, 240, 0, 72, 177, 20, - 72, 129, 20, 174, 65, 0, 211, 180, 10, 159, - 144, 153, 151, 169, 20, 4, 64, 0, 199, 117, - 145, 129, 101, 93, 215, 37, 21, 228, 35, 73, - 110, 57, 17, 65, 192, 4, 43, 160, 45, 23, - 112, 2, 142, 233, 17, 208, 48, 18, 48, 130, - 10, 186, 112, 9, 100, 112, 73, 188, 153, 5, - 104, 224, 10, 247, 0, 24, 206, 208, 18, 135, - 129, 15, 199, 64, 42, 18, 20, 11, 10, 214, - 69, 245, 80, 15, 176, 244, 145, 71, 35, 13, - 62, 177, 13, 3, 0, 19, 161, 249, 0, 151, - 35, 21, 83, 97, 97, 23, 134, 87, 19, 209, - 3, 76, 255, 112, 1, 0, 16, 94, 22, 128, - 17, 232, 144, 11, 35, 129, 94, 129, 112, 6, - 103, 113, 6, 89, 64, 59, 41, 70, 6, 89, - 64, 5, 79, 224, 10, 246, 49, 99, 213, 99, - 32, 223, 64, 11, 126, 168, 12, 0, 38, 67, - 252, 57, 13, 171, 50, 14, 148, 176, 12, 217, - 224, 71, 217, 35, 60, 136, 225, 18, 63, 1, - 97, 15, 32, 97, 63, 25, 62, 22, 198, 57, - 91, 177, 124, 0, 80, 2, 166, 179, 158, 165, - 176, 58, 130, 18, 63, 172, 166, 98, 179, 83, - 7, 116, 33, 46, 79, 16, 5, 175, 160, 0, - 240, 240, 59, 193, 131, 24, 228, 80, 60, 162, - 128, 60, 6, 162, 13, 215, 160, 14, 194, 144, - 113, 194, 64, 9, 209, 160, 13, 236, 96, 100, - 76, 134, 26, 168, 97, 32, 50, 212, 96, 81, - 246, 1, 83, 118, 4, 72, 74, 161, 53, 192, - 148, 58, 233, 2, 65, 32, 4, 28, 182, 15, - 66, 211, 27, 68, 135, 9, 62, 7, 28, 38, - 22, 23, 42, 150, 5, 25, 67, 59, 30, 130, - 6, 108, 16, 13, 132, 244, 156, 131, 81, 24, - 6, 146, 13, 227, 208, 85, 230, 160, 14, 217, - 243, 13, 234, 192, 70, 141, 1, 61, 210, 192, - 14, 134, 20, 26, 157, 97, 72, 40, 36, 15, - 167, 241, 66, 48, 244, 100, 52, 225, 26, 31, - 0, 2, 179, 1, 106, 76, 138, 16, 88, 168, - 62, 162, 243, 97, 71, 21, 102, 102, 255, 134, - 8, 103, 80, 102, 141, 192, 8, 108, 33, 63, - 178, 99, 23, 136, 39, 7, 115, 96, 6, 101, - 176, 9, 159, 192, 14, 127, 193, 26, 63, 241, - 19, 197, 121, 12, 228, 128, 48, 204, 160, 99, - 205, 208, 12, 211, 16, 118, 196, 112, 14, 229, - 32, 11, 174, 32, 13, 121, 164, 31, 5, 144, - 71, 158, 65, 32, 184, 112, 11, 7, 192, 167, - 243, 192, 167, 218, 195, 26, 216, 16, 168, 131, - 90, 161, 161, 181, 101, 165, 134, 58, 29, 234, - 133, 98, 246, 94, 177, 163, 8, 140, 112, 68, - 204, 145, 5, 117, 33, 6, 112, 246, 63, 113, - 102, 41, 239, 112, 103, 199, 144, 20, 144, 192, - 9, 157, 208, 10, 213, 16, 13, 88, 130, 108, - 110, 176, 5, 82, 34, 9, 121, 224, 112, 73, - 50, 14, 209, 112, 12, 252, 1, 105, 145, 38, - 105, 120, 154, 167, 120, 154, 0, 168, 17, 67, - 228, 214, 26, 55, 148, 88, 233, 246, 157, 121, - 211, 3, 130, 103, 8, 35, 225, 62, 131, 162, - 106, 141, 128, 98, 42, 102, 63, 137, 144, 63, - 96, 24, 159, 4, 100, 107, 182, 54, 7, 193, - 121, 146, 237, 224, 107, 221, 192, 10, 191, 64, - 103, 19, 20, 37, 91, 96, 65, 228, 42, 5, - 244, 231, 48, 150, 49, 14, 157, 81, 31, 1, - 178, 14, 240, 106, 66, 184, 192, 100, 183, 144, - 31, 161, 113, 26, 212, 163, 61, 13, 192, 105, - 251, 154, 88, 59, 255, 84, 78, 68, 240, 21, - 16, 240, 110, 168, 54, 8, 195, 49, 8, 98, - 102, 6, 201, 129, 8, 89, 144, 8, 11, 235, - 28, 208, 33, 29, 183, 54, 29, 94, 64, 112, - 157, 208, 12, 127, 113, 12, 10, 244, 10, 183, - 24, 123, 201, 198, 5, 91, 144, 181, 89, 203, - 5, 118, 48, 11, 134, 8, 10, 149, 176, 113, - 210, 134, 31, 249, 97, 109, 36, 100, 171, 0, - 178, 14, 119, 106, 24, 7, 2, 110, 226, 166, - 119, 229, 22, 33, 232, 182, 67, 88, 120, 129, - 201, 26, 111, 189, 32, 28, 109, 65, 10, 166, - 192, 102, 114, 129, 120, 251, 22, 8, 100, 160, - 8, 209, 225, 5, 93, 112, 184, 134, 251, 7, - 4, 103, 112, 6, 224, 14, 199, 224, 10, 202, - 48, 76, 120, 64, 136, 87, 219, 81, 89, 50, - 9, 65, 38, 12, 212, 224, 85, 161, 32, 14, - 109, 0, 12, 131, 52, 114, 35, 68, 66, 212, - 134, 178, 237, 160, 114, 160, 113, 72, 196, 183, - 32, 46, 81, 1, 139, 21, 33, 55, 112, 21, - 65, 208, 101, 55, 167, 9, 142, 144, 183, 241, - 195, 8, 169, 38, 34, 240, 21, 6, 128, 187, - 28, 129, 240, 63, 207, 33, 112, 139, 2, 112, - 93, 224, 5, 144, 192, 14, 240, 96, 15, 15, - 144, 12, 173, 66, 13, 231, 0, 113, 87, 107, - 43, 233, 138, 122, 15, 103, 12, 202, 144, 10, - 148, 192, 127, 230, 234, 9, 223, 112, 11, 237, - 255, 48, 15, 117, 186, 14, 240, 64, 72, 244, - 176, 109, 5, 160, 31, 229, 11, 26, 187, 234, - 114, 138, 180, 26, 174, 11, 73, 145, 52, 17, - 164, 230, 110, 56, 151, 187, 207, 122, 165, 245, - 134, 22, 193, 171, 111, 33, 178, 8, 99, 240, - 7, 2, 124, 9, 93, 208, 125, 112, 32, 142, - 52, 226, 11, 197, 128, 177, 189, 0, 14, 76, - 226, 42, 180, 112, 70, 145, 112, 7, 195, 164, - 104, 194, 112, 14, 98, 119, 14, 14, 240, 3, - 20, 240, 142, 178, 64, 9, 120, 96, 7, 178, - 48, 10, 110, 103, 109, 143, 54, 10, 222, 112, - 61, 246, 209, 14, 215, 144, 119, 47, 183, 119, - 127, 247, 72, 19, 113, 2, 95, 65, 120, 97, - 150, 8, 100, 144, 195, 152, 176, 8, 67, 52, - 8, 74, 100, 10, 39, 130, 73, 68, 215, 34, - 138, 66, 196, 226, 8, 117, 78, 55, 41, 165, - 88, 10, 204, 226, 9, 177, 16, 0, 228, 48, - 43, 3, 85, 14, 139, 65, 13, 194, 224, 181, - 181, 64, 12, 252, 176, 0, 169, 128, 0, 174, - 64, 71, 162, 87, 9, 33, 12, 11, 201, 227, - 69, 122, 6, 154, 153, 137, 13, 199, 160, 13, - 171, 235, 194, 9, 178, 119, 114, 210, 119, 51, - 124, 33, 25, 130, 9, 70, 155, 28, 32, 34, - 34, 79, 148, 9, 167, 32, 125, 42, 146, 94, - 45, 34, 41, 71, 76, 121, 78, 167, 69, 142, - 144, 177, 169, 64, 126, 215, 255, 224, 121, 125, - 88, 170, 125, 216, 60, 204, 160, 12, 148, 128, - 122, 193, 244, 112, 183, 210, 181, 170, 18, 10, - 118, 192, 5, 133, 112, 8, 93, 18, 65, 210, - 16, 48, 223, 192, 14, 200, 176, 14, 163, 48, - 10, 225, 27, 67, 110, 252, 77, 113, 18, 39, - 244, 251, 21, 150, 80, 120, 152, 148, 120, 33, - 50, 116, 151, 212, 199, 41, 242, 39, 135, 210, - 84, 148, 55, 74, 78, 7, 8, 112, 224, 34, - 49, 162, 11, 187, 192, 9, 188, 208, 10, 205, - 240, 13, 55, 161, 75, 233, 64, 75, 181, 212, - 95, 59, 56, 13, 12, 167, 122, 171, 167, 70, - 147, 192, 139, 227, 224, 6, 119, 16, 9, 173, - 64, 128, 0, 184, 10, 202, 210, 76, 186, 215, - 37, 189, 151, 13, 223, 192, 198, 238, 203, 38, - 245, 160, 1, 226, 36, 39, 174, 217, 101, 222, - 178, 11, 153, 20, 125, 210, 71, 125, 125, 114, - 10, 214, 23, 74, 133, 28, 35, 166, 100, 74, - 95, 240, 11, 154, 96, 10, 169, 208, 123, 191, - 199, 37, 0, 99, 126, 166, 130, 75, 225, 0, - 15, 11, 227, 108, 181, 160, 65, 196, 52, 9, - 248, 39, 14, 182, 48, 11, 192, 208, 10, 185, - 167, 44, 222, 236, 205, 196, 226, 43, 196, 178, - 44, 93, 146, 77, 45, 129, 206, 50, 212, 0, - 28, 48, 89, 156, 117, 21, 45, 176, 62, 241, - 76, 98, 139, 64, 40, 155, 196, 78, 236, 84, - 12, 187, 255, 188, 40, 193, 28, 204, 169, 212, - 5, 207, 164, 11, 57, 210, 161, 173, 80, 75, - 191, 39, 20, 173, 240, 9, 58, 225, 80, 203, - 0, 14, 71, 29, 122, 6, 106, 11, 181, 64, - 127, 176, 194, 135, 228, 48, 13, 110, 128, 7, - 148, 0, 10, 221, 124, 8, 104, 176, 9, 206, - 100, 123, 9, 216, 49, 8, 248, 49, 195, 178, - 6, 187, 23, 210, 209, 80, 15, 28, 80, 89, - 51, 112, 147, 19, 145, 179, 94, 1, 1, 208, - 32, 47, 158, 212, 39, 187, 192, 129, 169, 102, - 203, 4, 220, 5, 111, 144, 215, 112, 240, 125, - 144, 80, 7, 111, 240, 5, 127, 224, 27, 189, - 112, 104, 211, 32, 14, 228, 32, 10, 224, 16, - 13, 245, 226, 10, 205, 178, 12, 71, 93, 75, - 224, 32, 14, 5, 19, 10, 161, 224, 122, 125, - 40, 43, 211, 80, 9, 226, 177, 205, 173, 64, - 8, 75, 168, 5, 139, 232, 132, 140, 88, 44, - 29, 179, 44, 3, 128, 89, 208, 114, 147, 88, - 9, 176, 63, 20, 207, 114, 45, 211, 125, 44, - 111, 134, 231, 63, 94, 16, 138, 111, 208, 5, - 104, 208, 215, 111, 224, 5, 98, 24, 7, 153, - 64, 211, 191, 144, 12, 146, 173, 48, 164, 226, - 9, 70, 241, 10, 175, 16, 11, 203, 16, 14, - 58, 152, 14, 224, 160, 12, 227, 80, 14, 94, - 235, 159, 229, 64, 80, 179, 2, 123, 20, 183, - 5, 71, 88, 7, 192, 114, 128, 7, 255, 104, - 82, 163, 253, 49, 43, 229, 82, 34, 96, 147, - 208, 120, 45, 198, 170, 133, 233, 228, 133, 241, - 182, 183, 153, 224, 33, 98, 56, 138, 111, 80, - 7, 169, 128, 5, 235, 194, 7, 189, 29, 6, - 171, 115, 10, 166, 208, 10, 80, 172, 14, 241, - 161, 52, 89, 229, 9, 173, 32, 139, 225, 16, - 81, 82, 44, 217, 70, 194, 12, 127, 56, 13, - 1, 48, 127, 147, 171, 108, 160, 128, 136, 104, - 32, 82, 30, 125, 82, 225, 253, 10, 28, 0, - 137, 105, 179, 57, 18, 161, 210, 40, 32, 94, - 179, 121, 115, 122, 178, 8, 239, 212, 33, 98, - 32, 223, 244, 125, 5, 159, 168, 7, 104, 232, - 5, 49, 162, 9, 135, 224, 86, 233, 16, 122, - 112, 24, 12, 2, 112, 96, 176, 192, 156, 31, - 25, 122, 214, 109, 36, 213, 253, 135, 12, 195, - 42, 15, 77, 127, 81, 3, 10, 254, 104, 49, - 238, 149, 49, 30, 205, 136, 159, 208, 0, 35, - 35, 147, 146, 232, 175, 60, 36, 187, 69, 64, - 94, 29, 113, 115, 114, 96, 23, 134, 75, 7, - 144, 192, 226, 45, 174, 7, 161, 248, 46, 127, - 64, 41, 157, 192, 9, 191, 176, 10, 177, 26, - 0, 197, 195, 12, 227, 0, 11, 160, 96, 224, - 71, 13, 221, 146, 173, 12, 178, 0, 14, 31, - 204, 212, 236, 209, 85, 189, 120, 7, 253, 55, - 140, 254, 152, 136, 34, 133, 44, 24, 78, 44, - 175, 0, 15, 100, 255, 67, 50, 29, 238, 225, - 51, 117, 45, 62, 80, 4, 143, 105, 151, 190, - 240, 11, 101, 16, 230, 103, 40, 84, 127, 221, - 161, 165, 128, 33, 191, 112, 230, 13, 228, 64, - 29, 9, 139, 191, 23, 65, 31, 9, 14, 149, - 32, 143, 21, 149, 139, 187, 72, 53, 179, 160, - 12, 254, 247, 4, 80, 0, 235, 87, 48, 235, - 107, 197, 86, 105, 96, 232, 5, 16, 87, 27, - 176, 140, 6, 217, 150, 16, 177, 54, 211, 168, - 2, 57, 21, 92, 69, 128, 10, 181, 253, 137, - 99, 174, 46, 123, 208, 5, 146, 66, 18, 128, - 112, 18, 190, 0, 80, 233, 197, 10, 172, 208, - 13, 157, 160, 9, 159, 48, 77, 201, 45, 146, - 241, 40, 10, 179, 128, 85, 91, 165, 42, 239, - 216, 127, 81, 208, 143, 83, 64, 86, 96, 0, - 232, 173, 80, 163, 4, 105, 54, 29, 96, 50, - 56, 153, 50, 112, 35, 151, 26, 153, 151, 69, - 32, 51, 17, 16, 1, 151, 80, 79, 35, 168, - 7, 222, 184, 51, 111, 32, 35, 183, 105, 35, - 154, 224, 10, 237, 40, 11, 178, 0, 12, 7, - 207, 36, 90, 23, 182, 110, 64, 217, 242, 40, - 10, 167, 74, 11, 67, 104, 231, 90, 3, 5, - 177, 62, 5, 92, 19, 14, 34, 179, 140, 4, - 249, 238, 7, 25, 239, 22, 186, 54, 55, 192, - 149, 64, 176, 151, 17, 121, 90, 20, 208, 13, - 155, 0, 6, 59, 51, 5, 124, 128, 192, 190, - 139, 208, 10, 70, 35, 11, 145, 16, 9, 146, - 144, 243, 103, 247, 142, 180, 64, 30, 76, 19, - 143, 180, 160, 12, 142, 157, 0, 9, 208, 0, - 12, 48, 1, 49, 41, 147, 98, 147, 232, 6, - 169, 148, 140, 238, 148, 114, 131, 4, 67, 16, - 4, 63, 176, 3, 139, 35, 145, 129, 73, 93, - 133, 5, 21, 21, 38, 27, 57, 36, 183, 141, - 245, 88, 145, 165, 3, 147, 229, 146, 152, 229, - 82, 73, 223, 82, 52, 48, 45, 114, 147, 152, - 6, 177, 148, 53, 112, 4, 164, 213, 87, 131, - 181, 245, 152, 115, 88, 66, 9, 187, 142, 165, - 4, 173, 44, 89, 147, 37, 129, 50, 224, 244, - 109, 239, 246, 191, 78, 149, 134, 127, 248, 34, - 79, 248, 35, 143, 248, 134, 239, 246, 1, 1, - 0, 59 }; diff --git a/main/main.c b/main/main.c deleted file mode 100644 index 6c86370084..0000000000 --- a/main/main.c +++ /dev/null @@ -1,1786 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* {{{ includes - */ - -#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS - -#include "php.h" -#include <stdio.h> -#ifdef PHP_WIN32 -#include "win32/time.h" -#include "win32/signal.h" -#include <process.h> -#elif defined(NETWARE) -#ifdef NEW_LIBC -#include <sys/timeval.h> -#else -#include "netware/time_nw.h" -#endif -/*#include "netware/signal_nw.h"*/ -/*#include "netware/env.h"*/ /* Temporary */ -/*#include <process.h>*/ -#ifdef USE_WINSOCK -#include <novsock2.h> -#endif -#endif -#if HAVE_SYS_TIME_H -#include <sys/time.h> -#endif -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#if HAVE_SIGNAL_H -#include <signal.h> -#endif -#if HAVE_SETLOCALE -#include <locale.h> -#endif -#include "zend.h" -#include "zend_extensions.h" -#include "php_ini.h" -#include "php_globals.h" -#include "php_main.h" -#include "fopen_wrappers.h" -#include "ext/standard/php_standard.h" -#include "php_variables.h" -#include "ext/standard/credits.h" -#ifdef PHP_WIN32 -#include <io.h> -#include <fcntl.h> -#include "win32/php_registry.h" -#endif -#include "php_syslog.h" -#include "Zend/zend_default_classes.h" - -#if PHP_SIGCHILD -#include <sys/types.h> -#include <sys/wait.h> -#endif - -#include "zend_compile.h" -#include "zend_execute.h" -#include "zend_highlight.h" -#include "zend_indent.h" -#include "zend_extensions.h" -#include "zend_ini.h" - -#include "php_content_types.h" -#include "php_ticks.h" -#include "php_logos.h" -#include "php_streams.h" - -#include "SAPI.h" -#include "rfc1867.h" -/* }}} */ - -#ifndef ZTS -php_core_globals core_globals; -#else -PHPAPI int core_globals_id; -#endif - -#define SAFE_FILENAME(f) ((f)?(f):"-") - -/* {{{ PHP_INI_MH - */ -static PHP_INI_MH(OnSetPrecision) -{ - EG(precision) = atoi(new_value); - return SUCCESS; -} -/* }}} */ - -#if MEMORY_LIMIT -/* {{{ PHP_INI_MH - */ -static PHP_INI_MH(OnChangeMemoryLimit) -{ - if (new_value) { - PG(memory_limit) = zend_atoi(new_value, new_value_length); - } else { - PG(memory_limit) = 1<<30; /* effectively, no limit */ - } - return zend_set_memory_limit(PG(memory_limit)); -} -/* }}} */ -#endif - - -/* {{{ php_disable_functions - */ -static void php_disable_functions(TSRMLS_D) -{ - char *s = NULL, *e; - - if (!*(INI_STR("disable_functions"))) { - return; - } - - e = PG(disable_functions) = strdup(INI_STR("disable_functions")); - - while (*e) { - switch (*e) { - case ' ': - case ',': - if (s) { - *e = '\0'; - zend_disable_function(s, e-s TSRMLS_CC); - s = NULL; - } - break; - default: - if (!s) { - s = e; - } - break; - } - e++; - } - if (s) { - zend_disable_function(s, e-s TSRMLS_CC); - } -} -/* }}} */ - -/* {{{ php_disable_classes - */ -static void php_disable_classes(TSRMLS_D) -{ - char *s = NULL, *e; - - if (!*(INI_STR("disable_classes"))) { - return; - } - - e = PG(disable_classes) = strdup(INI_STR("disable_classes")); - - while (*e) { - switch (*e) { - case ' ': - case ',': - if (s) { - *e = '\0'; - zend_disable_class(s, e-s TSRMLS_CC); - s = NULL; - } - break; - default: - if (!s) { - s = e; - } - break; - } - e++; - } - if (s) { - zend_disable_class(s, e-s TSRMLS_CC); - } -} -/* }}} */ - -/* {{{ PHP_INI_MH - */ -static PHP_INI_MH(OnUpdateTimeout) -{ - EG(timeout_seconds) = atoi(new_value); - if (stage==PHP_INI_STAGE_STARTUP) { - /* Don't set a timeout on startup, only per-request */ - return SUCCESS; - } - zend_unset_timeout(TSRMLS_C); - zend_set_timeout(EG(timeout_seconds)); - return SUCCESS; -} -/* }}} */ - -/* Need to convert to strings and make use of: - * PHP_SAFE_MODE - * - * Need to be read from the environment (?): - * PHP_AUTO_PREPEND_FILE - * PHP_AUTO_APPEND_FILE - * PHP_DOCUMENT_ROOT - * PHP_USER_DIR - * PHP_INCLUDE_PATH - */ - -#ifndef PHP_SAFE_MODE_EXEC_DIR -# define PHP_SAFE_MODE_EXEC_DIR "" -#endif - -#ifdef PHP_PROG_SENDMAIL -# define DEFAULT_SENDMAIL_PATH PHP_PROG_SENDMAIL " -t -i " -#else -# define DEFAULT_SENDMAIL_PATH NULL -#endif -/* {{{ PHP_INI - */ -PHP_INI_BEGIN() - PHP_INI_ENTRY_EX("define_syslog_variables", "0", PHP_INI_ALL, NULL, php_ini_boolean_displayer_cb) - PHP_INI_ENTRY_EX("highlight.bg", HL_BG_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb) - PHP_INI_ENTRY_EX("highlight.comment", HL_COMMENT_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb) - PHP_INI_ENTRY_EX("highlight.default", HL_DEFAULT_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb) - PHP_INI_ENTRY_EX("highlight.html", HL_HTML_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb) - PHP_INI_ENTRY_EX("highlight.keyword", HL_KEYWORD_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb) - PHP_INI_ENTRY_EX("highlight.string", HL_STRING_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb) - - STD_PHP_INI_BOOLEAN("allow_call_time_pass_reference", "1", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, allow_call_time_pass_reference, zend_compiler_globals, compiler_globals) - STD_PHP_INI_BOOLEAN("asp_tags", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, asp_tags, zend_compiler_globals, compiler_globals) - STD_PHP_INI_BOOLEAN("display_errors", "1", PHP_INI_ALL, OnUpdateBool, display_errors, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("display_startup_errors", "0", PHP_INI_ALL, OnUpdateBool, display_startup_errors, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("enable_dl", "1", PHP_INI_SYSTEM, OnUpdateBool, enable_dl, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("expose_php", "1", PHP_INI_SYSTEM, OnUpdateBool, expose_php, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("docref_root", "", PHP_INI_ALL, OnUpdateString, docref_root, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("docref_ext", "", PHP_INI_ALL, OnUpdateString, docref_ext, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("html_errors", "1", PHP_INI_ALL, OnUpdateBool, html_errors, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("xmlrpc_errors", "0", PHP_INI_SYSTEM, OnUpdateBool, xmlrpc_errors, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("xmlrpc_error_number", "0", PHP_INI_ALL, OnUpdateLong, xmlrpc_error_number, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("max_input_time", "-1", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, max_input_time, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("ignore_user_abort", "0", PHP_INI_ALL, OnUpdateBool, ignore_user_abort, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("implicit_flush", "0", PHP_INI_ALL, OnUpdateBool, implicit_flush, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("log_errors", "0", PHP_INI_ALL, OnUpdateBool, log_errors, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("log_errors_max_len", "1024", PHP_INI_ALL, OnUpdateLong, log_errors_max_len, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("ignore_repeated_errors", "0", PHP_INI_ALL, OnUpdateBool, ignore_repeated_errors, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("ignore_repeated_source", "0", PHP_INI_ALL, OnUpdateBool, ignore_repeated_source, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("report_memleaks", "1", PHP_INI_ALL, OnUpdateBool, report_memleaks, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("report_zend_debug", "1", PHP_INI_ALL, OnUpdateBool, report_zend_debug, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("magic_quotes_gpc", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, magic_quotes_gpc, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("magic_quotes_runtime", "0", PHP_INI_ALL, OnUpdateBool, magic_quotes_runtime, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("magic_quotes_sybase", "0", PHP_INI_ALL, OnUpdateBool, magic_quotes_sybase, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("output_buffering", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateLong, output_buffering, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("output_handler", NULL, PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateString, output_handler, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("register_argc_argv", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_argc_argv, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("register_globals", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_globals, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("register_long_arrays", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_long_arrays, php_core_globals, core_globals) -#if PHP_SAFE_MODE - STD_PHP_INI_BOOLEAN("safe_mode", "1", PHP_INI_SYSTEM, OnUpdateBool, safe_mode, php_core_globals, core_globals) -#else - STD_PHP_INI_BOOLEAN("safe_mode", "0", PHP_INI_SYSTEM, OnUpdateBool, safe_mode, php_core_globals, core_globals) -#endif - STD_PHP_INI_ENTRY("safe_mode_include_dir", NULL, PHP_INI_SYSTEM, OnUpdateString, safe_mode_include_dir, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("safe_mode_gid", "0", PHP_INI_SYSTEM, OnUpdateBool, safe_mode_gid, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("short_open_tag", DEFAULT_SHORT_OPEN_TAG, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, short_tags, zend_compiler_globals, compiler_globals) - STD_PHP_INI_BOOLEAN("sql.safe_mode", "0", PHP_INI_SYSTEM, OnUpdateBool, sql_safe_mode, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("track_errors", "0", PHP_INI_ALL, OnUpdateBool, track_errors, php_core_globals, core_globals) - 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("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) - - STD_PHP_INI_ENTRY("auto_append_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_append_file, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("auto_prepend_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_prepend_file, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("doc_root", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, doc_root, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("default_charset", SAPI_DEFAULT_CHARSET, PHP_INI_ALL, OnUpdateString, default_charset, sapi_globals_struct,sapi_globals) - STD_PHP_INI_ENTRY("default_mimetype", SAPI_DEFAULT_MIMETYPE, PHP_INI_ALL, OnUpdateString, default_mimetype, sapi_globals_struct,sapi_globals) - STD_PHP_INI_ENTRY("error_log", NULL, PHP_INI_ALL, OnUpdateString, error_log, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("extension_dir", PHP_EXTENSION_DIR, PHP_INI_SYSTEM, OnUpdateStringUnempty, extension_dir, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("gpc_order", "GPC", PHP_INI_ALL, OnUpdateStringUnempty, gpc_order, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("include_path", PHP_INCLUDE_PATH, PHP_INI_ALL, OnUpdateStringUnempty, include_path, php_core_globals, core_globals) - PHP_INI_ENTRY("max_execution_time", "30", PHP_INI_ALL, OnUpdateTimeout) - STD_PHP_INI_ENTRY("open_basedir", NULL, PHP_INI_SYSTEM, OnUpdateString, open_basedir, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("safe_mode_exec_dir", PHP_SAFE_MODE_EXEC_DIR, PHP_INI_SYSTEM, OnUpdateString, safe_mode_exec_dir, php_core_globals, core_globals) - - STD_PHP_INI_BOOLEAN("file_uploads", "1", PHP_INI_SYSTEM, OnUpdateBool, file_uploads, php_core_globals, core_globals) - 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("user_dir", NULL, PHP_INI_SYSTEM, OnUpdateString, user_dir, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("variables_order", NULL, PHP_INI_ALL, OnUpdateStringUnempty, variables_order, php_core_globals, core_globals) - - STD_PHP_INI_ENTRY("error_append_string", NULL, PHP_INI_ALL, OnUpdateString, error_append_string, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("error_prepend_string", NULL, PHP_INI_ALL, OnUpdateString, error_prepend_string, php_core_globals, core_globals) - - 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", "8M", PHP_INI_ALL, OnChangeMemoryLimit) -#endif - 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) - PHP_INI_ENTRY("mail.force_extra_parameters",NULL, PHP_INI_SYSTEM, NULL) - PHP_INI_ENTRY("disable_functions", "", PHP_INI_SYSTEM, NULL) - PHP_INI_ENTRY("disable_classes", "", PHP_INI_SYSTEM, NULL) - - STD_PHP_INI_BOOLEAN("allow_url_fopen", "1", PHP_INI_ALL, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("always_populate_raw_post_data", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, always_populate_raw_post_data, php_core_globals, core_globals) - -PHP_INI_END() -/* }}} */ - -/* True globals (no need for thread safety */ -/* But don't make them a single int bitfield */ -static int module_initialized = 0; -static int module_startup = 1; -static int module_shutdown = 0; - -/* {{{ php_log_err - */ -PHPAPI void php_log_err(char *log_message TSRMLS_DC) -{ - FILE *log_file; - char error_time_str[128]; - struct tm tmbuf; - time_t error_time; - - /* Try to use the specified logging location. */ - if (PG(error_log) != NULL) { -#ifdef HAVE_SYSLOG_H - if (!strcmp(PG(error_log), "syslog")) { - php_syslog(LOG_NOTICE, "%.500s", log_message); - return; - } -#endif - log_file = VCWD_FOPEN(PG(error_log), "a"); - if (log_file != NULL) { - 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); - return; - } - } - - /* Otherwise fall back to the default logging location, if we have one */ - - if (sapi_module.log_message) { - sapi_module.log_message(log_message); - } -} -/* }}} */ - -/* {{{ php_write - wrapper for modules to use PHPWRITE */ -PHPAPI int php_write(void *buf, uint size TSRMLS_DC) -{ - return PHPWRITE(buf, size); -} -/* }}} */ - -/* {{{ php_printf - */ -PHPAPI int php_printf(const char *format, ...) -{ - va_list args; - int ret; - char *buffer; - int size; - TSRMLS_FETCH(); - - va_start(args, format); - size = vspprintf(&buffer, 0, format, args); - if (buffer) { - ret = PHPWRITE(buffer, size); - efree(buffer); - } else { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Out of memory"); - ret = 0; - } - va_end(args); - - return ret; -} -/* }}} */ - -/* {{{ php_verror helpers */ - -/* {{{ php_during_module_startup */ -static int php_during_module_startup() -{ - return module_startup; -} -/* }}} */ - -/* {{{ php_during_module_shutdown */ -static int php_during_module_shutdown() -{ - return module_shutdown; -} -/* }}} */ - -/* {{{ get_active_class_name */ -static char *get_active_class_name(char **space TSRMLS_DC) -{ - if (!zend_is_executing(TSRMLS_C)) { - if (space) { - *space = ""; - } - return ""; - } - switch (EG(function_state_ptr)->function->type) { - case ZEND_USER_FUNCTION: - case ZEND_INTERNAL_FUNCTION: - { - zend_class_entry *ce = EG(function_state_ptr)->function->common.scope; - - if (space) { - *space = ce ? "::" : ""; - } - return ce ? ce->name : ""; - } - default: - if (space) { - *space = ""; - } - return ""; - } -} -/* }}} */ -/* }}} */ - -/* {{{ php_verror */ -/* php_verror is called from php_error_docref<n> functions. - * Its purpose is to unify error messages and automatically generate clickable - * html error messages if correcponding ini setting (html_errors) is activated. - * See: CODING_STANDARDS for details. - */ -PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC) -{ - char *buffer = NULL, *docref_buf = NULL, *target = NULL; - char *docref_target = "", *docref_root = ""; - char *p; - int buffer_len = 0; - char *space; - char *class_name = get_active_class_name(&space TSRMLS_CC); - char *function; - char *origin; - char *message; - int is_function = 0; - - /* get error text into buffer and escape for html if necessary */ - buffer_len = vspprintf(&buffer, 0, format, args); - if (PG(html_errors)) { - int len; - char *replace = php_escape_html_entities(buffer, buffer_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC); - efree(buffer); - buffer = replace; - buffer_len = len; - } - - /* which function caused the problem if any at all */ - if (php_during_module_startup()) { - function = "PHP Startup"; - } else if (php_during_module_shutdown()) { - function = "PHP Shutdown"; - } else { - function = get_active_function_name(TSRMLS_C); - if (!function || !strlen(function)) { - function = "Unknown"; - } else { - is_function = 1; - } - } - - /* if we still have memory then format the origin */ - if (is_function) { - spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, params); - } else { - spprintf(&origin, 0, "%s", function); - } - - /* origin and buffer available, so lets come up with the error message */ - if (docref && docref[0] == '#') { - docref_target = strchr(docref, '#'); - docref = NULL; - } - - /* no docref given but function is known (the default) */ - if (!docref && is_function) { - spprintf(&docref_buf, 0, "function.%s", function); - while((p = strchr(docref_buf, '_')) != NULL) { - *p = '-'; - } - docref = docref_buf; - } - - /* we have a docref for a function AND - * - we show erroes in html mode OR - * - the user wants to see the links anyway - */ - if (docref && is_function && (PG(html_errors) || strlen(PG(docref_root)))) { - if (strncmp(docref, "http://", 7)) { - /* We don't have 'http://' so we use docref_root */ - - char *ref; /* temp copy for duplicated docref */ - - docref_root = PG(docref_root); - - ref = estrdup(docref); - if (docref_buf) { - efree(docref_buf); - } - docref_buf = ref; - /* strip of the target if any */ - p = strrchr(ref, '#'); - if (p) { - target = estrdup(p); - if (target) { - docref_target = target; - *p = '\0'; - } - } - /* add the extension if it is set in ini */ - if (PG(docref_ext) && strlen(PG(docref_ext))) { - spprintf(&docref_buf, 0, "%s%s", ref, PG(docref_ext)); - efree(ref); - } - docref = docref_buf; - } - /* display html formatted or only show the additional links */ - if (PG(html_errors)) { - spprintf(&message, 0, "%s [<a href='%s%s%s'>%s</a>]: %s", origin, docref_root, docref, docref_target, docref, buffer); - } else { - spprintf(&message, 0, "%s [%s%s%s]: %s", origin, docref_root, docref, docref_target, buffer); - } - if (target) { - efree(target); - } - } else { - spprintf(&message, 0, "%s: %s", origin, buffer); - } - efree(origin); - if (docref_buf) { - efree(docref_buf); - } - php_error(type, "%s", message); - efree(message); - - if (PG(track_errors) && module_initialized && EG(active_symbol_table)) { - zval *tmp; - ALLOC_INIT_ZVAL(tmp); - ZVAL_STRINGL(tmp, buffer, buffer_len, 1); - zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) &tmp, sizeof(pval *), NULL); - } - efree(buffer); -} -/* }}} */ - -/* {{{ php_error_docref */ -/* See: CODING_STANDARDS for details. */ -PHPAPI void php_error_docref(const char *docref TSRMLS_DC, int type, const char *format, ...) -{ - va_list args; - - va_start(args, format); - php_verror(docref, "", type, format, args TSRMLS_CC); - va_end(args); -} -/* }}} */ - -/* {{{ php_error_docref1 */ -/* See: CODING_STANDARDS for details. */ -PHPAPI void php_error_docref1(const char *docref TSRMLS_DC, const char *param1, int type, const char *format, ...) -{ - va_list args; - - va_start(args, format); - php_verror(docref, param1, type, format, args TSRMLS_CC); - va_end(args); -} -/* }}} */ - -/* {{{ php_error_docref2 */ -/* See: CODING_STANDARDS for details. */ -PHPAPI void php_error_docref2(const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...) -{ - char *params; - va_list args; - - spprintf(¶ms, 0, "%s,%s", param1, param2); - va_start(args, format); - php_verror(docref, params ? params : "...", type, format, args TSRMLS_CC); - va_end(args); - if (params) { - efree(params); - } -} -/* }}} */ - -/* {{{ php_html_puts */ -PHPAPI void php_html_puts(const char *str, uint size TSRMLS_DC) -{ - zend_html_puts(str, size TSRMLS_CC); -} -/* }}} */ - -/* {{{ php_suppress_errors */ -PHPAPI void php_set_error_handling(error_handling_t error_handling, zend_class_entry *exception_class TSRMLS_DC) { - PG(error_handling) = error_handling; - PG(exception_class) = exception_class; - if (PG(last_error_message)) { - free(PG(last_error_message)); - PG(last_error_message) = NULL; - } - if (PG(last_error_file)) { - free(PG(last_error_file)); - PG(last_error_file) = NULL; - } - PG(last_error_lineno) = 0; -} -/* }}} */ - -/* {{{ php_error_cb - extended error handling function */ -static void php_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) -{ - char *buffer; - int buffer_len, display; - TSRMLS_FETCH(); - - buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format, args); - - /* check for repeated errors to be ignored */ - if (PG(ignore_repeated_errors) && PG(last_error_message)) { - /* no check for PG(last_error_file) is needed since it cannot - * be NULL if PG(last_error_message) is not NULL */ - if (strcmp(PG(last_error_message), buffer) - || (!PG(ignore_repeated_source) - && ((PG(last_error_lineno) != error_lineno) - || strcmp(PG(last_error_file), error_filename)))) { - display = 1; - } else { - display = 0; - } - } else { - display = 1; - } - - /* store the error if it has changed */ - if (display) { - if (PG(last_error_message)) { - free(PG(last_error_message)); - } - if (PG(last_error_file)) { - free(PG(last_error_file)); - } - PG(last_error_message) = strdup(buffer); - PG(last_error_file) = strdup(error_filename); - PG(last_error_lineno) = error_lineno; - } - - /* according to error handling mode, suppress error, throw exception or show it */ - if (PG(error_handling) != EH_NORMAL) { - switch (type) { - case E_ERROR: - case E_CORE_ERROR: - case E_COMPILE_ERROR: - case E_USER_ERROR: - case E_PARSE: - /* fatal errors are real errors and cannot be made exceptions */ - break; - default: - /* throw an exception if we are in EH_THROW mode - * but DO NOT overwrite a pending excepption - */ - if (PG(error_handling) == EH_THROW && !EG(exception)) { - zend_throw_exception(PG(exception_class), buffer, 0 TSRMLS_CC); - } - efree(buffer); - return; - } - } - - /* display/log the error if necessary */ - if (display && (EG(error_reporting) & type || (type & E_CORE)) - && (PG(log_errors) || PG(display_errors) || (!module_initialized))) { - char *error_type_str; - - switch (type) { - case E_ERROR: - case E_CORE_ERROR: - case E_COMPILE_ERROR: - case E_USER_ERROR: - error_type_str = "Fatal error"; - break; - case E_WARNING: - case E_CORE_WARNING: - case E_COMPILE_WARNING: - case E_USER_WARNING: - error_type_str = "Warning"; - break; - case E_PARSE: - error_type_str = "Parse error"; - break; - case E_NOTICE: - case E_USER_NOTICE: - error_type_str = "Notice"; - break; - case E_STRICT: - error_type_str = "Strict Standards"; - break; - default: - error_type_str = "Unknown error"; - break; - } - - if (!module_initialized || PG(log_errors)) { - char *log_buffer; - -#ifdef PHP_WIN32 - if (type==E_CORE_ERROR || type==E_CORE_WARNING) { - MessageBox(NULL, buffer, error_type_str, MB_OK|ZEND_SERVICE_MB_STYLE); - } -#endif - spprintf(&log_buffer, 0, "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno); - php_log_err(log_buffer TSRMLS_CC); - efree(log_buffer); - } - if (module_initialized && PG(display_errors) - && (!PG(during_request_startup) || PG(display_startup_errors))) { - - if (PG(xmlrpc_errors)) { - php_printf("<?xml version=\"1.0\"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>%ld</int></value></member><member><name>faultString</name><value><string>%s:%s in %s on line %d</string></value></member></struct></value></fault></methodResponse>", PG(xmlrpc_error_number), error_type_str, buffer, error_filename, error_lineno); - } else { - char *prepend_string = INI_STR("error_prepend_string"); - char *append_string = INI_STR("error_append_string"); - char *error_format = PG(html_errors) ? - "%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n%s" - : "%s\n%s: %s in %s on line %d\n%s"; - php_printf(error_format, STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); - } - } -#if ZEND_DEBUG - if (PG(report_zend_debug)) { - zend_bool trigger_break; - - switch (type) { - case E_ERROR: - case E_CORE_ERROR: - case E_COMPILE_ERROR: - case E_USER_ERROR: - trigger_break=1; - break; - default: - trigger_break=0; - break; - } - zend_output_debug_string(trigger_break, "%s(%d) : %s - %s", error_filename, error_lineno, error_type_str, buffer); - } -#endif - } - - /* Bail out if we can't recover */ - switch (type) { - case E_CORE_ERROR: - if(!module_initialized) { - /* bad error in module startup - no way we can live with this */ - exit(-2); - } - /* no break - intentionally */ - case E_ERROR: - /*case E_PARSE: the parser would return 1 (failure), we can bail out nicely */ - case E_COMPILE_ERROR: - case E_USER_ERROR: - EG(exit_status) = 255; - if (module_initialized) { -#if MEMORY_LIMIT - /* restore memory limit */ - AG(memory_limit) = PG(memory_limit); -#endif - zend_bailout(); - efree(buffer); - return; - } - break; - } - - /* Log if necessary */ - if (!display) { - efree(buffer); - return; - } - if (PG(track_errors) && module_initialized && EG(active_symbol_table)) { - pval *tmp; - - ALLOC_ZVAL(tmp); - INIT_PZVAL(tmp); - Z_STRVAL_P(tmp) = (char *) estrndup(buffer, buffer_len); - Z_STRLEN_P(tmp) = buffer_len; - Z_TYPE_P(tmp) = IS_STRING; - zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(pval *), NULL); - } - efree(buffer); -} -/* }}} */ - -/* {{{ proto bool set_time_limit(int seconds) - Sets the maximum time a script can run */ -PHP_FUNCTION(set_time_limit) -{ - zval **new_timeout; - - if (PG(safe_mode)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot set time limit in safe mode"); - RETURN_FALSE; - } - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &new_timeout) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(new_timeout); - if (zend_alter_ini_entry("max_execution_time", sizeof("max_execution_time"), Z_STRVAL_PP(new_timeout), Z_STRLEN_PP(new_timeout), PHP_INI_USER, PHP_INI_STAGE_RUNTIME) == SUCCESS) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ php_fopen_wrapper_for_zend - */ -static FILE *php_fopen_wrapper_for_zend(const char *filename, char **opened_path) -{ - TSRMLS_FETCH(); - - return php_stream_open_wrapper_as_file((char *)filename, "rb", ENFORCE_SAFE_MODE|USE_PATH|IGNORE_URL_WIN|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE, opened_path); -} -/* }}} */ - -static void stream_closer_for_zend(void *handle TSRMLS_DC) -{ - php_stream_close((php_stream*)handle); -} - -static int php_stream_open_for_zend(const char *filename, zend_file_handle *handle 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); - - if (stream) { - handle->type = ZEND_HANDLE_STREAM; - handle->filename = (char*)filename; - handle->free_filename = 0; - handle->handle.stream.handle = stream; - handle->handle.stream.reader = (zend_stream_reader_t)_php_stream_read; - handle->handle.stream.closer = stream_closer_for_zend; - handle->handle.stream.interactive = 0; - - return SUCCESS; - } - return FAILURE; -} - - -/* {{{ php_get_configuration_directive_for_zend - */ -static int php_get_configuration_directive_for_zend(char *name, uint name_length, zval *contents) -{ - zval *retval = cfg_get_entry(name, name_length); - - if (retval) { - *contents = *retval; - return SUCCESS; - } else { - return FAILURE; - } -} -/* }}} */ - -/* {{{ php_message_handler_for_zend - */ -static void php_message_handler_for_zend(long message, void *data) -{ - TSRMLS_FETCH(); - - switch (message) { - case ZMSG_FAILED_INCLUDE_FOPEN: - php_error_docref("function.include" TSRMLS_CC, E_WARNING, "Failed opening '%s' for inclusion (include_path='%s')", php_strip_url_passwd((char *) data), STR_PRINT(PG(include_path))); - break; - case ZMSG_FAILED_REQUIRE_FOPEN: - php_error_docref("function.require" TSRMLS_CC, E_COMPILE_ERROR, "Failed opening required '%s' (include_path='%s')", php_strip_url_passwd((char *) data), STR_PRINT(PG(include_path))); - break; - case ZMSG_FAILED_HIGHLIGHT_FOPEN: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed opening '%s' for highlighting", php_strip_url_passwd((char *) data)); - break; - case ZMSG_MEMORY_LEAK_DETECTED: - case ZMSG_MEMORY_LEAK_REPEATED: -#if ZEND_DEBUG - if ((EG(error_reporting)&E_WARNING) && PG(report_memleaks)) { - char memory_leak_buf[512]; - - if (message==ZMSG_MEMORY_LEAK_DETECTED) { - zend_mem_header *t = (zend_mem_header *) data; - void *ptr = (void *)((char *)t+sizeof(zend_mem_header)+MEM_HEADER_PADDING); - - snprintf(memory_leak_buf, 512, "%s(%d) : Freeing 0x%.8lX (%d bytes), script=%s\n", t->filename, t->lineno, (unsigned long)ptr, 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); - } - } else { - unsigned long leak_count = (unsigned long) data; - - snprintf(memory_leak_buf, 512, "Last leak repeated %ld time%s\n", leak_count, (leak_count>1?"s":"")); - } -# if defined(PHP_WIN32) - OutputDebugString(memory_leak_buf); -# else - fprintf(stderr, "%s", memory_leak_buf); -# endif - } -#endif - break; - case ZMSG_MEMORY_LEAKS_GRAND_TOTAL: -#if ZEND_DEBUG - if ((EG(error_reporting)&E_WARNING) && PG(report_memleaks)) { - char memory_leak_buf[512]; - - snprintf(memory_leak_buf, 512, "=== Total %d memory leaks detected ===\n", *((zend_uint *) data)); -# if defined(PHP_WIN32) - OutputDebugString(memory_leak_buf); -# else - fprintf(stderr, "%s", memory_leak_buf); -# endif - } -#endif - break; - case ZMSG_LOG_SCRIPT_NAME: { - struct tm *ta, tmbuf; - time_t curtime; - char *datetime_str, asctimebuf[52]; - - 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)); - } - break; - } -} -/* }}} */ - - -void php_on_timeout(int seconds TSRMLS_DC) -{ - PG(connection_status) |= PHP_CONNECTION_TIMEOUT; - zend_set_timeout(EG(timeout_seconds)); -} - -#if PHP_SIGCHILD -/* {{{ sigchld_handler - */ -static void sigchld_handler(int apar) -{ - while (waitpid(-1, NULL, WNOHANG) > 0); - signal(SIGCHLD, sigchld_handler); -} -/* }}} */ -#endif - -/* {{{ php_start_sapi() - */ -static int php_start_sapi(TSRMLS_D) -{ - int retval = SUCCESS; - - if(!SG(sapi_started)) { - zend_try { - PG(during_request_startup) = 1; - - /* initialize global variables */ - PG(modules_activated) = 0; - PG(header_is_being_sent) = 0; - PG(connection_status) = PHP_CONNECTION_NORMAL; - - zend_activate(TSRMLS_C); - zend_set_timeout(EG(timeout_seconds)); - zend_activate_modules(TSRMLS_C); - PG(modules_activated)=1; - } zend_catch { - retval = FAILURE; - } zend_end_try(); - - SG(sapi_started) = 1; - } - return retval; -} - -/* }}} */ - -/* {{{ php_request_startup - */ - #ifndef APACHE_HOOKS -int php_request_startup(TSRMLS_D) -{ - int retval = SUCCESS; - -#ifdef PHP_WIN32 - CoInitialize(NULL); -#endif - -#if PHP_SIGCHILD - signal(SIGCHLD, sigchld_handler); -#endif - - zend_try { - PG(during_request_startup) = 1; - - php_output_activate(TSRMLS_C); - - /* initialize global variables */ - PG(modules_activated) = 0; - PG(header_is_being_sent) = 0; - PG(connection_status) = PHP_CONNECTION_NORMAL; - - zend_activate(TSRMLS_C); - sapi_activate(TSRMLS_C); - - if (PG(max_input_time) == -1) { - zend_set_timeout(EG(timeout_seconds)); - } else { - zend_set_timeout(PG(max_input_time)); - } - - if (PG(expose_php)) { - sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1); - } - - if (PG(output_handler) && PG(output_handler)[0]) { - php_start_ob_buffer_named(PG(output_handler), 0, 1 TSRMLS_CC); - } else if (PG(output_buffering)) { - if (PG(output_buffering)>1) { - php_start_ob_buffer(NULL, PG(output_buffering), 1 TSRMLS_CC); - } else { - php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC); - } - } else if (PG(implicit_flush)) { - php_start_implicit_flush(TSRMLS_C); - } - - /* We turn this off in php_execute_script() */ - /* PG(during_request_startup) = 0; */ - - php_hash_environment(TSRMLS_C); - zend_activate_modules(TSRMLS_C); - PG(modules_activated)=1; - } zend_catch { - retval = FAILURE; - } zend_end_try(); - - return retval; -} -# else -int php_request_startup(TSRMLS_D) -{ - int retval = SUCCESS; - -#if PHP_SIGCHILD - signal(SIGCHLD, sigchld_handler); -#endif - - if (php_start_sapi() == FAILURE) { - return FAILURE; - } - - php_output_activate(TSRMLS_C); - sapi_activate(TSRMLS_C); - php_hash_environment(TSRMLS_C); - - zend_try { - PG(during_request_startup) = 1; - php_output_activate(TSRMLS_C); - if (PG(expose_php)) { - sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1); - } - } zend_catch { - retval = FAILURE; - } zend_end_try(); - - return retval; -} -# endif -/* }}} */ - -/* {{{ php_request_startup_for_hook - */ -int php_request_startup_for_hook(TSRMLS_D) -{ - int retval = SUCCESS; - -#if PHP_SIGCHLD - signal(SIGCHLD, sigchld_handler); -#endif - - if (php_start_sapi(TSRMLS_C) == FAILURE) { - return FAILURE; - } - - php_output_activate(TSRMLS_C); - sapi_activate_headers_only(TSRMLS_C); - php_hash_environment(TSRMLS_C); - - return retval; -} -/* }}} */ - -/* {{{ php_request_shutdown_for_exec - */ -void php_request_shutdown_for_exec(void *dummy) -{ - TSRMLS_FETCH(); - - /* used to close fd's in the 3..255 range here, but it's problematic - */ - shutdown_memory_manager(1, 1 TSRMLS_CC); -} -/* }}} */ - -/* {{{ php_request_shutdown_for_hook - */ -void php_request_shutdown_for_hook(void *dummy) -{ - TSRMLS_FETCH(); - if (PG(modules_activated)) zend_try { - php_call_shutdown_functions(); - } zend_end_try(); - - if (PG(modules_activated)) { - zend_deactivate_modules(TSRMLS_C); - } - - zend_try { - int i; - - for (i = 0; i < NUM_TRACK_VARS; i++) { - if (PG(http_globals)[i]) { - zval_ptr_dtor(&PG(http_globals)[i]); - } - } - } zend_end_try(); - - zend_deactivate(TSRMLS_C); - - zend_try { - sapi_deactivate(TSRMLS_C); - } zend_end_try(); - - zend_try { - shutdown_memory_manager(CG(unclean_shutdown), 0 TSRMLS_CC); - } zend_end_try(); - - zend_try { - zend_unset_timeout(TSRMLS_C); - } zend_end_try(); -} - -/* }}} */ - -/* {{{ php_request_shutdown - */ -void php_request_shutdown(void *dummy) -{ - TSRMLS_FETCH(); - - /* EG(opline_ptr) points into nirvana and therefore cannot be safely accessed - * inside zend_executor callback functions. - */ - EG(opline_ptr) = NULL; - - zend_try { - zend_exec_finished(TSRMLS_C); - } zend_end_try(); - - zend_try { - php_end_ob_buffers((zend_bool)(SG(request_info).headers_only?0:1) TSRMLS_CC); - } zend_end_try(); - - zend_try { - sapi_send_headers(TSRMLS_C); - } zend_end_try(); - - if (PG(modules_activated)) zend_try { - php_call_shutdown_functions(); - } zend_end_try(); - - if (PG(modules_activated)) { - zend_deactivate_modules(TSRMLS_C); - } - - zend_try { - int i; - - for (i=0; i<NUM_TRACK_VARS; i++) { - if (PG(http_globals)[i]) { - zval_ptr_dtor(&PG(http_globals)[i]); - } - } - } zend_end_try(); - - - zend_deactivate(TSRMLS_C); - - zend_try { - sapi_deactivate(TSRMLS_C); - } zend_end_try(); - - zend_try { - shutdown_memory_manager(CG(unclean_shutdown), 0 TSRMLS_CC); - } zend_end_try(); - - zend_try { - zend_unset_timeout(TSRMLS_C); - } zend_end_try(); - -#ifdef PHP_WIN32 - CoUninitialize(); -#endif -} -/* }}} */ - - -/* {{{ php_body_write_wrapper - */ -static int php_body_write_wrapper(const char *str, uint str_length) -{ - TSRMLS_FETCH(); - return php_body_write(str, str_length TSRMLS_CC); -} -/* }}} */ - -#ifdef ZTS -/* {{{ core_globals_ctor - */ -static void core_globals_ctor(php_core_globals *core_globals TSRMLS_DC) -{ - memset(core_globals, 0, sizeof(*core_globals)); -} -/* }}} */ -#endif - -/* {{{ php_startup_extensions - */ -int php_startup_extensions(zend_module_entry **ptr, int count) -{ - zend_module_entry **end = ptr+count; - - while (ptr < end) { - if (*ptr) { - if (zend_startup_module(*ptr)==FAILURE) { - return FAILURE; - } - } - ptr++; - } - return SUCCESS; -} -/* }}} */ - - -/* {{{ php_module_startup - */ -int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint num_additional_modules) -{ - zend_utility_functions zuf; - zend_utility_values zuv; - int module_number=0; /* for REGISTER_INI_ENTRIES() */ - char *php_os; -#ifdef ZTS - zend_executor_globals *executor_globals; - void ***tsrm_ls; - - php_core_globals *core_globals; -#endif -#if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK)) - WORD wVersionRequested = MAKEWORD(2, 0); - WSADATA wsaData; -#endif -#ifdef PHP_WIN32 - { - DWORD dwVersion = GetVersion(); - - /* Get build numbers for Windows NT or Win95 */ - if (dwVersion < 0x80000000){ - php_os="WINNT"; - } else { - php_os="WIN32"; - } - } -#else - php_os=PHP_OS; -#endif - -#ifdef ZTS - tsrm_ls = ts_resource(0); -#endif - - sapi_initialize_empty_request(TSRMLS_C); - sapi_activate(TSRMLS_C); - - if (module_initialized) { - return SUCCESS; - } - - sapi_module = *sf; - - php_output_startup(); - php_output_activate(TSRMLS_C); - - zuf.error_function = php_error_cb; - zuf.printf_function = php_printf; - zuf.write_function = php_body_write_wrapper; - zuf.fopen_function = php_fopen_wrapper_for_zend; - zuf.message_handler = php_message_handler_for_zend; - zuf.block_interruptions = sapi_module.block_interruptions; - zuf.unblock_interruptions = sapi_module.unblock_interruptions; - zuf.get_configuration_directive = php_get_configuration_directive_for_zend; - zuf.ticks_function = php_run_ticks; - zuf.on_timeout = php_on_timeout; - zuf.stream_open_function = php_stream_open_for_zend; - zuf.vspprintf_function = vspprintf; - zend_startup(&zuf, NULL, 1); - -#ifdef ZTS - executor_globals = ts_resource(executor_globals_id); - ts_allocate_id(&core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, NULL); - core_globals = ts_resource(core_globals_id); -#endif - EG(bailout_set) = 0; - EG(error_reporting) = E_ALL & ~E_NOTICE; - - PG(header_is_being_sent) = 0; - SG(request_info).headers_only = 0; - SG(request_info).argv0 = NULL; - SG(request_info).argc=0; - SG(request_info).argv=(char **)NULL; - PG(connection_status) = PHP_CONNECTION_NORMAL; - PG(during_request_startup) = 0; - PG(last_error_message) = NULL; - PG(last_error_file) = NULL; - PG(last_error_lineno) = 0; - PG(error_handling) = EH_NORMAL; - PG(disable_functions) = NULL; - PG(disable_classes) = NULL; - -#if HAVE_SETLOCALE - setlocale(LC_CTYPE, ""); -#endif - -#if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK)) - /* start up winsock services */ - if (WSAStartup(wVersionRequested, &wsaData) != 0) { - php_printf("\nwinsock.dll unusable. %d\n", WSAGetLastError()); - return FAILURE; - } -#endif - - le_index_ptr = zend_register_list_destructors_ex(NULL, NULL, "index pointer", 0); - - - /* this will read in php.ini, set up the configuration parameters, - load zend extensions and register php function extensions - to be loaded later */ - if (php_init_config() == FAILURE) { - return FAILURE; - } - - REGISTER_INI_ENTRIES(); - zend_register_standard_ini_entries(TSRMLS_C); - - /* initialize stream wrappers registry - * (this uses configuration parameters from php.ini) - */ - if (php_init_stream_wrappers(module_number TSRMLS_CC) == FAILURE) { - php_printf("PHP: Unable to initialize stream url wrappers.\n"); - return FAILURE; - } - - /* initialize registry for images to be used in phpinfo() - (this uses configuration parameters from php.ini) - */ - if (php_init_info_logos() == FAILURE) { - php_printf("PHP: Unable to initialize info phpinfo logos.\n"); - return FAILURE; - } - - zuv.html_errors = 1; - zuv.import_use_extension = ".php"; - php_startup_auto_globals(TSRMLS_C); - zend_set_utility_values(&zuv); - php_startup_sapi_content_types(); - - REGISTER_MAIN_STRINGL_CONSTANT("PHP_VERSION", PHP_VERSION, sizeof(PHP_VERSION)-1, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS", php_os, strlen(php_os), CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_STRINGL_CONSTANT("PHP_SAPI", sapi_module.name, strlen(sapi_module.name), CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_STRINGL_CONSTANT("DEFAULT_INCLUDE_PATH", PHP_INCLUDE_PATH, sizeof(PHP_INCLUDE_PATH)-1, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_STRINGL_CONSTANT("PEAR_INSTALL_DIR", PEAR_INSTALLDIR, sizeof(PEAR_INSTALLDIR)-1, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_STRINGL_CONSTANT("PEAR_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_STRINGL_CONSTANT("PHP_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_STRINGL_CONSTANT("PHP_PREFIX", PHP_PREFIX, sizeof(PHP_PREFIX)-1, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINDIR", PHP_BINDIR, sizeof(PHP_BINDIR)-1, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_STRINGL_CONSTANT("PHP_LIBDIR", PHP_LIBDIR, sizeof(PHP_LIBDIR)-1, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_STRINGL_CONSTANT("PHP_DATADIR", PHP_DATADIR, sizeof(PHP_DATADIR)-1, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_STRINGL_CONSTANT("PHP_SYSCONFDIR", PHP_SYSCONFDIR, sizeof(PHP_SYSCONFDIR)-1, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_STRINGL_CONSTANT("PHP_LOCALSTATEDIR", PHP_LOCALSTATEDIR, sizeof(PHP_LOCALSTATEDIR)-1, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_PATH", PHP_CONFIG_FILE_PATH, sizeof(PHP_CONFIG_FILE_PATH)-1, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_SCAN_DIR", PHP_CONFIG_FILE_SCAN_DIR, sizeof(PHP_CONFIG_FILE_SCAN_DIR)-1, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_STRINGL_CONSTANT("PHP_SHLIB_SUFFIX", PHP_SHLIB_SUFFIX, sizeof(PHP_SHLIB_SUFFIX)-1, CONST_PERSISTENT | CONST_CS); - php_output_register_constants(TSRMLS_C); - php_rfc1867_register_constants(TSRMLS_C); - - if (php_startup_ticks(TSRMLS_C) == FAILURE) { - php_printf("Unable to start PHP ticks\n"); - return FAILURE; - } - - /* startup extensions staticly compiled in */ - if (php_startup_internal_extensions() == FAILURE) { - php_printf("Unable to start builtin modules\n"); - return FAILURE; - } - /* start additional PHP extensions */ - php_startup_extensions(&additional_modules, num_additional_modules); - - - /* load and startup extensions compiled as shared objects (aka DLLs) - as requested by php.ini entries - theese are loaded after initialization of internal extensions - as extensions *might* rely on things from ext/standard - which is always an internal extension and to be initialized - ahead of all other internals - */ - php_ini_delayed_modules_startup(TSRMLS_C); - - /* disable certain classes and functions as requested by php.ini */ - php_disable_functions(TSRMLS_C); - php_disable_classes(TSRMLS_C); - - /* start Zend extensions */ - zend_startup_extensions(); - -#ifdef ZTS - zend_post_startup(TSRMLS_C); -#endif - - /* */ - module_initialized = 1; - sapi_deactivate(TSRMLS_C); - module_startup = 0; - - /* we're done */ - return SUCCESS; -} -/* }}} */ - -void php_module_shutdown_for_exec() -{ - /* used to close fd's in the range 3.255 here, but it's problematic */ -} - -/* {{{ php_module_shutdown_wrapper - */ -int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals) -{ - TSRMLS_FETCH(); - php_module_shutdown(TSRMLS_C); - return SUCCESS; -} -/* }}} */ - -/* {{{ php_module_shutdown - */ -void php_module_shutdown(TSRMLS_D) -{ - int module_number=0; /* for UNREGISTER_INI_ENTRIES() */ - - module_shutdown = 1; - - if (!module_initialized) { - return; - } - -#if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK)) - /*close winsock */ - WSACleanup(); -#endif - - php_shutdown_ticks(TSRMLS_C); - sapi_flush(TSRMLS_C); - - zend_shutdown(TSRMLS_C); - - php_shutdown_stream_wrappers(module_number TSRMLS_CC); - - php_shutdown_info_logos(); - UNREGISTER_INI_ENTRIES(); - - /* close down the ini config */ - php_shutdown_config(); - -#ifndef ZTS - zend_ini_shutdown(TSRMLS_C); - shutdown_memory_manager(CG(unclean_shutdown), 1 TSRMLS_CC); -#endif - - module_initialized = 0; - if (PG(last_error_message)) { - free(PG(last_error_message)); - } - if (PG(last_error_file)) { - free(PG(last_error_file)); - } - if (PG(disable_functions)) { - free(PG(disable_functions)); - } - if (PG(disable_classes)) { - free(PG(disable_classes)); - } -} -/* }}} */ - - -/* {{{ php_execute_script - */ -PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC) -{ - zend_file_handle *prepend_file_p, *append_file_p; - zend_file_handle prepend_file = {0}, append_file = {0}; -#if HAVE_BROKEN_GETCWD - int old_cwd_fd = -1; -#else - char *old_cwd; -#endif - char *old_primary_file_path = NULL; - int retval = 0; - - EG(exit_status) = 0; - if (php_handle_special_queries(TSRMLS_C)) { - return 0; - } -#ifndef HAVE_BROKEN_GETCWD -# define OLD_CWD_SIZE 4096 - old_cwd = do_alloca(OLD_CWD_SIZE); - old_cwd[0] = '\0'; -#endif - - zend_try { -#ifdef PHP_WIN32 - UpdateIniFromRegistry(primary_file->filename TSRMLS_CC); -#endif - - PG(during_request_startup) = 0; - - if (primary_file->type == ZEND_HANDLE_FILENAME - && primary_file->filename) { -#if HAVE_BROKEN_GETCWD - /* this looks nasty to me */ - old_cwd_fd = open(".", 0); -#else - VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1); -#endif - VCWD_CHDIR_FILE(primary_file->filename); - } - - if (primary_file->filename) { - char realfile[MAXPATHLEN]; - int realfile_len; - int dummy = 1; - if (VCWD_REALPATH(primary_file->filename, realfile)) { - realfile_len = strlen(realfile); - zend_hash_add(&EG(included_files), realfile, realfile_len+1, (void *)&dummy, sizeof(int), NULL); - if (strncmp(realfile, primary_file->filename, realfile_len)) { - old_primary_file_path = primary_file->filename; - primary_file->filename = realfile; - } - } - } - - if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) { - prepend_file.filename = PG(auto_prepend_file); - prepend_file.opened_path = NULL; - prepend_file.free_filename = 0; - prepend_file.type = ZEND_HANDLE_FILENAME; - prepend_file_p = &prepend_file; - } else { - prepend_file_p = NULL; - } - - if (PG(auto_append_file) && PG(auto_append_file)[0]) { - append_file.filename = PG(auto_append_file); - append_file.opened_path = NULL; - append_file.free_filename = 0; - append_file.type = ZEND_HANDLE_FILENAME; - append_file_p = &append_file; - } else { - append_file_p = NULL; - } -#ifdef PHP_WIN32 - zend_unset_timeout(TSRMLS_C); -#endif - zend_set_timeout(INI_INT("max_execution_time")); - retval = (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 3, prepend_file_p, primary_file, append_file_p) == SUCCESS); - - if (old_primary_file_path) { - primary_file->filename = old_primary_file_path; - } - - } zend_end_try(); - -#if HAVE_BROKEN_GETCWD - if (old_cwd_fd != -1) { - fchdir(old_cwd_fd); - close(old_cwd_fd); - } -#else - if (old_cwd[0] != '\0') { - VCWD_CHDIR(old_cwd); - } - free_alloca(old_cwd); -#endif - return retval; -} -/* }}} */ - -/* {{{ php_execute_simple_script - */ -PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval **ret TSRMLS_DC) -{ - char *old_cwd; - - EG(exit_status) = 0; -#define OLD_CWD_SIZE 4096 - old_cwd = do_alloca(OLD_CWD_SIZE); - old_cwd[0] = '\0'; - - zend_try { -#ifdef PHP_WIN32 - UpdateIniFromRegistry(primary_file->filename TSRMLS_CC); -#endif - - PG(during_request_startup) = 0; - - if (primary_file->type == ZEND_HANDLE_FILENAME && primary_file->filename) { - VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1); - VCWD_CHDIR_FILE(primary_file->filename); - } - zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, ret, 1, primary_file); - } zend_end_try(); - - if (old_cwd[0] != '\0') { - VCWD_CHDIR(old_cwd); - } - - free_alloca(old_cwd); - return EG(exit_status); -} -/* }}} */ - -/* {{{ php_handle_aborted_connection - */ -PHPAPI void php_handle_aborted_connection(void) -{ - TSRMLS_FETCH(); - - PG(connection_status) = PHP_CONNECTION_ABORTED; - php_output_set_status(0 TSRMLS_CC); - - if (!PG(ignore_user_abort)) { - zend_bailout(); - } -} -/* }}} */ - -/* {{{ php_handle_auth_data - */ -PHPAPI int php_handle_auth_data(const char *auth TSRMLS_DC) -{ - int ret = -1; - - if (auth && auth[0] != '\0' && strncmp(auth, "Basic ", 6) == 0) { - char *pass; - char *user; - - user = php_base64_decode(auth + 6, strlen(auth) - 6, NULL); - if (user) { - pass = strchr(user, ':'); - if (pass) { - *pass++ = '\0'; - SG(request_info).auth_user = user; - SG(request_info).auth_password = estrdup(pass); - ret = 0; - } else { - efree(user); - } - } - } - - if (ret == -1) { - SG(request_info).auth_user = SG(request_info).auth_password = NULL; - } - - return ret; -} -/* }}} */ - -/* {{{ php_lint_script - */ -PHPAPI int php_lint_script(zend_file_handle *file TSRMLS_DC) -{ - zend_op_array *op_array; - - zend_try { - op_array = zend_compile_file(file, ZEND_INCLUDE TSRMLS_CC); - zend_destroy_file_handle(file TSRMLS_CC); - - if (op_array) { - destroy_op_array(op_array TSRMLS_CC); - efree(op_array); - return SUCCESS; - } else { - return FAILURE; - } - } zend_end_try(); - - return FAILURE; -} -/* }}} */ - -#ifdef PHP_WIN32 -/* {{{ dummy_indent - just so that this symbol gets exported... */ -PHPAPI void dummy_indent() -{ - zend_indent(); -} -/* }}} */ -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/mergesort.c b/main/mergesort.c deleted file mode 100644 index 117f859e94..0000000000 --- a/main/mergesort.c +++ /dev/null @@ -1,363 +0,0 @@ -/*- - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Peter McIlroy. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* $Id$ */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)merge.c 8.2 (Berkeley) 2/14/94"; -#endif /* LIBC_SCCS and not lint */ - -/* - * Hybrid exponential search/linear search merge sort with hybrid - * natural/pairwise first pass. Requires about .3% more comparisons - * for random data than LSMS with pairwise first pass alone. - * It works for objects as small as two bytes. - */ - -#define NATURAL -#define THRESHOLD 16 /* Best choice for natural merge cut-off. */ - -/* #define NATURAL to get hybrid natural merge. - * (The default is pairwise merging.) - */ - -#include <sys/types.h> - -#include <errno.h> -#include <stdlib.h> -#include <string.h> - -#include "php.h" - -#ifdef PHP_WIN32 -#include <winsock2.h> /* Includes definition for u_char */ -#endif - -#if defined(NETWARE) && !defined(NEW_LIBC) -/*#include <ws2nlm.h>*/ -#include <sys/socket.h> -#endif - -static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC); -static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC); - -#define ISIZE sizeof(int) -#define PSIZE sizeof(u_char *) -#define ICOPY_LIST(src, dst, last) \ - do \ - *(int*)dst = *(int*)src, src += ISIZE, dst += ISIZE; \ - while(src < last) -#define ICOPY_ELT(src, dst, i) \ - do \ - *(int*) dst = *(int*) src, src += ISIZE, dst += ISIZE; \ - while (i -= ISIZE) - -#define CCOPY_LIST(src, dst, last) \ - do \ - *dst++ = *src++; \ - while (src < last) -#define CCOPY_ELT(src, dst, i) \ - do \ - *dst++ = *src++; \ - while (i -= 1) - -/* - * Find the next possible pointer head. (Trickery for forcing an array - * to do double duty as a linked list when objects do not align with word - * boundaries. - */ -/* Assumption: PSIZE is a power of 2. */ -#define EVAL(p) (u_char **) \ - ((u_char *)0 + \ - (((u_char *)p + PSIZE - 1 - (u_char *) 0) & ~(PSIZE - 1))) - -/* {{{ php_mergesort - * Arguments are as for qsort. - */ -int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC) -{ - register unsigned int i; - register int sense; - int big, iflag; - register u_char *f1, *f2, *t, *b, *tp2, *q, *l1, *l2; - u_char *list2, *list1, *p2, *p, *last, **p1; - - if (size < PSIZE / 2) { /* Pointers must fit into 2 * size. */ - errno = EINVAL; - return (-1); - } - - if (nmemb == 0) - return (0); - - /* - * XXX - * Stupid subtraction for the Cray. - */ - iflag = 0; - if (!(size % ISIZE) && !(((char *)base - (char *)0) % ISIZE)) - iflag = 1; - - if ((list2 = malloc(nmemb * size + PSIZE)) == NULL) - return (-1); - - list1 = base; - setup(list1, list2, nmemb, size, cmp TSRMLS_CC); - last = list2 + nmemb * size; - i = big = 0; - while (*EVAL(list2) != last) { - l2 = list1; - p1 = EVAL(list1); - for (tp2 = p2 = list2; p2 != last; p1 = EVAL(l2)) { - p2 = *EVAL(p2); - f1 = l2; - f2 = l1 = list1 + (p2 - list2); - if (p2 != last) - p2 = *EVAL(p2); - l2 = list1 + (p2 - list2); - while (f1 < l1 && f2 < l2) { - if ((*cmp)(f1, f2 TSRMLS_CC) <= 0) { - q = f2; - b = f1, t = l1; - sense = -1; - } else { - q = f1; - b = f2, t = l2; - sense = 0; - } - if (!big) { /* here i = 0 */ - while ((b += size) < t && cmp(q, b TSRMLS_CC) >sense) - if (++i == 6) { - big = 1; - goto EXPONENTIAL; - } - } else { -EXPONENTIAL: for (i = size; ; i <<= 1) - if ((p = (b + i)) >= t) { - if ((p = t - size) > b && - (*cmp)(q, p TSRMLS_CC) <= sense) - t = p; - else - b = p; - break; - } else if ((*cmp)(q, p TSRMLS_CC) <= sense) { - t = p; - if (i == size) - big = 0; - goto FASTCASE; - } else - b = p; - while (t > b+size) { - i = (((t - b) / size) >> 1) * size; - if ((*cmp)(q, p = b + i TSRMLS_CC) <= sense) - t = p; - else - b = p; - } - goto COPY; -FASTCASE: while (i > size) - if ((*cmp)(q, - p = b + (i >>= 1) TSRMLS_CC) <= sense) - t = p; - else - b = p; -COPY: b = t; - } - i = size; - if (q == f1) { - if (iflag) { - ICOPY_LIST(f2, tp2, b); - ICOPY_ELT(f1, tp2, i); - } else { - CCOPY_LIST(f2, tp2, b); - CCOPY_ELT(f1, tp2, i); - } - } else { - if (iflag) { - ICOPY_LIST(f1, tp2, b); - ICOPY_ELT(f2, tp2, i); - } else { - CCOPY_LIST(f1, tp2, b); - CCOPY_ELT(f2, tp2, i); - } - } - } - if (f2 < l2) { - if (iflag) - ICOPY_LIST(f2, tp2, l2); - else - CCOPY_LIST(f2, tp2, l2); - } else if (f1 < l1) { - if (iflag) - ICOPY_LIST(f1, tp2, l1); - else - CCOPY_LIST(f1, tp2, l1); - } - *p1 = l2; - } - tp2 = list1; /* swap list1, list2 */ - list1 = list2; - list2 = tp2; - last = list2 + nmemb*size; - } - if (base == list2) { - memmove(list2, list1, nmemb*size); - list2 = list1; - } - free(list2); - return (0); -} -/* }}} */ - -#define swap(a, b) { \ - s = b; \ - i = size; \ - do { \ - tmp = *a; *a++ = *s; *s++ = tmp; \ - } while (--i); \ - a -= size; \ - } -#define reverse(bot, top) { \ - s = top; \ - do { \ - i = size; \ - do { \ - tmp = *bot; *bot++ = *s; *s++ = tmp; \ - } while (--i); \ - s -= size2; \ - } while(bot < s); \ -} - -/* {{{ setup - * Optional hybrid natural/pairwise first pass. Eats up list1 in runs of - * increasing order, list2 in a corresponding linked list. Checks for runs - * when THRESHOLD/2 pairs compare with same sense. (Only used when NATURAL - * is defined. Otherwise simple pairwise merging is used.) - */ -static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC) -{ - int i, length, size2, tmp, sense; - u_char *f1, *f2, *s, *l2, *last, *p2; - - size2 = size*2; - if (n <= 5) { - insertionsort(list1, n, size, cmp TSRMLS_CC); - *EVAL(list2) = (u_char*) list2 + n*size; - return; - } - /* - * Avoid running pointers out of bounds; limit n to evens - * for simplicity. - */ - i = 4 + (n & 1); - insertionsort(list1 + (n - i) * size, i, size, cmp TSRMLS_CC); - last = list1 + size * (n - i); - *EVAL(list2 + (last - list1)) = list2 + n * size; - -#ifdef NATURAL - p2 = list2; - f1 = list1; - sense = (cmp(f1, f1 + size TSRMLS_CC) > 0); - for (; f1 < last; sense = !sense) { - length = 2; - /* Find pairs with same sense. */ - for (f2 = f1 + size2; f2 < last; f2 += size2) { - if ((cmp(f2, f2+ size TSRMLS_CC) > 0) != sense) - break; - length += 2; - } - if (length < THRESHOLD) { /* Pairwise merge */ - do { - p2 = *EVAL(p2) = f1 + size2 - list1 + list2; - if (sense > 0) - swap (f1, f1 + size); - } while ((f1 += size2) < f2); - } else { /* Natural merge */ - l2 = f2; - for (f2 = f1 + size2; f2 < l2; f2 += size2) { - if ((cmp(f2-size, f2 TSRMLS_CC) > 0) != sense) { - p2 = *EVAL(p2) = f2 - list1 + list2; - if (sense > 0) - reverse(f1, f2-size); - f1 = f2; - } - } - if (sense > 0) - reverse (f1, f2-size); - f1 = f2; - if (f2 < last || cmp(f2 - size, f2 TSRMLS_CC) > 0) - p2 = *EVAL(p2) = f2 - list1 + list2; - else - p2 = *EVAL(p2) = list2 + n*size; - } - } -#else /* pairwise merge only. */ - for (f1 = list1, p2 = list2; f1 < last; f1 += size2) { - p2 = *EVAL(p2) = p2 + size2; - if (cmp (f1, f1 + size TSRMLS_CC) > 0) - swap(f1, f1 + size); - } -#endif /* NATURAL */ -} -/* }}} */ - -/* {{{ insertionsort - * This is to avoid out-of-bounds addresses in sorting the - * last 4 elements. - */ -static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC) -{ - u_char *ai, *s, *t, *u, tmp; - int i; - - for (ai = a+size; --n >= 1; ai += size) - for (t = ai; t > a; t -= size) { - u = t - size; - if (cmp(u, t TSRMLS_CC) <= 0) - break; - swap(u, t); - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/main/network.c b/main/network.c deleted file mode 100644 index 42245eab89..0000000000 --- a/main/network.c +++ /dev/null @@ -1,1034 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Stig Venaas <venaas@uninett.no> | - | Streams work by Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/*#define DEBUG_MAIN_NETWORK 1*/ - -#include "php.h" - -#include <stddef.h> - -#ifdef PHP_WIN32 -#define O_RDONLY _O_RDONLY -#include "win32/param.h" -#elif defined(NETWARE) -#ifdef NEW_LIBC -#include <sys/timeval.h> -#include <sys/param.h> -#else -#include "netware/time_nw.h" -#endif -#else -#include <sys/param.h> -#endif - -#include <sys/types.h> -#if HAVE_SYS_SOCKET_H -#include <sys/socket.h> -#endif - -#ifndef _FCNTL_H -#include <fcntl.h> -#endif - -#ifdef HAVE_SYS_SELECT_H -#include <sys/select.h> -#endif -#if HAVE_SYS_POLL_H -#include <sys/poll.h> -#endif - -#if defined(NETWARE) -#ifdef USE_WINSOCK -/*#include <ws2nlm.h>*/ -#include <novsock2.h> -#else -/* New headers for socket stuff */ -#ifdef NEW_LIBC -#include <netinet/in.h> -#include <netdb.h> -#include <sys/select.h> -#endif -#include <sys/socket.h> -#endif -#elif !defined(PHP_WIN32) -#include <netinet/in.h> -#include <netdb.h> -#if HAVE_ARPA_INET_H -#include <arpa/inet.h> -#endif -#endif - -#ifndef HAVE_INET_ATON -int inet_aton(const char *, struct in_addr *); -#endif - -#include "php_network.h" - -#if defined(PHP_WIN32) || defined(__riscos__) || defined(NETWARE) -#undef AF_UNIX -#endif - -#if defined(AF_UNIX) -#include <sys/un.h> -#endif - -#include "ext/standard/file.h" - -#ifdef PHP_WIN32 -# include "win32/time.h" -# define SOCK_ERR INVALID_SOCKET -# define SOCK_CONN_ERR SOCKET_ERROR -# define PHP_TIMEOUT_ERROR_VALUE WSAETIMEDOUT -#else -# define SOCK_ERR -1 -# define SOCK_CONN_ERR -1 -# define PHP_TIMEOUT_ERROR_VALUE ETIMEDOUT -#endif - -#if HAVE_GETADDRINFO -#ifdef HAVE_GAI_STRERROR -# define PHP_GAI_STRERROR(x) (gai_strerror(x)) -#else -# define PHP_GAI_STRERROR(x) (php_gai_strerror(x)) -/* {{{ php_gai_strerror - */ -static char *php_gai_strerror(int code) -{ - static struct { - int code; - const char *msg; - } values[] = { -# ifdef EAI_ADDRFAMILY - {EAI_ADDRFAMILY, "Address family for hostname not supported"}, -# endif - {EAI_AGAIN, "Temporary failure in name resolution"}, - {EAI_BADFLAGS, "Bad value for ai_flags"}, - {EAI_FAIL, "Non-recoverable failure in name resolution"}, - {EAI_FAMILY, "ai_family not supported"}, - {EAI_MEMORY, "Memory allocation failure"}, -# ifdef EAI_NODATA - {EAI_NODATA, "No address associated with hostname"}, -# endif - {EAI_NONAME, "Name or service not known"}, - {EAI_SERVICE, "Servname not supported for ai_socktype"}, - {EAI_SOCKTYPE, "ai_socktype not supported"}, - {EAI_SYSTEM, "System error"}, - {0, NULL} - }; - int i; - - for (i = 0; values[i].msg != NULL; i++) { - if (values[i].code == code) { - return (char *)values[i].msg; - } - } - - return "Unknown error"; -} -/* }}} */ -#endif -#endif - -/* {{{ php_network_freeaddresses - */ -static void php_network_freeaddresses(struct sockaddr **sal) -{ - struct sockaddr **sap; - - if (sal == NULL) - return; - for (sap = sal; *sap != NULL; sap++) - efree(*sap); - efree(sal); -} -/* }}} */ - -/* {{{ php_network_getaddresses - * Returns number of addresses, 0 for none/error - */ -static int php_network_getaddresses(const char *host, int socktype, struct sockaddr ***sal, char **error_string TSRMLS_DC) -{ - struct sockaddr **sap; - int n; -#if HAVE_GETADDRINFO - static int ipv6_borked = -1; /* the way this is used *is* thread safe */ - struct addrinfo hints, *res, *sai; -#else - struct hostent *host_info; - struct in_addr in; -#endif - - if (host == NULL) { - return 0; - } -#if HAVE_GETADDRINFO - memset(&hints, '\0', sizeof(hints)); - - hints.ai_family = AF_INET; /* default to regular inet (see below) */ - hints.ai_socktype = socktype; - -# if HAVE_IPV6 - /* probe for a working IPv6 stack; even if detected as having v6 at compile - * time, at runtime some stacks are slow to resolve or have other issues - * if they are not correctly configured. - * static variable use is safe here since simple store or fetch operations - * are atomic and because the actual probe process is not in danger of - * collisions or race conditions. */ - if (ipv6_borked == -1) { - int s; - - s = socket(PF_INET6, SOCK_DGRAM, 0); - if (s == SOCK_ERR) { - ipv6_borked = 1; - } else { - ipv6_borked = 0; - closesocket(s); - } - } - hints.ai_family = ipv6_borked ? AF_INET : AF_UNSPEC; -# endif - - if ((n = getaddrinfo(host, NULL, &hints, &res))) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "php_network_getaddresses: getaddrinfo failed: %s", PHP_GAI_STRERROR(n)); - return 0; - } else if (res == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "php_network_getaddresses: getaddrinfo failed (null result pointer)"); - return 0; - } - - sai = res; - for (n = 1; (sai = sai->ai_next) != NULL; n++) - ; - - *sal = safe_emalloc((n + 1), sizeof(*sal), 0); - sai = res; - sap = *sal; - - do { - *sap = emalloc(sai->ai_addrlen); - memcpy(*sap, sai->ai_addr, sai->ai_addrlen); - sap++; - } while ((sai = sai->ai_next) != NULL); - - freeaddrinfo(res); -#else - if (!inet_aton(host, &in)) { - /* XXX NOT THREAD SAFE (is safe under win32) */ - host_info = gethostbyname(host); - if (host_info == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "php_network_getaddresses: gethostbyname failed"); - return 0; - } - in = *((struct in_addr *) host_info->h_addr); - } - - *sal = safe_emalloc(2, sizeof(*sal), 0); - sap = *sal; - *sap = emalloc(sizeof(struct sockaddr_in)); - (*sap)->sa_family = AF_INET; - ((struct sockaddr_in *)*sap)->sin_addr = in; - sap++; - n = 1; -#endif - - *sap = NULL; - return n; -} -/* }}} */ - -#ifndef O_NONBLOCK -#define O_NONBLOCK O_NDELAY -#endif - -#if !defined(__BEOS__) -# define HAVE_NON_BLOCKING_CONNECT 1 -# ifdef PHP_WIN32 -typedef u_long php_non_blocking_flags_t; -# define SET_SOCKET_BLOCKING_MODE(sock, save) \ - save = TRUE; ioctlsocket(sock, FIONBIO, &save) -# define RESTORE_SOCKET_BLOCKING_MODE(sock, save) \ - ioctlsocket(sock, FIONBIO, &save) -# else -typedef int php_non_blocking_flags_t; -# define SET_SOCKET_BLOCKING_MODE(sock, save) \ - save = fcntl(sock, F_GETFL, 0); \ - fcntl(sock, F_SETFL, save | O_NONBLOCK) -# define RESTORE_SOCKET_BLOCKING_MODE(sock, save) \ - fcntl(sock, F_SETFL, save) -# endif -#endif - -/* Connect to a socket using an interruptible connect with optional timeout. - * Optionally, the connect can be made asynchronously, which will implicitly - * enable non-blocking mode on the socket. - * */ -/* {{{ php_network_connect_socket */ -PHPAPI int php_network_connect_socket(php_socket_t sockfd, - const struct sockaddr *addr, - socklen_t addrlen, - int asynchronous, - struct timeval *timeout, - char **error_string, - int *error_code) -{ -#if HAVE_NON_BLOCKING_CONNECT - php_non_blocking_flags_t orig_flags; - int n; - int error = 0; - socklen_t len; - int ret = 0; - fd_set rset; - fd_set wset; - fd_set eset; - - SET_SOCKET_BLOCKING_MODE(sockfd, orig_flags); - - if ((n = connect(sockfd, addr, addrlen)) < 0) { - error = php_socket_errno(); - - if (error_code) { - *error_code = error; - } - - if (error != EINPROGRESS) { - if (error_string) { - *error_string = php_socket_strerror(error, NULL, 0); - } - - return -1; - } - if (asynchronous && error == EINPROGRESS) { - /* this is fine by us */ - return 0; - } - } - - if (n == 0) { - goto ok; - } - - FD_ZERO(&rset); - FD_ZERO(&eset); - FD_SET(sockfd, &rset); - FD_SET(sockfd, &eset); - - wset = rset; - - if ((n = select(sockfd + 1, &rset, &wset, &eset, timeout)) == 0) { - error = PHP_TIMEOUT_ERROR_VALUE; - } - - if(FD_ISSET(sockfd, &rset) || FD_ISSET(sockfd, &wset)) { - len = sizeof(error); - /* - BSD-derived systems set errno correctly - Solaris returns -1 from getsockopt in case of error - */ - if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (char*)&error, &len) < 0) { - ret = -1; - } - } else { - /* whoops: sockfd has disappeared */ - ret = -1; - } - -ok: - if (!asynchronous) { - /* back to blocking mode */ - RESTORE_SOCKET_BLOCKING_MODE(sockfd, orig_flags); - } - - if (error_code) { - *error_code = error; - } - - if (error && error_string) { - *error_string = php_socket_strerror(error, NULL, 0); - ret = -1; - } - return ret; -#else - if (asynchronous) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Asynchronous connect() not supported on this platform"); - } - return connect(sockfd, addr, addrlen); -#endif -} -/* }}} */ - -/* {{{ sub_times */ -static inline void sub_times(struct timeval a, struct timeval b, struct timeval *result) -{ - result->tv_usec = a.tv_usec - b.tv_usec; - if (result->tv_usec < 0L) { - a.tv_sec--; - result->tv_usec += 1000000L; - } - result->tv_sec = a.tv_sec - b.tv_sec; - if (result->tv_sec < 0L) { - result->tv_sec++; - result->tv_usec -= 1000000L; - } -} -/* }}} */ - -/* Bind to a local IP address. - * Returns the bound socket, or -1 on failure. - * */ -/* {{{ php_network_bind_socket_to_local_addr */ -php_socket_t php_network_bind_socket_to_local_addr(const char *host, unsigned port, - int socktype, char **error_string, int *error_code - TSRMLS_DC) -{ - int num_addrs, n, err = 0; - php_socket_t sock; - struct sockaddr **sal, **psal, *sa; - socklen_t socklen; - - num_addrs = php_network_getaddresses(host, socktype, &psal, error_string TSRMLS_CC); - - if (num_addrs == 0) { - /* could not resolve address(es) */ - return -1; - } - - for (sal = psal; *sal != NULL; sal++) { - sa = *sal; - - /* create a socket for this address */ - sock = socket(sa->sa_family, socktype, 0); - - if (sock == SOCK_ERR) { - continue; - } - - switch (sa->sa_family) { -#if HAVE_GETADDRINFO && HAVE_IPV6 - case AF_INET6: - ((struct sockaddr_in6 *)sa)->sin6_family = sa->sa_family; - ((struct sockaddr_in6 *)sa)->sin6_port = htons(port); - socklen = sizeof(struct sockaddr_in6); - break; -#endif - case AF_INET: - ((struct sockaddr_in *)sa)->sin_family = sa->sa_family; - ((struct sockaddr_in *)sa)->sin_port = htons(port); - socklen = sizeof(struct sockaddr_in); - break; - default: - /* Unknown family */ - socklen = 0; - sa = NULL; - } - - if (sa) { - /* attempt to bind */ - -#ifdef SO_REUSEADDR - { - int val = 1; - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&val, sizeof(val)); - } -#endif - - n = bind(sock, sa, socklen); - - if (n != SOCK_CONN_ERR) { - goto bound; - } - - err = php_socket_errno(); - } - - close(sock); - } - sock = -1; - - if (error_code) { - *error_code = err; - } - if (error_string) { - *error_string = php_socket_strerror(err, NULL, 0); - } - -bound: - - php_network_freeaddresses(psal); - - return sock; - -} -/* }}} */ - -PHPAPI int php_network_parse_network_address_with_port(const char *addr, long addrlen, struct sockaddr *sa, socklen_t *sl TSRMLS_DC) -{ - char *colon; - char *tmp; - int ret = FAILURE; - short port; - struct sockaddr_in *in4 = (struct sockaddr_in*)sa; - struct sockaddr **psal; - int n; - char *errstr = NULL; -#if HAVE_IPV6 - struct sockaddr_in6 *in6 = (struct sockaddr_in6*)sa; -#endif - - if (*addr == '[') { - colon = memchr(addr + 1, ']', addrlen-1); - if (!colon || colon[1] != ':') { - return 0; - } - port = atoi(colon + 2); - addr++; - } else { - colon = memchr(addr, ':', addrlen); - port = atoi(colon + 1); - } - - tmp = estrndup(addr, colon - addr); - - /* first, try interpreting the address as a numeric address */ - -#if HAVE_IPV6 && HAVE_INET_PTON - if (inet_pton(AF_INET6, tmp, &in6->sin6_addr) > 0) { - in6->sin6_port = htons(port); - in6->sin6_family = AF_INET6; - *sl = sizeof(struct sockaddr_in6); - ret = SUCCESS; - goto out; - } -#endif - if (inet_aton(tmp, &in4->sin_addr) > 0) { - in4->sin_port = htons(port); - in4->sin_family = AF_INET; - *sl = sizeof(struct sockaddr_in); - ret = SUCCESS; - goto out; - } - - /* looks like we'll need to resolve it */ - n = php_network_getaddresses(tmp, SOCK_DGRAM, &psal, &errstr TSRMLS_CC); - - if (n == 0) { - if (errstr) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to resolve `%s': %s", tmp, errstr); - STR_FREE(errstr); - } - goto out; - } - - /* copy the details from the first item */ - switch ((*psal)->sa_family) { -#if HAVE_GETADDRINFO && HAVE_IPV6 - case AF_INET6: - *in6 = **(struct sockaddr_in6**)psal; - in6->sin6_port = htons(port); - *sl = sizeof(struct sockaddr_in6); - ret = SUCCESS; - break; -#endif - case AF_INET: - *in4 = **(struct sockaddr_in**)psal; - in4->sin_port = htons(port); - *sl = sizeof(struct sockaddr_in); - ret = SUCCESS; - break; - } - - php_network_freeaddresses(psal); - -out: - STR_FREE(tmp); - return ret; -} - - -PHPAPI void php_network_populate_name_from_sockaddr( - /* input address */ - struct sockaddr *sa, socklen_t sl, - /* output readable address */ - char **textaddr, long *textaddrlen, - /* output address */ - struct sockaddr **addr, - socklen_t *addrlen - TSRMLS_DC) -{ - if (addr) { - *addr = emalloc(sl); - memcpy(*addr, sa, sl); - *addrlen = sl; - } - - if (textaddr) { -#if HAVE_IPV6 && HAVE_INET_NTOP - char abuf[256]; -#endif - char *buf = NULL; - - switch (sa->sa_family) { - case AF_INET: - /* generally not thread safe, but it *is* thread safe under win32 */ - buf = inet_ntoa(((struct sockaddr_in*)sa)->sin_addr); - if (buf) { - *textaddrlen = strlen(buf); - *textaddr = estrndup(buf, *textaddrlen); - } - - break; - -#if HAVE_IPV6 && HAVE_INET_NTOP - case AF_INET6: - buf = (char*)inet_ntop(sa->sa_family, &((struct sockaddr_in6*)sa)->sin6_addr, (char *)&abuf, sizeof(abuf)); - if (buf) { - *textaddrlen = strlen(buf); - *textaddr = estrndup(buf, *textaddrlen); - } - - break; -#endif -#ifdef AF_UNIX - case AF_UNIX: - { - struct sockaddr_un *ua = (struct sockaddr_un*)sa; - - if (ua->sun_path[0] == '\0') { - /* abstract name */ - int len = strlen(ua->sun_path + 1) + 1; - *textaddrlen = len; - *textaddr = emalloc(len + 1); - memcpy(*textaddr, ua->sun_path, len); - (*textaddr)[len] = '\0'; - } else { - *textaddrlen = strlen(ua->sun_path); - *textaddr = estrndup(ua->sun_path, *textaddrlen); - } - } - break; -#endif - - } - - } -} - -PHPAPI int php_network_get_peer_name(php_socket_t sock, - char **textaddr, long *textaddrlen, - struct sockaddr **addr, - socklen_t *addrlen - TSRMLS_DC) -{ - php_sockaddr_storage sa; - socklen_t sl = sizeof(sa); - - if (getpeername(sock, (struct sockaddr*)&sa, &sl) == 0) { - php_network_populate_name_from_sockaddr((struct sockaddr*)&sa, sl, - textaddr, textaddrlen, - addr, addrlen - TSRMLS_CC); - return 0; - } - return -1; -} - -PHPAPI int php_network_get_sock_name(php_socket_t sock, - char **textaddr, long *textaddrlen, - struct sockaddr **addr, - socklen_t *addrlen - TSRMLS_DC) -{ - php_sockaddr_storage sa; - socklen_t sl = sizeof(sa); - - if (getsockname(sock, (struct sockaddr*)&sa, &sl) == 0) { - php_network_populate_name_from_sockaddr((struct sockaddr*)&sa, sl, - textaddr, textaddrlen, - addr, addrlen - TSRMLS_CC); - return 0; - } - return -1; - -} - - -/* Accept a client connection from a server socket, - * using an optional timeout. - * Returns the peer address in addr/addrlen (it will emalloc - * these, so be sure to efree the result). - * If you specify textaddr/textaddrlen, a text-printable - * version of the address will be emalloc'd and returned. - * */ - -/* {{{ php_network_accept_incoming */ -PHPAPI php_socket_t php_network_accept_incoming(php_socket_t srvsock, - char **textaddr, long *textaddrlen, - struct sockaddr **addr, - socklen_t *addrlen, - struct timeval *timeout, - char **error_string, - int *error_code - TSRMLS_DC) -{ - php_socket_t clisock = -1; - fd_set rset; - int error = 0, n; - php_sockaddr_storage sa; - socklen_t sl; - - FD_ZERO(&rset); - FD_SET(srvsock, &rset); - - n = select(srvsock + 1, &rset, NULL, NULL, timeout); - - if (n == 0) { - error = PHP_TIMEOUT_ERROR_VALUE; - } else if (n == -1) { - error = php_socket_errno(); - } else if (FD_ISSET(srvsock, &rset)) { - sl = sizeof(sa); - - clisock = accept(srvsock, (struct sockaddr*)&sa, &sl); - - if (clisock >= 0) { - php_network_populate_name_from_sockaddr((struct sockaddr*)&sa, sl, - textaddr, textaddrlen, - addr, addrlen - TSRMLS_CC); - } else { - error = php_socket_errno(); - } - } - - if (error_code) { - *error_code = error; - } - if (error_string) { - *error_string = php_socket_strerror(error, NULL, 0); - } - - return clisock; -} -/* }}} */ - - - -/* Connect to a remote host using an interruptible connect with optional timeout. - * Optionally, the connect can be made asynchronously, which will implicitly - * enable non-blocking mode on the socket. - * Returns the connected (or connecting) socket, or -1 on failure. - * */ - -/* {{{ php_network_connect_socket_to_host */ -php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short port, - int socktype, int asynchronous, struct timeval *timeout, char **error_string, - int *error_code - TSRMLS_DC) -{ - int num_addrs, n, fatal = 0; - php_socket_t sock; - struct sockaddr **sal, **psal, *sa; - struct timeval working_timeout; - socklen_t socklen; -#if HAVE_GETTIMEOFDAY - struct timeval limit_time, time_now; -#endif - - num_addrs = php_network_getaddresses(host, socktype, &psal, error_string TSRMLS_CC); - - if (num_addrs == 0) { - /* could not resolve address(es) */ - return -1; - } - - if (timeout) { - memcpy(&working_timeout, timeout, sizeof(working_timeout)); -#if HAVE_GETTIMEOFDAY - gettimeofday(&limit_time, NULL); - limit_time.tv_sec += working_timeout.tv_sec; - limit_time.tv_usec += working_timeout.tv_usec; - if (limit_time.tv_usec >= 1000000) { - limit_time.tv_usec -= 1000000; - limit_time.tv_sec++; - } -#endif - } - - for (sal = psal; !fatal && *sal != NULL; sal++) { - sa = *sal; - - /* create a socket for this address */ - sock = socket(sa->sa_family, socktype, 0); - - if (sock == SOCK_ERR) { - continue; - } - - switch (sa->sa_family) { -#if HAVE_GETADDRINFO && HAVE_IPV6 - case AF_INET6: - ((struct sockaddr_in6 *)sa)->sin6_family = sa->sa_family; - ((struct sockaddr_in6 *)sa)->sin6_port = htons(port); - socklen = sizeof(struct sockaddr_in6); - break; -#endif - case AF_INET: - ((struct sockaddr_in *)sa)->sin_family = sa->sa_family; - ((struct sockaddr_in *)sa)->sin_port = htons(port); - socklen = sizeof(struct sockaddr_in); - break; - default: - /* Unknown family */ - socklen = 0; - sa = NULL; - } - - if (sa) { - /* make a connection attempt */ - - n = php_network_connect_socket(sock, sa, socklen, asynchronous, - timeout ? &working_timeout : NULL, - error_string, error_code); - - if (n != SOCK_CONN_ERR) { - goto connected; - } - - /* adjust timeout for next attempt */ -#if HAVE_GETTIMEOFDAY - if (timeout) { - gettimeofday(&time_now, NULL); - - if (timercmp(&time_now, &limit_time, >=)) { - /* time limit expired; don't attempt any further connections */ - fatal = 1; - } else { - /* work out remaining time */ - sub_times(limit_time, time_now, &working_timeout); - } - } -#else - if (err == PHP_TIMEOUT_ERROR_VALUE) { - /* Don't even bother trying to connect to the next alternative; - * we have no way to determine how long we have already taken - * and it is quite likely that the next attempt will fail too. */ - fatal = 1; - } else { - /* re-use the same initial timeout. - * Not the best thing, but in practice it should be good-enough */ - if (timeout) { - memcpy(&working_timeout, timeout, sizeof(working_timeout)); - } - } -#endif - } - - close(sock); - } - sock = -1; - -connected: - - php_network_freeaddresses(psal); - - return sock; -} -/* }}} */ - -/* {{{ php_any_addr - * Fills the any (wildcard) address into php_sockaddr_storage - */ -PHPAPI void php_any_addr(int family, php_sockaddr_storage *addr, unsigned short port) -{ - memset(addr, 0, sizeof(php_sockaddr_storage)); - switch (family) { -#if HAVE_IPV6 - case AF_INET6: { - struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) addr; - sin6->sin6_family = AF_INET6; - sin6->sin6_port = htons(port); - sin6->sin6_addr = in6addr_any; - break; - } -#endif - case AF_INET: { - struct sockaddr_in *sin = (struct sockaddr_in *) addr; - sin->sin_family = AF_INET; - sin->sin_port = htons(port); - sin->sin_addr.s_addr = htonl(INADDR_ANY); - break; - } - } -} -/* }}} */ - -/* {{{ php_sockaddr_size - * Returns the size of struct sockaddr_xx for the family - */ -PHPAPI int php_sockaddr_size(php_sockaddr_storage *addr) -{ - switch (((struct sockaddr *)addr)->sa_family) { - case AF_INET: - return sizeof(struct sockaddr_in); -#if HAVE_IPV6 - case AF_INET6: - return sizeof(struct sockaddr_in6); -#endif -#ifdef AF_UNIX - case AF_UNIX: - return sizeof(struct sockaddr_un); -#endif - default: - return 0; - } -} -/* }}} */ - -/* Given a socket error code, if buf == NULL: - * emallocs storage for the error message and returns - * else - * sprintf message into provided buffer and returns buf - */ -/* {{{ php_socket_strerror */ -PHPAPI char *php_socket_strerror(long err, char *buf, size_t bufsize) -{ -#ifndef PHP_WIN32 - char *errstr; - - errstr = strerror(err); - if (buf == NULL) { - buf = estrdup(errstr); - } else { - strncpy(buf, errstr, bufsize); - } - return buf; -#else - char *sysbuf; - int free_it = 1; - - if (!FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - err, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)&sysbuf, - 0, - NULL)) { - free_it = 0; - sysbuf = "Unknown Error"; - } - - if (buf == NULL) { - buf = estrdup(sysbuf); - } else { - strncpy(buf, sysbuf, bufsize); - } - - if (free_it) { - LocalFree(sysbuf); - } - - return buf; -#endif -} -/* }}} */ - -/* deprecated */ -PHPAPI php_stream *_php_stream_sock_open_from_socket(php_socket_t socket, const char *persistent_id STREAMS_DC TSRMLS_DC) -{ - php_stream *stream; - php_netstream_data_t *sock; - - sock = pemalloc(sizeof(php_netstream_data_t), persistent_id ? 1 : 0); - memset(sock, 0, sizeof(php_netstream_data_t)); - - sock->is_blocked = 1; - sock->timeout.tv_sec = FG(default_socket_timeout); - sock->timeout.tv_usec = 0; - sock->socket = socket; - - stream = php_stream_alloc_rel(&php_stream_generic_socket_ops, sock, persistent_id, "r+"); - stream->flags |= PHP_STREAM_FLAG_AVOID_BLOCKING; - - if (stream == NULL) - pefree(sock, persistent_id ? 1 : 0); - - return stream; -} - -PHPAPI php_stream *_php_stream_sock_open_host(const char *host, unsigned short port, - int socktype, struct timeval *timeout, const char *persistent_id STREAMS_DC TSRMLS_DC) -{ - char *res; - long reslen; - php_stream *stream; - - reslen = spprintf(&res, 0, "tcp://%s:%d", host, port); - - stream = php_stream_xport_create(res, reslen, ENFORCE_SAFE_MODE | REPORT_ERRORS, - STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, persistent_id, timeout, NULL, NULL, NULL); - - efree(res); - - return stream; -} - -PHPAPI int php_set_sock_blocking(int socketd, int block TSRMLS_DC) -{ - int ret = SUCCESS; - int flags; - int myflag = 0; - -#ifdef PHP_WIN32 - /* with ioctlsocket, a non-zero sets nonblocking, a zero sets blocking */ - flags = !block; - if (ioctlsocket(socketd, FIONBIO, &flags)==SOCKET_ERROR){ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", WSAGetLastError()); - ret = FALSE; - } -#else - flags = fcntl(socketd, F_GETFL); -#ifdef O_NONBLOCK - myflag = O_NONBLOCK; /* POSIX version */ -#elif defined(O_NDELAY) - myflag = O_NDELAY; /* old non-POSIX version */ -#endif - if (!block) { - flags |= myflag; - } else { - flags &= ~myflag; - } - fcntl(socketd, F_SETFL, flags); -#endif - return ret; -} - - -/* - * Local variables: - * tab-width: 8 - * c-basic-offset: 8 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/output.c b/main/output.c deleted file mode 100644 index ff3e3a49b5..0000000000 --- a/main/output.c +++ /dev/null @@ -1,1079 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Zeev Suraski <zeev@zend.com> | - | Thies C. Arntzen <thies@thieso.net> | - | Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "ext/standard/head.h" -#include "ext/standard/basic_functions.h" -#include "ext/standard/url_scanner_ex.h" -#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB) -#include "ext/zlib/php_zlib.h" -#endif -#include "SAPI.h" - -#define OB_DEFAULT_HANDLER_NAME "default output handler" - -/* output functions */ -static int php_ub_body_write(const char *str, uint str_length TSRMLS_DC); -static int php_ub_body_write_no_header(const char *str, uint str_length TSRMLS_DC); -static int php_b_body_write(const char *str, uint str_length TSRMLS_DC); - -static int php_ob_init(uint initial_size, uint block_size, zval *output_handler, uint chunk_size, zend_bool erase TSRMLS_DC); -static void php_ob_append(const char *text, uint text_length TSRMLS_DC); -#if 0 -static void php_ob_prepend(const char *text, uint text_length); -#endif - -#ifdef ZTS -int output_globals_id; -#else -php_output_globals output_globals; -#endif - -/* {{{ php_default_output_func */ -static inline int php_default_output_func(const char *str, uint str_len TSRMLS_DC) -{ - fwrite(str, 1, str_len, stderr); - return str_len; -} -/* }}} */ - -/* {{{ php_output_init_globals */ -static void php_output_init_globals(php_output_globals *output_globals_p TSRMLS_DC) -{ - OG(php_body_write) = php_default_output_func; - OG(php_header_write) = php_default_output_func; - OG(implicit_flush) = 0; - OG(output_start_filename) = NULL; - OG(output_start_lineno) = 0; -} -/* }}} */ - - -/* {{{ php_output_startup - Start output layer */ -PHPAPI void php_output_startup(void) -{ -#ifdef ZTS - ts_allocate_id(&output_globals_id, sizeof(php_output_globals), (ts_allocate_ctor) php_output_init_globals, NULL); -#else - php_output_init_globals(&output_globals TSRMLS_CC); -#endif -} -/* }}} */ - - -/* {{{ php_output_activate - Initilize output global for activation */ -PHPAPI void php_output_activate(TSRMLS_D) -{ - OG(php_body_write) = php_ub_body_write; - OG(php_header_write) = sapi_module.ub_write; - OG(ob_nesting_level) = 0; - OG(ob_lock) = 0; - OG(disable_output) = 0; - OG(output_start_filename) = NULL; - OG(output_start_lineno) = 0; -} -/* }}} */ - - -/* {{{ php_output_set_status - Toggle output status. Do NOT use in application code, only in SAPIs where appropriate. */ -PHPAPI void php_output_set_status(zend_bool status TSRMLS_DC) -{ - OG(disable_output) = !status; -} -/* }}} */ - -/* {{{ php_output_register_constants */ -void php_output_register_constants(TSRMLS_D) -{ - REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_START", PHP_OUTPUT_HANDLER_START, CONST_CS | CONST_PERSISTENT); - REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_CONT", PHP_OUTPUT_HANDLER_CONT, CONST_CS | CONST_PERSISTENT); - REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_END", PHP_OUTPUT_HANDLER_END, CONST_CS | CONST_PERSISTENT); -} -/* }}} */ - - -/* {{{ php_body_wirte - * Write body part */ -PHPAPI int php_body_write(const char *str, uint str_length TSRMLS_DC) -{ - return OG(php_body_write)(str, str_length TSRMLS_CC); -} -/* }}} */ - -/* {{{ php_header_wirte - * Write HTTP header */ -PHPAPI int php_header_write(const char *str, uint str_length TSRMLS_DC) -{ - if (OG(disable_output)) { - return 0; - } else { - return OG(php_header_write)(str, str_length TSRMLS_CC); - } -} -/* }}} */ - -/* {{{ php_start_ob_buffer - * Start output buffering */ -PHPAPI int php_start_ob_buffer(zval *output_handler, uint chunk_size, zend_bool erase TSRMLS_DC) -{ - uint initial_size, block_size; - - if (OG(ob_lock)) { - if (SG(headers_sent) && !SG(request_info).headers_only) { - OG(php_body_write) = php_ub_body_write_no_header; - } else { - OG(php_body_write) = php_ub_body_write; - } - OG(ob_nesting_level) = 0; - php_error_docref("ref.outcontrol" TSRMLS_CC, E_ERROR, "Cannot use output buffering in output buffering display handlers"); - return FAILURE; - } - if (chunk_size > 0) { - if (chunk_size==1) { - chunk_size = 4096; - } - initial_size = (chunk_size*3/2); - block_size = chunk_size/2; - } else { - initial_size = 40*1024; - block_size = 10*1024; - } - return php_ob_init(initial_size, block_size, output_handler, chunk_size, erase TSRMLS_CC); -} -/* }}} */ - -/* {{{ php_start_ob_buffer_named - * Start output buffering */ -PHPAPI int php_start_ob_buffer_named(const char *output_handler_name, uint chunk_size, zend_bool erase TSRMLS_DC) -{ - zval *output_handler; - int result; - - ALLOC_INIT_ZVAL(output_handler); - Z_STRLEN_P(output_handler) = strlen(output_handler_name); /* this can be optimized */ - Z_STRVAL_P(output_handler) = estrndup(output_handler_name, Z_STRLEN_P(output_handler)); - Z_TYPE_P(output_handler) = IS_STRING; - result = php_start_ob_buffer(output_handler, chunk_size, erase TSRMLS_CC); - zval_dtor(output_handler); - FREE_ZVAL(output_handler); - return result; -} -/* }}} */ - -/* {{{ php_end_ob_buffer - * End output buffering (one level) */ -PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush TSRMLS_DC) -{ - char *final_buffer=NULL; - unsigned int final_buffer_length=0; - zval *alternate_buffer=NULL; - char *to_be_destroyed_buffer, *to_be_destroyed_handler_name; - char *to_be_destroyed_handled_output[2] = { 0, 0 }; - int status; - php_ob_buffer *prev_ob_buffer_p=NULL; - php_ob_buffer orig_ob_buffer; - - if (OG(ob_nesting_level)==0) { - return; - } - status = 0; - if (!OG(active_ob_buffer).status & PHP_OUTPUT_HANDLER_START) { - /* our first call */ - status |= PHP_OUTPUT_HANDLER_START; - } - if (just_flush) { - status |= PHP_OUTPUT_HANDLER_CONT; - } else { - status |= PHP_OUTPUT_HANDLER_END; - } - -#if 0 - { - FILE *fp; - fp = fopen("/tmp/ob_log", "a"); - fprintf(fp, "NestLevel: %d ObStatus: %d HandlerName: %s\n", OG(ob_nesting_level), status, OG(active_ob_buffer).handler_name); - fclose(fp); - } -#endif - - if (OG(active_ob_buffer).internal_output_handler) { - final_buffer = OG(active_ob_buffer).internal_output_handler_buffer; - final_buffer_length = OG(active_ob_buffer).internal_output_handler_buffer_size; - OG(active_ob_buffer).internal_output_handler(OG(active_ob_buffer).buffer, OG(active_ob_buffer).text_length, &final_buffer, &final_buffer_length, status TSRMLS_CC); - } else if (OG(active_ob_buffer).output_handler) { - zval **params[2]; - zval *orig_buffer; - zval *z_status; - - ALLOC_INIT_ZVAL(orig_buffer); - ZVAL_STRINGL(orig_buffer, OG(active_ob_buffer).buffer, OG(active_ob_buffer).text_length, 1); - orig_buffer->refcount=2; /* don't let call_user_function() destroy our buffer */ - orig_buffer->is_ref=1; - - ALLOC_INIT_ZVAL(z_status); - ZVAL_LONG(z_status, status); - - params[0] = &orig_buffer; - params[1] = &z_status; - OG(ob_lock) = 1; - - if (call_user_function_ex(CG(function_table), NULL, OG(active_ob_buffer).output_handler, &alternate_buffer, 2, params, 1, NULL TSRMLS_CC)==SUCCESS) { - if (!(Z_TYPE_P(alternate_buffer)==IS_BOOL && Z_BVAL_P(alternate_buffer)==0)) { - convert_to_string_ex(&alternate_buffer); - final_buffer = Z_STRVAL_P(alternate_buffer); - final_buffer_length = Z_STRLEN_P(alternate_buffer); - } - } - OG(ob_lock) = 0; - if (!just_flush) { - zval_ptr_dtor(&OG(active_ob_buffer).output_handler); - } - orig_buffer->refcount -=2; - if (orig_buffer->refcount <= 0) { /* free the zval */ - zval_dtor(orig_buffer); - FREE_ZVAL(orig_buffer); - } - zval_ptr_dtor(&z_status); - } - - if (!final_buffer) { - final_buffer = OG(active_ob_buffer).buffer; - final_buffer_length = OG(active_ob_buffer).text_length; - } - - if (OG(ob_nesting_level)==1) { /* end buffering */ - if (SG(headers_sent) && !SG(request_info).headers_only) { - OG(php_body_write) = php_ub_body_write_no_header; - } else { - OG(php_body_write) = php_ub_body_write; - } - } - - to_be_destroyed_buffer = OG(active_ob_buffer).buffer; - to_be_destroyed_handler_name = OG(active_ob_buffer).handler_name; - if (OG(active_ob_buffer).internal_output_handler - && (final_buffer != OG(active_ob_buffer).internal_output_handler_buffer) - && (final_buffer != OG(active_ob_buffer).buffer)) { - to_be_destroyed_handled_output[0] = final_buffer; - } - - if (!just_flush) { - if (OG(active_ob_buffer).internal_output_handler) { - to_be_destroyed_handled_output[1] = OG(active_ob_buffer).internal_output_handler_buffer; - } - } - if (OG(ob_nesting_level)>1) { /* restore previous buffer */ - zend_stack_top(&OG(ob_buffers), (void **) &prev_ob_buffer_p); - orig_ob_buffer = OG(active_ob_buffer); - OG(active_ob_buffer) = *prev_ob_buffer_p; - zend_stack_del_top(&OG(ob_buffers)); - if (!just_flush && OG(ob_nesting_level)==2) { /* destroy the stack */ - zend_stack_destroy(&OG(ob_buffers)); - } - } - OG(ob_nesting_level)--; - - if (send_buffer) { - OG(php_body_write)(final_buffer, final_buffer_length TSRMLS_CC); - } - - if (just_flush) { /* we restored the previous ob, return to the current */ - if (prev_ob_buffer_p) { - zend_stack_push(&OG(ob_buffers), &OG(active_ob_buffer), sizeof(php_ob_buffer)); - OG(active_ob_buffer) = orig_ob_buffer; - } - OG(ob_nesting_level)++; - } - - if (alternate_buffer) { - zval_ptr_dtor(&alternate_buffer); - } - - if (status & PHP_OUTPUT_HANDLER_END) { - efree(to_be_destroyed_handler_name); - } - if (!just_flush) { - efree(to_be_destroyed_buffer); - } else { - OG(active_ob_buffer).text_length = 0; - OG(active_ob_buffer).status |= PHP_OUTPUT_HANDLER_START; - OG(php_body_write) = php_b_body_write; - } - if (to_be_destroyed_handled_output[0]) { - efree(to_be_destroyed_handled_output[0]); - } - if (to_be_destroyed_handled_output[1]) { - efree(to_be_destroyed_handled_output[1]); - } -} -/* }}} */ - -/* {{{ php_end_ob_buffers - * End output buffering (all buffers) */ -PHPAPI void php_end_ob_buffers(zend_bool send_buffer TSRMLS_DC) -{ - while (OG(ob_nesting_level)!=0) { - php_end_ob_buffer(send_buffer, 0 TSRMLS_CC); - } -} -/* }}} */ - -/* {{{ php_start_implicit_flush - */ -PHPAPI void php_start_implicit_flush(TSRMLS_D) -{ - OG(implicit_flush)=1; -} -/* }}} */ - -/* {{{ php_end_implicit_flush - */ -PHPAPI void php_end_implicit_flush(TSRMLS_D) -{ - OG(implicit_flush)=0; -} -/* }}} */ - -/* {{{ php_ob_set_internal_handler - */ -PHPAPI void php_ob_set_internal_handler(php_output_handler_func_t internal_output_handler, uint buffer_size, char *handler_name, zend_bool erase TSRMLS_DC) -{ - if (OG(ob_nesting_level)==0 || OG(active_ob_buffer).internal_output_handler || strcmp(OG(active_ob_buffer).handler_name, OB_DEFAULT_HANDLER_NAME)) { - php_start_ob_buffer(NULL, buffer_size, erase TSRMLS_CC); - } - - OG(active_ob_buffer).internal_output_handler = internal_output_handler; - OG(active_ob_buffer).internal_output_handler_buffer = (char *) emalloc(buffer_size); - OG(active_ob_buffer).internal_output_handler_buffer_size = buffer_size; - if (OG(active_ob_buffer).handler_name) { - efree(OG(active_ob_buffer).handler_name); - } - OG(active_ob_buffer).handler_name = estrdup(handler_name); - OG(active_ob_buffer).erase = erase; -} -/* }}} */ - -/* - * Output buffering - implementation - */ - -/* {{{ php_ob_allocate - */ -static inline void php_ob_allocate(uint text_length TSRMLS_DC) -{ - uint new_len = OG(active_ob_buffer).text_length + text_length; - - if (OG(active_ob_buffer).size < new_len) { - uint buf_size = OG(active_ob_buffer).size; - while (buf_size <= new_len) { - buf_size += OG(active_ob_buffer).block_size; - } - - OG(active_ob_buffer).buffer = (char *) erealloc(OG(active_ob_buffer).buffer, buf_size+1); - OG(active_ob_buffer).size = buf_size; - } - OG(active_ob_buffer).text_length = new_len; -} -/* }}} */ - -/* {{{ php_ob_init_conflict - * Returns 1 if handler_set is already used and generates error message - */ -PHPAPI int php_ob_init_conflict(char *handler_new, char *handler_set TSRMLS_DC) -{ - if (php_ob_handler_used(handler_set TSRMLS_CC)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "output handler '%s' conflicts with '%s'", handler_new, handler_set); - return 1; - } - return 0; -} -/* }}} */ - -/* {{{ php_ob_init_named - */ -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) -{ - if (output_handler && !zend_is_callable(output_handler, 0, NULL)) { - return FAILURE; - } - 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)) { - return FAILURE; - } -#endif - if (OG(ob_nesting_level)==1) { /* initialize stack */ - zend_stack_init(&OG(ob_buffers)); - } - 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(php_body_write) = php_b_body_write; - return SUCCESS; -} -/* }}} */ - -/* {{{ php_ob_handler_from_string - * Create zval output handler from string - */ -static zval* php_ob_handler_from_string(const char *handler_name, int len TSRMLS_DC) -{ - zval *output_handler; - - ALLOC_INIT_ZVAL(output_handler); - Z_STRLEN_P(output_handler) = len; - Z_STRVAL_P(output_handler) = estrndup(handler_name, len); - Z_TYPE_P(output_handler) = IS_STRING; - return output_handler; -} -/* }}} */ - -/* {{{ php_ob_init - */ -static int php_ob_init(uint initial_size, uint block_size, zval *output_handler, uint chunk_size, zend_bool erase TSRMLS_DC) -{ - int result = FAILURE, handler_len, len; - char *handler_name, *next_handler_name; - HashPosition pos; - zval **tmp; - zval *handler_zval; - - if (output_handler && output_handler->type == IS_STRING) { - handler_name = Z_STRVAL_P(output_handler); - handler_len = Z_STRLEN_P(output_handler); - - result = SUCCESS; - if (handler_len && handler_name[0] != '\0') { - while ((next_handler_name=strchr(handler_name, ',')) != NULL) { - len = next_handler_name-handler_name; - next_handler_name = estrndup(handler_name, len); - handler_zval = php_ob_handler_from_string(next_handler_name, len TSRMLS_CC); - result = php_ob_init_named(initial_size, block_size, next_handler_name, handler_zval, chunk_size, erase TSRMLS_CC); - if (result != SUCCESS) { - zval_dtor(handler_zval); - FREE_ZVAL(handler_zval); - } - handler_name += len+1; - handler_len -= len+1; - efree(next_handler_name); - } - } - if (result == SUCCESS) { - handler_zval = php_ob_handler_from_string(handler_name, handler_len TSRMLS_CC); - result = php_ob_init_named(initial_size, block_size, handler_name, handler_zval, chunk_size, erase TSRMLS_CC); - if (result != SUCCESS) { - zval_dtor(handler_zval); - FREE_ZVAL(handler_zval); - } - } - } else if (output_handler && output_handler->type == IS_ARRAY) { - /* do we have array(object,method) */ - if (zend_is_callable(output_handler, 0, &handler_name)) { - SEPARATE_ZVAL(&output_handler); - output_handler->refcount++; - result = php_ob_init_named(initial_size, block_size, handler_name, output_handler, chunk_size, erase TSRMLS_CC); - efree(handler_name); - } else { - efree(handler_name); - /* init all array elements recursively */ - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(output_handler), &pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_P(output_handler), (void **)&tmp, &pos) == SUCCESS) { - result = php_ob_init(initial_size, block_size, *tmp, chunk_size, erase TSRMLS_CC); - if (result == FAILURE) { - break; - } - zend_hash_move_forward_ex(Z_ARRVAL_P(output_handler), &pos); - } - } - } else if (output_handler && output_handler->type == IS_OBJECT) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "No method name given: use ob_start(array($object,'method')) to specify instance $object and the name of a method of class %s to use as output handler", Z_OBJCE_P(output_handler)->name); - result = FAILURE; - } else { - result = php_ob_init_named(initial_size, block_size, OB_DEFAULT_HANDLER_NAME, NULL, chunk_size, erase TSRMLS_CC); - } - return result; -} -/* }}} */ - -/* {{{ php_ob_list_each - */ -static int php_ob_list_each(php_ob_buffer *ob_buffer, zval *ob_handler_array) -{ - add_next_index_string(ob_handler_array, ob_buffer->handler_name, 1); - return 0; -} -/* }}} */ - -/* {{{ proto false|array ob_list_handlers() - * List all output_buffers in an array - */ -PHP_FUNCTION(ob_list_handlers) -{ - if (ZEND_NUM_ARGS()!=0) { - ZEND_WRONG_PARAM_COUNT(); - RETURN_FALSE; - } - - array_init(return_value); - if (OG(ob_nesting_level)) { - if (OG(ob_nesting_level)>1) { - zend_stack_apply_with_argument(&OG(ob_buffers), ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_ob_list_each, return_value); - } - php_ob_list_each(&OG(active_ob_buffer), return_value); - } -} -/* }}} */ - -/* {{{ php_ob_used_each - * Sets handler_name to NULL is found - */ -static int php_ob_handler_used_each(php_ob_buffer *ob_buffer, char **handler_name) -{ - if (!strcmp(ob_buffer->handler_name, *handler_name)) { - *handler_name = NULL; - return 1; - } - return 0; -} -/* }}} */ - -/* {{{ php_ob_used - * returns 1 if given handler_name is used as output_handler - */ -PHPAPI int php_ob_handler_used(char *handler_name TSRMLS_DC) -{ - char *tmp = handler_name; - - if (OG(ob_nesting_level)) { - if (!strcmp(OG(active_ob_buffer).handler_name, handler_name)) { - return 1; - } - if (OG(ob_nesting_level)>1) { - zend_stack_apply_with_argument(&OG(ob_buffers), ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_ob_handler_used_each, &tmp); - } - } - return tmp ? 0 : 1; -} -/* }}} */ - -/* {{{ php_ob_append - */ -static inline void php_ob_append(const char *text, uint text_length TSRMLS_DC) -{ - char *target; - int original_ob_text_length; - - original_ob_text_length=OG(active_ob_buffer).text_length; - - php_ob_allocate(text_length TSRMLS_CC); - target = OG(active_ob_buffer).buffer+original_ob_text_length; - memcpy(target, text, text_length); - target[text_length]=0; - - /* If implicit_flush is On or chunked buffering, send contents to next buffer and return. */ - if (OG(active_ob_buffer).chunk_size - && OG(active_ob_buffer).text_length >= OG(active_ob_buffer).chunk_size) { - zval *output_handler = OG(active_ob_buffer).output_handler; - - if (output_handler) { - output_handler->refcount++; - } - php_end_ob_buffer(1, 1 TSRMLS_CC); - return; - } -} -/* }}} */ - -#if 0 -static inline void php_ob_prepend(const char *text, uint text_length) -{ - char *p, *start; - TSRMLS_FETCH(); - - php_ob_allocate(text_length TSRMLS_CC); - - /* php_ob_allocate() may change OG(ob_buffer), so we can't initialize p&start earlier */ - p = OG(ob_buffer)+OG(ob_text_length); - start = OG(ob_buffer); - - while (--p>=start) { - p[text_length] = *p; - } - memcpy(OG(ob_buffer), text, text_length); - OG(ob_buffer)[OG(active_ob_buffer).text_length]=0; -} -#endif - - -/* {{{ php_ob_get_buffer - * Return the current output buffer */ -PHPAPI int php_ob_get_buffer(zval *p TSRMLS_DC) -{ - if (OG(ob_nesting_level)==0) { - return FAILURE; - } - ZVAL_STRINGL(p, OG(active_ob_buffer).buffer, OG(active_ob_buffer).text_length, 1); - return SUCCESS; -} -/* }}} */ - -/* {{{ php_ob_get_length - * Return the size of the current output buffer */ -PHPAPI int php_ob_get_length(zval *p TSRMLS_DC) -{ - if (OG(ob_nesting_level) == 0) { - return FAILURE; - } - ZVAL_LONG(p, OG(active_ob_buffer).text_length); - return SUCCESS; -} -/* }}} */ - -/* - * Wrapper functions - implementation - */ - - -/* buffered output function */ -static int php_b_body_write(const char *str, uint str_length TSRMLS_DC) -{ - php_ob_append(str, str_length TSRMLS_CC); - return str_length; -} - -/* {{{ php_ub_body_write_no_header - */ -static int php_ub_body_write_no_header(const char *str, uint str_length TSRMLS_DC) -{ - int result; - - if (OG(disable_output)) { - return 0; - } - - result = OG(php_header_write)(str, str_length TSRMLS_CC); - - if (OG(implicit_flush)) { - sapi_flush(TSRMLS_C); - } - - return result; -} -/* }}} */ - -/* {{{ php_ub_body_write - */ -static int php_ub_body_write(const char *str, uint str_length TSRMLS_DC) -{ - int result = 0; - - if (SG(request_info).headers_only) { - php_header(TSRMLS_C); - zend_bailout(); - } - if (php_header(TSRMLS_C)) { - if (zend_is_compiling(TSRMLS_C)) { - OG(output_start_filename) = zend_get_compiled_filename(TSRMLS_C); - OG(output_start_lineno) = zend_get_compiled_lineno(TSRMLS_C); - } else if (zend_is_executing(TSRMLS_C)) { - OG(output_start_filename) = zend_get_executed_filename(TSRMLS_C); - OG(output_start_lineno) = zend_get_executed_lineno(TSRMLS_C); - } - - OG(php_body_write) = php_ub_body_write_no_header; - result = php_ub_body_write_no_header(str, str_length TSRMLS_CC); - } - - return result; -} -/* }}} */ - -/* - * HEAD support - */ - -/* {{{ proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) - Turn on Output Buffering (specifying an optional output handler). */ -PHP_FUNCTION(ob_start) -{ - zval *output_handler=NULL; - long chunk_size=0; - zend_bool erase=1; - int argc = ZEND_NUM_ARGS(); - - if (zend_parse_parameters(argc TSRMLS_CC, "|zlb", &output_handler, &chunk_size, &erase) == FAILURE) { - RETURN_FALSE; - } - - if (chunk_size < 0) - chunk_size = 0; - - if (php_start_ob_buffer(output_handler, chunk_size, erase TSRMLS_CC)==FAILURE) { - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool ob_flush(void) - Flush (send) contents of the output buffer. The last buffer content is sent to next buffer */ -PHP_FUNCTION(ob_flush) -{ - if (ZEND_NUM_ARGS() != 0) { - ZEND_WRONG_PARAM_COUNT(); - } - - if (!OG(ob_nesting_level)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer. No buffer to flush."); - RETURN_FALSE; - } - - php_end_ob_buffer(1, 1 TSRMLS_CC); - RETURN_TRUE; -} -/* }}} */ - - -/* {{{ proto bool ob_clean(void) - Clean (delete) the current output buffer */ -PHP_FUNCTION(ob_clean) -{ - if (ZEND_NUM_ARGS() != 0) { - ZEND_WRONG_PARAM_COUNT(); - } - - if (!OG(ob_nesting_level)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete."); - RETURN_FALSE; - } - - if (!OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s.", OG(active_ob_buffer).handler_name); - RETURN_FALSE; - } - - php_end_ob_buffer(0, 1 TSRMLS_CC); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool ob_end_flush(void) - Flush (send) the output buffer, and delete current output buffer */ -PHP_FUNCTION(ob_end_flush) -{ - if (ZEND_NUM_ARGS() != 0) { - ZEND_WRONG_PARAM_COUNT(); - } - - if (!OG(ob_nesting_level)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete and flush buffer. No buffer to delete or flush."); - RETURN_FALSE; - } - if (OG(ob_nesting_level) && !OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s.", OG(active_ob_buffer).handler_name); - RETURN_FALSE; - } - - php_end_ob_buffer(1, 0 TSRMLS_CC); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool ob_end_clean(void) - Clean the output buffer, and delete current output buffer */ -PHP_FUNCTION(ob_end_clean) -{ - if (ZEND_NUM_ARGS() != 0) { - ZEND_WRONG_PARAM_COUNT(); - } - - if (!OG(ob_nesting_level)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete."); - RETURN_FALSE; - } - if (OG(ob_nesting_level) && !OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s.", OG(active_ob_buffer).handler_name); - RETURN_FALSE; - } - - php_end_ob_buffer(0, 0 TSRMLS_CC); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool ob_get_flush(void) - Get current buffer contents, flush (send) the output buffer, and delete current output buffer */ -PHP_FUNCTION(ob_get_flush) -{ - if (ZEND_NUM_ARGS() != 0) { - ZEND_WRONG_PARAM_COUNT(); - } - - /* get contents */ - if (php_ob_get_buffer(return_value TSRMLS_CC)==FAILURE) { - RETURN_FALSE; - } - /* error checks */ - if (!OG(ob_nesting_level)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete and flush buffer. No buffer to delete or flush."); - RETURN_FALSE; - } - if (OG(ob_nesting_level) && !OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s.", OG(active_ob_buffer).handler_name); - RETURN_FALSE; - } - /* flush */ - php_end_ob_buffer(1, 0 TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto bool ob_get_clean(void) - Get current buffer contents and delete current output buffer */ -PHP_FUNCTION(ob_get_clean) -{ - if (ZEND_NUM_ARGS() != 0) - ZEND_WRONG_PARAM_COUNT(); - - /* get contents */ - if (php_ob_get_buffer(return_value TSRMLS_CC)==FAILURE) { - RETURN_FALSE; - } - /* error checks */ - if (!OG(ob_nesting_level)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete."); - RETURN_FALSE; - } - if (OG(ob_nesting_level) && !OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s.", OG(active_ob_buffer).handler_name); - RETURN_FALSE; - } - /* delete buffer */ - php_end_ob_buffer(0, 0 TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto string ob_get_contents(void) - Return the contents of the output buffer */ -PHP_FUNCTION(ob_get_contents) -{ - if (ZEND_NUM_ARGS() != 0) { - ZEND_WRONG_PARAM_COUNT(); - } - - if (php_ob_get_buffer(return_value TSRMLS_CC)==FAILURE) { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto int ob_get_level(void) - Return the nesting level of the output buffer */ -PHP_FUNCTION(ob_get_level) -{ - if (ZEND_NUM_ARGS() != 0) { - ZEND_WRONG_PARAM_COUNT(); - } - - RETURN_LONG (OG(ob_nesting_level)); -} -/* }}} */ - -/* {{{ proto int ob_get_length(void) - Return the length of the output buffer */ -PHP_FUNCTION(ob_get_length) -{ - if (ZEND_NUM_ARGS() != 0) { - ZEND_WRONG_PARAM_COUNT(); - } - - if (php_ob_get_length(return_value TSRMLS_CC)==FAILURE) { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ int php_ob_buffer_status(php_ob_buffer *ob_buffer, zval *result) */ -static int php_ob_buffer_status(php_ob_buffer *ob_buffer, zval *result) -{ - zval *elem; - - MAKE_STD_ZVAL(elem); - array_init(elem); - - add_assoc_long(elem, "chunk_size", ob_buffer->chunk_size); - if (!ob_buffer->chunk_size) { - add_assoc_long(elem, "size", ob_buffer->size); - add_assoc_long(elem, "block_size", ob_buffer->block_size); - } - if (ob_buffer->internal_output_handler) { - add_assoc_long(elem, "type", PHP_OUTPUT_HANDLER_INTERNAL); - add_assoc_long(elem, "buffer_size", ob_buffer->internal_output_handler_buffer_size); - } - else { - add_assoc_long(elem, "type", PHP_OUTPUT_HANDLER_USER); - } - add_assoc_long(elem, "status", ob_buffer->status); - add_assoc_string(elem, "name", ob_buffer->handler_name, 1); - add_assoc_bool(elem, "del", ob_buffer->erase); - add_next_index_zval(result, elem); - - return SUCCESS; -} -/* }}} */ - - -/* {{{ proto false|array ob_get_status([bool full_status]) - Return the status of the active or all output buffers */ -PHP_FUNCTION(ob_get_status) -{ - int argc = ZEND_NUM_ARGS(); - zend_bool full_status = 0; - - if (zend_parse_parameters(argc TSRMLS_CC, "|b", &full_status) == FAILURE ) - RETURN_FALSE; - - array_init(return_value); - - if (full_status) { - if (OG(ob_nesting_level)>1) { - zend_stack_apply_with_argument(&OG(ob_buffers), ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *elem, void *))php_ob_buffer_status, return_value); - } - if (OG(ob_nesting_level)>0 && php_ob_buffer_status(&OG(active_ob_buffer), return_value)==FAILURE) { - RETURN_FALSE; - } - } else if (OG(ob_nesting_level)>0) { - add_assoc_long(return_value, "level", OG(ob_nesting_level)); - if (OG(active_ob_buffer).internal_output_handler) { - add_assoc_long(return_value, "type", PHP_OUTPUT_HANDLER_INTERNAL); - } else { - add_assoc_long(return_value, "type", PHP_OUTPUT_HANDLER_USER); - } - add_assoc_long(return_value, "status", OG(active_ob_buffer).status); - add_assoc_string(return_value, "name", OG(active_ob_buffer).handler_name, 1); - add_assoc_bool(return_value, "del", OG(active_ob_buffer).erase); - } -} -/* }}} */ - - -/* {{{ proto void ob_implicit_flush([int flag]) - Turn implicit flush on/off and is equivalent to calling flush() after every output call */ -PHP_FUNCTION(ob_implicit_flush) -{ - zval **zv_flag; - int flag; - - switch(ZEND_NUM_ARGS()) { - case 0: - flag = 1; - break; - case 1: - if (zend_get_parameters_ex(1, &zv_flag)==FAILURE) { - RETURN_FALSE; - } - convert_to_long_ex(zv_flag); - flag = Z_LVAL_PP(zv_flag); - break; - default: - ZEND_WRONG_PARAM_COUNT(); - break; - } - if (flag) { - php_start_implicit_flush(TSRMLS_C); - } else { - php_end_implicit_flush(TSRMLS_C); - } -} -/* }}} */ - - -/* {{{ char *php_get_output_start_filename(TSRMLS_D) - Return filename start output something */ -PHPAPI char *php_get_output_start_filename(TSRMLS_D) -{ - return OG(output_start_filename); -} -/* }}} */ - - -/* {{{ char *php_get_output_start_lineno(TSRMLS_D) - Return line number start output something */ -PHPAPI int php_get_output_start_lineno(TSRMLS_D) -{ - return OG(output_start_lineno); -} -/* }}} */ - - -/* {{{ proto bool output_reset_rewrite_vars(void) - Reset(clear) URL rewriter values */ -PHP_FUNCTION(output_reset_rewrite_vars) -{ - if (php_url_scanner_reset_vars(TSRMLS_C) == SUCCESS) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -/* {{{ proto bool output_add_rewrite_var(string name, string value) - Add URL rewriter values */ -PHP_FUNCTION(output_add_rewrite_var) -{ - char *name, *value; - int name_len, value_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &value, &value_len) == FAILURE) { - RETURN_FALSE; - } - - if (php_url_scanner_add_var(name, name_len, value, value_len, 1 TSRMLS_CC) == SUCCESS) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/php.h b/main/php.h deleted file mode 100644 index f19affd178..0000000000 --- a/main/php.h +++ /dev/null @@ -1,468 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef PHP_H -#define PHP_H - -#ifdef HAVE_DMALLOC -#include <dmalloc.h> -#endif - -#define PHP_API_VERSION 20031224 -#define PHP_HAVE_STREAMS -#define YYDEBUG 0 - -#include "php_version.h" -#include "zend.h" -#include "zend_qsort.h" -#include "php_compat.h" - -#include "zend_API.h" - -#if PHP_BROKEN_SPRINTF -#undef sprintf -#define sprintf php_sprintf -#endif - -/* PHP's DEBUG value must match Zend's ZEND_DEBUG value */ -#undef PHP_DEBUG -#define PHP_DEBUG ZEND_DEBUG - -#ifdef PHP_WIN32 -#include "tsrm_win32.h" -#include "win95nt.h" -# ifdef PHP_EXPORTS -# define PHPAPI __declspec(dllexport) -# else -# define PHPAPI __declspec(dllimport) -# endif -#define PHP_DIR_SEPARATOR '\\' -#define PHP_EOL "\r\n" -#else -#define PHPAPI -#define THREAD_LS -#define PHP_DIR_SEPARATOR '/' -#if defined(__MacOSX__) -#define PHP_EOL "\r" -#else -#define PHP_EOL "\n" -#endif -#endif - -#ifdef NETWARE -/* For php_get_uname() function */ -#define PHP_UNAME "NetWare" -/* - * This is obtained using uname(2) on Unix and assigned in the case of Windows; - * we'll do it this way at least for now. - */ -#define PHP_OS PHP_UNAME -#endif - -#include "php_regex.h" - -#if HAVE_ASSERT_H -#if PHP_DEBUG -#undef NDEBUG -#else -#ifndef NDEBUG -#define NDEBUG -#endif -#endif -#include <assert.h> -#else /* HAVE_ASSERT_H */ -#define assert(expr) ((void) (0)) -#endif /* HAVE_ASSERT_H */ - -#define APACHE 0 - -#if HAVE_UNIX_H -#include <unix.h> -#endif - -#if HAVE_ALLOCA_H -#include <alloca.h> -#endif - -#if HAVE_BUILD_DEFS_H -#include "build-defs.h" -#endif - -/* - * This is a fast version of strlcpy which should be used, if you - * know the size of the destination buffer and if you know - * the length of the source string. - * - * size is the allocated number of bytes of dst - * src_size is the number of bytes excluding the NUL of src - */ - -#define PHP_STRLCPY(dst, src, size, src_size) \ - { \ - size_t php_str_len; \ - \ - if (src_size >= size) \ - php_str_len = size - 1; \ - else \ - php_str_len = src_size; \ - memcpy(dst, src, php_str_len); \ - dst[php_str_len] = '\0'; \ - } - -#ifndef HAVE_STRLCPY -BEGIN_EXTERN_C() -PHPAPI size_t php_strlcpy(char *dst, const char *src, size_t siz); -END_EXTERN_C() -#undef strlcpy -#define strlcpy php_strlcpy -#endif - -#ifndef HAVE_STRLCAT -BEGIN_EXTERN_C() -PHPAPI size_t php_strlcat(char *dst, const char *src, size_t siz); -END_EXTERN_C() -#undef strlcat -#define strlcat php_strlcat -#endif - -#ifndef HAVE_STRTOK_R -BEGIN_EXTERN_C() -char *strtok_r(char *s, const char *delim, char **last); -END_EXTERN_C() -#endif - -#ifndef HAVE_SOCKLEN_T -typedef unsigned int socklen_t; -#endif - -#define CREATE_MUTEX(a, b) -#define SET_MUTEX(a) -#define FREE_MUTEX(a) - -/* - * Then the ODBC support can use both iodbc and Solid, - * uncomment this. - * #define HAVE_ODBC (HAVE_IODBC|HAVE_SOLID) - */ - -#include <stdlib.h> -#include <ctype.h> -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#if HAVE_STDARG_H -#include <stdarg.h> -#else -# if HAVE_SYS_VARARGS_H -# include <sys/varargs.h> -# endif -#endif - - -#include "zend_hash.h" -#include "php3_compat.h" -#include "zend_alloc.h" -#include "zend_stack.h" - -#if STDC_HEADERS -# include <string.h> -#else -# ifndef HAVE_MEMCPY -# define memcpy(d, s, n) bcopy((s), (d), (n)) -# endif -# ifndef HAVE_MEMMOVE -# define memmove(d, s, n) bcopy ((s), (d), (n)) -# endif -#endif - -#include "safe_mode.h" - -#ifndef HAVE_STRERROR -char *strerror(int); -#endif - -#if (REGEX == 1 || REGEX == 0) && !defined(NO_REGEX_EXTRA_H) -#include "regex/regex_extra.h" -#endif - -#if HAVE_PWD_H -# ifdef PHP_WIN32 -#include "win32/pwd.h" -#include "win32/param.h" -#elif defined(NETWARE) -#ifdef NEW_LIBC -#include <sys/param.h> -#else -#include "NetWare/param.h" -#endif -#include "NetWare/pwd.h" -# else -#include <pwd.h> -#include <sys/param.h> -# endif -#endif - -#if HAVE_LIMITS_H -#include <limits.h> -#endif - -#ifndef LONG_MAX -#define LONG_MAX 2147483647L -#endif - -#ifndef LONG_MIN -#define LONG_MIN (- LONG_MAX - 1) -#endif - -#define PHP_GCC_VERSION ZEND_GCC_VERSION -#define PHP_ATTRIBUTE_MALLOC ZEND_ATTRIBUTE_MALLOC -#define PHP_ATTRIBUTE_FORMAT ZEND_ATTRIBUTE_FORMAT - -#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) || PHP_BROKEN_SPRINTF || PHP_BROKEN_SNPRINTF || PHP_BROKEN_VSNPRINTF -#include "snprintf.h" -#endif -#include "spprintf.h" - -#define EXEC_INPUT_BUF 4096 - -#define PHP_MIME_TYPE "application/x-httpd-php" - -/* macros */ -#define STR_PRINT(str) ((str)?(str):"") - -#ifndef MAXPATHLEN -# ifdef PATH_MAX -# define MAXPATHLEN PATH_MAX -# else -# define MAXPATHLEN 256 /* Should be safe for any weird systems that do not define it */ -# endif -#endif - - -/* global variables */ -extern pval *data; -#if !defined(PHP_WIN32) -#ifdef NETWARE -#ifdef NEW_LIBC -#define php_sleep sleep -#else /* NEW_LIBC */ -#define php_sleep delay /* sleep() and usleep() are not available */ -#define usleep delay -#endif /* NEW_LIBC */ -extern char **environ; -#else /* NETWARE */ -extern char **environ; -#define php_sleep sleep -#endif /* NETWARE */ -#endif /* !defined(PHP_WIN32) */ - -#ifdef PHP_PWRITE_64 -ssize_t pwrite(int, void *, size_t, off64_t); -#endif - -#ifdef PHP_PREAD_64 -ssize_t pread(int, void *, size_t, off64_t); -#endif - -BEGIN_EXTERN_C() -void phperror(char *error); -PHPAPI int php_write(void *buf, uint size TSRMLS_DC); -PHPAPI int php_printf(const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 1, - 2); -PHPAPI void php_log_err(char *log_message TSRMLS_DC); -int Debug(char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 1, 2); -int cfgparse(void); -END_EXTERN_C() - -#define php_error zend_error - -typedef enum { - EH_NORMAL = 0, - EH_SUPPRESS, - EH_THROW -} error_handling_t; - -BEGIN_EXTERN_C() -PHPAPI void php_set_error_handling(error_handling_t error_handling, zend_class_entry *exception_class TSRMLS_DC); -#define php_std_error_handling() php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC) - -PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC) PHP_ATTRIBUTE_FORMAT(printf, 4, 0); - -#ifdef ZTS -#define PHP_ATTR_FMT_OFFSET 1 -#else -#define PHP_ATTR_FMT_OFFSET 0 -#endif - -/* PHPAPI void php_error(int type, const char *format, ...); */ -PHPAPI void php_error_docref0(const char *docref TSRMLS_DC, int type, const char *format, ...) - PHP_ATTRIBUTE_FORMAT(printf, PHP_ATTR_FMT_OFFSET + 3, PHP_ATTR_FMT_OFFSET + 4); -PHPAPI void php_error_docref1(const char *docref TSRMLS_DC, const char *param1, int type, const char *format, ...) - PHP_ATTRIBUTE_FORMAT(printf, PHP_ATTR_FMT_OFFSET + 4, PHP_ATTR_FMT_OFFSET + 5); -PHPAPI void php_error_docref2(const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...) - PHP_ATTRIBUTE_FORMAT(printf, PHP_ATTR_FMT_OFFSET + 5, PHP_ATTR_FMT_OFFSET + 6); -END_EXTERN_C() - -#define php_error_docref php_error_docref0 - -#define zenderror phperror -#define zendlex phplex - -#define phpparse zendparse -#define phprestart zendrestart -#define phpin zendin - -#define php_memnstr zend_memnstr - -/* functions */ -BEGIN_EXTERN_C() -int php_startup_internal_extensions(void); - -int php_mergesort(void *base, size_t nmemb, register size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC); - -PHPAPI void php_register_pre_request_shutdown(void (*func)(void *), void *userdata); - -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); -END_EXTERN_C() - -/* PHP-named Zend macro wrappers */ -#define PHP_FN ZEND_FN -#define PHP_NAMED_FUNCTION ZEND_NAMED_FUNCTION -#define PHP_FUNCTION ZEND_FUNCTION -#define PHP_METHOD ZEND_METHOD - -#define PHP_NAMED_FE ZEND_NAMED_FE -#define PHP_FE ZEND_FE -#define PHP_FALIAS ZEND_FALIAS -#define PHP_ME ZEND_ME -#define PHP_ME_MAPPING ZEND_ME_MAPPING - -#define PHP_MODULE_STARTUP_N ZEND_MODULE_STARTUP_N -#define PHP_MODULE_SHUTDOWN_N ZEND_MODULE_SHUTDOWN_N -#define PHP_MODULE_ACTIVATE_N ZEND_MODULE_ACTIVATE_N -#define PHP_MODULE_DEACTIVATE_N ZEND_MODULE_DEACTIVATE_N -#define PHP_MODULE_INFO_N ZEND_MODULE_INFO_N - -#define PHP_MODULE_STARTUP_D ZEND_MODULE_STARTUP_D -#define PHP_MODULE_SHUTDOWN_D ZEND_MODULE_SHUTDOWN_D -#define PHP_MODULE_ACTIVATE_D ZEND_MODULE_ACTIVATE_D -#define PHP_MODULE_DEACTIVATE_D ZEND_MODULE_DEACTIVATE_D -#define PHP_MODULE_INFO_D ZEND_MODULE_INFO_D - -/* Compatibility macros */ -#define PHP_MINIT ZEND_MODULE_STARTUP_N -#define PHP_MSHUTDOWN ZEND_MODULE_SHUTDOWN_N -#define PHP_RINIT ZEND_MODULE_ACTIVATE_N -#define PHP_RSHUTDOWN ZEND_MODULE_DEACTIVATE_N -#define PHP_MINFO ZEND_MODULE_INFO_N - -#define PHP_MINIT_FUNCTION ZEND_MODULE_STARTUP_D -#define PHP_MSHUTDOWN_FUNCTION ZEND_MODULE_SHUTDOWN_D -#define PHP_RINIT_FUNCTION ZEND_MODULE_ACTIVATE_D -#define PHP_RSHUTDOWN_FUNCTION ZEND_MODULE_DEACTIVATE_D -#define PHP_MINFO_FUNCTION ZEND_MODULE_INFO_D - - -/* Output support */ -#include "main/php_output.h" -#define PHPWRITE(str, str_len) php_body_write((str), (str_len) TSRMLS_CC) -#define PUTS(str) do { \ - const char *__str = (str); \ - php_body_write(__str, strlen(__str) TSRMLS_CC); \ -} while (0) - -#define PUTC(c) (php_body_write(&(c), 1 TSRMLS_CC), (c)) -#define PHPWRITE_H(str, str_len) php_header_write((str), (str_len) TSRMLS_CC) -#define PUTS_H(str) do { \ - const char *__str = (str); \ - php_header_write(__str, strlen(__str) TSRMLS_CC); \ -} while (0) - -#define PUTC_H(c) (php_header_write(&(c), 1 TSRMLS_CC), (c)) - -#ifdef ZTS -#define VIRTUAL_DIR -#endif - -#include "php_streams.h" -#include "php_memory_streams.h" -#include "fopen_wrappers.h" - - -/* Virtual current working directory support */ -#include "tsrm_virtual_cwd.h" - -#include "zend_constants.h" - -/* connection status states */ -#define PHP_CONNECTION_NORMAL 0 -#define PHP_CONNECTION_ABORTED 1 -#define PHP_CONNECTION_TIMEOUT 2 - -#include "php_reentrancy.h" - -/* Finding offsets of elements within structures. - * Taken from the Apache code, which in turn, was taken from X code... - */ - -#ifndef XtOffset -#if defined(CRAY) || (defined(__arm) && !defined(LINUX)) -#ifdef __STDC__ -#define XtOffset(p_type, field) _Offsetof(p_type, field) -#else -#ifdef CRAY2 -#define XtOffset(p_type, field) \ - (sizeof(int)*((unsigned int)&(((p_type)NULL)->field))) - -#else /* !CRAY2 */ - -#define XtOffset(p_type, field) ((unsigned int)&(((p_type)NULL)->field)) - -#endif /* !CRAY2 */ -#endif /* __STDC__ */ -#else /* ! (CRAY || __arm) */ - -#define XtOffset(p_type, field) \ - ((long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL))) - -#endif /* !CRAY */ -#endif /* ! XtOffset */ - -#ifndef XtOffsetOf -#ifdef offsetof -#define XtOffsetOf(s_type, field) offsetof(s_type, field) -#else -#define XtOffsetOf(s_type, field) XtOffset(s_type*, field) -#endif -#endif /* !XtOffsetOf */ - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/php3_compat.h b/main/php3_compat.h deleted file mode 100644 index f9248e704d..0000000000 --- a/main/php3_compat.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP3_COMPAT_H -#define PHP3_COMPAT_H - -typedef zval pval; - -#define pval_copy_constructor zval_copy_ctor -#define pval_destructor zval_dtor - -#define _php3_hash_init zend_hash_init -#define _php3_hash_destroy zend_hash_destroy - -#define _php3_hash_clean zend_hash_clean - -#define _php3_hash_add_or_update zend_hash_add_or_update -#define _php3_hash_add zend_hash_add -#define _php3_hash_update zend_hash_update - -#define _php3_hash_quick_add_or_update zend_hash_quick_add_or_update -#define _php3_hash_quick_add zend_hash_quick_add -#define _php3_hash_quick_update zend_hash_quick_update - -#define _php3_hash_index_update_or_next_insert zend_hash_index_update_or_next_insert -#define _php3_hash_index_update zend_hash_index_update -#define _php3_hash_next_index_insert zend_hash_next_index_insert - -#define _php3_hash_pointer_update zend_hash_pointer_update - -#define _php3_hash_pointer_index_update_or_next_insert zend_hash_pointer_index_update_or_next_insert -#define _php3_hash_pointer_index_update zend_hash_pointer_index_update -#define _php3_hash_next_index_pointer_update zend_hash_next_index_pointer_update -#define _php3_hash_next_index_pointer_insert zend_hash_next_index_pointer_insert - -#define _php3_hash_del_key_or_index zend_hash_del_key_or_index -#define _php3_hash_del zend_hash_del -#define _php3_hash_index_del zend_hash_index_del - -#define _php3_hash_find zend_hash_find -#define _php3_hash_quick_find zend_hash_quick_find -#define _php3_hash_index_find zend_hash_index_find - -#define _php3_hash_exists zend_hash_exists -#define _php3_hash_index_exists zend_hash_index_exists -#define _php3_hash_is_pointer zend_hash_is_pointer -#define _php3_hash_index_is_pointer zend_hash_index_is_pointer -#define _php3_hash_next_free_element zend_hash_next_free_element - -#define _php3_hash_move_forward zend_hash_move_forward -#define _php3_hash_move_backwards zend_hash_move_backwards -#define _php3_hash_get_current_key zend_hash_get_current_key -#define _php3_hash_get_current_data zend_hash_get_current_data -#define _php3_hash_internal_pointer_reset zend_hash_internal_pointer_reset -#define _php3_hash_internal_pointer_end zend_hash_internal_pointer_end - -#define _php3_hash_copy zend_hash_copy -#define _php3_hash_merge zend_hash_merge -#define _php3_hash_sort zend_hash_sort -#define _php3_hash_minmax zend_hash_minmax - -#define _php3_hash_num_elements zend_hash_num_elements - -#define _php3_hash_apply zend_hash_apply -#define _php3_hash_apply_with_argument zend_hash_apply_with_argument - - -#define php3_error php_error - -#define php3_printf php_printf -#define _php3_sprintf php_sprintf - - - -#define php3_module_entry zend_module_entry - -#define php3_strndup zend_strndup -#define php3_str_tolower zend_str_tolower -#define php3_binary_strcmp zend_binary_strcmp - - -#define php3_list_insert zend_list_insert -#define php3_list_find zend_list_find -#define php3_list_delete zend_list_delete - -#define php3_plist_insert zend_plist_insert -#define php3_plist_find zend_plist_find -#define php3_plist_delete zend_plist_delete - -#define zend_print_pval zend_print_zval -#define zend_print_pval_r zend_print_zval_r - - -#define function_entry zend_function_entry - -#define _php3_addslashes php_addslashes -#define _php3_stripslashes php_stripslashes -#define php3_dl php_dl - -#define getParameters zend_get_parameters -#define getParametersArray zend_get_parameters_array - -#define list_entry zend_rsrc_list_entry - -#endif /* PHP3_COMPAT_H */ diff --git a/main/php_compat.h b/main/php_compat.h deleted file mode 100644 index 4645feaa98..0000000000 --- a/main/php_compat.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_COMPAT_H -#define PHP_COMPAT_H - -#ifdef PHP_WIN32 -#include "config.w32.h" -#elif defined(NETWARE) -#include "config.nw.h" -#else -#include "php_config.h" -#endif - -#if defined(HAVE_BUNDLED_PCRE) || !defined(PHP_VERSION) -#define pcre_compile php_pcre_compile -#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_list php_pcre_get_substring_list -#define pcre_info php_pcre_info -#define pcre_maketables php_pcre_maketables -#define pcre_study php_pcre_study -#define pcre_version php_pcre_version -#define pcre_fullinfo php_pcre_fullinfo -#endif - -#define lookup php_lookup -#define hashTableInit php_hashTableInit -#define hashTableDestroy php_hashTableDestroy -#define hashTableIterInit php_hashTableIterInit -#define hashTableIterNext php_hashTableIterNext - -#if defined(HAVE_LIBXML) && defined(HAVE_XML) && !defined(HAVE_LIBEXPAT) -#define XML_DefaultCurrent php_XML_DefaultCurrent -#define XML_ErrorString php_XML_ErrorString -#define XML_ExpatVersion php_XML_ExpatVersion -#define XML_ExpatVersionInfo php_XML_ExpatVersionInfo -#define XML_ExternalEntityParserCreate php_XML_ExternalEntityParserCreate -#define XML_GetBase php_XML_GetBase -#define XML_GetBuffer php_XML_GetBuffer -#define XML_GetCurrentByteCount php_XML_GetCurrentByteCount -#define XML_GetCurrentByteIndex php_XML_GetCurrentByteIndex -#define XML_GetCurrentColumnNumber php_XML_GetCurrentColumnNumber -#define XML_GetCurrentLineNumber php_XML_GetCurrentLineNumber -#define XML_GetErrorCode php_XML_GetErrorCode -#define XML_GetIdAttributeIndex php_XML_GetIdAttributeIndex -#define XML_GetInputContext php_XML_GetInputContext -#define XML_GetSpecifiedAttributeCount php_XML_GetSpecifiedAttributeCount -#define XmlGetUtf16InternalEncodingNS php_XmlGetUtf16InternalEncodingNS -#define XmlGetUtf16InternalEncoding php_XmlGetUtf16InternalEncoding -#define XmlGetUtf8InternalEncodingNS php_XmlGetUtf8InternalEncodingNS -#define XmlGetUtf8InternalEncoding php_XmlGetUtf8InternalEncoding -#define XmlInitEncoding php_XmlInitEncoding -#define XmlInitEncodingNS php_XmlInitEncodingNS -#define XmlInitUnknownEncoding php_XmlInitUnknownEncoding -#define XmlInitUnknownEncodingNS php_XmlInitUnknownEncodingNS -#define XML_ParseBuffer php_XML_ParseBuffer -#define XML_Parse php_XML_Parse -#define XML_ParserCreate_MM php_XML_ParserCreate_MM -#define XML_ParserCreateNS php_XML_ParserCreateNS -#define XML_ParserCreate php_XML_ParserCreate -#define XML_ParserFree php_XML_ParserFree -#define XmlParseXmlDecl php_XmlParseXmlDecl -#define XmlParseXmlDeclNS php_XmlParseXmlDeclNS -#define XmlPrologStateInitExternalEntity php_XmlPrologStateInitExternalEntity -#define XmlPrologStateInit php_XmlPrologStateInit -#define XML_SetAttlistDeclHandler php_XML_SetAttlistDeclHandler -#define XML_SetBase php_XML_SetBase -#define XML_SetCdataSectionHandler php_XML_SetCdataSectionHandler -#define XML_SetCharacterDataHandler php_XML_SetCharacterDataHandler -#define XML_SetCommentHandler php_XML_SetCommentHandler -#define XML_SetDefaultHandlerExpand php_XML_SetDefaultHandlerExpand -#define XML_SetDefaultHandler php_XML_SetDefaultHandler -#define XML_SetDoctypeDeclHandler php_XML_SetDoctypeDeclHandler -#define XML_SetElementDeclHandler php_XML_SetElementDeclHandler -#define XML_SetElementHandler php_XML_SetElementHandler -#define XML_SetEncoding php_XML_SetEncoding -#define XML_SetEndCdataSectionHandler php_XML_SetEndCdataSectionHandler -#define XML_SetEndDoctypeDeclHandler php_XML_SetEndDoctypeDeclHandler -#define XML_SetEndElementHandler php_XML_SetEndElementHandler -#define XML_SetEndNamespaceDeclHandler php_XML_SetEndNamespaceDeclHandler -#define XML_SetEntityDeclHandler php_XML_SetEntityDeclHandler -#define XML_SetExternalEntityRefHandlerArg php_XML_SetExternalEntityRefHandlerArg -#define XML_SetExternalEntityRefHandler php_XML_SetExternalEntityRefHandler -#define XML_SetNamespaceDeclHandler php_XML_SetNamespaceDeclHandler -#define XML_SetNotationDeclHandler php_XML_SetNotationDeclHandler -#define XML_SetNotStandaloneHandler php_XML_SetNotStandaloneHandler -#define XML_SetParamEntityParsing php_XML_SetParamEntityParsing -#define XML_SetProcessingInstructionHandler php_XML_SetProcessingInstructionHandler -#define XML_SetReturnNSTriplet php_XML_SetReturnNSTriplet -#define XML_SetStartCdataSectionHandler php_XML_SetStartCdataSectionHandler -#define XML_SetStartDoctypeDeclHandler php_XML_SetStartDoctypeDeclHandler -#define XML_SetStartElementHandler php_XML_SetStartElementHandler -#define XML_SetStartNamespaceDeclHandler php_XML_SetStartNamespaceDeclHandler -#define XML_SetUnknownEncodingHandler php_XML_SetUnknownEncodingHandler -#define XML_SetUnparsedEntityDeclHandler php_XML_SetUnparsedEntityDeclHandler -#define XML_SetUserData php_XML_SetUserData -#define XML_SetXmlDeclHandler php_XML_SetXmlDeclHandler -#define XmlSizeOfUnknownEncoding php_XmlSizeOfUnknownEncoding -#define XML_UseParserAsHandlerArg php_XML_UseParserAsHandlerArg -#define XmlUtf16Encode php_XmlUtf16Encode -#define XmlUtf8Encode php_XmlUtf8Encode -#define XML_FreeContentModel php_XML_FreeContentModel -#define XML_MemMalloc php_XML_MemMalloc -#define XML_MemRealloc php_XML_MemRealloc -#define XML_MemFree php_XML_MemFree -#define XML_UseForeignDTD php_XML_UseForeignDTD -#define XML_GetFeatureList php_XML_GetFeatureList -#define XML_ParserReset php_XML_ParserReset - -/* Define to specify how much context to retain around the current parse - point. */ -#define XML_CONTEXT_BYTES 1024 - -/* Define to make parameter entity parsing functionality available. */ -#define XML_DTD 1 - -/* Define to make XML Namespaces functionality available. */ -#define XML_NS 1 -#endif - -#ifdef PHP_EXPORTS -#define PCRE_STATIC -#endif - -#endif diff --git a/main/php_content_types.c b/main/php_content_types.c deleted file mode 100644 index 3dfabf840a..0000000000 --- a/main/php_content_types.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "SAPI.h" -#include "rfc1867.h" - -#include "php_content_types.h" - -/* {{{ php_post_entries[] - */ -static sapi_post_entry php_post_entries[] = { - { DEFAULT_POST_CONTENT_TYPE, sizeof(DEFAULT_POST_CONTENT_TYPE)-1, sapi_read_standard_form_data, php_std_post_handler }, - { MULTIPART_CONTENT_TYPE, sizeof(MULTIPART_CONTENT_TYPE)-1, NULL, rfc1867_post_handler }, - { NULL, 0, NULL, NULL } -}; -/* }}} */ - -/* {{{ SAPI_POST_READER_FUNC - */ -SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader) -{ - char *data = NULL; - int length = 0; - - /* $HTTP_RAW_POST_DATA registration */ - if(!strcmp(SG(request_info).request_method, "POST")) { - if(NULL == SG(request_info).post_entry) { - /* no post handler registered, so we just swallow the data */ - sapi_read_standard_form_data(TSRMLS_C); - length = SG(request_info).post_data_length; - data = estrndup(SG(request_info).post_data, length); - } else if(PG(always_populate_raw_post_data) && SG(request_info).post_data) { - length = SG(request_info).post_data_length; - data = estrndup(SG(request_info).post_data, length); - } - if(data) { - SET_VAR_STRINGL("HTTP_RAW_POST_DATA", data, length); - } - } - - /* for php://input stream: - some post handlers modify the content of request_info.post_data - so for now we need a copy for the php://input stream - in the long run post handlers should be changed to not touch - request_info.post_data for memory preservation reasons - */ - if(SG(request_info).post_data) { - SG(request_info).raw_post_data = estrndup(SG(request_info).post_data, SG(request_info).post_data_length); - SG(request_info).raw_post_data_length = SG(request_info).post_data_length; - } - -} -/* }}} */ - -/* {{{ php_startup_sapi_content_types - */ -int php_startup_sapi_content_types(void) -{ - sapi_register_post_entries(php_post_entries); - sapi_register_default_post_reader(php_default_post_reader); - sapi_register_treat_data(php_default_treat_data); - sapi_register_input_filter(php_default_input_filter); - return SUCCESS; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/php_content_types.h b/main/php_content_types.h deleted file mode 100644 index deab9271b1..0000000000 --- a/main/php_content_types.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_CONTENT_TYPES_H -#define PHP_CONTENT_TYPES_H - -#define DEFAULT_POST_CONTENT_TYPE "application/x-www-form-urlencoded" - -SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader); -SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler); -int php_startup_sapi_content_types(void); - -#endif /* PHP_CONTENT_TYPES_H */ diff --git a/main/php_globals.h b/main/php_globals.h deleted file mode 100644 index ca2caa461d..0000000000 --- a/main/php_globals.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_GLOBALS_H -#define PHP_GLOBALS_H - -#include "zend_globals.h" - -typedef struct _php_core_globals php_core_globals; - -#ifdef ZTS -# define PG(v) TSRMG(core_globals_id, php_core_globals *, v) -extern PHPAPI int core_globals_id; -#else -# define PG(v) (core_globals.v) -extern ZEND_API struct _php_core_globals core_globals; -#endif - - -#define TRACK_VARS_POST 0 -#define TRACK_VARS_GET 1 -#define TRACK_VARS_COOKIE 2 -#define TRACK_VARS_SERVER 3 -#define TRACK_VARS_ENV 4 -#define TRACK_VARS_FILES 5 -#define TRACK_VARS_REQUEST 6 - -struct _php_tick_function_entry; - -typedef struct _arg_separators { - char *output; - char *input; -} arg_separators; - -struct _php_core_globals { - zend_bool magic_quotes_gpc; - zend_bool magic_quotes_runtime; - zend_bool magic_quotes_sybase; - - zend_bool safe_mode; - - zend_bool allow_call_time_pass_reference; - zend_bool implicit_flush; - - long output_buffering; - - char *safe_mode_include_dir; - zend_bool safe_mode_gid; - zend_bool sql_safe_mode; - zend_bool enable_dl; - - char *output_handler; - - char *unserialize_callback_func; - long serialize_precision; - - char *safe_mode_exec_dir; - - long memory_limit; - long max_input_time; - - zend_bool track_errors; - zend_bool display_errors; - zend_bool display_startup_errors; - zend_bool log_errors; - long log_errors_max_len; - zend_bool ignore_repeated_errors; - zend_bool ignore_repeated_source; - zend_bool report_memleaks; - char *error_log; - - char *doc_root; - char *user_dir; - char *include_path; - char *open_basedir; - char *extension_dir; - - char *upload_tmp_dir; - long upload_max_filesize; - - char *error_append_string; - char *error_prepend_string; - - char *auto_prepend_file; - char *auto_append_file; - - arg_separators arg_separator; - - char *gpc_order; - char *variables_order; - - HashTable rfc1867_protected_variables; - - short connection_status; - short ignore_user_abort; - - unsigned char header_is_being_sent; - - zend_llist tick_functions; - - zval *http_globals[6]; - - zend_bool expose_php; - - zend_bool register_globals; - zend_bool register_long_arrays; - zend_bool register_argc_argv; - - zend_bool y2k_compliance; - - char *docref_root; - char *docref_ext; - - zend_bool html_errors; - zend_bool xmlrpc_errors; - - long xmlrpc_error_number; - - zend_bool activated_auto_globals[8]; - - zend_bool modules_activated; - zend_bool file_uploads; - zend_bool during_request_startup; - zend_bool allow_url_fopen; - zend_bool always_populate_raw_post_data; - zend_bool report_zend_debug; - - char *last_error_message; - char *last_error_file; - int last_error_lineno; - error_handling_t error_handling; - zend_class_entry *exception_class; - - char *disable_functions; - char *disable_classes; -}; - - -#endif /* PHP_GLOBALS_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/main/php_ini.c b/main/php_ini.c deleted file mode 100644 index 8fd1c00f9a..0000000000 --- a/main/php_ini.c +++ /dev/null @@ -1,628 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* Check CWD for php.ini */ -#define INI_CHECK_CWD - -#include "php.h" -#include "ext/standard/info.h" -#include "zend_ini.h" -#include "php_ini.h" -#include "ext/standard/dl.h" -#include "zend_extensions.h" -#include "zend_highlight.h" -#include "SAPI.h" -#include "php_main.h" -#include "php_scandir.h" -#ifdef PHP_WIN32 -#include "win32/php_registry.h" -#endif - -#if HAVE_SCANDIR && HAVE_ALPHASORT && HAVE_DIRENT_H -#include <dirent.h> -#endif - -#ifndef S_ISREG -#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) -#endif - -typedef struct _php_extension_lists { - zend_llist engine; - zend_llist functions; -} php_extension_lists; - - -/* True globals */ -static HashTable configuration_hash; -PHPAPI char *php_ini_opened_path=NULL; -static php_extension_lists extension_lists; -PHPAPI char *php_ini_scanned_files=NULL; - -/* {{{ php_ini_displayer_cb - */ -static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type) -{ - if (ini_entry->displayer) { - ini_entry->displayer(ini_entry, type); - } else { - char *display_string; - uint display_string_length, esc_html=0; - TSRMLS_FETCH(); - - if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) { - if (ini_entry->orig_value && ini_entry->orig_value[0]) { - display_string = ini_entry->orig_value; - display_string_length = ini_entry->orig_value_length; - esc_html = !sapi_module.phpinfo_as_text; - } else { - if (!sapi_module.phpinfo_as_text) { - display_string = "<i>no value</i>"; - display_string_length = sizeof("<i>no value</i>") - 1; - } else { - display_string = "no value"; - display_string_length = sizeof("no value") - 1; - } - } - } else if (ini_entry->value && ini_entry->value[0]) { - display_string = ini_entry->value; - display_string_length = ini_entry->value_length; - esc_html = !sapi_module.phpinfo_as_text; - } else { - if (!sapi_module.phpinfo_as_text) { - display_string = "<i>no value</i>"; - display_string_length = sizeof("<i>no value</i>") - 1; - } else { - display_string = "no value"; - display_string_length = sizeof("no value") - 1; - } - } - - if (esc_html) { - php_html_puts(display_string, display_string_length TSRMLS_CC); - } else { - PHPWRITE(display_string, display_string_length); - } - } -} -/* }}} */ - -/* {{{ php_ini_displayer - */ -static int php_ini_displayer(zend_ini_entry *ini_entry, int module_number TSRMLS_DC) -{ - if (ini_entry->module_number != module_number) { - return 0; - } - if (!sapi_module.phpinfo_as_text) { - PUTS("<tr>"); - PUTS("<td class=\"e\">"); - PHPWRITE(ini_entry->name, ini_entry->name_length - 1); - PUTS("</td><td class=\"v\">"); - php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE); - PUTS("</td><td class=\"v\">"); - php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG); - PUTS("</td></tr>\n"); - } else { - PHPWRITE(ini_entry->name, ini_entry->name_length - 1); - PUTS(" => "); - php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE); - PUTS(" => "); - php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG); - PUTS("\n"); - } - return 0; -} -/* }}} */ - -/* {{{ display_ini_entries - */ -PHPAPI void display_ini_entries(zend_module_entry *module) -{ - int module_number; - TSRMLS_FETCH(); - - if (module) { - module_number = module->module_number; - } else { - module_number = 0; - } - 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); - php_info_print_table_end(); -} -/* }}} */ - -/* php.ini support */ - -#ifdef ZTS -# if (ZEND_DEBUG) -# define ZEND_EXTENSION_TOKEN "zend_extension_debug_ts" -# else -# define ZEND_EXTENSION_TOKEN "zend_extension_ts" -# endif -#else -# if (ZEND_DEBUG) -# define ZEND_EXTENSION_TOKEN "zend_extension_debug" -# else -# define ZEND_EXTENSION_TOKEN "zend_extension" -# endif -#endif - -/* {{{ pvalue_config_destructor - */ -static void pvalue_config_destructor(zval *pvalue) -{ - if (Z_TYPE_P(pvalue) == IS_STRING && Z_STRVAL_P(pvalue) != empty_string) { - free(Z_STRVAL_P(pvalue)); - } -} -/* }}} */ - -/* {{{ php_config_ini_parser_cb - */ -static void php_config_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, void *arg) -{ - switch (callback_type) { - case ZEND_INI_PARSER_ENTRY: { - zval *entry; - - if (!arg2) { - break; - } - if (!strcasecmp(Z_STRVAL_P(arg1), "extension")) { /* load function module */ - zval copy; - - copy = *arg2; - zval_copy_ctor(©); - copy.refcount = 0; - zend_llist_add_element(&extension_lists.functions, ©); - } else if (!strcasecmp(Z_STRVAL_P(arg1), ZEND_EXTENSION_TOKEN)) { /* load Zend extension */ - char *extension_name = estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2)); - - zend_llist_add_element(&extension_lists.engine, &extension_name); - } else { - zend_hash_update(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, arg2, sizeof(zval), (void **) &entry); - Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry)); - } - } - break; - - case ZEND_INI_PARSER_POP_ENTRY: { - zval *hash; - zval **find_hash; - zval *element; - - if (!arg2) { - /* bare string - nothing to do */ - break; - } - - if (zend_hash_find(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, (void **) &find_hash) == FAILURE) { - ALLOC_ZVAL(hash); - array_init(hash); - - zend_hash_update(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, &hash, sizeof(zval *), NULL); - } else { - hash = *find_hash; - } - - ALLOC_ZVAL(element); - *element = *arg2; - zval_copy_ctor(element); - INIT_PZVAL(element); - add_next_index_zval(hash, element); - } - break; - - case ZEND_INI_PARSER_SECTION: - break; - } -} -/* }}} */ - -/* {{{ php_load_function_extension_cb - */ -static void php_load_function_extension_cb(void *arg TSRMLS_DC) -{ - zval *extension = (zval *) arg; - zval zval; - - php_dl(extension, MODULE_PERSISTENT, &zval TSRMLS_CC); -} -/* }}} */ - -/* {{{ php_load_zend_extension_cb - */ -static void php_load_zend_extension_cb(void *arg TSRMLS_DC) -{ - zend_load_extension(*((char **) arg)); -} -/* }}} */ - -/* {{{ php_init_config - */ -int php_init_config() -{ - char *env_location, *php_ini_search_path; - char *binary_location; - int safe_mode_state; - char *open_basedir; - int free_ini_search_path=0; - zend_file_handle fh; - struct stat sb; - char ini_file[MAXPATHLEN]; - char *p; - zend_llist scanned_ini_list; - int l, total_l=0; - zend_llist_element *element; - TSRMLS_FETCH(); - - if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1) == FAILURE) { - return FAILURE; - } - - if (sapi_module.ini_defaults) { - sapi_module.ini_defaults(&configuration_hash); - } - - zend_llist_init(&extension_lists.engine, sizeof(char *), (llist_dtor_func_t) free_estring, 1); - zend_llist_init(&extension_lists.functions, sizeof(zval), (llist_dtor_func_t) ZVAL_DESTRUCTOR, 1); - zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1); - - safe_mode_state = PG(safe_mode); - open_basedir = PG(open_basedir); - - env_location = getenv("PHPRC"); - if (!env_location) { - env_location = ""; - } - if (sapi_module.php_ini_path_override) { - php_ini_search_path = sapi_module.php_ini_path_override; - free_ini_search_path = 0; - } else { - char *default_location; - static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 }; -#ifdef PHP_WIN32 - char *reg_location; -#endif - - php_ini_search_path = (char *) emalloc(MAXPATHLEN * 4 + strlen(env_location) + 3 + 1); - free_ini_search_path = 1; - php_ini_search_path[0] = 0; - -#ifdef PHP_WIN32 - /* Add registry location */ - reg_location = GetIniPathFromRegistry(); - if(reg_location != NULL) { - if (*php_ini_search_path) { - strcat(php_ini_search_path, paths_separator); - } - strcat(php_ini_search_path, reg_location); - efree(reg_location); - } -#endif - /* - * Prepare search path - */ - - /* Add environment location */ - if (env_location[0]) { - if (*php_ini_search_path) { - strcat(php_ini_search_path, paths_separator); - } - strcat(php_ini_search_path, env_location); - } - - /* Add cwd */ -#ifdef INI_CHECK_CWD - if (strcmp(sapi_module.name, "cli") != 0) { - if (*php_ini_search_path) { - strcat(php_ini_search_path, paths_separator); - } - strcat(php_ini_search_path, "."); - } -#endif - - /* Add binary directory */ -#ifdef PHP_WIN32 - binary_location = (char *) emalloc(MAXPATHLEN); - if (GetModuleFileName(0, binary_location, MAXPATHLEN) == 0) { - efree(binary_location); - binary_location = NULL; - } -#else - if (sapi_module.executable_location) { - binary_location = estrdup(sapi_module.executable_location); - } else { - binary_location = NULL; - } -#endif - if (binary_location) { - char *separator_location = strrchr(binary_location, DEFAULT_SLASH); - - if (separator_location) { - *(separator_location+1) = 0; - } - if (*php_ini_search_path) { - strcat(php_ini_search_path, paths_separator); - } - strcat(php_ini_search_path, binary_location); - efree(binary_location); - } - - /* Add default location */ -#ifdef PHP_WIN32 - default_location = (char *) emalloc(MAXPATHLEN + 1); - - if (0 < GetWindowsDirectory(default_location, MAXPATHLEN)) { - if (*php_ini_search_path) { - strcat(php_ini_search_path, paths_separator); - } - strcat(php_ini_search_path, default_location); - } - efree(default_location); - - { - /* For people running under terminal services, GetWindowsDirectory will - * return their personal Windows directory, so lets add the system - * windows directory too */ - typedef UINT (WINAPI *get_system_windows_directory_func)(char *buffer, UINT size); - static get_system_windows_directory_func get_system_windows_directory = NULL; - HMODULE kern; - - if (get_system_windows_directory == NULL) { - kern = LoadLibrary("kernel32.dll"); - if (kern) { - get_system_windows_directory = (get_system_windows_directory_func)GetProcAddress(kern, "GetSystemWindowsDirectoryA"); - } - } - if (get_system_windows_directory != NULL) { - 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); - } - strcat(php_ini_search_path, default_location); - } - efree(default_location); - } - } -#else - default_location = PHP_CONFIG_FILE_PATH; - if (*php_ini_search_path) { - strcat(php_ini_search_path, paths_separator); - } - strcat(php_ini_search_path, default_location); -#endif - } - - PG(safe_mode) = 0; - PG(open_basedir) = NULL; - - memset(&fh, 0, sizeof(fh)); - /* Check if php_ini_path_override is a file */ - if (!sapi_module.php_ini_ignore) { - if (sapi_module.php_ini_path_override && sapi_module.php_ini_path_override[0]) { - struct stat statbuf; - - if (!VCWD_STAT(sapi_module.php_ini_path_override, &statbuf)) { - if (!((statbuf.st_mode & S_IFMT) == S_IFDIR)) { - fh.handle.fp = VCWD_FOPEN(sapi_module.php_ini_path_override, "r"); - fh.filename = sapi_module.php_ini_path_override; - } - } - } - /* 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); - 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) { - fh.filename = php_ini_opened_path; - } - } - /* Search php.ini file in search path */ - if (!fh.handle.fp) { - fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC); - if (fh.handle.fp) { - fh.filename = php_ini_opened_path; - } - } - } - - if (free_ini_search_path) { - efree(php_ini_search_path); - } - - PG(safe_mode) = safe_mode_state; - PG(open_basedir) = open_basedir; - - if (fh.handle.fp) { - fh.type = ZEND_HANDLE_FP; - - zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists); - - { - zval tmp; - - Z_STRLEN(tmp) = strlen(fh.filename); - Z_STRVAL(tmp) = zend_strndup(fh.filename, Z_STRLEN(tmp)); - Z_TYPE(tmp) = IS_STRING; - zend_hash_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path"), (void *) &tmp, sizeof(zval), NULL); - if (php_ini_opened_path) { - efree(php_ini_opened_path); - } - php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp)); - } - } - - /* If the config_file_scan_dir is set at compile-time, go and scan this directory and - * parse any .ini files found in this directory. */ - if (!sapi_module.php_ini_ignore && strlen(PHP_CONFIG_FILE_SCAN_DIR)) { - struct dirent **namelist; - int ndir, i; - - if ((ndir = php_scandir(PHP_CONFIG_FILE_SCAN_DIR, &namelist, 0, php_alphasort)) > 0) { - for (i = 0; i < ndir; i++) { - /* check for a .ini extension */ - if (!(p = strrchr(namelist[i]->d_name, '.')) || (p && strcmp(p, ".ini"))) { - free(namelist[i]); - continue; - } - snprintf(ini_file, MAXPATHLEN, "%s%c%s", PHP_CONFIG_FILE_SCAN_DIR, DEFAULT_SLASH, namelist[i]->d_name); - if (VCWD_STAT(ini_file, &sb) == 0) { - if (S_ISREG(sb.st_mode)) { - if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) { - fh.filename = ini_file; - fh.type = ZEND_HANDLE_FP; - zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists); - /* Here, add it to the list of ini files read */ - l = strlen(ini_file); - total_l += l + 2; - p = estrndup(ini_file, l); - zend_llist_add_element(&scanned_ini_list, &p); - } - } - } - free(namelist[i]); - } - free(namelist); - - /* - * Don't need an extra byte for the \0 in this malloc as the last - * element will not get a trailing , which gives us the byte for the \0 - */ - 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"); - } - zend_llist_destroy(&scanned_ini_list); - } - } - return SUCCESS; -} -/* }}} */ - -/* {{{ php_shutdown_config - */ -int php_shutdown_config(void) -{ - zend_hash_destroy(&configuration_hash); - if (php_ini_opened_path) { - free(php_ini_opened_path); - } - if (php_ini_scanned_files) { - free(php_ini_scanned_files); - } - return SUCCESS; -} -/* }}} */ - -/* {{{ php_ini_delayed_modules_startup - */ -void php_ini_delayed_modules_startup(TSRMLS_D) -{ - zend_llist_apply(&extension_lists.engine, php_load_zend_extension_cb TSRMLS_CC); - zend_llist_apply(&extension_lists.functions, php_load_function_extension_cb TSRMLS_CC); - - zend_llist_destroy(&extension_lists.engine); - zend_llist_destroy(&extension_lists.functions); -} -/* }}} */ - -/* {{{ cfg_get_entry - */ -zval *cfg_get_entry(char *name, uint name_length) -{ - zval *tmp; - - if (zend_hash_find(&configuration_hash, name, name_length, (void **) &tmp) == SUCCESS) { - return tmp; - } else { - return NULL; - } -} -/* }}} */ - -/* {{{ cfg_get_long - */ -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; - return FAILURE; - } - var = *tmp; - zval_copy_ctor(&var); - convert_to_long(&var); - *result = Z_LVAL(var); - return SUCCESS; -} -/* }}} */ - -/* {{{ cfg_get_double - */ -PHPAPI int cfg_get_double(char *varname, double *result) -{ - zval *tmp, var; - - if (zend_hash_find(&configuration_hash, varname, strlen(varname) + 1, (void **) &tmp) == FAILURE) { - *result = (double) 0; - return FAILURE; - } - var = *tmp; - zval_copy_ctor(&var); - convert_to_double(&var); - *result = Z_DVAL(var); - return SUCCESS; -} -/* }}} */ - -/* {{{ cfg_get_string - */ -PHPAPI int cfg_get_string(char *varname, char **result) -{ - zval *tmp; - - if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp) == FAILURE) { - *result = NULL; - return FAILURE; - } - *result = Z_STRVAL_P(tmp); - return SUCCESS; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * indent-tabs-mode: t - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/php_ini.h b/main/php_ini.h deleted file mode 100644 index 94b5d3271f..0000000000 --- a/main/php_ini.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_INI_H -#define PHP_INI_H - -#include "zend_ini.h" - -BEGIN_EXTERN_C() -int php_init_config(); -int php_shutdown_config(void); -void php_ini_delayed_modules_startup(TSRMLS_D); -zval *cfg_get_entry(char *name, uint name_length); -END_EXTERN_C() - -#define PHP_INI_USER ZEND_INI_USER -#define PHP_INI_PERDIR ZEND_INI_PERDIR -#define PHP_INI_SYSTEM ZEND_INI_SYSTEM - -#define PHP_INI_ALL ZEND_INI_ALL - -#define php_ini_entry zend_ini_entry - -#define PHP_INI_MH ZEND_INI_MH -#define PHP_INI_DISP ZEND_INI_DISP - -#define PHP_INI_BEGIN ZEND_INI_BEGIN -#define PHP_INI_END ZEND_INI_END - -#define PHP_INI_ENTRY3_EX ZEND_INI_ENTRY3_EX -#define PHP_INI_ENTRY3 ZEND_INI_ENTRY3 -#define PHP_INI_ENTRY2_EX ZEND_INI_ENTRY2_EX -#define PHP_INI_ENTRY2 ZEND_INI_ENTRY2 -#define PHP_INI_ENTRY1_EX ZEND_INI_ENTRY1_EX -#define PHP_INI_ENTRY1 ZEND_INI_ENTRY1 -#define PHP_INI_ENTRY_EX ZEND_INI_ENTRY_EX -#define PHP_INI_ENTRY ZEND_INI_ENTRY - -#define STD_PHP_INI_ENTRY STD_ZEND_INI_ENTRY -#define STD_PHP_INI_ENTRY_EX STD_ZEND_INI_ENTRY_EX -#define STD_PHP_INI_BOOLEAN STD_ZEND_INI_BOOLEAN - -#define PHP_INI_DISPLAY_ORIG ZEND_INI_DISPLAY_ORIG -#define PHP_INI_DISPLAY_ACTIVE ZEND_INI_DISPLAY_ACTIVE - -#define PHP_INI_STAGE_STARTUP ZEND_INI_STAGE_STARTUP -#define PHP_INI_STAGE_SHUTDOWN ZEND_INI_STAGE_SHUTDOWN -#define PHP_INI_STAGE_ACTIVATE ZEND_INI_STAGE_ACTIVATE -#define PHP_INI_STAGE_DEACTIVATE ZEND_INI_STAGE_DEACTIVATE -#define PHP_INI_STAGE_RUNTIME ZEND_INI_STAGE_RUNTIME - -#define php_ini_boolean_displayer_cb zend_ini_boolean_displayer_cb -#define php_ini_color_displayer_cb zend_ini_color_displayer_cb - -#define php_alter_ini_entry zend_alter_ini_entry - -#define php_ini_long zend_ini_long -#define php_ini_double zend_ini_double -#define php_ini_string zend_ini_string - -#endif /* PHP_INI_H */ diff --git a/main/php_logos.c b/main/php_logos.c deleted file mode 100644 index e69a0f9310..0000000000 --- a/main/php_logos.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Hartmut Holzgraefe <hholzgra@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "logos.h" -#include "php_logos.h" -#include "ext/standard/info.h" -#include "SAPI.h" - -typedef struct _php_info_logo { - char *mimetype; - int mimelen; - unsigned char *data; - int size; -} php_info_logo; - -HashTable phpinfo_logo_hash; - -PHPAPI int php_register_info_logo(char *logo_string, char *mimetype, unsigned char *data, int size) -{ - php_info_logo info_logo; - - info_logo.mimetype = mimetype; - info_logo.mimelen = strlen(mimetype); - info_logo.data = data; - info_logo.size = size; - - return zend_hash_add(&phpinfo_logo_hash, logo_string, strlen(logo_string), &info_logo, sizeof(php_info_logo), NULL); -} - -PHPAPI int php_unregister_info_logo(char *logo_string) -{ - return zend_hash_del(&phpinfo_logo_hash, logo_string, strlen(logo_string)); -} - -int php_init_info_logos(void) -{ - if(zend_hash_init(&phpinfo_logo_hash, 0, NULL, NULL, 1)==FAILURE) - return FAILURE; - - php_register_info_logo(PHP_LOGO_GUID , "image/gif", php_logo , sizeof(php_logo)); - php_register_info_logo(PHP_EGG_LOGO_GUID, "image/gif", php_egg_logo, sizeof(php_egg_logo)); - php_register_info_logo(ZEND_LOGO_GUID , "image/gif", zend_logo , sizeof(zend_logo)); - - return SUCCESS; -} - -int php_shutdown_info_logos(void) -{ - zend_hash_destroy(&phpinfo_logo_hash); - return SUCCESS; -} - -#define CONTENT_TYPE_HEADER "Content-Type: " -int php_info_logos(const char *logo_string TSRMLS_DC) -{ - php_info_logo *logo_image; - char *content_header; - int len; - - 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); - - PHPWRITE(logo_image->data, logo_image->size); - return 1; -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/php_logos.h b/main/php_logos.h deleted file mode 100644 index 4271ef4740..0000000000 --- a/main/php_logos.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - - -#ifndef _PHP_LOGOS_H -#define _PHP_LOGOS_H - -PHPAPI int php_register_info_logo(char *logo_string, char *mimetype, unsigned char *data, int size); -PHPAPI int php_unregister_info_logo(char *logo_string); -int php_init_info_logos(void); -int php_shutdown_info_logos(void); -int php_info_logos(const char *logo_string TSRMLS_DC); - -#endif /* _PHP_LOGOS_H */ diff --git a/main/php_main.h b/main/php_main.h deleted file mode 100644 index 01656e5d24..0000000000 --- a/main/php_main.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef PHP_MAIN_H -#define PHP_MAIN_H - -#include "zend_globals.h" -#include "php_globals.h" -#include "SAPI.h" - -BEGIN_EXTERN_C() -PHPAPI int php_request_startup(TSRMLS_D); -PHPAPI void php_request_shutdown(void *dummy); -PHPAPI void php_request_shutdown_for_exec(void *dummy); -PHPAPI int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint num_additional_modules); -PHPAPI void php_module_shutdown(TSRMLS_D); -PHPAPI void php_module_shutdown_for_exec(void); -PHPAPI int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals); -PHPAPI int php_request_startup_for_hook(TSRMLS_D); - -PHPAPI int php_startup_extensions(zend_module_entry **ptr, int count); - -PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC); -PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval **ret TSRMLS_DC); -PHPAPI int php_handle_special_queries(TSRMLS_D); -PHPAPI int php_lint_script(zend_file_handle *file TSRMLS_DC); - -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); - -extern void php_call_shutdown_functions(void); - -/* environment module */ -extern int php_init_environ(void); -extern int php_shutdown_environ(void); -END_EXTERN_C() - -#endif diff --git a/main/php_memory_streams.h b/main/php_memory_streams.h deleted file mode 100644 index 37ff932c00..0000000000 --- a/main/php_memory_streams.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef PHP_MEMORY_STREAM_H -#define PHP_MEMORY_STREAM_H - -#include "php_streams.h" - -#define PHP_STREAM_MAX_MEM 2 * 1024 * 1024 - -#define TEMP_STREAM_DEFAULT 0 -#define TEMP_STREAM_READONLY 1 - -#define php_stream_memory_create(mode) _php_stream_memory_create((mode) STREAMS_CC TSRMLS_CC) -#define php_stream_memory_create_rel(mode) _php_stream_memory_create((mode) STREAMS_REL_CC TSRMLS_CC) -#define php_stream_memory_open(mode, buf, length) _php_stream_memory_open((mode), (buf), (length) STREAMS_CC TSRMLS_CC) -#define php_stream_memory_get_buffer(stream, length) _php_stream_memory_get_buffer((stream), (length) STREAMS_CC TSRMLS_CC) - -#define php_stream_temp_new() php_stream_temp_create(TEMP_STREAM_DEFAULT, PHP_STREAM_MAX_MEM) -#define php_stream_temp_create(mode, max_memory_usage) _php_stream_temp_create((mode), (max_memory_usage) STREAMS_CC TSRMLS_CC) -#define php_stream_temp_create_rel(mode, max_memory_usage) _php_stream_temp_create((mode), (max_memory_usage) STREAMS_REL_CC TSRMLS_CC) -#define php_stream_temp_open(mode, max_memory_usage, buf, length) _php_stream_temp_open((mode), (max_memory_usage), (buf), (length) STREAMS_CC TSRMLS_CC) - - -PHPAPI php_stream *_php_stream_memory_create(int mode STREAMS_DC TSRMLS_DC); -PHPAPI php_stream *_php_stream_memory_open(int mode, char *buf, size_t length STREAMS_DC TSRMLS_DC); -PHPAPI char *_php_stream_memory_get_buffer(php_stream *stream, size_t *length STREAMS_DC TSRMLS_DC); - -PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STREAMS_DC TSRMLS_DC); -PHPAPI php_stream *_php_stream_temp_open(int mode, size_t max_memory_usage, char *buf, size_t length STREAMS_DC TSRMLS_DC); - -extern php_stream_ops php_stream_memory_ops; -extern php_stream_ops php_stream_temp_ops; - -#define PHP_STREAM_IS_MEMORY &php_stream_memory_ops -#define PHP_STREAM_IS_TEMP &php_stream_temp_ops - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/php_network.h b/main/php_network.h deleted file mode 100644 index b165e21b32..0000000000 --- a/main/php_network.h +++ /dev/null @@ -1,214 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Stig Venaas <venaas@uninett.no> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef _PHP_NETWORK_H -#define _PHP_NETWORK_H - -#ifdef PHP_WIN32 -# ifndef WINNT -# define WINNT 1 -# endif -# undef FD_SETSIZE -# include "arpa/inet.h" - /* Apache folks decided that strtoul was evil and redefined - * it to something that breaks the windows headers */ -# undef strtoul -/* defines socklen_t and some IPV6 stuff */ -# include <ws2tcpip.h> -# if HAVE_WSPIAPI_H - /* getaddrinfo */ -# include <wspiapi.h> -# endif -#else -# undef closesocket -# define closesocket close -#endif - -#ifndef HAVE_SHUTDOWN -#undef shutdown -#define shutdown(s,n) /* nothing */ -#endif - -#ifdef PHP_WIN32 -#define EWOULDBLOCK WSAEWOULDBLOCK -#define EINPROGRESS WSAEWOULDBLOCK -# define fsync _commit -# define ftruncate(a, b) chsize(a, b) -#endif /* defined(PHP_WIN32) */ - -#ifdef PHP_WIN32 -#define php_socket_errno() WSAGetLastError() -#else -#define php_socket_errno() errno -#endif - -/* like strerror, but caller must efree the returned string, - * unless buf is not NULL. - * Also works sensibly for win32 */ -PHPAPI char *php_socket_strerror(long err, char *buf, size_t bufsize); - -#ifdef HAVE_NETINET_IN_H -# include <netinet/in.h> -#endif - -#ifdef HAVE_SYS_SOCKET_H -#include <sys/socket.h> -#endif - -/* These are here, rather than with the win32 counterparts above, - * since <sys/socket.h> defines them. */ -#ifndef SHUT_RD -# define SHUT_RD 0 -# define SHUT_WR 1 -# define SHUT_RDWR 2 -#endif - -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#endif - -#ifdef HAVE_STDDEF_H -#include <stddef.h> -#endif - -#ifdef PHP_WIN32 -typedef SOCKET php_socket_t; -#else -typedef int php_socket_t; -#endif - -#ifdef PHP_WIN32 -# define SOCK_ERR INVALID_SOCKET -# define SOCK_CONN_ERR SOCKET_ERROR -# define SOCK_RECV_ERR SOCKET_ERROR -#else -# define SOCK_ERR -1 -# define SOCK_CONN_ERR -1 -# define SOCK_RECV_ERR -1 -#endif - -#define PHP_SOCK_CHUNK_SIZE 8192 - -#ifdef HAVE_SOCKADDR_STORAGE -typedef struct sockaddr_storage php_sockaddr_storage; -#else -typedef struct { -#ifdef HAVE_SOCKADDR_LEN - unsigned char ss_len; - unsigned char ss_family; -#else - unsigned short ss_family; -#endif - char info[126]; -} php_sockaddr_storage; -#endif - -PHPAPI php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short port, - int socktype, int asynchronous, struct timeval *timeout, char **error_string, - int *error_code - TSRMLS_DC); - -PHPAPI int php_network_connect_socket(php_socket_t sockfd, - const struct sockaddr *addr, - socklen_t addrlen, - int asynchronous, - struct timeval *timeout, - char **error_string, - int *error_code); - -#define php_connect_nonb(sock, addr, addrlen, timeout) \ - php_network_connect_socket((sock), (addr), (addrlen), 0, (timeout), NULL, NULL) - -PHPAPI php_socket_t php_network_bind_socket_to_local_addr(const char *host, unsigned port, - int socktype, char **error_string, int *error_code - TSRMLS_DC); - -PHPAPI php_socket_t php_network_accept_incoming(php_socket_t srvsock, - char **textaddr, long *textaddrlen, - struct sockaddr **addr, - socklen_t *addrlen, - struct timeval *timeout, - char **error_string, - int *error_code - TSRMLS_DC); - -PHPAPI int php_network_get_sock_name(php_socket_t sock, - char **textaddr, long *textaddrlen, - struct sockaddr **addr, - socklen_t *addrlen - TSRMLS_DC); - -PHPAPI int php_network_get_peer_name(php_socket_t sock, - char **textaddr, long *textaddrlen, - struct sockaddr **addr, - socklen_t *addrlen - TSRMLS_DC); - -PHPAPI void php_any_addr(int family, php_sockaddr_storage *addr, unsigned short port); -PHPAPI int php_sockaddr_size(php_sockaddr_storage *addr); - - -struct _php_netstream_data_t { - php_socket_t socket; - char is_blocked; - struct timeval timeout; - char timeout_event; - size_t ownsize; -}; -typedef struct _php_netstream_data_t php_netstream_data_t; -PHPAPI extern php_stream_ops php_stream_socket_ops; -extern php_stream_ops php_stream_generic_socket_ops; -#define PHP_STREAM_IS_SOCKET (&php_stream_socket_ops) - -PHPAPI php_stream *_php_stream_sock_open_from_socket(php_socket_t socket, const char *persistent_id STREAMS_DC TSRMLS_DC ); -/* open a connection to a host using php_hostconnect and return a stream */ -PHPAPI php_stream *_php_stream_sock_open_host(const char *host, unsigned short port, - int socktype, struct timeval *timeout, const char *persistent_id STREAMS_DC TSRMLS_DC); -PHPAPI void php_network_populate_name_from_sockaddr( - /* input address */ - struct sockaddr *sa, socklen_t sl, - /* output readable address */ - char **textaddr, long *textaddrlen, - /* output address */ - struct sockaddr **addr, - socklen_t *addrlen - TSRMLS_DC); - -PHPAPI int php_network_parse_network_address_with_port(const char *addr, - long addrlen, struct sockaddr *sa, socklen_t *sl TSRMLS_DC); - -#define php_stream_sock_open_from_socket(socket, persistent) _php_stream_sock_open_from_socket((socket), (persistent) STREAMS_CC TSRMLS_CC) -#define php_stream_sock_open_host(host, port, socktype, timeout, persistent) _php_stream_sock_open_host((host), (port), (socktype), (timeout), (persistent) STREAMS_CC TSRMLS_CC) - -/* {{{ memory debug */ -#define php_stream_sock_open_from_socket_rel(socket, persistent) _php_stream_sock_open_from_socket((socket), (persistent) STREAMS_REL_CC TSRMLS_CC) -#define php_stream_sock_open_host_rel(host, port, socktype, timeout, persistent) _php_stream_sock_open_host((host), (port), (socktype), (timeout), (persistent) STREAMS_REL_CC TSRMLS_CC) -#define php_stream_sock_open_unix_rel(path, pathlen, persistent, timeval) _php_stream_sock_open_unix((path), (pathlen), (persistent), (timeval) STREAMS_REL_CC TSRMLS_CC) - -/* }}} */ - -#endif /* _PHP_NETWORK_H */ - -/* - * Local variables: - * tab-width: 8 - * c-basic-offset: 8 - * End: - */ diff --git a/main/php_open_temporary_file.c b/main/php_open_temporary_file.c deleted file mode 100644 index a3db16deb6..0000000000 --- a/main/php_open_temporary_file.c +++ /dev/null @@ -1,264 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" - -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - -#ifdef PHP_WIN32 -#define O_RDONLY _O_RDONLY -#include "win32/param.h" -#include "win32/winutil.h" -#elif defined(NETWARE) -#ifdef USE_WINSOCK -/*#include <ws2nlm.h>*/ -#include <novsock2.h> -#else -#include <sys/socket.h> -#endif -#ifdef NEW_LIBC -#include <sys/param.h> -#else -#include "netware/param.h" -#endif -#include "netware/mktemp.h" -#else -#include <sys/param.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> -#if HAVE_ARPA_INET_H -#include <arpa/inet.h> -#endif -#endif -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#endif - -#ifdef HAVE_SYS_FILE_H -#include <sys/file.h> -#endif - -#if !defined(P_tmpdir) -#define P_tmpdir "" -#endif - -/* {{{ php_do_open_temporary_file */ - -/* Loosely based on a tempnam() implementation by UCLA */ - -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -static int php_do_open_temporary_file(const char *path, const char *pfx, char **opened_path_p TSRMLS_DC) -{ - char *trailing_slash; - char *opened_path; - int fd = -1; -#ifndef HAVE_MKSTEMP - int open_flags = O_CREAT | O_TRUNC | O_RDWR -#ifdef PHP_WIN32 - | _O_BINARY -#endif - ; -#endif -#ifdef NETWARE - char *file_path = NULL; -#endif - - if (!path) { - return -1; - } - - if (!(opened_path = emalloc(MAXPATHLEN))) { - return -1; - } - - if (IS_SLASH(path[strlen(path)-1])) { - trailing_slash = ""; - } else { - trailing_slash = "/"; - } - - (void)snprintf(opened_path, MAXPATHLEN, "%s%s%sXXXXXX", path, trailing_slash, pfx); - -#ifdef PHP_WIN32 - if (GetTempFileName(path, pfx, 0, opened_path)) { - /* Some versions of windows set the temp file to be read-only, - * which means that opening it will fail... */ - VCWD_CHMOD(opened_path, 0600); - fd = VCWD_OPEN_MODE(opened_path, open_flags, 0600); - } -#elif defined(NETWARE) - /* Using standard mktemp() implementation for NetWare */ - file_path = mktemp(opened_path); - if (file_path) { - fd = VCWD_OPEN(file_path, open_flags); - } -#elif defined(HAVE_MKSTEMP) - fd = mkstemp(opened_path); -#else - if (mktemp(opened_path)) { - fd = VCWD_OPEN(opened_path, open_flags); - } -#endif - if (fd == -1 || !opened_path_p) { - efree(opened_path); - } else { - *opened_path_p = opened_path; - } - return fd; -} -/* }}} */ - -/* - * Determine where to place temporary files. - */ -const char* get_temporary_directory() -{ - /* Cache the chosen temporary directory. */ - static char* temporary_directory; - - /* Did we determine the temporary directory already? */ - if (temporary_directory) { - return temporary_directory; - } - -#ifdef PHP_WIN32 - /* We can't count on the environment variables TEMP or TMP, - * and so must make the Win32 API call to get the default - * directory for temporary files. Note this call checks - * the environment values TMP and TEMP (in order) first. - */ - { - char sTemp[MAX_PATH]; - DWORD n = GetTempPath(sizeof(sTemp),sTemp); - assert(0 < n); /* should *never* fail! */ - temporary_directory = strdup(sTemp); - return temporary_directory; - } -#else - /* On Unix use the (usual) TMPDIR environment variable. */ - { - char* s = getenv("TMPDIR"); - if (s) { - temporary_directory = strdup(s); - return temporary_directory; - } - } -#ifdef P_tmpdir - /* Use the standard default temporary directory. */ - if (P_tmpdir) { - temporary_directory = P_tmpdir; - return temporary_directory; - } -#endif - /* Shouldn't ever(!) end up here ... last ditch default. */ - temporary_directory = "/tmp"; - return temporary_directory; -#endif -} - -/* {{{ php_open_temporary_file - * - * Unlike tempnam(), the supplied dir argument takes precedence - * over the TMPDIR environment variable - * This function should do its best to return a file pointer to a newly created - * unique file, on every platform. - */ -PHPAPI int php_open_temporary_fd(const char *dir, const char *pfx, char **opened_path_p TSRMLS_DC) -{ - int fd; - - if (!pfx) { - pfx = "tmp."; - } - if (opened_path_p) { - *opened_path_p = NULL; - } - - /* Try the directory given as parameter. */ - fd = php_do_open_temporary_file(dir, pfx, opened_path_p TSRMLS_CC); - if (fd == -1) { - /* Use default temporary directory. */ - fd = php_do_open_temporary_file(get_temporary_directory(), pfx, opened_path_p TSRMLS_CC); - } - return fd; -} - -PHPAPI FILE *php_open_temporary_file(const char *dir, const char *pfx, char **opened_path_p TSRMLS_DC) -{ - FILE *fp; - int fd = php_open_temporary_fd(dir, pfx, opened_path_p TSRMLS_CC); - - if (fd == -1) { - return NULL; - } - - fp = fdopen(fd, "r+b"); - if (fp == NULL) { - close(fd); - } - - return fp; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/php_open_temporary_file.h b/main/php_open_temporary_file.h deleted file mode 100644 index 50092d0e52..0000000000 --- a/main/php_open_temporary_file.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_OPEN_TEMPORARY_FILE_H -#define PHP_OPEN_TEMPORARY_FILE_H - -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); - -#endif /* PHP_OPEN_TEMPORARY_FILE_H */ diff --git a/main/php_output.h b/main/php_output.h deleted file mode 100644 index 04d69e2672..0000000000 --- a/main/php_output.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_OUTPUT_H -#define PHP_OUTPUT_H - -typedef void (*php_output_handler_func_t)(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC); - -PHPAPI void php_output_startup(void); -PHPAPI void php_output_activate(TSRMLS_D); -PHPAPI void php_output_set_status(zend_bool status TSRMLS_DC); -PHPAPI void php_output_register_constants(TSRMLS_D); -PHPAPI int php_body_write(const char *str, uint str_length TSRMLS_DC); -PHPAPI int php_header_write(const char *str, uint str_length TSRMLS_DC); -PHPAPI int php_start_ob_buffer(zval *output_handler, uint chunk_size, zend_bool erase TSRMLS_DC); -PHPAPI int php_start_ob_buffer_named(const char *output_handler_name, uint chunk_size, zend_bool erase TSRMLS_DC); -PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush TSRMLS_DC); -PHPAPI void php_end_ob_buffers(zend_bool send_buffer TSRMLS_DC); -PHPAPI int php_ob_get_buffer(zval *p TSRMLS_DC); -PHPAPI int php_ob_get_length(zval *p TSRMLS_DC); -PHPAPI void php_start_implicit_flush(TSRMLS_D); -PHPAPI void php_end_implicit_flush(TSRMLS_D); -PHPAPI char *php_get_output_start_filename(TSRMLS_D); -PHPAPI int php_get_output_start_lineno(TSRMLS_D); -PHPAPI void php_ob_set_internal_handler(php_output_handler_func_t internal_output_handler, uint buffer_size, char *handler_name, zend_bool erase TSRMLS_DC); -PHPAPI int php_ob_handler_used(char *handler_name TSRMLS_DC); -PHPAPI int php_ob_init_conflict(char *handler_new, char *handler_set TSRMLS_DC); -PHPAPI int php_ob_get_buffer(zval *p TSRMLS_DC); -PHPAPI int php_ob_get_length(zval *p TSRMLS_DC); - -PHP_FUNCTION(ob_start); -PHP_FUNCTION(ob_flush); -PHP_FUNCTION(ob_clean); -PHP_FUNCTION(ob_end_flush); -PHP_FUNCTION(ob_end_clean); -PHP_FUNCTION(ob_get_flush); -PHP_FUNCTION(ob_get_clean); -PHP_FUNCTION(ob_get_contents); -PHP_FUNCTION(ob_get_length); -PHP_FUNCTION(ob_get_level); -PHP_FUNCTION(ob_get_status); -PHP_FUNCTION(ob_implicit_flush); -PHP_FUNCTION(ob_list_handlers); - -typedef struct _php_ob_buffer { - char *buffer; - uint size; - uint text_length; - int block_size; - uint chunk_size; - int status; - zval *output_handler; - php_output_handler_func_t internal_output_handler; - char *internal_output_handler_buffer; - uint internal_output_handler_buffer_size; - char *handler_name; - zend_bool erase; -} php_ob_buffer; - -typedef struct _php_output_globals { - int (*php_body_write)(const char *str, uint str_length TSRMLS_DC); /* string output */ - int (*php_header_write)(const char *str, uint str_length TSRMLS_DC); /* unbuffer string output */ - php_ob_buffer active_ob_buffer; - unsigned char implicit_flush; - char *output_start_filename; - int output_start_lineno; - zend_stack ob_buffers; - int ob_nesting_level; - zend_bool ob_lock; - zend_bool disable_output; -} php_output_globals; - -#ifdef ZTS -#define OG(v) TSRMG(output_globals_id, php_output_globals *, v) -ZEND_API extern int output_globals_id; -#else -#define OG(v) (output_globals.v) -ZEND_API extern php_output_globals output_globals; -#endif - -#define PHP_OUTPUT_HANDLER_START (1<<0) -#define PHP_OUTPUT_HANDLER_CONT (1<<1) -#define PHP_OUTPUT_HANDLER_END (1<<2) - -#define PHP_OUTPUT_HANDLER_INTERNAL 0 -#define PHP_OUTPUT_HANDLER_USER 1 - -PHP_FUNCTION(output_add_rewrite_var); -PHP_FUNCTION(output_reset_rewrite_vars); - - -#endif /* PHP_OUTPUT_H */ diff --git a/main/php_realpath.c b/main/php_realpath.c deleted file mode 100644 index 0607e91cc4..0000000000 --- a/main/php_realpath.c +++ /dev/null @@ -1,285 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sander Steffann (sander@steffann.nl) | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" - -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <sys/stat.h> - -#ifndef MAXSYMLINKS -#define MAXSYMLINKS 32 -#endif - -#ifndef S_ISDIR -#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR) -#endif - -char *php_realpath(char *path, char resolved_path[]); - -#ifdef PHP_WIN32 -#define IS_SLASH(p) ((p) == '/' || (p) == '\\') -#else -#define IS_SLASH(p) ((p) == '/') -#endif - -char *php_realpath(char *path, char resolved_path []) { - char path_construction[MAXPATHLEN]; /* We build the result in here */ - char *writepos; /* Position to write next char */ - - char path_copy[MAXPATHLEN]; /* A work-copy of the path */ - char *workpos; /* working position in *path */ - -#if !defined(PHP_WIN32) - char buf[MAXPATHLEN]; /* Buffer for readlink */ - int linklength; /* The result from readlink */ -#endif - int linkcount = 0; /* Count symlinks to avoid loops */ - - struct stat filestat; /* result from stat */ - -#ifdef PHP_WIN32 - char *temppos; /* position while counting '.' */ - int dotcount; /* number of '.' */ - int t; /* counter */ -#endif - - /* Set the work-position to the beginning of the given path */ - strcpy(path_copy, path); - workpos = path_copy; - -#ifdef PHP_WIN32 - /* Find out where we start - Windows version */ - if (IS_SLASH(*workpos)) { - /* We start at the root of the current drive */ - /* Get the current directory */ - if (V_GETCWD(path_construction, MAXPATHLEN-1) == NULL) { - /* Unable to get cwd */ - resolved_path[0] = 0; - return NULL; - } - /* We only need the first three chars (for example "C:\") */ - path_construction[3] = 0; - workpos++; - } else if (workpos[1] == ':') { - /* A drive-letter is specified, copy it */ - strncpy(path_construction, path, 2); - strcat(path_construction, "\\"); - workpos++; - workpos++; - } else { - /* Use the current directory */ - if (V_GETCWD(path_construction, MAXPATHLEN-1) == NULL) { - /* Unable to get cwd */ - resolved_path[0] = 0; - return NULL; - } - strcat(path_construction, "\\"); - } -#else - /* Find out where we start - Unix version */ - if (*workpos == '/') { - /* We start at the root */ - strcpy(path_construction, "/"); - workpos++; - } else { - /* Use the current directory */ - if (V_GETCWD(path_construction, MAXPATHLEN-1) == NULL) { - /* Unable to get cwd */ - resolved_path[0] = 0; - return NULL; - } - strcat(path_construction, "/"); - } -#endif - - /* Set the next-char-position */ - writepos = &path_construction[strlen(path_construction)]; - - /* Go to the end, then stop */ - while(*workpos != 0) { - /* Strip (back)slashes */ - while(IS_SLASH(*workpos)) workpos++; - -#ifdef PHP_WIN32 - /* reset dotcount */ - dotcount = 0; - - /* Look for .. */ - if ((workpos[0] == '.') && (workpos[1] != 0)) { - /* Windows accepts \...\ as \..\..\, \....\ as \..\..\..\, etc */ - /* At least Win98 does */ - - temppos = workpos; - while(*temppos++ == '.') { - dotcount++; - if (!IS_SLASH(*temppos) && (*temppos != 0) && (*temppos != '.')) { - /* This is not a /../ component, but a filename that starts with '.' */ - dotcount = 0; - } - } - - /* Go back dotcount-1 times */ - for (t=0 ; t<(dotcount-1) ; t++) { - workpos++; /* move to next '.' */ - - /* Can we still go back? */ - if ((writepos-3) <= path_construction) return NULL; - - /* Go back */ - writepos--; /* move to '\' */ - writepos--; - while(!IS_SLASH(*writepos)) writepos--; /* skip until previous '\\' */ - } - workpos++; - } - - /* No special case */ - if (dotcount == 0) { - /* Append */ - while(!IS_SLASH(*workpos) && (*workpos != 0)) { - *writepos++ = *workpos++; - } - } - - /* Just one '.', go to next element */ - if (dotcount == 1) { - while(!IS_SLASH(*workpos) && (*workpos != 0)) { - *workpos++; - } - - /* Avoid double \ in the result */ - writepos--; - } - - /* If it was a directory, append a slash */ - if (IS_SLASH(*workpos)) { - *writepos++ = *workpos++; - } - *writepos = 0; -#else /* defined(PHP_WIN32) */ - /* Look for .. */ - if ((workpos[0] == '.') && (workpos[1] != 0)) { - if ((workpos[1] == '.') && ((workpos[2] == '/') || (workpos[2] == 0))) { - /* One directory back */ - /* Set pointers to right position */ - workpos++; /* move to second '.' */ - workpos++; /* move to '/' */ - - /* Only apply .. if not in root */ - if ((writepos-1) > path_construction) { - writepos--; /* move to '/' */ - while(*--writepos != '/') ; /* skip until previous '/' */ - } - } else { - if (workpos[1] == '/') { - /* Found a /./ skip it */ - workpos++; /* move to '/' */ - - /* Avoid double / in the result */ - writepos--; - } else { - /* No special case, the name just started with a . */ - /* Append */ - while((*workpos != '/') && (*workpos != 0)) { - *writepos++ = *workpos++; - } - } - } - } else { - /* No special case */ - /* Append */ - while((*workpos != '/') && (*workpos != 0)) { - *writepos++ = *workpos++; - } - } - -#if HAVE_SYMLINK - /* We are going to use path_construction, so close it */ - *writepos = 0; - - /* Check the current location to see if it is a symlink */ - if((linklength = readlink(path_construction, buf, MAXPATHLEN)) != -1) { - /* Check linkcount */ - if (linkcount > MAXSYMLINKS) return NULL; - - /* Count this symlink */ - linkcount++; - - /* Set end of buf */ - buf[linklength] = 0; - - /* Check for overflow */ - if ((strlen(workpos) + strlen(buf) + 1) >= MAXPATHLEN) return NULL; - - /* Remove the symlink-component wrom path_construction */ - writepos--; /* move to '/' */ - while(*--writepos != '/') ; /* skip until previous '/' */ - *++writepos = 0; /* end of string after '/' */ - - /* If the symlink starts with a '/', empty path_construction */ - if (*buf == '/') { - *path_construction = 0; - writepos = path_construction; - } - - /* Insert symlink into path_copy */ - strcat(buf, workpos); - strcpy(path_copy, buf); - workpos = path_copy; - } -#endif /* HAVE_SYMLINK */ - - /* If it was a directory, append a slash */ - if (*workpos == '/') { - *writepos++ = *workpos++; - } - *writepos = 0; -#endif /* defined(PHP_WIN32) */ - } - - /* Check if the resolved path is a directory */ - if (V_STAT(path_construction, &filestat) != 0) { - if (errno != ENOENT) return NULL; - } else { - if (S_ISDIR(filestat.st_mode)) { - /* It's a directory, append a / if needed */ - if (*(writepos-1) != '/') { - /* Check for overflow */ - if ((strlen(workpos) + 2) >= MAXPATHLEN) { - return NULL; - } - *writepos++ = '/'; - *writepos = 0; - } - } - } - - strcpy(resolved_path, path_construction); - return resolved_path; -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/main/php_reentrancy.h b/main/php_reentrancy.h deleted file mode 100644 index bbbe0343ab..0000000000 --- a/main/php_reentrancy.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef PHP_REENTRANCY_H -#define PHP_REENTRANCY_H - -#include "php.h" - -#include <sys/types.h> -#ifdef HAVE_DIRENT_H -#include <dirent.h> -#endif -#include <time.h> - -/* currently, PHP does not check for these functions, but assumes - that they are available on all systems. */ - -#define HAVE_LOCALTIME 1 -#define HAVE_GMTIME 1 -#define HAVE_ASCTIME 1 -#define HAVE_CTIME 1 - -#if defined(PHP_IRIX_TIME_R) -#undef HAVE_ASCTIME_R -#undef HAVE_CTIME_R -#endif - -#if defined(PHP_HPUX_TIME_R) -#undef HAVE_LOCALTIME_R -#undef HAVE_ASCTIME_R -#undef HAVE_CTIME_R -#undef HAVE_GMTIME_R -#endif - -#if defined(HAVE_POSIX_READDIR_R) -#define php_readdir_r readdir_r -#else -PHPAPI int php_readdir_r(DIR *dirp, struct dirent *entry, - struct dirent **result); -#endif - -#if !defined(HAVE_LOCALTIME_R) && defined(HAVE_LOCALTIME) -#define PHP_NEED_REENTRANCY 1 -PHPAPI struct tm *php_localtime_r(const time_t *const timep, struct tm *p_tm); -#else -#define php_localtime_r localtime_r -#ifdef MISSING_LOCALTIME_R_DECL -struct tm *localtime_r(const time_t *const timep, struct tm *p_tm); -#endif -#endif - - -#if !defined(HAVE_CTIME_R) && defined(HAVE_CTIME) -#define PHP_NEED_REENTRANCY 1 -PHPAPI char *php_ctime_r(const time_t *clock, char *buf); -#else -#define php_ctime_r ctime_r -#ifdef MISSING_CTIME_R_DECL -char *ctime_r(const time_t *clock, char *buf); -#endif -#endif - - -#if !defined(HAVE_ASCTIME_R) && defined(HAVE_ASCTIME) -#define PHP_NEED_REENTRANCY 1 -PHPAPI char *php_asctime_r(const struct tm *tm, char *buf); -#else -#define php_asctime_r asctime_r -#ifdef MISSING_ASCTIME_R_DECL -char *asctime_r(const struct tm *tm, char *buf); -#endif -#endif - - -#if !defined(HAVE_GMTIME_R) && defined(HAVE_GMTIME) || defined(__BEOS__) -#define PHP_NEED_REENTRANCY 1 -PHPAPI struct tm *php_gmtime_r(const time_t *const timep, struct tm *p_tm); -#else -#define php_gmtime_r gmtime_r -#ifdef MISSING_GMTIME_R_DECL -struct tm *php_gmtime_r(const time_t *const timep, struct tm *p_tm); -#endif -#endif - -#if !defined(HAVE_STRTOK_R) -PHPAPI char *php_strtok_r(char *s, const char *delim, char **last); -#else -#define php_strtok_r strtok_r -#ifdef MISSING_STRTOK_R_DECL -char *strtok_r(char *s, const char *delim, char **last); -#endif -#endif - -#if !defined(HAVE_RAND_R) -PHPAPI int php_rand_r(unsigned int *seed); -#else -#define php_rand_r rand_r -#endif - -#if !defined(ZTS) -#undef PHP_NEED_REENTRANCY -#endif - -#if defined(PHP_NEED_REENTRANCY) -void reentrancy_startup(void); -void reentrancy_shutdown(void); -#else -#define reentrancy_startup() -#define reentrancy_shutdown() -#endif - -#endif diff --git a/main/php_regex.h b/main/php_regex.h deleted file mode 100644 index 56fdcfd4bf..0000000000 --- a/main/php_regex.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_REGEX_H -#define PHP_REGEX_H - -/* - * REGEX means: - * 0.. system regex - * 1.. bundled regex - */ - -#if REGEX -/* get aliases */ -#include "regex/regex_extra.h" -#include "regex/regex.h" - -/* get rid of aliases */ -#define PHP_NO_ALIASES -#include "regex/regex_extra.h" -#undef PHP_NO_ALIASES - -#undef _PCREPOSIX_H -#define _PCREPOSIX_H 1 - -#ifndef _REGEX_H -#define _REGEX_H 1 /* this should stop Apache from loading the system version of regex.h */ -#endif -#ifndef _REGEX_H_ -#define _REGEX_H_ 1 -#endif -#ifndef _RX_H -#define _RX_H 1 /* Try defining these for Linux to */ -#endif -#ifndef __REGEXP_LIBRARY_H__ -#define __REGEXP_LIBRARY_H__ 1 /* avoid Apache including regex.h */ -#endif -#ifndef _H_REGEX -#define _H_REGEX 1 /* This one is for AIX */ -#endif -#elif REGEX == 0 -#include <regex.h> -#ifndef _REGEX_H_ -#define _REGEX_H_ 1 -#endif -#endif - -#endif /* PHP_REGEX_H */ diff --git a/main/php_scandir.c b/main/php_scandir.c deleted file mode 100644 index e24b4137f5..0000000000 --- a/main/php_scandir.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Shane Caraveo <shane@caraveo.com> | - | Ilia Alshanetsky <ilia@prohost.org> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef PHP_WIN32 -#include "config.w32.h" -#else -#include "php_config.h" -#endif - -#include "php_scandir.h" - -#ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif - -#ifdef HAVE_DIRENT_H -#include <dirent.h> -#endif - -#ifndef HAVE_SCANDIR - -#ifdef PHP_WIN32 -#include "win32/readdir.h" -#endif - -#include <stdlib.h> -#include <search.h> - -#endif /* HAVE_SCANDIR */ - -#ifndef HAVE_ALPHASORT - -#ifdef HAVE_STRING_H -#include <string.h> -#endif - -int php_alphasort(const struct dirent **a, const struct dirent **b) -{ - return strcoll((*a)->d_name,(*b)->d_name); -} -#endif /* HAVE_ALPHASORT */ - -#ifndef HAVE_SCANDIR -int php_scandir(const char *dirname, struct dirent **namelist[], int (*selector) (const struct dirent *entry), int (*compare) (const struct dirent **a, const struct dirent **b)) -{ - DIR *dirp = NULL; - struct dirent **vector = NULL; - struct dirent *dp = NULL; - int vector_size = 0; - int nfiles = 0; - - if (namelist == NULL) { - return -1; - } - - if (!(dirp = opendir(dirname))) { - return -1; - } - - while ((dp = readdir(dirp)) != NULL) { - int dsize = 0; - struct dirent *newdp = NULL; - - if (selector && (*selector)(dp) == 0) { - continue; - } - - if (nfiles == vector_size) { - struct dirent **newv; - if (vector_size == 0) { - vector_size = 10; - } else { - vector_size *= 2; - } - - newv = (struct dirent **) realloc (vector, vector_size * sizeof (struct dirent *)); - if (!newv) { - return -1; - } - vector = newv; - } - - dsize = sizeof (struct dirent) + ((strlen(dp->d_name) + 1) * sizeof(char)); - newdp = (struct dirent *) malloc(dsize); - - if (newdp == NULL) { - goto fail; - } - - vector[nfiles++] = (struct dirent *) memcpy(newdp, dp, dsize); - } - - closedir(dirp); - - *namelist = vector; - - if (compare) { - qsort (*namelist, nfiles, sizeof(struct dirent *), compare); - } - - return nfiles; - -fail: - while (nfiles-- > 0) { - free(vector[nfiles]); - } - free(vector); - return -1; -} -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/php_scandir.h b/main/php_scandir.h deleted file mode 100644 index 0ff56ebbc2..0000000000 --- a/main/php_scandir.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Shane Caraveo <shane@caraveo.com> | - | Ilia Alshanetsky <ilia@prohost.org> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_SCANDIR_H -#define PHP_SCANDIR_H - -#include <sys/types.h> - -#ifdef HAVE_SYS_DIR_H -#include <sys/dir.h> -#endif - -#ifdef PHP_WIN32 -#include "config.w32.h" -#include "win32/readdir.h" -#else -#include "php_config.h" -#endif - -#ifdef HAVE_DIRENT_H -#include <dirent.h> -#endif - -#ifdef HAVE_SCANDIR -#define php_scandir scandir -#else -int php_scandir(const char *dirname, struct dirent **namelist[], int (*selector) (const struct dirent *entry), int (*compare) (const struct dirent **a, const struct dirent **b)); -#endif - -#ifdef HAVE_ALPHASORT -#define php_alphasort alphasort -#else -int php_alphasort(const struct dirent **a, const struct dirent **b); -#endif - -#endif /* PHP_SCANDIR_H */ diff --git a/main/php_sprintf.c b/main/php_sprintf.c deleted file mode 100644 index f7daab2952..0000000000 --- a/main/php_sprintf.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Jaakko Hyvätti <jaakko.hyvatti@iki.fi> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include <stdio.h> -#include <stdarg.h> -#ifdef NETWARE -#include "config.nw.h" -#else -#include "php_config.h" -#endif - -#if PHP_BROKEN_SPRINTF - -int -php_sprintf (char*s, const char* format, ...) -{ - va_list args; - char *ret; - - va_start (args, format); - s[0] = '\0'; - ret = vsprintf (s, format, args); - va_end (args); - if (!ret) - return -1; - return strlen (s); -} - -#endif /* PHP_BROKEN_SPRINTF */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/php_streams.h b/main/php_streams.h deleted file mode 100755 index 2fcb1c413d..0000000000 --- a/main/php_streams.h +++ /dev/null @@ -1,529 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Wez Furlong (wez@thebrainroom.com) | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef PHP_STREAMS_H -#define PHP_STREAMS_H - -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#endif -#include <sys/types.h> -#include <sys/stat.h> - -PHPAPI int php_file_le_stream(void); -PHPAPI int php_file_le_pstream(void); - -/* {{{ Streams memory debugging stuff */ - -#if ZEND_DEBUG -/* these have more of a dependency on the definitions of the zend macros than - * I would prefer, but doing it this way saves loads of idefs :-/ */ -# define STREAMS_D int __php_stream_call_depth ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC -# define STREAMS_C 0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC -# define STREAMS_REL_C __php_stream_call_depth + 1 ZEND_FILE_LINE_CC, \ - __php_stream_call_depth ? __zend_orig_filename : __zend_filename, \ - __php_stream_call_depth ? __zend_orig_lineno : __zend_lineno - -# define STREAMS_DC , STREAMS_D -# define STREAMS_CC , STREAMS_C -# define STREAMS_REL_CC , STREAMS_REL_C - -#else -# define STREAMS_D -# define STREAMS_C -# define STREAMS_REL_C -# define STREAMS_DC -# define STREAMS_CC -# define STREAMS_REL_CC -#endif - -/* these functions relay the file/line number information. They are depth aware, so they will pass - * the ultimate ancestor, which is useful, because there can be several layers of calls */ -#define php_stream_alloc_rel(ops, thisptr, persistent, mode) _php_stream_alloc((ops), (thisptr), (persistent), (mode) STREAMS_REL_CC TSRMLS_CC) - -#define php_stream_copy_to_mem_rel(src, buf, maxlen, persistent) _php_stream_copy_to_mem((src), (buf), (maxlen), (persistent) STREAMS_REL_CC TSRMLS_CC) - -#define php_stream_fopen_rel(filename, mode, opened, options) _php_stream_fopen((filename), (mode), (opened), (options) STREAMS_REL_CC TSRMLS_CC) - -#define php_stream_fopen_with_path_rel(filename, mode, path, opened, options) _php_stream_fopen_with_path((filename), (mode), (path), (opened), (options) STREAMS_REL_CC TSRMLS_CC) - -#define php_stream_fopen_from_fd_rel(fd, mode, persistent_id) _php_stream_fopen_from_fd((fd), (mode), (persistent_id) STREAMS_REL_CC TSRMLS_CC) -#define php_stream_fopen_from_file_rel(file, mode) _php_stream_fopen_from_file((file), (mode) STREAMS_REL_CC TSRMLS_CC) - -#define php_stream_fopen_from_pipe_rel(file, mode) _php_stream_fopen_from_pipe((file), (mode) STREAMS_REL_CC TSRMLS_CC) - -#define php_stream_fopen_tmpfile_rel() _php_stream_fopen_tmpfile(0 STREAMS_REL_CC TSRMLS_CC) - -#define php_stream_fopen_temporary_file_rel(dir, pfx, opened_path) _php_stream_fopen_temporary_file((dir), (pfx), (opened_path) STREAMS_REL_CC TSRMLS_CC) - -#define php_stream_open_wrapper_rel(path, mode, options, opened) _php_stream_open_wrapper_ex((path), (mode), (options), (opened), NULL STREAMS_REL_CC TSRMLS_CC) -#define php_stream_open_wrapper_ex_rel(path, mode, options, opened, context) _php_stream_open_wrapper_ex((path), (mode), (options), (opened), (context) STREAMS_REL_CC TSRMLS_CC) - -#define php_stream_make_seekable_rel(origstream, newstream, flags) _php_stream_make_seekable((origstream), (newstream), (flags) STREAMS_REL_CC TSRMLS_CC) - -/* }}} */ - -/* The contents of the php_stream_ops and php_stream should only be accessed - * using the functions/macros in this header. - * If you need to get at something that doesn't have an API, - * drop me a line <wez@thebrainroom.com> and we can sort out a way to do - * it properly. - * - * The only exceptions to this rule are that stream implementations can use - * the php_stream->abstract pointer to hold their context, and streams - * opened via stream_open_wrappers can use the zval ptr in - * php_stream->wrapperdata to hold meta data for php scripts to - * retrieve using file_get_wrapper_data(). */ - -typedef struct _php_stream php_stream; -typedef struct _php_stream_wrapper php_stream_wrapper; -typedef struct _php_stream_context php_stream_context; -typedef struct _php_stream_filter php_stream_filter; - -#include "streams/php_stream_context.h" -#include "streams/php_stream_filter_api.h" - -typedef struct _php_stream_statbuf { -#if defined(NETWARE) && defined(CLIB_STAT_PATCH) - struct stat_libc sb; /* regular info */ -#else - struct stat sb; /* regular info */ -#endif - /* extended info to go here some day: content-type etc. etc. */ -} php_stream_statbuf; - -typedef struct _php_stream_dirent { - char d_name[MAXPATHLEN]; -} php_stream_dirent; - -/* operations on streams that are file-handles */ -typedef struct _php_stream_ops { - /* stdio like functions - these are mandatory! */ - size_t (*write)(php_stream *stream, const char *buf, size_t count TSRMLS_DC); - size_t (*read)(php_stream *stream, char *buf, size_t count TSRMLS_DC); - int (*close)(php_stream *stream, int close_handle TSRMLS_DC); - int (*flush)(php_stream *stream TSRMLS_DC); - - const char *label; /* label for this ops structure */ - - /* these are optional */ - int (*seek)(php_stream *stream, off_t offset, int whence, off_t *newoffset TSRMLS_DC); - int (*cast)(php_stream *stream, int castas, void **ret TSRMLS_DC); - int (*stat)(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC); - int (*set_option)(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC); -} php_stream_ops; - -typedef struct _php_stream_wrapper_ops { - /* open/create a wrapped stream */ - php_stream *(*stream_opener)(php_stream_wrapper *wrapper, char *filename, char *mode, - int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); - /* close/destroy a wrapped stream */ - int (*stream_closer)(php_stream_wrapper *wrapper, php_stream *stream TSRMLS_DC); - /* stat a wrapped stream */ - int (*stream_stat)(php_stream_wrapper *wrapper, php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC); - /* stat a URL */ - int (*url_stat)(php_stream_wrapper *wrapper, char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC); - /* open a "directory" stream */ - php_stream *(*dir_opener)(php_stream_wrapper *wrapper, char *filename, char *mode, - int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); - - const char *label; - - /* delete a file */ - int (*unlink)(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC); - - /* rename a file */ - int (*rename)(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC); - - /* Create/Remove directory */ - int (*stream_mkdir)(php_stream_wrapper *wrapper, char *url, int mode, int options, php_stream_context *context TSRMLS_DC); - int (*stream_rmdir)(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC); -} php_stream_wrapper_ops; - -struct _php_stream_wrapper { - php_stream_wrapper_ops *wops; /* operations the wrapper can perform */ - void *abstract; /* context for the wrapper */ - int is_url; /* so that PG(allow_url_fopen) can be respected */ - - /* support for wrappers to return (multiple) error messages to the stream opener */ - int err_count; - char **err_stack; -}; - -#define PHP_STREAM_FLAG_NO_SEEK 1 -#define PHP_STREAM_FLAG_NO_BUFFER 2 - -#define PHP_STREAM_FLAG_EOL_UNIX 0 /* also includes DOS */ -#define PHP_STREAM_FLAG_DETECT_EOL 4 -#define PHP_STREAM_FLAG_EOL_MAC 8 - -/* set this when the stream might represent "interactive" data. - * When set, the read buffer will avoid certain operations that - * might otherwise cause the read to block for much longer than - * is strictly required. */ -#define PHP_STREAM_FLAG_AVOID_BLOCKING 16 - -struct _php_stream { - php_stream_ops *ops; - void *abstract; /* convenience pointer for abstraction */ - - php_stream_filter_chain readfilters, writefilters; - - php_stream_wrapper *wrapper; /* which wrapper was used to open the stream */ - void *wrapperthis; /* convenience pointer for a instance of a wrapper */ - zval *wrapperdata; /* fgetwrapperdata retrieves this */ - - int fgetss_state; /* for fgetss to handle multiline tags */ - int is_persistent; - char mode[16]; /* "rwb" etc. ala stdio */ - int rsrc_id; /* used for auto-cleanup */ - int in_free; /* to prevent recursion during free */ - /* so we know how to clean it up correctly. This should be set to - * PHP_STREAM_FCLOSE_XXX as appropriate */ - int fclose_stdiocast; - FILE *stdiocast; /* cache this, otherwise we might leak! */ -#if ZEND_DEBUG - int __exposed; /* non-zero if exposed as a zval somewhere */ -#endif - char *orig_path; - - php_stream_context *context; - int flags; /* PHP_STREAM_FLAG_XXX */ - - /* buffer */ - off_t position; /* of underlying stream */ - unsigned char *readbuf; - size_t readbuflen; - off_t readpos; - off_t writepos; - - /* how much data to read when filling buffer */ - size_t chunk_size; - - int eof; - -}; /* php_stream */ -/* state definitions when closing down; these are private to streams.c */ -#define PHP_STREAM_FCLOSE_NONE 0 -#define PHP_STREAM_FCLOSE_FDOPEN 1 -#define PHP_STREAM_FCLOSE_FOPENCOOKIE 2 - -/* allocate a new stream for a particular ops */ -PHPAPI php_stream *_php_stream_alloc(php_stream_ops *ops, void *abstract, - const char *persistent_id, const char *mode STREAMS_DC TSRMLS_DC); -#define php_stream_alloc(ops, thisptr, persistent_id, mode) _php_stream_alloc((ops), (thisptr), (persistent_id), (mode) STREAMS_CC TSRMLS_CC) - - -#define php_stream_get_resource_id(stream) (stream)->rsrc_id -#if ZEND_DEBUG -/* use this to tell the stream that it is OK if we don't explicitly close it */ -# define php_stream_auto_cleanup(stream) { (stream)->__exposed++; } -/* use this to assign the stream to a zval and tell the stream that is - * has been exported to the engine; it will expect to be closed automatically - * when the resources are auto-destructed */ -# define php_stream_to_zval(stream, zval) { ZVAL_RESOURCE(zval, (stream)->rsrc_id); (stream)->__exposed++; } -#else -# define php_stream_auto_cleanup(stream) /* nothing */ -# define php_stream_to_zval(stream, zval) { ZVAL_RESOURCE(zval, (stream)->rsrc_id); } -#endif - -#define php_stream_from_zval(xstr, ppzval) ZEND_FETCH_RESOURCE2((xstr), php_stream *, (ppzval), -1, "stream", php_file_le_stream(), php_file_le_pstream()) -#define php_stream_from_zval_no_verify(xstr, ppzval) (xstr) = (php_stream*)zend_fetch_resource((ppzval) TSRMLS_CC, -1, "stream", NULL, 2, php_file_le_stream(), php_file_le_pstream()) - -PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream **stream TSRMLS_DC); -#define PHP_STREAM_PERSISTENT_SUCCESS 0 /* id exists */ -#define PHP_STREAM_PERSISTENT_FAILURE 1 /* id exists but is not a stream! */ -#define PHP_STREAM_PERSISTENT_NOT_EXIST 2 /* id does not exist */ - -#define PHP_STREAM_FREE_CALL_DTOR 1 /* call ops->close */ -#define PHP_STREAM_FREE_RELEASE_STREAM 2 /* pefree(stream) */ -#define PHP_STREAM_FREE_PRESERVE_HANDLE 4 /* tell ops->close to not close it's underlying handle */ -#define PHP_STREAM_FREE_RSRC_DTOR 8 /* called from the resource list dtor */ -#define PHP_STREAM_FREE_PERSISTENT 16 /* manually freeing a persistent connection */ -#define PHP_STREAM_FREE_CLOSE (PHP_STREAM_FREE_CALL_DTOR | PHP_STREAM_FREE_RELEASE_STREAM) -#define PHP_STREAM_FREE_CLOSE_CASTED (PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_PRESERVE_HANDLE) -#define PHP_STREAM_FREE_CLOSE_PERSISTENT (PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_PERSISTENT) -PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC); -#define php_stream_free(stream, close_options) _php_stream_free((stream), (close_options) TSRMLS_CC) -#define php_stream_close(stream) _php_stream_free((stream), PHP_STREAM_FREE_CLOSE TSRMLS_CC) -#define php_stream_pclose(stream) _php_stream_free((stream), PHP_STREAM_FREE_CLOSE_PERSISTENT TSRMLS_CC) - -PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_DC); -#define php_stream_rewind(stream) _php_stream_seek((stream), 0L, SEEK_SET TSRMLS_CC) -#define php_stream_seek(stream, offset, whence) _php_stream_seek((stream), (offset), (whence) TSRMLS_CC) - -PHPAPI off_t _php_stream_tell(php_stream *stream TSRMLS_DC); -#define php_stream_tell(stream) _php_stream_tell((stream) TSRMLS_CC) - -PHPAPI size_t _php_stream_read(php_stream *stream, char *buf, size_t count TSRMLS_DC); -#define php_stream_read(stream, buf, count) _php_stream_read((stream), (buf), (count) TSRMLS_CC) - -PHPAPI size_t _php_stream_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC); -#define php_stream_write_string(stream, str) _php_stream_write(stream, str, strlen(str) TSRMLS_CC) -#define php_stream_write(stream, buf, count) _php_stream_write(stream, (buf), (count) TSRMLS_CC) - -PHPAPI size_t _php_stream_printf(php_stream *stream TSRMLS_DC, const char *fmt, ...); -/* php_stream_printf macro & function require TSRMLS_CC */ -#define php_stream_printf _php_stream_printf - -PHPAPI int _php_stream_eof(php_stream *stream TSRMLS_DC); -#define php_stream_eof(stream) _php_stream_eof((stream) TSRMLS_CC) - -PHPAPI int _php_stream_getc(php_stream *stream TSRMLS_DC); -#define php_stream_getc(stream) _php_stream_getc((stream) TSRMLS_CC) - -PHPAPI int _php_stream_putc(php_stream *stream, int c TSRMLS_DC); -#define php_stream_putc(stream, c) _php_stream_putc((stream), (c) TSRMLS_CC) - -PHPAPI int _php_stream_flush(php_stream *stream, int closing TSRMLS_DC); -#define php_stream_flush(stream) _php_stream_flush((stream), 0 TSRMLS_CC) - -PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, size_t *returned_len TSRMLS_DC); -#define php_stream_gets(stream, buf, maxlen) _php_stream_get_line((stream), (buf), (maxlen), NULL TSRMLS_CC) - -#define php_stream_get_line(stream, buf, maxlen, retlen) _php_stream_get_line((stream), (buf), (maxlen), (retlen) TSRMLS_CC) -PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, char *delim, size_t delim_len TSRMLS_DC); - -/* CAREFUL! this is equivalent to puts NOT fputs! */ -PHPAPI int _php_stream_puts(php_stream *stream, char *buf TSRMLS_DC); -#define php_stream_puts(stream, buf) _php_stream_puts((stream), (buf) TSRMLS_CC) - -PHPAPI int _php_stream_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC); -#define php_stream_stat(stream, ssb) _php_stream_stat((stream), (ssb) TSRMLS_CC) - -PHPAPI int _php_stream_stat_path(char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC); -#define php_stream_stat_path(path, ssb) _php_stream_stat_path((path), 0, (ssb), NULL TSRMLS_CC) -#define php_stream_stat_path_ex(path, flags, ssb, context) _php_stream_stat_path((path), (flags), (ssb), (context) TSRMLS_CC) - -PHPAPI int _php_stream_mkdir(char *path, int mode, int options, php_stream_context *context TSRMLS_DC); -#define php_stream_mkdir(path, mode, options, context) _php_stream_mkdir(path, mode, options, context TSRMLS_CC) - -PHPAPI int _php_stream_rmdir(char *path, int options, php_stream_context *context TSRMLS_DC); -#define php_stream_rmdir(path, options, context) _php_stream_rmdir(path, options, context TSRMLS_CC) - -PHPAPI php_stream *_php_stream_opendir(char *path, int options, php_stream_context *context STREAMS_DC TSRMLS_DC); -#define php_stream_opendir(path, options, context) _php_stream_opendir((path), (options), (context) STREAMS_CC TSRMLS_CC) -PHPAPI php_stream_dirent *_php_stream_readdir(php_stream *dirstream, php_stream_dirent *ent TSRMLS_DC); -#define php_stream_readdir(dirstream, dirent) _php_stream_readdir((dirstream), (dirent) TSRMLS_CC) -#define php_stream_closedir(dirstream) php_stream_close((dirstream)) -#define php_stream_rewinddir(dirstream) php_stream_rewind((dirstream)) - -PHPAPI int _php_stream_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC); -#define php_stream_set_option(stream, option, value, ptrvalue) _php_stream_set_option((stream), (option), (value), (ptrvalue) TSRMLS_CC) - -#define php_stream_set_chunk_size(stream, size) _php_stream_set_option((stream), PHP_STREAM_OPTION_SET_CHUNK_SIZE, (size), NULL TSRMLS_CC) - -/* Flags for mkdir method in wrapper ops */ -#define PHP_STREAM_MKDIR_RECURSIVE 1 -/* define REPORT ERRORS 8 (below) */ - -/* Flags for rmdir method in wrapper ops */ -/* define REPORT_ERRORS 8 (below) */ - -/* Flags for url_stat method in wrapper ops */ -#define PHP_STREAM_URL_STAT_LINK 1 -#define PHP_STREAM_URL_STAT_QUIET 2 - -/* change the blocking mode of stream: value == 1 => blocking, value == 0 => non-blocking. */ -#define PHP_STREAM_OPTION_BLOCKING 1 - -/* change the buffering mode of stream. value is a PHP_STREAM_BUFFER_XXXX value, ptrparam is a ptr to a size_t holding - * the required buffer size */ -#define PHP_STREAM_OPTION_READ_BUFFER 2 -#define PHP_STREAM_OPTION_WRITE_BUFFER 3 - -#define PHP_STREAM_BUFFER_NONE 0 /* unbuffered */ -#define PHP_STREAM_BUFFER_LINE 1 /* line buffered */ -#define PHP_STREAM_BUFFER_FULL 2 /* fully buffered */ - -/* set the timeout duration for reads on the stream. ptrparam is a pointer to a struct timeval * */ -#define PHP_STREAM_OPTION_READ_TIMEOUT 4 -#define PHP_STREAM_OPTION_SET_CHUNK_SIZE 5 - -/* set or release lock on a stream */ -#define PHP_STREAM_OPTION_LOCKING 6 - -/* whether or not locking is supported */ -#define PHP_STREAM_LOCK_SUPPORTED 1 - -#define php_stream_supports_lock(stream) _php_stream_set_option((stream), PHP_STREAM_OPTION_LOCKING, 0, (void *) PHP_STREAM_LOCK_SUPPORTED TSRMLS_CC) == 0 ? 1 : 0 -#define php_stream_lock(stream, mode) _php_stream_set_option((stream), PHP_STREAM_OPTION_LOCKING, (mode), (void *) NULL TSRMLS_CC) - -/* option code used by the php_stream_xport_XXX api */ -#define PHP_STREAM_OPTION_XPORT_API 7 /* see php_stream_transport.h */ -#define PHP_STREAM_OPTION_CRYPTO_API 8 /* see php_stream_transport.h */ -#define PHP_STREAM_OPTION_MMAP_API 9 /* see php_stream_mmap.h */ -#define PHP_STREAM_OPTION_TRUNCATE_API 10 - -#define PHP_STREAM_TRUNCATE_SUPPORTED 0 -#define PHP_STREAM_TRUNCATE_SET_SIZE 1 /* ptrparam is a pointer to a size_t */ - -#define php_stream_truncate_supported(stream) (_php_stream_set_option((stream), PHP_STREAM_OPTION_TRUNCATE_API, PHP_STREAM_TRUNCATE_SUPPORTED, NULL TSRMLS_CC) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0) - -PHPAPI int _php_stream_truncate_set_size(php_stream *stream, size_t newsize TSRMLS_DC); -#define php_stream_truncate_set_size(stream, size) _php_stream_truncate_set_size((stream), (size) TSRMLS_CC) - -#define PHP_STREAM_OPTION_META_DATA_API 11 /* ptrparam is a zval* to which to add meta data information */ -#define php_stream_populate_meta_data(stream, zv) (_php_stream_set_option((stream), PHP_STREAM_OPTION_META_DATA_API, 0, zv TSRMLS_CC) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0) - -/* Check if the stream is still "live"; for sockets/pipes this means the socket - * is still connected; for files, this does not really have meaning */ -#define PHP_STREAM_OPTION_CHECK_LIVENESS 12 /* no parameters */ - -#define PHP_STREAM_OPTION_RETURN_OK 0 /* option set OK */ -#define PHP_STREAM_OPTION_RETURN_ERR -1 /* problem setting option */ -#define PHP_STREAM_OPTION_RETURN_NOTIMPL -2 /* underlying stream does not implement; streams can handle it instead */ - -/* copy up to maxlen bytes from src to dest. If maxlen is PHP_STREAM_COPY_ALL, copy until eof(src). - * Uses mmap if the src is a plain file and at offset 0 */ -#define PHP_STREAM_COPY_ALL -1 -PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, size_t maxlen STREAMS_DC TSRMLS_DC); -#define php_stream_copy_to_stream(src, dest, maxlen) _php_stream_copy_to_stream((src), (dest), (maxlen) STREAMS_CC TSRMLS_CC) - - -/* read all data from stream and put into a buffer. Caller must free buffer when done. - * The copy will use mmap if available. */ -PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen, - int persistent STREAMS_DC TSRMLS_DC); -#define php_stream_copy_to_mem(src, buf, maxlen, persistent) _php_stream_copy_to_mem((src), (buf), (maxlen), (persistent) STREAMS_CC TSRMLS_CC) - -/* output all data from a stream */ -PHPAPI size_t _php_stream_passthru(php_stream * src STREAMS_DC TSRMLS_DC); -#define php_stream_passthru(stream) _php_stream_passthru((stream) STREAMS_CC TSRMLS_CC) - -#include "streams/php_stream_transport.h" -#include "streams/php_stream_plain_wrapper.h" -#include "streams/php_stream_userspace.h" -#include "streams/php_stream_mmap.h" - -/* coerce the stream into some other form */ -/* cast as a stdio FILE * */ -#define PHP_STREAM_AS_STDIO 0 -/* cast as a POSIX fd or socketd */ -#define PHP_STREAM_AS_FD 1 -/* cast as a socketd */ -#define PHP_STREAM_AS_SOCKETD 2 -/* cast as fd/socket for select purposes */ -#define PHP_STREAM_AS_FD_FOR_SELECT 3 - -/* try really, really hard to make sure the cast happens (avoid using this flag if possible) */ -#define PHP_STREAM_CAST_TRY_HARD 0x80000000 -#define PHP_STREAM_CAST_RELEASE 0x40000000 /* stream becomes invalid on success */ -#define PHP_STREAM_CAST_INTERNAL 0x20000000 /* stream cast for internal use */ -#define PHP_STREAM_CAST_MASK (PHP_STREAM_CAST_TRY_HARD | PHP_STREAM_CAST_RELEASE | PHP_STREAM_CAST_INTERNAL) -PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show_err TSRMLS_DC); -/* use this to check if a stream can be cast into another form */ -#define php_stream_can_cast(stream, as) _php_stream_cast((stream), (as), NULL, 0 TSRMLS_CC) -#define php_stream_cast(stream, as, ret, show_err) _php_stream_cast((stream), (as), (ret), (show_err) TSRMLS_CC) - -/* use this to check if a stream is of a particular type: - * PHPAPI int php_stream_is(php_stream *stream, php_stream_ops *ops); */ -#define php_stream_is(stream, anops) ((stream)->ops == anops) -#define PHP_STREAM_IS_STDIO &php_stream_stdio_ops - -#define php_stream_is_persistent(stream) (stream)->is_persistent - -/* Wrappers support */ - -#define IGNORE_PATH 0 -#define USE_PATH 1 -#define IGNORE_URL 2 -#define ENFORCE_SAFE_MODE 4 -#define REPORT_ERRORS 8 -/* If you don't need to write to the stream, but really need to - * be able to seek, use this flag in your options. */ -#define STREAM_MUST_SEEK 16 -/* If you are going to end up casting the stream into a FILE* or - * a socket, pass this flag and the streams/wrappers will not use - * buffering mechanisms while reading the headers, so that HTTP - * wrapped streams will work consistently. - * If you omit this flag, streams will use buffering and should end - * up working more optimally. - * */ -#define STREAM_WILL_CAST 32 - -/* this flag applies to php_stream_locate_url_wrapper */ -#define STREAM_LOCATE_WRAPPERS_ONLY 64 - -/* this flag is only used by include/require functions */ -#define STREAM_OPEN_FOR_INCLUDE 128 - -/* this flag tells streams to ONLY open urls */ -#define STREAM_USE_URL 256 - -/* this flag is used when only the headers from HTTP request are to be fetched */ -#define STREAM_ONLY_GET_HEADERS 512 - -/* don't apply open_basedir checks */ -#define STREAM_DISABLE_OPEN_BASEDIR 1024 - -/* get (or create) a persistent version of the stream */ -#define STREAM_OPEN_PERSISTENT 2048 - -/* Antique - no longer has meaning */ -#define IGNORE_URL_WIN 0 - -int php_init_stream_wrappers(int module_number TSRMLS_DC); -int php_shutdown_stream_wrappers(int module_number TSRMLS_DC); -PHP_RSHUTDOWN_FUNCTION(streams); - -PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC); -PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC); -PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); -PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char **path_for_open, int options TSRMLS_DC); -PHPAPI char *php_stream_locate_eol(php_stream *stream, char *buf, size_t buf_len TSRMLS_DC); - -#define php_stream_open_wrapper(path, mode, options, opened) _php_stream_open_wrapper_ex((path), (mode), (options), (opened), NULL STREAMS_CC TSRMLS_CC) -#define php_stream_open_wrapper_ex(path, mode, options, opened, context) _php_stream_open_wrapper_ex((path), (mode), (options), (opened), (context) STREAMS_CC TSRMLS_CC) - -#define php_stream_get_from_zval(stream, zstream, mode, options, opened, context) \ - if (Z_TYPE_PP((zstream)) == IS_RESOURCE) { \ - php_stream_from_zval((stream), (zstream)); \ - } else (stream) = Z_TYPE_PP((zstream)) == IS_STRING ? \ - php_stream_open_wrapper_ex(Z_STRVAL_PP((zstream)), (mode), (options), (opened), (context)) : NULL - -/* pushes an error message onto the stack for a wrapper instance */ -PHPAPI void php_stream_wrapper_log_error(php_stream_wrapper *wrapper, int options TSRMLS_DC, const char *fmt, ...); - - -#define PHP_STREAM_UNCHANGED 0 /* orig stream was seekable anyway */ -#define PHP_STREAM_RELEASED 1 /* newstream should be used; origstream is no longer valid */ -#define PHP_STREAM_FAILED 2 /* an error occurred while attempting conversion */ -#define PHP_STREAM_CRITICAL 3 /* an error occurred; origstream is in an unknown state; you should close origstream */ -#define PHP_STREAM_NO_PREFERENCE 0 -#define PHP_STREAM_PREFER_STDIO 1 -#define PHP_STREAM_FORCE_CONVERSION 2 -/* DO NOT call this on streams that are referenced by resources! */ -PHPAPI int _php_stream_make_seekable(php_stream *origstream, php_stream **newstream, int flags STREAMS_DC TSRMLS_DC); -#define php_stream_make_seekable(origstream, newstream, flags) _php_stream_make_seekable((origstream), (newstream), (flags) STREAMS_CC TSRMLS_CC) - -/* Give other modules access to the url_stream_wrappers_hash and stream_filters_hash */ -PHPAPI HashTable *php_stream_get_url_stream_wrappers_hash(); -PHPAPI HashTable *php_get_stream_filters_hash(); -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/php_syslog.h b/main/php_syslog.h deleted file mode 100644 index 3f93f28ee1..0000000000 --- a/main/php_syslog.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_SYSLOG_H -#define PHP_SYSLOG_H - -#ifdef PHP_WIN32 -#include "win32/syslog.h" -#elif defined(NETWARE) -# include "config.nw.h" -#ifdef HAVE_SYSLOG_H -#include <syslog.h> -#endif -#else -#include "php_config.h" -#ifdef HAVE_SYSLOG_H -#include <syslog.h> -#endif -#endif - -/* - * The SCO OpenServer 5 Development System (not the UDK) - * defines syslog to std_syslog. - */ - -#ifdef syslog - -#ifdef HAVE_STD_SYSLOG -#define php_syslog std_syslog -#endif - -#undef syslog - -#endif - -#ifndef php_syslog -#define php_syslog syslog -#endif - -#endif diff --git a/main/php_ticks.c b/main/php_ticks.c deleted file mode 100644 index 945a5549d9..0000000000 --- a/main/php_ticks.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Stig Bakken <ssb@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "php_ticks.h" - -int php_startup_ticks(TSRMLS_D) -{ - zend_llist_init(&PG(tick_functions), sizeof(void(*)(int)), NULL, 1); - return SUCCESS; -} - -void php_shutdown_ticks(TSRMLS_D) -{ - zend_llist_destroy(&PG(tick_functions)); -} - -static int php_compare_tick_functions(void *elem1, void *elem2) -{ - void(*func1)(int); - void(*func2)(int); - memcpy(&func1, elem1, sizeof(void(*)(int))); - memcpy(&func2, elem2, sizeof(void(*)(int))); - return (func1 == func2); -} - -PHPAPI void php_add_tick_function(void (*func)(int)) -{ - TSRMLS_FETCH(); - - zend_llist_add_element(&PG(tick_functions), (void *)&func); -} - -PHPAPI void php_remove_tick_function(void (*func)(int)) -{ - TSRMLS_FETCH(); - - zend_llist_del_element(&PG(tick_functions), (void *)func, - (int(*)(void*, void*))php_compare_tick_functions); -} - -static void php_tick_iterator(void *data, void *arg TSRMLS_DC) -{ - void (*func)(int); - - memcpy(&func, data, sizeof(void(*)(int))); - func(*((int *)arg)); -} - -void php_run_ticks(int count) -{ - TSRMLS_FETCH(); - - zend_llist_apply_with_argument(&PG(tick_functions), (llist_apply_with_arg_func_t) php_tick_iterator, &count TSRMLS_CC); -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/php_ticks.h b/main/php_ticks.h deleted file mode 100644 index e6550d3d79..0000000000 --- a/main/php_ticks.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Stig Bakken <ssb@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_TICKS_H -#define PHP_TICKS_H - -int php_startup_ticks(TSRMLS_D); -void php_shutdown_ticks(TSRMLS_D); -void php_run_ticks(int count); -PHPAPI void php_add_tick_function(void (*func)(int)); -PHPAPI void php_remove_tick_function(void (*func)(int)); - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/main/php_variables.c b/main/php_variables.c deleted file mode 100644 index 514b9c98bf..0000000000 --- a/main/php_variables.c +++ /dev/null @@ -1,803 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include <stdio.h> -#include "php.h" -#include "ext/standard/php_standard.h" -#include "ext/standard/credits.h" -#include "php_variables.h" -#include "php_globals.h" -#include "php_content_types.h" -#include "SAPI.h" -#include "php_logos.h" - -#include "zend_globals.h" - - -/* for systems that need to override reading of environment variables */ -void _php_import_environment_variables(zval *array_ptr TSRMLS_DC); -PHPAPI void (*php_import_environment_variables)(zval *array_ptr TSRMLS_DC) = _php_import_environment_variables; - -PHPAPI void php_register_variable(char *var, char *strval, zval *track_vars_array TSRMLS_DC) -{ - php_register_variable_safe(var, strval, strlen(strval), track_vars_array TSRMLS_CC); -} - - -/* binary-safe version */ -PHPAPI void php_register_variable_safe(char *var, char *strval, int str_len, zval *track_vars_array TSRMLS_DC) -{ - zval new_entry; - assert(strval != NULL); - - /* Prepare value */ - Z_STRLEN(new_entry) = str_len; - if (PG(magic_quotes_gpc)) { - Z_STRVAL(new_entry) = php_addslashes(strval, Z_STRLEN(new_entry), &Z_STRLEN(new_entry), 0 TSRMLS_CC); - } else { - Z_STRVAL(new_entry) = estrndup(strval, Z_STRLEN(new_entry)); - } - Z_TYPE(new_entry) = IS_STRING; - - php_register_variable_ex(var, &new_entry, track_vars_array TSRMLS_CC); -} - - -PHPAPI void php_register_variable_ex(char *var, zval *val, pval *track_vars_array TSRMLS_DC) -{ - char *p = NULL; - char *ip; /* index pointer */ - char *index; - int var_len, index_len; - zval *gpc_element, **gpc_element_p; - zend_bool is_array; - HashTable *symtable1=NULL; - - assert(var != NULL); - - if (track_vars_array) { - symtable1 = Z_ARRVAL_P(track_vars_array); - } else if (PG(register_globals)) { - symtable1 = EG(active_symbol_table); - } - if (!symtable1) { - /* Nothing to do */ - zval_dtor(val); - return; - } - - /* - * Prepare variable name - */ - ip = strchr(var, '['); - if (ip) { - is_array = 1; - *ip = 0; - } else { - is_array = 0; - } - /* ignore leading spaces in the variable name */ - while (*var && *var==' ') { - var++; - } - var_len = strlen(var); - if (var_len==0) { /* empty variable name, or variable name with a space in it */ - zval_dtor(val); - return; - } - /* ensure that we don't have spaces or dots in the variable name (not binary safe) */ - for (p=var; *p; p++) { - switch(*p) { - case ' ': - case '.': - *p='_'; - break; - } - } - - index = var; - index_len = var_len; - - while (1) { - if (is_array) { - char *escaped_index = NULL, *index_s; - int new_idx_len = 0; - - ip++; - index_s = ip; - if (isspace(*ip)) { - ip++; - } - if (*ip==']') { - index_s = NULL; - } else { - ip = strchr(ip, ']'); - if (!ip) { - /* PHP variables cannot contain '[' in their names, so we replace the character with a '_' */ - *(index_s - 1) = '_'; - index_len = var_len = strlen(var); - goto plain_var; - return; - } - *ip = 0; - new_idx_len = strlen(index_s); - } - - if (!index) { - MAKE_STD_ZVAL(gpc_element); - 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 */ - escaped_index = php_addslashes(index, index_len, &index_len, 0 TSRMLS_CC); - } else { - escaped_index = index; - } - if (zend_symtable_find(symtable1, escaped_index, index_len+1, (void **) &gpc_element_p)==FAILURE - || Z_TYPE_PP(gpc_element_p) != IS_ARRAY) { - MAKE_STD_ZVAL(gpc_element); - array_init(gpc_element); - zend_symtable_update(symtable1, escaped_index, index_len+1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p); - } - if (index!=escaped_index) { - efree(escaped_index); - } - } - symtable1 = Z_ARRVAL_PP(gpc_element_p); - /* ip pointed to the '[' character, now obtain the key */ - index = index_s; - index_len = new_idx_len; - - ip++; - if (*ip=='[') { - is_array = 1; - *ip = 0; - } else { - is_array = 0; - } - } else { -plain_var: - MAKE_STD_ZVAL(gpc_element); - gpc_element->value = val->value; - Z_TYPE_P(gpc_element) = Z_TYPE_P(val); - if (!index) { - zend_hash_next_index_insert(symtable1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p); - } else { - char *escaped_index = php_addslashes(index, index_len, &index_len, 0 TSRMLS_CC); - zend_symtable_update(symtable1, escaped_index, index_len+1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p); - efree(escaped_index); - } - break; - } - } -} - - -SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler) -{ - char *var, *val; - char *strtok_buf = NULL; - zval *array_ptr = (zval *) arg; - - if (SG(request_info).post_data==NULL) { - return; - } - - var = php_strtok_r(SG(request_info).post_data, "&", &strtok_buf); - - while (var) { - val = strchr(var, '='); - if (val) { /* have a value */ - unsigned int val_len, new_val_len; - - *val++ = '\0'; - php_url_decode(var, strlen(var)); - val_len = php_url_decode(val, strlen(val)); - if (sapi_module.input_filter(PARSE_POST, var, &val, val_len, &new_val_len TSRMLS_CC)) { - php_register_variable_safe(var, val, new_val_len, array_ptr TSRMLS_CC); - } - } - var = php_strtok_r(NULL, "&", &strtok_buf); - } -} - -SAPI_API SAPI_INPUT_FILTER_FUNC(php_default_input_filter) -{ - /* TODO: check .ini setting here and apply user-defined input filter */ - *new_val_len = val_len; - return 1; -} - -SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data) -{ - char *res = NULL, *var, *val, *separator=NULL; - const char *c_var; - pval *array_ptr; - int free_buffer=0; - char *strtok_buf = NULL; - - switch (arg) { - case PARSE_POST: - case PARSE_GET: - case PARSE_COOKIE: - ALLOC_ZVAL(array_ptr); - array_init(array_ptr); - INIT_PZVAL(array_ptr); - switch (arg) { - case PARSE_POST: - PG(http_globals)[TRACK_VARS_POST] = array_ptr; - break; - case PARSE_GET: - PG(http_globals)[TRACK_VARS_GET] = array_ptr; - break; - case PARSE_COOKIE: - PG(http_globals)[TRACK_VARS_COOKIE] = array_ptr; - break; - } - break; - default: - array_ptr=destArray; - break; - } - - if (arg==PARSE_POST) { - sapi_handle_post(array_ptr TSRMLS_CC); - return; - } - - if (arg == PARSE_GET) { /* GET data */ - c_var = SG(request_info).query_string; - if (c_var && *c_var) { - res = (char *) estrdup(c_var); - free_buffer = 1; - } else { - free_buffer = 0; - } - } else if (arg == PARSE_COOKIE) { /* Cookie data */ - c_var = SG(request_info).cookie_data; - if (c_var && *c_var) { - res = (char *) estrdup(c_var); - free_buffer = 1; - } else { - free_buffer = 0; - } - } else if (arg == PARSE_STRING) { /* String data */ - res = str; - free_buffer = 1; - } - - if (!res) { - return; - } - - switch (arg) { - case PARSE_GET: - case PARSE_STRING: - separator = (char *) estrdup(PG(arg_separator).input); - break; - case PARSE_COOKIE: - separator = ";\0"; - break; - } - - var = php_strtok_r(res, separator, &strtok_buf); - - while (var) { - val = strchr(var, '='); - if (val) { /* have a value */ - int val_len; - unsigned int new_val_len; - - *val++ = '\0'; - php_url_decode(var, strlen(var)); - val_len = php_url_decode(val, strlen(val)); - if (sapi_module.input_filter(PARSE_POST, var, &val, val_len, &new_val_len TSRMLS_CC)) { - php_register_variable_safe(var, val, new_val_len, array_ptr TSRMLS_CC); - } - } else { - php_url_decode(var, strlen(var)); - php_register_variable_safe(var, "", 0, array_ptr TSRMLS_CC); - } - var = php_strtok_r(NULL, separator, &strtok_buf); - } - - if(arg != PARSE_COOKIE) { - efree(separator); - } - - if (free_buffer) { - efree(res); - } -} - -void _php_import_environment_variables(zval *array_ptr TSRMLS_DC) -{ - char buf[128]; - char **env, *p, *t = buf; - size_t alloc_size = sizeof(buf); - unsigned long nlen; /* ptrdiff_t is not portable */ - - /* turn off magic_quotes while importing environment variables */ - int magic_quotes_gpc = PG(magic_quotes_gpc); - PG(magic_quotes_gpc) = 0; - - for (env = environ; env != NULL && *env != NULL; env++) { - p = strchr(*env, '='); - if (!p) { /* malformed entry? */ - continue; - } - nlen = p - *env; - if (nlen >= alloc_size) { - alloc_size = nlen + 64; - t = (t == buf ? emalloc(alloc_size): erealloc(t, alloc_size)); - } - memcpy(t, *env, nlen); - t[nlen] = '\0'; - php_register_variable(t, p+1, array_ptr TSRMLS_CC); - } - if (t != buf && t != NULL) { - efree(t); - } - PG(magic_quotes_gpc) = magic_quotes_gpc; -} - - -zend_bool php_std_auto_global_callback(char *name, uint name_len TSRMLS_DC) -{ - zend_printf("%s\n", name); - return 0; /* don't rearm */ -} - -/* {{{ php_build_argv - */ -static void php_build_argv(char *s, zval *track_vars_array TSRMLS_DC) -{ - pval *arr, *argc, *tmp; - int count = 0; - char *ss, *space; - - if (! (PG(register_globals) || SG(request_info).argc || - PG(http_globals)[TRACK_VARS_SERVER]) ) { - return; - } - - ALLOC_ZVAL(arr); - array_init(arr); - arr->is_ref = 0; - arr->refcount = 0; - - /* Prepare argv */ - if (SG(request_info).argc) { /* are we in cli sapi? */ - int i; - for (i=0; i<SG(request_info).argc; i++) { - ALLOC_ZVAL(tmp); - Z_TYPE_P(tmp) = IS_STRING; - Z_STRLEN_P(tmp) = strlen(SG(request_info).argv[i]); - Z_STRVAL_P(tmp) = estrndup(SG(request_info).argv[i], Z_STRLEN_P(tmp)); - INIT_PZVAL(tmp); - if (zend_hash_next_index_insert(Z_ARRVAL_P(arr), &tmp, sizeof(pval *), NULL)==FAILURE) { - if (Z_TYPE_P(tmp) == IS_STRING) { - efree(Z_STRVAL_P(tmp)); - } - } - } - } else if (s && *s) { - ss = s; - while (ss) { - space = strchr(ss, '+'); - if (space) { - *space = '\0'; - } - /* auto-type */ - ALLOC_ZVAL(tmp); - Z_TYPE_P(tmp) = IS_STRING; - Z_STRLEN_P(tmp) = strlen(ss); - Z_STRVAL_P(tmp) = estrndup(ss, Z_STRLEN_P(tmp)); - INIT_PZVAL(tmp); - count++; - if (zend_hash_next_index_insert(Z_ARRVAL_P(arr), &tmp, sizeof(pval *), NULL)==FAILURE) { - if (Z_TYPE_P(tmp) == IS_STRING) { - efree(Z_STRVAL_P(tmp)); - } - } - if (space) { - *space = '+'; - ss = space + 1; - } else { - ss = space; - } - } - } - - /* prepare argc */ - ALLOC_ZVAL(argc); - if (SG(request_info).argc) { - Z_LVAL_P(argc) = SG(request_info).argc; - } else { - Z_LVAL_P(argc) = count; - } - Z_TYPE_P(argc) = IS_LONG; - argc->is_ref = 0; - argc->refcount = 0; - - if (PG(register_globals) || SG(request_info).argc) { - arr->refcount++; - argc->refcount++; - zend_hash_update(&EG(symbol_table), "argv", sizeof("argv"), &arr, sizeof(zval *), NULL); - zend_hash_add(&EG(symbol_table), "argc", sizeof("argc"), &argc, sizeof(zval *), NULL); - } - if (track_vars_array) { - arr->refcount++; - argc->refcount++; - zend_hash_update(Z_ARRVAL_P(track_vars_array), "argv", sizeof("argv"), &arr, sizeof(pval *), NULL); - zend_hash_update(Z_ARRVAL_P(track_vars_array), "argc", sizeof("argc"), &argc, sizeof(pval *), NULL); - } -} -/* }}} */ - -/* {{{ php_handle_special_queries - */ -PHPAPI int php_handle_special_queries(TSRMLS_D) -{ - if (SG(request_info).query_string && SG(request_info).query_string[0]=='=' - && PG(expose_php)) { - if (php_info_logos(SG(request_info).query_string+1 TSRMLS_CC)) { - return 1; - } else if (!strcmp(SG(request_info).query_string+1, PHP_CREDITS_GUID)) { - php_print_credits(PHP_CREDITS_ALL TSRMLS_CC); - return 1; - } - } - return 0; -} -/* }}} */ - - - -/* {{{ php_register_server_variables - */ -static inline void php_register_server_variables(TSRMLS_D) -{ - zval *array_ptr=NULL; - /* turn off magic_quotes while importing server variables */ - int magic_quotes_gpc = PG(magic_quotes_gpc); - - ALLOC_ZVAL(array_ptr); - array_init(array_ptr); - INIT_PZVAL(array_ptr); - PG(http_globals)[TRACK_VARS_SERVER] = array_ptr; - PG(magic_quotes_gpc) = 0; - - /* Server variables */ - if (sapi_module.register_server_variables) { - sapi_module.register_server_variables(array_ptr TSRMLS_CC); - } - - /* PHP Authentication support */ - if (SG(request_info).auth_user) { - php_register_variable("PHP_AUTH_USER", SG(request_info).auth_user, array_ptr TSRMLS_CC); - } - if (SG(request_info).auth_password) { - php_register_variable("PHP_AUTH_PW", SG(request_info).auth_password, array_ptr TSRMLS_CC); - } - PG(magic_quotes_gpc) = magic_quotes_gpc; -} -/* }}} */ - - - -/* {{{ php_autoglobal_merge - */ -static void php_autoglobal_merge(HashTable *dest, HashTable *src TSRMLS_DC) -{ - zval **src_entry, **dest_entry; - char *string_key; - uint string_key_len; - ulong num_key; - HashPosition pos; - int key_type; - - zend_hash_internal_pointer_reset_ex(src, &pos); - while (zend_hash_get_current_data_ex(src, (void **)&src_entry, &pos) == SUCCESS) { - key_type = zend_hash_get_current_key_ex(src, &string_key, &string_key_len, &num_key, 0, &pos); - if (Z_TYPE_PP(src_entry) != IS_ARRAY - || (key_type==HASH_KEY_IS_STRING && zend_hash_find(dest, string_key, string_key_len, (void **) &dest_entry) != SUCCESS) - || (key_type==HASH_KEY_IS_LONG && zend_hash_index_find(dest, num_key, (void **)&dest_entry) != SUCCESS) - || Z_TYPE_PP(dest_entry) != IS_ARRAY) { - (*src_entry)->refcount++; - if (key_type == HASH_KEY_IS_STRING) { - zend_hash_update(dest, string_key, strlen(string_key)+1, src_entry, sizeof(zval *), NULL); - } else { - zend_hash_index_update(dest, num_key, src_entry, sizeof(zval *), NULL); - } - } else { - SEPARATE_ZVAL(dest_entry); - php_autoglobal_merge(Z_ARRVAL_PP(dest_entry), Z_ARRVAL_PP(src_entry) TSRMLS_CC); - } - zend_hash_move_forward_ex(src, &pos); - } -} -/* }}} */ - - -static zend_bool php_auto_globals_create_server(char *name, uint name_len TSRMLS_DC); -static zend_bool php_auto_globals_create_env(char *name, uint name_len TSRMLS_DC); -static zend_bool php_auto_globals_create_request(char *name, uint name_len TSRMLS_DC); - -/* {{{ php_hash_environment - */ -int php_hash_environment(TSRMLS_D) -{ - char *p; - unsigned char _gpc_flags[5] = {0, 0, 0, 0, 0}; - zend_bool have_variables_order; - zval *dummy_track_vars_array = NULL; - zend_bool initialized_dummy_track_vars_array=0; - zend_bool jit_initialization = (!PG(register_globals) && !PG(register_long_arrays)); - char *variables_order; - struct auto_global_record { - char *name; - uint name_len; - char *long_name; - uint long_name_len; - zend_bool jit_initialization; - } auto_global_records[] = { - { "_POST", sizeof("_POST"), "HTTP_POST_VARS", sizeof("HTTP_POST_VARS"), 0 }, - { "_GET", sizeof("_GET"), "HTTP_GET_VARS", sizeof("HTTP_GET_VARS"), 0 }, - { "_COOKIE", sizeof("_COOKIE"), "HTTP_COOKIE_VARS", sizeof("HTTP_COOKIE_VARS"), 0 }, - { "_SERVER", sizeof("_SERVER"), "HTTP_SERVER_VARS", sizeof("HTTP_SERVER_VARS"), 1 }, - { "_ENV", sizeof("_ENV"), "HTTP_ENV_VARS", sizeof("HTTP_ENV_VARS"), 1 }, - { "_FILES", sizeof("_FILES"), "HTTP_POST_FILES", sizeof("HTTP_POST_FILES"), 0 }, - }; - size_t num_track_vars = sizeof(auto_global_records)/sizeof(struct auto_global_record); - size_t i; - - /* jit_initialization = 0; */ - for (i=0; i<num_track_vars; i++) { - PG(http_globals)[i] = NULL; - } - - if (PG(variables_order)) { - variables_order = PG(variables_order); - have_variables_order=1; - } else { - variables_order = PG(gpc_order); - have_variables_order=0; - ALLOC_ZVAL(PG(http_globals)[TRACK_VARS_ENV]); - array_init(PG(http_globals)[TRACK_VARS_ENV]); - INIT_PZVAL(PG(http_globals)[TRACK_VARS_ENV]); - php_import_environment_variables(PG(http_globals)[TRACK_VARS_ENV] TSRMLS_CC); - if (PG(register_globals)) { - php_autoglobal_merge(&EG(symbol_table), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_ENV]) TSRMLS_CC); - } - } - - for (p=variables_order; p && *p; p++) { - switch(*p) { - case 'p': - case 'P': - if (!_gpc_flags[0] && !SG(headers_sent) && SG(request_info).request_method && !strcasecmp(SG(request_info).request_method, "POST")) { - sapi_module.treat_data(PARSE_POST, NULL, NULL TSRMLS_CC); /* POST Data */ - _gpc_flags[0]=1; - if (PG(register_globals)) { - php_autoglobal_merge(&EG(symbol_table), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_POST]) TSRMLS_CC); - } - } - break; - case 'c': - case 'C': - if (!_gpc_flags[1]) { - sapi_module.treat_data(PARSE_COOKIE, NULL, NULL TSRMLS_CC); /* Cookie Data */ - _gpc_flags[1]=1; - if (PG(register_globals)) { - php_autoglobal_merge(&EG(symbol_table), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]) TSRMLS_CC); - } - } - break; - case 'g': - case 'G': - if (!_gpc_flags[2]) { - sapi_module.treat_data(PARSE_GET, NULL, NULL TSRMLS_CC); /* GET Data */ - _gpc_flags[2]=1; - if (PG(register_globals)) { - php_autoglobal_merge(&EG(symbol_table), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]) TSRMLS_CC); - } - } - break; - case 'e': - case 'E': - if (!jit_initialization && !_gpc_flags[3]) { - if (have_variables_order) { - php_auto_globals_create_env("_ENV", sizeof("_ENV")-1 TSRMLS_CC); - if (PG(register_globals)) { - php_autoglobal_merge(&EG(symbol_table), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_ENV]) TSRMLS_CC); - } - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported 'e' element (environment) used in gpc_order - use variables_order instead"); - } - _gpc_flags[3]=1; - } - break; - case 's': - case 'S': - if (!jit_initialization && !_gpc_flags[4]) { - php_register_server_variables(TSRMLS_C); - _gpc_flags[4]=1; - if (PG(register_globals)) { - php_autoglobal_merge(&EG(symbol_table), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]) TSRMLS_CC); - } - } - break; - } - } - - if (!jit_initialization && !have_variables_order && !_gpc_flags[4]) { - php_register_server_variables(TSRMLS_C); - if (PG(register_globals)) { - php_autoglobal_merge(&EG(symbol_table), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]) TSRMLS_CC); - } - } - - /* argv/argc support */ - if (PG(register_argc_argv)) { - php_build_argv(SG(request_info).query_string, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC); - } - - for (i=0; i<num_track_vars; i++) { - if (jit_initialization && auto_global_records[i].jit_initialization) { - 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; - } - - zend_hash_update(&EG(symbol_table), auto_global_records[i].name, auto_global_records[i].name_len, &PG(http_globals)[i], sizeof(zval *), NULL); - PG(http_globals)[i]->refcount++; - if (PG(register_long_arrays)) { - zend_hash_update(&EG(symbol_table), auto_global_records[i].long_name, auto_global_records[i].long_name_len, &PG(http_globals)[i], sizeof(zval *), NULL); - PG(http_globals)[i]->refcount++; - } - } - - /* Create _REQUEST */ - if (!jit_initialization) { - php_auto_globals_create_request("_REQUEST", sizeof("_REQUEST")-1 TSRMLS_CC); - } - - return SUCCESS; -} -/* }}} */ - - -static zend_bool php_auto_globals_create_server(char *name, uint name_len TSRMLS_DC) -{ - php_register_server_variables(TSRMLS_C); - - zend_hash_update(&EG(symbol_table), name, name_len+1, &PG(http_globals)[TRACK_VARS_SERVER], sizeof(zval *), NULL); - PG(http_globals)[TRACK_VARS_SERVER]->refcount++; - - if (PG(register_long_arrays)) { - zend_hash_update(&EG(symbol_table), "HTTP_SERVER_VARS", sizeof("HTTP_SERVER_VARS"), &PG(http_globals)[TRACK_VARS_SERVER], sizeof(zval *), NULL); - PG(http_globals)[TRACK_VARS_SERVER]->refcount++; - } - - return 0; /* don't rearm */ -} - - -static zend_bool php_auto_globals_create_env(char *name, uint name_len TSRMLS_DC) -{ - ALLOC_ZVAL(PG(http_globals)[TRACK_VARS_ENV]); - array_init(PG(http_globals)[TRACK_VARS_ENV]); - INIT_PZVAL(PG(http_globals)[TRACK_VARS_ENV]); - php_import_environment_variables(PG(http_globals)[TRACK_VARS_ENV] TSRMLS_CC); - - zend_hash_update(&EG(symbol_table), name, name_len+1, &PG(http_globals)[TRACK_VARS_ENV], sizeof(zval *), NULL); - PG(http_globals)[TRACK_VARS_ENV]->refcount++; - - if (PG(register_long_arrays)) { - zend_hash_update(&EG(symbol_table), "HTTP_ENV_VARS", sizeof("HTTP_ENV_VARS"), &PG(http_globals)[TRACK_VARS_ENV], sizeof(zval *), NULL); - PG(http_globals)[TRACK_VARS_ENV]->refcount++; - } - - return 0; /* don't rearm */ -} - - -static zend_bool php_auto_globals_create_request(char *name, uint name_len TSRMLS_DC) -{ - zval *form_variables; - char *variables_order; - unsigned char _gpc_flags[3] = {0, 0, 0}; - char *p; - - if (PG(variables_order)) { - variables_order = PG(variables_order); - } else { - variables_order = PG(gpc_order); - } - - ALLOC_ZVAL(form_variables); - array_init(form_variables); - INIT_PZVAL(form_variables); - - for (p=variables_order; p && *p; p++) { - switch (*p) { - case 'g': - case 'G': - if (!_gpc_flags[0]) { - php_autoglobal_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]) TSRMLS_CC); - _gpc_flags[0] = 1; - } - break; - case 'p': - case 'P': - if (!_gpc_flags[1]) { - php_autoglobal_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_POST]) TSRMLS_CC); - _gpc_flags[1] = 1; - } - break; - case 'c': - case 'C': - if (!_gpc_flags[2]) { - php_autoglobal_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]) TSRMLS_CC); - _gpc_flags[2] = 1; - } - break; - } - } - - zend_hash_update(&EG(symbol_table), "_REQUEST", sizeof("_REQUEST"), &form_variables, sizeof(zval *), NULL); - return 0; -} - - -void php_startup_auto_globals(TSRMLS_D) -{ - zend_bool cb = (!PG(register_globals) && !PG(register_long_arrays)); - - /*cb = 0;*/ - zend_register_auto_global("_GET", sizeof("_GET")-1, NULL TSRMLS_CC); - zend_register_auto_global("_POST", sizeof("_POST")-1, NULL TSRMLS_CC); - zend_register_auto_global("_COOKIE", sizeof("_COOKIE")-1, NULL TSRMLS_CC); - zend_register_auto_global("_SERVER", sizeof("_SERVER")-1, cb?php_auto_globals_create_server:NULL TSRMLS_CC); - zend_register_auto_global("_ENV", sizeof("_ENV")-1, cb?php_auto_globals_create_env:NULL TSRMLS_CC); - zend_register_auto_global("_REQUEST", sizeof("_REQUEST")-1, cb?php_auto_globals_create_request:NULL TSRMLS_CC); - zend_register_auto_global("_FILES", sizeof("_FILES")-1, NULL TSRMLS_CC); -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/php_variables.h b/main/php_variables.h deleted file mode 100644 index 15ed91ff20..0000000000 --- a/main/php_variables.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_VARIABLES_H -#define PHP_VARIABLES_H - -#include "php.h" -#include "SAPI.h" - -#define PARSE_POST 0 -#define PARSE_GET 1 -#define PARSE_COOKIE 2 -#define PARSE_STRING 3 - -BEGIN_EXTERN_C() -void php_treat_data(int arg, char *str, zval* destArray TSRMLS_DC); -void php_startup_auto_globals(TSRMLS_D); -extern PHPAPI void (*php_import_environment_variables)(zval *array_ptr TSRMLS_DC); -PHPAPI void php_register_variable(char *var, char *val, pval *track_vars_array TSRMLS_DC); -/* binary-safe version */ -PHPAPI void php_register_variable_safe(char *var, char *val, int val_len, pval *track_vars_array TSRMLS_DC); -PHPAPI void php_register_variable_ex(char *var, zval *val, pval *track_vars_array TSRMLS_DC); - -int php_hash_environment(TSRMLS_D); -END_EXTERN_C() - -#define NUM_TRACK_VARS 6 - -#endif /* PHP_VARIABLES_H */ diff --git a/main/php_version.h b/main/php_version.h deleted file mode 100644 index 2b07113854..0000000000 --- a/main/php_version.h +++ /dev/null @@ -1,7 +0,0 @@ -/* automatically generated by configure */ -/* edit configure.in to change version number */ -#define PHP_MAJOR_VERSION 5 -#define PHP_MINOR_VERSION 0 -#define PHP_RELEASE_VERSION 0 -#define PHP_EXTRA_VERSION "RC1-dev" -#define PHP_VERSION "5.0.0RC1-dev" diff --git a/main/reentrancy.c b/main/reentrancy.c deleted file mode 100644 index 8d7a7ff2bb..0000000000 --- a/main/reentrancy.c +++ /dev/null @@ -1,504 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include <sys/types.h> -#include <string.h> -#include <errno.h> -#ifdef HAVE_DIRENT_H -#include <dirent.h> -#endif - -#ifdef PHP_WIN32 -#include "win32/readdir.h" -#endif - -#if defined(NETWARE) && !(NEW_LIBC) -/*#include <ws2nlm.h>*/ -#include <sys/socket.h> -#endif - -#include "php_reentrancy.h" -#include "ext/standard/php_rand.h" /* for PHP_RAND_MAX */ - -enum { - LOCALTIME_R, - CTIME_R, - ASCTIME_R, - GMTIME_R, - READDIR_R, - NUMBER_OF_LOCKS -}; - -#if defined(PHP_NEED_REENTRANCY) - -#include <TSRM.h> - -static MUTEX_T reentrant_locks[NUMBER_OF_LOCKS]; - -#define local_lock(x) tsrm_mutex_lock(reentrant_locks[x]) -#define local_unlock(x) tsrm_mutex_unlock(reentrant_locks[x]) - -#else - -#define local_lock(x) -#define local_unlock(x) - -#endif - -#if defined(PHP_IRIX_TIME_R) - -#define HAVE_CTIME_R 1 -#define HAVE_ASCTIME_R 1 - -PHPAPI char *php_ctime_r(const time_t *clock, char *buf) -{ - if (ctime_r(clock, buf, 26) == buf) - return (buf); - return (NULL); -} - -PHPAPI char *php_asctime_r(const struct tm *tm, char *buf) -{ - if (asctime_r(tm, buf, 26) == buf) - return (buf); - return (NULL); -} - -#endif - -#if defined(PHP_HPUX_TIME_R) - -#define HAVE_LOCALTIME_R 1 -#define HAVE_CTIME_R 1 -#define HAVE_ASCTIME_R 1 -#define HAVE_GMTIME_R 1 - -PHPAPI struct tm *php_localtime_r(const time_t *const timep, struct tm *p_tm) -{ - if (localtime_r(timep, p_tm) == 0) - return (p_tm); - return (NULL); -} - -PHPAPI char *php_ctime_r(const time_t *clock, char *buf) -{ - if (ctime_r(clock, buf, 26) != -1) - return (buf); - return (NULL); -} - -PHPAPI char *php_asctime_r(const struct tm *tm, char *buf) -{ - if (asctime_r(tm, buf, 26) != -1) - return (buf); - return (NULL); -} - -PHPAPI struct tm *php_gmtime_r(const time_t *const timep, struct tm *p_tm) -{ - if (gmtime_r(timep, p_tm) == 0) - return (p_tm); - return (NULL); -} - -#endif - -#if defined(NETWARE) -/* - Re-entrant versions of functions seem to be better for loading NLMs in different address space. - Since we have them now in LibC, we might as well make use of them. -*/ - -#define HAVE_LOCALTIME_R 1 -#define HAVE_CTIME_R 1 -#define HAVE_ASCTIME_R 1 -#define HAVE_GMTIME_R 1 - -PHPAPI struct tm *php_localtime_r(const time_t *const timep, struct tm *p_tm) -{ - /* Modified according to LibC definition */ - if (localtime_r(timep, p_tm) != NULL) - return (p_tm); - return (NULL); -} - -PHPAPI char *php_ctime_r(const time_t *clock, char *buf) -{ - /* Modified according to LibC definition */ - if (ctime_r(clock, buf) != NULL) - return (buf); - return (NULL); -} - -PHPAPI char *php_asctime_r(const struct tm *tm, char *buf) -{ - /* Modified according to LibC definition */ - if (asctime_r(tm, buf) != NULL) - return (buf); - return (NULL); -} - -PHPAPI struct tm *php_gmtime_r(const time_t *const timep, struct tm *p_tm) -{ - /* Modified according to LibC definition */ - if (gmtime_r(timep, p_tm) != NULL) - return (p_tm); - return (NULL); -} - -#endif /* NETWARE */ - -#if defined(__BEOS__) - -PHPAPI struct tm *php_gmtime_r(const time_t *const timep, struct tm *p_tm) -{ - /* Modified according to LibC definition */ - if (((struct tm*)gmtime_r(timep, p_tm)) == p_tm) - return (p_tm); - return (NULL); -} - -#endif /* BEOS */ - -#if !defined(HAVE_POSIX_READDIR_R) - -PHPAPI int php_readdir_r(DIR *dirp, struct dirent *entry, - struct dirent **result) -{ -#if defined(HAVE_OLD_READDIR_R) - int ret = 0; - - /* We cannot rely on the return value of readdir_r - as it differs between various platforms - (HPUX returns 0 on success whereas Solaris returns non-zero) - */ - entry->d_name[0] = '\0'; - readdir_r(dirp, entry); - - if (entry->d_name[0] == '\0') { - *result = NULL; - ret = errno; - } else { - *result = entry; - } - return ret; -#else - struct dirent *ptr; - int ret = 0; - - local_lock(READDIR_R); - - errno = 0; - - ptr = readdir(dirp); - - if (!ptr && errno != 0) - ret = errno; - - if (ptr) - memcpy(entry, ptr, sizeof(*ptr)); - - *result = ptr; - - local_unlock(READDIR_R); - - return ret; -#endif -} - -#endif - -#if !defined(HAVE_LOCALTIME_R) && defined(HAVE_LOCALTIME) - -PHPAPI struct tm *php_localtime_r(const time_t *const timep, struct tm *p_tm) -{ - struct tm *tmp; - - local_lock(LOCALTIME_R); - - tmp = localtime(timep); - if (tmp) { - memcpy(p_tm, tmp, sizeof(struct tm)); - tmp = p_tm; - } - - local_unlock(LOCALTIME_R); - - return tmp; -} - -#endif - -#if !defined(HAVE_CTIME_R) && defined(HAVE_CTIME) - -PHPAPI char *php_ctime_r(const time_t *clock, char *buf) -{ - char *tmp; - - local_lock(CTIME_R); - - tmp = ctime(clock); - strcpy(buf, tmp); - - local_unlock(CTIME_R); - - return buf; -} - -#endif - -#if !defined(HAVE_ASCTIME_R) && defined(HAVE_ASCTIME) - -PHPAPI char *php_asctime_r(const struct tm *tm, char *buf) -{ - char *tmp; - - local_lock(ASCTIME_R); - - tmp = asctime(tm); - strcpy(buf, tmp); - - local_unlock(ASCTIME_R); - - return buf; -} - -#endif - -#if !defined(HAVE_GMTIME_R) && defined(HAVE_GMTIME) - -PHPAPI struct tm *php_gmtime_r(const time_t *const timep, struct tm *p_tm) -{ - struct tm *tmp; - - local_lock(GMTIME_R); - - tmp = gmtime(timep); - if (tmp) { - memcpy(p_tm, tmp, sizeof(struct tm)); - tmp = p_tm; - } - - local_unlock(GMTIME_R); - - return tmp; -} - -#endif - -#if defined(PHP_NEED_REENTRANCY) - -void reentrancy_startup(void) -{ - int i; - - for (i = 0; i < NUMBER_OF_LOCKS; i++) { - reentrant_locks[i] = tsrm_mutex_alloc(); - } -} - -void reentrancy_shutdown(void) -{ - int i; - - for (i = 0; i < NUMBER_OF_LOCKS; i++) { - tsrm_mutex_free(reentrant_locks[i]); - } -} - -#endif - -#ifndef HAVE_RAND_R - -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Posix rand_r function added May 1999 by Wes Peters <wes@softweyr.com>. - */ - -#include <sys/types.h> -#include <stdlib.h> - -static int -do_rand(unsigned long *ctx) -{ - return ((*ctx = *ctx * 1103515245 + 12345) % ((u_long)PHP_RAND_MAX + 1)); -} - - -PHPAPI int -php_rand_r(unsigned int *ctx) -{ - u_long val = (u_long) *ctx; - *ctx = do_rand(&val); - return (int) *ctx; -} - -#endif - - -#ifndef HAVE_STRTOK_R - -/* - * Copyright (c) 1998 Softweyr LLC. All rights reserved. - * - * strtok_r, from Berkeley strtok - * Oct 13, 1998 by Wes Peters <wes@softweyr.com> - * - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notices, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notices, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * - * This product includes software developed by Softweyr LLC, the - * University of California, Berkeley, and its contributors. - * - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTWEYR LLC, THE - * REGENTS, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <stddef.h> - -PHPAPI char * -php_strtok_r(char *s, const char *delim, char **last) -{ - char *spanp; - int c, sc; - char *tok; - - if (s == NULL && (s = *last) == NULL) - { - return NULL; - } - - /* - * Skip (span) leading delimiters (s += strspn(s, delim), sort of). - */ -cont: - c = *s++; - for (spanp = (char *)delim; (sc = *spanp++) != 0; ) - { - if (c == sc) - { - goto cont; - } - } - - if (c == 0) /* no non-delimiter characters */ - { - *last = NULL; - return NULL; - } - tok = s - 1; - - /* - * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). - * Note that delim must have one NUL; we stop if we see that, too. - */ - for (;;) - { - c = *s++; - spanp = (char *)delim; - do - { - if ((sc = *spanp++) == c) - { - if (c == 0) - { - s = NULL; - } - else - { - char *w = s - 1; - *w = '\0'; - } - *last = s; - return tok; - } - } - while (sc != 0); - } - /* NOTREACHED */ -} - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/rfc1867.c b/main/rfc1867.c deleted file mode 100644 index 385a52b315..0000000000 --- a/main/rfc1867.c +++ /dev/null @@ -1,1177 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | Jani Taskinen <sniper@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* - * This product includes software developed by the Apache Group - * for use in the Apache HTTP server project (http://www.apache.org/). - * - */ - -#include <stdio.h> -#include "php.h" -#include "php_open_temporary_file.h" -#include "zend_globals.h" -#include "php_globals.h" -#include "php_variables.h" -#include "rfc1867.h" - -#undef DEBUG_FILE_UPLOAD - -#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING) -#include "ext/mbstring/mbstring.h" - -static void safe_php_register_variable(char *var, char *strval, zval *track_vars_array, zend_bool override_protection TSRMLS_DC); - -#define SAFE_RETURN { \ - php_mb_flush_gpc_variables(num_vars, val_list, len_list, array_ptr TSRMLS_CC); \ - if (lbuf) efree(lbuf); \ - if (abuf) efree(abuf); \ - if (array_index) efree(array_index); \ - zend_hash_destroy(&PG(rfc1867_protected_variables)); \ - zend_llist_destroy(&header); \ - if (mbuff->boundary_next) efree(mbuff->boundary_next); \ - if (mbuff->boundary) efree(mbuff->boundary); \ - if (mbuff->buffer) efree(mbuff->buffer); \ - if (mbuff) efree(mbuff); \ - return; } - -void php_mb_flush_gpc_variables(int num_vars, char **val_list, int *len_list, zval *array_ptr TSRMLS_DC) -{ - int i; - if (php_mb_encoding_translation(TSRMLS_C)) { - if (num_vars > 0 && - php_mb_gpc_encoding_detector(val_list, len_list, num_vars, NULL TSRMLS_CC) == SUCCESS) { - php_mb_gpc_encoding_converter(val_list, len_list, num_vars, NULL, NULL TSRMLS_CC); - } - for (i=0; i<num_vars; i+=2){ - safe_php_register_variable(val_list[i], val_list[i+1], array_ptr, 0 TSRMLS_CC); - efree(val_list[i]); - efree(val_list[i+1]); - } - efree(val_list); - efree(len_list); - } -} - -void php_mb_gpc_realloc_buffer(char ***pval_list, int **plen_list, int *num_vars_max, int inc TSRMLS_DC) -{ - /* allow only even increments */ - if (inc & 1) { - inc++; - } - (*num_vars_max) += inc; - *pval_list = (char **)erealloc(*pval_list, (*num_vars_max+2)*sizeof(char *)); - *plen_list = (int *)erealloc(*plen_list, (*num_vars_max+2)*sizeof(int)); -} - -void php_mb_gpc_stack_variable(char *param, char *value, char ***pval_list, int **plen_list, int *num_vars, int *num_vars_max TSRMLS_DC) -{ - char **val_list=*pval_list; - int *len_list=*plen_list; - - if (*num_vars>=*num_vars_max){ - php_mb_gpc_realloc_buffer(pval_list, plen_list, num_vars_max, - 16 TSRMLS_CC); - } - - val_list[*num_vars] = (char *)estrdup(param); - len_list[*num_vars] = strlen(param); - (*num_vars)++; - val_list[*num_vars] = (char *)estrdup(value); - len_list[*num_vars] = strlen(value); - (*num_vars)++; -} - -#else - -#define SAFE_RETURN { \ - if (lbuf) efree(lbuf); \ - if (abuf) efree(abuf); \ - if (array_index) efree(array_index); \ - zend_hash_destroy(&PG(rfc1867_protected_variables)); \ - zend_llist_destroy(&header); \ - if (mbuff->boundary_next) efree(mbuff->boundary_next); \ - if (mbuff->boundary) efree(mbuff->boundary); \ - if (mbuff->buffer) efree(mbuff->buffer); \ - if (mbuff) efree(mbuff); \ - return; } -#endif - -/* The longest property name we use in an uploaded file array */ -#define MAX_SIZE_OF_INDEX sizeof("[tmp_name]") - -/* The longest anonymous name */ -#define MAX_SIZE_ANONNAME 33 - -/* Errors */ -#define UPLOAD_ERROR_OK 0 /* File upload succesful */ -#define UPLOAD_ERROR_A 1 /* Uploaded file exceeded upload_max_filesize */ -#define UPLOAD_ERROR_B 2 /* Uploaded file exceeded MAX_FILE_SIZE */ -#define UPLOAD_ERROR_C 3 /* Partially uploaded */ -#define UPLOAD_ERROR_D 4 /* No file uploaded */ - -void php_rfc1867_register_constants(TSRMLS_D) -{ - REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_OK", UPLOAD_ERROR_OK, CONST_CS | CONST_PERSISTENT); - REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_INI_SIZE", UPLOAD_ERROR_A, CONST_CS | CONST_PERSISTENT); - REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_FORM_SIZE", UPLOAD_ERROR_B, CONST_CS | CONST_PERSISTENT); - REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_PARTIAL", UPLOAD_ERROR_C, CONST_CS | CONST_PERSISTENT); - REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_NO_FILE", UPLOAD_ERROR_D, CONST_CS | CONST_PERSISTENT); -} - -static void normalize_protected_variable(char *varname TSRMLS_DC) -{ - char *s=varname, *index=NULL, *indexend=NULL, *p; - - /* overjump leading space */ - while (*s == ' ') { - s++; - } - - /* and remove it */ - if (s != varname) { - memmove(varname, s, strlen(s)+1); - } - - for (p=varname; *p && *p != '['; p++) { - switch(*p) { - case ' ': - case '.': - *p='_'; - break; - } - } - - /* find index */ - index = strchr(varname, '['); - if (index) { - index++; - s=index; - } else { - return; - } - - /* done? */ - while (index) { - - while (*index == ' ' || *index == '\r' || *index == '\n' || *index=='\t') { - index++; - } - indexend = strchr(index, ']'); - indexend = indexend ? indexend + 1 : index + strlen(index); - - if (s != index) { - memmove(s, index, strlen(index)+1); - s += indexend-index; - } else { - s = indexend; - } - - if (*s == '[') { - s++; - index = s; - } else { - index = NULL; - } - } - *s++='\0'; -} - - -static void add_protected_variable(char *varname TSRMLS_DC) -{ - int dummy=1; - - normalize_protected_variable(varname TSRMLS_CC); - zend_hash_add(&PG(rfc1867_protected_variables), varname, strlen(varname)+1, &dummy, sizeof(int), NULL); -} - - -static zend_bool is_protected_variable(char *varname TSRMLS_DC) -{ - normalize_protected_variable(varname TSRMLS_CC); - return zend_hash_exists(&PG(rfc1867_protected_variables), varname, strlen(varname)+1); -} - - -static void safe_php_register_variable(char *var, char *strval, zval *track_vars_array, zend_bool override_protection TSRMLS_DC) -{ - if (override_protection || !is_protected_variable(var TSRMLS_CC)) { - php_register_variable(var, strval, track_vars_array TSRMLS_CC); - } -} - - -static void safe_php_register_variable_ex(char *var, zval *val, zval *track_vars_array, zend_bool override_protection TSRMLS_DC) -{ - if (override_protection || !is_protected_variable(var TSRMLS_CC)) { - php_register_variable_ex(var, val, track_vars_array TSRMLS_CC); - } -} - - -static void register_http_post_files_variable(char *strvar, char *val, zval *http_post_files, zend_bool override_protection TSRMLS_DC) -{ - int register_globals = PG(register_globals); - - PG(register_globals) = 0; - safe_php_register_variable(strvar, val, http_post_files, override_protection TSRMLS_CC); - PG(register_globals) = register_globals; -} - - -static void register_http_post_files_variable_ex(char *var, zval *val, zval *http_post_files, zend_bool override_protection TSRMLS_DC) -{ - int register_globals = PG(register_globals); - - PG(register_globals) = 0; - safe_php_register_variable_ex(var, val, http_post_files, override_protection TSRMLS_CC); - PG(register_globals) = register_globals; -} - - -static int unlink_filename(char **filename TSRMLS_DC) -{ - VCWD_UNLINK(*filename); - return 0; -} - - -void destroy_uploaded_files_hash(TSRMLS_D) -{ - zend_hash_apply(SG(rfc1867_uploaded_files), (apply_func_t) unlink_filename TSRMLS_CC); - zend_hash_destroy(SG(rfc1867_uploaded_files)); - FREE_HASHTABLE(SG(rfc1867_uploaded_files)); -} - - -/* - * Following code is based on apache_multipart_buffer.c from libapreq-0.33 package. - * - */ - -#define FILLUNIT (1024 * 5) - -typedef struct { - - /* read buffer */ - char *buffer; - char *buf_begin; - int bufsize; - int bytes_in_buffer; - - /* boundary info */ - char *boundary; - char *boundary_next; - int boundary_next_len; - -} multipart_buffer; - - -typedef struct { - char *key; - char *value; -} mime_header_entry; - - -/* - fill up the buffer with client data. - returns number of bytes added to buffer. -*/ -static int fill_buffer(multipart_buffer *self TSRMLS_DC) -{ - int bytes_to_read, total_read = 0, actual_read = 0; - - /* shift the existing data if necessary */ - if (self->bytes_in_buffer > 0 && self->buf_begin != self->buffer) { - memmove(self->buffer, self->buf_begin, self->bytes_in_buffer); - } - - self->buf_begin = self->buffer; - - /* calculate the free space in the buffer */ - bytes_to_read = self->bufsize - self->bytes_in_buffer; - - /* read the required number of bytes */ - while (bytes_to_read > 0) { - - char *buf = self->buffer + self->bytes_in_buffer; - - actual_read = sapi_module.read_post(buf, bytes_to_read TSRMLS_CC); - - /* update the buffer length */ - if (actual_read > 0) { - self->bytes_in_buffer += actual_read; - SG(read_post_bytes) += actual_read; - total_read += actual_read; - bytes_to_read -= actual_read; - } else { - break; - } - } - - return total_read; -} - - -/* eof if we are out of bytes, or if we hit the final boundary */ -static int multipart_buffer_eof(multipart_buffer *self TSRMLS_DC) -{ - if ( (self->bytes_in_buffer == 0 && fill_buffer(self TSRMLS_CC) < 1) ) { - return 1; - } else { - return 0; - } -} - - -/* create new multipart_buffer structure */ -static multipart_buffer *multipart_buffer_new(char *boundary, int boundary_len) -{ - multipart_buffer *self = (multipart_buffer *) ecalloc(1, sizeof(multipart_buffer)); - - int minsize = boundary_len + 6; - if (minsize < FILLUNIT) minsize = FILLUNIT; - - self->buffer = (char *) ecalloc(1, minsize + 1); - self->bufsize = minsize; - - self->boundary = (char *) ecalloc(1, boundary_len + 3); - sprintf(self->boundary, "--%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->buf_begin = self->buffer; - self->bytes_in_buffer = 0; - - return self; -} - - -/* - gets the next CRLF terminated line from the input buffer. - if it doesn't find a CRLF, and the buffer isn't completely full, returns - NULL; otherwise, returns the beginning of the null-terminated line, - minus the CRLF. - - note that we really just look for LF terminated lines. this works - around a bug in internet explorer for the macintosh which sends mime - boundaries that are only LF terminated when you use an image submit - button in a multipart/form-data form. - */ -static char *next_line(multipart_buffer *self) -{ - /* look for LF in the data */ - char* line = self->buf_begin; - char* ptr = memchr(self->buf_begin, '\n', self->bytes_in_buffer); - - if (ptr) { /* LF found */ - - /* terminate the string, remove CRLF */ - if ((ptr - line) > 0 && *(ptr-1) == '\r') { - *(ptr-1) = 0; - } else { - *ptr = 0; - } - - /* bump the pointer */ - self->buf_begin = ptr + 1; - self->bytes_in_buffer -= (self->buf_begin - line); - - } else { /* no LF found */ - - /* buffer isn't completely full, fail */ - if (self->bytes_in_buffer < self->bufsize) { - return NULL; - } - /* return entire buffer as a partial line */ - line[self->bufsize] = 0; - self->buf_begin = ptr; - self->bytes_in_buffer = 0; - } - - return line; -} - - -/* returns the next CRLF terminated line from the client */ -static char *get_line(multipart_buffer *self TSRMLS_DC) -{ - char* ptr = next_line(self); - - if (!ptr) { - fill_buffer(self TSRMLS_CC); - ptr = next_line(self); - } - - return ptr; -} - - -/* Free header entry */ -static void php_free_hdr_entry(mime_header_entry *h) -{ - if (h->key) { - efree(h->key); - } - if (h->value) { - efree(h->value); - } -} - - -/* finds a boundary */ -static int find_boundary(multipart_buffer *self, char *boundary TSRMLS_DC) -{ - char *line; - - /* loop thru lines */ - while( (line = get_line(self TSRMLS_CC)) ) - { - /* finished if we found the boundary */ - if (!strcmp(line, boundary)) { - return 1; - } - } - - /* didn't find the boundary */ - return 0; -} - - -/* parse headers */ -static int multipart_buffer_headers(multipart_buffer *self, zend_llist *header TSRMLS_DC) -{ - char *line; - mime_header_entry prev_entry, entry; - int prev_len, cur_len; - - /* didn't find boundary, abort */ - if (!find_boundary(self, self->boundary TSRMLS_CC)) { - return 0; - } - - /* get lines of text, or CRLF_CRLF */ - - while( (line = get_line(self TSRMLS_CC)) && strlen(line) > 0 ) - { - /* add header to table */ - - char *key = line; - char *value = NULL; - - /* space in the beginning means same header */ - if (!isspace(line[0])) { - value = strchr(line, ':'); - } - - if (value) { - *value = 0; - do { value++; } while(isspace(*value)); - - entry.value = estrdup(value); - entry.key = estrdup(key); - - } else if (zend_llist_count(header)) { /* If no ':' on the line, add to previous line */ - - prev_len = strlen(prev_entry.value); - cur_len = strlen(line); - - entry.value = emalloc(prev_len + cur_len + 1); - memcpy(entry.value, prev_entry.value, prev_len); - memcpy(entry.value + prev_len, line, cur_len); - entry.value[cur_len + prev_len] = '\0'; - - entry.key = estrdup(prev_entry.key); - - zend_llist_remove_tail(header); - } else { - continue; - } - - zend_llist_add_element(header, &entry); - prev_entry = entry; - } - - return 1; -} - - -static char *php_mime_get_hdr_value(zend_llist header, char *key) -{ - mime_header_entry *entry; - - if (key == NULL) { - return NULL; - } - - entry = zend_llist_get_first(&header); - while (entry) { - if (!strcasecmp(entry->key, key)) { - return entry->value; - } - entry = zend_llist_get_next(&header); - } - - return NULL; -} - - -static char *php_ap_getword(char **line, char stop) -{ - char *pos = *line, quote; - char *res; - - while (*pos && *pos != stop) { - - if ((quote = *pos) == '"' || quote == '\'') { - ++pos; - while (*pos && *pos != quote) { - if (*pos == '\\' && pos[1] && pos[1] == quote) { - pos += 2; - } else { - ++pos; - } - } - if (*pos) { - ++pos; - } - } else ++pos; - - } - if (*pos == '\0') { - res = estrdup(*line); - *line += strlen(*line); - return res; - } - - res = estrndup(*line, pos - *line); - - while (*pos == stop) { - ++pos; - } - - *line = pos; - return res; -} - - -static char *substring_conf(char *start, int len, char quote TSRMLS_DC) -{ - char *result = emalloc(len + 2); - char *resp = result; - int i; - - for (i = 0; i < len; ++i) { - if (start[i] == '\\' && (start[i + 1] == '\\' || (quote && start[i + 1] == quote))) { - *resp++ = start[++i]; - } else { -#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING) - if (php_mb_encoding_translation(TSRMLS_C)) { - size_t j = php_mb_gpc_mbchar_bytes(start+i TSRMLS_CC); - while (j-- > 0 && i < len) { - *resp++ = start[i++]; - } - --i; - } else { - *resp++ = start[i]; - } -#else - *resp++ = start[i]; -#endif - } - } - - *resp++ = '\0'; - return result; -} - - -static char *php_ap_getword_conf(char **line TSRMLS_DC) -{ - char *str = *line, *strend, *res, quote; - -#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING) - if (php_mb_encoding_translation(TSRMLS_C)) { - int len=strlen(str); - php_mb_gpc_encoding_detector(&str, &len, 1, NULL TSRMLS_CC); - } -#endif - - while (*str && isspace(*str)) { - ++str; - } - - if (!*str) { - *line = str; - return estrdup(""); - } - - if ((quote = *str) == '"' || quote == '\'') { - strend = str + 1; - while (*strend && *strend != quote) { - if (*strend == '\\' && strend[1] && strend[1] == quote) { - strend += 2; - } else { - ++strend; - } - } - res = substring_conf(str + 1, strend - str - 1, quote TSRMLS_CC); - - if (*strend == quote) { - ++strend; - } - - } else { - - strend = str; - while (*strend && !isspace(*strend)) { - ++strend; - } - res = substring_conf(str, strend - str, 0 TSRMLS_CC); - } - - while (*strend && isspace(*strend)) { - ++strend; - } - - *line = strend; - return res; -} - - -/* - search for a string in a fixed-length byte string. - if partial is true, partial matches are allowed at the end of the buffer. - returns NULL if not found, or a pointer to the start of the first match. -*/ -static void *php_ap_memstr(char *haystack, int haystacklen, char *needle, int needlen, int partial) -{ - int len = haystacklen; - char *ptr = haystack; - - /* iterate through first character matches */ - while( (ptr = memchr(ptr, needle[0], len)) ) { - - /* calculate length after match */ - len = haystacklen - (ptr - (char *)haystack); - - /* done if matches up to capacity of buffer */ - if (memcmp(needle, ptr, needlen < len ? needlen : len) == 0 && (partial || len >= needlen)) { - break; - } - - /* next character */ - ptr++; len--; - } - - return ptr; -} - - -/* read until a boundary condition */ -static int multipart_buffer_read(multipart_buffer *self, char *buf, int bytes TSRMLS_DC) -{ - int len, max; - char *bound; - - /* fill buffer if needed */ - if (bytes > self->bytes_in_buffer) { - fill_buffer(self TSRMLS_CC); - } - - /* look for a potential boundary match, only read data up to that point */ - if ((bound = php_ap_memstr(self->buf_begin, self->bytes_in_buffer, self->boundary_next, self->boundary_next_len, 1))) { - max = bound - self->buf_begin; - } else { - max = self->bytes_in_buffer; - } - - /* maximum number of bytes we are reading */ - len = max < bytes-1 ? max : bytes-1; - - /* if we read any data... */ - if (len > 0) { - - /* copy the data */ - memcpy(buf, self->buf_begin, len); - buf[len] = 0; - - if (bound && len > 0 && buf[len-1] == '\r') { - buf[--len] = 0; - } - - /* update the buffer */ - self->bytes_in_buffer -= len; - self->buf_begin += len; - } - - return len; -} - - -/* - XXX: this is horrible memory-usage-wise, but we only expect - to do this on small pieces of form data. -*/ -static char *multipart_buffer_read_body(multipart_buffer *self TSRMLS_DC) -{ - char buf[FILLUNIT], *out=NULL; - int total_bytes=0, read_bytes=0; - - while((read_bytes = multipart_buffer_read(self, buf, sizeof(buf) TSRMLS_CC))) { - out = erealloc(out, total_bytes + read_bytes + 1); - memcpy(out + total_bytes, buf, read_bytes); - total_bytes += read_bytes; - } - - if (out) out[total_bytes] = '\0'; - - return out; -} - - -/* - * The combined READER/HANDLER - * - */ - -SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) -{ - char *boundary, *s=NULL, *boundary_end = NULL, *start_arr=NULL, *array_index=NULL; - char *temp_filename=NULL, *lbuf=NULL, *abuf=NULL; - int boundary_len=0, total_bytes=0, cancel_upload=0, is_arr_upload=0, array_len=0; - int max_file_size=0, skip_upload=0, anonindex=0, is_anonymous; - zval *http_post_files=NULL; -#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING) - int str_len = 0, num_vars = 0, num_vars_max = 2*10, *len_list = NULL; - char **val_list = NULL; -#endif - zend_bool magic_quotes_gpc; - multipart_buffer *mbuff; - zval *array_ptr = (zval *) arg; - FILE *fp; - zend_llist header; - - if (SG(request_info).content_length > SG(post_max_size)) { - sapi_module.sapi_error(E_WARNING, "POST Content-Length of %d bytes exceeds the limit of %d bytes", SG(request_info).content_length, SG(post_max_size)); - return; - } - - /* Get the boundary */ - boundary = strstr(content_type_dup, "boundary"); - if (!boundary || !(boundary=strchr(boundary, '='))) { - sapi_module.sapi_error(E_WARNING, "Missing boundary in multipart/form-data POST data"); - return; - } - - boundary++; - boundary_len = strlen(boundary); - - if (boundary[0] == '"') { - boundary++; - boundary_end = strchr(boundary, '"'); - if (!boundary_end) { - sapi_module.sapi_error(E_WARNING, "Invalid boundary in multipart/form-data POST data"); - return; - } - } else { - /* search for the end of the boundary */ - boundary_end = strchr(boundary, ','); - } - if (boundary_end) { - boundary_end[0] = '\0'; - boundary_len = boundary_end-boundary; - } - - /* Initialize the buffer */ - if (!(mbuff = multipart_buffer_new(boundary, boundary_len))) { - sapi_module.sapi_error(E_WARNING, "Unable to initialize the input buffer"); - return; - } - - /* Initialize $_FILES[] */ - zend_hash_init(&PG(rfc1867_protected_variables), 5, NULL, NULL, 0); - - ALLOC_HASHTABLE(SG(rfc1867_uploaded_files)); - zend_hash_init(SG(rfc1867_uploaded_files), 5, NULL, (dtor_func_t) free_estring, 0); - - ALLOC_ZVAL(http_post_files); - array_init(http_post_files); - INIT_PZVAL(http_post_files); - PG(http_globals)[TRACK_VARS_FILES] = http_post_files; - -#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING) - if (php_mb_encoding_translation(TSRMLS_C)) { - val_list = (char **)ecalloc(num_vars_max+2, sizeof(char *)); - len_list = (int *)ecalloc(num_vars_max+2, sizeof(int)); - } -#endif - zend_llist_init(&header, sizeof(mime_header_entry), (llist_dtor_func_t) php_free_hdr_entry, 0); - - while (!multipart_buffer_eof(mbuff TSRMLS_CC)) - { - char buff[FILLUNIT]; - char *cd=NULL,*param=NULL,*filename=NULL; - int blen=0, wlen=0; - - zend_llist_clean(&header); - - if (!multipart_buffer_headers(mbuff, &header TSRMLS_CC)) { - SAFE_RETURN; - } - - if ((cd = php_mime_get_hdr_value(header, "Content-Disposition"))) { - char *pair=NULL; - - while (isspace(*cd)) { - ++cd; - } - - while (*cd && (pair = php_ap_getword(&cd, ';'))) - { - char *key=NULL, *word = pair; - - while (isspace(*cd)) { - ++cd; - } - - if (strchr(pair, '=')) { - key = php_ap_getword(&pair, '='); - - if (!strcasecmp(key, "name")) { - if (param) { - efree(param); - } - param = php_ap_getword_conf(&pair TSRMLS_CC); - } else if (!strcasecmp(key, "filename")) { - if (filename) { - efree(filename); - } - filename = php_ap_getword_conf(&pair TSRMLS_CC); - } - } - if (key) { - efree(key); - } - efree(word); - } - - /* Normal form variable, safe to read all data into memory */ - if (!filename && param) { - - char *value = multipart_buffer_read_body(mbuff TSRMLS_CC); - unsigned int new_val_len; /* Dummy variable */ - - if (!value) { - value = estrdup(""); - } - - if (sapi_module.input_filter(PARSE_POST, param, &value, strlen(value), &new_val_len TSRMLS_CC)) { -#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING) - if (php_mb_encoding_translation(TSRMLS_C)) { - php_mb_gpc_stack_variable(param, value, &val_list, &len_list, - &num_vars, &num_vars_max TSRMLS_CC); - } else { - safe_php_register_variable(param, value, array_ptr, 0 TSRMLS_CC); - } -#else - safe_php_register_variable(param, value, array_ptr, 0 TSRMLS_CC); -#endif - } - if (!strcasecmp(param, "MAX_FILE_SIZE")) { - max_file_size = atol(value); - } - - efree(param); - efree(value); - continue; - } - - /* If file_uploads=off, skip the file part */ - if (!PG(file_uploads)) { - skip_upload = 1; - } - - /* Return with an error if the posted data is garbled */ - if (!param && !filename) { - sapi_module.sapi_error(E_WARNING, "File Upload Mime headers garbled"); - SAFE_RETURN; - } - - if (!param) { - is_anonymous = 1; - param = emalloc(MAX_SIZE_ANONNAME); - snprintf(param, MAX_SIZE_ANONNAME, "%u", anonindex++); - } else { - is_anonymous = 0; - } - - if (!skip_upload) { - /* Handle file */ - fp = php_open_temporary_file(PG(upload_tmp_dir), "php", &temp_filename TSRMLS_CC); - if (!fp) { - sapi_module.sapi_error(E_WARNING, "File upload error - unable to create a temporary file"); - skip_upload = 1; - } - } - if (skip_upload) { - efree(param); - efree(filename); - continue; - } - - total_bytes = 0; - cancel_upload = 0; - - if(strlen(filename) == 0) { -#ifdef DEBUG_FILE_UPLOAD - sapi_module.sapi_error(E_NOTICE, "No file uploaded"); -#endif - cancel_upload = UPLOAD_ERROR_D; - } - - while (!cancel_upload && (blen = multipart_buffer_read(mbuff, buff, sizeof(buff) TSRMLS_CC))) - { - if (PG(upload_max_filesize) > 0 && total_bytes > PG(upload_max_filesize)) { - sapi_module.sapi_error(E_WARNING, "upload_max_filesize of %ld bytes exceeded - file [%s=%s] not saved", PG(upload_max_filesize), param, filename); - cancel_upload = UPLOAD_ERROR_A; - } else if (max_file_size && (total_bytes > max_file_size)) { - sapi_module.sapi_error(E_WARNING, "MAX_FILE_SIZE of %ld bytes exceeded - file [%s=%s] not saved", max_file_size, param, filename); - cancel_upload = UPLOAD_ERROR_B; - } else if (blen > 0) { - wlen = fwrite(buff, 1, blen, fp); - - if (wlen < blen) { - sapi_module.sapi_error(E_WARNING, "Only %d bytes were written, expected to write %ld", wlen, blen); - cancel_upload = UPLOAD_ERROR_C; - } else { - total_bytes += wlen; - } - } - } - fclose(fp); - -#ifdef DEBUG_FILE_UPLOAD - if(strlen(filename) > 0 && total_bytes == 0) { - sapi_module.sapi_error(E_WARNING, "Uploaded file size 0 - file [%s=%s] not saved", param, filename); - cancel_upload = 5; - } -#endif - - if (cancel_upload) { - if (temp_filename) { - unlink(temp_filename); - efree(temp_filename); - } - temp_filename=""; - } else { - zend_hash_add(SG(rfc1867_uploaded_files), temp_filename, strlen(temp_filename) + 1, &temp_filename, sizeof(char *), NULL); - } - - /* is_arr_upload is true when name of file upload field - * ends in [.*] - * start_arr is set to point to 1st [ - */ - is_arr_upload = (start_arr = strchr(param,'[')) && (param[strlen(param)-1] == ']'); - /* handle unterminated [ */ - if (!is_arr_upload && start_arr) { - *start_arr = '_'; - } - - if (is_arr_upload) { - array_len = strlen(start_arr); - if (array_index) { - efree(array_index); - } - array_index = estrndup(start_arr+1, array_len-2); - } - - /* Add $foo_name */ - if (lbuf) { - efree(lbuf); - } - 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); - } else { - sprintf(lbuf, "%s_name", param); - } - -#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING) - if (php_mb_encoding_translation(TSRMLS_C)) { - if (num_vars>=num_vars_max){ - php_mb_gpc_realloc_buffer(&val_list, &len_list, &num_vars_max, - 1 TSRMLS_CC); - } - val_list[num_vars] = filename; - len_list[num_vars] = strlen(filename); - num_vars++; - if(php_mb_gpc_encoding_detector(val_list, len_list, num_vars, NULL TSRMLS_CC) == SUCCESS) { - str_len = strlen(filename); - php_mb_gpc_encoding_converter(&filename, &str_len, 1, NULL, NULL TSRMLS_CC); - } - s = php_mb_strrchr(filename, '\\' TSRMLS_CC); - num_vars--; - } else { - s = strrchr(filename, '\\'); - } -#else - s = strrchr(filename, '\\'); -#endif - if (!is_anonymous) { - if (s && s > filename) { - safe_php_register_variable(lbuf, s+1, NULL, 0 TSRMLS_CC); - } else { - safe_php_register_variable(lbuf, filename, NULL, 0 TSRMLS_CC); - } - } - - /* Add $foo[name] */ - if (is_arr_upload) { - sprintf(lbuf, "%s[name][%s]", abuf, array_index); - } else { - sprintf(lbuf, "%s[name]", param); - } - if (s && s > filename) { - register_http_post_files_variable(lbuf, s+1, http_post_files, 0 TSRMLS_CC); - } else { - register_http_post_files_variable(lbuf, filename, http_post_files, 0 TSRMLS_CC); - } - efree(filename); - s = NULL; - - /* Possible Content-Type: */ - if (cancel_upload || !(cd = php_mime_get_hdr_value(header, "Content-Type"))) { - cd = ""; - } else { - /* fix for Opera 6.01 */ - s = strchr(cd, ';'); - if (s != NULL) { - *s = '\0'; - } - } - - /* Add $foo_type */ - if (is_arr_upload) { - sprintf(lbuf, "%s_type[%s]", abuf, array_index); - } else { - sprintf(lbuf, "%s_type", param); - } - if (!is_anonymous) { - safe_php_register_variable(lbuf, cd, NULL, 0 TSRMLS_CC); - } - - /* Add $foo[type] */ - if (is_arr_upload) { - sprintf(lbuf, "%s[type][%s]", abuf, array_index); - } else { - sprintf(lbuf, "%s[type]", param); - } - register_http_post_files_variable(lbuf, cd, http_post_files, 0 TSRMLS_CC); - - /* Restore Content-Type Header */ - if (s != NULL) { - *s = ';'; - } - s = ""; - - /* Initialize variables */ - add_protected_variable(param TSRMLS_CC); - - magic_quotes_gpc = PG(magic_quotes_gpc); - PG(magic_quotes_gpc) = 0; - /* if param is of form xxx[.*] this will cut it to xxx */ - if (!is_anonymous) { - safe_php_register_variable(param, temp_filename, NULL, 1 TSRMLS_CC); - } - - /* Add $foo[tmp_name] */ - if (is_arr_upload) { - sprintf(lbuf, "%s[tmp_name][%s]", abuf, array_index); - } else { - sprintf(lbuf, "%s[tmp_name]", param); - } - add_protected_variable(lbuf TSRMLS_CC); - register_http_post_files_variable(lbuf, temp_filename, http_post_files, 1 TSRMLS_CC); - - PG(magic_quotes_gpc) = magic_quotes_gpc; - - { - zval file_size, error_type; - - error_type.value.lval = cancel_upload; - error_type.type = IS_LONG; - - /* Add $foo[error] */ - if (cancel_upload) { - file_size.value.lval = 0; - file_size.type = IS_LONG; - } else { - file_size.value.lval = total_bytes; - file_size.type = IS_LONG; - } - - if (is_arr_upload) { - sprintf(lbuf, "%s[error][%s]", abuf, array_index); - } else { - sprintf(lbuf, "%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); - } else { - sprintf(lbuf, "%s_size", param); - } - if (!is_anonymous) { - safe_php_register_variable_ex(lbuf, &file_size, NULL, 0 TSRMLS_CC); - } - - /* Add $foo[size] */ - if (is_arr_upload) { - sprintf(lbuf, "%s[size][%s]", abuf, array_index); - } else { - sprintf(lbuf, "%s[size]", param); - } - register_http_post_files_variable_ex(lbuf, &file_size, http_post_files, 0 TSRMLS_CC); - } - efree(param); - } - } - - SAFE_RETURN; -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/rfc1867.h b/main/rfc1867.h deleted file mode 100644 index d8162914dd..0000000000 --- a/main/rfc1867.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef RFC1867_H -#define RFC1867_H - -#include "SAPI.h" - -#define MULTIPART_CONTENT_TYPE "multipart/form-data" - -SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler); - -void destroy_uploaded_files_hash(TSRMLS_D); -void php_rfc1867_register_constants(TSRMLS_D); - -#endif /* RFC1867_H */ diff --git a/main/safe_mode.c b/main/safe_mode.c deleted file mode 100644 index 9271610f9b..0000000000 --- a/main/safe_mode.c +++ /dev/null @@ -1,229 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" - -#include <stdio.h> -#include <stdlib.h> - -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <sys/stat.h> -#include "ext/standard/pageinfo.h" -#include "safe_mode.h" -#include "SAPI.h" -#include "php_globals.h" - -/* - * php_checkuid - * - * This function has six modes: - * - * 0 - return invalid (0) if file does not exist - * 1 - return valid (1) if file does not exist - * 2 - if file does not exist, check directory - * 3 - only check directory (needed for mkdir) - * 4 - check mode and param - * 5 - only check file - */ - -PHPAPI int php_checkuid_ex(const char *filename, char *fopen_mode, int mode, int flags) -{ - struct stat sb; - int ret, nofile=0; - long uid=0L, gid=0L, duid=0L, dgid=0L; - char path[MAXPATHLEN]; - char *s, filenamecopy[MAXPATHLEN]; - php_stream_wrapper *wrapper = NULL; - TSRMLS_FETCH(); - - strlcpy(filenamecopy, filename, MAXPATHLEN); - filename=(char *)&filenamecopy; - - if (!filename) { - return 0; /* path must be provided */ - } - - if (fopen_mode) { - if (fopen_mode[0] == 'r') { - mode = CHECKUID_DISALLOW_FILE_NOT_EXISTS; - } else { - mode = CHECKUID_CHECK_FILE_AND_DIR; - } - } - - /* - * If given filepath is a URL, allow - safe mode stuff - * related to URL's is checked in individual functions - */ - wrapper = php_stream_locate_url_wrapper(filename, NULL, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC); - if (wrapper != NULL) - return 1; - - /* First we see if the file is owned by the same user... - * If that fails, passthrough and check directory... - */ - if (mode != CHECKUID_ALLOW_ONLY_DIR) { - VCWD_REALPATH(filename, path); - ret = VCWD_STAT(path, &sb); - if (ret < 0) { - if (mode == CHECKUID_DISALLOW_FILE_NOT_EXISTS) { - if ((flags & CHECKUID_NO_ERRORS) == 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to access %s", filename); - } - return 0; - } else if (mode == CHECKUID_ALLOW_FILE_NOT_EXISTS) { - if ((flags & CHECKUID_NO_ERRORS) == 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to access %s", filename); - } - return 1; - } - nofile = 1; - } else { - uid = sb.st_uid; - gid = sb.st_gid; - if (uid == php_getuid()) { - return 1; - } else if (PG(safe_mode_gid) && gid == php_getgid()) { - return 1; - } - } - - /* Trim off filename */ - if ((s = strrchr(path, DEFAULT_SLASH))) { - if (s == path) - path[1] = '\0'; - else - *s = '\0'; - } - } else { /* CHECKUID_ALLOW_ONLY_DIR */ - s = strrchr(filename, DEFAULT_SLASH); - - if (s == filename) { - /* root dir */ - path[0] = DEFAULT_SLASH; - path[1] = '\0'; - } else if (s) { - *s = '\0'; - VCWD_REALPATH(filename, path); - *s = DEFAULT_SLASH; - } else { - /* Under Solaris, getcwd() can fail if there are no - * read permissions on a component of the path, even - * though it has the required x permissions */ - path[0] = '.'; - path[1] = '\0'; - VCWD_GETCWD(path, sizeof(path)); - } - } /* end CHECKUID_ALLOW_ONLY_DIR */ - - if (mode != CHECKUID_ALLOW_ONLY_FILE) { - /* check directory */ - ret = VCWD_STAT(path, &sb); - if (ret < 0) { - if ((flags & CHECKUID_NO_ERRORS) == 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to access %s", filename); - } - return 0; - } - duid = sb.st_uid; - dgid = sb.st_gid; - if (duid == php_getuid()) { - return 1; - } else if (PG(safe_mode_gid) && dgid == php_getgid()) { - return 1; - } else { - TSRMLS_FETCH(); - - if (SG(rfc1867_uploaded_files)) { - if (zend_hash_exists(SG(rfc1867_uploaded_files), (char *) filename, strlen(filename)+1)) { - return 1; - } - } - } - } - - if (mode == CHECKUID_ALLOW_ONLY_DIR) { - uid = duid; - gid = dgid; - if (s) { - *s = 0; - } - } - - if (nofile) { - uid = duid; - gid = dgid; - filename = path; - } - - if ((flags & CHECKUID_NO_ERRORS) == 0) { - if (PG(safe_mode_gid)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "SAFE MODE Restriction in effect. The script whose uid/gid is %ld/%ld is not allowed to access %s owned by uid/gid %ld/%ld", php_getuid(), php_getgid(), filename, uid, gid); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "SAFE MODE Restriction in effect. The script whose uid is %ld is not allowed to access %s owned by uid %ld", php_getuid(), filename, uid); - } - } - - return 0; -} - -PHPAPI int php_checkuid(const char *filename, char *fopen_mode, int mode) { - return php_checkuid_ex(filename, fopen_mode, mode, 0); -} - -PHPAPI char *php_get_current_user() -{ - struct passwd *pwd; - struct stat *pstat; - TSRMLS_FETCH(); - - if (SG(request_info).current_user) { - return SG(request_info).current_user; - } - - /* FIXME: I need to have this somehow handled if - USE_SAPI is defined, because cgi will also be - interfaced in USE_SAPI */ - - pstat = sapi_get_stat(TSRMLS_C); - - if (!pstat) { - return empty_string; - } - - if ((pwd=getpwuid(pstat->st_uid))==NULL) { - return empty_string; - } - 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; -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/safe_mode.h b/main/safe_mode.h deleted file mode 100644 index d03eabf292..0000000000 --- a/main/safe_mode.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef SAFE_MODE_H -#define SAFE_MODE_H - -/* mode's for php_checkuid() */ -#define CHECKUID_DISALLOW_FILE_NOT_EXISTS 0 -#define CHECKUID_ALLOW_FILE_NOT_EXISTS 1 -#define CHECKUID_CHECK_FILE_AND_DIR 2 -#define CHECKUID_ALLOW_ONLY_DIR 3 -#define CHECKUID_CHECK_MODE_PARAM 4 -#define CHECKUID_ALLOW_ONLY_FILE 5 - -/* flags for php_checkuid_ex() */ -#define CHECKUID_NO_ERRORS 0x01 - -extern PHPAPI int php_checkuid(const char *filename, char *fopen_mode, int mode); -extern PHPAPI int php_checkuid_ex(const char *filename, char *fopen_mode, int mode, int flags); -extern PHPAPI char *php_get_current_user(void); - -#endif diff --git a/main/snprintf.c b/main/snprintf.c deleted file mode 100644 index 94bebb8dd2..0000000000 --- a/main/snprintf.c +++ /dev/null @@ -1,1169 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* ==================================================================== - * Copyright (c) 1995-1998 The Apache Group. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the Apache Group - * for use in the Apache HTTP server project (http://www.apache.org/)." - * - * 4. The names "Apache Server" and "Apache Group" must not be used to - * endorse or promote products derived from this software without - * prior written permission. - * - * 5. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the Apache Group - * for use in the Apache HTTP server project (http://www.apache.org/)." - * - * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Group and was originally based - * on public domain software written at the National Center for - * Supercomputing Applications, University of Illinois, Urbana-Champaign. - * For more information on the Apache Group and the Apache HTTP server - * project, please see <http://www.apache.org/>. - * - * This code is based on, and used with the permission of, the - * 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 -#define NUL '\0' -#define INT_NULL ((int *)0) - -#define S_NULL "(null)" -#define S_NULL_LEN 6 - -#define FLOAT_DIGITS 6 -#define EXPONENT_LENGTH 10 - - -/* - * Convert num to its decimal format. - * Return value: - * - a pointer to a string containing the number (no sign) - * - len contains the length of the string - * - is_negative is set to TRUE or FALSE depending on the sign - * of the number (always set to FALSE if is_unsigned is TRUE) - * - * The caller provides a buffer for the string: that is the buf_end argument - * 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(register wide_int num, register bool_int is_unsigned, - register bool_int * is_negative, char *buf_end, register int *len) -{ - register char *p = buf_end; - register u_wide_int magnitude; - - if (is_unsigned) { - magnitude = (u_wide_int) num; - *is_negative = FALSE; - } else { - *is_negative = (num < 0); - - /* - * On a 2's complement machine, negating the most negative integer - * results in a number that cannot be represented as a signed integer. - * Here is what we do to obtain the number's magnitude: - * a. add 1 to the number - * b. negate it (becomes positive) - * c. convert it to unsigned - * d. add 1 - */ - if (*is_negative) { - wide_int t = num + 1; - - magnitude = ((u_wide_int) - t) + 1; - } else - magnitude = (u_wide_int) num; - } - - /* - * We use a do-while loop so that we write at least 1 digit - */ - do { - register u_wide_int new_magnitude = magnitude / 10; - - *--p = (char)(magnitude - new_magnitude * 10 + '0'); - magnitude = new_magnitude; - } - while (magnitude); - - *len = buf_end - p; - return (p); -} - -/* If you change this value then also change bug24640.phpt. - */ -#define NDIG 80 - - -/* - * Convert a floating point number to a string formats 'f', 'e' or 'E'. - * The result is placed in buf, and len denotes the length of the string - * 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) -{ - register char *s = buf; - register char *p; - 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); - - /* - * Check for Infinity and NaN - */ - if (isalpha((int)*p)) { - *len = strlen(p); - memcpy(buf, p, *len + 1); - *is_negative = FALSE; - return (buf); - } - if (format == 'f') { - if (decimal_point <= 0) { - *s++ = '0'; - if (precision > 0) { - *s++ = '.'; - while (decimal_point++ < 0) - *s++ = '0'; - } else if (add_dp) { - *s++ = '.'; - } - } else { - while (decimal_point-- > 0) { - *s++ = *p++; - } - if (precision > 0 || add_dp) { - *s++ = '.'; - } - } - } else { - *s++ = *p++; - if (precision > 0 || add_dp) - *s++ = '.'; - } - - /* - * copy the rest of p, the NUL is NOT copied - */ - while (*p) - *s++ = *p++; - - if (format != 'f') { - char temp[EXPONENT_LENGTH]; /* for exponent conversion */ - int t_len; - bool_int exponent_is_negative; - - *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); - *s++ = exponent_is_negative ? '-' : '+'; - - /* - * Make sure the exponent has at least 2 digits - */ - if (t_len == 1) - *s++ = '0'; - while (t_len--) - *s++ = *p++; - } else { - *s++ = '+'; - *s++ = '0'; - *s++ = '0'; - } - } - *len = s - buf; - return (buf); -} - - -/* - * Convert num to a base X number where X is a power of 2. nbits determines X. - * For example, if nbits is 3, we do base 8 conversion - * Return value: - * a pointer to a string containing the number - * - * The caller provides a buffer for the string: that is the buf_end argument - * 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) -{ - register int mask = (1 << nbits) - 1; - register char *p = buf_end; - static char low_digits[] = "0123456789abcdef"; - static char upper_digits[] = "0123456789ABCDEF"; - register char *digits = (format == 'X') ? upper_digits : low_digits; - - do { - *--p = digits[num & mask]; - num >>= nbits; - } - while (num); - - *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) { - p1 = &buf[NDIG]; - while (fi != 0) { - fj = modf(fi / 10, &fi); - if (p1 <= &buf[0]) { - mvl = NDIG - ndigits; - 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); -} - -#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) || PHP_BROKEN_SNPRINTF || PHP_BROKEN_VSNPRINTF - -/* - * NUM_BUF_SIZE is the size of the buffer used for arithmetic conversions - * - * XXX: this is a magic number; do not decrease it - */ -#define NUM_BUF_SIZE 512 - - -/* - * Descriptor for buffer area - */ -struct buf_area { - char *buf_end; - char *nextb; /* pointer to next byte to read/write */ -}; - -typedef struct buf_area buffy; - -/* - * The INS_CHAR macro inserts a character in the buffer and writes - * the buffer back to disk if necessary - * It uses the char pointers sp and bep: - * sp points to the next available character in the buffer - * bep points to the end-of-buffer+1 - * While using this macro, note that the nextb pointer is NOT updated. - * - * NOTE: Evaluation of the c argument should not have any side-effects - */ -#define INS_CHAR(c, sp, bep, cc) \ - { \ - if (sp < bep) \ - { \ - *sp++ = c; \ - } \ - cc++; \ - } - -#define NUM( c ) ( c - '0' ) - -#define STR_TO_DEC( str, num ) \ - num = NUM( *str++ ) ; \ - while ( isdigit((int)*str ) ) \ - { \ - num *= 10 ; \ - num += NUM( *str++ ) ; \ - } - -/* - * This macro does zero padding so that the precision - * requirement is satisfied. The padding is done by - * adding '0's to the left of the string that is going - * to be printed. - */ -#define FIX_PRECISION( adjust, precision, s, s_len ) \ - if ( adjust ) \ - while ( s_len < precision ) \ - { \ - *--s = '0' ; \ - s_len++ ; \ - } - -/* - * Macro that does padding. The padding is done by printing - * the character ch. - */ -#define PAD( width, len, ch ) do \ - { \ - INS_CHAR( ch, sp, bep, cc ) ; \ - width-- ; \ - } \ - while ( width > len ) - -/* - * Prefix the character ch to the string str - * Increase length - * Set the has_prefix flag - */ -#define PREFIX( str, length, ch ) *--str = ch ; length++ ; has_prefix = YES - - -/* - * Do format conversion placing the output in buffer - */ -static int format_converter(register buffy * odp, const char *fmt, - va_list ap) -{ - register char *sp; - register char *bep; - register int cc = 0; - register int i; - - register char *s = NULL; - char *q; - int s_len; - - register int min_width = 0; - int precision = 0; - enum { - LEFT, RIGHT - } adjust; - char pad_char; - char prefix_char; - - double fp_num; - wide_int i_num = (wide_int) 0; - u_wide_int ui_num; - - char num_buf[NUM_BUF_SIZE]; - char char_buf[2]; /* for printing %% and %<unknown> */ - - /* - * Flag variables - */ - length_modifier_e modifier; - boolean_e alternate_form; - boolean_e print_sign; - boolean_e print_blank; - boolean_e adjust_precision; - boolean_e adjust_width; - bool_int is_negative; - - sp = odp->nextb; - bep = odp->buf_end; - - while (*fmt) { - if (*fmt != '%') { - INS_CHAR(*fmt, sp, bep, cc); - } else { - /* - * Default variable settings - */ - adjust = RIGHT; - alternate_form = print_sign = print_blank = NO; - pad_char = ' '; - prefix_char = NUL; - - fmt++; - - /* - * Try to avoid checking for flags, width or precision - */ - if (isascii((int)*fmt) && !islower((int)*fmt)) { - /* - * Recognize flags: -, #, BLANK, + - */ - for (;; fmt++) { - if (*fmt == '-') - adjust = LEFT; - else if (*fmt == '+') - print_sign = YES; - else if (*fmt == '#') - alternate_form = YES; - else if (*fmt == ' ') - print_blank = YES; - else if (*fmt == '0') - pad_char = '0'; - else - break; - } - - /* - * Check if a width was specified - */ - if (isdigit((int)*fmt)) { - STR_TO_DEC(fmt, min_width); - adjust_width = YES; - } else if (*fmt == '*') { - min_width = va_arg(ap, int); - fmt++; - adjust_width = YES; - if (min_width < 0) { - adjust = LEFT; - min_width = -min_width; - } - } else - adjust_width = NO; - - /* - * Check if a precision was specified - * - * XXX: an unreasonable amount of precision may be specified - * resulting in overflow of num_buf. Currently we - * ignore this possibility. - */ - if (*fmt == '.') { - adjust_precision = YES; - fmt++; - if (isdigit((int)*fmt)) { - STR_TO_DEC(fmt, precision); - } else if (*fmt == '*') { - precision = va_arg(ap, int); - fmt++; - if (precision < 0) - precision = 0; - } else - precision = 0; - } else - adjust_precision = NO; - } else - adjust_precision = adjust_width = NO; - - /* - * Modifier check - */ - switch (*fmt) { - case 'L': - fmt++; - modifier = LM_LONG_DOUBLE; - break; - case 'l': - fmt++; -#if SIZEOF_LONG_LONG - if (*fmt == 'l') { - fmt++; - modifier = LM_LONG_LONG; - } else -#endif - modifier = LM_LONG; - break; - case 'z': - fmt++; - modifier = LM_SIZE_T; - break; - case 'j': - fmt++; -#if SIZEOF_INTMAX_T - modifier = LM_INTMAX_T; -#else - modifier = LM_SIZE_T; -#endif - break; - case 't': - fmt++; -#if SIZEOF_PTRDIFF_T - modifier = LM_PTRDIFF_T; -#else - modifier = LM_SIZE_T; -#endif - break; - case 'h': - fmt++; - if (*fmt == 'h') { - fmt++; - } - /* these are promoted to int, so no break */ - default: - modifier = LM_STD; - break; - } - - /* - * Argument extraction and printing. - * First we determine the argument type. - * Then, we convert the argument to a string. - * On exit from the switch, s points to the string that - * must be printed, s_len has the length of the string - * The precision requirements, if any, are reflected in s_len. - * - * NOTE: pad_char may be set to '0' because of the 0 flag. - * It is reset to ' ' by non-numeric formats - */ - switch (*fmt) { - case 'u': - switch(modifier) { - default: - i_num = (wide_int) va_arg(ap, unsigned int); - break; - case LM_LONG_DOUBLE: - goto fmt_error; - case LM_LONG: - i_num = (wide_int) va_arg(ap, unsigned long int); - break; - case LM_SIZE_T: - i_num = (wide_int) va_arg(ap, size_t); - break; -#if SIZEOF_LONG_LONG - case LM_LONG_LONG: - i_num = (wide_int) va_arg(ap, u_wide_int); - break; -#endif -#if SIZEOF_INTMAX_T - case LM_INTMAX_T: - i_num = (wide_int) va_arg(ap, uintmax_t); - break; -#endif -#if SIZEOF_PTRDIFF_T - case LM_PTRDIFF_T: - i_num = (wide_int) va_arg(ap, ptrdiff_t); - break; -#endif - } - /* - * The rest also applies to other integer formats, so fall - * into that case. - */ - case 'd': - case 'i': - /* - * Get the arg if we haven't already. - */ - if ((*fmt) != 'u') { - switch(modifier) { - default: - i_num = (wide_int) va_arg(ap, int); - break; - case LM_LONG_DOUBLE: - goto fmt_error; - case LM_LONG: - i_num = (wide_int) va_arg(ap, long int); - break; - case LM_SIZE_T: -#if SIZEOF_SSIZE_T - i_num = (wide_int) va_arg(ap, ssize_t); -#else - i_num = (wide_int) va_arg(ap, size_t); -#endif - break; -#if SIZEOF_LONG_LONG - case LM_LONG_LONG: - i_num = (wide_int) va_arg(ap, wide_int); - break; -#endif -#if SIZEOF_INTMAX_T - case LM_INTMAX_T: - i_num = (wide_int) va_arg(ap, intmax_t); - break; -#endif -#if SIZEOF_PTRDIFF_T - case LM_PTRDIFF_T: - i_num = (wide_int) va_arg(ap, ptrdiff_t); - break; -#endif - } - } - s = ap_php_conv_10(i_num, (*fmt) == 'u', &is_negative, - &num_buf[NUM_BUF_SIZE], &s_len); - FIX_PRECISION(adjust_precision, precision, s, s_len); - - if (*fmt != 'u') { - if (is_negative) - prefix_char = '-'; - else if (print_sign) - prefix_char = '+'; - else if (print_blank) - prefix_char = ' '; - } - break; - - - case 'o': - switch(modifier) { - default: - ui_num = (u_wide_int) va_arg(ap, unsigned int); - break; - case LM_LONG_DOUBLE: - goto fmt_error; - case LM_LONG: - ui_num = (u_wide_int) va_arg(ap, unsigned long int); - break; - case LM_SIZE_T: - ui_num = (u_wide_int) va_arg(ap, size_t); - break; -#if SIZEOF_LONG_LONG - case LM_LONG_LONG: - ui_num = (u_wide_int) va_arg(ap, u_wide_int); - break; -#endif -#if SIZEOF_INTMAX_T - case LM_INTMAX_T: - ui_num = (u_wide_int) va_arg(ap, uintmax_t); - break; -#endif -#if SIZEOF_PTRDIFF_T - case LM_PTRDIFF_T: - ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); - break; -#endif - } - 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'; - s_len++; - } - break; - - - case 'x': - case 'X': - switch(modifier) { - default: - ui_num = (u_wide_int) va_arg(ap, unsigned int); - break; - case LM_LONG_DOUBLE: - goto fmt_error; - case LM_LONG: - ui_num = (u_wide_int) va_arg(ap, unsigned long int); - break; - case LM_SIZE_T: - ui_num = (u_wide_int) va_arg(ap, size_t); - break; -#if SIZEOF_LONG_LONG - case LM_LONG_LONG: - ui_num = (u_wide_int) va_arg(ap, u_wide_int); - break; -#endif -#if SIZEOF_INTMAX_T - case LM_INTMAX_T: - ui_num = (u_wide_int) va_arg(ap, uintmax_t); - break; -#endif -#if SIZEOF_PTRDIFF_T - case LM_PTRDIFF_T: - ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); - break; -#endif - } - 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' */ - *--s = '0'; - s_len += 2; - } - break; - - - case 's': - s = va_arg(ap, char *); - if (s != NULL) { - s_len = strlen(s); - if (adjust_precision && precision < s_len) - s_len = precision; - } else { - s = S_NULL; - s_len = S_NULL_LEN; - } - pad_char = ' '; - break; - - - case 'f': - case 'e': - case 'E': - switch(modifier) { - case LM_LONG_DOUBLE: - fp_num = (double) va_arg(ap, long double); - break; - case LM_STD: - fp_num = va_arg(ap, double); - break; - default: - goto fmt_error; - } - - if (zend_isnan(fp_num)) { - s = "nan"; - s_len = 3; - } else if (zend_isinf(fp_num)) { - s = "inf"; - s_len = 3; - } else { - s = ap_php_conv_fp(*fmt, fp_num, alternate_form, - (adjust_precision == NO) ? FLOAT_DIGITS : precision, - &is_negative, &num_buf[1], &s_len); - if (is_negative) - prefix_char = '-'; - else if (print_sign) - prefix_char = '+'; - else if (print_blank) - prefix_char = ' '; - } - break; - - - case 'g': - case 'G': - switch(modifier) { - case LM_LONG_DOUBLE: - fp_num = (double) va_arg(ap, long double); - break; - case LM_STD: - fp_num = va_arg(ap, double); - break; - default: - goto fmt_error; - } - - if (zend_isnan(fp_num)) { - s = "NAN"; - s_len = 3; - break; - } else if (zend_isinf(fp_num)) { - if (fp_num > 0) { - s = "INF"; - s_len = 3; - } else { - s = "-INF"; - s_len = 4; - } - break; - } - - if (adjust_precision == NO) - precision = FLOAT_DIGITS; - 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 == '-') - prefix_char = *s++; - else if (print_sign) - prefix_char = '+'; - else if (print_blank) - prefix_char = ' '; - - s_len = strlen(s); - - if (alternate_form && (q = strchr(s, '.')) == NULL) - s[s_len++] = '.'; - if (*fmt == 'G' && (q = strchr(s, 'e')) != NULL) - *q = 'E'; - break; - - - case 'c': - char_buf[0] = (char) (va_arg(ap, int)); - s = &char_buf[0]; - s_len = 1; - pad_char = ' '; - break; - - - case '%': - char_buf[0] = '%'; - s = &char_buf[0]; - s_len = 1; - pad_char = ' '; - break; - - - case 'n': - *(va_arg(ap, int *)) = cc; - break; - - /* - * Always extract the argument as a "char *" pointer. We - * should be using "void *" but there are still machines - * that don't understand it. - * If the pointer size is equal to the size of an unsigned - * integer we convert the pointer to a hex number, otherwise - * we print "%p" to indicate that we don't handle "%p". - */ - case 'p': - if (sizeof(char *) <= sizeof(u_wide_int)) { - ui_num = (u_wide_int)((size_t) va_arg(ap, char *)); - s = ap_php_conv_p2(ui_num, 4, 'x', - &num_buf[NUM_BUF_SIZE], &s_len); - if (i_num != 0) { - *--s = 'x'; - *--s = '0'; - s_len += 2; - } - } else { - s = "%p"; - s_len = 2; - } - pad_char = ' '; - break; - - - case NUL: - /* - * The last character of the format string was %. - * We ignore it. - */ - continue; - - -fmt_error: - php_error(E_ERROR, "Illegal length modifier specified '%c' in s[np]printf call", *fmt); - /* - * The default case is for unrecognized %'s. - * We print %<char> to help the user identify what - * option is not understood. - * This is also useful in case the user wants to pass - * the output of format_converter to another function - * that understands some other %<char> (like syslog). - * Note that we can't point s inside fmt because the - * unknown <char> could be preceded by width etc. - */ - default: - char_buf[0] = '%'; - char_buf[1] = *fmt; - s = char_buf; - s_len = 2; - pad_char = ' '; - break; - } - - if (prefix_char != NUL) { - *--s = prefix_char; - s_len++; - } - if (adjust_width && adjust == RIGHT && min_width > s_len) { - if (pad_char == '0' && prefix_char != NUL) { - INS_CHAR(*s, sp, bep, cc) - s++; - s_len--; - min_width--; - } - PAD(min_width, s_len, pad_char); - } - /* - * Print the string s. - */ - for (i = s_len; i != 0; i--) { - INS_CHAR(*s, sp, bep, cc); - s++; - } - - if (adjust_width && adjust == LEFT && min_width > s_len) - PAD(min_width, s_len, pad_char); - } - fmt++; - } - 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) -{ - buffy od; - int cc; - - /* - * First initialize the descriptor - * Notice that if no length is given, we initialize buf_end to the - * highest possible address. - */ - if (len == 0) { - od.buf_end = (char *) ~0; - od.nextb = (char *) ~0; - } else { - od.buf_end = &buf[len-1]; - od.nextb = buf; - } - - /* - * Do the conversion - */ - cc = format_converter(&od, format, ap); - if (len != 0 && od.nextb <= od.buf_end) - *(od.nextb) = '\0'; - if (ccp) - *ccp = cc; -} - - -int ap_php_snprintf(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); - return (cc); -} - - -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); -} - -#endif /* HAVE_SNPRINTF */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/snprintf.h b/main/snprintf.h deleted file mode 100644 index 76b7b6a6ca..0000000000 --- a/main/snprintf.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Stig Sæther Bakken <ssb@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* - -Comparing: sprintf, snprintf, 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 - results in possible entries for buffer overrun attacks. So please - use this version only if you are sure the call is safe. sprintf - allways terminstes the buffer it writes to. - -snprintf knows the buffers size and will not write behind it. But you will - have to use either a static buffer or allocate a dynamic buffer - before beeing able to call the function. In other words you must - be sure that you really know the maximum size of the buffer required. - 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. - -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 - off by setting max_len to 0). spprintf is a little bit slower than - snprintf and offers possible memory leakes if you miss freeing the - buffer allocated by the function. Therfore this function should be - used where either no maximum is known or the maximum is much bigger - than normal size required. spprintf allways terminates the buffer. - -Example: - - #define MAX 1024 | #define MAX 1024 | #define MAX 1024 - char buffer[MAX] | char buffer[MAX] | char *buffer; - | | - | | // No need to initialize buffer: - | | // spprintf ignores value of buffer - sprintf(buffer, "test"); | snprintf(buffer, MAX, "test"); | spprintf(&buffer, MAX, "text"); - | | if (!buffer) - | | return OUT_OF_MEMORY - // sprintf allways terminates | // manual termination of | // spprintf allays terminates buffer - // buffer | // buffer *IS* required | - | buffer[MAX-1] = 0; | - action_with_buffer(buffer); | action_with_buffer(buffer); | action_with_buffer(buffer); - | | efree(buffer); -*/ - -#ifndef SNPRINTF_H -#define SNPRINTF_H - -#if !defined(HAVE_SNPRINTF) || PHP_BROKEN_SNPRINTF -int ap_php_snprintf(char *, size_t, const char *, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4); -#define snprintf ap_php_snprintf -#endif - -#if !defined(HAVE_VSNPRINTF) || PHP_BROKEN_VSNPRINTF -int ap_php_vsnprintf(char *, size_t, const char *, va_list ap) PHP_ATTRIBUTE_FORMAT(printf, 3, 0); -#define vsnprintf ap_php_vsnprintf -#endif - -#if PHP_BROKEN_SPRINTF -int php_sprintf (char* s, const char* format, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3); -#define sprintf php_sprintf -#endif - -typedef enum { - NO = 0, YES = 1 -} boolean_e; - -typedef enum { - LM_STD = 0, -#if SIZEOF_INTMAX_T - LM_INTMAX_T, -#endif -#if SIZEOF_PTRDIFF_T - LM_PTRDIFF_T, -#endif -#if SIZEOF_LONG_LONG - LM_LONG_LONG, -#endif - LM_SIZE_T, - LM_LONG, - 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); - -#if SIZEOF_LONG_LONG_INT -# define WIDE_INT long long int -#elif SIZEOF_LONG_LONG -# define WIDE_INT long long -#elif _WIN64 -# define WIDE_INT __int64 -#else -# define WIDE_INT long -#endif -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 */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/main/spprintf.c b/main/spprintf.c deleted file mode 100644 index 27336f7cf5..0000000000 --- a/main/spprintf.c +++ /dev/null @@ -1,756 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* This is the spprintf implementation. - * It has emerged from apache snprintf. See original header: - */ - -/* ==================================================================== - * Copyright (c) 1995-1998 The Apache Group. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the Apache Group - * for use in the Apache HTTP server project (http://www.apache.org/)." - * - * 4. The names "Apache Server" and "Apache Group" must not be used to - * endorse or promote products derived from this software without - * prior written permission. - * - * 5. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the Apache Group - * for use in the Apache HTTP server project (http://www.apache.org/)." - * - * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Group and was originally based - * on public domain software written at the National Center for - * Supercomputing Applications, University of Illinois, Urbana-Champaign. - * For more information on the Apache Group and the Apache HTTP server - * project, please see <http://www.apache.org/>. - * - * This code is based on, and used with the permission of, the - * 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 - -#include "snprintf.h" - -#define FALSE 0 -#define TRUE 1 -#define NUL '\0' -#define INT_NULL ((int *)0) - -#define S_NULL "(null)" -#define S_NULL_LEN 6 - -#define FLOAT_DIGITS 6 -#define EXPONENT_LENGTH 10 - -#include "ext/standard/php_smart_str.h" - -/* - * NUM_BUF_SIZE is the size of the buffer used for arithmetic conversions - * - * XXX: this is a magic number; do not decrease it - */ -#define NUM_BUF_SIZE 512 - -/* - * The INS_CHAR macro inserts a character in the buffer. - * - * NOTE: Evaluation of the ch argument should not have any side-effects - */ -#define INS_CHAR_NR(xbuf, ch) do { \ - smart_str_appendc(xbuf, ch); \ -} while (0) - -#define INS_STRING(xbuf, s, slen) do { \ - smart_str_appendl(xbuf, s, slen); \ -} while (0) - -#define INS_CHAR(xbuf, ch) \ - INS_CHAR_NR(xbuf, ch) - -/* - * Macro that does padding. The padding is done by printing - * the character ch. - */ -#define PAD(xbuf, count, ch) do { \ - if ((count) > 0) { \ - size_t newlen; \ - smart_str_alloc(xbuf, (count), 0); \ - memset(xbuf->c + xbuf->len, ch, (count)); \ - xbuf->len += (count); \ - } \ -} while (0) - -#define NUM(c) (c - '0') - -#define STR_TO_DEC(str, num) do { \ - num = NUM(*str++); \ - while (isdigit((int)*str)) { \ - num *= 10; \ - num += NUM(*str++); \ - if (num >= LONG_MAX / 10) { \ - while (isdigit((int)*str++)); \ - break; \ - } \ - } \ -} while (0) - -/* - * This macro does zero padding so that the precision - * requirement is satisfied. The padding is done by - * adding '0's to the left of the string that is going - * to be printed. - */ -#define FIX_PRECISION(adjust, precision, s, s_len) do { \ - if (adjust) \ - while (s_len < precision) { \ - *--s = '0'; \ - s_len++; \ - } \ -} while (0) - - - -/* - * Do format conversion placing the output in buffer - */ -static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) -{ - register char *s = NULL; - char *q; - int s_len; - - register int min_width = 0; - int precision = 0; - enum { - LEFT, RIGHT - } adjust; - char pad_char; - char prefix_char; - - double fp_num; - wide_int i_num = (wide_int) 0; - u_wide_int ui_num; - - char num_buf[NUM_BUF_SIZE]; - char char_buf[2]; /* for printing %% and %<unknown> */ - - /* - * Flag variables - */ - length_modifier_e modifier; - boolean_e alternate_form; - boolean_e print_sign; - boolean_e print_blank; - boolean_e adjust_precision; - boolean_e adjust_width; - bool_int is_negative; - - while (*fmt) { - if (*fmt != '%') { - INS_CHAR(xbuf, *fmt); - } else { - /* - * Default variable settings - */ - adjust = RIGHT; - alternate_form = print_sign = print_blank = NO; - pad_char = ' '; - prefix_char = NUL; - - fmt++; - - /* - * Try to avoid checking for flags, width or precision - */ - if (isascii((int)*fmt) && !islower((int)*fmt)) { - /* - * Recognize flags: -, #, BLANK, + - */ - for (;; fmt++) { - if (*fmt == '-') - adjust = LEFT; - else if (*fmt == '+') - print_sign = YES; - else if (*fmt == '#') - alternate_form = YES; - else if (*fmt == ' ') - print_blank = YES; - else if (*fmt == '0') - pad_char = '0'; - else - break; - } - - /* - * Check if a width was specified - */ - if (isdigit((int)*fmt)) { - STR_TO_DEC(fmt, min_width); - adjust_width = YES; - } else if (*fmt == '*') { - min_width = va_arg(ap, int); - fmt++; - adjust_width = YES; - if (min_width < 0) { - adjust = LEFT; - min_width = -min_width; - } - } else - adjust_width = NO; - - /* - * Check if a precision was specified - * - * XXX: an unreasonable amount of precision may be specified - * resulting in overflow of num_buf. Currently we - * ignore this possibility. - */ - if (*fmt == '.') { - adjust_precision = YES; - fmt++; - if (isdigit((int)*fmt)) { - STR_TO_DEC(fmt, precision); - } else if (*fmt == '*') { - precision = va_arg(ap, int); - fmt++; - if (precision < 0) - precision = 0; - } else - precision = 0; - } else - adjust_precision = NO; - } else - adjust_precision = adjust_width = NO; - - /* - * Modifier check - */ - switch (*fmt) { - case 'L': - fmt++; - modifier = LM_LONG_DOUBLE; - break; - case 'l': - fmt++; -#if SIZEOF_LONG_LONG - if (*fmt == 'l') { - fmt++; - modifier = LM_LONG_LONG; - } else -#endif - modifier = LM_LONG; - break; - case 'z': - fmt++; - modifier = LM_SIZE_T; - break; - case 'j': - fmt++; -#if SIZEOF_INTMAX_T - modifier = LM_INTMAX_T; -#else - modifier = LM_SIZE_T; -#endif - break; - case 't': - fmt++; -#if SIZEOF_PTRDIFF_T - modifier = LM_PTRDIFF_T; -#else - modifier = LM_SIZE_T; -#endif - break; - case 'h': - fmt++; - if (*fmt == 'h') { - fmt++; - } - /* these are promoted to int, so no break */ - default: - modifier = LM_STD; - break; - } - - /* - * Argument extraction and printing. - * First we determine the argument type. - * Then, we convert the argument to a string. - * On exit from the switch, s points to the string that - * must be printed, s_len has the length of the string - * The precision requirements, if any, are reflected in s_len. - * - * NOTE: pad_char may be set to '0' because of the 0 flag. - * It is reset to ' ' by non-numeric formats - */ - switch (*fmt) { - case 'u': - switch(modifier) { - default: - i_num = (wide_int) va_arg(ap, unsigned int); - break; - case LM_LONG_DOUBLE: - goto fmt_error; - case LM_LONG: - i_num = (wide_int) va_arg(ap, unsigned long int); - break; - case LM_SIZE_T: - i_num = (wide_int) va_arg(ap, size_t); - break; -#if SIZEOF_LONG_LONG - case LM_LONG_LONG: - i_num = (wide_int) va_arg(ap, u_wide_int); - break; -#endif -#if SIZEOF_INTMAX_T - case LM_INTMAX_T: - i_num = (wide_int) va_arg(ap, uintmax_t); - break; -#endif -#if SIZEOF_PTRDIFF_T - case LM_PTRDIFF_T: - i_num = (wide_int) va_arg(ap, ptrdiff_t); - break; -#endif - } - /* - * The rest also applies to other integer formats, so fall - * into that case. - */ - case 'd': - case 'i': - /* - * Get the arg if we haven't already. - */ - if ((*fmt) != 'u') { - switch(modifier) { - default: - i_num = (wide_int) va_arg(ap, int); - break; - case LM_LONG_DOUBLE: - goto fmt_error; - case LM_LONG: - i_num = (wide_int) va_arg(ap, long int); - break; - case LM_SIZE_T: -#if SIZEOF_SSIZE_T - i_num = (wide_int) va_arg(ap, ssize_t); -#else - i_num = (wide_int) va_arg(ap, size_t); -#endif - break; -#if SIZEOF_LONG_LONG - case LM_LONG_LONG: - i_num = (wide_int) va_arg(ap, wide_int); - break; -#endif -#if SIZEOF_INTMAX_T - case LM_INTMAX_T: - i_num = (wide_int) va_arg(ap, intmax_t); - break; -#endif -#if SIZEOF_PTRDIFF_T - case LM_PTRDIFF_T: - i_num = (wide_int) va_arg(ap, ptrdiff_t); - break; -#endif - } - } - s = ap_php_conv_10(i_num, (*fmt) == 'u', &is_negative, - &num_buf[NUM_BUF_SIZE], &s_len); - FIX_PRECISION(adjust_precision, precision, s, s_len); - - if (*fmt != 'u') { - if (is_negative) - prefix_char = '-'; - else if (print_sign) - prefix_char = '+'; - else if (print_blank) - prefix_char = ' '; - } - break; - - - case 'o': - switch(modifier) { - default: - ui_num = (u_wide_int) va_arg(ap, unsigned int); - break; - case LM_LONG_DOUBLE: - goto fmt_error; - case LM_LONG: - ui_num = (u_wide_int) va_arg(ap, unsigned long int); - break; - case LM_SIZE_T: - ui_num = (u_wide_int) va_arg(ap, size_t); - break; -#if SIZEOF_LONG_LONG - case LM_LONG_LONG: - ui_num = (u_wide_int) va_arg(ap, u_wide_int); - break; -#endif -#if SIZEOF_INTMAX_T - case LM_INTMAX_T: - ui_num = (u_wide_int) va_arg(ap, uintmax_t); - break; -#endif -#if SIZEOF_PTRDIFF_T - case LM_PTRDIFF_T: - ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); - break; -#endif - } - 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'; - s_len++; - } - break; - - - case 'x': - case 'X': - switch(modifier) { - default: - ui_num = (u_wide_int) va_arg(ap, unsigned int); - break; - case LM_LONG_DOUBLE: - goto fmt_error; - case LM_LONG: - ui_num = (u_wide_int) va_arg(ap, unsigned long int); - break; - case LM_SIZE_T: - ui_num = (u_wide_int) va_arg(ap, size_t); - break; -#if SIZEOF_LONG_LONG - case LM_LONG_LONG: - ui_num = (u_wide_int) va_arg(ap, u_wide_int); - break; -#endif -#if SIZEOF_INTMAX_T - case LM_INTMAX_T: - ui_num = (u_wide_int) va_arg(ap, uintmax_t); - break; -#endif -#if SIZEOF_PTRDIFF_T - case LM_PTRDIFF_T: - ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); - break; -#endif - } - 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' */ - *--s = '0'; - s_len += 2; - } - break; - - - case 's': - s = va_arg(ap, char *); - if (s != NULL) { - s_len = strlen(s); - if (adjust_precision && precision < s_len) - s_len = precision; - } else { - s = S_NULL; - s_len = S_NULL_LEN; - } - pad_char = ' '; - break; - - - case 'f': - case 'e': - case 'E': - switch(modifier) { - case LM_LONG_DOUBLE: - fp_num = (double) va_arg(ap, long double); - break; - case LM_STD: - fp_num = va_arg(ap, double); - break; - default: - goto fmt_error; - } - - if (zend_isnan(fp_num)) { - s = "nan"; - s_len = 3; - } else if (zend_isinf(fp_num)) { - s = "inf"; - s_len = 3; - } else { - s = ap_php_conv_fp(*fmt, fp_num, alternate_form, - (adjust_precision == NO) ? FLOAT_DIGITS : precision, - &is_negative, &num_buf[1], &s_len); - if (is_negative) - prefix_char = '-'; - else if (print_sign) - prefix_char = '+'; - else if (print_blank) - prefix_char = ' '; - } - break; - - - case 'g': - case 'G': - switch(modifier) { - case LM_LONG_DOUBLE: - fp_num = (double) va_arg(ap, long double); - break; - case LM_STD: - fp_num = va_arg(ap, double); - break; - default: - goto fmt_error; - } - - if (zend_isnan(fp_num)) { - s = "NAN"; - s_len = 3; - break; - } else if (zend_isinf(fp_num)) { - if (fp_num > 0) { - s = "INF"; - s_len = 3; - } else { - s = "-INF"; - s_len = 4; - } - break; - } - - if (adjust_precision == NO) - precision = FLOAT_DIGITS; - 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 == '-') - prefix_char = *s++; - else if (print_sign) - prefix_char = '+'; - else if (print_blank) - prefix_char = ' '; - - s_len = strlen(s); - - if (alternate_form && (q = strchr(s, '.')) == NULL) - s[s_len++] = '.'; - if (*fmt == 'G' && (q = strchr(s, 'e')) != NULL) - *q = 'E'; - break; - - - case 'c': - char_buf[0] = (char) (va_arg(ap, int)); - s = &char_buf[0]; - s_len = 1; - pad_char = ' '; - break; - - - case '%': - char_buf[0] = '%'; - s = &char_buf[0]; - s_len = 1; - pad_char = ' '; - break; - - - case 'n': - *(va_arg(ap, int *)) = xbuf->len; - break; - - /* - * Always extract the argument as a "char *" pointer. We - * should be using "void *" but there are still machines - * that don't understand it. - * If the pointer size is equal to the size of an unsigned - * integer we convert the pointer to a hex number, otherwise - * we print "%p" to indicate that we don't handle "%p". - */ - case 'p': - if (sizeof(char *) <= sizeof(u_wide_int)) { - ui_num = (u_wide_int)((size_t) va_arg(ap, char *)); - s = ap_php_conv_p2(ui_num, 4, 'x', - &num_buf[NUM_BUF_SIZE], &s_len); - if (i_num != 0) { - *--s = 'x'; - *--s = '0'; - s_len += 2; - } - } else { - s = "%p"; - s_len = 2; - } - pad_char = ' '; - break; - - - case NUL: - /* - * The last character of the format string was %. - * We ignore it. - */ - continue; - - -fmt_error: - php_error(E_ERROR, "Illegal length modifier specified '%c' in s[np]printf call", *fmt); - /* - * The default case is for unrecognized %'s. - * We print %<char> to help the user identify what - * option is not understood. - * This is also useful in case the user wants to pass - * the output of format_converter to another function - * that understands some other %<char> (like syslog). - * Note that we can't point s inside fmt because the - * unknown <char> could be preceded by width etc. - */ - default: - char_buf[0] = '%'; - char_buf[1] = *fmt; - s = char_buf; - s_len = 2; - pad_char = ' '; - break; - } - - if (prefix_char != NUL) { - *--s = prefix_char; - s_len++; - } - if (adjust_width && adjust == RIGHT && min_width > s_len) { - if (pad_char == '0' && prefix_char != NUL) { - INS_CHAR(xbuf, *s); - s++; - s_len--; - min_width--; - } - PAD(xbuf, min_width - s_len, pad_char); - } - /* - * Print the string s. - */ - INS_STRING(xbuf, s, s_len); - - if (adjust_width && adjust == LEFT && min_width > s_len) - PAD(xbuf, min_width - s_len, pad_char); - } - fmt++; - } - return; -} - - -/* - * This is the general purpose conversion function. - */ -PHPAPI int vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) -{ - smart_str xbuf = {0}; - - xbuf_format_converter(&xbuf, format, ap); - - if (max_len && xbuf.len > max_len) { - xbuf.len = max_len; - } - smart_str_0(&xbuf); - - *pbuf = xbuf.c; - - return xbuf.len; -} - - -PHPAPI int spprintf(char **pbuf, size_t max_len, const char *format, ...) -{ - int cc; - va_list ap; - - va_start(ap, format); - cc = vspprintf(pbuf, max_len, format, ap); - va_end(ap); - return (cc); -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/spprintf.h b/main/spprintf.h deleted file mode 100644 index 467294c216..0000000000 --- a/main/spprintf.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* - -The pbuf parameter of all spprintf version receives a pointer to the allocated -buffer. This buffer must be freed manually after usage using efree() function. -The buffer will allways be terminated by a zero character. When pbuf is NULL -the function can be used to calculate the required size of the buffer but for -that purpose snprintf is faster. When both pbuf and the return value are 0 -than you are out of memory. - -There is also snprintf: See difference explained in snprintf.h - -*/ - -#ifndef SPPRINTF_H -#define SPPRINTF_H - -#include "snprintf.h" - -BEGIN_EXTERN_C() -PHPAPI int spprintf( char **pbuf, size_t max_len, const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4); - -PHPAPI int vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) PHP_ATTRIBUTE_FORMAT(printf, 3, 0); -END_EXTERN_C() - -#endif /* SNPRINTF_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/main/streams/cast.c b/main/streams/cast.c deleted file mode 100644 index 1a1d99101c..0000000000 --- a/main/streams/cast.c +++ /dev/null @@ -1,350 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#define _GNU_SOURCE -#include "php.h" -#include "php_globals.h" -#include "php_network.h" -#include "php_open_temporary_file.h" -#include "ext/standard/file.h" -#include <stddef.h> -#include <fcntl.h> - -#include "php_streams_int.h" - -/* Under BSD, emulate fopencookie using funopen */ -#if HAVE_FUNOPEN -typedef struct { - int (*reader)(void *, char *, int); - int (*writer)(void *, const char *, int); - fpos_t (*seeker)(void *, fpos_t, int); - int (*closer)(void *); -} COOKIE_IO_FUNCTIONS_T; - -FILE *fopencookie(void *cookie, const char *mode, COOKIE_IO_FUNCTIONS_T *funcs) -{ - return funopen(cookie, funcs->reader, funcs->writer, funcs->seeker, funcs->closer); -} -# define HAVE_FOPENCOOKIE 1 -# define PHP_STREAM_COOKIE_FUNCTIONS &stream_cookie_functions -#elif HAVE_FOPENCOOKIE -# define PHP_STREAM_COOKIE_FUNCTIONS stream_cookie_functions -#endif - -/* {{{ STDIO with fopencookie */ -#if HAVE_FUNOPEN -/* use our fopencookie emulation */ -static int stream_cookie_reader(void *cookie, char *buffer, int size) -{ - int ret; - TSRMLS_FETCH(); - ret = php_stream_read((php_stream*)cookie, buffer, size); - return ret; -} - -static int stream_cookie_writer(void *cookie, const char *buffer, int size) -{ - TSRMLS_FETCH(); - return php_stream_write((php_stream *)cookie, (char *)buffer, size); -} - -static fpos_t stream_cookie_seeker(void *cookie, off_t position, int whence) -{ - TSRMLS_FETCH(); - return (fpos_t)php_stream_seek((php_stream *)cookie, position, whence); -} - -static int stream_cookie_closer(void *cookie) -{ - php_stream *stream = (php_stream*)cookie; - TSRMLS_FETCH(); - - /* prevent recursion */ - stream->fclose_stdiocast = PHP_STREAM_FCLOSE_NONE; - return php_stream_close(stream); -} - -#elif HAVE_FOPENCOOKIE -static ssize_t stream_cookie_reader(void *cookie, char *buffer, size_t size) -{ - ssize_t ret; - TSRMLS_FETCH(); - ret = php_stream_read(((php_stream *)cookie), buffer, size); - return ret; -} - -static ssize_t stream_cookie_writer(void *cookie, const char *buffer, size_t size) -{ - TSRMLS_FETCH(); - return php_stream_write(((php_stream *)cookie), (char *)buffer, size); -} - -#ifdef COOKIE_SEEKER_USES_OFF64_T -static int stream_cookie_seeker(void *cookie, __off64_t *position, int whence) -{ - TSRMLS_FETCH(); - - *position = php_stream_seek((php_stream *)cookie, (off_t)*position, whence); - - if (*position == -1) - return -1; - return 0; -} -#else -static int stream_cookie_seeker(void *cookie, off_t position, int whence) -{ - TSRMLS_FETCH(); - return php_stream_seek((php_stream *)cookie, position, whence); -} -#endif - -static int stream_cookie_closer(void *cookie) -{ - php_stream *stream = (php_stream*)cookie; - TSRMLS_FETCH(); - - /* prevent recursion */ - stream->fclose_stdiocast = PHP_STREAM_FCLOSE_NONE; - return php_stream_close(stream); -} -#endif /* elif HAVE_FOPENCOOKIE */ - -#if HAVE_FOPENCOOKIE -static COOKIE_IO_FUNCTIONS_T stream_cookie_functions = -{ - stream_cookie_reader, stream_cookie_writer, - stream_cookie_seeker, stream_cookie_closer -}; -#else -/* TODO: use socketpair() to emulate fopencookie, as suggested by Hartmut ? */ -#endif -/* }}} */ - -/* {{{ php_stream_cast */ -PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show_err TSRMLS_DC) -{ - int flags = castas & PHP_STREAM_CAST_MASK; - castas &= ~PHP_STREAM_CAST_MASK; - - /* synchronize our buffer (if possible) */ - if (ret && castas != PHP_STREAM_AS_FD_FOR_SELECT) { - php_stream_flush(stream); - if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) { - off_t dummy; - - stream->ops->seek(stream, stream->position, SEEK_SET, &dummy TSRMLS_CC); - stream->readpos = stream->writepos = 0; - } - } - - /* filtered streams can only be cast as stdio, and only when fopencookie is present */ - - if (castas == PHP_STREAM_AS_STDIO) { - if (stream->stdiocast) { - if (ret) { - *(FILE**)ret = stream->stdiocast; - } - goto exit_success; - } - - /* if the stream is a stdio stream let's give it a chance to respond - * first, to avoid doubling up the layers of stdio with an fopencookie */ - if (php_stream_is(stream, PHP_STREAM_IS_STDIO) && - stream->ops->cast && - !php_stream_is_filtered(stream) && - stream->ops->cast(stream, castas, ret TSRMLS_CC) == SUCCESS) - { - goto exit_success; - } - -#if HAVE_FOPENCOOKIE - /* if just checking, say yes we can be a FILE*, but don't actually create it yet */ - if (ret == NULL) - goto exit_success; - - *(FILE**)ret = fopencookie(stream, stream->mode, PHP_STREAM_COOKIE_FUNCTIONS); - - if (*ret != NULL) { - off_t pos; - - stream->fclose_stdiocast = PHP_STREAM_FCLOSE_FOPENCOOKIE; - - /* If the stream position is not at the start, we need to force - * the stdio layer to believe it's real location. */ - pos = php_stream_tell(stream); - if (pos > 0) - fseek(*ret, pos, SEEK_SET); - - goto exit_success; - } - - /* must be either: - a) programmer error - b) no memory - -> lets bail - */ - php_error_docref(NULL TSRMLS_CC, E_ERROR, "fopencookie failed"); - return FAILURE; -#endif - - if (!php_stream_is_filtered(stream) && stream->ops->cast && stream->ops->cast(stream, castas, NULL TSRMLS_CC) == SUCCESS) { - if (FAILURE == stream->ops->cast(stream, castas, ret TSRMLS_CC)) { - return FAILURE; - } - goto exit_success; - } else if (flags & PHP_STREAM_CAST_TRY_HARD) { - php_stream *newstream; - - newstream = php_stream_fopen_tmpfile(); - if (newstream) { - size_t copied = php_stream_copy_to_stream(stream, newstream, PHP_STREAM_COPY_ALL); - - if (copied == 0) { - php_stream_close(newstream); - } else { - int retcode = php_stream_cast(newstream, castas | flags, ret, show_err); - - if (retcode == SUCCESS) - rewind(*(FILE**)ret); - - /* do some specialized cleanup */ - if ((flags & PHP_STREAM_CAST_RELEASE)) { - php_stream_free(stream, PHP_STREAM_FREE_CLOSE_CASTED); - } - - return retcode; - } - } - } - } - - if (php_stream_is_filtered(stream)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot cast a filtered stream on this system"); - return FAILURE; - } else if (stream->ops->cast && stream->ops->cast(stream, castas, ret TSRMLS_CC) == SUCCESS) { - goto exit_success; - } - - if (show_err) { - /* these names depend on the values of the PHP_STREAM_AS_XXX defines in php_streams.h */ - static const char *cast_names[4] = { - "STDIO FILE*", "File Descriptor", "Socket Descriptor", "select()able descriptor" - }; - - php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot represent a stream of type %s as a %s", - stream->ops->label, - cast_names[castas] - ); - } - - return FAILURE; - -exit_success: - - if ((stream->writepos - stream->readpos) > 0 && - stream->fclose_stdiocast != PHP_STREAM_FCLOSE_FOPENCOOKIE && - (flags & PHP_STREAM_CAST_INTERNAL) == 0) { - /* the data we have buffered will be lost to the third party library that - * will be accessing the stream. Emit a warning so that the end-user will - * know that they should try something else */ - - php_error_docref(NULL TSRMLS_CC, E_WARNING, - "%ld bytes of buffered data lost during stream conversion!", - stream->writepos - stream->readpos); - } - - if (castas == PHP_STREAM_AS_STDIO && ret) - stream->stdiocast = *(FILE**)ret; - - if (flags & PHP_STREAM_CAST_RELEASE) { - php_stream_free(stream, PHP_STREAM_FREE_CLOSE_CASTED); - } - - return SUCCESS; - -} -/* }}} */ - -/* {{{ php_stream_open_wrapper_as_file */ -PHPAPI FILE * _php_stream_open_wrapper_as_file(char *path, char *mode, int options, char **opened_path STREAMS_DC TSRMLS_DC) -{ - FILE *fp = NULL; - php_stream *stream = NULL; - - stream = php_stream_open_wrapper_rel(path, mode, options|STREAM_WILL_CAST, opened_path); - - if (stream == NULL) - return NULL; - - if (php_stream_cast(stream, PHP_STREAM_AS_STDIO|PHP_STREAM_CAST_TRY_HARD|PHP_STREAM_CAST_RELEASE, - (void**)&fp, REPORT_ERRORS) == FAILURE) - { - php_stream_close(stream); - if (opened_path && *opened_path) - efree(*opened_path); - return NULL; - } - return fp; -} -/* }}} */ - -/* {{{ php_stream_make_seekable */ -PHPAPI int _php_stream_make_seekable(php_stream *origstream, php_stream **newstream, int flags STREAMS_DC TSRMLS_DC) -{ - assert(newstream != NULL); - - *newstream = NULL; - - if (((flags & PHP_STREAM_FORCE_CONVERSION) == 0) && origstream->ops->seek != NULL) { - *newstream = origstream; - return PHP_STREAM_UNCHANGED; - } - - /* Use a tmpfile and copy the old streams contents into it */ - - if (flags & PHP_STREAM_PREFER_STDIO) - *newstream = php_stream_fopen_tmpfile(); - else - *newstream = php_stream_temp_new(); - - if (*newstream == NULL) - return PHP_STREAM_FAILED; - - if (php_stream_copy_to_stream(origstream, *newstream, PHP_STREAM_COPY_ALL) == 0) { - php_stream_close(*newstream); - *newstream = NULL; - return PHP_STREAM_CRITICAL; - } - - php_stream_close(origstream); - php_stream_seek(*newstream, 0, SEEK_SET); - - return PHP_STREAM_RELEASED; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/main/streams/filter.c b/main/streams/filter.c deleted file mode 100644 index ff0549972c..0000000000 --- a/main/streams/filter.c +++ /dev/null @@ -1,339 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" -#include "php_globals.h" -#include "php_network.h" -#include "php_open_temporary_file.h" -#include "ext/standard/file.h" -#include <stddef.h> -#include <fcntl.h> - -#include "php_streams_int.h" - -static HashTable stream_filters_hash; - -PHPAPI HashTable *php_get_stream_filters_hash() -{ - return &stream_filters_hash; -} - -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); -} - -PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern TSRMLS_DC) -{ - return zend_hash_del(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern)); -} - -/* Buckets */ - -PHPAPI php_stream_bucket *php_stream_bucket_new(php_stream *stream, char *buf, size_t buflen, int own_buf, int buf_persistent TSRMLS_DC) -{ - int is_persistent = php_stream_is_persistent(stream); - php_stream_bucket *bucket; - - bucket = (php_stream_bucket*)pemalloc(sizeof(php_stream_bucket), is_persistent); - - if (bucket == NULL) { - return NULL; - } - - bucket->next = bucket->prev = NULL; - - if (is_persistent && !buf_persistent) { - /* all data in a persistent bucket must also be persistent */ - bucket->buf = pemalloc(buflen, 1); - - if (bucket->buf == NULL) { - pefree(bucket, 1); - return NULL; - } - - memcpy(bucket->buf, buf, buflen); - bucket->buflen = buflen; - bucket->own_buf = 1; - } else { - bucket->buf = buf; - bucket->buflen = buflen; - bucket->own_buf = own_buf; - } - bucket->is_persistent = is_persistent; - bucket->refcount = 1; - - return bucket; -} - -/* Given a bucket, returns a version of that bucket with a writeable buffer. - * If the original bucket has a refcount of 1 and owns its buffer, then it - * is returned unchanged. - * Otherwise, a copy of the buffer is made. - * In both cases, the original bucket is unlinked from its brigade. - * If a copy is made, the original bucket is delref'd. - * */ -PHPAPI php_stream_bucket *php_stream_bucket_make_writeable(php_stream_bucket *bucket TSRMLS_DC) -{ - php_stream_bucket *retval; - - php_stream_bucket_unlink(bucket TSRMLS_CC); - - if (bucket->refcount == 1 && bucket->own_buf) { - return bucket; - } - - retval = (php_stream_bucket*)pemalloc(sizeof(php_stream_bucket), bucket->is_persistent); - memcpy(retval, bucket, sizeof(*retval)); - - retval->buf = pemalloc(retval->buflen, retval->is_persistent); - memcpy(retval->buf, bucket->buf, retval->buflen); - - retval->refcount = 1; - retval->own_buf = 1; - - php_stream_bucket_delref(bucket TSRMLS_CC); - - return retval; -} - -PHPAPI int php_stream_bucket_split(php_stream_bucket *in, php_stream_bucket **left, php_stream_bucket **right, size_t length TSRMLS_DC) -{ - *left = (php_stream_bucket*)pecalloc(1, sizeof(php_stream_bucket), in->is_persistent); - *right = (php_stream_bucket*)pecalloc(1, sizeof(php_stream_bucket), in->is_persistent); - - if (*left == NULL || *right == NULL) { - goto exit_fail; - } - - (*left)->buf = pemalloc(length, in->is_persistent); - (*left)->buflen = length; - memcpy((*left)->buf, in->buf, length); - (*left)->refcount = 1; - (*left)->own_buf = 1; - (*left)->is_persistent = in->is_persistent; - - (*right)->buflen = in->buflen - length; - (*right)->buf = pemalloc((*right)->buflen, in->is_persistent); - memcpy((*right)->buf, in->buf + length, (*right)->buflen); - (*right)->refcount = 1; - (*right)->own_buf = 1; - (*right)->is_persistent = in->is_persistent; - - return SUCCESS; - -exit_fail: - if (*right) { - if ((*right)->buf) { - pefree((*right)->buf, in->is_persistent); - } - pefree(*right, in->is_persistent); - } - if (*left) { - if ((*left)->buf) { - pefree((*left)->buf, in->is_persistent); - } - pefree(*left, in->is_persistent); - } - return FAILURE; -} - -PHPAPI void php_stream_bucket_delref(php_stream_bucket *bucket TSRMLS_DC) -{ - if (--bucket->refcount == 0) { - if (bucket->own_buf) { - pefree(bucket->buf, bucket->is_persistent); - } - pefree(bucket, bucket->is_persistent); - } -} - -PHPAPI void php_stream_bucket_prepend(php_stream_bucket_brigade *brigade, php_stream_bucket *bucket TSRMLS_DC) -{ - bucket->next = brigade->head; - bucket->prev = NULL; - - if (brigade->head) { - brigade->head->prev = bucket; - } else { - brigade->tail = bucket; - } - brigade->head = bucket; - bucket->brigade = brigade; -} - -PHPAPI void php_stream_bucket_append(php_stream_bucket_brigade *brigade, php_stream_bucket *bucket TSRMLS_DC) -{ - bucket->prev = brigade->tail; - bucket->next = NULL; - - if (brigade->tail) { - brigade->tail->next = bucket; - } else { - brigade->head = bucket; - } - brigade->tail = bucket; - bucket->brigade = brigade; -} - -PHPAPI void php_stream_bucket_unlink(php_stream_bucket *bucket TSRMLS_DC) -{ - if (bucket->prev) { - bucket->prev->next = bucket->next; - } else { - bucket->brigade->head = bucket->next; - } - if (bucket->next) { - bucket->next->prev = bucket->prev; - } else { - bucket->brigade->tail = bucket->prev; - } - bucket->brigade = NULL; - bucket->next = bucket->prev = NULL; -} - - - - - - - - -/* We allow very simple pattern matching for filter factories: - * if "convert.charset.utf-8/sjis" is requested, we search first for an exact - * match. If that fails, we try "convert.charset.*", then "convert.*" - * This means that we don't need to clog up the hashtable with a zillion - * charsets (for example) but still be able to provide them all as filters */ -PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval *filterparams, int persistent TSRMLS_DC) -{ - php_stream_filter_factory *factory; - php_stream_filter *filter = NULL; - int n; - char *period; - - n = strlen(filtername); - - if (SUCCESS == zend_hash_find(&stream_filters_hash, (char*)filtername, n, (void**)&factory)) { - filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC); - } else if ((period = strrchr(filtername, '.'))) { - /* try a wildcard */ - char *wildname; - - wildname = estrdup(filtername); - period = wildname + (period - filtername); - while (period && !filter) { - *period = '\0'; - strcat(wildname, ".*"); - if (SUCCESS == zend_hash_find(&stream_filters_hash, wildname, strlen(wildname), (void**)&factory)) { - filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC); - } - - *period = '\0'; - period = strrchr(wildname, '.'); - } - efree(wildname); - } - - if (filter == NULL) { - /* TODO: these need correct docrefs */ - if (factory == NULL) - php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to locate filter \"%s\"", filtername); - else - php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to create or locate filter \"%s\"", filtername); - } - - return filter; -} - -PHPAPI php_stream_filter *_php_stream_filter_alloc(php_stream_filter_ops *fops, void *abstract, int persistent STREAMS_DC TSRMLS_DC) -{ - php_stream_filter *filter; - - filter = (php_stream_filter*) pemalloc_rel_orig(sizeof(php_stream_filter), persistent); - memset(filter, 0, sizeof(php_stream_filter)); - - filter->fops = fops; - filter->abstract = abstract; - filter->is_persistent = persistent; - - return filter; -} - -PHPAPI void php_stream_filter_free(php_stream_filter *filter TSRMLS_DC) -{ - if (filter->fops->dtor) - filter->fops->dtor(filter TSRMLS_CC); - pefree(filter, filter->is_persistent); -} - -PHPAPI void php_stream_filter_prepend(php_stream_filter_chain *chain, php_stream_filter *filter) -{ - filter->next = chain->head; - filter->prev = NULL; - - if (chain->head) { - chain->head->prev = filter; - } else { - chain->tail = filter; - } - chain->head = filter; - filter->chain = chain; -} - -PHPAPI void php_stream_filter_append(php_stream_filter_chain *chain, php_stream_filter *filter) -{ - filter->prev = chain->tail; - filter->next = NULL; - if (chain->tail) { - chain->tail->next = filter; - } else { - chain->head = filter; - } - chain->tail = filter; - filter->chain = chain; -} - -PHPAPI php_stream_filter *php_stream_filter_remove(php_stream_filter *filter, int call_dtor TSRMLS_DC) -{ - if (filter->prev) { - filter->prev->next = filter->next; - } else { - filter->chain->head = filter->next; - } - if (filter->next) { - filter->next->prev = filter->prev; - } else { - filter->chain->tail = filter->prev; - } - if (call_dtor) { - php_stream_filter_free(filter TSRMLS_CC); - return NULL; - } - return filter; -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/main/streams/memory.c b/main/streams/memory.c deleted file mode 100644 index a61bd6619e..0000000000 --- a/main/streams/memory.c +++ /dev/null @@ -1,473 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#define _GNU_SOURCE -#include "php.h" - -/* Memory streams use a dynamic memory buffer to emulate a stream. - * You can use php_stream_memory_open to create a readonly stream - * from an existing memory buffer. - */ - -/* Temp streams are streams that uses memory streams as long their - * size is less than a given memory amount. When a write operation - * exceeds that limit the content is written to a temporary file. - */ - -/* {{{ ------- MEMORY stream implementation -------*/ - -typedef struct { - char *data; - size_t fpos; - size_t fsize; - size_t smax; - int mode; -} php_stream_memory_data; - - -/* {{{ */ -static size_t php_stream_memory_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) -{ - php_stream_memory_data *ms; - - assert(stream != NULL); - ms = stream->abstract; - assert(ms != NULL); - - if (ms->mode & TEMP_STREAM_READONLY) { - return 0; - } - if (ms->fpos + count > ms->fsize) { - char *tmp; - - if (!ms->data) { - tmp = emalloc(ms->fpos + count); - } else { - tmp = erealloc(ms->data, ms->fpos + count); - } - if (!tmp) { - count = ms->fsize - ms->fpos + 1; - } else { - ms->data = tmp; - ms->fsize = ms->fpos + count; - } - } - if (!ms->data) - count = 0; - if (count) { - assert(buf!= NULL); - memcpy(ms->data+ms->fpos, (char*)buf, count); - ms->fpos += count; - } - return count; -} -/* }}} */ - - -/* {{{ */ -static size_t php_stream_memory_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) -{ - php_stream_memory_data *ms; - - assert(stream != NULL); - ms = stream->abstract; - assert(ms != NULL); - - if (ms->fpos + count > ms->fsize) { - count = ms->fsize - ms->fpos; - } - if (count) { - assert(ms->data!= NULL); - assert(buf!= NULL); - memcpy(buf, ms->data+ms->fpos, count); - ms->fpos += count; - } else { - stream->eof = 1; - } - return count; -} -/* }}} */ - - -/* {{{ */ -static int php_stream_memory_close(php_stream *stream, int close_handle TSRMLS_DC) -{ - php_stream_memory_data *ms; - - assert(stream != NULL); - ms = stream->abstract; - assert(ms != NULL); - - if (ms->data && close_handle && ms->mode != TEMP_STREAM_READONLY) { - efree(ms->data); - } - efree(ms); - return 0; -} -/* }}} */ - - -/* {{{ */ -static int php_stream_memory_flush(php_stream *stream TSRMLS_DC) -{ - /* nothing to do here */ - return 0; -} -/* }}} */ - - -/* {{{ */ -static int php_stream_memory_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) -{ - php_stream_memory_data *ms; - - assert(stream != NULL); - ms = stream->abstract; - assert(ms != NULL); - - switch(whence) { - case SEEK_CUR: - if (offset < 0) { - if (ms->fpos < (size_t)(-offset)) { - ms->fpos = 0; - /*return EINVAL;*/ - } else { - ms->fpos = ms->fpos + offset; - } - } else { - if (ms->fpos < (size_t)(offset)) { - ms->fpos = ms->fsize; - /*return EINVAL;*/ - } else { - ms->fpos = ms->fpos + offset; - } - } - *newoffs = ms->fpos; - return 0; - case SEEK_SET: - if (ms->fsize < (size_t)(offset)) { - ms->fpos = ms->fsize; - /*return EINVAL;*/ - } else { - ms->fpos = offset; - } - *newoffs = ms->fpos; - return 0; - case SEEK_END: - if (offset > 0) { - ms->fpos = ms->fsize; - /*return EINVAL;*/ - } else if (ms->fpos < (size_t)(-offset)) { - ms->fpos = 0; - /*return EINVAL;*/ - } else { - ms->fpos = ms->fsize + offset; - } - *newoffs = ms->fpos; - return 0; - default: - return 0; - /*return EINVAL;*/ - } -} -/* }}} */ - -/* {{{ */ -static int php_stream_memory_cast(php_stream *stream, int castas, void **ret TSRMLS_DC) -{ - return FAILURE; -} -/* }}} */ - - -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, - NULL, /* stat */ - NULL /* set_option */ -}; - - -/* {{{ */ -PHPAPI php_stream *_php_stream_memory_create(int mode STREAMS_DC TSRMLS_DC) -{ - php_stream_memory_data *self; - php_stream *stream; - - self = emalloc(sizeof(*self)); - self->data = NULL; - self->fpos = 0; - self->fsize = 0; - self->smax = -1; - self->mode = mode; - - stream = php_stream_alloc(&php_stream_memory_ops, self, 0, "r+b"); - stream->flags |= PHP_STREAM_FLAG_NO_BUFFER; - return stream; -} -/* }}} */ - - -/* {{{ */ -PHPAPI php_stream *_php_stream_memory_open(int mode, char *buf, size_t length STREAMS_DC TSRMLS_DC) -{ - php_stream *stream; - php_stream_memory_data *ms; - - if ((stream = php_stream_memory_create_rel(mode)) != NULL) { - ms = stream->abstract; - - if (mode == TEMP_STREAM_READONLY) { - /* use the buffer directly */ - ms->data = buf; - ms->fsize = length; - } else { - if (length) { - assert(buf != NULL); - php_stream_write(stream, buf, length); - } - } - } - return stream; -} -/* }}} */ - - -/* {{{ */ -PHPAPI char *_php_stream_memory_get_buffer(php_stream *stream, size_t *length STREAMS_DC TSRMLS_DC) -{ - php_stream_memory_data *ms; - - assert(stream != NULL); - ms = stream->abstract; - assert(ms != NULL); - assert(length != 0); - - *length = ms->fsize; - return ms->data; -} -/* }}} */ - -/* }}} */ - -/* {{{ ------- TEMP stream implementation -------*/ - -typedef struct { - php_stream *innerstream; - size_t smax; - int mode; -} php_stream_temp_data; - - -/* {{{ */ -static size_t php_stream_temp_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) -{ - php_stream_temp_data *ts; - - assert(stream != NULL); - ts = stream->abstract; - assert(ts != NULL); - - if (php_stream_is(ts->innerstream, PHP_STREAM_IS_MEMORY)) { - size_t memsize; - char *membuf = php_stream_memory_get_buffer(ts->innerstream, &memsize); - - if (memsize + count >= ts->smax) { - php_stream *file = php_stream_fopen_tmpfile(); - php_stream_write(file, membuf, memsize); - php_stream_close(ts->innerstream); - ts->innerstream = file; - } - } - return php_stream_write(ts->innerstream, buf, count); -} -/* }}} */ - - -/* {{{ */ -static size_t php_stream_temp_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) -{ - php_stream_temp_data *ts; - - assert(stream != NULL); - ts = stream->abstract; - assert(ts != NULL); - - return php_stream_read(ts->innerstream, buf, count); -} -/* }}} */ - - -/* {{{ */ -static int php_stream_temp_close(php_stream *stream, int close_handle TSRMLS_DC) -{ - php_stream_temp_data *ts; - int ret; - - assert(stream != NULL); - ts = stream->abstract; - assert(ts != NULL); - - ret = php_stream_free(ts->innerstream, PHP_STREAM_FREE_CLOSE | (close_handle ? 0 : PHP_STREAM_FREE_PRESERVE_HANDLE)); - - efree(ts); - - return ret; -} -/* }}} */ - - -/* {{{ */ -static int php_stream_temp_flush(php_stream *stream TSRMLS_DC) -{ - php_stream_temp_data *ts; - - assert(stream != NULL); - ts = stream->abstract; - assert(ts != NULL); - - return php_stream_flush(ts->innerstream); -} -/* }}} */ - - -/* {{{ */ -static int php_stream_temp_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) -{ - php_stream_temp_data *ts; - int ret; - - assert(stream != NULL); - ts = stream->abstract; - assert(ts != NULL); - - ret = php_stream_seek(ts->innerstream, offset, whence); - *newoffs = php_stream_tell(ts->innerstream); - - return ret; -} -/* }}} */ - -/* {{{ */ -static int php_stream_temp_cast(php_stream *stream, int castas, void **ret TSRMLS_DC) -{ - php_stream_temp_data *ts; - php_stream *file; - size_t memsize; - char *membuf; - off_t pos; - - assert(stream != NULL); - ts = stream->abstract; - assert(ts != NULL); - - if (php_stream_is(ts->innerstream, PHP_STREAM_IS_STDIO)) { - return php_stream_cast(ts->innerstream, castas, ret, 0); - } - - /* we are still using a memory based backing. If they are if we can be - * a FILE*, say yes because we can perform the conversion. - * If they actually want to perform the conversion, we need to switch - * the memory stream to a tmpfile stream */ - - if (ret == NULL && castas == PHP_STREAM_AS_STDIO) { - return SUCCESS; - } - - /* say "no" to other stream forms */ - if (ret == NULL) { - return FAILURE; - } - - /* perform the conversion and then pass the request on to the innerstream */ - membuf = php_stream_memory_get_buffer(ts->innerstream, &memsize); - file = php_stream_fopen_tmpfile(); - php_stream_write(file, membuf, memsize); - pos = php_stream_tell(ts->innerstream); - - php_stream_close(ts->innerstream); - ts->innerstream = file; - php_stream_seek(ts->innerstream, pos, SEEK_SET); - - return php_stream_cast(ts->innerstream, castas, ret, 1); -} -/* }}} */ - -php_stream_ops php_stream_temp_ops = { - php_stream_temp_write, php_stream_temp_read, - php_stream_temp_close, php_stream_temp_flush, - "TEMP", - php_stream_temp_seek, - php_stream_temp_cast, - NULL, /* stat */ - NULL /* set_option */ -}; - -/* }}} */ - -/* {{{ _php_stream_temp_create */ -PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STREAMS_DC TSRMLS_DC) -{ - php_stream_temp_data *self; - php_stream *stream; - - self = ecalloc(1, sizeof(*self)); - self->smax = max_memory_usage; - self->mode = mode; - stream = php_stream_alloc(&php_stream_temp_ops, self, 0, "r+b"); - stream->flags |= PHP_STREAM_FLAG_NO_BUFFER; - self->innerstream = php_stream_memory_create(mode); - - return stream; -} -/* }}} */ - - -/* {{{ _php_stream_temp_open */ -PHPAPI php_stream *_php_stream_temp_open(int mode, size_t max_memory_usage, char *buf, size_t length STREAMS_DC TSRMLS_DC) -{ - php_stream *stream; - php_stream_temp_data *ms; - - if ((stream = php_stream_temp_create_rel(mode & ~TEMP_STREAM_READONLY, max_memory_usage)) != NULL) { - if (length) { - assert(buf != NULL); - php_stream_temp_write(stream, buf, length TSRMLS_CC); - } - ms = stream->abstract; - assert(ms != NULL); - ms->mode = mode; - } - return stream; -} -/* }}} */ - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/main/streams/mmap.c b/main/streams/mmap.c deleted file mode 100644 index 443faf384d..0000000000 --- a/main/streams/mmap.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* Memory Mapping interface for streams */ -#include "php.h" -#include "php_streams_int.h" - -PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t length, php_stream_mmap_operation_t mode, size_t *mapped_len TSRMLS_DC) -{ - php_stream_mmap_range range; - - range.offset = offset; - range.length = length; - range.mode = mode; - range.mapped = NULL; - - /* TODO: Enforce system policy and limits for mmap sizes ? */ - - if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_MAP_RANGE, &range)) { - if (mapped_len) { - *mapped_len = range.length; - } - return range.mapped; - } - return NULL; -} - -PHPAPI int _php_stream_mmap_unmap(php_stream *stream TSRMLS_DC) -{ - return php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_UNMAP, NULL) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0; -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/main/streams/php_stream_context.h b/main/streams/php_stream_context.h deleted file mode 100644 index eb8b404cfb..0000000000 --- a/main/streams/php_stream_context.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* Stream context and status notification related definitions */ - -/* callback for status notifications */ -typedef void (*php_stream_notification_func)(php_stream_context *context, - int notifycode, int severity, - char *xmsg, int xcode, - size_t bytes_sofar, size_t bytes_max, - void * ptr TSRMLS_DC); - -#define PHP_STREAM_NOTIFIER_PROGRESS 1 - -/* Attempt to fetch context from the zval passed, - If no context was passed, use the default context - The the default context has not yet been created, do it now. */ -#define php_stream_context_from_zval(zcontext, nocontext) ( \ - (zcontext) ? zend_fetch_resource(&(zcontext) TSRMLS_CC, -1, "Stream-Context", NULL, 1, php_le_stream_context()) : \ - (nocontext) ? NULL : \ - FG(default_context) ? FG(default_context) : \ - (FG(default_context) = php_stream_context_alloc()) ) - -#define php_stream_context_to_zval(context, zval) { ZVAL_RESOURCE(zval, (context)->rsrc_id); } - -typedef struct _php_stream_notifier php_stream_notifier; - -struct _php_stream_notifier { - php_stream_notification_func func; - void (*dtor)(php_stream_notifier *notifier); - void *ptr; - int mask; - size_t progress, progress_max; /* position for progress notification */ -}; - -struct _php_stream_context { - php_stream_notifier *notifier; - zval *options; /* hash keyed by wrapper family or specific wrapper */ - zval *links; /* hash keyed by hostent for connection pooling */ - int rsrc_id; /* used for auto-cleanup */ -}; - -PHPAPI void php_stream_context_free(php_stream_context *context); -PHPAPI php_stream_context *php_stream_context_alloc(void); -PHPAPI int php_stream_context_get_option(php_stream_context *context, - const char *wrappername, const char *optionname, zval ***optionvalue); -PHPAPI int php_stream_context_set_option(php_stream_context *context, - const char *wrappername, const char *optionname, zval *optionvalue); - -PHPAPI int php_stream_context_get_link(php_stream_context *context, - const char *hostent, php_stream **stream); -PHPAPI int php_stream_context_set_link(php_stream_context *context, - const char *hostent, php_stream *stream); -PHPAPI int php_stream_context_del_link(php_stream_context *context, - php_stream *stream); - -PHPAPI php_stream_notifier *php_stream_notification_alloc(void); -PHPAPI void php_stream_notification_free(php_stream_notifier *notifier); - -/* not all notification codes are implemented */ -#define PHP_STREAM_NOTIFY_RESOLVE 1 -#define PHP_STREAM_NOTIFY_CONNECT 2 -#define PHP_STREAM_NOTIFY_AUTH_REQUIRED 3 -#define PHP_STREAM_NOTIFY_MIME_TYPE_IS 4 -#define PHP_STREAM_NOTIFY_FILE_SIZE_IS 5 -#define PHP_STREAM_NOTIFY_REDIRECTED 6 -#define PHP_STREAM_NOTIFY_PROGRESS 7 -#define PHP_STREAM_NOTIFY_COMPLETED 8 -#define PHP_STREAM_NOTIFY_FAILURE 9 -#define PHP_STREAM_NOTIFY_AUTH_RESULT 10 - -#define PHP_STREAM_NOTIFY_SEVERITY_INFO 0 -#define PHP_STREAM_NOTIFY_SEVERITY_WARN 1 -#define PHP_STREAM_NOTIFY_SEVERITY_ERR 2 - -PHPAPI void php_stream_notification_notify(php_stream_context *context, int notifycode, int severity, - char *xmsg, int xcode, size_t bytes_sofar, size_t bytes_max, void * ptr TSRMLS_DC); -PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context); - -#define php_stream_notify_info(context, code, xmsg, xcode) do { if ((context) && (context)->notifier) { \ - php_stream_notification_notify((context), (code), PHP_STREAM_NOTIFY_SEVERITY_INFO, \ - (xmsg), (xcode), 0, 0, NULL TSRMLS_CC); } } while (0) - -#define php_stream_notify_progress(context, bsofar, bmax) do { if ((context) && (context)->notifier) { \ - php_stream_notification_notify((context), PHP_STREAM_NOTIFY_PROGRESS, PHP_STREAM_NOTIFY_SEVERITY_INFO, \ - NULL, 0, (bsofar), (bmax), NULL TSRMLS_CC); } } while(0) - -#define php_stream_notify_progress_init(context, sofar, bmax) do { if ((context) && (context)->notifier) { \ - (context)->notifier->progress = (sofar); \ - (context)->notifier->progress_max = (bmax); \ - (context)->notifier->mask |= PHP_STREAM_NOTIFIER_PROGRESS; \ - php_stream_notify_progress((context), (sofar), (bmax)); } } while (0) - -#define php_stream_notify_progress_increment(context, dsofar, dmax) do { if ((context) && (context)->notifier && (context)->notifier->mask & PHP_STREAM_NOTIFIER_PROGRESS) { \ - (context)->notifier->progress += (dsofar); \ - (context)->notifier->progress_max += (dmax); \ - php_stream_notify_progress((context), (context)->notifier->progress, (context)->notifier->progress_max); } } while (0) - -#define php_stream_notify_file_size(context, file_size, xmsg, xcode) do { if ((context) && (context)->notifier) { \ - php_stream_notification_notify((context), PHP_STREAM_NOTIFY_FILE_SIZE_IS, PHP_STREAM_NOTIFY_SEVERITY_INFO, \ - (xmsg), (xcode), 0, (file_size), NULL TSRMLS_CC); } } while(0) - -#define php_stream_notify_error(context, code, xmsg, xcode) do { if ((context) && (context)->notifier) {\ - php_stream_notification_notify((context), (code), PHP_STREAM_NOTIFY_SEVERITY_ERR, \ - (xmsg), (xcode), 0, 0, NULL TSRMLS_CC); } } while(0) - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/streams/php_stream_filter_api.h b/main/streams/php_stream_filter_api.h deleted file mode 100644 index b5b129e968..0000000000 --- a/main/streams/php_stream_filter_api.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Wez Furlong <wez@thebrainroom.com> | - | With suggestions from: | - | Moriyoshi Koizumi <moriyoshi@at.wakwak.com> | - | Sara Golemon <pollita@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* The filter API works on the principle of "Bucket-Brigades". This is - * partially inspired by the Apache 2 method of doing things, although - * it is intentially a light-weight implementation. - * - * Each stream can have a chain of filters for reading and another for writing. - * - * When data is written to the stream, is is placed into a bucket and placed at - * the start of the input brigade. - * - * The first filter in the chain is invoked on the brigade and (depending on - * it's return value), the next filter is invoked and so on. - * */ - -#define PHP_STREAM_FILTER_READ 0x0001 -#define PHP_STREAM_FILTER_WRITE 0x0002 -#define PHP_STREAM_FILTER_ALL (PHP_STREAM_FILTER_READ | PHP_STREAM_FILTER_WRITE) - -typedef struct _php_stream_bucket php_stream_bucket; -typedef struct _php_stream_bucket_brigade php_stream_bucket_brigade; - -struct _php_stream_bucket { - php_stream_bucket *next, *prev; - php_stream_bucket_brigade *brigade; - - char *buf; - size_t buflen; - /* if non-zero, buf should be pefreed when the bucket is destroyed */ - int own_buf; - int is_persistent; - - /* destroy this struct when refcount falls to zero */ - int refcount; -}; - -struct _php_stream_bucket_brigade { - php_stream_bucket *head, *tail; -}; - -typedef enum { - PSFS_ERR_FATAL, /* error in data stream */ - PSFS_FEED_ME, /* filter needs more data; stop processing chain until more is available */ - PSFS_PASS_ON, /* filter generated output buckets; pass them on to next in chain */ -} php_stream_filter_status_t; - -/* Buckets API. */ -PHPAPI php_stream_bucket *php_stream_bucket_new(php_stream *stream, char *buf, size_t buflen, int own_buf, int buf_persistent TSRMLS_DC); -PHPAPI int php_stream_bucket_split(php_stream_bucket *in, php_stream_bucket **left, php_stream_bucket **right, size_t length TSRMLS_DC); -PHPAPI void php_stream_bucket_delref(php_stream_bucket *bucket TSRMLS_DC); -#define php_stream_bucket_addref(bucket) (bucket)->refcount++ -PHPAPI void php_stream_bucket_prepend(php_stream_bucket_brigade *brigade, php_stream_bucket *bucket TSRMLS_DC); -PHPAPI void php_stream_bucket_append(php_stream_bucket_brigade *brigade, php_stream_bucket *bucket TSRMLS_DC); -PHPAPI void php_stream_bucket_unlink(php_stream_bucket *bucket TSRMLS_DC); -PHPAPI php_stream_bucket *php_stream_bucket_make_writeable(php_stream_bucket *bucket TSRMLS_DC); - -#define PSFS_FLAG_NORMAL 0 /* regular read/write */ -#define PSFS_FLAG_FLUSH_INC 1 /* an incremental flush */ -#define PSFS_FLAG_FLUSH_CLOSE 2 /* final flush prior to closing */ - -typedef struct _php_stream_filter_ops { - - php_stream_filter_status_t (*filter)( - php_stream *stream, - php_stream_filter *thisfilter, - php_stream_bucket_brigade *buckets_in, - php_stream_bucket_brigade *buckets_out, - size_t *bytes_consumed, - int flags - TSRMLS_DC); - - void (*dtor)(php_stream_filter *thisfilter TSRMLS_DC); - - const char *label; - -} php_stream_filter_ops; - -typedef struct _php_stream_filter_chain { - php_stream_filter *head, *tail; -} php_stream_filter_chain; - -struct _php_stream_filter { - php_stream_filter_ops *fops; - void *abstract; /* for use by filter implementation */ - php_stream_filter *next; - php_stream_filter *prev; - int is_persistent; - - /* link into stream and chain */ - php_stream_filter_chain *chain; - - /* buffered buckets */ - php_stream_bucket_brigade buffer; -}; - -/* stack filter onto a stream */ -PHPAPI void php_stream_filter_prepend(php_stream_filter_chain *chain, php_stream_filter *filter); -PHPAPI void php_stream_filter_append(php_stream_filter_chain *chain, php_stream_filter *filter); -PHPAPI php_stream_filter *php_stream_filter_remove(php_stream_filter *filter, int call_dtor TSRMLS_DC); -PHPAPI void php_stream_filter_free(php_stream_filter *filter TSRMLS_DC); -PHPAPI php_stream_filter *_php_stream_filter_alloc(php_stream_filter_ops *fops, void *abstract, int persistent STREAMS_DC TSRMLS_DC); -#define php_stream_filter_alloc(fops, thisptr, persistent) _php_stream_filter_alloc((fops), (thisptr), (persistent) STREAMS_CC TSRMLS_CC) -#define php_stream_filter_alloc_rel(fops, thisptr, persistent) _php_stream_filter_alloc((fops), (thisptr), (persistent) STREAMS_REL_CC TSRMLS_CC) - -#define php_stream_is_filtered(stream) ((stream)->readfilters.head || (stream)->writefilters.head) - -typedef struct _php_stream_filter_factory { - php_stream_filter *(*create_filter)(const char *filtername, zval *filterparams, int persistent TSRMLS_DC); -} php_stream_filter_factory; - -PHPAPI int php_stream_filter_register_factory(const char *filterpattern, php_stream_filter_factory *factory TSRMLS_DC); -PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern TSRMLS_DC); -PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval *filterparams, int persistent TSRMLS_DC); - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/streams/php_stream_mmap.h b/main/streams/php_stream_mmap.h deleted file mode 100644 index 024eb7c6d2..0000000000 --- a/main/streams/php_stream_mmap.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* Memory Mapping interface for streams. - * The intention is to provide a uniform interface over the most common - * operations that are used within PHP itself, rather than a complete - * API for all memory mapping needs. - * - * ATM, we support only mmap(), but win32 memory mapping support will - * follow soon. - * */ - -typedef enum { - /* Does the stream support mmap ? */ - PHP_STREAM_MMAP_SUPPORTED, - /* Request a range and offset to be mapped; - * while mapped, you MUST NOT use any read/write functions - * on the stream (win9x compatibility) */ - PHP_STREAM_MMAP_MAP_RANGE, - /* Unmap the last range that was mapped for the stream */ - PHP_STREAM_MMAP_UNMAP -} php_stream_mmap_operation_t; - -typedef enum { - PHP_STREAM_MAP_MODE_READONLY, - PHP_STREAM_MAP_MODE_READWRITE, - PHP_STREAM_MAP_MODE_SHARED_READONLY, - PHP_STREAM_MAP_MODE_SHARED_READWRITE -} php_stream_mmap_access_t; - -typedef struct { - /* requested offset and length. - * If length is 0, the whole file is mapped */ - size_t offset; - size_t length; - - php_stream_mmap_access_t mode; - - /* returned mapped address */ - char *mapped; - -} php_stream_mmap_range; - -#define php_stream_mmap_supported(stream) (_php_stream_set_option((stream), PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_SUPPORTED, NULL TSRMLS_CC) == 0 ? 1 : 0) - -/* Returns 1 if the stream in its current state can be memory mapped, - * 0 otherwise */ -#define php_stream_mmap_possible(stream) (!php_stream_is_filtered((stream)) && php_stream_mmap_supported((stream))) - -PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t length, php_stream_mmap_operation_t mode, size_t *mapped_len TSRMLS_DC); -#define php_stream_mmap_range(stream, offset, length, mode, mapped_len) _php_stream_mmap_range((stream), (offset), (length), (mode), (mapped_len) TSRMLS_CC) - -/* un-maps the last mapped range */ -PHPAPI int _php_stream_mmap_unmap(php_stream *stream TSRMLS_DC); -#define php_stream_mmap_unmap(stream) _php_stream_mmap_unmap((stream) TSRMLS_CC) - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/main/streams/php_stream_plain_wrapper.h b/main/streams/php_stream_plain_wrapper.h deleted file mode 100644 index 9a23527532..0000000000 --- a/main/streams/php_stream_plain_wrapper.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* definitions for the plain files wrapper */ - -/* operations for a plain file; use the php_stream_fopen_XXX funcs below */ -PHPAPI extern php_stream_ops php_stream_stdio_ops; - -/* like fopen, but returns a stream */ -PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, char **opened_path, int options STREAMS_DC TSRMLS_DC); -#define php_stream_fopen(filename, mode, opened) _php_stream_fopen((filename), (mode), (opened), 0 STREAMS_CC TSRMLS_CC) - -PHPAPI php_stream *_php_stream_fopen_with_path(char *filename, char *mode, char *path, char **opened_path, int options STREAMS_DC TSRMLS_DC); -#define php_stream_fopen_with_path(filename, mode, path, opened) _php_stream_fopen_with_path((filename), (mode), (path), (opened) STREAMS_CC TSRMLS_CC) - -PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STREAMS_DC TSRMLS_DC); -#define php_stream_fopen_from_file(file, mode) _php_stream_fopen_from_file((file), (mode) STREAMS_CC TSRMLS_CC) - -PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const char *persistent_id STREAMS_DC TSRMLS_DC); -#define php_stream_fopen_from_fd(fd, mode, persistent_id) _php_stream_fopen_from_fd((fd), (mode), (persistent_id) STREAMS_CC TSRMLS_CC) - -PHPAPI php_stream *_php_stream_fopen_from_pipe(FILE *file, const char *mode STREAMS_DC TSRMLS_DC); -#define php_stream_fopen_from_pipe(file, mode) _php_stream_fopen_from_pipe((file), (mode) STREAMS_CC TSRMLS_CC) - -PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC TSRMLS_DC); -#define php_stream_fopen_tmpfile() _php_stream_fopen_tmpfile(0 STREAMS_CC TSRMLS_CC) - -PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, char **opened_path STREAMS_DC TSRMLS_DC); -#define php_stream_fopen_temporary_file(dir, pfx, opened_path) _php_stream_fopen_temporary_file((dir), (pfx), (opened_path) STREAMS_CC TSRMLS_CC) - -/* This is a utility API for extensions that are opening a stream, converting it - * to a FILE* and then closing it again. Be warned that fileno() on the result - * will most likely fail on systems with fopencookie. */ -PHPAPI FILE * _php_stream_open_wrapper_as_file(char * path, char * mode, int options, char **opened_path STREAMS_DC TSRMLS_DC); -#define php_stream_open_wrapper_as_file(path, mode, options, opened_path) _php_stream_open_wrapper_as_file((path), (mode), (options), (opened_path) STREAMS_CC TSRMLS_CC) - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/streams/php_stream_transport.h b/main/streams/php_stream_transport.h deleted file mode 100644 index d1fbb273f1..0000000000 --- a/main/streams/php_stream_transport.h +++ /dev/null @@ -1,188 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#if HAVE_SYS_SOCKET_H -# include <sys/socket.h> -#endif - -typedef php_stream *(php_stream_transport_factory_func)(const char *proto, long protolen, - char *resourcename, long resourcenamelen, - const char *persistent_id, int options, int flags, - struct timeval *timeout, - php_stream_context *context STREAMS_DC TSRMLS_DC); -typedef php_stream_transport_factory_func *php_stream_transport_factory; - -PHPAPI int php_stream_xport_register(char *protocol, php_stream_transport_factory factory TSRMLS_DC); -PHPAPI int php_stream_xport_unregister(char *protocol TSRMLS_DC); - -#define STREAM_XPORT_CLIENT 0 -#define STREAM_XPORT_SERVER 1 - -#define STREAM_XPORT_CONNECT 2 -#define STREAM_XPORT_BIND 4 -#define STREAM_XPORT_LISTEN 8 -#define STREAM_XPORT_CONNECT_ASYNC 16 - -/* Open a client or server socket connection */ -PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int options, - int flags, const char *persistent_id, - struct timeval *timeout, - php_stream_context *context, - char **error_string, - int *error_code - STREAMS_DC TSRMLS_DC); - -#define php_stream_xport_create(name, namelen, options, flags, persistent_id, timeout, context, estr, ecode) \ - _php_stream_xport_create(name, namelen, options, flags, persistent_id, timeout, context, estr, ecode STREAMS_CC TSRMLS_CC) - -/* Bind the stream to a local address */ -PHPAPI int php_stream_xport_bind(php_stream *stream, - const char *name, long namelen, - char **error_text - TSRMLS_DC); - -/* Connect to a remote address */ -PHPAPI int php_stream_xport_connect(php_stream *stream, - const char *name, long namelen, - int asynchronous, - struct timeval *timeout, - char **error_text, - int *error_code - TSRMLS_DC); - -/* Prepare to listen */ -PHPAPI int php_stream_xport_listen(php_stream *stream, - int backlog, - char **error_text - TSRMLS_DC); - -/* Get the next client and their address as a string, or the underlying address - * structure. You must efree either of these if you request them */ -PHPAPI int php_stream_xport_accept(php_stream *stream, php_stream **client, - char **textaddr, int *textaddrlen, - void **addr, socklen_t *addrlen, - struct timeval *timeout, - char **error_text - TSRMLS_DC); - -/* Get the name of either the socket or it's peer */ -PHPAPI int php_stream_xport_get_name(php_stream *stream, int want_peer, - char **textaddr, int *textaddrlen, - void **addr, socklen_t *addrlen - TSRMLS_DC); - -enum php_stream_xport_send_recv_flags { - STREAM_OOB = 1, - STREAM_PEEK = 2 -}; - -/* Similar to recv() system call; read data from the stream, optionally - * peeking, optionally retrieving OOB data */ -PHPAPI int php_stream_xport_recvfrom(php_stream *stream, char *buf, size_t buflen, - long flags, void **addr, socklen_t *addrlen, - char **textaddr, int *textaddrlen TSRMLS_DC); - -/* Similar to send() system call; send data to the stream, optionally - * 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); - -/* Structure definition for the set_option interface that the above functions wrap */ - -typedef struct _php_stream_xport_param { - enum { - STREAM_XPORT_OP_BIND, STREAM_XPORT_OP_CONNECT, - STREAM_XPORT_OP_LISTEN, STREAM_XPORT_OP_ACCEPT, - STREAM_XPORT_OP_CONNECT_ASYNC, - STREAM_XPORT_OP_GET_NAME, - STREAM_XPORT_OP_GET_PEER_NAME, - STREAM_XPORT_OP_RECV, - STREAM_XPORT_OP_SEND - } op; - unsigned int want_addr:1; - unsigned int want_textaddr:1; - unsigned int want_errortext:1; - - struct { - char *name; - long namelen; - int backlog; - struct timeval *timeout; - struct sockaddr *addr; - socklen_t addrlen; - char *buf; - size_t buflen; - long flags; - } inputs; - struct { - php_stream *client; - int returncode; - struct sockaddr *addr; - socklen_t addrlen; - char *textaddr; - long textaddrlen; - - char *error_text; - int error_code; - } outputs; -} php_stream_xport_param; - - -/* These functions provide crypto support on the underlying transport */ -typedef enum { - STREAM_CRYPTO_METHOD_SSLv2_CLIENT, - STREAM_CRYPTO_METHOD_SSLv3_CLIENT, - STREAM_CRYPTO_METHOD_SSLv23_CLIENT, - STREAM_CRYPTO_METHOD_TLS_CLIENT, - STREAM_CRYPTO_METHOD_SSLv2_SERVER, - STREAM_CRYPTO_METHOD_SSLv3_SERVER, - STREAM_CRYPTO_METHOD_SSLv23_SERVER, - STREAM_CRYPTO_METHOD_TLS_SERVER -} php_stream_xport_crypt_method_t; - -PHPAPI int php_stream_xport_crypto_setup(php_stream *stream, php_stream_xport_crypt_method_t crypto_method, php_stream *session_stream TSRMLS_DC); -PHPAPI int php_stream_xport_crypto_enable(php_stream *stream, int activate TSRMLS_DC); - -typedef struct _php_stream_xport_crypto_param { - enum { - STREAM_XPORT_CRYPTO_OP_SETUP, - STREAM_XPORT_CRYPTO_OP_ENABLE - } op; - struct { - int activate; - php_stream_xport_crypt_method_t method; - php_stream *session; - } inputs; - struct { - int returncode; - } outputs; -} php_stream_xport_crypto_param; - -PHPAPI HashTable *php_stream_xport_get_hash(void); -PHPAPI php_stream_transport_factory_func php_stream_generic_socket_factory; - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/main/streams/php_stream_userspace.h b/main/streams/php_stream_userspace.h deleted file mode 100644 index a5b59ffb74..0000000000 --- a/main/streams/php_stream_userspace.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - - -/* for user-space streams */ -PHPAPI extern php_stream_ops php_stream_userspace_ops; -PHPAPI extern php_stream_ops php_stream_userspace_dir_ops; -#define PHP_STREAM_IS_USERSPACE &php_stream_userspace_ops -#define PHP_STREAM_IS_USERSPACE_DIR &php_stream_userspace_dir_ops - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/streams/php_streams_int.h b/main/streams/php_streams_int.h deleted file mode 100644 index a753343463..0000000000 --- a/main/streams/php_streams_int.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#if ZEND_DEBUG -#define emalloc_rel_orig(size) \ - ( __php_stream_call_depth == 0 \ - ? _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_RELAY_CC) \ - : _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC) ) - -#define erealloc_rel_orig(ptr, size) \ - ( __php_stream_call_depth == 0 \ - ? _erealloc((ptr), (size), 0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_RELAY_CC) \ - : _erealloc((ptr), (size), 0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC) ) - - -#define pemalloc_rel_orig(size, persistent) ((persistent) ? malloc((size)) : emalloc_rel_orig((size))) -#define perealloc_rel_orig(ptr, size, persistent) ((persistent) ? realloc((ptr), (size)) : erealloc_rel_orig((ptr), (size))) -#else -# define pemalloc_rel_orig(size, persistent) pemalloc((size), (persistent)) -# define perealloc_rel_orig(ptr, size, persistent) perealloc((ptr), (size), (persistent)) -# define emalloc_rel_orig(size) emalloc((size)) -#endif - -#define STREAM_DEBUG 0 -#define STREAM_WRAPPER_PLAIN_FILES ((php_stream_wrapper*)-1) -extern php_stream_wrapper php_plain_files_wrapper; - -#ifndef MAP_FAILED -#define MAP_FAILED ((void *) -1) -#endif - -#define CHUNK_SIZE 8192 - -#ifdef PHP_WIN32 -#define EWOULDBLOCK WSAEWOULDBLOCK -#endif - -#ifndef S_ISREG -#define S_ISREG(mode) (((mode)&S_IFMT) == S_IFREG) -#endif - -void php_stream_tidy_wrapper_error_log(php_stream_wrapper *wrapper TSRMLS_DC); -void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, const char *path, const char *caption TSRMLS_DC); - diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c deleted file mode 100644 index c60063f355..0000000000 --- a/main/streams/plain_wrapper.c +++ /dev/null @@ -1,1281 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" -#include "php_globals.h" -#include "php_network.h" -#include "php_open_temporary_file.h" -#include "ext/standard/file.h" -#include "ext/standard/flock_compat.h" -#include <stddef.h> -#include <fcntl.h> -#if HAVE_SYS_WAIT_H -#include <sys/wait.h> -#endif -#if HAVE_SYS_FILE_H -#include <sys/file.h> -#endif -#ifdef HAVE_SYS_MMAN_H -#include <sys/mman.h> -#endif - -#include "php_streams_int.h" - -/* parse standard "fopen" modes into open() flags */ -PHPAPI int php_stream_parse_fopen_modes(const char *mode, int *open_flags) -{ - int flags; - - switch (mode[0]) { - case 'r': - flags = 0; - break; - case 'w': - flags = O_TRUNC|O_CREAT; - break; - case 'a': - flags = O_CREAT|O_APPEND; - break; - case 'x': - flags = O_CREAT|O_EXCL; - break; - default: - /* unknown mode */ - return FAILURE; - } - - if (strchr(mode, '+')) { - flags |= O_RDWR; - } else if (flags) { - flags |= O_WRONLY; - } else { - flags |= O_RDONLY; - } - -#if defined(_O_TEXT) && defined(O_BINARY) - if (strchr(mode, 't')) { - flags |= _O_TEXT; - } else { - flags |= O_BINARY; - } -#endif - - *open_flags = flags; - return SUCCESS; -} - - -/* {{{ php_stream_fopen */ -PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, char **opened_path, int options STREAMS_DC TSRMLS_DC) -{ - char *realpath = NULL; - struct stat st; - int open_flags; - int fd; - php_stream *ret; - int persistent = options & STREAM_OPEN_PERSISTENT; - char *persistent_id = NULL; - - if (FAILURE == php_stream_parse_fopen_modes(mode, &open_flags)) { - if (options & REPORT_ERRORS) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "`%s' is not a valid mode for fopen", mode); - } - return NULL; - } - - if ((realpath = expand_filepath(filename, NULL TSRMLS_CC)) == NULL) { - return NULL; - } - - if (persistent) { - spprintf(&persistent_id, 0, "streams_stdio_%d_%s", open_flags, realpath); - switch (php_stream_from_persistent_id(persistent_id, &ret TSRMLS_CC)) { - case PHP_STREAM_PERSISTENT_SUCCESS: - if (opened_path) { - *opened_path = realpath; - realpath = NULL; - } - if (realpath) { - efree(realpath); - } - /* fall through */ - - case PHP_STREAM_PERSISTENT_FAILURE: - efree(persistent_id);; - return ret; - } - } - - fd = open(realpath, open_flags, 0666); - - if (fd != -1) { - /* sanity checks for include/require */ - if (options & STREAM_OPEN_FOR_INCLUDE && (fstat(fd, &st) == -1 || !S_ISREG(st.st_mode))) { -#ifdef PHP_WIN32 - /* skip the sanity check; fstat doesn't appear to work on - * UNC paths */ - if (!IS_UNC_PATH(filename, strlen(filename))) -#endif - goto err; - } - - ret = php_stream_fopen_from_fd_rel(fd, mode, persistent_id); - - if (ret) { - if (opened_path) { - *opened_path = realpath; - realpath = NULL; - } - if (realpath) { - efree(realpath); - } - if (persistent_id) { - efree(persistent_id); - } - return ret; - } -err: - close(fd); - } - efree(realpath); - if (persistent_id) { - efree(persistent_id); - } - return NULL; -} -/* }}} */ - -/* {{{ ------- STDIO stream implementation -------*/ - -typedef struct { - FILE *file; - int fd; /* underlying file descriptor */ - int is_process_pipe; /* use pclose instead of fclose */ - int is_pipe; /* don't try and seek */ - int lock_flag; /* stores the lock state */ - char *temp_file_name; /* if non-null, this is the path to a temporary file that - * is to be deleted when the stream is closed */ -#if HAVE_FLUSHIO - char last_op; -#endif - -#if HAVE_MMAP - char *last_mapped_addr; - size_t last_mapped_len; -#endif -#ifdef PHP_WIN32 - char *last_mapped_addr; - HANDLE file_mapping; -#endif -} php_stdio_stream_data; - -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); - if (stream) { - return stream; - } - close(fd); - - php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to allocate stream"); - - return NULL; - } - return NULL; -} - -PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC TSRMLS_DC) -{ - char *opened_path = NULL; - int fd = php_open_temporary_fd(NULL, "php", &opened_path TSRMLS_CC); - - if (fd != -1) { - php_stream *stream = php_stream_fopen_from_fd_rel(fd, "r+b", NULL); - if (stream) { - php_stdio_stream_data *self = (php_stdio_stream_data*)stream->abstract; - - self->temp_file_name = opened_path; - self->lock_flag = LOCK_UN; - - return stream; - } - close(fd); - - php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to allocate stream"); - - return NULL; - } - return NULL; -} - -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; - -#ifdef S_ISFIFO - /* detect if this is a pipe */ - if (self->fd >= 0) { - struct stat sb; - self->is_pipe = (fstat(self->fd, &sb) == 0 && S_ISFIFO(sb.st_mode)) ? 1 : 0; - } -#elif defined(PHP_WIN32) - { - long handle = _get_osfhandle(self->fd); - DWORD in_buf_size, out_buf_size; - - if (handle != 0xFFFFFFFF) { - self->is_pipe = GetNamedPipeInfo((HANDLE)handle, NULL, &out_buf_size, &in_buf_size, NULL); - } - } -#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 { - stream->position = lseek(self->fd, 0, SEEK_CUR); - } - } - - return stream; -} - -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); - -#ifdef S_ISFIFO - /* detect if this is a pipe */ - if (self->fd >= 0) { - struct stat sb; - self->is_pipe = (fstat(self->fd, &sb) == 0 && S_ISFIFO(sb.st_mode)) ? 1 : 0; - } -#elif defined(PHP_WIN32) - { - long handle = _get_osfhandle(self->fd); - DWORD in_buf_size, out_buf_size; - - if (handle != 0xFFFFFFFF) { - self->is_pipe = GetNamedPipeInfo((HANDLE)handle, NULL, &out_buf_size, &in_buf_size, NULL); - } - } -#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 { - stream->position = ftell(file); - } - } - - return stream; -} - -PHPAPI php_stream *_php_stream_fopen_from_pipe(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 = 1; - self->lock_flag = LOCK_UN; - self->is_process_pipe = 1; - self->fd = fileno(file); - self->temp_file_name = NULL; - - stream = php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode); - stream->flags |= PHP_STREAM_FLAG_NO_SEEK; - return stream; -} - -#define PHP_STDIOP_GET_FD(anfd, data) anfd = (data)->file ? fileno((data)->file) : (data)->fd - -static size_t php_stdiop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) -{ - php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; - - assert(data != NULL); - - if (data->fd >= 0) { - int bytes_written = write(data->fd, buf, count); - if (bytes_written < 0) return 0; - return (size_t) bytes_written; - } else { - -#if HAVE_FLUSHIO - if (!data->is_pipe && data->last_op == 'r') { - fseek(data->file, 0, SEEK_CUR); - } - data->last_op = 'w'; -#endif - - return fwrite(buf, 1, count, data->file); - } -} - -static size_t php_stdiop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) -{ - php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; - size_t ret; - - assert(data != NULL); - - if (data->fd >= 0) { - ret = read(data->fd, buf, count); - - stream->eof = (ret == 0 || (ret == -1 && errno != EWOULDBLOCK)); - - } else { -#if HAVE_FLUSHIO - if (!data->is_pipe && data->last_op == 'w') - fseek(data->file, 0, SEEK_CUR); - data->last_op = 'r'; -#endif - - ret = fread(buf, 1, count, data->file); - - stream->eof = feof(data->file); - } - return ret; -} - -static int php_stdiop_close(php_stream *stream, int close_handle TSRMLS_DC) -{ - int ret; - php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; - - assert(data != NULL); - -#if HAVE_MMAP - if (data->last_mapped_addr) { - munmap(data->last_mapped_addr, data->last_mapped_len); - data->last_mapped_addr = NULL; - } -#elif defined(PHP_WIN32) - if (data->last_mapped_addr) { - UnmapViewOfFile(data->last_mapped_addr); - data->last_mapped_addr = NULL; - } - if (data->file_mapping) { - CloseHandle(data->file_mapping); - data->file_mapping = NULL; - } -#endif - - if (close_handle) { - if (data->lock_flag != LOCK_UN) { - php_stream_lock(stream, LOCK_UN); - } - if (data->file) { - if (data->is_process_pipe) { - errno = 0; - ret = pclose(data->file); - -#if HAVE_SYS_WAIT_H - if (WIFEXITED(ret)) { - ret = WEXITSTATUS(ret); - } -#endif - } else { - ret = fclose(data->file); - data->file = NULL; - } - } else if (data->fd != -1) { - ret = close(data->fd); - data->fd = -1; - } else { - return 0; /* everything should be closed already -> success */ - } - if (data->temp_file_name) { - unlink(data->temp_file_name); - /* temporary streams are never persistent */ - efree(data->temp_file_name); - data->temp_file_name = NULL; - } - } else { - ret = 0; - data->file = NULL; - data->fd = -1; - } - - pefree(data, stream->is_persistent); - - return ret; -} - -static int php_stdiop_flush(php_stream *stream TSRMLS_DC) -{ - php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; - - assert(data != NULL); - - /* - * stdio buffers data in user land. By calling fflush(3), this - * data is send to the kernel using write(2). fsync'ing is - * something completely different. - */ - if (data->file) { - return fflush(data->file); - } - return 0; -} - -static int php_stdiop_seek(php_stream *stream, off_t offset, int whence, off_t *newoffset TSRMLS_DC) -{ - php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; - int ret; - - assert(data != NULL); - - if (data->is_pipe) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot seek on a pipe"); - return -1; - } - - if (data->fd >= 0) { - off_t result; - - result = lseek(data->fd, offset, whence); - if (result == (off_t)-1) - return -1; - - *newoffset = result; - return 0; - - } else { - ret = fseek(data->file, offset, whence); - *newoffset = ftell(data->file); - return ret; - } -} - -static int php_stdiop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC) -{ - int fd; - php_stdio_stream_data *data = (php_stdio_stream_data*) stream->abstract; - - assert(data != NULL); - - /* as soon as someone touches the stdio layer, buffering may ensue, - * so we need to stop using the fd directly in that case */ - - switch (castas) { - case PHP_STREAM_AS_STDIO: - if (ret) { - - if (data->file == NULL) { - /* we were opened as a plain file descriptor, so we - * need fdopen now */ - data->file = fdopen(data->fd, stream->mode); - } - - *(FILE**)ret = data->file; - data->fd = -1; - } - return SUCCESS; - - case PHP_STREAM_AS_FD_FOR_SELECT: - PHP_STDIOP_GET_FD(fd, data); - if (fd < 0) { - return FAILURE; - } - if (ret) { - *(int*)ret = fd; - } - return SUCCESS; - - case PHP_STREAM_AS_FD: - PHP_STDIOP_GET_FD(fd, data); - - if (fd < 0) { - return FAILURE; - } - if (data->file) { - fflush(data->file); - } - if (ret) { - *(int*)ret = fd; - } - return SUCCESS; - default: - return FAILURE; - } -} - -static int php_stdiop_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC) -{ - int fd; - php_stdio_stream_data *data = (php_stdio_stream_data*) stream->abstract; - - assert(data != NULL); - - PHP_STDIOP_GET_FD(fd, data); - - return fstat(fd, &ssb->sb); -} - -static int php_stdiop_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC) -{ - php_stdio_stream_data *data = (php_stdio_stream_data*) stream->abstract; - size_t size; - int fd; -#ifdef O_NONBLOCK - /* FIXME: make this work for win32 */ - int flags; - int oldval; -#endif - - PHP_STDIOP_GET_FD(fd, data); - - switch(option) { - case PHP_STREAM_OPTION_BLOCKING: - if (fd == -1) - return -1; -#ifdef O_NONBLOCK - flags = fcntl(fd, F_GETFL, 0); - oldval = (flags & O_NONBLOCK) ? 0 : 1; - if (value) - flags ^= O_NONBLOCK; - else - flags |= O_NONBLOCK; - - if (-1 == fcntl(fd, F_SETFL, flags)) - return -1; - return oldval; -#else - return -1; /* not yet implemented */ -#endif - - case PHP_STREAM_OPTION_WRITE_BUFFER: - - if (data->file == NULL) { - return -1; - } - - if (ptrparam) - size = *(size_t *)ptrparam; - else - size = BUFSIZ; - - switch(value) { - case PHP_STREAM_BUFFER_NONE: - stream->flags |= PHP_STREAM_FLAG_NO_BUFFER; - return setvbuf(data->file, NULL, _IONBF, 0); - - case PHP_STREAM_BUFFER_LINE: - stream->flags ^= PHP_STREAM_FLAG_NO_BUFFER; - return setvbuf(data->file, NULL, _IOLBF, size); - - case PHP_STREAM_BUFFER_FULL: - stream->flags ^= PHP_STREAM_FLAG_NO_BUFFER; - return setvbuf(data->file, NULL, _IOFBF, size); - - default: - return -1; - } - break; - - case PHP_STREAM_OPTION_LOCKING: - if (fd == -1) { - return -1; - } - - if ((long) ptrparam == PHP_STREAM_LOCK_SUPPORTED) { - return 0; - } - - if (!flock(fd, value) || (errno == EWOULDBLOCK && value & LOCK_NB)) { - data->lock_flag = value; - return 0; - } else { - return -1; - } - break; - - case PHP_STREAM_OPTION_MMAP_API: -#if HAVE_MMAP - { - php_stream_mmap_range *range = (php_stream_mmap_range*)ptrparam; - struct stat sbuf; - int prot, flags; - - switch (value) { - case PHP_STREAM_MMAP_SUPPORTED: - return fd == -1 ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK; - - case PHP_STREAM_MMAP_MAP_RANGE: - fstat(fd, &sbuf); - if (range->length == 0 || range->length > sbuf.st_size) { - range->length = sbuf.st_size; - } - switch (range->mode) { - case PHP_STREAM_MAP_MODE_READONLY: - prot = PROT_READ; - flags = MAP_PRIVATE; - break; - case PHP_STREAM_MAP_MODE_READWRITE: - prot = PROT_READ | PROT_WRITE; - flags = MAP_PRIVATE; - break; - case PHP_STREAM_MAP_MODE_SHARED_READONLY: - prot = PROT_READ; - flags = MAP_SHARED; - break; - case PHP_STREAM_MAP_MODE_SHARED_READWRITE: - prot = PROT_READ | PROT_WRITE; - flags = MAP_SHARED; - break; - default: - return PHP_STREAM_OPTION_RETURN_ERR; - } - range->mapped = (char*)mmap(NULL, range->length, prot, flags, fd, range->offset); - if (range->mapped == (char*)MAP_FAILED) { - range->mapped = NULL; - return PHP_STREAM_OPTION_RETURN_ERR; - } - /* remember the mapping */ - data->last_mapped_addr = range->mapped; - data->last_mapped_len = range->length; - return PHP_STREAM_OPTION_RETURN_OK; - - case PHP_STREAM_MMAP_UNMAP: - if (data->last_mapped_addr) { - munmap(data->last_mapped_addr, data->last_mapped_len); - data->last_mapped_addr = NULL; - - return PHP_STREAM_OPTION_RETURN_OK; - } - return PHP_STREAM_OPTION_RETURN_ERR; - } - } -#elif defined(PHP_WIN32) - { - php_stream_mmap_range *range = (php_stream_mmap_range*)ptrparam; - HANDLE hfile = (HANDLE)_get_osfhandle(fd); - DWORD prot, acc, loffs = 0, delta = 0; - - switch (value) { - case PHP_STREAM_MMAP_SUPPORTED: - return hfile == INVALID_HANDLE_VALUE ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK; - - case PHP_STREAM_MMAP_MAP_RANGE: - switch (range->mode) { - case PHP_STREAM_MAP_MODE_READONLY: - prot = PAGE_READONLY; - acc = FILE_MAP_READ; - break; - case PHP_STREAM_MAP_MODE_READWRITE: - prot = PAGE_READWRITE; - acc = FILE_MAP_READ | FILE_MAP_WRITE; - break; - case PHP_STREAM_MAP_MODE_SHARED_READONLY: - prot = PAGE_READONLY; - acc = FILE_MAP_READ; - /* TODO: we should assign a name for the mapping */ - break; - case PHP_STREAM_MAP_MODE_SHARED_READWRITE: - prot = PAGE_READWRITE; - acc = FILE_MAP_READ | FILE_MAP_WRITE; - /* TODO: we should assign a name for the mapping */ - break; - } - - /* create a mapping capable of viewing the whole file (this costs no real resources) */ - data->file_mapping = CreateFileMapping(hfile, NULL, prot, 0, 0, NULL); - - if (data->file_mapping == NULL) { - return PHP_STREAM_OPTION_RETURN_ERR; - } - - if (range->length == 0) { - range->length = GetFileSize(hfile, NULL) - range->offset; - } - - /* figure out how big a chunk to map to be able to view the part that we need */ - if (range->offset != 0) { - SYSTEM_INFO info; - DWORD gran; - - GetSystemInfo(&info); - gran = info.dwAllocationGranularity; - loffs = (range->offset / gran) * gran; - delta = range->offset - loffs; - } - - data->last_mapped_addr = MapViewOfFile(data->file_mapping, acc, 0, loffs, range->length); - - if (data->last_mapped_addr) { - /* give them back the address of the start offset they requested */ - range->mapped = data->last_mapped_addr + delta; - return PHP_STREAM_OPTION_RETURN_OK; - } - - CloseHandle(data->file_mapping); - data->file_mapping = NULL; - - return PHP_STREAM_OPTION_RETURN_ERR; - - case PHP_STREAM_MMAP_UNMAP: - if (data->last_mapped_addr) { - UnmapViewOfFile(data->last_mapped_addr); - data->last_mapped_addr = NULL; - CloseHandle(data->file_mapping); - data->file_mapping = NULL; - return PHP_STREAM_OPTION_RETURN_OK; - } - return PHP_STREAM_OPTION_RETURN_ERR; - - default: - return PHP_STREAM_OPTION_RETURN_ERR; - } - } - -#endif - return PHP_STREAM_OPTION_RETURN_NOTIMPL; - - case PHP_STREAM_OPTION_TRUNCATE_API: - switch (value) { - 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; - } - - default: - return PHP_STREAM_OPTION_RETURN_NOTIMPL; - } -} - -PHPAPI php_stream_ops php_stream_stdio_ops = { - php_stdiop_write, php_stdiop_read, - php_stdiop_close, php_stdiop_flush, - "STDIO", - php_stdiop_seek, - php_stdiop_cast, - php_stdiop_stat, - php_stdiop_set_option -}; -/* }}} */ - -/* {{{ plain files opendir/readdir implementation */ -static size_t php_plain_files_dirstream_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) -{ - DIR *dir = (DIR*)stream->abstract; - /* avoid libc5 readdir problems */ - char entry[sizeof(struct dirent)+MAXPATHLEN]; - struct dirent *result = (struct dirent *)&entry; - php_stream_dirent *ent = (php_stream_dirent*)buf; - - /* avoid problems if someone mis-uses the stream */ - if (count != sizeof(php_stream_dirent)) - return 0; - - if (php_readdir_r(dir, (struct dirent *)entry, &result) == 0 && result) { - PHP_STRLCPY(ent->d_name, result->d_name, sizeof(ent->d_name), strlen(result->d_name)); - return sizeof(php_stream_dirent); - } - return 0; -} - -static int php_plain_files_dirstream_close(php_stream *stream, int close_handle TSRMLS_DC) -{ - return closedir((DIR *)stream->abstract); -} - -static int php_plain_files_dirstream_rewind(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) -{ - rewinddir((DIR *)stream->abstract); - return 0; -} - -static php_stream_ops php_plain_files_dirstream_ops = { - NULL, php_plain_files_dirstream_read, - php_plain_files_dirstream_close, NULL, - "dir", - php_plain_files_dirstream_rewind, - NULL, /* cast */ - NULL, /* stat */ - NULL /* set_option */ -}; - -static php_stream *php_plain_files_dir_opener(php_stream_wrapper *wrapper, char *path, char *mode, - int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) -{ - DIR *dir = NULL; - php_stream *stream = NULL; - - if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path TSRMLS_CC)) { - return NULL; - } - - if (PG(safe_mode) &&(!php_checkuid(path, NULL, CHECKUID_ALLOW_ONLY_FILE))) { - return NULL; - } - - dir = VCWD_OPENDIR(path); - -#ifdef PHP_WIN32 - if (dir && dir->finished) { - closedir(dir); - dir = NULL; - } -#endif - if (dir) { - stream = php_stream_alloc(&php_plain_files_dirstream_ops, dir, 0, mode); - if (stream == NULL) - closedir(dir); - } - - return stream; -} -/* }}} */ - - -static php_stream *php_plain_files_stream_opener(php_stream_wrapper *wrapper, char *path, char *mode, - int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) -{ - if ((options & USE_PATH) && PG(include_path) != NULL) { - return php_stream_fopen_with_path_rel(path, mode, PG(include_path), opened_path, options); - } - - if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path TSRMLS_CC)) { - return NULL; - } - - if ((options & ENFORCE_SAFE_MODE) && PG(safe_mode) && (!php_checkuid(path, mode, CHECKUID_CHECK_MODE_PARAM))) - return NULL; - - return php_stream_fopen_rel(path, mode, opened_path, options); -} - -static int php_plain_files_url_stater(php_stream_wrapper *wrapper, char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC) -{ - - if (strncmp(url, "file://", sizeof("file://") - 1) == 0) { - url += sizeof("file://") - 1; - } - - if (PG(safe_mode) &&(!php_checkuid_ex(url, NULL, CHECKUID_CHECK_FILE_AND_DIR, (flags & PHP_STREAM_URL_STAT_QUIET) ? CHECKUID_NO_ERRORS : 0))) { - return -1; - } - - if (php_check_open_basedir_ex(url, (flags & PHP_STREAM_URL_STAT_QUIET) ? 0 : 1 TSRMLS_CC)) { - return -1; - } - -#ifdef HAVE_SYMLINK - if (flags & PHP_STREAM_URL_STAT_LINK) { - return VCWD_LSTAT(url, &ssb->sb); - } else -#endif - return VCWD_STAT(url, &ssb->sb); -} - -static int php_plain_files_unlink(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC) -{ - char *p; - int ret; - zval funcname; - zval *retval = NULL; - - if ((p = strstr(url, "://")) != NULL) { - url = p + 3; - } - - if (options & ENFORCE_SAFE_MODE) { - if (PG(safe_mode) && !php_checkuid(url, NULL, CHECKUID_CHECK_FILE_AND_DIR)) { - return 0; - } - - if (php_check_open_basedir(url TSRMLS_CC)) { - return 0; - } - } - - ret = VCWD_UNLINK(url); - if (ret == -1) { - if (options & REPORT_ERRORS) { - php_error_docref1(NULL TSRMLS_CC, url, E_WARNING, "%s", strerror(errno)); - } - return 0; - } - /* Clear stat cache */ - ZVAL_STRINGL(&funcname, "clearstatcache", sizeof("clearstatcache")-1, 0); - call_user_function_ex(CG(function_table), NULL, &funcname, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (retval) { - zval_ptr_dtor(&retval); - } - return 1; -} - -static int php_plain_files_rename(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC) -{ - char *p; - int ret; - - if (!url_from || !url_to) { - return 0; - } - - if ((p = strstr(url_from, "://")) != NULL) { - url_from = p + 3; - } - - if ((p = strstr(url_to, "://")) != NULL) { - url_to = p + 3; - } - - if (PG(safe_mode) && (!php_checkuid(url_from, NULL, CHECKUID_CHECK_FILE_AND_DIR) || - !php_checkuid(url_to, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - return 0; - } - - if (php_check_open_basedir(url_from TSRMLS_CC) || php_check_open_basedir(url_to TSRMLS_CC)) { - return 0; - } - - ret = VCWD_RENAME(url_from, url_to); - - if (ret == -1) { -#ifdef EXDEV - if (errno == EXDEV) { - if (php_copy_file(url_from, url_to TSRMLS_CC) == SUCCESS) { - VCWD_UNLINK(url_from); - return 1; - } - } -#endif - php_error_docref2(NULL TSRMLS_CC, url_from, url_to, E_WARNING, "%s", strerror(errno)); - return 0; - } - - return 1; -} - -static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mode, int options, php_stream_context *context TSRMLS_DC) -{ - int ret, recursive = options & PHP_STREAM_MKDIR_RECURSIVE; - char *p; - - if ((p = strstr(dir, "://")) != NULL) { - dir = p + 3; - } - - if (!recursive) { - ret = php_mkdir(dir, mode TSRMLS_CC); - } else { - /* we look for directory separator from the end of string, thus hopefuly reducing our work load */ - char *e, *buf; - struct stat sb; - int dir_len = strlen(dir); - - buf = estrndup(dir, dir_len); - e = buf + dir_len; - - /* find a top level directory we need to create */ - while ((p = strrchr(buf, DEFAULT_SLASH))) { - *p = '\0'; - if (VCWD_STAT(buf, &sb) == 0) { - *p = DEFAULT_SLASH; - break; - } - } - if (p == buf) { - ret = php_mkdir(dir, mode TSRMLS_CC); - } else if (!(ret = php_mkdir(buf, mode TSRMLS_CC))) { - if (!p) { - p = buf; - } - /* create any needed directories if the creation of the 1st directory worked */ - while (++p != e) { - if (*p == '\0' && *(p + 1) != '\0') { - *p = DEFAULT_SLASH; - if ((ret = VCWD_MKDIR(buf, (mode_t)mode)) < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); - break; - } - } - } - } - efree(buf); - } - if (ret < 0) { - /* Failure */ - return 0; - } else { - /* Success */ - return 1; - } -} - -static int php_plain_files_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC) -{ - if (PG(safe_mode) &&(!php_checkuid(url, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - return 0; - } - - if (php_check_open_basedir(url TSRMLS_CC)) { - return 0; - } - - if (VCWD_RMDIR(url) < 0) { - php_error_docref1(NULL TSRMLS_CC, url, E_WARNING, "%s", strerror(errno)); - return 0; - } - - return 1; -} - -static php_stream_wrapper_ops php_plain_files_wrapper_ops = { - php_plain_files_stream_opener, - NULL, - NULL, - php_plain_files_url_stater, - php_plain_files_dir_opener, - "plainfile", - php_plain_files_unlink, - php_plain_files_rename, - php_plain_files_mkdir, - php_plain_files_rmdir -}; - -php_stream_wrapper php_plain_files_wrapper = { - &php_plain_files_wrapper_ops, - NULL, - 0 -}; - -/* {{{ php_stream_fopen_with_path */ -PHPAPI php_stream *_php_stream_fopen_with_path(char *filename, char *mode, char *path, char **opened_path, int options STREAMS_DC TSRMLS_DC) -{ - /* code ripped off from fopen_wrappers.c */ - char *pathbuf, *ptr, *end; - char *exec_fname; - char trypath[MAXPATHLEN]; - struct stat sb; - php_stream *stream; - int path_length; - int filename_length; - int exec_fname_length; - - if (opened_path) { - *opened_path = NULL; - } - - if(!filename) { - return NULL; - } - - filename_length = strlen(filename); - - /* Relative path open */ - if (*filename == '.' && (IS_SLASH(filename[1]) || filename[1] == '.')) { - /* further checks, we could have ....... filenames */ - ptr = filename + 1; - if (*ptr == '.') { - while (*(++ptr) == '.'); - if (!IS_SLASH(*ptr)) { /* not a relative path after all */ - goto not_relative_path; - } - } - - - if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(filename TSRMLS_CC)) { - return NULL; - } - - if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM))) { - return NULL; - } - return php_stream_fopen_rel(filename, mode, opened_path, options); - } - - /* - * files in safe_mode_include_dir (or subdir) are excluded from - * safe mode GID/UID checks - */ - -not_relative_path: - - /* Absolute path open */ - if (IS_ABSOLUTE_PATH(filename, filename_length)) { - - if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(filename TSRMLS_CC)) { - return NULL; - } - - if ((php_check_safe_mode_include_dir(filename TSRMLS_CC)) == 0) - /* filename is in safe_mode_include_dir (or subdir) */ - return php_stream_fopen_rel(filename, mode, opened_path, options); - - if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM))) - return NULL; - - return php_stream_fopen_rel(filename, mode, opened_path, options); - } - -#ifdef PHP_WIN32 - if (IS_SLASH(filename[0])) { - int cwd_len; - char *cwd; - cwd = virtual_getcwd_ex(&cwd_len TSRMLS_CC); - /* getcwd() will return always return [DRIVE_LETTER]:/) on windows. */ - *(cwd+3) = '\0'; - - snprintf(trypath, MAXPATHLEN, "%s%s", cwd, filename); - - free(cwd); - - if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(trypath TSRMLS_CC)) { - return NULL; - } - if ((php_check_safe_mode_include_dir(trypath TSRMLS_CC)) == 0) { - return php_stream_fopen_rel(trypath, mode, opened_path, options); - } - if (PG(safe_mode) && (!php_checkuid(trypath, mode, CHECKUID_CHECK_MODE_PARAM))) { - return NULL; - } - - return php_stream_fopen_rel(trypath, mode, opened_path, options); - } -#endif - - if (!path || (path && !*path)) { - - if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path TSRMLS_CC)) { - return NULL; - } - - if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM))) { - return NULL; - } - return php_stream_fopen_rel(filename, mode, opened_path, options); - } - - /* check in provided path */ - /* append the calling scripts' current working directory - * as a fall back case - */ - if (zend_is_executing(TSRMLS_C)) { - exec_fname = zend_get_executed_filename(TSRMLS_C); - exec_fname_length = strlen(exec_fname); - path_length = strlen(path); - - while ((--exec_fname_length >= 0) && !IS_SLASH(exec_fname[exec_fname_length])); - if ((exec_fname && exec_fname[0] == '[') - || exec_fname_length<=0) { - /* [no active file] or no path */ - pathbuf = estrdup(path); - } else { - pathbuf = (char *) emalloc(exec_fname_length + path_length +1 +1); - memcpy(pathbuf, path, path_length); - pathbuf[path_length] = DEFAULT_DIR_SEPARATOR; - memcpy(pathbuf+path_length+1, exec_fname, exec_fname_length); - pathbuf[path_length + exec_fname_length +1] = '\0'; - } - } else { - pathbuf = estrdup(path); - } - - ptr = pathbuf; - - while (ptr && *ptr) { - end = strchr(ptr, DEFAULT_DIR_SEPARATOR); - if (end != NULL) { - *end = '\0'; - end++; - } - snprintf(trypath, MAXPATHLEN, "%s/%s", ptr, filename); - - if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(trypath TSRMLS_CC)) { - stream = NULL; - goto stream_done; - } - - if (PG(safe_mode)) { - if (VCWD_STAT(trypath, &sb) == 0) { - /* file exists ... check permission */ - if ((php_check_safe_mode_include_dir(trypath TSRMLS_CC) == 0) || - php_checkuid(trypath, mode, CHECKUID_CHECK_MODE_PARAM)) { - /* UID ok, or trypath is in safe_mode_include_dir */ - stream = php_stream_fopen_rel(trypath, mode, opened_path, options); - } else { - stream = NULL; - } - goto stream_done; - } - } - stream = php_stream_fopen_rel(trypath, mode, opened_path, options); - if (stream) { -stream_done: - efree(pathbuf); - return stream; - } - ptr = end; - } /* end provided path */ - - efree(pathbuf); - return NULL; - -} -/* }}} */ - - - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/main/streams/streams.c b/main/streams/streams.c deleted file mode 100755 index ece1870ce1..0000000000 --- a/main/streams/streams.c +++ /dev/null @@ -1,1844 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Wez Furlong <wez@thebrainroom.com> | - | Borrowed code from: | - | Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - | Jim Winstead <jimw@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#define _GNU_SOURCE -#include "php.h" -#include "php_globals.h" -#include "php_network.h" -#include "php_open_temporary_file.h" -#include "ext/standard/file.h" -#include "ext/standard/basic_functions.h" /* for BG(mmap_file) (not strictly required) */ -#include "ext/standard/php_string.h" /* for php_memnstr, used by php_stream_get_record() */ -#include <stddef.h> -#include <fcntl.h> -#include "php_streams_int.h" - -/* {{{ resource and registration code */ -static HashTable url_stream_wrappers_hash; -static int le_stream = FAILURE; /* true global */ -static int le_pstream = FAILURE; /* true global */ - -PHPAPI int php_file_le_stream(void) -{ - return le_stream; -} - -PHPAPI int php_file_le_pstream(void) -{ - return le_pstream; -} - -PHPAPI HashTable *php_stream_get_url_stream_wrappers_hash() -{ - return &url_stream_wrappers_hash; -} - -static int _php_stream_release_context(list_entry *le, void *pContext TSRMLS_DC) -{ - if (le->ptr == pContext) { - return --le->refcount == 0; - } - return 0; -} - -static int forget_persistent_resource_id_numbers(zend_rsrc_list_entry *rsrc TSRMLS_DC) -{ - php_stream *stream; - - if (Z_TYPE_P(rsrc) != le_pstream) { - return 0; - } - - stream = (php_stream*)rsrc->ptr; - -#if STREAM_DEBUG -fprintf(stderr, "forget_persistent: %s:%p\n", stream->ops->label, stream); -#endif - - stream->rsrc_id = FAILURE; - - if (stream->context) { - zend_hash_apply_with_argument(&EG(regular_list), - (apply_func_arg_t) _php_stream_release_context, - stream->context TSRMLS_CC); - stream->context = NULL; - } - - return 0; -} - -PHP_RSHUTDOWN_FUNCTION(streams) -{ - zend_hash_apply(&EG(persistent_list), (apply_func_t)forget_persistent_resource_id_numbers TSRMLS_CC); - return SUCCESS; -} - -PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream **stream TSRMLS_DC) -{ - zend_rsrc_list_entry *le; - - if (zend_hash_find(&EG(persistent_list), (char*)persistent_id, strlen(persistent_id)+1, (void*) &le) == SUCCESS) { - if (Z_TYPE_P(le) == le_pstream) { - if (stream) { - *stream = (php_stream*)le->ptr; - le->refcount++; - (*stream)->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, *stream, le_pstream); - } - return PHP_STREAM_PERSISTENT_SUCCESS; - } - return PHP_STREAM_PERSISTENT_FAILURE; - } - return PHP_STREAM_PERSISTENT_NOT_EXIST; -} - -/* }}} */ - -/* {{{ wrapper error reporting */ -void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, const char *path, const char *caption TSRMLS_DC) -{ - char *tmp = estrdup(path); - char *msg; - int free_msg = 0; - - if (wrapper) { - if (wrapper->err_count > 0) { - int i; - size_t l; - int brlen; - char *br; - - if (PG(html_errors)) { - brlen = 7; - br = "<br />\n"; - } else { - brlen = 1; - br = "\n"; - } - - for (i = 0, l = 0; i < wrapper->err_count; i++) { - l += strlen(wrapper->err_stack[i]); - if (i < wrapper->err_count - 1) { - l += brlen; - } - } - msg = emalloc(l + 1); - msg[0] = '\0'; - for (i = 0; i < wrapper->err_count; i++) { - strcat(msg, wrapper->err_stack[i]); - if (i < wrapper->err_count - 1) { - strcat(msg, br); - } - } - - free_msg = 1; - } else { - msg = strerror(errno); - } - } else { - msg = "no suitable wrapper could be found"; - } - - php_strip_url_passwd(tmp); - php_error_docref1(NULL TSRMLS_CC, tmp, E_WARNING, "%s: %s", caption, msg); - efree(tmp); - if (free_msg) { - efree(msg); - } -} - -void php_stream_tidy_wrapper_error_log(php_stream_wrapper *wrapper TSRMLS_DC) -{ - if (wrapper) { - /* tidy up the error stack */ - int i; - - for (i = 0; i < wrapper->err_count; i++) { - efree(wrapper->err_stack[i]); - } - if (wrapper->err_stack) { - efree(wrapper->err_stack); - } - wrapper->err_stack = NULL; - wrapper->err_count = 0; - } -} - -PHPAPI void php_stream_wrapper_log_error(php_stream_wrapper *wrapper, int options TSRMLS_DC, const char *fmt, ...) -{ - va_list args; - char *buffer = NULL; - - va_start(args, fmt); - vspprintf(&buffer, 0, fmt, args); - va_end(args); - - if (options & REPORT_ERRORS || wrapper == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", buffer); - efree(buffer); - } else { - /* append to stack */ - wrapper->err_stack = erealloc(wrapper->err_stack, (wrapper->err_count + 1) * sizeof(char *)); - if (wrapper->err_stack) { - wrapper->err_stack[wrapper->err_count++] = buffer; - } - } -} - - -/* }}} */ - -/* allocate a new stream for a particular ops */ -PHPAPI php_stream *_php_stream_alloc(php_stream_ops *ops, void *abstract, const char *persistent_id, const char *mode STREAMS_DC TSRMLS_DC) /* {{{ */ -{ - php_stream *ret; - - ret = (php_stream*) pemalloc_rel_orig(sizeof(php_stream), persistent_id ? 1 : 0); - - memset(ret, 0, sizeof(php_stream)); - -#if STREAM_DEBUG -fprintf(stderr, "stream_alloc: %s:%p persistent=%s\n", ops->label, ret, persistent_id); -#endif - - ret->ops = ops; - ret->abstract = abstract; - ret->is_persistent = persistent_id ? 1 : 0; - ret->chunk_size = FG(def_chunk_size); - - if (FG(auto_detect_line_endings)) { - ret->flags |= PHP_STREAM_FLAG_DETECT_EOL; - } - - if (persistent_id) { - zend_rsrc_list_entry le; - - Z_TYPE(le) = le_pstream; - le.ptr = ret; - le.refcount = 0; - - if (FAILURE == zend_hash_update(&EG(persistent_list), (char *)persistent_id, - strlen(persistent_id) + 1, - (void *)&le, sizeof(le), NULL)) { - - pefree(ret, 1); - return NULL; - } - } - - ret->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, ret, persistent_id ? le_pstream : le_stream); - strlcpy(ret->mode, mode, sizeof(ret->mode)); - - return ret; -} -/* }}} */ - -static int _php_stream_free_persistent(list_entry *le, void *pStream TSRMLS_DC) -{ - return le->ptr == pStream; -} - -PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC) /* {{{ */ -{ - int ret = 1; - int remove_rsrc = 1; - int preserve_handle = close_options & PHP_STREAM_FREE_PRESERVE_HANDLE ? 1 : 0; - int release_cast = 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 - - /* recursion protection */ - if (stream->in_free) { - return 1; - } - - stream->in_free++; - - /* if we are releasing the stream only (and preserving the underlying handle), - * we need to do things a little differently. - * We are only ever called like this when the stream is cast to a FILE* - * for include (or other similar) purposes. - * */ - if (preserve_handle) { - if (stream->fclose_stdiocast == PHP_STREAM_FCLOSE_FOPENCOOKIE) { - /* If the stream was fopencookied, we must NOT touch anything - * here, as the cookied stream relies on it all. - * Instead, mark the stream as OK to auto-clean */ - php_stream_auto_cleanup(stream); - stream->in_free--; - return 0; - } - /* otherwise, make sure that we don't close the FILE* from a cast */ - release_cast = 0; - } - -#if STREAM_DEBUG -fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remove_rsrc=%d\n", - stream->ops->label, stream, stream->orig_path, preserve_handle, release_cast, remove_rsrc); -#endif - - /* make sure everything is saved */ - _php_stream_flush(stream, 1 TSRMLS_CC); - - /* If not called from the resource dtor, remove the stream from the resource list. */ - if ((close_options & PHP_STREAM_FREE_RSRC_DTOR) == 0 && remove_rsrc) { - zend_list_delete(stream->rsrc_id); - } - - /* Remove stream from any context link list */ - if (stream->context && stream->context->links) { - php_stream_context_del_link(stream->context, stream); - } - - if (close_options & PHP_STREAM_FREE_CALL_DTOR) { - if (release_cast && stream->fclose_stdiocast == PHP_STREAM_FCLOSE_FOPENCOOKIE) { - /* calling fclose on an fopencookied stream will ultimately - call this very same function. If we were called via fclose, - the cookie_closer unsets the fclose_stdiocast flags, so - we can be sure that we only reach here when PHP code calls - php_stream_free. - Lets let the cookie code clean it all up. - */ - stream->in_free = 0; - return fclose(stream->stdiocast); - } - - ret = stream->ops->close(stream, preserve_handle ? 0 : 1 TSRMLS_CC); - stream->abstract = NULL; - - /* tidy up any FILE* that might have been fdopened */ - if (release_cast && stream->fclose_stdiocast == PHP_STREAM_FCLOSE_FDOPEN && stream->stdiocast) { - fclose(stream->stdiocast); - stream->stdiocast = NULL; - stream->fclose_stdiocast = PHP_STREAM_FCLOSE_NONE; - } - } - - if (close_options & PHP_STREAM_FREE_RELEASE_STREAM) { - while (stream->readfilters.head) { - php_stream_filter_remove(stream->readfilters.head, 1 TSRMLS_CC); - } - while (stream->writefilters.head) { - php_stream_filter_remove(stream->writefilters.head, 1 TSRMLS_CC); - } - - if (stream->wrapper && stream->wrapper->wops && stream->wrapper->wops->stream_closer) { - stream->wrapper->wops->stream_closer(stream->wrapper, stream TSRMLS_CC); - stream->wrapper = NULL; - } - - if (stream->wrapperdata) { - zval_ptr_dtor(&stream->wrapperdata); - stream->wrapperdata = NULL; - } - - if (stream->readbuf) { - pefree(stream->readbuf, stream->is_persistent); - stream->readbuf = NULL; - } - - if (stream->is_persistent && (close_options & PHP_STREAM_FREE_PERSISTENT)) { - /* we don't work with *stream but need its value for comparison */ - zend_hash_apply_with_argument(&EG(persistent_list), (apply_func_arg_t) _php_stream_free_persistent, stream TSRMLS_CC); - } -#if ZEND_DEBUG - if ((close_options & PHP_STREAM_FREE_RSRC_DTOR) && (stream->__exposed == 0) && (EG(error_reporting) & E_WARNING)) { - /* it leaked: Lets deliberately NOT pefree it so that the memory manager shows it - * as leaked; it will log a warning, but lets help it out and display what kind - * of stream it was. */ - char *leakinfo; - spprintf(&leakinfo, 0, __FILE__ "(%d) : Stream of type '%s' %p (path:%s) was not closed\n", __LINE__, stream->ops->label, stream, stream->orig_path); - - if (stream->orig_path) { - pefree(stream->orig_path, stream->is_persistent); - stream->orig_path = NULL; - } - -# if defined(PHP_WIN32) - OutputDebugString(leakinfo); -# else - fprintf(stderr, "%s", leakinfo); -# endif - efree(leakinfo); - } else { - if (stream->orig_path) { - pefree(stream->orig_path, stream->is_persistent); - stream->orig_path = NULL; - } - - pefree(stream, stream->is_persistent); - } -#else - if (stream->orig_path) { - pefree(stream->orig_path, stream->is_persistent); - stream->orig_path = NULL; - } - - pefree(stream, stream->is_persistent); -#endif - } - - return ret; -} -/* }}} */ - -/* {{{ generic stream operations */ - -static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_DC) -{ - /* allocate/fill the buffer */ - - if (stream->readfilters.head) { - char *chunk_buf; - int err_flag = 0; - php_stream_bucket_brigade brig_in = { NULL, NULL }, brig_out = { NULL, NULL }; - php_stream_bucket_brigade *brig_inp = &brig_in, *brig_outp = &brig_out, *brig_swap; - - /* allocate a buffer for reading chunks */ - chunk_buf = emalloc(stream->chunk_size); - - while (!err_flag && (stream->writepos - stream->readpos < (off_t)size)) { - size_t justread = 0; - int flags; - php_stream_bucket *bucket; - php_stream_filter_status_t status = PSFS_ERR_FATAL; - php_stream_filter *filter; - - /* read a chunk into a bucket */ - justread = stream->ops->read(stream, chunk_buf, stream->chunk_size TSRMLS_CC); - if (justread > 0) { - bucket = php_stream_bucket_new(stream, chunk_buf, justread, 0, 0 TSRMLS_CC); - - /* after this call, bucket is owned by the brigade */ - php_stream_bucket_append(brig_inp, bucket TSRMLS_CC); - - flags = PSFS_FLAG_NORMAL; - } else { - flags = stream->eof ? PSFS_FLAG_FLUSH_CLOSE : PSFS_FLAG_FLUSH_INC; - } - - /* wind the handle... */ - for (filter = stream->readfilters.head; filter; filter = filter->next) { - status = filter->fops->filter(stream, filter, brig_inp, brig_outp, NULL, flags TSRMLS_CC); - - if (status != PSFS_PASS_ON) { - break; - } - - /* brig_out becomes brig_in. - * brig_in will always be empty here, as the filter MUST attach any un-consumed buckets - * to its own brigade */ - brig_swap = brig_inp; - brig_inp = brig_outp; - brig_outp = brig_swap; - memset(brig_outp, 0, sizeof(*brig_outp)); - } - - switch (status) { - case PSFS_PASS_ON: - /* we get here when the last filter in the chain has data to pass on. - * in this situation, we are passing the brig_in brigade into the - * stream read buffer */ - while (brig_inp->head) { - bucket = brig_inp->head; - /* grow buffer to hold this bucket - * TODO: this can fail for persistent streams */ - if (stream->readbuflen - stream->writepos < bucket->buflen) { - stream->readbuflen += bucket->buflen; - stream->readbuf = perealloc(stream->readbuf, stream->readbuflen, - stream->is_persistent); - } - memcpy(stream->readbuf + stream->writepos, bucket->buf, bucket->buflen); - stream->writepos += bucket->buflen; - - php_stream_bucket_unlink(bucket TSRMLS_CC); - php_stream_bucket_delref(bucket TSRMLS_CC); - } - - break; - - case PSFS_FEED_ME: - /* when a filter needs feeding, there is no brig_out to deal with. - * we simply continue the loop; if the caller needs more data, - * we will read again, otherwise out job is done here */ - if (justread == 0) { - /* there is no data */ - err_flag = 1; - break; - } - continue; - - case PSFS_ERR_FATAL: - /* some fatal error. Theoretically, the stream is borked, so all - * further reads should fail. */ - err_flag = 1; - break; - } - - if (justread == 0) { - break; - } - } - - efree(chunk_buf); - - } else { - /* is there enough data in the buffer ? */ - if (stream->writepos - stream->readpos < (off_t)size) { - size_t justread = 0; - - /* reduce buffer memory consumption if possible, to avoid a realloc */ - if (stream->readbuf && stream->readbuflen - stream->writepos < stream->chunk_size) { - memmove(stream->readbuf, stream->readbuf + stream->readpos, stream->readbuflen - stream->readpos); - stream->writepos -= stream->readpos; - stream->readpos = 0; - } - - /* grow the buffer if required - * TODO: this can fail for persistent streams */ - if (stream->readbuflen - stream->writepos < stream->chunk_size) { - stream->readbuflen += stream->chunk_size; - stream->readbuf = perealloc(stream->readbuf, stream->readbuflen, - stream->is_persistent); - } - - justread = stream->ops->read(stream, stream->readbuf + stream->writepos, - stream->readbuflen - stream->writepos - TSRMLS_CC); - - if (justread != (size_t)-1) { - stream->writepos += justread; - } - } - } -} - -PHPAPI size_t _php_stream_read(php_stream *stream, char *buf, size_t size TSRMLS_DC) -{ - size_t toread = 0, didread = 0; - - while (size > 0) { - - /* take from the read buffer first. - * It is possible that a buffered stream was switched to non-buffered, so we - * drain the remainder of the buffer before using the "raw" read mode for - * the excess */ - if (stream->writepos > stream->readpos) { - - toread = stream->writepos - stream->readpos; - if (toread > size) { - toread = size; - } - - memcpy(buf, stream->readbuf + stream->readpos, toread); - stream->readpos += toread; - size -= toread; - buf += toread; - didread += toread; - } - - /* ignore eof here; the underlying state might have changed */ - if (size == 0) { - break; - } - - if (!stream->readfilters.head && (stream->flags & PHP_STREAM_FLAG_NO_BUFFER || stream->chunk_size == 1)) { - toread = stream->ops->read(stream, buf, size TSRMLS_CC); - } else { - php_stream_fill_read_buffer(stream, size TSRMLS_CC); - - toread = stream->writepos - stream->readpos; - if (toread > size) { - toread = size; - } - - if (toread > 0) { - memcpy(buf, stream->readbuf + stream->readpos, toread); - stream->readpos += toread; - } - } - if (toread > 0) { - didread += toread; - buf += toread; - size -= toread; - } else { - /* EOF, or temporary end of data (for non-blocking mode). */ - break; - } - } - - if (didread > 0) { - stream->position += didread; - } - - return didread; -} - -PHPAPI int _php_stream_eof(php_stream *stream TSRMLS_DC) -{ - /* if there is data in the buffer, it's not EOF */ - if (stream->writepos - stream->readpos > 0) { - return 0; - } - - if (!stream->eof && PHP_STREAM_OPTION_RETURN_ERR == - php_stream_set_option(stream, PHP_STREAM_OPTION_CHECK_LIVENESS, - 0, NULL)) { - stream->eof = 1; - } - - return stream->eof; -} - -PHPAPI int _php_stream_putc(php_stream *stream, int c TSRMLS_DC) -{ - unsigned char buf = c; - - if (php_stream_write(stream, &buf, 1) > 0) { - return 1; - } - return EOF; -} - -PHPAPI int _php_stream_getc(php_stream *stream TSRMLS_DC) -{ - char buf; - - if (php_stream_read(stream, &buf, 1) > 0) { - return buf & 0xff; - } - return EOF; -} - -PHPAPI int _php_stream_puts(php_stream *stream, char *buf TSRMLS_DC) -{ - int len; - char newline[2] = "\n"; /* is this OK for Win? */ - len = strlen(buf); - - if (len > 0 && php_stream_write(stream, buf, len) && php_stream_write(stream, newline, 1)) { - return 1; - } - return 0; -} - -PHPAPI int _php_stream_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC) -{ - memset(ssb, 0, sizeof(*ssb)); - - /* if the stream was wrapped, allow the wrapper to stat it */ - if (stream->wrapper && stream->wrapper->wops->stream_stat != NULL) { - return stream->wrapper->wops->stream_stat(stream->wrapper, stream, ssb TSRMLS_CC); - } - - /* if the stream doesn't directly support stat-ing, return with failure. - * We could try and emulate this by casting to a FD and fstat-ing it, - * but since the fd might not represent the actual underlying content - * this would give bogus results. */ - if (stream->ops->stat == NULL) { - return -1; - } - - return (stream->ops->stat)(stream, ssb TSRMLS_CC); -} - -PHPAPI char *php_stream_locate_eol(php_stream *stream, char *buf, size_t buf_len TSRMLS_DC) -{ - size_t avail; - char *cr, *lf, *eol = NULL; - char *readptr; - - if (!buf) { - readptr = stream->readbuf + stream->readpos; - avail = stream->writepos - stream->readpos; - } else { - readptr = buf; - avail = buf_len; - } - - /* Look for EOL */ - if (stream->flags & PHP_STREAM_FLAG_DETECT_EOL) { - cr = memchr(readptr, '\r', avail); - lf = memchr(readptr, '\n', avail); - - if (cr && lf != cr + 1 && !(lf && lf < cr)) { - /* mac */ - stream->flags ^= PHP_STREAM_FLAG_DETECT_EOL; - stream->flags |= PHP_STREAM_FLAG_EOL_MAC; - eol = cr; - } else if ((cr && lf && cr == lf - 1) || (lf)) { - /* dos or unix endings */ - stream->flags ^= PHP_STREAM_FLAG_DETECT_EOL; - eol = lf; - } - } else if (stream->flags & PHP_STREAM_FLAG_EOL_MAC) { - eol = memchr(readptr, '\r', avail); - } else { - /* unix (and dos) line endings */ - eol = memchr(readptr, '\n', avail); - } - - return eol; -} - -/* If buf == NULL, the buffer will be allocated automatically and will be of an - * appropriate length to hold the line, regardless of the line length, memory - * permitting */ -PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, - size_t *returned_len TSRMLS_DC) -{ - size_t avail = 0; - size_t current_buf_size = 0; - size_t total_copied = 0; - int grow_mode = 0; - char *bufstart = buf; - - if (buf == NULL) { - grow_mode = 1; - } else if (maxlen == 0) { - return NULL; - } - - /* - * If the underlying stream operations block when no new data is readable, - * we need to take extra precautions. - * - * If there is buffered data available, we check for a EOL. If it exists, - * we pass the data immediately back to the caller. This saves a call - * to the read implementation and will not block where blocking - * is not necessary at all. - * - * If the stream buffer contains more data than the caller requested, - * we can also avoid that costly step and simply return that data. - */ - - for (;;) { - avail = stream->writepos - stream->readpos; - - if (avail > 0) { - size_t cpysz = 0; - char *readptr; - char *eol; - int done = 0; - - readptr = stream->readbuf + stream->readpos; - eol = php_stream_locate_eol(stream, NULL, 0 TSRMLS_CC); - - if (eol) { - cpysz = eol - readptr + 1; - done = 1; - } else { - cpysz = avail; - } - - if (grow_mode) { - /* allow room for a NUL. If this realloc is really a realloc - * (ie: second time around), we get an extra byte. In most - * cases, with the default chunk size of 8K, we will only - * incur that overhead once. When people have lines longer - * than 8K, we waste 1 byte per additional 8K or so. - * That seems acceptable to me, to avoid making this code - * hard to follow */ - bufstart = erealloc(bufstart, current_buf_size + cpysz + 1); - current_buf_size += cpysz + 1; - buf = bufstart + total_copied; - } else { - if (cpysz >= maxlen - 1) { - cpysz = maxlen - 1; - done = 1; - } - } - - memcpy(buf, readptr, cpysz); - - stream->position += cpysz; - stream->readpos += cpysz; - buf += cpysz; - maxlen -= cpysz; - total_copied += cpysz; - - if (done) { - break; - } - } else if (stream->eof) { - break; - } else { - /* XXX: Should be fine to always read chunk_size */ - size_t toread; - - if (grow_mode) { - toread = stream->chunk_size; - } else { - toread = maxlen - 1; - if (toread > stream->chunk_size) { - toread = stream->chunk_size; - } - } - - php_stream_fill_read_buffer(stream, toread TSRMLS_CC); - - if (stream->writepos - stream->readpos == 0) { - break; - } - } - } - - if (total_copied == 0) { - if (grow_mode) { - assert(bufstart == NULL); - } - return NULL; - } - - buf[0] = '\0'; - if (returned_len) { - *returned_len = total_copied; - } - - return bufstart; -} - -PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, char *delim, size_t delim_len TSRMLS_DC) -{ - char *e, *buf; - size_t toread; - - php_stream_fill_read_buffer(stream, maxlen TSRMLS_CC); - - if (delim_len == 0) { - toread = maxlen; - } else { - if (delim_len == 1) { - e = memchr(stream->readbuf, *delim, stream->readbuflen); - } else { - e = php_memnstr(stream->readbuf, delim, delim_len, (stream->readbuf + stream->readbuflen)); - } - - if (!e) { - toread = maxlen; - } else { - toread = e - (char *) stream->readbuf; - } - } - - if (toread > maxlen && maxlen > 0) { - toread = maxlen; - } - - buf = emalloc(toread + 1); - *returned_len = php_stream_read(stream, buf, toread); - - if (*returned_len >= 0) { - return buf; - } else { - efree(buf); - return NULL; - } -} - -/* Writes a buffer directly to a stream, using multiple of the chunk size */ -static size_t _php_stream_write_buffer(php_stream *stream, const char *buf, size_t count TSRMLS_DC) -{ - size_t didwrite = 0, towrite, justwrote; - - /* if we have a seekable stream we need to ensure that data is written at the - * current stream->position. This means invalidating the read buffer and then - * performing a low-level seek */ - if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) { - stream->readpos = stream->writepos = 0; - - stream->ops->seek(stream, stream->position, SEEK_SET, &stream->position TSRMLS_CC); - } - - - while (count > 0) { - towrite = count; - if (towrite > stream->chunk_size) - towrite = stream->chunk_size; - - justwrote = stream->ops->write(stream, buf, towrite TSRMLS_CC); - - /* convert justwrote to an integer, since normally it is unsigned */ - if ((int)justwrote > 0) { - buf += justwrote; - count -= justwrote; - didwrite += justwrote; - - /* Only screw with the buffer if we can seek, otherwise we lose data - * buffered from fifos and sockets */ - if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) { - stream->position += justwrote; - } - } else { - break; - } - } - return didwrite; - -} - -/* push some data through the write filter chain. - * buf may be NULL, if flags are set to indicate a flush. - * This may trigger a real write to the stream. - * Returns the number of bytes consumed from buf by the first filter in the chain. - * */ -static size_t _php_stream_write_filtered(php_stream *stream, const char *buf, size_t count, int flags TSRMLS_DC) -{ - size_t consumed = 0; - php_stream_bucket *bucket; - php_stream_bucket_brigade brig_in = { NULL, NULL }, brig_out = { NULL, NULL }; - php_stream_bucket_brigade *brig_inp = &brig_in, *brig_outp = &brig_out, *brig_swap; - php_stream_filter_status_t status = PSFS_ERR_FATAL; - php_stream_filter *filter; - - if (buf) { - bucket = php_stream_bucket_new(stream, (char *)buf, count, 0, 0 TSRMLS_CC); - php_stream_bucket_append(&brig_in, bucket TSRMLS_CC); - } - - for (filter = stream->writefilters.head; filter; filter = filter->next) { - /* for our return value, we are interested in the number of bytes consumed from - * the first filter in the chain */ - status = filter->fops->filter(stream, filter, brig_inp, brig_outp, - filter == stream->writefilters.head ? &consumed : NULL, flags TSRMLS_CC); - - if (status != PSFS_PASS_ON) { - break; - } - /* brig_out becomes brig_in. - * brig_in will always be empty here, as the filter MUST attach any un-consumed buckets - * to its own brigade */ - brig_swap = brig_inp; - brig_inp = brig_outp; - brig_outp = brig_swap; - memset(brig_outp, 0, sizeof(*brig_outp)); - } - - switch (status) { - case PSFS_PASS_ON: - /* filter chain generated some output; push it through to the - * underlying stream */ - while (brig_inp->head) { - bucket = brig_inp->head; - _php_stream_write_buffer(stream, bucket->buf, bucket->buflen TSRMLS_CC); - /* Potential error situation - eg: no space on device. Perhaps we should keep this brigade - * hanging around and try to write it later. - * At the moment, we just drop it on the floor - * */ - - php_stream_bucket_unlink(bucket TSRMLS_CC); - php_stream_bucket_delref(bucket TSRMLS_CC); - } - break; - case PSFS_FEED_ME: - /* need more data before we can push data through to the stream */ - break; - - case PSFS_ERR_FATAL: - /* some fatal error. Theoretically, the stream is borked, so all - * further writes should fail. */ - break; - } - - return consumed; -} - -PHPAPI int _php_stream_flush(php_stream *stream, int closing TSRMLS_DC) -{ - int ret = 0; - - if (stream->writefilters.head) { - _php_stream_write_filtered(stream, NULL, 0, closing ? PSFS_FLAG_FLUSH_CLOSE : PSFS_FLAG_FLUSH_INC TSRMLS_CC); - } - - if (stream->ops->flush) { - ret = stream->ops->flush(stream TSRMLS_CC); - } - - return ret; -} - -PHPAPI size_t _php_stream_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) -{ - if (buf == NULL || count == 0 || stream->ops->write == NULL) { - return 0; - } - - if (stream->writefilters.head) { - return _php_stream_write_filtered(stream, buf, count, PSFS_FLAG_NORMAL TSRMLS_CC); - } else { - return _php_stream_write_buffer(stream, buf, count TSRMLS_CC); - } -} - -PHPAPI size_t _php_stream_printf(php_stream *stream TSRMLS_DC, const char *fmt, ...) -{ - size_t count; - char *buf; - va_list ap; - - va_start(ap, fmt); - count = vspprintf(&buf, 0, fmt, ap); - va_end(ap); - - if (!buf) { - return 0; /* error condition */ - } - - count = php_stream_write(stream, buf, count); - efree(buf); - - return count; -} - -PHPAPI off_t _php_stream_tell(php_stream *stream TSRMLS_DC) -{ - return stream->position; -} - -PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_DC) -{ - /* handle the case where we are in the buffer */ - if ((stream->flags & PHP_STREAM_FLAG_NO_BUFFER) == 0) { - switch(whence) { - case SEEK_CUR: - if (offset > 0 && offset < stream->writepos - stream->readpos) { - stream->readpos += offset; - stream->position += offset; - stream->eof = 0; - return 0; - } - break; - case SEEK_SET: - if (offset > stream->position && - offset < stream->position + stream->writepos - stream->readpos) { - stream->readpos += offset - stream->position; - stream->position = offset; - stream->eof = 0; - return 0; - } - break; - } - } - - - if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) { - int ret; - - if (stream->writefilters.head) { - _php_stream_flush(stream, 0 TSRMLS_CC); - } - - switch(whence) { - case SEEK_CUR: - offset = stream->position + offset; - whence = SEEK_SET; - break; - } - ret = stream->ops->seek(stream, offset, whence, &stream->position TSRMLS_CC); - - if (((stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) || ret == 0) { - if (ret == 0) { - stream->eof = 0; - } - - /* invalidate the buffer contents */ - stream->readpos = stream->writepos = 0; - - return ret; - } - /* else the stream has decided that it can't support seeking after all; - * fall through to attempt emulation */ - } - - /* emulate forward moving seeks with reads */ - if (whence == SEEK_CUR && offset > 0) { - char tmp[1024]; - while(offset >= sizeof(tmp)) { - if (php_stream_read(stream, tmp, sizeof(tmp)) == 0) { - return -1; - } - offset -= sizeof(tmp); - } - if (offset && (php_stream_read(stream, tmp, offset) == 0)) { - return -1; - } - stream->eof = 0; - return 0; - } - - php_error_docref(NULL TSRMLS_CC, E_WARNING, "stream does not support seeking"); - - return -1; -} - -PHPAPI int _php_stream_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC) -{ - int ret = PHP_STREAM_OPTION_RETURN_NOTIMPL; - - if (stream->ops->set_option) { - ret = stream->ops->set_option(stream, option, value, ptrparam TSRMLS_CC); - } - - if (ret == PHP_STREAM_OPTION_RETURN_NOTIMPL) { - switch(option) { - case PHP_STREAM_OPTION_SET_CHUNK_SIZE: - ret = stream->chunk_size; - stream->chunk_size = value; - return ret; - - case PHP_STREAM_OPTION_READ_BUFFER: - /* try to match the buffer mode as best we can */ - if (value == PHP_STREAM_BUFFER_NONE) { - stream->flags |= PHP_STREAM_FLAG_NO_BUFFER; - } else { - stream->flags ^= PHP_STREAM_FLAG_NO_BUFFER; - } - ret = PHP_STREAM_OPTION_RETURN_OK; - break; - - default: - ; - } - } - - return ret; -} - -PHPAPI int _php_stream_truncate_set_size(php_stream *stream, size_t newsize TSRMLS_DC) -{ - return php_stream_set_option(stream, PHP_STREAM_OPTION_TRUNCATE_API, PHP_STREAM_TRUNCATE_SET_SIZE, &newsize); -} - -PHPAPI size_t _php_stream_passthru(php_stream * stream STREAMS_DC TSRMLS_DC) -{ - size_t bcount = 0; - char buf[8192]; - int b; - - if (php_stream_mmap_possible(stream)) { - char *p; - size_t mapped; - - p = php_stream_mmap_range(stream, php_stream_tell(stream), 0, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped); - - if (p) { - PHPWRITE(p, mapped); - - php_stream_mmap_unmap(stream); - - return mapped; - } - } - - while ((b = php_stream_read(stream, buf, sizeof(buf))) > 0) { - PHPWRITE(buf, b); - bcount += b; - } - - return bcount; -} - - -PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen, int persistent STREAMS_DC TSRMLS_DC) -{ - size_t ret = 0; - char *ptr; - size_t len = 0, max_len; - int step = CHUNK_SIZE; - int min_room = CHUNK_SIZE / 4; - php_stream_statbuf ssbuf; - - if (buf) { - *buf = NULL; - } - - if (maxlen == 0) { - return 0; - } - - if (maxlen == PHP_STREAM_COPY_ALL) { - maxlen = 0; - } - - if (php_stream_mmap_possible(src)) { - char *p; - size_t mapped; - - p = php_stream_mmap_range(src, php_stream_tell(src), maxlen, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped); - - if (p) { - *buf = pemalloc_rel_orig(mapped + 1, persistent); - - if (*buf) { - memcpy(*buf, p, mapped); - (*buf)[mapped] = '\0'; - } - - php_stream_mmap_unmap(src); - - return mapped; - } - } - - /* avoid many reallocs by allocating a good sized chunk to begin with, if - * we can. Note that the stream may be filtered, in which case the stat - * result may be inaccurate, as the filter may inflate or deflate the - * number of bytes that we can read. In order to avoid an upsize followed - * by a downsize of the buffer, overestimate by the step size (which is - * 2K). */ - if (php_stream_stat(src, &ssbuf) == 0 && ssbuf.sb.st_size > 0) { - max_len = ssbuf.sb.st_size + step; - } else { - max_len = step; - } - - ptr = *buf = pemalloc_rel_orig(max_len, persistent); - - while((ret = php_stream_read(src, ptr, max_len - len))) { - len += ret; - if (len + min_room >= max_len) { - *buf = perealloc_rel_orig(*buf, max_len + step, persistent); - max_len += step; - ptr = *buf + len; - } - } - if (len) { - *buf = perealloc_rel_orig(*buf, len + 1, persistent); - (*buf)[len] = '\0'; - } else { - pefree(*buf, persistent); - *buf = NULL; - } - return len; -} - -PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, size_t maxlen STREAMS_DC TSRMLS_DC) -{ - char buf[CHUNK_SIZE]; - size_t readchunk; - size_t haveread = 0; - size_t didread; - php_stream_statbuf ssbuf; - - if (maxlen == 0) { - return 0; - } - - if (maxlen == PHP_STREAM_COPY_ALL) { - maxlen = 0; - } - - if (php_stream_stat(src, &ssbuf) == 0) { - /* in the event that the source file is 0 bytes, return 1 to indicate success - * because opening the file to write had already created a copy */ - if (ssbuf.sb.st_size == 0 -#ifdef S_ISFIFO - && !S_ISFIFO(ssbuf.sb.st_mode) -#endif -#ifdef S_ISCHR - && !S_ISCHR(ssbuf.sb.st_mode) -#endif - ) { - return 1; - } - } - - if (php_stream_mmap_possible(src)) { - char *p; - size_t mapped; - - p = php_stream_mmap_range(src, php_stream_tell(src), maxlen, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped); - - if (p) { - haveread = php_stream_write(dest, p, mapped); - - php_stream_mmap_unmap(src); - - return mapped; - } - } - - while(1) { - readchunk = sizeof(buf); - - if (maxlen && (maxlen - haveread) < readchunk) - readchunk = maxlen - haveread; - - didread = php_stream_read(src, buf, readchunk); - - if (didread) { - /* extra paranoid */ - size_t didwrite, towrite; - char *writeptr; - - towrite = didread; - writeptr = buf; - haveread += didread; - - while(towrite) { - didwrite = php_stream_write(dest, writeptr, towrite); - if (didwrite == 0) { - return 0; /* error */ - } - - towrite -= didwrite; - writeptr += didwrite; - } - } else { - if (maxlen == 0) { - return haveread; - } else { - return 0; /* error */ - } - } - - if (maxlen - haveread == 0) { - break; - } - } - return haveread; - -} -/* }}} */ - -/* {{{ wrapper init and registration */ - -static void stream_resource_regular_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) -{ - php_stream *stream = (php_stream*)rsrc->ptr; - /* set the return value for pclose */ - FG(pclose_ret) = php_stream_free(stream, PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_RSRC_DTOR); -} - -static void stream_resource_persistent_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) -{ - php_stream *stream = (php_stream*)rsrc->ptr; - FG(pclose_ret) = php_stream_free(stream, PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_RSRC_DTOR); -} - -int php_init_stream_wrappers(int module_number TSRMLS_DC) -{ - le_stream = zend_register_list_destructors_ex(stream_resource_regular_dtor, NULL, "stream", module_number); - le_pstream = zend_register_list_destructors_ex(NULL, stream_resource_persistent_dtor, "persistent stream", module_number); - - return ( - zend_hash_init(&url_stream_wrappers_hash, 0, NULL, NULL, 1) == SUCCESS - && - zend_hash_init(php_get_stream_filters_hash(), 0, NULL, NULL, 1) == SUCCESS - && - zend_hash_init(php_stream_xport_get_hash(), 0, NULL, NULL, 1) == SUCCESS - && - php_stream_xport_register("tcp", php_stream_generic_socket_factory TSRMLS_CC) == SUCCESS - && - php_stream_xport_register("udp", php_stream_generic_socket_factory TSRMLS_CC) == SUCCESS -#if defined(AF_UNIX) && !(defined(PHP_WIN32) || defined(__riscos__) || defined(NETWARE)) - && - php_stream_xport_register("unix", php_stream_generic_socket_factory TSRMLS_CC) == SUCCESS - && - php_stream_xport_register("udg", php_stream_generic_socket_factory TSRMLS_CC) == SUCCESS -#endif - ) ? SUCCESS : FAILURE; -} - -int php_shutdown_stream_wrappers(int module_number TSRMLS_DC) -{ - zend_hash_destroy(&url_stream_wrappers_hash); - zend_hash_destroy(php_get_stream_filters_hash()); - zend_hash_destroy(php_stream_xport_get_hash()); - return SUCCESS; -} - -PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC) -{ - return zend_hash_add(&url_stream_wrappers_hash, protocol, strlen(protocol), 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)); -} -/* }}} */ - -/* {{{ php_stream_locate_url_wrapper */ -PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char **path_for_open, int options TSRMLS_DC) -{ - php_stream_wrapper *wrapper = NULL; - const char *p, *protocol = NULL; - int n = 0; - - if (path_for_open) { - *path_for_open = (char*)path; - } - - if (options & IGNORE_URL) { - return (options & STREAM_LOCATE_WRAPPERS_ONLY) ? NULL : &php_plain_files_wrapper; - } - - for (p = path; isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'; p++) { - n++; - } - - if ((*p == ':') && (n > 1) && !strncmp("://", p, 3)) { - protocol = path; - } else if (strncasecmp(path, "zlib:", 5) == 0) { - /* BC with older php scripts and zlib wrapper */ - protocol = "compress.zlib"; - n = 13; - 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(&url_stream_wrappers_hash, (char*)protocol, n, (void**)&wrapper)) { - char wrapper_name[32]; - - if (n >= sizeof(wrapper_name)) - n = sizeof(wrapper_name) - 1; - PHP_STRLCPY(wrapper_name, protocol, sizeof(wrapper_name), n); - - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unable to find the wrapper \"%s\" - did you forget to enable it when you configured PHP?", - wrapper_name); - - wrapper = NULL; - protocol = NULL; - } - } - /* TODO: curl based streams probably support file:// properly */ - if (!protocol || !strncasecmp(protocol, "file", n)) { - if (protocol && path[n+1] == '/' && path[n+2] == '/' && path[n+3] != '/') { - if (options & REPORT_ERRORS) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "remote host file access not supported, %s", path); - } - return NULL; - } - if (protocol && path_for_open) { - /* skip past protocol and :/, but handle windows correctly */ - *path_for_open = (char*)path + n + 1; - while (*(++*path_for_open)=='/'); -#ifdef PHP_WIN32 - if (*(*path_for_open + 1) != ':') -#endif - (*path_for_open)--; - } - - /* fall back on regular file access */ - return (options & STREAM_LOCATE_WRAPPERS_ONLY) ? NULL : &php_plain_files_wrapper; - } - - if (wrapper && wrapper->is_url && !PG(allow_url_fopen)) { - if (options & REPORT_ERRORS) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "URL file-access is disabled in the server configuration"); - } - return NULL; - } - - return wrapper; -} -/* }}} */ - -/* {{{ _php_stream_mkdir - */ -PHPAPI int _php_stream_mkdir(char *path, int mode, int options, php_stream_context *context TSRMLS_DC) -{ - php_stream_wrapper *wrapper = NULL; - - wrapper = php_stream_locate_url_wrapper(path, NULL, ENFORCE_SAFE_MODE TSRMLS_CC); - if (!wrapper || !wrapper->wops || !wrapper->wops->stream_mkdir) { - return 0; - } - - return wrapper->wops->stream_mkdir(wrapper, path, mode, options, context TSRMLS_CC); -} -/* }}} */ - -/* {{{ _php_stream_rmdir - */ -PHPAPI int _php_stream_rmdir(char *path, int options, php_stream_context *context TSRMLS_DC) -{ - php_stream_wrapper *wrapper = NULL; - - wrapper = php_stream_locate_url_wrapper(path, NULL, ENFORCE_SAFE_MODE TSRMLS_CC); - if (!wrapper || !wrapper->wops || !wrapper->wops->stream_rmdir) { - return 0; - } - - return wrapper->wops->stream_rmdir(wrapper, path, options, context TSRMLS_CC); -} -/* }}} */ - -/* {{{ _php_stream_stat_path */ -PHPAPI int _php_stream_stat_path(char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC) -{ - php_stream_wrapper *wrapper = NULL; - char *path_to_open = path; - int ret; - - /* Try to hit the cache first */ - if (flags & PHP_STREAM_URL_STAT_LINK) { - if (BG(CurrentLStatFile) && strcmp(path, BG(CurrentLStatFile)) == 0) { - memcpy(ssb, &BG(lssb), sizeof(php_stream_statbuf)); - return 0; - } - } else { - if (BG(CurrentStatFile) && strcmp(path, BG(CurrentStatFile)) == 0) { - memcpy(ssb, &BG(ssb), sizeof(php_stream_statbuf)); - return 0; - } - } - - wrapper = php_stream_locate_url_wrapper(path, &path_to_open, ENFORCE_SAFE_MODE TSRMLS_CC); - if (wrapper && wrapper->wops->url_stat) { - ret = wrapper->wops->url_stat(wrapper, path_to_open, flags, ssb, context TSRMLS_CC); - if (ret == 0) { - /* Drop into cache */ - if (flags & PHP_STREAM_URL_STAT_LINK) { - if (BG(CurrentLStatFile)) { - efree(BG(CurrentLStatFile)); - } - BG(CurrentLStatFile) = estrdup(path); - memcpy(&BG(lssb), ssb, sizeof(php_stream_statbuf)); - } else { - if (BG(CurrentStatFile)) { - efree(BG(CurrentStatFile)); - } - BG(CurrentStatFile) = estrdup(path); - memcpy(&BG(ssb), ssb, sizeof(php_stream_statbuf)); - } - } - return ret; - } - return -1; -} -/* }}} */ - -/* {{{ php_stream_opendir */ -PHPAPI php_stream *_php_stream_opendir(char *path, int options, - php_stream_context *context STREAMS_DC TSRMLS_DC) -{ - php_stream *stream = NULL; - php_stream_wrapper *wrapper = NULL; - char *path_to_open; - - if (!path || !*path) { - return NULL; - } - - path_to_open = path; - - wrapper = php_stream_locate_url_wrapper(path, &path_to_open, options TSRMLS_CC); - - if (wrapper && wrapper->wops->dir_opener) { - stream = wrapper->wops->dir_opener(wrapper, - path_to_open, "r", options ^ REPORT_ERRORS, NULL, - context STREAMS_REL_CC TSRMLS_CC); - - if (stream) { - stream->wrapper = wrapper; - stream->flags |= PHP_STREAM_FLAG_NO_BUFFER; - } - } else if (wrapper) { - php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS TSRMLS_CC, "not implemented"); - } - if (stream == NULL && (options & REPORT_ERRORS)) { - php_stream_display_wrapper_errors(wrapper, path, "failed to open dir" TSRMLS_CC); - } - php_stream_tidy_wrapper_error_log(wrapper TSRMLS_CC); - - return stream; -} -/* }}} */ - -/* {{{ _php_stream_readdir */ -PHPAPI php_stream_dirent *_php_stream_readdir(php_stream *dirstream, php_stream_dirent *ent TSRMLS_DC) -{ - - if (sizeof(php_stream_dirent) == php_stream_read(dirstream, (char*)ent, sizeof(php_stream_dirent))) { - return ent; - } - - return NULL; -} -/* }}} */ - -/* {{{ php_stream_open_wrapper_ex */ -PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int options, - char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) -{ - php_stream *stream = NULL; - php_stream_wrapper *wrapper = NULL; - char *path_to_open; - int persistent = options & STREAM_OPEN_PERSISTENT; - char *copy_of_path = NULL; - - - if (opened_path) { - *opened_path = NULL; - } - - if (!path || !*path) { - return NULL; - } - - path_to_open = path; - - wrapper = php_stream_locate_url_wrapper(path, &path_to_open, options TSRMLS_CC); - if (options & STREAM_USE_URL && (!wrapper || !wrapper->is_url)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "This function may only be used against URLs."); - return NULL; - } - - if (wrapper) { - - 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 */ - if (stream && (options & STREAM_OPEN_PERSISTENT) && !stream->is_persistent) { - php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS TSRMLS_CC, - "wrapper does not support persistent streams"); - php_stream_close(stream); - stream = NULL; - } - - if (stream) { - stream->wrapper = wrapper; - } - } - - if (stream) { - copy_of_path = pestrdup(path, persistent); - stream->orig_path = copy_of_path; - } - - if (stream != NULL && (options & STREAM_MUST_SEEK)) { - php_stream *newstream; - - switch(php_stream_make_seekable_rel(stream, &newstream, - (options & STREAM_WILL_CAST) - ? PHP_STREAM_PREFER_STDIO : PHP_STREAM_NO_PREFERENCE)) { - case PHP_STREAM_UNCHANGED: - return stream; - case PHP_STREAM_RELEASED: - newstream->orig_path = pestrdup(path, persistent); - return newstream; - default: - php_stream_close(stream); - stream = NULL; - if (options & REPORT_ERRORS) { - char *tmp = estrdup(path); - php_strip_url_passwd(tmp); - php_error_docref1(NULL TSRMLS_CC, tmp, E_WARNING, "could not make seekable - %s", - tmp); - efree(tmp); - - options ^= REPORT_ERRORS; - } - } - } - - if (stream && stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0 && strchr(mode, 'a') && stream->position == 0) { - off_t newpos = 0; - - /* if opened for append, we need to revise our idea of the initial file position */ - if (0 == stream->ops->seek(stream, 0, SEEK_CUR, &newpos TSRMLS_CC)) { - stream->position = newpos; - } - } - - if (stream == NULL && (options & REPORT_ERRORS)) { - php_stream_display_wrapper_errors(wrapper, path, "failed to open stream" TSRMLS_CC); - } - php_stream_tidy_wrapper_error_log(wrapper TSRMLS_CC); -#if ZEND_DEBUG - if (stream == NULL && copy_of_path != NULL) { - pefree(copy_of_path, persistent); - } -#endif - return stream; -} -/* }}} */ - -/* {{{ context API */ -PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context) -{ - php_stream_context *oldcontext = stream->context; - stream->context = context; - return oldcontext; -} - -PHPAPI void php_stream_notification_notify(php_stream_context *context, int notifycode, int severity, - char *xmsg, int xcode, size_t bytes_sofar, size_t bytes_max, void * ptr TSRMLS_DC) -{ - if (context && context->notifier) - context->notifier->func(context, notifycode, severity, xmsg, xcode, bytes_sofar, bytes_max, ptr TSRMLS_CC); -} - -PHPAPI void php_stream_context_free(php_stream_context *context) -{ - if (context->options) { - zval_ptr_dtor(&context->options); - context->options = NULL; - } - if (context->notifier) { - php_stream_notification_free(context->notifier); - context->notifier = NULL; - } - if (context->links) { - zval_ptr_dtor(&context->links); - context->links = NULL; - } - efree(context); -} - -PHPAPI php_stream_context *php_stream_context_alloc(void) -{ - php_stream_context *context; - - context = ecalloc(1, sizeof(php_stream_context)); - context->notifier = NULL; - MAKE_STD_ZVAL(context->options); - array_init(context->options); - - context->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, context, php_le_stream_context()); - return context; -} - -PHPAPI php_stream_notifier *php_stream_notification_alloc(void) -{ - return ecalloc(1, sizeof(php_stream_notifier)); -} - -PHPAPI void php_stream_notification_free(php_stream_notifier *notifier) -{ - if (notifier->dtor) { - notifier->dtor(notifier); - } - efree(notifier); -} - -PHPAPI int php_stream_context_get_option(php_stream_context *context, - const char *wrappername, const char *optionname, zval ***optionvalue) -{ - zval **wrapperhash; - - if (FAILURE == zend_hash_find(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)&wrapperhash)) { - return FAILURE; - } - return zend_hash_find(Z_ARRVAL_PP(wrapperhash), (char*)optionname, strlen(optionname)+1, (void**)optionvalue); -} - -PHPAPI int php_stream_context_set_option(php_stream_context *context, - const char *wrappername, const char *optionname, zval *optionvalue) -{ - zval **wrapperhash; - zval *category, *copied_val; - - ALLOC_INIT_ZVAL(copied_val); - *copied_val = *optionvalue; - zval_copy_ctor(copied_val); - INIT_PZVAL(copied_val); - - if (FAILURE == zend_hash_find(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)&wrapperhash)) { - MAKE_STD_ZVAL(category); - array_init(category); - if (FAILURE == zend_hash_update(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)&category, sizeof(zval *), NULL)) { - return FAILURE; - } - - wrapperhash = &category; - } - return zend_hash_update(Z_ARRVAL_PP(wrapperhash), (char*)optionname, strlen(optionname)+1, (void**)&copied_val, sizeof(zval *), NULL); -} - -PHPAPI int php_stream_context_get_link(php_stream_context *context, - const char *hostent, php_stream **stream) -{ - php_stream **pstream; - - if (!stream || !hostent || !context || !(context->links)) { - return FAILURE; - } - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(context->links), (char*)hostent, strlen(hostent)+1, (void**)&pstream)) { - *stream = *pstream; - return SUCCESS; - } - return FAILURE; -} - -PHPAPI int php_stream_context_set_link(php_stream_context *context, - const char *hostent, php_stream *stream) -{ - if (!context) { - return FAILURE; - } - if (!context->links) { - ALLOC_INIT_ZVAL(context->links); - array_init(context->links); - } - if (!stream) { - /* Delete any entry for <hostent> */ - return zend_hash_del(Z_ARRVAL_P(context->links), (char*)hostent, strlen(hostent)+1); - } - return zend_hash_update(Z_ARRVAL_P(context->links), (char*)hostent, strlen(hostent)+1, (void**)&stream, sizeof(php_stream *), NULL); -} - -PHPAPI int php_stream_context_del_link(php_stream_context *context, - php_stream *stream) -{ - php_stream **pstream; - char *hostent; - int ret = SUCCESS; - - if (!context || !context->links || !stream) { - return FAILURE; - } - - for(zend_hash_internal_pointer_reset(Z_ARRVAL_P(context->links)); - SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(context->links), (void**)&pstream); - zend_hash_move_forward(Z_ARRVAL_P(context->links))) { - if (*pstream == stream) { - if (SUCCESS == zend_hash_get_current_key(Z_ARRVAL_P(context->links), &hostent, NULL, 0)) { - if (FAILURE == zend_hash_del(Z_ARRVAL_P(context->links), (char*)hostent, strlen(hostent)+1)) { - ret = FAILURE; - } - } else { - ret = FAILURE; - } - } - } - - return ret; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/main/streams/transports.c b/main/streams/transports.c deleted file mode 100644 index 5b2c0d89bb..0000000000 --- a/main/streams/transports.c +++ /dev/null @@ -1,487 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "php_streams_int.h" -#include "ext/standard/file.h" - -static HashTable xport_hash; - -PHPAPI HashTable *php_stream_xport_get_hash(void) -{ - return &xport_hash; -} - -PHPAPI int php_stream_xport_register(char *protocol, php_stream_transport_factory factory TSRMLS_DC) -{ - return zend_hash_update(&xport_hash, protocol, strlen(protocol), &factory, sizeof(factory), NULL); -} - -PHPAPI int php_stream_xport_unregister(char *protocol TSRMLS_DC) -{ - return zend_hash_del(&xport_hash, protocol, strlen(protocol)); -} - -#define ERR_REPORT(out_err, fmt, arg) \ - if (out_err) { spprintf(out_err, 0, fmt, arg); } \ - else { php_error_docref(NULL TSRMLS_CC, E_WARNING, fmt, arg); } - -#define ERR_RETURN(out_err, local_err, fmt) \ - if (out_err) { *out_err = local_err; } \ - else { php_error_docref(NULL TSRMLS_CC, E_WARNING, fmt, local_err ? local_err : "Unspecified error"); \ - if (local_err) { efree(local_err); local_err = NULL; } \ - } - -PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int options, - int flags, const char *persistent_id, - struct timeval *timeout, - php_stream_context *context, - char **error_string, - int *error_code - STREAMS_DC TSRMLS_DC) -{ - php_stream *stream = NULL; - php_stream_transport_factory *factory = NULL; - const char *p, *protocol = NULL; - int n = 0, failed = 0; - char *error_text = NULL; - struct timeval default_timeout = { 0, 0 }; - - default_timeout.tv_sec = FG(default_socket_timeout); - - if (timeout == NULL) { - timeout = &default_timeout; - } - - /* check for a cached persistent socket */ - if (persistent_id) { - switch(php_stream_from_persistent_id(persistent_id, &stream TSRMLS_CC)) { - case PHP_STREAM_PERSISTENT_SUCCESS: - if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_CHECK_LIVENESS, 0, NULL)) { - return stream; - } - /* dead - kill it */ - php_stream_pclose(stream); - stream = NULL; - - /* fall through */ - - case PHP_STREAM_PERSISTENT_FAILURE: - default: - /* failed; get a new one */ - ; - } - } - - for (p = name; isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'; p++) { - n++; - } - - if ((*p == ':') && (n > 1) && !strncmp("://", p, 3)) { - protocol = name; - name = p + 3; - namelen -= n + 3; - } else { - protocol = "tcp"; - n = 3; - } - - if (protocol) { - if (FAILURE == zend_hash_find(&xport_hash, (char*)protocol, n, (void**)&factory)) { - char wrapper_name[32]; - - if (n >= sizeof(wrapper_name)) - n = sizeof(wrapper_name) - 1; - PHP_STRLCPY(wrapper_name, protocol, sizeof(wrapper_name), n); - - ERR_REPORT(error_string, "Unable to find the socket transport \"%s\" - did you forget to enable it when you configured PHP?", - wrapper_name); - - return NULL; - } - } - - if (factory == NULL) { - /* should never happen */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not find a factory !?"); - return NULL; - } - - stream = (*factory)(protocol, n, - (char*)name, namelen, persistent_id, options, flags, timeout, - context STREAMS_REL_CC TSRMLS_CC); - - if (stream) { - stream->context = context; - - if ((flags & STREAM_XPORT_SERVER) == 0) { - /* client */ - - if (flags & STREAM_XPORT_CONNECT) { - if (0 != php_stream_xport_connect(stream, name, namelen, - flags & STREAM_XPORT_OP_CONNECT_ASYNC ? 1 : 0, - timeout, &error_text, error_code TSRMLS_CC)) { - - ERR_RETURN(error_string, error_text, "connect() failed: %s"); - - failed = 1; - } - } - - } else { - /* server */ - if (flags & STREAM_XPORT_BIND) { - if (0 != php_stream_xport_bind(stream, name, namelen, &error_text TSRMLS_CC)) { - ERR_RETURN(error_string, error_text, "bind() failed: %s"); - failed = 1; - } else if (flags & STREAM_XPORT_LISTEN) { - if (0 != php_stream_xport_listen(stream, 5, &error_text TSRMLS_CC)) { - ERR_RETURN(error_string, error_text, "listen() failed: %s"); - failed = 1; - } - } - } - } - } - - if (failed) { - /* failure means that they don't get a stream to play with */ - php_stream_close(stream); - stream = NULL; - } - - return stream; -} - -/* Bind the stream to a local address */ -PHPAPI int php_stream_xport_bind(php_stream *stream, - const char *name, long namelen, - char **error_text - TSRMLS_DC) -{ - php_stream_xport_param param; - int ret; - - memset(¶m, 0, sizeof(param)); - param.op = STREAM_XPORT_OP_BIND; - param.inputs.name = (char*)name; - param.inputs.namelen = namelen; - param.want_errortext = error_text ? 1 : 0; - - ret = php_stream_set_option(stream, PHP_STREAM_OPTION_XPORT_API, 0, ¶m); - - if (ret == PHP_STREAM_OPTION_RETURN_OK) { - if (error_text) { - *error_text = param.outputs.error_text; - } - - return param.outputs.returncode; - } - - return ret; -} - -/* Connect to a remote address */ -PHPAPI int php_stream_xport_connect(php_stream *stream, - const char *name, long namelen, - int asynchronous, - struct timeval *timeout, - char **error_text, - int *error_code - TSRMLS_DC) -{ - php_stream_xport_param param; - int ret; - - memset(¶m, 0, sizeof(param)); - param.op = asynchronous ? STREAM_XPORT_OP_CONNECT_ASYNC: STREAM_XPORT_OP_CONNECT; - param.inputs.name = (char*)name; - param.inputs.namelen = namelen; - param.inputs.timeout = timeout; - - param.want_errortext = error_text ? 1 : 0; - - ret = php_stream_set_option(stream, PHP_STREAM_OPTION_XPORT_API, 0, ¶m); - - if (ret == PHP_STREAM_OPTION_RETURN_OK) { - if (error_text) { - *error_text = param.outputs.error_text; - } - if (error_code) { - *error_code = param.outputs.error_code; - } - return param.outputs.returncode; - } - - return ret; - -} - -/* Prepare to listen */ -PHPAPI int php_stream_xport_listen(php_stream *stream, int backlog, char **error_text TSRMLS_DC) -{ - php_stream_xport_param param; - int ret; - - memset(¶m, 0, sizeof(param)); - param.op = STREAM_XPORT_OP_LISTEN; - param.inputs.backlog = backlog; - param.want_errortext = error_text ? 1 : 0; - - ret = php_stream_set_option(stream, PHP_STREAM_OPTION_XPORT_API, 0, ¶m); - - if (ret == PHP_STREAM_OPTION_RETURN_OK) { - if (error_text) { - *error_text = param.outputs.error_text; - } - - return param.outputs.returncode; - } - - return ret; -} - -/* Get the next client and their address (as a string) */ -PHPAPI int php_stream_xport_accept(php_stream *stream, php_stream **client, - char **textaddr, int *textaddrlen, - void **addr, socklen_t *addrlen, - struct timeval *timeout, - char **error_text - TSRMLS_DC) -{ - php_stream_xport_param param; - int ret; - - memset(¶m, 0, sizeof(param)); - - param.op = STREAM_XPORT_OP_ACCEPT; - param.inputs.timeout = timeout; - param.want_addr = addr ? 1 : 0; - param.want_textaddr = textaddr ? 1 : 0; - param.want_errortext = error_text ? 1 : 0; - - ret = php_stream_set_option(stream, PHP_STREAM_OPTION_XPORT_API, 0, ¶m); - - if (ret == PHP_STREAM_OPTION_RETURN_OK) { - *client = param.outputs.client; - if (addr) { - *addr = param.outputs.addr; - *addrlen = param.outputs.addrlen; - } - if (textaddr) { - *textaddr = param.outputs.textaddr; - *textaddrlen = param.outputs.textaddrlen; - } - if (error_text) { - *error_text = param.outputs.error_text; - } - - return param.outputs.returncode; - } - return ret; -} - -PHPAPI int php_stream_xport_get_name(php_stream *stream, int want_peer, - char **textaddr, int *textaddrlen, - void **addr, socklen_t *addrlen - TSRMLS_DC) -{ - php_stream_xport_param param; - int ret; - - memset(¶m, 0, sizeof(param)); - - param.op = want_peer ? STREAM_XPORT_OP_GET_PEER_NAME : STREAM_XPORT_OP_GET_NAME; - param.want_addr = addr ? 1 : 0; - param.want_textaddr = textaddr ? 1 : 0; - - ret = php_stream_set_option(stream, PHP_STREAM_OPTION_XPORT_API, 0, ¶m); - - if (ret == PHP_STREAM_OPTION_RETURN_OK) { - if (addr) { - *addr = param.outputs.addr; - *addrlen = param.outputs.addrlen; - } - if (textaddr) { - *textaddr = param.outputs.textaddr; - *textaddrlen = param.outputs.textaddrlen; - } - - return param.outputs.returncode; - } - return ret; -} - -PHPAPI int php_stream_xport_crypto_setup(php_stream *stream, php_stream_xport_crypt_method_t crypto_method, php_stream *session_stream TSRMLS_DC) -{ - php_stream_xport_crypto_param param; - int ret; - - memset(¶m, 0, sizeof(param)); - param.op = STREAM_XPORT_CRYPTO_OP_SETUP; - param.inputs.method = crypto_method; - param.inputs.session = session_stream; - - ret = php_stream_set_option(stream, PHP_STREAM_OPTION_CRYPTO_API, 0, ¶m); - - if (ret == PHP_STREAM_OPTION_RETURN_OK) { - return param.outputs.returncode; - } - - php_error_docref("streams.crypto" TSRMLS_CC, E_WARNING, "this stream does not support SSL/crypto"); - - return ret; -} - -PHPAPI int php_stream_xport_crypto_enable(php_stream *stream, int activate TSRMLS_DC) -{ - php_stream_xport_crypto_param param; - int ret; - - memset(¶m, 0, sizeof(param)); - param.op = STREAM_XPORT_CRYPTO_OP_ENABLE; - param.inputs.activate = activate; - - ret = php_stream_set_option(stream, PHP_STREAM_OPTION_CRYPTO_API, 0, ¶m); - - if (ret == PHP_STREAM_OPTION_RETURN_OK) { - return param.outputs.returncode; - } - - php_error_docref("streams.crypto" TSRMLS_CC, E_WARNING, "this stream does not support SSL/crypto"); - - return ret; -} - -/* Similar to recv() system call; read data from the stream, optionally - * peeking, optionally retrieving OOB data */ -PHPAPI int php_stream_xport_recvfrom(php_stream *stream, char *buf, size_t buflen, - long flags, void **addr, socklen_t *addrlen, char **textaddr, int *textaddrlen - TSRMLS_DC) -{ - php_stream_xport_param param; - int ret = 0; - int recvd_len = 0; - int oob; - - if (flags == 0 && addr == NULL) { - return php_stream_read(stream, buf, buflen); - } - - if (stream->readfilters.head) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot peek or fetch OOB data from a filtered stream"); - return -1; - } - - oob = (flags & STREAM_OOB) == STREAM_OOB; - - if (!oob && addr == NULL) { - /* must be peeking at regular data; copy content from the buffer - * first, then adjust the pointer/len before handing off to the - * stream */ - recvd_len = stream->writepos - stream->readpos; - if (recvd_len > buflen) { - recvd_len = buflen; - } - if (recvd_len) { - memcpy(buf, stream->readbuf, recvd_len); - buf += recvd_len; - buflen -= recvd_len; - } - /* if we filled their buffer, return */ - if (buflen == 0) { - return recvd_len; - } - } - - /* otherwise, we are going to bypass the buffer */ - - memset(¶m, 0, sizeof(param)); - - param.op = STREAM_XPORT_OP_RECV; - param.want_addr = addr ? 1 : 0; - param.want_textaddr = textaddr ? 1 : 0; - param.inputs.buf = buf; - param.inputs.buflen = buflen; - param.inputs.flags = flags; - - ret = php_stream_set_option(stream, PHP_STREAM_OPTION_XPORT_API, 0, ¶m); - - if (ret == PHP_STREAM_OPTION_RETURN_OK) { - if (addr) { - *addr = param.outputs.addr; - *addrlen = param.outputs.addrlen; - } - if (textaddr) { - *textaddr = param.outputs.textaddr; - *textaddrlen = param.outputs.textaddrlen; - } - return recvd_len + param.outputs.returncode; - } - return recvd_len ? recvd_len : -1; -} - -/* Similar to send() system call; send data to the stream, optionally - * 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) -{ - php_stream_xport_param param; - int ret = 0; - int oob; - - if (flags == 0 && addr == NULL) { - return php_stream_write(stream, buf, buflen); - } - - oob = (flags & STREAM_OOB) == STREAM_OOB; - - if ((oob || addr) && stream->writefilters.head) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot write OOB data, or data to a targeted address on a filtered stream"); - return -1; - } - - memset(¶m, 0, sizeof(param)); - - param.op = STREAM_XPORT_OP_SEND; - param.want_addr = addr ? 1 : 0; - param.inputs.buf = (char*)buf; - param.inputs.buflen = buflen; - param.inputs.flags = flags; - param.inputs.addr = addr; - param.inputs.addrlen = addrlen; - - ret = php_stream_set_option(stream, PHP_STREAM_OPTION_XPORT_API, 0, ¶m); - - if (ret == PHP_STREAM_OPTION_RETURN_OK) { - return param.outputs.returncode; - } - return -1; -} - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/main/streams/userspace.c b/main/streams/userspace.c deleted file mode 100644 index a016bb2abf..0000000000 --- a/main/streams/userspace.c +++ /dev/null @@ -1,1245 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Wez Furlong <wez@thebrainroom.com> | - | Sara Golemon <pollita@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "php_globals.h" -#include "ext/standard/file.h" - -static int le_protocols; - -struct php_user_stream_wrapper { - char * protoname; - char * classname; - zend_class_entry *ce; - php_stream_wrapper wrapper; -}; - -static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filename, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); -static int user_wrapper_stat_url(php_stream_wrapper *wrapper, char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC); -static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC); -static int user_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC); -static int user_wrapper_mkdir(php_stream_wrapper *wrapper, char *url, int mode, int options, php_stream_context *context TSRMLS_DC); -static int user_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC); -static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, char *filename, char *mode, - int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); - -static php_stream_wrapper_ops user_stream_wops = { - user_wrapper_opener, - NULL, /* close - the streams themselves know how */ - NULL, /* stat - the streams themselves know how */ - user_wrapper_stat_url, - user_wrapper_opendir, - "user-space", - user_wrapper_unlink, - user_wrapper_rename, - user_wrapper_mkdir, - user_wrapper_rmdir -}; - - -static void stream_wrapper_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) -{ - struct php_user_stream_wrapper * uwrap = (struct php_user_stream_wrapper*)rsrc->ptr; - - php_unregister_url_stream_wrapper(uwrap->protoname TSRMLS_CC); - efree(uwrap->protoname); - efree(uwrap->classname); - efree(uwrap); -} - - -PHP_MINIT_FUNCTION(user_streams) -{ - le_protocols = zend_register_list_destructors_ex(stream_wrapper_dtor, NULL, "stream factory", 0); - if (le_protocols == FAILURE) - return FAILURE; - - REGISTER_LONG_CONSTANT("STREAM_USE_PATH", USE_PATH, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_IGNORE_URL", IGNORE_URL, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_ENFORCE_SAFE_MODE", ENFORCE_SAFE_MODE, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_REPORT_ERRORS", REPORT_ERRORS, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_MUST_SEEK", STREAM_MUST_SEEK, CONST_CS|CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("STREAM_URL_STAT_LINK", PHP_STREAM_URL_STAT_LINK, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_URL_STAT_QUIET", PHP_STREAM_URL_STAT_QUIET, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_MKDIR_RECURSIVE", PHP_STREAM_MKDIR_RECURSIVE, CONST_CS|CONST_PERSISTENT); - - return SUCCESS; -} - -struct _php_userstream_data { - struct php_user_stream_wrapper * wrapper; - zval * object; -}; -typedef struct _php_userstream_data php_userstream_data_t; - -/* names of methods */ -#define USERSTREAM_OPEN "stream_open" -#define USERSTREAM_CLOSE "stream_close" -#define USERSTREAM_READ "stream_read" -#define USERSTREAM_WRITE "stream_write" -#define USERSTREAM_FLUSH "stream_flush" -#define USERSTREAM_SEEK "stream_seek" -#define USERSTREAM_TELL "stream_tell" -#define USERSTREAM_EOF "stream_eof" -#define USERSTREAM_STAT "stream_stat" -#define USERSTREAM_STATURL "url_stat" -#define USERSTREAM_UNLINK "unlink" -#define USERSTREAM_RENAME "rename" -#define USERSTREAM_MKDIR "mkdir" -#define USERSTREAM_RMDIR "rmdir" -#define USERSTREAM_DIR_OPEN "dir_opendir" -#define USERSTREAM_DIR_READ "dir_readdir" -#define USERSTREAM_DIR_REWIND "dir_rewinddir" -#define USERSTREAM_DIR_CLOSE "dir_closedir" -#define USERSTREAM_LOCK "stream_lock" - -/* {{{ class should have methods like these: - - function stream_open($path, $mode, $options, &$opened_path) - { - return true/false; - } - - function stream_read($count) - { - return false on error; - else return string; - } - - function stream_write($data) - { - return false on error; - else return count written; - } - - function stream_close() - { - } - - function stream_flush() - { - return true/false; - } - - function stream_seek($offset, $whence) - { - return true/false; - } - - function stream_tell() - { - return (int)$position; - } - - function stream_eof() - { - return true/false; - } - - function stream_stat() - { - return array( just like that returned by fstat() ); - } - - function url_stat(string $url, int $flags) - { - return array( just like that returned by stat() ); - } - - function unlink(string $url) - { - return true / false; - } - - function rename(string $from, string $to) - { - return true / false; - } - - function mkdir($dir, $mode, $options) - { - return true / false; - } - - function rmdir($dir, $options) - { - return true / false; - } - - function dir_opendir(string $url, int $options) - { - return true / false; - } - - function dir_readdir() - { - return string next filename in dir ; - } - - function dir_closedir() - { - release dir related resources; - } - - function dir_rewinddir() - { - reset to start of dir list; - } - - }}} **/ - -static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filename, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) -{ - struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; - php_userstream_data_t *us; - zval *zfilename, *zmode, *zopened, *zoptions, *zretval = NULL, *zfuncname; - zval **args[4]; - int call_result; - php_stream *stream = NULL; - zval *zcontext = NULL; - - /* Try to catch bad usage without preventing flexibility */ - if (FG(user_stream_current_filename) != NULL && strcmp(filename, FG(user_stream_current_filename)) == 0) { - php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "infinite recursion prevented"); - return NULL; - } - FG(user_stream_current_filename) = filename; - - us = emalloc(sizeof(*us)); - us->wrapper = uwrap; - - /* create an instance of our class */ - ALLOC_ZVAL(us->object); - object_init_ex(us->object, uwrap->ce); - ZVAL_REFCOUNT(us->object) = 1; - PZVAL_IS_REF(us->object) = 1; - - if (context) { - MAKE_STD_ZVAL(zcontext); - php_stream_context_to_zval(context, zcontext); - add_property_zval(us->object, "context", zcontext); - /* The object property should be the only reference, - 'get rid' of our local reference. */ - zval_ptr_dtor(&zcontext); - } else { - add_property_null(us->object, "context"); - } - - /* call it's stream_open method - set up params first */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, filename, 1); - args[0] = &zfilename; - - MAKE_STD_ZVAL(zmode); - ZVAL_STRING(zmode, mode, 1); - args[1] = &zmode; - - MAKE_STD_ZVAL(zoptions); - ZVAL_LONG(zoptions, options); - args[2] = &zoptions; - - MAKE_STD_ZVAL(zopened); - ZVAL_REFCOUNT(zopened) = 1; - PZVAL_IS_REF(zopened) = 1; - ZVAL_NULL(zopened); - args[3] = &zopened; - - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_OPEN, 1); - - call_result = call_user_function_ex(NULL, - &us->object, - zfuncname, - &zretval, - 4, args, - 0, NULL TSRMLS_CC); - - if (call_result == SUCCESS && zretval != NULL && zval_is_true(zretval)) { - /* the stream is now open! */ - stream = php_stream_alloc_rel(&php_stream_userspace_ops, us, 0, mode); - - /* if the opened path is set, copy it out */ - if (Z_TYPE_P(zopened) == IS_STRING && opened_path) { - *opened_path = estrndup(Z_STRVAL_P(zopened), Z_STRLEN_P(zopened)); - } - - /* set wrapper data to be a reference to our object */ - stream->wrapperdata = us->object; - zval_add_ref(&stream->wrapperdata); - } else { - php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "\"%s::" USERSTREAM_OPEN "\" call failed", - us->wrapper->classname); - } - - /* destroy everything else */ - if (stream == NULL) { - zval_ptr_dtor(&us->object); - efree(us); - } - if (zretval) - zval_ptr_dtor(&zretval); - - zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zopened); - zval_ptr_dtor(&zoptions); - zval_ptr_dtor(&zmode); - zval_ptr_dtor(&zfilename); - - FG(user_stream_current_filename) = NULL; - - return stream; -} - -static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, char *filename, char *mode, - int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) -{ - struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; - php_userstream_data_t *us; - zval *zfilename, *zoptions, *zretval = NULL, *zfuncname, *zcontext; - zval **args[2]; - int call_result; - php_stream *stream = NULL; - - /* Try to catch bad usage without preventing flexibility */ - if (FG(user_stream_current_filename) != NULL && strcmp(filename, FG(user_stream_current_filename)) == 0) { - php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "infinite recursion prevented"); - return NULL; - } - FG(user_stream_current_filename) = filename; - - us = emalloc(sizeof(*us)); - us->wrapper = uwrap; - - /* create an instance of our class */ - ALLOC_ZVAL(us->object); - object_init_ex(us->object, uwrap->ce); - ZVAL_REFCOUNT(us->object) = 1; - PZVAL_IS_REF(us->object) = 1; - - if (context) { - MAKE_STD_ZVAL(zcontext); - php_stream_context_to_zval(context, zcontext); - add_property_zval(us->object, "context", zcontext); - /* The object property should be the only reference, - 'get rid' of our local reference. */ - zval_ptr_dtor(&zcontext); - } else { - add_property_null(us->object, "context"); - } - - /* call it's dir_open method - set up params first */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, filename, 1); - args[0] = &zfilename; - - MAKE_STD_ZVAL(zoptions); - ZVAL_LONG(zoptions, options); - args[1] = &zoptions; - - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_DIR_OPEN, 1); - - call_result = call_user_function_ex(NULL, - &us->object, - zfuncname, - &zretval, - 2, args, - 0, NULL TSRMLS_CC); - - if (call_result == SUCCESS && zretval != NULL && zval_is_true(zretval)) { - /* the stream is now open! */ - stream = php_stream_alloc_rel(&php_stream_userspace_dir_ops, us, 0, mode); - - /* set wrapper data to be a reference to our object */ - stream->wrapperdata = us->object; - zval_add_ref(&stream->wrapperdata); - } else { - php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "\"%s::" USERSTREAM_DIR_OPEN "\" call failed", - us->wrapper->classname); - } - - /* destroy everything else */ - if (stream == NULL) { - zval_ptr_dtor(&us->object); - efree(us); - } - if (zretval) - zval_ptr_dtor(&zretval); - - zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zoptions); - zval_ptr_dtor(&zfilename); - - FG(user_stream_current_filename) = NULL; - - return stream; -} - - -/* {{{ proto bool stream_wrapper_register(string protocol, string classname) - Registers a custom URL protocol handler class */ -PHP_FUNCTION(stream_wrapper_register) -{ - char *protocol, *classname; - int protocol_len, classname_len; - struct php_user_stream_wrapper * uwrap; - int rsrc_id; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &protocol, &protocol_len, &classname, &classname_len) == FAILURE) { - RETURN_FALSE; - } - - uwrap = (struct php_user_stream_wrapper *)ecalloc(1, sizeof(*uwrap)); - uwrap->protoname = estrndup(protocol, protocol_len); - uwrap->classname = estrndup(classname, classname_len); - uwrap->wrapper.wops = &user_stream_wops; - uwrap->wrapper.abstract = uwrap; - - zend_str_tolower(uwrap->classname, classname_len); - rsrc_id = ZEND_REGISTER_RESOURCE(NULL, uwrap, le_protocols); - - if (zend_hash_find(EG(class_table), uwrap->classname, classname_len + 1, (void**)&uwrap->ce) == SUCCESS) { -#ifdef ZEND_ENGINE_2 - uwrap->ce = *(zend_class_entry**)uwrap->ce; -#endif - if (php_register_url_stream_wrapper(protocol, &uwrap->wrapper TSRMLS_CC) == SUCCESS) { - RETURN_TRUE; - } - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "class '%s' is undefined", - classname); - } - - zend_list_delete(rsrc_id); - RETURN_FALSE; -} -/* }}} */ - - -static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) -{ - zval func_name; - zval *retval = NULL; - int call_result; - php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - zval **args[1]; - zval zbuff, *zbufptr; - size_t didwrite = 0; - - assert(us != NULL); - - ZVAL_STRINGL(&func_name, USERSTREAM_WRITE, sizeof(USERSTREAM_WRITE)-1, 0); - - ZVAL_STRINGL(&zbuff, (char*)buf, count, 0); - zbufptr = &zbuff; - args[0] = &zbufptr; - - call_result = call_user_function_ex(NULL, - &us->object, - &func_name, - &retval, - 1, args, - 0, NULL TSRMLS_CC); - - didwrite = 0; - if (call_result == SUCCESS && retval != NULL) { - convert_to_long(retval); - didwrite = Z_LVAL_P(retval); - } else if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_WRITE " is not implemented!", - us->wrapper->classname); - } - - /* don't allow strange buffer overruns due to bogus return */ - if (didwrite > count) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_WRITE " wrote %zd bytes more data than requested (%zd written, %zd max)", - us->wrapper->classname, - didwrite - count, didwrite, count); - didwrite = count; - } - - if (retval) - zval_ptr_dtor(&retval); - - return didwrite; -} - -static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) -{ - zval func_name; - zval *retval = NULL; - zval **args[1]; - int call_result; - size_t didread = 0; - php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - zval *zcount; - - assert(us != NULL); - - ZVAL_STRINGL(&func_name, USERSTREAM_READ, sizeof(USERSTREAM_READ)-1, 0); - - MAKE_STD_ZVAL(zcount); - ZVAL_LONG(zcount, count); - args[0] = &zcount; - - call_result = call_user_function_ex(NULL, - &us->object, - &func_name, - &retval, - 1, args, - 0, NULL TSRMLS_CC); - - if (call_result == SUCCESS && retval != NULL) { - convert_to_string(retval); - didread = Z_STRLEN_P(retval); - if (didread > count) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_READ " - read %zd bytes more data than requested (%zd read, %zd max) - excess data will be lost", - us->wrapper->classname, didread - count, didread, count); - didread = count; - } - if (didread > 0) - memcpy(buf, Z_STRVAL_P(retval), didread); - } else if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_READ " is not implemented!", - us->wrapper->classname); - } - zval_ptr_dtor(&zcount); - - if (retval) { - zval_ptr_dtor(&retval); - retval = NULL; - } - - /* since the user stream has no way of setting the eof flag directly, we need to ask it if we hit eof */ - - ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1, 0); - - call_result = call_user_function_ex(NULL, - &us->object, - &func_name, - &retval, - 0, NULL, 0, NULL TSRMLS_CC); - - if (call_result == SUCCESS && retval != NULL && zval_is_true(retval)) { - stream->eof = 1; - } else if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, - "%s::" USERSTREAM_EOF " is not implemented! Assuming EOF", - us->wrapper->classname); - - stream->eof = 1; - } - - if (retval) { - zval_ptr_dtor(&retval); - retval = NULL; - } - - return didread; -} - -static int php_userstreamop_close(php_stream *stream, int close_handle TSRMLS_DC) -{ - zval func_name; - zval *retval = NULL; - php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - - assert(us != NULL); - - ZVAL_STRINGL(&func_name, USERSTREAM_CLOSE, sizeof(USERSTREAM_CLOSE)-1, 0); - - call_user_function_ex(NULL, - &us->object, - &func_name, - &retval, - 0, NULL, 0, NULL TSRMLS_CC); - - if (retval) - zval_ptr_dtor(&retval); - - zval_ptr_dtor(&us->object); - - efree(us); - - return 0; -} - -static int php_userstreamop_flush(php_stream *stream TSRMLS_DC) -{ - zval func_name; - zval *retval = NULL; - int call_result; - php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - - assert(us != NULL); - - ZVAL_STRINGL(&func_name, USERSTREAM_FLUSH, sizeof(USERSTREAM_FLUSH)-1, 0); - - call_result = call_user_function_ex(NULL, - &us->object, - &func_name, - &retval, - 0, NULL, 0, NULL TSRMLS_CC); - - if (call_result == SUCCESS && retval != NULL && zval_is_true(retval)) - call_result = 0; - else - call_result = -1; - - if (retval) - zval_ptr_dtor(&retval); - - return call_result; -} - -static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) -{ - zval func_name; - zval *retval = NULL; - int call_result, ret; - php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - zval **args[2]; - zval *zoffs, *zwhence; - - assert(us != NULL); - - ZVAL_STRINGL(&func_name, USERSTREAM_SEEK, sizeof(USERSTREAM_SEEK)-1, 0); - - MAKE_STD_ZVAL(zoffs); - ZVAL_LONG(zoffs, offset); - args[0] = &zoffs; - - MAKE_STD_ZVAL(zwhence); - ZVAL_LONG(zwhence, whence); - args[1] = &zwhence; - - call_result = call_user_function_ex(NULL, - &us->object, - &func_name, - &retval, - 2, args, - 0, NULL TSRMLS_CC); - - zval_ptr_dtor(&zoffs); - zval_ptr_dtor(&zwhence); - - if (call_result == FAILURE) { - /* stream_seek is not implemented, so disable seeks for this stream */ - stream->flags |= PHP_STREAM_FLAG_NO_SEEK; - /* there should be no retval to clean up */ - - if (retval) - zval_ptr_dtor(&retval); - - return -1; - } else if (call_result == SUCCESS && retval != NULL && zval_is_true(retval)) { - ret = 0; - } else { - ret = -1; - } - - if (retval) { - zval_ptr_dtor(&retval); - retval = NULL; - } - - /* now determine where we are */ - ZVAL_STRINGL(&func_name, USERSTREAM_TELL, sizeof(USERSTREAM_TELL)-1, 0); - - call_result = call_user_function_ex(NULL, - &us->object, - &func_name, - &retval, - 0, NULL, 0, NULL TSRMLS_CC); - - 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); - - if (retval) - zval_ptr_dtor(&retval); - - return 0; -} - -/* parse the return value from one of the stat functions and store the - * relevant fields into the statbuf provided */ -static int statbuf_from_array(zval *array, php_stream_statbuf *ssb TSRMLS_DC) -{ - zval **elem; - -#define STAT_PROP_ENTRY_EX(name, name2) \ - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(array), #name, sizeof(#name), (void**)&elem)) { \ - convert_to_long(*elem); \ - ssb->sb.st_##name2 = Z_LVAL_PP(elem); \ - } - -#define STAT_PROP_ENTRY(name) STAT_PROP_ENTRY_EX(name,name) - - STAT_PROP_ENTRY(dev); - STAT_PROP_ENTRY(ino); - STAT_PROP_ENTRY(mode); - STAT_PROP_ENTRY(nlink); - STAT_PROP_ENTRY(uid); - STAT_PROP_ENTRY(gid); -#if HAVE_ST_RDEV - STAT_PROP_ENTRY(rdev); -#endif - STAT_PROP_ENTRY(size); -#if defined(NETWARE) && defined(CLIB_STAT_PATCH) - STAT_PROP_ENTRY_EX(atime, atime.tv_sec); - STAT_PROP_ENTRY_EX(mtime, mtime.tv_sec); - STAT_PROP_ENTRY_EX(ctime, ctime.tv_sec); -#else - STAT_PROP_ENTRY(atime); - STAT_PROP_ENTRY(mtime); - STAT_PROP_ENTRY(ctime); -#endif -#ifdef HAVE_ST_BLKSIZE - STAT_PROP_ENTRY(blksize); -#endif -#ifdef HAVE_ST_BLOCKS - STAT_PROP_ENTRY(blocks); -#endif - -#undef STAT_PROP_ENTRY -#undef STAT_PROP_ENTRY_EX - return SUCCESS; -} - -static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC) -{ - zval func_name; - zval *retval = NULL; - int call_result; - php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - int ret = -1; - - ZVAL_STRINGL(&func_name, USERSTREAM_STAT, sizeof(USERSTREAM_STAT)-1, 0); - - call_result = call_user_function_ex(NULL, - &us->object, - &func_name, - &retval, - 0, NULL, 0, NULL TSRMLS_CC); - - if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_ARRAY) { - if (SUCCESS == statbuf_from_array(retval, ssb TSRMLS_CC)) - ret = 0; - } else { - if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_STAT " is not implemented!", - us->wrapper->classname); - } - } - - if (retval) - zval_ptr_dtor(&retval); - - return ret; -} - - -static int php_userstreamop_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC) { - zval func_name; - zval *retval = NULL; - int call_result; - php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - int ret = -1; - zval *zvalue; - zval **args[1]; - - MAKE_STD_ZVAL(zvalue); - ZVAL_LONG(zvalue, value); - args[0] = &zvalue; - - switch (option) { - case PHP_STREAM_OPTION_LOCKING: - // TODO wouldblock - ZVAL_STRINGL(&func_name, USERSTREAM_LOCK, sizeof(USERSTREAM_LOCK)-1, 0); - - call_result = call_user_function_ex(NULL, - &us->object, - &func_name, - &retval, - 1, args, 0, NULL TSRMLS_CC); - - if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_BOOL) { - ret = !Z_LVAL_P(retval); - } else if (call_result == FAILURE) { - if (value == 0) { - ret = 0; // lock support test (TODO: more check) - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_LOCK " is not implemented!", - us->wrapper->classname); - } - } - - if (retval) - zval_ptr_dtor(&retval); - - break; - } - - /* clean up */ - zval_ptr_dtor(&zvalue); - - return ret; -} - - -static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC) -{ - struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; - zval *zfilename, *zfuncname, *zretval, *zcontext; - zval **args[1]; - int call_result; - zval *object; - int ret = 0; - - /* create an instance of our class */ - ALLOC_ZVAL(object); - object_init_ex(object, uwrap->ce); - ZVAL_REFCOUNT(object) = 1; - PZVAL_IS_REF(object) = 1; - - if (context) { - MAKE_STD_ZVAL(zcontext); - php_stream_context_to_zval(context, zcontext); - add_property_zval(object, "context", zcontext); - /* The object property should be the only reference, - 'get rid' of our local reference. */ - zval_ptr_dtor(&zcontext); - } else { - add_property_null(object, "context"); - } - - /* call the unlink method */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, url, 1); - args[0] = &zfilename; - - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_UNLINK, 1); - - call_result = call_user_function_ex(NULL, - &object, - zfuncname, - &zretval, - 1, args, - 0, NULL TSRMLS_CC); - - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); - } else if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_UNLINK " is not implemented!", uwrap->classname); - } - - /* clean up */ - zval_ptr_dtor(&object); - if (zretval) - zval_ptr_dtor(&zretval); - - zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zfilename); - - return ret; -} - -static int user_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC) -{ - struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; - zval *zold_name, *znew_name, *zfuncname, *zretval, *zcontext; - zval **args[2]; - int call_result; - zval *object; - int ret = 0; - - /* create an instance of our class */ - ALLOC_ZVAL(object); - object_init_ex(object, uwrap->ce); - ZVAL_REFCOUNT(object) = 1; - PZVAL_IS_REF(object) = 1; - - if (context) { - MAKE_STD_ZVAL(zcontext); - php_stream_context_to_zval(context, zcontext); - add_property_zval(object, "context", zcontext); - /* The object property should be the only reference, - 'get rid' of our local reference. */ - zval_ptr_dtor(&zcontext); - } else { - add_property_null(object, "context"); - } - - /* call the rename method */ - MAKE_STD_ZVAL(zold_name); - ZVAL_STRING(zold_name, url_from, 1); - args[0] = &zold_name; - - MAKE_STD_ZVAL(znew_name); - ZVAL_STRING(znew_name, url_to, 1); - args[1] = &znew_name; - - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_RENAME, 1); - - call_result = call_user_function_ex(NULL, - &object, - zfuncname, - &zretval, - 2, args, - 0, NULL TSRMLS_CC); - - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); - } else if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_RENAME " is not implemented!", uwrap->classname); - } - - /* clean up */ - zval_ptr_dtor(&object); - if (zretval) - zval_ptr_dtor(&zretval); - - zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zold_name); - zval_ptr_dtor(&znew_name); - - return ret; -} - -static int user_wrapper_mkdir(php_stream_wrapper *wrapper, char *url, int mode, int options, php_stream_context *context TSRMLS_DC) -{ - struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; - zval *zfilename, *zmode, *zoptions, *zfuncname, *zretval, *zcontext; - zval **args[3]; - int call_result; - zval *object; - int ret = 0; - - /* create an instance of our class */ - ALLOC_ZVAL(object); - object_init_ex(object, uwrap->ce); - ZVAL_REFCOUNT(object) = 1; - PZVAL_IS_REF(object) = 1; - - if (context) { - MAKE_STD_ZVAL(zcontext); - php_stream_context_to_zval(context, zcontext); - add_property_zval(object, "context", zcontext); - /* The object property should be the only reference, - 'get rid' of our local reference. */ - zval_ptr_dtor(&zcontext); - } else { - add_property_null(object, "context"); - } - - /* call the unlink method */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, url, 1); - args[0] = &zfilename; - - MAKE_STD_ZVAL(zmode); - ZVAL_LONG(zmode, mode); - args[1] = &zmode; - - MAKE_STD_ZVAL(zoptions); - ZVAL_LONG(zoptions, options); - args[2] = &zoptions; - - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_MKDIR, 1); - - call_result = call_user_function_ex(NULL, - &object, - zfuncname, - &zretval, - 3, args, - 0, NULL TSRMLS_CC); - - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); - } else if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_MKDIR " is not implemented!", uwrap->classname); - } - - /* clean up */ - zval_ptr_dtor(&object); - if (zretval) { - zval_ptr_dtor(&zretval); - } - - zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zfilename); - zval_ptr_dtor(&zmode); - zval_ptr_dtor(&zoptions); - - return ret; -} - -static int user_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC) -{ - struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; - zval *zfilename, *zoptions, *zfuncname, *zretval, *zcontext; - zval **args[3]; - int call_result; - zval *object; - int ret = 0; - - /* create an instance of our class */ - ALLOC_ZVAL(object); - object_init_ex(object, uwrap->ce); - ZVAL_REFCOUNT(object) = 1; - PZVAL_IS_REF(object) = 1; - - if (context) { - MAKE_STD_ZVAL(zcontext); - php_stream_context_to_zval(context, zcontext); - add_property_zval(object, "context", zcontext); - /* The object property should be the only reference, - 'get rid' of our local reference. */ - zval_ptr_dtor(&zcontext); - } else { - add_property_null(object, "context"); - } - - /* call the unlink method */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, url, 1); - args[0] = &zfilename; - - MAKE_STD_ZVAL(zoptions); - ZVAL_LONG(zoptions, options); - args[1] = &zoptions; - - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_RMDIR, 1); - - call_result = call_user_function_ex(NULL, - &object, - zfuncname, - &zretval, - 2, args, - 0, NULL TSRMLS_CC); - - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); - } else if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_RMDIR " is not implemented!", uwrap->classname); - } - - /* clean up */ - zval_ptr_dtor(&object); - if (zretval) { - zval_ptr_dtor(&zretval); - } - - zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zfilename); - zval_ptr_dtor(&zoptions); - - return ret; -} - -static int user_wrapper_stat_url(php_stream_wrapper *wrapper, char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC) -{ - struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; - zval *zfilename, *zfuncname, *zretval, *zflags, *zcontext; - zval **args[2]; - int call_result; - zval *object; - int ret = -1; - - /* create an instance of our class */ - ALLOC_ZVAL(object); - object_init_ex(object, uwrap->ce); - ZVAL_REFCOUNT(object) = 1; - PZVAL_IS_REF(object) = 1; - - if (context) { - MAKE_STD_ZVAL(zcontext); - php_stream_context_to_zval(context, zcontext); - add_property_zval(object, "context", zcontext); - /* The object property should be the only reference, - 'get rid' of our local reference. */ - zval_ptr_dtor(&zcontext); - } else { - add_property_null(object, "context"); - } - - /* call the stat_url method */ - - /* call it's stream_open method - set up params first */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, url, 1); - args[0] = &zfilename; - - MAKE_STD_ZVAL(zflags); - ZVAL_LONG(zflags, flags); - args[1] = &zflags; - - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_STATURL, 1); - - call_result = call_user_function_ex(NULL, - &object, - zfuncname, - &zretval, - 2, args, - 0, NULL TSRMLS_CC); - - if (call_result == SUCCESS && zretval != NULL && Z_TYPE_P(zretval) == IS_ARRAY) { - /* We got the info we needed */ - if (SUCCESS == statbuf_from_array(zretval, ssb TSRMLS_CC)) - ret = 0; - } else { - if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_STATURL " is not implemented!", - uwrap->classname); - } - } - - /* clean up */ - zval_ptr_dtor(&object); - if (zretval) - zval_ptr_dtor(&zretval); - - zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zfilename); - zval_ptr_dtor(&zflags); - - return ret; - -} - -static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t count TSRMLS_DC) -{ - zval func_name; - zval *retval = NULL; - int call_result; - size_t didread = 0; - php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - php_stream_dirent *ent = (php_stream_dirent*)buf; - - /* avoid problems if someone mis-uses the stream */ - if (count != sizeof(php_stream_dirent)) - return 0; - - ZVAL_STRINGL(&func_name, USERSTREAM_DIR_READ, sizeof(USERSTREAM_DIR_READ)-1, 0); - - call_result = call_user_function_ex(NULL, - &us->object, - &func_name, - &retval, - 0, NULL, - 0, NULL TSRMLS_CC); - - if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) != IS_BOOL) { - convert_to_string(retval); - PHP_STRLCPY(ent->d_name, Z_STRVAL_P(retval), sizeof(ent->d_name), Z_STRLEN_P(retval)); - - didread = sizeof(php_stream_dirent); - } else if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_DIR_READ " is not implemented!", - us->wrapper->classname); - } - - if (retval) - zval_ptr_dtor(&retval); - - return didread; -} - -static int php_userstreamop_closedir(php_stream *stream, int close_handle TSRMLS_DC) -{ - zval func_name; - zval *retval = NULL; - php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - - assert(us != NULL); - - ZVAL_STRINGL(&func_name, USERSTREAM_DIR_CLOSE, sizeof(USERSTREAM_DIR_CLOSE)-1, 0); - - call_user_function_ex(NULL, - &us->object, - &func_name, - &retval, - 0, NULL, 0, NULL TSRMLS_CC); - - if (retval) - zval_ptr_dtor(&retval); - - zval_ptr_dtor(&us->object); - - efree(us); - - return 0; -} - -static int php_userstreamop_rewinddir(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) -{ - zval func_name; - zval *retval = NULL; - zval **args[1]; - php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - - ZVAL_STRINGL(&func_name, USERSTREAM_DIR_REWIND, sizeof(USERSTREAM_DIR_REWIND)-1, 0); - - call_user_function_ex(NULL, - &us->object, - &func_name, - &retval, - 0, NULL, 0, NULL TSRMLS_CC); - - if (retval) - zval_ptr_dtor(&retval); - - return 0; - -} - -php_stream_ops php_stream_userspace_ops = { - php_userstreamop_write, php_userstreamop_read, - php_userstreamop_close, php_userstreamop_flush, - "user-space", - php_userstreamop_seek, - NULL, /* cast */ - php_userstreamop_stat, - php_userstreamop_set_option, -}; - -php_stream_ops php_stream_userspace_dir_ops = { - NULL, /* write */ - php_userstreamop_readdir, - php_userstreamop_closedir, - NULL, /* flush */ - "user-space-dir", - php_userstreamop_rewinddir, - NULL, /* cast */ - NULL, /* stat */ - NULL /* set_option */ -}; - - diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c deleted file mode 100644 index 00b20b2b63..0000000000 --- a/main/streams/xp_socket.c +++ /dev/null @@ -1,751 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "ext/standard/file.h" -#include "streams/php_streams_int.h" -#include "php_network.h" - -#if defined(PHP_WIN32) || defined(__riscos__) || defined(NETWARE) -# undef AF_UNIX -#endif - -#if defined(AF_UNIX) -#include <sys/un.h> -#endif - -php_stream_ops php_stream_generic_socket_ops; -PHPAPI php_stream_ops php_stream_socket_ops; -php_stream_ops php_stream_udp_socket_ops; -#ifdef AF_UNIX -php_stream_ops php_stream_unix_socket_ops; -php_stream_ops php_stream_unixdg_socket_ops; -#endif - - -static int php_tcp_sockop_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC); - -/* {{{ Generic socket stream operations */ -static size_t php_sockop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) -{ - php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; - int didwrite; - - if (sock->socket == -1) { - return 0; - } - - didwrite = send(sock->socket, buf, count, 0); - - if (didwrite <= 0) { - char *estr = php_socket_strerror(php_socket_errno(), NULL, 0); - - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "send of %d bytes failed with errno=%d %s", - count, php_socket_errno(), estr); - efree(estr); - } - - if (didwrite > 0) { - php_stream_notify_progress_increment(stream->context, didwrite, 0); - } - - if (didwrite < 0) { - didwrite = 0; - } - - return didwrite; -} - -static void php_sock_stream_wait_for_data(php_stream *stream, php_netstream_data_t *sock TSRMLS_DC) -{ - fd_set fdr, tfdr; - int retval; - struct timeval timeout, *ptimeout; - - if (sock->socket == -1) { - return; - } - - FD_ZERO(&fdr); - FD_SET(sock->socket, &fdr); - sock->timeout_event = 0; - - if (sock->timeout.tv_sec == -1) - ptimeout = NULL; - else - ptimeout = &timeout; - - - while(1) { - tfdr = fdr; - timeout = sock->timeout; - - retval = select(sock->socket + 1, &tfdr, NULL, NULL, ptimeout); - - if (retval == 0) - sock->timeout_event = 1; - - if (retval >= 0) - break; - } -} - -static size_t php_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) -{ - php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; - int nr_bytes = 0; - - if (sock->socket == -1) { - return 0; - } - - if (sock->is_blocked) { - php_sock_stream_wait_for_data(stream, sock TSRMLS_CC); - if (sock->timeout_event) - return 0; - } - - nr_bytes = recv(sock->socket, buf, count, 0); - - stream->eof = (nr_bytes == 0 || (nr_bytes == -1 && php_socket_errno() != EWOULDBLOCK)); - - if (nr_bytes > 0) { - php_stream_notify_progress_increment(stream->context, nr_bytes, 0); - } - - if (nr_bytes < 0) { - nr_bytes = 0; - } - - return nr_bytes; -} - - -static int php_sockop_close(php_stream *stream, int close_handle TSRMLS_DC) -{ - php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; -#ifdef PHP_WIN32 - fd_set wrfds, efds; - int n; - struct timeval timeout; -#endif - - if (close_handle) { - - if (sock->socket != -1) { -#ifdef PHP_WIN32 - /* prevent more data from coming in */ - shutdown(sock->socket, SHUT_RD); - - /* try to make sure that the OS sends all data before we close the connection. - * Essentially, we are waiting for the socket to become writeable, which means - * that all pending data has been sent. - * We use a small timeout which should encourage the OS to send the data, - * but at the same time avoid hanging indefintely. - * */ - do { - FD_ZERO(&wrfds); - FD_SET(sock->socket, &wrfds); - efds = wrfds; - - timeout.tv_sec = 0; - timeout.tv_usec = 5000; /* arbitrary */ - - n = select(sock->socket + 1, NULL, &wrfds, &efds, &timeout); - } while (n == -1 && php_socket_errno() == EINTR); -#endif - - closesocket(sock->socket); - sock->socket = -1; - } - - } - - pefree(sock, php_stream_is_persistent(stream)); - - return 0; -} - -static int php_sockop_flush(php_stream *stream TSRMLS_DC) -{ - php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; - return fsync(sock->socket); -} - -static int php_sockop_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC) -{ - php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; - return fstat(sock->socket, &ssb->sb); -} - -static inline int sock_recvfrom(php_netstream_data_t *sock, char *buf, size_t buflen, int flags, - char **textaddr, long *textaddrlen, - struct sockaddr **addr, socklen_t *addrlen - TSRMLS_DC) -{ - php_sockaddr_storage sa; - socklen_t sl = sizeof(sa); - int ret; - int want_addr = textaddr || addr; - - if (want_addr) { - ret = recvfrom(sock->socket, buf, buflen, flags, (struct sockaddr*)&sa, &sl); - php_network_populate_name_from_sockaddr((struct sockaddr*)&sa, sl, - textaddr, textaddrlen, addr, addrlen TSRMLS_CC); - } else { - ret = recv(sock->socket, buf, buflen, flags); - } - - return ret; -} - -static int php_sockop_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC) -{ - int oldmode, flags; - php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; - php_stream_xport_param *xparam; - - switch(option) { - case PHP_STREAM_OPTION_CHECK_LIVENESS: - { - fd_set rfds; - struct timeval tv; - char buf; - int alive = 1; - - if (sock->timeout.tv_sec == -1) { - tv.tv_sec = FG(default_socket_timeout); - } else { - tv = sock->timeout; - } - - if (sock->socket == -1) { - alive = 0; - } else { - FD_ZERO(&rfds); - FD_SET(sock->socket, &rfds); - - if (select(sock->socket + 1, &rfds, NULL, NULL, &tv) > 0 && FD_ISSET(sock->socket, &rfds)) { - if (0 == recv(sock->socket, &buf, sizeof(buf), MSG_PEEK) && php_socket_errno() != EAGAIN) { - alive = 0; - } - } - } - return alive ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR; - } - - case PHP_STREAM_OPTION_BLOCKING: - - oldmode = sock->is_blocked; - - /* no need to change anything */ - if (value == oldmode) - return oldmode; - - if (SUCCESS == php_set_sock_blocking(sock->socket, value TSRMLS_CC)) { - sock->is_blocked = value; - return oldmode; - } - - return PHP_STREAM_OPTION_RETURN_ERR; - - case PHP_STREAM_OPTION_READ_TIMEOUT: - sock->timeout = *(struct timeval*)ptrparam; - sock->timeout_event = 0; - return PHP_STREAM_OPTION_RETURN_OK; - - case PHP_STREAM_OPTION_META_DATA_API: - add_assoc_bool((zval *)ptrparam, "timed_out", sock->timeout_event); - add_assoc_bool((zval *)ptrparam, "blocked", sock->is_blocked); - add_assoc_bool((zval *)ptrparam, "eof", stream->eof); - return PHP_STREAM_OPTION_RETURN_OK; - - case PHP_STREAM_OPTION_XPORT_API: - xparam = (php_stream_xport_param *)ptrparam; - - switch (xparam->op) { - case STREAM_XPORT_OP_LISTEN: - xparam->outputs.returncode = listen(sock->socket, 5); - return PHP_STREAM_OPTION_RETURN_OK; - - case STREAM_XPORT_OP_GET_NAME: - xparam->outputs.returncode = php_network_get_sock_name(sock->socket, - xparam->want_textaddr ? &xparam->outputs.textaddr : NULL, - xparam->want_textaddr ? &xparam->outputs.textaddrlen : NULL, - xparam->want_addr ? &xparam->outputs.addr : NULL, - xparam->want_addr ? &xparam->outputs.addrlen : NULL - TSRMLS_CC); - return PHP_STREAM_OPTION_RETURN_OK; - - case STREAM_XPORT_OP_GET_PEER_NAME: - xparam->outputs.returncode = php_network_get_peer_name(sock->socket, - xparam->want_textaddr ? &xparam->outputs.textaddr : NULL, - xparam->want_textaddr ? &xparam->outputs.textaddrlen : NULL, - xparam->want_addr ? &xparam->outputs.addr : NULL, - xparam->want_addr ? &xparam->outputs.addrlen : NULL - TSRMLS_CC); - return PHP_STREAM_OPTION_RETURN_OK; - - case STREAM_XPORT_OP_SEND: - flags = 0; - if ((xparam->inputs.flags & STREAM_OOB) == STREAM_OOB) { - flags |= MSG_OOB; - } - xparam->outputs.returncode = sendto(sock->socket, - xparam->inputs.buf, xparam->inputs.buflen, - flags, - xparam->inputs.addr, - xparam->inputs.addrlen); - if (xparam->outputs.returncode == -1) { - char *err = php_socket_strerror(php_socket_errno(), NULL, 0); - php_error_docref(NULL TSRMLS_CC, E_WARNING, - "%s\n", err); - efree(err); - } - return PHP_STREAM_OPTION_RETURN_OK; - - case STREAM_XPORT_OP_RECV: - flags = 0; - if ((xparam->inputs.flags & STREAM_OOB) == STREAM_OOB) { - flags |= MSG_OOB; - } - if ((xparam->inputs.flags & STREAM_PEEK) == STREAM_PEEK) { - flags |= MSG_PEEK; - } - xparam->outputs.returncode = sock_recvfrom(sock, - xparam->inputs.buf, xparam->inputs.buflen, - flags, - xparam->want_textaddr ? &xparam->outputs.textaddr : NULL, - xparam->want_textaddr ? &xparam->outputs.textaddrlen : NULL, - xparam->want_addr ? &xparam->outputs.addr : NULL, - xparam->want_addr ? &xparam->outputs.addrlen : NULL - TSRMLS_CC); - return PHP_STREAM_OPTION_RETURN_OK; - - - default: - return PHP_STREAM_OPTION_RETURN_NOTIMPL; - } - - default: - return PHP_STREAM_OPTION_RETURN_NOTIMPL; - } -} - -static int php_sockop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC) -{ - php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; - - switch(castas) { - case PHP_STREAM_AS_STDIO: - if (ret) { - *(FILE**)ret = fdopen(sock->socket, stream->mode); - if (*ret) - return SUCCESS; - return FAILURE; - } - return SUCCESS; - case PHP_STREAM_AS_FD_FOR_SELECT: - case PHP_STREAM_AS_FD: - case PHP_STREAM_AS_SOCKETD: - if (ret) - *(int*)ret = sock->socket; - return SUCCESS; - default: - return FAILURE; - } -} -/* }}} */ - -/* These may look identical, but we need them this way so that - * we can determine which type of socket we are dealing with - * by inspecting stream->ops. - * A "useful" side-effect is that the user's scripts can then - * make similar decisions using stream_get_meta_data. - * */ -php_stream_ops php_stream_generic_socket_ops = { - php_sockop_write, php_sockop_read, - php_sockop_close, php_sockop_flush, - "generic_socket", - NULL, /* seek */ - php_sockop_cast, - php_sockop_stat, - php_sockop_set_option, -}; - - -php_stream_ops php_stream_socket_ops = { - php_sockop_write, php_sockop_read, - php_sockop_close, php_sockop_flush, - "tcp_socket", - NULL, /* seek */ - php_sockop_cast, - php_sockop_stat, - php_tcp_sockop_set_option, -}; - -php_stream_ops php_stream_udp_socket_ops = { - php_sockop_write, php_sockop_read, - php_sockop_close, php_sockop_flush, - "udp_socket", - NULL, /* seek */ - php_sockop_cast, - php_sockop_stat, - php_tcp_sockop_set_option, -}; - -#ifdef AF_UNIX -php_stream_ops php_stream_unix_socket_ops = { - php_sockop_write, php_sockop_read, - php_sockop_close, php_sockop_flush, - "unix_socket", - NULL, /* seek */ - php_sockop_cast, - php_sockop_stat, - php_tcp_sockop_set_option, -}; -php_stream_ops php_stream_unixdg_socket_ops = { - php_sockop_write, php_sockop_read, - php_sockop_close, php_sockop_flush, - "udg_socket", - NULL, /* seek */ - php_sockop_cast, - php_sockop_stat, - php_tcp_sockop_set_option, -}; -#endif - - -/* network socket operations */ - -#ifdef AF_UNIX -static inline int parse_unix_address(php_stream_xport_param *xparam, struct sockaddr_un *unix_addr TSRMLS_DC) -{ - memset(unix_addr, 0, sizeof(*unix_addr)); - unix_addr->sun_family = AF_UNIX; - - /* we need to be binary safe on systems that support an abstract - * namespace */ - if (xparam->inputs.namelen >= sizeof(unix_addr->sun_path)) { - /* On linux, when the path begins with a NUL byte we are - * referring to an abstract namespace. In theory we should - * allow an extra byte below, since we don't need the NULL. - * BUT, to get into this branch of code, the name is too long, - * so we don't care. */ - xparam->inputs.namelen = sizeof(unix_addr->sun_path) - 1; - } - - memcpy(unix_addr->sun_path, xparam->inputs.name, xparam->inputs.namelen); - - return 1; -} -#endif - -static inline char *parse_ip_address(php_stream_xport_param *xparam, int *portno TSRMLS_DC) -{ - char *colon; - char *host = NULL; - -#ifdef HAVE_IPV6 - char *p; - - if (*(xparam->inputs.name) == '[') { - /* IPV6 notation to specify raw address with port (i.e. [fe80::1]:80) */ - p = memchr(xparam->inputs.name + 1, ']', xparam->inputs.namelen - 2); - if (!p || *(p + 1) != ':') { - if (xparam->want_errortext) { - spprintf(&xparam->outputs.error_text, 0, "Failed to parse IPv6 address \"%s\"", xparam->inputs.name); - } - return NULL; - } - *portno = atoi(p + 2); - return estrndup(xparam->inputs.name + 1, p - xparam->inputs.name - 1); - } -#endif - - colon = memchr(xparam->inputs.name, ':', xparam->inputs.namelen - 1); - if (colon) { - *portno = atoi(colon + 1); - host = estrndup(xparam->inputs.name, colon - xparam->inputs.name); - } else { - if (xparam->want_errortext) { - spprintf(&xparam->outputs.error_text, 0, "Failed to parse address \"%s\"", xparam->inputs.name); - } - return NULL; - } - - return host; -} - -static inline int php_tcp_sockop_bind(php_stream *stream, php_netstream_data_t *sock, - php_stream_xport_param *xparam TSRMLS_DC) -{ - char *host = NULL; - int portno, err; - -#ifdef AF_UNIX - if (stream->ops == &php_stream_unix_socket_ops || stream->ops == &php_stream_unixdg_socket_ops) { - struct sockaddr_un unix_addr; - - sock->socket = socket(PF_UNIX, stream->ops == &php_stream_unix_socket_ops ? SOCK_STREAM : SOCK_DGRAM, 0); - - if (sock->socket == SOCK_ERR) { - if (xparam->want_errortext) { - spprintf(&xparam->outputs.error_text, 0, "Failed to create unix%s socket %s", - stream->ops == &php_stream_unix_socket_ops ? "" : "datagram", - strerror(errno)); - } - return -1; - } - - parse_unix_address(xparam, &unix_addr TSRMLS_CC); - - return bind(sock->socket, (struct sockaddr *)&unix_addr, sizeof(unix_addr)); - } -#endif - - host = parse_ip_address(xparam, &portno TSRMLS_CC); - - if (host == NULL) { - return -1; - } - - sock->socket = php_network_bind_socket_to_local_addr(host, portno, - stream->ops == &php_stream_udp_socket_ops ? SOCK_DGRAM : SOCK_STREAM, - xparam->want_errortext ? &xparam->outputs.error_text : NULL, - &err - TSRMLS_CC); - - if (host) { - efree(host); - } - - return sock->socket == -1 ? -1 : 0; -} - -static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_t *sock, - php_stream_xport_param *xparam TSRMLS_DC) -{ - char *host = NULL; - int portno; - int err; - int ret; - -#ifdef AF_UNIX - if (stream->ops == &php_stream_unix_socket_ops || stream->ops == &php_stream_unixdg_socket_ops) { - struct sockaddr_un unix_addr; - - sock->socket = socket(PF_UNIX, stream->ops == &php_stream_unix_socket_ops ? SOCK_STREAM : SOCK_DGRAM, 0); - - if (sock->socket == SOCK_ERR) { - if (xparam->want_errortext) { - spprintf(&xparam->outputs.error_text, 0, "Failed to create unix socket"); - } - return -1; - } - - parse_unix_address(xparam, &unix_addr TSRMLS_CC); - - ret = php_network_connect_socket(sock->socket, - (const struct sockaddr *)&unix_addr, (socklen_t)sizeof(unix_addr), - xparam->op == STREAM_XPORT_OP_CONNECT_ASYNC, xparam->inputs.timeout, - xparam->want_errortext ? &xparam->outputs.error_text : NULL, - &err); - - xparam->outputs.error_code = err; - - goto out; - } -#endif - - host = parse_ip_address(xparam, &portno TSRMLS_CC); - - if (host == NULL) { - return -1; - } - - /* Note: the test here for php_stream_udp_socket_ops is important, because we - * want the default to be TCP sockets so that the openssl extension can - * re-use this code. */ - - sock->socket = php_network_connect_socket_to_host(host, portno, - stream->ops == &php_stream_udp_socket_ops ? SOCK_DGRAM : SOCK_STREAM, - xparam->op == STREAM_XPORT_OP_CONNECT_ASYNC, - xparam->inputs.timeout, - xparam->want_errortext ? &xparam->outputs.error_text : NULL, - &err - TSRMLS_CC); - - ret = sock->socket == -1 ? -1 : 0; - xparam->outputs.error_code = err; - - if (host) { - efree(host); - } - -#ifdef AF_UNIX -out: -#endif - - if (ret >= 0 && xparam->op == STREAM_XPORT_OP_CONNECT_ASYNC && err == EINPROGRESS) { - /* indicates pending connection */ - return 1; - } - - return ret; -} - -static inline int php_tcp_sockop_accept(php_stream *stream, php_netstream_data_t *sock, - php_stream_xport_param *xparam STREAMS_DC TSRMLS_DC) -{ - int clisock; - - xparam->outputs.client = NULL; - - clisock = php_network_accept_incoming(sock->socket, - xparam->want_textaddr ? &xparam->outputs.textaddr : NULL, - xparam->want_textaddr ? &xparam->outputs.textaddrlen : NULL, - xparam->want_addr ? &xparam->outputs.addr : NULL, - xparam->want_addr ? &xparam->outputs.addrlen : NULL, - xparam->inputs.timeout, - xparam->want_errortext ? &xparam->outputs.error_text : NULL, - &xparam->outputs.error_code - TSRMLS_CC); - - if (clisock >= 0) { - php_netstream_data_t *clisockdata; - - clisockdata = emalloc(sizeof(*clisockdata)); - - if (clisockdata == NULL) { - close(clisock); - /* technically a fatal error */ - } else { - memcpy(clisockdata, sock, sizeof(*clisockdata)); - clisockdata->socket = clisock; - - xparam->outputs.client = php_stream_alloc_rel(stream->ops, clisockdata, NULL, "r+"); - if (xparam->outputs.client) { - /* TODO: addref ? */ - xparam->outputs.client->context = stream->context; - } - } - } - - return xparam->outputs.client == NULL ? -1 : 0; -} - -static int php_tcp_sockop_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC) -{ - php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; - php_stream_xport_param *xparam; - - switch(option) { - case PHP_STREAM_OPTION_XPORT_API: - xparam = (php_stream_xport_param *)ptrparam; - - switch(xparam->op) { - case STREAM_XPORT_OP_CONNECT: - case STREAM_XPORT_OP_CONNECT_ASYNC: - xparam->outputs.returncode = php_tcp_sockop_connect(stream, sock, xparam TSRMLS_CC); - return PHP_STREAM_OPTION_RETURN_OK; - - case STREAM_XPORT_OP_BIND: - xparam->outputs.returncode = php_tcp_sockop_bind(stream, sock, xparam TSRMLS_CC); - return PHP_STREAM_OPTION_RETURN_OK; - - - case STREAM_XPORT_OP_ACCEPT: - xparam->outputs.returncode = php_tcp_sockop_accept(stream, sock, xparam STREAMS_CC TSRMLS_CC); - return PHP_STREAM_OPTION_RETURN_OK; - default: - /* fall through */ - ; - } - - /* fall through */ - default: - return php_sockop_set_option(stream, option, value, ptrparam TSRMLS_CC); - } -} - - -PHPAPI php_stream *php_stream_generic_socket_factory(const char *proto, long protolen, - char *resourcename, long resourcenamelen, - const char *persistent_id, int options, int flags, - struct timeval *timeout, - php_stream_context *context STREAMS_DC TSRMLS_DC) -{ - php_stream *stream = NULL; - php_netstream_data_t *sock; - php_stream_ops *ops; - - /* which type of socket ? */ - if (strncmp(proto, "tcp", protolen) == 0) { - ops = &php_stream_socket_ops; - } else if (strncmp(proto, "udp", protolen) == 0) { - ops = &php_stream_udp_socket_ops; - } -#ifdef AF_UNIX - else if (strncmp(proto, "unix", protolen) == 0) { - ops = &php_stream_unix_socket_ops; - } else if (strncmp(proto, "udg", protolen) == 0) { - ops = &php_stream_unixdg_socket_ops; - } -#endif - else { - /* should never happen */ - return NULL; - } - - sock = pemalloc(sizeof(php_netstream_data_t), persistent_id ? 1 : 0); - memset(sock, 0, sizeof(php_netstream_data_t)); - - sock->is_blocked = 1; - sock->timeout.tv_sec = FG(default_socket_timeout); - sock->timeout.tv_usec = 0; - - /* we don't know the socket until we have determined if we are binding or - * connecting */ - sock->socket = -1; - - stream = php_stream_alloc_rel(ops, sock, persistent_id, "r+"); - - if (stream == NULL) { - pefree(sock, persistent_id ? 1 : 0); - return NULL; - } - - if (flags == 0) { - return stream; - } - - return stream; -} - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/main/strlcat.c b/main/strlcat.c deleted file mode 100644 index a60d8f330b..0000000000 --- a/main/strlcat.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" - -#ifndef HAVE_STRLCAT - -/* $OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $ */ - -/* - * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <string.h> - -/* - * Appends src to string dst of size siz (unlike strncat, siz is the - * full size of dst, not space left). At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns strlen(src); if retval >= siz, truncation occurred. - */ -PHPAPI size_t php_strlcat(dst, src, siz) - char *dst; - const char *src; - size_t siz; -{ - register char *d = dst; - register const char *s = src; - register size_t n = siz; - size_t dlen; - - /* Find the end of dst and adjust bytes left but don't go past end */ - while (*d != '\0' && n-- != 0) - d++; - dlen = d - dst; - n = siz - dlen; - - if (n == 0) - return(dlen + strlen(s)); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; - n--; - } - s++; - } - *d = '\0'; - - return(dlen + (s - src)); /* count does not include NUL */ -} - -#endif /* !HAVE_STRLCAT */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/strlcpy.c b/main/strlcpy.c deleted file mode 100644 index 11faa550f1..0000000000 --- a/main/strlcpy.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" - -#ifndef HAVE_STRLCPY - -/* $OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $ */ - -/* - * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <string.h> - -/* - * Copy src to string dst of size siz. At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns strlen(src); if retval >= siz, truncation occurred. - */ -PHPAPI size_t php_strlcpy(dst, src, siz) - char *dst; - const char *src; - size_t siz; -{ - register char *d = dst; - register const char *s = src; - register size_t n = siz; - - /* Copy as many bytes as will fit */ - if (n != 0 && --n != 0) { - do { - if ((*d++ = *s++) == 0) - break; - } while (--n != 0); - } - - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while (*s++) - ; - } - - return(s - src - 1); /* count does not include NUL */ -} - -#endif /* !HAVE_STRLCPY */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/win95nt.h b/main/win95nt.h deleted file mode 100644 index 5750e4173f..0000000000 --- a/main/win95nt.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* Defines and types for Windows 95/NT */ -#define HAVE_DECLARED_TIMEZONE -#define WIN32_LEAN_AND_MEAN -#include <io.h> -#include <malloc.h> -#include <direct.h> -#include <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <sys/types.h> -typedef int uid_t; -typedef int gid_t; -typedef char * caddr_t; -#define lstat(x, y) stat(x, y) -#define _IFIFO 0010000 /* fifo */ -#define _IFBLK 0060000 /* block special */ -#define _IFLNK 0120000 /* symbolic link */ -#define S_IFIFO _IFIFO -#define S_IFBLK _IFBLK -#define S_IFLNK _IFLNK -#ifndef S_ISREG -#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -#endif -#define chdir(path) SetCurrentDirectory(path) -#define mkdir(a, b) _mkdir(a) -#define rmdir(a) _rmdir(a) -#define getpid _getpid -#define php_sleep(t) Sleep(t*1000) -#define getcwd(a, b) _getcwd(a, b) -#define off_t _off_t -typedef unsigned int uint; -typedef unsigned long ulong; -#if !NSAPI -typedef long pid_t; -#endif - -/* missing in vc5 math.h */ -#define M_PI 3.14159265358979323846 -#define M_TWOPI (M_PI * 2.0) -#define M_PI_2 1.57079632679489661923 -#ifndef M_PI_4 -#define M_PI_4 0.78539816339744830962 -#endif - -#if !defined(PHP_DEBUG) -#ifdef inline -#undef inline -#endif -#define inline __inline -#endif - -/* General Windows stuff */ -#define WINDOWS 1 - -/* Prevent use of VC5 OpenFile function */ -#define NOOPENFILE - -/* sendmail is built-in */ -#ifdef PHP_PROG_SENDMAIL -#undef PHP_PROG_SENDMAIL -#define PHP_PROG_SENDMAIL "Built in mailer" -#endif |