Merge "Fix SIGSEV on freeing server domains list" into tizen
[platform/upstream/connman.git] / src / error.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2013  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program 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
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <errno.h>
27 #include <string.h>
28
29 #include <gdbus.h>
30
31 #include "connman.h"
32
33 DBusMessage *__connman_error_failed(DBusMessage *msg, int errnum)
34 {
35         const char *str = strerror(errnum);
36
37         switch (errnum) {
38         case ESRCH:
39                 return __connman_error_not_registered(msg);
40         case ENXIO:
41                 return __connman_error_not_found(msg);
42         case EPERM:
43         case EACCES:
44                 return __connman_error_permission_denied(msg);
45         case EEXIST:
46                 return __connman_error_already_exists(msg);
47         case EINVAL:
48                 return __connman_error_invalid_arguments(msg);
49         case ENOSYS:
50                 return __connman_error_not_implemented(msg);
51         case ENOLINK:
52                 return __connman_error_no_carrier(msg);
53         case ENOTUNIQ:
54                 return __connman_error_not_unique(msg);
55         case EOPNOTSUPP:
56                 return __connman_error_not_supported(msg);
57         case ECONNABORTED:
58                 return __connman_error_operation_aborted(msg);
59         case EISCONN:
60                 return __connman_error_already_connected(msg);
61         case ENOTCONN:
62         case ECONNREFUSED:
63                 return __connman_error_not_connected(msg);
64         case ETIMEDOUT:
65                 return __connman_error_operation_timeout(msg);
66         case EALREADY:
67         case EINPROGRESS:
68                 return __connman_error_in_progress(msg);
69         case ENOKEY:
70                 return __connman_error_passphrase_required(msg);
71         case ECANCELED:
72                 return __connman_error_operation_canceled(msg);
73         }
74
75         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
76                                         ".Failed", "%s", str);
77 }
78
79 DBusMessage *__connman_error_invalid_arguments(DBusMessage *msg)
80 {
81         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
82                                 ".InvalidArguments", "Invalid arguments");
83 }
84
85 DBusMessage *__connman_error_permission_denied(DBusMessage *msg)
86 {
87         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
88                                 ".PermissionDenied", "Permission denied");
89 }
90
91 DBusMessage *__connman_error_passphrase_required(DBusMessage *msg)
92 {
93         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
94                                 ".PassphraseRequired", "Passphrase required");
95 }
96
97 DBusMessage *__connman_error_not_registered(DBusMessage *msg)
98 {
99         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
100                                         ".NotRegistered", "Not registered");
101 }
102
103 DBusMessage *__connman_error_not_unique(DBusMessage *msg)
104 {
105         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
106                                         ".NotUnique", "Not unique");
107 }
108
109 DBusMessage *__connman_error_not_supported(DBusMessage *msg)
110 {
111         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
112                                         ".NotSupported", "Not supported");
113 }
114
115 DBusMessage *__connman_error_not_implemented(DBusMessage *msg)
116 {
117         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
118                                         ".NotImplemented", "Not implemented");
119 }
120
121 DBusMessage *__connman_error_not_found(DBusMessage *msg)
122 {
123         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
124                                                 ".NotFound", "Not found");
125 }
126
127 DBusMessage *__connman_error_no_carrier(DBusMessage *msg)
128 {
129         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
130                                                 ".NoCarrier", "No carrier");
131 }
132
133 DBusMessage *__connman_error_in_progress(DBusMessage *msg)
134 {
135         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
136                                                 ".InProgress", "In progress");
137 }
138
139 DBusMessage *__connman_error_already_exists(DBusMessage *msg)
140 {
141         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
142                                 ".AlreadyExists", "Already exists");
143 }
144
145 DBusMessage *__connman_error_already_enabled(DBusMessage *msg)
146 {
147         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
148                                 ".AlreadyEnabled", "Already enabled");
149 }
150
151 DBusMessage *__connman_error_already_disabled(DBusMessage *msg)
152 {
153         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
154                                 ".AlreadyDisabled", "Already disabled");
155 }
156
157 DBusMessage *__connman_error_already_connected(DBusMessage *msg)
158 {
159         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
160                                 ".AlreadyConnected", "Already connected");
161 }
162
163 DBusMessage *__connman_error_not_connected(DBusMessage *msg)
164 {
165         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
166                                         ".NotConnected", "Not connected");
167 }
168 DBusMessage *__connman_error_operation_aborted(DBusMessage *msg)
169 {
170         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
171                                 ".OperationAborted", "Operation aborted");
172 }
173
174 DBusMessage *__connman_error_operation_timeout(DBusMessage *msg)
175 {
176         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
177                                 ".OperationTimeout", "Operation timeout");
178 }
179
180 DBusMessage *__connman_error_invalid_service(DBusMessage *msg)
181 {
182         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
183                                 ".InvalidService", "Invalid service");
184 }
185
186 DBusMessage *__connman_error_invalid_property(DBusMessage *msg)
187 {
188         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
189                                 ".InvalidProperty", "Invalid property");
190 }
191
192 #if defined TIZEN_EXT_WIFI_MESH
193 DBusMessage *__connman_error_invalid_command(DBusMessage *msg)
194 {
195         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
196                                 ".InvalidCommand", "Invalid Mesh Command");
197 }
198
199 DBusMessage *__connman_error_scan_abort_failed(DBusMessage *msg)
200 {
201         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
202                                 ".ScanAbortFailed", "Scan Abort Failed");
203 }
204 #endif
205
206 DBusMessage *__connman_error_operation_canceled(DBusMessage *msg)
207 {
208         return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
209                                 ".OperationCanceled", "Operation canceled");
210 }