1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

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

Check window logfile parameter

(cherry picked from commit 6f5026fd49)
This commit is contained in:
ailin-nemui 2022-12-23 10:34:56 +01:00 committed by Ailin Nemui
parent f422b98613
commit 473cf8ca3f

View File

@ -91,10 +91,10 @@ static void cmd_log_open(const char *data)
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);
@ -112,8 +112,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')
@ -133,8 +132,7 @@ 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);
}
@ -231,12 +229,10 @@ 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" : "",
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);
@ -253,8 +249,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;
@ -331,21 +327,34 @@ static void cmd_window_logfile(const char *data)
{
LOG_REC *log;
char window[MAX_INT_STRLEN];
void *free_arg;
char *fname;
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 */
@ -379,10 +388,10 @@ static void sig_server_disconnected(SERVER_REC *server)
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);
}
}
@ -421,8 +430,7 @@ static char *escape_target(const char *target)
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;
@ -447,8 +455,7 @@ static void autolog_open(SERVER_REC *server, const char *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) {
@ -484,8 +491,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";
@ -495,8 +502,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)
@ -512,8 +518,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);
}
@ -553,8 +558,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;
@ -564,8 +568,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;
@ -579,8 +583,8 @@ 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;
@ -620,8 +624,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;
@ -632,23 +636,20 @@ 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)