- fix leak in http_send_data()
[m6w6/ext-http] / http_functions.c
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2006, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 /* $Id$ */
14
15 #define HTTP_WANT_SAPI
16 #define HTTP_WANT_CURL
17 #define HTTP_WANT_ZLIB
18 #include "php_http.h"
19
20 #include "php_ini.h"
21 #include "ext/standard/php_string.h"
22 #include "zend_operators.h"
23
24 #ifdef HTTP_HAVE_SESSION
25 # include "ext/session/php_session.h"
26 #endif
27
28 #include "php_http_api.h"
29 #include "php_http_cache_api.h"
30 #include "php_http_cookie_api.h"
31 #include "php_http_date_api.h"
32 #include "php_http_encoding_api.h"
33 #include "php_http_headers_api.h"
34 #include "php_http_message_api.h"
35 #include "php_http_request_api.h"
36 #include "php_http_request_method_api.h"
37 #include "php_http_send_api.h"
38 #include "php_http_url_api.h"
39
40 /* {{{ proto string http_date([int timestamp])
41 *
42 * Compose a valid HTTP date regarding RFC 1123
43 * looking like: "Wed, 22 Dec 2004 11:34:47 GMT"
44 *
45 * Accepts an optional unix timestamp as parameter.
46 *
47 * Returns the HTTP date as string.
48 */
49 PHP_FUNCTION(http_date)
50 {
51 long t = -1;
52
53 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &t) != SUCCESS) {
54 RETURN_FALSE;
55 }
56
57 if (t == -1) {
58 t = HTTP_G->request.time;
59 }
60
61 RETURN_STRING(http_date(t), 0);
62 }
63 /* }}} */
64
65 #if PHP_MAJOR_VERSION == 4 && PHP_MINOR_VERSION == 3 && PHP_RELEASE_VERSION < 10
66 # define php_url_parse_ex(u, l) php_url_parse(u)
67 #endif
68
69 /* {{{ proto string http_build_url([mixed url[, mixed parts[, int flags = HTTP_URL_REPLACE[, array &new_url]]]])
70 *
71 * Build an URL.
72 *
73 * Expexts (part(s) of) an URL as first parameter in form of a string or assoziative array
74 * like parse_url() returns. Accepts an optional second parameter in the same way as the
75 * first argument. Accepts an optional third integer parameter, which is a bitmask of
76 * binary or'ed HTTP_URL_* constants. The optional fourth parameter will be filled
77 * with the results as associative array like parse_url() would return.
78 *
79 * The parts of the second URL will be merged into the first according to the flags argument.
80 * The following flags are recognized:
81 * <pre>
82 * - HTTP_URL_REPLACE: (default) set parts of the second url will replace the parts in the first
83 * - HTTP_URL_JOIN_PATH: the path of the second url will be merged into the one of the first
84 * - HTTP_URL_JOIN_QUERY: the two querystrings will be merged recursively
85 * - HTTP_URL_STRIP_USER: the user part will not appear in the result
86 * - HTTP_URL_STRIP_PASS: the password part will not appear in the result
87 * - HTTP_URL_STRIP_AUTH: neither the user nor the password part will appear in the result
88 * - HTTP_URL_STRIP_PORT: no explicit port will be set in the result
89 * - HTTP_URL_STRIP_PATH: the path part will not appear in the result
90 * - HTTP_URL_STRIP_QUERY: no query string will be present in the result
91 * - HTTP_URL_STRIP_FRAGMENT: no fragment will be present in the result
92 * </pre>
93 *
94 * Example:
95 * <pre>
96 * <?php
97 * // ftp://ftp.example.com/pub/files/current/?a=b&a=c
98 * echo http_build_url("http://user@www.example.com/pub/index.php?a=b#files",
99 * array(
100 * "scheme" => "ftp",
101 * "host" => "ftp.example.com",
102 * "path" => "files/current/",
103 * "query" => "a=c"
104 * ),
105 * HTTP_URL_STRIP_AUTH | HTTP_URL_JOIN_PATH | HTTP_URL_JOIN_QUERY | HTTP_URL_STRIP_FRAGMENT
106 * );
107 * ?>
108 * </pre>
109 * Returns the new URL as string on success or FALSE on failure.
110 */
111 PHP_FUNCTION(http_build_url)
112 {
113 char *url_str = NULL;
114 size_t url_len = 0;
115 long flags = HTTP_URL_REPLACE;
116 zval *z_old_url = NULL, *z_new_url = NULL, *z_composed_url = NULL;
117 php_url *old_url = NULL, *new_url = NULL, *composed_url = NULL;
118
119 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!/z!/lz", &z_old_url, &z_new_url, &flags, &z_composed_url) != SUCCESS) {
120 RETURN_FALSE;
121 }
122
123 if (z_new_url) {
124 if (Z_TYPE_P(z_new_url) == IS_ARRAY || Z_TYPE_P(z_new_url) == IS_OBJECT) {
125 new_url = http_url_from_struct(NULL, HASH_OF(z_new_url));
126 } else {
127 convert_to_string(z_new_url);
128 if (!(new_url = php_url_parse_ex(Z_STRVAL_P(z_new_url), Z_STRLEN_P(z_new_url)))) {
129 http_error_ex(HE_WARNING, HTTP_E_URL, "Could not parse URL (%s)", Z_STRVAL_P(z_new_url));
130 RETURN_FALSE;
131 }
132 }
133 }
134
135 if (z_old_url) {
136 if (Z_TYPE_P(z_old_url) == IS_ARRAY || Z_TYPE_P(z_old_url) == IS_OBJECT) {
137 old_url = http_url_from_struct(NULL, HASH_OF(z_old_url));
138 } else {
139 convert_to_string(z_old_url);
140 if (!(old_url = php_url_parse_ex(Z_STRVAL_P(z_old_url), Z_STRLEN_P(z_old_url)))) {
141 if (new_url) {
142 php_url_free(new_url);
143 }
144 http_error_ex(HE_WARNING, HTTP_E_URL, "Could not parse URL (%s)", Z_STRVAL_P(z_old_url));
145 RETURN_FALSE;
146 }
147 }
148 }
149
150 if (z_composed_url) {
151 http_build_url(flags, old_url, new_url, &composed_url, &url_str, &url_len);
152 http_url_tostruct(composed_url, z_composed_url);
153 php_url_free(composed_url);
154 } else {
155 http_build_url(flags, old_url, new_url, NULL, &url_str, &url_len);
156 }
157
158 if (new_url) {
159 php_url_free(new_url);
160 }
161 if (old_url) {
162 php_url_free(old_url);
163 }
164
165 RETURN_STRINGL(url_str, url_len, 0);
166 }
167 /* }}} */
168
169 /* {{{ proto string http_build_str(array query [, string prefix[, string arg_separator]])
170 *
171 * Opponent to parse_str().
172 *
173 * Expects an array as first argument which represents the parts of the query string to build.
174 * Accepts a string as optional second parameter containing a top-level prefix to use.
175 * The optional third parameter should specify an argument separator to use (by default the
176 * INI setting arg_separator.output will be used, or "&" if neither is set).
177 *
178 * Returns the built query as string on success or FALSE on failure.
179 */
180 PHP_FUNCTION(http_build_str)
181 {
182 zval *formdata;
183 char *prefix = NULL, *arg_sep = INI_STR("arg_separator.output");
184 int prefix_len = 0, arg_sep_len = strlen(arg_sep);
185 phpstr formstr;
186
187 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|ss", &formdata, &prefix, &prefix_len, &arg_sep, &arg_sep_len) != SUCCESS) {
188 RETURN_FALSE;
189 }
190
191 if (!arg_sep_len) {
192 arg_sep = HTTP_URL_ARGSEP;
193 arg_sep_len = lenof(HTTP_URL_ARGSEP);
194 }
195
196 phpstr_init(&formstr);
197 if (SUCCESS != http_urlencode_hash_recursive(HASH_OF(formdata), &formstr, arg_sep, arg_sep_len, prefix, prefix_len)) {
198 RETURN_FALSE;
199 }
200
201 if (!formstr.used) {
202 phpstr_dtor(&formstr);
203 RETURN_NULL();
204 }
205
206 RETURN_PHPSTR_VAL(&formstr);
207 }
208 /* }}} */
209
210 #define HTTP_DO_NEGOTIATE(type, supported, rs_array) \
211 { \
212 HashTable *result; \
213 if ((result = http_negotiate_ ##type(supported))) { \
214 char *key; \
215 uint key_len; \
216 ulong idx; \
217 \
218 if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(result, &key, &key_len, &idx, 1, NULL)) { \
219 RETVAL_STRINGL(key, key_len-1, 0); \
220 } else { \
221 RETVAL_NULL(); \
222 } \
223 \
224 if (rs_array) { \
225 zend_hash_copy(Z_ARRVAL_P(rs_array), result, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); \
226 } \
227 \
228 zend_hash_destroy(result); \
229 FREE_HASHTABLE(result); \
230 \
231 } else { \
232 zval **value; \
233 \
234 zend_hash_internal_pointer_reset(Z_ARRVAL_P(supported)); \
235 if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(supported), (void *) &value)) { \
236 RETVAL_ZVAL(*value, 1, 0); \
237 } else { \
238 RETVAL_NULL(); \
239 } \
240 \
241 if (rs_array) { \
242 HashPosition pos; \
243 zval **value; \
244 \
245 FOREACH_VAL(pos, supported, value) { \
246 convert_to_string_ex(value); \
247 add_assoc_double(rs_array, Z_STRVAL_PP(value), 1.0); \
248 } \
249 } \
250 } \
251 }
252
253
254 /* {{{ proto string http_negotiate_language(array supported[, array &result])
255 *
256 * This function negotiates the clients preferred language based on its
257 * Accept-Language HTTP header. The qualifier is recognized and languages
258 * without qualifier are rated highest. The qualifier will be decreased by
259 * 10% for partial matches (i.e. matching primary language).
260 *
261 * Expects an array as parameter containing the supported languages as values.
262 * If the optional second parameter is supplied, it will be filled with an
263 * array containing the negotiation results.
264 *
265 * Returns the negotiated language or the default language (i.e. first array entry)
266 * if none match.
267 *
268 * Example:
269 * <pre>
270 * <?php
271 * $langs = array(
272 * 'en-US',// default
273 * 'fr',
274 * 'fr-FR',
275 * 'de',
276 * 'de-DE',
277 * 'de-AT',
278 * 'de-CH',
279 * );
280 *
281 * include './langs/'. http_negotiate_language($langs, $result) .'.php';
282 *
283 * print_r($result);
284 * ?>
285 * </pre>
286 */
287 PHP_FUNCTION(http_negotiate_language)
288 {
289 zval *supported, *rs_array = NULL;
290
291 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|z", &supported, &rs_array) != SUCCESS) {
292 RETURN_FALSE;
293 }
294
295 if (rs_array) {
296 zval_dtor(rs_array);
297 array_init(rs_array);
298 }
299
300 HTTP_DO_NEGOTIATE(language, supported, rs_array);
301 }
302 /* }}} */
303
304 /* {{{ proto string http_negotiate_charset(array supported[, array &result])
305 *
306 * This function negotiates the clients preferred charset based on its
307 * Accept-Charset HTTP header. The qualifier is recognized and charsets
308 * without qualifier are rated highest.
309 *
310 * Expects an array as parameter containing the supported charsets as values.
311 * If the optional second parameter is supplied, it will be filled with an
312 * array containing the negotiation results.
313 *
314 * Returns the negotiated charset or the default charset (i.e. first array entry)
315 * if none match.
316 *
317 * Example:
318 * <pre>
319 * <?php
320 * $charsets = array(
321 * 'iso-8859-1', // default
322 * 'iso-8859-2',
323 * 'iso-8859-15',
324 * 'utf-8'
325 * );
326 *
327 * $pref = http_negotiate_charset($charsets, $result);
328 *
329 * if (strcmp($pref, 'iso-8859-1')) {
330 * iconv_set_encoding('internal_encoding', 'iso-8859-1');
331 * iconv_set_encoding('output_encoding', $pref);
332 * ob_start('ob_iconv_handler');
333 * }
334 *
335 * print_r($result);
336 * ?>
337 * </pre>
338 */
339 PHP_FUNCTION(http_negotiate_charset)
340 {
341 zval *supported, *rs_array = NULL;
342
343 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|z", &supported, &rs_array) != SUCCESS) {
344 RETURN_FALSE;
345 }
346
347 if (rs_array) {
348 zval_dtor(rs_array);
349 array_init(rs_array);
350 }
351
352 HTTP_DO_NEGOTIATE(charset, supported, rs_array);
353 }
354 /* }}} */
355
356 /* {{{ proto string http_negotiate_ctype(array supported[, array &result])
357 *
358 * This function negotiates the clients preferred content type based on its
359 * Accept HTTP header. The qualifier is recognized and content types
360 * without qualifier are rated highest.
361 *
362 * Expects an array as parameter containing the supported content types as values.
363 * If the optional second parameter is supplied, it will be filled with an
364 * array containing the negotiation results.
365 *
366 * Returns the negotiated content type or the default content type
367 * (i.e. first array entry) if none match.
368 *
369 * Example:
370 * <pre>
371 * <?php
372 * $ctypes = array('application/xhtml+xml', 'text/html');
373 * http_send_content_type(http_negotiate_content_type($ctypes));
374 * ?>
375 * </pre>
376 */
377 PHP_FUNCTION(http_negotiate_content_type)
378 {
379 zval *supported, *rs_array = NULL;
380
381 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|z", &supported, &rs_array)) {
382 RETURN_FALSE;
383 }
384
385 if (rs_array) {
386 zval_dtor(rs_array);
387 array_init(rs_array);
388 }
389
390 HTTP_DO_NEGOTIATE(content_type, supported, rs_array);
391 }
392 /* }}} */
393
394 /* {{{ proto bool http_send_status(int status)
395 *
396 * Send HTTP status code.
397 *
398 * Expects an HTTP status code as parameter.
399 *
400 * Returns TRUE on success or FALSE on failure.
401 */
402 PHP_FUNCTION(http_send_status)
403 {
404 int status = 0;
405
406 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &status) != SUCCESS) {
407 RETURN_FALSE;
408 }
409 if (status < 100 || status > 510) {
410 http_error_ex(HE_WARNING, HTTP_E_HEADER, "Invalid HTTP status code (100-510): %d", status);
411 RETURN_FALSE;
412 }
413
414 RETURN_SUCCESS(http_send_status(status));
415 }
416 /* }}} */
417
418 /* {{{ proto bool http_send_last_modified([int timestamp])
419 *
420 * Send a "Last-Modified" header with a valid HTTP date.
421 *
422 * Accepts a unix timestamp, converts it to a valid HTTP date and
423 * sends it as "Last-Modified" HTTP header. If timestamp is
424 * omitted, the current time will be sent.
425 *
426 * Returns TRUE on success or FALSE on failure.
427 */
428 PHP_FUNCTION(http_send_last_modified)
429 {
430 long t = -1;
431
432 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &t) != SUCCESS) {
433 RETURN_FALSE;
434 }
435
436 if (t == -1) {
437 t = HTTP_G->request.time;
438 }
439
440 RETURN_SUCCESS(http_send_last_modified(t));
441 }
442 /* }}} */
443
444 /* {{{ proto bool http_send_content_type([string content_type = 'application/x-octetstream'])
445 *
446 * Send the Content-Type of the sent entity. This is particularly important
447 * if you use the http_send() API.
448 *
449 * Accepts an optional string parameter containing the desired content type
450 * (primary/secondary).
451 *
452 * Returns TRUE on success or FALSE on failure.
453 */
454 PHP_FUNCTION(http_send_content_type)
455 {
456 char *ct = "application/x-octetstream";
457 int ct_len = lenof("application/x-octetstream");
458
459 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &ct, &ct_len) != SUCCESS) {
460 RETURN_FALSE;
461 }
462
463 RETURN_SUCCESS(http_send_content_type(ct, ct_len));
464 }
465 /* }}} */
466
467 /* {{{ proto bool http_send_content_disposition(string filename[, bool inline = false])
468 *
469 * Send the Content-Disposition. The Content-Disposition header is very useful
470 * if the data actually sent came from a file or something similar, that should
471 * be "saved" by the client/user (i.e. by browsers "Save as..." popup window).
472 *
473 * Expects a string parameter specifying the file name the "Save as..." dialog
474 * should display. Optionally accepts a bool parameter, which, if set to true
475 * and the user agent knows how to handle the content type, will probably not
476 * cause the popup window to be shown.
477 *
478 * Returns TRUE on success or FALSE on failure.
479 */
480 PHP_FUNCTION(http_send_content_disposition)
481 {
482 char *filename;
483 int f_len;
484 zend_bool send_inline = 0;
485
486 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &filename, &f_len, &send_inline) != SUCCESS) {
487 RETURN_FALSE;
488 }
489 RETURN_SUCCESS(http_send_content_disposition(filename, f_len, send_inline));
490 }
491 /* }}} */
492
493 /* {{{ proto bool http_match_modified([int timestamp[, bool for_range = false]])
494 *
495 * Matches the given unix timestamp against the clients "If-Modified-Since"
496 * resp. "If-Unmodified-Since" HTTP headers.
497 *
498 * Accepts a unix timestamp which should be matched. Optionally accepts an
499 * additional bool parameter, which if set to true will check the header
500 * usually used to validate HTTP ranges. If timestamp is omitted, the
501 * current time will be used.
502 *
503 * Returns TRUE if timestamp represents an earlier date than the header,
504 * else FALSE.
505 */
506 PHP_FUNCTION(http_match_modified)
507 {
508 long t = -1;
509 zend_bool for_range = 0;
510
511 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lb", &t, &for_range) != SUCCESS) {
512 RETURN_FALSE;
513 }
514
515 // current time if not supplied (senseless though)
516 if (t == -1) {
517 t = HTTP_G->request.time;
518 }
519
520 if (for_range) {
521 RETURN_BOOL(http_match_last_modified("HTTP_IF_UNMODIFIED_SINCE", t));
522 }
523 RETURN_BOOL(http_match_last_modified("HTTP_IF_MODIFIED_SINCE", t));
524 }
525 /* }}} */
526
527 /* {{{ proto bool http_match_etag(string etag[, bool for_range = false])
528 *
529 * Matches the given ETag against the clients "If-Match" resp.
530 * "If-None-Match" HTTP headers.
531 *
532 * Expects a string parameter containing the ETag to compare. Optionally
533 * accepts a bool parameter, which, if set to true, will check the header
534 * usually used to validate HTTP ranges.
535 *
536 * Returns TRUE if ETag matches or the header contained the asterisk ("*"),
537 * else FALSE.
538 */
539 PHP_FUNCTION(http_match_etag)
540 {
541 int etag_len;
542 char *etag;
543 zend_bool for_range = 0;
544
545 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &etag, &etag_len, &for_range) != SUCCESS) {
546 RETURN_FALSE;
547 }
548
549 if (for_range) {
550 RETURN_BOOL(http_match_etag("HTTP_IF_MATCH", etag));
551 }
552 RETURN_BOOL(http_match_etag("HTTP_IF_NONE_MATCH", etag));
553 }
554 /* }}} */
555
556 /* {{{ proto bool http_cache_last_modified([int timestamp_or_expires]])
557 *
558 * Attempts to cache the sent entity by its last modification date.
559 *
560 * Accepts a unix timestamp as parameter which is handled as follows:
561 *
562 * If timestamp_or_expires is greater than 0, it is handled as timestamp
563 * and will be sent as date of last modification. If it is 0 or omitted,
564 * the current time will be sent as Last-Modified date. If it's negative,
565 * it is handled as expiration time in seconds, which means that if the
566 * requested last modification date is not between the calculated timespan,
567 * the Last-Modified header is updated and the actual body will be sent.
568 *
569 * Returns FALSE on failure, or *exits* with "304 Not Modified" if the entity is cached.
570 *
571 * A log entry will be written to the cache log if the INI entry
572 * http.log.cache is set and the cache attempt was successful.
573 */
574 PHP_FUNCTION(http_cache_last_modified)
575 {
576 long last_modified = 0, send_modified = 0, t;
577 zval *zlm;
578
579 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &last_modified) != SUCCESS) {
580 RETURN_FALSE;
581 }
582
583 HTTP_CHECK_HEADERS_SENT(RETURN_FALSE);
584
585 t = HTTP_G->request.time;
586
587 /* 0 or omitted */
588 if (!last_modified) {
589 /* does the client have? (att: caching "forever") */
590 if ((zlm = http_get_server_var("HTTP_IF_MODIFIED_SINCE"))) {
591 last_modified = send_modified = http_parse_date(Z_STRVAL_P(zlm));
592 /* send current time */
593 } else {
594 send_modified = t;
595 }
596 /* negative value is supposed to be expiration time */
597 } else if (last_modified < 0) {
598 last_modified += t;
599 send_modified = t;
600 /* send supplied time explicitly */
601 } else {
602 send_modified = last_modified;
603 }
604
605 RETURN_SUCCESS(http_cache_last_modified(last_modified, send_modified, HTTP_DEFAULT_CACHECONTROL, lenof(HTTP_DEFAULT_CACHECONTROL)));
606 }
607 /* }}} */
608
609 /* {{{ proto bool http_cache_etag([string etag])
610 *
611 * Attempts to cache the sent entity by its ETag, either supplied or generated
612 * by the hash algorithm specified by the INI setting "http.etag.mode".
613 *
614 * If the clients "If-None-Match" header matches the supplied/calculated
615 * ETag, the body is considered cached on the clients side and
616 * a "304 Not Modified" status code is issued.
617 *
618 * Returns FALSE on failure, or *exits* with "304 Not Modified" if the entity is cached.
619 *
620 * A log entry is written to the cache log if the INI entry
621 * "http.log.cache" is set and the cache attempt was successful.
622 */
623 PHP_FUNCTION(http_cache_etag)
624 {
625 char *etag = NULL;
626 int etag_len = 0;
627
628 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &etag, &etag_len) != SUCCESS) {
629 RETURN_FALSE;
630 }
631
632 HTTP_CHECK_HEADERS_SENT(RETURN_FALSE);
633
634 RETURN_SUCCESS(http_cache_etag(etag, etag_len, HTTP_DEFAULT_CACHECONTROL, lenof(HTTP_DEFAULT_CACHECONTROL)));
635 }
636 /* }}} */
637
638 /* {{{ proto string ob_etaghandler(string data, int mode)
639 *
640 * For use with ob_start(). Output buffer handler generating an ETag with
641 * the hash algorithm specified with the INI setting "http.etag.mode".
642 */
643 PHP_FUNCTION(ob_etaghandler)
644 {
645 char *data;
646 int data_len;
647 long mode;
648
649 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &data, &data_len, &mode)) {
650 RETURN_FALSE;
651 }
652
653 Z_TYPE_P(return_value) = IS_STRING;
654 http_ob_etaghandler(data, data_len, &Z_STRVAL_P(return_value), (uint *) &Z_STRLEN_P(return_value), mode);
655 }
656 /* }}} */
657
658 /* {{{ proto void http_throttle(double sec[, int bytes = 40960])
659 *
660 * Sets the throttle delay and send buffer size for use with http_send() API.
661 * Provides a basic throttling mechanism, which will yield the current process
662 * resp. thread until the entity has been completely sent, though.
663 *
664 * Expects a double parameter specifying the seconds too sleep() after
665 * each chunk sent. Additionally accepts an optional int parameter
666 * representing the chunk size in bytes.
667 *
668 * Example:
669 * <pre>
670 * <?php
671 * // ~ 20 kbyte/s
672 * # http_throttle(1, 20000);
673 * # http_throttle(0.5, 10000);
674 * # http_throttle(0.1, 2000);
675 * http_send_file('document.pdf');
676 * ?>
677 * </pre>
678 */
679 PHP_FUNCTION(http_throttle)
680 {
681 long chunk_size = HTTP_SENDBUF_SIZE;
682 double interval;
683
684 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d|l", &interval, &chunk_size)) {
685 return;
686 }
687
688 HTTP_G->send.throttle_delay = interval;
689 HTTP_G->send.buffer_size = chunk_size;
690 }
691 /* }}} */
692
693 /* {{{ proto void http_redirect([string url[, array params[, bool session = false[, int status = 302]]]])
694 *
695 * Redirect to the given url.
696 *
697 * The supplied url will be expanded with http_build_url(), the params array will
698 * be treated with http_build_query() and the session identification will be appended
699 * if session is true.
700 *
701 * The HTTP response code will be set according to status.
702 * You can use one of the following constants for convenience:
703 * - HTTP_REDIRECT 302 Found for GET/HEAD, else 303 See Other
704 * - HTTP_REDIRECT_PERM 301 Moved Permanently
705 * - HTTP_REDIRECT_FOUND 302 Found
706 * - HTTP_REDIRECT_POST 303 See Other
707 * - HTTP_REDIRECT_PROXY 305 Use Proxy
708 * - HTTP_REDIRECT_TEMP 307 Temporary Redirect
709 *
710 * Please see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3
711 * for which redirect response code to use in which situation.
712 *
713 * To be RFC compliant, "Redirecting to <a>URL</a>." will be displayed,
714 * if the client doesn't redirect immediately, and the request method was
715 * another one than HEAD.
716 *
717 * Returns FALSE on failure, or *exits* on success.
718 *
719 * A log entry will be written to the redirect log, if the INI entry
720 * "http.log.redirect" is set and the redirect attempt was successful.
721 */
722 PHP_FUNCTION(http_redirect)
723 {
724 int url_len = 0;
725 size_t query_len = 0;
726 zend_bool session = 0, free_params = 0;
727 zval *params = NULL;
728 long status = HTTP_REDIRECT;
729 char *query = NULL, *url = NULL, *URI, *LOC, *RED = NULL;
730
731 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sa!/bl", &url, &url_len, &params, &session, &status) != SUCCESS) {
732 RETURN_FALSE;
733 }
734
735 #ifdef HTTP_HAVE_SESSION
736 /* append session info */
737 if (session) {
738 if (!params) {
739 free_params = 1;
740 MAKE_STD_ZVAL(params);
741 array_init(params);
742 }
743 if (PS(session_status) == php_session_active) {
744 if (add_assoc_string(params, PS(session_name), PS(id), 1) != SUCCESS) {
745 http_error(HE_WARNING, HTTP_E_RUNTIME, "Could not append session information");
746 }
747 }
748 }
749 #endif
750
751 /* treat params array with http_build_query() */
752 if (params) {
753 if (SUCCESS != http_urlencode_hash_ex(Z_ARRVAL_P(params), 0, NULL, 0, &query, &query_len)) {
754 if (free_params) {
755 zval_dtor(params);
756 FREE_ZVAL(params);
757 }
758 if (query) {
759 efree(query);
760 }
761 RETURN_FALSE;
762 }
763 }
764
765 URI = http_absolute_url(url);
766
767 if (query_len) {
768 spprintf(&LOC, 0, "Location: %s?%s", URI, query);
769 if (status != 300) {
770 spprintf(&RED, 0, "Redirecting to <a href=\"%s?%s\">%s?%s</a>.\n", URI, query, URI, query);
771 }
772 } else {
773 spprintf(&LOC, 0, "Location: %s", URI);
774 if (status != 300) {
775 spprintf(&RED, 0, "Redirecting to <a href=\"%s\">%s</a>.\n", URI, URI);
776 }
777 }
778
779 efree(URI);
780 if (query) {
781 efree(query);
782 }
783 if (free_params) {
784 zval_dtor(params);
785 FREE_ZVAL(params);
786 }
787
788 switch (status) {
789 case 300:
790 RETVAL_SUCCESS(http_send_status_header(status, LOC));
791 efree(LOC);
792 return;
793
794 case HTTP_REDIRECT_PERM:
795 case HTTP_REDIRECT_FOUND:
796 case HTTP_REDIRECT_POST:
797 case HTTP_REDIRECT_PROXY:
798 case HTTP_REDIRECT_TEMP:
799 break;
800
801 case 306:
802 default:
803 http_error_ex(HE_NOTICE, HTTP_E_RUNTIME, "Unsupported redirection status code: %ld", status);
804 case HTTP_REDIRECT:
805 if ( SG(request_info).request_method &&
806 strcasecmp(SG(request_info).request_method, "HEAD") &&
807 strcasecmp(SG(request_info).request_method, "GET")) {
808 status = HTTP_REDIRECT_POST;
809 } else {
810 status = HTTP_REDIRECT_FOUND;
811 }
812 break;
813 }
814
815 RETURN_SUCCESS(http_exit_ex(status, LOC, RED, 1));
816 }
817 /* }}} */
818
819 /* {{{ proto bool http_send_data(string data)
820 *
821 * Sends raw data with support for (multiple) range requests.
822 *
823 * Returns TRUE on success, or FALSE on failure.
824 */
825 PHP_FUNCTION(http_send_data)
826 {
827 int data_len;
828 char *data_buf;
829
830 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data_buf, &data_len) != SUCCESS) {
831 RETURN_FALSE;
832 }
833
834 RETURN_SUCCESS(http_send_data(data_buf, data_len));
835 }
836 /* }}} */
837
838 /* {{{ proto bool http_send_file(string file)
839 *
840 * Sends a file with support for (multiple) range requests.
841 *
842 * Expects a string parameter referencing the file to send.
843 *
844 * Returns TRUE on success, or FALSE on failure.
845 */
846 PHP_FUNCTION(http_send_file)
847 {
848 char *file;
849 int flen = 0;
850
851 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &flen) != SUCCESS) {
852 RETURN_FALSE;
853 }
854 if (!flen) {
855 RETURN_FALSE;
856 }
857
858 RETURN_SUCCESS(http_send_file(file));
859 }
860 /* }}} */
861
862 /* {{{ proto bool http_send_stream(resource stream)
863 *
864 * Sends an already opened stream with support for (multiple) range requests.
865 *
866 * Expects a resource parameter referencing the stream to read from.
867 *
868 * Returns TRUE on success, or FALSE on failure.
869 */
870 PHP_FUNCTION(http_send_stream)
871 {
872 zval *zstream;
873 php_stream *file;
874
875 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream) != SUCCESS) {
876 RETURN_FALSE;
877 }
878
879 php_stream_from_zval(file, &zstream);
880 RETURN_SUCCESS(http_send_stream(file));
881 }
882 /* }}} */
883
884 /* {{{ proto string http_chunked_decode(string encoded)
885 *
886 * Decodes a string that was HTTP-chunked encoded.
887 *
888 * Expects a chunked encoded string as parameter.
889 *
890 * Returns the decoded string on success or FALSE on failure.
891 */
892 PHP_FUNCTION(http_chunked_decode)
893 {
894 char *encoded = NULL, *decoded = NULL;
895 size_t decoded_len = 0;
896 int encoded_len = 0;
897
898 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &encoded, &encoded_len) != SUCCESS) {
899 RETURN_FALSE;
900 }
901
902 if (NULL != http_encoding_dechunk(encoded, encoded_len, &decoded, &decoded_len)) {
903 RETURN_STRINGL(decoded, (int) decoded_len, 0);
904 } else {
905 RETURN_FALSE;
906 }
907 }
908 /* }}} */
909
910 /* {{{ proto object http_parse_message(string message)
911 *
912 * Parses (a) http_message(s) into a simple recursive object structure.
913 *
914 * Expects a string parameter containing a single HTTP message or
915 * several consecutive HTTP messages.
916 *
917 * Returns an hierarchical object structure of the parsed messages.
918 *
919 * Example:
920 * <pre>
921 * <?php
922 * print_r(http_parse_message(http_get(URL, array('redirect' => 3)));
923 *
924 * stdClass object
925 * (
926 * [type] => 2
927 * [httpVersion] => 1.1
928 * [responseCode] => 200
929 * [headers] => Array
930 * (
931 * [Content-Length] => 3
932 * [Server] => Apache
933 * )
934 * [body] => Hi!
935 * [parentMessage] => stdClass object
936 * (
937 * [type] => 2
938 * [httpVersion] => 1.1
939 * [responseCode] => 302
940 * [headers] => Array
941 * (
942 * [Content-Length] => 0
943 * [Location] => ...
944 * )
945 * [body] =>
946 * [parentMessage] => ...
947 * )
948 * )
949 * ?>
950 * </pre>
951 */
952 PHP_FUNCTION(http_parse_message)
953 {
954 char *message;
955 int message_len;
956 http_message *msg = NULL;
957
958 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &message, &message_len)) {
959 RETURN_NULL();
960 }
961
962 if ((msg = http_message_parse(message, message_len))) {
963 object_init(return_value);
964 http_message_tostruct_recursive(msg, return_value);
965 http_message_free(&msg);
966 } else {
967 RETURN_NULL();
968 }
969 }
970 /* }}} */
971
972 /* {{{ proto array http_parse_headers(string header)
973 *
974 * Parses HTTP headers into an associative array.
975 *
976 * Expects a string parameter containing HTTP headers.
977 *
978 * Returns an array on success, or FALSE on failure.
979 *
980 * Example:
981 * <pre>
982 * <?php
983 * $headers = "content-type: text/html; charset=UTF-8\r\n".
984 * "Server: Funky/1.0\r\n".
985 * "Set-Cookie: foo=bar\r\n".
986 * "Set-Cookie: baz=quux\r\n".
987 * "Folded: works\r\n\ttoo\r\n";
988 * print_r(http_parse_headers($headers));
989 *
990 * Array
991 * (
992 * [Content-Type] => text/html; chatset=UTF-8
993 * [Server] => Funky/1.0
994 * [Set-Cookie] => Array
995 * (
996 * [0] => foo=bar
997 * [1] => baz=quux
998 * )
999 * [Folded] => works
1000 * too
1001 * )
1002 * ?>
1003 * </pre>
1004 */
1005 PHP_FUNCTION(http_parse_headers)
1006 {
1007 char *header;
1008 int header_len;
1009
1010 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &header, &header_len)) {
1011 RETURN_FALSE;
1012 }
1013
1014 array_init(return_value);
1015 if (SUCCESS != http_parse_headers(header, return_value)) {
1016 zval_dtor(return_value);
1017 http_error(HE_WARNING, HTTP_E_MALFORMED_HEADERS, "Failed to parse headers");
1018 RETURN_FALSE;
1019 }
1020 }
1021 /* }}}*/
1022
1023 /* {{{ proto object http_parse_cookie(string cookie[, int flags[, array allowed_extras]])
1024 *
1025 * Parses HTTP cookies like sent in a response into a struct.
1026 *
1027 * Expects a string as parameter containing the value of a Set-Cookie response header.
1028 *
1029 * Returns an stdClass olike shown in the example on success or FALSE on failure.
1030 *
1031 * Example:
1032 * <pre>
1033 * <?php
1034 * print_r(http_parse_cookie("foo=bar; bar=baz; path=/; domain=example.com; comment=; secure", 0, array("comment")));
1035 *
1036 * stdClass Object
1037 * (
1038 * [cookies] => Array
1039 * (
1040 * [foo] => bar
1041 * [bar] => baz
1042 * )
1043 *
1044 * [extras] => Array
1045 * (
1046 * [comment] =>
1047 * )
1048 *
1049 * [flags] => 16
1050 * [expires] => 0
1051 * [path] => /
1052 * [domain] => example.com
1053 * )
1054 * ?>
1055 * </pre>
1056 */
1057 PHP_FUNCTION(http_parse_cookie)
1058 {
1059 char *cookie, **allowed_extras = NULL;
1060 int i = 0, cookie_len;
1061 long flags = 0;
1062 zval *allowed_extras_array = NULL, **entry = NULL;
1063 HashPosition pos;
1064 http_cookie_list list;
1065
1066 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|la!", &cookie, &cookie_len, &flags, &allowed_extras_array)) {
1067 RETURN_FALSE;
1068 }
1069
1070 if (allowed_extras_array) {
1071 allowed_extras = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array)) + 1, sizeof(char *));
1072 FOREACH_VAL(pos, allowed_extras_array, entry) {
1073 ZVAL_ADDREF(*entry);
1074 convert_to_string_ex(entry);
1075 allowed_extras[i++] = estrndup(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry));
1076 zval_ptr_dtor(entry);
1077 }
1078 }
1079
1080 if (http_parse_cookie_ex(&list, cookie, flags, allowed_extras)) {
1081 object_init(return_value);
1082 http_cookie_list_tostruct(&list, return_value);
1083 http_cookie_list_dtor(&list);
1084 } else {
1085 RETVAL_FALSE;
1086 }
1087
1088 if (allowed_extras) {
1089 for (i = 0; allowed_extras[i]; ++i) {
1090 efree(allowed_extras[i]);
1091 }
1092 efree(allowed_extras);
1093 }
1094 }
1095 /* }}} */
1096
1097 /* {{{ proto string http_build_cookie(array cookie)
1098 *
1099 * Build a cookie string from an array/object like returned by http_parse_cookie().
1100 */
1101 PHP_FUNCTION(http_build_cookie)
1102 {
1103 char *str = NULL;
1104 size_t len = 0;
1105 zval *strct;
1106 http_cookie_list list;
1107
1108 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &strct)) {
1109 RETURN_FALSE;
1110 }
1111
1112 http_cookie_list_fromstruct(&list, strct);
1113 http_cookie_list_tostring(&list, &str, &len);
1114 http_cookie_list_dtor(&list);
1115
1116 RETURN_STRINGL(str, len, 0);
1117 }
1118 /* }}} */
1119
1120 /* {{{ proto object http_parse_params(string param[, int flags = HTTP_PARAMS_DEFAULT])
1121 *
1122 * Parse parameter list.
1123 */
1124 PHP_FUNCTION(http_parse_params)
1125 {
1126 char *param;
1127 int param_len;
1128 zval *params;
1129 long flags = HTTP_PARAMS_DEFAULT;
1130
1131 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &param, &param_len, &flags)) {
1132 RETURN_FALSE;
1133 }
1134
1135 params = ecalloc(1, sizeof(zval));
1136 array_init(params);
1137 if (SUCCESS != http_parse_params(param, flags, Z_ARRVAL_P(params))) {
1138 zval_dtor(params);
1139 FREE_ZVAL(params);
1140 RETURN_FALSE;
1141 }
1142 object_init(return_value);
1143 add_property_zval(return_value, "params", params);
1144 }
1145 /* }}} */
1146
1147 /* {{{ proto array http_get_request_headers(void)
1148 *
1149 * Get a list of incoming HTTP headers.
1150 *
1151 * Returns an associative array of incoming request headers.
1152 */
1153 PHP_FUNCTION(http_get_request_headers)
1154 {
1155 NO_ARGS;
1156
1157 array_init(return_value);
1158 http_get_request_headers(Z_ARRVAL_P(return_value));
1159 }
1160 /* }}} */
1161
1162 /* {{{ proto string http_get_request_body(void)
1163 *
1164 * Get the raw request body (e.g. POST or PUT data).
1165 *
1166 * This function can not be used after http_get_request_body_stream()
1167 * if the request method was another than POST.
1168 *
1169 * Returns the raw request body as string on success or NULL on failure.
1170 */
1171 PHP_FUNCTION(http_get_request_body)
1172 {
1173 char *body;
1174 size_t length;
1175
1176 NO_ARGS;
1177
1178 if (SUCCESS == http_get_request_body(&body, &length)) {
1179 RETURN_STRINGL(body, (int) length, 0);
1180 } else {
1181 RETURN_NULL();
1182 }
1183 }
1184 /* }}} */
1185
1186 /* {{{ proto resource http_get_request_body_stream(void)
1187 *
1188 * Create a stream to read the raw request body (e.g. POST or PUT data).
1189 *
1190 * This function can only be used once if the request method was another than POST.
1191 *
1192 * Returns the raw request body as stream on success or NULL on failure.
1193 */
1194 PHP_FUNCTION(http_get_request_body_stream)
1195 {
1196 php_stream *s;
1197
1198 NO_ARGS;
1199
1200 if ((s = http_get_request_body_stream())) {
1201 php_stream_to_zval(s, return_value);
1202 } else {
1203 http_error(HE_WARNING, HTTP_E_RUNTIME, "Failed to create request body stream");
1204 RETURN_NULL();
1205 }
1206 }
1207 /* }}} */
1208
1209 /* {{{ proto bool http_match_request_header(string header, string value[, bool match_case = false])
1210 *
1211 * Match an incoming HTTP header.
1212 *
1213 * Expects two string parameters representing the header name (case-insensitive)
1214 * and the header value that should be compared. The case sensitivity of the
1215 * header value depends on the additional optional bool parameter accepted.
1216 *
1217 * Returns TRUE if header value matches, else FALSE.
1218 */
1219 PHP_FUNCTION(http_match_request_header)
1220 {
1221 char *header, *value;
1222 int header_len, value_len;
1223 zend_bool match_case = 0;
1224
1225 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &header, &header_len, &value, &value_len, &match_case)) {
1226 RETURN_FALSE;
1227 }
1228
1229 RETURN_BOOL(http_match_request_header_ex(header, value, match_case));
1230 }
1231 /* }}} */
1232
1233 /* {{{ HAVE_CURL */
1234 #ifdef HTTP_HAVE_CURL
1235
1236 #define RETVAL_RESPONSE_OR_BODY(request) \
1237 { \
1238 zval **bodyonly; \
1239 \
1240 /* check if only the body should be returned */ \
1241 if (options && (SUCCESS == zend_hash_find(Z_ARRVAL_P(options), "bodyonly", sizeof("bodyonly"), (void *) &bodyonly)) && zval_is_true(*bodyonly)) { \
1242 http_message *msg = http_message_parse(PHPSTR_VAL(&request.conv.response), PHPSTR_LEN(&request.conv.response)); \
1243 \
1244 if (msg) { \
1245 RETVAL_STRINGL(PHPSTR_VAL(&msg->body), PHPSTR_LEN(&msg->body), 1); \
1246 http_message_free(&msg); \
1247 } \
1248 } else { \
1249 RETVAL_STRINGL(request.conv.response.data, request.conv.response.used, 1); \
1250 } \
1251 }
1252
1253 /* {{{ proto string http_get(string url[, array options[, array &info]])
1254 *
1255 * Performs an HTTP GET request on the supplied url.
1256 *
1257 * The second parameter, if set, is expected to be an associative
1258 * array where the following keys will be recognized:
1259 * <pre>
1260 * - redirect: int, whether and how many redirects to follow
1261 * - unrestrictedauth: bool, whether to continue sending credentials on
1262 * redirects to a different host
1263 * - proxyhost: string, proxy host in "host[:port]" format
1264 * - proxyport: int, use another proxy port as specified in proxyhost
1265 * - proxytype: int, HTTP_PROXY_HTTP, SOCKS4 or SOCKS5
1266 * - proxyauth: string, proxy credentials in "user:pass" format
1267 * - proxyauthtype: int, HTTP_AUTH_BASIC and/or HTTP_AUTH_NTLM
1268 * - httpauth: string, http credentials in "user:pass" format
1269 * - httpauthtype: int, HTTP_AUTH_BASIC, DIGEST and/or NTLM
1270 * - compress: bool, whether to allow gzip/deflate content encoding
1271 * - port: int, use another port as specified in the url
1272 * - referer: string, the referer to send
1273 * - useragent: string, the user agent to send
1274 * (defaults to PECL::HTTP/version (PHP/version)))
1275 * - headers: array, list of custom headers as associative array
1276 * like array("header" => "value")
1277 * - cookies: array, list of cookies as associative array
1278 * like array("cookie" => "value")
1279 * - encodecookies: bool, whether to urlencode the cookies (default: true)
1280 * - cookiestore: string, path to a file where cookies are/will be stored
1281 * - cookiesession: bool, don't load session cookies from cookiestore if TRUE
1282 * - resume: int, byte offset to start the download from;
1283 * if the server supports ranges
1284 * - range: array, array of arrays, each containing two integers,
1285 * specifying the ranges to download if server support is
1286 * given; only recognized if the resume option is empty
1287 * - maxfilesize: int, maximum file size that should be downloaded;
1288 * has no effect, if the size of the requested entity is not known
1289 * - lastmodified: int, timestamp for If-(Un)Modified-Since header
1290 * - etag: string, quoted etag for If-(None-)Match header
1291 * - timeout: int, seconds the request may take
1292 * - connecttimeout: int, seconds the connect may take
1293 * - onprogress: mixed, progress callback
1294 * - interface: string, outgoing network interface (ifname, ip or hostname)
1295 * - portrange: array, 2 integers specifying outgoing portrange to try
1296 * - ssl: array, with the following options:
1297 * cert: string, path to certificate
1298 * certtype: string, type of certificate
1299 * certpasswd: string, password for certificate
1300 * key: string, path to key
1301 * keytype: string, type of key
1302 * keypasswd: string, pasword for key
1303 * engine: string, ssl engine to use
1304 * version: int, ssl version to use
1305 * verifypeer: bool, whether to verify the peer
1306 * verifyhost: bool whether to verify the host
1307 * cipher_list: string, list of allowed ciphers
1308 * cainfo: string
1309 * capath: string
1310 * random_file: string
1311 * egdsocket: string
1312 * </pre>
1313 *
1314 * The optional third parameter will be filled with some additional information
1315 * in form of an associative array, if supplied, like the following example:
1316 * <pre>
1317 * <?php
1318 * array (
1319 * 'effective_url' => 'http://www.example.com/',
1320 * 'response_code' => 302,
1321 * 'connect_code' => 0,
1322 * 'filetime' => -1,
1323 * 'total_time' => 0.212348,
1324 * 'namelookup_time' => 0.038296,
1325 * 'connect_time' => 0.104144,
1326 * 'pretransfer_time' => 0.104307,
1327 * 'starttransfer_time' => 0.212077,
1328 * 'redirect_time' => 0,
1329 * 'redirect_count' => 0,
1330 * 'size_upload' => 0,
1331 * 'size_download' => 218,
1332 * 'speed_download' => 1026,
1333 * 'speed_upload' => 0,
1334 * 'header_size' => 307,
1335 * 'request_size' => 103,
1336 * 'ssl_verifyresult' => 0,
1337 * 'ssl_engines' =>
1338 * array (
1339 * 0 => 'dynamic',
1340 * 1 => 'cswift',
1341 * 2 => 'chil',
1342 * 3 => 'atalla',
1343 * 4 => 'nuron',
1344 * 5 => 'ubsec',
1345 * 6 => 'aep',
1346 * 7 => 'sureware',
1347 * 8 => '4758cca',
1348 * ),
1349 * 'content_length_download' => 218,
1350 * 'content_length_upload' => 0,
1351 * 'content_type' => 'text/html',
1352 * 'httpauth_avail' => 0,
1353 * 'proxyauth_avail' => 0,
1354 * 'num_connects' => 1,
1355 * 'os_errno' => 0,
1356 * 'error' => '',
1357 * )
1358 * ?>
1359 * </pre>
1360 *
1361 * Returns the HTTP response(s) as string on success, or FALSE on failure.
1362 */
1363 PHP_FUNCTION(http_get)
1364 {
1365 zval *options = NULL, *info = NULL;
1366 char *URL;
1367 int URL_len;
1368 http_request request;
1369
1370 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a/!z", &URL, &URL_len, &options, &info) != SUCCESS) {
1371 RETURN_FALSE;
1372 }
1373
1374 if (info) {
1375 zval_dtor(info);
1376 array_init(info);
1377 }
1378
1379 RETVAL_FALSE;
1380
1381 http_request_init_ex(&request, NULL, HTTP_GET, URL);
1382 if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
1383 http_request_exec(&request);
1384 if (info) {
1385 http_request_info(&request, Z_ARRVAL_P(info));
1386 }
1387 RETVAL_RESPONSE_OR_BODY(request);
1388 }
1389 http_request_dtor(&request);
1390 }
1391 /* }}} */
1392
1393 /* {{{ proto string http_head(string url[, array options[, array &info]])
1394 *
1395 * Performs an HTTP HEAD request on the supplied url.
1396 *
1397 * See http_get() for a full list of available parameters and options.
1398 *
1399 * Returns the HTTP response as string on success, or FALSE on failure.
1400 */
1401 PHP_FUNCTION(http_head)
1402 {
1403 zval *options = NULL, *info = NULL;
1404 char *URL;
1405 int URL_len;
1406 http_request request;
1407
1408 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a/!z", &URL, &URL_len, &options, &info) != SUCCESS) {
1409 RETURN_FALSE;
1410 }
1411
1412 if (info) {
1413 zval_dtor(info);
1414 array_init(info);
1415 }
1416
1417 RETVAL_FALSE;
1418
1419 http_request_init_ex(&request, NULL, HTTP_HEAD, URL);
1420 if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
1421 http_request_exec(&request);
1422 if (info) {
1423 http_request_info(&request, Z_ARRVAL_P(info));
1424 }
1425 RETVAL_RESPONSE_OR_BODY(request);
1426 }
1427 http_request_dtor(&request);
1428 }
1429 /* }}} */
1430
1431 /* {{{ proto string http_post_data(string url, string data[, array options[, array &info]])
1432 *
1433 * Performs an HTTP POST request on the supplied url.
1434 *
1435 * Expects a string as second parameter containing the pre-encoded post data.
1436 * See http_get() for a full list of available parameters and options.
1437 *
1438 * Returns the HTTP response(s) as string on success, or FALSE on failure.
1439 */
1440 PHP_FUNCTION(http_post_data)
1441 {
1442 zval *options = NULL, *info = NULL;
1443 char *URL, *postdata;
1444 int postdata_len, URL_len;
1445 http_request_body body;
1446 http_request request;
1447
1448 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a/!z", &URL, &URL_len, &postdata, &postdata_len, &options, &info) != SUCCESS) {
1449 RETURN_FALSE;
1450 }
1451
1452 if (info) {
1453 zval_dtor(info);
1454 array_init(info);
1455 }
1456
1457 RETVAL_FALSE;
1458
1459 http_request_init_ex(&request, NULL, HTTP_POST, URL);
1460 request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_CSTRING, postdata, postdata_len, 0);
1461 if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
1462 http_request_exec(&request);
1463 if (info) {
1464 http_request_info(&request, Z_ARRVAL_P(info));
1465 }
1466 RETVAL_RESPONSE_OR_BODY(request);
1467 }
1468 http_request_dtor(&request);
1469 }
1470 /* }}} */
1471
1472 /* {{{ proto string http_post_fields(string url, array data[, array files[, array options[, array &info]]])
1473 *
1474 * Performs an HTTP POST request on the supplied url.
1475 *
1476 * Expects an associative array as second parameter, which will be
1477 * www-form-urlencoded. See http_get() for a full list of available options.
1478 *
1479 * Returns the HTTP response(s) as string on success, or FALSE on failure.
1480 */
1481 PHP_FUNCTION(http_post_fields)
1482 {
1483 zval *options = NULL, *info = NULL, *fields = NULL, *files = NULL;
1484 char *URL;
1485 int URL_len;
1486 http_request_body body;
1487 http_request request;
1488
1489 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa!|a!a/!z", &URL, &URL_len, &fields, &files, &options, &info) != SUCCESS) {
1490 RETURN_FALSE;
1491 }
1492
1493 if (!http_request_body_fill(&body, fields ? Z_ARRVAL_P(fields) : NULL, files ? Z_ARRVAL_P(files) : NULL)) {
1494 RETURN_FALSE;
1495 }
1496
1497 if (info) {
1498 zval_dtor(info);
1499 array_init(info);
1500 }
1501
1502 RETVAL_FALSE;
1503
1504 http_request_init_ex(&request, NULL, HTTP_POST, URL);
1505 request.body = &body;
1506 if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
1507 http_request_exec(&request);
1508 if (info) {
1509 http_request_info(&request, Z_ARRVAL_P(info));
1510 }
1511 RETVAL_RESPONSE_OR_BODY(request);
1512 }
1513 http_request_dtor(&request);
1514 }
1515 /* }}} */
1516
1517 /* {{{ proto string http_put_file(string url, string file[, array options[, array &info]])
1518 *
1519 * Performs an HTTP PUT request on the supplied url.
1520 *
1521 * Expects the second parameter to be a string referencing the file to upload.
1522 * See http_get() for a full list of available options.
1523 *
1524 * Returns the HTTP response(s) as string on success, or FALSE on failure.
1525 */
1526 PHP_FUNCTION(http_put_file)
1527 {
1528 char *URL, *file;
1529 int URL_len, f_len;
1530 zval *options = NULL, *info = NULL;
1531 php_stream *stream;
1532 php_stream_statbuf ssb;
1533 http_request_body body;
1534 http_request request;
1535
1536 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a/!z", &URL, &URL_len, &file, &f_len, &options, &info)) {
1537 RETURN_FALSE;
1538 }
1539
1540 if (!(stream = php_stream_open_wrapper_ex(file, "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL, HTTP_DEFAULT_STREAM_CONTEXT))) {
1541 RETURN_FALSE;
1542 }
1543 if (php_stream_stat(stream, &ssb)) {
1544 php_stream_close(stream);
1545 RETURN_FALSE;
1546 }
1547
1548 if (info) {
1549 zval_dtor(info);
1550 array_init(info);
1551 }
1552
1553 RETVAL_FALSE;
1554
1555 http_request_init_ex(&request, NULL, HTTP_PUT, URL);
1556 request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_UPLOADFILE, stream, ssb.sb.st_size, 1);
1557 if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
1558 http_request_exec(&request);
1559 if (info) {
1560 http_request_info(&request, Z_ARRVAL_P(info));
1561 }
1562 RETVAL_RESPONSE_OR_BODY(request);
1563 }
1564 http_request_dtor(&request);
1565 }
1566 /* }}} */
1567
1568 /* {{{ proto string http_put_stream(string url, resource stream[, array options[, array &info]])
1569 *
1570 * Performs an HTTP PUT request on the supplied url.
1571 *
1572 * Expects the second parameter to be a resource referencing an already
1573 * opened stream, from which the data to upload should be read.
1574 * See http_get() for a full list of available options.
1575 *
1576 * Returns the HTTP response(s) as string on success, or FALSE on failure.
1577 */
1578 PHP_FUNCTION(http_put_stream)
1579 {
1580 zval *resource, *options = NULL, *info = NULL;
1581 char *URL;
1582 int URL_len;
1583 php_stream *stream;
1584 php_stream_statbuf ssb;
1585 http_request_body body;
1586 http_request request;
1587
1588 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sr|a/!z", &URL, &URL_len, &resource, &options, &info)) {
1589 RETURN_FALSE;
1590 }
1591
1592 php_stream_from_zval(stream, &resource);
1593 if (php_stream_stat(stream, &ssb)) {
1594 RETURN_FALSE;
1595 }
1596
1597 if (info) {
1598 zval_dtor(info);
1599 array_init(info);
1600 }
1601
1602 RETVAL_FALSE;
1603
1604 http_request_init_ex(&request, NULL, HTTP_PUT, URL);
1605 request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_UPLOADFILE, stream, ssb.sb.st_size, 0);
1606 if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
1607 http_request_exec(&request);
1608 if (info) {
1609 http_request_info(&request, Z_ARRVAL_P(info));
1610 }
1611 RETVAL_RESPONSE_OR_BODY(request);
1612 }
1613 http_request_dtor(&request);
1614 }
1615 /* }}} */
1616
1617 /* {{{ proto string http_put_data(string url, string data[, array options[, array &info]])
1618 *
1619 * Performs an HTTP PUT request on the supplied url.
1620 *
1621 * Expects the second parameter to be a string containing the data to upload.
1622 * See http_get() for a full list of available options.
1623 *
1624 * Returns the HTTP response(s) as string on success, or FALSE on failure.
1625 */
1626 PHP_FUNCTION(http_put_data)
1627 {
1628 char *URL, *data;
1629 int URL_len, data_len;
1630 zval *options = NULL, *info = NULL;
1631 http_request_body body;
1632 http_request request;
1633
1634 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a/!z", &URL, &URL_len, &data, &data_len, &options, &info)) {
1635 RETURN_FALSE;
1636 }
1637
1638 if (info) {
1639 zval_dtor(info);
1640 array_init(info);
1641 }
1642
1643 RETVAL_FALSE;
1644
1645 http_request_init_ex(&request, NULL, HTTP_PUT, URL);
1646 request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_CSTRING, data, data_len, 0);
1647 if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
1648 http_request_exec(&request);
1649 if (info) {
1650 http_request_info(&request, Z_ARRVAL_P(info));
1651 }
1652 RETVAL_RESPONSE_OR_BODY(request);
1653 }
1654 http_request_dtor(&request);
1655 }
1656 /* }}} */
1657
1658 /* {{{ proto string http_request(int method, string url[, string body[, array options[, array &info]]])
1659 *
1660 * Performs a custom HTTP request on the supplied url.
1661 *
1662 * Expects the first parameter to be an integer specifying the request method to use.
1663 * Accepts an optional third string parameter containing the raw request body.
1664 * See http_get() for a full list of available options.
1665 *
1666 * Returns the HTTP response(s) as string on success, or FALSE on failure.
1667 */
1668 PHP_FUNCTION(http_request)
1669 {
1670 long meth;
1671 char *URL, *data = NULL;
1672 int URL_len, data_len = 0;
1673 zval *options = NULL, *info = NULL;
1674 http_request_body body;
1675 http_request request;
1676
1677 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls|sa/!z", &meth, &URL, &URL_len, &data, &data_len, &options, &info)) {
1678 RETURN_FALSE;
1679 }
1680
1681 if (info) {
1682 zval_dtor(info);
1683 array_init(info);
1684 }
1685
1686 RETVAL_FALSE;
1687
1688 http_request_init_ex(&request, NULL, meth, URL);
1689 request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_CSTRING, data, data_len, 0);
1690 if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
1691 http_request_exec(&request);
1692 if (info) {
1693 http_request_info(&request, Z_ARRVAL_P(info));
1694 }
1695 RETVAL_RESPONSE_OR_BODY(request);
1696 }
1697 http_request_dtor(&request);
1698 }
1699 /* }}} */
1700
1701 /* {{{ proto string http_request_body_encode(array fields, array files)
1702 *
1703 * Generate x-www-form-urlencoded resp. form-data encoded request body.
1704 *
1705 * Returns encoded string on success, or FALSE on failure.
1706 */
1707 PHP_FUNCTION(http_request_body_encode)
1708 {
1709 zval *fields = NULL, *files = NULL;
1710 HashTable *fields_ht, *files_ht;
1711 http_request_body body;
1712 char *buf;
1713 size_t len;
1714
1715 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!a!", &fields, &files)) {
1716 RETURN_FALSE;
1717 }
1718
1719 fields_ht = (fields && Z_TYPE_P(fields) == IS_ARRAY) ? Z_ARRVAL_P(fields) : NULL;
1720 files_ht = (files && Z_TYPE_P(files) == IS_ARRAY) ? Z_ARRVAL_P(files) : NULL;
1721 if (http_request_body_fill(&body, fields_ht, files_ht) && (SUCCESS == http_request_body_encode(&body, &buf, &len))) {
1722 RETVAL_STRINGL(buf, len, 0);
1723 } else {
1724 http_error(HE_WARNING, HTTP_E_RUNTIME, "Could not encode request body");
1725 RETVAL_FALSE;
1726 }
1727 http_request_body_dtor(&body);
1728 }
1729 #endif /* HTTP_HAVE_CURL */
1730 /* }}} HAVE_CURL */
1731
1732 /* {{{ proto int http_request_method_register(string method)
1733 *
1734 * Register a custom request method.
1735 *
1736 * Expects a string parameter containing the request method name to register.
1737 *
1738 * Returns the ID of the request method on success, or FALSE on failure.
1739 */
1740 PHP_FUNCTION(http_request_method_register)
1741 {
1742 char *method;
1743 int method_len;
1744 ulong existing;
1745
1746 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len)) {
1747 RETURN_FALSE;
1748 }
1749 if ((existing = http_request_method_exists(1, 0, method))) {
1750 RETURN_LONG((long) existing);
1751 }
1752
1753 RETVAL_LONG((long) http_request_method_register(method, method_len));
1754 }
1755 /* }}} */
1756
1757 /* {{{ proto bool http_request_method_unregister(mixed method)
1758 *
1759 * Unregister a previously registered custom request method.
1760 *
1761 * Expects either the request method name or ID.
1762 *
1763 * Returns TRUE on success, or FALSE on failure.
1764 */
1765 PHP_FUNCTION(http_request_method_unregister)
1766 {
1767 zval *method;
1768
1769 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &method)) {
1770 RETURN_FALSE;
1771 }
1772
1773 switch (Z_TYPE_P(method)) {
1774 case IS_OBJECT:
1775 convert_to_string(method);
1776 case IS_STRING:
1777 if (is_numeric_string(Z_STRVAL_P(method), Z_STRLEN_P(method), NULL, NULL, 1)) {
1778 convert_to_long(method);
1779 } else {
1780 int mn;
1781 if (!(mn = http_request_method_exists(1, 0, Z_STRVAL_P(method)))) {
1782 RETURN_FALSE;
1783 }
1784 zval_dtor(method);
1785 ZVAL_LONG(method, (long)mn);
1786 }
1787 case IS_LONG:
1788 RETURN_SUCCESS(http_request_method_unregister(Z_LVAL_P(method)));
1789 default:
1790 RETURN_FALSE;
1791 }
1792 }
1793 /* }}} */
1794
1795 /* {{{ proto int http_request_method_exists(mixed method)
1796 *
1797 * Check if a request method is registered (or available by default).
1798 *
1799 * Expects either the request method name or ID as parameter.
1800 *
1801 * Returns TRUE if the request method is known, else FALSE.
1802 */
1803 PHP_FUNCTION(http_request_method_exists)
1804 {
1805 if (return_value_used) {
1806 zval *method;
1807
1808 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &method)) {
1809 RETURN_FALSE;
1810 }
1811
1812 switch (Z_TYPE_P(method)) {
1813 case IS_OBJECT:
1814 convert_to_string(method);
1815 case IS_STRING:
1816 if (is_numeric_string(Z_STRVAL_P(method), Z_STRLEN_P(method), NULL, NULL, 1)) {
1817 convert_to_long(method);
1818 } else {
1819 RETURN_LONG((long) http_request_method_exists(1, 0, Z_STRVAL_P(method)));
1820 }
1821 case IS_LONG:
1822 RETURN_LONG((long) http_request_method_exists(0, (int) Z_LVAL_P(method), NULL));
1823 default:
1824 RETURN_FALSE;
1825 }
1826 }
1827 }
1828 /* }}} */
1829
1830 /* {{{ proto string http_request_method_name(int method)
1831 *
1832 * Get the literal string representation of a standard or registered request method.
1833 *
1834 * Expects the request method ID as parameter.
1835 *
1836 * Returns the request method name as string on success, or FALSE on failure.
1837 */
1838 PHP_FUNCTION(http_request_method_name)
1839 {
1840 if (return_value_used) {
1841 long method;
1842
1843 if ((SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &method)) || (method < 0)) {
1844 RETURN_FALSE;
1845 }
1846
1847 RETURN_STRING(estrdup(http_request_method_name((int) method)), 0);
1848 }
1849 }
1850 /* }}} */
1851
1852 /* {{{ */
1853 #ifdef HTTP_HAVE_ZLIB
1854
1855 /* {{{ proto string http_deflate(string data[, int flags = 0])
1856 *
1857 * Compress data with gzip, zlib AKA deflate or raw deflate encoding.
1858 *
1859 * Expects the first parameter to be a string containing the data that should
1860 * be encoded.
1861 *
1862 * Returns the encoded string on success, or NULL on failure.
1863 */
1864 PHP_FUNCTION(http_deflate)
1865 {
1866 char *data;
1867 int data_len;
1868 long flags = 0;
1869
1870 RETVAL_NULL();
1871
1872 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &flags)) {
1873 char *encoded;
1874 size_t encoded_len;
1875
1876 if (SUCCESS == http_encoding_deflate(flags, data, data_len, &encoded, &encoded_len)) {
1877 RETURN_STRINGL(encoded, (int) encoded_len, 0);
1878 }
1879 }
1880 }
1881 /* }}} */
1882
1883 /* {{{ proto string http_inflate(string data)
1884 *
1885 * Decompress data compressed with either gzip, deflate AKA zlib or raw
1886 * deflate encoding.
1887 *
1888 * Expects a string as parameter containing the compressed data.
1889 *
1890 * Returns the decoded string on success, or NULL on failure.
1891 */
1892 PHP_FUNCTION(http_inflate)
1893 {
1894 char *data;
1895 int data_len;
1896
1897 RETVAL_NULL();
1898
1899 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len)) {
1900 char *decoded;
1901 size_t decoded_len;
1902
1903 if (SUCCESS == http_encoding_inflate(data, data_len, &decoded, &decoded_len)) {
1904 RETURN_STRINGL(decoded, (int) decoded_len, 0);
1905 }
1906 }
1907 }
1908 /* }}} */
1909
1910 /* {{{ proto string ob_deflatehandler(string data, int mode)
1911 *
1912 * For use with ob_start(). The deflate output buffer handler can only be used once.
1913 * It conflicts with ob_gzhandler and zlib.output_compression as well and should
1914 * not be used after ext/mbstrings mb_output_handler and ext/sessions URL-Rewriter (AKA
1915 * session.use_trans_sid).
1916 */
1917 PHP_FUNCTION(ob_deflatehandler)
1918 {
1919 char *data;
1920 int data_len;
1921 long mode;
1922
1923 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &data, &data_len, &mode)) {
1924 RETURN_FALSE;
1925 }
1926
1927 http_ob_deflatehandler(data, data_len, &Z_STRVAL_P(return_value), (uint *) &Z_STRLEN_P(return_value), mode);
1928 Z_TYPE_P(return_value) = Z_STRVAL_P(return_value) ? IS_STRING : IS_NULL;
1929 }
1930 /* }}} */
1931
1932 /* {{{ proto string ob_inflatehandler(string data, int mode)
1933 *
1934 * For use with ob_start(). Same restrictions as with ob_deflatehandler apply.
1935 */
1936 PHP_FUNCTION(ob_inflatehandler)
1937 {
1938 char *data;
1939 int data_len;
1940 long mode;
1941
1942 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &data, &data_len, &mode)) {
1943 RETURN_FALSE;
1944 }
1945
1946 http_ob_inflatehandler(data, data_len, &Z_STRVAL_P(return_value), (uint *) &Z_STRLEN_P(return_value), mode);
1947 Z_TYPE_P(return_value) = Z_STRVAL_P(return_value) ? IS_STRING : IS_NULL;
1948 }
1949 /* }}} */
1950
1951 #endif /* HTTP_HAVE_ZLIB */
1952 /* }}} */
1953
1954 /* {{{ proto int http_support([int feature = 0])
1955 *
1956 * Check for feature that require external libraries.
1957 *
1958 * Accepts an optional in parameter specifying which feature to probe for.
1959 * If the parameter is 0 or omitted, the return value contains a bitmask of
1960 * all supported features that depend on external libraries.
1961 *
1962 * Available features to probe for are:
1963 * <ul>
1964 * <li> HTTP_SUPPORT: always set
1965 * <li> HTTP_SUPPORT_REQUESTS: whether ext/http was linked against libcurl,
1966 * and HTTP requests can be issued
1967 * <li> HTTP_SUPPORT_SSLREQUESTS: whether libcurl was linked against openssl,
1968 * and SSL requests can be issued
1969 * <li> HTTP_SUPPORT_ENCODINGS: whether ext/http was linked against zlib,
1970 * and compressed HTTP responses can be decoded
1971 * <li> HTTP_SUPPORT_MAGICMIME: whether ext/http was linked against libmagic,
1972 * and the HttpResponse::guessContentType() method is usable
1973 * </ul>
1974 *
1975 * Returns int, whether requested feature is supported, or a bitmask with
1976 * all supported features.
1977 */
1978 PHP_FUNCTION(http_support)
1979 {
1980 long feature = 0;
1981
1982 RETVAL_LONG(0L);
1983
1984 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &feature)) {
1985 RETVAL_LONG(http_support(feature));
1986 }
1987 }
1988 /* }}} */
1989
1990 PHP_FUNCTION(http_test)
1991 {
1992 }
1993
1994 /*
1995 * Local variables:
1996 * tab-width: 4
1997 * c-basic-offset: 4
1998 * End:
1999 * vim600: noet sw=4 ts=4 fdm=marker
2000 * vim<600: noet sw=4 ts=4
2001 */
2002