cvs: pecl /http http.c http_functions.c http_headers_api.c php_http.h php_http_headers_api.h

From: Date: Mon, 06 Jun 2005 11:31:40 +0000
Subject: cvs: pecl /http http.c http_functions.c http_headers_api.c php_http.h php_http_headers_api.h
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-3229@lists.php.net to get a copy of this message
mike Mon Jun 6 07:31:40 2005 EDT Modified files: /pecl/http http.c http_functions.c http_headers_api.c php_http.h php_http_headers_api.h Log: - add http_match_request_header() http://cvs.php.net/diff.php/pecl/http/http.c?r1=1.75&r2=1.76&ty=u Index: pecl/http/http.c diff -u pecl/http/http.c:1.75 pecl/http/http.c:1.76 --- pecl/http/http.c:1.75 Mon May 30 08:35:17 2005 +++ pecl/http/http.c Mon Jun 6 07:31:38 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http.c,v 1.75 2005/05/30 12:35:17 mike Exp $ */ +/* $Id: http.c,v 1.76 2005/06/06 11:31:38 mike Exp $ */ #ifdef HAVE_CONFIG_H @@ -114,6 +114,7 @@ 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) http://cvs.php.net/diff.php/pecl/http/http_functions.c?r1=1.35&r2=1.36&ty=u Index: pecl/http/http_functions.c diff -u pecl/http/http_functions.c:1.35 pecl/http/http_functions.c:1.36 --- pecl/http/http_functions.c:1.35 Mon May 30 08:05:07 2005 +++ pecl/http/http_functions.c Mon Jun 6 07:31:38 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http_functions.c,v 1.35 2005/05/30 12:05:07 mike Exp $ */ +/* $Id: http_functions.c,v 1.36 2005/06/06 11:31:38 mike Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -652,6 +652,7 @@ /* {{{ proto array http_get_request_headers(void) * + * Get a list of incoming HTTP headers. */ PHP_FUNCTION(http_get_request_headers) { @@ -662,6 +663,24 @@ } /* }}} */ +/* {{{ 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 @@ } else { RETVAL_FALSE; } - http_request_body_dtor(&body); } /* }}} */ http://cvs.php.net/diff.php/pecl/http/http_headers_api.c?r1=1.8&r2=1.9&ty=u Index: pecl/http/http_headers_api.c diff -u pecl/http/http_headers_api.c:1.8 pecl/http/http_headers_api.c:1.9 --- pecl/http/http_headers_api.c:1.8 Tue May 3 02:35:30 2005 +++ pecl/http/http_headers_api.c Mon Jun 6 07:31:38 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http_headers_api.c,v 1.8 2005/05/03 06:35:30 mike Exp $ */ +/* $Id: http_headers_api.c,v 1.9 2005/06/06 11:31:38 mike Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -464,6 +464,36 @@ } /* }}} */ +/* {{{ 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: http://cvs.php.net/diff.php/pecl/http/php_http.h?r1=1.51&r2=1.52&ty=u Index: pecl/http/php_http.h diff -u pecl/http/php_http.h:1.51 pecl/http/php_http.h:1.52 --- pecl/http/php_http.h:1.51 Tue May 31 08:29:27 2005 +++ pecl/http/php_http.h Mon Jun 6 07:31:38 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_http.h,v 1.51 2005/05/31 12:29:27 mike Exp $ */ +/* $Id: php_http.h,v 1.52 2005/06/06 11:31:38 mike Exp $ */ #ifndef PHP_EXT_HTTP_H #define PHP_EXT_HTTP_H @@ -104,6 +104,7 @@ 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); http://cvs.php.net/diff.php/pecl/http/php_http_headers_api.h?r1=1.4&r2=1.5&ty=u Index: pecl/http/php_http_headers_api.h diff -u pecl/http/php_http_headers_api.h:1.4 pecl/http/php_http_headers_api.h:1.5 --- pecl/http/php_http_headers_api.h:1.4 Tue May 3 10:26:41 2005 +++ pecl/http/php_http_headers_api.h Mon Jun 6 07:31:38 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_http_headers_api.h,v 1.4 2005/05/03 14:26:41 mike Exp $ */ +/* $Id: php_http_headers_api.h,v 1.5 2005/06/06 11:31:38 mike Exp $ */ #ifndef PHP_HTTP_HEADERS_API_H #define PHP_HTTP_HEADERS_API_H @@ -40,7 +40,7 @@ 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 @@ #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 /*

« previous php.pecl.cvs (#3229) next »