From 1dd464f35c2de2379e971c0f4816549ef828cd0b Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Thu, 6 Aug 2015 23:00:16 +0200
Subject: degesch; fix handling of CTCP requests
---
degesch.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/degesch.c b/degesch.c
index 2146005..299ef86 100644
--- a/degesch.c
+++ b/degesch.c
@@ -5471,27 +5471,31 @@ irc_handle_ctcp_request (struct server *s,
{
const char *target = msg->params.vector[0];
if (irc_is_this_us (s, msg->prefix))
- log_ctcp_query (s, target, chunk->tag.str);
+ {
+ if (s->cap_echo_message)
+ log_ctcp_query (s, target, chunk->tag.str);
+ if (!irc_is_this_us (s, target))
+ return;
+ }
+ // TODO: eventually "requested by #n (to ##channel)"
log_server_status (s, s->buffer,
"CTCP requested by #n: #S", msg->prefix, chunk->tag.str);
- char *recipient = irc_is_channel (s, target)
- ? irc_cut_nickname (msg->prefix)
- : xstrdup (target);
+ char *nickname = irc_cut_nickname (msg->prefix);
if (!strcmp (chunk->tag.str, "CLIENTINFO"))
- irc_send_ctcp_reply (s, recipient, "CLIENTINFO %s %s %s %s",
+ irc_send_ctcp_reply (s, nickname, "CLIENTINFO %s %s %s %s",
"PING", "VERSION", "TIME", "CLIENTINFO");
else if (!strcmp (chunk->tag.str, "PING"))
- irc_send_ctcp_reply (s, recipient, "PING %s", chunk->text.str);
+ irc_send_ctcp_reply (s, nickname, "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_ctcp_reply (s, recipient, "VERSION %s %s on %s %s",
+ irc_send_ctcp_reply (s, nickname, "VERSION %s %s on %s %s",
PROGRAM_NAME, PROGRAM_VERSION, info.sysname, info.machine);
}
else if (!strcmp (chunk->tag.str, "TIME"))
@@ -5500,10 +5504,10 @@ irc_handle_ctcp_request (struct server *s,
if (!ctime_now (buf))
LOG_LIBC_FAILURE ("asctime_r");
else
- irc_send_ctcp_reply (s, recipient, "TIME %s", buf);
+ irc_send_ctcp_reply (s, nickname, "TIME %s", buf);
}
- free (recipient);
+ free (nickname);
}
static void
--
cgit v1.2.3-70-g09d2