- http_request_defaults() already takes care of resetting curl options so check strin...
authorMichael Wallner <mike@php.net>
Fri, 6 Jan 2006 23:34:45 +0000 (23:34 +0000)
committerMichael Wallner <mike@php.net>
Fri, 6 Jan 2006 23:34:45 +0000 (23:34 +0000)
- move redirect constants and init to http_send_api
- register global version constants
- php_stream_open_wrapper already takes care of open_basedir on http_log()
- add HTTP_REDIRECT_AUTO being PHP default behaviour and make it default for http_redirect()
- fix tests

http.c
http_api.c
http_functions.c
http_headers_api.c
http_request_api.c
http_send_api.c
php_http_headers_api.h
php_http_send_api.h
tests/HttpRequest_007.phpt
tests/HttpRequest_008.phpt

diff --git a/http.c b/http.c
index fefdab17c1524283ef747e8dfbbb37e408217a8d..f5f66a7f846e599421edc7035669f15b3cd7dcb5 100644 (file)
--- a/http.c
+++ b/http.c
@@ -29,7 +29,7 @@
 #include "php_http_api.h"
 #include "php_http_send_api.h"
 #include "php_http_cache_api.h"
 #include "php_http_api.h"
 #include "php_http_send_api.h"
 #include "php_http_cache_api.h"
-#include "php_http_headers_api.h"
+#include "php_http_send_api.h"
 #include "php_http_message_api.h"
 #include "php_http_request_method_api.h"
 #ifdef HTTP_HAVE_CURL
 #include "php_http_message_api.h"
 #include "php_http_request_method_api.h"
 #ifdef HTTP_HAVE_CURL
