degesch: fix /ctcp with CAP echo-message

This commit is contained in:
Přemysl Eric Janouch 2015-06-28 16:57:08 +02:00
parent a1fa9d187e
commit db6939bd60
1 changed files with 26 additions and 13 deletions

View File

@ -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;
}