forked from fhoenig/Kellner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
php_event.h
271 lines (236 loc) · 6.41 KB
/
php_event.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*
* Copyright (c) 2009, Kargo Global Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Kargo Global Inc. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Kargo Global Inc. ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Kargo Global Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Author: Florian Hoenig <[email protected]>
*/
#ifndef PHP_EVENT_H
#define PHP_EVENT_H
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
extern zend_module_entry event_module_entry;
#define phpext_event_ptr &event_module_entry
#ifdef PHP_WIN32
#define PHP_EVENT_API __declspec(dllexport)
#else
#define PHP_EVENT_API
#endif
#ifdef ZTS
#include "TSRM.h"
#endif
/* refcount macros */
#ifndef Z_ADDREF_P
#define Z_ADDREF_P(pz) (pz)->refcount++
#endif
#ifndef Z_DELREF_P
#define Z_DELREF_P(pz) (pz)->refcount--
#endif
#ifndef Z_SET_REFCOUNT_P
#define Z_SET_REFCOUNT_P(pz, rc) (pz)->refcount = rc
#endif
PHP_MINIT_FUNCTION(event);
PHP_MSHUTDOWN_FUNCTION(event);
PHP_RINIT_FUNCTION(event);
PHP_RSHUTDOWN_FUNCTION(event);
PHP_MINFO_FUNCTION(event);
/*
* Basic libevent functions
*/
PHP_FUNCTION(event_init);
PHP_FUNCTION(event_reinit);
PHP_FUNCTION(event_new);
PHP_FUNCTION(event_free);
PHP_FUNCTION(event_set);
PHP_FUNCTION(event_add);
PHP_FUNCTION(event_del);
PHP_FUNCTION(event_dispatch);
PHP_FUNCTION(event_loopbreak);
/*
* HTTP Client/Server functions
*/
PHP_FUNCTION(evhttp_start);
PHP_FUNCTION(evhttp_set_gencb);
PHP_FUNCTION(evhttp_connection_new);
PHP_FUNCTION(evhttp_connection_set_closecb);
PHP_FUNCTION(evhttp_request_new);
PHP_FUNCTION(evhttp_request_free);
PHP_FUNCTION(evhttp_make_request);
/*
* HTTP Request functions
*/
PHP_FUNCTION(evhttp_request_get_uri);
PHP_FUNCTION(evhttp_request_method);
PHP_FUNCTION(evhttp_request_body);
PHP_FUNCTION(evhttp_request_input_buffer);
PHP_FUNCTION(evhttp_request_headers);
PHP_FUNCTION(evhttp_request_find_header);
PHP_FUNCTION(evhttp_request_add_header);
PHP_FUNCTION(evhttp_request_status);
PHP_FUNCTION(evhttp_request_append_body);
/*
* Buffer functions
*/
PHP_FUNCTION(evbuffer_new);
PHP_FUNCTION(evbuffer_free);
PHP_FUNCTION(evbuffer_add);
PHP_FUNCTION(evbuffer_readline);
/*
* Response functions
*/
PHP_FUNCTION(evhttp_response_set);
PHP_FUNCTION(evhttp_response_add_header);
/*
* Buffered Events
*/
PHP_FUNCTION(bufferevent_new);
PHP_FUNCTION(bufferevent_enable);
PHP_FUNCTION(bufferevent_disable);
PHP_FUNCTION(bufferevent_read);
PHP_FUNCTION(bufferevent_write);
/*
* Network byte-order conversion functions
*
* Some PHP version have problems unpacking on 64-bit platforms.
* These functions serve as a workaround for that. Useful for many binary
* protocol implementations.
*/
PHP_FUNCTION(ntohs);
PHP_FUNCTION(ntohl);
PHP_FUNCTION(htons);
PHP_FUNCTION(htonl);
/*
*
Declare any global variables you may need between the BEGIN
and END macros here:
ZEND_BEGIN_MODULE_GLOBALS(event)
long global_value;
char *global_string;
ZEND_END_MODULE_GLOBALS(event)
*/
#define PHP_EVENT_RES_NAME "EVENT"
#define PHP_BUFFEREVENT_RES_NAME "BUFFEREVENT"
#define PHP_EVHTTP_RES_NAME "EVHTTP"
#define PHP_EVHTTP_REQUEST_RES_NAME "EVHTTP Request"
#define PHP_EVHTTP_CONNECTION_RES_NAME "EVHTTP Connection"
#define PHP_EVBUFFER_RES_NAME "EVBUFFER"
#define PHP_EVHTTP_RESPONSE_RES_NAME "EVHTTP Response"
/* In every utility function you add that needs to use variables
in php_event_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 EVENT_G(variable). You are
encouraged to rename these macros something shorter, see
examples in any other php module directory.
*/
#ifdef ZTS
#define EVENT_G(v) TSRMG(event_globals_id, zend_event_globals *, v)
#else
#define EVENT_G(v) (event_globals.v)
#endif
/*
* PHP Event struct
*/
typedef struct _php_event
{
zval *stream;
zval *cb;
zval *flags;
zval *event;
#ifdef ZTS
TSRMLS_D;
#endif
} php_event;
/*
* PHP Event struct for bufferevent
*/
typedef struct _php_bufferevent
{
zval *res_bufferevent;
zval *stream;
zval *r_cb;
zval *w_cb;
zval *e_cb;
#ifdef ZTS
TSRMLS_D;
#endif
} php_bufferevent;
/*
* PHP Event struct for httpevent
*/
typedef struct _php_httpevent
{
zval *res_httpevent;
zval *r_cb;
#ifdef ZTS
TSRMLS_D;
#endif
} php_httpevent;
/*
* PHP Event struct for evhttp_connection onClose
*/
typedef struct _php_httpcon
{
zval *res_httpcon;
zval *c_cb;
#ifdef ZTS
TSRMLS_D;
#endif
} php_httpcon;
/*
* Custom event struct that has a http response code and message associated
* with the buffer. Note that libevent uses the evhttp_request struct for
* both requests and responses -- this just keeps things cleaner for PHP.
*/
typedef struct _evhttp_response
{
int res_code;
char* res_message;
char* res_body;
int res_body_len;
#ifdef ZTS
TSRMLS_D;
#endif
} evhttp_response;
typedef struct _evhttp_callback_arg
{
zval *arg;
#ifdef ZTS
TSRMLS_D;
#endif
} evhttp_callback_arg;
#endif /* PHP_EVENT_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
*/