xref: /titanic_44/usr/src/lib/libnwam/common/libnwam_error.c (revision 6ba597c56d749c61b4f783157f63196d7b2445f0)
1*6ba597c5SAnurag S. Maskey /*
2*6ba597c5SAnurag S. Maskey  * CDDL HEADER START
3*6ba597c5SAnurag S. Maskey  *
4*6ba597c5SAnurag S. Maskey  * The contents of this file are subject to the terms of the
5*6ba597c5SAnurag S. Maskey  * Common Development and Distribution License (the "License").
6*6ba597c5SAnurag S. Maskey  * You may not use this file except in compliance with the License.
7*6ba597c5SAnurag S. Maskey  *
8*6ba597c5SAnurag S. Maskey  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*6ba597c5SAnurag S. Maskey  * or http://www.opensolaris.org/os/licensing.
10*6ba597c5SAnurag S. Maskey  * See the License for the specific language governing permissions
11*6ba597c5SAnurag S. Maskey  * and limitations under the License.
12*6ba597c5SAnurag S. Maskey  *
13*6ba597c5SAnurag S. Maskey  * When distributing Covered Code, include this CDDL HEADER in each
14*6ba597c5SAnurag S. Maskey  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*6ba597c5SAnurag S. Maskey  * If applicable, add the following below this CDDL HEADER, with the
16*6ba597c5SAnurag S. Maskey  * fields enclosed by brackets "[]" replaced with your own identifying
17*6ba597c5SAnurag S. Maskey  * information: Portions Copyright [yyyy] [name of copyright owner]
18*6ba597c5SAnurag S. Maskey  *
19*6ba597c5SAnurag S. Maskey  * CDDL HEADER END
20*6ba597c5SAnurag S. Maskey  */
21*6ba597c5SAnurag S. Maskey 
22*6ba597c5SAnurag S. Maskey /*
23*6ba597c5SAnurag S. Maskey  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24*6ba597c5SAnurag S. Maskey  * Use is subject to license terms.
25*6ba597c5SAnurag S. Maskey  */
26*6ba597c5SAnurag S. Maskey 
27*6ba597c5SAnurag S. Maskey #include <libnwam.h>
28*6ba597c5SAnurag S. Maskey #include <libintl.h>
29*6ba597c5SAnurag S. Maskey 
30*6ba597c5SAnurag S. Maskey static struct nwam_error_info {
31*6ba597c5SAnurag S. Maskey 	nwam_error_t error_code;
32*6ba597c5SAnurag S. Maskey 	const char *error_desc;
33*6ba597c5SAnurag S. Maskey } nwam_errors[] = {
34*6ba597c5SAnurag S. Maskey 	{NWAM_SUCCESS,			"no error"},
35*6ba597c5SAnurag S. Maskey 	{NWAM_LIST_END,			"end of list reached"},
36*6ba597c5SAnurag S. Maskey 	{NWAM_INVALID_HANDLE,		"entity handle is invalid"},
37*6ba597c5SAnurag S. Maskey 	{NWAM_HANDLE_UNBOUND,		"handle not bound to entity"},
38*6ba597c5SAnurag S. Maskey 	{NWAM_INVALID_ARG,		"argument is invalid"},
39*6ba597c5SAnurag S. Maskey 	{NWAM_PERMISSION_DENIED,	"Insufficient permissions for action"},
40*6ba597c5SAnurag S. Maskey 	{NWAM_NO_MEMORY,		"out of memory"},
41*6ba597c5SAnurag S. Maskey 	{NWAM_ENTITY_EXISTS,		"entity exists"},
42*6ba597c5SAnurag S. Maskey 	{NWAM_ENTITY_IN_USE,		"entity in use"},
43*6ba597c5SAnurag S. Maskey 	{NWAM_ENTITY_COMMITTED,		"entity already committed"},
44*6ba597c5SAnurag S. Maskey 	{NWAM_ENTITY_NOT_FOUND,		"entity not found"},
45*6ba597c5SAnurag S. Maskey 	{NWAM_ENTITY_TYPE_MISMATCH,	"entity type mismatch"},
46*6ba597c5SAnurag S. Maskey 	{NWAM_ENTITY_INVALID,		"validation of entity failed"},
47*6ba597c5SAnurag S. Maskey 	{NWAM_ENTITY_INVALID_MEMBER,	"entity has invalid member"},
48*6ba597c5SAnurag S. Maskey 	{NWAM_ENTITY_INVALID_STATE,	"entity is in incorrect state"},
49*6ba597c5SAnurag S. Maskey 	{NWAM_ENTITY_INVALID_VALUE,	"validation of entity value failed"},
50*6ba597c5SAnurag S. Maskey 	{NWAM_ENTITY_MISSING_MEMBER,	"entity is missing required member"},
51*6ba597c5SAnurag S. Maskey 	{NWAM_ENTITY_NO_VALUE,		"no value associated with entity"},
52*6ba597c5SAnurag S. Maskey 	{NWAM_ENTITY_MULTIPLE_VALUES,	"multiple values for entity"},
53*6ba597c5SAnurag S. Maskey 	{NWAM_ENTITY_READ_ONLY,		"entity is read only"},
54*6ba597c5SAnurag S. Maskey 	{NWAM_ENTITY_NOT_DESTROYABLE,	"entity cannot be destroyed"},
55*6ba597c5SAnurag S. Maskey 	{NWAM_ENTITY_NOT_MANUAL, "entity cannot be manually enabled/disabled"},
56*6ba597c5SAnurag S. Maskey 	{NWAM_WALK_HALTED,		"callback function returned nonzero"},
57*6ba597c5SAnurag S. Maskey 	{NWAM_ERROR_BIND,		"could not bind to backend server"},
58*6ba597c5SAnurag S. Maskey 	{NWAM_ERROR_BACKEND_INIT,	"could not initialize backend"},
59*6ba597c5SAnurag S. Maskey 	{NWAM_ERROR_INTERNAL,		"internal error"}
60*6ba597c5SAnurag S. Maskey };
61*6ba597c5SAnurag S. Maskey 
62*6ba597c5SAnurag S. Maskey #define	NWAM_NUM_ERRORS	(sizeof (nwam_errors) / sizeof (*nwam_errors))
63*6ba597c5SAnurag S. Maskey 
64*6ba597c5SAnurag S. Maskey const char *
nwam_strerror(nwam_error_t code)65*6ba597c5SAnurag S. Maskey nwam_strerror(nwam_error_t code)
66*6ba597c5SAnurag S. Maskey {
67*6ba597c5SAnurag S. Maskey 	struct nwam_error_info *cur, *end;
68*6ba597c5SAnurag S. Maskey 
69*6ba597c5SAnurag S. Maskey 	cur = nwam_errors;
70*6ba597c5SAnurag S. Maskey 	end = cur + NWAM_NUM_ERRORS;
71*6ba597c5SAnurag S. Maskey 
72*6ba597c5SAnurag S. Maskey 	for (; cur < end; cur++) {
73*6ba597c5SAnurag S. Maskey 		if (code == cur->error_code)
74*6ba597c5SAnurag S. Maskey 			return (dgettext(TEXT_DOMAIN, cur->error_desc));
75*6ba597c5SAnurag S. Maskey 	}
76*6ba597c5SAnurag S. Maskey 
77*6ba597c5SAnurag S. Maskey 	return (dgettext(TEXT_DOMAIN, "unknown error"));
78*6ba597c5SAnurag S. Maskey }
79