Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * err.h |
michael@0 | 3 | * |
michael@0 | 4 | * error status codes |
michael@0 | 5 | * |
michael@0 | 6 | * David A. McGrew |
michael@0 | 7 | * Cisco Systems, Inc. |
michael@0 | 8 | */ |
michael@0 | 9 | /* |
michael@0 | 10 | * |
michael@0 | 11 | * Copyright (c) 2001-2006, Cisco Systems, Inc. |
michael@0 | 12 | * All rights reserved. |
michael@0 | 13 | * |
michael@0 | 14 | * Redistribution and use in source and binary forms, with or without |
michael@0 | 15 | * modification, are permitted provided that the following conditions |
michael@0 | 16 | * are met: |
michael@0 | 17 | * |
michael@0 | 18 | * Redistributions of source code must retain the above copyright |
michael@0 | 19 | * notice, this list of conditions and the following disclaimer. |
michael@0 | 20 | * |
michael@0 | 21 | * Redistributions in binary form must reproduce the above |
michael@0 | 22 | * copyright notice, this list of conditions and the following |
michael@0 | 23 | * disclaimer in the documentation and/or other materials provided |
michael@0 | 24 | * with the distribution. |
michael@0 | 25 | * |
michael@0 | 26 | * Neither the name of the Cisco Systems, Inc. nor the names of its |
michael@0 | 27 | * contributors may be used to endorse or promote products derived |
michael@0 | 28 | * from this software without specific prior written permission. |
michael@0 | 29 | * |
michael@0 | 30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 31 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 32 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
michael@0 | 33 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
michael@0 | 34 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
michael@0 | 35 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
michael@0 | 36 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
michael@0 | 37 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
michael@0 | 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
michael@0 | 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
michael@0 | 40 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
michael@0 | 41 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 42 | * |
michael@0 | 43 | */ |
michael@0 | 44 | |
michael@0 | 45 | |
michael@0 | 46 | #ifndef ERR_H |
michael@0 | 47 | #define ERR_H |
michael@0 | 48 | |
michael@0 | 49 | #include "datatypes.h" |
michael@0 | 50 | |
michael@0 | 51 | /** |
michael@0 | 52 | * @defgroup Error Error Codes |
michael@0 | 53 | * |
michael@0 | 54 | * Error status codes are represented by the enumeration err_status_t. |
michael@0 | 55 | * |
michael@0 | 56 | * @{ |
michael@0 | 57 | */ |
michael@0 | 58 | |
michael@0 | 59 | |
michael@0 | 60 | /* |
michael@0 | 61 | * @brief err_status_t defines error codes. |
michael@0 | 62 | * |
michael@0 | 63 | * The enumeration err_status_t defines error codes. Note that the |
michael@0 | 64 | * value of err_status_ok is equal to zero, which can simplify error |
michael@0 | 65 | * checking somewhat. |
michael@0 | 66 | * |
michael@0 | 67 | */ |
michael@0 | 68 | typedef enum { |
michael@0 | 69 | err_status_ok = 0, /**< nothing to report */ |
michael@0 | 70 | err_status_fail = 1, /**< unspecified failure */ |
michael@0 | 71 | err_status_bad_param = 2, /**< unsupported parameter */ |
michael@0 | 72 | err_status_alloc_fail = 3, /**< couldn't allocate memory */ |
michael@0 | 73 | err_status_dealloc_fail = 4, /**< couldn't deallocate properly */ |
michael@0 | 74 | err_status_init_fail = 5, /**< couldn't initialize */ |
michael@0 | 75 | err_status_terminus = 6, /**< can't process as much data as requested */ |
michael@0 | 76 | err_status_auth_fail = 7, /**< authentication failure */ |
michael@0 | 77 | err_status_cipher_fail = 8, /**< cipher failure */ |
michael@0 | 78 | err_status_replay_fail = 9, /**< replay check failed (bad index) */ |
michael@0 | 79 | err_status_replay_old = 10, /**< replay check failed (index too old) */ |
michael@0 | 80 | err_status_algo_fail = 11, /**< algorithm failed test routine */ |
michael@0 | 81 | err_status_no_such_op = 12, /**< unsupported operation */ |
michael@0 | 82 | err_status_no_ctx = 13, /**< no appropriate context found */ |
michael@0 | 83 | err_status_cant_check = 14, /**< unable to perform desired validation */ |
michael@0 | 84 | err_status_key_expired = 15, /**< can't use key any more */ |
michael@0 | 85 | err_status_socket_err = 16, /**< error in use of socket */ |
michael@0 | 86 | err_status_signal_err = 17, /**< error in use POSIX signals */ |
michael@0 | 87 | err_status_nonce_bad = 18, /**< nonce check failed */ |
michael@0 | 88 | err_status_read_fail = 19, /**< couldn't read data */ |
michael@0 | 89 | err_status_write_fail = 20, /**< couldn't write data */ |
michael@0 | 90 | err_status_parse_err = 21, /**< error pasring data */ |
michael@0 | 91 | err_status_encode_err = 22, /**< error encoding data */ |
michael@0 | 92 | err_status_semaphore_err = 23,/**< error while using semaphores */ |
michael@0 | 93 | err_status_pfkey_err = 24 /**< error while using pfkey */ |
michael@0 | 94 | } err_status_t; |
michael@0 | 95 | |
michael@0 | 96 | /** |
michael@0 | 97 | * @} |
michael@0 | 98 | */ |
michael@0 | 99 | |
michael@0 | 100 | typedef enum { |
michael@0 | 101 | err_level_emergency = 0, |
michael@0 | 102 | err_level_alert, |
michael@0 | 103 | err_level_critical, |
michael@0 | 104 | err_level_error, |
michael@0 | 105 | err_level_warning, |
michael@0 | 106 | err_level_notice, |
michael@0 | 107 | err_level_info, |
michael@0 | 108 | err_level_debug, |
michael@0 | 109 | err_level_none |
michael@0 | 110 | } err_reporting_level_t; |
michael@0 | 111 | |
michael@0 | 112 | /* |
michael@0 | 113 | * err_reporting_init prepares the error system. If |
michael@0 | 114 | * ERR_REPORTING_SYSLOG is defined, it will open syslog. |
michael@0 | 115 | * |
michael@0 | 116 | * The ident argument is a string that will be prepended to |
michael@0 | 117 | * all syslog messages. It is conventionally argv[0]. |
michael@0 | 118 | */ |
michael@0 | 119 | |
michael@0 | 120 | err_status_t |
michael@0 | 121 | err_reporting_init(char *ident); |
michael@0 | 122 | |
michael@0 | 123 | #ifdef SRTP_KERNEL_LINUX |
michael@0 | 124 | extern err_reporting_level_t err_level; |
michael@0 | 125 | #else |
michael@0 | 126 | |
michael@0 | 127 | /* |
michael@0 | 128 | * keydaemon_report_error reports a 'printf' formatted error |
michael@0 | 129 | * string, followed by a an arg list. The priority argument |
michael@0 | 130 | * is equivalent to that defined for syslog. |
michael@0 | 131 | * |
michael@0 | 132 | * Errors will be reported to ERR_REPORTING_FILE, if defined, and to |
michael@0 | 133 | * syslog, if ERR_REPORTING_SYSLOG is defined. |
michael@0 | 134 | * |
michael@0 | 135 | */ |
michael@0 | 136 | |
michael@0 | 137 | void |
michael@0 | 138 | err_report(int priority, char *format, ...); |
michael@0 | 139 | #endif /* ! SRTP_KERNEL_LINUX */ |
michael@0 | 140 | |
michael@0 | 141 | |
michael@0 | 142 | /* |
michael@0 | 143 | * debug_module_t defines a debug module |
michael@0 | 144 | */ |
michael@0 | 145 | |
michael@0 | 146 | typedef struct { |
michael@0 | 147 | int on; /* 1 if debugging is on, 0 if it is off */ |
michael@0 | 148 | char *name; /* printable name for debug module */ |
michael@0 | 149 | } debug_module_t; |
michael@0 | 150 | |
michael@0 | 151 | #ifdef ENABLE_DEBUGGING |
michael@0 | 152 | |
michael@0 | 153 | #define debug_on(mod) (mod).on = 1 |
michael@0 | 154 | |
michael@0 | 155 | #define debug_off(mod) (mod).on = 0 |
michael@0 | 156 | |
michael@0 | 157 | /* use err_report() to report debug message */ |
michael@0 | 158 | #define debug_print(mod, format, arg) \ |
michael@0 | 159 | if (mod.on) err_report(err_level_debug, ("%s: " format "\n"), mod.name, arg) |
michael@0 | 160 | #define debug_print2(mod, format, arg1,arg2) \ |
michael@0 | 161 | if (mod.on) err_report(err_level_debug, ("%s: " format "\n"), mod.name, arg1,arg2) |
michael@0 | 162 | |
michael@0 | 163 | #else |
michael@0 | 164 | |
michael@0 | 165 | /* define macros to do nothing */ |
michael@0 | 166 | #define debug_print(mod, format, arg) |
michael@0 | 167 | |
michael@0 | 168 | #define debug_on(mod) |
michael@0 | 169 | |
michael@0 | 170 | #define debug_off(mod) |
michael@0 | 171 | |
michael@0 | 172 | #endif |
michael@0 | 173 | |
michael@0 | 174 | #endif /* ERR_H */ |