Permalink
Browse files

* implement new output API, fixing some bugs and implementing some fe…

…ature

  requests--let's see what I can dig out of the bugtracker for NEWS--
  and while crossing the road:
   * implemented new zlib API
   * fixed up ext/tidy (what was "s&" in zend_parse_parameters() supposed to do?)

Thanks to Jani and Felipe for pioneering.
  • Loading branch information...
1 parent 27299b7 commit 11d24c1593d6617f73d3f290617bd8994182f4dc @m6w6 m6w6 committed May 31, 2010
Showing with 3,410 additions and 2,550 deletions.
  1. +426 −0 README.NEW-OUTPUT-API
  2. +67 −62 ext/iconv/iconv.c
  3. +4 −4 ext/session/session.c
  4. +26 −76 ext/soap/soap.c
  5. +21 −29 ext/standard/basic_functions.c
  6. +3 −1 ext/standard/exec.c
  7. +2 −2 ext/standard/head.c
  8. +242 −357 ext/standard/info.c
  9. +2 −0 ext/standard/tests/general_functions/ob_get_flush_error.phpt
  10. +4 −4 ext/standard/url_scanner_ex.c
  11. +3 −3 ext/standard/url_scanner_ex.re
  12. +3 −3 ext/standard/var.c
  13. +1 −0 ext/tidy/php_tidy.h
  14. +149 −105 ext/tidy/tidy.c
  15. +1 −1 ext/zlib/CREDITS
  16. +8 −1 ext/zlib/config0.m4
  17. +29 −17 ext/zlib/php_zlib.h
  18. +2 −0 ext/zlib/tests/006.phpt
  19. +8 −8 ext/zlib/tests/007.phpt
  20. +3 −3 ext/zlib/tests/gzcompress_basic1.phpt
  21. +17 −11 ext/zlib/tests/gzcompress_error1.phpt
  22. +2 −4 ext/zlib/tests/gzcompress_variation1.phpt
  23. +1 −1 ext/zlib/tests/gzdeflate_basic1.phpt
  24. +14 −4 ext/zlib/tests/gzdeflate_error1.phpt
  25. +20 −7 ext/zlib/tests/gzencode_basic1.phpt
  26. +4 −4 ext/zlib/tests/gzencode_error1.phpt
  27. +5 −1 ext/zlib/tests/gzencode_variation1.phpt
  28. +42 −0 ext/zlib/tests/gzencode_variation2-win32.phpt
  29. +7 −1 ext/zlib/tests/gzencode_variation2.phpt
  30. +7 −4 ext/zlib/tests/gzinflate-bug42663.phpt
  31. +1 −1 ext/zlib/tests/gzinflate_length.phpt
  32. +7 −2 ext/zlib/tests/gzreadgzwrite.phpt
  33. +12 −3 ext/zlib/tests/gzreadgzwriteplain.phpt
  34. +2 −6 ext/zlib/tests/gzuncompress_error1.phpt
  35. +1 −1 ext/zlib/tests/gzwrite_variation1.phpt
  36. +20 −0 ext/zlib/tests/ob_001.phpt
  37. +18 −0 ext/zlib/tests/ob_002.phpt
  38. +25 −0 ext/zlib/tests/ob_003.phpt
  39. +25 −0 ext/zlib/tests/ob_004.phpt
  40. +21 −0 ext/zlib/tests/ob_005.phpt
  41. +1 −1 ext/zlib/tests/readgzfile_variation14.phpt
  42. +9 −0 ext/zlib/tests/readgzfile_variation4.phpt
  43. +8 −1 ext/zlib/tests/readgzfile_variation5.phpt
  44. +1 −0 ext/zlib/tests/readgzfile_variation6.phpt
  45. +7 −0 ext/zlib/tests/readgzfile_variation7.phpt
  46. +2 −2 ext/zlib/tests/zlib_filter_inflate2.phpt
  47. +632 −891 ext/zlib/zlib.c
  48. +16 −9 ext/zlib/zlib_filter.c
  49. +1 −1 ext/zlib/zlib_fopen_wrapper.c
  50. +2 −2 main/SAPI.c
  51. +33 −27 main/main.c
  52. +1,060 −664 main/output.c
  53. +1 −14 main/php.h
  54. +1 −1 main/php_logos.c
  55. +227 −67 main/php_output.h
  56. +1 −1 sapi/apache/mod_php5.c
  57. +1 −1 sapi/apache/php_apache.c
  58. +1 −1 sapi/apache2handler/php_functions.c
  59. +1 −1 sapi/apache_hooks/mod_php5.c
  60. +1 −1 sapi/apache_hooks/php_apache.c
  61. +5 −8 sapi/cgi/cgi_main.c
  62. +4 −4 sapi/cli/php_cli.c
  63. +5 −7 sapi/milter/php_milter.c
  64. +1 −1 sapi/nsapi/nsapi.c
  65. +2 −2 tests/output/bug46897.phpt
  66. +0 −2 tests/output/ob_011.phpt
  67. +37 −35 tests/output/ob_013.phpt
  68. +6 −6 tests/output/ob_017.phpt
  69. +2 −2 tests/output/ob_clean_basic_001.phpt
  70. +2 −2 tests/output/ob_end_clean_basic_001.phpt
  71. +3 −3 tests/output/ob_end_flush_basic_001.phpt
  72. +2 −2 tests/output/ob_flush_basic_001.phpt
  73. +1 −0 tests/output/ob_get_clean_basic_001.phpt
  74. +2 −2 tests/output/ob_get_level_basic_001.phpt
  75. +11 −12 tests/output/ob_get_status.phpt
  76. +14 −4 tests/output/ob_start_basic_004.phpt
  77. +16 −27 tests/output/ob_start_basic_006.phpt
  78. +3 −3 tests/output/ob_start_basic_unerasable_002.phpt
  79. +5 −4 tests/output/ob_start_basic_unerasable_003.phpt
  80. +5 −4 tests/output/ob_start_basic_unerasable_004.phpt
  81. +2 −2 tests/output/ob_start_basic_unerasable_005.phpt
  82. +8 −5 tests/output/ob_start_error_001.phpt
  83. +7 −0 tests/output/ob_start_error_002.phpt
  84. +3 −1 tests/output/ob_start_error_003.phpt
  85. +3 −1 tests/output/ob_start_error_004.phpt
