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