summaryrefslogtreecommitdiff
path: root/libmailutils/diag/syslog.c
blob: 9451bafa8b9123cb2c2d2f2fd54757e390fbf15f (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* GNU Mailutils -- a suite of utilities for electronic mail
   Copyright (C) 2007-2012, 2014 Free Software Foundation, Inc.

   GNU Mailutils is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 3 of the License, or (at your
   option) any later version.

   GNU Mailutils is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <syslog.h>
#include <string.h>
#include <mailutils/diag.h>
#include <mailutils/kwd.h>
#include <mailutils/syslog.h>
#include <mailutils/cstr.h>

#ifndef LOG_AUTHPRIV
# define LOG_AUTHPRIV
#endif

static mu_kwd_t kw_facility[] = {
  { "USER",    LOG_USER },   
  { "DAEMON",  LOG_DAEMON },
  { "AUTH",    LOG_AUTH },
  { "AUTHPRIV",LOG_AUTHPRIV },
  { "MAIL",    LOG_MAIL },
  { "CRON",    LOG_CRON },
  { "LOCAL0",  LOG_LOCAL0 },
  { "LOCAL1",  LOG_LOCAL1 },
  { "LOCAL2",  LOG_LOCAL2 },
  { "LOCAL3",  LOG_LOCAL3 },
  { "LOCAL4",  LOG_LOCAL4 },
  { "LOCAL5",  LOG_LOCAL5 },
  { "LOCAL6",  LOG_LOCAL6 },
  { "LOCAL7",  LOG_LOCAL7 },
  { NULL }
};

static int
syslog_to_n (mu_kwd_t *kw, const char *str, int *pint)
{
  if (mu_c_strncasecmp (str, "LOG_", 4) == 0)
    str += 4;
  return mu_kwd_xlat_name_ci (kw, str, pint);
}

int
mu_string_to_syslog_facility (const char *str, int *pfacility)
{
  return syslog_to_n (kw_facility, str, pfacility);
}

const char *
mu_syslog_facility_to_string (int n)
{
  const char *res = NULL;
  mu_kwd_xlat_tok (kw_facility, n, &res);
  return res;
}

static mu_kwd_t kw_prio[] = {
  { "EMERG", LOG_EMERG },
  { "ALERT", LOG_ALERT },
  { "CRIT", LOG_CRIT },
  { "ERR", LOG_ERR },
  { "WARNING", LOG_WARNING },
  { "NOTICE", LOG_NOTICE },
  { "INFO", LOG_INFO },
  { "DEBUG", LOG_DEBUG },
  { NULL }
};

int
mu_string_to_syslog_priority (const char *str, int *pprio)
{
  return syslog_to_n (kw_prio, str, pprio);
}

const char *
mu_syslog_priority_to_string (int n)
{
  const char *res = NULL;
  mu_kwd_xlat_tok (kw_prio, n, &res);
  return res;
}

int
mu_diag_level_to_syslog (mu_log_level_t level)
{
  switch (level)
    {
    case MU_DIAG_EMERG:
      return LOG_EMERG;
      
    case MU_DIAG_ALERT:
      return LOG_ALERT;
	
    case MU_DIAG_CRIT:
      return LOG_CRIT;
      
    case MU_DIAG_ERROR:
      return LOG_ERR;
      
    case MU_DIAG_WARNING:
      return LOG_WARNING;
      
    case MU_DIAG_NOTICE:
      return LOG_NOTICE;
      
    case MU_DIAG_INFO:
      return LOG_INFO;
      
    case MU_DIAG_DEBUG:
      return LOG_DEBUG;
    }
  return LOG_EMERG;
}



int mu_log_syslog = 0;
int mu_log_facility = LOG_FACILITY;
char *mu_log_tag = NULL;
int mu_log_print_severity = 0;
unsigned mu_log_severity_threshold = MU_LOG_DEBUG;
int mu_log_session_id;

Return to:

Send suggestions and report system problems to the System administrator.