- 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>
- * 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);
-
- http_split_response(zresponse, zheaders, zbody);
-
- array_init(return_value);
- add_index_zval(return_value, 0, zheaders);
- add_index_zval(return_value, 1, zbody);
-}
-/* }}} */
-
-/* {{{ HAVE_CURL */
-#if defined(HAVE_CURL) && 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 (don't forget to initialize it
- * with NULL or array()).
- */
-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);
- }