1
0
mirror of https://github.com/irssi/irssi.git synced 2024-06-30 06:45:25 +00: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

@ -92,10 +92,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);
@ -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,8 +133,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);
}
@ -232,12 +230,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);
@ -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;
@ -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;
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 */
@ -380,10 +389,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);
}
}
@ -422,8 +431,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;
@ -448,8 +456,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) {
@ -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,8 +584,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;
@ -606,7 +610,7 @@ 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;
@ -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,23 +637,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)