1
0
mirror of https://github.com/irssi/irssi.git synced 2024-11-03 04:27:19 -05:00

Merge pull request #1432 from horgh/horgh/win-logfile

Check window logfile parameter
This commit is contained in:
ailin-nemui 2022-12-23 10:34:56 +01:00 committed by GitHub
commit 6f5026fd49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,15 +61,15 @@ static GTimeZone *utc;
static char *log_colorizer_strip(const char *str)
{
return strip_codes(str);
return strip_codes(str);
}
static void log_add_targets(LOG_REC *log, const char *targets, const char *tag)
{
char **tmp, **items;
g_return_if_fail(log != NULL);
g_return_if_fail(targets != NULL);
g_return_if_fail(log != NULL);
g_return_if_fail(targets != NULL);
items = g_strsplit(targets, " ", -1);
@ -84,18 +84,18 @@ static void log_add_targets(LOG_REC *log, const char *targets, const char *tag)
<fname> [<levels>] */
static void cmd_log_open(const char *data)
{
SERVER_REC *server;
GHashTable *optlist;
SERVER_REC *server;
GHashTable *optlist;
char *targetarg, *fname, *levels, *servertag;
void *free_arg;
char window[MAX_INT_STRLEN];
LOG_REC *log;
int level;
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST |
PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_OPTIONS |
PARAM_FLAG_STRIP_TRAILING_WS, "log open", &optlist,
&fname, &levels))
if (!cmd_get_params(data, &free_arg,
2 | PARAM_FLAG_GETREST | PARAM_FLAG_UNKNOWN_OPTIONS |
PARAM_FLAG_OPTIONS | PARAM_FLAG_STRIP_TRAILING_WS,
"log open", &optlist, &fname, &levels))
return;
if (*fname == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
@ -113,8 +113,7 @@ static void cmd_log_open(const char *data)
ltoa(window, active_win->refnum);
targetarg = window;
}
log_item_add(log, LOG_ITEM_WINDOW_REFNUM, targetarg,
servertag);
log_item_add(log, LOG_ITEM_WINDOW_REFNUM, targetarg, servertag);
} else {
targetarg = g_hash_table_lookup(optlist, "targets");
if (targetarg != NULL && *targetarg != '\0')
@ -134,14 +133,13 @@ static void cmd_log_open(const char *data)
if (log->handle == -1 && g_hash_table_lookup(optlist, "noopen") == NULL) {
/* start logging */
if (log_start_logging(log)) {
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
TXT_LOG_OPENED, fname);
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_LOG_OPENED, fname);
} else {
log_close(log);
}
}
cmd_params_free(free_arg);
cmd_params_free(free_arg);
}
static LOG_REC *log_find_from_data(const char *data)
@ -210,7 +208,7 @@ static char *log_items_get_list(LOG_REC *log)
for (tmp = log->items; tmp != NULL; tmp = tmp->next) {
rec = tmp->data;
g_string_append_printf(str, "%s, ", rec->name);
g_string_append_printf(str, "%s, ", rec->name);
}
g_string_truncate(str, str->len-2);
if(rec->servertag != NULL)
@ -232,13 +230,11 @@ static void cmd_log_list(void)
LOG_REC *rec = tmp->data;
levelstr = bits2level(rec->level);
items = rec->items == NULL ? NULL :
log_items_get_list(rec);
items = rec->items == NULL ? NULL : log_items_get_list(rec);
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_LOG_LIST,
index, rec->fname, items != NULL ? items : "",
levelstr, rec->autoopen ? " -autoopen" : "",
rec->handle != -1 ? " active" : "");
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_LOG_LIST, index, rec->fname,
items != NULL ? items : "", levelstr, rec->autoopen ? " -autoopen" : "",
rec->handle != -1 ? " active" : "");
g_free_not_null(items);
g_free(levelstr);
@ -254,8 +250,8 @@ static void cmd_log(const char *data, SERVER_REC *server, void *item)
command_runsub("log", data, server, item);
}
static LOG_REC *logs_find_item(int type, const char *item,
const char *servertag, LOG_ITEM_REC **ret_item)
static LOG_REC *logs_find_item(int type, const char *item, const char *servertag,
LOG_ITEM_REC **ret_item)
{
LOG_ITEM_REC *logitem;
GSList *tmp;
@ -285,17 +281,17 @@ static void cmd_window_log(const char *data)
if (!cmd_get_params(data, &free_arg, 2, &set, &fname))
return;
ltoa(window, active_win->refnum);
ltoa(window, active_win->refnum);
log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, window, NULL, NULL);
open_log = close_log = FALSE;
open_log = close_log = FALSE;
if (g_ascii_strcasecmp(set, "ON") == 0)
open_log = TRUE;
else if (g_ascii_strcasecmp(set, "OFF") == 0) {
close_log = TRUE;
} else if (g_ascii_strcasecmp(set, "TOGGLE") == 0) {
open_log = log == NULL;
close_log = log != NULL;
open_log = log == NULL;
close_log = log != NULL;
} else {
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_NOT_TOGGLE);
cmd_params_free(free_arg);
@ -310,7 +306,7 @@ static void cmd_window_log(const char *data)
active_win->name != NULL ? "" : window);
log = log_create_rec(fname, MSGLEVEL_ALL);
log->colorizer = log_colorizer_strip;
log_item_add(log, LOG_ITEM_WINDOW_REFNUM, window, NULL);
log_item_add(log, LOG_ITEM_WINDOW_REFNUM, window, NULL);
log_update(log);
g_free(fname);
}
@ -323,7 +319,7 @@ static void cmd_window_log(const char *data)
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_LOG_CLOSED, log->fname);
}
cmd_params_free(free_arg);
cmd_params_free(free_arg);
}
/* Create log file entry to window, but don't start logging */
@ -332,21 +328,34 @@ static void cmd_window_logfile(const char *data)
{
LOG_REC *log;
char window[MAX_INT_STRLEN];
void *free_arg;
char *fname;
ltoa(window, active_win->refnum);
if (!cmd_get_params(data, &free_arg, 1, &fname)) {
return;
}
if (!fname || strlen(fname) == 0) {
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
}
ltoa(window, active_win->refnum);
log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, window, NULL, NULL);
if (log != NULL) {
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_WINDOWLOG_FILE_LOGGING);
cmd_params_free(free_arg);
return;
}
log = log_create_rec(data, MSGLEVEL_ALL);
log = log_create_rec(fname, MSGLEVEL_ALL);
log->colorizer = log_colorizer_strip;
log_item_add(log, LOG_ITEM_WINDOW_REFNUM, window, NULL);
log_update(log);
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_WINDOWLOG_FILE, data);
cmd_params_free(free_arg);
}
/* window's refnum changed - update the logs to log the new window refnum */
@ -356,7 +365,7 @@ static void sig_window_refnum_changed(WINDOW_REC *window, gpointer old_refnum)
LOG_REC *log;
LOG_ITEM_REC *item;
ltoa(winnum, GPOINTER_TO_INT(old_refnum));
ltoa(winnum, GPOINTER_TO_INT(old_refnum));
log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, winnum, NULL, &item);
if (log != NULL) {
@ -369,7 +378,7 @@ static void sig_window_refnum_changed(WINDOW_REC *window, gpointer old_refnum)
static void sig_server_disconnected(SERVER_REC *server)
{
LOG_ITEM_REC *logitem;
LOG_ITEM_REC *logitem;
GSList *tmp, *next;
for (tmp = logs; tmp != NULL; tmp = next) {
@ -377,13 +386,13 @@ static void sig_server_disconnected(SERVER_REC *server)
next = tmp->next;
if (!log->temp || log->items == NULL)
continue;
continue;
logitem = log->items->data;
if (logitem->type == LOG_ITEM_TARGET &&
logitem->servertag != NULL &&
if (logitem->type == LOG_ITEM_TARGET && logitem->servertag != NULL &&
g_ascii_strcasecmp(logitem->servertag, server->tag) == 0 &&
server_ischannel(server, logitem->name)) /* kludge again.. so we won't close dcc chats */
server_ischannel(
server, logitem->name)) /* kludge again.. so we won't close dcc chats */
log_close(log);
}
}
@ -415,15 +424,14 @@ static char *escape_target(const char *target)
*p++ = *target;
}
target++;
target++;
}
*p = '\0';
return str;
return str;
}
static void autolog_open(SERVER_REC *server, const char *server_tag,
const char *target)
static void autolog_open(SERVER_REC *server, const char *server_tag, const char *target)
{
LOG_REC *log;
char *fname, *dir, *fixed_target, *params;
@ -444,17 +452,16 @@ static void autolog_open(SERVER_REC *server, const char *server_tag,
if (CHAT_PROTOCOL(server)->case_insensitive)
ascii_strdown(fixed_target);
/* $0 = target, $1 = server tag */
params = g_strconcat(fixed_target, " ", server_tag, NULL);
/* $0 = target, $1 = server tag */
params = g_strconcat(fixed_target, " ", server_tag, NULL);
g_free(fixed_target);
fname = parse_special_string(autolog_path, server, NULL,
params, NULL, 0);
fname = parse_special_string(autolog_path, server, NULL, params, NULL, 0);
g_free(params);
if (log_find(fname) == NULL) {
log = log_create_rec(fname, autolog_level);
if (!settings_get_bool("autolog_colors"))
if (!settings_get_bool("autolog_colors"))
log->colorizer = log_colorizer_strip;
log_item_add(log, LOG_ITEM_TARGET, target, server_tag);
@ -485,8 +492,8 @@ static void autolog_open_check(TEXT_DEST_REC *dest)
we're parting the channel with /WINDOW CLOSE.. Maybe a small
timeout would be nice instead of immediately closing the log file
after "window item destroyed" */
if (level == MSGLEVEL_PARTS ||
(autolog_level & level) == 0 || target == NULL || *target == '\0')
if (level == MSGLEVEL_PARTS || (autolog_level & level) == 0 || target == NULL ||
*target == '\0')
return;
deftarget = server ? server->nick : "unknown";
@ -496,8 +503,7 @@ static void autolog_open_check(TEXT_DEST_REC *dest)
&& channel_setup_find(target, server_tag) == NULL)
return;
if (autolog_ignore_targets != NULL &&
strarray_find_dest(autolog_ignore_targets, dest))
if (autolog_ignore_targets != NULL && strarray_find_dest(autolog_ignore_targets, dest))
return;
if (target != NULL)
@ -513,8 +519,7 @@ static void log_single_line(WINDOW_REC *window, const char *server_tag, const ch
if (window != NULL) {
/* save to log created with /WINDOW LOG */
ltoa(windownum, window->refnum);
log = logs_find_item(LOG_ITEM_WINDOW_REFNUM,
windownum, NULL, NULL);
log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, windownum, NULL, NULL);
if (log != NULL)
log_write_rec(log, text, level, t);
}
@ -554,8 +559,7 @@ static void log_line(TEXT_DEST_REC *dest, const char *text)
g_strfreev(lines);
}
static void sig_printtext(TEXT_DEST_REC *dest, const char *text,
const char *stripped)
static void sig_printtext(TEXT_DEST_REC *dest, const char *text, const char *stripped)
{
if (skip_next_printtext) {
skip_next_printtext = FALSE;
@ -565,8 +569,8 @@ static void sig_printtext(TEXT_DEST_REC *dest, const char *text,
log_line(dest, text);
}
static void sig_print_format(THEME_REC *theme, const char *module,
TEXT_DEST_REC *dest, void *formatnum, char **args)
static void sig_print_format(THEME_REC *theme, const char *module, TEXT_DEST_REC *dest,
void *formatnum, char **args)
{
char *str, *linestart, *tmp;
@ -580,14 +584,14 @@ static void sig_print_format(THEME_REC *theme, const char *module,
if (theme == log_theme)
return;
str = format_get_text_theme_charargs(log_theme, module, dest,
GPOINTER_TO_INT(formatnum), args);
str = format_get_text_theme_charargs(log_theme, module, dest, GPOINTER_TO_INT(formatnum),
args);
if (str != NULL && *str != '\0') {
skip_next_printtext = TRUE;
/* add the line start format */
linestart = format_get_level_tag(log_theme, dest);
tmp = str;
tmp = str;
str = format_add_linestart(tmp, linestart);
g_free_not_null(linestart);
g_free(tmp);
@ -606,14 +610,14 @@ static int sig_autoremove(void)
GSList *tmp, *next;
time_t removetime;
removetime = time(NULL)-AUTOLOG_INACTIVITY_CLOSE;
removetime = time(NULL) - AUTOLOG_INACTIVITY_CLOSE;
for (tmp = logs; tmp != NULL; tmp = next) {
LOG_REC *log = tmp->data;
next = tmp->next;
if (!log->temp || log->last > removetime || log->items == NULL)
continue;
continue;
/* Close only logs with private messages */
logitem = log->items->data;
@ -621,8 +625,8 @@ static int sig_autoremove(void)
continue;
server = server_find_tag(logitem->servertag);
if (logitem->type == LOG_ITEM_TARGET &&
server != NULL && !server_ischannel(server, logitem->name))
if (logitem->type == LOG_ITEM_TARGET && server != NULL &&
!server_ischannel(server, logitem->name))
log_close(log);
}
return 1;
@ -633,43 +637,40 @@ static void sig_window_item_remove(WINDOW_REC *window, WI_ITEM_REC *item)
LOG_REC *log;
log = logs_find_item(LOG_ITEM_TARGET, item->visible_name,
item->server == NULL ? NULL :
item->server->tag, NULL);
item->server == NULL ? NULL : item->server->tag, NULL);
if (log != NULL && log->temp)
log_close(log);
}
static void sig_log_locked(LOG_REC *log)
{
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
TXT_LOG_LOCKED, log->real_fname);
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_LOG_LOCKED, log->real_fname);
}
static void sig_log_create_failed(LOG_REC *log)
{
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
TXT_LOG_CREATE_FAILED,
log->real_fname, g_strerror(errno));
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_LOG_CREATE_FAILED, log->real_fname,
g_strerror(errno));
}
static void sig_log_new(LOG_REC *log)
{
if (!settings_get_bool("awaylog_colors") &&
g_strcmp0(log->fname, settings_get_str("awaylog_file")) == 0)
log->colorizer = log_colorizer_strip;
log->colorizer = log_colorizer_strip;
}
static void sig_log_config_read(LOG_REC *log, CONFIG_NODE *node)
{
if (!config_node_get_bool(node, "colors", FALSE))
if (!config_node_get_bool(node, "colors", FALSE))
log->colorizer = log_colorizer_strip;
}
static void sig_log_config_save(LOG_REC *log, CONFIG_NODE *node)
{
if (log->colorizer == NULL)
if (log->colorizer == NULL)
iconfig_node_set_bool(node, "colors", TRUE);
else
else
iconfig_node_set_str(node, "colors", NULL);
}
@ -686,7 +687,7 @@ static void sig_awaylog_show(LOG_REC *log, gpointer pmsgs, gpointer pfilepos)
else {
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_LOG_AWAY_MSGS, log->real_fname, msgs);
str = g_strdup_printf("\"%s\" %d", log->real_fname, filepos);
str = g_strdup_printf("\"%s\" %d", log->real_fname, filepos);
signal_emit("command cat", 1, str);
g_free(str);
}
@ -748,13 +749,13 @@ void fe_log_init(void)
utc = g_time_zone_new_utc();
settings_add_bool("log", "awaylog_colors", TRUE);
settings_add_bool("log", "autolog", FALSE);
settings_add_bool("log", "autolog", FALSE);
settings_add_bool("log", "autolog_colors", FALSE);
settings_add_bool("log", "autolog_only_saved_channels", FALSE);
settings_add_choice("log", "log_server_time", 2, "off;on;auto");
settings_add_str("log", "autolog_path", "~/irclogs/$tag/$0.log");
settings_add_level("log", "autolog_level", "all -crap -clientcrap -ctcps");
settings_add_str("log", "log_theme", "");
settings_add_str("log", "log_theme", "");
settings_add_str("log", "autolog_ignore_targets", "");
autolog_level = 0;