- fix static property access (sizeof() vs. sizeof()-1)
[m6w6/ext-http] / php_http_api.h
1 /*
2 +----------------------------------------------------------------------+
3 | PECL :: http |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.0 of the PHP license, that |
6 | is bundled with this package in the file LICENSE, and is available |
7 | through the world-wide-web at http://www.php.net/license/3_0.txt. |
8 | If you did not receive a copy of the PHP license and are unable to |
9 | obtain it through the world-wide-web, please send a note to |
10 | license@php.net so we can mail you a copy immediately. |
11 +----------------------------------------------------------------------+
12 | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
13 +----------------------------------------------------------------------+
14 */
15
16 /* $Id$ */
17
18 #ifndef PHP_HTTP_API_H
19 #define PHP_HTTP_API_H
20
21 #include "php_http_std_defs.h"
22
23 #define pretty_key(key, key_len, uctitle, xhyphen) _http_pretty_key(key, key_len, uctitle, xhyphen)
24 extern char *_http_pretty_key(char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen);
25
26 typedef void (*http_key_list_decode_t)(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC);
27 #define http_key_list_default_decoder _http_key_list_default_decoder
28 extern void _http_key_list_default_decoder(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC);
29
30 #define http_parse_cookie(l, i) _http_parse_key_list((l), (i), ';', http_key_list_default_decoder, 1 TSRMLS_CC)
31 #define http_parse_key_list(l, i, s, d, f) _http_parse_key_list((l), (i), (s), (d), (f) TSRMLS_CC)
32 extern STATUS _http_parse_key_list(const char *list, HashTable *items, char separator, http_key_list_decode_t decode, zend_bool first_entry_is_name_value_pair TSRMLS_DC);
33
34 #define http_error(type, code, string) _http_error_ex(type, code, "%s", string)
35 #define http_error_ex _http_error_ex
36 extern void _http_error_ex(long type, long code, const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
37
38 #define http_log(f, i, m) _http_log_ex((f), (i), (m) TSRMLS_CC)
39 extern void http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC);
40
41 #define http_exit(s, h) http_exit_ex((s), (h), NULL, 1)
42 #define http_exit_ex(s, h, b, e) _http_exit_ex((s), (h), (b), (e) TSRMLS_CC)
43 extern STATUS _http_exit_ex(int status, char *header, char *body, zend_bool send_header TSRMLS_DC);
44
45 #define http_check_method(m) http_check_method_ex((m), HTTP_KNOWN_METHODS)
46 #define http_check_method_ex(m, a) _http_check_method_ex((m), (a))
47 extern STATUS _http_check_method_ex(const char *method, const char *methods);
48
49 #define HTTP_GSC(var, name, ret) HTTP_GSP(var, name, return ret)
50 #define HTTP_GSP(var, name, ret) \
51 if (!(var = _http_get_server_var_ex(name, strlen(name)+1, 1 TSRMLS_CC))) { \
52 ret; \
53 }
54 #define http_got_server_var(v) (NULL != _http_get_server_var_ex((v), sizeof(v), 1 TSRMLS_CC))
55 #define http_get_server_var(v) http_get_server_var_ex((v), sizeof(v))
56 #define http_get_server_var_ex(v, s) _http_get_server_var_ex((v), (s), 0 TSRMLS_CC)
57 PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_size, zend_bool check TSRMLS_DC);
58
59 #define http_get_request_body(b, l) _http_get_request_body_ex((b), (l), 1 TSRMLS_CC)
60 #define http_get_Request_body_ex(b, l, d) _http_get_request_body_ex((b), (l), (d) TSRMLS_CC)
61 PHP_HTTP_API STATUS _http_get_request_body_ex(char **body, size_t *length, zend_bool dup TSRMLS_DC);
62
63 #define http_chunked_decode(e, el, d, dl) _http_chunked_decode((e), (el), (d), (dl) TSRMLS_CC)
64 PHP_HTTP_API const char *_http_chunked_decode(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC);
65
66 #define http_locate_body _http_locate_body
67 static inline const char *_http_locate_body(const char *message)
68 {
69 const char *cr = strstr(message, "\r\n\r\n");
70 const char *lf = strstr(message, "\n\n");
71
72 if (lf && cr) {
73 return MIN(lf + 2, cr + 4);
74 } else if (lf || cr) {
75 return MAX(lf + 2, cr + 4);
76 } else {
77 return NULL;
78 }
79 }
80
81 #define http_locate_eol _http_locate_eol
82 static inline const char *_http_locate_eol(const char *line, size_t *eol_len)
83 {
84 const char *eol = strpbrk(line, "\r\n");
85
86 if (eol_len) {
87 *eol_len = eol ? ((eol[0] == '\r' && eol[1] == '\n') ? 2 : 1) : 0;
88 }
89 return eol;
90 }
91
92 #endif
93
94 /*
95 * Local variables:
96 * tab-width: 4
97 * c-basic-offset: 4
98 * End:
99 * vim600: noet sw=4 ts=4 fdm=marker
100 * vim<600: noet sw=4 ts=4
101 */
102