* HTTPi_Response mostly done
[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 #define _WINSOCKAPI_
19 #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
20
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
24
25 #include "php.h"
26 #include "php_ini.h"
27 #include "snprintf.h"
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"
32
33 #include "SAPI.h"
34
35 #include "php_http.h"
36 #include "php_http_api.h"
37
38 #ifdef ZEND_ENGINE_2
39 # include "ext/standard/php_http.h"
40 #endif
41
42 #ifdef HTTP_HAVE_CURL
43
44 # ifdef PHP_WIN32
45 # include <winsock2.h>
46 # include <sys/types.h>
47 # endif
48
49 # include <curl/curl.h>
50
51 /* {{{ ARG_INFO */
52 # ifdef ZEND_BEGIN_ARG_INFO
53 ZEND_BEGIN_ARG_INFO(http_request_info_ref_3, 0)
54 ZEND_ARG_PASS_INFO(0)
55 ZEND_ARG_PASS_INFO(0)
56 ZEND_ARG_PASS_INFO(1)
57 ZEND_END_ARG_INFO();
58
59 ZEND_BEGIN_ARG_INFO(http_request_info_ref_4, 0)
60 ZEND_ARG_PASS_INFO(0)
61 ZEND_ARG_PASS_INFO(0)
62 ZEND_ARG_PASS_INFO(0)
63 ZEND_ARG_PASS_INFO(1)
64 ZEND_END_ARG_INFO();
65 # else
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};
68 # endif
69 /* }}} ARG_INFO */
70
71 #endif /* HTTP_HAVE_CURL */
72
73 ZEND_DECLARE_MODULE_GLOBALS(http)
74
75 #ifdef COMPILE_DL_HTTP
76 ZEND_GET_MODULE(http)
77 #endif
78
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_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_content_type, NULL)
93 PHP_FE(http_content_disposition, 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)
106 #endif
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)
111 #endif
112 PHP_FE(ob_httpetaghandler, NULL)
113 {NULL, NULL, NULL}
114 };
115 /* }}} */
116
117 #define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v))
118 #define HASH_ORNULL(z) ((z) ? Z_ARRVAL_P(z) : NULL)
119
120 #ifdef ZEND_ENGINE_2
121
122 # define HTTP_REGISTER_CLASS_EX(classname, name, parent, flags) \
123 { \
124 zend_class_entry ce; \
125 INIT_CLASS_ENTRY(ce, #classname, name## _class_methods); \
126 ce.create_object = name## _new_object; \
127 name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
128 name## _ce->ce_flags |= flags; \
129 memcpy(& name## _object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \
130 name## _object_handlers.clone_obj = NULL; \
131 name## _declare_default_properties(name## _ce); \
132 }
133
134 # define HTTP_REGISTER_CLASS(classname, name, parent, flags) \
135 { \
136 zend_class_entry ce; \
137 INIT_CLASS_ENTRY(ce, #classname, name## _class_methods); \
138 ce.create_object = NULL; \
139 name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
140 name## _ce->ce_flags |= flags; \
141 }
142
143 # define getObject(t, o) t * o = ((t *) zend_object_store_get_object(getThis() TSRMLS_CC))
144 # define OBJ_PROP(o) o->zo.properties
145 # define DCL_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC)
146 # define UPD_PROP(o, t, n, v) zend_update_property_ ##t(o->zo.ce, getThis(), (#n), sizeof(#n), (v) TSRMLS_CC)
147 # define SET_PROP(o, n, z) zend_update_property(o->zo.ce, getThis(), (#n), sizeof(#n), (z) TSRMLS_CC)
148 # define GET_PROP(o, n) zend_read_property(o->zo.ce, getThis(), (#n), sizeof(#n), 0 TSRMLS_CC)
149
150 /* {{{ HTTPi */
151
152 zend_class_entry *httpi_ce;
153
154 #define HTTPi_ME(me, al, ai) ZEND_FENTRY(me, ZEND_FN(al), ai, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
155
156 zend_function_entry httpi_class_methods[] = {
157 HTTPi_ME(date, http_date, NULL)
158 HTTPi_ME(absoluteURI, http_absolute_uri, NULL)
159 HTTPi_ME(negotiateLanguage, http_negotiate_language, NULL)
160 HTTPi_ME(negotiateCharset, http_negotiate_charset, NULL)
161 HTTPi_ME(redirect, http_redirect, NULL)
162 HTTPi_ME(sendStatus, http_send_status, NULL)
163 HTTPi_ME(sendLastModified, http_send_last_modified, NULL)
164 HTTPi_ME(matchModified, http_match_modified, NULL)
165 HTTPi_ME(matchEtag, http_match_etag, NULL)
166 HTTPi_ME(cacheLastModified, http_cache_last_modified, NULL)
167 HTTPi_ME(cacheEtag, http_cache_etag, NULL)
168 HTTPi_ME(chunkedDecode, http_chunked_decode, NULL)
169 HTTPi_ME(splitResponse, http_split_response, NULL)
170 HTTPi_ME(parseHeaders, http_parse_headers, NULL)
171 HTTPi_ME(getRequestHeaders, http_get_request_headers, NULL)
172 #ifdef HTTP_HAVE_CURL
173 HTTPi_ME(get, http_get, http_request_info_ref_3)
174 HTTPi_ME(head, http_head, http_request_info_ref_3)
175 HTTPi_ME(postData, http_post_data, http_request_info_ref_4)
176 HTTPi_ME(postArray, http_post_array, http_request_info_ref_4)
177 #endif
178 HTTPi_ME(authBasic, http_auth_basic, NULL)
179 HTTPi_ME(authBasicCallback, http_auth_basic_cb, NULL)
180 {NULL, NULL, NULL}
181 };
182 /* }}} HTTPi */
183
184 /* {{{ HTTPi_Response */
185
186 zend_class_entry *httpi_response_ce;
187 static zend_object_handlers httpi_response_object_handlers;
188
189 typedef struct {
190 zend_object zo;
191 } httpi_response_object;
192
193 #define httpi_response_declare_default_properties(ce) _httpi_response_declare_default_properties(ce TSRMLS_CC)
194 static inline void _httpi_response_declare_default_properties(zend_class_entry *ce TSRMLS_DC)
195 {
196 DCL_PROP(PROTECTED, string, contentType, "application/x-octetstream");
197 DCL_PROP(PROTECTED, string, eTag, "");
198 DCL_PROP(PROTECTED, string, dispoFile, "");
199 DCL_PROP(PROTECTED, string, cacheControl, "public");
200 DCL_PROP(PROTECTED, string, data, "");
201 DCL_PROP(PROTECTED, string, file, "");
202 DCL_PROP(PROTECTED, long, stream, 0);
203 DCL_PROP(PROTECTED, long, size, 0);
204 DCL_PROP(PROTECTED, long, lastModified, 0);
205 DCL_PROP(PROTECTED, long, dispoInline, 0);
206 DCL_PROP(PROTECTED, long, cache, 0);
207 DCL_PROP(PROTECTED, long, gzip, 0);
208
209 DCL_PROP(PRIVATE, long, raw_cache_header, 0);
210 DCL_PROP(PRIVATE, long, send_mode, -1);
211 }
212
213 #define httpi_response_destroy_object _httpi_response_destroy_object
214 void _httpi_response_destroy_object(void *object, zend_object_handle handle TSRMLS_DC)
215 {
216 httpi_response_object *o = object;
217 if (OBJ_PROP(o)) {
218 zend_hash_destroy(OBJ_PROP(o));
219 FREE_HASHTABLE(OBJ_PROP(o));
220 }
221 }
222
223 #define httpi_response_new_object _httpi_response_new_object
224 zend_object_value _httpi_response_new_object(zend_class_entry *ce TSRMLS_DC)
225 {
226 zend_object_value ov;
227 httpi_response_object *o;
228
229 o = ecalloc(sizeof(httpi_response_object), 1);
230 o->zo.ce = ce;
231
232 ALLOC_HASHTABLE(o->zo.properties);
233 zend_hash_init(o->zo.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
234
235 ov.handle = zend_objects_store_put(o, httpi_response_destroy_object, NULL, NULL TSRMLS_CC);
236 ov.handlers = &httpi_response_object_handlers;
237
238 return ov;
239 }
240
241 zend_function_entry httpi_response_class_methods[] = {
242 PHP_ME(HTTPi_Response, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
243 /* PHP_ME(HTTPi_Response, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
244 */
245 PHP_ME(HTTPi_Response, setETag, NULL, ZEND_ACC_PUBLIC)
246 PHP_ME(HTTPi_Response, getETag, NULL, ZEND_ACC_PUBLIC)
247
248 PHP_ME(HTTPi_Response, setContentDisposition, NULL, ZEND_ACC_PUBLIC)
249 PHP_ME(HTTPi_Response, getContentDisposition, NULL, ZEND_ACC_PUBLIC)
250
251 PHP_ME(HTTPi_Response, setContentType, NULL, ZEND_ACC_PUBLIC)
252 PHP_ME(HTTPi_Response, getContentType, NULL, ZEND_ACC_PUBLIC)
253
254 PHP_ME(HTTPi_Response, setCache, NULL, ZEND_ACC_PUBLIC)
255 PHP_ME(HTTPi_Response, getCache, NULL, ZEND_ACC_PUBLIC)
256
257 PHP_ME(HTTPi_Response, setCacheControl, NULL, ZEND_ACC_PUBLIC)
258 PHP_ME(HTTPi_Response, getCacheControl, NULL, ZEND_ACC_PUBLIC)
259
260 PHP_ME(HTTPi_Response, setGzip, NULL, ZEND_ACC_PUBLIC)
261 PHP_ME(HTTPi_Response, getGzip, NULL, ZEND_ACC_PUBLIC)
262
263 PHP_ME(HTTPi_Response, setData, NULL, ZEND_ACC_PUBLIC)
264 PHP_ME(HTTPi_Response, getData, NULL, ZEND_ACC_PUBLIC)
265
266 PHP_ME(HTTPi_Response, setFile, NULL, ZEND_ACC_PUBLIC)
267 PHP_ME(HTTPi_Response, getFile, NULL, ZEND_ACC_PUBLIC)
268
269 PHP_ME(HTTPi_Response, setStream, NULL, ZEND_ACC_PUBLIC)
270 PHP_ME(HTTPi_Response, getStream, NULL, ZEND_ACC_PUBLIC)
271
272 PHP_ME(HTTPi_Response, send, NULL, ZEND_ACC_PUBLIC)
273
274 PHP_ME(HTTPi_Response, getSize, NULL, ZEND_ACC_PUBLIC)
275
276 {NULL, NULL, NULL}
277 };
278
279 /* {{{ proto void HTTPi_Response::__construct(bool cache, bool gzip)
280 *
281 */
282 PHP_METHOD(HTTPi_Response, __construct)
283 {
284 zend_bool do_cache = 0, do_gzip = 0;
285 getObject(httpi_response_object, obj);
286
287 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bb", &do_cache, &do_gzip)) {
288 // throw exception
289 return;
290 }
291
292 UPD_PROP(obj, long, cache, do_cache);
293 UPD_PROP(obj, long, gzip, do_gzip);
294 }
295 /* }}} */
296
297 /* {{{ proto bool HTTPi_Response::setCache(bool cache)
298 *
299 */
300 PHP_METHOD(HTTPi_Response, setCache)
301 {
302 zend_bool do_cache = 0;
303 getObject(httpi_response_object, obj);
304
305 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &do_cache)) {
306 RETURN_FALSE;
307 }
308
309 UPD_PROP(obj, long, cache, do_cache);
310 RETURN_TRUE;
311 }
312 /* }}} */
313
314 /* {{{ proto bool HTTPi_Response::getCache()
315 *
316 */
317 PHP_METHOD(HTTPi_Response, getCache)
318 {
319 zval *do_cache = NULL;
320 getObject(httpi_response_object, obj);
321
322 if (ZEND_NUM_ARGS()) {
323 WRONG_PARAM_COUNT;
324 }
325
326 do_cache = GET_PROP(obj, cache);
327 RETURN_BOOL(Z_LVAL_P(do_cache));
328 }
329 /* }}}*/
330
331 /* {{{ proto bool HTTPi_Response::setGzip(bool gzip)
332 *
333 */
334 PHP_METHOD(HTTPi_Response, setGzip)
335 {
336 zend_bool do_gzip = 0;
337 getObject(httpi_response_object, obj);
338
339 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &do_gzip)) {
340 RETURN_FALSE;
341 }
342
343 UPD_PROP(obj, long, gzip, do_gzip);
344 RETURN_TRUE;
345 }
346 /* }}} */
347
348 /* {{{ proto bool HTTPi_Response::getGzip()
349 *
350 */
351 PHP_METHOD(HTTPi_Response, getGzip)
352 {
353 zval *do_gzip = NULL;
354 getObject(httpi_response_object, obj);
355
356 if (ZEND_NUM_ARGS()) {
357 WRONG_PARAM_COUNT;
358 }
359
360 do_gzip = GET_PROP(obj, gzip);
361 RETURN_BOOL(Z_LVAL_P(do_gzip));
362 }
363 /* }}} */
364
365 /* {{{ proto bool HTTPi_Response::setCacheControl(string control[, bool raw = false])
366 *
367 */
368 PHP_METHOD(HTTPi_Response, setCacheControl)
369 {
370 char *ccontrol;
371 int cc_len;
372 zend_bool raw = 0;
373 getObject(httpi_response_object, obj);
374
375 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &ccontrol, &cc_len, &raw)) {
376 RETURN_FALSE;
377 }
378
379 if ((!raw) && (strcmp(ccontrol, "public") && strcmp(ccontrol, "private") && strcmp(ccontrol, "no-cache"))) {
380 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cache-Control '%s' doesn't match public, private or no-cache", ccontrol);
381 RETURN_FALSE;
382 }
383
384 UPD_PROP(obj, long, raw_cache_header, raw);
385 UPD_PROP(obj, string, cacheControl, ccontrol);
386 RETURN_TRUE;
387 }
388 /* }}} */
389
390 /* {{{ proto string HTTPi_Response::getCacheControl()
391 *
392 */
393 PHP_METHOD(HTTPi_Response, getCacheControl)
394 {
395 zval *ccontrol;
396 getObject(httpi_response_object, obj);
397
398 if (ZEND_NUM_ARGS()) {
399 WRONG_PARAM_COUNT;
400 }
401
402 ccontrol = GET_PROP(obj, cacheControl);
403 RETURN_STRINGL(Z_STRVAL_P(ccontrol), Z_STRLEN_P(ccontrol), 1);
404 }
405 /* }}} */
406
407 /* {{{ proto bool HTTPi::setContentType(string content_type)
408 *
409 */
410 PHP_METHOD(HTTPi_Response, setContentType)
411 {
412 char *ctype;
413 int ctype_len;
414 getObject(httpi_response_object, obj);
415
416 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ctype, &ctype_len)) {
417 RETURN_FALSE;
418 }
419
420 if (!strchr(ctype, '/')) {
421 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Content type '%s' doesn't seem to contain a primary and secondary part", ctype);
422 RETURN_FALSE;
423 }
424
425 UPD_PROP(obj, string, contentType, ctype);
426 if (HTTP_G(ctype)) {
427 efree(HTTP_G(ctype));
428 }
429 HTTP_G(ctype) = estrndup(ctype, ctype_len);
430 RETURN_TRUE;
431 }
432 /* }}} */
433
434 /* {{{ proto string HTTPi_Response::getContentType()
435 *
436 */
437 PHP_METHOD(HTTPi_Response, getContentType)
438 {
439 zval *ctype;
440 getObject(httpi_response_object, obj);
441
442 if (ZEND_NUM_ARGS()) {
443 WRONG_PARAM_COUNT;
444 }
445
446 ctype = GET_PROP(obj, contentType);
447 RETURN_STRINGL(Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
448 }
449 /* }}} */
450
451 /* {{{ proto bool HTTPi_Response::setContentDisposition(string filename[, bool inline = false])
452 *
453 */
454 PHP_METHOD(HTTPi_Response, setContentDisposition)
455 {
456 char *file;
457 int file_len;
458 zend_bool is_inline = 0;
459 getObject(httpi_response_object, obj);
460
461 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &file, &file_len, &is_inline)) {
462 RETURN_FALSE;
463 }
464
465 UPD_PROP(obj, string, dispoFile, file);
466 UPD_PROP(obj, long, dispoInline, is_inline);
467 RETURN_TRUE;
468 }
469 /* }}} */
470
471 /* {{{ proto array HTTPi_Response::getContentDisposition()
472 *
473 */
474 PHP_METHOD(HTTPi_Response, getContentDisposition)
475 {
476 zval *file;
477 zval *is_inline;
478 getObject(httpi_response_object, obj);
479
480 if (ZEND_NUM_ARGS()) {
481 WRONG_PARAM_COUNT;
482 }
483
484 file = GET_PROP(obj, dispoFile);
485 is_inline = GET_PROP(obj, dispoInline);
486
487 array_init(return_value);
488 add_assoc_stringl(return_value, "filename", Z_STRVAL_P(file), Z_STRLEN_P(file), 1);
489 add_assoc_bool(return_value, "inline", Z_LVAL_P(is_inline));
490 }
491 /* }}} */
492
493 /* {{{ proto bool HTTPi_Response::setETag(string etag)
494 *
495 */
496 PHP_METHOD(HTTPi_Response, setETag)
497 {
498 char *etag;
499 int etag_len;
500 getObject(httpi_response_object, obj);
501
502 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &etag, &etag_len)) {
503 RETURN_FALSE;
504 }
505
506 UPD_PROP(obj, string, eTag, etag);
507 RETURN_TRUE;
508 }
509 /* }}} */
510
511 /* {{{ proto string HTTPi_Response::getETag()
512 *
513 */
514 PHP_METHOD(HTTPi_Response, getETag)
515 {
516 zval *etag;
517 getObject(httpi_response_object, obj);
518
519 if (ZEND_NUM_ARGS()) {
520 WRONG_PARAM_COUNT;
521 }
522
523 etag = GET_PROP(obj, eTag);
524 RETURN_STRINGL(Z_STRVAL_P(etag), Z_STRLEN_P(etag), 1);
525 }
526 /* }}} */
527
528 /* {{{ proto bool HTTPi_Response::setData(string data)
529 *
530 */
531 PHP_METHOD(HTTPi_Response, setData)
532 {
533 zval *the_data;
534 getObject(httpi_response_object, obj);
535
536 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &the_data)) {
537 RETURN_FALSE;
538 }
539
540 convert_to_string_ex(&the_data);
541 SET_PROP(obj, data, the_data);
542 UPD_PROP(obj, string, eTag, http_etag(Z_STRVAL_P(the_data), Z_STRLEN_P(the_data), SEND_DATA));
543 UPD_PROP(obj, long, size, Z_STRLEN_P(the_data));
544 UPD_PROP(obj, long, lastModified, time(NULL));
545 UPD_PROP(obj, long, send_mode, SEND_DATA);
546 RETURN_TRUE;
547 }
548 /* }}} */
549
550 /* {{{ proto string HTTPi_Response::getData()
551 *
552 */
553 PHP_METHOD(HTTPi_Response, getData)
554 {
555 zval *the_data;
556 getObject(httpi_response_object, obj);
557
558 if (ZEND_NUM_ARGS()) {
559 WRONG_PARAM_COUNT;
560 }
561
562 the_data = GET_PROP(obj, data);
563 RETURN_STRINGL(Z_STRVAL_P(the_data), Z_STRLEN_P(the_data), 1);
564 }
565 /* }}} */
566
567 /* {{{ proto bool HTTPi_Response::setStream(resource stream)
568 *
569 */
570 PHP_METHOD(HTTPi_Response, setStream)
571 {
572 zval *the_stream;
573 php_stream *the_real_stream;
574 getObject(httpi_response_object, obj);
575
576 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &the_stream)) {
577 RETURN_FALSE;
578 }
579
580 php_stream_from_zval(the_real_stream, &the_stream);
581
582 SET_PROP(obj, stream, the_stream);
583 UPD_PROP(obj, string, eTag, http_etag(the_real_stream, 0, SEND_RSRC));
584 UPD_PROP(obj, long, size, HTTP_G(ssb).sb.st_size);
585 UPD_PROP(obj, long, lastModified, HTTP_G(ssb).sb.st_mtime);
586 UPD_PROP(obj, long, send_mode, SEND_RSRC);
587 RETURN_TRUE;
588 }
589 /* }}} */
590
591 /* {{{ proto resource HTTPi_Response::getStream()
592 *
593 */
594 PHP_METHOD(HTTPi_Response, getStream)
595 {
596 zval *the_stream;
597 getObject(httpi_response_object, obj);
598
599 if (ZEND_NUM_ARGS()) {
600 WRONG_PARAM_COUNT;
601 }
602
603 the_stream = GET_PROP(obj, stream);
604 RETURN_RESOURCE(Z_LVAL_P(the_stream));
605 }
606 /* }}} */
607
608 /* {{{ proto bool HTTPi_Response::setFile(string file)
609 *
610 */
611 PHP_METHOD(HTTPi_Response, setFile)
612 {
613 char *the_file;
614 int file_len;
615 zval fmtime, fsize;
616 getObject(httpi_response_object, obj);
617
618 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &the_file, &file_len)) {
619 RETURN_FALSE;
620 }
621
622 php_stat(the_file, file_len, FS_SIZE, &fsize TSRMLS_CC);
623 php_stat(the_file, file_len, FS_MTIME, &fmtime TSRMLS_CC);
624
625 UPD_PROP(obj, string, file, the_file);
626 UPD_PROP(obj, long, size, Z_LVAL(fsize));
627 UPD_PROP(obj, long, lastModified, Z_LVAL(fmtime));
628 UPD_PROP(obj, long, send_mode, -1);
629 RETURN_TRUE;
630 }
631 /* }}} */
632
633 /* {{{ proto string HTTPi_Response::getFile()
634 *
635 */
636 PHP_METHOD(HTTPi_Response, getFile)
637 {
638 zval *the_file;
639 getObject(httpi_response_object, obj);
640
641 if (ZEND_NUM_ARGS()) {
642 WRONG_PARAM_COUNT;
643 }
644
645 the_file = GET_PROP(obj, file);
646 RETURN_STRINGL(Z_STRVAL_P(the_file), Z_STRLEN_P(the_file), 1);
647 }
648 /* }}} */
649
650 /* {{{ proto int HTTPi_Response::getSize()
651 *
652 */
653 PHP_METHOD(HTTPi_Response, getSize)
654 {
655 zval *the_size;
656 getObject(httpi_response_object, obj);
657
658 if (ZEND_NUM_ARGS()) {
659 WRONG_PARAM_COUNT;
660 }
661
662 the_size = GET_PROP(obj, size);
663 RETURN_LONG(Z_LVAL_P(the_size));
664 }
665 /* }}} */
666
667 PHP_METHOD(HTTPi_Response, send)
668 {
669 zval *do_cache;
670 getObject(httpi_response_object, obj);
671
672 do_cache = GET_PROP(obj, cache);
673
674 /* caching */
675 if (Z_LVAL_P(do_cache)) {
676 /* cache header */
677 {
678 zval *ccontrol = GET_PROP(obj, cacheControl);
679 if (Z_STRLEN_P(ccontrol)) {
680 char *cc_header;
681 zval *cc_raw = GET_PROP(obj, raw_cache_control);
682 if (Z_LVAL_P(cc_raw)) {
683 cc_header = ecalloc(sizeof("Cache-Control: ") + Z_STRLEN_P(ccontrol), 1);
684 sprintf(cc_header, "Cache-Control: %s", Z_STRVAL_P(ccontrol));
685 } else {
686 cc_header = ecalloc(sizeof("Cache-Control: , must-revalidate, max-age=0") + Z_STRLEN_P(ccontrol), 1);
687 sprintf(cc_header, "Cache-Control: %s, must-revalidate, max-age=0", Z_STRVAL_P(ccontrol));
688 }
689 http_send_header(cc_header);
690 efree(cc_header);
691 } else {
692 http_send_header("Cache-Control: public, must-revalidate, max-age=0");
693 }
694 }
695 /* etag */
696 {
697 zval *etag = GET_PROP(obj, eTag);
698 if (Z_STRLEN_P(etag)) {
699 if ((!http_is_range_request()) && http_etag_match("HTTP_IF_NONE_MATCH", Z_STRVAL_P(etag))) {
700 http_send_status(304);
701 RETURN_TRUE;
702 }
703 http_send_etag(Z_STRVAL_P(etag), Z_STRLEN_P(etag));
704 if (HTTP_G(etag)) {
705 efree(HTTP_G(etag));
706 }
707 HTTP_G(etag) = estrndup(Z_STRVAL_P(etag), Z_STRLEN_P(etag));
708 }
709 }
710 /* last modified */
711 {
712 zval *lmod = GET_PROP(obj, lastModified);
713 if (Z_LVAL_P(lmod)) {
714 if (http_modified_match("HTTP_IF_MODIFIED_SINCE", Z_LVAL_P(lmod))) {
715 http_send_status(304);
716 RETURN_TRUE;
717 }
718 http_send_last_modified(Z_LVAL_P(lmod));
719 HTTP_G(lmod) = Z_LVAL_P(lmod);
720 } else {
721 time_t t = time(NULL);
722 http_send_last_modified(t);
723 HTTP_G(lmod) = t;
724 }
725 }
726 } /* caching done */
727
728 /* gzip */
729 /* ... */
730
731 /* content type */
732 {
733 zval *ctype = GET_PROP(obj, contentType);
734 if (Z_STRLEN_P(ctype)) {
735 char *ctype_header = ecalloc(sizeof("Content-Type: ") + Z_STRLEN_P(ctype), 1);
736 sprintf(ctype_header, "Content-Type: %s", Z_STRVAL_P(ctype));
737 http_send_header(ctype_header);
738 efree(ctype_header);
739 if (HTTP_G(ctype)) {
740 efree(HTTP_G(ctype));
741 }
742 HTTP_G(ctype) = estrndup(Z_STRVAL_P(ctype), Z_STRLEN_P(ctype));
743 } else {
744 http_send_header("Content-Type: application/x-octetstream");
745 if (HTTP_G(ctype)) {
746 efree(HTTP_G(ctype));
747 }
748 HTTP_G(ctype) = estrdup("application/x-octetstream");
749 }
750 }
751
752 /* content disposition */
753 {
754 zval *dispo_file = GET_PROP(obj, dispoFile);
755 if (Z_STRLEN_P(dispo_file)) {
756 char *dispo_header;
757 zval *dispo_inline = GET_PROP(obj, dispoInline);
758 if (Z_LVAL_P(dispo_inline)) {
759 dispo_header = ecalloc(sizeof("Content-Disposition: inline; filename=\"\"") + Z_STRLEN_P(dispo_file), 1);
760 sprintf(dispo_header, "Content-Disposition: inline; filename=\"%s\"", Z_STRVAL_P(dispo_file));
761 } else {
762 dispo_header = ecalloc(sizeof("Content-Disposition: attachment; filename=\"\"") + Z_STRLEN_P(dispo_file), 1);
763 sprintf(dispo_header, "Content-Disposition: attachment; filename=\"%s\"", Z_STRVAL_P(dispo_file));
764 }
765 http_send_header(dispo_header);
766 efree(dispo_header);
767 }
768 }
769
770 /* send */
771 {
772 zval *send_mode = GET_PROP(obj, send_mode);
773 switch (Z_LVAL_P(send_mode))
774 {
775 case SEND_DATA:
776 {
777 RETURN_SUCCESS(http_send_data(GET_PROP(obj, data)));
778 }
779
780 case SEND_RSRC:
781 {
782 php_stream *the_real_stream;
783 zval *the_stream = GET_PROP(obj, stream);
784 php_stream_from_zval(the_real_stream, &the_stream);
785 RETURN_SUCCESS(http_send_stream(the_real_stream));
786 }
787
788 default:
789 {
790 RETURN_SUCCESS(http_send_file(GET_PROP(obj, file)));
791 }
792 }
793 }
794 }
795
796 #endif /* ZEND_ENGINE_2 */
797
798 /* {{{ http_module_entry */
799 zend_module_entry http_module_entry = {
800 #if ZEND_MODULE_API_NO >= 20010901
801 STANDARD_MODULE_HEADER,
802 #endif
803 "http",
804 http_functions,
805 PHP_MINIT(http),
806 PHP_MSHUTDOWN(http),
807 PHP_RINIT(http),
808 PHP_RSHUTDOWN(http),
809 PHP_MINFO(http),
810 #if ZEND_MODULE_API_NO >= 20010901
811 PHP_EXT_HTTP_VERSION,
812 #endif
813 STANDARD_MODULE_PROPERTIES
814 };
815 /* }}} */
816
817 /* {{{ proto string http_date([int timestamp])
818 *
819 * This function returns a valid HTTP date regarding RFC 822/1123
820 * looking like: "Wed, 22 Dec 2004 11:34:47 GMT"
821 *
822 */
823 PHP_FUNCTION(http_date)
824 {
825 long t = -1;
826
827 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &t) != SUCCESS) {
828 RETURN_FALSE;
829 }
830
831 if (t == -1) {
832 t = (long) time(NULL);
833 }
834
835 RETURN_STRING(http_date(t), 0);
836 }
837 /* }}} */
838
839 /* {{{ proto string http_absolute_uri(string url[, string proto])
840 *
841 * This function returns an absolute URI constructed from url.
842 * If the url is already abolute but a different proto was supplied,
843 * only the proto part of the URI will be updated. If url has no
844 * path specified, the path of the current REQUEST_URI will be taken.
845 * The host will be taken either from the Host HTTP header of the client
846 * the SERVER_NAME or just localhost if prior are not available.
847 *
848 * Some examples:
849 * <pre>
850 * url = "page.php" => http://www.example.com/current/path/page.php
851 * url = "/page.php" => http://www.example.com/page.php
852 * url = "/page.php", proto = "https" => https://www.example.com/page.php
853 * </pre>
854 *
855 */
856 PHP_FUNCTION(http_absolute_uri)
857 {
858 char *url = NULL, *proto = NULL;
859 int url_len = 0, proto_len = 0;
860
861 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &url, &url_len, &proto, &proto_len) != SUCCESS) {
862 RETURN_FALSE;
863 }
864
865 RETURN_STRING(http_absolute_uri(url, proto), 0);
866 }
867 /* }}} */
868
869 /* {{{ proto string http_negotiate_language(array supported[, string default = 'en-US'])
870 *
871 * This function negotiates the clients preferred language based on its
872 * Accept-Language HTTP header. It returns the negotiated language or
873 * the default language if none match.
874 *
875 * The qualifier is recognized and languages without qualifier are rated highest.
876 *
877 * The supported parameter is expected to be an array having
878 * the supported languages as array values.
879 *
880 * Example:
881 * <pre>
882 * <?php
883 * $langs = array(
884 * 'en-US',// default
885 * 'fr',
886 * 'fr-FR',
887 * 'de',
888 * 'de-DE',
889 * 'de-AT',
890 * 'de-CH',
891 * );
892 * include './langs/'. http_negotiate_language($langs) .'.php';
893 * ?>
894 * </pre>
895 *
896 */
897 PHP_FUNCTION(http_negotiate_language)
898 {
899 zval *supported;
900 char *def = NULL;
901 int def_len = 0;
902
903 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|s", &supported, &def, &def_len) != SUCCESS) {
904 RETURN_FALSE;
905 }
906
907 if (!def) {
908 def = "en-US";
909 }
910
911 RETURN_STRING(http_negotiate_language(supported, def), 0);
912 }
913 /* }}} */
914
915 /* {{{ proto string http_negotiate_charset(array supported[, string default = 'iso-8859-1'])
916 *
917 * This function negotiates the clients preferred charset based on its
918 * Accept-Charset HTTP header. It returns the negotiated charset or
919 * the default charset if none match.
920 *
921 * The qualifier is recognized and charset without qualifier are rated highest.
922 *
923 * The supported parameter is expected to be an array having
924 * the supported charsets as array values.
925 *
926 * Example:
927 * <pre>
928 * <?php
929 * $charsets = array(
930 * 'iso-8859-1', // default
931 * 'iso-8859-2',
932 * 'iso-8859-15',
933 * 'utf-8'
934 * );
935 * $pref = http_negotiate_charset($charsets);
936 * if (!strcmp($pref, 'iso-8859-1')) {
937 * iconv_set_encoding('internal_encoding', 'iso-8859-1');
938 * iconv_set_encoding('output_encoding', $pref);
939 * ob_start('ob_iconv_handler');
940 * }
941 * ?>
942 * </pre>
943 */
944 PHP_FUNCTION(http_negotiate_charset)
945 {
946 zval *supported;
947 char *def = NULL;
948 int def_len = 0;
949
950 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|s", &supported, &def, &def_len) != SUCCESS) {
951 RETURN_FALSE;
952 }
953
954 if (!def) {
955 def = "iso-8859-1";
956 }
957
958 RETURN_STRING(http_negotiate_charset(supported, def), 0);
959 }
960 /* }}} */
961
962 /* {{{ proto bool http_send_status(int status)
963 *
964 * Send HTTP status code.
965 *
966 */
967 PHP_FUNCTION(http_send_status)
968 {
969 int status = 0;
970
971 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &status) != SUCCESS) {
972 RETURN_FALSE;
973 }
974 if (status < 100 || status > 510) {
975 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid HTTP status code (100-510): %d", status);
976 RETURN_FALSE;
977 }
978
979 RETURN_SUCCESS(http_send_status(status));
980 }
981 /* }}} */
982
983 /* {{{ proto bool http_send_last_modified([int timestamp])
984 *
985 * This converts the given timestamp to a valid HTTP date and
986 * sends it as "Last-Modified" HTTP header. If timestamp is
987 * omitted, current time is sent.
988 *
989 */
990 PHP_FUNCTION(http_send_last_modified)
991 {
992 long t = -1;
993
994 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &t) != SUCCESS) {
995 RETURN_FALSE;
996 }
997
998 if (t == -1) {
999 t = (long) time(NULL);
1000 }
1001
1002 RETURN_SUCCESS(http_send_last_modified(t));
1003 }
1004 /* }}} */
1005
1006 /* {{{ proto bool http_match_modified([int timestamp])
1007 *
1008 * Matches the given timestamp against the clients "If-Modified-Since" resp.
1009 * "If-Unmodified-Since" HTTP headers.
1010 *
1011 */
1012 PHP_FUNCTION(http_match_modified)
1013 {
1014 long t = -1;
1015
1016 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &t) != SUCCESS) {
1017 RETURN_FALSE;
1018 }
1019
1020 // current time if not supplied (senseless though)
1021 if (t == -1) {
1022 t = (long) time(NULL);
1023 }
1024
1025 RETURN_BOOL(http_modified_match("HTTP_IF_MODIFIED_SINCE", t) || http_modified_match("HTTP_IF_UNMODIFIED_SINCE", t));
1026 }
1027 /* }}} */
1028
1029 /* {{{ proto bool http_match_etag(string etag)
1030 *
1031 * This matches the given ETag against the clients
1032 * "If-Match" resp. "If-None-Match" HTTP headers.
1033 *
1034 */
1035 PHP_FUNCTION(http_match_etag)
1036 {
1037 int etag_len;
1038 char *etag;
1039
1040 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &etag, &etag_len) != SUCCESS) {
1041 RETURN_FALSE;
1042 }
1043
1044 RETURN_BOOL(http_etag_match("HTTP_IF_NONE_MATCH", etag) || http_etag_match("HTTP_IF_MATCH", etag));
1045 }
1046 /* }}} */
1047
1048 /* {{{ proto bool http_cache_last_modified([int timestamp_or_expires]])
1049 *
1050 * If timestamp_or_exires is greater than 0, it is handled as timestamp
1051 * and will be sent as date of last modification. If it is 0 or omitted,
1052 * the current time will be sent as Last-Modified date. If it's negative,
1053 * it is handled as expiration time in seconds, which means that if the
1054 * requested last modification date is not between the calculated timespan,
1055 * the Last-Modified header is updated and the actual body will be sent.
1056 *
1057 */
1058 PHP_FUNCTION(http_cache_last_modified)
1059 {
1060 long last_modified = 0, send_modified = 0, t;
1061 zval *zlm;
1062
1063 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &last_modified) != SUCCESS) {
1064 RETURN_FALSE;
1065 }
1066
1067 t = (long) time(NULL);
1068
1069 /* 0 or omitted */
1070 if (!last_modified) {
1071 /* does the client have? (att: caching "forever") */
1072 if (zlm = http_get_server_var("HTTP_IF_MODIFIED_SINCE")) {
1073 last_modified = send_modified = http_parse_date(Z_STRVAL_P(zlm));
1074 /* send current time */
1075 } else {
1076 send_modified = t;
1077 }
1078 /* negative value is supposed to be expiration time */
1079 } else if (last_modified < 0) {
1080 last_modified += t;
1081 send_modified = t;
1082 /* send supplied time explicitly */
1083 } else {
1084 send_modified = last_modified;
1085 }
1086
1087 http_send_header("Cache-Control: private, must-revalidate, max-age=0");
1088
1089 if (http_modified_match("HTTP_IF_MODIFIED_SINCE", last_modified)) {
1090 if (SUCCESS == http_send_status(304)) {
1091 zend_bailout();
1092 } else {
1093 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not send 304 Not Modified");
1094 RETURN_FALSE;
1095 }
1096 }
1097 RETURN_SUCCESS(http_send_last_modified(send_modified));
1098 }
1099 /* }}} */
1100
1101 /* {{{ proto bool http_cache_etag([string etag])
1102 *
1103 * This function attempts to cache the HTTP body based on an ETag,
1104 * either supplied or generated through calculation of the MD5
1105 * checksum of the output (uses output buffering).
1106 *
1107 * If clients "If-None-Match" header matches the supplied/calculated
1108 * ETag, the body is considered cached on the clients side and
1109 * a "304 Not Modified" status code is issued.
1110 *
1111 */
1112 PHP_FUNCTION(http_cache_etag)
1113 {
1114 char *etag;
1115 int etag_len = 0;
1116
1117 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &etag, &etag_len) != SUCCESS) {
1118 RETURN_FALSE;
1119 }
1120
1121 http_send_header("Cache-Control: private, must-revalidate, max-age=0");
1122
1123 if (etag_len) {
1124 http_send_etag(etag, etag_len);
1125 if (http_etag_match("HTTP_IF_NONE_MATCH", etag)) {
1126 if (SUCCESS == http_send_status(304)) {
1127 zend_bailout();
1128 } else {
1129 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not send 304 Not Modified");
1130 RETURN_FALSE;
1131 }
1132 }
1133 }
1134
1135 /* if no etag is given and we didn't already start ob_etaghandler -- start it */
1136 if (!HTTP_G(etag_started)) {
1137 RETURN_BOOL(HTTP_G(etag_started) = (SUCCESS == http_start_ob_handler(_http_ob_etaghandler, "ob_etaghandler", 4096, 1)));
1138 }
1139 RETURN_TRUE;
1140 }
1141 /* }}} */
1142
1143 /* {{{ proto string ob_httpetaghandler(string data, int mode)
1144 *
1145 * For use with ob_start().
1146 * Note that this has to be started as first output buffer.
1147 * WARNING: Don't use with http_send_*().
1148 */
1149 PHP_FUNCTION(ob_httpetaghandler)
1150 {
1151 char *data;
1152 int data_len;
1153 long mode;
1154
1155 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &data, &data_len, &mode)) {
1156 RETURN_FALSE;
1157 }
1158
1159 if (mode & PHP_OUTPUT_HANDLER_START) {
1160 if (HTTP_G(etag_started)) {
1161 php_error_docref(NULL TSRMLS_CC, E_WARNING, "ob_httpetaghandler can only be used once");
1162 RETURN_STRINGL(data, data_len, 1);
1163 }
1164 http_send_header("Cache-Control: private, must-revalidate, max-age=0");
1165 HTTP_G(etag_started) = 1;
1166 }
1167
1168 if (OG(ob_nesting_level) > 1) {
1169 php_error_docref(NULL TSRMLS_CC, E_WARNING, "ob_httpetaghandler must be started prior to other output buffers");
1170 RETURN_STRINGL(data, data_len, 1);
1171 }
1172
1173 Z_TYPE_P(return_value) = IS_STRING;
1174 http_ob_etaghandler(data, data_len, &Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value), mode);
1175 }
1176 /* }}} */
1177
1178 /* {{{ proto void http_redirect([string url[, array params[, bool session,[ bool permanent]]]])
1179 *
1180 * Redirect to a given url.
1181 * The supplied url will be expanded with http_absolute_uri(), the params array will
1182 * be treated with http_build_query() and the session identification will be appended
1183 * if session is true.
1184 *
1185 * Depending on permanent the redirection will be issued with a permanent
1186 * ("301 Moved Permanently") or a temporary ("302 Found") redirection
1187 * status code.
1188 *
1189 * To be RFC compliant, "Redirecting to <a>URI</a>." will be displayed,
1190 * if the client doesn't redirect immediatly.
1191 */
1192 PHP_FUNCTION(http_redirect)
1193 {
1194 int url_len;
1195 zend_bool session = 0, permanent = 0;
1196 zval *params = NULL;
1197 smart_str qstr = {0};
1198 char *url, *URI, LOC[HTTP_URI_MAXLEN + 9], RED[HTTP_URI_MAXLEN * 2 + 34];
1199
1200 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sa!/bb", &url, &url_len, &params, &session, &permanent) != SUCCESS) {
1201 RETURN_FALSE;
1202 }
1203
1204 /* append session info */
1205 if (session && (PS(session_status) == php_session_active)) {
1206 if (!params) {
1207 MAKE_STD_ZVAL(params);
1208 array_init(params);
1209 }
1210 if (add_assoc_string(params, PS(session_name), PS(id), 1) != SUCCESS) {
1211 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not append session information");
1212 }
1213 }
1214
1215 /* treat params array with http_build_query() */
1216 if (params) {
1217 if (php_url_encode_hash_ex(Z_ARRVAL_P(params), &qstr, NULL,0,NULL,0,NULL,0,NULL TSRMLS_CC) != SUCCESS) {
1218 if (qstr.c) {
1219 efree(qstr.c);
1220 }
1221 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not encode query parameters");
1222 RETURN_FALSE;
1223 }
1224 smart_str_0(&qstr);
1225 }
1226
1227 URI = http_absolute_uri(url, NULL);
1228 if (qstr.c) {
1229 snprintf(LOC, HTTP_URI_MAXLEN + strlen("Location: "), "Location: %s?%s", URI, qstr.c);
1230 sprintf(RED, "Redirecting to <a href=\"%s?%s\">%s?%s</a>.\n", URI, qstr.c, URI, qstr.c);
1231 efree(qstr.c);
1232 } else {
1233 snprintf(LOC, HTTP_URI_MAXLEN + strlen("Location: "), "Location: %s", URI);
1234 sprintf(RED, "Redirecting to <a href=\"%s\">%s</a>.\n", URI, URI);
1235 }
1236 efree(URI);
1237
1238 if ((SUCCESS == http_send_header(LOC)) && (SUCCESS == http_send_status((permanent ? 301 : 302)))) {
1239 php_body_write(RED, strlen(RED) TSRMLS_CC);
1240 RETURN_TRUE;
1241 }
1242 RETURN_FALSE;
1243 }
1244 /* }}} */
1245
1246 /* {{{ proto bool http_send_data(string data)
1247 *
1248 * Sends raw data with support for (multiple) range requests.
1249 *
1250 */
1251 PHP_FUNCTION(http_send_data)
1252 {
1253 zval *zdata;
1254
1255 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zdata) != SUCCESS) {
1256 RETURN_FALSE;
1257 }
1258
1259 convert_to_string_ex(&zdata);
1260 http_send_header("Accept-Ranges: bytes");
1261 RETURN_SUCCESS(http_send_data(zdata));
1262 }
1263 /* }}} */
1264
1265 /* {{{ proto bool http_send_file(string file)
1266 *
1267 * Sends a file with support for (multiple) range requests.
1268 *
1269 */
1270 PHP_FUNCTION(http_send_file)
1271 {
1272 zval *zfile;
1273
1274 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zfile) != SUCCESS) {
1275 RETURN_FALSE;
1276 }
1277
1278 convert_to_string_ex(&zfile);
1279 http_send_header("Accept-Ranges: bytes");
1280 RETURN_SUCCESS(http_send_file(zfile));
1281 }
1282 /* }}} */
1283
1284 /* {{{ proto bool http_send_stream(resource stream)
1285 *
1286 * Sends an already opened stream with support for (multiple) range requests.
1287 *
1288 */
1289 PHP_FUNCTION(http_send_stream)
1290 {
1291 zval *zstream;
1292 php_stream *file;
1293
1294 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream) != SUCCESS) {
1295 RETURN_FALSE;
1296 }
1297
1298 php_stream_from_zval(file, &zstream);
1299 http_send_header("Accept-Ranges: bytes");
1300 RETURN_SUCCESS(http_send_stream(file));
1301 }
1302 /* }}} */
1303
1304 /* {{{ proto bool http_content_type([string content_type = 'application/x-octetstream'])
1305 *
1306 * Sets the content type.
1307 *
1308 */
1309 PHP_FUNCTION(http_content_type)
1310 {
1311 char *ct, *content_type;
1312 int ct_len = 0;
1313
1314 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &ct, &ct_len) != SUCCESS) {
1315 RETURN_FALSE;
1316 }
1317
1318 if (!ct_len) {
1319 RETURN_SUCCESS(http_send_header("Content-Type: application/x-octetstream"));
1320 }
1321
1322 /* remember for multiple ranges */
1323 if (HTTP_G(ctype)) {
1324 efree(HTTP_G(ctype));
1325 }
1326 HTTP_G(ctype) = estrndup(ct, ct_len);
1327
1328 content_type = (char *) emalloc(strlen("Content-Type: ") + ct_len + 1);
1329 sprintf(content_type, "Content-Type: %s", ct);
1330
1331 RETVAL_BOOL(SUCCESS == http_send_header(content_type));
1332 efree(content_type);
1333 }
1334 /* }}} */
1335
1336 /* {{{ proto bool http_content_disposition(string filename[, bool inline = false])
1337 *
1338 * Set the Content Disposition. The Content-Disposition header is very useful
1339 * if the data actually sent came from a file or something similar, that should
1340 * be "saved" by the client/user (i.e. by browsers "Save as..." popup window).
1341 *
1342 */
1343 PHP_FUNCTION(http_content_disposition)
1344 {
1345 char *filename, *header;
1346 int f_len;
1347 zend_bool send_inline = 0;
1348
1349 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &filename, &f_len, &send_inline) != SUCCESS) {
1350 RETURN_FALSE;
1351 }
1352
1353 if (send_inline) {
1354 header = (char *) emalloc(strlen("Content-Disposition: inline; filename=\"\"") + f_len + 1);
1355 sprintf(header, "Content-Disposition: inline; filename=\"%s\"", filename);
1356 } else {
1357 header = (char *) emalloc(strlen("Content-Disposition: attachment; filename=\"\"") + f_len + 1);
1358 sprintf(header, "Content-Disposition: attachment; filename=\"%s\"", filename);
1359 }
1360
1361 RETVAL_BOOL(SUCCESS == http_send_header(header));
1362 efree(header);
1363 }
1364 /* }}} */
1365
1366 /* {{{ proto string http_chunked_decode(string encoded)
1367 *
1368 * This function decodes a string that was HTTP-chunked encoded.
1369 * Returns false on failure.
1370 */
1371 PHP_FUNCTION(http_chunked_decode)
1372 {
1373 char *encoded = NULL, *decoded = NULL;
1374 int encoded_len = 0, decoded_len = 0;
1375
1376 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &encoded, &encoded_len) != SUCCESS) {
1377 RETURN_FALSE;
1378 }
1379
1380 if (SUCCESS == http_chunked_decode(encoded, encoded_len, &decoded, &decoded_len)) {
1381 RETURN_STRINGL(decoded, decoded_len, 0);
1382 } else {
1383 RETURN_FALSE;
1384 }
1385 }
1386 /* }}} */
1387
1388 /* {{{ proto array http_split_response(string http_response)
1389 *
1390 * This function splits an HTTP response into an array with headers and the
1391 * content body. The returned array may look simliar to the following example:
1392 *
1393 * <pre>
1394 * <?php
1395 * array(
1396 * 0 => array(
1397 * 'Status' => '200 Ok',
1398 * 'Content-Type' => 'text/plain',
1399 * 'Content-Language' => 'en-US'
1400 * ),
1401 * 1 => "Hello World!"
1402 * );
1403 * ?>
1404 * </pre>
1405 */
1406 PHP_FUNCTION(http_split_response)
1407 {
1408 zval *zresponse, *zbody, *zheaders;
1409
1410 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zresponse) != SUCCESS) {
1411 RETURN_FALSE;
1412 }
1413
1414 convert_to_string_ex(&zresponse);
1415
1416 MAKE_STD_ZVAL(zbody);
1417 MAKE_STD_ZVAL(zheaders);
1418 array_init(zheaders);
1419
1420 if (SUCCESS != http_split_response(zresponse, zheaders, zbody)) {
1421 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse HTTP response");
1422 RETURN_FALSE;
1423 }
1424
1425 array_init(return_value);
1426 add_index_zval(return_value, 0, zheaders);
1427 add_index_zval(return_value, 1, zbody);
1428 }
1429 /* }}} */
1430
1431 /* {{{ proto array http_parse_headers(string header)
1432 *
1433 */
1434 PHP_FUNCTION(http_parse_headers)
1435 {
1436 char *header, *rnrn;
1437 int header_len;
1438
1439 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &header, &header_len)) {
1440 RETURN_FALSE;
1441 }
1442
1443 array_init(return_value);
1444
1445 if (rnrn = strstr(header, HTTP_CRLF HTTP_CRLF)) {
1446 header_len = rnrn - header + 2;
1447 }
1448 if (SUCCESS != http_parse_headers(header, header_len, return_value)) {
1449 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse HTTP header");
1450 zval_dtor(return_value);
1451 RETURN_FALSE;
1452 }
1453 }
1454 /* }}}*/
1455
1456 /* {{{ proto array http_get_request_headers(void)
1457 *
1458 */
1459 PHP_FUNCTION(http_get_request_headers)
1460 {
1461 if (ZEND_NUM_ARGS()) {
1462 WRONG_PARAM_COUNT;
1463 }
1464
1465 array_init(return_value);
1466 http_get_request_headers(return_value);
1467 }
1468 /* }}} */
1469
1470 /* {{{ HAVE_CURL */
1471 #ifdef HTTP_HAVE_CURL
1472
1473 /* {{{ proto string http_get(string url[, array options[, array &info]])
1474 *
1475 * Performs an HTTP GET request on the supplied url.
1476 *
1477 * The second parameter is expected to be an associative
1478 * array where the following keys will be recognized:
1479 * <pre>
1480 * - redirect: int, whether and how many redirects to follow
1481 * - unrestrictedauth: bool, whether to continue sending credentials on
1482 * redirects to a different host
1483 * - proxyhost: string, proxy host in "host[:port]" format
1484 * - proxyport: int, use another proxy port as specified in proxyhost
1485 * - proxyauth: string, proxy credentials in "user:pass" format
1486 * - proxyauthtype: int, HTTP_AUTH_BASIC and/or HTTP_AUTH_NTLM
1487 * - httpauth: string, http credentials in "user:pass" format
1488 * - httpauthtype: int, HTTP_AUTH_BASIC, DIGEST and/or NTLM
1489 * - compress: bool, whether to allow gzip/deflate content encoding
1490 * (defaults to true)
1491 * - port: int, use another port as specified in the url
1492 * - referer: string, the referer to sends
1493 * - useragent: string, the user agent to send
1494 * (defaults to PECL::HTTP/version (PHP/version)))
1495 * - headers: array, list of custom headers as associative array
1496 * like array("header" => "value")
1497 * - cookies: array, list of cookies as associative array
1498 * like array("cookie" => "value")
1499 * - cookiestore: string, path to a file where cookies are/will be stored
1500 * </pre>
1501 *
1502 * The optional third parameter will be filled with some additional information
1503 * in form af an associative array, if supplied, like the following example:
1504 * <pre>
1505 * <?php
1506 * array (
1507 * 'effective_url' => 'http://localhost',
1508 * 'response_code' => 403,
1509 * 'total_time' => 0.017,
1510 * 'namelookup_time' => 0.013,
1511 * 'connect_time' => 0.014,
1512 * 'pretransfer_time' => 0.014,
1513 * 'size_upload' => 0,
1514 * 'size_download' => 202,
1515 * 'speed_download' => 11882,
1516 * 'speed_upload' => 0,
1517 * 'header_size' => 145,
1518 * 'request_size' => 62,
1519 * 'ssl_verifyresult' => 0,
1520 * 'filetime' => -1,
1521 * 'content_length_download' => 202,
1522 * 'content_length_upload' => 0,
1523 * 'starttransfer_time' => 0.017,
1524 * 'content_type' => 'text/html; charset=iso-8859-1',
1525 * 'redirect_time' => 0,
1526 * 'redirect_count' => 0,
1527 * 'private' => '',
1528 * 'http_connectcode' => 0,
1529 * 'httpauth_avail' => 0,
1530 * 'proxyauth_avail' => 0,
1531 * )
1532 * ?>
1533 * </pre>
1534 */
1535 PHP_FUNCTION(http_get)
1536 {
1537 char *URL, *data = NULL;
1538 size_t data_len = 0;
1539 int URL_len;
1540 zval *options = NULL, *info = NULL;
1541
1542 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a/!z", &URL, &URL_len, &options, &info) != SUCCESS) {
1543 RETURN_FALSE;
1544 }
1545
1546 if (info) {
1547 zval_dtor(info);
1548 array_init(info);
1549 }
1550
1551 if (SUCCESS == http_get(URL, HASH_ORNULL(options), HASH_ORNULL(info), &data, &data_len)) {
1552 RETURN_STRINGL(data, data_len, 0);
1553 } else {
1554 RETURN_FALSE;
1555 }
1556 }
1557 /* }}} */
1558
1559 /* {{{ proto string http_head(string url[, array options[, array &info]])
1560 *
1561 * Performs an HTTP HEAD request on the suppied url.
1562 * Returns the HTTP response as string.
1563 * See http_get() for a full list of available options.
1564 */
1565 PHP_FUNCTION(http_head)
1566 {
1567 char *URL, *data = NULL;
1568 size_t data_len = 0;
1569 int URL_len;
1570 zval *options = NULL, *info = NULL;
1571
1572 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a/!z", &URL, &URL_len, &options, &info) != SUCCESS) {
1573 RETURN_FALSE;
1574 }
1575
1576 if (info) {
1577 zval_dtor(info);
1578 array_init(info);
1579 }
1580
1581 if (SUCCESS == http_head(URL, HASH_ORNULL(options), HASH_ORNULL(info), &data, &data_len)) {
1582 RETURN_STRINGL(data, data_len, 0);
1583 } else {
1584 RETURN_FALSE;
1585 }
1586 }
1587 /* }}} */
1588
1589 /* {{{ proto string http_post_data(string url, string data[, array options[, &info]])
1590 *
1591 * Performs an HTTP POST request, posting data.
1592 * Returns the HTTP response as string.
1593 * See http_get() for a full list of available options.
1594 */
1595 PHP_FUNCTION(http_post_data)
1596 {
1597 char *URL, *postdata, *data = NULL;
1598 size_t data_len = 0;
1599 int postdata_len, URL_len;
1600 zval *options = NULL, *info = NULL;
1601
1602 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a/!z", &URL, &URL_len, &postdata, &postdata_len, &options, &info) != SUCCESS) {
1603 RETURN_FALSE;
1604 }
1605
1606 if (info) {
1607 zval_dtor(info);
1608 array_init(info);
1609 }
1610
1611 if (SUCCESS == http_post_data(URL, postdata, (size_t) postdata_len, HASH_ORNULL(options), HASH_ORNULL(info), &data, &data_len)) {
1612 RETURN_STRINGL(data, data_len, 0);
1613 } else {
1614 RETURN_FALSE;
1615 }
1616 }
1617 /* }}} */
1618
1619 /* {{{ proto string http_post_array(string url, array data[, array options[, array &info]])
1620 *
1621 * Performs an HTTP POST request, posting www-form-urlencoded array data.
1622 * Returns the HTTP response as string.
1623 * See http_get() for a full list of available options.
1624 */
1625 PHP_FUNCTION(http_post_array)
1626 {
1627 char *URL, *data = NULL;
1628 size_t data_len = 0;
1629 int URL_len;
1630 zval *options = NULL, *info = NULL, *postdata;
1631
1632 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa|a/!z", &URL, &URL_len, &postdata, &options, &info) != SUCCESS) {
1633 RETURN_FALSE;
1634 }
1635
1636 if (info) {
1637 zval_dtor(info);
1638 array_init(info);
1639 }
1640
1641 if (SUCCESS == http_post_array(URL, Z_ARRVAL_P(postdata), HASH_ORNULL(options), HASH_ORNULL(info), &data, &data_len)) {
1642 RETURN_STRINGL(data, data_len, 0);
1643 } else {
1644 RETURN_FALSE;
1645 }
1646 }
1647 /* }}} */
1648
1649 #endif
1650 /* }}} HAVE_CURL */
1651
1652
1653 /* {{{ proto bool http_auth_basic(string user, string pass[, string realm = "Restricted"])
1654 *
1655 * Example:
1656 * <pre>
1657 * <?php
1658 * if (!http_auth_basic('mike', 's3c|r3t')) {
1659 * die('<h1>Authorization failed!</h1>');
1660 * }
1661 * ?>
1662 * </pre>
1663 */
1664 PHP_FUNCTION(http_auth_basic)
1665 {
1666 char *realm = NULL, *user, *pass, *suser, *spass;
1667 int r_len, u_len, p_len;
1668
1669 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|s", &user, &u_len, &pass, &p_len, &realm, &r_len) != SUCCESS) {
1670 RETURN_FALSE;
1671 }
1672
1673 if (!realm) {
1674 realm = "Restricted";
1675 }
1676
1677 if (SUCCESS != http_auth_credentials(&suser, &spass)) {
1678 http_auth_header("Basic", realm);
1679 RETURN_FALSE;
1680 }
1681
1682 if (strcasecmp(suser, user)) {
1683 http_auth_header("Basic", realm);
1684 RETURN_FALSE;
1685 }
1686
1687 if (strcmp(spass, pass)) {
1688 http_auth_header("Basic", realm);
1689 RETURN_FALSE;
1690 }
1691
1692 RETURN_TRUE;
1693 }
1694 /* }}} */
1695
1696 /* {{{ proto bool http_auth_basic_cb(mixed callback[, string realm = "Restricted"])
1697 *
1698 * Example:
1699 * <pre>
1700 * <?php
1701 * function auth_cb($user, $pass)
1702 * {
1703 * global $db;
1704 * $query = 'SELECT pass FROM users WHERE user='. $db->quoteSmart($user);
1705 * if (strlen($realpass = $db->getOne($query)) {
1706 * return $pass === $realpass;
1707 * }
1708 * return false;
1709 * }
1710 *
1711 * if (!http_auth_basic_cb('auth_cb')) {
1712 * die('<h1>Authorization failed</h1>');
1713 * }
1714 * ?>
1715 * </pre>
1716 */
1717 PHP_FUNCTION(http_auth_basic_cb)
1718 {
1719 zval *cb;
1720 char *realm = NULL, *user, *pass;
1721 int r_len;
1722
1723 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|s", &cb, &realm, &r_len) != SUCCESS) {
1724 RETURN_FALSE;
1725 }
1726
1727 if (!realm) {
1728 realm = "Restricted";
1729 }
1730
1731 if (SUCCESS != http_auth_credentials(&user, &pass)) {
1732 http_auth_header("Basic", realm);
1733 RETURN_FALSE;
1734 }
1735 {
1736 zval *zparams[2] = {NULL, NULL}, retval;
1737 int result = 0;
1738
1739 MAKE_STD_ZVAL(zparams[0]);
1740 MAKE_STD_ZVAL(zparams[1]);
1741 ZVAL_STRING(zparams[0], user, 0);
1742 ZVAL_STRING(zparams[1], pass, 0);
1743
1744 if (SUCCESS == call_user_function(EG(function_table), NULL, cb,
1745 &retval, 2, zparams TSRMLS_CC)) {
1746 result = Z_LVAL(retval);
1747 }
1748
1749 efree(user);
1750 efree(pass);
1751 efree(zparams[0]);
1752 efree(zparams[1]);
1753
1754 if (!result) {
1755 http_auth_header("Basic", realm);
1756 }
1757
1758 RETURN_BOOL(result);
1759 }
1760 }
1761 /* }}}*/
1762
1763
1764 /* {{{ php_http_init_globals(zend_http_globals *) */
1765 static void php_http_init_globals(zend_http_globals *http_globals)
1766 {
1767 http_globals->etag_started = 0;
1768 http_globals->ctype = NULL;
1769 http_globals->etag = NULL;
1770 http_globals->lmod = 0;
1771 #ifdef HTTP_HAVE_CURL
1772 http_globals->curlbuf.body.data = NULL;
1773 http_globals->curlbuf.body.used = 0;
1774 http_globals->curlbuf.body.free = 0;
1775 http_globals->curlbuf.hdrs.data = NULL;
1776 http_globals->curlbuf.hdrs.used = 0;
1777 http_globals->curlbuf.hdrs.free = 0;
1778 #endif
1779 http_globals->allowed_methods = NULL;
1780 }
1781 /* }}} */
1782
1783 /* {{{ static inline STATUS http_check_allowed_methods(char *, int) */
1784 #define http_check_allowed_methods(m, l) _http_check_allowed_methods((m), (l) TSRMLS_CC)
1785 static inline void _http_check_allowed_methods(char *methods, int length TSRMLS_DC)
1786 {
1787 if (length && SG(request_info).request_method && (!strstr(methods, SG(request_info).request_method))) {
1788 char *allow_header = emalloc(length + sizeof("Allow: "));
1789 sprintf(allow_header, "Allow: %s", methods);
1790 http_send_header(allow_header);
1791 efree(allow_header);
1792 http_send_status(405);
1793 zend_bailout();
1794 }
1795 }
1796 /* }}} */
1797
1798 /* {{{ PHP_INI */
1799 PHP_INI_MH(update_allowed_methods)
1800 {
1801 http_check_allowed_methods(new_value, new_value_length);
1802 return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
1803 }
1804
1805 PHP_INI_BEGIN()
1806 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)
1807 PHP_INI_END()
1808 /* }}} */
1809
1810 /* {{{ PHP_MINIT_FUNCTION */
1811 PHP_MINIT_FUNCTION(http)
1812 {
1813 ZEND_INIT_MODULE_GLOBALS(http, php_http_init_globals, NULL);
1814 REGISTER_INI_ENTRIES();
1815
1816 #ifdef HTTP_HAVE_CURL
1817 REGISTER_LONG_CONSTANT("HTTP_AUTH_BASIC", CURLAUTH_BASIC, CONST_CS | CONST_PERSISTENT);
1818 REGISTER_LONG_CONSTANT("HTTP_AUTH_DIGEST", CURLAUTH_DIGEST, CONST_CS | CONST_PERSISTENT);
1819 REGISTER_LONG_CONSTANT("HTTP_AUTH_NTLM", CURLAUTH_NTLM, CONST_CS | CONST_PERSISTENT);
1820 #endif
1821
1822 #ifdef ZEND_ENGINE_2
1823 /*
1824 REGISTER_LONG_CONSTANT("HTTP_GET", HTTP_GET, CONST_CS | CONST_PERSISTENT);
1825 REGISTER_LONG_CONSTANT("HTTP_HEAD", HTTP_HEAD, CONST_CS | CONST_PERSISTENT);
1826 REGISTER_LONG_CONSTANT("HTTP_POST", HTTP_POST, CONST_CS | CONST_PERSISTENT);
1827 */
1828 HTTP_REGISTER_CLASS(HTTPi, httpi, NULL, ZEND_ACC_FINAL_CLASS);
1829 HTTP_REGISTER_CLASS_EX(HTTPi_Response, httpi_response, NULL, 0);
1830 #endif
1831 return SUCCESS;
1832 }
1833 /* }}} */
1834
1835 /* {{{ PHP_MSHUTDOWN_FUNCTION */
1836 PHP_MSHUTDOWN_FUNCTION(http)
1837 {
1838 UNREGISTER_INI_ENTRIES();
1839 return SUCCESS;
1840 }
1841 /* }}} */
1842
1843 /* {{{ PHP_RINIT_FUNCTION */
1844 PHP_RINIT_FUNCTION(http)
1845 {
1846 char *allowed_methods = INI_STR("http.allowed_methods");
1847 http_check_allowed_methods(allowed_methods, strlen(allowed_methods));
1848 return SUCCESS;
1849 }
1850 /* }}} */
1851
1852 /* {{{ PHP_RSHUTDOWN_FUNCTION */
1853 PHP_RSHUTDOWN_FUNCTION(http)
1854 {
1855 HTTP_G(etag_started) = 0;
1856 HTTP_G(lmod) = 0;
1857
1858 if (HTTP_G(etag)) {
1859 efree(HTTP_G(etag));
1860 HTTP_G(etag) = NULL;
1861 }
1862
1863 if (HTTP_G(ctype)) {
1864 efree(HTTP_G(ctype));
1865 HTTP_G(ctype) = NULL;
1866 }
1867 #ifdef HTTP_HAVE_CURL
1868 if (HTTP_G(curlbuf).body.data) {
1869 efree(HTTP_G(curlbuf).body.data);
1870 HTTP_G(curlbuf).body.data = NULL;
1871 }
1872 if (HTTP_G(curlbuf).hdrs.data) {
1873 efree(HTTP_G(curlbuf).hdrs.data);
1874 HTTP_G(curlbuf).hdrs.data = NULL;
1875 }
1876 #endif
1877 return SUCCESS;
1878 }
1879 /* }}} */
1880
1881 /* {{{ PHP_MINFO_FUNCTION */
1882 PHP_MINFO_FUNCTION(http)
1883 {
1884 php_info_print_table_start();
1885 php_info_print_table_header(2, "Extended HTTP support", "enabled");
1886 php_info_print_table_row(2, "Version:", PHP_EXT_HTTP_VERSION);
1887 php_info_print_table_row(2, "cURL convenience functions:",
1888 #ifdef HTTP_HAVE_CURL
1889 "enabled"
1890 #else
1891 "disabled"
1892 #endif
1893 );
1894 php_info_print_table_end();
1895
1896 DISPLAY_INI_ENTRIES();
1897 }
1898 /* }}} */
1899
1900 /*
1901 * Local variables:
1902 * tab-width: 4
1903 * c-basic-offset: 4
1904 * End:
1905 * vim600: noet sw=4 ts=4 fdm=marker
1906 * vim<600: noet sw=4 ts=4
1907 */
1908