View
Oops, something went wrong.
View
@@ -112,11 +112,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_iconv, 0)
ZEND_ARG_INFO(0, str)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO(arginfo_ob_iconv_handler, 0)
- ZEND_ARG_INFO(0, contents)
- ZEND_ARG_INFO(0, status)
-ZEND_END_ARG_INFO()
-
ZEND_BEGIN_ARG_INFO(arginfo_iconv_set_encoding, 0)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(0, charset)
@@ -132,7 +127,6 @@ ZEND_END_ARG_INFO()
*/
const zend_function_entry iconv_functions[] = {
PHP_RAW_NAMED_FE(iconv,php_if_iconv, arginfo_iconv)
- PHP_FE(ob_iconv_handler, arginfo_ob_iconv_handler)
PHP_FE(iconv_get_encoding, arginfo_iconv_get_encoding)
PHP_FE(iconv_set_encoding, arginfo_iconv_set_encoding)
PHP_FE(iconv_strlen, arginfo_iconv_strlen)
@@ -214,6 +208,10 @@ static php_iconv_err_t _php_iconv_mime_decode(smart_str *pretval, const char *st
static php_iconv_err_t php_iconv_stream_filter_register_factory(TSRMLS_D);
static php_iconv_err_t php_iconv_stream_filter_unregister_factory(TSRMLS_D);
+
+static int php_iconv_output_conflict(const char *handler_name, size_t handler_name_len TSRMLS_DC);
+static php_output_handler *php_iconv_output_handler_init(const char *name, size_t name_len, size_t chunk_size, int flags TSRMLS_DC);
+static int php_iconv_output_handler(void **nothing, php_output_context *output_context);
/* }}} */
/* {{{ static globals */
@@ -278,6 +276,9 @@ PHP_MINIT_FUNCTION(miconv)
return FAILURE;
}
+ php_output_handler_alias_register(ZEND_STRL("ob_iconv_handler"), php_iconv_output_handler_init TSRMLS_CC);
+ php_output_handler_conflict_register(ZEND_STRL("ob_iconv_handler"), php_iconv_output_conflict TSRMLS_CC);
+
return SUCCESS;
}
/* }}} */
@@ -312,6 +313,62 @@ PHP_MINFO_FUNCTION(miconv)
}
/* }}} */
+static int php_iconv_output_conflict(const char *handler_name, size_t handler_name_len TSRMLS_DC)
+{
+ if (php_output_get_level(TSRMLS_C)) {
+ if (php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("ob_iconv_handler") TSRMLS_CC)
+ || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("mb_output_handler") TSRMLS_CC)) {
+ return FAILURE;
+ }
+ }
+ return SUCCESS;
+}
+
+static php_output_handler *php_iconv_output_handler_init(const char *handler_name, size_t handler_name_len, size_t chunk_size, int flags TSRMLS_DC)
+{
+ return php_output_handler_create_internal(handler_name, handler_name_len, php_iconv_output_handler, chunk_size, flags TSRMLS_CC);
+}
+
+static int php_iconv_output_handler(void **nothing, php_output_context *output_context)
+{
+ char *s, *content_type, *mimetype = NULL;
+ int output_status, mimetype_len = 0;
+ PHP_OUTPUT_TSRMLS(output_context);
+
+ if (output_context->op & PHP_OUTPUT_HANDLER_START) {
+ output_status = php_output_get_status(TSRMLS_C);
+ if (output_status & PHP_OUTPUT_SENT) {
+ return FAILURE;
+ }
+
+ if (SG(sapi_headers).mimetype && !strncasecmp(SG(sapi_headers).mimetype, "text/", 5)) {
+ if ((s = strchr(SG(sapi_headers).mimetype,';')) == NULL){
+ mimetype = SG(sapi_headers).mimetype;
+ } else {
+ mimetype = SG(sapi_headers).mimetype;
+ mimetype_len = s - SG(sapi_headers).mimetype;
+ }
+ } else if (SG(sapi_headers).send_default_content_type) {
+ mimetype = SG(default_mimetype) ? SG(default_mimetype) : SAPI_DEFAULT_MIMETYPE;
+ }
+
+ if (mimetype != NULL && !(output_context->op & PHP_OUTPUT_HANDLER_CLEAN)) {
+ int len = spprintf(&content_type, 0, "Content-Type: %.*s; charset=%s", mimetype_len?mimetype_len:strlen(mimetype), mimetype, ICONVG(output_encoding));
+ if (content_type && SUCCESS == sapi_add_header(content_type, len, 0)) {
+ SG(sapi_headers).send_default_content_type = 0;
+ php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE, NULL TSRMLS_CC);
+ }
+ }
+ }
+
+ if (output_context->in.used) {
+ output_context->out.free = 1;
+ _php_iconv_show_error(php_iconv_string(output_context->in.data, output_context->in.used, &output_context->out.data, &output_context->out.used, ICONVG(output_encoding), ICONVG(internal_encoding)), ICONVG(output_encoding), ICONVG(internal_encoding) TSRMLS_CC);
+ }
+
+ return SUCCESS;
+}
+
/* {{{ _php_iconv_appendl() */
static php_iconv_err_t _php_iconv_appendl(smart_str *d, const char *s, size_t l, iconv_t cd)
{
@@ -1131,7 +1188,7 @@ static php_iconv_err_t _php_iconv_mime_encode(smart_str *pretval, const char *fn
goto out;
}
break;
-
+
default:
err = PHP_ICONV_ERR_UNKNOWN;
goto out;
@@ -1725,7 +1782,7 @@ static php_iconv_err_t _php_iconv_mime_decode(smart_str *pretval, const char *st
break;
case '\n':
- scan_stat = 8;
+ scan_stat = 8;
break;
case '=': /* first letter of an encoded chunk */
@@ -2308,58 +2365,6 @@ PHP_NAMED_FUNCTION(php_if_iconv)
}
/* }}} */
-/* {{{ proto string ob_iconv_handler(string contents, int status)
- Returns str in output buffer converted to the iconv.output_encoding character set */
-PHP_FUNCTION(ob_iconv_handler)
-{
- char *out_buffer, *content_type, *mimetype = NULL, *s;
- zval *zv_string;
- size_t out_len;
- int mimetype_alloced = 0;
- long status;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &zv_string, &status) == FAILURE)
- return;
-
- convert_to_string(zv_string);
-
- if (SG(sapi_headers).mimetype &&
- strncasecmp(SG(sapi_headers).mimetype, "text/", 5) == 0) {
- if ((s = strchr(SG(sapi_headers).mimetype,';')) == NULL){
- mimetype = SG(sapi_headers).mimetype;
- } else {
- mimetype = estrndup(SG(sapi_headers).mimetype, s-SG(sapi_headers).mimetype);
- mimetype_alloced = 1;
- }
- } else if (SG(sapi_headers).send_default_content_type) {
- mimetype =(SG(default_mimetype) ? SG(default_mimetype) : SAPI_DEFAULT_MIMETYPE);
- }
- if (mimetype != NULL) {
- php_iconv_err_t err = php_iconv_string(Z_STRVAL_P(zv_string),
- Z_STRLEN_P(zv_string), &out_buffer, &out_len,
- ICONVG(output_encoding), ICONVG(internal_encoding));
- _php_iconv_show_error(err, ICONVG(output_encoding), ICONVG(internal_encoding) TSRMLS_CC);
- if (out_buffer != NULL) {
- int len = spprintf(&content_type, 0, "Content-Type:%s; charset=%s", mimetype, ICONVG(output_encoding));
- if (content_type && sapi_add_header(content_type, len, 0) != FAILURE) {
- SG(sapi_headers).send_default_content_type = 0;
- }
- if (mimetype_alloced) {
- efree(mimetype);
- }
- RETURN_STRINGL(out_buffer, out_len, 0);
- }
- if (mimetype_alloced) {
- efree(mimetype);
- }
- }
-
- zval_dtor(return_value);
- *return_value = *zv_string;
- zval_copy_ctor(return_value);
-}
-/* }}} */
-
/* {{{ proto bool iconv_set_encoding(string type, string charset)
Sets internal encoding and output encoding for ob_iconv_handler() */
PHP_FUNCTION(iconv_set_encoding)
@@ -2488,7 +2493,7 @@ static int php_iconv_stream_filter_append_bucket(
char *pd, *pt;
size_t ocnt, prev_ocnt, icnt, tcnt;
size_t initial_out_buf_size;
-
+
if (ps == NULL) {
initial_out_buf_size = 64;
icnt = 1;
@@ -2784,7 +2789,7 @@ static php_stream_filter *php_iconv_stream_filter_factory_create(const char *nam
pefree(inst, persistent);
}
- return retval;
+ return retval;
}
/* }}} */
@@ -1093,8 +1093,8 @@ static int php_session_cache_limiter(TSRMLS_D) /* {{{ */
if (PS(cache_limiter)[0] == '\0') return 0;
if (SG(headers_sent)) {
- char *output_start_filename = php_get_output_start_filename(TSRMLS_C);
- int output_start_lineno = php_get_output_start_lineno(TSRMLS_C);
+ char *output_start_filename = php_output_get_start_filename(TSRMLS_C);
+ int output_start_lineno = php_output_get_start_lineno(TSRMLS_C);
if (output_start_filename) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot send session cache limiter - headers already sent (output started at %s:%d)", output_start_filename, output_start_lineno);
@@ -1133,8 +1133,8 @@ static void php_session_send_cookie(TSRMLS_D) /* {{{ */
char *e_session_name, *e_id;
if (SG(headers_sent)) {
- char *output_start_filename = php_get_output_start_filename(TSRMLS_C);
- int output_start_lineno = php_get_output_start_lineno(TSRMLS_C);
+ char *output_start_filename = php_output_get_start_filename(TSRMLS_C);
+ int output_start_lineno = php_output_get_start_lineno(TSRMLS_C);
if (output_start_filename) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot send session cookie - headers already sent by (output started at %s:%d)", output_start_filename, output_start_lineno);
Oops, something went wrong.

0 comments on commit 11d24c1

Please sign in to comment.