/* {{{ PHP_RSHUTDOWN_FUNCTION */ static PHP_RSHUTDOWN_FUNCTION(zlib) { php_zlib_cleanup_ob_gzhandler_mess(); ZLIBG(handler_registered) = 0; return SUCCESS; }
/* {{{ proto string ob_gzhandler(string data, int flags) Legacy hack */ static PHP_FUNCTION(ob_gzhandler) { char *in_str; size_t in_len; zend_long flags = 0; php_output_context ctx = {0}; int encoding, rv; /* * NOTE that the real ob_gzhandler is an alias to "zlib output compression". * This is a really bad hack, because * - we have to initialize a php_zlib_context on demand * - we have to clean it up in RSHUTDOWN * - OG(running) is not set or set to any other output handler * - we have to mess around with php_output_context */ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "sl", &in_str, &in_len, &flags)) { RETURN_FALSE; } if (!(encoding = php_zlib_output_encoding())) { RETURN_FALSE; } if (flags & PHP_OUTPUT_HANDLER_START) { switch (encoding) { case PHP_ZLIB_ENCODING_GZIP: sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1); break; case PHP_ZLIB_ENCODING_DEFLATE: sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1); break; } sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0); } if (!ZLIBG(ob_gzhandler)) { ZLIBG(ob_gzhandler) = php_zlib_output_handler_context_init(); } ctx.op = flags; ctx.in.data = in_str; ctx.in.used = in_len; rv = php_zlib_output_handler_ex(ZLIBG(ob_gzhandler), &ctx); if (SUCCESS != rv) { if (ctx.out.data && ctx.out.free) { efree(ctx.out.data); } php_zlib_cleanup_ob_gzhandler_mess(); RETURN_FALSE; } if (ctx.out.data) { RETVAL_STRINGL(ctx.out.data, ctx.out.used); if (ctx.out.free) { efree(ctx.out.data); } } else { RETVAL_EMPTY_STRING(); } }