fixed event2 headers inclusion once more
[m6w6/ext-http] / php_http.c
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2013, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #include "php_http_api.h"
14
15 #include <php_ini.h>
16 #include <ext/standard/info.h>
17
18 #include <zlib.h>
19
20 #if PHP_HTTP_HAVE_CURL
21 # include <curl/curl.h>
22 # if PHP_HTTP_HAVE_EVENT
23 # if PHP_HTTP_HAVE_EVENT2
24 # include <event2/event.h>
25 # include <event2/event_struct.h>
26 # else
27 # include <event.h>
28 # endif
29 # endif
30 #endif
31 #if PHP_HTTP_HAVE_SERF
32 # include <serf.h>
33 #endif
34
35 ZEND_DECLARE_MODULE_GLOBALS(php_http);
36
37 #ifdef COMPILE_DL_HTTP
38 ZEND_GET_MODULE(http)
39 #endif
40
41 zend_function_entry http_functions[] = {
42 EMPTY_FUNCTION_ENTRY
43 };
44
45 PHP_MINIT_FUNCTION(http);
46 PHP_MSHUTDOWN_FUNCTION(http);
47 PHP_RINIT_FUNCTION(http);
48 PHP_RSHUTDOWN_FUNCTION(http);
49 PHP_MINFO_FUNCTION(http);
50
51 static zend_module_dep http_module_deps[] = {
52 ZEND_MOD_REQUIRED("raphf")
53 ZEND_MOD_REQUIRED("propro")
54 ZEND_MOD_REQUIRED("spl")
55 #ifdef PHP_HTTP_HAVE_HASH
56 ZEND_MOD_REQUIRED("hash")
57 #endif
58 #ifdef PHP_HTTP_HAVE_ICONV
59 ZEND_MOD_REQUIRED("iconv")
60 #endif
61 #ifdef PHP_HTTP_HAVE_JSON
62 ZEND_MOD_REQUIRED("json")
63 #endif
64 #ifdef PHP_HTTP_HAVE_EVENT
65 ZEND_MOD_CONFLICTS("event")
66 #endif
67 {NULL, NULL, NULL, 0}
68 };
69
70 zend_module_entry http_module_entry = {
71 STANDARD_MODULE_HEADER_EX,
72 NULL,
73 http_module_deps,
74 "http",
75 http_functions,
76 PHP_MINIT(http),
77 PHP_MSHUTDOWN(http),
78 PHP_RINIT(http),
79 PHP_RSHUTDOWN(http),
80 PHP_MINFO(http),
81 PHP_PECL_HTTP_VERSION,
82 STANDARD_MODULE_PROPERTIES
83 };
84
85 int http_module_number;
86
87 #if PHP_DEBUG && !HAVE_GCOV
88 void _dpf(int type, const char *data, size_t length)
89 {
90 static const char _sym[] = "><><><";
91 if (type) {
92 int nwp = 0;
93 for (fprintf(stderr, "%c ", _sym[type-1]); length--; data++) {
94 int ip = PHP_HTTP_IS_CTYPE(print, *data);
95 if (!ip && *data != '\r' && *data != '\n') nwp = 1;
96 fprintf(stderr, ip?"%c":"\\x%02x", (int) (*data & 0xff));
97 if (!nwp && *data == '\n' && length) {
98 fprintf(stderr, "\n%c ", _sym[type-1]);
99 }
100 }
101 fprintf(stderr, "\n");
102 } else {
103 fprintf(stderr, "# %.*s\n", (int) length, data);
104 }
105 }
106 #endif
107
108 static void php_http_globals_init_once(zend_php_http_globals *G)
109 {
110 memset(G, 0, sizeof(*G));
111 }
112
113 #if 0
114 static inline void php_http_globals_init(zend_php_http_globals *G TSRMLS_DC)
115 {
116 }
117
118 static inline void php_http_globals_free(zend_php_http_globals *G TSRMLS_DC)
119 {
120 }
121 #endif
122
123 #if ZTS && PHP_DEBUG && !HAVE_GCOV
124 zend_php_http_globals *php_http_globals(void)
125 {
126 TSRMLS_FETCH();
127 return PHP_HTTP_G;
128 }
129 #endif
130
131 PHP_INI_BEGIN()
132 STD_PHP_INI_ENTRY("http.etag.mode", "crc32b", PHP_INI_ALL, OnUpdateString, env.etag_mode, zend_php_http_globals, php_http_globals)
133 PHP_INI_END()
134
135 PHP_MINIT_FUNCTION(http)
136 {
137 http_module_number = module_number;
138 ZEND_INIT_MODULE_GLOBALS(php_http, php_http_globals_init_once, NULL);
139 REGISTER_INI_ENTRIES();
140
141 if (0
142 || SUCCESS != PHP_MINIT_CALL(http_exception)
143 || SUCCESS != PHP_MINIT_CALL(http_cookie)
144 || SUCCESS != PHP_MINIT_CALL(http_encoding)
145 || SUCCESS != PHP_MINIT_CALL(http_filter)
146 || SUCCESS != PHP_MINIT_CALL(http_header)
147 || SUCCESS != PHP_MINIT_CALL(http_message)
148 || SUCCESS != PHP_MINIT_CALL(http_message_body)
149 || SUCCESS != PHP_MINIT_CALL(http_querystring)
150 || SUCCESS != PHP_MINIT_CALL(http_client)
151 || SUCCESS != PHP_MINIT_CALL(http_client_request)
152 || SUCCESS != PHP_MINIT_CALL(http_client_response)
153 #if PHP_HTTP_HAVE_CURL
154 || SUCCESS != PHP_MINIT_CALL(http_curl)
155 || SUCCESS != PHP_MINIT_CALL(http_client_curl)
156 #endif
157 || SUCCESS != PHP_MINIT_CALL(http_url)
158 || SUCCESS != PHP_MINIT_CALL(http_env)
159 || SUCCESS != PHP_MINIT_CALL(http_env_request)
160 || SUCCESS != PHP_MINIT_CALL(http_env_response)
161 || SUCCESS != PHP_MINIT_CALL(http_params)
162 ) {
163 return FAILURE;
164 }
165
166 return SUCCESS;
167 }
168
169
170
171 PHP_MSHUTDOWN_FUNCTION(http)
172 {
173 UNREGISTER_INI_ENTRIES();
174
175 if (0
176 || SUCCESS != PHP_MSHUTDOWN_CALL(http_message)
177 #if PHP_HTTP_HAVE_CURL
178 || SUCCESS != PHP_MSHUTDOWN_CALL(http_client_curl)
179 || SUCCESS != PHP_MSHUTDOWN_CALL(http_curl)
180 #endif
181 || SUCCESS != PHP_MSHUTDOWN_CALL(http_client)
182 ) {
183 return FAILURE;
184 }
185
186 return SUCCESS;
187 }
188
189 PHP_RINIT_FUNCTION(http)
190 {
191 if (0
192 || SUCCESS != PHP_RINIT_CALL(http_env)
193 #if PHP_HTTP_HAVE_CURL && PHP_HTTP_HAVE_EVENT
194 || SUCCESS != PHP_RINIT_CALL(http_client_curl)
195 #endif
196 ) {
197 return FAILURE;
198 }
199
200 return SUCCESS;
201 }
202
203 PHP_RSHUTDOWN_FUNCTION(http)
204 {
205 if (0
206 #if PHP_HTTP_HAVE_CURL && PHP_HTTP_HAVE_EVENT
207 || SUCCESS != PHP_RSHUTDOWN_CALL(http_client_curl)
208 #endif
209 || SUCCESS != PHP_RSHUTDOWN_CALL(http_env)
210 ) {
211 return FAILURE;
212 }
213
214 return SUCCESS;
215 }
216
217 PHP_MINFO_FUNCTION(http)
218 {
219 php_http_buffer_t buf;
220
221 php_http_buffer_init(&buf);
222
223 php_info_print_table_start();
224 php_info_print_table_header(2, "HTTP Support", "enabled");
225 php_info_print_table_row(2, "Extension Version", PHP_PECL_HTTP_VERSION);
226 php_info_print_table_end();
227
228 php_info_print_table_start();
229 php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
230 php_info_print_table_row(3, "libz", ZLIB_VERSION, zlibVersion());
231 #if PHP_HTTP_HAVE_CURL
232 {
233 curl_version_info_data *cv = curl_version_info(CURLVERSION_NOW);
234 php_info_print_table_row(3, "libcurl", LIBCURL_VERSION, cv->version);
235 }
236 #else
237 php_info_print_table_row(3, "libcurl", "disabled", "disabled");
238 #endif
239
240 #if PHP_HTTP_HAVE_EVENT
241 php_info_print_table_row(3, "libevent",
242 # ifdef LIBEVENT_VERSION
243 LIBEVENT_VERSION,
244 # else
245 PHP_HTTP_EVENT_VERSION,
246 # endif
247 event_get_version());
248 #else
249 php_info_print_table_row(3, "libevent", "disabled", "disabled");
250 #endif
251
252 php_info_print_table_end();
253
254 DISPLAY_INI_ENTRIES();
255 }
256
257
258 /*
259 * Local variables:
260 * tab-width: 4
261 * c-basic-offset: 4
262 * End:
263 * vim600: noet sw=4 ts=4 fdm=marker
264 * vim<600: noet sw=4 ts=4
265 */
266