From 3a46247bd475fcb3c7a587d62a827ecd0bd86356 Mon Sep 17 00:00:00 2001 From: nohar Date: Thu, 19 May 2005 20:55:11 +0000 Subject: [PATCH] better log file format, log options, with backlog with memory based backlog --- src/bip.c | 35 ++- src/conf.c | 637 ++++++++++++++++++++++++++++------------------------- src/conf.h | 56 ++--- src/conf.y | 5 +- src/irc.c | 28 +-- src/lex.c | 300 ++++++++++++------------- src/lex.l | 3 +- src/log.c | 315 ++++++++++++++++++-------- src/log.h | 10 +- 9 files changed, 795 insertions(+), 594 deletions(-) diff --git a/src/bip.c b/src/bip.c index 94fa523..a43ad64 100644 --- a/src/bip.c +++ b/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; diff --git a/src/conf.c b/src/conf.c index d4f9dcb..2228abc 100644 --- a/src/conf.c +++ b/src/conf.c @@ -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. @@ -83,18 +83,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 @@ -127,18 +128,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 @@ -247,8 +249,8 @@ typedef union YYSTYPE { void *list; struct tuple *tuple; } YYSTYPE; -/* Line 191 of yacc.c. */ -#line 252 "y.tab.c" +/* Line 190 of yacc.c. */ +#line 254 "y.tab.c" # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_TRIVIAL 1 @@ -259,8 +261,8 @@ typedef union YYSTYPE { /* Copy the second part of user declarations. */ -/* Line 214 of yacc.c. */ -#line 264 "y.tab.c" +/* Line 213 of yacc.c. */ +#line 266 "y.tab.c" #if ! defined (yyoverflow) || YYERROR_VERBOSE @@ -275,14 +277,10 @@ typedef union YYSTYPE { # ifdef YYSTACK_USE_ALLOCA # if YYSTACK_USE_ALLOCA -# define YYSTACK_ALLOC alloca -# endif -# else -# if defined (alloca) || defined (_ALLOCA_H) -# define YYSTACK_ALLOC alloca -# else # ifdef __GNUC__ # define YYSTACK_ALLOC __builtin_alloca +# else +# define YYSTACK_ALLOC alloca # endif # endif # endif @@ -366,20 +364,20 @@ union yyalloc /* YYFINAL -- State number of the termination state. */ #define YYFINAL 2 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 146 +#define YYLAST 144 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 45 +#define YYNTOKENS 46 /* YYNNTS -- Number of nonterminals. */ #define YYNNTS 13 /* YYNRULES -- Number of rules. */ -#define YYNRULES 51 +#define YYNRULES 52 /* YYNRULES -- Number of states. */ -#define YYNSTATES 134 +#define YYNSTATES 137 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ #define YYUNDEFTOK 2 -#define YYMAXUTOK 299 +#define YYMAXUTOK 300 #define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) @@ -416,7 +414,8 @@ static const unsigned char yytranslate[] = 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 + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45 }; #if YYDEBUG @@ -425,46 +424,47 @@ static const unsigned char yytranslate[] = static const unsigned char yyprhs[] = { 0, 0, 3, 4, 8, 12, 16, 20, 24, 28, - 32, 36, 40, 44, 48, 52, 57, 62, 63, 67, - 71, 75, 80, 81, 85, 89, 93, 98, 99, 103, + 32, 36, 40, 44, 48, 52, 56, 61, 66, 67, + 71, 75, 79, 84, 85, 89, 93, 97, 102, 103, 107, 111, 115, 119, 123, 127, 131, 135, 139, 143, - 147, 151, 155, 160, 164, 165, 169, 173, 177, 178, - 182, 186 + 147, 151, 155, 159, 164, 168, 169, 173, 177, 181, + 182, 186, 190 }; /* YYRHS -- A `-1'-separated list of the rules' RHS. */ static const yysigned_char yyrhs[] = { - 46, 0, -1, -1, 46, 47, 7, -1, 29, 4, - 44, -1, 30, 4, 44, -1, 31, 4, 43, -1, - 3, 4, 44, -1, 5, 4, 43, -1, 6, 4, - 42, -1, 32, 4, 43, -1, 33, 4, 42, -1, - 40, 4, 42, -1, 34, 4, 43, -1, 38, 4, - 44, -1, 9, 10, 48, 11, -1, 12, 10, 50, - 11, -1, -1, 48, 49, 7, -1, 13, 4, 44, - -1, 26, 4, 42, -1, 16, 10, 56, 11, -1, - -1, 50, 51, 7, -1, 13, 4, 44, -1, 17, - 4, 44, -1, 8, 10, 52, 11, -1, -1, 52, - 53, 7, -1, 13, 4, 44, -1, 9, 4, 44, - -1, 41, 4, 44, -1, 15, 4, 44, -1, 12, - 4, 44, -1, 25, 4, 44, -1, 17, 4, 44, - -1, 20, 4, 44, -1, 21, 4, 43, -1, 26, - 4, 42, -1, 37, 4, 44, -1, 35, 4, 42, - -1, 39, 4, 42, -1, 27, 10, 54, 11, -1, - 36, 4, 44, -1, -1, 54, 55, 7, -1, 13, - 4, 44, -1, 28, 4, 44, -1, -1, 56, 57, - 7, -1, 19, 4, 44, -1, 5, 4, 43, -1 + 47, 0, -1, -1, 47, 48, 7, -1, 29, 4, + 45, -1, 30, 4, 45, -1, 31, 4, 44, -1, + 3, 4, 45, -1, 5, 4, 44, -1, 6, 4, + 43, -1, 32, 4, 44, -1, 33, 4, 43, -1, + 34, 4, 43, -1, 41, 4, 43, -1, 35, 4, + 44, -1, 39, 4, 45, -1, 9, 10, 49, 11, + -1, 12, 10, 51, 11, -1, -1, 49, 50, 7, + -1, 13, 4, 45, -1, 26, 4, 43, -1, 16, + 10, 57, 11, -1, -1, 51, 52, 7, -1, 13, + 4, 45, -1, 17, 4, 45, -1, 8, 10, 53, + 11, -1, -1, 53, 54, 7, -1, 13, 4, 45, + -1, 9, 4, 45, -1, 42, 4, 45, -1, 15, + 4, 45, -1, 12, 4, 45, -1, 25, 4, 45, + -1, 17, 4, 45, -1, 20, 4, 45, -1, 21, + 4, 44, -1, 26, 4, 43, -1, 38, 4, 45, + -1, 36, 4, 43, -1, 40, 4, 43, -1, 27, + 10, 55, 11, -1, 37, 4, 45, -1, -1, 55, + 56, 7, -1, 13, 4, 45, -1, 28, 4, 45, + -1, -1, 57, 58, 7, -1, 19, 4, 45, -1, + 5, 4, 44, -1 }; /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const unsigned char yyrline[] = { 0, 99, 99, 100, 104, 105, 107, 108, 109, 110, - 111, 113, 115, 117, 119, 120, 122, 125, 126, 129, - 130, 131, 135, 136, 139, 141, 143, 147, 148, 152, - 153, 155, 156, 157, 158, 160, 162, 163, 165, 166, - 168, 170, 172, 174, 177, 178, 181, 182, 185, 186, - 189, 190 + 111, 113, 115, 116, 118, 120, 121, 123, 126, 127, + 130, 131, 132, 136, 137, 140, 142, 144, 148, 149, + 153, 154, 156, 157, 158, 159, 161, 163, 164, 166, + 167, 169, 171, 173, 175, 178, 179, 182, 183, 186, + 187, 190, 191 }; #endif @@ -479,13 +479,13 @@ static const char *const yytname[] = "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", "LEX_BOOL", "LEX_INT", "LEX_STRING", - "$accept", "commands", "command", "network", "net_command", "user", - "usr_command", "connection", "con_command", "channel", "cha_command", - "server", "ser_command", 0 + "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", "LEX_BOOL", + "LEX_INT", "LEX_STRING", "$accept", "commands", "command", "network", + "net_command", "user", "usr_command", "connection", "con_command", + "channel", "cha_command", "server", "ser_command", 0 }; #endif @@ -498,30 +498,30 @@ static const unsigned short int yytoknum[] = 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, - 295, 296, 297, 298, 299 + 295, 296, 297, 298, 299, 300 }; # endif /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const unsigned char yyr1[] = { - 0, 45, 46, 46, 47, 47, 47, 47, 47, 47, - 47, 47, 47, 47, 47, 47, 47, 48, 48, 49, - 49, 49, 50, 50, 51, 51, 51, 52, 52, 53, - 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, - 53, 53, 53, 53, 54, 54, 55, 55, 56, 56, - 57, 57 + 0, 46, 47, 47, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, 49, 49, + 50, 50, 50, 51, 51, 52, 52, 52, 53, 53, + 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, + 54, 54, 54, 54, 54, 55, 55, 56, 56, 57, + 57, 58, 58 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ static const unsigned char yyr2[] = { 0, 2, 0, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 4, 4, 0, 3, 3, - 3, 4, 0, 3, 3, 3, 4, 0, 3, 3, + 3, 3, 3, 3, 3, 3, 4, 4, 0, 3, + 3, 3, 4, 0, 3, 3, 3, 4, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 4, 3, 0, 3, 3, 3, 0, 3, - 3, 3 + 3, 3, 3, 4, 3, 0, 3, 3, 3, 0, + 3, 3, 3 }; /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state @@ -531,25 +531,25 @@ static const unsigned char yydefact[] = { 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 17, 22, 0, 0, 0, 0, 0, 0, 0, 0, - 3, 7, 8, 9, 0, 0, 4, 5, 6, 10, - 11, 13, 14, 12, 15, 0, 0, 0, 0, 0, - 16, 0, 0, 0, 0, 48, 0, 18, 27, 0, - 0, 23, 19, 0, 20, 0, 24, 25, 0, 21, - 0, 0, 0, 26, 0, 0, 0, 0, 0, 0, + 0, 18, 23, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 3, 7, 8, 9, 0, 0, 4, 5, + 6, 10, 11, 12, 14, 15, 13, 16, 0, 0, + 0, 0, 0, 17, 0, 0, 0, 0, 49, 0, + 19, 28, 0, 0, 24, 20, 0, 21, 0, 25, + 26, 0, 22, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 49, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 44, 0, 0, 0, 0, 0, 28, 51, 50, - 30, 33, 29, 32, 35, 36, 37, 34, 38, 0, - 40, 43, 39, 41, 31, 42, 0, 0, 0, 0, - 0, 45, 46, 47 + 0, 0, 0, 0, 50, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 45, 0, 0, 0, 0, 0, + 29, 52, 51, 31, 34, 30, 33, 36, 37, 38, + 35, 39, 0, 41, 44, 40, 42, 32, 43, 0, + 0, 0, 0, 0, 46, 47, 48 }; /* YYDEFGOTO[NTERM-NUM]. */ static const short int yydefgoto[] = { - -1, 1, 16, 34, 48, 35, 53, 65, 88, 119, - 128, 63, 71 + -1, 1, 17, 36, 51, 37, 56, 68, 91, 122, + 131, 66, 74 }; /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing @@ -558,19 +558,19 @@ static const short int yydefgoto[] = static const yysigned_char yypact[] = { -10, 0, -10, 13, 14, 17, 12, 15, 20, 22, - 23, 24, 31, 32, 33, 40, 39, 4, 6, 10, - -10, -10, 9, 16, 11, 18, 21, 19, 26, 34, - -10, -10, -10, -10, -3, 3, -10, -10, -10, -10, - -10, -10, -10, -10, -10, 54, 49, 60, 61, 62, - -10, 69, 70, 68, 35, -10, 36, -10, -10, 37, - 38, -10, -10, -4, -10, 30, -10, -10, 73, -10, - 76, 77, 79, -10, 81, 82, 83, 84, 85, 86, - 87, 88, 89, 90, 91, 92, 93, 94, 95, 50, - 56, -10, 57, 59, 63, 64, 65, 66, 71, 67, - 74, -10, 75, 78, 80, 96, 97, -10, -10, -10, - -10, -10, -10, -10, -10, -10, -10, -10, -10, -9, - -10, -10, -10, -10, -10, -10, 100, 101, 99, 98, - 102, -10, -10, -10 + 23, 24, 32, 33, 34, 41, 43, 42, 5, 9, + 11, -10, -10, 10, 16, 18, 19, 21, 27, 28, + 29, 35, -10, -10, -10, -10, -3, 3, -10, -10, + -10, -10, -10, -10, -10, -10, -10, -10, 55, 50, + 61, 59, 65, -10, 72, 73, 74, 37, -10, 36, + -10, -10, 38, 39, -10, -10, -4, -10, 31, -10, + -10, 76, -10, 81, 79, 83, -10, 84, 85, 86, + 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, + 97, 98, 52, 58, -10, 62, 63, 64, 66, 67, + 68, 60, 69, 75, -10, 77, 70, 71, 78, 80, + -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, + -10, -10, -9, -10, -10, -10, -10, -10, -10, 102, + 106, 110, 82, 99, -10, -10, -10 }; /* YYPGOTO[NTERM-NUM]. */ @@ -587,21 +587,21 @@ static const yysigned_char yypgoto[] = #define YYTABLE_NINF -1 static const unsigned char yytable[] = { - 2, 68, 125, 3, 126, 4, 5, 69, 44, 6, - 45, 49, 7, 46, 50, 70, 51, 17, 18, 127, - 52, 19, 20, 47, 22, 21, 23, 24, 25, 8, - 9, 10, 11, 12, 13, 26, 27, 28, 14, 72, - 15, 73, 74, 75, 29, 76, 30, 77, 31, 32, - 78, 79, 33, 36, 38, 80, 81, 82, 54, 55, - 37, 39, 41, 40, 56, 83, 84, 85, 57, 86, - 42, 87, 58, 59, 60, 61, 43, 89, 64, 62, - 90, 66, 67, 92, 91, 93, 94, 95, 96, 97, - 98, 99, 100, 108, 102, 103, 104, 105, 106, 101, - 109, 110, 107, 111, 129, 130, 131, 112, 113, 114, - 115, 117, 0, 0, 116, 0, 118, 120, 0, 0, - 0, 0, 121, 0, 122, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 123, 0, - 0, 124, 132, 0, 0, 0, 133 + 2, 71, 128, 3, 129, 4, 5, 72, 47, 6, + 48, 52, 7, 49, 53, 73, 54, 18, 19, 130, + 55, 20, 21, 50, 23, 22, 24, 25, 26, 8, + 9, 10, 11, 12, 13, 14, 27, 28, 29, 15, + 75, 16, 76, 77, 78, 30, 79, 31, 80, 32, + 33, 81, 82, 34, 35, 38, 83, 84, 85, 57, + 58, 39, 40, 41, 42, 59, 60, 86, 87, 88, + 43, 89, 44, 90, 45, 61, 62, 63, 46, 67, + 92, 64, 65, 69, 70, 93, 94, 95, 96, 97, + 98, 99, 100, 101, 102, 103, 111, 105, 106, 107, + 108, 109, 104, 112, 119, 110, 132, 113, 114, 115, + 133, 116, 117, 118, 120, 124, 125, 134, 121, 0, + 123, 126, 0, 0, 0, 127, 0, 135, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 136 }; static const yysigned_char yycheck[] = @@ -609,38 +609,38 @@ static const yysigned_char yycheck[] = 0, 5, 11, 3, 13, 5, 6, 11, 11, 9, 13, 8, 12, 16, 11, 19, 13, 4, 4, 28, 17, 4, 10, 26, 4, 10, 4, 4, 4, 29, - 30, 31, 32, 33, 34, 4, 4, 4, 38, 9, - 40, 11, 12, 13, 4, 15, 7, 17, 44, 43, - 20, 21, 42, 44, 43, 25, 26, 27, 4, 10, - 44, 43, 43, 42, 4, 35, 36, 37, 7, 39, - 44, 41, 10, 4, 4, 7, 42, 4, 42, 44, - 4, 44, 44, 4, 7, 4, 4, 4, 4, 4, - 4, 4, 4, 43, 4, 4, 4, 4, 4, 10, - 44, 44, 7, 44, 4, 4, 7, 44, 44, 44, - 44, 44, -1, -1, 43, -1, 42, 42, -1, -1, - -1, -1, 44, -1, 44, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 42, -1, - -1, 44, 44, -1, -1, -1, 44 + 30, 31, 32, 33, 34, 35, 4, 4, 4, 39, + 9, 41, 11, 12, 13, 4, 15, 4, 17, 7, + 45, 20, 21, 44, 43, 45, 25, 26, 27, 4, + 10, 45, 44, 44, 43, 4, 7, 36, 37, 38, + 43, 40, 44, 42, 45, 10, 4, 4, 43, 43, + 4, 7, 45, 45, 45, 4, 7, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 44, 4, 4, 4, + 4, 4, 10, 45, 44, 7, 4, 45, 45, 45, + 4, 45, 45, 45, 45, 45, 45, 7, 43, -1, + 43, 43, -1, -1, -1, 45, -1, 45, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 45 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ static const unsigned char yystos[] = { - 0, 46, 0, 3, 5, 6, 9, 12, 29, 30, - 31, 32, 33, 34, 38, 40, 47, 4, 4, 4, - 10, 10, 4, 4, 4, 4, 4, 4, 4, 4, - 7, 44, 43, 42, 48, 50, 44, 44, 43, 43, - 42, 43, 44, 42, 11, 13, 16, 26, 49, 8, - 11, 13, 17, 51, 4, 10, 4, 7, 10, 4, - 4, 7, 44, 56, 42, 52, 44, 44, 5, 11, - 19, 57, 9, 11, 12, 13, 15, 17, 20, 21, - 25, 26, 27, 35, 36, 37, 39, 41, 53, 4, - 4, 7, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 10, 4, 4, 4, 4, 4, 7, 43, 44, - 44, 44, 44, 44, 44, 44, 43, 44, 42, 54, - 42, 44, 44, 42, 44, 11, 13, 28, 55, 4, - 4, 7, 44, 44 + 0, 47, 0, 3, 5, 6, 9, 12, 29, 30, + 31, 32, 33, 34, 35, 39, 41, 48, 4, 4, + 4, 10, 10, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 7, 45, 44, 43, 49, 51, 45, 45, + 44, 44, 43, 43, 44, 45, 43, 11, 13, 16, + 26, 50, 8, 11, 13, 17, 52, 4, 10, 4, + 7, 10, 4, 4, 7, 45, 57, 43, 53, 45, + 45, 5, 11, 19, 58, 9, 11, 12, 13, 15, + 17, 20, 21, 25, 26, 27, 36, 37, 38, 40, + 42, 54, 4, 4, 7, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 10, 4, 4, 4, 4, 4, + 7, 44, 45, 45, 45, 45, 45, 45, 45, 44, + 45, 43, 55, 43, 45, 45, 43, 45, 11, 13, + 28, 56, 4, 4, 7, 45, 45 }; #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) @@ -694,20 +694,53 @@ do \ } \ while (0) + #define YYTERROR 1 #define YYERRCODE 256 -/* YYLLOC_DEFAULT -- Compute the default location (before the actions - are run). */ +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) #ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - ((Current).first_line = (Rhs)[1].first_line, \ - (Current).first_column = (Rhs)[1].first_column, \ - (Current).last_line = (Rhs)[N].last_line, \ - (Current).last_column = (Rhs)[N].last_column) +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (N) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ + while (0) #endif + +/* YY_LOCATION_PRINT -- Print the location on the stream. + This macro was not mandated originally: define only if we know + we won't break user code: when these are the locations we know. */ + +#ifndef YY_LOCATION_PRINT +# if YYLTYPE_IS_TRIVIAL +# define YY_LOCATION_PRINT(File, Loc) \ + fprintf (File, "%d.%d-%d.%d", \ + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column) +# else +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif +#endif + + /* YYLEX -- calling `yylex' with the right arguments. */ #ifdef YYLEX_PARAM @@ -730,19 +763,13 @@ do { \ YYFPRINTF Args; \ } while (0) -# define YYDSYMPRINT(Args) \ -do { \ - if (yydebug) \ - yysymprint Args; \ -} while (0) - -# define YYDSYMPRINTF(Title, Token, Value, Location) \ +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ do { \ if (yydebug) \ { \ YYFPRINTF (stderr, "%s ", Title); \ yysymprint (stderr, \ - Token, Value); \ + Type, Value); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) @@ -809,8 +836,7 @@ do { \ int yydebug; #else /* !YYDEBUG */ # define YYDPRINTF(Args) -# define YYDSYMPRINT(Args) -# define YYDSYMPRINTF(Title, Token, Value, Location) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ @@ -828,10 +854,6 @@ int yydebug; SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH) evaluated with infinite-precision integer arithmetic. */ -#if defined (YYMAXDEPTH) && YYMAXDEPTH == 0 -# undef YYMAXDEPTH -#endif - #ifndef YYMAXDEPTH # define YYMAXDEPTH 10000 #endif @@ -913,15 +935,15 @@ yysymprint (yyoutput, yytype, yyvaluep) (void) yyvaluep; if (yytype < YYNTOKENS) - { - YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); -# ifdef YYPRINT - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# endif - } + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); else YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# endif switch (yytype) { default: @@ -937,10 +959,11 @@ yysymprint (yyoutput, yytype, yyvaluep) #if defined (__STDC__) || defined (__cplusplus) static void -yydestruct (int yytype, YYSTYPE *yyvaluep) +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) #else static void -yydestruct (yytype, yyvaluep) +yydestruct (yymsg, yytype, yyvaluep) + const char *yymsg; int yytype; YYSTYPE *yyvaluep; #endif @@ -948,6 +971,10 @@ yydestruct (yytype, yyvaluep) /* Pacify ``unused variable'' warnings. */ (void) yyvaluep; + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + switch (yytype) { @@ -975,10 +1002,10 @@ int yyparse (); -/* The lookahead symbol. */ +/* The look-ahead symbol. */ int yychar; -/* The semantic value of the lookahead symbol. */ +/* The semantic value of the look-ahead symbol. */ YYSTYPE yylval; /* Number of syntax errors so far. */ @@ -1014,7 +1041,7 @@ yyparse () int yyresult; /* Number of tokens to shift before error messages enabled. */ int yyerrstatus; - /* Lookahead token as an internal (translated) token number. */ + /* Look-ahead token as an internal (translated) token number. */ int yytoken = 0; /* Three stacks and their tools: @@ -1066,6 +1093,8 @@ yyparse () yyvsp = yyvs; + yyvsp[0] = yylval; + goto yysetstate; /*------------------------------------------------------------. @@ -1155,18 +1184,18 @@ yyparse () yybackup: /* Do appropriate processing given the current state. */ -/* Read a lookahead token if we need one and don't already have one. */ +/* Read a look-ahead token if we need one and don't already have one. */ /* yyresume: */ - /* First try to decide what to do without reference to lookahead token. */ + /* First try to decide what to do without reference to look-ahead token. */ yyn = yypact[yystate]; if (yyn == YYPACT_NINF) goto yydefault; - /* Not known => get a lookahead token if don't already have one. */ + /* Not known => get a look-ahead token if don't already have one. */ - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */ if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); @@ -1181,7 +1210,7 @@ yybackup: else { yytoken = YYTRANSLATE (yychar); - YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); } /* If the proper action on seeing token YYTOKEN is to reduce or to @@ -1201,8 +1230,8 @@ yybackup: if (yyn == YYFINAL) YYACCEPT; - /* Shift the lookahead token. */ - YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken])); + /* Shift the look-ahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); /* Discard the token being shifted unless it is eof. */ if (yychar != YYEOF) @@ -1253,279 +1282,284 @@ yyreduce: { case 2: #line 99 "conf.y" - { yyval.list = root_list = list_new(NULL); } + { (yyval.list) = root_list = list_new(NULL); } break; case 3: #line 100 "conf.y" - { list_add_last(yyvsp[-2].list, yyvsp[-1].tuple); yyval.list = yyvsp[-2].list; } + { list_add_last((yyvsp[-2].list), (yyvsp[-1].tuple)); (yyval.list) = (yyvsp[-2].list); } break; case 4: #line 104 "conf.y" - { yyval.tuple = tuple_s_new(LEX_LOG_ROOT, yyvsp[0].string); } + { (yyval.tuple) = tuple_s_new(LEX_LOG_ROOT, (yyvsp[0].string)); } break; case 5: #line 105 "conf.y" - { yyval.tuple = tuple_s_new(LEX_LOG_FORMAT, - yyvsp[0].string); } + { (yyval.tuple) = tuple_s_new(LEX_LOG_FORMAT, + (yyvsp[0].string)); } break; case 6: #line 107 "conf.y" - { yyval.tuple = tuple_i_new(LEX_LOG_LEVEL, yyvsp[0].number); } + { (yyval.tuple) = tuple_i_new(LEX_LOG_LEVEL, (yyvsp[0].number)); } break; case 7: #line 108 "conf.y" - { yyval.tuple = tuple_s_new(LEX_IP, yyvsp[0].string); } + { (yyval.tuple) = tuple_s_new(LEX_IP, (yyvsp[0].string)); } break; case 8: #line 109 "conf.y" - { yyval.tuple = tuple_i_new(LEX_PORT, yyvsp[0].number); } + { (yyval.tuple) = tuple_i_new(LEX_PORT, (yyvsp[0].number)); } break; case 9: #line 110 "conf.y" - { yyval.tuple = tuple_i_new(LEX_CSS, yyvsp[0].number); } + { (yyval.tuple) = tuple_i_new(LEX_CSS, (yyvsp[0].number)); } break; case 10: #line 111 "conf.y" - { yyval.tuple = tuple_i_new(LEX_BACKLOG_LINES, - yyvsp[0].number); } + { (yyval.tuple) = tuple_i_new(LEX_BACKLOG_LINES, + (yyvsp[0].number)); } break; case 11: #line 113 "conf.y" - { yyval.tuple = tuple_i_new(LEX_NO_BACKLOG, - yyvsp[0].number); } + { (yyval.tuple) = tuple_i_new(LEX_BACKLOG, + (yyvsp[0].number)); } break; case 12: #line 115 "conf.y" - { yyval.tuple = tuple_i_new( - LEX_ALWAYS_BACKLOG, yyvsp[0].number); } + { (yyval.tuple) = tuple_i_new(LEX_LOG, (yyvsp[0].number)); } break; case 13: -#line 117 "conf.y" - { yyval.tuple = tuple_i_new( - LEX_LOG_SYNC_INTERVAL, yyvsp[0].number); } +#line 116 "conf.y" + { (yyval.tuple) = tuple_i_new( + LEX_ALWAYS_BACKLOG, (yyvsp[0].number)); } break; case 14: -#line 119 "conf.y" - { yyval.tuple = tuple_s_new(LEX_PID_FILE, yyvsp[0].string); } +#line 118 "conf.y" + { (yyval.tuple) = tuple_i_new( + LEX_LOG_SYNC_INTERVAL, (yyvsp[0].number)); } break; case 15: #line 120 "conf.y" - { yyval.tuple = tuple_l_new(LEX_NETWORK, - yyvsp[-1].list); } + { (yyval.tuple) = tuple_s_new(LEX_PID_FILE, (yyvsp[0].string)); } break; case 16: -#line 122 "conf.y" - { yyval.tuple = tuple_l_new(LEX_USER, yyvsp[-1].list); } +#line 121 "conf.y" + { (yyval.tuple) = tuple_l_new(LEX_NETWORK, + (yyvsp[-1].list)); } break; case 17: -#line 125 "conf.y" - { yyval.list = list_new(NULL); } +#line 123 "conf.y" + { (yyval.tuple) = tuple_l_new(LEX_USER, (yyvsp[-1].list)); } break; case 18: #line 126 "conf.y" - { list_add_last(yyvsp[-2].list, yyvsp[-1].tuple); yyval.list = yyvsp[-2].list; } + { (yyval.list) = list_new(NULL); } break; case 19: -#line 129 "conf.y" - { yyval.tuple = tuple_s_new(LEX_NAME, yyvsp[0].string); } +#line 127 "conf.y" + { list_add_last((yyvsp[-2].list), (yyvsp[-1].tuple)); (yyval.list) = (yyvsp[-2].list); } break; case 20: #line 130 "conf.y" - { yyval.tuple = tuple_i_new(LEX_SSL, yyvsp[0].number); } + { (yyval.tuple) = tuple_s_new(LEX_NAME, (yyvsp[0].string)); } break; case 21: #line 131 "conf.y" - { - yyval.tuple = tuple_l_new(LEX_SERVER, yyvsp[-1].list); } + { (yyval.tuple) = tuple_i_new(LEX_SSL, (yyvsp[0].number)); } break; case 22: -#line 135 "conf.y" - { yyval.list = list_new(NULL); } +#line 132 "conf.y" + { + (yyval.tuple) = tuple_l_new(LEX_SERVER, (yyvsp[-1].list)); } break; case 23: #line 136 "conf.y" - { list_add_last(yyvsp[-2].list, yyvsp[-1].tuple); yyval.list = yyvsp[-2].list; } + { (yyval.list) = list_new(NULL); } break; case 24: -#line 139 "conf.y" - { - yyval.tuple = tuple_s_new(LEX_NAME, yyvsp[0].string); } +#line 137 "conf.y" + { list_add_last((yyvsp[-2].list), (yyvsp[-1].tuple)); (yyval.list) = (yyvsp[-2].list); } break; case 25: -#line 141 "conf.y" - { yyval.tuple = tuple_s_new(LEX_PASSWORD, - yyvsp[0].string); } +#line 140 "conf.y" + { + (yyval.tuple) = tuple_s_new(LEX_NAME, (yyvsp[0].string)); } break; case 26: -#line 143 "conf.y" - { - yyval.tuple = tuple_l_new(LEX_CONNECTION, yyvsp[-1].list); } +#line 142 "conf.y" + { (yyval.tuple) = tuple_s_new(LEX_PASSWORD, + (yyvsp[0].string)); } break; case 27: -#line 147 "conf.y" - { yyval.list = list_new(NULL); } +#line 144 "conf.y" + { + (yyval.tuple) = tuple_l_new(LEX_CONNECTION, (yyvsp[-1].list)); } break; case 28: #line 148 "conf.y" - { - list_add_last(yyvsp[-2].list, yyvsp[-1].tuple); yyval.list = yyvsp[-2].list; } + { (yyval.list) = list_new(NULL); } break; case 29: -#line 152 "conf.y" - { yyval.tuple = tuple_s_new(LEX_NAME, yyvsp[0].string); } +#line 149 "conf.y" + { + list_add_last((yyvsp[-2].list), (yyvsp[-1].tuple)); (yyval.list) = (yyvsp[-2].list); } break; case 30: #line 153 "conf.y" - { yyval.tuple = tuple_s_new(LEX_NETWORK, - yyvsp[0].string); } + { (yyval.tuple) = tuple_s_new(LEX_NAME, (yyvsp[0].string)); } break; case 31: -#line 155 "conf.y" - { yyval.tuple = tuple_s_new(LEX_LOGIN, yyvsp[0].string); } +#line 154 "conf.y" + { (yyval.tuple) = tuple_s_new(LEX_NETWORK, + (yyvsp[0].string)); } break; case 32: #line 156 "conf.y" - { yyval.tuple = tuple_s_new(LEX_NICK, yyvsp[0].string); } + { (yyval.tuple) = tuple_s_new(LEX_LOGIN, (yyvsp[0].string)); } break; case 33: #line 157 "conf.y" - { yyval.tuple = tuple_s_new(LEX_USER, yyvsp[0].string); } + { (yyval.tuple) = tuple_s_new(LEX_NICK, (yyvsp[0].string)); } break; case 34: #line 158 "conf.y" - { yyval.tuple = tuple_s_new(LEX_REALNAME, - yyvsp[0].string); } + { (yyval.tuple) = tuple_s_new(LEX_USER, (yyvsp[0].string)); } break; case 35: -#line 160 "conf.y" - { yyval.tuple = tuple_s_new(LEX_PASSWORD, - yyvsp[0].string); } +#line 159 "conf.y" + { (yyval.tuple) = tuple_s_new(LEX_REALNAME, + (yyvsp[0].string)); } break; case 36: -#line 162 "conf.y" - { yyval.tuple = tuple_s_new(LEX_VHOST, yyvsp[0].string); } +#line 161 "conf.y" + { (yyval.tuple) = tuple_s_new(LEX_PASSWORD, + (yyvsp[0].string)); } break; case 37: #line 163 "conf.y" - { - yyval.tuple = tuple_i_new(LEX_SOURCE_PORT, yyvsp[0].number); } + { (yyval.tuple) = tuple_s_new(LEX_VHOST, (yyvsp[0].string)); } break; case 38: -#line 165 "conf.y" - { yyval.tuple = tuple_i_new(LEX_SSL, yyvsp[0].number); } +#line 164 "conf.y" + { + (yyval.tuple) = tuple_i_new(LEX_SOURCE_PORT, (yyvsp[0].number)); } break; case 39: #line 166 "conf.y" - { yyval.tuple = tuple_s_new(LEX_AWAY_NICK, - yyvsp[0].string); } + { (yyval.tuple) = tuple_i_new(LEX_SSL, (yyvsp[0].number)); } break; case 40: -#line 168 "conf.y" - { - yyval.tuple = tuple_i_new(LEX_FOLLOW_NICK, yyvsp[0].number); } +#line 167 "conf.y" + { (yyval.tuple) = tuple_s_new(LEX_AWAY_NICK, + (yyvsp[0].string)); } break; case 41: -#line 170 "conf.y" - { yyval.tuple = tuple_i_new( - LEX_IGN_FIRST_NICK, yyvsp[0].number); } +#line 169 "conf.y" + { + (yyval.tuple) = tuple_i_new(LEX_FOLLOW_NICK, (yyvsp[0].number)); } break; case 42: -#line 172 "conf.y" - { yyval.tuple = tuple_l_new( - LEX_CHANNEL, yyvsp[-1].list); } +#line 171 "conf.y" + { (yyval.tuple) = tuple_i_new( + LEX_IGN_FIRST_NICK, (yyvsp[0].number)); } break; case 43: -#line 174 "conf.y" - { yyval.tuple = tuple_s_new( - LEX_ON_CONNECT_SEND, yyvsp[0].string); } +#line 173 "conf.y" + { (yyval.tuple) = tuple_l_new( + LEX_CHANNEL, (yyvsp[-1].list)); } break; case 44: -#line 177 "conf.y" - { yyval.list = list_new(NULL); } +#line 175 "conf.y" + { (yyval.tuple) = tuple_s_new( + LEX_ON_CONNECT_SEND, (yyvsp[0].string)); } break; case 45: #line 178 "conf.y" - { list_add_last(yyvsp[-2].list, yyvsp[-1].tuple); yyval.list = yyvsp[-2].list; } + { (yyval.list) = list_new(NULL); } break; case 46: -#line 181 "conf.y" - { yyval.tuple = tuple_s_new(LEX_NAME, yyvsp[0].string); } +#line 179 "conf.y" + { list_add_last((yyvsp[-2].list), (yyvsp[-1].tuple)); (yyval.list) = (yyvsp[-2].list); } break; case 47: #line 182 "conf.y" - { yyval.tuple = tuple_s_new(LEX_KEY, yyvsp[0].string); } + { (yyval.tuple) = tuple_s_new(LEX_NAME, (yyvsp[0].string)); } break; case 48: -#line 185 "conf.y" - { yyval.list = list_new(NULL); } +#line 183 "conf.y" + { (yyval.tuple) = tuple_s_new(LEX_KEY, (yyvsp[0].string)); } break; case 49: #line 186 "conf.y" - { list_add_last(yyvsp[-2].list, yyvsp[-1].tuple); yyval.list = yyvsp[-2].list; } + { (yyval.list) = list_new(NULL); } break; case 50: -#line 189 "conf.y" - { yyval.tuple = tuple_s_new(LEX_HOST, yyvsp[0].string); } +#line 187 "conf.y" + { list_add_last((yyvsp[-2].list), (yyvsp[-1].tuple)); (yyval.list) = (yyvsp[-2].list); } break; case 51: #line 190 "conf.y" - { yyval.tuple = tuple_i_new(LEX_PORT, yyvsp[0].number); } + { (yyval.tuple) = tuple_s_new(LEX_HOST, (yyvsp[0].string)); } + break; + + case 52: +#line 191 "conf.y" + { (yyval.tuple) = tuple_i_new(LEX_PORT, (yyvsp[0].number)); } break; } -/* Line 1010 of yacc.c. */ -#line 1529 "y.tab.c" +/* Line 1037 of yacc.c. */ +#line 1563 "y.tab.c" yyvsp -= yylen; yyssp -= yylen; @@ -1625,7 +1659,7 @@ yyerrlab: if (yyerrstatus == 3) { - /* If just tried and failed to reuse lookahead token after an + /* If just tried and failed to reuse look-ahead token after an error, discard it. */ if (yychar <= YYEOF) @@ -1635,23 +1669,22 @@ yyerrlab: if (yychar == YYEOF) for (;;) { + YYPOPSTACK; if (yyssp == yyss) YYABORT; - YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); - yydestruct (yystos[*yyssp], yyvsp); + yydestruct ("Error: popping", + yystos[*yyssp], yyvsp); } } else { - YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc); - yydestruct (yytoken, &yylval); + yydestruct ("Error: discarding", yytoken, &yylval); yychar = YYEMPTY; - } } - /* Else will try to reuse lookahead token after shifting the error + /* Else will try to reuse look-ahead token after shifting the error token. */ goto yyerrlab1; @@ -1668,7 +1701,7 @@ yyerrorlab: goto yyerrorlab; #endif - yyvsp -= yylen; +yyvsp -= yylen; yyssp -= yylen; yystate = *yyssp; goto yyerrlab1; @@ -1698,8 +1731,8 @@ yyerrlab1: if (yyssp == yyss) YYABORT; - YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); - yydestruct (yystos[yystate], yyvsp); + + yydestruct ("Error: popping", yystos[yystate], yyvsp); YYPOPSTACK; yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -1708,11 +1741,12 @@ yyerrlab1: if (yyn == YYFINAL) YYACCEPT; - YYDPRINTF ((stderr, "Shifting error token, ")); - *++yyvsp = yylval; + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + yystate = yyn; goto yynewstate; @@ -1728,6 +1762,9 @@ yyacceptlab: | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ yyabortlab: + yydestruct ("Error: discarding lookahead", + yytoken, &yylval); + yychar = YYEMPTY; yyresult = 1; goto yyreturn; diff --git a/src/conf.h b/src/conf.h index 1932f58..b9a4953 100644 --- a/src/conf.h +++ b/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 diff --git a/src/conf.y b/src/conf.y index 27a5f29..e1bd0c9 100644 --- a/src/conf.y +++ b/src/conf.y @@ -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( diff --git a/src/irc.c b/src/irc.c index f904cbc..d60445e 100644 --- a/src/irc.c +++ b/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; } diff --git a/src/lex.c b/src/lex.c index 93f1bfc..572b56b 100644 --- a/src/lex.c +++ b/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" diff --git a/src/lex.l b/src/lex.l index ebdf483..0bcb62a 100644 --- a/src/lex.l +++ b/src/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; } diff --git a/src/log.c b/src/log.c index 27516ba..aecd168 100644 --- a/src/log.c +++ b/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; diff --git a/src/log.h b/src/log.h index 4c8f784..89a3a81 100644 --- a/src/log.h +++ b/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);