defer warnings/exceptions of the client
[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-2014, 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_RSHUTDOWN_FUNCTION(http);
48 PHP_MINFO_FUNCTION(http);
49
50 static zend_module_dep http_module_deps[] = {
51 ZEND_MOD_REQUIRED("raphf")
52 ZEND_MOD_REQUIRED("propro")
53 ZEND_MOD_REQUIRED("spl")
54 #ifdef PHP_HTTP_HAVE_HASH
55 ZEND_MOD_REQUIRED("hash")
56 #endif
57 #ifdef PHP_HTTP_HAVE_ICONV
58 ZEND_MOD_REQUIRED("iconv")
59 #endif
60 {NULL, NULL, NULL, 0}
61 };
62
63 zend_module_entry http_module_entry = {
64 STANDARD_MODULE_HEADER_EX,
65 NULL,
66 http_module_deps,
67 "http",
68 http_functions,
69 PHP_MINIT(http),
70 PHP_MSHUTDOWN(http),
71 NULL,
72 PHP_RSHUTDOWN(http),
73 PHP_MINFO(http),
74 PHP_PECL_HTTP_VERSION,
75 STANDARD_MODULE_PROPERTIES
76 };
77
78 int http_module_number;
79
80 #if PHP_DEBUG && !HAVE_GCOV
81 void _dpf(int type, const char *data, size_t length)
82 {
83 static const char _sym[] = "><><><";
84 if (type) {
85 int nwp = 0;
86 for (fprintf(stderr, "%c ", _sym[type-1]); length--; data++) {
87 int ip = PHP_HTTP_IS_CTYPE(print, *data);
88 if (!ip && *data != '\r' && *data != '\n') nwp = 1;
89 fprintf(stderr, ip?"%c":"\\x%02x", (int) (*data & 0xff));
90 if (!nwp && *data == '\n' && length) {
91 fprintf(stderr, "\n%c ", _sym[type-1]);
92 }
93 }
94 fprintf(stderr, "\n");
95 } else {
96 fprintf(stderr, "# %.*s\n", (int) length, data);
97 }
98 }
99 #endif
100
101 static void php_http_globals_init_once(zend_php_http_globals *G)
102 {
103 memset(G, 0, sizeof(*G));
104 }
105
106 #if 0
107 static inline void php_http_globals_init(zend_php_http_globals *G TSRMLS_DC)
108 {
109 }
110
111 static inline void php_http_globals_free(zend_php_http_globals *G TSRMLS_DC)
112 {
113 }
114 #endif
115
116 #if ZTS && PHP_DEBUG && !HAVE_GCOV
117 zend_php_http_globals *php_http_globals(void)
118 {
119 TSRMLS_FETCH();
120 return PHP_HTTP_G;
121 }
122 #endif
123
124 PHP_INI_BEGIN()
125 STD_PHP_INI_ENTRY("http.etag.mode", "crc32b", PHP_INI_ALL, OnUpdateString, env.etag_mode, zend_php_http_globals, php_http_globals)
126 PHP_INI_END()
127
128 PHP_MINIT_FUNCTION(http)
129 {
130 http_module_number = module_number;
131 ZEND_INIT_MODULE_GLOBALS(php_http, php_http_globals_init_once, NULL);
132 REGISTER_INI_ENTRIES();
133
134 if (0
135 || SUCCESS != PHP_MINIT_CALL(http_exception)
136 || SUCCESS != PHP_MINIT_CALL(http_cookie)
137 || SUCCESS != PHP_MINIT_CALL(http_encoding)
138 || SUCCESS != PHP_MINIT_CALL(http_filter)
139 || SUCCESS != PHP_MINIT_CALL(http_header)
140 || SUCCESS != PHP_MINIT_CALL(http_header_parser)
141 || SUCCESS != PHP_MINIT_CALL(http_message)
142 || SUCCESS != PHP_MINIT_CALL(http_message_parser)
143 || SUCCESS != PHP_MINIT_CALL(http_message_body)
144 || SUCCESS != PHP_MINIT_CALL(http_querystring)
145 || SUCCESS != PHP_MINIT_CALL(http_client)
146 || SUCCESS != PHP_MINIT_CALL(http_client_request)
147 || SUCCESS != PHP_MINIT_CALL(http_client_response)
148 #if PHP_HTTP_HAVE_CURL
149 || SUCCESS != PHP_MINIT_CALL(http_curl)
150 || SUCCESS != PHP_MINIT_CALL(http_client_curl)
151 #endif
152 || SUCCESS != PHP_MINIT_CALL(http_url)
153 || SUCCESS != PHP_MINIT_CALL(http_env)
154 || SUCCESS != PHP_MINIT_CALL(http_env_request)
155 || SUCCESS != PHP_MINIT_CALL(http_env_response)
156 || SUCCESS != PHP_MINIT_CALL(http_params)
157 ) {
158 return FAILURE;
159 }
160
161 return SUCCESS;
162 }
163
164
165
166 PHP_MSHUTDOWN_FUNCTION(http)
167 {
168 UNREGISTER_INI_ENTRIES();
169
170 if (0
171 || SUCCESS != PHP_MSHUTDOWN_CALL(http_message)
172 #if PHP_HTTP_HAVE_CURL
173 || SUCCESS != PHP_MSHUTDOWN_CALL(http_client_curl)
174 || SUCCESS != PHP_MSHUTDOWN_CALL(http_curl)
175 #endif
176 || SUCCESS != PHP_MSHUTDOWN_CALL(http_client)
177 ) {
178 return FAILURE;
179 }
180
181 return SUCCESS;
182 }
183
184 PHP_RSHUTDOWN_FUNCTION(http)
185 {
186 if (0
187 || SUCCESS != PHP_RSHUTDOWN_CALL(http_env)
188 ) {
189 return FAILURE;
190 }
191
192 return SUCCESS;
193 }
194
195 PHP_MINFO_FUNCTION(http)
196 {
197 php_http_buffer_t buf;
198
199 php_http_buffer_init(&buf);
200
201 php_info_print_table_start();
202 php_info_print_table_header(2, "HTTP Support", "enabled");
203 php_info_print_table_row(2, "Extension Version", PHP_PECL_HTTP_VERSION);
204 php_info_print_table_end();
205
206 php_info_print_table_start();
207 php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
208 php_info_print_table_row(3, "libz", ZLIB_VERSION, zlibVersion());
209 #if PHP_HTTP_HAVE_CURL
210 {
211 curl_version_info_data *cv = curl_version_info(CURLVERSION_NOW);
212 php_info_print_table_row(3, "libcurl", LIBCURL_VERSION, cv->version);
213 }
214 #else
215 php_info_print_table_row(3, "libcurl", "disabled", "disabled");
216 #endif
217
218 #if PHP_HTTP_HAVE_EVENT
219 php_info_print_table_row(3, "libevent",
220 # ifdef LIBEVENT_VERSION
221 LIBEVENT_VERSION,
222 # else
223 PHP_HTTP_EVENT_VERSION,
224 # endif
225 event_get_version());
226 #else
227 php_info_print_table_row(3, "libevent", "disabled", "disabled");
228 #endif
229
230 php_info_print_table_end();
231
232 DISPLAY_INI_ENTRIES();
233 }
234
235
236 /*
237 * Local variables:
238 * tab-width: 4
239 * c-basic-offset: 4
240 * End:
241 * vim600: noet sw=4 ts=4 fdm=marker
242 * vim<600: noet sw=4 ts=4
243 */
244