2 log-away.c : Awaylog handling
4 Copyright (C) 1999-2001 Timo Sirainen
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 static LOG_REC *awaylog;
29 static int away_filepos;
32 static void sig_log_written(LOG_REC *log)
34 if (log != awaylog) return;
39 static void awaylog_open(void)
41 const char *fname, *levelstr;
45 fname = settings_get_str("awaylog_file");
46 levelstr = settings_get_str("awaylog_level");
47 if (*fname == '\0' || *levelstr == '\0') return;
49 level = level2bits(levelstr);
50 if (level == 0) return;
52 log = log_find(fname);
53 if (log != NULL && log->handle != -1)
54 return; /* already open */
57 log = log_create_rec(fname, level);
62 if (!log_start_logging(log)) {
63 /* creating log file failed? close it. */
69 away_filepos = lseek(log->handle, 0, SEEK_CUR);
73 static void awaylog_close(void)
78 fname = settings_get_str("awaylog_file");
79 if (*fname == '\0') return;
81 log = log_find(fname);
82 if (log == NULL || log->handle == -1) {
83 /* awaylog not open */
87 if (awaylog == log) awaylog = NULL;
89 signal_emit("awaylog show", 3, log, GINT_TO_POINTER(away_msgs),
90 GINT_TO_POINTER(away_filepos));
94 static void sig_away_changed(SERVER_REC *server)
96 if (server->usermode_away)
102 void log_away_init(void)
108 settings_add_str("log", "awaylog_file", IRSSI_DIR_SHORT"/away.log");
109 settings_add_str("log", "awaylog_level", "msgs hilight");
111 signal_add("log written", (SIGNAL_FUNC) sig_log_written);
112 signal_add("away mode changed", (SIGNAL_FUNC) sig_away_changed);
115 void log_away_deinit(void)
117 signal_remove("log written", (SIGNAL_FUNC) sig_log_written);
118 signal_remove("away mode changed", (SIGNAL_FUNC) sig_away_changed);