cfcfdb07bef00496ecef645648fe237f3f6e7921
[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 typedef char *(*php_http_negotiate_func_t)(const char *test, double *quality, HashTable *supported TSRMLS_DC);
17
18 extern char *php_http_negotiate_language_func(const char *test, double *quality, HashTable *supported TSRMLS_DC);
19 extern char *php_http_negotiate_default_func(const char *test, double *quality, HashTable *supported TSRMLS_DC);
20
21 PHP_HTTP_API HashTable *php_http_negotiate(const char *value, HashTable *supported, php_http_negotiate_func_t neg TSRMLS_DC);
22
23 static inline HashTable *php_http_negotiate_language(HashTable *supported TSRMLS_DC)
24 {
25 HashTable *result = NULL;
26 char *value = php_http_env_get_request_header(ZEND_STRL("Accept-Language") TSRMLS_CC);
27
28 if (value) {
29 result = php_http_negotiate(value, supported, php_http_negotiate_language_func TSRMLS_CC);
30 }
31 STR_FREE(value);
32
33 return result;
34 }
35
36 static inline HashTable *php_http_negotiate_encoding(HashTable *supported TSRMLS_DC)
37 {
38 HashTable *result = NULL;
39 char *value = php_http_env_get_request_header(ZEND_STRL("Accept-Encoding") TSRMLS_CC);
40
41 if (value) {
42 result = php_http_negotiate(value, supported, NULL TSRMLS_CC);
43 }
44 STR_FREE(value);
45
46 return result;
47 }
48
49 static inline HashTable *php_http_negotiate_charset(HashTable *supported TSRMLS_DC)
50 {
51 HashTable *result = NULL;
52 char *value = php_http_env_get_request_header(ZEND_STRL("Accept-Charset") TSRMLS_CC);
53
54 if (value) {
55 result = php_http_negotiate(value, supported, NULL TSRMLS_CC);
56 }
57 STR_FREE(value);
58
59 return result;
60 }
61
62 static inline HashTable *php_http_negotiate_content_type(HashTable *supported TSRMLS_DC)
63 {
64 HashTable *result = NULL;
65 char *value = php_http_env_get_request_header(ZEND_STRL("Accept") TSRMLS_CC);
66
67 if (value) {
68 result = php_http_negotiate(value, supported, NULL TSRMLS_CC);
69 }
70 STR_FREE(value);
71
72 return result;
73 }
74
75
76 #endif
77
78 /*
79 * Local variables:
80 * tab-width: 4
81 * c-basic-offset: 4
82 * End:
83 * vim600: noet sw=4 ts=4 fdm=marker
84 * vim<600: noet sw=4 ts=4
85 */
86