michael@0: /* michael@0: * err.h michael@0: * michael@0: * error status codes michael@0: * michael@0: * David A. McGrew michael@0: * Cisco Systems, Inc. michael@0: */ michael@0: /* michael@0: * michael@0: * Copyright (c) 2001-2006, Cisco Systems, Inc. michael@0: * All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * michael@0: * Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * michael@0: * Redistributions in binary form must reproduce the above michael@0: * copyright notice, this list of conditions and the following michael@0: * disclaimer in the documentation and/or other materials provided michael@0: * with the distribution. michael@0: * michael@0: * Neither the name of the Cisco Systems, Inc. nor the names of its michael@0: * contributors may be used to endorse or promote products derived michael@0: * from this software without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS michael@0: * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE michael@0: * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, michael@0: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES michael@0: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR michael@0: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) michael@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, michael@0: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) michael@0: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED michael@0: * OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: * michael@0: */ michael@0: michael@0: michael@0: #ifndef ERR_H michael@0: #define ERR_H michael@0: michael@0: #include "datatypes.h" michael@0: michael@0: /** michael@0: * @defgroup Error Error Codes michael@0: * michael@0: * Error status codes are represented by the enumeration err_status_t. michael@0: * michael@0: * @{ michael@0: */ michael@0: michael@0: michael@0: /* michael@0: * @brief err_status_t defines error codes. michael@0: * michael@0: * The enumeration err_status_t defines error codes. Note that the michael@0: * value of err_status_ok is equal to zero, which can simplify error michael@0: * checking somewhat. michael@0: * michael@0: */ michael@0: typedef enum { michael@0: err_status_ok = 0, /**< nothing to report */ michael@0: err_status_fail = 1, /**< unspecified failure */ michael@0: err_status_bad_param = 2, /**< unsupported parameter */ michael@0: err_status_alloc_fail = 3, /**< couldn't allocate memory */ michael@0: err_status_dealloc_fail = 4, /**< couldn't deallocate properly */ michael@0: err_status_init_fail = 5, /**< couldn't initialize */ michael@0: err_status_terminus = 6, /**< can't process as much data as requested */ michael@0: err_status_auth_fail = 7, /**< authentication failure */ michael@0: err_status_cipher_fail = 8, /**< cipher failure */ michael@0: err_status_replay_fail = 9, /**< replay check failed (bad index) */ michael@0: err_status_replay_old = 10, /**< replay check failed (index too old) */ michael@0: err_status_algo_fail = 11, /**< algorithm failed test routine */ michael@0: err_status_no_such_op = 12, /**< unsupported operation */ michael@0: err_status_no_ctx = 13, /**< no appropriate context found */ michael@0: err_status_cant_check = 14, /**< unable to perform desired validation */ michael@0: err_status_key_expired = 15, /**< can't use key any more */ michael@0: err_status_socket_err = 16, /**< error in use of socket */ michael@0: err_status_signal_err = 17, /**< error in use POSIX signals */ michael@0: err_status_nonce_bad = 18, /**< nonce check failed */ michael@0: err_status_read_fail = 19, /**< couldn't read data */ michael@0: err_status_write_fail = 20, /**< couldn't write data */ michael@0: err_status_parse_err = 21, /**< error pasring data */ michael@0: err_status_encode_err = 22, /**< error encoding data */ michael@0: err_status_semaphore_err = 23,/**< error while using semaphores */ michael@0: err_status_pfkey_err = 24 /**< error while using pfkey */ michael@0: } err_status_t; michael@0: michael@0: /** michael@0: * @} michael@0: */ michael@0: michael@0: typedef enum { michael@0: err_level_emergency = 0, michael@0: err_level_alert, michael@0: err_level_critical, michael@0: err_level_error, michael@0: err_level_warning, michael@0: err_level_notice, michael@0: err_level_info, michael@0: err_level_debug, michael@0: err_level_none michael@0: } err_reporting_level_t; michael@0: michael@0: /* michael@0: * err_reporting_init prepares the error system. If michael@0: * ERR_REPORTING_SYSLOG is defined, it will open syslog. michael@0: * michael@0: * The ident argument is a string that will be prepended to michael@0: * all syslog messages. It is conventionally argv[0]. michael@0: */ michael@0: michael@0: err_status_t michael@0: err_reporting_init(char *ident); michael@0: michael@0: #ifdef SRTP_KERNEL_LINUX michael@0: extern err_reporting_level_t err_level; michael@0: #else michael@0: michael@0: /* michael@0: * keydaemon_report_error reports a 'printf' formatted error michael@0: * string, followed by a an arg list. The priority argument michael@0: * is equivalent to that defined for syslog. michael@0: * michael@0: * Errors will be reported to ERR_REPORTING_FILE, if defined, and to michael@0: * syslog, if ERR_REPORTING_SYSLOG is defined. michael@0: * michael@0: */ michael@0: michael@0: void michael@0: err_report(int priority, char *format, ...); michael@0: #endif /* ! SRTP_KERNEL_LINUX */ michael@0: michael@0: michael@0: /* michael@0: * debug_module_t defines a debug module michael@0: */ michael@0: michael@0: typedef struct { michael@0: int on; /* 1 if debugging is on, 0 if it is off */ michael@0: char *name; /* printable name for debug module */ michael@0: } debug_module_t; michael@0: michael@0: #ifdef ENABLE_DEBUGGING michael@0: michael@0: #define debug_on(mod) (mod).on = 1 michael@0: michael@0: #define debug_off(mod) (mod).on = 0 michael@0: michael@0: /* use err_report() to report debug message */ michael@0: #define debug_print(mod, format, arg) \ michael@0: if (mod.on) err_report(err_level_debug, ("%s: " format "\n"), mod.name, arg) michael@0: #define debug_print2(mod, format, arg1,arg2) \ michael@0: if (mod.on) err_report(err_level_debug, ("%s: " format "\n"), mod.name, arg1,arg2) michael@0: michael@0: #else michael@0: michael@0: /* define macros to do nothing */ michael@0: #define debug_print(mod, format, arg) michael@0: michael@0: #define debug_on(mod) michael@0: michael@0: #define debug_off(mod) michael@0: michael@0: #endif michael@0: michael@0: #endif /* ERR_H */