78355a63c47f4bea0b7b14c617b68cf56ab9afaf
[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 /*
22 DUMP:
23 HttpMessage
24 ->toResponseString();
25 ->toRequestString();
26 ->__toString(); ->__sleep(); ->serialize();
27 ->fromString(); __wakeup($message); ->unserialize();
28 ->setStatusCode();
29 ->setHeader(); ->addHeader()...
30 */
31
32 #include "phpstr/phpstr.h"
33 #include "php_http_headers_api.h"
34
35 typedef enum {
36 HTTP_MSG_NONE,
37 HTTP_MSG_REQUEST,
38 HTTP_MSG_RESPONSE
39 } http_message_type;
40
41 typedef struct _http_message http_message;
42
43 struct _http_message {
44 phpstr body;
45 HashTable hdrs;
46 http_message_type type;
47
48 union {
49 struct {
50 float http_version;
51 char *method;
52 char *URI;
53 } request;
54
55 struct {
56 float http_version;
57 int code;
58 } response;
59
60 } info;
61
62 size_t len;
63 char *raw;
64
65 http_message *nested;
66 };
67
68 /* required minimum length of an HTTP message "HTTP/1.1 200\r\n" */
69 #define HTTP_MSG_MIN_SIZE 15
70
71 #define http_message_new() _http_message_init_ex(NULL, 0)
72 #define http_message_init(m) _http_message_init_ex((m), 0)
73 #define http_message_init_ex(m, t) _http_message_init_ex((m), (t))
74 PHP_HTTP_API http_message *_http_message_init_ex(http_message *m, http_message_type t);
75
76 #define http_message_parse(m, l) http_message_parse_ex(NULL, (m), (l), 1)
77 #define http_message_parse_ex(h, m, l, d) _http_message_parse_ex((h), (m), (l), (d) TSRMLS_CC)
78 PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, char *message, size_t length, zend_bool duplicate TSRMLS_DC);
79
80 #define http_message_parse_headers_callback _http_message_parse_headers_callback
81 PHP_HTTP_API void _http_message_parse_headers_callback(void *message, char *http_line, size_t line_length, HashTable **headers TSRMLS_DC);
82
83 #define http_message_tostring(m, s, l) _http_message_tostring((m), (s), (l))
84 PHP_HTTP_API void _http_message_tostring(http_message *msg, char **string, size_t *length);
85 #define http_message_dtor(m) _http_message_dtor((m))
86 PHP_HTTP_API void _http_message_dtor(http_message *message);
87
88 #define http_message_free(m) _http_message_free((m))
89 PHP_HTTP_API void _http_message_free(http_message *message);
90
91 #endif
92
93 /*
94 * Local variables:
95 * tab-width: 4
96 * c-basic-offset: 4
97 * End:
98 * vim600: noet sw=4 ts=4 fdm=marker
99 * vim<600: noet sw=4 ts=4
100 */
101