@@ -235,7 +235,7 @@ PHP_MINIT_FUNCTION(http)
        REGISTER_INI_ENTRIES();
        
        if (    (SUCCESS != PHP_MINIT_CALL(http_support))       ||
        REGISTER_INI_ENTRIES();
        
        if (    (SUCCESS != PHP_MINIT_CALL(http_support))       ||
-                       (SUCCESS != PHP_MINIT_CALL(http_headers))       ||
+                       (SUCCESS != PHP_MINIT_CALL(http_send))          ||
 #ifdef HTTP_HAVE_CURL
                        (SUCCESS != PHP_MINIT_CALL(http_request))       ||
 #endif /* HTTP_HAVE_CURL */
 #ifdef HTTP_HAVE_CURL
                        (SUCCESS != PHP_MINIT_CALL(http_request))       ||
 #endif /* HTTP_HAVE_CURL */
index 6046052f1be597943442acb832b0109d00ea4b62..edd80aeec36cc3087b3facd79114da9cc7af7cd0 100644 (file)
@@ -206,9 +206,7 @@ void _http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC)
 {
        time_t now;
        struct tm nowtm;
 {
        time_t now;
        struct tm nowtm;
-       char datetime[128];
-       
-       HTTP_CHECK_OPEN_BASEDIR(file, return);
+       char datetime[20] = {0};
        
        time(&now);
        strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", php_localtime_r(&now, &nowtm));
        
        time(&now);
        strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", php_localtime_r(&now, &nowtm));
index 642f335b6827b12dc8267b2407cb29e5f5c50145..aae091d691a543c6846ea6a83d4c090cf34c073e 100644 (file)
@@ -643,6 +643,7 @@ PHP_FUNCTION(http_throttle)
  * The HTTP response code will be set according to status.
  * You can use one of the following constants for convenience:
  *  - HTTP_REDIRECT                    302 Found
  * The HTTP response code will be set according to status.
  * You can use one of the following constants for convenience:
  *  - HTTP_REDIRECT                    302 Found
+ *  - HTTP_REDIRECT_AUTO       303 See Other for POST, else 302 Found
  *  - HTTP_REDIRECT_PERM       301 Moved Permanently
  *  - HTTP_REDIRECT_POST       303 See Other
  *  - HTTP_REDIRECT_TEMP       307 Temporary Redirect
  *  - HTTP_REDIRECT_PERM       301 Moved Permanently
  *  - HTTP_REDIRECT_POST       303 See Other
  *  - HTTP_REDIRECT_TEMP       307 Temporary Redirect
@@ -665,7 +666,7 @@ PHP_FUNCTION(http_redirect)
        size_t query_len = 0;
        zend_bool session = 0, free_params = 0;
        zval *params = NULL;
        size_t query_len = 0;
        zend_bool session = 0, free_params = 0;
        zval *params = NULL;
-       long status = 302;
+       long status = 0;
        char *query = NULL, *url = NULL, *URI, *LOC, *RED = NULL;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sa!/bl", &url, &url_len, &params, &session, &status) != SUCCESS) {
        char *query = NULL, *url = NULL, *URI, *LOC, *RED = NULL;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sa!/bl", &url, &url_len, &params, &session, &status) != SUCCESS) {
index 0952ffbe32c0162b42aba7774408f86447549998..96110d337779e2441f56668f9ab0a9db92463aa7 100644 (file)
 #      define HTTP_DBG_NEG 0
 #endif
 
 #      define HTTP_DBG_NEG 0
 #endif
 
-/* {{{ */
-PHP_MINIT_FUNCTION(http_headers)
-{
-       HTTP_LONG_CONSTANT("HTTP_REDIRECT", HTTP_REDIRECT);
-       HTTP_LONG_CONSTANT("HTTP_REDIRECT_PERM", HTTP_REDIRECT_PERM);
-       HTTP_LONG_CONSTANT("HTTP_REDIRECT_POST", HTTP_REDIRECT_POST);
-       HTTP_LONG_CONSTANT("HTTP_REDIRECT_TEMP", HTTP_REDIRECT_TEMP);
-       
-       return SUCCESS;
-}
-/* }}} */
-
 /* {{{ static int http_sort_q(const void *, const void *) */
 static int http_sort_q(const void *a, const void *b TSRMLS_DC)
 {
 /* {{{ static int http_sort_q(const void *, const void *) */
 static int http_sort_q(const void *a, const void *b TSRMLS_DC)
 {
index 3786caf061eb14f459e062acc8d2ee03749dee52..8e7d0b0f3bf9a73443e4362d9cd23ef9a2bdd4ce 100644 (file)
@@ -88,6 +88,10 @@ PHP_MINIT_FUNCTION(http_request)
        HTTP_LONG_CONSTANT("HTTP_AUTH_DIGEST", CURLAUTH_DIGEST);
        HTTP_LONG_CONSTANT("HTTP_AUTH_NTLM", CURLAUTH_NTLM);
        HTTP_LONG_CONSTANT("HTTP_AUTH_ANY", CURLAUTH_ANY);
        HTTP_LONG_CONSTANT("HTTP_AUTH_DIGEST", CURLAUTH_DIGEST);
        HTTP_LONG_CONSTANT("HTTP_AUTH_NTLM", CURLAUTH_NTLM);
        HTTP_LONG_CONSTANT("HTTP_AUTH_ANY", CURLAUTH_ANY);
+       
+       HTTP_LONG_CONSTANT("HTTP_VERSION_NONE", CURL_HTTP_VERSION_NONE);
+       HTTP_LONG_CONSTANT("HTTP_VERSION_1_0", CURL_HTTP_VERSION_1_0);
+       HTTP_LONG_CONSTANT("HTTP_VERSION_1_1", CURL_HTTP_VERSION_1_1);
 
        return SUCCESS;
 }
 
        return SUCCESS;
 }
@@ -405,14 +409,17 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
 
        /* proxy */
        if ((zoption = http_request_option(request, options, "proxyhost", IS_STRING))) {
 
        /* proxy */
        if ((zoption = http_request_option(request, options, "proxyhost", IS_STRING))) {
-               HTTP_CURL_OPT(PROXY, (Z_STRLEN_P(zoption) ? Z_STRVAL_P(zoption) : NULL));
+               if (Z_STRLEN_P(zoption)) {
+                       HTTP_CURL_OPT(PROXY, Z_STRVAL_P(zoption));
+               }
+
                /* port */
                if ((zoption = http_request_option(request, options, "proxyport", IS_LONG))) {
                        HTTP_CURL_OPT(PROXYPORT, Z_LVAL_P(zoption));
                }
                /* user:pass */
                /* port */
                if ((zoption = http_request_option(request, options, "proxyport", IS_LONG))) {
                        HTTP_CURL_OPT(PROXYPORT, Z_LVAL_P(zoption));
                }
                /* user:pass */
-               if ((zoption = http_request_option(request, options, "proxyauth", IS_STRING))) {
-                       HTTP_CURL_OPT(PROXYUSERPWD, (Z_STRLEN_P(zoption) ? Z_STRVAL_P(zoption) : NULL));
+               if ((zoption = http_request_option(request, options, "proxyauth", IS_STRING)) && Z_STRLEN_P(zoption)) {
+                       HTTP_CURL_OPT(PROXYUSERPWD, Z_STRVAL_P(zoption));
                }
                /* auth method */
                if ((zoption = http_request_option(request, options, "proxyauthtype", IS_LONG))) {
                }
                /* auth method */
                if ((zoption = http_request_option(request, options, "proxyauthtype", IS_LONG))) {
@@ -431,8 +438,8 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
        }
 
        /* auth */
        }
 
        /* auth */
-       if ((zoption = http_request_option(request, options, "httpauth", IS_STRING))) {
-               HTTP_CURL_OPT(USERPWD, (Z_STRLEN_P(zoption) ? Z_STRVAL_P(zoption) : NULL));
+       if ((zoption = http_request_option(request, options, "httpauth", IS_STRING)) && Z_STRLEN_P(zoption)) {
+               HTTP_CURL_OPT(USERPWD, Z_STRVAL_P(zoption));
        }
        if ((zoption = http_request_option(request, options, "httpauthtype", IS_LONG))) {
                HTTP_CURL_OPT(HTTPAUTH, Z_LVAL_P(zoption));
        }
        if ((zoption = http_request_option(request, options, "httpauthtype", IS_LONG))) {
                HTTP_CURL_OPT(HTTPAUTH, Z_LVAL_P(zoption));
@@ -448,13 +455,13 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
        }
 
        /* referer */
        }
 
        /* referer */
-       if ((zoption = http_request_option(request, options, "referer", IS_STRING))) {
-               HTTP_CURL_OPT(REFERER, (Z_STRLEN_P(zoption) ? Z_STRVAL_P(zoption) : NULL));
+       if ((zoption = http_request_option(request, options, "referer", IS_STRING)) && Z_STRLEN_P(zoption)) {
+               HTTP_CURL_OPT(REFERER, Z_STRVAL_P(zoption));
        }
 
        /* useragent, default "PECL::HTTP/version (PHP/version)" */
        }
 
        /* useragent, default "PECL::HTTP/version (PHP/version)" */
-       if ((zoption = http_request_option(request, options, "useragent", IS_STRING))) {
-               HTTP_CURL_OPT(USERAGENT, (Z_STRLEN_P(zoption) ? Z_STRVAL_P(zoption) : NULL));
+       if ((zoption = http_request_option(request, options, "useragent", IS_STRING)) && Z_STRLEN_P(zoption)) {
+               HTTP_CURL_OPT(USERAGENT, Z_STRVAL_P(zoption));
        }
 
        /* additional headers, array('name' => 'value') */
        }
 
        /* additional headers, array('name' => 'value') */
@@ -498,8 +505,6 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
                                phpstr_fix(&request->_cache.cookies);
                                HTTP_CURL_OPT(COOKIE, request->_cache.cookies.data);
                        }
                                phpstr_fix(&request->_cache.cookies);
                                HTTP_CURL_OPT(COOKIE, request->_cache.cookies.data);
                        }
-               } else {
-                       HTTP_CURL_OPT(COOKIE, NULL);
                }
        }
 
                }
        }
 
