Updates to Tomato RAF including NGINX && PHP
[tomato.git] / release / src / router / php / ext / standard / php_var.h
blob35343b3d5d06800886ee3be4b75c605f42261f63
1 /*
2 +----------------------------------------------------------------------+
3 | PHP Version 5 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1997-2013 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: Jani Lehtimäki <jkl@njet.net> |
16 +----------------------------------------------------------------------+
19 /* $Id$ */
21 #ifndef PHP_VAR_H
22 #define PHP_VAR_H
24 #include "ext/standard/basic_functions.h"
25 #include "ext/standard/php_smart_str_public.h"
27 PHP_FUNCTION(var_dump);
28 PHP_FUNCTION(var_export);
29 PHP_FUNCTION(debug_zval_dump);
30 PHP_FUNCTION(serialize);
31 PHP_FUNCTION(unserialize);
32 PHP_FUNCTION(memory_get_usage);
33 PHP_FUNCTION(memory_get_peak_usage);
35 PHPAPI void php_var_dump(zval **struc, int level TSRMLS_DC);
36 PHPAPI void php_var_export(zval **struc, int level TSRMLS_DC);
37 PHPAPI void php_var_export_ex(zval **struc, int level, smart_str *buf TSRMLS_DC);
39 PHPAPI void php_debug_zval_dump(zval **struc, int level TSRMLS_DC);
41 typedef HashTable* php_serialize_data_t;
43 struct php_unserialize_data {
44 void *first;
45 void *last;
46 void *first_dtor;
47 void *last_dtor;
50 typedef struct php_unserialize_data* php_unserialize_data_t;
52 PHPAPI void php_var_serialize(smart_str *buf, zval **struc, php_serialize_data_t *var_hash TSRMLS_DC);
53 PHPAPI int php_var_unserialize(zval **rval, const unsigned char **p, const unsigned char *max, php_unserialize_data_t *var_hash TSRMLS_DC);
55 #define PHP_VAR_SERIALIZE_INIT(var_hash_ptr) \
56 do { \
57 /* fprintf(stderr, "SERIALIZE_INIT == lock: %u, level: %u\n", BG(serialize_lock), BG(serialize).level); */ \
58 if (BG(serialize_lock) || !BG(serialize).level) { \
59 ALLOC_HASHTABLE(var_hash_ptr); \
60 zend_hash_init((var_hash_ptr), 10, NULL, NULL, 0); \
61 if (!BG(serialize_lock)) { \
62 BG(serialize).var_hash = (void *)(var_hash_ptr); \
63 BG(serialize).level = 1; \
64 } \
65 } else { \
66 (var_hash_ptr) = (php_serialize_data_t)BG(serialize).var_hash; \
67 ++BG(serialize).level; \
68 } \
69 } while(0)
71 #define PHP_VAR_SERIALIZE_DESTROY(var_hash_ptr) \
72 do { \
73 /* fprintf(stderr, "SERIALIZE_DESTROY == lock: %u, level: %u\n", BG(serialize_lock), BG(serialize).level); */ \
74 if (BG(serialize_lock) || !BG(serialize).level) { \
75 zend_hash_destroy((var_hash_ptr)); \
76 FREE_HASHTABLE(var_hash_ptr); \
77 } else { \
78 if (!--BG(serialize).level) { \
79 zend_hash_destroy((php_serialize_data_t)BG(serialize).var_hash); \
80 FREE_HASHTABLE((php_serialize_data_t)BG(serialize).var_hash); \
81 BG(serialize).var_hash = NULL; \
82 } \
83 } \
84 } while (0)
86 #define PHP_VAR_UNSERIALIZE_INIT(var_hash_ptr) \
87 do { \
88 /* fprintf(stderr, "UNSERIALIZE_INIT == lock: %u, level: %u\n", BG(serialize_lock), BG(unserialize).level); */ \
89 if (BG(serialize_lock) || !BG(unserialize).level) { \
90 (var_hash_ptr) = (php_unserialize_data_t)ecalloc(1, sizeof(struct php_unserialize_data)); \
91 if (!BG(serialize_lock)) { \
92 BG(unserialize).var_hash = (void *)(var_hash_ptr); \
93 BG(unserialize).level = 1; \
94 } \
95 } else { \
96 (var_hash_ptr) = (php_unserialize_data_t)BG(unserialize).var_hash; \
97 ++BG(unserialize).level; \
98 } \
99 } while (0)
101 #define PHP_VAR_UNSERIALIZE_DESTROY(var_hash_ptr) \
102 do { \
103 /* fprintf(stderr, "UNSERIALIZE_DESTROY == lock: %u, level: %u\n", BG(serialize_lock), BG(unserialize).level); */ \
104 if (BG(serialize_lock) || !BG(unserialize).level) { \
105 var_destroy(&(var_hash_ptr)); \
106 efree(var_hash_ptr); \
107 } else { \
108 if (!--BG(unserialize).level) { \
109 var_destroy(&(var_hash_ptr)); \
110 efree((var_hash_ptr)); \
111 BG(unserialize).var_hash = NULL; \
114 } while (0)
116 PHPAPI void var_replace(php_unserialize_data_t *var_hash, zval *ozval, zval **nzval);
117 PHPAPI void var_push_dtor(php_unserialize_data_t *var_hash, zval **val);
118 PHPAPI void var_destroy(php_unserialize_data_t *var_hash);
120 #define PHP_VAR_UNSERIALIZE_ZVAL_CHANGED(var_hash, ozval, nzval) \
121 var_replace((var_hash), (ozval), &(nzval))
123 PHPAPI zend_class_entry *php_create_empty_class(char *class_name, int len);
125 static inline int php_varname_check(char *name, int name_len, zend_bool silent TSRMLS_DC) /* {{{ */
127 if (name_len == sizeof("GLOBALS") - 1 && !memcmp(name, "GLOBALS", sizeof("GLOBALS") - 1)) {
128 if (!silent) {
129 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempted GLOBALS variable overwrite");
131 return FAILURE;
132 } else if (name[0] == '_' &&
134 (name_len == sizeof("_GET") - 1 && !memcmp(name, "_GET", sizeof("_GET") - 1)) ||
135 (name_len == sizeof("_POST") - 1 && !memcmp(name, "_POST", sizeof("_POST") - 1)) ||
136 (name_len == sizeof("_COOKIE") - 1 && !memcmp(name, "_COOKIE", sizeof("_COOKIE") - 1)) ||
137 (name_len == sizeof("_ENV") - 1 && !memcmp(name, "_ENV", sizeof("_ENV") - 1)) ||
138 (name_len == sizeof("_SERVER") - 1 && !memcmp(name, "_SERVER", sizeof("_SERVER") - 1)) ||
139 (name_len == sizeof("_SESSION") - 1 && !memcmp(name, "_SESSION", sizeof("_SESSION") - 1)) ||
140 (name_len == sizeof("_FILES") - 1 && !memcmp(name, "_FILES", sizeof("_FILES") - 1)) ||
141 (name_len == sizeof("_REQUEST") -1 && !memcmp(name, "_REQUEST", sizeof("_REQUEST") - 1))
144 if (!silent) {
145 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempted super-global (%s) variable overwrite", name);
147 return FAILURE;
148 } else if (name[0] == 'H' &&
150 (name_len == sizeof("HTTP_POST_VARS") - 1 && !memcmp(name, "HTTP_POST_VARS", sizeof("HTTP_POST_VARS") - 1)) ||
151 (name_len == sizeof("HTTP_GET_VARS") - 1 && !memcmp(name, "HTTP_GET_VARS", sizeof("HTTP_GET_VARS") - 1)) ||
152 (name_len == sizeof("HTTP_COOKIE_VARS") - 1 && !memcmp(name, "HTTP_COOKIE_VARS", sizeof("HTTP_COOKIE_VARS") - 1)) ||
153 (name_len == sizeof("HTTP_ENV_VARS") - 1 && !memcmp(name, "HTTP_ENV_VARS", sizeof("HTTP_ENV_VARS") - 1)) ||
154 (name_len == sizeof("HTTP_SERVER_VARS") - 1 && !memcmp(name, "HTTP_SERVER_VARS", sizeof("HTTP_SERVER_VARS") - 1)) ||
155 (name_len == sizeof("HTTP_SESSION_VARS") - 1 && !memcmp(name, "HTTP_SESSION_VARS", sizeof("HTTP_SESSION_VARS") - 1)) ||
156 (name_len == sizeof("HTTP_RAW_POST_DATA") - 1 && !memcmp(name, "HTTP_RAW_POST_DATA", sizeof("HTTP_RAW_POST_DATA") - 1)) ||
157 (name_len == sizeof("HTTP_POST_FILES") - 1 && !memcmp(name, "HTTP_POST_FILES", sizeof("HTTP_POST_FILES") - 1))
160 if (!silent) {
161 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempted long input array (%s) overwrite", name);
163 return FAILURE;
165 return SUCCESS;
167 /* }}} */
169 #endif /* PHP_VAR_H */