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