names changing )
[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 # 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 #if PHP_DEBUG && !HAVE_GCOV
83 void _dpf(int type, const char *data, size_t length)
84 {
85 static const char _sym[] = "><><><";
86 if (type) {
87 int nwp = 0;
88 for (fprintf(stderr, "%c ", _sym[type-1]); length--; data++) {
89 int ip = PHP_HTTP_IS_CTYPE(print, *data);
90 if (!ip && *data != '\r' && *data != '\n') nwp = 1;
91 fprintf(stderr, ip?"%c":"\\x%02x", (int) (*data & 0xff));
92 if (!nwp && *data == '\n' && length) {
93 fprintf(stderr, "\n%c ", _sym[type-1]);
94 }
95 }
96 fprintf(stderr, "\n");
97 } else {
98 fprintf(stderr, "# %.*s\n", (int) length, data);
99 }
100 }
101 #endif
102
103 static void php_http_globals_init_once(zend_php_http_globals *G)
104 {
105 memset(G, 0, sizeof(*G));
106 }
107
108 #if 0
109 static inline void php_http_globals_init(zend_php_http_globals *G TSRMLS_DC)
110 {
111 }
112
113 static inline void php_http_globals_free(zend_php_http_globals *G TSRMLS_DC)
114 {
115 }
116 #endif
117
118 #if ZTS && PHP_DEBUG && !HAVE_GCOV
119 zend_php_http_globals *php_http_globals(void)
120 {
121 TSRMLS_FETCH();
122 return PHP_HTTP_G;
123 }
124 #endif
125
126 PHP_INI_BEGIN()
127 STD_PHP_INI_ENTRY("http.etag.mode", "crc32b", PHP_INI_ALL, OnUpdateString, env.etag_mode, zend_php_http_globals, php_http_globals)
128 PHP_INI_END()
129
130 PHP_MINIT_FUNCTION(http)
131 {
132 http_module_number = module_number;
133 ZEND_INIT_MODULE_GLOBALS(php_http, php_http_globals_init_once, NULL);
134 REGISTER_INI_ENTRIES();
135
136 if (0
137 || SUCCESS != PHP_MINIT_CALL(http_object)
138 || SUCCESS != PHP_MINIT_CALL(http_exception)
139 || SUCCESS != PHP_MINIT_CALL(http_cookie)
140 || SUCCESS != PHP_MINIT_CALL(http_encoding)
141 || SUCCESS != PHP_MINIT_CALL(http_filter)
142 || SUCCESS != PHP_MINIT_CALL(http_header)
143 || SUCCESS != PHP_MINIT_CALL(http_message)
144 || SUCCESS != PHP_MINIT_CALL(http_message_body)
145 || SUCCESS != PHP_MINIT_CALL(http_querystring)
146 || SUCCESS != PHP_MINIT_CALL(http_client)
147 || SUCCESS != PHP_MINIT_CALL(http_client_request)
148 || SUCCESS != PHP_MINIT_CALL(http_client_response)
149 #if PHP_HTTP_HAVE_CURL
150 || SUCCESS != PHP_MINIT_CALL(http_curl)
151 || SUCCESS != PHP_MINIT_CALL(http_client_curl)
152 #endif
153 || SUCCESS != PHP_MINIT_CALL(http_url)
154 || SUCCESS != PHP_MINIT_CALL(http_env)
155 || SUCCESS != PHP_MINIT_CALL(http_env_request)
156 || SUCCESS != PHP_MINIT_CALL(http_env_response)
157 || SUCCESS != PHP_MINIT_CALL(http_params)
158 ) {
159 return FAILURE;
160 }
161
162 return SUCCESS;
163 }
164
165
166
167 PHP_MSHUTDOWN_FUNCTION(http)
168 {
169 UNREGISTER_INI_ENTRIES();
170
171 if (0
172 || SUCCESS != PHP_MSHUTDOWN_CALL(http_message)
173 #if PHP_HTTP_HAVE_CURL
174 || SUCCESS != PHP_MSHUTDOWN_CALL(http_client_curl)
175 || SUCCESS != PHP_MSHUTDOWN_CALL(http_curl)
176 #endif
177 || SUCCESS != PHP_MSHUTDOWN_CALL(http_client)
178 ) {
179 return FAILURE;
180 }
181
182 return SUCCESS;
183 }
184
185 PHP_RINIT_FUNCTION(http)
186 {
187 if (0
188 || SUCCESS != PHP_RINIT_CALL(http_env)
189 #if PHP_HTTP_HAVE_CURL && PHP_HTTP_HAVE_EVENT
190 || SUCCESS != PHP_RINIT_CALL(http_client_curl)
191 #endif
192 ) {
193 return FAILURE;
194 }
195
196 return SUCCESS;
197 }
198
199 PHP_RSHUTDOWN_FUNCTION(http)
200 {
201 if (0
202 #if PHP_HTTP_HAVE_CURL && PHP_HTTP_HAVE_EVENT
203 || SUCCESS != PHP_RSHUTDOWN_CALL(http_client_curl)
204 #endif
205 || SUCCESS != PHP_RSHUTDOWN_CALL(http_env)
206 ) {
207 return FAILURE;
208 }
209
210 return SUCCESS;
211 }
212
213 PHP_MINFO_FUNCTION(http)
214 {
215 php_http_buffer_t buf;
216
217 php_http_buffer_init(&buf);
218
219 php_info_print_table_start();
220 php_info_print_table_header(2, "HTTP Support", "enabled");
221 php_info_print_table_row(2, "Extension Version", PHP_HTTP_EXT_VERSION);
222 php_info_print_table_end();
223
224 php_info_print_table_start();
225 php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
226 php_info_print_table_row(3, "libz", ZLIB_VERSION, zlibVersion());
227 #if PHP_HTTP_HAVE_CURL
228 {
229 curl_version_info_data *cv = curl_version_info(CURLVERSION_NOW);
230 php_info_print_table_row(3, "libcurl", LIBCURL_VERSION, cv->version);
231 }
232 #else
233 php_info_print_table_row(3, "libcurl", "disabled", "disabled");
234 #endif
235
236 #if PHP_HTTP_HAVE_EVENT
237 php_info_print_table_row(3, "libevent",
238 # ifdef LIBEVENT_VERSION
239 LIBEVENT_VERSION,
240 # else
241 PHP_HTTP_EVENT_VERSION,
242 # endif
243 event_get_version());
244 #else
245 php_info_print_table_row(3, "libevent", "disabled", "disabled");
246 #endif
247
248 php_info_print_table_end();
249
250 DISPLAY_INI_ENTRIES();
251 }
252
253
254 /*
255 * Local variables:
256 * tab-width: 4
257 * c-basic-offset: 4
258 * End:
259 * vim600: noet sw=4 ts=4 fdm=marker
260 * vim<600: noet sw=4 ts=4
261 */
262