Content-Encoding support
[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-message-body.h>
11 #include <libsoup/soup-message-headers.h>
12 #include <libsoup/soup-method.h>
13
14 G_BEGIN_DECLS
15
16 #define SOUP_TYPE_MESSAGE            (soup_message_get_type ())
17 #define SOUP_MESSAGE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), SOUP_TYPE_MESSAGE, SoupMessage))
18 #define SOUP_MESSAGE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), SOUP_TYPE_MESSAGE, SoupMessageClass))
19 #define SOUP_IS_MESSAGE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SOUP_TYPE_MESSAGE))
20 #define SOUP_IS_MESSAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), SOUP_TYPE_MESSAGE))
21 #define SOUP_MESSAGE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), SOUP_TYPE_MESSAGE, SoupMessageClass))
22
23 struct _SoupMessage {
24         GObject parent;
25
26         /*< public >*/
27         const char         *method;
28
29         guint               status_code;
30         char               *reason_phrase;
31
32         SoupMessageBody    *request_body;
33         SoupMessageHeaders *request_headers;
34
35         SoupMessageBody    *response_body;
36         SoupMessageHeaders *response_headers;
37 };
38
39 typedef struct {
40         GObjectClass parent_class;
41
42         /* signals */
43         void     (*wrote_informational) (SoupMessage *msg);
44         void     (*wrote_headers)       (SoupMessage *msg);
45         void     (*wrote_chunk)         (SoupMessage *msg);
46         void     (*wrote_body)          (SoupMessage *msg);
47         void     (*got_informational)   (SoupMessage *msg);
48         void     (*got_headers)         (SoupMessage *msg);
49         void     (*got_chunk)           (SoupMessage *msg, SoupBuffer *chunk);
50         void     (*got_body)            (SoupMessage *msg);
51         void     (*restarted)           (SoupMessage *msg);
52         void     (*finished)            (SoupMessage *msg);
53
54         /* Padding for future expansion */
55         void (*_libsoup_reserved1) (void);
56         void (*_libsoup_reserved2) (void);
57         void (*_libsoup_reserved3) (void);
58         void (*_libsoup_reserved4) (void);
59 } SoupMessageClass;
60
61 GType soup_message_get_type (void);
62
63 #define SOUP_MESSAGE_METHOD        "method"
64 #define SOUP_MESSAGE_URI           "uri"
65 #define SOUP_MESSAGE_HTTP_VERSION  "http-version"
66 #define SOUP_MESSAGE_FLAGS         "flags"
67 #define SOUP_MESSAGE_SERVER_SIDE   "server-side"
68 #define SOUP_MESSAGE_STATUS_CODE   "status-code"
69 #define SOUP_MESSAGE_REASON_PHRASE "reason-phrase"
70
71 SoupMessage   *soup_message_new                 (const char        *method,
72                                                  const char        *uri_string);
73 SoupMessage   *soup_message_new_from_uri        (const char        *method,
74                                                  SoupURI           *uri);
75
76 void           soup_message_set_request         (SoupMessage       *msg,
77                                                  const char        *content_type,
78                                                  SoupMemoryUse      req_use,
79                                                  const char        *req_body,
80                                                  gsize              req_length);
81 void           soup_message_set_response        (SoupMessage       *msg,
82                                                  const char        *content_type,
83                                                  SoupMemoryUse      resp_use,
84                                                  const char        *resp_body,
85                                                  gsize              resp_length);
86
87 typedef enum {
88         SOUP_HTTP_1_0 = 0,
89         SOUP_HTTP_1_1 = 1
90 } SoupHTTPVersion;
91
92 void             soup_message_set_http_version    (SoupMessage       *msg,
93                                                    SoupHTTPVersion    version);
94 SoupHTTPVersion  soup_message_get_http_version    (SoupMessage       *msg);
95
96 gboolean         soup_message_is_keepalive        (SoupMessage       *msg);
97
98 SoupURI         *soup_message_get_uri             (SoupMessage       *msg);
99 void             soup_message_set_uri             (SoupMessage       *msg,
100                                                    SoupURI           *uri);
101 SoupAddress     *soup_message_get_address         (SoupMessage       *msg);
102
103 typedef enum {
104         SOUP_MESSAGE_NO_REDIRECT      = (1 << 1),
105 #ifndef LIBSOUP_DISABLE_DEPRECATED
106         SOUP_MESSAGE_OVERWRITE_CHUNKS = (1 << 3),
107 #endif
108         SOUP_MESSAGE_CONTENT_DECODED  = (1 << 4)
109 } SoupMessageFlags;
110
111 void           soup_message_set_flags           (SoupMessage        *msg,
112                                                  SoupMessageFlags    flags);
113
114 SoupMessageFlags soup_message_get_flags         (SoupMessage        *msg);
115
116 /* Specialized signal handlers */
117 guint          soup_message_add_header_handler  (SoupMessage       *msg,
118                                                  const char        *signal,
119                                                  const char        *header,
120                                                  GCallback          callback,
121                                                  gpointer           user_data);
122
123 guint          soup_message_add_status_code_handler (
124                                                  SoupMessage       *msg,
125                                                  const char        *signal,
126                                                  guint              status_code,
127                                                  GCallback          callback,
128                                                  gpointer           user_data);
129
130 /*
131  * Status Setting
132  */
133 void           soup_message_set_status          (SoupMessage       *msg, 
134                                                  guint              status_code);
135
136 void           soup_message_set_status_full     (SoupMessage       *msg, 
137                                                  guint              status_code, 
138                                                  const char        *reason_phrase);
139
140 /* I/O */
141 typedef SoupBuffer * (*SoupChunkAllocator)      (SoupMessage       *msg,
142                                                  gsize              max_len,
143                                                  gpointer           user_data);
144
145 void           soup_message_set_chunk_allocator (SoupMessage       *msg,
146                                                  SoupChunkAllocator allocator,
147                                                  gpointer           user_data,
148                                                  GDestroyNotify     destroy_notify);
149
150 void           soup_message_disable_feature     (SoupMessage       *msg,
151                                                  GType              feature_type);
152
153 void soup_message_wrote_informational (SoupMessage *msg);
154 void soup_message_wrote_headers       (SoupMessage *msg);
155 void soup_message_wrote_chunk         (SoupMessage *msg);
156 void soup_message_wrote_body_data     (SoupMessage *msg, SoupBuffer *chunk);
157 void soup_message_wrote_body          (SoupMessage *msg);
158 void soup_message_got_informational   (SoupMessage *msg);
159 void soup_message_got_headers         (SoupMessage *msg);
160 void soup_message_got_chunk           (SoupMessage *msg, SoupBuffer *chunk);
161 void soup_message_got_body            (SoupMessage *msg);
162 void soup_message_content_sniffed     (SoupMessage *msg, const char *content_type, GHashTable *params);
163 void soup_message_restarted           (SoupMessage *msg);
164 void soup_message_finished            (SoupMessage *msg);
165
166 G_END_DECLS
167
168 #endif /*SOUP_MESSAGE_H*/