1/*** 2 This file is part of avahi. 3 4 avahi is free software; you can redistribute it and/or modify it 5 under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 2.1 of the 7 License, or (at your option) any later version. 8 9 avahi is distributed in the hope that it will be useful, but WITHOUT 10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General 12 Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with avahi; if not, write to the Free Software 16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 17 USA. 18***/ 19 20#ifdef HAVE_CONFIG_H 21#include <config.h> 22#endif 23 24#include <stdlib.h> 25#include <string.h> 26#include <assert.h> 27 28#include <avahi-common/error.h> 29#include <avahi-common/dbus.h> 30 31static const char * const table[- AVAHI_ERR_MAX] = { 32 AVAHI_DBUS_ERR_OK, 33 AVAHI_DBUS_ERR_FAILURE, 34 AVAHI_DBUS_ERR_BAD_STATE, 35 AVAHI_DBUS_ERR_INVALID_HOST_NAME, 36 AVAHI_DBUS_ERR_INVALID_DOMAIN_NAME, 37 AVAHI_DBUS_ERR_NO_NETWORK, 38 AVAHI_DBUS_ERR_INVALID_TTL, 39 AVAHI_DBUS_ERR_IS_PATTERN, 40 AVAHI_DBUS_ERR_COLLISION, 41 AVAHI_DBUS_ERR_INVALID_RECORD, 42 43 AVAHI_DBUS_ERR_INVALID_SERVICE_NAME, 44 AVAHI_DBUS_ERR_INVALID_SERVICE_TYPE, 45 AVAHI_DBUS_ERR_INVALID_PORT, 46 AVAHI_DBUS_ERR_INVALID_KEY, 47 AVAHI_DBUS_ERR_INVALID_ADDRESS, 48 AVAHI_DBUS_ERR_TIMEOUT, 49 AVAHI_DBUS_ERR_TOO_MANY_CLIENTS, 50 AVAHI_DBUS_ERR_TOO_MANY_OBJECTS, 51 AVAHI_DBUS_ERR_TOO_MANY_ENTRIES, 52 AVAHI_DBUS_ERR_OS, 53 54 AVAHI_DBUS_ERR_ACCESS_DENIED, 55 AVAHI_DBUS_ERR_INVALID_OPERATION, 56 AVAHI_DBUS_ERR_DBUS_ERROR, 57 AVAHI_DBUS_ERR_DISCONNECTED, 58 AVAHI_DBUS_ERR_NO_MEMORY, 59 AVAHI_DBUS_ERR_INVALID_OBJECT, 60 AVAHI_DBUS_ERR_NO_DAEMON, 61 AVAHI_DBUS_ERR_INVALID_INTERFACE, 62 AVAHI_DBUS_ERR_INVALID_PROTOCOL, 63 AVAHI_DBUS_ERR_INVALID_FLAGS, 64 65 AVAHI_DBUS_ERR_NOT_FOUND, 66 AVAHI_DBUS_ERR_INVALID_CONFIG, 67 AVAHI_DBUS_ERR_VERSION_MISMATCH, 68 AVAHI_DBUS_ERR_INVALID_SERVICE_SUBTYPE, 69 AVAHI_DBUS_ERR_INVALID_PACKET, 70 AVAHI_DBUS_ERR_INVALID_DNS_ERROR, 71 AVAHI_DBUS_ERR_DNS_FORMERR, 72 AVAHI_DBUS_ERR_DNS_SERVFAIL, 73 AVAHI_DBUS_ERR_DNS_NXDOMAIN, 74 AVAHI_DBUS_ERR_DNS_NOTIMP, 75 76 AVAHI_DBUS_ERR_DNS_REFUSED, 77 AVAHI_DBUS_ERR_DNS_YXDOMAIN, 78 AVAHI_DBUS_ERR_DNS_YXRRSET, 79 AVAHI_DBUS_ERR_DNS_NXRRSET, 80 AVAHI_DBUS_ERR_DNS_NOTAUTH, 81 AVAHI_DBUS_ERR_DNS_NOTZONE, 82 AVAHI_DBUS_ERR_INVALID_RDATA, 83 AVAHI_DBUS_ERR_INVALID_DNS_CLASS, 84 AVAHI_DBUS_ERR_INVALID_DNS_TYPE, 85 AVAHI_DBUS_ERR_NOT_SUPPORTED, 86 87 AVAHI_DBUS_ERR_NOT_PERMITTED, 88 AVAHI_DBUS_ERR_INVALID_ARGUMENT, 89 AVAHI_DBUS_ERR_IS_EMPTY, 90 AVAHI_DBUS_ERR_NO_CHANGE 91}; 92 93struct error_map { 94 const char *dbus_error; 95 int avahi_error; 96}; 97 98static struct error_map error_map[] = { 99 { DBUS_ERROR_FAILED, AVAHI_ERR_FAILURE }, 100 { DBUS_ERROR_NO_MEMORY, AVAHI_ERR_NO_MEMORY }, 101 { DBUS_ERROR_SERVICE_UNKNOWN, AVAHI_ERR_NO_DAEMON }, 102 { DBUS_ERROR_BAD_ADDRESS, AVAHI_ERR_NO_DAEMON }, 103 { DBUS_ERROR_NOT_SUPPORTED, AVAHI_ERR_NOT_SUPPORTED }, 104 { DBUS_ERROR_LIMITS_EXCEEDED, AVAHI_ERR_TOO_MANY_OBJECTS }, 105 { DBUS_ERROR_ACCESS_DENIED, AVAHI_ERR_ACCESS_DENIED }, 106 { DBUS_ERROR_AUTH_FAILED, AVAHI_ERR_ACCESS_DENIED }, 107 { DBUS_ERROR_NO_SERVER, AVAHI_ERR_NO_DAEMON }, 108 { DBUS_ERROR_TIMEOUT, AVAHI_ERR_TIMEOUT }, 109 { DBUS_ERROR_NO_NETWORK, AVAHI_ERR_NO_NETWORK }, 110 { DBUS_ERROR_DISCONNECTED, AVAHI_ERR_DISCONNECTED }, 111 { DBUS_ERROR_INVALID_ARGS, AVAHI_ERR_INVALID_ARGUMENT }, 112 { DBUS_ERROR_TIMED_OUT, AVAHI_ERR_TIMEOUT }, 113 { NULL, 0 } 114}; 115 116int avahi_error_dbus_to_number(const char *s) { 117 int e; 118 const struct error_map *m; 119 120 assert(s); 121 122 for (e = -1; e > AVAHI_ERR_MAX; e--) 123 if (strcmp(s, table[-e]) == 0) 124 return e; 125 126 for (m = error_map; m->dbus_error; m++) 127 if (strcmp(m->dbus_error, s) == 0) 128 return m->avahi_error; 129 130 return AVAHI_ERR_DBUS_ERROR; 131} 132 133const char *avahi_error_number_to_dbus(int error) { 134 assert(error > AVAHI_ERR_MAX); 135 assert(error < 1); 136 137 return table[-error]; 138} 139