extesion deps
[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-2011, 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 # include <event.h>
24 # endif
25 #endif
26 #if PHP_HTTP_HAVE_SERF
27 # include <serf.h>
28 #endif
29
30 ZEND_DECLARE_MODULE_GLOBALS(php_http);
31
32 #ifdef COMPILE_DL_HTTP
33 ZEND_GET_MODULE(http)
34 #endif
35
36 zend_function_entry http_functions[] = {
37 EMPTY_FUNCTION_ENTRY
38 };
39
40 PHP_MINIT_FUNCTION(http);
41 PHP_MSHUTDOWN_FUNCTION(http);
42 PHP_RINIT_FUNCTION(http);
43 PHP_RSHUTDOWN_FUNCTION(http);
44 PHP_MINFO_FUNCTION(http);
45
46 static zend_module_dep http_module_deps[] = {
47 ZEND_MOD_REQUIRED("raphf")
48 ZEND_MOD_REQUIRED("propro")
49 ZEND_MOD_REQUIRED("spl")
50 #ifdef PHP_HTTP_HAVE_HASH
51 ZEND_MOD_REQUIRED("hash")
52 #endif
53 #ifdef PHP_HTTP_HAVE_ICONV
54 ZEND_MOD_REQUIRED("iconv")
55 #endif
56 #ifdef PHP_HTTP_HAVE_JSON
57 ZEND_MOD_REQUIRED("json")
58 #endif
59 #ifdef PHP_HTTP_HAVE_EVENT
60 ZEND_MOD_CONFLICTS("event")
61 #endif
62 {NULL, NULL, NULL, 0}
63 };
64
65 zend_module_entry http_module_entry = {
66 STANDARD_MODULE_HEADER_EX,
67 NULL,
68 http_module_deps,
69 "http",
70 http_functions,
71 PHP_MINIT(http),
72 PHP_MSHUTDOWN(http),
73 PHP_RINIT(http),
74 PHP_RSHUTDOWN(http),
75 PHP_MINFO(http),
76 PHP_HTTP_EXT_VERSION,
77 STANDARD_MODULE_PROPERTIES
78 };
79
80 int http_module_number;
81
82 static HashTable http_module_classes;
83 void php_http_register_class(zend_class_entry *(*get_ce)(void))
84 {
85 zend_hash_next_index_insert(&http_module_classes, &get_ce, sizeof(get_ce), NULL);
86 }
87 static void php_http_registered_classes(php_http_buffer_t *buf, unsigned flags)
88 {
89 HashPosition pos;
90 zend_class_entry *(**get_ce)(void);
91
92 FOREACH_HASH_VAL(pos, &http_module_classes, get_ce) {
93 zend_class_entry *ce = (*get_ce)();
94 if ((flags && (ce->ce_flags & flags)) || (!flags && !(ce->ce_flags & 0x0fff))) {
95 if (buf->used) {
96 php_http_buffer_appends(buf, ", ");
97 }
98 php_http_buffer_append(buf, ce->name, ce->name_length);
99 }
100 }
101 php_http_buffer_fix(buf);
102 }
103
104 #if PHP_DEBUG && !HAVE_GCOV
105 void _dpf(int type, const char *data, size_t length)
106 {
107 static const char _sym[] = "><><><";
108 if (type) {
109 int nwp = 0;
110 for (fprintf(stderr, "%c ", _sym[type-1]); length--; data++) {
111 int ip = PHP_HTTP_IS_CTYPE(print, *data);
112 if (!ip && *data != '\r' && *data != '\n') nwp = 1;
113 fprintf(stderr, ip?"%c":"\\x%02x", (int) (*data & 0xff));
114 if (!nwp && *data == '\n' && length) {
115 fprintf(stderr, "\n%c ", _sym[type-1]);
116 }
117 }
118 fprintf(stderr, "\n");
119 } else {
120 fprintf(stderr, "# %.*s\n", (int) length, data);
121 }
122 }
123 #endif
124
125 static void php_http_globals_init_once(zend_php_http_globals *G)
126 {
127 memset(G, 0, sizeof(*G));
128 }
129
130 #if 0
131 static inline void php_http_globals_init(zend_php_http_globals *G TSRMLS_DC)
132 {
133 }
134
135 static inline void php_http_globals_free(zend_php_http_globals *G TSRMLS_DC)
136 {
137 }
138 #endif
139
140 #if ZTS && PHP_DEBUG && !HAVE_GCOV
141 zend_php_http_globals *php_http_globals(void)
142 {
143 TSRMLS_FETCH();
144 return PHP_HTTP_G;
145 }
146 #endif
147
148 PHP_INI_BEGIN()
149 PHP_HTTP_INI_ENTRY("http.etag.mode", "crc32b", PHP_INI_ALL, OnUpdateString, env.etag_mode)
150 PHP_INI_END()
151
152 PHP_MINIT_FUNCTION(http)
153 {
154 http_module_number = module_number;
155 ZEND_INIT_MODULE_GLOBALS(php_http, php_http_globals_init_once, NULL);
156 REGISTER_INI_ENTRIES();
157
158 zend_hash_init(&http_module_classes, 0, NULL, NULL, 1);
159
160 if (0
161 || SUCCESS != PHP_MINIT_CALL(http_object)
162 || SUCCESS != PHP_MINIT_CALL(http_exception)
163 || SUCCESS != PHP_MINIT_CALL(http_cookie)
164 || SUCCESS != PHP_MINIT_CALL(http_encoding)
165 || SUCCESS != PHP_MINIT_CALL(http_filter)
166 || SUCCESS != PHP_MINIT_CALL(http_header)
167 || SUCCESS != PHP_MINIT_CALL(http_message)
168 || SUCCESS != PHP_MINIT_CALL(http_message_body)
169 || SUCCESS != PHP_MINIT_CALL(http_querystring)
170 || SUCCESS != PHP_MINIT_CALL(http_client_interface)
171 || SUCCESS != PHP_MINIT_CALL(http_client)
172 || SUCCESS != PHP_MINIT_CALL(http_client_request)
173 || SUCCESS != PHP_MINIT_CALL(http_client_response)
174 || SUCCESS != PHP_MINIT_CALL(http_client_datashare)
175 || SUCCESS != PHP_MINIT_CALL(http_client_pool)
176 || SUCCESS != PHP_MINIT_CALL(http_client_factory)
177 #if PHP_HTTP_HAVE_CURL
178 || SUCCESS != PHP_MINIT_CALL(http_curl)
179 || SUCCESS != PHP_MINIT_CALL(http_curl_client)
180 || SUCCESS != PHP_MINIT_CALL(http_curl_client_pool)
181 || SUCCESS != PHP_MINIT_CALL(http_curl_client_datashare)
182 #endif
183 || SUCCESS != PHP_MINIT_CALL(http_url)
184 || SUCCESS != PHP_MINIT_CALL(http_env)
185 || SUCCESS != PHP_MINIT_CALL(http_env_request)
186 || SUCCESS != PHP_MINIT_CALL(http_env_response)
187 || SUCCESS != PHP_MINIT_CALL(http_params)
188 ) {
189 return FAILURE;
190 }
191
192 return SUCCESS;
193 }
194
195
196
197 PHP_MSHUTDOWN_FUNCTION(http)
198 {
199 UNREGISTER_INI_ENTRIES();
200
201 if (0
202 || SUCCESS != PHP_MSHUTDOWN_CALL(http_message)
203 #if PHP_HTTP_HAVE_CURL
204 || SUCCESS != PHP_MSHUTDOWN_CALL(http_curl_client)
205 || SUCCESS != PHP_MSHUTDOWN_CALL(http_curl)
206 #endif
207 || SUCCESS != PHP_MSHUTDOWN_CALL(http_client_factory)
208 ) {
209 return FAILURE;
210 }
211
212 zend_hash_destroy(&http_module_classes);
213
214 return SUCCESS;
215 }
216
217 PHP_RINIT_FUNCTION(http)
218 {
219 if (0
220 || SUCCESS != PHP_RINIT_CALL(http_env)
221 #if PHP_HTTP_HAVE_CURL && PHP_HTTP_HAVE_EVENT
222 || SUCCESS != PHP_RINIT_CALL(http_curl_client_pool)
223 #endif
224 ) {
225 return FAILURE;
226 }
227
228 return SUCCESS;
229 }
230
231 PHP_RSHUTDOWN_FUNCTION(http)
232 {
233 if (0
234 #if PHP_HTTP_HAVE_CURL && PHP_HTTP_HAVE_EVENT
235 || SUCCESS != PHP_RSHUTDOWN_CALL(http_curl_client_pool)
236 #endif
237 || SUCCESS != PHP_RSHUTDOWN_CALL(http_env)
238 ) {
239 return FAILURE;
240 }
241
242 return SUCCESS;
243 }
244
245 PHP_MINFO_FUNCTION(http)
246 {
247 unsigned i;
248 php_http_buffer_t buf;
249
250 php_http_buffer_init(&buf);
251
252 php_info_print_table_start();
253 php_info_print_table_header(2, "HTTP Support", "enabled");
254 php_info_print_table_row(2, "Extension Version", PHP_HTTP_EXT_VERSION);
255 php_info_print_table_end();
256
257 php_info_print_table_start();
258 php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
259 php_info_print_table_row(3, "libz", ZLIB_VERSION, zlibVersion());
260 #if PHP_HTTP_HAVE_CURL
261 {
262 curl_version_info_data *cv = curl_version_info(CURLVERSION_NOW);
263 php_info_print_table_row(3, "libcurl", LIBCURL_VERSION, cv->version);
264 }
265 #else
266 php_info_print_table_row(3, "libcurl", "disabled", "disabled");
267 #endif
268
269 #if PHP_HTTP_HAVE_EVENT
270 php_info_print_table_row(3, "libevent",
271 # ifdef LIBEVENT_VERSION
272 LIBEVENT_VERSION,
273 # else
274 PHP_HTTP_EVENT_VERSION,
275 # endif
276 event_get_version());
277 #else
278 php_info_print_table_row(3, "libevent", "disabled", "disabled");
279 #endif
280
281 #if PHP_HTTP_HAVE_SERF
282 {
283 int v[3];
284
285 serf_lib_version(&v[0], &v[1], &v[2]);
286 php_http_buffer_appendf(&buf, "%d.%d.%d", v[0], v[1], v[2]);
287 php_http_buffer_fix(&buf);
288 php_info_print_table_row(3, "libserf", SERF_VERSION_STRING, buf.data);
289 php_http_buffer_reset(&buf);
290 }
291 #else
292 php_info_print_table_row(3, "libserf", "disabled", "disabled");
293 #endif
294 php_info_print_table_end();
295
296 php_info_print_table_start();
297 php_info_print_table_colspan_header(2, "Registered API");
298 for (i = 0; http_functions[i].fname; ++i) {
299 if (buf.used) {
300 php_http_buffer_appends(&buf, ", ");
301 }
302 php_http_buffer_appendl(&buf, http_functions[i].fname);
303 }
304 php_http_buffer_fix(&buf);
305 php_info_print_table_row(2, "Functions", buf.data);
306 php_http_buffer_reset(&buf);
307 php_http_registered_classes(&buf, ZEND_ACC_INTERFACE);
308 php_info_print_table_row(2, "Interfaces", buf.data);
309 php_http_buffer_reset(&buf);
310 php_http_registered_classes(&buf, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
311 php_info_print_table_row(2, "Abstract Classes", buf.data);
312 php_http_buffer_reset(&buf);
313 php_http_registered_classes(&buf, 0);
314 php_info_print_table_row(2, "Implemented Classes", buf.data);
315 php_http_buffer_reset(&buf);
316 php_http_registered_classes(&buf, ZEND_ACC_FINAL_CLASS);
317 php_info_print_table_row(2, "Final Classes", buf.data);
318 php_http_buffer_dtor(&buf);
319
320 php_info_print_table_row(2, "Stream Filters", "http.chunked_encode, http.chunked_decode, http.inflate, http.deflate");
321 php_info_print_table_end();
322
323
324 DISPLAY_INI_ENTRIES();
325 }
326
327
328 /*
329 * Local variables:
330 * tab-width: 4
331 * c-basic-offset: 4
332 * End:
333 * vim600: noet sw=4 ts=4 fdm=marker
334 * vim<600: noet sw=4 ts=4
335 */
336