php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
zlib.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
14 | Stefan Röhrich <sr@linux.de> |
15 | Zeev Suraski <zeev@php.net> |
16 | Jade Nicoletti <nicoletti@nns.ch> |
17 | Michael Wallner <mike@php.net> |
18 +----------------------------------------------------------------------+
19 */
20
21#ifdef HAVE_CONFIG_H
22#include <config.h>
23#endif
24
25#include "php.h"
26#include "SAPI.h"
27#include "php_ini.h"
28#include "ext/standard/info.h"
29#include "php_zlib.h"
30#include "zlib_arginfo.h"
31
32/*
33 * zlib include files can define the following preprocessor defines which rename
34 * the corresponding PHP functions to gzopen64, gzseek64 and gztell64 and thereby
35 * breaking some software, most notably PEAR's Archive_Tar, which halts execution
36 * without error message on gzip compressed archives.
37 *
38 * This only seems to happen on 32bit systems with large file support.
39 */
40#undef gzopen
41#undef gzseek
42#undef gztell
43
45
46/* InflateContext class */
47
49static zend_object_handlers inflate_context_object_handlers;
50
51static inline php_zlib_context *inflate_context_from_obj(zend_object *obj) {
52 return (php_zlib_context *)((char *)(obj) - XtOffsetOf(php_zlib_context, std));
53}
54
55#define Z_INFLATE_CONTEXT_P(zv) inflate_context_from_obj(Z_OBJ_P(zv))
56
57static zend_object *inflate_context_create_object(zend_class_entry *class_type) {
58 php_zlib_context *intern = zend_object_alloc(sizeof(php_zlib_context), class_type);
59
60 zend_object_std_init(&intern->std, class_type);
61 object_properties_init(&intern->std, class_type);
62
63 return &intern->std;
64}
65
66static zend_function *inflate_context_get_constructor(zend_object *object) {
67 zend_throw_error(NULL, "Cannot directly construct InflateContext, use inflate_init() instead");
68 return NULL;
69}
70
71static void inflate_context_free_obj(zend_object *object)
72{
73 php_zlib_context *intern = inflate_context_from_obj(object);
74
75 if (intern->inflateDict) {
76 efree(intern->inflateDict);
77 }
78 inflateEnd(&intern->Z);
79
80 zend_object_std_dtor(&intern->std);
81}
82/* }}} */
83
84/* DeflateContext class */
85
87static zend_object_handlers deflate_context_object_handlers;
88
89static inline php_zlib_context *deflate_context_from_obj(zend_object *obj) {
90 return (php_zlib_context *)((char *)(obj) - XtOffsetOf(php_zlib_context, std));
91}
92
93#define Z_DEFLATE_CONTEXT_P(zv) deflate_context_from_obj(Z_OBJ_P(zv))
94
95static zend_object *deflate_context_create_object(zend_class_entry *class_type) {
96 php_zlib_context *intern = zend_object_alloc(sizeof(php_zlib_context), class_type);
97
98 zend_object_std_init(&intern->std, class_type);
99 object_properties_init(&intern->std, class_type);
100
101 return &intern->std;
102}
103
104static zend_function *deflate_context_get_constructor(zend_object *object) {
105 zend_throw_error(NULL, "Cannot directly construct DeflateContext, use deflate_init() instead");
106 return NULL;
107}
108
109static void deflate_context_free_obj(zend_object *object)
110{
111 php_zlib_context *intern = deflate_context_from_obj(object);
112
113 deflateEnd(&intern->Z);
114
115 zend_object_std_dtor(&intern->std);
116}
117/* }}} */
118
119/* {{{ Memory management wrappers */
120
121static voidpf php_zlib_alloc(voidpf opaque, uInt items, uInt size)
122{
123 return (voidpf)safe_emalloc(items, size, 0);
124}
125
126static void php_zlib_free(voidpf opaque, voidpf address)
127{
128 efree((void*)address);
129}
130/* }}} */
131
132/* {{{ php_zlib_output_conflict_check() */
133static zend_result php_zlib_output_conflict_check(const char *handler_name, size_t handler_name_len)
134{
135 if (php_output_get_level() > 0) {
136 if (php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME))
137 || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("ob_gzhandler"))
138 || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("mb_output_handler"))
139 || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("URL-Rewriter"))) {
140 return FAILURE;
141 }
142 }
143 return SUCCESS;
144}
145/* }}} */
146
147/* {{{ php_zlib_output_encoding() */
148static int php_zlib_output_encoding(void)
149{
150 zval *enc;
151
153 if ((Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY || zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER))) &&
154 (enc = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING") - 1))) {
156 if (strstr(Z_STRVAL_P(enc), "gzip")) {
158 } else if (strstr(Z_STRVAL_P(enc), "deflate")) {
160 }
161 }
162 }
164}
165/* }}} */
166
167/* {{{ php_zlib_output_handler_ex() */
168static zend_result php_zlib_output_handler_ex(php_zlib_context *ctx, php_output_context *output_context)
169{
170 int flags = Z_SYNC_FLUSH;
171
172 if (output_context->op & PHP_OUTPUT_HANDLER_START) {
173 /* start up */
174 if (Z_OK != deflateInit2(&ctx->Z, ZLIBG(output_compression_level), Z_DEFLATED, ZLIBG(compression_coding), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY)) {
175 return FAILURE;
176 }
177 }
178
179 if (output_context->op & PHP_OUTPUT_HANDLER_CLEAN) {
180 /* free buffers */
181 deflateEnd(&ctx->Z);
182
183 if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) {
184 /* discard */
185 return SUCCESS;
186 } else {
187 /* restart */
188 if (Z_OK != deflateInit2(&ctx->Z, ZLIBG(output_compression_level), Z_DEFLATED, ZLIBG(compression_coding), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY)) {
189 return FAILURE;
190 }
191 ctx->buffer.used = 0;
192 }
193 } else {
194 if (output_context->in.used) {
195 /* append input */
196 if (ctx->buffer.free < output_context->in.used) {
197 if (!(ctx->buffer.aptr = erealloc_recoverable(ctx->buffer.data, ctx->buffer.used + ctx->buffer.free + output_context->in.used))) {
198 deflateEnd(&ctx->Z);
199 return FAILURE;
200 }
201 ctx->buffer.data = ctx->buffer.aptr;
202 ctx->buffer.free += output_context->in.used;
203 }
204 memcpy(ctx->buffer.data + ctx->buffer.used, output_context->in.data, output_context->in.used);
205 ctx->buffer.free -= output_context->in.used;
206 ctx->buffer.used += output_context->in.used;
207 }
208 output_context->out.size = PHP_ZLIB_BUFFER_SIZE_GUESS(output_context->in.used);
209 output_context->out.data = emalloc(output_context->out.size);
210 output_context->out.free = 1;
211 output_context->out.used = 0;
212
213 ctx->Z.avail_in = ctx->buffer.used;
214 ctx->Z.next_in = (Bytef *) ctx->buffer.data;
215 ctx->Z.avail_out = output_context->out.size;
216 ctx->Z.next_out = (Bytef *) output_context->out.data;
217
218 if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) {
219 flags = Z_FINISH;
220 } else if (output_context->op & PHP_OUTPUT_HANDLER_FLUSH) {
221 flags = Z_FULL_FLUSH;
222 }
223
224 switch (deflate(&ctx->Z, flags)) {
225 case Z_OK:
226 if (flags == Z_FINISH) {
227 deflateEnd(&ctx->Z);
228 return FAILURE;
229 }
231 case Z_STREAM_END:
232 if (ctx->Z.avail_in) {
233 memmove(ctx->buffer.data, ctx->buffer.data + ctx->buffer.used - ctx->Z.avail_in, ctx->Z.avail_in);
234 }
235 ctx->buffer.free += ctx->buffer.used - ctx->Z.avail_in;
236 ctx->buffer.used = ctx->Z.avail_in;
237 output_context->out.used = output_context->out.size - ctx->Z.avail_out;
238 break;
239 default:
240 deflateEnd(&ctx->Z);
241 return FAILURE;
242 }
243
244 if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) {
245 deflateEnd(&ctx->Z);
246 }
247 }
248
249 return SUCCESS;
250}
251/* }}} */
252
253/* {{{ php_zlib_output_handler() */
254static zend_result php_zlib_output_handler(void **handler_context, php_output_context *output_context)
255{
256 php_zlib_context *ctx = *(php_zlib_context **) handler_context;
257
258 if (!php_zlib_output_encoding()) {
259 /* "Vary: Accept-Encoding" header sent along uncompressed content breaks caching in MSIE,
260 so let's just send it with successfully compressed content or unless the complete
261 buffer gets discarded, see http://bugs.php.net/40325;
262
263 Test as follows:
264 +Vary: $ HTTP_ACCEPT_ENCODING=gzip ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n";'
265 +Vary: $ HTTP_ACCEPT_ENCODING= ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n";'
266 -Vary: $ HTTP_ACCEPT_ENCODING=gzip ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n"; ob_end_clean();'
267 -Vary: $ HTTP_ACCEPT_ENCODING= ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n"; ob_end_clean();'
268 */
269 if ((output_context->op & PHP_OUTPUT_HANDLER_START)
271 ) {
272 sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0);
273 }
274 return FAILURE;
275 }
276
277 if (SUCCESS != php_zlib_output_handler_ex(ctx, output_context)) {
278 return FAILURE;
279 }
280
281 if (!(output_context->op & PHP_OUTPUT_HANDLER_CLEAN) || ((output_context->op & PHP_OUTPUT_HANDLER_START) && !(output_context->op & PHP_OUTPUT_HANDLER_FINAL))) {
282 int flags;
283
285 /* only run this once */
288 deflateEnd(&ctx->Z);
289 return FAILURE;
290 }
291 switch (ZLIBG(compression_coding)) {
293 sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1);
294 break;
296 sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1);
297 break;
298 default:
299 deflateEnd(&ctx->Z);
300 return FAILURE;
301 }
302 sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0);
304 }
305 }
306 }
307
308 return SUCCESS;
309}
310/* }}} */
311
312/* {{{ php_zlib_output_handler_context_init() */
313static php_zlib_context *php_zlib_output_handler_context_init(void)
314{
316 ctx->Z.zalloc = php_zlib_alloc;
317 ctx->Z.zfree = php_zlib_free;
318 return ctx;
319}
320/* }}} */
321
322/* {{{ php_zlib_output_handler_context_dtor() */
323static void php_zlib_output_handler_context_dtor(void *opaq)
324{
325 php_zlib_context *ctx = (php_zlib_context *) opaq;
326
327 if (ctx) {
328 if (ctx->buffer.data) {
329 efree(ctx->buffer.data);
330 }
331 efree(ctx);
332 }
333}
334/* }}} */
335
336/* {{{ php_zlib_output_handler_init() */
337static php_output_handler *php_zlib_output_handler_init(const char *handler_name, size_t handler_name_len, size_t chunk_size, int flags)
338{
340
342 ZLIBG(output_compression) = chunk_size ? chunk_size : PHP_OUTPUT_HANDLER_DEFAULT_SIZE;
343 }
344
346
347 if ((h = php_output_handler_create_internal(handler_name, handler_name_len, php_zlib_output_handler, chunk_size, flags))) {
348 php_output_handler_set_context(h, php_zlib_output_handler_context_init(), php_zlib_output_handler_context_dtor);
349 }
350
351 return h;
352}
353/* }}} */
354
355/* {{{ php_zlib_output_compression_start() */
356static void php_zlib_output_compression_start(void)
357{
358 zval zoh;
360
361 switch (ZLIBG(output_compression)) {
362 case 0:
363 break;
364 case 1:
367 default:
368 if ( php_zlib_output_encoding() &&
374 zval_ptr_dtor(&zoh);
375 }
376 }
377 break;
378 }
379}
380/* }}} */
381
382/* {{{ php_zlib_encode() */
383static zend_string *php_zlib_encode(const char *in_buf, size_t in_len, int encoding, int level)
384{
385 int status;
386 z_stream Z;
388
389 memset(&Z, 0, sizeof(z_stream));
390 Z.zalloc = php_zlib_alloc;
391 Z.zfree = php_zlib_free;
392
393 if (Z_OK == (status = deflateInit2(&Z, level, Z_DEFLATED, encoding, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) {
394 out = zend_string_alloc(PHP_ZLIB_BUFFER_SIZE_GUESS(in_len), 0);
395
396 Z.next_in = (Bytef *) in_buf;
397 Z.next_out = (Bytef *) ZSTR_VAL(out);
398 Z.avail_in = in_len;
399 Z.avail_out = ZSTR_LEN(out);
400
401 status = deflate(&Z, Z_FINISH);
402 deflateEnd(&Z);
403
404 if (Z_STREAM_END == status) {
405 /* size buffer down to actual length */
406 out = zend_string_truncate(out, Z.total_out, 0);
407 ZSTR_VAL(out)[ZSTR_LEN(out)] = '\0';
408 return out;
409 } else {
410 zend_string_efree(out);
411 }
412 }
413
414 php_error_docref(NULL, E_WARNING, "%s", zError(status));
415 return NULL;
416}
417/* }}} */
418
419/* {{{ php_zlib_inflate_rounds() */
420static inline int php_zlib_inflate_rounds(z_stream *Z, size_t max, char **buf, size_t *len)
421{
422 int status, round = 0;
423 php_zlib_buffer buffer = {NULL, NULL, 0, 0, 0};
424
425 *buf = NULL;
426 *len = 0;
427
428 buffer.size = (max && (max < Z->avail_in)) ? max : Z->avail_in;
429
430 do {
431 if ((max && (max <= buffer.used)) || !(buffer.aptr = erealloc_recoverable(buffer.data, buffer.size))) {
432 status = Z_MEM_ERROR;
433 } else {
434 buffer.data = buffer.aptr;
435 Z->avail_out = buffer.free = buffer.size - buffer.used;
436 Z->next_out = (Bytef *) buffer.data + buffer.used;
437#if 0
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);
439#endif
440 status = inflate(Z, Z_NO_FLUSH);
441
442 buffer.used += buffer.free - Z->avail_out;
443 buffer.free = Z->avail_out;
444#if 0
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);
446#endif
447 buffer.size += (buffer.size >> 3) + 1;
448 }
449 } while ((Z_BUF_ERROR == status || (Z_OK == status && Z->avail_in)) && ++round < 100);
450
451 if (status == Z_STREAM_END) {
452 buffer.data = erealloc(buffer.data, buffer.used + 1);
453 buffer.data[buffer.used] = '\0';
454 *buf = buffer.data;
455 *len = buffer.used;
456 } else {
457 if (buffer.data) {
458 efree(buffer.data);
459 }
460 /* HACK: See zlib/examples/zpipe.c inf() function for explanation. */
461 /* This works as long as this function is not used for streaming. Required to catch very short invalid data. */
462 status = (status == Z_OK) ? Z_DATA_ERROR : status;
463 }
464 return status;
465}
466/* }}} */
467
468/* {{{ php_zlib_decode() */
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)
470{
471 int status = Z_DATA_ERROR;
472 z_stream Z;
473
474 memset(&Z, 0, sizeof(z_stream));
475 Z.zalloc = php_zlib_alloc;
476 Z.zfree = php_zlib_free;
477
478 if (in_len) {
479retry_raw_inflate:
480 status = inflateInit2(&Z, encoding);
481 if (Z_OK == status) {
482 Z.next_in = (Bytef *) in_buf;
483 Z.avail_in = in_len + 1; /* NOTE: data must be zero terminated */
484
485 switch (status = php_zlib_inflate_rounds(&Z, max_len, out_buf, out_len)) {
486 case Z_STREAM_END:
487 inflateEnd(&Z);
488 return SUCCESS;
489
490 case Z_DATA_ERROR:
491 /* raw deflated data? */
493 inflateEnd(&Z);
495 goto retry_raw_inflate;
496 }
497 }
498 inflateEnd(&Z);
499 }
500 }
501
502 *out_buf = NULL;
503 *out_len = 0;
504
505 php_error_docref(NULL, E_WARNING, "%s", zError(status));
506 return FAILURE;
507}
508/* }}} */
509
510/* {{{ php_zlib_cleanup_ob_gzhandler_mess() */
511static void php_zlib_cleanup_ob_gzhandler_mess(void)
512{
513 if (ZLIBG(ob_gzhandler)) {
514 deflateEnd(&(ZLIBG(ob_gzhandler)->Z));
515 php_zlib_output_handler_context_dtor(ZLIBG(ob_gzhandler));
517 }
518}
519/* }}} */
520
521/* {{{ Legacy hack */
523{
524 char *in_str;
525 size_t in_len;
526 zend_long flags = 0;
527 php_output_context ctx = {0};
528 int encoding;
529
530 /*
531 * NOTE that the real ob_gzhandler is an alias to "zlib output compression".
532 * This is a really bad hack, because
533 * - we have to initialize a php_zlib_context on demand
534 * - we have to clean it up in RSHUTDOWN
535 * - OG(running) is not set or set to any other output handler
536 * - we have to mess around with php_output_context */
537
538 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "sl", &in_str, &in_len, &flags)) {
540 }
541
542 if (!(encoding = php_zlib_output_encoding())) {
544 }
545
547 switch (encoding) {
549 sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1);
550 break;
552 sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1);
553 break;
554 }
555 sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 0);
556 }
557
558 if (!ZLIBG(ob_gzhandler)) {
559 ZLIBG(ob_gzhandler) = php_zlib_output_handler_context_init();
560 }
561
562 ctx.op = flags;
563 ctx.in.data = in_str;
564 ctx.in.used = in_len;
565
566 zend_result rv = php_zlib_output_handler_ex(ZLIBG(ob_gzhandler), &ctx);
567
568 if (SUCCESS != rv) {
569 if (ctx.out.data && ctx.out.free) {
570 efree(ctx.out.data);
571 }
572 php_zlib_cleanup_ob_gzhandler_mess();
574 }
575
576 if (ctx.out.data) {
577 RETVAL_STRINGL(ctx.out.data, ctx.out.used);
578 if (ctx.out.free) {
579 efree(ctx.out.data);
580 }
581 } else {
583 }
584}
585/* }}} */
586
587/* {{{ Returns the coding type used for output compression */
589{
592 }
593 switch (ZLIBG(compression_coding)) {
595 RETURN_STRINGL("gzip", sizeof("gzip") - 1);
597 RETURN_STRINGL("deflate", sizeof("deflate") - 1);
598 default:
600 }
601}
602/* }}} */
603
604/* {{{ Read and uncompress entire .gz-file into an array */
606{
607 char *filename;
608 size_t filename_len;
609 int flags = REPORT_ERRORS;
610 char buf[8192] = {0};
611 int i = 0;
613 php_stream *stream;
614
617 }
618
619 if (use_include_path) {
620 flags |= USE_PATH;
621 }
622
623 /* using a stream here is a bit more efficient (resource wise) than php_gzopen_wrapper */
624 stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, NULL STREAMS_CC);
625
626 if (!stream) {
627 /* Error reporting is already done by stream code */
629 }
630
631 /* Initialize return array */
633
634 /* Now loop through the file and do the magic quotes thing if needed */
635 memset(buf, 0, sizeof(buf));
636
637 while (php_stream_gets(stream, buf, sizeof(buf) - 1) != NULL) {
639 }
640 php_stream_close(stream);
641}
642/* }}} */
643
644/* {{{ Open a .gz-file and return a .gz-file pointer */
646{
647 char *filename;
648 char *mode;
649 size_t filename_len, mode_len;
650 int flags = REPORT_ERRORS;
651 php_stream *stream;
653
656 }
657
658 if (use_include_path) {
659 flags |= USE_PATH;
660 }
661
662 stream = php_stream_gzopen(NULL, filename, mode, flags, NULL, NULL STREAMS_CC);
663
664 if (!stream) {
666 }
668}
669/* }}} */
670
671/* {{{ Output a .gz-file */
673{
674 char *filename;
675 size_t filename_len;
676 int flags = REPORT_ERRORS;
677 php_stream *stream;
678 size_t size;
680
683 }
684
685 if (use_include_path) {
686 flags |= USE_PATH;
687 }
688
689 stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, NULL STREAMS_CC);
690
691 if (!stream) {
693 }
694 size = php_stream_passthru(stream);
695 php_stream_close(stream);
697}
698/* }}} */
699
700#define PHP_ZLIB_ENCODE_FUNC(name, default_encoding) \
701PHP_FUNCTION(name) \
702{ \
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)) { \
708 RETURN_THROWS(); \
709 } \
710 } else { \
711 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "Sl|l", &in, &encoding, &level)) { \
712 RETURN_THROWS(); \
713 } \
714 } \
715 if (level < -1 || level > 9) { \
716 zend_argument_value_error(default_encoding ? 2 : 3, "must be between -1 and 9"); \
717 RETURN_THROWS(); \
718 } \
719 switch (encoding) { \
720 case PHP_ZLIB_ENCODING_RAW: \
721 case PHP_ZLIB_ENCODING_GZIP: \
722 case PHP_ZLIB_ENCODING_DEFLATE: \
723 break; \
724 default: \
725 zend_argument_value_error(default_encoding ? 3 : 2, "must be one of ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP, or ZLIB_ENCODING_DEFLATE"); \
726 RETURN_THROWS(); \
727 } \
728 if ((out = php_zlib_encode(ZSTR_VAL(in), ZSTR_LEN(in), encoding, level)) == NULL) { \
729 RETURN_FALSE; \
730 } \
731 RETURN_STR(out); \
732}
733
734#define PHP_ZLIB_DECODE_FUNC(name, encoding) \
735PHP_FUNCTION(name) \
736{ \
737 char *in_buf, *out_buf; \
738 size_t in_len; \
739 size_t out_len; \
740 zend_long max_len = 0; \
741 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &in_buf, &in_len, &max_len)) { \
742 RETURN_THROWS(); \
743 } \
744 if (max_len < 0) { \
745 zend_argument_value_error(2, "must be greater than or equal to 0"); \
746 RETURN_THROWS(); \
747 } \
748 if (SUCCESS != php_zlib_decode(in_buf, in_len, &out_buf, &out_len, encoding, max_len)) { \
749 RETURN_FALSE; \
750 } \
751 RETVAL_STRINGL(out_buf, out_len); \
752 efree(out_buf); \
753}
754
755/* {{{ Compress data with the specified encoding */
757/* }}} */
758
759/* {{{ Uncompress any raw/gzip/zlib encoded data */
761/* }}} */
762
763/* NOTE: The naming of these userland functions was quite unlucky */
764/* {{{ Encode data with the raw deflate encoding */
766/* }}} */
767
768/* {{{ Encode data with the gzip encoding */
770/* }}} */
771
772/* {{{ Encode data with the zlib encoding */
774/* }}} */
775
776/* {{{ Decode raw deflate encoded data */
778/* }}} */
779
780/* {{{ Decode gzip encoded data */
782/* }}} */
783
784/* {{{ Decode zlib encoded data */
786/* }}} */
787
788static bool zlib_create_dictionary_string(HashTable *options, char **dict, size_t *dictlen) {
789 zval *option_buffer;
790
791 if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("dictionary"))) != NULL) {
792 ZVAL_DEINDIRECT(option_buffer);
793 ZVAL_DEREF(option_buffer);
794 switch (Z_TYPE_P(option_buffer)) {
795 case IS_STRING: {
796 zend_string *str = Z_STR_P(option_buffer);
797 *dict = emalloc(ZSTR_LEN(str));
798 memcpy(*dict, ZSTR_VAL(str), ZSTR_LEN(str));
799 *dictlen = ZSTR_LEN(str);
800 } break;
801
802 case IS_ARRAY: {
803 HashTable *dictionary = Z_ARR_P(option_buffer);
804
805 if (zend_hash_num_elements(dictionary) > 0) {
806 char *dictptr;
807 zval *cur;
808 zend_string **strings = safe_emalloc(zend_hash_num_elements(dictionary), sizeof(zend_string *), 0);
809 zend_string **end, **ptr = strings - 1;
810
811 ZEND_HASH_FOREACH_VAL(dictionary, cur) {
812 *++ptr = zval_get_string(cur);
814 if (ZSTR_LEN(*ptr) == 0 || EG(exception)) {
815 do {
816 zend_string_release(*ptr);
817 } while (--ptr >= strings);
818 efree(strings);
819 if (!EG(exception)) {
820 zend_argument_value_error(2, "must not contain empty strings");
821 }
822 return 0;
823 }
824 if (zend_str_has_nul_byte(*ptr)) {
825 do {
826 zend_string_release(*ptr);
827 } while (--ptr >= strings);
828 efree(strings);
829 zend_argument_value_error(2, "must not contain strings with null bytes");
830 return 0;
831 }
832
833 *dictlen += ZSTR_LEN(*ptr) + 1;
835
836 dictptr = *dict = emalloc(*dictlen);
837 ptr = strings;
838 end = strings + zend_hash_num_elements(dictionary);
839 do {
840 memcpy(dictptr, ZSTR_VAL(*ptr), ZSTR_LEN(*ptr));
841 dictptr += ZSTR_LEN(*ptr);
842 *dictptr++ = 0;
844 } while (++ptr != end);
845 efree(strings);
846 }
847 } break;
848
849 default:
850 zend_argument_type_error(2, "must be of type zero-terminated string or array, %s given", zend_zval_value_name(option_buffer));
851 return 0;
852 }
853 }
854
855 return 1;
856}
857
858/* {{{ Initialize an incremental inflate context with the specified encoding */
860{
861 php_zlib_context *ctx;
862 zend_long encoding, window = 15;
863 char *dict = NULL;
864 size_t dictlen = 0;
866 zval *option_buffer;
867
870 }
871
872 if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("window"))) != NULL) {
873 ZVAL_DEINDIRECT(option_buffer);
874 window = zval_get_long(option_buffer);
875 }
876 if (window < 8 || window > 15) {
877 zend_value_error("zlib window size (logarithm) (" ZEND_LONG_FMT ") must be within 8..15", window);
879 }
880
881 switch (encoding) {
885 break;
886 default:
887 zend_value_error("Encoding mode must be ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE");
889 }
890
891 if (!zlib_create_dictionary_string(options, &dict, &dictlen)) {
893 }
894
897
898 ctx->Z.zalloc = php_zlib_alloc;
899 ctx->Z.zfree = php_zlib_free;
900 ctx->inflateDict = dict;
901 ctx->inflateDictlen = dictlen;
902 ctx->status = Z_OK;
903
904 if (encoding < 0) {
905 encoding += 15 - window;
906 } else {
907 encoding -= 15 - window;
908 }
909
910 if (inflateInit2(&ctx->Z, encoding) != Z_OK) {
912 php_error_docref(NULL, E_WARNING, "Failed allocating zlib.inflate context");
914 }
915
916 if (encoding == PHP_ZLIB_ENCODING_RAW && dictlen > 0) {
917 switch (inflateSetDictionary(&ctx->Z, (Bytef *) ctx->inflateDict, ctx->inflateDictlen)) {
918 case Z_OK:
919 efree(ctx->inflateDict);
920 ctx->inflateDict = NULL;
921 break;
922 case Z_DATA_ERROR:
923 php_error_docref(NULL, E_WARNING, "Dictionary does not match expected dictionary (incorrect adler32 hash)");
924 efree(ctx->inflateDict);
925 ctx->inflateDict = NULL;
926 break;
928 }
929 }
930}
931/* }}} */
932
933/* {{{ Incrementally inflate encoded data in the specified context */
935{
937 char *in_buf;
938 size_t in_len, buffer_used = 0, CHUNK_SIZE = 8192;
939 zval *res;
940 php_zlib_context *ctx;
941 zend_long flush_type = Z_SYNC_FLUSH;
942 int status;
943
944 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "Os|l", &res, inflate_context_ce, &in_buf, &in_len, &flush_type)) {
946 }
947
949
950 switch (flush_type) {
951 case Z_NO_FLUSH:
952 case Z_PARTIAL_FLUSH:
953 case Z_SYNC_FLUSH:
954 case Z_FULL_FLUSH:
955 case Z_BLOCK:
956 case Z_FINISH:
957 break;
958
959 default:
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");
962 }
963
964 /* Lazy-resetting the zlib stream so ctx->total_in remains available until the next inflate_add() call. */
965 if (ctx->status == Z_STREAM_END)
966 {
967 ctx->status = Z_OK;
968 inflateReset(&ctx->Z);
969 }
970
971 if (in_len <= 0 && flush_type != Z_FINISH) {
973 }
974
975 out = zend_string_alloc((in_len > CHUNK_SIZE) ? in_len : CHUNK_SIZE, 0);
976 ctx->Z.next_in = (Bytef *) in_buf;
977 ctx->Z.next_out = (Bytef *) ZSTR_VAL(out);
978 ctx->Z.avail_in = in_len;
979 ctx->Z.avail_out = ZSTR_LEN(out);
980
981 do {
982 status = inflate(&ctx->Z, flush_type);
983 buffer_used = ZSTR_LEN(out) - ctx->Z.avail_out;
984
985 ctx->status = status; /* Save status for exposing to userspace */
986
987 switch (status) {
988 case Z_OK:
989 if (ctx->Z.avail_out == 0) {
990 /* more output buffer space needed; realloc and try again */
991 out = zend_string_realloc(out, ZSTR_LEN(out) + CHUNK_SIZE, 0);
992 ctx->Z.avail_out = CHUNK_SIZE;
993 ctx->Z.next_out = (Bytef *) ZSTR_VAL(out) + buffer_used;
994 break;
995 } else {
996 goto complete;
997 }
998 case Z_STREAM_END:
999 goto complete;
1000 case Z_BUF_ERROR:
1001 if (flush_type == Z_FINISH && ctx->Z.avail_out == 0) {
1002 /* more output buffer space needed; realloc and try again */
1003 out = zend_string_realloc(out, ZSTR_LEN(out) + CHUNK_SIZE, 0);
1004 ctx->Z.avail_out = CHUNK_SIZE;
1005 ctx->Z.next_out = (Bytef *) ZSTR_VAL(out) + buffer_used;
1006 break;
1007 } else {
1008 /* No more input data; we're finished */
1009 goto complete;
1010 }
1011 case Z_NEED_DICT:
1012 if (ctx->inflateDict) {
1013 switch (inflateSetDictionary(&ctx->Z, (Bytef *) ctx->inflateDict, ctx->inflateDictlen)) {
1014 case Z_OK:
1015 efree(ctx->inflateDict);
1016 ctx->inflateDict = NULL;
1017 break;
1018 case Z_DATA_ERROR:
1019 efree(ctx->inflateDict);
1020 ctx->inflateDict = NULL;
1022 php_error_docref(NULL, E_WARNING, "Dictionary does not match expected dictionary (incorrect adler32 hash)");
1025 }
1026 break;
1027 } else {
1028 php_error_docref(NULL, E_WARNING, "Inflating this data requires a preset dictionary, please specify it in the options array of inflate_init()");
1030 }
1031 default:
1033 php_error_docref(NULL, E_WARNING, "%s", zError(status));
1035 }
1036 } while (1);
1037
1038complete:
1039 out = zend_string_realloc(out, buffer_used, 0);
1040 ZSTR_VAL(out)[buffer_used] = 0;
1041 RETURN_STR(out);
1042}
1043/* }}} */
1044
1045/* {{{ Get decompression status, usually returns either ZLIB_OK or ZLIB_STREAM_END. */
1047{
1048 zval *res;
1049 php_zlib_context *ctx;
1050
1052 RETURN_THROWS();
1053 }
1054
1055 ctx = Z_INFLATE_CONTEXT_P(res);
1056
1057 RETURN_LONG(ctx->status);
1058}
1059/* }}} */
1060
1061/* {{{ Get number of bytes read so far. */
1063{
1064 zval *res;
1065 php_zlib_context *ctx;
1066
1068 RETURN_THROWS();
1069 }
1070
1071 ctx = Z_INFLATE_CONTEXT_P(res);
1072
1073 RETURN_LONG(ctx->Z.total_in);
1074}
1075/* }}} */
1076
1077/* {{{ Initialize an incremental deflate context using the specified encoding */
1079{
1080 php_zlib_context *ctx;
1081 zend_long encoding, level = -1, memory = 8, window = 15, strategy = Z_DEFAULT_STRATEGY;
1082 char *dict = NULL;
1083 size_t dictlen = 0;
1085 zval *option_buffer;
1086
1088 RETURN_THROWS();
1089 }
1090
1091 if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("level"))) != NULL) {
1092 ZVAL_DEINDIRECT(option_buffer);
1093 level = zval_get_long(option_buffer);
1094 }
1095 if (level < -1 || level > 9) {
1096 zend_value_error("deflate_init(): \"level\" option must be between -1 and 9");
1097 RETURN_THROWS();
1098 }
1099
1100 if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("memory"))) != NULL) {
1101 ZVAL_DEINDIRECT(option_buffer);
1102 memory = zval_get_long(option_buffer);
1103 }
1104 if (memory < 1 || memory > 9) {
1105 zend_value_error("deflate_init(): \"memory\" option must be between 1 and 9");
1106 RETURN_THROWS();
1107 }
1108
1109 if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("window"))) != NULL) {
1110 ZVAL_DEINDIRECT(option_buffer);
1111 window = zval_get_long(option_buffer);
1112 }
1113 if (window < 8 || window > 15) {
1114 zend_value_error("deflate_init(): \"window\" option must be between 8 and 15");
1115 RETURN_THROWS();
1116 }
1117
1118 if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("strategy"))) != NULL) {
1119 ZVAL_DEINDIRECT(option_buffer);
1120 strategy = zval_get_long(option_buffer);
1121 }
1122 switch (strategy) {
1123 case Z_FILTERED:
1124 case Z_HUFFMAN_ONLY:
1125 case Z_RLE:
1126 case Z_FIXED:
1127 case Z_DEFAULT_STRATEGY:
1128 break;
1129 default:
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");
1131 RETURN_THROWS();
1132 }
1133
1134 switch (encoding) {
1138 break;
1139 default:
1140 zend_argument_value_error(1, "must be one of ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP, or ZLIB_ENCODING_DEFLATE");
1141 RETURN_THROWS();
1142 }
1143
1144 if (!zlib_create_dictionary_string(options, &dict, &dictlen)) {
1145 RETURN_THROWS();
1146 }
1147
1150
1151 ctx->Z.zalloc = php_zlib_alloc;
1152 ctx->Z.zfree = php_zlib_free;
1153
1154 if (encoding < 0) {
1155 encoding += 15 - window;
1156 } else {
1157 encoding -= 15 - window;
1158 }
1159
1160 if (deflateInit2(&ctx->Z, level, Z_DEFLATED, encoding, memory, strategy) != Z_OK) {
1162 php_error_docref(NULL, E_WARNING, "Failed allocating zlib.deflate context");
1164 }
1165
1166 if (dict) {
1167 int success = deflateSetDictionary(&ctx->Z, (Bytef *) dict, dictlen);
1168 ZEND_ASSERT(success == Z_OK);
1169 efree(dict);
1170 }
1171}
1172/* }}} */
1173
1174/* {{{ Incrementally deflate data in the specified context */
1176{
1178 char *in_buf;
1179 size_t in_len, out_size, buffer_used;
1180 zval *res;
1181 php_zlib_context *ctx;
1182 zend_long flush_type = Z_SYNC_FLUSH;
1183 int status;
1184
1185 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "Os|l", &res, deflate_context_ce, &in_buf, &in_len, &flush_type)) {
1186 RETURN_THROWS();
1187 }
1188
1189 ctx = Z_DEFLATE_CONTEXT_P(res);
1190
1191 switch (flush_type) {
1192 case Z_BLOCK:
1193#if ZLIB_VERNUM < 0x1240L
1194 zend_throw_error(NULL, "zlib >= 1.2.4 required for BLOCK deflate; current version: %s", ZLIB_VERSION);
1195 RETURN_THROWS();
1196#endif
1197 case Z_NO_FLUSH:
1198 case Z_PARTIAL_FLUSH:
1199 case Z_SYNC_FLUSH:
1200 case Z_FULL_FLUSH:
1201 case Z_FINISH:
1202 break;
1203
1204 default:
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");
1206 RETURN_THROWS();
1207 }
1208
1209 if (in_len <= 0 && flush_type != Z_FINISH) {
1211 }
1212
1213 out_size = PHP_ZLIB_BUFFER_SIZE_GUESS(in_len);
1214 out_size = (out_size < 64) ? 64 : out_size;
1215 out = zend_string_alloc(out_size, 0);
1216
1217 ctx->Z.next_in = (Bytef *) in_buf;
1218 ctx->Z.next_out = (Bytef *) ZSTR_VAL(out);
1219 ctx->Z.avail_in = in_len;
1220 ctx->Z.avail_out = ZSTR_LEN(out);
1221
1222 buffer_used = 0;
1223
1224 do {
1225 if (ctx->Z.avail_out == 0) {
1226 /* more output buffer space needed; realloc and try again */
1227 /* adding 64 more bytes solved every issue I have seen */
1228 out = zend_string_realloc(out, ZSTR_LEN(out) + 64, 0);
1229 ctx->Z.avail_out = 64;
1230 ctx->Z.next_out = (Bytef *) ZSTR_VAL(out) + buffer_used;
1231 }
1232 status = deflate(&ctx->Z, flush_type);
1233 buffer_used = ZSTR_LEN(out) - ctx->Z.avail_out;
1234 } while (status == Z_OK && ctx->Z.avail_out == 0);
1235
1236 switch (status) {
1237 case Z_OK:
1238 ZSTR_LEN(out) = (char *) ctx->Z.next_out - ZSTR_VAL(out);
1239 ZSTR_VAL(out)[ZSTR_LEN(out)] = 0;
1240 RETURN_STR(out);
1241 break;
1242 case Z_STREAM_END:
1243 ZSTR_LEN(out) = (char *) ctx->Z.next_out - ZSTR_VAL(out);
1244 ZSTR_VAL(out)[ZSTR_LEN(out)] = 0;
1245 deflateReset(&ctx->Z);
1246 RETURN_STR(out);
1247 break;
1248 default:
1250 php_error_docref(NULL, E_WARNING, "zlib error (%s)", zError(status));
1252 }
1253}
1254/* }}} */
1255
1256#ifdef COMPILE_DL_ZLIB
1257#ifdef ZTS
1259#endif
1260ZEND_GET_MODULE(php_zlib)
1261#endif
1262
1263/* {{{ OnUpdate_zlib_output_compression */
1264static PHP_INI_MH(OnUpdate_zlib_output_compression)
1265{
1266 int int_value;
1267 char *ini_value;
1268 if (new_value == NULL) {
1269 return FAILURE;
1270 }
1271
1272 if (zend_string_equals_literal_ci(new_value, "off")) {
1273 int_value = 0;
1274 } else if (zend_string_equals_literal_ci(new_value, "on")) {
1275 int_value = 1;
1276 } else {
1277 int_value = (int) zend_ini_parse_quantity_warn(new_value, entry->name);
1278 }
1279 ini_value = zend_ini_string("output_handler", sizeof("output_handler") - 1, 0);
1280
1281 if (ini_value && *ini_value && int_value) {
1282 php_error_docref("ref.outcontrol", E_CORE_ERROR, "Cannot use both zlib.output_compression and output_handler together!!");
1283 return FAILURE;
1284 }
1285 if (stage == PHP_INI_STAGE_RUNTIME) {
1287 if (status & PHP_OUTPUT_SENT) {
1288 php_error_docref("ref.outcontrol", E_WARNING, "Cannot change zlib.output_compression - headers already sent");
1289 return FAILURE;
1290 }
1291 }
1292
1294 *p = int_value;
1295
1297 if (stage == PHP_INI_STAGE_RUNTIME && int_value) {
1299 php_zlib_output_compression_start();
1300 }
1301 }
1302
1303 return SUCCESS;
1304}
1305/* }}} */
1306
1307/* {{{ OnUpdate_zlib_output_handler */
1308static PHP_INI_MH(OnUpdate_zlib_output_handler)
1309{
1311 php_error_docref("ref.outcontrol", E_WARNING, "Cannot change zlib.output_handler - headers already sent");
1312 return FAILURE;
1313 }
1314
1315 return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
1316}
1317/* }}} */
1318
1319/* {{{ INI */
1321 STD_PHP_INI_BOOLEAN("zlib.output_compression", "0", PHP_INI_ALL, OnUpdate_zlib_output_compression, output_compression_default, zend_zlib_globals, zlib_globals)
1322 STD_PHP_INI_ENTRY("zlib.output_compression_level", "-1", PHP_INI_ALL, OnUpdateLong, output_compression_level, zend_zlib_globals, zlib_globals)
1323 STD_PHP_INI_ENTRY("zlib.output_handler", "", PHP_INI_ALL, OnUpdate_zlib_output_handler, output_handler, zend_zlib_globals, zlib_globals)
1325
1326/* }}} */
1327
1328/* {{{ PHP_MINIT_FUNCTION */
1329static PHP_MINIT_FUNCTION(zlib)
1330{
1333
1334 php_output_handler_alias_register(ZEND_STRL("ob_gzhandler"), php_zlib_output_handler_init);
1335 php_output_handler_conflict_register(ZEND_STRL("ob_gzhandler"), php_zlib_output_conflict_check);
1337
1338 inflate_context_ce = register_class_InflateContext();
1339 inflate_context_ce->create_object = inflate_context_create_object;
1340 inflate_context_ce->default_object_handlers = &inflate_context_object_handlers;
1341
1342 memcpy(&inflate_context_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
1343 inflate_context_object_handlers.offset = XtOffsetOf(php_zlib_context, std);
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;
1347 inflate_context_object_handlers.compare = zend_objects_not_comparable;
1348
1349 deflate_context_ce = register_class_DeflateContext();
1350 deflate_context_ce->create_object = deflate_context_create_object;
1351 deflate_context_ce->default_object_handlers = &deflate_context_object_handlers;
1352
1353 memcpy(&deflate_context_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
1354 deflate_context_object_handlers.offset = XtOffsetOf(php_zlib_context, std);
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;
1358 deflate_context_object_handlers.compare = zend_objects_not_comparable;
1359
1360 register_zlib_symbols(module_number);
1361
1363 return SUCCESS;
1364}
1365/* }}} */
1366
1367/* {{{ PHP_MSHUTDOWN_FUNCTION */
1368static PHP_MSHUTDOWN_FUNCTION(zlib)
1369{
1372
1374
1375 return SUCCESS;
1376}
1377/* }}} */
1378
1379/* {{{ PHP_RINIT_FUNCTION */
1380static PHP_RINIT_FUNCTION(zlib)
1381{
1383 if (!ZLIBG(handler_registered)) {
1385 php_zlib_output_compression_start();
1386 }
1387
1388 return SUCCESS;
1389}
1390/* }}} */
1391
1392/* {{{ PHP_RSHUTDOWN_FUNCTION */
1393static PHP_RSHUTDOWN_FUNCTION(zlib)
1394{
1395 php_zlib_cleanup_ob_gzhandler_mess();
1397
1398 return SUCCESS;
1399}
1400/* }}} */
1401
1402/* {{{ PHP_MINFO_FUNCTION */
1403static PHP_MINFO_FUNCTION(zlib)
1404{
1406 php_info_print_table_row(2, "ZLib Support", "enabled");
1407 php_info_print_table_row(2, "Stream Wrapper", "compress.zlib://");
1408 php_info_print_table_row(2, "Stream Filter", "zlib.inflate, zlib.deflate");
1409 php_info_print_table_row(2, "Compiled Version", ZLIB_VERSION);
1410 php_info_print_table_row(2, "Linked Version", (char *) zlibVersion());
1412
1414}
1415/* }}} */
1416
1417/* {{{ ZEND_MODULE_GLOBALS_CTOR */
1418static PHP_GINIT_FUNCTION(zlib)
1419{
1420#if defined(COMPILE_DL_ZLIB) && defined(ZTS)
1422#endif
1423 zlib_globals->ob_gzhandler = NULL;
1424 zlib_globals->handler_registered = 0;
1425}
1426/* }}} */
1427
1428/* {{{ php_zlib_module_entry */
1431 "zlib",
1432 ext_functions,
1433 PHP_MINIT(zlib),
1434 PHP_MSHUTDOWN(zlib),
1435 PHP_RINIT(zlib),
1436 PHP_RSHUTDOWN(zlib),
1437 PHP_MINFO(zlib),
1439 PHP_MODULE_GLOBALS(zlib),
1440 PHP_GINIT(zlib),
1441 NULL,
1442 NULL,
1444};
1445/* }}} */
SAPI_API int sapi_add_header_ex(const char *header_line, size_t header_line_len, bool duplicate, bool replace)
Definition SAPI.c:628
#define SG(v)
Definition SAPI.h:160
size_t len
Definition apprentice.c:174
bool exception
Definition assert.c:30
fprintf($stream, string $format, mixed ... $values)
strstr(string $haystack, string $needle, bool $before_needle=false)
headers_sent(&$filename=null, &$line=null)
DNS_STATUS status
Definition dns_win32.c:49
#define max(a, b)
Definition exif.c:60
new_type size
Definition ffi.c:4365
zend_string * res
Definition ffi.c:4692
void * ptr
Definition ffi.c:3814
memcpy(ptr1, ptr2, size)
memset(ptr, 0, type->size)
zend_ffi_ctype_name_buf buf
Definition ffi.c:4685
size_t mode_len
bool use_include_path
char * mode
size_t filename_len
#define NULL
Definition gdcache.h:45
#define round(tables, k1, k2)
Definition hash_gost.c:26
#define SUCCESS
Definition hash_sha3.c:261
PHPAPI int php_stream_filter_register_factory(const char *filterpattern, const php_stream_filter_factory *factory)
Definition filter.c:43
PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern)
Definition filter.c:52
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
Definition main.c:1173
PHPAPI zend_result php_output_handler_hook(php_output_handler_hook_t type, void *arg)
Definition output.c:669
PHPAPI bool php_output_handler_conflict(const char *handler_new, size_t handler_new_len, const char *handler_set, size_t handler_set_len)
Definition output.c:582
PHPAPI bool php_output_handler_started(const char *name, size_t name_len)
Definition output.c:561
PHPAPI zend_result php_output_start_user(zval *output_handler, size_t chunk_size, int flags)
Definition output.c:428
PHPAPI zend_result php_output_handler_conflict_register(const char *name, size_t name_len, php_output_handler_conflict_check_t check_func)
Definition output.c:598
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)
Definition output.c:505
PHPAPI int php_output_get_level(void)
Definition output.c:351
PHPAPI zend_result php_output_handler_alias_register(const char *name, size_t name_len, php_output_handler_alias_ctor_t func)
Definition output.c:652
PHPAPI zend_result php_output_handler_start(php_output_handler *handler)
Definition output.c:532
PHPAPI int php_output_get_status(void)
Definition output.c:214
PHPAPI void php_output_handler_set_context(php_output_handler *handler, void *opaq, void(*dtor)(void *))
Definition output.c:520
#define memmove(a, b, c)
php_info_print_table_start()
Definition info.c:1064
php_info_print_table_row(2, "PDO Driver for Firebird", "enabled")
php_info_print_table_end()
Definition info.c:1074
#define PHP_GINIT
Definition php.h:397
#define PHP_FUNCTION
Definition php.h:364
#define PHP_MSHUTDOWN_FUNCTION
Definition php.h:401
#define PHP_MINFO
Definition php.h:396
#define PHP_MINIT_FUNCTION
Definition php.h:400
#define PHP_RINIT
Definition php.h:394
#define PHP_MSHUTDOWN
Definition php.h:393
#define PHP_MINFO_FUNCTION
Definition php.h:404
#define PHP_GINIT_FUNCTION
Definition php.h:405
#define PHP_RSHUTDOWN
Definition php.h:395
#define PHP_RINIT_FUNCTION
Definition php.h:402
#define PHP_RSHUTDOWN_FUNCTION
Definition php.h:403
#define PHP_MINIT
Definition php.h:392
#define PHP_MODULE_GLOBALS
Definition php.h:408
unsigned const char * end
Definition php_ffi.h:51
#define TRACK_VARS_SERVER
Definition php_globals.h:43
#define PG(v)
Definition php_globals.h:31
#define PHP_INI_STAGE_RUNTIME
Definition php_ini.h:75
#define PHP_INI_ALL
Definition php_ini.h:45
#define PHP_INI_BEGIN
Definition php_ini.h:52
#define STD_PHP_INI_ENTRY
Definition php_ini.h:64
#define STD_PHP_INI_BOOLEAN
Definition php_ini.h:66
#define PHP_INI_MH
Definition php_ini.h:49
#define PHP_INI_END
Definition php_ini.h:53
PHP_JSON_API size_t int options
Definition php_json.h:102
struct _php_output_handler php_output_handler
#define PHP_OUTPUT_HANDLER_FLUSH
Definition php_output.h:26
#define PHP_OUTPUT_SENT
Definition php_output.h:65
#define PHP_OUTPUT_HANDLER_STDFLAGS
Definition php_output.h:39
@ PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS
Definition php_output.h:75
@ PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE
Definition php_output.h:77
#define PHP_OUTPUT_HANDLER_CLEAN
Definition php_output.h:25
#define PHP_OUTPUT_HANDLER_FINAL
Definition php_output.h:27
#define PHP_OUTPUT_HANDLER_DEFAULT_SIZE
Definition php_output.h:89
#define PHP_OUTPUT_HANDLER_STARTED
Definition php_output.h:42
struct _php_output_context php_output_context
#define PHP_OUTPUT_HANDLER_START
Definition php_output.h:24
xmlCharEncodingHandlerPtr encoding
Definition php_soap.h:170
struct _php_stream php_stream
Definition php_streams.h:96
#define REPORT_ERRORS
#define php_stream_gets(stream, buf, maxlen)
#define STREAMS_CC
Definition php_streams.h:54
#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)
Definition streams.c:1911
PHPAPI zend_result php_unregister_url_stream_wrapper(const char *protocol)
Definition streams.c:1927
#define USE_PATH
#define php_stream_passthru(stream)
#define CHUNK_SIZE
zend_long output_compression
Definition php_zlib.h:55
const php_stream_filter_factory php_zlib_filter_factory
#define PHP_ZLIB_BUFFER_SIZE_GUESS(in_len)
Definition php_zlib.h:34
const php_stream_wrapper php_stream_gzip_wrapper
php_zlib_context * ob_gzhandler
Definition php_zlib.h:58
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
Definition php_zlib.h:27
bool handler_registered
Definition php_zlib.h:60
zend_long output_compression_level
Definition php_zlib.h:56
#define PHP_ZLIB_OUTPUT_HANDLER_NAME
Definition php_zlib.h:33
#define PHP_ZLIB_ENCODING_DEFLATE
Definition php_zlib.h:29
char * output_handler
Definition php_zlib.h:57
int compression_coding
Definition php_zlib.h:61
#define PHP_ZLIB_ENCODING_GZIP
Definition php_zlib.h:28
#define ZLIBG(v)
Definition php_zlib.h:64
#define PHP_ZLIB_ENCODING_ANY
Definition php_zlib.h:31
#define PHP_ZLIB_VERSION
Definition php_zlib.h:23
zend_module_entry php_zlib_module_entry
Definition zlib.c:1429
struct _php_zlib_buffer php_zlib_buffer
zend_long output_compression_default
Definition php_zlib.h:59
zval rv
Definition session.c:1024
p
Definition session.c:1105
php_output_buffer in
Definition php_output.h:101
php_output_buffer out
Definition php_output.h:102
zend_object std
Definition php_zlib.h:50
char * inflateDict
Definition php_zlib.h:46
php_zlib_buffer buffer
Definition php_zlib.h:49
size_t inflateDictlen
Definition php_zlib.h:48
Definition file.h:177
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format,...)
Definition zend.c:1772
ZEND_API ZEND_COLD void zend_value_error(const char *format,...)
Definition zend.c:1849
#define ZEND_TSRMLS_CACHE_UPDATE()
Definition zend.h:69
#define ZEND_TSRMLS_CACHE_DEFINE()
Definition zend.h:68
ZEND_API const char * zend_zval_value_name(const zval *arg)
Definition zend_API.c:148
ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *class_type)
Definition zend_API.c:1849
ZEND_API void add_index_string(zval *arg, zend_ulong index, const char *str)
Definition zend_API.c:2087
ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec,...)
Definition zend_API.c:1300
ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type)
Definition zend_API.c:1688
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
Definition zend_API.c:433
ZEND_API ZEND_COLD void zend_argument_type_error(uint32_t arg_num, const char *format,...)
Definition zend_API.c:423
#define ZEND_NUM_ARGS()
Definition zend_API.h:530
#define RETURN_STRINGL(s, l)
Definition zend_API.h:1044
#define RETURN_FALSE
Definition zend_API.h:1058
#define ZVAL_STRING(z, s)
Definition zend_API.h:956
#define ZEND_DECLARE_MODULE_GLOBALS(module_name)
Definition zend_API.h:268
#define ZEND_GET_MODULE(name)
Definition zend_API.h:241
#define zend_parse_parameters_none()
Definition zend_API.h:353
#define RETVAL_EMPTY_STRING()
Definition zend_API.h:1021
#define RETURN_LONG(l)
Definition zend_API.h:1037
#define RETURN_THROWS()
Definition zend_API.h:1060
#define RETURN_STR(s)
Definition zend_API.h:1039
#define RETURN_EMPTY_STRING()
Definition zend_API.h:1047
#define RETVAL_STRINGL(s, l)
Definition zend_API.h:1018
#define array_init(arg)
Definition zend_API.h:537
#define erealloc_recoverable(ptr, size)
Definition zend_alloc.h:162
#define ecalloc(nmemb, size)
Definition zend_alloc.h:158
#define efree(ptr)
Definition zend_alloc.h:155
#define erealloc(ptr, size)
Definition zend_alloc.h:159
#define safe_emalloc(nmemb, size, offset)
Definition zend_alloc.h:154
#define emalloc(size)
Definition zend_alloc.h:151
struct _zval_struct zval
zend_string_release_ex(func->internal_function.function_name, 0)
ZEND_API bool zend_is_auto_global(zend_string *name)
#define E_WARNING
Definition zend_errors.h:24
#define E_CORE_ERROR
Definition zend_errors.h:27
union _zend_function zend_function
#define EG(v)
ZEND_API zval *ZEND_FASTCALL zend_hash_str_find(const HashTable *ht, const char *str, size_t len)
Definition zend_hash.c:2689
#define ZEND_HASH_FOREACH_END()
Definition zend_hash.h:1086
#define ZEND_HASH_FOREACH_VAL(ht, _val)
Definition zend_hash.h:1102
ZEND_API zend_long zend_ini_parse_quantity_warn(zend_string *value, zend_string *setting)
Definition zend_ini.c:869
ZEND_API char * zend_ini_string(const char *name, size_t name_length, int orig)
Definition zend_ini.c:505
#define UNREGISTER_INI_ENTRIES()
Definition zend_ini.h:204
#define REGISTER_INI_ENTRIES()
Definition zend_ini.h:203
#define DISPLAY_INI_ENTRIES()
Definition zend_ini.h:205
#define ZEND_INI_GET_ADDR()
Definition zend_ini.h:259
int32_t zend_long
Definition zend_long.h:42
#define ZEND_LONG_FMT
Definition zend_long.h:87
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 ZEND_FALLTHROUGH
#define XtOffsetOf(s_type, field)
#define ZEND_ASSERT(c)
#define ZEND_STRL(str)
#define EMPTY_SWITCH_DEFAULT_CASE()
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
#define ZSTR_VAL(zstr)
Definition zend_string.h:68
#define ZSTR_KNOWN(idx)
#define ZSTR_LEN(zstr)
Definition zend_string.h:69
#define zend_string_equals_literal_ci(str, c)
#define Z_TYPE_P(zval_p)
Definition zend_types.h:660
#define Z_STRVAL_P(zval_p)
Definition zend_types.h:975
#define ZVAL_DEREF(z)
#define IS_STRING
Definition zend_types.h:606
struct _zend_array HashTable
Definition zend_types.h:386
#define IS_ARRAY
Definition zend_types.h:607
#define Z_STR_P(zval_p)
Definition zend_types.h:972
@ FAILURE
Definition zend_types.h:61
ZEND_RESULT_CODE zend_result
Definition zend_types.h:64
struct _zend_object_handlers zend_object_handlers
Definition zend_types.h:88
#define Z_TYPE(zval)
Definition zend_types.h:659
#define Z_ARRVAL(zval)
Definition zend_types.h:986
#define Z_ARR_P(zval_p)
Definition zend_types.h:984
#define ZVAL_DEINDIRECT(z)
ZEND_API void zval_ptr_dtor(zval *zval_ptr)
zval * return_value
out($f, $s)
#define PHP_ZLIB_ENCODE_FUNC(name, default_encoding)
Definition zlib.c:700
zend_class_entry * inflate_context_ce
Definition zlib.c:48
#define PHP_ZLIB_DECODE_FUNC(name, encoding)
Definition zlib.c:734
zend_class_entry * deflate_context_ce
Definition zlib.c:86
#define Z_INFLATE_CONTEXT_P(zv)
Definition zlib.c:55
#define Z_DEFLATE_CONTEXT_P(zv)
Definition zlib.c:93
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=[])
zlib_get_coding_type()
readgzfile(string $filename, int $use_include_path=0)
const ZLIB_VERSION
Definition zlib.stub.php:93