- smart_str_0(&qstr);
- }
-
- URI = http_absolute_uri(url, NULL);
- if (qstr.c) {
- snprintf(LOC, HTTP_URI_MAXLEN + strlen("Location: "), "Location: %s?%s", URI, qstr.c);
- sprintf(RED, "Redirecting to <a href=\"%s?%s\">%s?%s</a>.\n", URI, qstr.c, URI, qstr.c);
- efree(qstr.c);
- } else {
- snprintf(LOC, HTTP_URI_MAXLEN + strlen("Location: "), "Location: %s", URI);
- sprintf(RED, "Redirecting to <a href=\"%s\">%s</a>.\n", URI, URI);
- }
- efree(URI);
-
- if ((SUCCESS == http_send_header(LOC)) && (SUCCESS == http_send_status((permanent ? 301 : 302)))) {
- php_body_write(RED, strlen(RED) TSRMLS_CC);
- RETURN_TRUE;
- }
- RETURN_FALSE;
-}
-/* }}} */
-
-/* {{{ proto bool http_send_data(string data)
- *
- * Sends raw data with support for (multiple) range requests.
- *
- */
-PHP_FUNCTION(http_send_data)
-{
- zval *zdata;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zdata) != SUCCESS) {
- RETURN_FALSE;
- }
-
- convert_to_string_ex(&zdata);
- http_send_header("Accept-Ranges: bytes");
- RETURN_SUCCESS(http_send_data(zdata));
-}
-/* }}} */
-
-/* {{{ proto bool http_send_file(string file)
- *
- * Sends a file with support for (multiple) range requests.
- *
- */
-PHP_FUNCTION(http_send_file)
-{
- zval *zfile;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zfile) != SUCCESS) {
- RETURN_FALSE;
- }
-
- convert_to_string_ex(&zfile);
- http_send_header("Accept-Ranges: bytes");
- RETURN_SUCCESS(http_send_file(zfile));
-}
-/* }}} */
-
-/* {{{ proto bool http_send_stream(resource stream)
- *
- * Sends an already opened stream with support for (multiple) range requests.
- *
- */
-PHP_FUNCTION(http_send_stream)
-{
- zval *zstream;
- php_stream *file;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream) != SUCCESS) {
- RETURN_FALSE;
- }
-
- php_stream_from_zval(file, &zstream);
- http_send_header("Accept-Ranges: bytes");
- RETURN_SUCCESS(http_send_stream(file));
-}
-/* }}} */
-
-/* {{{ proto bool http_content_type([string content_type = 'application/x-octetstream'])
- *
- * Sets the content type.
- *
- */
-PHP_FUNCTION(http_content_type)
-{
- char *ct, *content_type;
- int ct_len = 0;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &ct, &ct_len) != SUCCESS) {
- RETURN_FALSE;
- }
-
- if (!ct_len) {
- RETURN_SUCCESS(http_send_header("Content-Type: application/x-octetstream"));
- }
-
- /* remember for multiple ranges */
- if (HTTP_G(ctype)) {
- efree(HTTP_G(ctype));
- }
- HTTP_G(ctype) = estrndup(ct, ct_len);
-
- content_type = (char *) emalloc(strlen("Content-Type: ") + ct_len + 1);
- sprintf(content_type, "Content-Type: %s", ct);
-
- RETVAL_BOOL(SUCCESS == http_send_header(content_type));
- efree(content_type);
-}
-/* }}} */
-
-/* {{{ proto bool http_content_disposition(string filename[, bool inline = false])
- *
- * Set the Content Disposition. The Content-Disposition header is very useful
- * if the data actually sent came from a file or something similar, that should
- * be "saved" by the client/user (i.e. by browsers "Save as..." popup window).
- *
- */
-PHP_FUNCTION(http_content_disposition)
-{
- char *filename, *header;
- int f_len;
- zend_bool send_inline = 0;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &filename, &f_len, &send_inline) != SUCCESS) {
- RETURN_FALSE;
- }
-
- if (send_inline) {
- header = (char *) emalloc(strlen("Content-Disposition: inline; filename=\"\"") + f_len + 1);
- sprintf(header, "Content-Disposition: inline; filename=\"%s\"", filename);
- } else {
- header = (char *) emalloc(strlen("Content-Disposition: attachment; filename=\"\"") + f_len + 1);
- sprintf(header, "Content-Disposition: attachment; filename=\"%s\"", filename);
- }
-
- RETVAL_BOOL(SUCCESS == http_send_header(header));
- efree(header);
-}
-/* }}} */
-
-/* {{{ proto string http_chunked_decode(string encoded)
- *
- * This function decodes a string that was HTTP-chunked encoded.
- * Returns false on failure.
- */
-PHP_FUNCTION(http_chunked_decode)
-{
- char *encoded = NULL, *decoded = NULL;
- int encoded_len = 0, decoded_len = 0;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &encoded, &encoded_len) != SUCCESS) {
- RETURN_FALSE;
- }
-
- if (SUCCESS == http_chunked_decode(encoded, encoded_len, &decoded, &decoded_len)) {
- RETURN_STRINGL(decoded, decoded_len, 0);
- } else {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-/* {{{ proto array http_split_response(string http_response)
- *
- * This function splits an HTTP response into an array with headers and the
- * content body. The returned array may look simliar to the following example:
- *
- * <pre>
- * <?php
- * array(
- * 0 => array(
- * 'Status' => '200 Ok',
- * 'Content-Type' => 'text/plain',
- * 'Content-Language' => 'en-US'
- * ),
- * 1 => "Hello World!"
- * );
- * ?>
- * </pre>
- */
-PHP_FUNCTION(http_split_response)
-{
- zval *zresponse, *zbody, *zheaders;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zresponse) != SUCCESS) {
- RETURN_FALSE;
- }
-
- convert_to_string_ex(&zresponse);
-
- MAKE_STD_ZVAL(zbody);
- MAKE_STD_ZVAL(zheaders);
- array_init(zheaders);
-
- if (SUCCESS != http_split_response(zresponse, zheaders, zbody)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse HTTP response");
- RETURN_FALSE;
- }
-
- array_init(return_value);
- add_index_zval(return_value, 0, zheaders);
- add_index_zval(return_value, 1, zbody);
-}
-/* }}} */
-
-/* {{{ proto array http_parse_headers(string header)
- *
- */
-PHP_FUNCTION(http_parse_headers)
-{
- char *header, *rnrn;
- int header_len;
-
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &header, &header_len)) {
- RETURN_FALSE;
- }
-
- array_init(return_value);
-
- if (rnrn = strstr(header, HTTP_CRLF HTTP_CRLF)) {
- header_len = rnrn - header + 2;
- }
- if (SUCCESS != http_parse_headers(header, header_len, return_value)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse HTTP header");
- zval_dtor(return_value);
- RETURN_FALSE;
- }
-}
-/* }}}*/
-
-/* {{{ proto array http_get_request_headers(void)
- *
- */
-PHP_FUNCTION(http_get_request_headers)
-{
- if (ZEND_NUM_ARGS()) {
- WRONG_PARAM_COUNT;
- }
-
- array_init(return_value);
- http_get_request_headers(return_value);
-}
-/* }}} */
-
-/* {{{ HAVE_CURL */
-#ifdef HTTP_HAVE_CURL
-
-/* {{{ proto string http_get(string url[, array options[, array &info]])
- *
- * Performs an HTTP GET request on the supplied url.
- *
- * The second parameter is expected to be an associative
- * array where the following keys will be recognized:
- * <pre>
- * - redirect: int, whether and how many redirects to follow
- * - unrestrictedauth: bool, whether to continue sending credentials on
- * redirects to a different host
- * - proxyhost: string, proxy host in "host[:port]" format
- * - proxyport: int, use another proxy port as specified in proxyhost
- * - proxyauth: string, proxy credentials in "user:pass" format
- * - proxyauthtype: int, HTTP_AUTH_BASIC and/or HTTP_AUTH_NTLM
- * - httpauth: string, http credentials in "user:pass" format
- * - httpauthtype: int, HTTP_AUTH_BASIC, DIGEST and/or NTLM
- * - compress: bool, whether to allow gzip/deflate content encoding
- * (defaults to true)
- * - port: int, use another port as specified in the url
- * - referer: string, the referer to sends
- * - useragent: string, the user agent to send
- * (defaults to PECL::HTTP/version (PHP/version)))
- * - headers: array, list of custom headers as associative array
- * like array("header" => "value")
- * - cookies: array, list of cookies as associative array
- * like array("cookie" => "value")
- * - cookiestore: string, path to a file where cookies are/will be stored
- * </pre>
- *
- * The optional third parameter will be filled with some additional information
- * in form af an associative array, if supplied, like the following example:
- * <pre>
- * <?php
- * array (
- * 'effective_url' => 'http://localhost',
- * 'response_code' => 403,
- * 'total_time' => 0.017,
- * 'namelookup_time' => 0.013,
- * 'connect_time' => 0.014,
- * 'pretransfer_time' => 0.014,
- * 'size_upload' => 0,
- * 'size_download' => 202,
- * 'speed_download' => 11882,
- * 'speed_upload' => 0,
- * 'header_size' => 145,
- * 'request_size' => 62,
- * 'ssl_verifyresult' => 0,
- * 'filetime' => -1,
- * 'content_length_download' => 202,
- * 'content_length_upload' => 0,
- * 'starttransfer_time' => 0.017,
- * 'content_type' => 'text/html; charset=iso-8859-1',
- * 'redirect_time' => 0,
- * 'redirect_count' => 0,
- * 'private' => '',
- * 'http_connectcode' => 0,
- * 'httpauth_avail' => 0,
- * 'proxyauth_avail' => 0,
- * )
- * ?>
- * </pre>
- */
-PHP_FUNCTION(http_get)
-{
- char *URL, *data = NULL;
- size_t data_len = 0;
- int URL_len;
- zval *options = NULL, *info = NULL;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a/!z", &URL, &URL_len, &options, &info) != SUCCESS) {
- RETURN_FALSE;
- }
-
- if (info) {
- zval_dtor(info);
- array_init(info);
- }
-
- if (SUCCESS == http_get(URL, HASH_ORNULL(options), HASH_ORNULL(info), &data, &data_len)) {
- RETURN_STRINGL(data, data_len, 0);
- } else {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-/* {{{ proto string http_head(string url[, array options[, array &info]])
- *
- * Performs an HTTP HEAD request on the suppied url.
- * Returns the HTTP response as string.
- * See http_get() for a full list of available options.
- */
-PHP_FUNCTION(http_head)
-{
- char *URL, *data = NULL;
- size_t data_len = 0;
- int URL_len;
- zval *options = NULL, *info = NULL;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a/!z", &URL, &URL_len, &options, &info) != SUCCESS) {
- RETURN_FALSE;
- }
-
- if (info) {
- zval_dtor(info);
- array_init(info);
- }
-
- if (SUCCESS == http_head(URL, HASH_ORNULL(options), HASH_ORNULL(info), &data, &data_len)) {
- RETURN_STRINGL(data, data_len, 0);
- } else {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-/* {{{ proto string http_post_data(string url, string data[, array options[, &info]])
- *
- * Performs an HTTP POST request, posting data.
- * Returns the HTTP response as string.
- * See http_get() for a full list of available options.
- */
-PHP_FUNCTION(http_post_data)
-{
- char *URL, *postdata, *data = NULL;
- size_t data_len = 0;
- int postdata_len, URL_len;
- zval *options = NULL, *info = NULL;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a/!z", &URL, &URL_len, &postdata, &postdata_len, &options, &info) != SUCCESS) {
- RETURN_FALSE;
- }
-
- if (info) {
- zval_dtor(info);
- array_init(info);
- }
-
- if (SUCCESS == http_post_data(URL, postdata, (size_t) postdata_len, HASH_ORNULL(options), HASH_ORNULL(info), &data, &data_len)) {
- RETURN_STRINGL(data, data_len, 0);
- } else {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-/* {{{ proto string http_post_array(string url, array data[, array options[, array &info]])
- *
- * Performs an HTTP POST request, posting www-form-urlencoded array data.
- * Returns the HTTP response as string.
- * See http_get() for a full list of available options.
- */
-PHP_FUNCTION(http_post_array)
-{
- char *URL, *data = NULL;
- size_t data_len = 0;
- int URL_len;
- zval *options = NULL, *info = NULL, *postdata;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa|a/!z", &URL, &URL_len, &postdata, &options, &info) != SUCCESS) {
- RETURN_FALSE;
- }
-
- if (info) {
- zval_dtor(info);
- array_init(info);
- }
-
- if (SUCCESS == http_post_array(URL, Z_ARRVAL_P(postdata), HASH_ORNULL(options), HASH_ORNULL(info), &data, &data_len)) {
- RETURN_STRINGL(data, data_len, 0);
- } else {
- RETURN_FALSE;