File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / main / php_output.h
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue May 29 12:34:35 2012 UTC (12 years, 1 month ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_17p0, HEAD
php 5.4.3+patches

    1: /*
    2:    +----------------------------------------------------------------------+
    3:    | PHP Version 5                                                        |
    4:    +----------------------------------------------------------------------+
    5:    | Copyright (c) 1997-2012 The PHP Group                                |
    6:    +----------------------------------------------------------------------+
    7:    | This source file is subject to version 3.01 of the PHP license,      |
    8:    | that is bundled with this package in the file LICENSE, and is        |
    9:    | available through the world-wide-web at the following url:           |
   10:    | http://www.php.net/license/3_01.txt                                  |
   11:    | If you did not receive a copy of the PHP license and are unable to   |
   12:    | obtain it through the world-wide-web, please send a note to          |
   13:    | license@php.net so we can mail you a copy immediately.               |
   14:    +----------------------------------------------------------------------+
   15:    | Author: Michael Wallner <mike@php.net>                               |
   16:    +----------------------------------------------------------------------+
   17: */
   18: 
   19: /* $Id: php_output.h,v 1.1.1.2 2012/05/29 12:34:35 misho Exp $ */
   20: 
   21: #ifndef PHP_OUTPUT_H
   22: #define PHP_OUTPUT_H
   23: 
   24: #define PHP_OUTPUT_NEWAPI 1
   25: 
   26: /* handler ops */
   27: #define PHP_OUTPUT_HANDLER_WRITE	0x00	/* standard passthru */
   28: #define PHP_OUTPUT_HANDLER_START	0x01	/* start */
   29: #define PHP_OUTPUT_HANDLER_CLEAN	0x02	/* restart */
   30: #define PHP_OUTPUT_HANDLER_FLUSH	0x04	/* pass along as much as possible */
   31: #define PHP_OUTPUT_HANDLER_FINAL	0x08	/* finalize */
   32: #define PHP_OUTPUT_HANDLER_CONT		PHP_OUTPUT_HANDLER_WRITE
   33: #define PHP_OUTPUT_HANDLER_END		PHP_OUTPUT_HANDLER_FINAL
   34: 
   35: /* handler types */
   36: #define PHP_OUTPUT_HANDLER_INTERNAL		0x0000
   37: #define PHP_OUTPUT_HANDLER_USER			0x0001
   38: 
   39: /* handler ability flags */
   40: #define PHP_OUTPUT_HANDLER_CLEANABLE	0x0010
   41: #define PHP_OUTPUT_HANDLER_FLUSHABLE	0x0020
   42: #define PHP_OUTPUT_HANDLER_REMOVABLE	0x0040
   43: #define PHP_OUTPUT_HANDLER_STDFLAGS		0x0070
   44: 
   45: /* handler status flags */
   46: #define PHP_OUTPUT_HANDLER_STARTED		0x1000
   47: #define PHP_OUTPUT_HANDLER_DISABLED		0x2000
   48: 
   49: /* handler op return values */
   50: typedef enum _php_output_handler_status_t {
   51: 	PHP_OUTPUT_HANDLER_FAILURE,
   52: 	PHP_OUTPUT_HANDLER_SUCCESS,
   53: 	PHP_OUTPUT_HANDLER_NO_DATA
   54: } php_output_handler_status_t;
   55: 
   56: /* php_output_stack_pop() flags */
   57: #define PHP_OUTPUT_POP_TRY			0x000
   58: #define PHP_OUTPUT_POP_FORCE		0x001
   59: #define PHP_OUTPUT_POP_DISCARD		0x010
   60: #define PHP_OUTPUT_POP_SILENT		0x100
   61: 
   62: /* real global flags */
   63: #define PHP_OUTPUT_IMPLICITFLUSH		0x01
   64: #define PHP_OUTPUT_DISABLED				0x02
   65: #define PHP_OUTPUT_WRITTEN				0x04
   66: #define PHP_OUTPUT_SENT					0x08
   67: /* supplementary flags for php_output_get_status() */
   68: #define PHP_OUTPUT_ACTIVE				0x10
   69: #define PHP_OUTPUT_LOCKED				0x20
   70: /* output layer is ready to use */
   71: #define PHP_OUTPUT_ACTIVATED		0x100000
   72: 
   73: /* handler hooks */
   74: typedef enum _php_output_handler_hook_t {
   75: 	PHP_OUTPUT_HANDLER_HOOK_GET_OPAQ,
   76: 	PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS,
   77: 	PHP_OUTPUT_HANDLER_HOOK_GET_LEVEL,
   78: 	PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE,
   79: 	PHP_OUTPUT_HANDLER_HOOK_DISABLE,
   80: 	/* unused */
   81: 	PHP_OUTPUT_HANDLER_HOOK_LAST
   82: } php_output_handler_hook_t;
   83: 
   84: #define PHP_OUTPUT_HANDLER_INITBUF_SIZE(s) \
   85: ( (s) ? \
   86: 	(s) + PHP_OUTPUT_HANDLER_ALIGNTO_SIZE - ((s) % (PHP_OUTPUT_HANDLER_ALIGNTO_SIZE)) : \
   87: 	PHP_OUTPUT_HANDLER_DEFAULT_SIZE \
   88: )
   89: #define PHP_OUTPUT_HANDLER_ALIGNTO_SIZE		0x1000
   90: #define PHP_OUTPUT_HANDLER_DEFAULT_SIZE		0x4000
   91: 
   92: typedef struct _php_output_buffer {
   93: 	char *data;
   94: 	size_t size;
   95: 	size_t used;
   96: 	uint free:1;
   97: 	uint _res:31;
   98: } php_output_buffer;
   99: 
  100: typedef struct _php_output_context {
  101: 	int op;
  102: 	php_output_buffer in;
  103: 	php_output_buffer out;
  104: #ifdef ZTS
  105: 	void ***tsrm_ls;
  106: #endif
  107: } php_output_context;
  108: 
  109: #define PHP_OUTPUT_TSRMLS(ctx) TSRMLS_FETCH_FROM_CTX((ctx)->tsrm_ls)
  110: 
  111: /* old-style, stateless callback */
  112: typedef void (*php_output_handler_func_t)(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC);
  113: /* new-style, opaque context callback */
  114: typedef int (*php_output_handler_context_func_t)(void **handler_context, php_output_context *output_context);
  115: /* output handler context dtor */
  116: typedef void (*php_output_handler_context_dtor_t)(void *opaq TSRMLS_DC);
  117: /* conflict check callback */
  118: typedef int (*php_output_handler_conflict_check_t)(const char *handler_name, size_t handler_name_len TSRMLS_DC);
  119: /* ctor for aliases */
  120: typedef 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 TSRMLS_DC);
  121: 
  122: typedef struct _php_output_handler_user_func_t {
  123: 	zend_fcall_info fci;
  124: 	zend_fcall_info_cache fcc;
  125: 	zval *zoh;
  126: } php_output_handler_user_func_t;
  127: 
  128: typedef struct _php_output_handler {
  129: 	char *name;
  130: 	size_t name_len;
  131: 	int flags;
  132: 	int level;
  133: 	size_t size;
  134: 	php_output_buffer buffer;
  135: 	
  136: 	void *opaq;
  137: 	void (*dtor)(void *opaq TSRMLS_DC);
  138: 	
  139: 	union {
  140: 		php_output_handler_user_func_t *user;
  141: 		php_output_handler_context_func_t internal;
  142: 	} func;
  143: } php_output_handler;
  144: 
  145: ZEND_BEGIN_MODULE_GLOBALS(output)
  146: 	int flags;
  147: 	zend_stack handlers;
  148: 	php_output_handler *active;
  149: 	php_output_handler *running;
  150: 	const char *output_start_filename;
  151: 	int output_start_lineno;
  152: ZEND_END_MODULE_GLOBALS(output)
  153: 
  154: /* there should not be a need to use OG() from outside of output.c */
  155: #ifdef ZTS
  156: # define OG(v) TSRMG(output_globals_id, zend_output_globals *, v)
  157: #else
  158: # define OG(v) (output_globals.v)
  159: #endif
  160: 
  161: /* convenience macros */
  162: #define PHPWRITE(str, str_len)		php_output_write((str), (str_len) TSRMLS_CC)
  163: #define PHPWRITE_H(str, str_len)	php_output_write_unbuffered((str), (str_len) TSRMLS_CC)
  164: 
  165: #define PUTC(c)						(php_output_write(&(c), 1 TSRMLS_CC), (c))
  166: #define PUTC_H(c)					(php_output_write_unbuffered(&(c), 1 TSRMLS_CC), (c))
  167: 
  168: #define PUTS(str)					do {				\
  169: 	const char *__str = (str);							\
  170: 	php_output_write(__str, strlen(__str) TSRMLS_CC);	\
  171: } while (0)
  172: #define PUTS_H(str)					do {							\
  173: 	const char *__str = (str);										\
  174: 	php_output_write_unbuffered(__str, strlen(__str) TSRMLS_CC);	\
  175: } while (0)
  176: 
  177: 
  178: BEGIN_EXTERN_C()
  179: 
  180: extern const char php_output_default_handler_name[sizeof("default output handler")];
  181: extern const char php_output_devnull_handler_name[sizeof("null output handler")];
  182: 
  183: #define php_output_tearup() \
  184: 	php_output_startup(); \
  185: 	php_output_activate(TSRMLS_C)
  186: #define php_output_teardown() \
  187: 	php_output_end_all(TSRMLS_C); \
  188: 	php_output_deactivate(TSRMLS_C); \
  189: 	php_output_shutdown()
  190: 
  191: /* MINIT */
  192: PHPAPI void php_output_startup(void);
  193: /* MSHUTDOWN */
  194: PHPAPI void php_output_shutdown(void);
  195: 
  196: PHPAPI void php_output_register_constants(TSRMLS_D);
  197: 
  198: /* RINIT */
  199: PHPAPI int php_output_activate(TSRMLS_D);
  200: /* RSHUTDOWN */
  201: PHPAPI void php_output_deactivate(TSRMLS_D);
  202: 
  203: PHPAPI void php_output_set_status(int status TSRMLS_DC);
  204: PHPAPI int php_output_get_status(TSRMLS_D);
  205: PHPAPI void php_output_set_implicit_flush(int flush TSRMLS_DC);
  206: PHPAPI const char *php_output_get_start_filename(TSRMLS_D);
  207: PHPAPI int php_output_get_start_lineno(TSRMLS_D);
  208: 
  209: PHPAPI int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC);
  210: PHPAPI int php_output_write(const char *str, size_t len TSRMLS_DC);
  211: 
  212: PHPAPI int php_output_flush(TSRMLS_D);
  213: PHPAPI void php_output_flush_all(TSRMLS_D);
  214: PHPAPI int php_output_clean(TSRMLS_D);
  215: PHPAPI void php_output_clean_all(TSRMLS_D);
  216: PHPAPI int php_output_end(TSRMLS_D);
  217: PHPAPI void php_output_end_all(TSRMLS_D);
  218: PHPAPI int php_output_discard(TSRMLS_D);
  219: PHPAPI void php_output_discard_all(TSRMLS_D);
  220: 
  221: PHPAPI int php_output_get_contents(zval *p TSRMLS_DC);
  222: PHPAPI int php_output_get_length(zval *p TSRMLS_DC);
  223: PHPAPI int php_output_get_level(TSRMLS_D);
  224: PHPAPI php_output_handler* php_output_get_active_handler(TSRMLS_D);
  225: 
  226: PHPAPI int php_output_start_default(TSRMLS_D);
  227: PHPAPI int php_output_start_devnull(TSRMLS_D);
  228: 
  229: PHPAPI int php_output_start_user(zval *output_handler, size_t chunk_size, int flags TSRMLS_DC);
  230: PHPAPI int php_output_start_internal(const char *name, size_t name_len, php_output_handler_func_t output_handler, size_t chunk_size, int flags TSRMLS_DC);
  231: 
  232: PHPAPI php_output_handler *php_output_handler_create_user(zval *handler, size_t chunk_size, int flags TSRMLS_DC);
  233: PHPAPI php_output_handler *php_output_handler_create_internal(const char *name, size_t name_len, php_output_handler_context_func_t handler, size_t chunk_size, int flags TSRMLS_DC);
  234: 
  235: PHPAPI void php_output_handler_set_context(php_output_handler *handler, void *opaq, void (*dtor)(void* TSRMLS_DC) TSRMLS_DC);
  236: PHPAPI int php_output_handler_start(php_output_handler *handler TSRMLS_DC);
  237: PHPAPI int php_output_handler_started(const char *name, size_t name_len TSRMLS_DC);
  238: PHPAPI int php_output_handler_hook(php_output_handler_hook_t type, void *arg TSRMLS_DC);
  239: PHPAPI void php_output_handler_dtor(php_output_handler *handler TSRMLS_DC);
  240: PHPAPI void php_output_handler_free(php_output_handler **handler TSRMLS_DC);
  241: 
  242: PHPAPI int php_output_handler_conflict(const char *handler_new, size_t handler_new_len, const char *handler_set, size_t handler_set_len TSRMLS_DC);
  243: PHPAPI int php_output_handler_conflict_register(const char *handler_name, size_t handler_name_len, php_output_handler_conflict_check_t check_func TSRMLS_DC);
  244: PHPAPI int php_output_handler_reverse_conflict_register(const char *handler_name, size_t handler_name_len, php_output_handler_conflict_check_t check_func TSRMLS_DC);
  245: 
  246: PHPAPI php_output_handler_alias_ctor_t *php_output_handler_alias(const char *handler_name, size_t handler_name_len TSRMLS_DC);
  247: PHPAPI int php_output_handler_alias_register(const char *handler_name, size_t handler_name_len, php_output_handler_alias_ctor_t func TSRMLS_DC);
  248: 
  249: END_EXTERN_C()
  250: 
  251: 
  252: PHP_FUNCTION(ob_start);
  253: PHP_FUNCTION(ob_flush);
  254: PHP_FUNCTION(ob_clean);
  255: PHP_FUNCTION(ob_end_flush);
  256: PHP_FUNCTION(ob_end_clean);
  257: PHP_FUNCTION(ob_get_flush);
  258: PHP_FUNCTION(ob_get_clean);
  259: PHP_FUNCTION(ob_get_contents);
  260: PHP_FUNCTION(ob_get_length);
  261: PHP_FUNCTION(ob_get_level);
  262: PHP_FUNCTION(ob_get_status);
  263: PHP_FUNCTION(ob_implicit_flush);
  264: PHP_FUNCTION(ob_list_handlers);
  265: 
  266: PHP_FUNCTION(output_add_rewrite_var);
  267: PHP_FUNCTION(output_reset_rewrite_vars);
  268: 
  269: #endif
  270: 
  271: /*
  272:  * Local variables:
  273:  * tab-width: 4
  274:  * c-basic-offset: 4
  275:  * End:
  276:  * vim600: sw=4 ts=4 fdm=marker
  277:  * vim<600: sw=4 ts=4
  278:  */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>