2 +----------------------------------------------------------------------+
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 +----------------------------------------------------------------------+
25 # include <winsock2.h>
27 # include <curl/curl.h>
34 #include "ext/standard/info.h"
39 #include "php_http_std_defs.h"
40 #include "php_http_send_api.h"
43 # include "php_http_util_object.h"
44 # include "php_http_message_object.h"
45 # include "php_http_response_object.h"
46 # ifdef HTTP_HAVE_CURL
47 # include "php_http_request_object.h"
49 # include "php_http_exception_object.h"
52 #include "phpstr/phpstr.h"
57 ZEND_BEGIN_ARG_INFO(http_request_info_ref_3
, 0)
64 ZEND_BEGIN_ARG_INFO(http_request_info_ref_4
, 0)
71 static unsigned char http_request_info_ref_3
[] = {3, BYREF_NONE
, BYREF_NONE
, BYREF_FORCE
};
72 static unsigned char http_request_info_ref_4
[] = {4, BYREF_NONE
, BYREF_NONE
, BYREF_NONE
, BYREF_FORCE
};
73 #endif /* ZEND_ENGINE_2 */
74 #endif /* HTTP_HAVE_CURL */
76 ZEND_DECLARE_MODULE_GLOBALS(http
)
78 #ifdef COMPILE_DL_HTTP
82 /* {{{ http_functions[] */
83 function_entry http_functions
[] = {
84 PHP_FE(http_test
, NULL
)
85 PHP_FE(http_date
, NULL
)
86 PHP_FE(http_absolute_uri
, NULL
)
87 PHP_FE(http_negotiate_language
, NULL
)
88 PHP_FE(http_negotiate_charset
, NULL
)
89 PHP_FE(http_redirect
, NULL
)
90 PHP_FE(http_send_status
, NULL
)
91 PHP_FE(http_send_last_modified
, NULL
)
92 PHP_FE(http_send_content_type
, NULL
)
93 PHP_FE(http_send_content_disposition
, NULL
)
94 PHP_FE(http_match_modified
, NULL
)
95 PHP_FE(http_match_etag
, NULL
)
96 PHP_FE(http_cache_last_modified
, NULL
)
97 PHP_FE(http_cache_etag
, NULL
)
98 PHP_FE(http_send_data
, NULL
)
99 PHP_FE(http_send_file
, NULL
)
100 PHP_FE(http_send_stream
, NULL
)
101 PHP_FE(http_chunked_decode
, NULL
)
102 PHP_FE(http_split_response
, NULL
)
103 PHP_FE(http_parse_headers
, NULL
)
104 PHP_FE(http_get_request_headers
, NULL
)
105 #ifdef HTTP_HAVE_CURL
106 PHP_FE(http_get
, http_request_info_ref_3
)
107 PHP_FE(http_head
, http_request_info_ref_3
)
108 PHP_FE(http_post_data
, http_request_info_ref_4
)
109 PHP_FE(http_post_array
, http_request_info_ref_4
)
111 PHP_FE(http_auth_basic
, NULL
)
112 PHP_FE(http_auth_basic_cb
, NULL
)
113 #ifndef ZEND_ENGINE_2
114 PHP_FE(http_build_query
, NULL
)
116 PHP_FE(ob_httpetaghandler
, NULL
)
121 /* {{{ http_module_entry */
122 zend_module_entry http_module_entry
= {
123 #if ZEND_MODULE_API_NO >= 20010901
124 STANDARD_MODULE_HEADER
,
133 #if ZEND_MODULE_API_NO >= 20010901
136 STANDARD_MODULE_PROPERTIES
141 static void free_to_free(void *s
)
146 /* {{{ void _http_init_globals(zend_http_globals *) */
147 static void _http_init_globals(zend_http_globals
*http_globals
)
149 http_globals
->etag_started
= 0;
150 http_globals
->ctype
= NULL
;
151 http_globals
->etag
= NULL
;
152 http_globals
->lmod
= 0;
153 #ifdef HTTP_HAVE_CURL
154 # if LIBCURL_VERSION_NUM < 0x070c00
155 memset(&http_globals
->curlerr
, 0, sizeof(http_globals
->curlerr
));
157 zend_llist_init(&http_globals
->to_free
, sizeof(char *), free_to_free
, 0);
159 http_globals
->allowed_methods
= NULL
;
163 /* {{{ static inline STATUS http_check_allowed_methods(char *, int) */
164 #define http_check_allowed_methods(m, l) _http_check_allowed_methods((m), (l) TSRMLS_CC)
165 static inline void _http_check_allowed_methods(char *methods
, int length TSRMLS_DC
)
167 char *found
, *header
;
169 if (!length
|| !SG(request_info
).request_method
) {
173 if ( (found
= strstr(methods
, SG(request_info
).request_method
)) &&
174 (found
== SG(request_info
).request_method
|| !isalpha(found
[-1])) &&
175 (!isalpha(found
[strlen(SG(request_info
).request_method
) + 1]))) {
179 header
= emalloc(length
+ sizeof("Allow: "));
180 sprintf(header
, "Allow: %s", methods
);
181 http_send_header(header
);
183 http_send_status(405);
189 PHP_INI_MH(update_allowed_methods
)
191 http_check_allowed_methods(new_value
, new_value_length
);
192 return OnUpdateString(entry
, new_value
, new_value_length
, mh_arg1
, mh_arg2
, mh_arg3
, stage TSRMLS_CC
);
196 STD_PHP_INI_ENTRY("http.allowed_methods",
198 "GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE, CONNECT, "
199 /* WebDAV - RFC 2518 * /
200 "PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, "
201 /* WebDAV Versioning - RFC 3253 * /
202 "VERSION-CONTROL, REPORT, CHECKOUT, CHECKIN, UNCHECKOUT, "
203 "MKWORKSPACE, UPDATE, LABEL, MERGE, BASELINE-CONTROL, MKACTIVITY, "
204 /* WebDAV Access Control - RFC 3744 * /
208 PHP_INI_ALL
, update_allowed_methods
, allowed_methods
, zend_http_globals
, http_globals
)
212 /* {{{ HTTP_CURL_USE_ZEND_MM */
213 #if defined(HTTP_HAVE_CURL) && defined(HTTP_CURL_USE_ZEND_MM)
214 static void http_curl_free(void *p
) { efree(p
); }
215 static char *http_curl_strdup(const char *p
) { return estrdup(p
); }
216 static void *http_curl_malloc(size_t s
) { return emalloc(s
); }
217 static void *http_curl_realloc(void *p
, size_t s
) { return erealloc(p
, s
); }
218 static void *http_curl_calloc(size_t n
, size_t s
) { return ecalloc(n
, s
); }
219 #endif /* HTTP_HAVE_CURL && HTTP_CURL_USE_ZEND_MM */
222 /* {{{ PHP_MINIT_FUNCTION */
223 PHP_MINIT_FUNCTION(http
)
225 ZEND_INIT_MODULE_GLOBALS(http
, _http_init_globals
, NULL
);
226 REGISTER_INI_ENTRIES();
228 #ifdef HTTP_HAVE_CURL
229 # ifdef HTTP_CURL_USE_ZEND_MM
230 if (CURLE_OK
!= curl_global_init_mem(CURL_GLOBAL_ALL
,
238 # endif /* HTTP_CURL_USE_ZEND_MM */
239 #endif /* HTTP_HAVE_CURL */
242 http_util_object_init(INIT_FUNC_ARGS_PASSTHRU
);
243 http_message_object_init(INIT_FUNC_ARGS_PASSTHRU
);
244 http_response_object_init(INIT_FUNC_ARGS_PASSTHRU
);
245 # ifdef HTTP_HAVE_CURL
246 http_request_object_init(INIT_FUNC_ARGS_PASSTHRU
);
247 # endif /* HTTP_HAVE_CURL */
248 http_exception_object_init(INIT_FUNC_ARGS_PASSTHRU
);
249 #endif /* ZEND_ENGINE_2 */
255 /* {{{ PHP_MSHUTDOWN_FUNCTION */
256 PHP_MSHUTDOWN_FUNCTION(http
)
258 UNREGISTER_INI_ENTRIES();
259 #ifdef HTTP_HAVE_CURL
260 curl_global_cleanup();
266 /* {{{ PHP_RINIT_FUNCTION */
267 PHP_RINIT_FUNCTION(http
)
269 char *allowed_methods
= INI_STR("http.allowed_methods");
270 http_check_allowed_methods(allowed_methods
, strlen(allowed_methods
));
275 /* {{{ PHP_RSHUTDOWN_FUNCTION */
276 PHP_RSHUTDOWN_FUNCTION(http
)
278 HTTP_G(etag_started
) = 0;
287 efree(HTTP_G(ctype
));
288 HTTP_G(ctype
) = NULL
;
291 #ifdef HTTP_HAVE_CURL
292 # if LIBCURL_VERSION_NUM < 0x070c00
293 memset(&HTTP_G(curlerr
), 0, sizeof(HTTP_G(curlerr
)));
301 /* {{{ PHP_MINFO_FUNCTION */
302 PHP_MINFO_FUNCTION(http
)
305 # define HTTP_FUNC_AVAIL(CLASS) "procedural, object oriented (" CLASS ")"
307 # define HTTP_FUNC_AVAIL(CLASS) "procedural"
310 #ifdef HTTP_HAVE_CURL
311 # define HTTP_CURL_VERSION curl_version()
312 # ifdef ZEND_ENGINE_2
313 # define HTTP_CURL_AVAIL(CLASS) "procedural, object oriented (" CLASS ")"
315 # define HTTP_CURL_AVAIL(CLASS) "procedural"
318 # define HTTP_CURL_VERSION "libcurl not available"
319 # define HTTP_CURL_AVAIL(CLASS) "libcurl not available"
322 char full_version_string
[1024] = {0};
323 snprintf(full_version_string
, 1023, "%s (%s)", HTTP_PEXT_VERSION
, HTTP_CURL_VERSION
);
325 php_info_print_table_start();
326 php_info_print_table_row(2, "Extended HTTP support", "enabled");
327 php_info_print_table_row(2, "Extension Version:", full_version_string
);
328 php_info_print_table_end();
330 php_info_print_table_start();
331 php_info_print_table_header(2, "Functionality", "Availability");
332 php_info_print_table_row(2, "Miscellaneous Utilities:", HTTP_FUNC_AVAIL("HttpUtil, HttpMessage"));
333 php_info_print_table_row(2, "Extended HTTP Responses:", HTTP_FUNC_AVAIL("HttpResponse"));
334 php_info_print_table_row(2, "Extended HTTP Requests:", HTTP_CURL_AVAIL("HttpRequest"));
335 php_info_print_table_end();
337 DISPLAY_INI_ENTRIES();
346 * vim600: noet sw=4 ts=4 fdm=marker
347 * vim<600: noet sw=4 ts=4