1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* |
---|
3 | * Copyright (C) 2000-2003, Ximian, Inc. |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef SOUP_MESSAGE_H |
---|
7 | #define SOUP_MESSAGE_H 1 |
---|
8 | |
---|
9 | #include <libsoup/soup-types.h> |
---|
10 | #include <libsoup/soup-method.h> |
---|
11 | |
---|
12 | #define SOUP_TYPE_MESSAGE (soup_message_get_type ()) |
---|
13 | #define SOUP_MESSAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SOUP_TYPE_MESSAGE, SoupMessage)) |
---|
14 | #define SOUP_MESSAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SOUP_TYPE_MESSAGE, SoupMessageClass)) |
---|
15 | #define SOUP_IS_MESSAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SOUP_TYPE_MESSAGE)) |
---|
16 | #define SOUP_IS_MESSAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), SOUP_TYPE_MESSAGE)) |
---|
17 | #define SOUP_MESSAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SOUP_TYPE_MESSAGE, SoupMessageClass)) |
---|
18 | |
---|
19 | typedef struct SoupMessagePrivate SoupMessagePrivate; |
---|
20 | |
---|
21 | typedef enum { |
---|
22 | SOUP_MESSAGE_STATUS_IDLE, |
---|
23 | SOUP_MESSAGE_STATUS_QUEUED, |
---|
24 | SOUP_MESSAGE_STATUS_CONNECTING, |
---|
25 | SOUP_MESSAGE_STATUS_RUNNING, |
---|
26 | SOUP_MESSAGE_STATUS_FINISHED |
---|
27 | } SoupMessageStatus; |
---|
28 | |
---|
29 | #define SOUP_MESSAGE_IS_STARTING(msg) (msg->status == SOUP_MESSAGE_STATUS_QUEUED || msg->status == SOUP_MESSAGE_STATUS_CONNECTING) |
---|
30 | |
---|
31 | typedef enum { |
---|
32 | SOUP_TRANSFER_UNKNOWN = 0, |
---|
33 | SOUP_TRANSFER_CHUNKED, |
---|
34 | SOUP_TRANSFER_CONTENT_LENGTH |
---|
35 | } SoupTransferEncoding; |
---|
36 | |
---|
37 | typedef enum { |
---|
38 | SOUP_BUFFER_SYSTEM_OWNED = 0, |
---|
39 | SOUP_BUFFER_USER_OWNED, |
---|
40 | SOUP_BUFFER_STATIC |
---|
41 | } SoupOwnership; |
---|
42 | |
---|
43 | typedef struct { |
---|
44 | SoupOwnership owner; |
---|
45 | char *body; |
---|
46 | guint length; |
---|
47 | } SoupDataBuffer; |
---|
48 | |
---|
49 | struct SoupMessage { |
---|
50 | GObject parent; |
---|
51 | |
---|
52 | SoupMessagePrivate *priv; |
---|
53 | |
---|
54 | const char *method; |
---|
55 | |
---|
56 | guint status_code; |
---|
57 | const char *reason_phrase; |
---|
58 | |
---|
59 | SoupDataBuffer request; |
---|
60 | GHashTable *request_headers; |
---|
61 | |
---|
62 | SoupDataBuffer response; |
---|
63 | GHashTable *response_headers; |
---|
64 | |
---|
65 | SoupMessageStatus status; |
---|
66 | }; |
---|
67 | |
---|
68 | typedef struct { |
---|
69 | GObjectClass parent_class; |
---|
70 | |
---|
71 | /* signals */ |
---|
72 | void (*wrote_informational) (SoupMessage *msg); |
---|
73 | void (*wrote_headers) (SoupMessage *msg); |
---|
74 | void (*wrote_chunk) (SoupMessage *msg); |
---|
75 | void (*wrote_body) (SoupMessage *msg); |
---|
76 | void (*got_informational) (SoupMessage *msg); |
---|
77 | void (*got_headers) (SoupMessage *msg); |
---|
78 | void (*got_chunk) (SoupMessage *msg); |
---|
79 | void (*got_body) (SoupMessage *msg); |
---|
80 | void (*restarted) (SoupMessage *msg); |
---|
81 | void (*finished) (SoupMessage *msg); |
---|
82 | } SoupMessageClass; |
---|
83 | |
---|
84 | GType soup_message_get_type (void); |
---|
85 | |
---|
86 | typedef void (*SoupMessageCallbackFn) (SoupMessage *req, gpointer user_data); |
---|
87 | |
---|
88 | SoupMessage *soup_message_new (const char *method, |
---|
89 | const char *uri_string); |
---|
90 | SoupMessage *soup_message_new_from_uri (const char *method, |
---|
91 | const SoupUri *uri); |
---|
92 | |
---|
93 | void soup_message_set_request (SoupMessage *msg, |
---|
94 | const char *content_type, |
---|
95 | SoupOwnership req_owner, |
---|
96 | char *req_body, |
---|
97 | gulong req_length); |
---|
98 | |
---|
99 | void soup_message_set_response (SoupMessage *msg, |
---|
100 | const char *content_type, |
---|
101 | SoupOwnership resp_owner, |
---|
102 | char *resp_body, |
---|
103 | gulong resp_length); |
---|
104 | |
---|
105 | void soup_message_add_header (GHashTable *hash, |
---|
106 | const char *name, |
---|
107 | const char *value); |
---|
108 | |
---|
109 | const char *soup_message_get_header (GHashTable *hash, |
---|
110 | const char *name); |
---|
111 | |
---|
112 | const GSList *soup_message_get_header_list (GHashTable *hash, |
---|
113 | const char *name); |
---|
114 | |
---|
115 | void soup_message_foreach_header (GHashTable *hash, |
---|
116 | GHFunc func, |
---|
117 | gpointer user_data); |
---|
118 | |
---|
119 | void soup_message_remove_header (GHashTable *hash, |
---|
120 | const char *name); |
---|
121 | |
---|
122 | void soup_message_clear_headers (GHashTable *hash); |
---|
123 | |
---|
124 | typedef enum { |
---|
125 | SOUP_HTTP_1_0 = 0, |
---|
126 | SOUP_HTTP_1_1 = 1 |
---|
127 | } SoupHttpVersion; |
---|
128 | |
---|
129 | void soup_message_set_http_version (SoupMessage *msg, |
---|
130 | SoupHttpVersion version); |
---|
131 | SoupHttpVersion soup_message_get_http_version (SoupMessage *msg); |
---|
132 | |
---|
133 | gboolean soup_message_is_keepalive (SoupMessage *msg); |
---|
134 | |
---|
135 | const SoupUri *soup_message_get_uri (SoupMessage *msg); |
---|
136 | void soup_message_set_uri (SoupMessage *msg, |
---|
137 | const SoupUri *uri); |
---|
138 | |
---|
139 | typedef enum { |
---|
140 | /* |
---|
141 | * SOUP_MESSAGE_NO_REDIRECT: |
---|
142 | * Do not follow redirection responses. |
---|
143 | */ |
---|
144 | SOUP_MESSAGE_NO_REDIRECT = (1 << 1), |
---|
145 | |
---|
146 | /* |
---|
147 | * SOUP_MESSAGE_OVERWRITE_CHUNKS: |
---|
148 | * Downloaded data chunks should not be stored in the response |
---|
149 | * data buffer. Instead only send data to SOUP_HANDLER_BODY_CHUNK |
---|
150 | * handlers, then truncate the data buffer. |
---|
151 | * |
---|
152 | * Useful when the response is expected to be very large, and |
---|
153 | * storage in memory is not desired. |
---|
154 | */ |
---|
155 | SOUP_MESSAGE_OVERWRITE_CHUNKS = (1 << 3), |
---|
156 | |
---|
157 | /* |
---|
158 | * SOUP_MESSAGE_EXPECT_CONTINUE: The message includes an |
---|
159 | * "Expect: 100-continue" header, and we should not send the |
---|
160 | * body until the Continue response has been received. (This |
---|
161 | * is automatically set if there is an "Expect: 100-continue" |
---|
162 | * header.) |
---|
163 | */ |
---|
164 | SOUP_MESSAGE_EXPECT_CONTINUE = (1 << 4) |
---|
165 | } SoupMessageFlags; |
---|
166 | |
---|
167 | void soup_message_set_flags (SoupMessage *msg, |
---|
168 | guint flags); |
---|
169 | |
---|
170 | guint soup_message_get_flags (SoupMessage *msg); |
---|
171 | |
---|
172 | /* |
---|
173 | * Handler Registration |
---|
174 | */ |
---|
175 | typedef enum { |
---|
176 | SOUP_HANDLER_POST_REQUEST = 1, |
---|
177 | SOUP_HANDLER_PRE_BODY, |
---|
178 | SOUP_HANDLER_BODY_CHUNK, |
---|
179 | SOUP_HANDLER_POST_BODY |
---|
180 | } SoupHandlerPhase; |
---|
181 | |
---|
182 | void soup_message_add_handler (SoupMessage *msg, |
---|
183 | SoupHandlerPhase type, |
---|
184 | SoupMessageCallbackFn handler_cb, |
---|
185 | gpointer user_data); |
---|
186 | |
---|
187 | void soup_message_add_header_handler (SoupMessage *msg, |
---|
188 | const char *header, |
---|
189 | SoupHandlerPhase type, |
---|
190 | SoupMessageCallbackFn, |
---|
191 | gpointer user_data); |
---|
192 | |
---|
193 | void soup_message_add_status_code_handler ( |
---|
194 | SoupMessage *msg, |
---|
195 | guint status_code, |
---|
196 | SoupHandlerPhase type, |
---|
197 | SoupMessageCallbackFn, |
---|
198 | gpointer user_data); |
---|
199 | |
---|
200 | void soup_message_add_status_class_handler ( |
---|
201 | SoupMessage *msg, |
---|
202 | SoupStatusClass status_class, |
---|
203 | SoupHandlerPhase type, |
---|
204 | SoupMessageCallbackFn, |
---|
205 | gpointer user_data); |
---|
206 | |
---|
207 | void soup_message_remove_handler (SoupMessage *msg, |
---|
208 | SoupHandlerPhase type, |
---|
209 | SoupMessageCallbackFn, |
---|
210 | gpointer user_data); |
---|
211 | |
---|
212 | /* |
---|
213 | * Status Setting |
---|
214 | */ |
---|
215 | void soup_message_set_status (SoupMessage *msg, |
---|
216 | guint status_code); |
---|
217 | |
---|
218 | void soup_message_set_status_full (SoupMessage *msg, |
---|
219 | guint status_code, |
---|
220 | const char *reason_phrase); |
---|
221 | |
---|
222 | |
---|
223 | /* Chunked encoding */ |
---|
224 | void soup_message_add_chunk (SoupMessage *msg, |
---|
225 | SoupOwnership owner, |
---|
226 | const char *body, |
---|
227 | guint length); |
---|
228 | void soup_message_add_final_chunk (SoupMessage *msg); |
---|
229 | |
---|
230 | SoupDataBuffer*soup_message_pop_chunk (SoupMessage *msg); |
---|
231 | |
---|
232 | |
---|
233 | /* I/O */ |
---|
234 | void soup_message_send_request (SoupMessage *req, |
---|
235 | SoupSocket *sock, |
---|
236 | gboolean via_proxy); |
---|
237 | void soup_message_read_request (SoupMessage *req, |
---|
238 | SoupSocket *sock); |
---|
239 | void soup_message_io_stop (SoupMessage *msg); |
---|
240 | void soup_message_io_pause (SoupMessage *msg); |
---|
241 | void soup_message_io_unpause (SoupMessage *msg); |
---|
242 | |
---|
243 | |
---|
244 | void soup_message_wrote_informational (SoupMessage *msg); |
---|
245 | void soup_message_wrote_headers (SoupMessage *msg); |
---|
246 | void soup_message_wrote_chunk (SoupMessage *msg); |
---|
247 | void soup_message_wrote_body (SoupMessage *msg); |
---|
248 | void soup_message_got_informational (SoupMessage *msg); |
---|
249 | void soup_message_got_headers (SoupMessage *msg); |
---|
250 | void soup_message_got_chunk (SoupMessage *msg); |
---|
251 | void soup_message_got_body (SoupMessage *msg); |
---|
252 | void soup_message_restarted (SoupMessage *msg); |
---|
253 | void soup_message_finished (SoupMessage *msg); |
---|
254 | |
---|
255 | #endif /*SOUP_MESSAGE_H*/ |
---|