5a0d6af40079355dde36ed8284f2544aec70722a
[m6w6/ext-http] / php_http_negotiate.h
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2011, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #ifndef PHP_HTTP_NEGOTIATE_H
14 #define PHP_HTTP_NEGOTIATE_H
15
16 PHP_HTTP_API HashTable *php_http_negotiate(const char *value_str, size_t value_len, HashTable *supported, const char *primary_sep_str, size_t primary_sep_len TSRMLS_DC);
17
18 static inline HashTable *php_http_negotiate_language(HashTable *supported TSRMLS_DC)
19 {
20 HashTable *result = NULL;
21 size_t length;
22 char *value = php_http_env_get_request_header(ZEND_STRL("Accept-Language"), &length TSRMLS_CC);
23
24 if (value) {
25 result = php_http_negotiate(value, length, supported, "-", 1 TSRMLS_CC);
26 }
27 STR_FREE(value);
28
29 return result;
30 }
31
32 static inline HashTable *php_http_negotiate_encoding(HashTable *supported TSRMLS_DC)
33 {
34 HashTable *result = NULL;
35 size_t length;
36 char *value = php_http_env_get_request_header(ZEND_STRL("Accept-Encoding"), &length TSRMLS_CC);
37
38 if (value) {
39 result = php_http_negotiate(value, length, supported, NULL, 0 TSRMLS_CC);
40 }
41 STR_FREE(value);
42
43 return result;
44 }
45
46 static inline HashTable *php_http_negotiate_charset(HashTable *supported TSRMLS_DC)
47 {
48 HashTable *result = NULL;
49 size_t length;
50 char *value = php_http_env_get_request_header(ZEND_STRL("Accept-Charset"), &length TSRMLS_CC);
51
52 if (value) {
53 result = php_http_negotiate(value, length, supported, NULL, 0 TSRMLS_CC);
54 }
55 STR_FREE(value);
56
57 return result;
58 }
59
60 static inline HashTable *php_http_negotiate_content_type(HashTable *supported TSRMLS_DC)
61 {
62 HashTable *result = NULL;
63 size_t length;
64 char *value = php_http_env_get_request_header(ZEND_STRL("Accept"), &length TSRMLS_CC);
65
66 if (value) {
67 result = php_http_negotiate(value, length, supported, "/", 1 TSRMLS_CC);
68 }
69 STR_FREE(value);
70
71 return result;
72 }
73
74 #endif
75
76 /*
77 * Local variables:
78 * tab-width: 4
79 * c-basic-offset: 4
80 * End:
81 * vim600: noet sw=4 ts=4 fdm=marker
82 * vim<600: noet sw=4 ts=4
83 */
84