err.h 3.62 KB
Newer Older
Cullen Jennings's avatar
Cullen Jennings committed
1 2
/*
 * err.h
3
 *
Cullen Jennings's avatar
Cullen Jennings committed
4 5 6 7 8 9
 * error status codes
 *
 * David A. McGrew
 * Cisco Systems, Inc.
 */
/*
10
 *
David McGrew's avatar
David McGrew committed
11
 * Copyright (c) 2001-2006, Cisco Systems, Inc.
Cullen Jennings's avatar
Cullen Jennings committed
12
 * All rights reserved.
13
 *
Cullen Jennings's avatar
Cullen Jennings committed
14 15 16
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
17
 *
Cullen Jennings's avatar
Cullen Jennings committed
18 19
 *   Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
20
 *
Cullen Jennings's avatar
Cullen Jennings committed
21 22 23 24
 *   Redistributions in binary form must reproduce the above
 *   copyright notice, this list of conditions and the following
 *   disclaimer in the documentation and/or other materials provided
 *   with the distribution.
25
 *
Cullen Jennings's avatar
Cullen Jennings committed
26 27 28
 *   Neither the name of the Cisco Systems, Inc. nor the names of its
 *   contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
29
 *
Cullen Jennings's avatar
Cullen Jennings committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */


#ifndef ERR_H
#define ERR_H

49 50
#include <stdio.h>
#include <stdarg.h>
51
#include "srtp.h"
Cullen Jennings's avatar
Cullen Jennings committed
52 53 54

/**
 * @defgroup Error Error Codes
55
 *
56
 * Error status codes are represented by the enumeration srtp_err_status_t.
57
 *
Cullen Jennings's avatar
Cullen Jennings committed
58 59 60 61 62 63 64 65 66
 * @{
 */


/**
 * @}
 */

typedef enum {
67 68 69 70 71 72 73 74 75 76
    srtp_err_level_emergency = 0,
    srtp_err_level_alert,
    srtp_err_level_critical,
    srtp_err_level_error,
    srtp_err_level_warning,
    srtp_err_level_notice,
    srtp_err_level_info,
    srtp_err_level_debug,
    srtp_err_level_none
} srtp_err_reporting_level_t;
Cullen Jennings's avatar
Cullen Jennings committed
77 78 79 80 81 82

/*
 * err_reporting_init prepares the error system.  If
 * ERR_REPORTING_SYSLOG is defined, it will open syslog.
 *
 * The ident argument is a string that will be prepended to
83
 * all syslog messages.  It is conventionally argv[0].
Cullen Jennings's avatar
Cullen Jennings committed
84 85
 */

86
srtp_err_status_t srtp_err_reporting_init(const char *ident);
87

Cullen Jennings's avatar
Cullen Jennings committed
88 89 90 91 92 93 94 95 96 97 98
/*
 * keydaemon_report_error reports a 'printf' formatted error
 * string, followed by a an arg list.  The priority argument
 * is equivalent to that defined for syslog.
 *
 * Errors will be reported to ERR_REPORTING_FILE, if defined, and to
 * syslog, if ERR_REPORTING_SYSLOG is defined.
 *
 */

void
99
srtp_err_report(int priority, const char *format, ...);
Cullen Jennings's avatar
Cullen Jennings committed
100 101 102


/*
103
 * debug_module_t defines a debug module
Cullen Jennings's avatar
Cullen Jennings committed
104 105
 */

106
typedef struct {
107 108 109
    int on;           /* 1 if debugging is on, 0 if it is off */
    const char *name; /* printable name for debug module      */
} srtp_debug_module_t;
Cullen Jennings's avatar
Cullen Jennings committed
110

Marcus Sundberg's avatar
Marcus Sundberg committed
111
#ifdef ENABLE_DEBUGGING
Cullen Jennings's avatar
Cullen Jennings committed
112 113 114 115 116 117 118

#define debug_on(mod)  (mod).on = 1

#define debug_off(mod) (mod).on = 0

/* use err_report() to report debug message */
#define debug_print(mod, format, arg)                  \
119 120 121
    if (mod.on) srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, arg)
#define debug_print2(mod, format, arg1, arg2)                  \
    if (mod.on) srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, arg1, arg2)
Cullen Jennings's avatar
Cullen Jennings committed
122

123
#else
Cullen Jennings's avatar
Cullen Jennings committed
124 125

/* define macros to do nothing */
126
#define debug_print(mod, format, arg)
Cullen Jennings's avatar
Cullen Jennings committed
127

128
#define debug_on(mod)
Cullen Jennings's avatar
Cullen Jennings committed
129

130
#define debug_off(mod)
Cullen Jennings's avatar
Cullen Jennings committed
131 132 133 134

#endif

#endif /* ERR_H */