| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#include "asterisk.h" |
| 30 |
#include "asterisk/utils.h" |
| 31 |
#include "asterisk/syslog.h" |
| 32 |
|
| 33 |
#include <syslog.h> |
| 34 |
|
| 35 |
static const struct { |
| 36 |
const char *name; |
| 37 |
int value; |
| 38 |
} facility_map[] = { |
| 39 |
|
| 40 |
{ "user", LOG_USER }, |
| 41 |
{ "local0", LOG_LOCAL0 }, |
| 42 |
{ "local1", LOG_LOCAL1 }, |
| 43 |
{ "local2", LOG_LOCAL2 }, |
| 44 |
{ "local3", LOG_LOCAL3 }, |
| 45 |
{ "local4", LOG_LOCAL4 }, |
| 46 |
{ "local5", LOG_LOCAL5 }, |
| 47 |
{ "local6", LOG_LOCAL6 }, |
| 48 |
{ "local7", LOG_LOCAL7 }, |
| 49 |
#if defined(HAVE_SYSLOG_FACILITY_LOG_KERN) |
| 50 |
{ "kern", LOG_KERN }, |
| 51 |
#endif |
| 52 |
#if defined(HAVE_SYSLOG_FACILITY_LOG_MAIL) |
| 53 |
{ "mail", LOG_MAIL }, |
| 54 |
#endif |
| 55 |
#if defined(HAVE_SYSLOG_FACILITY_LOG_DAEMON) |
| 56 |
{ "daemon", LOG_DAEMON }, |
| 57 |
#endif |
| 58 |
#if defined(HAVE_SYSLOG_FACILITY_LOG_AUTH) |
| 59 |
{ "auth", LOG_AUTH }, |
| 60 |
{ "security", LOG_AUTH }, |
| 61 |
#endif |
| 62 |
#if defined(HAVE_SYSLOG_FACILITY_LOG_AUTHPRIV) |
| 63 |
{ "authpriv", LOG_AUTHPRIV }, |
| 64 |
#endif |
| 65 |
#if defined(HAVE_SYSLOG_FACILITY_LOG_SYSLOG) |
| 66 |
{ "syslog", LOG_SYSLOG }, |
| 67 |
#endif |
| 68 |
#if defined(HAVE_SYSLOG_FACILITY_LOG_FTP) |
| 69 |
{ "ftp", LOG_FTP }, |
| 70 |
#endif |
| 71 |
#if defined(HAVE_SYSLOG_FACILITY_LOG_LPR) |
| 72 |
{ "lpr", LOG_LPR }, |
| 73 |
#endif |
| 74 |
#if defined(HAVE_SYSLOG_FACILITY_LOG_NEWS) |
| 75 |
{ "news", LOG_NEWS }, |
| 76 |
#endif |
| 77 |
#if defined(HAVE_SYSLOG_FACILITY_LOG_UUCP) |
| 78 |
{ "uucp", LOG_UUCP }, |
| 79 |
#endif |
| 80 |
#if defined(HAVE_SYSLOG_FACILITY_LOG_CRON) |
| 81 |
{ "cron", LOG_CRON }, |
| 82 |
#endif |
| 83 |
}; |
| 84 |
|
| 85 |
int ast_syslog_facility(const char *facility) |
| 86 |
{ |
| 87 |
int index; |
| 88 |
|
| 89 |
for (index = 0; index < ARRAY_LEN(facility_map); index++) { |
| 90 |
if (!strcasecmp(facility_map[index].name, facility)) { |
| 91 |
return facility_map[index].value; |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
return -1; |
| 96 |
} |
| 97 |
|
| 98 |
const char *ast_syslog_facility_name(int facility) |
| 99 |
{ |
| 100 |
int index; |
| 101 |
|
| 102 |
for (index = 0; index < ARRAY_LEN(facility_map); index++) { |
| 103 |
if (facility_map[index].value == facility) { |
| 104 |
return facility_map[index].name; |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
return NULL; |
| 109 |
} |
| 110 |
|
| 111 |
static const struct { |
| 112 |
const char *name; |
| 113 |
int value; |
| 114 |
} priority_map[] = { |
| 115 |
{ "alert", LOG_ALERT }, |
| 116 |
{ "crit", LOG_CRIT }, |
| 117 |
{ "debug", LOG_DEBUG }, |
| 118 |
{ "emerg", LOG_EMERG }, |
| 119 |
{ "err", LOG_ERR }, |
| 120 |
{ "error", LOG_ERR }, |
| 121 |
{ "info", LOG_INFO }, |
| 122 |
{ "notice", LOG_NOTICE }, |
| 123 |
{ "warning", LOG_WARNING }, |
| 124 |
}; |
| 125 |
|
| 126 |
int ast_syslog_priority(const char *priority) |
| 127 |
{ |
| 128 |
int index; |
| 129 |
|
| 130 |
for (index = 0; index < ARRAY_LEN(priority_map); index++) { |
| 131 |
if (!strcasecmp(priority_map[index].name, priority)) { |
| 132 |
return priority_map[index].value; |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
return -1; |
| 137 |
} |
| 138 |
|
| 139 |
const char *ast_syslog_priority_name(int priority) |
| 140 |
{ |
| 141 |
int index; |
| 142 |
|
| 143 |
for (index = 0; index < ARRAY_LEN(priority_map); index++) { |
| 144 |
if (priority_map[index].value == priority) { |
| 145 |
return priority_map[index].name; |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
return NULL; |
| 150 |
} |
| 151 |
|
| 152 |
static const int logger_level_to_syslog_map[] = { |
| 153 |
[__LOG_DEBUG] = LOG_DEBUG, |
| 154 |
[1] = LOG_INFO, |
| 155 |
[__LOG_NOTICE] = LOG_NOTICE, |
| 156 |
[__LOG_WARNING] = LOG_WARNING, |
| 157 |
[__LOG_ERROR] = LOG_ERR, |
| 158 |
[__LOG_VERBOSE] = LOG_DEBUG, |
| 159 |
[__LOG_DTMF] = LOG_DEBUG, |
| 160 |
}; |
| 161 |
|
| 162 |
int ast_syslog_priority_from_loglevel(int level) |
| 163 |
{ |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
if (level >= 16 && level < ASTNUMLOGLEVELS) { |
| 168 |
return LOG_NOTICE; |
| 169 |
} |
| 170 |
|
| 171 |
if (level < 0 || level >= ARRAY_LEN(logger_level_to_syslog_map)) { |
| 172 |
return -1; |
| 173 |
} |
| 174 |
|
| 175 |
return logger_level_to_syslog_map[level]; |
| 176 |
} |