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

printtext(): you can now specify server target with tag name instead of

record. This is useful with DCC chats when you know the initial server tag
but the server might be already disconnected.

So what this means is that you now get ~/irclogs/ircnet/=nick.log instead of
~/irclogs/=nick.log :)


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2388 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2002-02-04 04:27:45 +00:00 committed by cras
parent 82b0c081e2
commit cf83236346
8 changed files with 118 additions and 56 deletions

View File

@ -257,11 +257,11 @@ LOG_ITEM_REC *log_item_find(LOG_REC *log, int type, const char *item,
return NULL;
}
void log_file_write(SERVER_REC *server, const char *item, int level,
void log_file_write(const char *server_tag, const char *item, int level,
const char *str, int no_fallbacks)
{
GSList *tmp, *fallbacks;
char *tmpstr, *servertag;
char *tmpstr;
int found;
g_return_if_fail(str != NULL);
@ -269,7 +269,6 @@ void log_file_write(SERVER_REC *server, const char *item, int level,
if (logs == NULL)
return;
servertag = server == NULL ? NULL : server->tag;
fallbacks = NULL; found = FALSE;
for (tmp = logs; tmp != NULL; tmp = tmp->next) {
@ -285,7 +284,7 @@ void log_file_write(SERVER_REC *server, const char *item, int level,
fallbacks = g_slist_append(fallbacks, rec);
else if (item != NULL &&
log_item_find(rec, LOG_ITEM_TARGET, item,
servertag) != NULL)
server_tag) != NULL)
log_write_rec(rec, str, level);
}

View File

@ -48,7 +48,7 @@ void log_item_destroy(LOG_REC *log, LOG_ITEM_REC *item);
LOG_ITEM_REC *log_item_find(LOG_REC *log, int type, const char *item,
const char *servertag);
void log_file_write(SERVER_REC *server, const char *item, int level,
void log_file_write(const char *server_tag, const char *item, int level,
const char *str, int no_fallbacks);
void log_write_rec(LOG_REC *log, const char *str, int level);

View File

@ -363,7 +363,8 @@ static void sig_server_disconnected(SERVER_REC *server)
logitem = log->items->data;
if (logitem->type == LOG_ITEM_TARGET &&
logitem->servertag != NULL &&
g_strcasecmp(logitem->servertag, server->tag) == 0)
g_strcasecmp(logitem->servertag, server->tag) == 0 &&
server_ischannel(server, logitem->name)) /* kludge again.. so we won't close dcc chats */
log_close(log);
}
}
@ -402,13 +403,13 @@ static char *escape_target(const char *target)
return str;
}
static void autolog_open(SERVER_REC *server, 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, *tag;
char *fname, *dir, *fixed_target;
tag = server == NULL ? NULL : server->tag;
log = logs_find_item(LOG_ITEM_TARGET, target, tag, NULL);
log = logs_find_item(LOG_ITEM_TARGET, target, server_tag, NULL);
if (log != NULL && !log->failed) {
log_start_logging(log);
return;
@ -430,7 +431,7 @@ static void autolog_open(SERVER_REC *server, const char *target)
log = log_create_rec(fname, autolog_level);
if (!settings_get_bool("autolog_colors"))
log->colorizer = log_colorizer_strip;
log_item_add(log, LOG_ITEM_TARGET, target, tag);
log_item_add(log, LOG_ITEM_TARGET, target, server_tag);
dir = g_dirname(log->real_fname);
mkpath(dir, LOG_DIR_CREATE_MODE);
@ -443,23 +444,27 @@ static void autolog_open(SERVER_REC *server, const char *target)
g_free(fname);
}
static void autolog_open_check(SERVER_REC *server, const char *target,
int level)
static void autolog_open_check(SERVER_REC *server, const char *server_tag,
const char *target, int level)
{
char **targets, **tmp;
if (level == MSGLEVEL_PARTS || /* FIXME: kind of a kludge, but we don't want to reopen logs when we're parting the channel with /WINDOW CLOSE.. */
/* FIXME: kind of a kludge, but we don't want to reopen logs when
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')
return;
/* there can be multiple targets separated with comma */
targets = g_strsplit(target, ",", -1);
for (tmp = targets; *tmp != NULL; tmp++)
autolog_open(server, *tmp);
autolog_open(server, server_tag, *tmp);
g_strfreev(targets);
}
static void log_single_line(WINDOW_REC *window, void *server,
static void log_single_line(WINDOW_REC *window, const char *server_tag,
const char *target, int level, const char *text)
{
char windownum[MAX_INT_STRLEN];
@ -475,26 +480,26 @@ static void log_single_line(WINDOW_REC *window, void *server,
}
if (target == NULL)
log_file_write(server, NULL, level, text, FALSE);
log_file_write(server_tag, NULL, level, text, FALSE);
else {
/* there can be multiple items separated with comma */
targets = g_strsplit(target, ",", -1);
for (tmp = targets; *tmp != NULL; tmp++)
log_file_write(server, *tmp, level, text, FALSE);
log_file_write(server_tag, *tmp, level, text, FALSE);
g_strfreev(targets);
}
}
static void log_line(WINDOW_REC *window, SERVER_REC *server,
const char *target, int level, const char *text)
static void log_line(TEXT_DEST_REC *dest, const char *text)
{
char **lines, **tmp;
if (level == MSGLEVEL_NEVER)
if (dest->level == MSGLEVEL_NEVER)
return;
/* let autolog open the log records */
autolog_open_check(server, target, level);
autolog_open_check(dest->server, dest->server_tag,
dest->target, dest->level);
if (logs == NULL)
return;
@ -503,7 +508,8 @@ static void log_line(WINDOW_REC *window, SERVER_REC *server,
line at a time */
lines = g_strsplit(text, "\n", -1);
for (tmp = lines; *tmp != NULL; tmp++)
log_single_line(window, server, target, level, *tmp);
log_single_line(dest->window, dest->server_tag,
dest->target, dest->level, *tmp);
g_strfreev(lines);
}
@ -515,8 +521,7 @@ static void sig_printtext(TEXT_DEST_REC *dest, const char *text,
return;
}
log_line(dest->window, dest->server, dest->target,
dest->level, text);
log_line(dest, text);
}
static void sig_print_format(THEME_REC *theme, const char *module,
@ -547,8 +552,7 @@ static void sig_print_format(THEME_REC *theme, const char *module,
g_free(tmp);
/* strip colors from text, log it. */
log_line(dest->window, dest->server, dest->target,
dest->level, str);
log_line(dest, str);
}
g_free(str);

View File

@ -277,10 +277,18 @@ void format_read_arglist(va_list va, FORMAT_REC *format,
void format_create_dest(TEXT_DEST_REC *dest,
void *server, const char *target,
int level, WINDOW_REC *window)
{
format_create_dest_tag(dest, server, NULL, target, level, window);
}
void format_create_dest_tag(TEXT_DEST_REC *dest, void *server,
const char *server_tag, const char *target,
int level, WINDOW_REC *window)
{
memset(dest, 0, sizeof(TEXT_DEST_REC));
dest->server = server;
dest->server_tag = server != NULL ? SERVER(server)->tag : server_tag;
dest->target = target;
dest->level = level;
dest->window = window != NULL ? window :
@ -611,12 +619,9 @@ static char *get_timestamp(THEME_REC *theme, TEXT_DEST_REC *dest, time_t t)
static char *get_server_tag(THEME_REC *theme, TEXT_DEST_REC *dest)
{
SERVER_REC *server;
int count = 0;
server = dest->server;
if (server == NULL || hide_server_tags)
if (dest->server_tag == NULL || hide_server_tags)
return NULL;
/* check for flags if we want to override defaults */
@ -625,7 +630,7 @@ static char *get_server_tag(THEME_REC *theme, TEXT_DEST_REC *dest)
if ((dest->flags & PRINT_FLAG_SET_SERVERTAG) == 0) {
if (dest->window->active != NULL &&
dest->window->active->server == server)
dest->window->active->server == dest->server)
return NULL;
if (servers != NULL) {
@ -644,7 +649,7 @@ static char *get_server_tag(THEME_REC *theme, TEXT_DEST_REC *dest)
}
return format_get_text_theme(theme, MODULE_NAME, dest,
TXT_SERVERTAG, server->tag);
TXT_SERVERTAG, dest->server_tag);
}
char *format_get_line_start(THEME_REC *theme, TEXT_DEST_REC *dest, time_t t)

View File

@ -45,6 +45,7 @@ struct _FORMAT_REC {
typedef struct {
WINDOW_REC *window;
SERVER_REC *server;
const char *server_tag; /* if server is non-NULL, must be server->tag */
const char *target;
int level;
@ -100,6 +101,9 @@ char *format_get_line_start(THEME_REC *theme, TEXT_DEST_REC *dest, time_t t);
void format_create_dest(TEXT_DEST_REC *dest,
void *server, const char *target,
int level, WINDOW_REC *window);
void format_create_dest_tag(TEXT_DEST_REC *dest, void *server,
const char *server_tag, const char *target,
int level, WINDOW_REC *window);
void format_newline(WINDOW_REC *window);

View File

@ -43,8 +43,8 @@ static int sending_print_starting;
static void print_line(TEXT_DEST_REC *dest, const char *text);
static void printformat_module_dest(const char *module, TEXT_DEST_REC *dest,
int formatnum, va_list va)
void printformat_module_dest_args(const char *module, TEXT_DEST_REC *dest,
int formatnum, va_list va)
{
char *arglist[MAX_FORMAT_PARAMS];
char buffer[DEFAULT_FORMAT_ARGLIST_SIZE];
@ -74,6 +74,16 @@ static void printformat_module_dest(const char *module, TEXT_DEST_REC *dest,
g_free(str);
}
void printformat_module_dest(const char *module, TEXT_DEST_REC *dest,
int formatnum, ...)
{
va_list va;
va_start(va, formatnum);
printformat_module_dest_args(module, dest, formatnum, va);
va_end(va);
}
void printformat_module_args(const char *module, void *server,
const char *target, int level,
int formatnum, va_list va)
@ -81,7 +91,7 @@ void printformat_module_args(const char *module, void *server,
TEXT_DEST_REC dest;
format_create_dest(&dest, server, target, level, NULL);
printformat_module_dest(module, &dest, formatnum, va);
printformat_module_dest_args(module, &dest, formatnum, va);
}
void printformat_module(const char *module, void *server, const char *target,
@ -100,7 +110,7 @@ void printformat_module_window_args(const char *module, WINDOW_REC *window,
TEXT_DEST_REC dest;
format_create_dest(&dest, NULL, NULL, level, window);
printformat_module_dest(module, &dest, formatnum, va);
printformat_module_dest_args(module, &dest, formatnum, va);
}
void printformat_module_window(const char *module, WINDOW_REC *window,

View File

@ -6,9 +6,11 @@
void printformat_module(const char *module, void *server, const char *target, int level, int formatnum, ...);
void printformat_module_window(const char *module, WINDOW_REC *window, int level, int formatnum, ...);
void printformat_module_dest(const char *module, TEXT_DEST_REC *dest, int formatnum, ...);
void printformat_module_args(const char *module, void *server, const char *target, int level, int formatnum, va_list va);
void printformat_module_window_args(const char *module, WINDOW_REC *window, int level, int formatnum, va_list va);
void printformat_module_dest_args(const char *module, TEXT_DEST_REC *dest, int formatnum, va_list va);
void printtext(void *server, const char *target, int level, const char *text, ...);
void printtext_string(void *server, const char *target, int level, const char *text);
@ -38,6 +40,8 @@ void printtext_deinit(void);
printformat_module(MODULE_NAME, server, target, level, ##formatnum)
# define printformat_window(window, level, formatnum...) \
printformat_module_window(MODULE_NAME, window, level, ##formatnum)
# define printformat_dest(dest, formatnum...) \
printformat_module_dest(MODULE_NAME, dest, ##formatnum)
# define printformat_gui(formatnum...) \
printformat_module_gui(MODULE_NAME, ##formatnum)
#elif defined (_ISOC99_SOURCE)
@ -46,6 +50,8 @@ void printtext_deinit(void);
printformat_module(MODULE_NAME, server, target, level, formatnum, __VA_ARGS__)
# define printformat_window(window, level, formatnum, ...) \
printformat_module_window(MODULE_NAME, window, level, formatnum, __VA_ARGS__)
# define printformat_dest(dest, formatnum, ...) \
printformat_module_dest(MODULE_NAME, dest, formatnum, __VA_ARGS__)
# define printformat_gui(formatnum, ...) \
printformat_module_gui(MODULE_NAME, formatnum, __VA_ARGS__)
#else
@ -78,6 +84,20 @@ void printformat_window(WINDOW_REC *window, int level, int formatnum, ...)
va_end(va);
}
#ifdef G_CAN_INLINE
G_INLINE_FUNC
#else
static
#endif
void printformat_dest(TEXT_DEST_REC *dest, int formatnum, ...)
{
va_list va;
va_start(va, formatnum);
printformat_module_dest_args(MODULE_NAME, dest, formatnum, va);
va_end(va);
}
#ifdef G_CAN_INLINE
G_INLINE_FUNC
#else

View File

@ -30,80 +30,100 @@
static void sig_message_dcc_own(CHAT_DCC_REC *dcc, const char *msg)
{
TEXT_DEST_REC dest;
QUERY_REC *query;
char *tag;
tag = g_strconcat("=", dcc->id, NULL);
query = query_find(NULL, tag);
printformat(NULL, tag, MSGLEVEL_DCCMSGS | MSGLEVEL_NOHILIGHT,
query != NULL ? IRCTXT_OWN_DCC_QUERY :
IRCTXT_OWN_DCC, dcc->mynick, dcc->id, msg);
format_create_dest_tag(&dest, dcc->server, dcc->servertag, tag,
MSGLEVEL_DCCMSGS | MSGLEVEL_NOHILIGHT, NULL);
printformat_dest(&dest, query != NULL ? IRCTXT_OWN_DCC_QUERY :
IRCTXT_OWN_DCC, dcc->mynick, dcc->id, msg);
g_free(tag);
}
static void sig_message_dcc_own_action(CHAT_DCC_REC *dcc, const char *msg)
{
TEXT_DEST_REC dest;
QUERY_REC *query;
char *tag;
tag = g_strconcat("=", dcc->id, NULL);
query = query_find(NULL, tag);
printformat(NULL, tag, MSGLEVEL_DCCMSGS | MSGLEVEL_NOHILIGHT,
query != NULL ? IRCTXT_OWN_DCC_ACTION_QUERY :
IRCTXT_OWN_DCC_ACTION, dcc->mynick, dcc->id, msg);
format_create_dest_tag(&dest, dcc->server, dcc->servertag, tag,
MSGLEVEL_DCCMSGS | MSGLEVEL_ACTIONS |
MSGLEVEL_NOHILIGHT, NULL);
printformat_dest(&dest, query != NULL ? IRCTXT_OWN_DCC_ACTION_QUERY :
IRCTXT_OWN_DCC_ACTION, dcc->mynick, dcc->id, msg);
g_free(tag);
}
static void sig_message_dcc_own_ctcp(CHAT_DCC_REC *dcc, const char *cmd,
const char *data)
{
TEXT_DEST_REC dest;
char *tag;
tag = g_strconcat("=", dcc->id, NULL);
printformat(NULL, tag, MSGLEVEL_DCC, IRCTXT_OWN_DCC_CTCP,
dcc->id, cmd, data);
format_create_dest_tag(&dest, dcc->server, dcc->servertag, tag,
MSGLEVEL_DCC | MSGLEVEL_CTCPS, NULL);
printformat_dest(&dest, IRCTXT_OWN_DCC_CTCP, dcc->id, cmd, data);
g_free(tag);
}
static void sig_message_dcc(CHAT_DCC_REC *dcc, const char *msg)
{
TEXT_DEST_REC dest;
QUERY_REC *query;
char *tag;
tag = g_strconcat("=", dcc->id, NULL);
query = query_find(NULL, tag);
printformat(NULL, tag, MSGLEVEL_DCCMSGS,
query != NULL ? IRCTXT_DCC_MSG_QUERY : IRCTXT_DCC_MSG,
dcc->id, msg);
format_create_dest_tag(&dest, dcc->server, dcc->servertag, tag,
MSGLEVEL_DCCMSGS, NULL);
printformat_dest(&dest, query != NULL ? IRCTXT_DCC_MSG_QUERY :
IRCTXT_DCC_MSG, dcc->id, msg);
g_free(tag);
}
static void sig_message_dcc_action(CHAT_DCC_REC *dcc, const char *msg)
{
TEXT_DEST_REC dest;
QUERY_REC *query;
char *tag;
tag = g_strconcat("=", dcc->id, NULL);
query = query_find(NULL, tag);
printformat(NULL, tag, MSGLEVEL_DCCMSGS | MSGLEVEL_ACTIONS,
query != NULL ? IRCTXT_ACTION_DCC_QUERY :
IRCTXT_ACTION_DCC, dcc->id, msg);
g_free(tag);
format_create_dest_tag(&dest, dcc->server, dcc->servertag, tag,
MSGLEVEL_DCCMSGS | MSGLEVEL_ACTIONS, NULL);
printformat_dest(&dest, query != NULL ? IRCTXT_ACTION_DCC_QUERY :
IRCTXT_ACTION_DCC, dcc->id, msg);
g_free(tag);
}
static void sig_message_dcc_ctcp(CHAT_DCC_REC *dcc, const char *cmd,
const char *data)
{
TEXT_DEST_REC dest;
char *tag;
tag = g_strconcat("=", dcc->id, NULL);
printformat(NULL, tag, MSGLEVEL_DCC, IRCTXT_DCC_CTCP,
dcc->id, cmd, data);
format_create_dest_tag(&dest, dcc->server, dcc->servertag, tag,
MSGLEVEL_DCC | MSGLEVEL_CTCPS, NULL);
printformat_dest(&dest, IRCTXT_DCC_CTCP, dcc->id, cmd, data);
g_free(tag);
}