* try the direct way
[m6w6/ext-http] / http.c
1 /*
2 +----------------------------------------------------------------------+
3 | PECL :: http |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.0 of the PHP license, that |
6 | is bundled with this package in the file LICENSE, and is available |
7 | through the world-wide-web at http://www.php.net/license/3_0.txt. |
8 | If you did not receive a copy of the PHP license and are unable to |
9 | obtain it through the world-wide-web, please send a note to |
10 | license@php.net so we can mail you a copy immediately. |
11 +----------------------------------------------------------------------+
12 | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
13 +----------------------------------------------------------------------+
14 */
15
16 /* $Id$ */
17
18
19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 #endif
22
23 #ifdef HTTP_HAVE_CURL
24 # ifdef PHP_WIN32
25 # include <winsock2.h>
26 # endif
27 # include <curl/curl.h>
28 #endif
29
30 #include "php.h"
31 #include "php_ini.h"
32 #include "snprintf.h"
33 #include "ext/standard/info.h"
34 #include "ext/session/php_session.h"
35 #include "ext/standard/php_string.h"
36 #include "ext/standard/php_smart_str.h"
37
38 #include "SAPI.h"
39
40 #include "php_http.h"
41 #include "php_http_api.h"
42 #include "php_http_curl_api.h"
43 #include "php_http_std_defs.h"
44
45 #include "phpstr/phpstr.h"
46
47 #ifdef HTTP_HAVE_CURL
48 /* {{{ ARG_INFO */
49 # ifdef ZEND_BEGIN_ARG_INFO
50 ZEND_BEGIN_ARG_INFO(http_request_info_ref_3, 0)
51 ZEND_ARG_PASS_INFO(0)
52 ZEND_ARG_PASS_INFO(0)
53 ZEND_ARG_PASS_INFO(1)
54 ZEND_END_ARG_INFO();
55
56 ZEND_BEGIN_ARG_INFO(http_request_info_ref_4, 0)
57 ZEND_ARG_PASS_INFO(0)
58 ZEND_ARG_PASS_INFO(0)
59 ZEND_ARG_PASS_INFO(0)
60 ZEND_ARG_PASS_INFO(1)
61 ZEND_END_ARG_INFO();
62 # else
63 static unsigned char http_request_info_ref_3[] = {3, BYREF_NONE, BYREF_NONE, BYREF_FORCE};
64 static unsigned char http_request_info_ref_4[] = {4, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE};
65 # endif
66 /* }}} ARG_INFO */
67
68 #endif /* HTTP_HAVE_CURL */
69
70 ZEND_DECLARE_MODULE_GLOBALS(http)
71
72 #ifdef COMPILE_DL_HTTP
73 ZEND_GET_MODULE(http)
74 #endif
75
76 /* {{{ http_functions[] */
77 function_entry http_functions[] = {
78 PHP_FE(http_test, NULL)
79 PHP_FE(http_date, NULL)
80 PHP_FE(http_absolute_uri, NULL)
81 PHP_FE(http_negotiate_language, NULL)
82 PHP_FE(http_negotiate_charset, NULL)
83 PHP_FE(http_redirect, NULL)
84 PHP_FE(http_send_status, NULL)
85 PHP_FE(http_send_last_modified, NULL)
86 PHP_FE(http_send_content_type, NULL)
87 PHP_FE(http_send_content_disposition, NULL)
88 PHP_FE(http_match_modified, NULL)
89 PHP_FE(http_match_etag, NULL)
90 PHP_FE(http_cache_last_modified, NULL)
91 PHP_FE(http_cache_etag, NULL)
92 PHP_FE(http_send_data, NULL)
93 PHP_FE(http_send_file, NULL)
94 PHP_FE(http_send_stream, NULL)
95 PHP_FE(http_chunked_decode, NULL)
96 PHP_FE(http_split_response, NULL)
97 PHP_FE(http_parse_headers, NULL)
98 PHP_FE(http_get_request_headers, NULL)
99 #ifdef HTTP_HAVE_CURL
100 PHP_FE(http_get, http_request_info_ref_3)
101 PHP_FE(http_head, http_request_info_ref_3)
102 PHP_FE(http_post_data, http_request_info_ref_4)
103 PHP_FE(http_post_array, http_request_info_ref_4)
104 #endif
105 PHP_FE(http_auth_basic, NULL)
106 PHP_FE(http_auth_basic_cb, NULL)
107 #ifndef ZEND_ENGINE_2
108 PHP_FE(http_build_query, NULL)
109 #endif
110 PHP_FE(ob_httpetaghandler, NULL)
111 {NULL, NULL, NULL}
112 };
113 /* }}} */
114
115
116 #ifdef ZEND_ENGINE_2
117
118 /* {{{ HttpUtil */
119
120 zend_class_entry *http_util_ce;
121
122 #define HTTP_UTIL_ME(me, al, ai) ZEND_FENTRY(me, ZEND_FN(al), ai, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
123
124 zend_function_entry http_util_class_methods[] = {
125 HTTP_UTIL_ME(date, http_date, NULL)
126 HTTP_UTIL_ME(absoluteURI, http_absolute_uri, NULL)
127 HTTP_UTIL_ME(negotiateLanguage, http_negotiate_language, NULL)
128 HTTP_UTIL_ME(negotiateCharset, http_negotiate_charset, NULL)
129 HTTP_UTIL_ME(redirect, http_redirect, NULL)
130 HTTP_UTIL_ME(sendStatus, http_send_status, NULL)
131 HTTP_UTIL_ME(sendLastModified, http_send_last_modified, NULL)
132 HTTP_UTIL_ME(sendContentType, http_send_content_type, NULL)
133 HTTP_UTIL_ME(sendContentDisposition, http_send_content_disposition, NULL)
134 HTTP_UTIL_ME(matchModified, http_match_modified, NULL)
135 HTTP_UTIL_ME(matchEtag, http_match_etag, NULL)
136 HTTP_UTIL_ME(cacheLastModified, http_cache_last_modified, NULL)
137 HTTP_UTIL_ME(cacheEtag, http_cache_etag, NULL)
138 HTTP_UTIL_ME(chunkedDecode, http_chunked_decode, NULL)
139 HTTP_UTIL_ME(splitResponse, http_split_response, NULL)
140 HTTP_UTIL_ME(parseHeaders, http_parse_headers, NULL)
141 HTTP_UTIL_ME(getRequestHeaders, http_get_request_headers, NULL)
142 #ifdef HTTP_HAVE_CURL
143 HTTP_UTIL_ME(get, http_get, http_request_info_ref_3)
144 HTTP_UTIL_ME(head, http_head, http_request_info_ref_3)
145 HTTP_UTIL_ME(postData, http_post_data, http_request_info_ref_4)
146 HTTP_UTIL_ME(postArray, http_post_array, http_request_info_ref_4)
147 #endif
148 HTTP_UTIL_ME(authBasic, http_auth_basic, NULL)
149 HTTP_UTIL_ME(authBasicCallback, http_auth_basic_cb, NULL)
150 {NULL, NULL, NULL}
151 };
152 /* }}} HttpUtil */
153
154 /* {{{ HttpResponse */
155
156 zend_class_entry *http_response_ce;
157 static zend_object_handlers http_response_object_handlers;
158
159 #define http_response_declare_default_properties(ce) _http_response_declare_default_properties(ce TSRMLS_CC)
160 static inline void _http_response_declare_default_properties(zend_class_entry *ce TSRMLS_DC)
161 {
162 DCL_PROP(PROTECTED, string, contentType, "application/x-octetstream");
163 DCL_PROP(PROTECTED, string, eTag, "");
164 DCL_PROP(PROTECTED, string, dispoFile, "");
165 DCL_PROP(PROTECTED, string, cacheControl, "public");
166 DCL_PROP(PROTECTED, string, data, "");
167 DCL_PROP(PROTECTED, string, file, "");
168 DCL_PROP(PROTECTED, long, stream, 0);
169 DCL_PROP(PROTECTED, long, lastModified, 0);
170 DCL_PROP(PROTECTED, long, dispoInline, 0);
171 DCL_PROP(PROTECTED, long, cache, 0);
172 DCL_PROP(PROTECTED, long, gzip, 0);
173
174 DCL_PROP(PRIVATE, long, raw_cache_header, 0);
175 DCL_PROP(PRIVATE, long, send_mode, -1);
176 }
177
178 #define http_response_destroy_object _http_response_destroy_object
179 void _http_response_destroy_object(void *object, zend_object_handle handle TSRMLS_DC)
180 {
181 http_response_object *o = object;
182 if (OBJ_PROP(o)) {
183 zend_hash_destroy(OBJ_PROP(o));
184 FREE_HASHTABLE(OBJ_PROP(o));
185 }
186 efree(o);
187 }
188
189 #define http_response_new_object _http_response_new_object
190 zend_object_value _http_response_new_object(zend_class_entry *ce TSRMLS_DC)
191 {
192 zend_object_value ov;
193 http_response_object *o;
194
195 o = ecalloc(1, sizeof(http_response_object));
196 o->zo.ce = ce;
197
198 ALLOC_HASHTABLE(OBJ_PROP(o));
199 zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0);
200 zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
201
202 ov.handle = zend_objects_store_put(o, http_response_destroy_object, NULL, NULL TSRMLS_CC);
203 ov.handlers = &http_response_object_handlers;
204
205 return ov;
206 }
207
208 zend_function_entry http_response_class_methods[] = {
209 PHP_ME(HttpResponse, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
210 /* PHP_ME(HttpResponse, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
211 */
212 PHP_ME(HttpResponse, setETag, NULL, ZEND_ACC_PUBLIC)
213 PHP_ME(HttpResponse, getETag, NULL, ZEND_ACC_PUBLIC)
214
215 PHP_ME(HttpResponse, setContentDisposition, NULL, ZEND_ACC_PUBLIC)
216 PHP_ME(HttpResponse, getContentDisposition, NULL, ZEND_ACC_PUBLIC)
217
218 PHP_ME(HttpResponse, setContentType, NULL, ZEND_ACC_PUBLIC)
219 PHP_ME(HttpResponse, getContentType, NULL, ZEND_ACC_PUBLIC)
220
221 PHP_ME(HttpResponse, setCache, NULL, ZEND_ACC_PUBLIC)
222 PHP_ME(HttpResponse, getCache, NULL, ZEND_ACC_PUBLIC)
223
224 PHP_ME(HttpResponse, setCacheControl, NULL, ZEND_ACC_PUBLIC)
225 PHP_ME(HttpResponse, getCacheControl, NULL, ZEND_ACC_PUBLIC)
226
227 PHP_ME(HttpResponse, setGzip, NULL, ZEND_ACC_PUBLIC)
228 PHP_ME(HttpResponse, getGzip, NULL, ZEND_ACC_PUBLIC)
229
230 PHP_ME(HttpResponse, setData, NULL, ZEND_ACC_PUBLIC)
231 PHP_ME(HttpResponse, getData, NULL, ZEND_ACC_PUBLIC)
232
233 PHP_ME(HttpResponse, setFile, NULL, ZEND_ACC_PUBLIC)
234 PHP_ME(HttpResponse, getFile, NULL, ZEND_ACC_PUBLIC)
235
236 PHP_ME(HttpResponse, setStream, NULL, ZEND_ACC_PUBLIC)
237 PHP_ME(HttpResponse, getStream, NULL, ZEND_ACC_PUBLIC)
238
239 PHP_ME(HttpResponse, send, NULL, ZEND_ACC_PUBLIC)
240
241 {NULL, NULL, NULL}
242 };
243 /* }}} */
244
245 /* {{{ HttpRequest */
246 #ifdef HTTP_HAVE_CURL
247
248 zend_class_entry *http_request_ce;
249 static zend_object_handlers http_request_object_handlers;
250
251 #define http_request_declare_default_properties(ce) _http_request_declare_default_properties(ce TSRMLS_CC)
252 static inline void _http_request_declare_default_properties(zend_class_entry *ce TSRMLS_DC)
253 {
254 DCL_PROP_N(PROTECTED, options);
255 DCL_PROP_N(PROTECTED, responseInfo);
256 DCL_PROP_N(PROTECTED, responseData);
257 DCL_PROP_N(PROTECTED, postData);
258 DCL_PROP_N(PROTECTED, postFiles);
259
260 DCL_PROP(PROTECTED, long, method, HTTP_GET);
261
262 DCL_PROP(PROTECTED, string, url, "");
263 DCL_PROP(PROTECTED, string, contentType, "");
264 DCL_PROP(PROTECTED, string, queryData, "");
265 DCL_PROP(PROTECTED, string, postData, "");
266 }
267
268 #define http_request_free_object _http_request_free_object
269 void _http_request_free_object(zend_object /* void */ *object TSRMLS_DC)
270 {
271 http_request_object *o = (http_request_object *) object;
272
273 if (OBJ_PROP(o)) {
274 zend_hash_destroy(OBJ_PROP(o));
275 FREE_HASHTABLE(OBJ_PROP(o));
276 }
277 if (o->ch) {
278 curl_easy_cleanup(o->ch);
279 o->ch = NULL;
280 }
281 efree(o);
282 }
283
284 #define http_request_new_object _http_request_new_object
285 zend_object_value _http_request_new_object(zend_class_entry *ce TSRMLS_DC)
286 {
287 zend_object_value ov;
288 http_request_object *o;
289
290 o = ecalloc(1, sizeof(http_request_object));
291 o->zo.ce = ce;
292 o->ch = curl_easy_init();
293
294 ALLOC_HASHTABLE(OBJ_PROP(o));
295 zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0);
296 zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
297
298 ov.handle = zend_objects_store_put(o, (zend_objects_store_dtor_t) zend_objects_destroy_object, http_request_free_object, NULL TSRMLS_CC);
299 ov.handlers = &http_request_object_handlers;
300
301 return ov;
302 }
303
304 zend_function_entry http_request_class_methods[] = {
305 PHP_ME(HttpRequest, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
306 PHP_ME(HttpRequest, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
307
308 PHP_ME(HttpRequest, setOptions, NULL, ZEND_ACC_PUBLIC)
309 PHP_ME(HttpRequest, getOptions, NULL, ZEND_ACC_PUBLIC)
310 PHP_ME(HttpRequest, unsetOptions, NULL, ZEND_ACC_PUBLIC)
311
312 PHP_ME(HttpRequest, addHeader, NULL, ZEND_ACC_PUBLIC)
313 PHP_ME(HttpRequest, addCookie, NULL, ZEND_ACC_PUBLIC)
314
315 PHP_ME(HttpRequest, setMethod, NULL, ZEND_ACC_PUBLIC)
316 PHP_ME(HttpRequest, getMethod, NULL, ZEND_ACC_PUBLIC)
317
318 PHP_ME(HttpRequest, setURL, NULL, ZEND_ACC_PUBLIC)
319 PHP_ME(HttpRequest, getURL, NULL, ZEND_ACC_PUBLIC)
320
321 PHP_ME(HttpRequest, setContentType, NULL, ZEND_ACC_PUBLIC)
322 PHP_ME(HttpRequest, getContentType, NULL, ZEND_ACC_PUBLIC)
323
324 PHP_ME(HttpRequest, setQueryData, NULL, ZEND_ACC_PUBLIC)
325 PHP_ME(HttpRequest, getQueryData, NULL, ZEND_ACC_PUBLIC)
326 PHP_ME(HttpRequest, addQueryData, NULL, ZEND_ACC_PUBLIC)
327 PHP_ME(HttpRequest, unsetQueryData, NULL, ZEND_ACC_PUBLIC)
328
329 PHP_ME(HttpRequest, setPostData, NULL, ZEND_ACC_PUBLIC)
330 PHP_ME(HttpRequest, getPostData, NULL, ZEND_ACC_PUBLIC)
331 PHP_ME(HttpRequest, addPostData, NULL, ZEND_ACC_PUBLIC)
332 PHP_ME(HttpRequest, unsetPostData, NULL, ZEND_ACC_PUBLIC)
333
334 PHP_ME(HttpRequest, addPostFile, NULL, ZEND_ACC_PUBLIC)
335 PHP_ME(HttpRequest, getPostFiles, NULL, ZEND_ACC_PUBLIC)
336 PHP_ME(HttpRequest, unsetPostFiles, NULL, ZEND_ACC_PUBLIC)
337
338 PHP_ME(HttpRequest, send, NULL, ZEND_ACC_PUBLIC)
339
340 PHP_ME(HttpRequest, getResponseData, NULL, ZEND_ACC_PUBLIC)
341 PHP_ME(HttpRequest, getResponseHeader, NULL, ZEND_ACC_PUBLIC)
342 PHP_ME(HttpRequest, getResponseCode, NULL, ZEND_ACC_PUBLIC)
343 PHP_ME(HttpRequest, getResponseBody, NULL, ZEND_ACC_PUBLIC)
344 PHP_ME(HttpRequest, getResponseInfo, NULL, ZEND_ACC_PUBLIC)
345
346 {NULL, NULL, NULL}
347 };
348
349 #endif /* HTTP_HAVE_CURL */
350 /* }}} */
351
352 #endif /* ZEND_ENGINE_2 */
353
354 /* {{{ http_module_entry */
355 zend_module_entry http_module_entry = {
356 #if ZEND_MODULE_API_NO >= 20010901
357 STANDARD_MODULE_HEADER,
358 #endif
359 "http",
360 http_functions,
361 PHP_MINIT(http),
362 PHP_MSHUTDOWN(http),
363 PHP_RINIT(http),
364 PHP_RSHUTDOWN(http),
365 PHP_MINFO(http),
366 #if ZEND_MODULE_API_NO >= 20010901
367 HTTP_PEXT_VERSION,
368 #endif
369 STANDARD_MODULE_PROPERTIES
370 };
371 /* }}} */
372
373
374 static void free_to_free(void *s)
375 {
376 efree(*(char **)s);
377 }
378
379 /* {{{ php_http_init_globals(zend_http_globals *) */
380 static void php_http_init_globals(zend_http_globals *http_globals)
381 {
382 http_globals->etag_started = 0;
383 http_globals->ctype = NULL;
384 http_globals->etag = NULL;
385 http_globals->lmod = 0;
386 #ifdef HTTP_HAVE_CURL
387 phpstr_init_ex(&http_globals->curlbuf, HTTP_CURLBUF_SIZE, 0);
388 zend_llist_init(&http_globals->to_free, sizeof(char *), free_to_free, 0);
389 #endif
390 http_globals->allowed_methods = NULL;
391 }
392 /* }}} */
393
394 /* {{{ static inline STATUS http_check_allowed_methods(char *, int) */
395 #define http_check_allowed_methods(m, l) _http_check_allowed_methods((m), (l) TSRMLS_CC)
396 static inline void _http_check_allowed_methods(char *methods, int length TSRMLS_DC)
397 {
398 if (length && SG(request_info).request_method && (!strstr(methods, SG(request_info).request_method))) {
399 char *allow_header = emalloc(length + sizeof("Allow: "));
400 sprintf(allow_header, "Allow: %s", methods);
401 http_send_header(allow_header);
402 efree(allow_header);
403 http_send_status(405);
404 zend_bailout();
405 }
406 }
407 /* }}} */
408
409 /* {{{ PHP_INI */
410 PHP_INI_MH(update_allowed_methods)
411 {
412 http_check_allowed_methods(new_value, new_value_length);
413 return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
414 }
415
416 PHP_INI_BEGIN()
417 STD_PHP_INI_ENTRY("http.allowed_methods",
418 /* HTTP 1.1 */
419 "GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE, CONNECT, "
420 /* WebDAV - RFC 2518 * /
421 "PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, "
422 /* WebDAV Versioning - RFC 3253 * /
423 "VERSION-CONTROL, REPORT, CHECKOUT, CHECKIN, UNCHECKOUT, "
424 "MKWORKSPACE, UPDATE, LABEL, MERGE, BASELINE-CONTROL, MKACTIVITY, "
425 /* WebDAV Access Control - RFC 3744 * /
426 "ACL, "
427 /* END */
428 ,
429 PHP_INI_ALL, update_allowed_methods, allowed_methods, zend_http_globals, http_globals)
430 PHP_INI_END()
431 /* }}} */
432
433 /* {{{ HTTP_CURL_USE_ZEND_MM */
434 #if defined(HTTP_HAVE_CURL) && defined(HTTP_CURL_USE_ZEND_MM)
435 static void http_curl_free(void *p) { efree(p); }
436 static char *http_curl_strdup(const char *p) { return estrdup(p); }
437 static void *http_curl_malloc(size_t s) { return emalloc(s); }
438 static void *http_curl_realloc(void *p, size_t s) { return erealloc(p, s); }
439 static void *http_curl_calloc(size_t n, size_t s) { return ecalloc(n, s); }
440 #endif /* HTTP_HAVE_CURL && HTTP_CURL_USE_ZEND_MM */
441 /* }}} */
442
443 /* {{{ PHP_MINIT_FUNCTION */
444 PHP_MINIT_FUNCTION(http)
445 {
446 ZEND_INIT_MODULE_GLOBALS(http, php_http_init_globals, NULL);
447 REGISTER_INI_ENTRIES();
448
449 #ifdef HTTP_HAVE_CURL
450 # ifdef HTTP_CURL_USE_ZEND_MM
451 if (CURLE_OK != curl_global_init_mem(CURL_GLOBAL_ALL,
452 http_curl_malloc,
453 http_curl_free,
454 http_curl_realloc,
455 http_curl_strdup,
456 http_curl_calloc)) {
457 return FAILURE;
458 }
459 # endif /* HTTP_CURL_USE_ZEND_MM */
460
461 # if LIBCURL_VERSION_NUM >= 0x070a05
462 REGISTER_LONG_CONSTANT("HTTP_AUTH_BASIC", CURLAUTH_BASIC, CONST_CS | CONST_PERSISTENT);
463 REGISTER_LONG_CONSTANT("HTTP_AUTH_DIGEST", CURLAUTH_DIGEST, CONST_CS | CONST_PERSISTENT);
464 REGISTER_LONG_CONSTANT("HTTP_AUTH_NTLM", CURLAUTH_NTLM, CONST_CS | CONST_PERSISTENT);
465 # endif /* LIBCURL_VERSION_NUM */
466 #endif /* HTTP_HAVE_CURL */
467
468 #ifdef ZEND_ENGINE_2
469 HTTP_REGISTER_CLASS(HttpUtil, http_util, NULL, ZEND_ACC_FINAL_CLASS);
470 HTTP_REGISTER_CLASS_EX(HttpResponse, http_response, NULL, 0);
471 # ifdef HTTP_HAVE_CURL
472 HTTP_REGISTER_CLASS_EX(HttpRequest, http_request, NULL, 0);
473
474 REGISTER_LONG_CONSTANT("HTTP_GET", HTTP_GET, CONST_CS | CONST_PERSISTENT);
475 REGISTER_LONG_CONSTANT("HTTP_HEAD", HTTP_HEAD, CONST_CS | CONST_PERSISTENT);
476 REGISTER_LONG_CONSTANT("HTTP_POST", HTTP_POST, CONST_CS | CONST_PERSISTENT);
477 # endif /* HTTP_HAVE_CURL */
478 #endif /* ZEND_ENGINE_2 */
479 return SUCCESS;
480 }
481 /* }}} */
482
483 /* {{{ PHP_MSHUTDOWN_FUNCTION */
484 PHP_MSHUTDOWN_FUNCTION(http)
485 {
486 UNREGISTER_INI_ENTRIES();
487 #ifdef HTTP_HAVE_CURL
488 phpstr_dtor(&HTTP_G(curlbuf));
489 curl_global_cleanup();
490 #endif
491 return SUCCESS;
492 }
493 /* }}} */
494
495 /* {{{ PHP_RINIT_FUNCTION */
496 PHP_RINIT_FUNCTION(http)
497 {
498 char *allowed_methods = INI_STR("http.allowed_methods");
499 http_check_allowed_methods(allowed_methods, strlen(allowed_methods));
500 return SUCCESS;
501 }
502 /* }}} */
503
504 /* {{{ PHP_RSHUTDOWN_FUNCTION */
505 PHP_RSHUTDOWN_FUNCTION(http)
506 {
507 HTTP_G(etag_started) = 0;
508 HTTP_G(lmod) = 0;
509
510 if (HTTP_G(etag)) {
511 efree(HTTP_G(etag));
512 HTTP_G(etag) = NULL;
513 }
514
515 if (HTTP_G(ctype)) {
516 efree(HTTP_G(ctype));
517 HTTP_G(ctype) = NULL;
518 }
519
520 #ifdef HTTP_HAVE_CURL
521 phpstr_dtor(&HTTP_G(curlbuf));
522 #endif
523
524 return SUCCESS;
525 }
526 /* }}} */
527
528 /* {{{ PHP_MINFO_FUNCTION */
529 PHP_MINFO_FUNCTION(http)
530 {
531 #ifdef ZEND_ENGINE_2
532 # define HTTP_FUNC_AVAIL(CLASS) "procedural, object oriented (class " CLASS ")"
533 #else
534 # define HTTP_FUNC_AVAIL(CLASS) "procedural"
535 #endif
536
537 #ifdef HTTP_HAVE_CURL
538 # define HTTP_CURL_VERSION curl_version()
539 # ifdef ZEND_ENGINE_2
540 # define HTTP_CURL_AVAIL(CLASS) "procedural, object oriented (class " CLASS ")"
541 # else
542 # define HTTP_CURL_AVAIL(CLASS) "procedural"
543 # endif
544 #else
545 # define HTTP_CURL_VERSION "libcurl not available"
546 # define HTTP_CURL_AVAIL(CLASS) "libcurl not available"
547 #endif
548
549 char full_version_string[1024] = {0};
550 snprintf(full_version_string, 1023, "%s (%s)", HTTP_PEXT_VERSION, HTTP_CURL_VERSION);
551
552 php_info_print_table_start();
553 php_info_print_table_row(2, "Extended HTTP support", "enabled");
554 php_info_print_table_row(2, "Extension Version:", full_version_string);
555 php_info_print_table_end();
556
557 php_info_print_table_start();
558 php_info_print_table_header(2, "Functionality", "Availability");
559 php_info_print_table_row(2, "Miscellaneous Utilities:", HTTP_FUNC_AVAIL("HttpUtil"));
560 php_info_print_table_row(2, "Extended HTTP Responses:", HTTP_FUNC_AVAIL("HttpResponse"));
561 php_info_print_table_row(2, "Extended HTTP Requests:", HTTP_CURL_AVAIL("HttpRequest"));
562 php_info_print_table_end();
563
564 DISPLAY_INI_ENTRIES();
565 }
566 /* }}} */
567
568 /*
569 * Local variables:
570 * tab-width: 4
571 * c-basic-offset: 4
572 * End:
573 * vim600: noet sw=4 ts=4 fdm=marker
574 * vim<600: noet sw=4 ts=4
575 */
576