2000-04-26 04:03:38 -04:00
|
|
|
/*
|
|
|
|
fe-log.c : irssi
|
|
|
|
|
2000-04-28 04:07:42 -04:00
|
|
|
Copyright (C) 1999-2000 Timo Sirainen
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
#include "module-formats.h"
|
|
|
|
#include "signals.h"
|
|
|
|
#include "commands.h"
|
2000-08-26 11:39:44 -04:00
|
|
|
#include "servers.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "levels.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "special-vars.h"
|
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
#include "windows.h"
|
|
|
|
#include "window-items.h"
|
|
|
|
|
|
|
|
/* close autologs after 5 minutes of inactivity */
|
|
|
|
#define AUTOLOG_INACTIVITY_CLOSE (60*5)
|
|
|
|
|
|
|
|
#define LOG_DIR_CREATE_MODE 0770
|
|
|
|
|
|
|
|
static int autolog_level;
|
|
|
|
static int autoremove_tag;
|
|
|
|
static const char *autolog_path;
|
|
|
|
|
2000-10-17 19:37:21 -04:00
|
|
|
static void log_add_targets(LOG_REC *log, const char *targets)
|
|
|
|
{
|
|
|
|
char **tmp, **items;
|
|
|
|
|
|
|
|
g_return_if_fail(log != NULL);
|
|
|
|
g_return_if_fail(targets != NULL);
|
|
|
|
|
|
|
|
items = g_strsplit(targets, " ", -1);
|
|
|
|
|
|
|
|
for (tmp = items; *tmp != NULL; tmp++)
|
|
|
|
log_item_add(log, LOG_ITEM_TARGET, *tmp, NULL);
|
|
|
|
|
|
|
|
g_strfreev(items);
|
|
|
|
}
|
|
|
|
|
2000-08-11 18:07:42 -04:00
|
|
|
/* SYNTAX: LOG OPEN [-noopen] [-autoopen] [-targets <targets>]
|
|
|
|
[-window] <fname> [<levels>] */
|
2000-04-26 04:03:38 -04:00
|
|
|
static void cmd_log_open(const char *data)
|
|
|
|
{
|
2000-06-17 21:18:12 -04:00
|
|
|
GHashTable *optlist;
|
2000-08-11 18:07:42 -04:00
|
|
|
char *targetarg, *fname, *levels;
|
2000-06-17 21:18:12 -04:00
|
|
|
void *free_arg;
|
2000-04-26 04:03:38 -04:00
|
|
|
char window[MAX_INT_STRLEN];
|
|
|
|
LOG_REC *log;
|
2000-08-11 18:07:42 -04:00
|
|
|
int level;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS | PARAM_FLAG_GETREST,
|
|
|
|
"log open", &optlist, &fname, &levels))
|
|
|
|
return;
|
2000-04-26 04:03:38 -04:00
|
|
|
if (*fname == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
|
|
|
|
|
|
|
level = level2bits(levels);
|
2000-10-17 19:37:21 -04:00
|
|
|
log = log_create_rec(fname, level != 0 ? level : MSGLEVEL_ALL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
if (g_hash_table_lookup(optlist, "window")) {
|
2000-04-26 04:03:38 -04:00
|
|
|
/* log by window ref# */
|
|
|
|
ltoa(window, active_win->refnum);
|
2000-10-17 19:37:21 -04:00
|
|
|
log_item_add(log, LOG_ITEM_WINDOW_REFNUM, window, NULL);
|
|
|
|
} else {
|
|
|
|
targetarg = g_hash_table_lookup(optlist, "targets");
|
|
|
|
if (targetarg != NULL && *targetarg != '\0')
|
|
|
|
log_add_targets(log, targetarg);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-10-17 19:37:21 -04:00
|
|
|
if (g_hash_table_lookup(optlist, "autoopen"))
|
|
|
|
log->autoopen = TRUE;
|
|
|
|
|
|
|
|
log_update(log);
|
2000-06-04 08:59:46 -04:00
|
|
|
|
2000-10-17 19:37:21 -04:00
|
|
|
if (log->handle == -1 && g_hash_table_lookup(optlist, "noopen") == NULL) {
|
|
|
|
/* start logging */
|
|
|
|
if (log_start_logging(log)) {
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
IRCTXT_LOG_OPENED, fname);
|
|
|
|
} else {
|
|
|
|
log_close(log);
|
2000-06-04 08:59:46 -04:00
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
cmd_params_free(free_arg);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-06-04 08:59:46 -04:00
|
|
|
static LOG_REC *log_find_from_data(const char *data)
|
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
if (!is_numeric(data, ' '))
|
|
|
|
return log_find(data);
|
|
|
|
|
|
|
|
/* with index number */
|
|
|
|
tmp = g_slist_nth(logs, atoi(data)-1);
|
|
|
|
return tmp == NULL ? NULL : tmp->data;
|
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: LOG CLOSE <id>|<file> */
|
2000-04-26 04:03:38 -04:00
|
|
|
static void cmd_log_close(const char *data)
|
|
|
|
{
|
|
|
|
LOG_REC *log;
|
|
|
|
|
2000-06-04 08:59:46 -04:00
|
|
|
log = log_find_from_data(data);
|
2000-04-26 04:03:38 -04:00
|
|
|
if (log == NULL)
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, IRCTXT_LOG_NOT_OPEN, data);
|
|
|
|
else {
|
|
|
|
log_close(log);
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_LOG_CLOSED, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: LOG START <id>|<file> */
|
2000-04-26 04:03:38 -04:00
|
|
|
static void cmd_log_start(const char *data)
|
|
|
|
{
|
|
|
|
LOG_REC *log;
|
|
|
|
|
2000-06-04 08:59:46 -04:00
|
|
|
log = log_find_from_data(data);
|
2000-04-26 04:03:38 -04:00
|
|
|
if (log != NULL) {
|
|
|
|
log_start_logging(log);
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_LOG_OPENED, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: LOG STOP <id>|<file> */
|
2000-04-26 04:03:38 -04:00
|
|
|
static void cmd_log_stop(const char *data)
|
|
|
|
{
|
|
|
|
LOG_REC *log;
|
|
|
|
|
2000-06-04 08:59:46 -04:00
|
|
|
log = log_find_from_data(data);
|
2000-04-26 04:03:38 -04:00
|
|
|
if (log == NULL || log->handle == -1)
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, IRCTXT_LOG_NOT_OPEN, data);
|
|
|
|
else {
|
|
|
|
log_stop_logging(log);
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_LOG_CLOSED, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-17 19:37:21 -04:00
|
|
|
static char *log_items_get_list(LOG_REC *log)
|
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
GString *str;
|
|
|
|
char *ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail(log != NULL, NULL);
|
|
|
|
g_return_val_if_fail(log->items != NULL, NULL);
|
|
|
|
|
|
|
|
str = g_string_new(NULL);
|
|
|
|
for (tmp = log->items; tmp != NULL; tmp = tmp->next) {
|
|
|
|
LOG_ITEM_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
g_string_sprintfa(str, "%s, ", rec->name);
|
|
|
|
}
|
|
|
|
g_string_truncate(str, str->len-2);
|
|
|
|
|
|
|
|
ret = str->str;
|
|
|
|
g_string_free(str, FALSE);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: LOG LIST */
|
2000-04-26 04:03:38 -04:00
|
|
|
static void cmd_log_list(void)
|
|
|
|
{
|
|
|
|
GSList *tmp;
|
2000-08-11 18:07:42 -04:00
|
|
|
char *levelstr, *items;
|
2000-06-04 08:59:46 -04:00
|
|
|
int index;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_LOG_LIST_HEADER);
|
2000-06-04 08:59:46 -04:00
|
|
|
for (tmp = logs, index = 1; tmp != NULL; tmp = tmp->next, index++) {
|
2000-04-26 04:03:38 -04:00
|
|
|
LOG_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
levelstr = bits2level(rec->level);
|
|
|
|
items = rec->items == NULL ? NULL :
|
2000-10-17 19:37:21 -04:00
|
|
|
log_items_get_list(rec);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_LOG_LIST,
|
2000-06-04 08:59:46 -04:00
|
|
|
index, rec->fname, items != NULL ? items : "",
|
2000-08-11 18:07:42 -04:00
|
|
|
levelstr, rec->autoopen ? " -autoopen" : "");
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
g_free_not_null(items);
|
|
|
|
g_free(levelstr);
|
|
|
|
}
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_LOG_LIST_FOOTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cmd_log(const char *data, SERVER_REC *server, void *item)
|
|
|
|
{
|
2000-06-28 13:15:37 -04:00
|
|
|
if (*data == '\0')
|
|
|
|
cmd_log_list();
|
|
|
|
else
|
|
|
|
command_runsub("log", data, server, item);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-10-17 19:37:21 -04:00
|
|
|
static LOG_REC *logs_find_item(int type, const char *item,
|
|
|
|
SERVER_REC *server, LOG_ITEM_REC **ret_item)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-10-17 19:37:21 -04:00
|
|
|
LOG_ITEM_REC *logitem;
|
2000-04-26 04:03:38 -04:00
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
for (tmp = logs; tmp != NULL; tmp = tmp->next) {
|
2000-10-17 19:37:21 -04:00
|
|
|
LOG_REC *log = tmp->data;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-10-17 19:37:21 -04:00
|
|
|
logitem = log_item_find(log, type, item, server);
|
|
|
|
if (logitem != NULL) {
|
|
|
|
if (ret_item != NULL) *ret_item = logitem;
|
|
|
|
return log;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: WINDOW LOG on|off|toggle [<filename>] */
|
2000-04-26 04:03:38 -04:00
|
|
|
static void cmd_window_log(const char *data)
|
|
|
|
{
|
|
|
|
LOG_REC *log;
|
2000-06-17 21:18:12 -04:00
|
|
|
char *set, *fname, window[MAX_INT_STRLEN];
|
|
|
|
void *free_arg;
|
2000-04-26 04:03:38 -04:00
|
|
|
int open_log, close_log;
|
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
if (!cmd_get_params(data, &free_arg, 2, &set, &fname))
|
|
|
|
return;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
ltoa(window, active_win->refnum);
|
2000-10-17 19:37:21 -04:00
|
|
|
log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, window, NULL, NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
open_log = close_log = FALSE;
|
|
|
|
if (g_strcasecmp(set, "ON") == 0)
|
|
|
|
open_log = TRUE;
|
|
|
|
else if (g_strcasecmp(set, "OFF") == 0) {
|
|
|
|
close_log = TRUE;
|
|
|
|
} else if (g_strcasecmp(set, "TOGGLE") == 0) {
|
|
|
|
open_log = log == NULL;
|
|
|
|
close_log = log != NULL;
|
|
|
|
} else {
|
2000-05-04 06:32:42 -04:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_NOT_TOGGLE);
|
2000-06-17 21:18:12 -04:00
|
|
|
cmd_params_free(free_arg);
|
2000-04-26 04:03:38 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (open_log && log == NULL) {
|
|
|
|
/* irc.log.<windowname> or irc.log.Window<ref#> */
|
|
|
|
fname = *fname != '\0' ? g_strdup(fname) :
|
|
|
|
g_strdup_printf("~/irc.log.%s%s",
|
|
|
|
active_win->name != NULL ? active_win->name : "Window",
|
|
|
|
active_win->name != NULL ? "" : window);
|
2000-10-17 19:37:21 -04:00
|
|
|
log = log_create_rec(fname, MSGLEVEL_ALL);
|
|
|
|
log_item_add(log, LOG_ITEM_WINDOW_REFNUM, window, NULL);
|
|
|
|
log_update(log);
|
2000-04-26 04:03:38 -04:00
|
|
|
g_free(fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (open_log && log != NULL) {
|
|
|
|
log_start_logging(log);
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_LOG_OPENED, log->fname);
|
|
|
|
} else if (close_log && log != NULL && log->handle != -1) {
|
|
|
|
log_stop_logging(log);
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_LOG_CLOSED, log->fname);
|
|
|
|
}
|
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
cmd_params_free(free_arg);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create log file entry to window, but don't start logging */
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: WINDOW LOGFILE <file> */
|
2000-04-26 04:03:38 -04:00
|
|
|
static void cmd_window_logfile(const char *data)
|
|
|
|
{
|
|
|
|
LOG_REC *log;
|
|
|
|
char window[MAX_INT_STRLEN];
|
|
|
|
|
|
|
|
ltoa(window, active_win->refnum);
|
2000-10-17 19:37:21 -04:00
|
|
|
log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, window, NULL, NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
if (log != NULL) {
|
2000-05-04 06:32:42 -04:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_WINDOWLOG_FILE_LOGGING);
|
2000-04-26 04:03:38 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-10-17 19:37:21 -04:00
|
|
|
log = log_create_rec(data, MSGLEVEL_ALL);
|
|
|
|
log_item_add(log, LOG_ITEM_WINDOW_REFNUM, window, NULL);
|
|
|
|
log_update(log);
|
|
|
|
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_WINDOWLOG_FILE, data);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
/* window's refnum changed - update the logs to log the new window refnum */
|
|
|
|
static void sig_window_refnum_changed(WINDOW_REC *window, gpointer old_refnum)
|
|
|
|
{
|
|
|
|
char winnum[MAX_INT_STRLEN];
|
|
|
|
LOG_REC *log;
|
2000-10-17 19:37:21 -04:00
|
|
|
LOG_ITEM_REC *item;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
|
|
|
ltoa(winnum, GPOINTER_TO_INT(old_refnum));
|
2000-10-17 19:37:21 -04:00
|
|
|
log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, winnum, NULL, &item);
|
2000-05-04 06:32:42 -04:00
|
|
|
|
|
|
|
if (log != NULL) {
|
|
|
|
ltoa(winnum, window->refnum);
|
|
|
|
|
2000-10-17 19:37:21 -04:00
|
|
|
g_free(item->name);
|
|
|
|
item->name = g_strdup(winnum);
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
static void autologs_close_all(void)
|
|
|
|
{
|
|
|
|
GSList *tmp, *next;
|
|
|
|
|
|
|
|
for (tmp = logs; tmp != NULL; tmp = next) {
|
|
|
|
LOG_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
next = tmp->next;
|
|
|
|
if (rec->temp) log_close(rec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void autolog_log(void *server, const char *target)
|
|
|
|
{
|
|
|
|
LOG_REC *log;
|
|
|
|
char *fname, *dir, *str;
|
|
|
|
|
2000-10-17 19:37:21 -04:00
|
|
|
log = logs_find_item(LOG_ITEM_TARGET, target, server, NULL);
|
2000-10-13 17:53:25 -04:00
|
|
|
if (log != NULL && !log->failed) {
|
2000-07-22 12:02:50 -04:00
|
|
|
log_start_logging(log);
|
|
|
|
return;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
fname = parse_special_string(autolog_path, server, NULL, target, NULL);
|
|
|
|
if (log_find(fname) == NULL) {
|
|
|
|
str = convert_home(fname);
|
|
|
|
dir = g_dirname(str);
|
|
|
|
g_free(str);
|
|
|
|
|
2000-08-12 11:50:50 -04:00
|
|
|
mkpath(dir, LOG_DIR_CREATE_MODE);
|
2000-04-26 04:03:38 -04:00
|
|
|
g_free(dir);
|
|
|
|
|
2000-10-17 19:37:21 -04:00
|
|
|
log = log_create_rec(fname, autolog_level);
|
|
|
|
log_item_add(log, LOG_ITEM_TARGET, target, server);
|
|
|
|
|
|
|
|
log->temp = TRUE;
|
|
|
|
log_update(log);
|
|
|
|
log_start_logging(log);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
g_free(fname);
|
|
|
|
}
|
|
|
|
|
2000-08-11 16:13:49 -04:00
|
|
|
static void sig_printtext_stripped(WINDOW_REC *window, void *server,
|
|
|
|
const char *target, gpointer levelp,
|
|
|
|
const char *text)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
|
|
|
char windownum[MAX_INT_STRLEN];
|
2000-08-11 16:13:49 -04:00
|
|
|
char **targets, **tmp;
|
2000-04-26 04:03:38 -04:00
|
|
|
LOG_REC *log;
|
|
|
|
int level;
|
|
|
|
|
|
|
|
level = GPOINTER_TO_INT(levelp);
|
2000-05-15 04:25:45 -04:00
|
|
|
if (level == MSGLEVEL_NEVER) return;
|
|
|
|
|
|
|
|
/* let autolog create the log records */
|
2000-08-11 16:13:49 -04:00
|
|
|
if ((autolog_level & level) && target != NULL && *target != '\0') {
|
|
|
|
/* there can be multiple targets separated with comma */
|
|
|
|
targets = g_strsplit(target, ",", -1);
|
|
|
|
for (tmp = targets; *tmp != NULL; tmp++) {
|
|
|
|
autolog_log(server, *tmp);
|
|
|
|
}
|
|
|
|
g_strfreev(targets);
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
/* save to log created with /WINDOW LOG */
|
|
|
|
ltoa(windownum, window->refnum);
|
2000-10-17 19:37:21 -04:00
|
|
|
log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, windownum, NULL, NULL);
|
2000-05-15 04:25:45 -04:00
|
|
|
if (log != NULL) log_write_rec(log, text);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sig_autoremove(void)
|
|
|
|
{
|
2000-10-17 19:37:21 -04:00
|
|
|
SERVER_REC *server;
|
|
|
|
LOG_ITEM_REC *logitem;
|
2000-04-26 04:03:38 -04:00
|
|
|
GSList *tmp, *next;
|
|
|
|
time_t removetime;
|
|
|
|
|
|
|
|
removetime = time(NULL)-AUTOLOG_INACTIVITY_CLOSE;
|
|
|
|
for (tmp = logs; tmp != NULL; tmp = next) {
|
2000-10-17 19:37:21 -04:00
|
|
|
LOG_REC *log = tmp->data;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
next = tmp->next;
|
2000-10-17 19:37:21 -04:00
|
|
|
|
|
|
|
if (!log->temp || log->last > removetime || log->items == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Close only logs with private messages */
|
|
|
|
logitem = log->items->data;
|
|
|
|
server = server_find_tag(logitem->servertag);
|
|
|
|
if (logitem->type == LOG_ITEM_TARGET &&
|
|
|
|
server != NULL && !server->ischannel(*logitem->name))
|
|
|
|
log_close(log);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_window_item_remove(WINDOW_REC *window, WI_ITEM_REC *item)
|
|
|
|
{
|
2000-10-17 19:37:21 -04:00
|
|
|
LOG_REC *log;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-10-17 19:37:21 -04:00
|
|
|
log = logs_find_item(LOG_ITEM_TARGET, item->name, item->server, NULL);
|
|
|
|
if (log != NULL) log_close(log);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_log_locked(LOG_REC *log)
|
|
|
|
{
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
IRCTXT_LOG_LOCKED, log->fname);
|
|
|
|
}
|
|
|
|
|
2000-05-18 04:46:56 -04:00
|
|
|
static void sig_log_create_failed(LOG_REC *log)
|
|
|
|
{
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
IRCTXT_LOG_CREATE_FAILED, log->fname, g_strerror(errno));
|
|
|
|
}
|
|
|
|
|
2000-06-01 21:15:51 -04:00
|
|
|
static void sig_awaylog_show(LOG_REC *log, gpointer pmsgs, gpointer pfilepos)
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
int msgs, filepos;
|
|
|
|
|
|
|
|
msgs = GPOINTER_TO_INT(pmsgs);
|
|
|
|
filepos = GPOINTER_TO_INT(pfilepos);
|
|
|
|
|
|
|
|
if (msgs == 0)
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_LOG_NO_AWAY_MSGS, log->fname);
|
|
|
|
else {
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_LOG_AWAY_MSGS, log->fname, msgs);
|
|
|
|
|
|
|
|
str = g_strdup_printf("\"%s\" %d", log->fname, filepos);
|
|
|
|
signal_emit("command cat", 1, str);
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
static void read_settings(void)
|
|
|
|
{
|
|
|
|
int old_autolog = autolog_level;
|
|
|
|
|
|
|
|
autolog_path = settings_get_str("autolog_path");
|
|
|
|
autolog_level = !settings_get_bool("autolog") ? 0 :
|
|
|
|
level2bits(settings_get_str("autolog_level"));
|
|
|
|
|
|
|
|
if (old_autolog && !autolog_level)
|
|
|
|
autologs_close_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
void fe_log_init(void)
|
|
|
|
{
|
|
|
|
autoremove_tag = g_timeout_add(60000, (GSourceFunc) sig_autoremove, NULL);
|
|
|
|
|
|
|
|
settings_add_str("log", "autolog_path", "~/irclogs/$tag/$0.log");
|
2000-10-17 19:37:21 -04:00
|
|
|
settings_add_str("log", "autolog_level", "all -crap -clientcrap");
|
2000-04-26 04:03:38 -04:00
|
|
|
settings_add_bool("log", "autolog", FALSE);
|
|
|
|
|
|
|
|
autolog_level = 0;
|
|
|
|
read_settings();
|
|
|
|
|
|
|
|
command_bind("log", NULL, (SIGNAL_FUNC) cmd_log);
|
|
|
|
command_bind("log open", NULL, (SIGNAL_FUNC) cmd_log_open);
|
|
|
|
command_bind("log close", NULL, (SIGNAL_FUNC) cmd_log_close);
|
|
|
|
command_bind("log start", NULL, (SIGNAL_FUNC) cmd_log_start);
|
|
|
|
command_bind("log stop", NULL, (SIGNAL_FUNC) cmd_log_stop);
|
|
|
|
command_bind("window log", NULL, (SIGNAL_FUNC) cmd_window_log);
|
|
|
|
command_bind("window logfile", NULL, (SIGNAL_FUNC) cmd_window_logfile);
|
|
|
|
signal_add_first("print text stripped", (SIGNAL_FUNC) sig_printtext_stripped);
|
|
|
|
signal_add("window item remove", (SIGNAL_FUNC) sig_window_item_remove);
|
2000-05-04 06:32:42 -04:00
|
|
|
signal_add("window refnum changed", (SIGNAL_FUNC) sig_window_refnum_changed);
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_add("log locked", (SIGNAL_FUNC) sig_log_locked);
|
2000-05-18 04:46:56 -04:00
|
|
|
signal_add("log create failed", (SIGNAL_FUNC) sig_log_create_failed);
|
2000-06-01 21:15:51 -04:00
|
|
|
signal_add("awaylog show", (SIGNAL_FUNC) sig_awaylog_show);
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
|
2000-06-17 21:18:12 -04:00
|
|
|
|
2000-08-11 18:07:42 -04:00
|
|
|
command_set_options("log open", "noopen autoopen -targets window");
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void fe_log_deinit(void)
|
|
|
|
{
|
|
|
|
g_source_remove(autoremove_tag);
|
|
|
|
|
|
|
|
command_unbind("log", (SIGNAL_FUNC) cmd_log);
|
|
|
|
command_unbind("log open", (SIGNAL_FUNC) cmd_log_open);
|
|
|
|
command_unbind("log close", (SIGNAL_FUNC) cmd_log_close);
|
|
|
|
command_unbind("log start", (SIGNAL_FUNC) cmd_log_start);
|
|
|
|
command_unbind("log stop", (SIGNAL_FUNC) cmd_log_stop);
|
|
|
|
command_unbind("window log", (SIGNAL_FUNC) cmd_window_log);
|
|
|
|
command_unbind("window logfile", (SIGNAL_FUNC) cmd_window_logfile);
|
|
|
|
signal_remove("print text stripped", (SIGNAL_FUNC) sig_printtext_stripped);
|
|
|
|
signal_remove("window item remove", (SIGNAL_FUNC) sig_window_item_remove);
|
2000-05-04 06:32:42 -04:00
|
|
|
signal_remove("window refnum changed", (SIGNAL_FUNC) sig_window_refnum_changed);
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_remove("log locked", (SIGNAL_FUNC) sig_log_locked);
|
2000-05-18 04:46:56 -04:00
|
|
|
signal_remove("log create failed", (SIGNAL_FUNC) sig_log_create_failed);
|
2000-06-01 21:15:51 -04:00
|
|
|
signal_remove("awaylog show", (SIGNAL_FUNC) sig_awaylog_show);
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
|
|
|
}
|