diff --git a/ext/standard/credits.c b/ext/standard/credits.c index 3a13855c356..8906d3595ad 100644 --- a/ext/standard/credits.c +++ b/ext/standard/credits.c @@ -24,6 +24,7 @@ #include "SAPI.h" #define CREDIT_LINE(module, authors) php_info_print_table_row(2, module, authors) +#define CREDIT_PUTS(s) php_output_write_western((s), strlen(s) TSRMLS_CC) /* {{{ php_print_credits */ @@ -34,9 +35,9 @@ PHPAPI void php_print_credits(int flag TSRMLS_DC) } if (!sapi_module.phpinfo_as_text) { - PUTS("

PHP Credits

\n"); + CREDIT_PUTS("

PHP Credits

\n"); } else { - PUTS("PHP Credits\n"); + CREDIT_PUTS("PHP Credits\n"); } if (flag & PHP_CREDITS_GROUP) { @@ -127,7 +128,7 @@ PHPAPI void php_print_credits(int flag TSRMLS_DC) } if (!sapi_module.phpinfo_as_text && flag & PHP_CREDITS_FULLPAGE) { - PUTS("\n"); + CREDIT_PUTS("\n"); } } /* }}} */ diff --git a/ext/standard/info.c b/ext/standard/info.c index 25ea0c903be..0255e979044 100644 --- a/ext/standard/info.c +++ b/ext/standard/info.c @@ -51,7 +51,7 @@ ZEND_EXTERN_MODULE_GLOBALS(iconv) #include #define SECTION(name) if (!sapi_module.phpinfo_as_text) { \ - PUTS("

" name "

\n"); \ + php_info_print("

" name "

\n"); \ } else { \ php_info_print_table_start(); \ php_info_print_table_header(1, name); \ @@ -60,33 +60,131 @@ ZEND_EXTERN_MODULE_GLOBALS(iconv) PHPAPI extern char *php_ini_opened_path; PHPAPI extern char *php_ini_scanned_files; - -static int php_info_write_wrapper(const char *str, uint str_length) + +static int php_info_print_html_esc(const char *str, int len) { int new_len, written; - char *elem_esc; - + char *new_str; TSRMLS_FETCH(); - - elem_esc = php_escape_html_entities((char *)str, str_length, &new_len, 0, ENT_QUOTES, NULL TSRMLS_CC); - - written = PHPWRITE(elem_esc, new_len); - - efree(elem_esc); - + + new_str = php_escape_html_entities((char *) str, len, &new_len, 0, ENT_QUOTES, "iso-8859-1" TSRMLS_CC); + written = php_output_write_western(new_str, new_len TSRMLS_CC); + efree(new_str); return written; } +static int php_info_uprint_html_esc(const UChar *str, int len) +{ + UErrorCode status = U_ZERO_ERROR; + char *new_str = NULL, *esc_str; + int new_len, esc_len, written; + TSRMLS_FETCH(); + + zend_unicode_to_string_ex(UG(utf8_conv), &new_str, &new_len, str, len, &status); + if (U_FAILURE(status)) { + return 0; + } + + esc_str = php_escape_html_entities(new_str, new_len, &esc_len, 0, ENT_QUOTES, "utf8" TSRMLS_CC); + written = php_output_write_utf8(esc_str, esc_len TSRMLS_CC); + efree(new_str); + return written; +} +static int php_info_printf(const char *fmt, ...) +{ + char *buf; + int len, written; + va_list argv; + TSRMLS_FETCH(); + + va_start(argv, fmt); + len = vspprintf(&buf, 0, fmt, argv); + va_end(argv); + + written = php_output_write_western(buf, len TSRMLS_CC); + efree(buf); + return written; +} + +static void php_info_print_request_uri(TSRMLS_D) +{ + if (SG(request_info).request_uri) { + php_info_print_html_esc(SG(request_info).request_uri, strlen(SG(request_info).request_uri)); + } +} + + +static int php_info_print(const char *str) +{ + TSRMLS_FETCH(); + return php_output_write_western(str, strlen(str) TSRMLS_CC); +} + +static int php_info_uprint(const UChar *str, int len) +{ + TSRMLS_FETCH(); + return php_output_write_unicode(str, len TSRMLS_CC); +} + +static void php_info_print_stream_hash(const char *name, HashTable *ht TSRMLS_DC) +{ + zstr key; + uint len; + int type; + + if (ht) { + if (zend_hash_num_elements(ht)) { + if (!sapi_module.phpinfo_as_text) { + php_info_printf("Registered %s", name); + } else { + php_info_printf("\nRegistered %s => ", name); + } + + zend_hash_internal_pointer_reset(ht); + type = zend_hash_get_current_key_ex(ht, &key, &len, NULL, 0, NULL); + do { + switch (type) { + case IS_STRING: + php_info_print(key.s); + break; + case IS_UNICODE: + php_info_uprint(key.u, len); + break; + } + + zend_hash_move_forward(ht); + type = zend_hash_get_current_key_ex(ht, &key, &len, NULL, 0, NULL); + + if (type == IS_STRING || type == IS_UNICODE) { + php_info_print(", "); + } else { + break; + } + } while (1); + + if (!sapi_module.phpinfo_as_text) { + php_info_print("\n"); + } + } else { + char reg_name[128]; + snprintf(reg_name, sizeof(reg_name), "Registered %s", name); + php_info_print_table_row(2, reg_name, "none registered"); + } + } else { + php_info_print_table_row(2, name, "disabled"); + } +} + /* {{{ _display_module_info - */ +*/ static int _display_module_info(zend_module_entry *module, void *arg TSRMLS_DC) { int show_info_func = *((int *) arg); if (show_info_func && module->info_func) { if (!sapi_module.phpinfo_as_text) { - php_printf("

