summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xC.c131
1 files changed, 74 insertions, 57 deletions
diff --git a/xC.c b/xC.c
index 1574cfb..e5ce465 100644
--- a/xC.c
+++ b/xC.c
@@ -1521,19 +1521,27 @@ formatter_free (struct formatter *self)
enum buffer_line_flags
{
- BUFFER_LINE_STATUS = 1 << 0, ///< Status message
- BUFFER_LINE_ERROR = 1 << 1, ///< Error message
+ BUFFER_LINE_SKIP_FILE = 1 << 0, ///< Don't log this to file
+ BUFFER_LINE_UNIMPORTANT = 1 << 1, ///< Joins, parts, similar spam
BUFFER_LINE_HIGHLIGHT = 1 << 2, ///< The user was highlighted by this
- BUFFER_LINE_SKIP_FILE = 1 << 3, ///< Don't log this to file
- BUFFER_LINE_INDENT = 1 << 4, ///< Just indent the line
- BUFFER_LINE_UNIMPORTANT = 1 << 5 ///< Joins, parts, similar spam
+};
+
+enum buffer_line_rendition
+{
+ BUFFER_LINE_BARE, ///< Unadorned
+ BUFFER_LINE_INDENT, ///< Just indent the line
+ BUFFER_LINE_STATUS, ///< Status message
+ BUFFER_LINE_ERROR, ///< Error message
+ BUFFER_LINE_JOIN, ///< Join arrow
+ BUFFER_LINE_PART, ///< Part arrow
};
struct buffer_line
{
LIST_HEADER (struct buffer_line)
- int flags; ///< Flags
+ unsigned flags; ///< Functional flags
+ enum buffer_line_rendition r; ///< What the line should look like
time_t when; ///< Time of the event
struct formatter_item items[]; ///< Line data
};
@@ -3966,10 +3974,15 @@ static void
buffer_line_flush (struct buffer_line *line, struct formatter *f, FILE *output,
int flush_opts)
{
- int flags = line->flags;
- if (flags & BUFFER_LINE_INDENT) formatter_add (f, " ");
- if (flags & BUFFER_LINE_STATUS) formatter_add (f, " - ");
- if (flags & BUFFER_LINE_ERROR) formatter_add (f, "#a=!=#r ", ATTR_ERROR);
+ switch (line->r)
+ {
+ case BUFFER_LINE_BARE: break;
+ case BUFFER_LINE_INDENT: formatter_add (f, " "); break;
+ case BUFFER_LINE_STATUS: formatter_add (f, " - "); break;
+ case BUFFER_LINE_ERROR: formatter_add (f, "#a=!=#r ", ATTR_ERROR); break;
+ case BUFFER_LINE_JOIN: formatter_add (f, "#a-->#r ", ATTR_JOIN); break;
+ case BUFFER_LINE_PART: formatter_add (f, "#a<--#r ", ATTR_PART); break;
+ }
for (struct formatter_item *iter = line->items; iter->type; iter++)
formatter_add_item (f, *iter);
@@ -4057,14 +4070,15 @@ buffer_line_write_to_log (struct app_context *ctx,
}
static void
-log_formatter (struct app_context *ctx,
- struct buffer *buffer, int flags, struct formatter *f)
+log_formatter (struct app_context *ctx, struct buffer *buffer,
+ unsigned flags, enum buffer_line_rendition r, struct formatter *f)
{
if (!buffer)
buffer = ctx->global_buffer;
struct buffer_line *line = buffer_line_new (f);
line->flags = flags;
+ line->r = r;
// TODO: allow providing custom time (IRCv3.2 server-time)
line->when = time (NULL);
@@ -4117,45 +4131,45 @@ log_formatter (struct app_context *ctx,
static void
log_full (struct app_context *ctx, struct server *s, struct buffer *buffer,
- int flags, const char *format, ...)
+ unsigned flags, enum buffer_line_rendition r, const char *format, ...)
{
va_list ap;
va_start (ap, format);
struct formatter f = formatter_make (ctx, s);
formatter_addv (&f, format, &ap);
- log_formatter (ctx, buffer, flags, &f);
+ log_formatter (ctx, buffer, flags, r, &f);
va_end (ap);
}
-#define log_global(ctx, flags, ...) \
- log_full ((ctx), NULL, (ctx)->global_buffer, flags, __VA_ARGS__)
-#define log_server(s, buffer, flags, ...) \
- log_full ((s)->ctx, s, (buffer), flags, __VA_ARGS__)
+#define log_global(ctx, flags, r, ...) \
+ log_full ((ctx), NULL, (ctx)->global_buffer, (flags), (r), __VA_ARGS__)
+#define log_server(s, buffer, flags, r, ...) \
+ log_full ((s)->ctx, (s), (buffer), (flags), (r), __VA_ARGS__)
#define log_global_status(ctx, ...) \
- log_global ((ctx), BUFFER_LINE_STATUS, __VA_ARGS__)
+ log_global ((ctx), 0, BUFFER_LINE_STATUS, __VA_ARGS__)
#define log_global_error(ctx, ...) \
- log_global ((ctx), BUFFER_LINE_ERROR, __VA_ARGS__)
+ log_global ((ctx), 0, BUFFER_LINE_ERROR, __VA_ARGS__)
#define log_global_indent(ctx, ...) \
- log_global ((ctx), BUFFER_LINE_INDENT, __VA_ARGS__)
+ log_global ((ctx), 0, BUFFER_LINE_INDENT, __VA_ARGS__)
#define log_server_status(s, buffer, ...) \
- log_server ((s), (buffer), BUFFER_LINE_STATUS, __VA_ARGS__)
+ log_server ((s), (buffer), 0, BUFFER_LINE_STATUS, __VA_ARGS__)
#define log_server_error(s, buffer, ...) \
- log_server ((s), (buffer), BUFFER_LINE_ERROR, __VA_ARGS__)
+ log_server ((s), (buffer), 0, BUFFER_LINE_ERROR, __VA_ARGS__)
#define log_global_debug(ctx, ...) \
BLOCK_START \
if (g_debug_mode) \
- log_global ((ctx), 0, "(*) " __VA_ARGS__); \
+ log_global ((ctx), 0, 0, "(*) " __VA_ARGS__); \
BLOCK_END
#define log_server_debug(s, ...) \
BLOCK_START \
if (g_debug_mode) \
- log_server ((s), (s)->buffer, 0, "(*) " __VA_ARGS__); \
+ log_server ((s), (s)->buffer, 0, 0, "(*) " __VA_ARGS__); \
BLOCK_END
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -4163,25 +4177,26 @@ log_full (struct app_context *ctx, struct server *s, struct buffer *buffer,
// Lines that are used in more than one place
#define log_nick_self(s, buffer, new_) \
- log_server ((s), (buffer), BUFFER_LINE_STATUS | BUFFER_LINE_UNIMPORTANT, \
+ log_server ((s), (buffer), BUFFER_LINE_UNIMPORTANT, BUFFER_LINE_STATUS, \
"You are now known as #n", (new_))
#define log_nick(s, buffer, old, new_) \
- log_server ((s), (buffer), BUFFER_LINE_STATUS | BUFFER_LINE_UNIMPORTANT, \
+ log_server ((s), (buffer), BUFFER_LINE_UNIMPORTANT, BUFFER_LINE_STATUS, \
"#n is now known as #n", (old), (new_))
#define log_chghost_self(s, buffer, new_) \
- log_server ((s), (buffer), BUFFER_LINE_STATUS | BUFFER_LINE_UNIMPORTANT, \
+ log_server ((s), (buffer), BUFFER_LINE_UNIMPORTANT, BUFFER_LINE_STATUS, \
"You are now #N", (new_))
#define log_chghost(s, buffer, old, new_) \
- log_server ((s), (buffer), BUFFER_LINE_STATUS | BUFFER_LINE_UNIMPORTANT, \
+ log_server ((s), (buffer), BUFFER_LINE_UNIMPORTANT, BUFFER_LINE_STATUS, \
"#N is now #N", (old), (new_))
#define log_outcoming_notice(s, buffer, who, text) \
log_server_status ((s), (buffer), "#s(#n): #m", "Notice", (who), (text))
#define log_outcoming_privmsg(s, buffer, prefixes, who, text) \
- log_server ((s), (buffer), 0, "<#s#n> #m", (prefixes), (who), (text))
+ log_server ((s), (buffer), 0, 0, "<#s#n> #m", (prefixes), (who), (text))
#define log_outcoming_action(s, buffer, who, text) \
- log_server ((s), (buffer), 0, " #a*#r #n #m", ATTR_ACTION, (who), (text))
+ log_server ((s), (buffer), 0, 0, " #a*#r #n #m", \
+ ATTR_ACTION, (who), (text))
#define log_outcoming_orphan_notice(s, target, text) \
log_server_status ((s), (s)->buffer, "Notice -> #n: #m", (target), (text))
@@ -4450,7 +4465,7 @@ buffer_merge (struct app_context *ctx,
{
// XXX: anything better to do? This situation is arguably rare and I'm
// not entirely sure what action to take.
- log_full (ctx, NULL, buffer, BUFFER_LINE_STATUS,
+ log_full (ctx, NULL, buffer, 0, BUFFER_LINE_STATUS,
"Buffer #s was merged into this buffer", merged->name);
// Find all lines from "merged" newer than the newest line in "buffer"
@@ -4481,7 +4496,7 @@ buffer_merge (struct app_context *ctx,
buffer->lines_tail = tail;
buffer->lines_count += n;
- log_full (ctx, NULL, buffer, BUFFER_LINE_STATUS | BUFFER_LINE_SKIP_FILE,
+ log_full (ctx, NULL, buffer, BUFFER_LINE_SKIP_FILE, BUFFER_LINE_STATUS,
"End of merged content");
}
@@ -5148,7 +5163,7 @@ irc_disconnect (struct server *s)
struct str_map_iter iter = str_map_iter_make (&s->irc_buffer_map);
struct buffer *buffer;
while ((buffer = str_map_iter_next (&iter)))
- log_server (s, buffer, BUFFER_LINE_STATUS | BUFFER_LINE_UNIMPORTANT,
+ log_server (s, buffer, BUFFER_LINE_UNIMPORTANT, BUFFER_LINE_STATUS,
"Disconnected from server");
irc_cancel_timers (s);
@@ -6977,8 +6992,8 @@ irc_handle_join (struct server *s, const struct irc_message *msg)
// Finally log the message
if (buffer)
{
- log_server (s, buffer, BUFFER_LINE_UNIMPORTANT, "#a-->#r #N #a#s#r #S",
- ATTR_JOIN, msg->prefix, ATTR_JOIN, "has joined", channel_name);
+ log_server (s, buffer, BUFFER_LINE_UNIMPORTANT, BUFFER_LINE_JOIN,
+ "#N #a#s#r #S", msg->prefix, ATTR_JOIN, "has joined", channel_name);
}
}
@@ -7015,11 +7030,11 @@ irc_handle_kick (struct server *s, const struct irc_message *msg)
if (buffer)
{
struct formatter f = formatter_make (s->ctx, s);
- formatter_add (&f, "#a<--#r #N #a#s#r #n",
- ATTR_PART, msg->prefix, ATTR_PART, "has kicked", target);
+ formatter_add (&f, "#N #a#s#r #n",
+ msg->prefix, ATTR_PART, "has kicked", target);
if (message)
formatter_add (&f, " (#m)", message);
- log_formatter (s->ctx, buffer, 0, &f);
+ log_formatter (s->ctx, buffer, 0, BUFFER_LINE_PART, &f);
}
}
@@ -7066,7 +7081,7 @@ irc_handle_mode (struct server *s, const struct irc_message *msg)
if (buffer)
{
- log_server (s, buffer, BUFFER_LINE_STATUS | flags,
+ log_server (s, buffer, flags, BUFFER_LINE_STATUS,
"Mode #S [#S] by #n", context, modes, msg->prefix);
}
}
@@ -7222,7 +7237,7 @@ irc_handle_notice_text (struct server *s,
char *nick = irc_cut_nickname (msg->prefix);
// IRCv3.2 echo-message could otherwise cause us to highlight ourselves
if (!irc_is_this_us (s, msg->prefix) && irc_is_highlight (s, text->str))
- log_server (s, buffer, BUFFER_LINE_STATUS | BUFFER_LINE_HIGHLIGHT,
+ log_server (s, buffer, BUFFER_LINE_HIGHLIGHT, BUFFER_LINE_STATUS,
"#a#s(#S)#r: #m", ATTR_HIGHLIGHT, "Notice", nick, text->str);
else
log_outcoming_notice (s, buffer, msg->prefix, text->str);
@@ -7279,11 +7294,12 @@ irc_handle_part (struct server *s, const struct irc_message *msg)
if (buffer)
{
struct formatter f = formatter_make (s->ctx, s);
- formatter_add (&f, "#a<--#r #N #a#s#r #S",
- ATTR_PART, msg->prefix, ATTR_PART, "has left", channel_name);
+ formatter_add (&f, "#N #a#s#r #S",
+ msg->prefix, ATTR_PART, "has left", channel_name);
if (message)
formatter_add (&f, " (#m)", message);
- log_formatter (s->ctx, buffer, BUFFER_LINE_UNIMPORTANT, &f);
+ log_formatter (s->ctx, buffer,
+ BUFFER_LINE_UNIMPORTANT, BUFFER_LINE_PART, &f);
}
}
@@ -7345,7 +7361,7 @@ irc_handle_ctcp_request (struct server *s,
if (irc_is_channel (s, irc_skip_statusmsg (s, target)))
formatter_add (&f, " (to #S)", target);
formatter_add (&f, ": #S", chunk->tag.str);
- log_formatter (s->ctx, s->buffer, BUFFER_LINE_STATUS, &f);
+ log_formatter (s->ctx, s->buffer, 0, BUFFER_LINE_STATUS, &f);
char *nickname = irc_cut_nickname (msg->prefix);
@@ -7413,10 +7429,10 @@ irc_handle_privmsg_text (struct server *s,
log_outcoming_privmsg (s, buffer, prefixes, nickname, text->str);
}
else if (is_action)
- log_server (s, buffer, BUFFER_LINE_HIGHLIGHT,
+ log_server (s, buffer, BUFFER_LINE_HIGHLIGHT, 0,
" #a*#r #n #m", ATTR_HIGHLIGHT, msg->prefix, text->str);
else
- log_server (s, buffer, BUFFER_LINE_HIGHLIGHT,
+ log_server (s, buffer, BUFFER_LINE_HIGHLIGHT, 0,
"#a<#S#S>#r #m", ATTR_HIGHLIGHT, prefixes, nickname, text->str);
free (nickname);
@@ -7446,11 +7462,11 @@ log_quit (struct server *s,
struct buffer *buffer, const char *prefix, const char *reason)
{
struct formatter f = formatter_make (s->ctx, s);
- formatter_add (&f, "#a<--#r #N #a#s#r",
- ATTR_PART, prefix, ATTR_PART, "has quit");
+ formatter_add (&f, "#N #a#s#r", prefix, ATTR_PART, "has quit");
if (reason)
formatter_add (&f, " (#m)", reason);
- log_formatter (s->ctx, buffer, BUFFER_LINE_UNIMPORTANT, &f);
+ log_formatter (s->ctx, buffer,
+ BUFFER_LINE_UNIMPORTANT, BUFFER_LINE_PART, &f);
}
static void
@@ -7526,7 +7542,7 @@ irc_handle_topic (struct server *s, const struct irc_message *msg)
if (buffer)
{
- log_server (s, buffer, BUFFER_LINE_STATUS, "#n #s \"#m\"",
+ log_server (s, buffer, 0, BUFFER_LINE_STATUS, "#n #s \"#m\"",
msg->prefix, "has changed the topic to", topic);
}
}
@@ -7538,7 +7554,7 @@ irc_handle_wallops (struct server *s, const struct irc_message *msg)
return;
const char *message = msg->params.vector[0];
- log_server (s, s->buffer, 0, "<#n> #m", msg->prefix, message);
+ log_server (s, s->buffer, 0, 0, "<#n> #m", msg->prefix, message);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -8224,7 +8240,7 @@ irc_process_numeric (struct server *s,
strv_append_vector (&copy, msg->params.vector + !!msg->params.len);
struct buffer *buffer = s->buffer;
- int flags = BUFFER_LINE_STATUS;
+ int flags = 0;
switch (numeric)
{
case IRC_RPL_WELCOME:
@@ -8310,7 +8326,8 @@ irc_process_numeric (struct server *s,
if (buffer)
{
// Join the parameter vector back and send it to the server buffer
- log_server (s, buffer, flags, "#&m", strv_join (&copy, " "));
+ log_server (s, buffer, flags, BUFFER_LINE_STATUS,
+ "#&m", strv_join (&copy, " "));
}
strv_free (&copy);
@@ -9220,7 +9237,7 @@ lua_buffer_log (lua_State *L)
struct buffer *buffer = wrapper->object;
const char *message = lua_plugin_check_utf8 (L, 2);
log_full (wrapper->plugin->ctx, buffer->server, buffer,
- BUFFER_LINE_STATUS, "#s", message);
+ 0, BUFFER_LINE_STATUS, "#s", message);
return 0;
}
@@ -12627,7 +12644,7 @@ send_message_to_buffer (struct app_context *ctx, struct buffer *buffer,
buffer->user->nickname, message, buffer);
break;
default:
- log_full (ctx, NULL, buffer, BUFFER_LINE_ERROR,
+ log_full (ctx, NULL, buffer, 0, BUFFER_LINE_ERROR,
"This buffer is not a channel");
}
}
@@ -14491,7 +14508,7 @@ on_flush_timer (struct app_context *ctx)
// Might be a transient error such as running out of disk space,
// keep notifying of the problem until it disappears
clearerr (buffer->log_file);
- log_global (ctx, BUFFER_LINE_ERROR | BUFFER_LINE_SKIP_FILE,
+ log_global (ctx, BUFFER_LINE_SKIP_FILE, BUFFER_LINE_ERROR,
"Log write failure detected for #s", buffer->name);
}