index b7aafaacc2b0879028bf1a4e7041d1b42b189d34..fb25f40a8adb65fad443bc6ce50b39a9ee338178 100644 (file)
@@ -175,6 +175,19 @@ static inline void _http_send_response_finish(void **buffer TSRMLS_DC)
 }
 /* }}} */
 
 }
 /* }}} */
 
+/* {{{ */
+PHP_MINIT_FUNCTION(http_send)
+{
+       HTTP_LONG_CONSTANT("HTTP_REDIRECT", HTTP_REDIRECT);
+       HTTP_LONG_CONSTANT("HTTP_REDIRECT_AUTO", HTTP_REDIRECT_AUTO);
+       HTTP_LONG_CONSTANT("HTTP_REDIRECT_PERM", HTTP_REDIRECT_PERM);
+       HTTP_LONG_CONSTANT("HTTP_REDIRECT_POST", HTTP_REDIRECT_POST);
+       HTTP_LONG_CONSTANT("HTTP_REDIRECT_TEMP", HTTP_REDIRECT_TEMP);
+       
+       return SUCCESS;
+}
+/* }}} */
+
 
 /* {{{ STATUS http_send_header(char *, char *, zend_bool) */
 PHP_HTTP_API STATUS _http_send_header_ex(const char *name, size_t name_len, const char *value, size_t value_len, zend_bool replace, char **sent_header TSRMLS_DC)
 
 /* {{{ STATUS http_send_header(char *, char *, zend_bool) */
 PHP_HTTP_API STATUS _http_send_header_ex(const char *name, size_t name_len, const char *value, size_t value_len, zend_bool replace, char **sent_header TSRMLS_DC)
