php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
output.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: Zeev Suraski <zeev@php.net> |
14 | Thies C. Arntzen <thies@thieso.net> |
15 | Marcus Boerger <helly@php.net> |
16 | New API: Michael Wallner <mike@php.net> |
17 +----------------------------------------------------------------------+
18*/
19
20#ifndef PHP_OUTPUT_DEBUG
21# define PHP_OUTPUT_DEBUG 0
22#endif
23#ifndef PHP_OUTPUT_NOINLINE
24# define PHP_OUTPUT_NOINLINE 0
25#endif
26
27#include "php.h"
28#include "ext/standard/head.h"
30#include "SAPI.h"
31#include "zend_stack.h"
32#include "php_output.h"
33
35
36const char php_output_default_handler_name[sizeof("default output handler")] = "default output handler";
37const char php_output_devnull_handler_name[sizeof("null output handler")] = "null output handler";
38
39#if PHP_OUTPUT_NOINLINE || PHP_OUTPUT_DEBUG
40# undef inline
41# define inline
42#endif
43
44/* {{{ aliases, conflict and reverse conflict hash tables */
45static HashTable php_output_handler_aliases;
46static HashTable php_output_handler_conflicts;
47static HashTable php_output_handler_reverse_conflicts;
48/* }}} */
49
50/* {{{ forward declarations */
51static inline bool php_output_lock_error(int op);
52static inline void php_output_op(int op, const char *str, size_t len);
53
54static inline php_output_handler *php_output_handler_init(zend_string *name, size_t chunk_size, int flags);
56static inline bool php_output_handler_append(php_output_handler *handler, const php_output_buffer *buf);
57static inline zval *php_output_handler_status(php_output_handler *handler, zval *entry);
58
59static inline void php_output_context_init(php_output_context *context, int op);
60static inline void php_output_context_reset(php_output_context *context);
61static inline void php_output_context_swap(php_output_context *context);
62static inline void php_output_context_dtor(php_output_context *context);
63
64static int php_output_stack_pop(int flags);
65static int php_output_stack_apply_op(void *h, void *c);
66static int php_output_stack_apply_clean(void *h, void *c);
67static int php_output_stack_apply_list(void *h, void *z);
68static int php_output_stack_apply_status(void *h, void *z);
69
70static zend_result php_output_handler_compat_func(void **handler_context, php_output_context *output_context);
71static zend_result php_output_handler_default_func(void **handler_context, php_output_context *output_context);
72static zend_result php_output_handler_devnull_func(void **handler_context, php_output_context *output_context);
73/* }}} */
74
75/* {{{ static void php_output_init_globals(zend_output_globals *G)
76 * Initialize the module globals on MINIT */
77static inline void php_output_init_globals(zend_output_globals *G)
78{
79 memset(G, 0, sizeof(*G));
80}
81/* }}} */
82
83/* {{{ stderr/stdout writer if not PHP_OUTPUT_ACTIVATED */
84static size_t php_output_stdout(const char *str, size_t str_len)
85{
86 fwrite(str, 1, str_len, stdout);
87 return str_len;
88}
89static size_t php_output_stderr(const char *str, size_t str_len)
90{
91 fwrite(str, 1, str_len, stderr);
92/* See http://support.microsoft.com/kb/190351 */
93#ifdef PHP_WIN32
94 fflush(stderr);
95#endif
96 return str_len;
97}
98static size_t (*php_output_direct)(const char *str, size_t str_len) = php_output_stderr;
99/* }}} */
100
101/* {{{ void php_output_header(void) */
102static void php_output_header(void)
103{
104 if (!SG(headers_sent)) {
106 if (zend_is_compiling()) {
109 } else if (zend_is_executing()) {
112 }
114 zend_string_addref(OG(output_start_filename));
115 }
116#if PHP_OUTPUT_DEBUG
117 fprintf(stderr, "!!! output started at: %s (%d)\n",
119#endif
120 }
121 if (!php_header()) {
123 }
124 }
125}
126/* }}} */
127
128static void reverse_conflict_dtor(zval *zv)
129{
132}
133
134/* {{{ void php_output_startup(void)
135 * Set up module globals and initialize the conflict and reverse conflict hash tables */
137{
138 ZEND_INIT_MODULE_GLOBALS(output, php_output_init_globals, NULL);
139 zend_hash_init(&php_output_handler_aliases, 8, NULL, NULL, 1);
140 zend_hash_init(&php_output_handler_conflicts, 8, NULL, NULL, 1);
141 zend_hash_init(&php_output_handler_reverse_conflicts, 8, NULL, reverse_conflict_dtor, 1);
142 php_output_direct = php_output_stdout;
143}
144/* }}} */
145
146/* {{{ void php_output_shutdown(void)
147 * Destroy module globals and the conflict and reverse conflict hash tables */
149{
150 php_output_direct = php_output_stderr;
151 zend_hash_destroy(&php_output_handler_aliases);
152 zend_hash_destroy(&php_output_handler_conflicts);
153 zend_hash_destroy(&php_output_handler_reverse_conflicts);
154}
155/* }}} */
156
157/* {{{ SUCCESS|FAILURE php_output_activate(void)
158 * Reset output globals and set up the output handler stack */
160{
161#ifdef ZTS
162 memset(TSRMG_BULK_STATIC(output_globals_id, zend_output_globals*), 0, sizeof(zend_output_globals));
163#else
164 memset(&output_globals, 0, sizeof(zend_output_globals));
165#endif
166
169
170 return SUCCESS;
171}
172/* }}} */
173
174/* {{{ void php_output_deactivate(void)
175 * Destroy the output handler stack */
177{
179
180 if ((OG(flags) & PHP_OUTPUT_ACTIVATED)) {
181 php_output_header();
182
184 OG(active) = NULL;
185 OG(running) = NULL;
186
187 /* release all output handlers */
188 if (OG(handlers).elements) {
189 while ((handler = zend_stack_top(&OG(handlers)))) {
192 }
193 }
195 }
196
198 zend_string_release(OG(output_start_filename));
200 }
201}
202/* }}} */
203
204/* {{{ void php_output_set_status(int status)
205 * Used by SAPIs to disable output */
207{
208 OG(flags) = (OG(flags) & ~0xf) | (status & 0xf);
209}
210/* }}} */
211
212/* {{{ int php_output_get_status()
213 * Get output control status */
215{
216 return (
217 OG(flags)
218 | (OG(active) ? PHP_OUTPUT_ACTIVE : 0)
220 ) & 0xff;
221}
222/* }}} */
223
224/* {{{ int php_output_write_unbuffered(const char *str, size_t len)
225 * Unbuffered write */
226PHPAPI size_t php_output_write_unbuffered(const char *str, size_t len)
227{
229 return sapi_module.ub_write(str, len);
230 }
231 return php_output_direct(str, len);
232}
233/* }}} */
234
235/* {{{ int php_output_write(const char *str, size_t len)
236 * Buffered write */
237PHPAPI size_t php_output_write(const char *str, size_t len)
238{
240 php_output_op(PHP_OUTPUT_HANDLER_WRITE, str, len);
241 return len;
242 }
244 return 0;
245 }
246 return php_output_direct(str, len);
247}
248/* }}} */
249
250/* {{{ SUCCESS|FAILURE php_output_flush(void)
251 * Flush the most recent output handlers buffer */
253{
255
257 php_output_context_init(&context, PHP_OUTPUT_HANDLER_FLUSH);
258 php_output_handler_op(OG(active), &context);
259 if (context.out.data && context.out.used) {
261 php_output_write(context.out.data, context.out.used);
263 }
264 php_output_context_dtor(&context);
265 return SUCCESS;
266 }
267 return FAILURE;
268}
269/* }}} */
270
271/* {{{ void php_output_flush_all()
272 * Flush all output buffers subsequently */
274{
275 if (OG(active)) {
276 php_output_op(PHP_OUTPUT_HANDLER_FLUSH, NULL, 0);
277 }
278}
279/* }}} */
280
281/* {{{ SUCCESS|FAILURE php_output_clean(void)
282 * Cleans the most recent output handlers buffer if the handler is cleanable */
284{
286
288 php_output_context_init(&context, PHP_OUTPUT_HANDLER_CLEAN);
289 php_output_handler_op(OG(active), &context);
290 php_output_context_dtor(&context);
291 return SUCCESS;
292 }
293 return FAILURE;
294}
295/* }}} */
296
297/* {{{ void php_output_clean_all(void)
298 * Cleans all output handler buffers, without regard whether the handler is cleanable */
300{
302
303 if (OG(active)) {
304 php_output_context_init(&context, PHP_OUTPUT_HANDLER_CLEAN);
306 }
307}
308
309/* {{{ SUCCESS|FAILURE php_output_end(void)
310 * Finalizes the most recent output handler at pops it off the stack if the handler is removable */
312{
313 if (php_output_stack_pop(PHP_OUTPUT_POP_TRY)) {
314 return SUCCESS;
315 }
316 return FAILURE;
317}
318/* }}} */
319
320/* {{{ void php_output_end_all(void)
321 * Finalizes all output handlers and ends output buffering without regard whether a handler is removable */
323{
324 while (OG(active) && php_output_stack_pop(PHP_OUTPUT_POP_FORCE));
325}
326/* }}} */
327
328/* {{{ SUCCESS|FAILURE php_output_discard(void)
329 * Discards the most recent output handlers buffer and pops it off the stack if the handler is removable */
331{
332 if (php_output_stack_pop(PHP_OUTPUT_POP_DISCARD|PHP_OUTPUT_POP_TRY)) {
333 return SUCCESS;
334 }
335 return FAILURE;
336}
337/* }}} */
338
339/* {{{ void php_output_discard_all(void)
340 * Discard all output handlers and buffers without regard whether a handler is removable */
342{
343 while (OG(active)) {
344 php_output_stack_pop(PHP_OUTPUT_POP_DISCARD|PHP_OUTPUT_POP_FORCE);
345 }
346}
347/* }}} */
348
349/* {{{ int php_output_get_level(void)
350 * Get output buffering level, i.e. how many output handlers the stack contains */
352{
353 return OG(active) ? zend_stack_count(&OG(handlers)) : 0;
354}
355/* }}} */
356
357/* {{{ SUCCESS|FAILURE php_output_get_contents(zval *z)
358 * Get the contents of the active output handlers buffer */
360{
361 if (OG(active)) {
362 if (OG(active)->buffer.used) {
363 ZVAL_STRINGL(p, OG(active)->buffer.data, OG(active)->buffer.used);
364 } else {
366 }
367 return SUCCESS;
368 } else {
369 ZVAL_NULL(p);
370 return FAILURE;
371 }
372}
373
374/* {{{ SUCCESS|FAILURE php_output_get_length(zval *z)
375 * Get the length of the active output handlers buffer */
377{
378 if (OG(active)) {
379 ZVAL_LONG(p, OG(active)->buffer.used);
380 return SUCCESS;
381 } else {
382 ZVAL_NULL(p);
383 return FAILURE;
384 }
385}
386/* }}} */
387
388/* {{{ php_output_handler* php_output_get_active_handler(void)
389 * Get active output handler */
394/* }}} */
395
396/* {{{ SUCCESS|FAILURE php_output_handler_start_default(void)
397 * Start a "default output handler" */
399{
401
402 handler = php_output_handler_create_internal(ZEND_STRL(php_output_default_handler_name), php_output_handler_default_func, 0, PHP_OUTPUT_HANDLER_STDFLAGS);
404 return SUCCESS;
405 }
407 return FAILURE;
408}
409/* }}} */
410
411/* {{{ SUCCESS|FAILURE php_output_handler_start_devnull(void)
412 * Start a "null output handler" */
424/* }}} */
425
426/* {{{ SUCCESS|FAILURE php_output_start_user(zval *handler, size_t chunk_size, int flags)
427 * Start a user level output handler */
429{
431
432 if (output_handler) {
434 } else {
435 handler = php_output_handler_create_internal(ZEND_STRL(php_output_default_handler_name), php_output_handler_default_func, chunk_size, flags);
436 }
438 return SUCCESS;
439 }
441 return FAILURE;
442}
443/* }}} */
444
445/* {{{ SUCCESS|FAILURE php_output_start_internal(zval *name, php_output_handler_func_t handler, size_t chunk_size, int flags)
446 * Start an internal output handler that does not have to maintain a non-global state */
448{
450
451 handler = php_output_handler_create_internal(name, name_len, php_output_handler_compat_func, chunk_size, flags);
454 return SUCCESS;
455 }
457 return FAILURE;
458}
459/* }}} */
460
461/* {{{ php_output_handler *php_output_handler_create_user(zval *handler, size_t chunk_size, int flags)
462 * Create a user level output handler */
464{
465 zend_string *handler_name = NULL;
466 char *error = NULL;
470
471 switch (Z_TYPE_P(output_handler)) {
472 case IS_NULL:
473 handler = php_output_handler_create_internal(ZEND_STRL(php_output_default_handler_name), php_output_handler_default_func, chunk_size, flags);
474 break;
475 case IS_STRING:
478 break;
479 }
481 default:
482 user = ecalloc(1, sizeof(php_output_handler_user_func_t));
483 if (SUCCESS == zend_fcall_info_init(output_handler, 0, &user->fci, &user->fcc, &handler_name, &error)) {
484 handler = php_output_handler_init(handler_name, chunk_size, PHP_OUTPUT_HANDLER_ABILITY_FLAGS(flags) | PHP_OUTPUT_HANDLER_USER);
486 handler->func.user = user;
487 } else {
488 efree(user);
489 }
490 if (error) {
491 php_error_docref("ref.outcontrol", E_WARNING, "%s", error);
492 efree(error);
493 }
494 if (handler_name) {
495 zend_string_release_ex(handler_name, 0);
496 }
497 }
498
499 return handler;
500}
501/* }}} */
502
503/* {{{ php_output_handler *php_output_handler_create_internal(zval *name, php_output_handler_context_func_t handler, size_t chunk_size, int flags)
504 * Create an internal output handler that can maintain a non-global state */
506{
508 zend_string *str = zend_string_init(name, name_len, 0);
509
510 handler = php_output_handler_init(str, chunk_size, PHP_OUTPUT_HANDLER_ABILITY_FLAGS(flags) | PHP_OUTPUT_HANDLER_INTERNAL);
511 handler->func.internal = output_handler;
513
514 return handler;
515}
516/* }}} */
517
518/* {{{ void php_output_handler_set_context(php_output_handler *handler, void *opaq, void (*dtor)(void*))
519 * Set the context/state of an output handler. Calls the dtor of the previous context if there is one */
521{
522 if (handler->dtor && handler->opaq) {
523 handler->dtor(handler->opaq);
524 }
525 handler->dtor = dtor;
526 handler->opaq = opaq;
527}
528/* }}} */
529
530/* {{{ SUCCESS|FAILURE php_output_handler_start(php_output_handler *handler)
531 * Starts the set up output handler and pushes it on top of the stack. Checks for any conflicts regarding the output handler to start */
533{
534 HashTable *rconflicts;
536
537 if (php_output_lock_error(PHP_OUTPUT_HANDLER_START) || !handler) {
538 return FAILURE;
539 }
540 if (NULL != (conflict = zend_hash_find_ptr(&php_output_handler_conflicts, handler->name))) {
541 if (SUCCESS != conflict(ZSTR_VAL(handler->name), ZSTR_LEN(handler->name))) {
542 return FAILURE;
543 }
544 }
545 if (NULL != (rconflicts = zend_hash_find_ptr(&php_output_handler_reverse_conflicts, handler->name))) {
546 ZEND_HASH_PACKED_FOREACH_PTR(rconflicts, conflict) {
547 if (SUCCESS != conflict(ZSTR_VAL(handler->name), ZSTR_LEN(handler->name))) {
548 return FAILURE;
549 }
551 }
552 /* zend_stack_push returns stack level */
554 OG(active) = handler;
555 return SUCCESS;
556}
557/* }}} */
558
559/* {{{ bool php_output_handler_started(zval *name)
560 * Check whether a certain output handler is in use */
561PHPAPI bool php_output_handler_started(const char *name, size_t name_len)
562{
564 int i, count = php_output_get_level();
565
566 if (count) {
568
569 for (i = 0; i < count; ++i) {
570 if (zend_string_equals_cstr(handlers[i]->name, name, name_len)) {
571 return true;
572 }
573 }
574 }
575
576 return false;
577}
578/* }}} */
579
580/* {{{ bool php_output_handler_conflict(zval *handler_new, zval *handler_old)
581 * Check whether a certain handler is in use and issue a warning that the new handler would conflict with the already used one */
582PHPAPI bool php_output_handler_conflict(const char *handler_new, size_t handler_new_len, const char *handler_set, size_t handler_set_len)
583{
584 if (php_output_handler_started(handler_set, handler_set_len)) {
585 if (handler_new_len != handler_set_len || memcmp(handler_new, handler_set, handler_set_len)) {
586 php_error_docref("ref.outcontrol", E_WARNING, "Output handler '%s' conflicts with '%s'", handler_new, handler_set);
587 } else {
588 php_error_docref("ref.outcontrol", E_WARNING, "Output handler '%s' cannot be used twice", handler_new);
589 }
590 return true;
591 }
592 return false;
593}
594/* }}} */
595
596/* {{{ SUCCESS|FAILURE php_output_handler_conflict_register(zval *name, php_output_handler_conflict_check_t check_func)
597 * Register a conflict checking function on MINIT */
599{
600 zend_string *str;
601
602 if (!EG(current_module)) {
603 zend_error_noreturn(E_ERROR, "Cannot register an output handler conflict outside of MINIT");
604 return FAILURE;
605 }
606 str = zend_string_init_interned(name, name_len, 1);
607 zend_hash_update_ptr(&php_output_handler_conflicts, str, check_func);
609 return SUCCESS;
610}
611/* }}} */
612
613/* {{{ SUCCESS|FAILURE php_output_handler_reverse_conflict_register(zval *name, php_output_handler_conflict_check_t check_func)
614 * Register a reverse conflict checking function on MINIT */
616{
617 HashTable rev, *rev_ptr = NULL;
618
619 if (!EG(current_module)) {
620 zend_error_noreturn(E_ERROR, "Cannot register a reverse output handler conflict outside of MINIT");
621 return FAILURE;
622 }
623
624 if (NULL != (rev_ptr = zend_hash_str_find_ptr(&php_output_handler_reverse_conflicts, name, name_len))) {
625 return zend_hash_next_index_insert_ptr(rev_ptr, check_func) ? SUCCESS : FAILURE;
626 } else {
627 zend_string *str;
628
629 zend_hash_init(&rev, 8, NULL, NULL, 1);
630 if (NULL == zend_hash_next_index_insert_ptr(&rev, check_func)) {
631 zend_hash_destroy(&rev);
632 return FAILURE;
633 }
634 str = zend_string_init_interned(name, name_len, 1);
635 zend_hash_update_mem(&php_output_handler_reverse_conflicts, str, &rev, sizeof(HashTable));
637 return SUCCESS;
638 }
639}
640/* }}} */
641
642/* {{{ php_output_handler_alias_ctor_t php_output_handler_alias(zval *name)
643 * Get an internal output handler for a user handler if it exists */
645{
646 return zend_hash_str_find_ptr(&php_output_handler_aliases, name, name_len);
647}
648/* }}} */
649
650/* {{{ SUCCESS|FAILURE php_output_handler_alias_register(zval *name, php_output_handler_alias_ctor_t func)
651 * Registers an internal output handler as alias for a user handler */
653{
654 zend_string *str;
655
656 if (!EG(current_module)) {
657 zend_error_noreturn(E_ERROR, "Cannot register an output handler alias outside of MINIT");
658 return FAILURE;
659 }
660 str = zend_string_init_interned(name, name_len, 1);
661 zend_hash_update_ptr(&php_output_handler_aliases, str, func);
663 return SUCCESS;
664}
665/* }}} */
666
667/* {{{ SUCCESS|FAILURE php_output_handler_hook(php_output_handler_hook_t type, void *arg)
668 * Output handler hook for output handler functions to check/modify the current handlers abilities */
670{
671 if (OG(running)) {
672 switch (type) {
674 *(void ***) arg = &OG(running)->opaq;
675 return SUCCESS;
677 *(int *) arg = OG(running)->flags;
678 return SUCCESS;
680 *(int *) arg = OG(running)->level;
681 return SUCCESS;
684 return SUCCESS;
687 return SUCCESS;
688 default:
689 break;
690 }
691 }
692 return FAILURE;
693}
694/* }}} */
695
696/* {{{ void php_output_handler_dtor(php_output_handler *handler)
697 * Destroy an output handler */
699{
700 if (handler->name) {
702 }
703 if (handler->buffer.data) {
704 efree(handler->buffer.data);
705 }
706 if (handler->flags & PHP_OUTPUT_HANDLER_USER) {
707 zval_ptr_dtor(&handler->func.user->zoh);
708 efree(handler->func.user);
709 }
710 if (handler->dtor && handler->opaq) {
711 handler->dtor(handler->opaq);
712 }
713 memset(handler, 0, sizeof(*handler));
714}
715/* }}} */
716
717/* {{{ void php_output_handler_free(php_output_handler **handler)
718 * Destroy and free an output handler */
720{
721 if (*h) {
723 efree(*h);
724 *h = NULL;
725 }
726}
727/* }}} */
728
729/* void php_output_set_implicit_flush(int enabled)
730 * Enable or disable implicit flush */
732{
733 if (flush) {
735 } else {
737 }
738}
739/* }}} */
740
741/* {{{ char *php_output_get_start_filename(void)
742 * Get the file name where output has started */
747/* }}} */
748
749/* {{{ int php_output_get_start_lineno(void)
750 * Get the line number where output has started */
755/* }}} */
756
757/* {{{ static bool php_output_lock_error(int op)
758 * Checks whether an unallowed operation is attempted from within the output handler and issues a fatal error */
759static inline bool php_output_lock_error(int op)
760{
761 /* if there's no ob active, ob has been stopped */
762 if (op && OG(active) && OG(running)) {
763 /* fatal error */
765 php_error_docref("ref.outcontrol", E_ERROR, "Cannot use output buffering in output buffering display handlers");
766 return true;
767 }
768 return false;
769}
770/* }}} */
771
772/* {{{ static php_output_context *php_output_context_init(php_output_context *context, int op)
773 * Initialize a new output context */
774static inline void php_output_context_init(php_output_context *context, int op)
775{
776 memset(context, 0, sizeof(php_output_context));
777 context->op = op;
778}
779/* }}} */
780
781/* {{{ static void php_output_context_reset(php_output_context *context)
782 * Reset an output context */
783static inline void php_output_context_reset(php_output_context *context)
784{
785 int op = context->op;
786 php_output_context_dtor(context);
787 memset(context, 0, sizeof(php_output_context));
788 context->op = op;
789}
790/* }}} */
791
792/* {{{ static void php_output_context_feed(php_output_context *context, char *, size_t, size_t)
793 * Feed output contexts input buffer */
794static inline void php_output_context_feed(php_output_context *context, char *data, size_t size, size_t used, bool free)
795{
796 if (context->in.free && context->in.data) {
797 efree(context->in.data);
798 }
799 context->in.data = data;
800 context->in.used = used;
801 context->in.free = free;
802 context->in.size = size;
803}
804/* }}} */
805
806/* {{{ static void php_output_context_swap(php_output_context *context)
807 * Swap output contexts buffers */
808static inline void php_output_context_swap(php_output_context *context)
809{
810 if (context->in.free && context->in.data) {
811 efree(context->in.data);
812 }
813 context->in.data = context->out.data;
814 context->in.used = context->out.used;
815 context->in.free = context->out.free;
816 context->in.size = context->out.size;
817 context->out.data = NULL;
818 context->out.used = 0;
819 context->out.free = 0;
820 context->out.size = 0;
821}
822/* }}} */
823
824/* {{{ static void php_output_context_pass(php_output_context *context)
825 * Pass input to output buffer */
826static inline void php_output_context_pass(php_output_context *context)
827{
828 context->out.data = context->in.data;
829 context->out.used = context->in.used;
830 context->out.size = context->in.size;
831 context->out.free = context->in.free;
832 context->in.data = NULL;
833 context->in.used = 0;
834 context->in.free = 0;
835 context->in.size = 0;
836}
837/* }}} */
838
839/* {{{ static void php_output_context_dtor(php_output_context *context)
840 * Destroy the contents of an output context */
841static inline void php_output_context_dtor(php_output_context *context)
842{
843 if (context->in.free && context->in.data) {
844 efree(context->in.data);
845 context->in.data = NULL;
846 }
847 if (context->out.free && context->out.data) {
848 efree(context->out.data);
849 context->out.data = NULL;
850 }
851}
852/* }}} */
853
854/* {{{ static php_output_handler *php_output_handler_init(zval *name, size_t chunk_size, int flags)
855 * Allocates and initializes a php_output_handler structure */
856static inline php_output_handler *php_output_handler_init(zend_string *name, size_t chunk_size, int flags)
857{
859
860 handler = ecalloc(1, sizeof(php_output_handler));
861 handler->name = zend_string_copy(name);
862 handler->size = chunk_size;
863 handler->flags = flags;
864 handler->buffer.size = PHP_OUTPUT_HANDLER_INITBUF_SIZE(chunk_size);
865 handler->buffer.data = emalloc(handler->buffer.size);
866
867 return handler;
868}
869/* }}} */
870
871/* {{{ static bool php_output_handler_append(php_output_handler *handler, const php_output_buffer *buf)
872 * Appends input to the output handlers buffer and indicates whether the buffer does not have to be processed by the output handler */
873static inline bool php_output_handler_append(php_output_handler *handler, const php_output_buffer *buf)
874{
875 if (buf->used) {
877 /* store it away */
878 if ((handler->buffer.size - handler->buffer.used) <= buf->used) {
879 size_t grow_int = PHP_OUTPUT_HANDLER_INITBUF_SIZE(handler->size);
880 size_t grow_buf = PHP_OUTPUT_HANDLER_INITBUF_SIZE(buf->used - (handler->buffer.size - handler->buffer.used));
881 size_t grow_max = MAX(grow_int, grow_buf);
882
883 handler->buffer.data = safe_erealloc(handler->buffer.data, 1, handler->buffer.size, grow_max);
884 handler->buffer.size += grow_max;
885 }
886 memcpy(handler->buffer.data + handler->buffer.used, buf->data, buf->used);
887 handler->buffer.used += buf->used;
888
889 /* chunked buffering */
890 if (handler->size && (handler->buffer.used >= handler->size)) {
891 /* store away errors and/or any intermediate output */
892 return OG(running) ? true : false;
893 }
894 }
895 return true;
896}
897/* }}} */
898
899/* {{{ static php_output_handler_status_t php_output_handler_op(php_output_handler *handler, php_output_context *context)
900 * Output handler operation dispatcher, applying context op to the php_output_handler handler */
902{
904 int original_op = context->op;
905
906#if PHP_OUTPUT_DEBUG
907 fprintf(stderr, ">>> op(%d, "
908 "handler=%p, "
909 "name=%s, "
910 "flags=%d, "
911 "buffer.data=%s, "
912 "buffer.used=%zu, "
913 "buffer.size=%zu, "
914 "in.data=%s, "
915 "in.used=%zu)\n",
916 context->op,
917 handler,
918 handler->name,
919 handler->flags,
920 handler->buffer.used?handler->buffer.data:"",
921 handler->buffer.used,
922 handler->buffer.size,
923 context->in.used?context->in.data:"",
924 context->in.used
925 );
926#endif
927
930 }
931
932 if (php_output_lock_error(context->op)) {
933 /* fatal error */
935 }
936
937 /* storable? */
938 if (php_output_handler_append(handler, &context->in) && !context->op) {
939 context->op = original_op;
941 } else {
942 /* need to start? */
943 if (!(handler->flags & PHP_OUTPUT_HANDLER_STARTED)) {
945 }
946
947 OG(running) = handler;
948 if (handler->flags & PHP_OUTPUT_HANDLER_USER) {
949 zval ob_args[2];
950 zval retval;
951
952 /* ob_data */
953 ZVAL_STRINGL(&ob_args[0], handler->buffer.data, handler->buffer.used);
954 /* ob_mode */
955 ZVAL_LONG(&ob_args[1], (zend_long) context->op);
956
957 /* Set FCI info */
958 handler->func.user->fci.param_count = 2;
959 handler->func.user->fci.params = ob_args;
960 handler->func.user->fci.retval = &retval;
961
962#define PHP_OUTPUT_USER_SUCCESS(retval) ((Z_TYPE(retval) != IS_UNDEF) && !(Z_TYPE(retval) == IS_FALSE))
963 if (SUCCESS == zend_call_function(&handler->func.user->fci, &handler->func.user->fcc) && PHP_OUTPUT_USER_SUCCESS(retval)) {
964 /* user handler may have returned TRUE */
966 if (Z_TYPE(retval) != IS_FALSE && Z_TYPE(retval) != IS_TRUE) {
968 if (Z_STRLEN(retval)) {
970 context->out.used = Z_STRLEN(retval);
971 context->out.free = 1;
973 }
974 }
975 } else {
976 /* call failed, pass internal buffer along */
978 }
979
980 /* Free arguments and return value */
981 zval_ptr_dtor(&ob_args[0]);
982 zval_ptr_dtor(&ob_args[1]);
984
985 } else {
986
987 php_output_context_feed(context, handler->buffer.data, handler->buffer.size, handler->buffer.used, 0);
988
989 if (SUCCESS == handler->func.internal(&handler->opaq, context)) {
990 if (context->out.used) {
992 } else {
994 }
995 } else {
997 }
998 }
1000 OG(running) = NULL;
1001 }
1002
1003 switch (status) {
1005 /* disable this handler */
1007 /* discard any output */
1008 if (context->out.data && context->out.free) {
1009 efree(context->out.data);
1010 }
1011 /* returns handlers buffer */
1012 context->out.data = handler->buffer.data;
1013 context->out.used = handler->buffer.used;
1014 context->out.free = 1;
1015 handler->buffer.data = NULL;
1016 handler->buffer.used = 0;
1017 handler->buffer.size = 0;
1018 break;
1020 /* handler ate all */
1021 php_output_context_reset(context);
1024 /* no more buffered data */
1025 handler->buffer.used = 0;
1027 break;
1028 }
1029
1030 context->op = original_op;
1031 return status;
1032}
1033/* }}} */
1034
1035
1036/* {{{ static void php_output_op(int op, const char *str, size_t len)
1037 * Output op dispatcher, passes input and output handlers output through the output handler stack until it gets written to the SAPI */
1038static inline void php_output_op(int op, const char *str, size_t len)
1039{
1042 int obh_cnt;
1043
1044 if (php_output_lock_error(op)) {
1045 return;
1046 }
1047
1048 php_output_context_init(&context, op);
1049
1050 /*
1051 * broken up for better performance:
1052 * - apply op to the one active handler; note that OG(active) might be popped off the stack on a flush
1053 * - or apply op to the handler stack
1054 */
1055 if (OG(active) && (obh_cnt = zend_stack_count(&OG(handlers)))) {
1056 context.in.data = (char *) str;
1057 context.in.used = len;
1058
1059 if (obh_cnt > 1) {
1061 } else if ((active = zend_stack_top(&OG(handlers))) && (!((*active)->flags & PHP_OUTPUT_HANDLER_DISABLED))) {
1062 php_output_handler_op(*active, &context);
1063 } else {
1064 php_output_context_pass(&context);
1065 }
1066 } else {
1067 context.out.data = (char *) str;
1068 context.out.used = len;
1069 }
1070
1071 if (context.out.data && context.out.used) {
1072 php_output_header();
1073
1074 if (!(OG(flags) & PHP_OUTPUT_DISABLED)) {
1075#if PHP_OUTPUT_DEBUG
1076 fprintf(stderr, "::: sapi_write('%s', %zu)\n", context.out.data, context.out.used);
1077#endif
1078 sapi_module.ub_write(context.out.data, context.out.used);
1079
1081 sapi_flush();
1082 }
1083
1085 }
1086 }
1087 php_output_context_dtor(&context);
1088}
1089/* }}} */
1090
1091/* {{{ static int php_output_stack_apply_op(void *h, void *c)
1092 * Operation callback for the stack apply function */
1093static int php_output_stack_apply_op(void *h, void *c)
1094{
1095 int was_disabled;
1099
1100 if ((was_disabled = (handler->flags & PHP_OUTPUT_HANDLER_DISABLED))) {
1102 } else {
1103 status = php_output_handler_op(handler, context);
1104 }
1105
1106 /*
1107 * handler ate all => break
1108 * handler returned data or failed resp. is disabled => continue
1109 */
1110 switch (status) {
1112 return 1;
1113
1115 /* swap contexts buffers, unless this is the last handler in the stack */
1116 if (handler->level) {
1117 php_output_context_swap(context);
1118 }
1119 return 0;
1120
1122 default:
1123 if (was_disabled) {
1124 /* pass input along, if it's the last handler in the stack */
1125 if (!handler->level) {
1126 php_output_context_pass(context);
1127 }
1128 } else {
1129 /* swap buffers, unless this is the last handler */
1130 if (handler->level) {
1131 php_output_context_swap(context);
1132 }
1133 }
1134 return 0;
1135 }
1136}
1137/* }}} */
1138
1139/* {{{ static int php_output_stack_apply_clean(void *h, void *c)
1140 * Clean callback for the stack apply function */
1141static int php_output_stack_apply_clean(void *h, void *c)
1142{
1145
1146 handler->buffer.used = 0;
1147 php_output_handler_op(handler, context);
1148 php_output_context_reset(context);
1149 return 0;
1150}
1151/* }}} */
1152
1153/* {{{ static int php_output_stack_apply_list(void *h, void *z)
1154 * List callback for the stack apply function */
1155static int php_output_stack_apply_list(void *h, void *z)
1156{
1158 zval *array = (zval *) z;
1159
1160 add_next_index_str(array, zend_string_copy(handler->name));
1161 return 0;
1162}
1163/* }}} */
1164
1165/* {{{ static int php_output_stack_apply_status(void *h, void *z)
1166 * Status callback for the stack apply function */
1167static int php_output_stack_apply_status(void *h, void *z)
1168{
1170 zval arr, *array = (zval *) z;
1171
1172 add_next_index_zval(array, php_output_handler_status(handler, &arr));
1173
1174 return 0;
1175}
1176
1177/* {{{ static zval *php_output_handler_status(php_output_handler *handler, zval *entry)
1178 * Returns an array with the status of the output handler */
1179static inline zval *php_output_handler_status(php_output_handler *handler, zval *entry)
1180{
1181 ZEND_ASSERT(entry != NULL);
1182
1183 array_init(entry);
1184 add_assoc_str(entry, "name", zend_string_copy(handler->name));
1185 add_assoc_long(entry, "type", (zend_long) (handler->flags & 0xf));
1186 add_assoc_long(entry, "flags", (zend_long) handler->flags);
1187 add_assoc_long(entry, "level", (zend_long) handler->level);
1188 add_assoc_long(entry, "chunk_size", (zend_long) handler->size);
1189 add_assoc_long(entry, "buffer_size", (zend_long) handler->buffer.size);
1190 add_assoc_long(entry, "buffer_used", (zend_long) handler->buffer.used);
1191
1192 return entry;
1193}
1194/* }}} */
1195
1196/* {{{ static int php_output_stack_pop(int flags)
1197 * Pops an output handler off the stack */
1198static int php_output_stack_pop(int flags)
1199{
1201 php_output_handler **current, *orphan = OG(active);
1202
1203 if (!orphan) {
1204 if (!(flags & PHP_OUTPUT_POP_SILENT)) {
1205 php_error_docref("ref.outcontrol", E_NOTICE, "Failed to %s buffer. No buffer to %s", (flags&PHP_OUTPUT_POP_DISCARD)?"discard":"send", (flags&PHP_OUTPUT_POP_DISCARD)?"discard":"send");
1206 }
1207 return 0;
1208 } else if (!(flags & PHP_OUTPUT_POP_FORCE) && !(orphan->flags & PHP_OUTPUT_HANDLER_REMOVABLE)) {
1209 if (!(flags & PHP_OUTPUT_POP_SILENT)) {
1210 php_error_docref("ref.outcontrol", E_NOTICE, "Failed to %s buffer of %s (%d)", (flags&PHP_OUTPUT_POP_DISCARD)?"discard":"send", ZSTR_VAL(orphan->name), orphan->level);
1211 }
1212 return 0;
1213 } else {
1214 php_output_context_init(&context, PHP_OUTPUT_HANDLER_FINAL);
1215
1216 /* don't run the output handler if it's disabled */
1217 if (!(orphan->flags & PHP_OUTPUT_HANDLER_DISABLED)) {
1218 /* didn't it start yet? */
1219 if (!(orphan->flags & PHP_OUTPUT_HANDLER_STARTED)) {
1221 }
1222 /* signal that we're cleaning up */
1225 }
1226 php_output_handler_op(orphan, &context);
1227 }
1228
1229 /* pop it off the stack */
1231 if ((current = zend_stack_top(&OG(handlers)))) {
1232 OG(active) = *current;
1233 } else {
1234 OG(active) = NULL;
1235 }
1236
1237 /* pass output along */
1238 if (context.out.data && context.out.used && !(flags & PHP_OUTPUT_POP_DISCARD)) {
1239 php_output_write(context.out.data, context.out.used);
1240 }
1241
1242 /* destroy the handler (after write!) */
1243 php_output_handler_free(&orphan);
1244 php_output_context_dtor(&context);
1245
1246 return 1;
1247 }
1248}
1249/* }}} */
1250
1251/* {{{ static SUCCESS|FAILURE php_output_handler_compat_func(void *ctx, php_output_context *)
1252 * php_output_handler_context_func_t for php_output_handler_func_t output handlers */
1253static zend_result php_output_handler_compat_func(void **handler_context, php_output_context *output_context)
1254{
1256
1257 if (func) {
1258 char *out_str = NULL;
1259 size_t out_len = 0;
1260
1261 func(output_context->in.data, output_context->in.used, &out_str, &out_len, output_context->op);
1262
1263 if (out_str) {
1264 output_context->out.data = out_str;
1265 output_context->out.used = out_len;
1266 output_context->out.free = 1;
1267 } else {
1268 php_output_context_pass(output_context);
1269 }
1270
1271 return SUCCESS;
1272 }
1273 return FAILURE;
1274}
1275/* }}} */
1276
1277/* {{{ static SUCCESS|FAILURE php_output_handler_default_func(void *ctx, php_output_context *)
1278 * Default output handler */
1279static zend_result php_output_handler_default_func(void **handler_context, php_output_context *output_context)
1280{
1281 php_output_context_pass(output_context);
1282 return SUCCESS;
1283}
1284/* }}} */
1285
1286/* {{{ static SUCCESS|FAILURE php_output_handler_devnull_func(void *ctx, php_output_context *)
1287 * Null output handler */
1288static zend_result php_output_handler_devnull_func(void **handler_context, php_output_context *output_context)
1289{
1290 return SUCCESS;
1291}
1292/* }}} */
1293
1294/*
1295 * USERLAND (nearly 1:1 of old output.c)
1296 */
1297
1298/* {{{ Turn on Output Buffering (specifying an optional output handler). */
1300{
1302 zend_long chunk_size = 0;
1304
1305 if (zend_parse_parameters(ZEND_NUM_ARGS(), "|zll", &output_handler, &chunk_size, &flags) == FAILURE) {
1306 RETURN_THROWS();
1307 }
1308
1309 if (chunk_size < 0) {
1310 chunk_size = 0;
1311 }
1312
1313 if (php_output_start_user(output_handler, chunk_size, flags) == FAILURE) {
1314 php_error_docref("ref.outcontrol", E_NOTICE, "Failed to create buffer");
1316 }
1318}
1319/* }}} */
1320
1321/* {{{ Flush (send) contents of the output buffer. The last buffer content is sent to next buffer */
1323{
1325 RETURN_THROWS();
1326 }
1327
1328 if (!OG(active)) {
1329 php_error_docref("ref.outcontrol", E_NOTICE, "Failed to flush buffer. No buffer to flush");
1331 }
1332
1333 if (SUCCESS != php_output_flush()) {
1334 php_error_docref("ref.outcontrol", E_NOTICE, "Failed to flush buffer of %s (%d)", ZSTR_VAL(OG(active)->name), OG(active)->level);
1336 }
1338}
1339/* }}} */
1340
1341/* {{{ Clean (delete) the current output buffer */
1343{
1345 RETURN_THROWS();
1346 }
1347
1348 if (!OG(active)) {
1349 php_error_docref("ref.outcontrol", E_NOTICE, "Failed to delete buffer. No buffer to delete");
1351 }
1352
1353 if (SUCCESS != php_output_clean()) {
1354 php_error_docref("ref.outcontrol", E_NOTICE, "Failed to delete buffer of %s (%d)", ZSTR_VAL(OG(active)->name), OG(active)->level);
1356 }
1358}
1359/* }}} */
1360
1361/* {{{ Flush (send) the output buffer, and delete current output buffer */
1363{
1365 RETURN_THROWS();
1366 }
1367
1368 if (!OG(active)) {
1369 php_error_docref("ref.outcontrol", E_NOTICE, "Failed to delete and flush buffer. No buffer to delete or flush");
1371 }
1372
1374}
1375/* }}} */
1376
1377/* {{{ Clean the output buffer, and delete current output buffer */
1379{
1381 RETURN_THROWS();
1382 }
1383
1384 if (!OG(active)) {
1385 php_error_docref("ref.outcontrol", E_NOTICE, "Failed to delete buffer. No buffer to delete");
1387 }
1388
1390}
1391/* }}} */
1392
1393/* {{{ Get current buffer contents, flush (send) the output buffer, and delete current output buffer */
1395{
1397 RETURN_THROWS();
1398 }
1399
1401 php_error_docref("ref.outcontrol", E_NOTICE, "Failed to delete and flush buffer. No buffer to delete or flush");
1403 }
1404
1405 if (SUCCESS != php_output_end()) {
1406 php_error_docref("ref.outcontrol", E_NOTICE, "Failed to delete buffer of %s (%d)", ZSTR_VAL(OG(active)->name), OG(active)->level);
1407 }
1408}
1409/* }}} */
1410
1411/* {{{ Get current buffer contents and delete current output buffer */
1413{
1415 RETURN_THROWS();
1416 }
1417
1418 if(!OG(active)) {
1420 }
1421
1423 php_error_docref("ref.outcontrol", E_NOTICE, "Failed to delete buffer. No buffer to delete");
1425 }
1426
1427 if (SUCCESS != php_output_discard()) {
1428 php_error_docref("ref.outcontrol", E_NOTICE, "Failed to delete buffer of %s (%d)", ZSTR_VAL(OG(active)->name), OG(active)->level);
1429 }
1430}
1431/* }}} */
1432
1433/* {{{ Return the contents of the output buffer */
1435{
1437 RETURN_THROWS();
1438 }
1439
1442 }
1443}
1444/* }}} */
1445
1446/* {{{ Return the nesting level of the output buffer */
1455/* }}} */
1456
1457/* {{{ Return the length of the output buffer */
1459{
1461 RETURN_THROWS();
1462 }
1463
1466 }
1467}
1468/* }}} */
1469
1470/* {{{ List all output_buffers in an array */
1472{
1474 RETURN_THROWS();
1475 }
1476
1478
1479 if (!OG(active)) {
1480 return;
1481 }
1482
1484}
1485/* }}} */
1486
1487/* {{{ Return the status of the active or all output buffers */
1489{
1490 bool full_status = 0;
1491
1492 if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &full_status) == FAILURE) {
1493 RETURN_THROWS();
1494 }
1495
1496 if (!OG(active)) {
1498 return;
1499 }
1500
1501 if (full_status) {
1504 } else {
1505 php_output_handler_status(OG(active), return_value);
1506 }
1507}
1508/* }}} */
1509
1510/* {{{ Turn implicit flush on/off and is equivalent to calling flush() after every output call */
1512{
1513 zend_long flag = 1;
1514
1515 if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &flag) == FAILURE) {
1516 RETURN_THROWS();
1517 }
1518
1520}
1521/* }}} */
1522
1523/* {{{ Reset(clear) URL rewriter values */
1525{
1527 RETURN_THROWS();
1528 }
1529
1532 } else {
1534 }
1535}
1536/* }}} */
1537
1538/* {{{ Add URL rewriter values */
1540{
1541 char *name, *value;
1542 size_t name_len, value_len;
1543
1544 if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &name_len, &value, &value_len) == FAILURE) {
1545 RETURN_THROWS();
1546 }
1547
1548 if (php_url_scanner_add_var(name, name_len, value, value_len, 1) == SUCCESS) {
1550 } else {
1552 }
1553}
1554/* }}} */
SAPI_API sapi_module_struct sapi_module
Definition SAPI.c:65
SAPI_API int sapi_flush(void)
Definition SAPI.c:1001
#define SG(v)
Definition SAPI.h:160
size_t len
Definition apprentice.c:174
fprintf($stream, string $format, mixed ... $values)
ob_get_status(bool $full_status=false)
fwrite($stream, string $data, ?int $length=null)
output_add_rewrite_var(string $name, string $value)
count(Countable|array $value, int $mode=COUNT_NORMAL)
ob_implicit_flush(bool $enable=true)
fflush($stream)
ob_start($callback=null, int $chunk_size=0, int $flags=PHP_OUTPUT_HANDLER_STDFLAGS)
output_reset_rewrite_vars()
headers_sent(&$filename=null, &$line=null)
DNS_STATUS status
Definition dns_win32.c:49
error($message)
Definition ext_skel.php:22
zend_ffi_type * type
Definition ffi.c:3812
zval * zv
Definition ffi.c:3975
new_type size
Definition ffi.c:4365
memcpy(ptr1, ptr2, size)
zval * arg
Definition ffi.c:3975
memset(ptr, 0, type->size)
HashTable * ht
Definition ffi.c:4838
zend_ffi_ctype_name_buf buf
Definition ffi.c:4685
#define NULL
Definition gdcache.h:45
#define SUCCESS
Definition hash_sha3.c:261
PHPAPI bool php_header(void)
Definition head.c:70
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
Definition main.c:1173
#define G(L)
Definition minilua.c:489
PHPAPI zend_result php_output_handler_hook(php_output_handler_hook_t type, void *arg)
Definition output.c:669
PHPAPI void php_output_handler_dtor(php_output_handler *handler)
Definition output.c:698
PHPAPI void php_output_end_all(void)
Definition output.c:322
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 int php_output_activate(void)
Definition output.c:159
PHPAPI zend_result php_output_start_devnull(void)
Definition output.c:413
PHPAPI bool php_output_handler_started(const char *name, size_t name_len)
Definition output.c:561
PHPAPI void php_output_flush_all(void)
Definition output.c:273
PHPAPI void php_output_set_status(int status)
Definition output.c:206
PHPAPI zend_result php_output_start_user(zval *output_handler, size_t chunk_size, int flags)
Definition output.c:428
PHPAPI php_output_handler * php_output_handler_create_user(zval *output_handler, size_t chunk_size, int flags)
Definition output.c:463
#define PHP_OUTPUT_USER_SUCCESS(retval)
PHPAPI zend_result php_output_get_length(zval *p)
Definition output.c:376
PHPAPI void php_output_discard_all(void)
Definition output.c:341
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 const char * php_output_get_start_filename(void)
Definition output.c:743
PHPAPI size_t php_output_write_unbuffered(const char *str, size_t len)
Definition output.c:226
PHPAPI void php_output_handler_free(php_output_handler **h)
Definition output.c:719
PHPAPI void php_output_shutdown(void)
Definition output.c:148
PHPAPI zend_result php_output_discard(void)
Definition output.c:330
PHPAPI size_t php_output_write(const char *str, size_t len)
Definition output.c:237
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 php_output_handler_alias_ctor_t php_output_handler_alias(const char *name, size_t name_len)
Definition output.c:644
PHPAPI void php_output_set_implicit_flush(int flush)
Definition output.c:731
PHPAPI zend_result php_output_end(void)
Definition output.c:311
PHPAPI php_output_handler * php_output_get_active_handler(void)
Definition output.c:390
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_start_internal(const char *name, size_t name_len, php_output_handler_func_t output_handler, size_t chunk_size, int flags)
Definition output.c:447
PHPAPI zend_result php_output_clean(void)
Definition output.c:283
PHPAPI zend_result php_output_start_default(void)
Definition output.c:398
PHPAPI void php_output_clean_all(void)
Definition output.c:299
PHPAPI zend_result php_output_handler_start(php_output_handler *handler)
Definition output.c:532
PHPAPI int php_output_get_start_lineno(void)
Definition output.c:751
PHPAPI int php_output_get_status(void)
Definition output.c:214
PHPAPI void php_output_startup(void)
Definition output.c:136
PHPAPI void php_output_handler_set_context(php_output_handler *handler, void *opaq, void(*dtor)(void *))
Definition output.c:520
PHPAPI zend_result php_output_get_contents(zval *p)
Definition output.c:359
PHPAPI zend_result php_output_flush(void)
Definition output.c:252
PHPAPI zend_result php_output_handler_reverse_conflict_register(const char *name, size_t name_len, php_output_handler_conflict_check_t check_func)
Definition output.c:615
PHPAPI void php_output_deactivate(void)
Definition output.c:176
#define PHP_FUNCTION
Definition php.h:364
#define PHPAPI
Definition php.h:71
php_output_handler * active
Definition php_output.h:140
#define PHP_OUTPUT_HANDLER_DISABLED
Definition php_output.h:43
@ PHP_OUTPUT_HANDLER_FAILURE
Definition php_output.h:50
@ PHP_OUTPUT_HANDLER_SUCCESS
Definition php_output.h:51
@ PHP_OUTPUT_HANDLER_NO_DATA
Definition php_output.h:52
enum _php_output_handler_status_t php_output_handler_status_t
zend_string * output_start_filename
Definition php_output.h:142
#define PHP_OUTPUT_POP_FORCE
Definition php_output.h:57
#define PHP_OUTPUT_HANDLER_PROCESSED
Definition php_output.h:44
#define PHP_OUTPUT_HANDLER_REMOVABLE
Definition php_output.h:38
#define PHP_OUTPUT_HANDLER_WRITE
Definition php_output.h:23
#define PHP_OUTPUT_HANDLER_INITBUF_SIZE(s)
Definition php_output.h:83
#define PHP_OUTPUT_HANDLER_FLUSHABLE
Definition php_output.h:37
struct _php_output_handler php_output_handler
#define PHP_OUTPUT_DISABLED
Definition php_output.h:63
php_output_handler * running
Definition php_output.h:141
enum _php_output_handler_hook_t php_output_handler_hook_t
#define PHP_OUTPUT_WRITTEN
Definition php_output.h:64
#define PHP_OUTPUT_IMPLICITFLUSH
Definition php_output.h:62
const char php_output_devnull_handler_name[sizeof("null output handler")]
#define PHP_OUTPUT_HANDLER_FLUSH
Definition php_output.h:26
#define PHP_OUTPUT_SENT
Definition php_output.h:65
#define PHP_OUTPUT_POP_TRY
Definition php_output.h:56
#define PHP_OUTPUT_HANDLER_STDFLAGS
Definition php_output.h:39
@ PHP_OUTPUT_HANDLER_HOOK_GET_LEVEL
Definition php_output.h:76
@ PHP_OUTPUT_HANDLER_HOOK_DISABLE
Definition php_output.h:78
@ PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS
Definition php_output.h:75
@ PHP_OUTPUT_HANDLER_HOOK_GET_OPAQ
Definition php_output.h:74
@ PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE
Definition php_output.h:77
#define PHP_OUTPUT_HANDLER_USER
Definition php_output.h:33
#define PHP_OUTPUT_HANDLER_CLEAN
Definition php_output.h:25
#define PHP_OUTPUT_LOCKED
Definition php_output.h:68
#define PHP_OUTPUT_ACTIVE
Definition php_output.h:67
struct _php_output_buffer php_output_buffer
#define PHP_OUTPUT_HANDLER_INTERNAL
Definition php_output.h:32
int output_start_lineno
Definition php_output.h:143
zend_stack handlers
Definition php_output.h:139
#define PHP_OUTPUT_POP_DISCARD
Definition php_output.h:58
#define PHP_OUTPUT_HANDLER_FINAL
Definition php_output.h:27
#define PHP_OUTPUT_HANDLER_DEFAULT_SIZE
Definition php_output.h:89
struct _php_output_handler_user_func_t php_output_handler_user_func_t
#define PHP_OUTPUT_HANDLER_CLEANABLE
Definition php_output.h:36
#define PHP_OUTPUT_ACTIVATED
Definition php_output.h:70
#define PHP_OUTPUT_HANDLER_STARTED
Definition php_output.h:42
struct _php_output_context php_output_context
zend_result(* php_output_handler_context_func_t)(void **handler_context, php_output_context *output_context)
Definition php_output.h:108
#define OG(v)
#define PHP_OUTPUT_POP_SILENT
Definition php_output.h:59
struct _php_output_handler *(* php_output_handler_alias_ctor_t)(const char *handler_name, size_t handler_name_len, size_t chunk_size, int flags)
Definition php_output.h:114
zend_result(* php_output_handler_conflict_check_t)(const char *handler_name, size_t handler_name_len)
Definition php_output.h:112
#define PHP_OUTPUT_HANDLER_ABILITY_FLAGS(bitmask)
Definition php_output.h:46
void(* php_output_handler_func_t)(char *output, size_t output_len, char **handled_output, size_t *handled_output_len, int mode)
Definition php_output.h:106
#define PHP_OUTPUT_HANDLER_START
Definition php_output.h:24
char * output_handler
Definition php_zlib.h:57
zend_constant * data
zval * current
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_fcall_info_cache fcc
Definition php_output.h:118
zend_string * name
Definition php_output.h:123
Definition file.h:177
Definition dce.c:49
PHPAPI zend_result php_url_scanner_add_var(const char *name, size_t name_len, const char *value, size_t value_len, bool encode)
PHPAPI zend_result php_url_scanner_reset_vars(void)
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format,...)
Definition zend.c:1703
ZEND_API zend_result zend_fcall_info_init(zval *callable, uint32_t check_flags, zend_fcall_info *fci, zend_fcall_info_cache *fcc, zend_string **callable_name, char **error)
Definition zend_API.c:4310
ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec,...)
Definition zend_API.c:1300
ZEND_API zend_result add_next_index_str(zval *arg, zend_string *str)
Definition zend_API.c:2177
#define ZEND_NUM_ARGS()
Definition zend_API.h:530
#define RETURN_FALSE
Definition zend_API.h:1058
#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)
Definition zend_API.h:272
#define ZEND_DECLARE_MODULE_GLOBALS(module_name)
Definition zend_API.h:268
#define zend_parse_parameters_none()
Definition zend_API.h:353
#define RETURN_LONG(l)
Definition zend_API.h:1037
#define RETURN_BOOL(b)
Definition zend_API.h:1035
#define RETURN_THROWS()
Definition zend_API.h:1060
#define ZVAL_STRINGL(z, s, l)
Definition zend_API.h:952
ZEND_API zend_result zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache)
#define RETURN_TRUE
Definition zend_API.h:1059
#define array_init(arg)
Definition zend_API.h:537
#define ZVAL_EMPTY_STRING(z)
Definition zend_API.h:961
#define safe_erealloc(ptr, nmemb, size, offset)
Definition zend_alloc.h:161
#define estrndup(s, length)
Definition zend_alloc.h:165
#define ecalloc(nmemb, size)
Definition zend_alloc.h:158
#define efree(ptr)
Definition zend_alloc.h:155
#define emalloc(size)
Definition zend_alloc.h:151
struct _zval_struct zval
zend_string_release_ex(func->internal_function.function_name, 0)
execute_data func
ZEND_API bool zend_is_compiling(void)
ZEND_API int zend_get_compiled_lineno(void)
ZEND_API zend_string * zend_get_compiled_filename(void)
#define E_NOTICE
Definition zend_errors.h:26
#define E_ERROR
Definition zend_errors.h:23
#define E_WARNING
Definition zend_errors.h:24
ZEND_API uint32_t zend_get_executed_lineno(void)
ZEND_API zend_string * zend_get_executed_filename_ex(void)
ZEND_API bool zend_is_executing(void)
#define EG(v)
ZEND_API void ZEND_FASTCALL zend_hash_destroy(HashTable *ht)
Definition zend_hash.c:1727
#define zend_hash_init(ht, nSize, pHashFunction, pDestructor, persistent)
Definition zend_hash.h:108
#define ZEND_HASH_PACKED_FOREACH_PTR(ht, _ptr)
Definition zend_hash.h:1487
#define ZEND_HASH_FOREACH_END()
Definition zend_hash.h:1086
int32_t zend_long
Definition zend_long.h:42
struct _zend_string zend_string
#define convert_to_string(op)
#define ZEND_FALLTHROUGH
#define ZEND_ASSERT(c)
#define ZEND_STRL(str)
#define MAX(a, b)
ZEND_API int zend_stack_push(zend_stack *stack, const void *element)
Definition zend_stack.c:33
ZEND_API void * zend_stack_base(const zend_stack *stack)
Definition zend_stack.c:87
ZEND_API void * zend_stack_top(const zend_stack *stack)
Definition zend_stack.c:45
ZEND_API int zend_stack_count(const zend_stack *stack)
Definition zend_stack.c:93
ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, zend_stack_apply_direction type, int(*apply_function)(void *element, void *arg), void *arg)
Definition zend_stack.c:122
ZEND_API void zend_stack_destroy(zend_stack *stack)
Definition zend_stack.c:78
ZEND_API void zend_stack_init(zend_stack *stack, int size)
Definition zend_stack.c:25
ZEND_API void zend_stack_del_top(zend_stack *stack)
Definition zend_stack.c:55
@ ZEND_STACK_APPLY_BOTTOMUP
Definition zend_stack.h:35
@ ZEND_STACK_APPLY_TOPDOWN
Definition zend_stack.h:34
ZEND_API zend_string_init_interned_func_t zend_string_init_interned
Definition zend_string.c:31
#define ZSTR_VAL(zstr)
Definition zend_string.h:68
#define ZSTR_LEN(zstr)
Definition zend_string.h:69
#define Z_TYPE_P(zval_p)
Definition zend_types.h:660
#define IS_TRUE
Definition zend_types.h:603
#define IS_FALSE
Definition zend_types.h:602
#define Z_STRVAL_P(zval_p)
Definition zend_types.h:975
#define ZVAL_NULL(z)
#define ZVAL_LONG(z, l)
#define IS_STRING
Definition zend_types.h:606
struct _zend_array HashTable
Definition zend_types.h:386
#define Z_PTR_P(zval_p)
#define Z_STRLEN_P(zval_p)
Definition zend_types.h:978
#define IS_NULL
Definition zend_types.h:601
#define Z_STRVAL(zval)
Definition zend_types.h:974
@ FAILURE
Definition zend_types.h:61
#define Z_STRLEN(zval)
Definition zend_types.h:977
#define ZVAL_COPY(z, v)
ZEND_RESULT_CODE zend_result
Definition zend_types.h:64
#define Z_TYPE(zval)
Definition zend_types.h:659
ZEND_API void zval_ptr_dtor(zval *zval_ptr)
zval retval
zval * return_value
zend_string * name
fbc internal_function handler(call, ret)
value