From e9221ae5b72d1add77a6874595bbd0b98d0446a0 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Sun, 6 Mar 2005 11:14:46 +0000 Subject: [PATCH] * tiny API adjustments * fixed new http_asolute_uri() --- http_api.c | 47 +++++++++++++++++++++++++++++++++-------------- http_functions.c | 6 +++--- php_http_api.h | 10 ++++++---- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/http_api.c b/http_api.c index 317e902..0e4e604 100644 --- a/http_api.c +++ b/http_api.c @@ -28,7 +28,6 @@ #include "php_version.h" #include "php_streams.h" #include "snprintf.h" -#include "spprintf.h" #include "ext/standard/md5.h" #include "ext/standard/url.h" #include "ext/standard/base64.h" @@ -909,6 +908,7 @@ PHP_HTTP_API char *_http_absolute_uri_ex( furl.user = purl->user; furl.pass = purl->pass; furl.path = purl->path; + furl.query = purl->query; furl.fragment = purl->fragment; if (proto) { @@ -982,14 +982,18 @@ PHP_HTTP_API char *_http_absolute_uri_ex( if (furl.path) { HTTP_URI_STRLCATL(URL, full_len, furl.path); - if (furl.query) { - HTTP_URI_STRLCATS(URL, full_len, "?"); - HTTP_URI_STRLCATL(URL, full_len, furl.query); - } - if (furl.fragment) { - HTTP_URI_STRLCATS(URL, full_len, "#"); - HTTP_URI_STRLCATL(URL, full_len, furl.fragment); - } + } else { + HTTP_URI_STRLCATS(URL, full_len, "/"); + } + + if (furl.query) { + HTTP_URI_STRLCATS(URL, full_len, "?"); + HTTP_URI_STRLCATL(URL, full_len, furl.query); + } + + if (furl.fragment) { + HTTP_URI_STRLCATS(URL, full_len, "#"); + HTTP_URI_STRLCATL(URL, full_len, furl.fragment); } if (scheme) { @@ -1460,12 +1464,13 @@ PHP_HTTP_API STATUS _http_split_response_ex(char *response, *body = estrndup(*body, *body_len - 1); } - return http_parse_headers(header, *body ? *body - header : response_len, headers); + return http_parse_headers_ex(header, *body ? *body - header : response_len, headers, 1); } /* }}} */ /* {{{ STATUS http_parse_headers(char *, long, zval *) */ -PHP_HTTP_API STATUS _http_parse_headers(char *header, int header_len, HashTable *headers TSRMLS_DC) +PHP_HTTP_API STATUS _http_parse_headers_ex(char *header, int header_len, + HashTable *headers, zend_bool prettify TSRMLS_DC) { char *colon = NULL, *line = NULL, *begin = header; zval array; @@ -1500,6 +1505,11 @@ PHP_HTTP_API STATUS _http_parse_headers(char *header, int header_len, HashTable /* skip empty key */ if (header != colon) { char *key = estrndup(header, colon - header); + + if (prettify) { + key = pretty_key(key, colon - header, 1, 1); + } + value_len += line - colon - 1; /* skip leading ws */ @@ -1533,17 +1543,26 @@ PHP_HTTP_API STATUS _http_parse_headers(char *header, int header_len, HashTable } /* }}} */ -/* {{{ void http_get_request_headers(zval *) */ -PHP_HTTP_API void _http_get_request_headers(zval *array TSRMLS_DC) +/* {{{ void http_get_request_headers_ex(HashTable *, zend_bool) */ +PHP_HTTP_API void _http_get_request_headers_ex(HashTable *headers, zend_bool prettify TSRMLS_DC) { char *key = NULL; long idx = 0; + zval array; + + Z_ARRVAL(array) = headers; FOREACH_HASH_KEY(HTTP_SERVER_VARS, key, idx) { if (key && !strncmp(key, "HTTP_", 5)) { zval **header; + + if (prettify) { + key = pretty_key(key + 5, strlen(key) - 5, 1, 1); + } + zend_hash_get_current_data(HTTP_SERVER_VARS, (void **) &header); - add_assoc_stringl(array, pretty_key(key + 5, strlen(key) - 5, 1, 1), Z_STRVAL_PP(header), Z_STRLEN_PP(header), 1); + add_assoc_stringl(&array, key, Z_STRVAL_PP(header), Z_STRLEN_PP(header), 1); + key = NULL; } } } diff --git a/http_functions.c b/http_functions.c index 3ed49b2..f4d32b2 100644 --- a/http_functions.c +++ b/http_functions.c @@ -469,7 +469,7 @@ PHP_FUNCTION(http_redirect) } URI = http_absolute_uri(url); - + if (query_len) { snprintf(LOC, HTTP_URI_MAXLEN + sizeof("Location: "), "Location: %s?%s", URI, query); sprintf(RED, "Redirecting to %s?%s.\n", URI, query, URI, query); @@ -632,8 +632,8 @@ PHP_FUNCTION(http_parse_headers) if (rnrn = strstr(header, HTTP_CRLF HTTP_CRLF)) { header_len = rnrn - header + 2; } - if (SUCCESS != http_parse_headers(header, header_len, Z_ARRVAL_P(return_value))) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse HTTP header"); + if (SUCCESS != http_parse_headers(header, header_len, return_value)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse HTTP headers"); zval_dtor(return_value); RETURN_FALSE; } diff --git a/php_http_api.h b/php_http_api.h index 22f11d2..550f1d4 100644 --- a/php_http_api.h +++ b/php_http_api.h @@ -135,11 +135,13 @@ PHP_HTTP_API STATUS _http_urlencode_hash_ex(HashTable *hash, int override_argsep #define http_split_response_ex(r, rl, h, b, bl) _http_split_response_ex((r), (rl), (h), (b), (bl) TSRMLS_CC) PHP_HTTP_API STATUS _http_split_response_ex(char *response, size_t repsonse_len, HashTable *headers, char **body, size_t *body_len TSRMLS_DC); -#define http_parse_headers(h, l, a) _http_parse_headers((h), (l), (a) TSRMLS_CC) -PHP_HTTP_API STATUS _http_parse_headers(char *header, int header_len, HashTable *headers TSRMLS_DC); +#define http_parse_headers(h, l, a) _http_parse_headers_ex((h), (l), Z_ARRVAL_P(a), 1 TSRMLS_CC) +#define http_parse_headers_ex(h, l, ht, p) _http_parse_headers_ex((h), (l), (ht), (p) TSRMLS_CC) +PHP_HTTP_API STATUS _http_parse_headers_ex(char *header, int header_len, HashTable *headers, zend_bool prettify TSRMLS_DC); -#define http_get_request_headers(h) _http_get_request_headers((h) TSRMLS_CC) -PHP_HTTP_API void _http_get_request_headers(zval *array TSRMLS_DC); +#define http_get_request_headers(h) _http_get_request_headers_ex(Z_ARRVAL_P(h), 1 TSRMLS_CC) +#define http_get_request_headers_ex(h, p) _http_get_request_headers_ex((h), (s) TSRMLS_CC) +PHP_HTTP_API void _http_get_request_headers_ex(HashTable *headers, zend_bool prettify TSRMLS_DC); #define http_auth_credentials(u, p) _http_auth_credentials((u), (p) TSRMLS_CC) PHP_HTTP_API STATUS _http_auth_credentials(char **user, char **pass TSRMLS_DC); -- 2.30.2