err.h 5.9 KB

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