From: Michael Wallner Date: Fri, 6 Jan 2006 23:34:45 +0000 (+0000) Subject: - http_request_defaults() already takes care of resetting curl options so check strin... X-Git-Tag: RELEASE_1_0_4~18 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=fa1a275e2b5e1b9dfb5bcbf97b51ef2b568e433c;p=m6w6%2Fext-http - http_request_defaults() already takes care of resetting curl options so check string length in the conditional where reasonable - 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 --- diff --git a/http.c b/http.c index fefdab1..f5f66a7 100644 --- 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_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 @@ -235,7 +235,7 @@ PHP_MINIT_FUNCTION(http) 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 */ diff --git a/http_api.c b/http_api.c index 6046052..edd80ae 100644 --- a/http_api.c +++ b/http_api.c @@ -206,9 +206,7 @@ void _http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC) { 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)); diff --git a/http_functions.c b/http_functions.c index 642f335..aae091d 100644 --- a/http_functions.c +++ b/http_functions.c @@ -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 + * - 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 @@ -665,7 +666,7 @@ PHP_FUNCTION(http_redirect) 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, ¶ms, &session, &status) != SUCCESS) { diff --git a/http_headers_api.c b/http_headers_api.c index 0952ffb..96110d3 100644 --- a/http_headers_api.c +++ b/http_headers_api.c @@ -28,18 +28,6 @@ # 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) { diff --git a/http_request_api.c b/http_request_api.c index 3786caf..8e7d0b0 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -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_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; } @@ -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))) { - 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 */ - 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))) { @@ -431,8 +438,8 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti } /* 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)); @@ -448,13 +455,13 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti } /* 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)" */ - 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') */ @@ -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); } - } else { - HTTP_CURL_OPT(COOKIE, NULL); } } diff --git a/http_send_api.c b/http_send_api.c index b7aafaa..fb25f40 100644 --- a/http_send_api.c +++ b/http_send_api.c @@ -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) diff --git a/php_http_headers_api.h b/php_http_headers_api.h index 0251afd..799f488 100644 --- a/php_http_headers_api.h +++ b/php_http_headers_api.h @@ -17,19 +17,12 @@ #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; -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) diff --git a/php_http_send_api.h b/php_http_send_api.h index 9abf1a5..ff4e2c0 100644 --- a/php_http_send_api.h +++ b/php_http_send_api.h @@ -20,6 +20,14 @@ typedef enum { 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) diff --git a/tests/HttpRequest_007.phpt b/tests/HttpRequest_007.phpt index d8a7e66..cf651be 100644 --- a/tests/HttpRequest_007.phpt +++ b/tests/HttpRequest_007.phpt @@ -19,8 +19,8 @@ echo "Done\n"; ?> --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 diff --git a/tests/HttpRequest_008.phpt b/tests/HttpRequest_008.phpt index bcb16ec..a0125e8 100644 --- a/tests/HttpRequest_008.phpt +++ b/tests/HttpRequest_008.phpt @@ -21,7 +21,7 @@ echo "Done\n"; --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: */*