-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathphp_timecop.h
170 lines (138 loc) · 5.57 KB
/
php_timecop.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
The MIT License
Copyright (c) 2012-2016 Yoshio HANAWA
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* $Id$ */
#ifndef PHP_TIMECOP_H
#define PHP_TIMECOP_H
#define PHP_TIMECOP_VERSION "1.1.0"
extern zend_module_entry timecop_module_entry;
#define phpext_timecop_ptr &timecop_module_entry
#ifdef PHP_WIN32
# define PHP_TIMECOP_API __declspec(dllexport)
#elif defined(__GNUC__) && __GNUC__ >= 4
# define PHP_TIMECOP_API __attribute__ ((visibility("default")))
#else
# define PHP_TIMECOP_API
#endif
#ifdef ZTS
#include "TSRM.h"
#endif
#include <time.h>
#include "Zend/zend_interfaces.h"
PHP_MINIT_FUNCTION(timecop);
PHP_MSHUTDOWN_FUNCTION(timecop);
PHP_RINIT_FUNCTION(timecop);
PHP_RSHUTDOWN_FUNCTION(timecop);
PHP_MINFO_FUNCTION(timecop);
PHP_FUNCTION(timecop_freeze);
PHP_FUNCTION(timecop_travel);
PHP_FUNCTION(timecop_return);
PHP_FUNCTION(timecop_time);
PHP_FUNCTION(timecop_mktime);
PHP_FUNCTION(timecop_gmmktime);
PHP_FUNCTION(timecop_date);
PHP_FUNCTION(timecop_gmdate);
PHP_FUNCTION(timecop_idate);
PHP_FUNCTION(timecop_getdate);
PHP_FUNCTION(timecop_localtime);
PHP_FUNCTION(timecop_strtotime);
PHP_FUNCTION(timecop_strftime);
PHP_FUNCTION(timecop_gmstrftime);
#ifdef HAVE_GETTIMEOFDAY
PHP_FUNCTION(timecop_microtime);
PHP_FUNCTION(timecop_gettimeofday);
#endif
PHP_FUNCTION(timecop_unixtojd);
PHP_FUNCTION(timecop_date_create);
PHP_FUNCTION(timecop_date_create_from_format);
PHP_METHOD(TimecopDateTime, __construct);
PHP_METHOD(TimecopOrigDateTime, __construct);
#if !defined(PHP_VERSION_ID) || PHP_VERSION_ID < 50300
PHP_METHOD(TimecopDateTime, getTimestamp);
PHP_METHOD(TimecopDateTime, setTimestamp);
#endif
typedef enum timecop_mode_t {
TIMECOP_MODE_NORMAL,
TIMECOP_MODE_FREEZE,
TIMECOP_MODE_TRAVEL
} timecop_mode_t;
ZEND_BEGIN_MODULE_GLOBALS(timecop)
long func_override;
long sync_request_time;
#if PHP_VERSION_ID >= 70000
zval orig_request_time;
#else
zval *orig_request_time;
#endif
timecop_mode_t timecop_mode;
long freezed_timestamp;
long travel_offset;
zend_class_entry *ce_DateTime;
zend_class_entry *ce_TimecopDateTime;
ZEND_END_MODULE_GLOBALS(timecop)
#if ZEND_DEBUG
# define TIMECOP_ASSERT(c) assert(c)
#else
# define TIMECOP_ASSERT(c)
#endif /* ZEND_DEBUG */
#define SAVE_FUNC_PREFIX "timecop_orig_"
#define OVRD_FUNC_PREFIX "timecop_"
#define OVRD_CLASS_PREFIX "timecop"
#define ORIG_FUNC_NAME(fname) \
(TIMECOP_G(func_override) ? (SAVE_FUNC_PREFIX fname) : fname)
#define ORIG_FUNC_NAME_SIZEOF(fname) \
(TIMECOP_G(func_override) ? sizeof(SAVE_FUNC_PREFIX fname) : sizeof(fname))
#define TIMECOP_OFE(fname) {fname, OVRD_FUNC_PREFIX fname, SAVE_FUNC_PREFIX fname}
#define TIMECOP_OCE(cname, mname) \
{cname, mname, OVRD_CLASS_PREFIX cname, SAVE_FUNC_PREFIX mname}
struct timecop_override_func_entry {
char *orig_func;
char *ovrd_func;
char *save_func;
};
struct timecop_override_class_entry {
char *orig_class;
char *orig_method;
char *ovrd_class;
char *save_method;
};
#define timecop_call_orig_method_with_0_params(obj, obj_ce, fn_proxy, function_name, retval) \
zend_call_method(obj, obj_ce, fn_proxy, ORIG_FUNC_NAME(function_name), ORIG_FUNC_NAME_SIZEOF(function_name)-1, retval, 0, NULL, NULL TSRMLS_CC)
#define timecop_call_orig_method_with_1_params(obj, obj_ce, fn_proxy, function_name, retval, arg1) \
zend_call_method(obj, obj_ce, fn_proxy, ORIG_FUNC_NAME(function_name), ORIG_FUNC_NAME_SIZEOF(function_name)-1, retval, 1, arg1, NULL TSRMLS_CC)
#define timecop_call_orig_method_with_2_params(obj, obj_ce, fn_proxy, function_name, retval, arg1, arg2) \
zend_call_method(obj, obj_ce, fn_proxy, ORIG_FUNC_NAME(function_name), ORIG_FUNC_NAME_SIZEOF(function_name)-1, retval, 2, arg1, arg2 TSRMLS_CC)
/* In every utility function you add that needs to use variables
in php_timecop_globals, call TSRMLS_FETCH(); after declaring other
variables used by that function, or better yet, pass in TSRMLS_CC
after the last function argument and declare your utility function
with TSRMLS_DC after the last declared argument. Always refer to
the globals in your function as TIMECOP_G(variable). You are
encouraged to rename these macros something shorter, see
examples in any other php module directory.
*/
#if PHP_VERSION_ID >= 70000
# define TIMECOP_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(timecop, v)
# if defined(ZTS) && defined(COMPILE_DL_TIMECOP)
ZEND_TSRMLS_CACHE_EXTERN();
# endif
#else
# ifdef ZTS
# define TIMECOP_G(v) TSRMG(timecop_globals_id, zend_timecop_globals *, v)
# else
# define TIMECOP_G(v) (timecop_globals.v)
# endif
#endif
#endif /* PHP_TIMECOP_H */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/