asterisk/main/syslog.c
Kevin P. Fleming 166b4e2b30 Multiple revisions 369001-369002
........
  r369001 | kpfleming | 2012-06-15 10:56:08 -0500 (Fri, 15 Jun 2012) | 11 lines
  
  Add support-level indications to many more source files.
  
  Since we now have tools that scan through the source tree looking for files
  with specific support levels, we need to ensure that every file that is
  a component of a 'core' or 'extended' module (or the main Asterisk binary)
  is explicitly marked with its support level. This patch adds support-level
  indications to many more source files in tree, but avoids adding them to
  third-party libraries that are included in the tree and to source files
  that don't end up involved in Asterisk itself.
........
  r369002 | kpfleming | 2012-06-15 10:57:14 -0500 (Fri, 15 Jun 2012) | 3 lines
  
  Add a script to enable finding source files without support-levels defined.
........

Merged revisions 369001-369002 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 369005 from http://svn.asterisk.org/svn/asterisk/branches/10


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@369013 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-06-15 16:20:16 +00:00

171 lines
3.9 KiB
C

/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2009, malleable, LLC.
*
* Sean Bright <sean@malleable.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*! \file
*
* \brief Asterisk Syslog Utility Functions
* \author Sean Bright <sean@malleable.com>
*/
/*** MODULEINFO
<support_level>core</support_level>
***/
#include "asterisk.h"
#include "asterisk/utils.h"
#include "asterisk/syslog.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <syslog.h>
static const struct {
const char *name;
int value;
} facility_map[] = {
/* POSIX only specifies USER and LOCAL0 - LOCAL7 */
{ "user", LOG_USER },
{ "local0", LOG_LOCAL0 },
{ "local1", LOG_LOCAL1 },
{ "local2", LOG_LOCAL2 },
{ "local3", LOG_LOCAL3 },
{ "local4", LOG_LOCAL4 },
{ "local5", LOG_LOCAL5 },
{ "local6", LOG_LOCAL6 },
{ "local7", LOG_LOCAL7 },
#if defined(HAVE_SYSLOG_FACILITY_LOG_KERN)
{ "kern", LOG_KERN },
#endif
#if defined(HAVE_SYSLOG_FACILITY_LOG_MAIL)
{ "mail", LOG_MAIL },
#endif
#if defined(HAVE_SYSLOG_FACILITY_LOG_DAEMON)
{ "daemon", LOG_DAEMON },
#endif
#if defined(HAVE_SYSLOG_FACILITY_LOG_AUTH)
{ "auth", LOG_AUTH },
{ "security", LOG_AUTH },
#endif
#if defined(HAVE_SYSLOG_FACILITY_LOG_AUTHPRIV)
{ "authpriv", LOG_AUTHPRIV },
#endif
#if defined(HAVE_SYSLOG_FACILITY_LOG_SYSLOG)
{ "syslog", LOG_SYSLOG },
#endif
#if defined(HAVE_SYSLOG_FACILITY_LOG_FTP)
{ "ftp", LOG_FTP },
#endif
#if defined(HAVE_SYSLOG_FACILITY_LOG_LPR)
{ "lpr", LOG_LPR },
#endif
#if defined(HAVE_SYSLOG_FACILITY_LOG_NEWS)
{ "news", LOG_NEWS },
#endif
#if defined(HAVE_SYSLOG_FACILITY_LOG_UUCP)
{ "uucp", LOG_UUCP },
#endif
#if defined(HAVE_SYSLOG_FACILITY_LOG_CRON)
{ "cron", LOG_CRON },
#endif
};
int ast_syslog_facility(const char *facility)
{
int index;
for (index = 0; index < ARRAY_LEN(facility_map); index++) {
if (!strcasecmp(facility_map[index].name, facility)) {
return facility_map[index].value;
}
}
return -1;
}
const char *ast_syslog_facility_name(int facility)
{
int index;
for (index = 0; index < ARRAY_LEN(facility_map); index++) {
if (facility_map[index].value == facility) {
return facility_map[index].name;
}
}
return NULL;
}
static const struct {
const char *name;
int value;
} priority_map[] = {
{ "alert", LOG_ALERT },
{ "crit", LOG_CRIT },
{ "debug", LOG_DEBUG },
{ "emerg", LOG_EMERG },
{ "err", LOG_ERR },
{ "error", LOG_ERR },
{ "info", LOG_INFO },
{ "notice", LOG_NOTICE },
{ "warning", LOG_WARNING },
};
int ast_syslog_priority(const char *priority)
{
int index;
for (index = 0; index < ARRAY_LEN(priority_map); index++) {
if (!strcasecmp(priority_map[index].name, priority)) {
return priority_map[index].value;
}
}
return -1;
}
const char *ast_syslog_priority_name(int priority)
{
int index;
for (index = 0; index < ARRAY_LEN(priority_map); index++) {
if (priority_map[index].value == priority) {
return priority_map[index].name;
}
}
return NULL;
}
static const int logger_level_to_syslog_map[] = {
[__LOG_DEBUG] = LOG_DEBUG,
[1] = LOG_INFO, /* Only kept for backwards compatibility */
[__LOG_NOTICE] = LOG_NOTICE,
[__LOG_WARNING] = LOG_WARNING,
[__LOG_ERROR] = LOG_ERR,
[__LOG_VERBOSE] = LOG_DEBUG,
[__LOG_DTMF] = LOG_DEBUG,
};
int ast_syslog_priority_from_loglevel(int level)
{
if (level < 0 || level >= ARRAY_LEN(logger_level_to_syslog_map)) {
return -1;
}
return logger_level_to_syslog_map[level];
}