index.html
Main Page
|
modules.html
Modules
|
namespaces.html
Namespace List
|
hierarchy.html
Class Hierarchy
|
annotated.html
Data Structures
|
dirs.html
Directories
|
files.html
File List
|
namespacemembers.html
Namespace Members
|
functions.html
Data Fields
|
pages.html
Related Pages
dir_000004.html
dbus
dbus-errors.c
00001
/* -*- mode: C; c-file-style: "gnu" -*- */
00002
/* dbus-errors.c Error reporting
00003
*
00004
* Copyright (C) 2002, 2004  Red Hat Inc.
00005
* Copyright (C) 2003  CodeFactory AB
00006
*
00007
* Licensed under the Academic Free License version 2.1
00008
*
00009
* This program is free software; you can redistribute it and/or modify
00010
* it under the terms of the GNU General Public License as published by
00011
* the Free Software Foundation; either version 2 of the License, or
00012
* (at your option) any later version.
00013
*
00014
* This program is distributed in the hope that it will be useful,
00015
* but WITHOUT ANY WARRANTY; without even the implied warranty of
00016
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017
* GNU General Public License for more details.
00018
*
00019
* You should have received a copy of the GNU General Public License
00020
* along with this program; if not, write to the Free Software
00021
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022
*
00023
*/
00024
#include "dbus-errors.h"
00025
#include "dbus-internals.h"
00026
#include "dbus-string.h"
00027
#include "dbus-protocol.h"
00028
#include <stdarg.h>
00029
#include <string.h>
00030
structDBusRealError.html
00041
typedef
struct
00042
{
structDBusRealError.html#o0
00043
const
char
*name;
structDBusRealError.html#o1
00044
char
*message;
structDBusRealError.html#o2
00046
unsigned
int
const_message : 1;
structDBusRealError.html#o3
00048
unsigned
int
dummy2 : 1;
structDBusRealError.html#o4
00049
unsigned
int
dummy3 : 1;
structDBusRealError.html#o5
00050
unsigned
int
dummy4 : 1;
structDBusRealError.html#o6
00051
unsigned
int
dummy5 : 1;
structDBusRealError.html#o7
00053
void
*padding1;
00055 }
structDBusRealError.html
DBusRealError
;
00056
00065
static
const
char
*
00066 message_from_error (
const
char
*error)
00067 {
00068
if
(strcmp (error, DBUS_ERROR_FAILED) == 0)
00069
return
"Unknown error"
;
00070
else
if
(strcmp (error, DBUS_ERROR_NO_MEMORY) == 0)
00071
return
"Not enough memory available"
;
00072
else
if
(strcmp (error, DBUS_ERROR_IO_ERROR) == 0)
00073
return
"Error reading or writing data"
;
00074
else
if
(strcmp (error, DBUS_ERROR_BAD_ADDRESS) == 0)
00075
return
"Could not parse address"
;
00076
else
if
(strcmp (error, DBUS_ERROR_NOT_SUPPORTED) == 0)
00077
return
"Feature not supported"
;
00078
else
if
(strcmp (error, DBUS_ERROR_LIMITS_EXCEEDED) == 0)
00079
return
"Resource limits exceeded"
;
00080
else
if
(strcmp (error, DBUS_ERROR_ACCESS_DENIED) == 0)
00081
return
"Permission denied"
;
00082
else
if
(strcmp (error, DBUS_ERROR_AUTH_FAILED) == 0)
00083
return
"Could not authenticate to server"
;
00084
else
if
(strcmp (error, DBUS_ERROR_NO_SERVER) == 0)
00085
return
"No server available at address"
;
00086
else
if
(strcmp (error, DBUS_ERROR_TIMEOUT) == 0)
00087
return
"Connection timed out"
;
00088
else
if
(strcmp (error, DBUS_ERROR_NO_NETWORK) == 0)
00089
return
"Network unavailable"
;
00090
else
if
(strcmp (error, DBUS_ERROR_ADDRESS_IN_USE) == 0)
00091
return
"Address already in use"
;
00092
else
if
(strcmp (error, DBUS_ERROR_DISCONNECTED) == 0)
00093
return
"Disconnected."
;
00094
else
if
(strcmp (error, DBUS_ERROR_INVALID_ARGS) == 0)
00095
return
"Invalid arguments."
;
00096
else
if
(strcmp (error, DBUS_ERROR_NO_REPLY) == 0)
00097
return
"Did not get a reply message."
;
00098
else
if
(strcmp (error, DBUS_ERROR_FILE_NOT_FOUND) == 0)
00099
return
"File doesn't exist."
;
00100
else
00101
return
error;
00102 }
00103
/* End of internals */
00105
00150
void
group__DBusErrors.html#ga0
00151
group__DBusErrors.html#ga0
dbus_error_init
(
structDBusError.html
DBusError
*error)
00152 {
00153
structDBusRealError.html
DBusRealError
*real;
00154
00155   _dbus_return_if_fail (error !=
group__DBusMacros.html#ga4
NULL
);
00156
00157
group__DBusInternalsUtils.html#ga129
_dbus_assert
(
sizeof
(
structDBusError.html
DBusError
) ==
sizeof
(
structDBusRealError.html
DBusRealError
));
00158
00159   real = (DBusRealError *)error;
00160
00161   real->
structDBusRealError.html#o0
name
=
group__DBusMacros.html#ga4
NULL
;
00162   real->
structDBusRealError.html#o1
message
=
group__DBusMacros.html#ga4
NULL
;
00163
00164   real->
structDBusRealError.html#o2
const_message
=
group__DBusMacros.html#ga2
TRUE
;
00165 }
00166
00173
void
group__DBusErrors.html#ga1
00174
group__DBusErrors.html#ga1
dbus_error_free
(
structDBusError.html
DBusError
*error)
00175 {
00176
structDBusRealError.html
DBusRealError
*real;
00177
00178   _dbus_return_if_fail (error !=
group__DBusMacros.html#ga4
NULL
);
00179
00180   real = (
structDBusRealError.html
DBusRealError
*)error;
00181
00182
if
(!real->
structDBusRealError.html#o2
const_message
)
00183
group__DBusMemory.html#ga3
dbus_free
(real->
structDBusRealError.html#o1
message
);
00184
00185
group__DBusErrors.html#ga0
dbus_error_init
(error);
00186 }
00187
00200
void
group__DBusErrors.html#ga2
00201
group__DBusErrors.html#ga2
dbus_set_error_const
(
structDBusError.html
DBusError
*error,
00202
const
char
*name,
00203
const
char
*message)
00204 {
00205
structDBusRealError.html
DBusRealError
*real;
00206
00207   _dbus_return_if_error_is_set (error);
00208   _dbus_return_if_fail (name !=
group__DBusMacros.html#ga4
NULL
);
00209
00210
if
(error ==
group__DBusMacros.html#ga4
NULL
)
00211
return
;
00212
00213
group__DBusInternalsUtils.html#ga129
_dbus_assert
(error->
structDBusError.html#o0
name
==
group__DBusMacros.html#ga4
NULL
);
00214
group__DBusInternalsUtils.html#ga129
_dbus_assert
(error->
structDBusError.html#o1
message
==
group__DBusMacros.html#ga4
NULL
);
00215
00216
if
(message ==
group__DBusMacros.html#ga4
NULL
)
00217     message = message_from_error (name);
00218
00219   real = (
structDBusRealError.html
DBusRealError
*)error;
00220
00221   real->
structDBusRealError.html#o0
name
= name;
00222   real->
structDBusRealError.html#o1
message
= (
char
*)message;
00223   real->
structDBusRealError.html#o2
const_message
=
group__DBusMacros.html#ga2
TRUE
;
00224 }
00225
00236
void
group__DBusErrors.html#ga3
00237
group__DBusErrors.html#ga3
dbus_move_error
(
structDBusError.html
DBusError
*src,
00238
structDBusError.html
DBusError
*dest)
00239 {
00240   _dbus_return_if_error_is_set (dest);
00241
00242
if
(dest)
00243     {
00244
group__DBusErrors.html#ga1
dbus_error_free
(dest);
00245       *dest = *src;
00246
group__DBusErrors.html#ga0
dbus_error_init
(src);
00247     }
00248
else
00249
group__DBusErrors.html#ga1
dbus_error_free
(src);
00250 }
00251
00259
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusErrors.html#ga4
00260
group__DBusErrors.html#ga4
dbus_error_has_name
(
const
structDBusError.html
DBusError
*error,
00261
const
char
*name)
00262 {
00263   _dbus_return_val_if_fail (error !=
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga3
FALSE
);
00264   _dbus_return_val_if_fail (name !=
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga3
FALSE
);
00265
00266
group__DBusInternalsUtils.html#ga129
_dbus_assert
((error->
structDBusError.html#o0
name
!=
group__DBusMacros.html#ga4
NULL
&& error->
structDBusError.html#o1
message
!=
group__DBusMacros.html#ga4
NULL
) ||
00267                 (error->
structDBusError.html#o0
name
==
group__DBusMacros.html#ga4
NULL
&& error->
structDBusError.html#o1
message
==
group__DBusMacros.html#ga4
NULL
));
00268
00269
if
(error->
structDBusError.html#o0
name
!=
group__DBusMacros.html#ga4
NULL
)
00270     {
00271
structDBusString.html
DBusString
str1, str2;
00272
group__DBusString.html#ga7
_dbus_string_init_const
(&str1, error->
structDBusError.html#o0
name
);
00273
group__DBusString.html#ga7
_dbus_string_init_const
(&str2, name);
00274
return
group__DBusString.html#ga49
_dbus_string_equal
(&str1, &str2);
00275     }
00276
else
00277
return
group__DBusMacros.html#ga3
FALSE
;
00278 }
00279
00286
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusErrors.html#ga5
00287
group__DBusErrors.html#ga5
dbus_error_is_set
(
const
structDBusError.html
DBusError
*error)
00288 {
00289   _dbus_return_val_if_fail (error !=
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga3
FALSE
);
00290
group__DBusInternalsUtils.html#ga129
_dbus_assert
((error->
structDBusError.html#o0
name
!=
group__DBusMacros.html#ga4
NULL
&& error->
structDBusError.html#o1
message
!=
group__DBusMacros.html#ga4
NULL
) ||
00291                 (error->
structDBusError.html#o0
name
==
group__DBusMacros.html#ga4
NULL
&& error->
structDBusError.html#o1
message
==
group__DBusMacros.html#ga4
NULL
));
00292
return
error->
structDBusError.html#o0
name
!=
group__DBusMacros.html#ga4
NULL
;
00293 }
00294
00312
void
group__DBusErrors.html#ga6
00313
group__DBusErrors.html#ga6
dbus_set_error
(
structDBusError.html
DBusError
*error,
00314
const
char
*name,
00315
const
char
*format,
00316                 ...)
00317 {
00318
structDBusRealError.html
DBusRealError
*real;
00319
structDBusString.html
DBusString
str;
00320   va_list args;
00321
00322
if
(error ==
group__DBusMacros.html#ga4
NULL
)
00323
return
;
00324
00325
/* it's a bug to pile up errors */
00326   _dbus_return_if_error_is_set (error);
00327   _dbus_return_if_fail (name !=
group__DBusMacros.html#ga4
NULL
);
00328
00329
group__DBusInternalsUtils.html#ga129
_dbus_assert
(error->
structDBusError.html#o0
name
==
group__DBusMacros.html#ga4
NULL
);
00330
group__DBusInternalsUtils.html#ga129
_dbus_assert
(error->
structDBusError.html#o1
message
==
group__DBusMacros.html#ga4
NULL
);
00331
00332
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&str))
00333
goto
nomem;
00334
00335
if
(format ==
group__DBusMacros.html#ga4
NULL
)
00336     {
00337
if
(!
group__DBusString.html#ga27
_dbus_string_append
(&str,
00338                                 message_from_error (name)))
00339         {
00340
group__DBusString.html#ga9
_dbus_string_free
(&str);
00341
goto
nomem;
00342         }
00343     }
00344
else
00345     {
00346       va_start (args, format);
00347
if
(!
group__DBusString.html#ga32
_dbus_string_append_printf_valist
(&str, format, args))
00348         {
00349
group__DBusString.html#ga9
_dbus_string_free
(&str);
00350
goto
nomem;
00351         }
00352       va_end (args);
00353     }
00354
00355   real = (
structDBusRealError.html
DBusRealError
*)error;
00356
00357
if
(!
group__DBusString.html#ga16
_dbus_string_steal_data
(&str, &real->
structDBusRealError.html#o1
message
))
00358     {
00359
group__DBusString.html#ga9
_dbus_string_free
(&str);
00360
goto
nomem;
00361     }
00362
00363   real->
structDBusRealError.html#o0
name
= name;
00364   real->
structDBusRealError.html#o2
const_message
=
group__DBusMacros.html#ga3
FALSE
;
00365
00366
group__DBusString.html#ga9
_dbus_string_free
(&str);
00367
00368
return
;
00369
00370  nomem:
00371   _DBUS_SET_OOM (error);
00372 }
00373
/* End public API */
Generated on Tue Sep 13 00:15:24 2005 for D-BUS by
http://www.doxygen.org/index.html
doxygen
1.4.4
