1 /* 2 +----------------------------------------------------------------------+ 3 | PHP Version 5 | 4 +----------------------------------------------------------------------+ 5 | Copyright (c) 1997-2020 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: Ruslan Osmanov <osmanov@php.net> | 16 +----------------------------------------------------------------------+ 17 */ 18 19 #ifndef PHP_EVENT_STRUCTS_H 20 #define PHP_EVENT_STRUCTS_H 21 22 /* Thread context. With it we are getting rid of need 23 * to call the heavy TSRMLS_FETCH() */ 24 #ifdef ZTS 25 # define PHP_EVENT_COMMON_THREAD_CTX void ***thread_ctx; 26 #else 27 # define PHP_EVENT_COMMON_THREAD_CTX 28 #endif 29 30 #define PHP_EVENT_OBJECT_HEAD \ 31 zend_object zo; /* Extending zend_object */ \ 32 HashTable *prop_handler /* no ';' */ 33 34 /* php_event_abstract_object_t is for type casting only. However, all the 35 * class objects must have the same fields at the head of their structs */ 36 typedef struct _php_event_abstract_object_t { 37 PHP_EVENT_OBJECT_HEAD; 38 } php_event_abstract_object_t; 39 40 /* Represents EventBase object */ 41 typedef struct _php_event_base_t { 42 PHP_EVENT_OBJECT_HEAD; 43 44 struct event_base *base; 45 zend_bool internal; /* Whether is an internal pointer, e.g. obtained with evconnlistener_get_base() */ 46 } php_event_base_t; 47 48 /* Represents Event object */ 49 typedef struct _php_event_t { 50 PHP_EVENT_OBJECT_HEAD; 51 52 struct event *event; /* Pointer returned by event_new */ 53 int stream_id; /* Resource ID of the file descriptor. -1 if none */ 54 zval *data; /* User custom data */ 55 /* fci and fcc represent userspace callback */ 56 zend_fcall_info *fci; 57 zend_fcall_info_cache *fcc; 58 59 PHP_EVENT_COMMON_THREAD_CTX 60 } php_event_t; 61 62 /* Represents EventConfig object */ 63 typedef struct _php_event_config_t { 64 PHP_EVENT_OBJECT_HEAD; 65 66 struct event_config *ptr; 67 } php_event_config_t; 68 69 /* Represents EventBufferEvent object */ 70 typedef struct _php_event_bevent_t { 71 PHP_EVENT_OBJECT_HEAD; 72 73 struct bufferevent *bevent; 74 int _internal; 75 zval *self; /* Object itself. For callbacks */ 76 zval *data; /* User custom data */ 77 zval *input; /* Input buffer */ 78 zval *output; /* Output buffer */ 79 zval *base; 80 81 /* fci and fcc members represent userspace callbacks */ 82 zend_fcall_info *fci_read; 83 zend_fcall_info_cache *fcc_read; 84 zend_fcall_info *fci_write; 85 zend_fcall_info_cache *fcc_write; 86 zend_fcall_info *fci_event; 87 zend_fcall_info_cache *fcc_event; 88 89 PHP_EVENT_COMMON_THREAD_CTX 90 } php_event_bevent_t; 91 92 /* Represents EventBuffer object */ 93 typedef struct _php_event_buffer_t { 94 PHP_EVENT_OBJECT_HEAD; 95 zend_bool internal; /* Whether is an internal buffer of a bufferevent */ 96 97 struct evbuffer *buf; 98 } php_event_buffer_t; 99 100 #ifdef HAVE_EVENT_EXTRA_LIB/* {{{ */ 101 102 enum { 103 PHP_EVENT_REQ_HEADER_INPUT = 1, 104 PHP_EVENT_REQ_HEADER_OUTPUT = 2, 105 }; 106 107 /* Represents EventDnsBase object */ 108 typedef struct _php_event_dns_base_t { 109 PHP_EVENT_OBJECT_HEAD; 110 111 struct evdns_base *dns_base; 112 } php_event_dns_base_t; 113 114 /* Represents EventListener object */ 115 typedef struct _php_event_listener_t { 116 PHP_EVENT_OBJECT_HEAD; 117 118 struct evconnlistener *listener; 119 zval *self; /* Object itself. For callbacks */ 120 zval *data; /* User custom data passed to callback */ 121 122 /* Accept callback */ 123 zend_fcall_info *fci; 124 zend_fcall_info_cache *fcc; 125 126 /* Error callback */ 127 zend_fcall_info *fci_err; 128 zend_fcall_info_cache *fcc_err; 129 130 PHP_EVENT_COMMON_THREAD_CTX 131 } php_event_listener_t; 132 133 typedef struct _php_event_http_cb_t php_event_http_cb_t; 134 135 /* Type for an HTTP server callback */ 136 struct _php_event_http_cb_t { 137 php_event_http_cb_t *next; /* Linked list */ 138 zval *data; /* User custom data passed to callback */ 139 zend_fcall_info *fci; 140 zend_fcall_info_cache *fcc; 141 zval *base; 142 143 PHP_EVENT_COMMON_THREAD_CTX 144 }; 145 146 /* Represents EventHttp object */ 147 typedef struct _php_event_http_t { 148 PHP_EVENT_OBJECT_HEAD; 149 150 struct evhttp *ptr; 151 zval *base; /* Event base associated with the listener */ 152 zval *data; /* User custom data passed to the gen(default) callback */ 153 154 /* General(default) callback for evhttp_gencb() */ 155 zend_fcall_info *fci; 156 zend_fcall_info_cache *fcc; 157 158 /* Linked list of attached callbacks */ 159 php_event_http_cb_t *cb_head; 160 161 PHP_EVENT_COMMON_THREAD_CTX 162 } php_event_http_t; 163 164 /* Represents EventHttpConnection object */ 165 typedef struct _php_event_http_conn_t { 166 PHP_EVENT_OBJECT_HEAD; 167 168 struct evhttp_connection *conn; 169 zval *base; /* Event base associated with the listener */ 170 zval *dns_base; /* Associated EventDnsBase */ 171 zval *self; 172 173 /* User custom data passed to the callback for connection close */ 174 zval *data_closecb; 175 /* Callback for connection close */ 176 zend_fcall_info *fci_closecb; 177 zend_fcall_info_cache *fcc_closecb; 178 179 /* Whether is artificially created object that must not free 'conn' */ 180 zend_bool internal; 181 182 PHP_EVENT_COMMON_THREAD_CTX 183 } php_event_http_conn_t; 184 185 typedef struct { 186 PHP_EVENT_OBJECT_HEAD; 187 188 struct evhttp_request *ptr; 189 /* Whether is artificially created object that must not free 'ptr' */ 190 zend_bool internal; 191 zval *self; 192 /* User custom data passed to the gen(default) callback */ 193 zval *data; 194 /* General(default) callback for evhttp_gencb() */ 195 zend_fcall_info *fci; 196 zend_fcall_info_cache *fcc; 197 198 PHP_EVENT_COMMON_THREAD_CTX 199 } php_event_http_req_t; 200 201 #endif/* HAVE_EVENT_EXTRA_LIB }}} */ 202 203 #ifdef HAVE_EVENT_OPENSSL_LIB 204 205 enum { 206 PHP_EVENT_OPT_LOCAL_CERT = 1, 207 PHP_EVENT_OPT_LOCAL_PK = 2, 208 PHP_EVENT_OPT_PASSPHRASE = 3, 209 PHP_EVENT_OPT_CA_FILE = 4, 210 PHP_EVENT_OPT_CA_PATH = 5, 211 PHP_EVENT_OPT_ALLOW_SELF_SIGNED = 6, 212 PHP_EVENT_OPT_VERIFY_PEER = 7, 213 PHP_EVENT_OPT_VERIFY_DEPTH = 8, 214 PHP_EVENT_OPT_CIPHERS = 9, 215 PHP_EVENT_OPT_NO_SSLv2 = 10, 216 PHP_EVENT_OPT_NO_SSLv3 = 11, 217 PHP_EVENT_OPT_NO_TLSv1 = 12, 218 PHP_EVENT_OPT_NO_TLSv1_1 = 13, 219 PHP_EVENT_OPT_NO_TLSv1_2 = 14, 220 PHP_EVENT_OPT_CIPHER_SERVER_PREFERENCE = 15, 221 PHP_EVENT_OPT_REQUIRE_CLIENT_CERT = 16, 222 PHP_EVENT_OPT_VERIFY_CLIENT_ONCE = 17 223 }; 224 225 enum { 226 PHP_EVENT_SSLv2_CLIENT_METHOD = 1, 227 PHP_EVENT_SSLv3_CLIENT_METHOD = 2, 228 PHP_EVENT_SSLv23_CLIENT_METHOD = 3, 229 PHP_EVENT_TLS_CLIENT_METHOD = 4, 230 PHP_EVENT_SSLv2_SERVER_METHOD = 5, 231 PHP_EVENT_SSLv3_SERVER_METHOD = 6, 232 PHP_EVENT_SSLv23_SERVER_METHOD = 7, 233 PHP_EVENT_TLS_SERVER_METHOD = 8, 234 PHP_EVENT_TLSv11_CLIENT_METHOD = 9, 235 PHP_EVENT_TLSv11_SERVER_METHOD = 10, 236 PHP_EVENT_TLSv12_CLIENT_METHOD = 11, 237 PHP_EVENT_TLSv12_SERVER_METHOD = 12 238 }; 239 240 typedef struct _php_event_ssl_context_t { 241 PHP_EVENT_OBJECT_HEAD; 242 243 SSL_CTX *ctx; 244 HashTable *ht; 245 zend_bool allow_self_signed; 246 } php_event_ssl_context_t; 247 #endif 248 249 typedef double php_event_timestamp_t; 250 251 typedef int (*php_event_prop_read_t)(php_event_abstract_object_t *obj, zval **retval TSRMLS_DC); 252 typedef int (*php_event_prop_write_t)(php_event_abstract_object_t *obj, zval *newval TSRMLS_DC); 253 typedef zval **(*php_event_prop_get_prop_ptr_ptr_t)(php_event_abstract_object_t *obj TSRMLS_DC); 254 255 typedef struct _php_event_property_entry_t { 256 const char *name; 257 size_t name_length; 258 php_event_prop_read_t read_func; 259 php_event_prop_write_t write_func; 260 php_event_prop_get_prop_ptr_ptr_t get_ptr_ptr_func; 261 } php_event_property_entry_t; 262 263 typedef struct _php_event_prop_handler_t { 264 char *name; 265 size_t name_len; 266 php_event_prop_read_t read_func; 267 php_event_prop_write_t write_func; 268 php_event_prop_get_prop_ptr_ptr_t get_ptr_ptr_func; 269 } php_event_prop_handler_t; 270 271 272 #ifndef LIBEVENT_VERSION_NUMBER 273 # error "<event2/*.h> must be included before " ## #__FILE__ 274 #endif 275 276 #if LIBEVENT_VERSION_NUMBER < 0x02000200 277 /* These types introduced in libevent 2.0.2-alpha */ 278 typedef void (*bufferevent_data_cb)(struct bufferevent *bev, void *ctx); 279 typedef void (*bufferevent_event_cb)(struct bufferevent *bev, short events, 280 void *ctx); 281 #endif 282 283 #endif /* PHP_EVENT_STRUCTS_H */ 284 285 /* 286 * Local variables: 287 * tab-width: 4 288 * c-basic-offset: 4 289 * End: 290 * vim600: noet sw=4 ts=4 fdm=marker 291 * vim<600: noet sw=4 ts=4 292 */ 293