55#define Z_INFLATE_CONTEXT_P(zv) inflate_context_from_obj(Z_OBJ_P(zv))
71static void inflate_context_free_obj(
zend_object *
object)
78 inflateEnd(&intern->
Z);
93#define Z_DEFLATE_CONTEXT_P(zv) deflate_context_from_obj(Z_OBJ_P(zv))
109static void deflate_context_free_obj(
zend_object *
object)
113 deflateEnd(&intern->
Z);
121static voidpf php_zlib_alloc(voidpf opaque, uInt items, uInt
size)
126static void php_zlib_free(voidpf opaque, voidpf address)
128 efree((
void*)address);
133static zend_result php_zlib_output_conflict_check(
const char *handler_name,
size_t handler_name_len)
148static int php_zlib_output_encoding(
void)
170 int flags = Z_SYNC_FLUSH;
194 if (output_context->
in.
used) {
215 ctx->
Z.avail_out = output_context->
out.
size;
216 ctx->
Z.next_out = (Bytef *) output_context->
out.
data;
221 flags = Z_FULL_FLUSH;
224 switch (deflate(&ctx->
Z,
flags)) {
226 if (
flags == Z_FINISH) {
232 if (ctx->
Z.avail_in) {
237 output_context->
out.
used = output_context->
out.
size - ctx->
Z.avail_out;
258 if (!php_zlib_output_encoding()) {
277 if (
SUCCESS != php_zlib_output_handler_ex(ctx, output_context)) {
316 ctx->
Z.zalloc = php_zlib_alloc;
317 ctx->
Z.zfree = php_zlib_free;
323static void php_zlib_output_handler_context_dtor(
void *opaq)
337static php_output_handler *php_zlib_output_handler_init(
const char *handler_name,
size_t handler_name_len,
size_t chunk_size,
int flags)
356static void php_zlib_output_compression_start(
void)
368 if ( php_zlib_output_encoding() &&
383static zend_string *php_zlib_encode(
const char *in_buf,
size_t in_len,
int encoding,
int level)
389 memset(&Z, 0,
sizeof(z_stream));
390 Z.zalloc = php_zlib_alloc;
391 Z.zfree = php_zlib_free;
393 if (Z_OK == (
status = deflateInit2(&Z, level, Z_DEFLATED,
encoding, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) {
396 Z.next_in = (Bytef *) in_buf;
401 status = deflate(&Z, Z_FINISH);
404 if (Z_STREAM_END ==
status) {
406 out = zend_string_truncate(
out, Z.total_out, 0);
410 zend_string_efree(
out);
420static inline int php_zlib_inflate_rounds(z_stream *Z,
size_t max,
char **
buf,
size_t *
len)
438 fprintf(stderr,
"\n%3d: %3d PRIOR: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n",
round,
status,
buffer.size,
buffer.free,
buffer.used, Z->avail_in, Z->avail_out);
440 status = inflate(Z, Z_NO_FLUSH);
443 buffer.free = Z->avail_out;
445 fprintf(stderr,
"%3d: %3d AFTER: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n",
round,
status,
buffer.size,
buffer.free,
buffer.used, Z->avail_in, Z->avail_out);
449 }
while ((Z_BUF_ERROR ==
status || (Z_OK ==
status && Z->avail_in)) && ++
round < 100);
451 if (
status == Z_STREAM_END) {
469static int php_zlib_decode(
const char *in_buf,
size_t in_len,
char **out_buf,
size_t *out_len,
int encoding,
size_t max_len)
471 int status = Z_DATA_ERROR;
474 memset(&Z, 0,
sizeof(z_stream));
475 Z.zalloc = php_zlib_alloc;
476 Z.zfree = php_zlib_free;
482 Z.next_in = (Bytef *) in_buf;
483 Z.avail_in = in_len + 1;
485 switch (
status = php_zlib_inflate_rounds(&Z, max_len, out_buf, out_len)) {
495 goto retry_raw_inflate;
511static void php_zlib_cleanup_ob_gzhandler_mess(
void)
542 if (!(
encoding = php_zlib_output_encoding())) {
572 php_zlib_cleanup_ob_gzhandler_mess();
610 char buf[8192] = {0};
700#define PHP_ZLIB_ENCODE_FUNC(name, default_encoding) \
703 zend_string *in, *out; \
704 zend_long level = -1; \
705 zend_long encoding = default_encoding; \
706 if (default_encoding) { \
707 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "S|ll", &in, &level, &encoding)) { \
711 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "Sl|l", &in, &encoding, &level)) { \
715 if (level < -1 || level > 9) { \
716 zend_argument_value_error(default_encoding ? 2 : 3, "must be between -1 and 9"); \
719 switch (encoding) { \
720 case PHP_ZLIB_ENCODING_RAW: \
721 case PHP_ZLIB_ENCODING_GZIP: \
722 case PHP_ZLIB_ENCODING_DEFLATE: \
725 zend_argument_value_error(default_encoding ? 3 : 2, "must be one of ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP, or ZLIB_ENCODING_DEFLATE"); \
728 if ((out = php_zlib_encode(ZSTR_VAL(in), ZSTR_LEN(in), encoding, level)) == NULL) { \
734#define PHP_ZLIB_DECODE_FUNC(name, encoding) \
737 char *in_buf, *out_buf; \
740 zend_long max_len = 0; \
741 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &in_buf, &in_len, &max_len)) { \
745 zend_argument_value_error(2, "must be greater than or equal to 0"); \
748 if (SUCCESS != php_zlib_decode(in_buf, in_len, &out_buf, &out_len, encoding, max_len)) { \
751 RETVAL_STRINGL(out_buf, out_len); \
788static bool zlib_create_dictionary_string(
HashTable *
options,
char **dict,
size_t *dictlen) {
805 if (zend_hash_num_elements(dictionary) > 0) {
812 *++
ptr = zval_get_string(cur);
816 zend_string_release(*
ptr);
817 }
while (--
ptr >= strings);
824 if (zend_str_has_nul_byte(*
ptr)) {
826 zend_string_release(*
ptr);
827 }
while (--
ptr >= strings);
836 dictptr = *dict =
emalloc(*dictlen);
838 end = strings + zend_hash_num_elements(dictionary);
874 window = zval_get_long(option_buffer);
876 if (window < 8 || window > 15) {
887 zend_value_error(
"Encoding mode must be ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE");
891 if (!zlib_create_dictionary_string(
options, &dict, &dictlen)) {
898 ctx->
Z.zalloc = php_zlib_alloc;
899 ctx->
Z.zfree = php_zlib_free;
910 if (inflateInit2(&ctx->
Z,
encoding) != Z_OK) {
938 size_t in_len, buffer_used = 0,
CHUNK_SIZE = 8192;
950 switch (flush_type) {
952 case Z_PARTIAL_FLUSH:
960 zend_argument_value_error(3,
"must be one of ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK, or ZLIB_FINISH");
965 if (ctx->
status == Z_STREAM_END)
968 inflateReset(&ctx->
Z);
971 if (in_len <= 0 && flush_type != Z_FINISH) {
976 ctx->
Z.next_in = (Bytef *) in_buf;
978 ctx->
Z.avail_in = in_len;
982 status = inflate(&ctx->
Z, flush_type);
989 if (ctx->
Z.avail_out == 0) {
993 ctx->
Z.next_out = (Bytef *)
ZSTR_VAL(
out) + buffer_used;
1001 if (flush_type == Z_FINISH && ctx->
Z.avail_out == 0) {
1005 ctx->
Z.next_out = (Bytef *)
ZSTR_VAL(
out) + buffer_used;
1028 php_error_docref(
NULL,
E_WARNING,
"Inflating this data requires a preset dictionary, please specify it in the options array of inflate_init()");
1039 out = zend_string_realloc(
out, buffer_used, 0);
1081 zend_long encoding, level = -1, memory = 8, window = 15, strategy = Z_DEFAULT_STRATEGY;
1085 zval *option_buffer;
1093 level = zval_get_long(option_buffer);
1095 if (level < -1 || level > 9) {
1096 zend_value_error(
"deflate_init(): \"level\" option must be between -1 and 9");
1102 memory = zval_get_long(option_buffer);
1104 if (memory < 1 || memory > 9) {
1105 zend_value_error(
"deflate_init(): \"memory\" option must be between 1 and 9");
1111 window = zval_get_long(option_buffer);
1113 if (window < 8 || window > 15) {
1114 zend_value_error(
"deflate_init(): \"window\" option must be between 8 and 15");
1120 strategy = zval_get_long(option_buffer);
1124 case Z_HUFFMAN_ONLY:
1127 case Z_DEFAULT_STRATEGY:
1130 zend_value_error(
"deflate_init(): \"strategy\" option must be one of ZLIB_FILTERED, ZLIB_HUFFMAN_ONLY, ZLIB_RLE, ZLIB_FIXED, or ZLIB_DEFAULT_STRATEGY");
1144 if (!zlib_create_dictionary_string(
options, &dict, &dictlen)) {
1151 ctx->
Z.zalloc = php_zlib_alloc;
1152 ctx->
Z.zfree = php_zlib_free;
1160 if (deflateInit2(&ctx->
Z, level, Z_DEFLATED,
encoding, memory, strategy) != Z_OK) {
1167 int success = deflateSetDictionary(&ctx->
Z, (Bytef *) dict, dictlen);
1179 size_t in_len, out_size, buffer_used;
1191 switch (flush_type) {
1193#if ZLIB_VERNUM < 0x1240L
1198 case Z_PARTIAL_FLUSH:
1205 zend_argument_value_error(3,
"must be one of ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK, or ZLIB_FINISH");
1209 if (in_len <= 0 && flush_type != Z_FINISH) {
1214 out_size = (out_size < 64) ? 64 : out_size;
1215 out = zend_string_alloc(out_size, 0);
1217 ctx->
Z.next_in = (Bytef *) in_buf;
1219 ctx->
Z.avail_in = in_len;
1225 if (ctx->
Z.avail_out == 0) {
1229 ctx->
Z.avail_out = 64;
1230 ctx->
Z.next_out = (Bytef *)
ZSTR_VAL(
out) + buffer_used;
1232 status = deflate(&ctx->
Z, flush_type);
1234 }
while (
status == Z_OK && ctx->
Z.avail_out == 0);
1245 deflateReset(&ctx->
Z);
1256#ifdef COMPILE_DL_ZLIB
1264static PHP_INI_MH(OnUpdate_zlib_output_compression)
1268 if (new_value ==
NULL) {
1279 ini_value =
zend_ini_string(
"output_handler",
sizeof(
"output_handler") - 1, 0);
1281 if (ini_value && *ini_value && int_value) {
1299 php_zlib_output_compression_start();
1308static PHP_INI_MH(OnUpdate_zlib_output_handler)
1315 return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
1344 inflate_context_object_handlers.free_obj = inflate_context_free_obj;
1345 inflate_context_object_handlers.get_constructor = inflate_context_get_constructor;
1346 inflate_context_object_handlers.clone_obj =
NULL;
1355 deflate_context_object_handlers.free_obj = deflate_context_free_obj;
1356 deflate_context_object_handlers.get_constructor = deflate_context_get_constructor;
1357 deflate_context_object_handlers.clone_obj =
NULL;
1360 register_zlib_symbols(module_number);
1385 php_zlib_output_compression_start();
1395 php_zlib_cleanup_ob_gzhandler_mess();
1420#if defined(COMPILE_DL_ZLIB) && defined(ZTS)
1423 zlib_globals->ob_gzhandler =
NULL;
1424 zlib_globals->handler_registered = 0;
SAPI_API int sapi_add_header_ex(const char *header_line, size_t header_line_len, bool duplicate, bool replace)
fprintf($stream, string $format, mixed ... $values)
strstr(string $haystack, string $needle, bool $before_needle=false)
headers_sent(&$filename=null, &$line=null)
memset(ptr, 0, type->size)
zend_ffi_ctype_name_buf buf
#define round(tables, k1, k2)
PHPAPI int php_stream_filter_register_factory(const char *filterpattern, const php_stream_filter_factory *factory)
PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern)
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
PHPAPI zend_result php_output_handler_hook(php_output_handler_hook_t type, void *arg)
PHPAPI bool php_output_handler_conflict(const char *handler_new, size_t handler_new_len, const char *handler_set, size_t handler_set_len)
PHPAPI bool php_output_handler_started(const char *name, size_t name_len)
PHPAPI zend_result php_output_start_user(zval *output_handler, size_t chunk_size, int flags)
PHPAPI zend_result php_output_handler_conflict_register(const char *name, size_t name_len, php_output_handler_conflict_check_t check_func)
PHPAPI php_output_handler * php_output_handler_create_internal(const char *name, size_t name_len, php_output_handler_context_func_t output_handler, size_t chunk_size, int flags)
PHPAPI int php_output_get_level(void)
PHPAPI zend_result php_output_handler_alias_register(const char *name, size_t name_len, php_output_handler_alias_ctor_t func)
PHPAPI zend_result php_output_handler_start(php_output_handler *handler)
PHPAPI int php_output_get_status(void)
PHPAPI void php_output_handler_set_context(php_output_handler *handler, void *opaq, void(*dtor)(void *))
php_info_print_table_start()
php_info_print_table_row(2, "PDO Driver for Firebird", "enabled")
php_info_print_table_end()
#define PHP_MSHUTDOWN_FUNCTION
#define PHP_MINIT_FUNCTION
#define PHP_MINFO_FUNCTION
#define PHP_GINIT_FUNCTION
#define PHP_RINIT_FUNCTION
#define PHP_RSHUTDOWN_FUNCTION
#define PHP_MODULE_GLOBALS
unsigned const char * end
#define TRACK_VARS_SERVER
#define PHP_INI_STAGE_RUNTIME
#define STD_PHP_INI_ENTRY
#define STD_PHP_INI_BOOLEAN
PHP_JSON_API size_t int options
struct _php_output_handler php_output_handler
#define PHP_OUTPUT_HANDLER_FLUSH
#define PHP_OUTPUT_HANDLER_STDFLAGS
@ PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS
@ PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE
#define PHP_OUTPUT_HANDLER_CLEAN
#define PHP_OUTPUT_HANDLER_FINAL
#define PHP_OUTPUT_HANDLER_DEFAULT_SIZE
#define PHP_OUTPUT_HANDLER_STARTED
struct _php_output_context php_output_context
#define PHP_OUTPUT_HANDLER_START
xmlCharEncodingHandlerPtr encoding
struct _php_stream php_stream
#define php_stream_gets(stream, buf, maxlen)
#define php_stream_to_zval(stream, zval)
#define php_stream_close(stream)
PHPAPI zend_result php_register_url_stream_wrapper(const char *protocol, const php_stream_wrapper *wrapper)
PHPAPI zend_result php_unregister_url_stream_wrapper(const char *protocol)
#define php_stream_passthru(stream)
zend_long output_compression
const php_stream_filter_factory php_zlib_filter_factory
#define PHP_ZLIB_BUFFER_SIZE_GUESS(in_len)
const php_stream_wrapper php_stream_gzip_wrapper
php_zlib_context * ob_gzhandler
struct _php_zlib_context php_zlib_context
php_stream * php_stream_gzopen(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC)
#define PHP_ZLIB_ENCODING_RAW
zend_long output_compression_level
#define PHP_ZLIB_OUTPUT_HANDLER_NAME
#define PHP_ZLIB_ENCODING_DEFLATE
#define PHP_ZLIB_ENCODING_GZIP
#define PHP_ZLIB_ENCODING_ANY
zend_module_entry php_zlib_module_entry
struct _php_zlib_buffer php_zlib_buffer
zend_long output_compression_default
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format,...)
ZEND_API ZEND_COLD void zend_value_error(const char *format,...)
#define ZEND_TSRMLS_CACHE_UPDATE()
#define ZEND_TSRMLS_CACHE_DEFINE()
ZEND_API const char * zend_zval_value_name(const zval *arg)
ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *class_type)
ZEND_API void add_index_string(zval *arg, zend_ulong index, const char *str)
ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec,...)
ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type)
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
ZEND_API ZEND_COLD void zend_argument_type_error(uint32_t arg_num, const char *format,...)
#define RETURN_STRINGL(s, l)
#define ZVAL_STRING(z, s)
#define ZEND_DECLARE_MODULE_GLOBALS(module_name)
#define ZEND_GET_MODULE(name)
#define zend_parse_parameters_none()
#define RETVAL_EMPTY_STRING()
#define RETURN_EMPTY_STRING()
#define RETVAL_STRINGL(s, l)
#define erealloc_recoverable(ptr, size)
#define ecalloc(nmemb, size)
#define erealloc(ptr, size)
#define safe_emalloc(nmemb, size, offset)
zend_string_release_ex(func->internal_function.function_name, 0)
ZEND_API bool zend_is_auto_global(zend_string *name)
union _zend_function zend_function
ZEND_API zval *ZEND_FASTCALL zend_hash_str_find(const HashTable *ht, const char *str, size_t len)
#define ZEND_HASH_FOREACH_END()
#define ZEND_HASH_FOREACH_VAL(ht, _val)
ZEND_API zend_long zend_ini_parse_quantity_warn(zend_string *value, zend_string *setting)
ZEND_API char * zend_ini_string(const char *name, size_t name_length, int orig)
#define UNREGISTER_INI_ENTRIES()
#define REGISTER_INI_ENTRIES()
#define DISPLAY_INI_ENTRIES()
#define ZEND_INI_GET_ADDR()
struct _zend_string zend_string
#define STANDARD_MODULE_HEADER
struct _zend_module_entry zend_module_entry
#define STANDARD_MODULE_PROPERTIES_EX
ZEND_API int zend_objects_not_comparable(zval *o1, zval *o2)
ZEND_API const zend_object_handlers std_object_handlers
ZEND_API void ZEND_FASTCALL zend_object_std_init(zend_object *object, zend_class_entry *ce)
ZEND_API void zend_object_std_dtor(zend_object *object)
#define convert_to_string(op)
#define XtOffsetOf(s_type, field)
#define EMPTY_SWITCH_DEFAULT_CASE()
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
#define zend_string_equals_literal_ci(str, c)
#define Z_STRVAL_P(zval_p)
struct _zend_array HashTable
ZEND_RESULT_CODE zend_result
struct _zend_object_handlers zend_object_handlers
#define ZVAL_DEINDIRECT(z)
ZEND_API void zval_ptr_dtor(zval *zval_ptr)
#define PHP_ZLIB_ENCODE_FUNC(name, default_encoding)
zend_class_entry * inflate_context_ce
#define PHP_ZLIB_DECODE_FUNC(name, encoding)
zend_class_entry * deflate_context_ce
#define Z_INFLATE_CONTEXT_P(zv)
#define Z_DEFLATE_CONTEXT_P(zv)
gzdeflate(string $data, int $level=-1, int $encoding=ZLIB_ENCODING_RAW)
gzopen(string $filename, string $mode, int $use_include_path=0)
deflate_add(DeflateContext $context, string $data, int $flush_mode=ZLIB_SYNC_FLUSH)
gzcompress(string $data, int $level=-1, int $encoding=ZLIB_ENCODING_DEFLATE)
inflate_add(InflateContext $context, string $data, int $flush_mode=ZLIB_SYNC_FLUSH)
gzencode(string $data, int $level=-1, int $encoding=ZLIB_ENCODING_GZIP)
gzuncompress(string $data, int $max_length=0)
gzinflate(string $data, int $max_length=0)
inflate_get_status(InflateContext $context)
gzfile(string $filename, int $use_include_path=0)
zlib_encode(string $data, int $encoding, int $level=-1)
zlib_decode(string $data, int $max_length=0)
inflate_get_read_len(InflateContext $context)
inflate_init(int $encoding, array|object $options=[])
gzdecode(string $data, int $max_length=0)
deflate_init(int $encoding, array|object $options=[])
readgzfile(string $filename, int $use_include_path=0)