better log file format, log options, with backlog with memory based backlog
This commit is contained in:
parent
5e939ecd4d
commit
3a46247bd4
35
src/bip.c
35
src/bip.c
@ -46,7 +46,9 @@ hash_t adm_users;
|
||||
|
||||
/* log options, for sure the trickiest :) */
|
||||
/* no backlog at all */
|
||||
int conf_no_backlog;
|
||||
int conf_backlog;
|
||||
int conf_memlog;
|
||||
int conf_log;
|
||||
/* number of lines in backlog */
|
||||
int conf_backlog_lines = 10;
|
||||
/* backlog even lines already backlogged */
|
||||
@ -576,8 +578,11 @@ int fireup(FILE *conf)
|
||||
case LEX_ALWAYS_BACKLOG:
|
||||
conf_always_backlog = t->ndata;
|
||||
break;
|
||||
case LEX_NO_BACKLOG:
|
||||
conf_no_backlog = t->ndata;
|
||||
case LEX_BACKLOG:
|
||||
conf_backlog = t->ndata;
|
||||
break;
|
||||
case LEX_LOG:
|
||||
conf_log = t->ndata;
|
||||
break;
|
||||
case LEX_BACKLOG_LINES:
|
||||
conf_backlog_lines = t->ndata;
|
||||
@ -623,6 +628,25 @@ int fireup(FILE *conf)
|
||||
}
|
||||
}
|
||||
|
||||
if (conf_backlog && !conf_log) {
|
||||
if (conf_backlog_lines == 0) {
|
||||
fatal("you must set conf_backlog_lines if conf_log = "
|
||||
"false and conf_backlog = true");
|
||||
}
|
||||
}
|
||||
|
||||
if (conf_always_backlog) {
|
||||
if (conf_backlog_lines == 0) {
|
||||
fatal("you must have not nul conf_backlog_lines if "
|
||||
"conf_always_backlog is enabled");
|
||||
}
|
||||
}
|
||||
|
||||
if (!conf_log)
|
||||
conf_memlog = 1;
|
||||
else
|
||||
conf_memlog = 0;
|
||||
|
||||
/*
|
||||
check_networks(networkl);
|
||||
check_clients(userl);
|
||||
@ -667,6 +691,8 @@ int fireup(FILE *conf)
|
||||
#endif
|
||||
if (!conf_log_format)
|
||||
conf_log_format = "%u/%n/%Y-%m/%c.%d.log";
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -851,7 +877,8 @@ int main(int argc, char **argv)
|
||||
conf_log_root = NULL;
|
||||
conf_log_format = NULL;
|
||||
conf_log_level = LOG_ERROR;
|
||||
conf_no_backlog = 0;
|
||||
conf_backlog = 1;
|
||||
conf_log = 1;
|
||||
conf_backlog_lines = 100;
|
||||
conf_log_sync_interval = 5;
|
||||
conf_daemonize = 1;
|
||||
|
637
src/conf.c
637
src/conf.c
File diff suppressed because it is too large
Load Diff
56
src/conf.h
56
src/conf.h
@ -1,4 +1,4 @@
|
||||
/* A Bison parser, made by GNU Bison 1.875d. */
|
||||
/* A Bison parser, made by GNU Bison 2.0. */
|
||||
|
||||
/* Skeleton parser for Yacc-like parsing with Bison,
|
||||
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
|
||||
@ -59,18 +59,19 @@
|
||||
LEX_LOG_FORMAT = 285,
|
||||
LEX_LOG_LEVEL = 286,
|
||||
LEX_BACKLOG_LINES = 287,
|
||||
LEX_NO_BACKLOG = 288,
|
||||
LEX_LOG_SYNC_INTERVAL = 289,
|
||||
LEX_FOLLOW_NICK = 290,
|
||||
LEX_ON_CONNECT_SEND = 291,
|
||||
LEX_AWAY_NICK = 292,
|
||||
LEX_PID_FILE = 293,
|
||||
LEX_IGN_FIRST_NICK = 294,
|
||||
LEX_ALWAYS_BACKLOG = 295,
|
||||
LEX_LOGIN = 296,
|
||||
LEX_BOOL = 297,
|
||||
LEX_INT = 298,
|
||||
LEX_STRING = 299
|
||||
LEX_BACKLOG = 288,
|
||||
LEX_LOG = 289,
|
||||
LEX_LOG_SYNC_INTERVAL = 290,
|
||||
LEX_FOLLOW_NICK = 291,
|
||||
LEX_ON_CONNECT_SEND = 292,
|
||||
LEX_AWAY_NICK = 293,
|
||||
LEX_PID_FILE = 294,
|
||||
LEX_IGN_FIRST_NICK = 295,
|
||||
LEX_ALWAYS_BACKLOG = 296,
|
||||
LEX_LOGIN = 297,
|
||||
LEX_BOOL = 298,
|
||||
LEX_INT = 299,
|
||||
LEX_STRING = 300
|
||||
};
|
||||
#endif
|
||||
#define LEX_IP 258
|
||||
@ -103,18 +104,19 @@
|
||||
#define LEX_LOG_FORMAT 285
|
||||
#define LEX_LOG_LEVEL 286
|
||||
#define LEX_BACKLOG_LINES 287
|
||||
#define LEX_NO_BACKLOG 288
|
||||
#define LEX_LOG_SYNC_INTERVAL 289
|
||||
#define LEX_FOLLOW_NICK 290
|
||||
#define LEX_ON_CONNECT_SEND 291
|
||||
#define LEX_AWAY_NICK 292
|
||||
#define LEX_PID_FILE 293
|
||||
#define LEX_IGN_FIRST_NICK 294
|
||||
#define LEX_ALWAYS_BACKLOG 295
|
||||
#define LEX_LOGIN 296
|
||||
#define LEX_BOOL 297
|
||||
#define LEX_INT 298
|
||||
#define LEX_STRING 299
|
||||
#define LEX_BACKLOG 288
|
||||
#define LEX_LOG 289
|
||||
#define LEX_LOG_SYNC_INTERVAL 290
|
||||
#define LEX_FOLLOW_NICK 291
|
||||
#define LEX_ON_CONNECT_SEND 292
|
||||
#define LEX_AWAY_NICK 293
|
||||
#define LEX_PID_FILE 294
|
||||
#define LEX_IGN_FIRST_NICK 295
|
||||
#define LEX_ALWAYS_BACKLOG 296
|
||||
#define LEX_LOGIN 297
|
||||
#define LEX_BOOL 298
|
||||
#define LEX_INT 299
|
||||
#define LEX_STRING 300
|
||||
|
||||
|
||||
|
||||
@ -127,8 +129,8 @@ typedef union YYSTYPE {
|
||||
void *list;
|
||||
struct tuple *tuple;
|
||||
} YYSTYPE;
|
||||
/* Line 1285 of yacc.c. */
|
||||
#line 132 "y.tab.h"
|
||||
/* Line 1318 of yacc.c. */
|
||||
#line 134 "y.tab.h"
|
||||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
|
@ -79,7 +79,7 @@ struct tuple *tuple_l_new(int type, void *p)
|
||||
}
|
||||
%}
|
||||
|
||||
%token LEX_IP LEX_EQ LEX_PORT LEX_CSS LEX_SEMICOLON LEX_CONNECTION LEX_NETWORK LEX_LBRA LEX_RBRA LEX_USER LEX_NAME LEX_USERNAME LEX_NICK LEX_SERVER LEX_PASSWORD LEX_SRCIP LEX_HOST LEX_VHOST LEX_SOURCE_PORT LEX_NONE LEX_COMMENT LEX_BUNCH LEX_REALNAME LEX_SSL LEX_CHANNEL LEX_KEY LEX_LOG_ROOT LEX_LOG_FORMAT LEX_LOG_LEVEL LEX_BACKLOG_LINES LEX_NO_BACKLOG LEX_LOG_SYNC_INTERVAL LEX_FOLLOW_NICK LEX_ON_CONNECT_SEND LEX_AWAY_NICK LEX_PID_FILE LEX_IGN_FIRST_NICK LEX_ALWAYS_BACKLOG LEX_LOGIN
|
||||
%token LEX_IP LEX_EQ LEX_PORT LEX_CSS LEX_SEMICOLON LEX_CONNECTION LEX_NETWORK LEX_LBRA LEX_RBRA LEX_USER LEX_NAME LEX_USERNAME LEX_NICK LEX_SERVER LEX_PASSWORD LEX_SRCIP LEX_HOST LEX_VHOST LEX_SOURCE_PORT LEX_NONE LEX_COMMENT LEX_BUNCH LEX_REALNAME LEX_SSL LEX_CHANNEL LEX_KEY LEX_LOG_ROOT LEX_LOG_FORMAT LEX_LOG_LEVEL LEX_BACKLOG_LINES LEX_BACKLOG LEX_LOG LEX_LOG_SYNC_INTERVAL LEX_FOLLOW_NICK LEX_ON_CONNECT_SEND LEX_AWAY_NICK LEX_PID_FILE LEX_IGN_FIRST_NICK LEX_ALWAYS_BACKLOG LEX_LOGIN
|
||||
|
||||
%union {
|
||||
int number;
|
||||
@ -110,8 +110,9 @@ command:
|
||||
| LEX_CSS LEX_EQ LEX_BOOL { $$ = tuple_i_new(LEX_CSS, $3); }
|
||||
| LEX_BACKLOG_LINES LEX_EQ LEX_INT { $$ = tuple_i_new(LEX_BACKLOG_LINES,
|
||||
$3); }
|
||||
| LEX_NO_BACKLOG LEX_EQ LEX_BOOL { $$ = tuple_i_new(LEX_NO_BACKLOG,
|
||||
| LEX_BACKLOG LEX_EQ LEX_BOOL { $$ = tuple_i_new(LEX_BACKLOG,
|
||||
$3); }
|
||||
| LEX_LOG LEX_EQ LEX_BOOL { $$ = tuple_i_new(LEX_LOG, $3); }
|
||||
| LEX_ALWAYS_BACKLOG LEX_EQ LEX_BOOL { $$ = tuple_i_new(
|
||||
LEX_ALWAYS_BACKLOG, $3); }
|
||||
| LEX_LOG_SYNC_INTERVAL LEX_EQ LEX_INT { $$ = tuple_i_new(
|
||||
|
28
src/irc.c
28
src/irc.c
@ -41,7 +41,7 @@ void irc_server_shutdown(struct link_server *s);
|
||||
|
||||
void irc_client_free(struct link_client *cli);
|
||||
static char *make_irc_mask(char *nick, char *oldim);
|
||||
extern int conf_no_backlog;
|
||||
extern int conf_backlog;
|
||||
extern int conf_log_sync_interval;
|
||||
extern int conf_error;
|
||||
extern char conf_errstr[];
|
||||
@ -457,16 +457,10 @@ static void irc_send_join(struct link_client *ic, struct channel *chan)
|
||||
chan->name, chan->creator, chan->create_ts);
|
||||
|
||||
/* XXX: could be more efficient */
|
||||
if (!conf_no_backlog && log_has_backlog(LINK(ic)->log, chan->name)) {
|
||||
if (conf_backlog && log_has_backlog(LINK(ic)->log, chan->name)) {
|
||||
char *line;
|
||||
int raw;
|
||||
while ((line = log_backread(LINK(ic)->log, chan->name, &raw))) {
|
||||
mylog(LOG_DEBUG, "backread:%s\n", line);
|
||||
if (raw)
|
||||
write_line(CONN(ic), line);
|
||||
else
|
||||
WRITE_LINE2(CONN(ic), P_IRCMASK, "PRIVMSG",
|
||||
chan->name, line);
|
||||
while ((line = log_backread(LINK(ic)->log, chan->name))) {
|
||||
write_line(CONN(ic), line);
|
||||
free(line);
|
||||
}
|
||||
WRITE_LINE2(CONN(ic), P_IRCMASK, "PRIVMSG", chan->name,
|
||||
@ -633,14 +627,8 @@ static int irc_cli_startup(struct link_client *ic, struct line *line,
|
||||
|
||||
/* backlog privates */
|
||||
char *str;
|
||||
int raw;
|
||||
while ((str = log_backread(LINK(ic)->log, S_PRIVATES, &raw))) {
|
||||
mylog(LOG_DEBUG, "backread:%s\n", line);
|
||||
if (raw)
|
||||
write_line(CONN(ic), str);
|
||||
else
|
||||
WRITE_LINE2(CONN(ic), P_IRCMASK, "PRIVMSG",
|
||||
LINK(ic)->l_server->nick, str);
|
||||
while ((str = log_backread(LINK(ic)->log, S_PRIVATES))) {
|
||||
write_line(CONN(ic), str);
|
||||
free(str);
|
||||
}
|
||||
|
||||
@ -717,14 +705,14 @@ static int irc_cli_quit(struct link_client *ic, struct line *line)
|
||||
|
||||
static int irc_cli_privmsg(struct link_client *ic, struct line *line)
|
||||
{
|
||||
log_privmsg(LINK(ic)->log, LINK(ic)->l_server->nick,
|
||||
log_cli_privmsg(LINK(ic)->log, LINK(ic)->l_server->nick,
|
||||
line->elemv[1], line->elemv[2]);
|
||||
return OK_COPY_CLI;
|
||||
}
|
||||
|
||||
static int irc_cli_notice(struct link_client *ic, struct line *line)
|
||||
{
|
||||
log_notice(LINK(ic)->log, LINK(ic)->l_server->nick,
|
||||
log_cli_notice(LINK(ic)->log, LINK(ic)->l_server->nick,
|
||||
line->elemv[1], line->elemv[2]);
|
||||
return OK_COPY_CLI;
|
||||
}
|
||||
|
300
src/lex.c
300
src/lex.c
@ -351,8 +351,8 @@ static void yy_fatal_error (yyconst char msg[] );
|
||||
*yy_cp = '\0'; \
|
||||
(yy_c_buf_p) = yy_cp;
|
||||
|
||||
#define YY_NUM_RULES 43
|
||||
#define YY_END_OF_BUFFER 44
|
||||
#define YY_NUM_RULES 44
|
||||
#define YY_END_OF_BUFFER 45
|
||||
/* This struct is not used in this scanner,
|
||||
but its presence is necessary. */
|
||||
struct yy_trans_info
|
||||
@ -360,36 +360,35 @@ struct yy_trans_info
|
||||
flex_int32_t yy_verify;
|
||||
flex_int32_t yy_nxt;
|
||||
};
|
||||
static yyconst flex_int16_t yy_accept[257] =
|
||||
static yyconst flex_int16_t yy_accept[248] =
|
||||
{ 0,
|
||||
0, 0, 44, 42, 1, 2, 42, 42, 4, 41,
|
||||
38, 42, 42, 42, 42, 42, 42, 42, 42, 42,
|
||||
42, 42, 42, 42, 42, 42, 42, 39, 40, 1,
|
||||
0, 37, 0, 3, 4, 0, 0, 0, 0, 0,
|
||||
0, 0, 45, 43, 1, 2, 43, 43, 4, 42,
|
||||
39, 43, 43, 43, 43, 43, 43, 43, 43, 43,
|
||||
43, 43, 43, 43, 43, 43, 43, 40, 41, 1,
|
||||
0, 38, 0, 3, 4, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 6, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 23, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 22, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 11, 0,
|
||||
0, 0, 23, 30, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 22, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 11, 0, 0, 0,
|
||||
|
||||
0, 0, 12, 0, 17, 0, 0, 0, 0, 7,
|
||||
0, 0, 0, 5, 14, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 15, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 20, 0,
|
||||
12, 0, 17, 0, 0, 0, 7, 0, 0, 0,
|
||||
5, 14, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 15, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 20, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 9, 0, 0,
|
||||
0, 0, 0, 24, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 10, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 26,
|
||||
0, 0, 0, 21, 36, 18, 0, 13, 0, 34,
|
||||
0, 0, 9, 0, 0, 0, 0, 29, 24, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 10, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 26, 0, 0, 21, 37, 18, 0,
|
||||
13, 0, 35, 0, 0, 0, 0, 0, 0, 25,
|
||||
|
||||
0, 0, 0, 0, 0, 0, 25, 0, 0, 0,
|
||||
0, 0, 0, 0, 16, 0, 0, 27, 0, 29,
|
||||
0, 0, 0, 0, 0, 32, 0, 0, 0, 19,
|
||||
0, 0, 0, 0, 0, 0, 0, 28, 0, 0,
|
||||
0, 0, 30, 0, 0, 0, 0, 8, 0, 0,
|
||||
35, 0, 0, 33, 31, 0
|
||||
0, 0, 0, 0, 0, 0, 16, 0, 0, 27,
|
||||
0, 0, 0, 0, 0, 0, 33, 0, 0, 0,
|
||||
19, 0, 0, 0, 0, 0, 0, 0, 28, 0,
|
||||
0, 0, 0, 31, 0, 0, 0, 0, 8, 0,
|
||||
0, 36, 0, 0, 34, 32, 0
|
||||
} ;
|
||||
|
||||
static yyconst flex_int32_t yy_ec[256] =
|
||||
@ -432,84 +431,81 @@ static yyconst flex_int32_t yy_meta[35] =
|
||||
1, 1, 1, 1
|
||||
} ;
|
||||
|
||||
static yyconst flex_int16_t yy_base[259] =
|
||||
static yyconst flex_int16_t yy_base[250] =
|
||||
{ 0,
|
||||
0, 0, 268, 269, 33, 269, 262, 263, 258, 269,
|
||||
269, 15, 253, 20, 28, 239, 23, 247, 237, 32,
|
||||
237, 31, 244, 30, 232, 230, 238, 269, 269, 56,
|
||||
250, 269, 251, 269, 246, 221, 240, 237, 238, 229,
|
||||
224, 225, 224, 217, 220, 269, 210, 224, 218, 211,
|
||||
225, 227, 226, 208, 220, 207, 221, 205, 201, 208,
|
||||
199, 212, 202, 214, 192, 203, 199, 206, 197, 192,
|
||||
197, 189, 192, 269, 43, 200, 183, 193, 200, 198,
|
||||
183, 199, 180, 186, 176, 179, 269, 189, 177, 175,
|
||||
169, 190, 178, 175, 174, 181, 180, 170, 269, 167,
|
||||
0, 0, 259, 260, 33, 260, 253, 254, 249, 260,
|
||||
260, 15, 244, 20, 28, 230, 23, 238, 228, 32,
|
||||
228, 31, 235, 30, 223, 221, 229, 260, 260, 54,
|
||||
241, 260, 242, 260, 237, 212, 231, 228, 229, 220,
|
||||
215, 216, 215, 208, 211, 260, 201, 215, 209, 202,
|
||||
216, 218, 200, 212, 199, 213, 197, 193, 200, 191,
|
||||
204, 194, 206, 184, 195, 191, 198, 189, 184, 189,
|
||||
181, 184, 260, 43, 192, 175, 185, 191, 176, 192,
|
||||
173, 179, 169, 172, 260, 182, 170, 168, 162, 183,
|
||||
171, 168, 167, 174, 173, 163, 260, 160, 43, 162,
|
||||
|
||||
43, 169, 269, 167, 269, 179, 165, 157, 171, 269,
|
||||
163, 170, 171, 269, 160, 154, 154, 157, 155, 163,
|
||||
149, 163, 144, 159, 149, 157, 147, 138, 269, 143,
|
||||
155, 144, 142, 146, 153, 137, 147, 150, 269, 150,
|
||||
140, 141, 136, 146, 127, 144, 143, 126, 121, 126,
|
||||
126, 128, 127, 123, 119, 123, 121, 269, 132, 119,
|
||||
128, 126, 128, 269, 110, 117, 112, 118, 111, 117,
|
||||
103, 117, 269, 108, 113, 113, 111, 110, 99, 108,
|
||||
111, 101, 99, 100, 94, 98, 97, 104, 93, 269,
|
||||
103, 88, 98, 269, 269, 269, 86, 269, 96, 269,
|
||||
260, 160, 260, 159, 151, 165, 260, 157, 164, 165,
|
||||
260, 154, 148, 148, 151, 149, 157, 143, 157, 138,
|
||||
153, 143, 151, 141, 132, 260, 137, 139, 137, 141,
|
||||
148, 132, 142, 145, 260, 145, 135, 136, 131, 141,
|
||||
122, 139, 138, 121, 116, 121, 121, 123, 119, 115,
|
||||
119, 117, 260, 128, 115, 124, 122, 124, 260, 106,
|
||||
113, 108, 114, 107, 113, 99, 113, 260, 110, 110,
|
||||
108, 107, 96, 105, 108, 98, 96, 97, 91, 95,
|
||||
94, 101, 90, 260, 100, 96, 260, 260, 260, 84,
|
||||
260, 94, 260, 87, 91, 81, 90, 76, 73, 260,
|
||||
|
||||
89, 93, 83, 92, 78, 75, 269, 83, 84, 72,
|
||||
73, 78, 74, 81, 269, 75, 67, 269, 70, 269,
|
||||
82, 63, 69, 74, 78, 269, 59, 58, 58, 269,
|
||||
60, 56, 55, 71, 65, 64, 61, 269, 50, 53,
|
||||
49, 51, 269, 52, 53, 41, 54, 269, 54, 55,
|
||||
269, 45, 42, 269, 269, 269, 60, 48
|
||||
81, 71, 72, 77, 73, 80, 260, 74, 66, 260,
|
||||
69, 81, 62, 68, 73, 77, 260, 58, 57, 57,
|
||||
260, 59, 55, 54, 70, 64, 63, 60, 260, 49,
|
||||
52, 48, 50, 260, 51, 52, 38, 53, 260, 53,
|
||||
54, 260, 43, 40, 260, 260, 260, 59, 48
|
||||
} ;
|
||||
|
||||
static yyconst flex_int16_t yy_def[259] =
|
||||
static yyconst flex_int16_t yy_def[250] =
|
||||
{ 0,
|
||||
256, 1, 256, 256, 256, 256, 257, 258, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
257, 256, 258, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
247, 1, 247, 247, 247, 247, 248, 249, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
248, 247, 249, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 0, 256, 256
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 0, 247, 247
|
||||
} ;
|
||||
|
||||
static yyconst flex_int16_t yy_nxt[304] =
|
||||
static yyconst flex_int16_t yy_nxt[295] =
|
||||
{ 0,
|
||||
4, 5, 6, 5, 7, 8, 9, 10, 11, 4,
|
||||
12, 13, 14, 4, 4, 15, 4, 16, 17, 18,
|
||||
19, 4, 20, 21, 22, 23, 24, 25, 26, 27,
|
||||
4, 4, 28, 29, 30, 36, 30, 39, 42, 45,
|
||||
40, 54, 49, 41, 58, 37, 50, 46, 33, 55,
|
||||
51, 43, 101, 59, 56, 52, 60, 30, 125, 30,
|
||||
31, 102, 255, 126, 254, 253, 252, 251, 127, 128,
|
||||
250, 249, 248, 247, 246, 245, 244, 243, 242, 241,
|
||||
40, 53, 49, 41, 57, 37, 50, 46, 33, 54,
|
||||
51, 43, 99, 58, 55, 30, 59, 30, 122, 31,
|
||||
246, 100, 245, 123, 244, 243, 242, 241, 124, 125,
|
||||
240, 239, 238, 237, 236, 235, 234, 233, 232, 231,
|
||||
230, 229, 228, 227, 226, 225, 224, 223, 222, 221,
|
||||
|
||||
220, 219, 218, 217, 216, 215, 214, 213, 212, 211,
|
||||
|
||||
210, 209, 208, 207, 206, 205, 204, 203, 202, 201,
|
||||
200, 199, 198, 197, 196, 195, 194, 193, 192, 191,
|
||||
190, 189, 188, 187, 186, 185, 184, 183, 182, 181,
|
||||
@ -518,58 +514,57 @@ static yyconst flex_int16_t yy_nxt[304] =
|
||||
160, 159, 158, 157, 156, 155, 154, 153, 152, 151,
|
||||
150, 149, 148, 147, 146, 145, 144, 143, 142, 141,
|
||||
140, 139, 138, 137, 136, 135, 134, 133, 132, 131,
|
||||
130, 129, 124, 123, 114, 122, 121, 120, 119, 118,
|
||||
|
||||
130, 129, 128, 127, 126, 121, 120, 111, 119, 118,
|
||||
117, 116, 115, 114, 113, 112, 111, 110, 109, 108,
|
||||
107, 106, 105, 104, 103, 100, 99, 98, 97, 96,
|
||||
|
||||
107, 106, 105, 104, 103, 102, 101, 98, 97, 96,
|
||||
95, 94, 93, 92, 91, 90, 89, 88, 87, 86,
|
||||
85, 84, 83, 82, 81, 80, 79, 78, 77, 76,
|
||||
75, 74, 73, 72, 71, 70, 69, 68, 67, 66,
|
||||
65, 64, 35, 34, 32, 63, 62, 61, 57, 53,
|
||||
48, 47, 44, 38, 35, 34, 32, 256, 3, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
65, 64, 63, 35, 34, 32, 62, 61, 60, 56,
|
||||
52, 48, 47, 44, 38, 35, 34, 32, 247, 3,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247
|
||||
|
||||
256, 256, 256
|
||||
} ;
|
||||
|
||||
static yyconst flex_int16_t yy_chk[304] =
|
||||
static yyconst flex_int16_t yy_chk[295] =
|
||||
{ 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 5, 12, 5, 14, 15, 17,
|
||||
14, 22, 20, 14, 24, 12, 20, 17, 258, 22,
|
||||
20, 15, 75, 24, 22, 20, 24, 30, 101, 30,
|
||||
257, 75, 253, 101, 252, 250, 249, 247, 101, 101,
|
||||
246, 245, 244, 242, 241, 240, 239, 237, 236, 235,
|
||||
234, 233, 232, 231, 229, 228, 227, 225, 224, 223,
|
||||
222, 221, 219, 217, 216, 214, 213, 212, 211, 210,
|
||||
14, 22, 20, 14, 24, 12, 20, 17, 249, 22,
|
||||
20, 15, 74, 24, 22, 30, 24, 30, 99, 248,
|
||||
244, 74, 243, 99, 241, 240, 238, 237, 99, 99,
|
||||
236, 235, 233, 232, 231, 230, 228, 227, 226, 225,
|
||||
224, 223, 222, 220, 219, 218, 216, 215, 214, 213,
|
||||
212, 211, 209, 208, 206, 205, 204, 203, 202, 201,
|
||||
|
||||
209, 208, 206, 205, 204, 203, 202, 201, 199, 197,
|
||||
193, 192, 191, 189, 188, 187, 186, 185, 184, 183,
|
||||
182, 181, 180, 179, 178, 177, 176, 175, 174, 172,
|
||||
171, 170, 169, 168, 167, 166, 165, 163, 162, 161,
|
||||
160, 159, 157, 156, 155, 154, 153, 152, 151, 150,
|
||||
149, 148, 147, 146, 145, 144, 143, 142, 141, 140,
|
||||
138, 137, 136, 135, 134, 133, 132, 131, 130, 128,
|
||||
127, 126, 125, 124, 123, 122, 121, 120, 119, 118,
|
||||
117, 116, 115, 113, 112, 111, 109, 108, 107, 106,
|
||||
104, 102, 100, 98, 97, 96, 95, 94, 93, 92,
|
||||
199, 198, 197, 196, 195, 194, 192, 190, 186, 185,
|
||||
183, 182, 181, 180, 179, 178, 177, 176, 175, 174,
|
||||
173, 172, 171, 170, 169, 167, 166, 165, 164, 163,
|
||||
162, 161, 160, 158, 157, 156, 155, 154, 152, 151,
|
||||
150, 149, 148, 147, 146, 145, 144, 143, 142, 141,
|
||||
140, 139, 138, 137, 136, 134, 133, 132, 131, 130,
|
||||
129, 128, 127, 125, 124, 123, 122, 121, 120, 119,
|
||||
118, 117, 116, 115, 114, 113, 112, 110, 109, 108,
|
||||
106, 105, 104, 102, 100, 98, 96, 95, 94, 93,
|
||||
92, 91, 90, 89, 88, 87, 86, 84, 83, 82,
|
||||
|
||||
91, 90, 89, 88, 86, 85, 84, 83, 82, 81,
|
||||
80, 79, 78, 77, 76, 73, 72, 71, 70, 69,
|
||||
68, 67, 66, 65, 64, 63, 62, 61, 60, 59,
|
||||
58, 57, 56, 55, 54, 53, 52, 51, 50, 49,
|
||||
48, 47, 45, 44, 43, 42, 41, 40, 39, 38,
|
||||
37, 36, 35, 33, 31, 27, 26, 25, 23, 21,
|
||||
19, 18, 16, 13, 9, 8, 7, 3, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
||||
81, 80, 79, 78, 77, 76, 75, 72, 71, 70,
|
||||
69, 68, 67, 66, 65, 64, 63, 62, 61, 60,
|
||||
59, 58, 57, 56, 55, 54, 53, 52, 51, 50,
|
||||
49, 48, 47, 45, 44, 43, 42, 41, 40, 39,
|
||||
38, 37, 36, 35, 33, 31, 27, 26, 25, 23,
|
||||
21, 19, 18, 16, 13, 9, 8, 7, 3, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247, 247, 247, 247, 247, 247, 247,
|
||||
247, 247, 247, 247
|
||||
|
||||
256, 256, 256
|
||||
} ;
|
||||
|
||||
static yy_state_type yy_last_accepting_state;
|
||||
@ -621,7 +616,7 @@ list_t *parse_conf(FILE *file)
|
||||
}
|
||||
return root_list;
|
||||
}
|
||||
#line 625 "lex.yy.c"
|
||||
#line 620 "lex.yy.c"
|
||||
|
||||
#define INITIAL 0
|
||||
|
||||
@ -774,7 +769,7 @@ YY_DECL
|
||||
|
||||
#line 36 "lex.l"
|
||||
|
||||
#line 778 "lex.yy.c"
|
||||
#line 773 "lex.yy.c"
|
||||
|
||||
if ( (yy_init) )
|
||||
{
|
||||
@ -827,13 +822,13 @@ yy_match:
|
||||
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
|
||||
{
|
||||
yy_current_state = (int) yy_def[yy_current_state];
|
||||
if ( yy_current_state >= 257 )
|
||||
if ( yy_current_state >= 248 )
|
||||
yy_c = yy_meta[(unsigned int) yy_c];
|
||||
}
|
||||
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
|
||||
++yy_cp;
|
||||
}
|
||||
while ( yy_base[yy_current_state] != 269 );
|
||||
while ( yy_base[yy_current_state] != 260 );
|
||||
|
||||
yy_find_action:
|
||||
yy_act = yy_accept[yy_current_state];
|
||||
@ -1011,47 +1006,52 @@ YY_RULE_SETUP
|
||||
case 29:
|
||||
YY_RULE_SETUP
|
||||
#line 72 "lex.l"
|
||||
{ return LEX_NO_BACKLOG; }
|
||||
{ return LEX_BACKLOG; }
|
||||
YY_BREAK
|
||||
case 30:
|
||||
YY_RULE_SETUP
|
||||
#line 73 "lex.l"
|
||||
{ return LEX_ALWAYS_BACKLOG; }
|
||||
{ return LEX_LOG; }
|
||||
YY_BREAK
|
||||
case 31:
|
||||
YY_RULE_SETUP
|
||||
#line 74 "lex.l"
|
||||
{ return LEX_LOG_SYNC_INTERVAL; }
|
||||
{ return LEX_ALWAYS_BACKLOG; }
|
||||
YY_BREAK
|
||||
case 32:
|
||||
YY_RULE_SETUP
|
||||
#line 75 "lex.l"
|
||||
{ return LEX_FOLLOW_NICK; }
|
||||
{ return LEX_LOG_SYNC_INTERVAL; }
|
||||
YY_BREAK
|
||||
case 33:
|
||||
YY_RULE_SETUP
|
||||
#line 76 "lex.l"
|
||||
{ return LEX_IGN_FIRST_NICK; }
|
||||
{ return LEX_FOLLOW_NICK; }
|
||||
YY_BREAK
|
||||
case 34:
|
||||
YY_RULE_SETUP
|
||||
#line 77 "lex.l"
|
||||
{ return LEX_AWAY_NICK; }
|
||||
{ return LEX_IGN_FIRST_NICK; }
|
||||
YY_BREAK
|
||||
case 35:
|
||||
YY_RULE_SETUP
|
||||
#line 78 "lex.l"
|
||||
{ return LEX_ON_CONNECT_SEND; }
|
||||
{ return LEX_AWAY_NICK; }
|
||||
YY_BREAK
|
||||
case 36:
|
||||
YY_RULE_SETUP
|
||||
#line 79 "lex.l"
|
||||
{ return LEX_PID_FILE; }
|
||||
{ return LEX_ON_CONNECT_SEND; }
|
||||
YY_BREAK
|
||||
case 37:
|
||||
/* rule 37 can match eol */
|
||||
YY_RULE_SETUP
|
||||
#line 80 "lex.l"
|
||||
{ return LEX_PID_FILE; }
|
||||
YY_BREAK
|
||||
case 38:
|
||||
/* rule 38 can match eol */
|
||||
YY_RULE_SETUP
|
||||
#line 81 "lex.l"
|
||||
{
|
||||
size_t len = strlen(yytext) - 2;
|
||||
yylval.string = malloc(len + 1);
|
||||
@ -1062,35 +1062,35 @@ YY_RULE_SETUP
|
||||
return LEX_STRING;
|
||||
}
|
||||
YY_BREAK
|
||||
case 38:
|
||||
YY_RULE_SETUP
|
||||
#line 89 "lex.l"
|
||||
{ return LEX_EQ; }
|
||||
YY_BREAK
|
||||
case 39:
|
||||
YY_RULE_SETUP
|
||||
#line 90 "lex.l"
|
||||
{ return LEX_LBRA; }
|
||||
{ return LEX_EQ; }
|
||||
YY_BREAK
|
||||
case 40:
|
||||
YY_RULE_SETUP
|
||||
#line 91 "lex.l"
|
||||
{ return LEX_RBRA; }
|
||||
{ return LEX_LBRA; }
|
||||
YY_BREAK
|
||||
case 41:
|
||||
YY_RULE_SETUP
|
||||
#line 92 "lex.l"
|
||||
{ return LEX_SEMICOLON; }
|
||||
{ return LEX_RBRA; }
|
||||
YY_BREAK
|
||||
case 42:
|
||||
YY_RULE_SETUP
|
||||
#line 93 "lex.l"
|
||||
{ printf("Parse error line %d, unknown character '%s'\n", linec + 1, yytext);
|
||||
return LEX_BUNCH; }
|
||||
{ return LEX_SEMICOLON; }
|
||||
YY_BREAK
|
||||
case 43:
|
||||
YY_RULE_SETUP
|
||||
#line 95 "lex.l"
|
||||
#line 94 "lex.l"
|
||||
{ printf("Parse error line %d, unknown character '%s'\n", linec + 1, yytext);
|
||||
return LEX_BUNCH; }
|
||||
YY_BREAK
|
||||
case 44:
|
||||
YY_RULE_SETUP
|
||||
#line 96 "lex.l"
|
||||
ECHO;
|
||||
YY_BREAK
|
||||
#line 1097 "lex.yy.c"
|
||||
@ -1377,7 +1377,7 @@ static int yy_get_next_buffer (void)
|
||||
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
|
||||
{
|
||||
yy_current_state = (int) yy_def[yy_current_state];
|
||||
if ( yy_current_state >= 257 )
|
||||
if ( yy_current_state >= 248 )
|
||||
yy_c = yy_meta[(unsigned int) yy_c];
|
||||
}
|
||||
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
|
||||
@ -1405,11 +1405,11 @@ static int yy_get_next_buffer (void)
|
||||
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
|
||||
{
|
||||
yy_current_state = (int) yy_def[yy_current_state];
|
||||
if ( yy_current_state >= 257 )
|
||||
if ( yy_current_state >= 248 )
|
||||
yy_c = yy_meta[(unsigned int) yy_c];
|
||||
}
|
||||
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
|
||||
yy_is_jam = (yy_current_state == 256);
|
||||
yy_is_jam = (yy_current_state == 247);
|
||||
|
||||
return yy_is_jam ? 0 : yy_current_state;
|
||||
}
|
||||
@ -2059,7 +2059,7 @@ void yyfree (void * ptr )
|
||||
#undef YY_DECL_IS_OURS
|
||||
#undef YY_DECL
|
||||
#endif
|
||||
#line 95 "lex.l"
|
||||
#line 96 "lex.l"
|
||||
|
||||
|
||||
|
||||
|
@ -69,7 +69,8 @@ list_t *parse_conf(FILE *file)
|
||||
"log_root" { return LEX_LOG_ROOT; }
|
||||
"log_format" { return LEX_LOG_FORMAT; }
|
||||
"backlog_lines" { return LEX_BACKLOG_LINES; }
|
||||
"no_backlog" { return LEX_NO_BACKLOG; }
|
||||
"backlog" { return LEX_BACKLOG; }
|
||||
"log" { return LEX_LOG; }
|
||||
"always_backlog" { return LEX_ALWAYS_BACKLOG; }
|
||||
"log_sync_interval" { return LEX_LOG_SYNC_INTERVAL; }
|
||||
"follow_nick" { return LEX_FOLLOW_NICK; }
|
||||
|
315
src/log.c
315
src/log.c
@ -20,14 +20,17 @@ extern int errno;
|
||||
extern int log_level;
|
||||
extern char *conf_log_root;
|
||||
extern char *conf_log_format;
|
||||
extern int conf_log;
|
||||
|
||||
int conf_memlog = 1;
|
||||
|
||||
/* conf_always_backlog => conf_backlog_lines != 0 */
|
||||
extern int conf_no_backlog;
|
||||
extern int conf_backlog;
|
||||
extern int conf_backlog_lines;
|
||||
extern int conf_always_backlog;
|
||||
|
||||
int log_set_backlog_offset(log_t *logdata, char *dest);
|
||||
static int _log_write(log_t *logdata, logfilegroup_t *lf, char *str);
|
||||
static int _log_write(log_t *logdata, logfilegroup_t *lf, char *d, char *str);
|
||||
void logfile_free(logfile_t *lf);
|
||||
|
||||
/* TODO: change fatal("out of memory") to cleanup & return NULL */
|
||||
@ -194,33 +197,37 @@ void log_reinit(logfilegroup_t *lfg)
|
||||
static int log_add_file(log_t *logdata, char *destination, char *filename)
|
||||
{
|
||||
FILE *f;
|
||||
logfile_t *lf;
|
||||
logfile_t *lf = NULL;
|
||||
logfilegroup_t *lfg;
|
||||
|
||||
f = fopen(filename, "a+");
|
||||
if (!f) {
|
||||
mylog(LOG_ERROR, "fopen(%s) %s", filename, strerror(errno));
|
||||
return 0;
|
||||
|
||||
if (conf_log) {
|
||||
f = fopen(filename, "a+");
|
||||
if (!f) {
|
||||
mylog(LOG_ERROR, "fopen(%s) %s", filename,
|
||||
strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
lf = malloc(sizeof(logfile_t));
|
||||
if (!lf)
|
||||
fatal("out of memory");
|
||||
lf->file = f;
|
||||
lf->filename = strdup(filename);
|
||||
if (!lf->filename)
|
||||
fatal("out of memory");
|
||||
|
||||
fseek(lf->file, 0, SEEK_END);
|
||||
if (ftell(f) < 0)
|
||||
fatal("ftell");
|
||||
lf->len = ftell(f);
|
||||
lf->backlog_offset = lf->len;
|
||||
log_updatelast(lf);
|
||||
}
|
||||
|
||||
lf = malloc(sizeof(logfile_t));
|
||||
if (!lf)
|
||||
fatal("out of memory");
|
||||
lf->file = f;
|
||||
lf->filename = strdup(filename);
|
||||
if (!lf->filename)
|
||||
fatal("out of memory");
|
||||
|
||||
fseek(lf->file, 0, SEEK_END);
|
||||
if (ftell(f) < 0)
|
||||
fatal("ftell");
|
||||
lf->len = ftell(f);
|
||||
lf->backlog_offset = lf->len;
|
||||
log_updatelast(lf);
|
||||
|
||||
lfg = hash_get(&logdata->logfgs, destination);
|
||||
|
||||
if (!lfg) {
|
||||
lfg = malloc(sizeof(logfilegroup_t));
|
||||
lfg = calloc(sizeof(logfilegroup_t), 1);
|
||||
if (!lfg)
|
||||
fatal("out of memory");
|
||||
list_init(&lfg->file_group, NULL);
|
||||
@ -230,7 +237,14 @@ static int log_add_file(log_t *logdata, char *destination, char *filename)
|
||||
lfg->skip_advance = 0;
|
||||
hash_insert(&logdata->logfgs, destination, lfg);
|
||||
}
|
||||
list_add_last(&lfg->file_group, lf);
|
||||
|
||||
if (conf_memlog) {
|
||||
if (!lfg->memlog)
|
||||
lfg->memlog = list_new(NULL);
|
||||
}
|
||||
|
||||
if (lf)
|
||||
list_add_last(&lfg->file_group, lf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -252,7 +266,7 @@ logfilegroup_t *log_find_file(log_t *logdata, char *destination)
|
||||
{
|
||||
logfile_t *lf;
|
||||
logfilegroup_t *lfg;
|
||||
char *filename;
|
||||
char *filename = NULL;
|
||||
time_t t;
|
||||
struct tm *ltime;
|
||||
|
||||
@ -261,13 +275,17 @@ logfilegroup_t *log_find_file(log_t *logdata, char *destination)
|
||||
|
||||
lfg = hash_get(&logdata->logfgs, destination);
|
||||
|
||||
if (!lfg) {
|
||||
filename = log_build_filename(logdata, destination);
|
||||
if (!filename)
|
||||
return NULL;
|
||||
if (lfg && !conf_log)
|
||||
return lfg;
|
||||
|
||||
mylog(LOG_DEBUG, "Creating new logfile for %s: %s", destination,
|
||||
filename);
|
||||
if (!lfg) {
|
||||
if (conf_log) {
|
||||
filename = log_build_filename(logdata, destination);
|
||||
if (!filename)
|
||||
return NULL;
|
||||
mylog(LOG_DEBUG, "Creating new logfile for %s: %s",
|
||||
destination, filename);
|
||||
}
|
||||
if (!log_add_file(logdata, destination, filename)) {
|
||||
free(filename);
|
||||
return NULL;
|
||||
@ -275,9 +293,11 @@ logfilegroup_t *log_find_file(log_t *logdata, char *destination)
|
||||
lfg = hash_get(&logdata->logfgs, destination);
|
||||
if (!lfg)
|
||||
fatal("internal log_find_file");
|
||||
free(filename);
|
||||
if (filename)
|
||||
free(filename);
|
||||
return lfg;
|
||||
}
|
||||
|
||||
/* This is reached if lfg already exists */
|
||||
time(&t);
|
||||
ltime = localtime(&t);
|
||||
@ -305,7 +325,7 @@ logfilegroup_t *log_find_file(log_t *logdata, char *destination)
|
||||
}
|
||||
free(filename);
|
||||
|
||||
if (conf_no_backlog) {
|
||||
if (!conf_backlog) {
|
||||
/* remove oldlf from file_group */
|
||||
if (list_remove_first(&lfg->file_group) != oldlf)
|
||||
fatal("internal log_find_file 2");
|
||||
@ -366,12 +386,16 @@ void log_nick(log_t *logdata, char *ircmask, char *channel, char *newnick)
|
||||
log_write(logdata, channel, logdata->buffer);
|
||||
}
|
||||
|
||||
void log_privmsg(log_t *logdata, char *ircmask, char *destination,
|
||||
char *message)
|
||||
static void _log_privmsg(log_t *logdata, char *ircmask, int src,
|
||||
char *destination, char *message)
|
||||
{
|
||||
char dir = '<';
|
||||
if (!ircmask)
|
||||
ircmask = "Server message";
|
||||
|
||||
if (src)
|
||||
dir = '>';
|
||||
|
||||
if (*message == '\001' && *(message + strlen(message) - 1) == '\001') {
|
||||
char *msg = strdup(message);
|
||||
if (!msg)
|
||||
@ -383,44 +407,74 @@ void log_privmsg(log_t *logdata, char *ircmask, char *destination,
|
||||
*(msg + strlen(msg) - 1) = '\0';
|
||||
if (ischannel(*destination) || strchr(destination, '@')) {
|
||||
snprintf(logdata->buffer, LOGLINE_MAXLEN,
|
||||
"%s * %s %s\n", timestamp(), ircmask,
|
||||
msg + 8);
|
||||
"%s * %c %s %s\n", timestamp(), dir,
|
||||
ircmask, msg + 8);
|
||||
} else {
|
||||
snprintf(logdata->buffer, LOGLINE_MAXLEN,
|
||||
"%s (%s) * %s %s\n", timestamp(),
|
||||
destination, ircmask, msg + 8);
|
||||
"%s (%s) * %c %s %s\n", timestamp(),
|
||||
destination, dir, ircmask, msg + 8);
|
||||
}
|
||||
free(msg);
|
||||
} else {
|
||||
if (ischannel(*destination) || strchr(destination, '@')) {
|
||||
snprintf(logdata->buffer, LOGLINE_MAXLEN, "%s %s: %s\n",
|
||||
timestamp(), ircmask, message);
|
||||
snprintf(logdata->buffer, LOGLINE_MAXLEN,
|
||||
"%s %c %s: %s\n", timestamp(), dir,
|
||||
ircmask, message);
|
||||
} else {
|
||||
snprintf(logdata->buffer, LOGLINE_MAXLEN,
|
||||
"%s %s (%s): %s\n", timestamp(),
|
||||
ircmask, destination, message);
|
||||
"%s %c %s (%s): %s\n", timestamp(),
|
||||
dir, ircmask, destination, message);
|
||||
}
|
||||
}
|
||||
log_write(logdata, destination, logdata->buffer);
|
||||
}
|
||||
|
||||
void log_notice(log_t *logdata, char *ircmask, char *destination, char *message)
|
||||
void log_privmsg(log_t *logdata, char *ircmask, char *destination,
|
||||
char *message)
|
||||
{
|
||||
_log_privmsg(logdata, ircmask, 0, destination, message);
|
||||
}
|
||||
|
||||
void log_cli_privmsg(log_t *logdata, char *ircmask, char *destination,
|
||||
char *message)
|
||||
{
|
||||
_log_privmsg(logdata, ircmask, 1, destination, message);
|
||||
}
|
||||
|
||||
static void _log_notice(log_t *logdata, char *ircmask, int src,
|
||||
char *destination, char *message)
|
||||
{
|
||||
char dir = '<';
|
||||
|
||||
if (!ircmask)
|
||||
ircmask = "Server message";
|
||||
if (src)
|
||||
dir = '>';
|
||||
if (*message == '\001' && *(message + strlen(message) - 1) == '\001')
|
||||
return;
|
||||
if (ischannel(*destination) || strchr(destination, '@')) {
|
||||
snprintf(logdata->buffer, LOGLINE_MAXLEN, "%s %s: %s\n",
|
||||
timestamp(), ircmask, message);
|
||||
snprintf(logdata->buffer, LOGLINE_MAXLEN, "%s %c %s: %s\n",
|
||||
timestamp(), dir, ircmask, message);
|
||||
} else {
|
||||
snprintf(logdata->buffer, LOGLINE_MAXLEN,
|
||||
"%s %s (%s): %s\n", timestamp(),
|
||||
ircmask, destination, message);
|
||||
"%s %c %s (%s): %s\n", timestamp(),
|
||||
dir, ircmask, destination, message);
|
||||
}
|
||||
log_write(logdata, destination, logdata->buffer);
|
||||
}
|
||||
|
||||
void log_notice(log_t *logdata, char *ircmask, char *destination,
|
||||
char *message)
|
||||
{
|
||||
_log_notice(logdata, ircmask, 0, destination, message);
|
||||
}
|
||||
|
||||
void log_cli_notice(log_t *logdata, char *ircmask, char *destination,
|
||||
char *message)
|
||||
{
|
||||
_log_notice(logdata, ircmask, 1, destination, message);
|
||||
}
|
||||
|
||||
void log_topic(log_t *logdata, char *ircmask, char *channel, char *message)
|
||||
{
|
||||
snprintf(logdata->buffer, LOGLINE_MAXLEN,
|
||||
@ -462,15 +516,20 @@ void log_mode(log_t *logdata, char *ircmask, char *channel, char *modes,
|
||||
char **modargv, unsigned modargc)
|
||||
{
|
||||
unsigned i;
|
||||
snprintf(logdata->buffer, LOGLINE_MAXLEN, "%s -!- mode/%s [%s ",
|
||||
timestamp(), channel, modes);
|
||||
log_write(logdata, channel, logdata->buffer);
|
||||
char *tmpbuf = malloc(LOGLINE_MAXLEN + 1);
|
||||
char *tmpbuf2 = malloc(LOGLINE_MAXLEN + 1);
|
||||
char *tmp;
|
||||
snprintf(tmpbuf, LOGLINE_MAXLEN, "%s -!- mode/%s [%s ", timestamp(),
|
||||
channel, modes);
|
||||
for (i = 0; i < modargc; i++) {
|
||||
snprintf(logdata->buffer, LOGLINE_MAXLEN, "%s%c", modargv[i],
|
||||
i == modargc - 1 ? ']' : ' ');
|
||||
log_write(logdata, channel, logdata->buffer);
|
||||
snprintf(tmpbuf2, LOGLINE_MAXLEN, "%s%s%c", tmpbuf,
|
||||
modargv[i], i == modargc - 1 ? ']' : ' ');
|
||||
tmp = tmpbuf;
|
||||
tmpbuf = tmpbuf2;
|
||||
tmpbuf2 = tmp;
|
||||
}
|
||||
snprintf(logdata->buffer, LOGLINE_MAXLEN, " by %s\n", ircmask);
|
||||
snprintf(logdata->buffer, LOGLINE_MAXLEN, "%s by %s\n", tmpbuf,
|
||||
ircmask);
|
||||
log_write(logdata, channel, logdata->buffer);
|
||||
}
|
||||
|
||||
@ -483,7 +542,7 @@ void log_disconnected(log_t *logdata)
|
||||
for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi);
|
||||
hash_it_next(&hi)) {
|
||||
lfg = hash_it_item(&hi);
|
||||
_log_write(logdata, lfg, logdata->buffer);
|
||||
_log_write(logdata, lfg, hash_it_key(&hi), logdata->buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -504,7 +563,7 @@ void log_connected(log_t *logdata)
|
||||
for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi);
|
||||
hash_it_next(&hi)) {
|
||||
lfg = hash_it_item(&hi);
|
||||
_log_write(logdata, lfg, logdata->buffer);
|
||||
_log_write(logdata, lfg, hash_it_key(&hi), logdata->buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -544,7 +603,7 @@ void log_client_connected(log_t *logdata)
|
||||
void log_advance_backlogs(log_t* ld, logfilegroup_t *lfg)
|
||||
{
|
||||
int c;
|
||||
if (conf_no_backlog || conf_backlog_lines == 0)
|
||||
if (!conf_backlog || conf_backlog_lines == 0)
|
||||
return;
|
||||
|
||||
if (lfg->skip_advance < conf_backlog_lines) {
|
||||
@ -589,6 +648,9 @@ int log_has_backlog(log_t *logdata, char *destination)
|
||||
if (!lfg)
|
||||
return 0;
|
||||
|
||||
if (lfg->memlog)
|
||||
return !list_is_empty(lfg->memlog);
|
||||
|
||||
logfile_t *lf;
|
||||
lf = list_get_first(&lfg->file_group);
|
||||
if (lf != list_get_last(&lfg->file_group))
|
||||
@ -601,8 +663,8 @@ int log_has_backlog(log_t *logdata, char *destination)
|
||||
#define LAMESTRING "!bip@bip.bip.bip PRIVMSG "
|
||||
|
||||
/*
|
||||
* 13-05-2005 12:14:29 nohar (nohar): coucou
|
||||
* 13-05-2005 12:14:30 nohar!~nohar@je.suis.t1r.net (nohar): coucou
|
||||
* 13-05-2005 12:14:29 > nohar (nohar): coucou
|
||||
* 13-05-2005 12:14:30 < nohar!~nohar@je.suis.t1r.net (nohar): coucou
|
||||
*/
|
||||
|
||||
/* must *not* return NULL */
|
||||
@ -617,7 +679,7 @@ static char *log_beautify(char *buf, char *dest, int *raw)
|
||||
char *sots, *son, *som, *sod = NULL;
|
||||
size_t lots, lon, lom, lod;
|
||||
char *ret;
|
||||
int guess_was_me = 0;
|
||||
int out;
|
||||
|
||||
mylog(LOG_INFO, "beautify in: \"%s\"", buf);
|
||||
|
||||
@ -627,62 +689,72 @@ static char *log_beautify(char *buf, char *dest, int *raw)
|
||||
|
||||
p = strchr(buf, ' ');
|
||||
if (!p || !p[0] || !p[1])
|
||||
return buf;
|
||||
return strdup(buf);
|
||||
p++;
|
||||
sots = p;
|
||||
p = strchr(p, ' ');
|
||||
if (!p || !p[0] || !p[1])
|
||||
return buf;
|
||||
return strdup(buf);
|
||||
lots = p - sots;
|
||||
p++;
|
||||
if (strncmp(p, "-!-", 3) == 0)
|
||||
return buf;
|
||||
return strdup(buf);
|
||||
|
||||
if (*p == '>')
|
||||
out = 1;
|
||||
else if (*p == '<')
|
||||
out = 0;
|
||||
else
|
||||
return strdup(buf);
|
||||
p++;
|
||||
if (*p != ' ')
|
||||
return strdup(buf);
|
||||
p++;
|
||||
if (*p == '*') {
|
||||
action = 1;
|
||||
if (!p[1] || !p[2])
|
||||
return buf;
|
||||
return strdup(buf);
|
||||
p += 2;
|
||||
}
|
||||
son = p;
|
||||
/* 'date time blawithnoexcl bla bla ! bla' --> ? */
|
||||
while (*p && *p != '!' && *p != ' ' && *p != ':')
|
||||
p++;
|
||||
if (*p != '!')
|
||||
guess_was_me = 1;
|
||||
if (!p[0] || !p[1])
|
||||
return buf;
|
||||
return strdup(buf);
|
||||
lon = p - son;
|
||||
p = strchr(p, ' ');
|
||||
if (!p || !p[0] || !p[1])
|
||||
return buf;
|
||||
return strdup(buf);
|
||||
p++;
|
||||
|
||||
if (*p == '(') {
|
||||
p++;
|
||||
if (!p[0] || !p[1] || p[0] == ')')
|
||||
return buf;
|
||||
return strdup(buf);
|
||||
sod = p;
|
||||
while (*p && *p != ')' && *p != ' ')
|
||||
p++;
|
||||
if (*p != ')')
|
||||
return buf;
|
||||
return strdup(buf);
|
||||
lod = p - sod;
|
||||
p++;
|
||||
if (*p != ':')
|
||||
return buf;
|
||||
return strdup(buf);
|
||||
p++;
|
||||
if (*p != ' ')
|
||||
return buf;
|
||||
return strdup(buf);
|
||||
p++;
|
||||
if (!p[0] || !p[1])
|
||||
return buf;
|
||||
return strdup(buf);
|
||||
} else {
|
||||
sod = dest;
|
||||
lod = strlen(dest);
|
||||
}
|
||||
if (guess_was_me) {
|
||||
lon = lod;
|
||||
|
||||
if (out && strcmp(dest, "privates") == 0) {
|
||||
son = sod;
|
||||
lon = lod;
|
||||
}
|
||||
|
||||
som = p;
|
||||
@ -713,8 +785,8 @@ static char *log_beautify(char *buf, char *dest, int *raw)
|
||||
memcpy(p, "ACTION ", strlen("ACTION "));
|
||||
p += strlen("ACTION ");
|
||||
}
|
||||
if (guess_was_me) {
|
||||
memcpy(p, "<-", 2);
|
||||
if (out) {
|
||||
memcpy(p, "->", 2);
|
||||
p += 2;
|
||||
}
|
||||
memcpy(p, sots, lots);
|
||||
@ -731,17 +803,17 @@ static char *log_beautify(char *buf, char *dest, int *raw)
|
||||
*p++ = '\n';
|
||||
*p = 0;
|
||||
mylog(LOG_INFO, "beautify out: \"%s\"", ret);
|
||||
free(buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *log_backread(log_t *logdata, char *destination, int *raw)
|
||||
static char *_log_backread(log_t *logdata, char *destination, int *raw)
|
||||
{
|
||||
char *buf;
|
||||
size_t pos = 0;
|
||||
logfile_t *lf;
|
||||
logfilegroup_t *lfg;
|
||||
int c;
|
||||
char *ret;
|
||||
|
||||
if (!conf_always_backlog && logdata->connected)
|
||||
return NULL;
|
||||
@ -750,14 +822,31 @@ char *log_backread(log_t *logdata, char *destination, int *raw)
|
||||
if (!lfg)
|
||||
return NULL;
|
||||
|
||||
/* freed by log_beautify sometimes */
|
||||
buf = (char *)malloc((LOGLINE_MAXLEN + 1) * sizeof(char));
|
||||
|
||||
if (!logdata->backlogging) {
|
||||
list_it_init(&lfg->file_group, &logdata->file_it);
|
||||
logdata->backlogging = 1;
|
||||
mylog(LOG_INFO, "backlogging!");
|
||||
if (lfg->memlog)
|
||||
list_it_init(lfg->memlog, &lfg->backlog_it);
|
||||
else
|
||||
list_it_init(&lfg->file_group, &logdata->file_it);
|
||||
}
|
||||
|
||||
if (lfg->memlog) {
|
||||
char *ptr;
|
||||
ptr = list_it_item(&lfg->backlog_it);
|
||||
if (!ptr) {
|
||||
logdata->backlogging = 0;
|
||||
return NULL;
|
||||
}
|
||||
list_it_next(&lfg->backlog_it);
|
||||
return strdup(ptr);
|
||||
}
|
||||
|
||||
if (!conf_log)
|
||||
return NULL;
|
||||
|
||||
buf = (char *)malloc((LOGLINE_MAXLEN + 1) * sizeof(char));
|
||||
|
||||
next_file:
|
||||
/* check the files containing data to backlog */
|
||||
lf = list_it_item(&logdata->file_it);
|
||||
@ -812,7 +901,9 @@ next_file:
|
||||
goto next_file;
|
||||
}
|
||||
buf[pos] = 0;
|
||||
return log_beautify(buf, destination, raw);
|
||||
ret = log_beautify(buf, destination, raw);
|
||||
free(buf);
|
||||
return ret;
|
||||
}
|
||||
buf[pos++] = c;
|
||||
}
|
||||
@ -859,7 +950,9 @@ next_file:
|
||||
if (conf_always_backlog && c == EOF)
|
||||
lf->backlog_offset--;
|
||||
buf[pos] = 0;
|
||||
return log_beautify(buf, destination, raw);
|
||||
ret = log_beautify(buf, destination, raw);
|
||||
free(buf);
|
||||
return ret;
|
||||
}
|
||||
buf[pos++] = c;
|
||||
}
|
||||
@ -868,10 +961,54 @@ next_file:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int _log_write(log_t *logdata, logfilegroup_t *lfg, char *str)
|
||||
char *log_backread(log_t *log, char *dest)
|
||||
{
|
||||
int raw;
|
||||
char *line;
|
||||
char *buf;
|
||||
int count;
|
||||
|
||||
line = _log_backread(log, dest, &raw);
|
||||
if (raw)
|
||||
return line;
|
||||
|
||||
buf = malloc(LOGLINE_MAXLEN + 1);
|
||||
count = snprintf(buf, LOGLINE_MAXLEN + 1,
|
||||
":" P_IRCMASK " PRIVMSG %s :%s", dest, line);
|
||||
if (count >= LOGLINE_MAXLEN + 1) {
|
||||
buf[LOGLINE_MAXLEN - 2] = '\r';
|
||||
buf[LOGLINE_MAXLEN - 1] = '\n';
|
||||
buf[LOGLINE_MAXLEN] = 0;
|
||||
}
|
||||
free(line);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
static int _log_write(log_t *logdata, logfilegroup_t *lfg, char *destination,
|
||||
char *str)
|
||||
{
|
||||
size_t nbwrite;
|
||||
size_t len;
|
||||
|
||||
if (str[LOGLINE_MAXLEN - 1] != 0) {
|
||||
str[LOGLINE_MAXLEN - 1] = '\n';
|
||||
str[LOGLINE_MAXLEN] = 0;
|
||||
}
|
||||
|
||||
if (lfg->memlog) {
|
||||
int raw;
|
||||
char *r = log_beautify(str, destination, &raw);
|
||||
list_add_last(lfg->memlog, r);
|
||||
if (lfg->memc == conf_backlog_lines)
|
||||
free(list_remove_first(lfg->memlog));
|
||||
else
|
||||
lfg->memc++;
|
||||
}
|
||||
|
||||
if (!conf_log)
|
||||
return 0;
|
||||
|
||||
logfile_t *lf = list_get_last(&lfg->file_group);
|
||||
|
||||
/* str alloced size is LOGLINE_MAXLEN + 1 */
|
||||
@ -897,7 +1034,7 @@ void log_write(log_t *logdata, char *destination, char *str)
|
||||
destination);
|
||||
return;
|
||||
}
|
||||
_log_write(logdata, lfg, str);
|
||||
_log_write(logdata, lfg, destination, str);
|
||||
}
|
||||
|
||||
static list_t *log_all_logs = NULL;
|
||||
|
10
src/log.h
10
src/log.h
@ -42,6 +42,10 @@ typedef struct logfilegroup
|
||||
char *name;
|
||||
list_t file_group;
|
||||
int skip_advance;
|
||||
|
||||
list_t *memlog;
|
||||
int memc;
|
||||
list_iterator_t backlog_it;
|
||||
} logfilegroup_t;
|
||||
|
||||
typedef struct log {
|
||||
@ -69,6 +73,10 @@ void log_nick(log_t *logdata, char *ircmask, char *channel, char *newnick);
|
||||
void log_privmsg(log_t *logdata, char *ircmask, char *destination,
|
||||
char *message);
|
||||
void log_notice(log_t *logdata, char *ircmask, char *channel, char *message);
|
||||
void log_cli_privmsg(log_t *logdata, char *ircmask, char *destination,
|
||||
char *message);
|
||||
void log_cli_notice(log_t *logdata, char *ircmask, char *channel,
|
||||
char *message);
|
||||
void log_write(log_t *logdata, char *str, char *destination);
|
||||
void log_mode(log_t *logdata, char *ircmask, char *channel,
|
||||
char *modes, char **modargv, unsigned modargc);
|
||||
@ -80,7 +88,7 @@ void log_disconnected(log_t *logdata);
|
||||
void log_ping_timeout(log_t *logdata);
|
||||
void log_client_disconnected(log_t *logdata);
|
||||
void log_client_connected(log_t *logdata);
|
||||
char *log_backread(log_t *logdata, char *destination, int *raw);
|
||||
char *log_backread(log_t *logdata, char *destination);
|
||||
int log_has_backlog(log_t *logdata, char *destination);
|
||||
void log_flush_all(void);
|
||||
void log_client_none_connected(log_t *logdata);
|
||||
|
Loading…
Reference in New Issue
Block a user