1 /*
2 +----------------------------------------------------------------------+
3 | Yet Another Framework |
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 | http://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 | Author: Xinchen Hui <laruence@php.net> |
14 +----------------------------------------------------------------------+
15 */
16
17 #ifndef PHP_YAF_H
18 #define PHP_YAF_H
19
20 extern zend_module_entry yaf_module_entry;
21 #define phpext_yaf_ptr &yaf_module_entry
22
23 #ifdef PHP_WIN32
24 #define PHP_YAF_API __declspec(dllexport)
25 #ifndef _MSC_VER
26 #define _MSC_VER 1600
27 #endif
28 #else
29 #define PHP_YAF_API
30 #endif
31
32 #ifdef ZTS
33 #include "TSRM.h"
34 #endif
35
36 #ifdef ZTS
37 #define YAF_G(v) TSRMG(yaf_globals_id, zend_yaf_globals *, v)
38 #else
39 #define YAF_G(v) (yaf_globals.v)
40 #endif
41
42 #ifndef ZEND_ACC_CTOR
43 # define ZEND_ACC_CTOR 0x0
44 # define ZEND_ACC_DTOR 0x0
45 #endif
46
47 #define PHP_YAF_VERSION "3.3.3"
48
49 #define YAF_STARTUP_FUNCTION(module) ZEND_MINIT_FUNCTION(yaf_##module)
50 #define YAF_RINIT_FUNCTION(module) ZEND_RINIT_FUNCTION(yaf_##module)
51 #define YAF_STARTUP(module) ZEND_MODULE_STARTUP_N(yaf_##module)(INIT_FUNC_ARGS_PASSTHRU)
52 #define YAF_SHUTDOWN_FUNCTION(module) ZEND_MSHUTDOWN_FUNCTION(yaf_##module)
53 #define YAF_SHUTDOWN(module) ZEND_MODULE_SHUTDOWN_N(yaf_##module)(INIT_FUNC_ARGS_PASSTHRU)
54 #define YAF_ME(c, m, a, f) {m, PHP_MN(c), a, (unsigned)(sizeof(a)/sizeof(struct _zend_arg_info)-1), f},
55 #define YAF_VAR_FLAGS(v) ((v).u2.next)
56
57 #if PHP_VERSION_ID < 70200
58 #define YAF_ALLOW_VIOLATION(ht)
59 #else
60 #define YAF_ALLOW_VIOLATION(ht) do { \
61 zend_hash_real_init(ht, 0); \
62 HT_ALLOW_COW_VIOLATION(ht); \
63 } while (0)
64 #endif
65
66 #if PHP_VERSION_ID < 70400
67 #define YAF_WRITE_HANDLER void
68 #define YAF_WHANDLER_RET(zv) return
69 # if PHP_VERSION_ID < 70300
70 # define GC_ADDREF(gc) (++GC_REFCOUNT(gc))
71 # define GC_DELREF(gc) (--GC_REFCOUNT(gc))
72 # endif
73 # define yaf_fake_get_gc NULL
74 #else
75 #define YAF_WRITE_HANDLER zval *
76 #define YAF_WHANDLER_RET(zv) return zv
77 HashTable *yaf_fake_get_gc(zend_object *zobj, zval **table, int *n);
78 #endif
79
80 #if PHP_VERSION_ID < 80000
81 #define yaf_object zval
82 #define yaf_strip_obj(o) Z_OBJ_P(o)
83 #else
84 #define yaf_object zend_object
85 #define yaf_strip_obj
86 #endif
87
88 #define yaf_application_t zval
89 #define yaf_view_t zval
90 #define yaf_controller_t zval
91 #define yaf_request_t zval
92 #define yaf_router_t zval
93 #define yaf_route_t zval
94 #define yaf_dispatcher_t zval
95 #define yaf_action_t zval
96 #define yaf_loader_t zval
97 #define yaf_response_t zval
98 #define yaf_config_t zval
99 #define yaf_registry_t zval
100 #define yaf_plugin_t zval
101 #define yaf_session_t zval
102 #define yaf_exception_t zval
103
104 #define YAF_USE_SPL_AUTOLOAD (1<<0)
105 #define YAF_LOWERCASE_PATH (1<<1)
106 #define YAF_NAME_SUFFIX (1<<2)
107 #define YAF_HAS_NAME_SEPERATOR (1<<3)
108 #define YAF_USE_NAMESPACE (1<<4)
109 #define YAF_ACTION_PREFER (1<<5)
110 #define YAF_THROW_EXCEPTION (1<<6)
111 #define YAF_CATCH_EXCEPTION (1<<7)
112
113 #define YAF_FLAGS() (YAF_VAR_FLAGS(YAF_G(app)))
114
115 ZEND_BEGIN_MODULE_GLOBALS(yaf)
116 /* for instances stash, and flags */
117 yaf_application_t app;
118 yaf_loader_t loader;
119 yaf_registry_t registry;
120 yaf_session_t session;
121
122 /* ini configurations */
123 char *name_separator;
124 size_t name_separator_len;
125 char *global_library;
126 char *environ_name;
127
128 /*for ini parsing */
129 zval active_ini_file_section;
130 zval *ini_wanted_section;
131 ZEND_END_MODULE_GLOBALS(yaf)
132
133 PHP_MINIT_FUNCTION(yaf);
134 PHP_MSHUTDOWN_FUNCTION(yaf);
135 PHP_RINIT_FUNCTION(yaf);
136 PHP_RSHUTDOWN_FUNCTION(yaf);
137 PHP_MINFO_FUNCTION(yaf);
138
139 typedef struct {
140 zend_object_iterator intern;
141 zval current;
142 HashPosition pos;
143 } yaf_iterator;
144
145 extern ZEND_DECLARE_MODULE_GLOBALS(yaf);
146 extern zend_object_iterator_funcs yaf_iterator_funcs;
147
148 zend_string *yaf_canonical_name(int type, zend_string *name);
149 zend_string *yaf_build_camel_name(const char *str, size_t len);
150 zend_string *yaf_build_lower_name(const char *str, size_t len);
151 int yaf_call_user_method(zend_object *obj, zend_function *fbc, int num_args, zval *args, zval *ret);
152 int yaf_call_user_method_with_0_arguments(zend_object *obj, zend_function *fbc, zval *ret);
153 int yaf_call_user_method_with_1_arguments(zend_object *obj, zend_function *fbc, zval *arg, zval *ret);
154 int yaf_call_user_method_with_2_arguments(zend_object *obj, zend_function *fbc, zval *arg1, zval *arg2, zval *ret);
155 void yaf_replace_chr(char *name, uint32_t len, zend_uchar f, zend_uchar t);
156
157 extern const char const *yaf_known_chars[];
158 extern zend_string **yaf_known_strings;
159 #define YAF_KNOWN_STR(id) (yaf_known_strings[id])
160 #define YAF_KNOWN_CHARS(id) (yaf_known_chars[id])
161 #define YAF_KNOWN_NAMES(_) \
162 _(YAF, "yaf") \
163 _(YAF_APPLICATION, "application") \
164 _(YAF_DIRECTORY, "directory") \
165 _(YAF_DISPATCHER, "dispatcher") \
166 _(YAF_DEFAULT_MODULE, "Index") \
167 _(YAF_DEFAULT_CONTROLLER, "Index") \
168 _(YAF_DEFAULT_ACTION, "index") \
169 _(YAF_ACTIONS_MAP, "actions") \
170 _(YAF_BOOTSTRAP, "bootstrap") \
171 _(YAF_CONTENT, "content") \
172 _(YAF_VAR_POST, "_POST") \
173 _(YAF_VAR_GET, "_GET") \
174 _(YAF_VAR_SERVER, "_SERVER") \
175 _(YAF_VAR_COOKIE, "_COOKIE") \
176 _(YAF_VAR_FILES, "_FILES") \
177 _(YAF_VAR_REQUEST, "_REQUEST") \
178 _(YAF_VAR_ENV, "_ENV") \
179 _(YAF_VAR_SESSION, "_SESSION") \
180 _(YAF_HOOK_ROUTESTARTUP, "routerstartup") \
181 _(YAF_HOOK_ROUTESHUTDOWN, "routershutdown") \
182 _(YAF_HOOK_LOOPSTARTUP, "dispatchloopstartup") \
183 _(YAF_HOOK_PREDISPATCH, "predispatch") \
184 _(YAF_HOOK_POSTDISPATCH, "postdispatch") \
185 _(YAF_HOOK_LOOPSHUTDOWN, "dispatchloopshutdown") \
186 _(YAF_AUTORENDER, "yafAutoRender") \
187 _(YAF_RENDER, "render") \
188 _(YAF_DISPLAY, "display") \
189 _(YAF_EXECUTE, "execute") \
190 _(YAF_PATH_INFO, "PATH_INFO") \
191 _(YAF_REQUEST_URI, "REQUEST_URI") \
192
193 enum _yaf_known_chars_id {
194 #define _YAF_CHARS_ID(id, str) id,
195 YAF_KNOWN_NAMES(_YAF_CHARS_ID)
196 #undef _YAF_CHARS_ID
197 YAF_LAST_KNOWN_CHARS
198 };
199
200 #define YSCMP(a, b, l, s) do { \
201 if (l>=sizeof(uint##s##_t)) { \
202 if (*(uint##s##_t*)a != *(uint##s##_t*)b) return 0; \
203 l-=sizeof(uint##s##_t),a+=sizeof(uint##s##_t),b+=sizeof(uint##s##_t); \
204 }\
205 } while (0)
yaf_slip_equal(const char * s,const char * p,unsigned char l)206 static zend_always_inline int yaf_slip_equal(const char *s, const char *p, unsigned char l) {
207 ZEND_ASSERT(l < 16);
208 #if SIZEOF_ZEND_LONG == 8
209 YSCMP(s, p, l, 64);
210 #else
211 YSCMP(s, p, l, 32); YSCMP(s, p, l, 32);
212 #endif
213 YSCMP(s, p, l, 32);
214 YSCMP(s, p, l, 16);
215 return (l == 0 || *s == *p);
216 }
217
yaf_get_forward_limit()218 static zend_always_inline unsigned int yaf_get_forward_limit() {
219 return YAF_VAR_FLAGS(YAF_G(loader));
220 }
yaf_is_use_namespace()221 static zend_always_inline zend_bool yaf_is_use_namespace() {
222 return YAF_FLAGS() & YAF_USE_NAMESPACE;
223 }
yaf_is_action_prefer()224 static zend_always_inline zend_bool yaf_is_action_prefer() {
225 return YAF_FLAGS() & YAF_ACTION_PREFER;
226 }
yaf_is_name_suffix()227 static zend_always_inline zend_bool yaf_is_name_suffix() {
228 return YAF_FLAGS() & YAF_NAME_SUFFIX;
229 }
yaf_has_name_separator()230 static zend_always_inline zend_bool yaf_has_name_separator() {
231 return YAF_FLAGS() & YAF_HAS_NAME_SEPERATOR;
232 }
yaf_is_throw_exception()233 static zend_always_inline zend_bool yaf_is_throw_exception() {
234 return YAF_FLAGS() & YAF_THROW_EXCEPTION;
235 }
yaf_is_catch_exception()236 static zend_always_inline zend_bool yaf_is_catch_exception() {
237 return YAF_FLAGS() & YAF_CATCH_EXCEPTION;
238 }
yaf_set_throw_exception(zend_bool flag)239 static zend_always_inline void yaf_set_throw_exception(zend_bool flag) {
240 if (flag) {
241 YAF_FLAGS() |= YAF_THROW_EXCEPTION;
242 } else {
243 YAF_FLAGS() &= ~YAF_THROW_EXCEPTION;
244 }
245 }
yaf_set_catch_exception(zend_bool flag)246 static zend_always_inline void yaf_set_catch_exception(zend_bool flag) {
247 if (flag) {
248 YAF_FLAGS() |= YAF_CATCH_EXCEPTION;
249 } else {
250 YAF_FLAGS() &= ~YAF_CATCH_EXCEPTION;
251 }
252 }
yaf_compose_2_pathes(char * buf,zend_string * c1,const char * c2,uint32_t l2)253 static zend_always_inline uint32_t yaf_compose_2_pathes(char *buf, zend_string *c1, const char *c2, uint32_t l2) {
254 uint32_t len = ZSTR_LEN(c1);
255 memcpy(buf, ZSTR_VAL(c1), len);
256 buf[len] = DEFAULT_SLASH;
257 memcpy(buf + len + 1, c2, l2);
258 len = len + l2 + 1;
259 return len;
260 }
261 #endif
262
263 /*
264 * Local variables:
265 * tab-width: 4
266 * c-basic-offset: 4
267 * End:
268 * vim600: noet sw=4 ts=4 fdm=marker
269 * vim<600: noet sw=4 ts=4
270 */
271