2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.0 of the PHP license, that |
6 | is bundled with this package in the file LICENSE, and is available |
7 | through the world-wide-web at http://www.php.net/license/3_0.txt. |
8 | If you did not receive a copy of the PHP license and are unable to |
9 | obtain it through the world-wide-web, please send a note to |
10 | license@php.net so we can mail you a copy immediately. |
11 +----------------------------------------------------------------------+
12 | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
13 +----------------------------------------------------------------------+
24 #include "ext/standard/info.h"
25 #include "ext/session/php_session.h"
26 #include "ext/standard/php_string.h"
27 #include "ext/standard/php_smart_str.h"
30 #include "php_http_api.h"
32 #if defined(HAVE_CURL) && HAVE_CURL
33 #include <curl/curl.h>
36 ZEND_DECLARE_MODULE_GLOBALS(http
)
38 #ifdef COMPILE_DL_HTTP
42 /* {{{ http_functions[] */
43 function_entry http_functions
[] = {
44 PHP_FE(http_date
, NULL
)
45 PHP_FE(http_absolute_uri
, NULL
)
46 PHP_FE(http_negotiate_language
, NULL
)
47 PHP_FE(http_negotiate_charset
, NULL
)
48 PHP_FE(http_redirect
, NULL
)
49 PHP_FE(http_send_status
, NULL
)
50 PHP_FE(http_send_last_modified
, NULL
)
51 PHP_FE(http_match_modified
, NULL
)
52 PHP_FE(http_match_etag
, NULL
)
53 PHP_FE(http_cache_last_modified
, NULL
)
54 PHP_FE(http_cache_etag
, NULL
)
55 PHP_FE(http_content_type
, NULL
)
56 PHP_FE(http_content_disposition
, NULL
)
57 PHP_FE(http_send_data
, NULL
)
58 PHP_FE(http_send_file
, NULL
)
59 PHP_FE(http_send_stream
, NULL
)
60 PHP_FE(http_chunked_decode
, NULL
)
61 PHP_FE(http_split_response
, NULL
)
62 #if defined(HAVE_CURL) && HAVE_CURL
63 PHP_FE(http_get
, NULL
)
64 PHP_FE(http_head
, NULL
)
65 PHP_FE(http_post_data
, NULL
)
66 PHP_FE(http_post_array
, NULL
)
68 PHP_FE(http_auth_basic
, NULL
)
69 PHP_FE(http_auth_basic_cb
, NULL
)
74 /* {{{ http_module_entry */
75 zend_module_entry http_module_entry
= {
76 #if ZEND_MODULE_API_NO >= 20010901
77 STANDARD_MODULE_HEADER
,
86 #if ZEND_MODULE_API_NO >= 20010901
89 STANDARD_MODULE_PROPERTIES
93 #define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v))
94 #define HASH_ORNULL(z) ((z) ? Z_ARRVAL_P(z) : NULL)
96 /* {{{ proto string http_date([int timestamp])
98 * This function returns a valid HTTP date regarding RFC 822/1123
99 * looking like: "Wed, 22 Dec 2004 11:34:47 GMT"
102 PHP_FUNCTION(http_date
)
106 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|l", &t
) != SUCCESS
) {
111 t
= (long) time(NULL
);
114 RETURN_STRING(http_date(t
), 0);
118 /* {{{ proto string http_absolute_uri(string url[, string proto])
120 * This function returns an absolute URI constructed from url.
121 * If the url is already abolute but a different proto was supplied,
122 * only the proto part of the URI will be updated. If url has no
123 * path specified, the path of the current REQUEST_URI will be taken.
124 * The host will be taken either from the Host HTTP header of the client
125 * the SERVER_NAME or just localhost if prior are not available.
129 * url = "page.php" => http://www.example.com/current/path/page.php
130 * url = "/page.php" => http://www.example.com/page.php
131 * url = "/page.php", proto = "https" => https://www.example.com/page.php
135 PHP_FUNCTION(http_absolute_uri
)
137 char *url
= NULL
, *proto
= NULL
;
138 int url_len
= 0, proto_len
= 0;
140 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|s", &url
, &url_len
, &proto
, &proto_len
) != SUCCESS
) {
144 RETURN_STRING(http_absolute_uri(url
, proto
), 0);
148 /* {{{ proto string http_negotiate_language(array supported[, string default = 'en-US'])
150 * This function negotiates the clients preferred language based on its
151 * Accept-Language HTTP header. It returns the negotiated language or
152 * the default language if none match.
154 * The qualifier is recognized and languages without qualifier are rated highest.
156 * The supported parameter is expected to be an array having
157 * the supported languages as array values.
171 * include './langs/'. http_negotiate_language($langs) .'.php';
176 PHP_FUNCTION(http_negotiate_language
)
182 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a|s", &supported
, &def
, &def_len
) != SUCCESS
) {
190 RETURN_STRING(http_negotiate_language(supported
, def
), 0);
194 /* {{{ proto string http_negotiate_charset(array supported[, string default = 'iso-8859-1'])
196 * This function negotiates the clients preferred charset based on its
197 * Accept-Charset HTTP header. It returns the negotiated charset or
198 * the default charset if none match.
200 * The qualifier is recognized and charset without qualifier are rated highest.
202 * The supported parameter is expected to be an array having
203 * the supported charsets as array values.
209 * 'iso-8859-1', // default
214 * $pref = http_negotiate_charset($charsets);
215 * if (!strcmp($pref, 'iso-8859-1')) {
216 * iconv_set_encoding('internal_encoding', 'iso-8859-1');
217 * iconv_set_encoding('output_encoding', $pref);
218 * ob_start('ob_iconv_handler');
223 PHP_FUNCTION(http_negotiate_charset
)
229 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a|s", &supported
, &def
, &def_len
) != SUCCESS
) {
237 RETURN_STRING(http_negotiate_charset(supported
, def
), 0);
241 /* {{{ proto bool http_send_status(int status)
243 * Send HTTP status code.
246 PHP_FUNCTION(http_send_status
)
250 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &status
) != SUCCESS
) {
253 if (status
< 100 || status
> 510) {
254 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Invalid HTTP status code (100-510): %d", status
);
258 RETURN_SUCCESS(http_send_status(status
));
262 /* {{{ proto bool http_send_last_modified([int timestamp])
264 * This converts the given timestamp to a valid HTTP date and
265 * sends it as "Last-Modified" HTTP header. If timestamp is
266 * omitted, current time is sent.
269 PHP_FUNCTION(http_send_last_modified
)
273 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|l", &t
) != SUCCESS
) {
278 t
= (long) time(NULL
);
281 RETURN_SUCCESS(http_send_last_modified(t
));
285 /* {{{ proto bool http_match_modified([int timestamp])
287 * Matches the given timestamp against the clients "If-Modified-Since" resp.
288 * "If-Unmodified-Since" HTTP headers.
291 PHP_FUNCTION(http_match_modified
)
295 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|l", &t
) != SUCCESS
) {
299 // current time if not supplied (senseless though)
301 t
= (long) time(NULL
);
304 RETURN_BOOL(http_modified_match("HTTP_IF_MODIFIED_SINCE", t
) || http_modified_match("HTTP_IF_UNMODIFIED_SINCE", t
));
308 /* {{{ proto bool http_match_etag(string etag)
310 * This matches the given ETag against the clients
311 * "If-Match" resp. "If-None-Match" HTTP headers.
314 PHP_FUNCTION(http_match_etag
)
319 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &etag
, &etag_len
) != SUCCESS
) {
323 RETURN_BOOL(http_etag_match("HTTP_IF_NONE_MATCH", etag
) || http_etag_match("HTTP_IF_MATCH", etag
));
327 /* {{{ proto bool http_cache_last_modified([int timestamp_or_expires]])
329 * If timestamp_or_exires is greater than 0, it is handled as timestamp
330 * and will be sent as date of last modification. If it is 0 or omitted,
331 * the current time will be sent as Last-Modified date. If it's negative,
332 * it is handled as expiration time in seconds, which means that if the
333 * requested last modification date is not between the calculated timespan,
334 * the Last-Modified header is updated and the actual body will be sent.
337 PHP_FUNCTION(http_cache_last_modified
)
339 long last_modified
= 0, send_modified
= 0, t
;
342 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|l", &last_modified
) != SUCCESS
) {
346 t
= (long) time(NULL
);
349 if (!last_modified
) {
350 /* does the client have? */
351 if (zlm
= http_get_server_var("HTTP_IF_MODIFIED_SINCE")) {
352 last_modified
= send_modified
= http_parse_date(Z_STRVAL_P(zlm
));
353 /* use current time */
355 last_modified
= send_modified
= t
;
357 /* negative value is supposed to be expiration time */
358 } else if (last_modified
< 0) {
361 /* send supplied time explicitly */
363 send_modified
= last_modified
;
366 http_send_header("Cache-Control: private, must-revalidate, max-age=0");
368 if (http_modified_match("HTTP_IF_MODIFIED_SINCE", last_modified
)) {
369 if (SUCCESS
== http_send_status(304)) {
372 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not send 304 Not Modified");
376 RETURN_SUCCESS(http_send_last_modified(send_modified
));
380 /* {{{ proto bool http_cache_etag([string etag])
382 * This function attempts to cache the HTTP body based on an ETag,
383 * either supplied or generated through calculation of the MD5
384 * checksum of the output (uses output buffering).
386 * If clients "If-None-Match" header matches the supplied/calculated
387 * ETag, the body is considered cached on the clients side and
388 * a "304 Not Modified" status code is issued.
391 PHP_FUNCTION(http_cache_etag
)
396 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s", &etag
, &etag_len
) != SUCCESS
) {
400 /* send remaining data to nirvana */
401 http_send_header("Connection: close");
402 http_send_header("Cache-Control: private, must-revalidate, max-age=0");
404 /* if no etag is given and we didn't already
405 * start ob_etaghandler -- start it
407 if (!HTTP_G(etag_started
) && !etag_len
) {
408 php_ob_set_internal_handler(_http_ob_etaghandler
, (uint
) 4096, "etag output handler", 0 TSRMLS_CC
);
409 HTTP_G(etag_started
) = 1;
410 RETURN_BOOL(php_start_ob_buffer_named("etag output handler", (uint
) 4096, 0 TSRMLS_CC
));
413 if (http_etag_match("HTTP_IF_NONE_MATCH", etag
)) {
414 if (SUCCESS
== http_send_status(304)) {
417 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not send 304 Not Modified");
422 RETURN_SUCCESS(http_send_etag(etag
, etag_len
));
426 /* {{{ proto void http_redirect([string url[, array params[, bool session,[ bool permanent]]]])
428 * Redirect to a given url.
429 * The supplied url will be expanded with http_absolute_uri(), the params array will
430 * be treated with http_build_query() and the session identification will be appended
431 * if session is true.
433 * Depending on permanent the redirection will be issued with a permanent
434 * ("301 Moved Permanently") or a temporary ("302 Found") redirection
438 PHP_FUNCTION(http_redirect
)
441 zend_bool session
= 0, permanent
= 0;
443 smart_str qstr
= {0};
444 char *url
, *URI
, LOC
[HTTP_URI_MAXLEN
+ 9];
446 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|sa!bb", &url
, &url_len
, ¶ms
, &session
, &permanent
) != SUCCESS
) {
450 /* append session info */
451 if (session
&& (PS(session_status
) == php_session_active
)) {
453 MAKE_STD_ZVAL(params
);
456 if (add_assoc_string(params
, PS(session_name
), PS(id
), 1) != SUCCESS
) {
457 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not append session information");
461 /* treat params array with http_build_query() */
463 if (php_url_encode_hash_ex(Z_ARRVAL_P(params
), &qstr
, NULL
,0,NULL
,0,NULL
,0,NULL TSRMLS_CC
) != SUCCESS
) {
467 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not encode query parameters");
473 URI
= http_absolute_uri(url
, NULL
);
475 snprintf(LOC
, HTTP_URI_MAXLEN
+ strlen("Location: "), "Location: %s?%s", URI
, qstr
.c
);
478 snprintf(LOC
, HTTP_URI_MAXLEN
+ strlen("Location: "), "Location: %s", URI
);
482 RETVAL_BOOL((SUCCESS
== http_send_header(LOC
)) && (SUCCESS
== http_send_status((permanent
? 301 : 302))));
486 /* {{{ proto bool http_send_data(string data)
488 * Sends raw data with support for (multiple) range requests.
491 PHP_FUNCTION(http_send_data
)
495 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z", &zdata
) != SUCCESS
) {
499 convert_to_string_ex(&zdata
);
500 http_send_header("Accept-Ranges: bytes");
501 RETURN_SUCCESS(http_send_data(zdata
));
505 /* {{{ proto bool http_send_file(string file)
507 * Sends a file with support for (multiple) range requests.
510 PHP_FUNCTION(http_send_file
)
514 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z", &zfile
) != SUCCESS
) {
518 convert_to_string_ex(&zfile
);
519 http_send_header("Accept-Ranges: bytes");
520 RETURN_SUCCESS(http_send_file(zfile
));
524 /* {{{ proto bool http_send_stream(resource stream)
526 * Sends an already opened stream with support for (multiple) range requests.
529 PHP_FUNCTION(http_send_stream
)
534 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "r", &zstream
) != SUCCESS
) {
538 php_stream_from_zval(file
, &zstream
);
539 http_send_header("Accept-Ranges: bytes");
540 RETURN_SUCCESS(http_send_stream(file
));
544 /* {{{ proto bool http_content_type([string content_type = 'application/x-octetstream'])
546 * Sets the content type.
549 PHP_FUNCTION(http_content_type
)
551 char *ct
, *content_type
;
554 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s", &ct
, &ct_len
) != SUCCESS
) {
559 RETURN_SUCCESS(http_send_header("Content-Type: application/x-octetstream"));
562 /* remember for multiple ranges */
564 efree(HTTP_G(ctype
));
566 HTTP_G(ctype
) = estrndup(ct
, ct_len
);
568 content_type
= (char *) emalloc(strlen("Content-Type: ") + ct_len
+ 1);
569 sprintf(content_type
, "Content-Type: %s", ct
);
571 RETVAL_BOOL(SUCCESS
== http_send_header(content_type
));
576 /* {{{ proto bool http_content_disposition(string filename[, bool inline = false])
578 * Set the Content Disposition. The Content-Disposition header is very useful
579 * if the data actually sent came from a file or something similar, that should
580 * be "saved" by the client/user (i.e. by browsers "Save as..." popup window).
583 PHP_FUNCTION(http_content_disposition
)
585 char *filename
, *header
;
587 zend_bool send_inline
= 0;
589 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|b", &filename
, &f_len
, &send_inline
) != SUCCESS
) {
594 header
= (char *) emalloc(strlen("Content-Disposition: inline; filename=\"\"") + f_len
+ 1);
595 sprintf(header
, "Content-Disposition: inline; filename=\"%s\"", filename
);
597 header
= (char *) emalloc(strlen("Content-Disposition: attachment; filename=\"\"") + f_len
+ 1);
598 sprintf(header
, "Content-Disposition: attachment; filename=\"%s\"", filename
);
601 RETVAL_BOOL(SUCCESS
== http_send_header(header
));
606 /* {{{ proto string http_chunked_decode(string encoded)
608 * This function decodes a string that was HTTP-chunked encoded.
609 * Returns false on failure.
611 PHP_FUNCTION(http_chunked_decode
)
613 char *encoded
= NULL
, *decoded
= NULL
;
614 int encoded_len
= 0, decoded_len
= 0;
616 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &encoded
, &encoded_len
) != SUCCESS
) {
620 if (SUCCESS
== http_chunked_decode(encoded
, encoded_len
, &decoded
, &decoded_len
)) {
621 RETURN_STRINGL(decoded
, decoded_len
, 0);
628 /* {{{ proto array http_split_response(string http_response)
630 * This function splits an HTTP response into an array with headers and the
631 * content body. The returned array may look simliar to the following example:
636 * 'Status' => '200 Ok',
637 * 'Content-Type' => 'text/plain',
638 * 'Content-Language' => 'en-US'
640 * 1 => "Hello World!"
644 PHP_FUNCTION(http_split_response
)
646 zval
*zresponse
, *zbody
, *zheaders
;
648 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z", &zresponse
) != SUCCESS
) {
652 convert_to_string_ex(&zresponse
);
654 MAKE_STD_ZVAL(zbody
);
655 MAKE_STD_ZVAL(zheaders
);
656 array_init(zheaders
);
658 http_split_response(zresponse
, zheaders
, zbody
);
660 array_init(return_value
);
661 add_index_zval(return_value
, 0, zheaders
);
662 add_index_zval(return_value
, 1, zbody
);
667 #if defined(HAVE_CURL) && HAVE_CURL
669 /* {{{ proto string http_get(string url[, array options[, array &info]])
671 * Performs an HTTP GET request on the supplied url.
673 * The second parameter is expected to be an associative
674 * array where the following keys will be recognized:
676 * - redirect: int, whether and how many redirects to follow
677 * - unrestrictedauth: bool, whether to continue sending credentials on
678 * redirects to a different host
679 * - proxyhost: string, proxy host in "host[:port]" format
680 * - proxyport: int, use another proxy port as specified in proxyhost
681 * - proxyauth: string, proxy credentials in "user:pass" format
682 * - proxyauthtype: int, HTTP_AUTH_BASIC and/or HTTP_AUTH_NTLM
683 * - httpauth: string, http credentials in "user:pass" format
684 * - httpauthtype: int, HTTP_AUTH_BASIC, DIGEST and/or NTLM
685 * - compress: bool, whether to allow gzip/deflate content encoding
687 * - port: int, use another port as specified in the url
688 * - referer: string, the referer to sends
689 * - useragent: string, the user agent to send
690 * (defaults to PECL::HTTP/version (PHP/version)))
691 * - headers: array, list of custom headers as associative array
692 * like array("header" => "value")
693 * - cookies: array, list of cookies as associative array
694 * like array("cookie" => "value")
695 * - cookiestore: string, path to a file where cookies are/will be stored
698 * The optional third parameter will be filled with some additional information
699 * in form af an associative array, if supplied (don't forget to initialize it
700 * with NULL or array()).
702 PHP_FUNCTION(http_get
)
704 char *URL
, *data
= NULL
;
707 zval
*options
= NULL
, *info
= NULL
;
709 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|a/!z", &URL
, &URL_len
, &options
, &info
) != SUCCESS
) {
718 if (SUCCESS
== http_get(URL
, HASH_ORNULL(options
), HASH_ORNULL(info
), &data
, &data_len
)) {
719 RETURN_STRINGL(data
, data_len
, 0);
726 /* {{{ proto string http_head(string url[, array options[, array &info]])
728 * Performs an HTTP HEAD request on the suppied url.
729 * Returns the HTTP response as string.
730 * See http_get() for a full list of available options.
732 PHP_FUNCTION(http_head
)
734 char *URL
, *data
= NULL
;
737 zval
*options
= NULL
, *info
= NULL
;
739 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|a/!z", &URL
, &URL_len
, &options
, &info
) != SUCCESS
) {
748 if (SUCCESS
== http_head(URL
, HASH_ORNULL(options
), HASH_ORNULL(info
), &data
, &data_len
)) {
749 RETURN_STRINGL(data
, data_len
, 0);
756 /* {{{ proto string http_post_data(string url, string data[, array options[, &info]])
758 * Performs an HTTP POST request, posting data.
759 * Returns the HTTP response as string.
760 * See http_get() for a full list of available options.
762 PHP_FUNCTION(http_post_data
)
764 char *URL
, *postdata
, *data
= NULL
;
766 int postdata_len
, URL_len
;
767 zval
*options
= NULL
, *info
= NULL
;
769 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "ss|a/!z", &URL
, &URL_len
, &postdata
, &postdata_len
, &options
, &info
) != SUCCESS
) {
778 if (SUCCESS
== http_post_data(URL
, postdata
, (size_t) postdata_len
, HASH_ORNULL(options
), HASH_ORNULL(info
), &data
, &data_len
)) {
779 RETURN_STRINGL(data
, data_len
, 0);
786 /* {{{ proto string http_post_array(string url, array data[, array options[, array &info]])
788 * Performs an HTTP POST request, posting www-form-urlencoded array data.
789 * Returns the HTTP response as string.
790 * See http_get() for a full list of available options.
792 PHP_FUNCTION(http_post_array
)
794 char *URL
, *data
= NULL
;
797 zval
*options
= NULL
, *info
= NULL
, *postdata
;
799 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "sa|a/!z", &URL
, &URL_len
, &postdata
, &options
, &info
) != SUCCESS
) {
808 if (SUCCESS
== http_post_array(URL
, Z_ARRVAL_P(postdata
), HASH_ORNULL(options
), HASH_ORNULL(info
), &data
, &data_len
)) {
809 RETURN_STRINGL(data
, data_len
, 0);
820 /* {{{ proto bool http_auth_basic(string user, string pass[, string realm = "Restricted"])
825 * if (!http_auth_basic('mike', 's3c|r3t')) {
826 * die('<h1>Authorization failed!</h1>');
831 PHP_FUNCTION(http_auth_basic
)
833 char *realm
= NULL
, *user
, *pass
, *suser
, *spass
;
834 int r_len
, u_len
, p_len
;
836 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "ss|s", &user
, &u_len
, &pass
, &p_len
, &realm
, &r_len
) != SUCCESS
) {
841 realm
= "Restricted";
844 if (SUCCESS
!= http_auth_credentials(&suser
, &spass
)) {
845 http_auth_header("Basic", realm
);
849 if (strcasecmp(suser
, user
)) {
850 http_auth_header("Basic", realm
);
854 if (strcmp(spass
, pass
)) {
855 http_auth_header("Basic", realm
);
863 /* {{{ proto bool http_auth_basic_cb(mixed callback[, string realm = "Restricted"])
868 * function auth_cb($user, $pass)
871 * $query = 'SELECT pass FROM users WHERE user='. $db->quoteSmart($user);
872 * if (strlen($realpass = $db->getOne($query)) {
873 * return $pass === $realpass;
878 * if (!http_auth_basic_cb('auth_cb')) {
879 * die('<h1>Authorization failed</h1>');
884 PHP_FUNCTION(http_auth_basic_cb
)
887 char *realm
= NULL
, *user
, *pass
;
890 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z|s", &cb
, &realm
, &r_len
) != SUCCESS
) {
895 realm
= "Restricted";
898 if (SUCCESS
!= http_auth_credentials(&user
, &pass
)) {
899 http_auth_header("Basic", realm
);
903 zval
*zparams
[2] = {NULL
, NULL
}, retval
;
906 MAKE_STD_ZVAL(zparams
[0]);
907 MAKE_STD_ZVAL(zparams
[1]);
908 ZVAL_STRING(zparams
[0], user
, 0);
909 ZVAL_STRING(zparams
[1], pass
, 0);
911 if (SUCCESS
== call_user_function(EG(function_table
), NULL
, cb
,
912 &retval
, 2, zparams TSRMLS_CC
)) {
913 result
= Z_LVAL(retval
);
922 http_auth_header("Basic", realm
);
931 /* {{{ php_http_init_globals(zend_http_globals *) */
932 static void php_http_init_globals(zend_http_globals
*http_globals
)
934 http_globals
->etag_started
= 0;
935 http_globals
->ctype
= NULL
;
936 #if defined(HAVE_CURL) && HAVE_CURL
937 http_globals
->curlbuf
.body
.data
= NULL
;
938 http_globals
->curlbuf
.body
.used
= 0;
939 http_globals
->curlbuf
.body
.free
= 0;
940 http_globals
->curlbuf
.hdrs
.data
= NULL
;
941 http_globals
->curlbuf
.hdrs
.used
= 0;
942 http_globals
->curlbuf
.hdrs
.free
= 0;
947 /* {{{ PHP_MINIT_FUNCTION */
948 PHP_MINIT_FUNCTION(http
)
950 ZEND_INIT_MODULE_GLOBALS(http
, php_http_init_globals
, NULL
);
951 #if defined(HAVE_CURL) && HAVE_CURL
952 REGISTER_LONG_CONSTANT("HTTP_AUTH_BASIC", CURLAUTH_BASIC
, CONST_CS
| CONST_PERSISTENT
);
953 REGISTER_LONG_CONSTANT("HTTP_AUTH_DIGEST", CURLAUTH_DIGEST
, CONST_CS
| CONST_PERSISTENT
);
954 REGISTER_LONG_CONSTANT("HTTP_AUTH_NTLM", CURLAUTH_NTLM
, CONST_CS
| CONST_PERSISTENT
);
960 /* {{{ PHP_RSHUTDOWN_FUNCTION */
961 PHP_RSHUTDOWN_FUNCTION(http
)
964 efree(HTTP_G(ctype
));
966 #if defined(HAVE_CURL) && HAVE_CURL
967 if (HTTP_G(curlbuf
).body
.data
) {
968 efree(HTTP_G(curlbuf
).body
.data
);
970 if (HTTP_G(curlbuf
).hdrs
.data
) {
971 efree(HTTP_G(curlbuf
).hdrs
.data
);
978 /* {{{ PHP_MINFO_FUNCTION */
979 PHP_MINFO_FUNCTION(http
)
981 php_info_print_table_start();
982 php_info_print_table_header(2, "Extended HTTP support", "enabled");
983 php_info_print_table_row(2, "Version:", PHP_EXT_HTTP_VERSION
);
984 php_info_print_table_row(2, "cURL convenience functions:",
985 #if defined(HAVE_CURL) && HAVE_CURL
991 php_info_print_table_end();
1000 * vim600: noet sw=4 ts=4 fdm=marker
1001 * vim<600: noet sw=4 ts=4