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