xref: /minix/crypto/external/bsd/libsaslc/dist/src/error.h (revision ebfedea0)
1 /* $NetBSD: error.h,v 1.3 2011/02/11 23:44:43 christos Exp $ */
2 
3 /* Copyright (c) 2010 The NetBSD Foundation, Inc.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to The NetBSD Foundation
7  * by Mateusz Kocielski.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *        This product includes software developed by the NetBSD
20  *        Foundation, Inc. and its contributors.
21  * 4. Neither the name of The NetBSD Foundation nor the names of its
22  *    contributors may be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED.	IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef _ERROR_H_
39 #define _ERROR_H_
40 
41 /** error definitions */
42 typedef enum {
43 	ERROR_GENERAL,		/**< general error */
44 	ERROR_NOMEM,		/**< no memory available */
45 	ERROR_BADARG,		/**< bad argument passed to function */
46 	ERROR_NOTEXISTS,	/**< key/node does not exist */
47 	ERROR_MECH,		/**< mechanism error */
48 	ERROR_PARSE		/**< parse error */
49 } saslc__error_code_t;
50 
51 /** error type */
52 typedef struct saslc__error_t {
53 	saslc__error_code_t err_no;     /**< error number */
54 	const char *err_str;	        /**< string error */
55 } saslc__error_t;
56 
57 /*
58  * saslc__error_set - sets error for the context of sasl session
59  *
60  * E - error
61  * N - error type
62  * S - error message
63  */
64 #define saslc__error_set(E, N, S)	\
65 do {					\
66 	(E)->err_no = (N);		\
67 	(E)->err_str = (S);		\
68 } while(/*CONSTCOND*/0);
69 
70 /*
71  * saslc__eror_get_errno - gets error type
72  *
73  * E - error
74  */
75 #define saslc__error_get_errno(E) ((E)->err_no)
76 
77 const char *saslc__error_get_strerror(saslc__error_t *);
78 
79 /*
80  * saslc__error_set_errno - sets error type with the default message
81  *
82  * E - error
83  * N - error type
84  */
85 #define saslc__error_set_errno(E, N) saslc__error_set((E), (N), NULL)
86 
87 /*
88  * ERR - gets address of the error structure, this macro should be used only
89  * for the saslc_t and saslc_session_t structures.
90  *
91  * X - context or session
92  */
93 #define ERR(X) (&((X)->err))
94 
95 #endif /* ! _ERROR_H_ */
96