- add http_match_request_header()
authorMichael Wallner <mike@php.net>
Mon, 6 Jun 2005 11:31:38 +0000 (11:31 +0000)
committerMichael Wallner <mike@php.net>
Mon, 6 Jun 2005 11:31:38 +0000 (11:31 +0000)
http.c
http_functions.c
http_headers_api.c
php_http.h
php_http_headers_api.h

diff --git a/http.c b/http.c
index ce1a3988c8133c294e4eaa6090173b3139d0b699..a09fa61251c00ef05931b74d512aaf1072636d6c 100644 (file)
--- a/http.c
+++ b/http.c
@@ -114,6 +114,7 @@ function_entry http_functions[] = {
        PHP_FE(http_split_response, NULL)
        PHP_FE(http_parse_headers, NULL)
        PHP_FE(http_get_request_headers, NULL)
+       PHP_FE(http_match_request_header, NULL)
 #ifdef HTTP_HAVE_CURL
        PHP_FE(http_get, http_request_info_ref_3)
        PHP_FE(http_head, http_request_info_ref_3)
index 4e88f42a202729f8d949c848c171b63db7186275..fa9cf9ca6a947e4b33df73adbf0d9349dda576ae 100644 (file)
@@ -652,6 +652,7 @@ PHP_FUNCTION(http_parse_headers)
 
 /* {{{ proto array http_get_request_headers(void)
  *
+ * Get a list of incoming HTTP headers.
  */
 PHP_FUNCTION(http_get_request_headers)
 {
@@ -662,6 +663,24 @@ PHP_FUNCTION(http_get_request_headers)
 }
 /* }}} */
 
+/* {{{ proto bool http_match_request_header(string header, string value[, bool match_case = false])
+ *
+ * Match an incoming HTTP header.
+ */
+PHP_FUNCTION(http_match_request_header)
+{
+       char *header, *value;
+       int header_len, value_len;
+       zend_bool match_case = 0, result = 0;
+
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &header, &header_len, &value, &value_len, &match_case)) {
+               RETURN_FALSE;
+       }
+
+       RETURN_BOOL(http_match_request_header_ex(header, value, match_case));
+}
+/* }}} */
+
 /* {{{ HAVE_CURL */
 #ifdef HTTP_HAVE_CURL
 
@@ -825,7 +844,6 @@ PHP_FUNCTION(http_post_data)
        } else {
                RETVAL_FALSE;
        }
-       http_request_body_dtor(&body);
 }
 /* }}} */
 
index 7d824525602ae4f45451392702fef9eb17b3f276..81181e5711e6141b9cf4c653c72506b8fd2e721f 100644 (file)
@@ -464,6 +464,36 @@ PHP_HTTP_API void _http_get_request_headers_ex(HashTable *headers, zend_bool pre
 }
 /* }}} */
 
+/* {{{ zend_bool http_match_request_header(char *, char *) */
+PHP_HTTP_API zend_bool _http_match_request_header_ex(const char *header, const char *value, zend_bool match_case TSRMLS_DC)
+{
+       char *name, *key = NULL;
+       ulong idx;
+       zend_bool result = 0;
+       HashTable headers;
+
+       name = pretty_key(estrdup(header), strlen(header), 1, 1);
+       zend_hash_init(&headers, 0, NULL, ZVAL_PTR_DTOR, 0);
+       http_get_request_headers_ex(&headers, 1);
+
+       FOREACH_HASH_KEY(&headers, key, idx) {
+               if (key && (!strcmp(key, name))) {
+                       zval **data;
+
+                       if (SUCCESS == zend_hash_get_current_data(&headers, (void **) &data)) {
+                               result = (match_case ? strcmp(Z_STRVAL_PP(data), value) : strcasecmp(Z_STRVAL_PP(data), value)) ? 0 : 1;
+                       }
+                       break;
+               }
+       }
+
+       zend_hash_destroy(&headers);
+       efree(name);
+
+       return result;
+}
+/* }}} */
+
 
 /*
  * Local variables:
index 27e8fc009bd626e87b7200f0fcd8a37e24f7b0e4..467507eea514a90c153dd0ef626d74efb9915e1d 100644 (file)
@@ -104,6 +104,7 @@ PHP_FUNCTION(http_chunked_decode);
 PHP_FUNCTION(http_split_response);
 PHP_FUNCTION(http_parse_headers);
 PHP_FUNCTION(http_get_request_headers);
+PHP_FUNCTION(http_match_request_header);
 #ifdef HTTP_HAVE_CURL
 PHP_FUNCTION(http_get);
 PHP_FUNCTION(http_head);
index ae3748ac3bb2b84cddfee74a4aa6bf05122ed58d..6d6319a31315bfea0a0841100dfd73f371ea8d98 100644 (file)
@@ -40,7 +40,7 @@ PHP_HTTP_API STATUS _http_parse_headers_ex(const char *header, HashTable *header
 PHP_HTTP_API STATUS _http_parse_cookie(const char *cookie, HashTable *values 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)
+#define http_get_request_headers_ex(h, p) _http_get_request_headers_ex((h), (p) TSRMLS_CC)
 PHP_HTTP_API void _http_get_request_headers_ex(HashTable *headers, zend_bool prettify TSRMLS_DC);
 
 #define http_negotiate_language(zsupported, def) http_negotiate_language_ex(Z_ARRVAL_P(zsupported), (def))
@@ -53,6 +53,10 @@ PHP_HTTP_API char *_http_negotiate_q(const char *entry, const HashTable *support
 #define http_get_request_ranges(r, l) _http_get_request_ranges((r), (l) TSRMLS_CC)
 PHP_HTTP_API http_range_status _http_get_request_ranges(HashTable *ranges, size_t length TSRMLS_DC);
 
+#define http_match_request_header(h, v) http_match_request_header_ex((h), (v), 0)
+#define http_match_request_header_ex(h, v, c) _http_match_request_header_ex((h), (v), (c) TSRMLS_CC)
+PHP_HTTP_API zend_bool _http_match_request_header_ex(const char *header, const char *value, zend_bool match_case TSRMLS_DC);
+
 #endif
 
 /*