| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
* logging.c: Defines the logging{} block of ircd.conf. |
| 4 |
* |
| 5 |
* Copyright (C) 2005 by the Hybrid Development Team. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 20 |
* USA |
| 21 |
* |
| 22 |
* $Id$ |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "stdinc.h" |
| 26 |
#include "conf/conf.h" |
| 27 |
#include "ircd.h" |
| 28 |
|
| 29 |
struct LoggingConf Logging; |
| 30 |
|
| 31 |
static dlink_node *hreset, *hverify; |
| 32 |
|
| 33 |
/* |
| 34 |
* reset_logging() |
| 35 |
* |
| 36 |
* Sets up default values before a rehash. |
| 37 |
* |
| 38 |
* inputs: none |
| 39 |
* output: none |
| 40 |
*/ |
| 41 |
static void * |
| 42 |
reset_logging(va_list args) |
| 43 |
{ |
| 44 |
set_log_level(L_NOTICE); |
| 45 |
|
| 46 |
Logging.use_logging = YES; |
| 47 |
Logging.operlog[0] = Logging.userlog[0] = Logging.klinelog[0] = |
| 48 |
Logging.glinelog[0] = Logging.killlog[0] = Logging.operspylog[0] = |
| 49 |
Logging.ioerrlog[0] = Logging.failed_operlog[0] = 0; |
| 50 |
|
| 51 |
return pass_callback(hreset); |
| 52 |
} |
| 53 |
|
| 54 |
/* |
| 55 |
* verify_logging() |
| 56 |
* |
| 57 |
* Reopens log files. |
| 58 |
* |
| 59 |
* inputs: none |
| 60 |
* output: none |
| 61 |
*/ |
| 62 |
static void * |
| 63 |
verify_logging(va_list args) |
| 64 |
{ |
| 65 |
if (Logging.use_logging) |
| 66 |
reopen_log(ServerState.logfile); |
| 67 |
|
| 68 |
return pass_callback(hverify); |
| 69 |
} |
| 70 |
|
| 71 |
static void |
| 72 |
set_log_path(void *value, void *where) |
| 73 |
{ |
| 74 |
strlcpy((char *) where, (const char *) value, PATH_MAX + 1); |
| 75 |
} |
| 76 |
|
| 77 |
static void |
| 78 |
conf_log_level(void *list, void *unused) |
| 79 |
{ |
| 80 |
int i; |
| 81 |
char *value; |
| 82 |
struct { char *name; int level; } levels[7] = { |
| 83 |
{"L_CRIT", L_CRIT}, |
| 84 |
{"L_ERROR", L_ERROR}, |
| 85 |
{"L_WARN", L_WARN}, |
| 86 |
{"L_NOTICE", L_NOTICE}, |
| 87 |
{"L_TRACE", L_TRACE}, |
| 88 |
{"L_INFO", L_INFO}, |
| 89 |
{"L_DEBUG", L_DEBUG} |
| 90 |
}; |
| 91 |
|
| 92 |
if (dlink_list_length((dlink_list *) list) != 1) |
| 93 |
{ |
| 94 |
error: |
| 95 |
parse_error("invalid log level"); |
| 96 |
return; |
| 97 |
} |
| 98 |
|
| 99 |
value = (char *) ((dlink_list *) list)->head->data; |
| 100 |
|
| 101 |
for (i = 0; i < 7; i++) |
| 102 |
if (!irccmp(value, levels[i].name)) |
| 103 |
{ |
| 104 |
set_log_level(levels[i].level); |
| 105 |
return; |
| 106 |
} |
| 107 |
|
| 108 |
goto error; |
| 109 |
} |
| 110 |
|
| 111 |
/* |
| 112 |
* init_logging() |
| 113 |
* |
| 114 |
* Defines the logging{} conf section. |
| 115 |
* |
| 116 |
* inputs: none |
| 117 |
* output: none |
| 118 |
*/ |
| 119 |
void |
| 120 |
init_logging(void) |
| 121 |
{ |
| 122 |
char *names[2] = {"logging", "log"}; |
| 123 |
char *short_fields[] = |
| 124 |
{"fuserlog", "foperlog", "fkilllog", "fklinelog", "fglinelog", |
| 125 |
"fioerrlog"}; |
| 126 |
char *long_fields[] = |
| 127 |
{"fname_userlog", "fname_operlog", "fname_killlog", "fname_klinelog", |
| 128 |
"fname_glinelog", "fname_ioerrlog"}; |
| 129 |
char *paths[] = |
| 130 |
{Logging.userlog, Logging.operlog, Logging.killlog, Logging.klinelog, |
| 131 |
Logging.glinelog, Logging.ioerrlog}; |
| 132 |
int i, j; |
| 133 |
|
| 134 |
hreset = install_hook(reset_conf, reset_logging); |
| 135 |
hverify = install_hook(verify_conf, verify_logging); |
| 136 |
|
| 137 |
for (i = 0; i < 2; i++) |
| 138 |
{ |
| 139 |
struct ConfSection *s = add_conf_section(names[i], 2); |
| 140 |
|
| 141 |
add_conf_field(s, "use_logging", CT_BOOL, NULL, &Logging.use_logging); |
| 142 |
add_conf_field(s, "logpath", CT_STRING, NULL, NULL); |
| 143 |
|
| 144 |
for (j = 0; j < 5; j++) |
| 145 |
{ |
| 146 |
add_conf_field(s, short_fields[j], CT_STRING, set_log_path, paths[j]); |
| 147 |
add_conf_field(s, long_fields[j], CT_STRING, set_log_path, paths[j]); |
| 148 |
} |
| 149 |
|
| 150 |
add_conf_field(s, "log_level", CT_LIST, conf_log_level, NULL); |
| 151 |
} |
| 152 |
} |