Replaces the three previous soup_connection_new* functions and uses
[platform/upstream/libsoup.git] / libsoup / soup-message.h
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_headers) (SoupMessage *msg);
73         void     (*wrote_chunk)   (SoupMessage *msg);
74         void     (*wrote_body)    (SoupMessage *msg);
75         void     (*got_headers)   (SoupMessage *msg);
76         void     (*got_chunk)     (SoupMessage *msg);
77         void     (*got_body)      (SoupMessage *msg);
78         void     (*finished)      (SoupMessage *msg);
79 } SoupMessageClass;
80
81 GType soup_message_get_type (void);
82
83 typedef void (*SoupMessageCallbackFn) (SoupMessage *req, gpointer user_data);
84
85 SoupMessage   *soup_message_new                 (const char        *method,
86                                                  const char        *uri);
87 SoupMessage   *soup_message_new_from_uri        (const char        *method,
88                                                  const SoupUri     *uri);
89
90 void           soup_message_set_request         (SoupMessage       *msg,
91                                                  const char        *content_type,
92                                                  SoupOwnership      req_owner,
93                                                  char              *req_body,
94                                                  gulong             req_len);
95
96 void           soup_message_set_response        (SoupMessage       *msg,
97                                                  const char        *content_type,
98                                                  SoupOwnership      resp_owner,
99                                                  char              *resp_body,
100                                                  gulong             resp_len);
101
102 void           soup_message_cancel              (SoupMessage       *req);
103
104 void           soup_message_prepare             (SoupMessage       *req);
105
106 void           soup_message_add_header          (GHashTable        *hash,
107                                                  const char        *name,
108                                                  const char        *value);
109
110 const char    *soup_message_get_header          (GHashTable        *hash,
111                                                  const char        *name);
112
113 const GSList  *soup_message_get_header_list     (GHashTable        *hash,
114                                                  const char        *name);
115
116 void           soup_message_foreach_header      (GHashTable        *hash,
117                                                  GHFunc             func,
118                                                  gpointer           user_data);
119
120 void           soup_message_remove_header       (GHashTable        *hash,
121                                                  const char        *name);
122
123 void           soup_message_clear_headers       (GHashTable        *hash);
124
125 typedef enum {
126         SOUP_HTTP_1_0 = 0,
127         SOUP_HTTP_1_1 = 1,
128 } SoupHttpVersion;
129
130 void             soup_message_set_http_version    (SoupMessage       *msg,
131                                                    SoupHttpVersion    version);
132 SoupHttpVersion  soup_message_get_http_version    (SoupMessage       *msg);
133
134 gboolean         soup_message_is_keepalive        (SoupMessage       *msg);
135
136 const SoupUri   *soup_message_get_uri             (SoupMessage       *msg);
137 void             soup_message_set_uri             (SoupMessage       *msg,
138                                                    const SoupUri     *uri);
139
140 typedef enum {
141         /*
142          * SOUP_MESSAGE_NO_PIPELINE: 
143          * Use a currently unused connection or establish a new 
144          * connection when issuing this request.
145          */
146         SOUP_MESSAGE_NO_PIPELINE      = (1 << 0),
147
148         /*
149          * SOUP_MESSAGE_NO_REDIRECT: 
150          * Do not follow redirection responses.
151          */
152         SOUP_MESSAGE_NO_REDIRECT      = (1 << 1),
153
154         /*
155          * SOUP_MESSAGE_NO_COOKIE:
156          * Do not send cookie information with request, and do not 
157          * store cookie information from the response.
158          */
159         SOUP_MESSAGE_NO_COOKIE        = (1 << 2),
160
161         /*
162          * SOUP_MESSAGE_OVERWRITE_CHUNKS:
163          * Downloaded data chunks should not be stored in the response 
164          * data buffer.  Instead only send data to SOUP_HANDLER_BODY_CHUNK 
165          * handlers, then truncate the data buffer.
166          *
167          * Useful when the response is expected to be very large, and 
168          * storage in memory is not desired.
169          */
170         SOUP_MESSAGE_OVERWRITE_CHUNKS = (1 << 3),
171
172         /*
173          * SOUP_MESSAGE_EXPECT_CONTINUE:
174          * The message includes an "Expect: 100-continue" header, and we
175          * should not send the body until the Continue response has been
176          * received. (This should be synchronized with the existence
177          * of the "Expect: 100-continue" header. FIXME!)
178          */
179         SOUP_MESSAGE_EXPECT_CONTINUE = (1 << 4)
180 } SoupMessageFlags;
181
182 void           soup_message_set_flags           (SoupMessage        *msg,
183                                                  guint               flags);
184
185 guint          soup_message_get_flags           (SoupMessage        *msg);
186
187 /*
188  * Handler Registration 
189  */
190 typedef enum {
191         SOUP_HANDLER_PRE_BODY = 1,
192         SOUP_HANDLER_BODY_CHUNK,
193         SOUP_HANDLER_POST_BODY
194 } SoupHandlerPhase;
195
196 void           soup_message_add_handler         (SoupMessage       *msg,
197                                                  SoupHandlerPhase   type,
198                                                  SoupMessageCallbackFn     handler_cb,
199                                                  gpointer           user_data);
200
201 void           soup_message_add_header_handler  (SoupMessage       *msg,
202                                                  const char        *header,
203                                                  SoupHandlerPhase   type,
204                                                  SoupMessageCallbackFn,
205                                                  gpointer           user_data);
206
207 void           soup_message_add_status_code_handler (
208                                                  SoupMessage       *msg,
209                                                  guint              status_code,
210                                                  SoupHandlerPhase   type,
211                                                  SoupMessageCallbackFn,
212                                                  gpointer           user_data);
213
214 void           soup_message_add_status_class_handler (
215                                                  SoupMessage       *msg,
216                                                  SoupStatusClass    status_class,
217                                                  SoupHandlerPhase   type,
218                                                  SoupMessageCallbackFn,
219                                                  gpointer           user_data);
220
221 void           soup_message_remove_handler      (SoupMessage       *msg, 
222                                                  SoupHandlerPhase   type,
223                                                  SoupMessageCallbackFn,
224                                                  gpointer           user_data);
225
226 /*
227  * Status Setting
228  */
229 void           soup_message_set_status          (SoupMessage       *msg, 
230                                                  guint              status_code);
231
232 void           soup_message_set_status_full     (SoupMessage       *msg, 
233                                                  guint              status_code, 
234                                                  const char        *reason_phrase);
235
236
237 /* Chunked encoding */
238 void           soup_message_add_chunk           (SoupMessage       *msg,
239                                                  SoupOwnership      owner,
240                                                  const char        *body,
241                                                  guint              length);
242 void           soup_message_add_final_chunk     (SoupMessage       *msg);
243
244 SoupDataBuffer*soup_message_pop_chunk           (SoupMessage       *msg);
245
246
247 /* I/O */
248 void           soup_message_send_request        (SoupMessage       *req,
249                                                  SoupSocket        *sock,
250                                                  gboolean           via_proxy);
251 void           soup_message_read_request        (SoupMessage       *req,
252                                                  SoupSocket        *sock);
253 void           soup_message_io_cancel           (SoupMessage       *msg);;
254 void           soup_message_io_pause            (SoupMessage       *msg);
255 void           soup_message_io_unpause          (SoupMessage       *msg);
256
257
258 void soup_message_wrote_headers  (SoupMessage *msg);
259 void soup_message_wrote_chunk    (SoupMessage *msg);
260 void soup_message_wrote_body     (SoupMessage *msg);
261 void soup_message_got_headers    (SoupMessage *msg);
262 void soup_message_got_chunk      (SoupMessage *msg);
263 void soup_message_got_body       (SoupMessage *msg);
264 void soup_message_finished       (SoupMessage *msg);
265
266 #endif /*SOUP_MESSAGE_H*/