4de90bcd6fec13257fd9cc2dd014659c03679a03
[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
31 typedef enum {
32 HTTP_MSG_NONE,
33 HTTP_MSG_REQUEST,
34 HTTP_MSG_RESPONSE
35 } http_message_type;
36
37 typedef struct _http_message http_message;
38
39 struct _http_message {
40 phpstr body;
41 HashTable hdrs;
42 http_message_type type;
43
44 union {
45 struct {
46 float http_version;
47 char *method;
48 char *URI;
49 } request;
50
51 struct {
52 float http_version;
53 int status;
54 } response;
55
56 } info;
57
58 size_t len;
59 char *raw;
60
61 http_message *nested;
62 };
63
64 /* required minimum length of an HTTP message "HTTP/1.1 200\r\n" */
65 #define HTTP_MSG_MIN_SIZE 15
66
67 #define HTTP_MSG_RAW(msg) ( (msg)->dup ? msg->raw.dup : msg->raw.ptr )
68
69 #define http_message_init() _http_message_init_ex(NULL, 0)
70 #define http_message_init_ex(m, t) _http_message_init_ex((m), (t))
71 #define http_message_free(m) _http_message_free((m))
72 #define http_message_dtor(m) _http_message_dtor((m))
73
74 PHP_HTTP_API void _http_message_dtor(http_message *message);
75 PHP_HTTP_API void _http_message_free(http_message *message);
76
77 #define http_message_parse(m, l) http_message_parse_ex((m), (l), 1)
78 #define http_message_parse_ex(m, l, d) _http_message_parse_ex((m), (l), (d) TSRMLS_CC)
79 PHP_HTTP_API http_message *_http_message_parse_ex(char *message, size_t length, zend_bool duplicate TSRMLS_DC);
80
81 #define http_message_tostring(m, s, l) _http_message_tostring((m), (s), (l))
82 PHP_HTTP_API void _http_message_tostring(http_message *msg, char **string, size_t *length);
83
84