Only set up a tunnel if the destination protocol is HTTPS.
[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_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_cancel              (SoupMessage       *msg);
106
107 void           soup_message_add_header          (GHashTable        *hash,
108                                                  const char        *name,
109                                                  const char        *value);
110
111 const char    *soup_message_get_header          (GHashTable        *hash,
112                                                  const char        *name);
113
114 const GSList  *soup_message_get_header_list     (GHashTable        *hash,
115                                                  const char        *name);
116
117 void           soup_message_foreach_header      (GHashTable        *hash,
118                                                  GHFunc             func,
119                                                  gpointer           user_data);
120
121 void           soup_message_remove_header       (GHashTable        *hash,
122                                                  const char        *name);
123
124 void           soup_message_clear_headers       (GHashTable        *hash);
125
126 typedef enum {
127         SOUP_HTTP_1_0 = 0,
128         SOUP_HTTP_1_1 = 1
129 } SoupHttpVersion;
130
131 void             soup_message_set_http_version    (SoupMessage       *msg,
132                                                    SoupHttpVersion    version);
133 SoupHttpVersion  soup_message_get_http_version    (SoupMessage       *msg);
134
135 gboolean         soup_message_is_keepalive        (SoupMessage       *msg);
136
137 const SoupUri   *soup_message_get_uri             (SoupMessage       *msg);
138 void             soup_message_set_uri             (SoupMessage       *msg,
139                                                    const SoupUri     *uri);
140
141 typedef enum {
142         /*
143          * SOUP_MESSAGE_NO_PIPELINE: 
144          * Use a currently unused connection or establish a new 
145          * connection when issuing this request.
146          */
147         SOUP_MESSAGE_NO_PIPELINE      = (1 << 0),
148
149         /*
150          * SOUP_MESSAGE_NO_REDIRECT: 
151          * Do not follow redirection responses.
152          */
153         SOUP_MESSAGE_NO_REDIRECT      = (1 << 1),
154
155         /*
156          * SOUP_MESSAGE_NO_COOKIE:
157          * Do not send cookie information with request, and do not 
158          * store cookie information from the response.
159          */
160         SOUP_MESSAGE_NO_COOKIE        = (1 << 2),
161
162         /*
163          * SOUP_MESSAGE_OVERWRITE_CHUNKS:
164          * Downloaded data chunks should not be stored in the response 
165          * data buffer.  Instead only send data to SOUP_HANDLER_BODY_CHUNK 
166          * handlers, then truncate the data buffer.
167          *
168          * Useful when the response is expected to be very large, and 
169          * storage in memory is not desired.
170          */
171         SOUP_MESSAGE_OVERWRITE_CHUNKS = (1 << 3),
172
173         /*
174          * SOUP_MESSAGE_EXPECT_CONTINUE: The message includes an
175          * "Expect: 100-continue" header, and we should not send the
176          * body until the Continue response has been received. (This
177          * is automatically set if there is an "Expect: 100-continue"
178          * header.)
179          */
180         SOUP_MESSAGE_EXPECT_CONTINUE = (1 << 4)
181 } SoupMessageFlags;
182
183 void           soup_message_set_flags           (SoupMessage        *msg,
184                                                  guint               flags);
185
186 guint          soup_message_get_flags           (SoupMessage        *msg);
187
188 /*
189  * Handler Registration 
190  */
191 typedef enum {
192         SOUP_HANDLER_POST_REQUEST = 1,
193         SOUP_HANDLER_PRE_BODY,
194         SOUP_HANDLER_BODY_CHUNK,
195         SOUP_HANDLER_POST_BODY
196 } SoupHandlerPhase;
197
198 void           soup_message_add_handler         (SoupMessage       *msg,
199                                                  SoupHandlerPhase   type,
200                                                  SoupMessageCallbackFn     handler_cb,
201                                                  gpointer           user_data);
202
203 void           soup_message_add_header_handler  (SoupMessage       *msg,
204                                                  const char        *header,
205                                                  SoupHandlerPhase   type,
206                                                  SoupMessageCallbackFn,
207                                                  gpointer           user_data);
208
209 void           soup_message_add_status_code_handler (
210                                                  SoupMessage       *msg,
211                                                  guint              status_code,
212                                                  SoupHandlerPhase   type,
213                                                  SoupMessageCallbackFn,
214                                                  gpointer           user_data);
215
216 void           soup_message_add_status_class_handler (
217                                                  SoupMessage       *msg,
218                                                  SoupStatusClass    status_class,
219                                                  SoupHandlerPhase   type,
220                                                  SoupMessageCallbackFn,
221                                                  gpointer           user_data);
222
223 void           soup_message_remove_handler      (SoupMessage       *msg, 
224                                                  SoupHandlerPhase   type,
225                                                  SoupMessageCallbackFn,
226                                                  gpointer           user_data);
227
228 /*
229  * Status Setting
230  */
231 void           soup_message_set_status          (SoupMessage       *msg, 
232                                                  guint              status_code);
233
234 void           soup_message_set_status_full     (SoupMessage       *msg, 
235                                                  guint              status_code, 
236                                                  const char        *reason_phrase);
237
238
239 /* Chunked encoding */
240 void           soup_message_add_chunk           (SoupMessage       *msg,
241                                                  SoupOwnership      owner,
242                                                  const char        *body,
243                                                  guint              length);
244 void           soup_message_add_final_chunk     (SoupMessage       *msg);
245
246 SoupDataBuffer*soup_message_pop_chunk           (SoupMessage       *msg);
247
248
249 /* I/O */
250 void           soup_message_send_request        (SoupMessage       *req,
251                                                  SoupSocket        *sock,
252                                                  gboolean           via_proxy);
253 void           soup_message_read_request        (SoupMessage       *req,
254                                                  SoupSocket        *sock);
255 void           soup_message_io_cancel           (SoupMessage       *msg);
256 void           soup_message_io_pause            (SoupMessage       *msg);
257 void           soup_message_io_unpause          (SoupMessage       *msg);
258
259
260 void soup_message_wrote_informational (SoupMessage *msg);
261 void soup_message_wrote_headers       (SoupMessage *msg);
262 void soup_message_wrote_chunk         (SoupMessage *msg);
263 void soup_message_wrote_body          (SoupMessage *msg);
264 void soup_message_got_informational   (SoupMessage *msg);
265 void soup_message_got_headers         (SoupMessage *msg);
266 void soup_message_got_chunk           (SoupMessage *msg);
267 void soup_message_got_body            (SoupMessage *msg);
268 void soup_message_restarted           (SoupMessage *msg);
269 void soup_message_finished            (SoupMessage *msg);
270
271 #endif /*SOUP_MESSAGE_H*/