- add missing support for raw post data (HttpRequest)
[m6w6/ext-http] / php_http_message_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_MESSAGE_API_H
19 #define PHP_HTTP_MESSAGE_API_H
20
21 #include "php_http_info_api.h"
22 #include "phpstr/phpstr.h"
23
24 typedef enum {
25 HTTP_MSG_NONE = 0,
26 HTTP_MSG_REQUEST = IS_HTTP_REQUEST,
27 HTTP_MSG_RESPONSE = IS_HTTP_RESPONSE,
28 } http_message_type;
29
30 typedef struct _http_message http_message;
31
32 struct _http_message {
33 phpstr body;
34 HashTable hdrs;
35 http_message_type type;
36 struct http_info http;
37 http_message *parent;
38 };
39
40 /* required minimum length of an HTTP message "HTTP/1.1" */
41 #define HTTP_MSG_MIN_SIZE 8
42
43 /* shorthand for type checks */
44 #define HTTP_MSG_TYPE(TYPE, msg) ((msg) && ((msg)->type == HTTP_MSG_ ##TYPE))
45
46 #define http_message_new() _http_message_init_ex(NULL, 0)
47 #define http_message_init(m) _http_message_init_ex((m), 0)
48 #define http_message_init_ex(m, t) _http_message_init_ex((m), (t))
49 PHP_HTTP_API http_message *_http_message_init_ex(http_message *m, http_message_type t);
50
51 #define http_message_set_type(m, t) _http_message_set_type((m), (t))
52 PHP_HTTP_API void _http_message_set_type(http_message *m, http_message_type t);
53
54 #define http_message_header(m, h) _http_message_header_ex((m), (h), sizeof(h))
55 #define http_message_header_ex _http_message_header_ex
56 static inline zval *_http_message_header_ex(http_message *msg, char *key_str, size_t key_len)
57 {
58 zval **header;
59 if (SUCCESS == zend_hash_find(&msg->hdrs, key_str, key_len, (void **) &header)) {
60 return *header;
61 }
62 return NULL;
63 }
64
65 #define http_message_parse(m, l) http_message_parse_ex(NULL, (m), (l))
66 #define http_message_parse_ex(h, m, l) _http_message_parse_ex((h), (m), (l) TSRMLS_CC)
67 PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char *message, size_t length TSRMLS_DC);
68
69 #define http_message_tostring(m, s, l) _http_message_tostring((m), (s), (l))
70 PHP_HTTP_API void _http_message_tostring(http_message *msg, char **string, size_t *length);
71
72 #define http_message_serialize(m, s, l) _http_message_serialize((m), (s), (l))
73 PHP_HTTP_API void _http_message_serialize(http_message *message, char **string, size_t *length);
74
75 #define http_message_tostruct_recursive(m, s) _http_message_tostruct_recursive((m), (s) TSRMLS_CC)
76 PHP_HTTP_API void _http_message_tostruct_recursive(http_message *msg, zval *strct TSRMLS_DC);
77
78 #define http_message_send(m) _http_message_send((m) TSRMLS_CC)
79 PHP_HTTP_API STATUS _http_message_send(http_message *message TSRMLS_DC);
80
81 #define http_message_dup(m) _http_message_dup((m) TSRMLS_CC)
82 PHP_HTTP_API http_message *_http_message_dup(http_message *msg TSRMLS_DC);
83
84 #define http_message_dtor(m) _http_message_dtor((m))
85 PHP_HTTP_API void _http_message_dtor(http_message *message);
86
87 #define http_message_free(m) _http_message_free((m))
88 PHP_HTTP_API void _http_message_free(http_message **message);
89
90 #endif
91
92 /*
93 * Local variables:
94 * tab-width: 4
95 * c-basic-offset: 4
96 * End:
97 * vim600: noet sw=4 ts=4 fdm=marker
98 * vim<600: noet sw=4 ts=4
99 */
100