index 0251afd9beb79cc226ffcf6b49043cdc0260d926..799f4880cb2a6a5c5f670a4b036060ffc8e4f175 100644 (file)
 
 #include "php_http_info_api.h"
 
 
 #include "php_http_info_api.h"
 
-#define HTTP_REDIRECT          302L
-#define HTTP_REDIRECT_PERM     301L
-#define HTTP_REDIRECT_POST     303L
-#define HTTP_REDIRECT_TEMP     307L
-
 typedef enum {
        RANGE_OK,
        RANGE_NO,
        RANGE_ERR
 } http_range_status;
 
 typedef enum {
        RANGE_OK,
        RANGE_NO,
        RANGE_ERR
 } http_range_status;
 
-extern PHP_MINIT_FUNCTION(http_headers);
-
 #define http_parse_headers(h, a) _http_parse_headers_ex((h), Z_ARRVAL_P(a), 1, http_info_default_callback, NULL TSRMLS_CC)
 #define http_parse_headers_ex(h, ht, p) _http_parse_headers_ex((h), (ht), (p), http_info_default_callback, NULL TSRMLS_CC)
 #define http_parse_headers_cb(h, ht, p, f, d) _http_parse_headers_ex((h), (ht), (p), (f), (d) TSRMLS_CC)
 #define http_parse_headers(h, a) _http_parse_headers_ex((h), Z_ARRVAL_P(a), 1, http_info_default_callback, NULL TSRMLS_CC)
 #define http_parse_headers_ex(h, ht, p) _http_parse_headers_ex((h), (ht), (p), http_info_default_callback, NULL TSRMLS_CC)
 #define http_parse_headers_cb(h, ht, p, f, d) _http_parse_headers_ex((h), (ht), (p), (f), (d) TSRMLS_CC)
index 9abf1a5718086900e8cbda4cc5f71a9900baa35c..ff4e2c0d3c319bfc6b3939db17de871605853a7f 100644 (file)
@@ -20,6 +20,14 @@ typedef enum {
        SEND_RSRC
 } http_send_mode;
 
        SEND_RSRC
 } http_send_mode;
 
+#define HTTP_REDIRECT          302L
+#define HTTP_REDIRECT_AUTO       0L
+#define HTTP_REDIRECT_PERM     301L
+#define HTTP_REDIRECT_POST     303L
+#define HTTP_REDIRECT_TEMP     307L
+
+extern PHP_MINIT_FUNCTION(http_send);
+
 #define http_send_status(s) sapi_header_op(SAPI_HEADER_SET_STATUS, (void *) (s) TSRMLS_CC)
 #define http_send_header(n, v, r) _http_send_header_ex((n), strlen(n), (v), strlen(v), (r) TSRMLS_CC)
 #define http_send_header_ex(n, nl, v, vl, r, s) _http_send_header_ex((n), (nl), (v), (vl), (r), (s) TSRMLS_CC)
 #define http_send_status(s) sapi_header_op(SAPI_HEADER_SET_STATUS, (void *) (s) TSRMLS_CC)
 #define http_send_header(n, v, r) _http_send_header_ex((n), strlen(n), (v), strlen(v), (r) TSRMLS_CC)
 #define http_send_header_ex(n, nl, v, vl, r, s) _http_send_header_ex((n), (nl), (v), (vl), (r), (s) TSRMLS_CC)
index d8a7e666443b92b6fb2e916b62c074af3fd39426..cf651be9ffa4e842b3176b37587dd05456bef12c 100644 (file)
@@ -19,8 +19,8 @@ echo "Done\n";
 ?>
 --EXPECTF--
 %sTEST
 ?>
 --EXPECTF--
 %sTEST
-string(467) "PUT /.print_request.php HTTP/1.1
-User-Agent: PECL::HTTP/0.21.0dev (PHP/5.1.2-dev)
+string(%d) "PUT /.print_request.php HTTP/1.1
+User-Agent: %s
 Host: dev.iworks.at
 Accept: */*
 content-type: text/plain
 Host: dev.iworks.at
 Accept: */*
 content-type: text/plain
index bcb16ec3ecdd3ab976fb5260f81fdc896979f09f..a0125e815d71ee61c998c6a59a611833a542cb13 100644 (file)
@@ -21,7 +21,7 @@ echo "Done\n";
 --EXPECTF--
 %sTEST
 int(200)
 --EXPECTF--
 %sTEST
 int(200)
-string(189) "FOOBAR /.print_request.php HTTP/1.1
+string(%d) "FOOBAR /.print_request.php HTTP/1.1
 User-Agent: %s
 Host: dev.iworks.at
 Accept: */*
 User-Agent: %s
 Host: dev.iworks.at
 Accept: */*