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 +----------------------------------------------------------------------+
19 #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
28 #include "ext/standard/info.h"
29 #include "ext/session/php_session.h"
30 #include "ext/standard/php_string.h"
31 #include "ext/standard/php_smart_str.h"
36 #include "php_http_api.h"
39 # include "ext/standard/php_http.h"
45 # include <winsock2.h>
46 # include <sys/types.h>
49 # include <curl/curl.h>
52 # ifdef ZEND_BEGIN_ARG_INFO
53 ZEND_BEGIN_ARG_INFO(http_request_info_ref_3
, 0)
59 ZEND_BEGIN_ARG_INFO(http_request_info_ref_4
, 0)
66 static unsigned char http_request_info_ref_3
[] = {3, BYREF_NONE
, BYREF_NONE
, BYREF_FORCE
};
67 static unsigned char http_request_info_ref_4
[] = {4, BYREF_NONE
, BYREF_NONE
, BYREF_NONE
, BYREF_FORCE
};
71 #endif /* HTTP_HAVE_CURL */
73 ZEND_DECLARE_MODULE_GLOBALS(http
)
75 #ifdef COMPILE_DL_HTTP
79 /* {{{ http_functions[] */
80 function_entry http_functions
[] = {
81 PHP_FE(http_date
, NULL
)
82 PHP_FE(http_absolute_uri
, NULL
)
83 PHP_FE(http_negotiate_language
, NULL
)
84 PHP_FE(http_negotiate_charset
, NULL
)
85 PHP_FE(http_redirect
, NULL
)
86 PHP_FE(http_send_status
, NULL
)
87 PHP_FE(http_send_last_modified
, NULL
)
88 PHP_FE(http_send_content_type
, NULL
)
89 PHP_FE(http_send_content_disposition
, NULL
)
90 PHP_FE(http_match_modified
, NULL
)
91 PHP_FE(http_match_etag
, NULL
)
92 PHP_FE(http_cache_last_modified
, NULL
)
93 PHP_FE(http_cache_etag
, NULL
)
94 PHP_FE(http_send_data
, NULL
)
95 PHP_FE(http_send_file
, NULL
)
96 PHP_FE(http_send_stream
, NULL
)
97 PHP_FE(http_chunked_decode
, NULL
)
98 PHP_FE(http_split_response
, NULL
)
99 PHP_FE(http_parse_headers
, NULL
)
100 PHP_FE(http_get_request_headers
, NULL
)
101 #ifdef HTTP_HAVE_CURL
102 PHP_FE(http_get
, http_request_info_ref_3
)
103 PHP_FE(http_head
, http_request_info_ref_3
)
104 PHP_FE(http_post_data
, http_request_info_ref_4
)
105 PHP_FE(http_post_array
, http_request_info_ref_4
)
107 PHP_FE(http_auth_basic
, NULL
)
108 PHP_FE(http_auth_basic_cb
, NULL
)
109 #ifndef ZEND_ENGINE_2
110 PHP_FE(http_build_query
, NULL
)
112 PHP_FE(ob_httpetaghandler
, NULL
)
117 #define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v))
118 #define HASH_ORNULL(z) ((z) ? Z_ARRVAL_P(z) : NULL)
119 #define NO_ARGS if (ZEND_NUM_ARGS()) WRONG_PARAM_COUNT
120 #define HTTP_URL_ARGSEP_OVERRIDE zend_alter_ini_entry("arg_separator.output", sizeof("arg_separator.output") - 1, "&", 1, ZEND_INI_ALL, ZEND_INI_STAGE_RUNTIME)
121 #define HTTP_URL_ARGSEP_RESTORE zend_restore_ini_entry("arg_separator.output", sizeof("arg_separator.output") - 1, ZEND_INI_STAGE_RUNTIME)
123 #define array_copy(src, dst) zend_hash_copy(Z_ARRVAL_P(dst), Z_ARRVAL_P(src), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *))
124 #define array_merge(src, dst) zend_hash_merge(Z_ARRVAL_P(dst), Z_ARRVAL_P(src), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *), 1)
128 # define HTTP_REGISTER_CLASS_EX(classname, name, parent, flags) \
130 zend_class_entry ce; \
131 INIT_CLASS_ENTRY(ce, #classname, name## _class_methods); \
132 ce.create_object = name## _new_object; \
133 name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
134 name## _ce->ce_flags |= flags; \
135 memcpy(& name## _object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \
136 name## _object_handlers.clone_obj = NULL; \
137 name## _declare_default_properties(name## _ce); \
140 # define HTTP_REGISTER_CLASS(classname, name, parent, flags) \
142 zend_class_entry ce; \
143 INIT_CLASS_ENTRY(ce, #classname, name## _class_methods); \
144 ce.create_object = NULL; \
145 name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
146 name## _ce->ce_flags |= flags; \
149 # define getObject(t, o) t * o = ((t *) zend_object_store_get_object(getThis() TSRMLS_CC))
150 # define OBJ_PROP(o) o->zo.properties
151 # define DCL_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC)
152 # define DCL_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC)
153 # define DCL_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n), (ZEND_ACC_ ##a) TSRMLS_CC)
154 # define UPD_PROP(o, t, n, v) zend_update_property_ ##t(o->zo.ce, getThis(), (#n), sizeof(#n), (v) TSRMLS_CC)
155 # define SET_PROP(o, n, z) zend_update_property(o->zo.ce, getThis(), (#n), sizeof(#n), (z) TSRMLS_CC)
156 # define GET_PROP(o, n) zend_read_property(o->zo.ce, getThis(), (#n), sizeof(#n), 0 TSRMLS_CC)
158 # define INIT_PARR(o, n) \
161 MAKE_STD_ZVAL(__tmp); \
163 SET_PROP(o, n, __tmp); \
166 # define FREE_PARR(o, p) \
168 zval *__tmp = NULL; \
169 if (__tmp = GET_PROP(o, p)) { \
178 zend_class_entry
*httpi_ce
;
180 #define HTTPi_ME(me, al, ai) ZEND_FENTRY(me, ZEND_FN(al), ai, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
182 zend_function_entry httpi_class_methods
[] = {
183 HTTPi_ME(date
, http_date
, NULL
)
184 HTTPi_ME(absoluteURI
, http_absolute_uri
, NULL
)
185 HTTPi_ME(negotiateLanguage
, http_negotiate_language
, NULL
)
186 HTTPi_ME(negotiateCharset
, http_negotiate_charset
, NULL
)
187 HTTPi_ME(redirect
, http_redirect
, NULL
)
188 HTTPi_ME(sendStatus
, http_send_status
, NULL
)
189 HTTPi_ME(sendLastModified
, http_send_last_modified
, NULL
)
190 HTTPi_ME(sendContentType
, http_send_content_type
, NULL
)
191 HTTPi_ME(sendContentDisposition
, http_send_content_disposition
, NULL
)
192 HTTPi_ME(matchModified
, http_match_modified
, NULL
)
193 HTTPi_ME(matchEtag
, http_match_etag
, NULL
)
194 HTTPi_ME(cacheLastModified
, http_cache_last_modified
, NULL
)
195 HTTPi_ME(cacheEtag
, http_cache_etag
, NULL
)
196 HTTPi_ME(chunkedDecode
, http_chunked_decode
, NULL
)
197 HTTPi_ME(splitResponse
, http_split_response
, NULL
)
198 HTTPi_ME(parseHeaders
, http_parse_headers
, NULL
)
199 HTTPi_ME(getRequestHeaders
, http_get_request_headers
, NULL
)
200 #ifdef HTTP_HAVE_CURL
201 HTTPi_ME(get
, http_get
, http_request_info_ref_3
)
202 HTTPi_ME(head
, http_head
, http_request_info_ref_3
)
203 HTTPi_ME(postData
, http_post_data
, http_request_info_ref_4
)
204 HTTPi_ME(postArray
, http_post_array
, http_request_info_ref_4
)
206 HTTPi_ME(authBasic
, http_auth_basic
, NULL
)
207 HTTPi_ME(authBasicCallback
, http_auth_basic_cb
, NULL
)
212 /* {{{ HTTPi_Response */
214 zend_class_entry
*httpi_response_ce
;
215 static zend_object_handlers httpi_response_object_handlers
;
219 } httpi_response_object
;
221 #define httpi_response_declare_default_properties(ce) _httpi_response_declare_default_properties(ce TSRMLS_CC)
222 static inline void _httpi_response_declare_default_properties(zend_class_entry
*ce TSRMLS_DC
)
224 DCL_PROP(PROTECTED
, string
, contentType
, "application/x-octetstream");
225 DCL_PROP(PROTECTED
, string
, eTag
, "");
226 DCL_PROP(PROTECTED
, string
, dispoFile
, "");
227 DCL_PROP(PROTECTED
, string
, cacheControl
, "public");
228 DCL_PROP(PROTECTED
, string
, data
, "");
229 DCL_PROP(PROTECTED
, string
, file
, "");
230 DCL_PROP(PROTECTED
, long, stream
, 0);
231 DCL_PROP(PROTECTED
, long, lastModified
, 0);
232 DCL_PROP(PROTECTED
, long, dispoInline
, 0);
233 DCL_PROP(PROTECTED
, long, cache
, 0);
234 DCL_PROP(PROTECTED
, long, gzip
, 0);
236 DCL_PROP(PRIVATE
, long, raw_cache_header
, 0);
237 DCL_PROP(PRIVATE
, long, send_mode
, -1);
240 #define httpi_response_destroy_object _httpi_response_destroy_object
241 void _httpi_response_destroy_object(void *object
, zend_object_handle handle TSRMLS_DC
)
243 httpi_response_object
*o
= object
;
245 zend_hash_destroy(OBJ_PROP(o
));
246 FREE_HASHTABLE(OBJ_PROP(o
));
251 #define httpi_response_new_object _httpi_response_new_object
252 zend_object_value
_httpi_response_new_object(zend_class_entry
*ce TSRMLS_DC
)
254 zend_object_value ov
;
255 httpi_response_object
*o
;
257 o
= ecalloc(sizeof(httpi_response_object
), 1);
260 ALLOC_HASHTABLE(OBJ_PROP(o
));
261 zend_hash_init(OBJ_PROP(o
), 0, NULL
, ZVAL_PTR_DTOR
, 0);
262 zend_hash_copy(OBJ_PROP(o
), &ce
->default_properties
, (copy_ctor_func_t
) zval_add_ref
, NULL
, sizeof(zval
*));
264 ov
.handle
= zend_objects_store_put(o
, httpi_response_destroy_object
, NULL
, NULL TSRMLS_CC
);
265 ov
.handlers
= &httpi_response_object_handlers
;
270 zend_function_entry httpi_response_class_methods
[] = {
271 PHP_ME(HTTPi_Response
, __construct
, NULL
, ZEND_ACC_PUBLIC
|ZEND_ACC_CTOR
)
272 /* PHP_ME(HTTPi_Response, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
274 PHP_ME(HTTPi_Response
, setETag
, NULL
, ZEND_ACC_PUBLIC
)
275 PHP_ME(HTTPi_Response
, getETag
, NULL
, ZEND_ACC_PUBLIC
)
277 PHP_ME(HTTPi_Response
, setContentDisposition
, NULL
, ZEND_ACC_PUBLIC
)
278 PHP_ME(HTTPi_Response
, getContentDisposition
, NULL
, ZEND_ACC_PUBLIC
)
280 PHP_ME(HTTPi_Response
, setContentType
, NULL
, ZEND_ACC_PUBLIC
)
281 PHP_ME(HTTPi_Response
, getContentType
, NULL
, ZEND_ACC_PUBLIC
)
283 PHP_ME(HTTPi_Response
, setCache
, NULL
, ZEND_ACC_PUBLIC
)
284 PHP_ME(HTTPi_Response
, getCache
, NULL
, ZEND_ACC_PUBLIC
)
286 PHP_ME(HTTPi_Response
, setCacheControl
, NULL
, ZEND_ACC_PUBLIC
)
287 PHP_ME(HTTPi_Response
, getCacheControl
, NULL
, ZEND_ACC_PUBLIC
)
289 PHP_ME(HTTPi_Response
, setGzip
, NULL
, ZEND_ACC_PUBLIC
)
290 PHP_ME(HTTPi_Response
, getGzip
, NULL
, ZEND_ACC_PUBLIC
)
292 PHP_ME(HTTPi_Response
, setData
, NULL
, ZEND_ACC_PUBLIC
)
293 PHP_ME(HTTPi_Response
, getData
, NULL
, ZEND_ACC_PUBLIC
)
295 PHP_ME(HTTPi_Response
, setFile
, NULL
, ZEND_ACC_PUBLIC
)
296 PHP_ME(HTTPi_Response
, getFile
, NULL
, ZEND_ACC_PUBLIC
)
298 PHP_ME(HTTPi_Response
, setStream
, NULL
, ZEND_ACC_PUBLIC
)
299 PHP_ME(HTTPi_Response
, getStream
, NULL
, ZEND_ACC_PUBLIC
)
301 PHP_ME(HTTPi_Response
, send
, NULL
, ZEND_ACC_PUBLIC
)
306 /* {{{ proto void HTTPi_Response::__construct(bool cache, bool gzip)
309 PHP_METHOD(HTTPi_Response
, __construct
)
311 zend_bool do_cache
= 0, do_gzip
= 0;
312 getObject(httpi_response_object
, obj
);
314 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|bb", &do_cache
, &do_gzip
)) {
319 UPD_PROP(obj
, long, cache
, do_cache
);
320 UPD_PROP(obj
, long, gzip
, do_gzip
);
324 /* {{{ proto bool HTTPi_Response::setCache(bool cache)
327 PHP_METHOD(HTTPi_Response
, setCache
)
329 zend_bool do_cache
= 0;
330 getObject(httpi_response_object
, obj
);
332 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "b", &do_cache
)) {
336 UPD_PROP(obj
, long, cache
, do_cache
);
341 /* {{{ proto bool HTTPi_Response::getCache()
344 PHP_METHOD(HTTPi_Response
, getCache
)
346 zval
*do_cache
= NULL
;
347 getObject(httpi_response_object
, obj
);
351 do_cache
= GET_PROP(obj
, cache
);
352 RETURN_BOOL(Z_LVAL_P(do_cache
));
356 /* {{{ proto bool HTTPi_Response::setGzip(bool gzip)
359 PHP_METHOD(HTTPi_Response
, setGzip
)
361 zend_bool do_gzip
= 0;
362 getObject(httpi_response_object
, obj
);
364 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "b", &do_gzip
)) {
368 UPD_PROP(obj
, long, gzip
, do_gzip
);
373 /* {{{ proto bool HTTPi_Response::getGzip()
376 PHP_METHOD(HTTPi_Response
, getGzip
)
378 zval
*do_gzip
= NULL
;
379 getObject(httpi_response_object
, obj
);
383 do_gzip
= GET_PROP(obj
, gzip
);
384 RETURN_BOOL(Z_LVAL_P(do_gzip
));
388 /* {{{ proto bool HTTPi_Response::setCacheControl(string control[, bool raw = false])
391 PHP_METHOD(HTTPi_Response
, setCacheControl
)
396 getObject(httpi_response_object
, obj
);
398 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|b", &ccontrol
, &cc_len
, &raw
)) {
402 if ((!raw
) && (strcmp(ccontrol
, "public") && strcmp(ccontrol
, "private") && strcmp(ccontrol
, "no-cache"))) {
403 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Cache-Control '%s' doesn't match public, private or no-cache", ccontrol
);
407 UPD_PROP(obj
, long, raw_cache_header
, raw
);
408 UPD_PROP(obj
, string
, cacheControl
, ccontrol
);
413 /* {{{ proto string HTTPi_Response::getCacheControl()
416 PHP_METHOD(HTTPi_Response
, getCacheControl
)
419 getObject(httpi_response_object
, obj
);
423 ccontrol
= GET_PROP(obj
, cacheControl
);
424 RETURN_STRINGL(Z_STRVAL_P(ccontrol
), Z_STRLEN_P(ccontrol
), 1);
428 /* {{{ proto bool HTTPi::setContentType(string content_type)
431 PHP_METHOD(HTTPi_Response
, setContentType
)
435 getObject(httpi_response_object
, obj
);
437 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &ctype
, &ctype_len
)) {
441 if (!strchr(ctype
, '/')) {
442 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
443 "Content type '%s' doesn't seem to contain a primary and a secondary part", ctype
);
447 UPD_PROP(obj
, string
, contentType
, ctype
);
453 /* {{{ proto string HTTPi_Response::getContentType()
456 PHP_METHOD(HTTPi_Response
, getContentType
)
459 getObject(httpi_response_object
, obj
);
463 ctype
= GET_PROP(obj
, contentType
);
464 RETURN_STRINGL(Z_STRVAL_P(ctype
), Z_STRLEN_P(ctype
), 1);
468 /* {{{ proto bool HTTPi_Response::setContentDisposition(string filename[, bool inline = false])
471 PHP_METHOD(HTTPi_Response
, setContentDisposition
)
475 zend_bool is_inline
= 0;
476 getObject(httpi_response_object
, obj
);
478 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|b", &file
, &file_len
, &is_inline
)) {
482 UPD_PROP(obj
, string
, dispoFile
, file
);
483 UPD_PROP(obj
, long, dispoInline
, is_inline
);
488 /* {{{ proto array HTTPi_Response::getContentDisposition()
491 PHP_METHOD(HTTPi_Response
, getContentDisposition
)
495 getObject(httpi_response_object
, obj
);
497 if (ZEND_NUM_ARGS()) {
501 file
= GET_PROP(obj
, dispoFile
);
502 is_inline
= GET_PROP(obj
, dispoInline
);
504 array_init(return_value
);
505 add_assoc_stringl(return_value
, "filename", Z_STRVAL_P(file
), Z_STRLEN_P(file
), 1);
506 add_assoc_bool(return_value
, "inline", Z_LVAL_P(is_inline
));
510 /* {{{ proto bool HTTPi_Response::setETag(string etag)
513 PHP_METHOD(HTTPi_Response
, setETag
)
517 getObject(httpi_response_object
, obj
);
519 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &etag
, &etag_len
)) {
523 UPD_PROP(obj
, string
, eTag
, etag
);
528 /* {{{ proto string HTTPi_Response::getETag()
531 PHP_METHOD(HTTPi_Response
, getETag
)
534 getObject(httpi_response_object
, obj
);
538 etag
= GET_PROP(obj
, eTag
);
539 RETURN_STRINGL(Z_STRVAL_P(etag
), Z_STRLEN_P(etag
), 1);
543 /* {{{ proto bool HTTPi_Response::setData(string data)
546 PHP_METHOD(HTTPi_Response
, setData
)
550 getObject(httpi_response_object
, obj
);
552 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z", &the_data
)) {
556 convert_to_string_ex(&the_data
);
557 SET_PROP(obj
, data
, the_data
);
558 UPD_PROP(obj
, long, lastModified
, http_lmod(the_data
, SEND_DATA
));
559 UPD_PROP(obj
, long, send_mode
, SEND_DATA
);
564 /* {{{ proto string HTTPi_Response::getData()
567 PHP_METHOD(HTTPi_Response
, getData
)
570 getObject(httpi_response_object
, obj
);
574 the_data
= GET_PROP(obj
, data
);
575 RETURN_STRINGL(Z_STRVAL_P(the_data
), Z_STRLEN_P(the_data
), 1);
579 /* {{{ proto bool HTTPi_Response::setStream(resource stream)
582 PHP_METHOD(HTTPi_Response
, setStream
)
585 php_stream
*the_real_stream
;
587 getObject(httpi_response_object
, obj
);
589 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "r", &the_stream
)) {
593 php_stream_from_zval(the_real_stream
, &the_stream
);
595 SET_PROP(obj
, stream
, the_stream
);
596 UPD_PROP(obj
, long, lastModified
, http_lmod(the_real_stream
, SEND_RSRC
));
597 UPD_PROP(obj
, long, send_mode
, SEND_RSRC
);
602 /* {{{ proto resource HTTPi_Response::getStream()
605 PHP_METHOD(HTTPi_Response
, getStream
)
608 getObject(httpi_response_object
, obj
);
612 the_stream
= GET_PROP(obj
, stream
);
613 RETURN_RESOURCE(Z_LVAL_P(the_stream
));
617 /* {{{ proto bool HTTPi_Response::setFile(string file)
620 PHP_METHOD(HTTPi_Response
, setFile
)
623 getObject(httpi_response_object
, obj
);
625 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z", &the_file
)) {
629 convert_to_string_ex(&the_file
);
631 UPD_PROP(obj
, string
, file
, Z_STRVAL_P(the_file
));
632 UPD_PROP(obj
, long, lastModified
, http_lmod(the_file
, -1));
633 UPD_PROP(obj
, long, send_mode
, -1);
638 /* {{{ proto string HTTPi_Response::getFile()
641 PHP_METHOD(HTTPi_Response
, getFile
)
644 getObject(httpi_response_object
, obj
);
648 the_file
= GET_PROP(obj
, file
);
649 RETURN_STRINGL(Z_STRVAL_P(the_file
), Z_STRLEN_P(the_file
), 1);
653 PHP_METHOD(HTTPi_Response
, send
)
655 zval
*do_cache
, *do_gzip
;
656 getObject(httpi_response_object
, obj
);
658 do_cache
= GET_PROP(obj
, cache
);
659 do_gzip
= GET_PROP(obj
, gzip
);
662 if (Z_LVAL_P(do_cache
)) {
663 zval
*cctrl
, *etag
, *lmod
, *ccraw
;
665 etag
= GET_PROP(obj
, eTag
);
666 lmod
= GET_PROP(obj
, lastModified
);
667 cctrl
= GET_PROP(obj
, cacheControl
);
668 ccraw
= GET_PROP(obj
, raw_cache_header
);
670 if (Z_LVAL_P(ccraw
)) {
671 http_cache_etag(Z_STRVAL_P(etag
), Z_STRLEN_P(etag
), Z_STRVAL_P(cctrl
), Z_STRLEN_P(cctrl
));
672 http_cache_last_modified(Z_LVAL_P(lmod
), Z_LVAL_P(lmod
) ? Z_LVAL_P(lmod
) : time(NULL
), Z_STRVAL_P(cctrl
), Z_STRLEN_P(cctrl
));
674 char cc_header
[42] = {0};
675 sprintf(cc_header
, "%s, must-revalidate, max-age=0", Z_STRVAL_P(cctrl
));
676 http_cache_etag(Z_STRVAL_P(etag
), Z_STRLEN_P(etag
), cc_header
, strlen(cc_header
));
677 http_cache_last_modified(Z_LVAL_P(lmod
), Z_LVAL_P(lmod
) ? Z_LVAL_P(lmod
) : time(NULL
), cc_header
, strlen(cc_header
));
682 if (Z_LVAL_P(do_gzip
)) {
688 zval
*ctype
= GET_PROP(obj
, contentType
);
689 if (Z_STRLEN_P(ctype
)) {
690 http_send_content_type(Z_STRVAL_P(ctype
), Z_STRLEN_P(ctype
));
692 http_send_content_type("application/x-octetstream", sizeof("application/x-octetstream") - 1);
696 /* content disposition */
698 zval
*dispo_file
= GET_PROP(obj
, dispoFile
);
699 if (Z_STRLEN_P(dispo_file
)) {
700 zval
*dispo_inline
= GET_PROP(obj
, dispoInline
);
701 http_send_content_disposition(Z_STRVAL_P(dispo_file
), Z_STRLEN_P(dispo_file
), Z_LVAL_P(dispo_inline
));
707 zval
*send_mode
= GET_PROP(obj
, send_mode
);
708 switch (Z_LVAL_P(send_mode
))
712 RETURN_SUCCESS(http_send_data(GET_PROP(obj
, data
)));
717 php_stream
*the_real_stream
;
718 zval
*the_stream
= GET_PROP(obj
, stream
);
719 php_stream_from_zval(the_real_stream
, &the_stream
);
720 RETURN_SUCCESS(http_send_stream(the_real_stream
));
725 RETURN_SUCCESS(http_send_file(GET_PROP(obj
, file
)));
732 /* {{{ HTTPi_Request */
733 #ifdef HTTP_HAVE_CURL
735 zend_class_entry
*httpi_request_ce
;
736 static zend_object_handlers httpi_request_object_handlers
;
741 } httpi_request_object
;
743 #define httpi_request_declare_default_properties(ce) _httpi_request_declare_default_properties(ce TSRMLS_CC)
744 static inline void _httpi_request_declare_default_properties(zend_class_entry
*ce TSRMLS_DC
)
746 DCL_PROP_N(PROTECTED
, options
);
747 DCL_PROP_N(PROTECTED
, responseInfo
);
748 DCL_PROP_N(PROTECTED
, responseData
);
750 DCL_PROP(PROTECTED
, long, method
, HTTP_GET
);
752 DCL_PROP(PROTECTED
, string
, url
, "");
753 DCL_PROP(PROTECTED
, string
, contentType
, "");
754 DCL_PROP(PROTECTED
, string
, queryData
, "");
755 DCL_PROP(PROTECTED
, string
, postData
, "");
758 #define httpi_request_free_object _httpi_request_free_object
759 void _httpi_request_free_object(zend_object
/* void */ *object TSRMLS_DC
)
761 httpi_request_object
*o
= (httpi_request_object
*) object
;
764 zend_hash_destroy(OBJ_PROP(o
));
765 FREE_HASHTABLE(OBJ_PROP(o
));
768 curl_easy_cleanup(o
->ch
);
774 #define httpi_request_new_object _httpi_request_new_object
775 zend_object_value
_httpi_request_new_object(zend_class_entry
*ce TSRMLS_DC
)
777 zend_object_value ov
;
778 httpi_request_object
*o
;
780 o
= ecalloc(sizeof(httpi_request_object
), 1);
782 o
->ch
= curl_easy_init();
784 ALLOC_HASHTABLE(OBJ_PROP(o
));
785 zend_hash_init(OBJ_PROP(o
), 0, NULL
, ZVAL_PTR_DTOR
, 0);
786 zend_hash_copy(OBJ_PROP(o
), &ce
->default_properties
, (copy_ctor_func_t
) zval_add_ref
, NULL
, sizeof(zval
*));
788 ov
.handle
= zend_objects_store_put(o
, zend_objects_destroy_object
, httpi_request_free_object
, NULL TSRMLS_CC
);
789 ov
.handlers
= &httpi_request_object_handlers
;
794 zend_function_entry httpi_request_class_methods
[] = {
795 PHP_ME(HTTPi_Request
, __construct
, NULL
, ZEND_ACC_PUBLIC
|ZEND_ACC_CTOR
)
796 PHP_ME(HTTPi_Request
, __destruct
, NULL
, ZEND_ACC_PUBLIC
|ZEND_ACC_DTOR
)
798 PHP_ME(HTTPi_Request
, setOptions
, NULL
, ZEND_ACC_PUBLIC
)
799 PHP_ME(HTTPi_Request
, getOptions
, NULL
, ZEND_ACC_PUBLIC
)
801 PHP_ME(HTTPi_Request
, setMethod
, NULL
, ZEND_ACC_PUBLIC
)
802 PHP_ME(HTTPi_Request
, getMethod
, NULL
, ZEND_ACC_PUBLIC
)
804 PHP_ME(HTTPi_Request
, setURL
, NULL
, ZEND_ACC_PUBLIC
)
805 PHP_ME(HTTPi_Request
, getURL
, NULL
, ZEND_ACC_PUBLIC
)
807 PHP_ME(HTTPi_Request
, setContentType
, NULL
, ZEND_ACC_PUBLIC
)
808 PHP_ME(HTTPi_Request
, getContentType
, NULL
, ZEND_ACC_PUBLIC
)
810 PHP_ME(HTTPi_Request
, setQueryData
, NULL
, ZEND_ACC_PUBLIC
)
811 PHP_ME(HTTPi_Request
, getQueryData
, NULL
, ZEND_ACC_PUBLIC
)
812 PHP_ME(HTTPi_Request
, addQueryData
, NULL
, ZEND_ACC_PUBLIC
)
813 PHP_ME(HTTPi_Request
, unsetQueryData
, NULL
, ZEND_ACC_PUBLIC
)
815 PHP_ME(HTTPi_Request, setPostData, NULL, ZEND_ACC_PUBLIC)
816 PHP_ME(HTTPi_Request, addPostData, NULL, ZEND_ACC_PUBLIC)
817 PHP_ME(HTTPi_Request, unsetPostData, NULL, ZEND_ACC_PUBLIC)
819 PHP_ME(HTTPi_Request, addPostFile, NULL, ZEND_ACC_PUBLIC)
821 PHP_ME(HTTPi_Request
, send
, NULL
, ZEND_ACC_PUBLIC
)
823 PHP_ME(HTTPi_Request
, getResponseData
, NULL
, ZEND_ACC_PUBLIC
)
824 PHP_ME(HTTPi_Request
, getResponseHeaders
, NULL
, ZEND_ACC_PUBLIC
)
825 PHP_ME(HTTPi_Request
, getResponseBody
, NULL
, ZEND_ACC_PUBLIC
)
826 PHP_ME(HTTPi_Request
, getResponseInfo
, NULL
, ZEND_ACC_PUBLIC
)
831 /* {{{ proto void HTTPi_Request::__construct([string url[, long request_method = HTTP_GET]])
834 PHP_METHOD(HTTPi_Request
, __construct
)
839 zval
*info
, *opts
, *resp
;
840 getObject(httpi_request_object
, obj
);
842 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|sl", &URL
, &URL_len
, &meth
)) {
846 INIT_PARR(obj
, options
);
847 INIT_PARR(obj
, responseInfo
);
848 INIT_PARR(obj
, responseData
);
851 UPD_PROP(obj
, string
, url
, URL
);
854 UPD_PROP(obj
, long, method
, meth
);
859 /* {{{ proto void HTTPi_Request::__destruct()
862 PHP_METHOD(HTTPi_Request
, __destruct
)
864 getObject(httpi_request_object
, obj
);
868 FREE_PARR(obj
, options
);
869 FREE_PARR(obj
, responseInfo
);
870 FREE_PARR(obj
, responseData
);
874 /* {{{ proto bool HTTPi_Request::setOptions(array options)
877 PHP_METHOD(HTTPi_Request
, setOptions
)
879 zval
*opts
, *old_opts
, **opt
;
880 getObject(httpi_request_object
, obj
);
882 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a/", &opts
)) {
886 old_opts
= GET_PROP(obj
, options
);
888 /* headers and cookies need extra attention -- thus cannot use zend_hash_merge() or php_array_merge() directly */
889 for ( zend_hash_internal_pointer_reset(Z_ARRVAL_P(opts
));
890 zend_hash_get_current_data(Z_ARRVAL_P(opts
), (void **) &opt
) == SUCCESS
;
891 zend_hash_move_forward(Z_ARRVAL_P(opts
))) {
894 if (HASH_KEY_IS_STRING
== zend_hash_get_current_key(Z_ARRVAL_P(opts
), &key
, &idx
, 0)) {
895 if (!strcmp(key
, "headers")) {
897 if (SUCCESS
== zend_hash_find(Z_ARRVAL_P(old_opts
), "headers", sizeof("headers"), (void **) &headers
)) {
898 array_merge(*opt
, *headers
);
901 } else if (!strcmp(key
, "cookies")) {
903 if (SUCCESS
== zend_hash_find(Z_ARRVAL_P(old_opts
), "cookies", sizeof("cookies"), (void **) &cookies
)) {
904 array_merge(*opt
, *cookies
);
909 add_assoc_zval(old_opts
, key
, *opt
);
916 /* {{{ proto array HTTPi_Request::getOptions()
919 PHP_METHOD(HTTPi_Request
, getOptions
)
922 getObject(httpi_request_object
, obj
);
926 opts
= GET_PROP(obj
, options
);
927 array_init(return_value
);
928 array_copy(opts
, return_value
);
932 /* {{{ proto bool HTTPi_Request::setURL(string url)
935 PHP_METHOD(HTTPi_Request
, setURL
)
939 getObject(httpi_request_object
, obj
);
941 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &URL
, &URL_len
)) {
945 UPD_PROP(obj
, string
, url
, URL
);
950 /* {{{ proto string HTTPi_Request::getUrl()
953 PHP_METHOD(HTTPi_Request
, getURL
)
956 getObject(httpi_request_object
, obj
);
960 URL
= GET_PROP(obj
, url
);
961 RETURN_STRINGL(Z_STRVAL_P(URL
), Z_STRLEN_P(URL
), 1);
965 /* {{{ proto bool HTTPi_Request::setMethod(long request_method)
968 PHP_METHOD(HTTPi_Request
, setMethod
)
971 getObject(httpi_request_object
, obj
);
973 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &meth
)) {
977 UPD_PROP(obj
, long, method
, meth
);
982 /* {{{ proto long HTTPi_Request::getMethod()
985 PHP_METHOD(HTTPi_Request
, getMethod
)
988 getObject(httpi_request_object
, obj
);
992 meth
= GET_PROP(obj
, method
);
993 RETURN_LONG(Z_LVAL_P(meth
));
997 /* {{{ proto bool HTTPi_Request::setContentType(string content_type)
1000 PHP_METHOD(HTTPi_Request
, setContentType
)
1004 getObject(httpi_request_object
, obj
);
1006 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &ctype
, &ct_len
)) {
1010 if (!strchr(ctype
, '/')) {
1011 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
1012 "Content-Type '%s' doesn't seem to contain a primary and a secondary part",
1017 UPD_PROP(obj
, string
, contentType
, ctype
);
1022 /* {{{ proto string HTTPi_Request::getContentType()
1025 PHP_METHOD(HTTPi_Request
, getContentType
)
1028 getObject(httpi_request_object
, obj
);
1032 ctype
= GET_PROP(obj
, contentType
);
1033 RETURN_STRINGL(Z_STRVAL_P(ctype
), Z_STRLEN_P(ctype
), 1);
1037 /* {{{ proto bool HTTPi_Request::setQueryData(mixed query_data)
1040 PHP_METHOD(HTTPi_Request
, setQueryData
)
1043 getObject(httpi_request_object
, obj
);
1045 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z", &qdata
)) {
1049 if ((Z_TYPE_P(qdata
) == IS_ARRAY
) || (Z_TYPE_P(qdata
) == IS_OBJECT
)) {
1050 smart_str qstr
= {0};
1051 HTTP_URL_ARGSEP_OVERRIDE
;
1052 if (SUCCESS
!= php_url_encode_hash_ex(HASH_OF(qdata
), &qstr
, NULL
, 0, NULL
, 0, NULL
, 0, NULL TSRMLS_CC
)) {
1053 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Couldn't encode query data");
1057 HTTP_URL_ARGSEP_RESTORE
;
1060 HTTP_URL_ARGSEP_RESTORE
;
1062 UPD_PROP(obj
, string
, queryData
, qstr
.c
);
1067 convert_to_string(qdata
);
1068 UPD_PROP(obj
, string
, queryData
, Z_STRVAL_P(qdata
));
1073 /* {{{ proto string HTTPi_Request::getQueryData()
1076 PHP_METHOD(HTTPi_Request
, getQueryData
)
1079 getObject(httpi_request_object
, obj
);
1083 qdata
= GET_PROP(obj
, queryData
);
1084 RETURN_STRINGL(Z_STRVAL_P(qdata
), Z_STRLEN_P(qdata
), 1);
1088 /* {{{ proto bool HTTPi_Request::addQueryData(array query_params)
1091 PHP_METHOD(HTTPi_Request
, addQueryData
)
1093 zval
*qdata
, *old_qdata
;
1094 smart_str qstr
= {0};
1096 getObject(httpi_request_object
, obj
);
1098 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a", &qdata
)) {
1102 old_qdata
= GET_PROP(obj
, queryData
);
1103 if (Z_STRLEN_P(old_qdata
)) {
1104 smart_str_appendl(&qstr
, Z_STRVAL_P(old_qdata
), Z_STRLEN_P(old_qdata
));
1107 HTTP_URL_ARGSEP_OVERRIDE
;
1108 if (SUCCESS
!= php_url_encode_hash_ex(HASH_OF(qdata
), &qstr
, NULL
, 0, NULL
, 0, NULL
, 0, NULL TSRMLS_CC
)) {
1109 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Couldn't encode query data");
1113 HTTP_URL_ARGSEP_RESTORE
;
1116 HTTP_URL_ARGSEP_RESTORE
;
1120 UPD_PROP(obj
, string
, queryData
, qstr
.c
);
1126 /* {{{ proto void HTTPi_Request::unsetQueryData()
1129 PHP_METHOD(HTTPi_Request
, unsetQueryData
)
1131 getObject(httpi_request_object
, obj
);
1135 UPD_PROP(obj
, string
, queryData
, "");
1139 /* {{{ proto array HTTPi_Request::getResponseData()
1142 PHP_METHOD(HTTPi_Request
, getResponseData
)
1145 getObject(httpi_request_object
, obj
);
1149 data
= GET_PROP(obj
, responseData
);
1150 array_init(return_value
);
1151 array_copy(data
, return_value
);
1155 /* {{{ proto array HTTPi_Request::getResponseHeaders()
1158 PHP_METHOD(HTTPi_Request
, getResponseHeaders
)
1160 zval
*data
, **headers
;
1161 getObject(httpi_request_object
, obj
);
1165 array_init(return_value
);
1166 data
= GET_PROP(obj
, responseData
);
1167 if (SUCCESS
== zend_hash_find(Z_ARRVAL_P(data
), "headers", sizeof("headers"), (void **) &headers
)) {
1168 array_copy(*headers
, return_value
);
1173 /* {{{ proto string HTTPi_Request::getResponseBody()
1176 PHP_METHOD(HTTPi_Request
, getResponseBody
)
1179 getObject(httpi_request_object
, obj
);
1183 data
= GET_PROP(obj
, responseData
);
1184 if (SUCCESS
== zend_hash_find(Z_ARRVAL_P(data
), "body", sizeof("body"), (void **) &body
)) {
1185 RETURN_STRINGL(Z_STRVAL_PP(body
), Z_STRLEN_PP(body
), 1);
1187 Z_TYPE_P(return_value
) = IS_NULL
;
1192 /* {{{ proto array HTTPi_Request::getResponseInfo()
1195 PHP_METHOD(HTTPi_Request
, getResponseInfo
)
1198 getObject(httpi_request_object
, obj
);
1202 info
= GET_PROP(obj
, responseInfo
);
1203 array_init(return_value
);
1204 array_copy(info
, return_value
);
1208 /* {{{ proto bool HTTPi_Request::send()
1211 PHP_METHOD(HTTPi_Request
, send
)
1213 STATUS status
= FAILURE
;
1214 zval
*meth
, *URL
, *qdata
, *opts
, *info
, *resp
;
1215 char *response_data
, *request_uri
, *uri
;
1216 size_t response_len
;
1217 getObject(httpi_request_object
, obj
);
1221 if ((!obj
->ch
) && (!(obj
->ch
= curl_easy_init()))) {
1222 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not initilaize cURL");
1226 meth
= GET_PROP(obj
, method
);
1227 URL
= GET_PROP(obj
, url
);
1228 qdata
= GET_PROP(obj
, queryData
);
1229 opts
= GET_PROP(obj
, options
);
1230 info
= GET_PROP(obj
, responseInfo
);
1231 resp
= GET_PROP(obj
, responseData
);
1233 uri
= http_absolute_uri(Z_STRVAL_P(URL
), NULL
);
1234 request_uri
= ecalloc(HTTP_URI_MAXLEN
+ 1, 1);
1235 strcpy(request_uri
, uri
);
1238 if (Z_STRLEN_P(qdata
) && (strlen(request_uri
) < HTTP_URI_MAXLEN
)) {
1239 if (!strchr(request_uri
, '?')) {
1240 strcat(request_uri
, "?");
1242 strcat(request_uri
, "&");
1244 strncat(request_uri
, Z_STRVAL_P(qdata
), HTTP_URI_MAXLEN
- strlen(request_uri
));
1247 switch (Z_LVAL_P(meth
))
1250 status
= http_get_ex(obj
->ch
, request_uri
, Z_ARRVAL_P(opts
), Z_ARRVAL_P(info
), &response_data
, &response_len
);
1254 status
= http_head_ex(obj
->ch
, request_uri
, Z_ARRVAL_P(opts
), Z_ARRVAL_P(info
), &response_data
, &response_len
);
1266 /* final data handling */
1267 if (status
!= SUCCESS
) {
1270 zval
*zheaders
, *zbody
;
1272 MAKE_STD_ZVAL(zbody
);
1273 MAKE_STD_ZVAL(zheaders
)
1274 array_init(zheaders
);
1276 if (SUCCESS
!= http_split_response_ex(response_data
, response_len
, zheaders
, zbody
)) {
1277 zval_dtor(zheaders
);
1280 efree(response_data
);
1284 add_assoc_zval(resp
, "headers", zheaders
);
1285 add_assoc_zval(resp
, "body", zbody
);
1287 efree(response_data
);
1295 #endif /* HTTP_HAVE_CURL */
1298 #endif /* ZEND_ENGINE_2 */
1300 /* {{{ http_module_entry */
1301 zend_module_entry http_module_entry
= {
1302 #if ZEND_MODULE_API_NO >= 20010901
1303 STANDARD_MODULE_HEADER
,
1308 PHP_MSHUTDOWN(http
),
1310 PHP_RSHUTDOWN(http
),
1312 #if ZEND_MODULE_API_NO >= 20010901
1313 PHP_EXT_HTTP_VERSION
,
1315 STANDARD_MODULE_PROPERTIES
1319 /* {{{ proto string http_date([int timestamp])
1321 * This function returns a valid HTTP date regarding RFC 822/1123
1322 * looking like: "Wed, 22 Dec 2004 11:34:47 GMT"
1325 PHP_FUNCTION(http_date
)
1329 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|l", &t
) != SUCCESS
) {
1334 t
= (long) time(NULL
);
1337 RETURN_STRING(http_date(t
), 0);
1341 /* {{{ proto string http_absolute_uri(string url[, string proto])
1343 * This function returns an absolute URI constructed from url.
1344 * If the url is already abolute but a different proto was supplied,
1345 * only the proto part of the URI will be updated. If url has no
1346 * path specified, the path of the current REQUEST_URI will be taken.
1347 * The host will be taken either from the Host HTTP header of the client
1348 * the SERVER_NAME or just localhost if prior are not available.
1352 * url = "page.php" => http://www.example.com/current/path/page.php
1353 * url = "/page.php" => http://www.example.com/page.php
1354 * url = "/page.php", proto = "https" => https://www.example.com/page.php
1358 PHP_FUNCTION(http_absolute_uri
)
1360 char *url
= NULL
, *proto
= NULL
;
1361 int url_len
= 0, proto_len
= 0;
1363 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|s", &url
, &url_len
, &proto
, &proto_len
) != SUCCESS
) {
1367 RETURN_STRING(http_absolute_uri(url
, proto
), 0);
1371 /* {{{ proto string http_negotiate_language(array supported[, string default = 'en-US'])
1373 * This function negotiates the clients preferred language based on its
1374 * Accept-Language HTTP header. It returns the negotiated language or
1375 * the default language if none match.
1377 * The qualifier is recognized and languages without qualifier are rated highest.
1379 * The supported parameter is expected to be an array having
1380 * the supported languages as array values.
1386 * 'en-US',// default
1394 * include './langs/'. http_negotiate_language($langs) .'.php';
1399 PHP_FUNCTION(http_negotiate_language
)
1405 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a|s", &supported
, &def
, &def_len
) != SUCCESS
) {
1413 RETURN_STRING(http_negotiate_language(supported
, def
), 0);
1417 /* {{{ proto string http_negotiate_charset(array supported[, string default = 'iso-8859-1'])
1419 * This function negotiates the clients preferred charset based on its
1420 * Accept-Charset HTTP header. It returns the negotiated charset or
1421 * the default charset if none match.
1423 * The qualifier is recognized and charset without qualifier are rated highest.
1425 * The supported parameter is expected to be an array having
1426 * the supported charsets as array values.
1431 * $charsets = array(
1432 * 'iso-8859-1', // default
1437 * $pref = http_negotiate_charset($charsets);
1438 * if (!strcmp($pref, 'iso-8859-1')) {
1439 * iconv_set_encoding('internal_encoding', 'iso-8859-1');
1440 * iconv_set_encoding('output_encoding', $pref);
1441 * ob_start('ob_iconv_handler');
1446 PHP_FUNCTION(http_negotiate_charset
)
1452 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a|s", &supported
, &def
, &def_len
) != SUCCESS
) {
1460 RETURN_STRING(http_negotiate_charset(supported
, def
), 0);
1464 /* {{{ proto bool http_send_status(int status)
1466 * Send HTTP status code.
1469 PHP_FUNCTION(http_send_status
)
1473 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &status
) != SUCCESS
) {
1476 if (status
< 100 || status
> 510) {
1477 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Invalid HTTP status code (100-510): %d", status
);
1481 RETURN_SUCCESS(http_send_status(status
));
1485 /* {{{ proto bool http_send_last_modified([int timestamp])
1487 * This converts the given timestamp to a valid HTTP date and
1488 * sends it as "Last-Modified" HTTP header. If timestamp is
1489 * omitted, current time is sent.
1492 PHP_FUNCTION(http_send_last_modified
)
1496 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|l", &t
) != SUCCESS
) {
1501 t
= (long) time(NULL
);
1504 RETURN_SUCCESS(http_send_last_modified(t
));
1508 /* {{{ proto bool http_send_content_type([string content_type = 'application/x-octetstream'])
1510 * Sets the content type.
1513 PHP_FUNCTION(http_send_content_type
)
1518 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s", &ct
, &ct_len
) != SUCCESS
) {
1523 RETURN_SUCCESS(http_send_content_type("application/x-octetstream", sizeof("application/x-octetstream") - 1));
1525 RETURN_SUCCESS(http_send_content_type(ct
, ct_len
));
1529 /* {{{ proto bool http_send_content_disposition(string filename[, bool inline = false])
1531 * Set the Content Disposition. The Content-Disposition header is very useful
1532 * if the data actually sent came from a file or something similar, that should
1533 * be "saved" by the client/user (i.e. by browsers "Save as..." popup window).
1536 PHP_FUNCTION(http_send_content_disposition
)
1540 zend_bool send_inline
= 0;
1542 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|b", &filename
, &f_len
, &send_inline
) != SUCCESS
) {
1545 RETURN_SUCCESS(http_send_content_disposition(filename
, f_len
, send_inline
));
1549 /* {{{ proto bool http_match_modified([int timestamp])
1551 * Matches the given timestamp against the clients "If-Modified-Since" resp.
1552 * "If-Unmodified-Since" HTTP headers.
1555 PHP_FUNCTION(http_match_modified
)
1559 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|l", &t
) != SUCCESS
) {
1563 // current time if not supplied (senseless though)
1565 t
= (long) time(NULL
);
1568 RETURN_BOOL(http_modified_match("HTTP_IF_MODIFIED_SINCE", t
) || http_modified_match("HTTP_IF_UNMODIFIED_SINCE", t
));
1572 /* {{{ proto bool http_match_etag(string etag)
1574 * This matches the given ETag against the clients
1575 * "If-Match" resp. "If-None-Match" HTTP headers.
1578 PHP_FUNCTION(http_match_etag
)
1583 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &etag
, &etag_len
) != SUCCESS
) {
1587 RETURN_BOOL(http_etag_match("HTTP_IF_NONE_MATCH", etag
) || http_etag_match("HTTP_IF_MATCH", etag
));
1591 /* {{{ proto bool http_cache_last_modified([int timestamp_or_expires]])
1593 * If timestamp_or_exires is greater than 0, it is handled as timestamp
1594 * and will be sent as date of last modification. If it is 0 or omitted,
1595 * the current time will be sent as Last-Modified date. If it's negative,
1596 * it is handled as expiration time in seconds, which means that if the
1597 * requested last modification date is not between the calculated timespan,
1598 * the Last-Modified header is updated and the actual body will be sent.
1601 PHP_FUNCTION(http_cache_last_modified
)
1603 long last_modified
= 0, send_modified
= 0, t
;
1606 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|l", &last_modified
) != SUCCESS
) {
1610 t
= (long) time(NULL
);
1613 if (!last_modified
) {
1614 /* does the client have? (att: caching "forever") */
1615 if (zlm
= http_get_server_var("HTTP_IF_MODIFIED_SINCE")) {
1616 last_modified
= send_modified
= http_parse_date(Z_STRVAL_P(zlm
));
1617 /* send current time */
1621 /* negative value is supposed to be expiration time */
1622 } else if (last_modified
< 0) {
1625 /* send supplied time explicitly */
1627 send_modified
= last_modified
;
1630 RETURN_SUCCESS(http_cache_last_modified(last_modified
, send_modified
, HTTP_DEFAULT_CACHECONTROL
, sizeof(HTTP_DEFAULT_CACHECONTROL
) - 1));
1634 /* {{{ proto bool http_cache_etag([string etag])
1636 * This function attempts to cache the HTTP body based on an ETag,
1637 * either supplied or generated through calculation of the MD5
1638 * checksum of the output (uses output buffering).
1640 * If clients "If-None-Match" header matches the supplied/calculated
1641 * ETag, the body is considered cached on the clients side and
1642 * a "304 Not Modified" status code is issued.
1645 PHP_FUNCTION(http_cache_etag
)
1650 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s", &etag
, &etag_len
) != SUCCESS
) {
1654 RETURN_SUCCESS(http_cache_etag(etag
, etag_len
, HTTP_DEFAULT_CACHECONTROL
, sizeof(HTTP_DEFAULT_CACHECONTROL
) - 1));
1658 /* {{{ proto string ob_httpetaghandler(string data, int mode)
1660 * For use with ob_start().
1661 * Note that this has to be started as first output buffer.
1662 * WARNING: Don't use with http_send_*().
1664 PHP_FUNCTION(ob_httpetaghandler
)
1670 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "sl", &data
, &data_len
, &mode
)) {
1674 if (mode
& PHP_OUTPUT_HANDLER_START
) {
1675 if (HTTP_G(etag_started
)) {
1676 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "ob_httpetaghandler can only be used once");
1677 RETURN_STRINGL(data
, data_len
, 1);
1679 http_send_header("Cache-Control: " HTTP_DEFAULT_CACHECONTROL
);
1680 HTTP_G(etag_started
) = 1;
1683 if (OG(ob_nesting_level
) > 1) {
1684 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "ob_httpetaghandler must be started prior to other output buffers");
1685 RETURN_STRINGL(data
, data_len
, 1);
1688 Z_TYPE_P(return_value
) = IS_STRING
;
1689 http_ob_etaghandler(data
, data_len
, &Z_STRVAL_P(return_value
), &Z_STRLEN_P(return_value
), mode
);
1693 /* {{{ proto void http_redirect([string url[, array params[, bool session,[ bool permanent]]]])
1695 * Redirect to a given url.
1696 * The supplied url will be expanded with http_absolute_uri(), the params array will
1697 * be treated with http_build_query() and the session identification will be appended
1698 * if session is true.
1700 * Depending on permanent the redirection will be issued with a permanent
1701 * ("301 Moved Permanently") or a temporary ("302 Found") redirection
1704 * To be RFC compliant, "Redirecting to <a>URI</a>." will be displayed,
1705 * if the client doesn't redirect immediatly.
1707 PHP_FUNCTION(http_redirect
)
1710 zend_bool session
= 0, permanent
= 0;
1711 zval
*params
= NULL
;
1712 smart_str qstr
= {0};
1713 char *url
, *URI
, LOC
[HTTP_URI_MAXLEN
+ 9], RED
[HTTP_URI_MAXLEN
* 2 + 34];
1715 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|sa!/bb", &url
, &url_len
, ¶ms
, &session
, &permanent
) != SUCCESS
) {
1719 /* append session info */
1720 if (session
&& (PS(session_status
) == php_session_active
)) {
1722 MAKE_STD_ZVAL(params
);
1725 if (add_assoc_string(params
, PS(session_name
), PS(id
), 1) != SUCCESS
) {
1726 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not append session information");
1730 /* treat params array with http_build_query() */
1732 if (php_url_encode_hash_ex(Z_ARRVAL_P(params
), &qstr
, NULL
,0,NULL
,0,NULL
,0,NULL TSRMLS_CC
) != SUCCESS
) {
1736 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not encode query parameters");
1742 URI
= http_absolute_uri(url
, NULL
);
1744 snprintf(LOC
, HTTP_URI_MAXLEN
+ strlen("Location: "), "Location: %s?%s", URI
, qstr
.c
);
1745 sprintf(RED
, "Redirecting to <a href=\"%s?%s\">%s?%s</a>.\n", URI
, qstr
.c
, URI
, qstr
.c
);
1748 snprintf(LOC
, HTTP_URI_MAXLEN
+ strlen("Location: "), "Location: %s", URI
);
1749 sprintf(RED
, "Redirecting to <a href=\"%s\">%s</a>.\n", URI
, URI
);
1753 if ((SUCCESS
== http_send_header(LOC
)) && (SUCCESS
== http_send_status((permanent
? 301 : 302)))) {
1754 php_body_write(RED
, strlen(RED
) TSRMLS_CC
);
1761 /* {{{ proto bool http_send_data(string data)
1763 * Sends raw data with support for (multiple) range requests.
1766 PHP_FUNCTION(http_send_data
)
1770 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z", &zdata
) != SUCCESS
) {
1774 convert_to_string_ex(&zdata
);
1775 http_send_header("Accept-Ranges: bytes");
1776 RETURN_SUCCESS(http_send_data(zdata
));
1780 /* {{{ proto bool http_send_file(string file)
1782 * Sends a file with support for (multiple) range requests.
1785 PHP_FUNCTION(http_send_file
)
1789 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z", &zfile
) != SUCCESS
) {
1793 convert_to_string_ex(&zfile
);
1794 http_send_header("Accept-Ranges: bytes");
1795 RETURN_SUCCESS(http_send_file(zfile
));
1799 /* {{{ proto bool http_send_stream(resource stream)
1801 * Sends an already opened stream with support for (multiple) range requests.
1804 PHP_FUNCTION(http_send_stream
)
1809 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "r", &zstream
) != SUCCESS
) {
1813 php_stream_from_zval(file
, &zstream
);
1814 http_send_header("Accept-Ranges: bytes");
1815 RETURN_SUCCESS(http_send_stream(file
));
1819 /* {{{ proto string http_chunked_decode(string encoded)
1821 * This function decodes a string that was HTTP-chunked encoded.
1822 * Returns false on failure.
1824 PHP_FUNCTION(http_chunked_decode
)
1826 char *encoded
= NULL
, *decoded
= NULL
;
1827 int encoded_len
= 0, decoded_len
= 0;
1829 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &encoded
, &encoded_len
) != SUCCESS
) {
1833 if (SUCCESS
== http_chunked_decode(encoded
, encoded_len
, &decoded
, &decoded_len
)) {
1834 RETURN_STRINGL(decoded
, decoded_len
, 0);
1841 /* {{{ proto array http_split_response(string http_response)
1843 * This function splits an HTTP response into an array with headers and the
1844 * content body. The returned array may look simliar to the following example:
1850 * 'Status' => '200 Ok',
1851 * 'Content-Type' => 'text/plain',
1852 * 'Content-Language' => 'en-US'
1854 * 1 => "Hello World!"
1859 PHP_FUNCTION(http_split_response
)
1861 zval
*zresponse
, *zbody
, *zheaders
;
1863 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z", &zresponse
) != SUCCESS
) {
1867 convert_to_string_ex(&zresponse
);
1869 MAKE_STD_ZVAL(zbody
);
1870 MAKE_STD_ZVAL(zheaders
);
1871 array_init(zheaders
);
1873 if (SUCCESS
!= http_split_response(zresponse
, zheaders
, zbody
)) {
1874 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not parse HTTP response");
1878 array_init(return_value
);
1879 add_index_zval(return_value
, 0, zheaders
);
1880 add_index_zval(return_value
, 1, zbody
);
1884 /* {{{ proto array http_parse_headers(string header)
1887 PHP_FUNCTION(http_parse_headers
)
1889 char *header
, *rnrn
;
1892 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &header
, &header_len
)) {
1896 array_init(return_value
);
1898 if (rnrn
= strstr(header
, HTTP_CRLF HTTP_CRLF
)) {
1899 header_len
= rnrn
- header
+ 2;
1901 if (SUCCESS
!= http_parse_headers(header
, header_len
, return_value
)) {
1902 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not parse HTTP header");
1903 zval_dtor(return_value
);
1909 /* {{{ proto array http_get_request_headers(void)
1912 PHP_FUNCTION(http_get_request_headers
)
1914 if (ZEND_NUM_ARGS()) {
1918 array_init(return_value
);
1919 http_get_request_headers(return_value
);
1924 #ifdef HTTP_HAVE_CURL
1926 /* {{{ proto string http_get(string url[, array options[, array &info]])
1928 * Performs an HTTP GET request on the supplied url.
1930 * The second parameter is expected to be an associative
1931 * array where the following keys will be recognized:
1933 * - redirect: int, whether and how many redirects to follow
1934 * - unrestrictedauth: bool, whether to continue sending credentials on
1935 * redirects to a different host
1936 * - proxyhost: string, proxy host in "host[:port]" format
1937 * - proxyport: int, use another proxy port as specified in proxyhost
1938 * - proxyauth: string, proxy credentials in "user:pass" format
1939 * - proxyauthtype: int, HTTP_AUTH_BASIC and/or HTTP_AUTH_NTLM
1940 * - httpauth: string, http credentials in "user:pass" format
1941 * - httpauthtype: int, HTTP_AUTH_BASIC, DIGEST and/or NTLM
1942 * - compress: bool, whether to allow gzip/deflate content encoding
1943 * (defaults to true)
1944 * - port: int, use another port as specified in the url
1945 * - referer: string, the referer to sends
1946 * - useragent: string, the user agent to send
1947 * (defaults to PECL::HTTP/version (PHP/version)))
1948 * - headers: array, list of custom headers as associative array
1949 * like array("header" => "value")
1950 * - cookies: array, list of cookies as associative array
1951 * like array("cookie" => "value")
1952 * - cookiestore: string, path to a file where cookies are/will be stored
1955 * The optional third parameter will be filled with some additional information
1956 * in form af an associative array, if supplied, like the following example:
1960 * 'effective_url' => 'http://localhost',
1961 * 'response_code' => 403,
1962 * 'total_time' => 0.017,
1963 * 'namelookup_time' => 0.013,
1964 * 'connect_time' => 0.014,
1965 * 'pretransfer_time' => 0.014,
1966 * 'size_upload' => 0,
1967 * 'size_download' => 202,
1968 * 'speed_download' => 11882,
1969 * 'speed_upload' => 0,
1970 * 'header_size' => 145,
1971 * 'request_size' => 62,
1972 * 'ssl_verifyresult' => 0,
1974 * 'content_length_download' => 202,
1975 * 'content_length_upload' => 0,
1976 * 'starttransfer_time' => 0.017,
1977 * 'content_type' => 'text/html; charset=iso-8859-1',
1978 * 'redirect_time' => 0,
1979 * 'redirect_count' => 0,
1981 * 'http_connectcode' => 0,
1982 * 'httpauth_avail' => 0,
1983 * 'proxyauth_avail' => 0,
1988 PHP_FUNCTION(http_get
)
1990 char *URL
, *data
= NULL
;
1991 size_t data_len
= 0;
1993 zval
*options
= NULL
, *info
= NULL
;
1995 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|a/!z", &URL
, &URL_len
, &options
, &info
) != SUCCESS
) {
2004 if (SUCCESS
== http_get(URL
, HASH_ORNULL(options
), HASH_ORNULL(info
), &data
, &data_len
)) {
2005 RETURN_STRINGL(data
, data_len
, 0);
2012 /* {{{ proto string http_head(string url[, array options[, array &info]])
2014 * Performs an HTTP HEAD request on the suppied url.
2015 * Returns the HTTP response as string.
2016 * See http_get() for a full list of available options.
2018 PHP_FUNCTION(http_head
)
2020 char *URL
, *data
= NULL
;
2021 size_t data_len
= 0;
2023 zval
*options
= NULL
, *info
= NULL
;
2025 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|a/!z", &URL
, &URL_len
, &options
, &info
) != SUCCESS
) {
2034 if (SUCCESS
== http_head(URL
, HASH_ORNULL(options
), HASH_ORNULL(info
), &data
, &data_len
)) {
2035 RETURN_STRINGL(data
, data_len
, 0);
2042 /* {{{ proto string http_post_data(string url, string data[, array options[, &info]])
2044 * Performs an HTTP POST request, posting data.
2045 * Returns the HTTP response as string.
2046 * See http_get() for a full list of available options.
2048 PHP_FUNCTION(http_post_data
)
2050 char *URL
, *postdata
, *data
= NULL
;
2051 size_t data_len
= 0;
2052 int postdata_len
, URL_len
;
2053 zval
*options
= NULL
, *info
= NULL
;
2055 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "ss|a/!z", &URL
, &URL_len
, &postdata
, &postdata_len
, &options
, &info
) != SUCCESS
) {
2064 if (SUCCESS
== http_post_data(URL
, postdata
, (size_t) postdata_len
, HASH_ORNULL(options
), HASH_ORNULL(info
), &data
, &data_len
)) {
2065 RETURN_STRINGL(data
, data_len
, 0);
2072 /* {{{ proto string http_post_array(string url, array data[, array options[, array &info]])
2074 * Performs an HTTP POST request, posting www-form-urlencoded array data.
2075 * Returns the HTTP response as string.
2076 * See http_get() for a full list of available options.
2078 PHP_FUNCTION(http_post_array
)
2080 char *URL
, *data
= NULL
;
2081 size_t data_len
= 0;
2083 zval
*options
= NULL
, *info
= NULL
, *postdata
;
2085 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "sa|a/!z", &URL
, &URL_len
, &postdata
, &options
, &info
) != SUCCESS
) {
2094 if (SUCCESS
== http_post_array(URL
, Z_ARRVAL_P(postdata
), HASH_ORNULL(options
), HASH_ORNULL(info
), &data
, &data_len
)) {
2095 RETURN_STRINGL(data
, data_len
, 0);
2106 /* {{{ proto bool http_auth_basic(string user, string pass[, string realm = "Restricted"])
2111 * if (!http_auth_basic('mike', 's3c|r3t')) {
2112 * die('<h1>Authorization failed!</h1>');
2117 PHP_FUNCTION(http_auth_basic
)
2119 char *realm
= NULL
, *user
, *pass
, *suser
, *spass
;
2120 int r_len
, u_len
, p_len
;
2122 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "ss|s", &user
, &u_len
, &pass
, &p_len
, &realm
, &r_len
) != SUCCESS
) {
2127 realm
= "Restricted";
2130 if (SUCCESS
!= http_auth_credentials(&suser
, &spass
)) {
2131 http_auth_header("Basic", realm
);
2135 if (strcasecmp(suser
, user
)) {
2136 http_auth_header("Basic", realm
);
2140 if (strcmp(spass
, pass
)) {
2141 http_auth_header("Basic", realm
);
2149 /* {{{ proto bool http_auth_basic_cb(mixed callback[, string realm = "Restricted"])
2154 * function auth_cb($user, $pass)
2157 * $query = 'SELECT pass FROM users WHERE user='. $db->quoteSmart($user);
2158 * if (strlen($realpass = $db->getOne($query)) {
2159 * return $pass === $realpass;
2164 * if (!http_auth_basic_cb('auth_cb')) {
2165 * die('<h1>Authorization failed</h1>');
2170 PHP_FUNCTION(http_auth_basic_cb
)
2173 char *realm
= NULL
, *user
, *pass
;
2176 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z|s", &cb
, &realm
, &r_len
) != SUCCESS
) {
2181 realm
= "Restricted";
2184 if (SUCCESS
!= http_auth_credentials(&user
, &pass
)) {
2185 http_auth_header("Basic", realm
);
2189 zval
*zparams
[2] = {NULL
, NULL
}, retval
;
2192 MAKE_STD_ZVAL(zparams
[0]);
2193 MAKE_STD_ZVAL(zparams
[1]);
2194 ZVAL_STRING(zparams
[0], user
, 0);
2195 ZVAL_STRING(zparams
[1], pass
, 0);
2197 if (SUCCESS
== call_user_function(EG(function_table
), NULL
, cb
,
2198 &retval
, 2, zparams TSRMLS_CC
)) {
2199 result
= Z_LVAL(retval
);
2208 http_auth_header("Basic", realm
);
2211 RETURN_BOOL(result
);
2217 /* {{{ php_http_init_globals(zend_http_globals *) */
2218 static void php_http_init_globals(zend_http_globals
*http_globals
)
2220 http_globals
->etag_started
= 0;
2221 http_globals
->ctype
= NULL
;
2222 http_globals
->etag
= NULL
;
2223 http_globals
->lmod
= 0;
2224 #ifdef HTTP_HAVE_CURL
2225 http_globals
->curlbuf
.body
.data
= NULL
;
2226 http_globals
->curlbuf
.body
.used
= 0;
2227 http_globals
->curlbuf
.body
.free
= 0;
2228 http_globals
->curlbuf
.hdrs
.data
= NULL
;
2229 http_globals
->curlbuf
.hdrs
.used
= 0;
2230 http_globals
->curlbuf
.hdrs
.free
= 0;
2232 http_globals
->allowed_methods
= NULL
;
2236 /* {{{ static inline STATUS http_check_allowed_methods(char *, int) */
2237 #define http_check_allowed_methods(m, l) _http_check_allowed_methods((m), (l) TSRMLS_CC)
2238 static inline void _http_check_allowed_methods(char *methods
, int length TSRMLS_DC
)
2240 if (length
&& SG(request_info
).request_method
&& (!strstr(methods
, SG(request_info
).request_method
))) {
2241 char *allow_header
= emalloc(length
+ sizeof("Allow: "));
2242 sprintf(allow_header
, "Allow: %s", methods
);
2243 http_send_header(allow_header
);
2244 efree(allow_header
);
2245 http_send_status(405);
2252 PHP_INI_MH(update_allowed_methods
)
2254 http_check_allowed_methods(new_value
, new_value_length
);
2255 return OnUpdateString(entry
, new_value
, new_value_length
, mh_arg1
, mh_arg2
, mh_arg3
, stage TSRMLS_CC
);
2259 STD_PHP_INI_ENTRY("http.allowed_methods", "OPTIONS,GET,HEAD,POST,PUT,DELETE,TRACE,CONNECT", PHP_INI_ALL
, update_allowed_methods
, allowed_methods
, zend_http_globals
, http_globals
)
2263 /* {{{ PHP_MINIT_FUNCTION */
2264 PHP_MINIT_FUNCTION(http
)
2266 ZEND_INIT_MODULE_GLOBALS(http
, php_http_init_globals
, NULL
);
2267 REGISTER_INI_ENTRIES();
2269 #if defined(HTTP_HAVE_CURL) && (LIBCURL_VERSION_NUM >= 0x070a05)
2270 REGISTER_LONG_CONSTANT("HTTP_AUTH_BASIC", CURLAUTH_BASIC
, CONST_CS
| CONST_PERSISTENT
);
2271 REGISTER_LONG_CONSTANT("HTTP_AUTH_DIGEST", CURLAUTH_DIGEST
, CONST_CS
| CONST_PERSISTENT
);
2272 REGISTER_LONG_CONSTANT("HTTP_AUTH_NTLM", CURLAUTH_NTLM
, CONST_CS
| CONST_PERSISTENT
);
2275 #ifdef ZEND_ENGINE_2
2276 HTTP_REGISTER_CLASS(HTTPi
, httpi
, NULL
, ZEND_ACC_FINAL_CLASS
);
2277 HTTP_REGISTER_CLASS_EX(HTTPi_Response
, httpi_response
, NULL
, 0);
2278 # ifdef HTTP_HAVE_CURL
2279 HTTP_REGISTER_CLASS_EX(HTTPi_Request
, httpi_request
, NULL
, 0);
2280 REGISTER_LONG_CONSTANT("HTTP_GET", HTTP_GET
, CONST_CS
| CONST_PERSISTENT
);
2281 REGISTER_LONG_CONSTANT("HTTP_HEAD", HTTP_HEAD
, CONST_CS
| CONST_PERSISTENT
);
2282 REGISTER_LONG_CONSTANT("HTTP_POST", HTTP_POST
, CONST_CS
| CONST_PERSISTENT
);
2283 # endif /* HTTP_HAVE_CURL */
2284 #endif /* ZEND_ENGINE_2 */
2289 /* {{{ PHP_MSHUTDOWN_FUNCTION */
2290 PHP_MSHUTDOWN_FUNCTION(http
)
2292 UNREGISTER_INI_ENTRIES();
2297 /* {{{ PHP_RINIT_FUNCTION */
2298 PHP_RINIT_FUNCTION(http
)
2300 char *allowed_methods
= INI_STR("http.allowed_methods");
2301 http_check_allowed_methods(allowed_methods
, strlen(allowed_methods
));
2306 /* {{{ PHP_RSHUTDOWN_FUNCTION */
2307 PHP_RSHUTDOWN_FUNCTION(http
)
2309 HTTP_G(etag_started
) = 0;
2313 efree(HTTP_G(etag
));
2314 HTTP_G(etag
) = NULL
;
2317 if (HTTP_G(ctype
)) {
2318 efree(HTTP_G(ctype
));
2319 HTTP_G(ctype
) = NULL
;
2321 #ifdef HTTP_HAVE_CURL
2322 if (HTTP_G(curlbuf
).body
.data
) {
2323 efree(HTTP_G(curlbuf
).body
.data
);
2324 HTTP_G(curlbuf
).body
.data
= NULL
;
2326 if (HTTP_G(curlbuf
).hdrs
.data
) {
2327 efree(HTTP_G(curlbuf
).hdrs
.data
);
2328 HTTP_G(curlbuf
).hdrs
.data
= NULL
;
2335 /* {{{ PHP_MINFO_FUNCTION */
2336 PHP_MINFO_FUNCTION(http
)
2338 php_info_print_table_start();
2339 php_info_print_table_header(2, "Extended HTTP support", "enabled");
2340 php_info_print_table_row(2, "Version:", PHP_EXT_HTTP_VERSION
);
2341 php_info_print_table_row(2, "cURL convenience functions:",
2342 #ifdef HTTP_HAVE_CURL
2348 php_info_print_table_end();
2350 DISPLAY_INI_ENTRIES();
2359 * vim600: noet sw=4 ts=4 fdm=marker
2360 * vim<600: noet sw=4 ts=4