Reapplying patch to disable attempts to use gtk-doc
[profile/ivi/libsoup2.4.git] / libsoup / soup-status.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * soup-status.c: Status code descriptions
4  *
5  * Copyright (C) 2001-2003, Ximian, Inc.
6  */
7
8 #include "config.h"
9
10 #include <glib.h>
11
12 #include "soup-status.h"
13
14 /**
15  * SECTION:soup-status
16  * @short_description: HTTP (and libsoup) status codes
17  *
18  **/
19
20 /**
21  * SOUP_STATUS_IS_TRANSPORT_ERROR:
22  * @status: a status code
23  *
24  * Tests if @status is a libsoup transport error.
25  *
26  * Return value: %TRUE or %FALSE
27  **/
28 /**
29  * SOUP_STATUS_IS_INFORMATIONAL:
30  * @status: an HTTP status code
31  *
32  * Tests if @status is an Informational (1xx) response.
33  *
34  * Return value: %TRUE or %FALSE
35  **/
36 /**
37  * SOUP_STATUS_IS_SUCCESSFUL:
38  * @status: an HTTP status code
39  *
40  * Tests if @status is a Successful (2xx) response.
41  *
42  * Return value: %TRUE or %FALSE
43  **/
44 /**
45  * SOUP_STATUS_IS_REDIRECTION:
46  * @status: an HTTP status code
47  *
48  * Tests if @status is a Redirection (3xx) response.
49  *
50  * Return value: %TRUE or %FALSE
51  **/
52 /**
53  * SOUP_STATUS_IS_CLIENT_ERROR:
54  * @status: an HTTP status code
55  *
56  * Tests if @status is a Client Error (4xx) response.
57  *
58  * Return value: %TRUE or %FALSE
59  **/
60 /**
61  * SOUP_STATUS_IS_SERVER_ERROR:
62  * @status: an HTTP status code
63  *
64  * Tests if @status is a Server Error (5xx) response.
65  *
66  * Return value: %TRUE or %FALSE
67  **/
68
69 /**
70  * SoupKnownStatusCode:
71  * @SOUP_STATUS_NONE: No status available. (Eg, the message has not
72  * been sent yet)
73  * @SOUP_STATUS_CANCELLED: Message was cancelled locally
74  * @SOUP_STATUS_CANT_RESOLVE: Unable to resolve destination host name
75  * @SOUP_STATUS_CANT_RESOLVE_PROXY: Unable to resolve proxy host name
76  * @SOUP_STATUS_CANT_CONNECT: Unable to connect to remote host
77  * @SOUP_STATUS_CANT_CONNECT_PROXY: Unable to connect to proxy
78  * @SOUP_STATUS_SSL_FAILED: SSL/TLS negotiation failed
79  * @SOUP_STATUS_IO_ERROR: A network error occurred, or the other end
80  * closed the connection unexpectedly
81  * @SOUP_STATUS_MALFORMED: Malformed data (usually a programmer error)
82  * @SOUP_STATUS_TRY_AGAIN: Used internally
83  * @SOUP_STATUS_TOO_MANY_REDIRECTS: There were too many redirections
84  * @SOUP_STATUS_TLS_FAILED: Used internally
85  * @SOUP_STATUS_CONTINUE: 100 Continue (HTTP)
86  * @SOUP_STATUS_SWITCHING_PROTOCOLS: 101 Switching Protocols (HTTP)
87  * @SOUP_STATUS_PROCESSING: 102 Processing (WebDAV)
88  * @SOUP_STATUS_OK: 200 Success (HTTP). Also used by many lower-level
89  * soup routines to indicate success.
90  * @SOUP_STATUS_CREATED: 201 Created (HTTP)
91  * @SOUP_STATUS_ACCEPTED: 202 Accepted (HTTP)
92  * @SOUP_STATUS_NON_AUTHORITATIVE: 203 Non-Authoritative Information
93  * (HTTP)
94  * @SOUP_STATUS_NO_CONTENT: 204 No Content (HTTP)
95  * @SOUP_STATUS_RESET_CONTENT: 205 Reset Content (HTTP)
96  * @SOUP_STATUS_PARTIAL_CONTENT: 206 Partial Content (HTTP)
97  * @SOUP_STATUS_MULTI_STATUS: 207 Multi-Status (WebDAV)
98  * @SOUP_STATUS_MULTIPLE_CHOICES: 300 Multiple Choices (HTTP)
99  * @SOUP_STATUS_MOVED_PERMANENTLY: 301 Moved Permanently (HTTP)
100  * @SOUP_STATUS_FOUND: 302 Found (HTTP)
101  * @SOUP_STATUS_MOVED_TEMPORARILY: 302 Moved Temporarily (old name,
102  * RFC 2068)
103  * @SOUP_STATUS_SEE_OTHER: 303 See Other (HTTP)
104  * @SOUP_STATUS_NOT_MODIFIED: 304 Not Modified (HTTP)
105  * @SOUP_STATUS_USE_PROXY: 305 Use Proxy (HTTP)
106  * @SOUP_STATUS_NOT_APPEARING_IN_THIS_PROTOCOL: 306 [Unused] (HTTP)
107  * @SOUP_STATUS_TEMPORARY_REDIRECT: 307 Temporary Redirect (HTTP)
108  * @SOUP_STATUS_BAD_REQUEST: 400 Bad Request (HTTP)
109  * @SOUP_STATUS_UNAUTHORIZED: 401 Unauthorized (HTTP)
110  * @SOUP_STATUS_PAYMENT_REQUIRED: 402 Payment Required (HTTP)
111  * @SOUP_STATUS_FORBIDDEN: 403 Forbidden (HTTP)
112  * @SOUP_STATUS_NOT_FOUND: 404 Not Found (HTTP)
113  * @SOUP_STATUS_METHOD_NOT_ALLOWED: 405 Method Not Allowed (HTTP)
114  * @SOUP_STATUS_NOT_ACCEPTABLE: 406 Not Acceptable (HTTP)
115  * @SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED: 407 Proxy Authentication
116  * Required (HTTP)
117  * @SOUP_STATUS_PROXY_UNAUTHORIZED: shorter alias for
118  * %SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED
119  * @SOUP_STATUS_REQUEST_TIMEOUT: 408 Request Timeout (HTTP)
120  * @SOUP_STATUS_CONFLICT: 409 Conflict (HTTP)
121  * @SOUP_STATUS_GONE: 410 Gone (HTTP)
122  * @SOUP_STATUS_LENGTH_REQUIRED: 411 Length Required (HTTP)
123  * @SOUP_STATUS_PRECONDITION_FAILED: 412 Precondition Failed (HTTP)
124  * @SOUP_STATUS_REQUEST_ENTITY_TOO_LARGE: 413 Request Entity Too Large
125  * (HTTP)
126  * @SOUP_STATUS_REQUEST_URI_TOO_LONG: 414 Request-URI Too Long (HTTP)
127  * @SOUP_STATUS_UNSUPPORTED_MEDIA_TYPE: 415 Unsupported Media Type
128  * (HTTP)
129  * @SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE: 416 Requested Range
130  * Not Satisfiable (HTTP)
131  * @SOUP_STATUS_INVALID_RANGE: shorter alias for
132  * %SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE
133  * @SOUP_STATUS_EXPECTATION_FAILED: 417 Expectation Failed (HTTP)
134  * @SOUP_STATUS_UNPROCESSABLE_ENTITY: 422 Unprocessable Entity
135  * (WebDAV)
136  * @SOUP_STATUS_LOCKED: 423 Locked (WebDAV)
137  * @SOUP_STATUS_FAILED_DEPENDENCY: 424 Failed Dependency (WebDAV)
138  * @SOUP_STATUS_INTERNAL_SERVER_ERROR: 500 Internal Server Error
139  * (HTTP)
140  * @SOUP_STATUS_NOT_IMPLEMENTED: 501 Not Implemented (HTTP)
141  * @SOUP_STATUS_BAD_GATEWAY: 502 Bad Gateway (HTTP)
142  * @SOUP_STATUS_SERVICE_UNAVAILABLE: 503 Service Unavailable (HTTP)
143  * @SOUP_STATUS_GATEWAY_TIMEOUT: 504 Gateway Timeout (HTTP)
144  * @SOUP_STATUS_HTTP_VERSION_NOT_SUPPORTED: 505 HTTP Version Not
145  * Supported (HTTP)
146  * @SOUP_STATUS_INSUFFICIENT_STORAGE: 507 Insufficient Storage
147  * (WebDAV)
148  * @SOUP_STATUS_NOT_EXTENDED: 510 Not Extended (RFC 2774)
149  * 
150  * These represent the known HTTP status code values, plus various
151  * network and internal errors.
152  **/
153
154 /**
155  * SOUP_HTTP_ERROR:
156  *
157  * A #GError domain representing an HTTP status. Use a
158  * #SoupKnownStatusCode for the <structfield>code</structfield>
159  * value.
160  **/
161
162
163 /* The reason_phrases are not localized because:
164  *
165  * 1. Only ASCII can be used portably in the HTTP Status-Line, so we
166  *    would not be able to return localized reason phrases from
167  *    SoupServer anyway.
168  *
169  * 2. Having a way for clients to get a localized version of a status
170  *    code would just encourage them to present those strings to the
171  *    user, which is bad because many of them are fairly
172  *    incomprehensible anyway.
173  */
174
175 static const struct {
176         guint code;
177         const char *phrase;
178 } reason_phrases [] = {
179         /* Transport errors */
180         { SOUP_STATUS_CANCELLED,                  "Cancelled" },
181         { SOUP_STATUS_CANT_RESOLVE,               "Cannot resolve hostname" },
182         { SOUP_STATUS_CANT_RESOLVE_PROXY,         "Cannot resolve proxy hostname" },
183         { SOUP_STATUS_CANT_CONNECT,               "Cannot connect to destination" },
184         { SOUP_STATUS_CANT_CONNECT_PROXY,         "Cannot connect to proxy" },
185         { SOUP_STATUS_SSL_FAILED,                 "SSL handshake failed" },
186         { SOUP_STATUS_IO_ERROR,                   "Connection terminated unexpectedly" },
187         { SOUP_STATUS_MALFORMED,                  "Message Corrupt" },
188         { SOUP_STATUS_TOO_MANY_REDIRECTS,         "Too many redirects" },
189
190         /* Informational */
191         { SOUP_STATUS_CONTINUE,                   "Continue" },
192         { SOUP_STATUS_SWITCHING_PROTOCOLS,        "Switching Protocols" },
193         { SOUP_STATUS_PROCESSING,                 "Processing" },
194
195         /* Success */
196         { SOUP_STATUS_OK,                         "OK" },
197         { SOUP_STATUS_CREATED,                    "Created" },
198         { SOUP_STATUS_ACCEPTED,                   "Accepted" },
199         { SOUP_STATUS_NON_AUTHORITATIVE,          "Non-Authoritative Information" },
200         { SOUP_STATUS_NO_CONTENT,                 "No Content" },
201         { SOUP_STATUS_RESET_CONTENT,              "Reset Content" },
202         { SOUP_STATUS_PARTIAL_CONTENT,            "Partial Content" },
203         { SOUP_STATUS_MULTI_STATUS,               "Multi-Status" },
204
205         /* Redirection */
206         { SOUP_STATUS_MULTIPLE_CHOICES,           "Multiple Choices" },
207         { SOUP_STATUS_MOVED_PERMANENTLY,          "Moved Permanently" },
208         { SOUP_STATUS_FOUND,                      "Found" },
209         { SOUP_STATUS_SEE_OTHER,                  "See Other" },
210         { SOUP_STATUS_NOT_MODIFIED,               "Not Modified" },
211         { SOUP_STATUS_USE_PROXY,                  "Use Proxy" },
212         { SOUP_STATUS_TEMPORARY_REDIRECT,         "Temporary Redirect" },
213
214         /* Client error */
215         { SOUP_STATUS_BAD_REQUEST,                "Bad Request" },
216         { SOUP_STATUS_UNAUTHORIZED,               "Unauthorized" },
217         { SOUP_STATUS_PAYMENT_REQUIRED,           "Payment Required" },
218         { SOUP_STATUS_FORBIDDEN,                  "Forbidden" },
219         { SOUP_STATUS_NOT_FOUND,                  "Not Found" },
220         { SOUP_STATUS_METHOD_NOT_ALLOWED,         "Method Not Allowed" },
221         { SOUP_STATUS_NOT_ACCEPTABLE,             "Not Acceptable" },
222         { SOUP_STATUS_PROXY_UNAUTHORIZED,         "Proxy Authentication Required" },
223         { SOUP_STATUS_REQUEST_TIMEOUT,            "Request Timeout" },
224         { SOUP_STATUS_CONFLICT,                   "Conflict" },
225         { SOUP_STATUS_GONE,                       "Gone" },
226         { SOUP_STATUS_LENGTH_REQUIRED,            "Length Required" },
227         { SOUP_STATUS_PRECONDITION_FAILED,        "Precondition Failed" },
228         { SOUP_STATUS_REQUEST_ENTITY_TOO_LARGE,   "Request Entity Too Large" },
229         { SOUP_STATUS_REQUEST_URI_TOO_LONG,       "Request-URI Too Long" },
230         { SOUP_STATUS_UNSUPPORTED_MEDIA_TYPE,     "Unsupported Media Type" },
231         { SOUP_STATUS_INVALID_RANGE,              "Requested Range Not Satisfiable" },
232         { SOUP_STATUS_EXPECTATION_FAILED,         "Expectation Failed" },
233         { SOUP_STATUS_UNPROCESSABLE_ENTITY,       "Unprocessable Entity" },
234         { SOUP_STATUS_LOCKED,                     "Locked" },
235         { SOUP_STATUS_FAILED_DEPENDENCY,          "Failed Dependency" },
236
237         /* Server error */
238         { SOUP_STATUS_INTERNAL_SERVER_ERROR,      "Internal Server Error" },
239         { SOUP_STATUS_NOT_IMPLEMENTED,            "Not Implemented" },
240         { SOUP_STATUS_BAD_GATEWAY,                "Bad Gateway" },
241         { SOUP_STATUS_SERVICE_UNAVAILABLE,        "Service Unavailable" },
242         { SOUP_STATUS_GATEWAY_TIMEOUT,            "Gateway Timeout" },
243         { SOUP_STATUS_HTTP_VERSION_NOT_SUPPORTED, "HTTP Version Not Supported" },
244         { SOUP_STATUS_INSUFFICIENT_STORAGE,       "Insufficient Storage" },
245         { SOUP_STATUS_NOT_EXTENDED,               "Not Extended" },
246
247         { 0 }
248 };
249
250 /**
251  * soup_status_get_phrase:
252  * @status_code: an HTTP status code
253  *
254  * Looks up the stock HTTP description of @status_code. This is used
255  * by soup_message_set_status() to get the correct text to go with a
256  * given status code.
257  *
258  * <emphasis>There is no reason for you to ever use this
259  * function.</emphasis> If you wanted the textual description for the
260  * #SoupMessage:status_code of a given #SoupMessage, you should just
261  * look at the message's #SoupMessage:reason_phrase. However, you
262  * should only do that for use in debugging messages; HTTP reason
263  * phrases are not localized, and are not generally very descriptive
264  * anyway, and so they should never be presented to the user directly.
265  * Instead, you should create you own error messages based on the
266  * status code, and on what you were trying to do.
267  *
268  * Return value: the (terse, English) description of @status_code
269  **/
270 const char *
271 soup_status_get_phrase (guint status_code)
272 {
273         int i;
274
275         for (i = 0; reason_phrases [i].code; i++) {
276                 if (reason_phrases [i].code == status_code)
277                         return reason_phrases [i].phrase;
278         }
279
280         return "Unknown Error";
281 }
282
283 /**
284  * soup_status_proxify:
285  * @status_code: a status code
286  *
287  * Turns %SOUP_STATUS_CANT_RESOLVE into
288  * %SOUP_STATUS_CANT_RESOLVE_PROXY and %SOUP_STATUS_CANT_CONNECT into
289  * %SOUP_STATUS_CANT_CONNECT_PROXY. Other status codes are passed
290  * through unchanged.
291  *
292  * Return value: the "proxified" equivalent of @status_code.
293  *
294  * Since: 2.26
295  **/
296 guint
297 soup_status_proxify (guint status_code)
298 {
299         if (status_code == SOUP_STATUS_CANT_RESOLVE)
300                 return SOUP_STATUS_CANT_RESOLVE_PROXY;
301         else if (status_code == SOUP_STATUS_CANT_CONNECT)
302                 return SOUP_STATUS_CANT_CONNECT_PROXY;
303         else
304                 return status_code;
305 }
306
307 GQuark
308 soup_http_error_quark (void)
309 {
310         static GQuark error;
311         if (!error)
312                 error = g_quark_from_static_string ("soup_http_error_quark");
313         return error;
314 }