aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-06-28 16:57:08 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-06-28 17:08:42 +0200
commitdb6939bd6085d9eef1a58e963f44c8b618d38030 (patch)
treea5e89b172968882fadf4533159653d09a2cbd62d
parenta1fa9d187eda5214bfdb0b478390a07654f2bcda (diff)
downloadxK-db6939bd6085d9eef1a58e963f44c8b618d38030.tar.gz
xK-db6939bd6085d9eef1a58e963f44c8b618d38030.tar.xz
xK-db6939bd6085d9eef1a58e963f44c8b618d38030.zip
degesch: fix /ctcp with CAP echo-message
-rw-r--r--degesch.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/degesch.c b/degesch.c
index c1eebca..69fb927 100644
--- a/degesch.c
+++ b/degesch.c
@@ -2554,6 +2554,11 @@ log_full (struct app_context *ctx, struct server *s, struct buffer *buffer,
#define log_outcoming_action(s, buffer, who, text) \
log_server ((s), (buffer), 0, " #a*#r #n #m", ATTR_ACTION, (who), (text))
+#define log_ctcp_query(s, target, tag) \
+ log_server_status ((s), (s)->buffer, "CTCP query to #S: #S", target, tag)
+#define log_ctcp_reply(s, target, reply /* freed! */) \
+ log_server_status ((s), (s)->buffer, "CTCP reply to #S: #&S", target, reply)
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static struct buffer *
@@ -4593,8 +4598,13 @@ static void
irc_handle_ctcp_reply (struct server *s,
const struct irc_message *msg, struct ctcp_chunk *chunk)
{
- log_server_status (s, s->buffer, "CTCP reply from #n: #S #S",
- msg->prefix, chunk->tag.str, chunk->text.str);
+ const char *target = msg->params.vector[0];
+ if (irc_is_this_us (s, msg->prefix))
+ log_ctcp_reply (s, target,
+ xstrdup_printf ("%s %s", chunk->tag.str, chunk->text.str));
+ else
+ log_server_status (s, s->buffer, "CTCP reply from #n: #S #S",
+ msg->prefix, chunk->tag.str, chunk->text.str);
}
static void
@@ -4716,24 +4726,26 @@ irc_send_ctcp_reply (struct server *s,
va_end (ap);
irc_send (s, "NOTICE %s :\x01%s\x01", recipient, m.str);
- // FIXME: CAP echo-message?
- log_server_status (s, s->buffer,
- "CTCP reply to #S: #&S", recipient, str_steal (&m));
+ if (!s->cap_echo_message)
+ log_ctcp_reply (s, recipient, str_steal (&m));
+ else
+ str_free (&m);
}
static void
irc_handle_ctcp_request (struct server *s,
const struct irc_message *msg, struct ctcp_chunk *chunk)
{
- char *nickname = irc_cut_nickname (msg->prefix);
+ const char *target = msg->params.vector[0];
+ if (irc_is_this_us (s, msg->prefix))
+ log_ctcp_query (s, target, chunk->tag.str);
log_server_status (s, s->buffer,
- "CTCP requested by #n: #S", nickname, chunk->tag.str);
+ "CTCP requested by #n: #S", msg->prefix, chunk->tag.str);
- const char *target = msg->params.vector[0];
- const char *recipient = nickname;
- if (irc_is_channel (s, target))
- recipient = target;
+ char *recipient = irc_is_channel (s, target)
+ ? irc_cut_nickname (msg->prefix)
+ : xstrdup (target);
if (!strcmp (chunk->tag.str, "CLIENTINFO"))
irc_send_ctcp_reply (s, recipient, "CLIENTINFO %s %s %s %s",
@@ -4758,7 +4770,7 @@ irc_handle_ctcp_request (struct server *s,
irc_send_ctcp_reply (s, recipient, "TIME %s", buf);
}
- free (nickname);
+ free (recipient);
}
static void
@@ -6366,7 +6378,8 @@ handle_command_ctcp (struct handler_args *a)
else
irc_send (a->s, "PRIVMSG %s :\x01%s\x01", target, tag);
- log_server_status (a->s, a->s->buffer, "CTCP query to #S: #S", target, tag);
+ if (!a->s->cap_echo_message)
+ log_ctcp_query (a->s, target, tag);
return true;
}