%s

\n", module->name, module->name); + php_info_printf("

%s

\n", module->name, module->name); } else { php_info_print_table_start(); php_info_print_table_header(1, module->name); @@ -95,13 +193,13 @@ static int _display_module_info(zend_module_entry *module, void *arg TSRMLS_DC) module->info_func(module TSRMLS_CC); } else if (!show_info_func && !module->info_func) { if (!sapi_module.phpinfo_as_text) { - php_printf(""); - php_printf(""); - php_printf("%s", module->name); - php_printf("\n"); + php_info_printf(""); + php_info_printf(""); + php_info_printf("%s", module->name); + php_info_printf("\n"); } else { - php_printf("%s", module->name); - php_printf("\n"); + php_info_printf("%s", module->name); + php_info_printf("\n"); } } return 0; @@ -116,7 +214,6 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC) zstr string_key; uint string_len; ulong num_key; - char *elem_esc = NULL; zend_is_auto_global(name, name_length TSRMLS_CC); @@ -125,76 +222,78 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC) zend_hash_internal_pointer_reset(Z_ARRVAL_PP(data)); while (zend_hash_get_current_data(Z_ARRVAL_PP(data), (void **) &tmp) == SUCCESS) { if (!sapi_module.phpinfo_as_text) { - PUTS(""); - PUTS(""); - + php_info_print(""); + php_info_print(""); } - PUTS(name); - PUTS("[\""); + php_info_print(name); + php_info_print("[\""); switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(data), &string_key, &string_len, &num_key, 0, NULL)) { + case HASH_KEY_IS_UNICODE: + if (!sapi_module.phpinfo_as_text) { + php_info_uprint_html_esc(string_key.u, string_len-1); + } else { + php_info_uprint(string_key.u, string_len); + } + break; case HASH_KEY_IS_STRING: if (!sapi_module.phpinfo_as_text) { - elem_esc = php_info_html_esc(string_key.s TSRMLS_CC); - PUTS(elem_esc); - efree(elem_esc); + php_info_print_html_esc(string_key.s, string_len-1); } else { - PUTS(string_key.s); - } + php_info_print(string_key.s); + } break; case HASH_KEY_IS_LONG: - php_printf("%ld", num_key); + php_info_printf("%ld", num_key); break; } - PUTS("\"]"); + php_info_print("\"]"); if (!sapi_module.phpinfo_as_text) { - PUTS(""); + php_info_print(""); } else { - PUTS(" => "); + php_info_print(" => "); } if (Z_TYPE_PP(tmp) == IS_ARRAY) { if (!sapi_module.phpinfo_as_text) { - PUTS("
");
-					zend_print_zval_r_ex((zend_write_func_t) php_info_write_wrapper, *tmp, 0 TSRMLS_CC);
-					PUTS("
"); + php_info_print("
");
+					zend_print_zval_r_ex((zend_write_func_t) php_info_print_html_esc, *tmp, 0 TSRMLS_CC);
+					php_info_print("
"); } else { zend_print_zval_r(*tmp, 0 TSRMLS_CC); } - } else if (Z_TYPE_PP(tmp) != IS_STRING) { - tmp2 = **tmp; - zval_copy_ctor(&tmp2); - convert_to_string(&tmp2); - if (!sapi_module.phpinfo_as_text) { - if (Z_STRLEN(tmp2) == 0) { - PUTS("no value"); - } else { - elem_esc = php_info_html_esc(Z_STRVAL(tmp2) TSRMLS_CC); - PUTS(elem_esc); - efree(elem_esc); - } - } else { - PUTS(Z_STRVAL(tmp2)); - } - zval_dtor(&tmp2); } else { - if (!sapi_module.phpinfo_as_text) { - if (Z_STRLEN_PP(tmp) == 0) { - PUTS("no value"); - } else { - elem_esc = php_info_html_esc(Z_STRVAL_PP(tmp) TSRMLS_CC); - PUTS(elem_esc); - efree(elem_esc); - } - } else { - PUTS(Z_STRVAL_PP(tmp)); - } + tmp2 = **tmp; + switch (Z_TYPE_PP(tmp)) { + default: + tmp = NULL; + zval_copy_ctor(&tmp2); + convert_to_string(&tmp2); + case IS_STRING: + case IS_UNICODE: + if (!sapi_module.phpinfo_as_text) { + if (Z_UNILEN(tmp2) == 0) { + php_info_print("no value"); + } else if (Z_TYPE(tmp2) == IS_UNICODE){ + php_info_uprint_html_esc(Z_USTRVAL(tmp2), Z_USTRLEN(tmp2)); + } else { + php_info_print_html_esc(Z_STRVAL(tmp2), Z_STRLEN(tmp2)); + } + } else if(Z_TYPE(tmp2) == IS_UNICODE) { + php_info_uprint(Z_USTRVAL(tmp2), Z_USTRLEN(tmp2)); + } else { + php_info_print(Z_STRVAL(tmp2)); + } + } + if (!tmp) { + zval_dtor(&tmp2); + } } if (!sapi_module.phpinfo_as_text) { - PUTS("\n"); + php_info_print("\n"); } else { - PUTS("\n"); - } + php_info_print("\n"); + } zend_hash_move_forward(Z_ARRVAL_PP(data)); } } @@ -205,9 +304,9 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC) */ void php_info_print_style(TSRMLS_D) { - php_printf("\n"); + php_info_printf("\n"); } /* }}} */ @@ -341,49 +440,14 @@ PHPAPI char *php_get_uname(char mode) */ PHPAPI void php_print_info_htmlhead(TSRMLS_D) { - -/*** none of this is needed now *** - - const char *charset = NULL; - - if (SG(default_charset)) { - charset = SG(default_charset); - } - -#if HAVE_MBSTRING - if (php_output_handler_started("mb_output_handler")) { - if (MBSTRG(current_http_output_encoding) == mbfl_no_encoding_pass) { - charset = "US-ASCII"; - } else { - charset = mbfl_no2preferred_mime_name(MBSTRG(current_http_output_encoding)); - } - } -#endif - -#if HAVE_ICONV - if (php_output_handler_started("ob_iconv_handler")) { - charset = ICONVG(output_encoding); - } -#endif - - if (!charset || !charset[0]) { - charset = "US-ASCII"; - } - -*** none of that is needed now ***/ - - - PUTS("\n"); - PUTS(""); - PUTS("\n"); + php_info_print("\n"); + php_info_print(""); + php_info_print("\n"); php_info_print_style(TSRMLS_C); - PUTS("phpinfo()"); - PUTS(""); -/* - php_printf("\n", charset); -*/ - PUTS("\n"); - PUTS("
\n"); + php_info_print("phpinfo()"); + php_info_print(""); + php_info_print("\n"); + php_info_print("
\n"); } /* }}} */ @@ -409,8 +473,8 @@ PHPAPI void php_print_info(int flag TSRMLS_DC) if (!sapi_module.phpinfo_as_text) { php_print_info_htmlhead(TSRMLS_C); } else { - PUTS("phpinfo()\n"); - } + php_info_print("phpinfo()\n"); + } if (flag & PHP_INFO_GENERAL) { char *zend_version = get_zend_version(); @@ -424,21 +488,17 @@ PHPAPI void php_print_info(int flag TSRMLS_DC) } if (expose_php && !sapi_module.phpinfo_as_text) { - PUTS("\"PHP"); + php_info_print("\" alt=\"PHP Logo\" />"); } if (!sapi_module.phpinfo_as_text) { - php_printf("

PHP Version %s

\n", PHP_VERSION); + php_info_printf("

PHP Version %s

\n", PHP_VERSION); } else { php_info_print_table_row(2, "PHP Version", PHP_VERSION); } @@ -501,139 +561,24 @@ PHPAPI void php_print_info(int flag TSRMLS_DC) #else php_info_print_table_row(2, "IPv6 Support", "disabled" ); #endif - { - HashTable *url_stream_wrappers_hash; - zstr stream_protocol; - char *stream_protocols_buf = NULL; - uint stream_protocol_len, stream_protocols_buf_len = 0; - ulong num_key; - - if ((url_stream_wrappers_hash = php_stream_get_url_stream_wrappers_hash())) { - for (zend_hash_internal_pointer_reset(url_stream_wrappers_hash); - zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, &stream_protocol_len, &num_key, 0, NULL) == HASH_KEY_IS_STRING; - zend_hash_move_forward(url_stream_wrappers_hash)) { - stream_protocols_buf = erealloc(stream_protocols_buf, stream_protocols_buf_len + stream_protocol_len + 2 + 1); - memcpy(stream_protocols_buf + stream_protocols_buf_len, stream_protocol.s, stream_protocol_len); - stream_protocols_buf[stream_protocols_buf_len + stream_protocol_len] = ','; - stream_protocols_buf[stream_protocols_buf_len + stream_protocol_len + 1] = ' '; - stream_protocols_buf_len += stream_protocol_len + 2; - } - if (stream_protocols_buf) { - stream_protocols_buf[stream_protocols_buf_len - 2] = ' '; - stream_protocols_buf[stream_protocols_buf_len] = 0; - php_info_print_table_row(2, "Registered PHP Streams", stream_protocols_buf); - efree(stream_protocols_buf); - } else { - /* Any chances we will ever hit this? */ - php_info_print_table_row(2, "Registered PHP Streams", "no streams registered"); - } - } else { - /* Any chances we will ever hit this? */ - php_info_print_table_row(2, "PHP Streams", "disabled"); /* ?? */ - } - } - - { - HashTable *stream_xport_hash; - zstr xport_name; - char *xport_buf = NULL; - uint xport_name_len, xport_buf_len = 0, xport_buf_size = 0; - ulong num_key; - - if ((stream_xport_hash = php_stream_xport_get_hash())) { - for(zend_hash_internal_pointer_reset(stream_xport_hash); - zend_hash_get_current_key_ex(stream_xport_hash, &xport_name, &xport_name_len, &num_key, 0, NULL) == HASH_KEY_IS_STRING; - zend_hash_move_forward(stream_xport_hash)) { - if (xport_buf_len + xport_name_len + 3 > xport_buf_size) { - while (xport_buf_len + xport_name_len + 3 > xport_buf_size) { - xport_buf_size += 256; - } - if (xport_buf) { - xport_buf = erealloc(xport_buf, xport_buf_size); - } else { - xport_buf = emalloc(xport_buf_size); - } - } - if (xport_buf_len > 0) { - xport_buf[xport_buf_len++] = ','; - xport_buf[xport_buf_len++] = ' '; - } - memcpy(xport_buf + xport_buf_len, xport_name.s, xport_name_len); - xport_buf_len += xport_name_len; - xport_buf[xport_buf_len] = '\0'; - } - if (xport_buf) { - php_info_print_table_row(2, "Registered Stream Socket Transports", xport_buf); - efree(xport_buf); - } else { - /* Any chances we will ever hit this? */ - php_info_print_table_row(2, "Registered Stream Socket Transports", "no transports registered"); - } - } else { - /* Any chances we will ever hit this? */ - php_info_print_table_row(2, "Stream Socket Transports", "disabled"); /* ?? */ - } - } - - { - HashTable *stream_filter_hash; - zstr filter_name; - char *filter_buf = NULL; - uint filter_name_len, filter_buf_len = 0, filter_buf_size = 0; - ulong num_key; - - if ((stream_filter_hash = php_get_stream_filters_hash())) { - for(zend_hash_internal_pointer_reset(stream_filter_hash); - zend_hash_get_current_key_ex(stream_filter_hash, &filter_name, &filter_name_len, &num_key, 0, NULL) == HASH_KEY_IS_STRING; - zend_hash_move_forward(stream_filter_hash)) { - if (filter_buf_len + filter_name_len + 3 > filter_buf_size) { - while (filter_buf_len + filter_name_len + 3 > filter_buf_size) { - filter_buf_size += 256; - } - if (filter_buf) { - filter_buf = erealloc(filter_buf, filter_buf_size); - } else { - filter_buf = emalloc(filter_buf_size); - } - } - if (filter_buf_len > 0) { - filter_buf[filter_buf_len++] = ','; - filter_buf[filter_buf_len++] = ' '; - } - memcpy(filter_buf + filter_buf_len, filter_name.s, filter_name_len); - filter_buf_len += filter_name_len; - filter_buf[filter_buf_len] = '\0'; - } - if (filter_buf) { - php_info_print_table_row(2, "Registered Stream Filters", filter_buf); - efree(filter_buf); - } else { - /* Any chances we will ever hit this? */ - php_info_print_table_row(2, "Registered Stream Filters", "no filters registered"); - } - } else { - /* Any chances we will ever hit this? */ - php_info_print_table_row(2, "Stream Filters", "disabled"); /* ?? */ - } - } + php_info_print_stream_hash("PHP Streams", php_stream_get_url_stream_wrappers_hash() TSRMLS_CC); + php_info_print_stream_hash("Stream Socket Transports", php_stream_xport_get_hash() TSRMLS_CC); + php_info_print_stream_hash("Stream Filters", php_get_stream_filters_hash() TSRMLS_CC); + php_info_print_table_end(); /* Zend Engine */ php_info_print_box_start(0); if (expose_php && !sapi_module.phpinfo_as_text) { - PUTS("\"Zend\n"); + php_info_print("\"Zend\n"); } - PUTS("This program makes use of the Zend Scripting Language Engine:"); - PUTS(!sapi_module.phpinfo_as_text?"
":"\n"); + php_info_print("This program makes use of the Zend Scripting Language Engine:"); + php_info_print(!sapi_module.phpinfo_as_text?"
":"\n"); if (sapi_module.phpinfo_as_text) { - PUTS(zend_version); + php_info_print(zend_version); } else { zend_html_puts(zend_version, strlen(zend_version) TSRMLS_CC); } @@ -643,15 +588,11 @@ PHPAPI void php_print_info(int flag TSRMLS_DC) if ((flag & PHP_INFO_CREDITS) && expose_php && !sapi_module.phpinfo_as_text) { php_info_print_hr(); - PUTS("

"); - PUTS("PHP Credits"); - PUTS("

\n"); + php_info_print("

"); + php_info_print("PHP Credits"); + php_info_print("

\n"); } zend_ini_sort_entries(TSRMLS_C); @@ -659,7 +600,7 @@ PHPAPI void php_print_info(int flag TSRMLS_DC) if (flag & PHP_INFO_CONFIGURATION) { php_info_print_hr(); if (!sapi_module.phpinfo_as_text) { - PUTS("

Configuration

\n"); + php_info_print("

Configuration

\n"); } else { SECTION("Configuration"); } @@ -740,37 +681,37 @@ PHPAPI void php_print_info(int flag TSRMLS_DC) if (!sapi_module.phpinfo_as_text) { SECTION("PHP License"); php_info_print_box_start(0); - PUTS("

\n"); - PUTS("This program is free software; you can redistribute it and/or modify "); - PUTS("it under the terms of the PHP License as published by the PHP Group "); - PUTS("and included in the distribution in the file: LICENSE\n"); - PUTS("

\n"); - PUTS("

"); - PUTS("This program is distributed in the hope that it will be useful, "); - PUTS("but WITHOUT ANY WARRANTY; without even the implied warranty of "); - PUTS("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); - PUTS("

\n"); - PUTS("

"); - PUTS("If you did not receive a copy of the PHP license, or have any questions about "); - PUTS("PHP licensing, please contact license@php.net.\n"); - PUTS("

\n"); + php_info_print("

\n"); + php_info_print("This program is free software; you can redistribute it and/or modify "); + php_info_print("it under the terms of the PHP License as published by the PHP Group "); + php_info_print("and included in the distribution in the file: LICENSE\n"); + php_info_print("

\n"); + php_info_print("

"); + php_info_print("This program is distributed in the hope that it will be useful, "); + php_info_print("but WITHOUT ANY WARRANTY; without even the implied warranty of "); + php_info_print("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); + php_info_print("

\n"); + php_info_print("

"); + php_info_print("If you did not receive a copy of the PHP license, or have any questions about "); + php_info_print("PHP licensing, please contact license@php.net.\n"); + php_info_print("

\n"); php_info_print_box_end(); } else { - PUTS("\nPHP License\n"); - PUTS("This program is free software; you can redistribute it and/or modify\n"); - PUTS("it under the terms of the PHP License as published by the PHP Group\n"); - PUTS("and included in the distribution in the file: LICENSE\n"); - PUTS("\n"); - PUTS("This program is distributed in the hope that it will be useful,\n"); - PUTS("but WITHOUT ANY WARRANTY; without even the implied warranty of\n"); - PUTS("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); - PUTS("\n"); - PUTS("If you did not receive a copy of the PHP license, or have any\n"); - PUTS("questions about PHP licensing, please contact license@php.net.\n"); + php_info_print("\nPHP License\n"); + php_info_print("This program is free software; you can redistribute it and/or modify\n"); + php_info_print("it under the terms of the PHP License as published by the PHP Group\n"); + php_info_print("and included in the distribution in the file: LICENSE\n"); + php_info_print("\n"); + php_info_print("This program is distributed in the hope that it will be useful,\n"); + php_info_print("but WITHOUT ANY WARRANTY; without even the implied warranty of\n"); + php_info_print("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); + php_info_print("\n"); + php_info_print("If you did not receive a copy of the PHP license, or have any\n"); + php_info_print("questions about PHP licensing, please contact license@php.net.\n"); } } if (!sapi_module.phpinfo_as_text) { - PUTS("
"); + php_info_print("
"); } } /* }}} */ @@ -779,16 +720,16 @@ PHPAPI void php_print_info(int flag TSRMLS_DC) PHPAPI void php_info_print_table_start() { if (!sapi_module.phpinfo_as_text) { - php_printf("\n"); + php_info_print("
\n"); } else { - php_printf("\n"); + php_info_print("\n"); } } PHPAPI void php_info_print_table_end() { if (!sapi_module.phpinfo_as_text) { - php_printf("

\n"); + php_info_print("
\n"); } } @@ -798,13 +739,13 @@ PHPAPI void php_info_print_box_start(int flag) php_info_print_table_start(); if (flag) { if (!sapi_module.phpinfo_as_text) { - php_printf("\n"); + php_info_print("\n"); } } else { if (!sapi_module.phpinfo_as_text) { - php_printf("\n"); + php_info_print("\n"); } else { - php_printf("\n"); + php_info_print("\n"); } } } @@ -812,7 +753,7 @@ PHPAPI void php_info_print_box_start(int flag) PHPAPI void php_info_print_box_end() { if (!sapi_module.phpinfo_as_text) { - php_printf("\n"); + php_info_print("\n"); } php_info_print_table_end(); } @@ -820,9 +761,9 @@ PHPAPI void php_info_print_box_end() PHPAPI void php_info_print_hr() { if (!sapi_module.phpinfo_as_text) { - php_printf("
\n"); + php_info_print("
\n"); } else { - php_printf("\n\n _______________________________________________________________________\n\n"); + php_info_print("\n\n _______________________________________________________________________\n\n"); } } @@ -831,10 +772,10 @@ PHPAPI void php_info_print_table_colspan_header(int num_cols, char *header) int spaces; if (!sapi_module.phpinfo_as_text) { - php_printf("%s\n", num_cols, header ); + php_info_printf("%s\n", num_cols, header ); } else { spaces = (74 - strlen(header)); - php_printf("%*s%s%*s\n", (int)(spaces/2), " ", header, (int)(spaces/2), " "); + php_info_printf("%*s%s%*s\n", (int)(spaces/2), " ", header, (int)(spaces/2), " "); } } @@ -846,11 +787,9 @@ PHPAPI void php_info_print_table_header(int num_cols, ...) va_list row_elements; char *row_element; - TSRMLS_FETCH(); - va_start(row_elements, num_cols); if (!sapi_module.phpinfo_as_text) { - php_printf(""); + php_info_print(""); } for (i=0; i"); - PUTS(row_element); - PUTS(""); + php_info_print(""); + php_info_print(row_element); + php_info_print(""); } else { - PUTS(row_element); + php_info_print(row_element); if (i < num_cols-1) { - PUTS(" => "); + php_info_print(" => "); } else { - PUTS("\n"); - } - } + php_info_print("\n"); + } + } } if (!sapi_module.phpinfo_as_text) { - php_printf("\n"); - } + php_info_print("\n"); + } va_end(row_elements); } @@ -885,49 +824,41 @@ static void php_info_print_table_row_internal(int num_cols, { int i; char *row_element; - char *elem_esc = NULL; -/* - int elem_esc_len; -*/ - - TSRMLS_FETCH(); if (!sapi_module.phpinfo_as_text) { - php_printf(""); + php_info_print(""); } for (i=0; i", + php_info_printf("", (i==0 ? "e" : value_class ) ); } row_element = va_arg(row_elements, char *); if (!row_element || !*row_element) { if (!sapi_module.phpinfo_as_text) { - PUTS( "no value" ); + php_info_print( "no value" ); } else { - PUTS( " " ); + php_info_print( " " ); } } else { if (!sapi_module.phpinfo_as_text) { - elem_esc = php_info_html_esc(row_element TSRMLS_CC); - PUTS(elem_esc); - efree(elem_esc); + php_info_print_html_esc(row_element, strlen(row_element)); } else { - PUTS(row_element); + php_info_print(row_element); if (i < num_cols-1) { - PUTS(" => "); + php_info_print(" => "); } } } if (!sapi_module.phpinfo_as_text) { - php_printf(" "); + php_info_print(" "); } else if (i == (num_cols - 1)) { - PUTS("\n"); + php_info_print("\n"); } } if (!sapi_module.phpinfo_as_text) { - php_printf("\n"); + php_info_print("\n"); } } /* }}} */ @@ -980,7 +911,7 @@ void register_phpinfo_constants(INIT_FUNC_ARGS) } /* }}} */ -/* {{{ proto void phpinfo([int what]) +/* {{{ proto void phpinfo([int what]) U Output a page of useful information about PHP and the current request */ PHP_FUNCTION(phpinfo) { @@ -1029,7 +960,7 @@ PHP_FUNCTION(phpversion) } /* }}} */ -/* {{{ proto void phpcredits([int flag]) +/* {{{ proto void phpcredits([int flag]) U Prints the list of people who've contributed to the PHP project */ PHP_FUNCTION(phpcredits) { diff --git a/main/output.c b/main/output.c index 0fc8e03713b..6df8fdfdfaf 100644 --- a/main/output.c +++ b/main/output.c @@ -153,6 +153,11 @@ PHPAPI void php_output_deactivate(TSRMLS_D) OG(handlers) = NULL; } + if (OG(conv).western) { + ucnv_close(OG(conv).western); + OG(conv).western = NULL; + } + if (OG(default_output_handler_name)) { zval_ptr_dtor(&OG(default_output_handler_name)); OG(default_output_handler_name) = NULL; @@ -231,46 +236,75 @@ PHPAPI int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC) Buffered ASCII write */ PHPAPI int php_output_write_ascii(const char *str, size_t len TSRMLS_DC) { - UErrorCode status = U_ZERO_ERROR; - char *buf_str = NULL; - int buf_len = 0; - - if (OG(flags) & PHP_OUTPUT_DISABLED) { - return 0; + return php_output_write_encoded(str, len, UG(ascii_conv), NULL TSRMLS_CC); +} +/* }}} */ + +/* {{{ int php_output_write_utf8(const char *str, size_t len TSRMLS_DC) + Buffered UTF8 write */ +PHPAPI int php_output_write_utf8(const char *str, size_t len TSRMLS_DC) +{ + return php_output_write_encoded(str, len, UG(utf8_conv), NULL TSRMLS_CC); +} +/* }}} */ + +/* {{{ int php_output_write_western(const char *str, size_t len TSRMLS_DC) + Buffered western cs write */ +PHPAPI int php_output_write_western(const char *str, size_t len TSRMLS_DC) +{ + if (!OG(conv).western) { + UErrorCode status = U_ZERO_ERROR; + + OG(conv).western = ucnv_open("latin1", &status); + if (U_FAILURE(status)) { + return 0; + } } - - zend_convert_encodings(UG(output_encoding_conv), UG(ascii_conv), - &buf_str, &buf_len, str, len, &status); - if (U_ZERO_ERROR == status) { - php_output_op(PHP_OUTPUT_HANDLER_WRITE, buf_str, buf_len TSRMLS_CC); - } - if (buf_str) { - efree(buf_str); - } - return (int) len; + return php_output_write_encoded(str, len, OG(conv).western, NULL TSRMLS_CC); } /* }}} */ /* {{{ int php_output_write_unicode(const UChar *str, size_t len TSRMLS_DC) Buffered Unicode write */ PHPAPI int php_output_write_unicode(const UChar *str, size_t len TSRMLS_DC) +{ + return php_output_write_encoded(str, len, NULL, NULL TSRMLS_CC); +} +/* }}} */ + +/* {{{ int php_output_write_encoded(const void *str, size_t len TSRMLS_DC) + Buffered write with specified encodings */ +PHPAPI int php_output_write_encoded(const void *str, size_t len, UConverter *src_encoding_conv, UConverter *dst_encoding_conv TSRMLS_DC) { UErrorCode status = U_ZERO_ERROR; - char *buf_str = NULL; - int buf_len = 0; + char *new_str = NULL; + int new_len; if (OG(flags) & PHP_OUTPUT_DISABLED) { return 0; } - zend_unicode_to_string_ex(UG(output_encoding_conv), &buf_str, &buf_len, str, len, &status); - if (U_ZERO_ERROR == status) { - php_output_op(PHP_OUTPUT_HANDLER_WRITE, buf_str, buf_len TSRMLS_CC); + if (!dst_encoding_conv) { + dst_encoding_conv = ZEND_U_CONVERTER(UG(output_encoding_conv)); } - if (buf_str) { - efree(buf_str); + + if (src_encoding_conv) { + zend_convert_encodings(dst_encoding_conv, src_encoding_conv, &new_str, &new_len, str, len, &status); + } else { + zend_unicode_to_string_ex(dst_encoding_conv, &new_str, &new_len, str, len, &status); } - return (int) len; + + if (U_SUCCESS(status)) { + php_output_op(PHP_OUTPUT_HANDLER_WRITE, new_str, new_len TSRMLS_CC); + } else { + len = 0; + } + + if (new_str) { + efree(new_str); + } + + return len; } /* }}} */ diff --git a/main/php_output.h b/main/php_output.h index 5159f0e05c7..7ea4a31f438 100644 --- a/main/php_output.h +++ b/main/php_output.h @@ -148,6 +148,9 @@ ZEND_BEGIN_MODULE_GLOBALS(output) int output_start_lineno; zval *default_output_handler_name; zval *devnull_output_handler_name; + struct { + UConverter *western; + } conv; ZEND_END_MODULE_GLOBALS(output); /* there should not be a need to use OG() from outside of output.c */ @@ -205,7 +208,10 @@ PHPAPI char *php_output_get_start_filename(TSRMLS_D); PHPAPI int php_output_get_start_lineno(TSRMLS_D); PHPAPI int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC); +PHPAPI int php_output_write_encoded(const void *str, size_t len, UConverter *src_encoding_conv, UConverter *dst_encoding_conv TSRMLS_DC); PHPAPI int php_output_write_unicode(const UChar *str, size_t len TSRMLS_DC); +PHPAPI int php_output_write_western(const char *str, size_t len TSRMLS_DC); +PHPAPI int php_output_write_utf8(const char *str, size_t len TSRMLS_DC); PHPAPI int php_output_write_ascii(const char *str, size_t len TSRMLS_DC); PHPAPI int php_output_write(const char *str, size_t len TSRMLS_DC);