Merge branch 'v2.6.x'
[m6w6/ext-http] / src / 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_IDN2
32 # include <idn2.h>
33 #elif PHP_HTTP_HAVE_IDN
34 # include <idna.h>
35 #endif
36
37 ZEND_DECLARE_MODULE_GLOBALS(php_http);
38
39 #ifdef COMPILE_DL_HTTP
40 ZEND_GET_MODULE(http)
41 #endif
42
43 zend_function_entry http_functions[] = {
44 EMPTY_FUNCTION_ENTRY
45 };
46
47 PHP_MINIT_FUNCTION(http);
48 PHP_MSHUTDOWN_FUNCTION(http);
49 PHP_RSHUTDOWN_FUNCTION(http);
50 PHP_MINFO_FUNCTION(http);
51
52 static zend_module_dep http_module_deps[] = {
53 ZEND_MOD_REQUIRED("raphf")
54 ZEND_MOD_REQUIRED("propro")
55 ZEND_MOD_REQUIRED("spl")
56 #ifdef PHP_HTTP_HAVE_HASH
57 ZEND_MOD_REQUIRED("hash")
58 #endif
59 #ifdef PHP_HTTP_HAVE_ICONV
60 ZEND_MOD_REQUIRED("iconv")
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 NULL,
74 PHP_RSHUTDOWN(http),
75 PHP_MINFO(http),
76 PHP_PECL_HTTP_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)
110 {
111 }
112
113 static inline void php_http_globals_free(zend_php_http_globals *G)
114 {
115 }
116 #endif
117
118 PHP_INI_BEGIN()
119 STD_PHP_INI_ENTRY("http.etag.mode", "crc32b", PHP_INI_ALL, OnUpdateString, env.etag_mode, zend_php_http_globals, php_http_globals)
120 PHP_INI_END()
121
122 PHP_MINIT_FUNCTION(http)
123 {
124 http_module_number = module_number;
125 ZEND_INIT_MODULE_GLOBALS(php_http, php_http_globals_init_once, NULL);
126 REGISTER_INI_ENTRIES();
127
128 if (0
129 || SUCCESS != PHP_MINIT_CALL(http_object)
130 || SUCCESS != PHP_MINIT_CALL(http_exception)
131 || SUCCESS != PHP_MINIT_CALL(http_cookie)
132 || SUCCESS != PHP_MINIT_CALL(http_encoding)
133 || SUCCESS != PHP_MINIT_CALL(http_filter)
134 || SUCCESS != PHP_MINIT_CALL(http_header)
135 || SUCCESS != PHP_MINIT_CALL(http_header_parser)
136 || SUCCESS != PHP_MINIT_CALL(http_message)
137 || SUCCESS != PHP_MINIT_CALL(http_message_parser)
138 || SUCCESS != PHP_MINIT_CALL(http_message_body)
139 || SUCCESS != PHP_MINIT_CALL(http_querystring)
140 || SUCCESS != PHP_MINIT_CALL(http_client)
141 || SUCCESS != PHP_MINIT_CALL(http_client_request)
142 || SUCCESS != PHP_MINIT_CALL(http_client_response)
143 #if PHP_HTTP_HAVE_CURL
144 || SUCCESS != PHP_MINIT_CALL(http_curl)
145 || SUCCESS != PHP_MINIT_CALL(http_client_curl)
146 || SUCCESS != PHP_MINIT_CALL(http_client_curl_user)
147 #endif
148 || SUCCESS != PHP_MINIT_CALL(http_url)
149 || SUCCESS != PHP_MINIT_CALL(http_env)
150 || SUCCESS != PHP_MINIT_CALL(http_env_request)
151 || SUCCESS != PHP_MINIT_CALL(http_env_response)
152 || SUCCESS != PHP_MINIT_CALL(http_params)
153 ) {
154 return FAILURE;
155 }
156
157 return SUCCESS;
158 }
159
160
161
162 PHP_MSHUTDOWN_FUNCTION(http)
163 {
164 UNREGISTER_INI_ENTRIES();
165
166 if (0
167 || SUCCESS != PHP_MSHUTDOWN_CALL(http_message)
168 #if PHP_HTTP_HAVE_CURL
169 || SUCCESS != PHP_MSHUTDOWN_CALL(http_client_curl)
170 || SUCCESS != PHP_MSHUTDOWN_CALL(http_curl)
171 #endif
172 || SUCCESS != PHP_MSHUTDOWN_CALL(http_client)
173 ) {
174 return FAILURE;
175 }
176
177 return SUCCESS;
178 }
179
180 PHP_RSHUTDOWN_FUNCTION(http)
181 {
182 if (0
183 || SUCCESS != PHP_RSHUTDOWN_CALL(http_env)
184 ) {
185 return FAILURE;
186 }
187
188 return SUCCESS;
189 }
190
191 PHP_MINFO_FUNCTION(http)
192 {
193 php_http_buffer_t buf;
194
195 php_http_buffer_init(&buf);
196
197 php_info_print_table_start();
198 php_info_print_table_header(2, "HTTP Support", "enabled");
199 php_info_print_table_row(2, "Extension Version", PHP_PECL_HTTP_VERSION);
200 php_info_print_table_end();
201
202 php_info_print_table_start();
203 php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
204 php_info_print_table_row(3, "libz", ZLIB_VERSION, zlibVersion());
205 #if PHP_HTTP_HAVE_CURL
206 {
207 curl_version_info_data *cv = curl_version_info(CURLVERSION_NOW);
208 php_info_print_table_row(3, "libcurl", LIBCURL_VERSION, cv->version);
209 }
210 #else
211 php_info_print_table_row(3, "libcurl", "disabled", "disabled");
212 #endif
213
214 #if PHP_HTTP_HAVE_EVENT
215 php_info_print_table_row(3, "libevent",
216 # ifdef LIBEVENT_VERSION
217 LIBEVENT_VERSION,
218 # else
219 PHP_HTTP_EVENT_VERSION,
220 # endif
221 event_get_version());
222 #else
223 php_info_print_table_row(3, "libevent", "disabled", "disabled");
224 #endif
225
226 #if PHP_HTTP_HAVE_IDN2
227 php_info_print_table_row(3, "libidn2 (IDNA2008)", IDN2_VERSION, idn2_check_version(NULL));
228 #elif PHP_HTTP_HAVE_IDN
229 php_info_print_table_row(3, "libidn (IDNA2003)", PHP_HTTP_LIBIDN_VERSION, "unknown");
230 #endif
231
232 php_info_print_table_end();
233
234 DISPLAY_INI_ENTRIES();
235 }
236
237
238 /*
239 * Local variables:
240 * tab-width: 4
241 * c-basic-offset: 4
242 * End:
243 * vim600: noet sw=4 ts=4 fdm=marker
244 * vim<600: noet sw=4 ts=4
245 */
246