1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/srtp/src/crypto/include/err.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,174 @@ 1.4 +/* 1.5 + * err.h 1.6 + * 1.7 + * error status codes 1.8 + * 1.9 + * David A. McGrew 1.10 + * Cisco Systems, Inc. 1.11 + */ 1.12 +/* 1.13 + * 1.14 + * Copyright (c) 2001-2006, Cisco Systems, Inc. 1.15 + * All rights reserved. 1.16 + * 1.17 + * Redistribution and use in source and binary forms, with or without 1.18 + * modification, are permitted provided that the following conditions 1.19 + * are met: 1.20 + * 1.21 + * Redistributions of source code must retain the above copyright 1.22 + * notice, this list of conditions and the following disclaimer. 1.23 + * 1.24 + * Redistributions in binary form must reproduce the above 1.25 + * copyright notice, this list of conditions and the following 1.26 + * disclaimer in the documentation and/or other materials provided 1.27 + * with the distribution. 1.28 + * 1.29 + * Neither the name of the Cisco Systems, Inc. nor the names of its 1.30 + * contributors may be used to endorse or promote products derived 1.31 + * from this software without specific prior written permission. 1.32 + * 1.33 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.34 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.35 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 1.36 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 1.37 + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 1.38 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 1.39 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 1.40 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1.41 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 1.42 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.43 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 1.44 + * OF THE POSSIBILITY OF SUCH DAMAGE. 1.45 + * 1.46 + */ 1.47 + 1.48 + 1.49 +#ifndef ERR_H 1.50 +#define ERR_H 1.51 + 1.52 +#include "datatypes.h" 1.53 + 1.54 +/** 1.55 + * @defgroup Error Error Codes 1.56 + * 1.57 + * Error status codes are represented by the enumeration err_status_t. 1.58 + * 1.59 + * @{ 1.60 + */ 1.61 + 1.62 + 1.63 +/* 1.64 + * @brief err_status_t defines error codes. 1.65 + * 1.66 + * The enumeration err_status_t defines error codes. Note that the 1.67 + * value of err_status_ok is equal to zero, which can simplify error 1.68 + * checking somewhat. 1.69 + * 1.70 + */ 1.71 +typedef enum { 1.72 + err_status_ok = 0, /**< nothing to report */ 1.73 + err_status_fail = 1, /**< unspecified failure */ 1.74 + err_status_bad_param = 2, /**< unsupported parameter */ 1.75 + err_status_alloc_fail = 3, /**< couldn't allocate memory */ 1.76 + err_status_dealloc_fail = 4, /**< couldn't deallocate properly */ 1.77 + err_status_init_fail = 5, /**< couldn't initialize */ 1.78 + err_status_terminus = 6, /**< can't process as much data as requested */ 1.79 + err_status_auth_fail = 7, /**< authentication failure */ 1.80 + err_status_cipher_fail = 8, /**< cipher failure */ 1.81 + err_status_replay_fail = 9, /**< replay check failed (bad index) */ 1.82 + err_status_replay_old = 10, /**< replay check failed (index too old) */ 1.83 + err_status_algo_fail = 11, /**< algorithm failed test routine */ 1.84 + err_status_no_such_op = 12, /**< unsupported operation */ 1.85 + err_status_no_ctx = 13, /**< no appropriate context found */ 1.86 + err_status_cant_check = 14, /**< unable to perform desired validation */ 1.87 + err_status_key_expired = 15, /**< can't use key any more */ 1.88 + err_status_socket_err = 16, /**< error in use of socket */ 1.89 + err_status_signal_err = 17, /**< error in use POSIX signals */ 1.90 + err_status_nonce_bad = 18, /**< nonce check failed */ 1.91 + err_status_read_fail = 19, /**< couldn't read data */ 1.92 + err_status_write_fail = 20, /**< couldn't write data */ 1.93 + err_status_parse_err = 21, /**< error pasring data */ 1.94 + err_status_encode_err = 22, /**< error encoding data */ 1.95 + err_status_semaphore_err = 23,/**< error while using semaphores */ 1.96 + err_status_pfkey_err = 24 /**< error while using pfkey */ 1.97 +} err_status_t; 1.98 + 1.99 +/** 1.100 + * @} 1.101 + */ 1.102 + 1.103 +typedef enum { 1.104 + err_level_emergency = 0, 1.105 + err_level_alert, 1.106 + err_level_critical, 1.107 + err_level_error, 1.108 + err_level_warning, 1.109 + err_level_notice, 1.110 + err_level_info, 1.111 + err_level_debug, 1.112 + err_level_none 1.113 +} err_reporting_level_t; 1.114 + 1.115 +/* 1.116 + * err_reporting_init prepares the error system. If 1.117 + * ERR_REPORTING_SYSLOG is defined, it will open syslog. 1.118 + * 1.119 + * The ident argument is a string that will be prepended to 1.120 + * all syslog messages. It is conventionally argv[0]. 1.121 + */ 1.122 + 1.123 +err_status_t 1.124 +err_reporting_init(char *ident); 1.125 + 1.126 +#ifdef SRTP_KERNEL_LINUX 1.127 +extern err_reporting_level_t err_level; 1.128 +#else 1.129 + 1.130 +/* 1.131 + * keydaemon_report_error reports a 'printf' formatted error 1.132 + * string, followed by a an arg list. The priority argument 1.133 + * is equivalent to that defined for syslog. 1.134 + * 1.135 + * Errors will be reported to ERR_REPORTING_FILE, if defined, and to 1.136 + * syslog, if ERR_REPORTING_SYSLOG is defined. 1.137 + * 1.138 + */ 1.139 + 1.140 +void 1.141 +err_report(int priority, char *format, ...); 1.142 +#endif /* ! SRTP_KERNEL_LINUX */ 1.143 + 1.144 + 1.145 +/* 1.146 + * debug_module_t defines a debug module 1.147 + */ 1.148 + 1.149 +typedef struct { 1.150 + int on; /* 1 if debugging is on, 0 if it is off */ 1.151 + char *name; /* printable name for debug module */ 1.152 +} debug_module_t; 1.153 + 1.154 +#ifdef ENABLE_DEBUGGING 1.155 + 1.156 +#define debug_on(mod) (mod).on = 1 1.157 + 1.158 +#define debug_off(mod) (mod).on = 0 1.159 + 1.160 +/* use err_report() to report debug message */ 1.161 +#define debug_print(mod, format, arg) \ 1.162 + if (mod.on) err_report(err_level_debug, ("%s: " format "\n"), mod.name, arg) 1.163 +#define debug_print2(mod, format, arg1,arg2) \ 1.164 + if (mod.on) err_report(err_level_debug, ("%s: " format "\n"), mod.name, arg1,arg2) 1.165 + 1.166 +#else 1.167 + 1.168 +/* define macros to do nothing */ 1.169 +#define debug_print(mod, format, arg) 1.170 + 1.171 +#define debug_on(mod) 1.172 + 1.173 +#define debug_off(mod) 1.174 + 1.175 +#endif 1.176 + 1.177 +#endif /* ERR_H */