Use GPL instead of LGPL.
[shishi.git] / lib / error.c
bloba86aafec376d438f9150463323749da36ebdfb74
1 /* error.c error handling functions
2 * Copyright (C) 2002 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "internal.h"
24 const char *
25 shishi_strerror_details (Shishi * handle)
27 return handle->error ? handle->
28 error :
29 "Internal application error: shishi_strerror() called without an "
30 "error condition";
33 /**
34 * shishi_strerror:
35 * @err: shishi error code
37 * Return value: Returns a pointer to a statically allocated string
38 * containing a description of the error with the error value
39 * @var{err}. This string can be used to output a diagnostic message
40 * to the user.
41 **/
42 const char *
43 shishi_strerror (int err)
45 char *p;
47 switch (err)
49 case SHISHI_OK:
50 p = _("Shishi success");
51 break;
53 case SHISHI_MALLOC_ERROR:
54 p = _("Memory allocation error in shishi library.");
55 break;
57 case SHISHI_BASE64_ERROR:
58 p = _("Base64 encoding or decoding failed. This usually means the "
59 "data is corrupt.");
60 break;
62 case SHISHI_FOPEN_ERROR:
63 p = _("Could not open file.");
64 break;
66 case SHISHI_FCLOSE_ERROR:
67 p = _("Could not close file.");
68 break;
70 case SHISHI_GCRYPT_ERROR:
71 p = _("Internal libgcrypt error.");
72 break;
74 case SHISHI_NONCE_MISMATCH:
75 p =
76 _("Replay protection value (nonce) differ between request and reply.");
77 break;
79 case SHISHI_REALM_MISMATCH:
80 p = _("Client realm value differ between request and reply.");
81 break;
83 case SHISHI_CNAME_MISMATCH:
84 p = _("Client name value differ between request and reply.");
85 break;
87 case SHISHI_ASN1_ERROR:
88 p = _("Error in ASN.1 data, probably due to corrupt data.");
89 break;
91 case SHISHI_CRYPTO_ERROR:
92 p =
94 ("Low-level cryptographic primitive failed. This usually indicates "
95 "bad password or data corruption.");
96 break;
98 case SHISHI_KDC_TIMEOUT:
99 p = _("Timedout talking to KDC. This usually indicates a network "
100 "or KDC address problem.");
101 break;
103 case SHISHI_KDC_NOT_KNOWN_FOR_REALM:
104 p = _("No KDC for realm known.");
105 break;
107 case SHISHI_SOCKET_ERROR:
108 p = _("The system call socket() failed. This usually indicates that "
109 "your system does not support the socket type.");
110 break;
112 case SHISHI_BIND_ERROR:
113 p = _("The system call bind() failed. This usually indicates "
114 "insufficient permissions.");
115 break;
117 case SHISHI_SENDTO_ERROR:
118 p = _("The system call sendto() failed.");
119 break;
121 case SHISHI_CLOSE_ERROR:
122 p = _("The system call close() failed.");
123 break;
125 case SHISHI_GOT_KRBERROR:
126 p = _("Server replied with an error message to request.");
127 break;
129 case SHISHI_INVALID_TICKETSET:
130 p = _("Ticketset not initialized. This usually indicates an internal "
131 "application error.");
132 break;
134 default:
135 shishi_asprintf (&p, _("Unknown shishi error (%d)"), err);
136 break;
139 return p;
143 void
144 shishi_error_clear (Shishi * handle)
146 handle->error[0] = '\0';
149 void
150 shishi_error_set (Shishi * handle, const char *error)
152 if (error)
153 strncpy (handle->error, error, sizeof (handle->error));
154 else
155 shishi_error_clear (handle);
158 void
159 shishi_error_printf (Shishi * handle, char *format, ...)
161 va_list ap;
163 va_start (ap, format);
165 vsnprintf (handle->error, sizeof (handle->error), format, ap);