summaryrefslogtreecommitdiff
path: root/logging.h
blob: 2c9764f3969257a7d837909e21f846d1a2faf083 (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
/*
 * This file is part of blabouncer (https://www.blatech.co.uk/l_bratch/blabouncer).
 * Copyright (C) 2019 Luke Bratch <luke@bratch.co.uk>.
 *
 * Blabouncer 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, version 3.
 *
 * Blabouncer 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 blabouncer. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef LOGGING_H_INCLUDED
#define LOGGING_H_INCLUDED

#include <stdio.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <sys/stat.h>
#include <ctype.h>

#include "functions.h"

#define MAXTOKENS 100
#define MAXDATASIZE 513 // max number of bytes we can get at once (RFC2812 says 512, plus one for null terminator)
#define MAXCHAR 1000

#define SOURCE_SERVER 0
#define SOURCE_CLIENT 1
#define LOG_PRIVMSG 0
#define LOG_JOINPART 1
#define LOG_TOPIC 2
#define LOG_NETWORK 3
#define LOG_QUIT 4
#define LOG_NICK 5
#define LOG_MODE 6
#define LOG_KICK 7
#define DEBUG_CRIT 0
#define DEBUG_SOME 1
#define DEBUG_FULL 2

// Write the line 'str' to the relevant log file such as
// '#channel.log' or 'nickname.log'.  'ircdstate->ircnick'
// is our own nick and is used to determine which log file
// to write to if the type is LOG_PRIVMSG.
// 'basedir' is the directory in which the 'logs' directory
// will be created in which logs are to be written.
//
// If LOG_PRIVMSG then it expects a string in the format:
// :from!bar@baz PRIVMSG to :hello world
//
// LOG_PRIVMSG is also used for NOTICEs.
//
// If LOG_JOINPART then it expects a string in the format:
// :nick!bar@baz JOIN :#channel
// or
// :nick!bar@baz PART #channel
//
// If LOG_TOPIC then it expects a string in the format:
// :nick!bar@baz TOPIC #channel :bla bla bla
//
// If LOG_NETWORK then it just logs the string verbatim in
// a file named 'ircdstate->ircdname'.log.
//
// If LOG_QUIT then it expects a string in the format:
// channelname :nick!bar@baz QUIT :bla bla bla
// 'channelname' probably has to be prepended manually by the
// caller since it doesn't feature in the raw message from
// the IRCd.  We need it in logline() to log to the relevant
// channel log file.  The caller probably has to call logline()
// multiple times for each channel the nick was in.
//
// If LOG_NICK then it expects a string in the format:
// channelname :oldnick!bar@baz NICK :newnick
// Same manual 'channelname' prepending as LOG_QUIT above.
//
// If LOG_MODE then it expects a string in the format:
// :nick!bar@baz MODE #channel foo bar [foo bar...]
//
// If LOG_KICK then it expects a string in the format:
// :kicker!bar@baz KICK #channel kickee :bla bla bla
//
// With the ":foo!bar@baz "prefix being important for all
// types.
//
// Returns 1 on success or 0 on failure.
int logline(char *str, struct ircdstate *ircdstate, char *basedir, int type);

#endif