import 2.0 devl branch, suitable for PHP-trunk
[m6w6/ext-http] / php_http_message.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-2010, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 /* $Id: php_http_message.h 292841 2009-12-31 08:48:57Z mike $ */
14
15 #ifndef PHP_HTTP_MESSAGE_H
16 #define PHP_HTTP_MESSAGE_H
17
18 /* required minimum length of an HTTP message "HTTP/1.1" */
19 #define PHP_HTTP_MESSAGE_MIN_SIZE 8
20 #define PHP_HTTP_MESSAGE_TYPE(TYPE, msg) ((msg) && ((msg)->type == PHP_HTTP_ ##TYPE))
21 #define PHP_HTTP_MESSAGE_TYPE_CHECK(type, msg, action) \
22 if (!PHP_HTTP_MESSAGE_TYPE(type, (msg))) { \
23 php_http_error(HE_NOTICE, PHP_HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type "#type); \
24 action; \
25 }
26
27 typedef php_http_info_type_t php_http_message_type_t;
28 typedef struct php_http_message php_http_message_t;
29
30 struct php_http_message {
31 PHP_HTTP_INFO_IMPL(http, type)
32 HashTable hdrs;
33 php_http_message_body_t body;
34 php_http_message_t *parent;
35 void *opaque;
36 #ifdef ZTS
37 void ***ts;
38 #endif
39 };
40
41 PHP_HTTP_API zend_bool php_http_message_info_callback(php_http_message_t **message, HashTable **headers, php_http_info_t *info TSRMLS_DC);
42
43 PHP_HTTP_API php_http_message_t *php_http_message_init(php_http_message_t *m, php_http_message_type_t t TSRMLS_DC);
44 PHP_HTTP_API php_http_message_t *php_http_message_init_env(php_http_message_t *m, php_http_message_type_t t TSRMLS_DC);
45 PHP_HTTP_API php_http_message_t *php_http_message_copy(php_http_message_t *from, php_http_message_t *to);
46 PHP_HTTP_API void php_http_message_dtor(php_http_message_t *message);
47 PHP_HTTP_API void php_http_message_free(php_http_message_t **message);
48
49 PHP_HTTP_API void php_http_message_set_type(php_http_message_t *m, php_http_message_type_t t);
50 PHP_HTTP_API void php_http_message_set_info(php_http_message_t *message, php_http_info_t *info);
51
52 PHP_HTTP_API zval *php_http_message_header(php_http_message_t *msg, char *key_str, size_t key_len, int join);
53
54 PHP_HTTP_API void php_http_message_to_string(php_http_message_t *msg, char **string, size_t *length);
55 PHP_HTTP_API void php_http_message_to_struct(php_http_message_t *msg, zval *strct);
56 PHP_HTTP_API void php_http_message_to_callback(php_http_message_t *msg, php_http_pass_callback_t cb, void *cb_arg);
57
58 PHP_HTTP_API void php_http_message_serialize(php_http_message_t *message, char **string, size_t *length);
59 PHP_HTTP_API php_http_message_t *php_http_message_reverse(php_http_message_t *msg);
60 PHP_HTTP_API php_http_message_t *php_http_message_interconnect(php_http_message_t *m1, php_http_message_t *m2);
61
62 #define php_http_message_count(c, m) \
63 { \
64 php_http_message_t *__tmp_msg = (m); \
65 for (c = 0; __tmp_msg; __tmp_msg = __tmp_msg->parent, ++(c)); \
66 }
67
68 PHP_HTTP_API php_http_message_t *php_http_message_parse(php_http_message_t *msg, const char *str, size_t len TSRMLS_DC);
69
70 /* PHP */
71
72 typedef struct php_http_message_object {
73 zend_object zo;
74 php_http_message_t *message;
75 zend_object_value parent, body;
76 zval *iterator;
77 } php_http_message_object_t;
78
79 extern zend_class_entry *php_http_message_class_entry;
80 extern zend_function_entry http_message_method_entry[];
81
82 extern PHP_MINIT_FUNCTION(http_message);
83 extern PHP_MSHUTDOWN_FUNCTION(http_message);
84
85 extern void php_http_message_object_prepend(zval *this_ptr, zval *prepend, zend_bool top /* = 1 */ TSRMLS_DC);
86 extern void php_http_message_object_reverse(zval *this_ptr, zval *return_value TSRMLS_DC);
87
88 extern zend_object_value php_http_message_object_new(zend_class_entry *ce TSRMLS_DC);
89 extern zend_object_value php_http_message_object_new_ex(zend_class_entry *ce, php_http_message_t *msg, php_http_message_object_t **ptr TSRMLS_DC);
90 extern zend_object_value php_http_message_object_clone(zval *object TSRMLS_DC);
91 extern void php_http_message_object_free(void *object TSRMLS_DC);
92
93 PHP_METHOD(HttpMessage, __construct);
94 PHP_METHOD(HttpMessage, getBody);
95 PHP_METHOD(HttpMessage, setBody);
96 PHP_METHOD(HttpMessage, getHeader);
97 PHP_METHOD(HttpMessage, setHeader);
98 PHP_METHOD(HttpMessage, addHeader);
99 PHP_METHOD(HttpMessage, getHeaders);
100 PHP_METHOD(HttpMessage, setHeaders);
101 PHP_METHOD(HttpMessage, addHeaders);
102 PHP_METHOD(HttpMessage, getType);
103 PHP_METHOD(HttpMessage, setType);
104 PHP_METHOD(HttpMessage, getInfo);
105 PHP_METHOD(HttpMessage, setInfo);
106 PHP_METHOD(HttpMessage, getResponseCode);
107 PHP_METHOD(HttpMessage, setResponseCode);
108 PHP_METHOD(HttpMessage, getResponseStatus);
109 PHP_METHOD(HttpMessage, setResponseStatus);
110 PHP_METHOD(HttpMessage, getRequestMethod);
111 PHP_METHOD(HttpMessage, setRequestMethod);
112 PHP_METHOD(HttpMessage, getRequestUrl);
113 PHP_METHOD(HttpMessage, setRequestUrl);
114 PHP_METHOD(HttpMessage, getHttpVersion);
115 PHP_METHOD(HttpMessage, setHttpVersion);
116 PHP_METHOD(HttpMessage, guessContentType);
117 PHP_METHOD(HttpMessage, getParentMessage);
118 PHP_METHOD(HttpMessage, send);
119 PHP_METHOD(HttpMessage, toString);
120 PHP_METHOD(HttpMessage, toMessageTypeObject);
121
122 PHP_METHOD(HttpMessage, count);
123 PHP_METHOD(HttpMessage, serialize);
124 PHP_METHOD(HttpMessage, unserialize);
125 PHP_METHOD(HttpMessage, rewind);
126 PHP_METHOD(HttpMessage, valid);
127 PHP_METHOD(HttpMessage, current);
128 PHP_METHOD(HttpMessage, key);
129 PHP_METHOD(HttpMessage, next);
130
131 PHP_METHOD(HttpMessage, factory);
132
133 PHP_METHOD(HttpMessage, detach);
134 PHP_METHOD(HttpMessage, prepend);
135 PHP_METHOD(HttpMessage, reverse);
136
137 #endif
138
139 /*
140 * Local variables:
141 * tab-width: 4
142 * c-basic-offset: 4
143 * End:
144 * vim600: noet sw=4 ts=4 fdm=marker
145 * vim<600: noet sw=4 ts=4
146 */
147