tizen 2.3.1 release
[external/gupnp.git] / libgupnp / gupnp-error.c
1 /*
2  * Copyright (C) 2006, 2007 OpenedHand Ltd.
3  *
4  * Author: Jorn Baayen <jorn@openedhand.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #include "gupnp-error.h"
23 #include "gupnp-error-private.h"
24
25 /**
26  * SECTION:gupnp-error
27  * @short_description: Error domains and codes.
28  */
29
30 /**
31  * GUPNP_SERVER_ERROR:
32  *
33  * The #GQuark uniquely used by GUPnP's server errors.
34  *
35  * Returns: a #GQuark uniquely used by GUPnP's server errors.
36  **/
37 GQuark
38 gupnp_server_error_quark (void)
39 {
40         static GQuark quark = 0;
41
42         if (!quark)
43                 quark = g_quark_from_static_string ("gupnp-server-error");
44
45         return quark;
46 }
47
48 /**
49  * GUPNP_EVENTING_ERROR:
50  *
51  * The #GQuark uniquely used by GUPnP's eventing errors.
52  *
53  * Returns: a #GQuark uniquely used by GUPnP's eventing errors.
54  **/
55 GQuark
56 gupnp_eventing_error_quark (void)
57 {
58         static GQuark quark = 0;
59
60         if (!quark)
61                 quark = g_quark_from_static_string ("gupnp-eventing-error");
62
63         return quark;
64 }
65
66 /**
67  * GUPNP_CONTROL_ERROR:
68  *
69  * The #GQuark uniquely used by GUPnP's control errors.
70  *
71  * Returns: a #GQuark uniquely used by GUPnP's control errors.
72  **/
73 GQuark
74 gupnp_control_error_quark (void)
75 {
76         static GQuark quark = 0;
77
78         if (!quark)
79                 quark = g_quark_from_static_string ("gupnp-control-error");
80
81         return quark;
82 }
83
84 /**
85  * GUPNP_XML_ERROR:
86  *
87  * The #GQuark uniquely used by GUPnP XML processing errors.
88  *
89  * Returns: a #GQuark uniquely used by GUPnP XML processing errors.
90  **/
91 GQuark
92 gupnp_xml_error_quark (void)
93 {
94         static GQuark quark = 0;
95
96         if (!quark)
97                 quark = g_quark_from_static_string ("gupnp-xml-error");
98
99         return quark;
100 }
101
102 /* Soup status code => GUPnPServerError */
103 static int
104 code_from_status_code (int status_code)
105 {
106         switch (status_code) {
107         case SOUP_STATUS_INTERNAL_SERVER_ERROR:
108                 return GUPNP_SERVER_ERROR_INTERNAL_SERVER_ERROR;
109         case SOUP_STATUS_NOT_IMPLEMENTED:
110                 return GUPNP_SERVER_ERROR_NOT_IMPLEMENTED;
111         case SOUP_STATUS_NOT_FOUND:
112                 return GUPNP_SERVER_ERROR_NOT_FOUND;
113         default:
114                 return GUPNP_SERVER_ERROR_OTHER;
115         }
116 }
117
118 /* Set status of @msg to @error */
119 void
120 _gupnp_error_set_server_error (GError     **error,
121                                SoupMessage *msg)
122 {
123         g_set_error_literal (error,
124                              GUPNP_SERVER_ERROR,
125                              code_from_status_code (msg->status_code),
126                              msg->reason_phrase);
127 }
128
129 /* Create a #GError with status of @msg */
130 GError *
131 _gupnp_error_new_server_error (SoupMessage *msg)
132 {
133         return g_error_new_literal (GUPNP_SERVER_ERROR,
134                                     code_from_status_code (msg->status_code),
135                                     msg->reason_phrase);
136 }