Add.
[shishi.git] / db / err.c
blobc3ed0bc36f44cf42abc39b7925d3c72a7ecca4b4
1 /* error.c --- Error handling functions for the Shisa library.
2 * Copyright (C) 2002, 2003, 2004, 2006 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Shishi 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.
16 * You should have received a copy of the GNU General Public License
17 * along with Shishi; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "info.h"
24 struct shisa_error_msgs
26 int errorcode;
27 const char *message;
30 static const struct shisa_error_msgs _shisa_error_messages[] = {
31 {SHISA_OK,
32 N_("Shisa success")},
33 {SHISA_INIT_ERROR,
34 N_("Shisa could not be initialized.")},
35 {SHISA_CFG_NO_FILE,
36 N_("The Shisa configuration file does not exist.")},
37 {SHISA_CFG_IO_ERROR,
38 N_("File I/O error for Shisa configuration file.")},
39 {SHISA_CFG_SYNTAX_ERROR,
40 N_("Syntax error in Shisa configuration token.")},
41 {SHISA_OPEN_ERROR,
42 N_("Shisa database could not be opened.")},
43 {SHISA_ENUMERATE_REALM_ERROR,
44 N_("Error enumerating realms in database.")},
45 {SHISA_ENUMERATE_PRINCIPAL_ERROR,
46 N_("Error enumerating principals in database.")},
47 {SHISA_ENUMERATE_KEY_ERROR,
48 N_("Error enumerating keys in database.")},
49 {SHISA_NO_REALM,
50 N_("Supplied realm does not exist.")},
51 {SHISA_NO_PRINCIPAL,
52 N_("Supplied principal does not exist.")},
53 {SHISA_NO_KEY,
54 N_("Principal is not associated with any matching key.")},
55 {SHISA_FIND_ERROR,
56 N_("Error finding principal.")},
57 {SHISA_ADD_REALM_EXISTS,
58 N_("Tried to add a realm that already exist.")},
59 {SHISA_ADD_REALM_ERROR,
60 N_("Error adding realm to database.")},
61 {SHISA_REMOVE_REALM_NONEMPTY,
62 N_("Tried to remove a non-empty realm.")},
63 {SHISA_REMOVE_REALM_ERROR,
64 N_("Error removing realm from database.")},
65 {SHISA_ADD_PRINCIPAL_EXISTS,
66 N_("Tried to add a principal that already exist.")},
67 {SHISA_ADD_PRINCIPAL_ERROR,
68 N_("Error adding principal to database.")},
69 {SHISA_REMOVE_PRINCIPAL_ERROR,
70 N_("Error removing principal from database.")},
71 {SHISA_ADD_KEY_ERROR,
72 N_("Error adding key to principal.")},
73 {SHISA_REMOVE_KEY_ERROR,
74 N_("Error removing key from principal.")},
75 {SHISA_MULTIPLE_KEY_MATCH,
76 N_("More than one key match given search criteria.")}
79 /**
80 * shisa_strerror:
81 * @err: shisa error code
83 * Return value: Returns a pointer to a statically allocated string
84 * containing a description of the error with the error value @err.
85 * This string can be used to output a diagnostic message to the user.
86 **/
87 const char *
88 shisa_strerror (int err)
90 size_t i;
92 for (i = 0; i < sizeof (_shisa_error_messages) /
93 sizeof (_shisa_error_messages[0]); i++)
94 if (_shisa_error_messages[i].errorcode == err)
95 return _(_shisa_error_messages[i].message);
97 return _("Unknown Shisa error");
101 * shisa_info:
102 * @dbh: Shisa library handle created by shisa().
103 * @format: printf style format string.
104 * @...: print style arguments.
106 * Print informational message to standard error.
108 void
109 shisa_info (Shisa * dbh, const char *format, ...)
111 va_list ap;
112 char *out;
114 va_start (ap, format);
115 vasprintf (&out, format, ap);
117 fprintf (stderr, _("shisa: %s\n"), out);
119 free (out);
120 va_end (ap);