degesch: log outcoming CTCPs
This commit is contained in:
parent
2f6974c7ca
commit
6003cc7138
45
degesch.c
45
degesch.c
|
@ -2656,6 +2656,33 @@ ctime_now (char buf[26])
|
|||
return buf;
|
||||
}
|
||||
|
||||
static void irc_send_ctcp_reply (struct app_context *ctx, const char *recipient,
|
||||
const char *format, ...) ATTRIBUTE_PRINTF (3, 4);
|
||||
|
||||
static void
|
||||
irc_send_ctcp_reply (struct app_context *ctx,
|
||||
const char *recipient, const char *format, ...)
|
||||
{
|
||||
struct str m;
|
||||
str_init (&m);
|
||||
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
str_append_vprintf (&m, format, ap);
|
||||
va_end (ap);
|
||||
|
||||
irc_send (ctx, "NOTICE %s :\x01%s\x01", recipient, m.str);
|
||||
|
||||
char *text_utf8 = irc_to_utf8 (ctx, m.str);
|
||||
char *recipient_utf8 = irc_to_utf8 (ctx, recipient);
|
||||
str_free (&m);
|
||||
|
||||
buffer_send_status (ctx, ctx->server_buffer,
|
||||
"CTCP reply to %s: %s", recipient_utf8, text_utf8);
|
||||
free (text_utf8);
|
||||
free (recipient_utf8);
|
||||
}
|
||||
|
||||
static void
|
||||
irc_handle_ctcp_request (struct app_context *ctx,
|
||||
const struct irc_message *msg, struct ctcp_chunk *chunk)
|
||||
|
@ -2672,25 +2699,19 @@ irc_handle_ctcp_request (struct app_context *ctx,
|
|||
if (irc_is_channel (ctx, target))
|
||||
recipient = target;
|
||||
|
||||
// TODO: log a "CTCP reply to <recipient>: <whatever>
|
||||
// Probably abstract the irc_send call to something like
|
||||
// irc_send_ctcp_reply (ctx, recipient, fmt, ...)
|
||||
|
||||
if (!strcmp (chunk->tag.str, "CLIENTINFO"))
|
||||
irc_send (ctx, "NOTICE %s :\x01" "CLIENTINFO %s %s %s %s\x01",
|
||||
recipient, "PING", "VERSION", "TIME", "CLIENTINFO");
|
||||
irc_send_ctcp_reply (ctx, recipient, "CLIENTINFO %s %s %s %s",
|
||||
"PING", "VERSION", "TIME", "CLIENTINFO");
|
||||
else if (!strcmp (chunk->tag.str, "PING"))
|
||||
irc_send (ctx, "NOTICE %s :\x01" "PING %s\x01",
|
||||
recipient, chunk->text.str);
|
||||
irc_send_ctcp_reply (ctx, recipient, "PING %s", chunk->text.str);
|
||||
else if (!strcmp (chunk->tag.str, "VERSION"))
|
||||
{
|
||||
struct utsname info;
|
||||
if (uname (&info))
|
||||
LOG_LIBC_FAILURE ("uname");
|
||||
else
|
||||
irc_send (ctx, "NOTICE %s :\x01" "VERSION %s %s on %s %s\x01",
|
||||
recipient, PROGRAM_NAME, PROGRAM_VERSION,
|
||||
info.sysname, info.machine);
|
||||
irc_send_ctcp_reply (ctx, recipient, "VERSION %s %s on %s %s",
|
||||
PROGRAM_NAME, PROGRAM_VERSION, info.sysname, info.machine);
|
||||
}
|
||||
else if (!strcmp (chunk->tag.str, "TIME"))
|
||||
{
|
||||
|
@ -2698,7 +2719,7 @@ irc_handle_ctcp_request (struct app_context *ctx,
|
|||
if (!ctime_now (buf))
|
||||
LOG_LIBC_FAILURE ("asctime_r");
|
||||
else
|
||||
irc_send (ctx, "NOTICE %s :\x01" "TIME %s\x01", recipient, buf);
|
||||
irc_send_ctcp_reply (ctx, recipient, "TIME %s", buf);
|
||||
}
|
||||
|
||||
free (nickname);
|
||||
|
|
Loading…
Reference in New Issue