Initial import (again)
[srvx.git] / src / log.h
1 /* log.h - Diagnostic and error logging
2  * Copyright 2000-2003 srvx Development Team
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.  Important limitations are
8  * listed in the COPYING file that accompanies this software.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, email srvx-maintainers@srvx.net.
17  */
18
19 #ifndef LOG_H
20 #define LOG_H
21
22 #include "common.h"
23
24 enum log_severity {
25     LOG_REPLAY,   /* 0 */
26     LOG_DEBUG,
27     LOG_COMMAND,
28     LOG_INFO,
29     LOG_OVERRIDE,
30     LOG_STAFF,    /* 5 */
31     LOG_WARNING,
32     LOG_ERROR,
33     LOG_FATAL,
34     LOG_NUM_SEVERITIES
35 };
36
37 struct log_type;
38
39 void log_init(void);
40 void log_reopen(void);
41 void log_debug(void);
42
43 /* bitmap values in flags parameter to log_audit */
44 #define AUDIT_HOSTMASK  0x01
45
46 struct log_type *log_register_type(const char *name, const char *default_log);
47 /* constraint for log_audit: sev one of LOG_COMMAND, LOG_OVERRIDE, LOG_STAFF */
48 void log_audit(struct log_type *type, enum log_severity sev, struct userNode *user, struct userNode *bot, const char *channel_name, unsigned int flags, const char *command);
49 /* constraint for log_module: sev < LOG_COMMAND */
50 void log_module(struct log_type *type, enum log_severity sev, const char *format, ...) PRINTF_LIKE(3, 4);
51 void log_replay(struct log_type *type, int is_write, const char *line);
52
53 /* Log searching functions - ONLY searches log_audit'ed data */
54
55 struct logEntry
56 {
57                                       /* field nullable in real entries? */
58     time_t            time;
59     enum log_severity slvl;
60     struct userNode   *bot;           /* no */
61     char              *channel_name;  /* yes */
62     char              *user_nick;     /* no */
63     char              *user_account;  /* yes */
64     char              *user_hostmask; /* yes */
65     char              *command;       /* no */
66     char              *default_desc;
67     struct logEntry   *next;
68     struct logEntry   *prev;
69 };
70
71 struct logSearch
72 {
73     struct logEntry  masks;
74     struct log_type  *type;
75     time_t           min_time;
76     time_t           max_time;
77     unsigned int     limit;
78     unsigned int     severities;
79 };
80
81 struct logReport
82 {
83     struct userNode  *reporter;
84     struct userNode  *user;
85 };
86
87 typedef void (*entry_search_func)(struct logEntry *match, void *extra);
88 void log_report_entry(struct logEntry *match, void *extra);
89 struct logSearch* log_discrim_create(struct userNode *service, struct userNode *user, unsigned int argc, char *argv[]);
90 unsigned int log_entry_search(struct logSearch *discrim, entry_search_func esf, void *data);
91 void report_entry(struct userNode *service, struct userNode *user, struct logEntry *entry);
92
93 #endif