Skip to content

Commit

Permalink
cap_message_tags: copy client tags only
Browse files Browse the repository at this point in the history
  • Loading branch information
RaitoBezarius committed Jul 20, 2022
1 parent cd36b6a commit 5c7df7b
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 12 deletions.
1 change: 1 addition & 0 deletions modules/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ LIBS += $(top_srcdir)/ircd/libircd.la
auto_load_moddir=@moduledir@/autoload

auto_load_mod_LTLIBRARIES = \
cap_message_tags.la \
cap_account_tag.la \
cap_server_time.la \
chm_nocolour.la \
Expand Down
82 changes: 82 additions & 0 deletions modules/cap_message_tags.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Solanum: a slightly advanced ircd
* cap_allow_list.c: implement the message-tags IRCv3 specification
*
* Copyright (c) 2022 Ryan Lahfa <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice is present in all copies.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#include "stdinc.h"
#include "modules.h"
#include "hook.h"
#include "client.h"
#include "ircd.h"
#include "send.h"
#include "s_conf.h"
#include "s_user.h"
#include "s_serv.h"
#include "numeric.h"
#include "chmode.h"
#include "inline/stringops.h"

static const char cap_message_tags_desc[] =
"Propagate message tags";

static void cap_message_tags_process(void *);
unsigned int CLICAP_MESSAGE_TAGS = 0;

mapi_hfn_list_av1 cap_message_tags_hfnlist[] = {
{ "outbound_msgbuf", cap_message_tags_process },
{ NULL, NULL }
};
mapi_cap_list_av2 cap_message_tags_cap_list[] = {
{ MAPI_CAP_CLIENT, "message-tags", NULL, &CLICAP_MESSAGE_TAGS },
{ 0, NULL, NULL, NULL },
};

static int
_modinit(void)
{
return 0;
}

static void
_moddeinit(void)
{
}

static void
cap_message_tags_process(void *data_)
{
hook_data *data = data_;
struct MsgBuf *msgbuf = data->arg1;

if (incoming_client != NULL) {
size_t n_tags = incoming_message->n_tags;
for (size_t index = 0 ; index < n_tags ; index++) {
if (incoming_message->tags[index].key[0] == '+') {
msgbuf_append_tag(msgbuf,
incoming_message->tags[index].key,
incoming_message->tags[index].value,
CLICAP_MESSAGE_TAGS); // TODO: client only capa neg
}
}
}
}

DECLARE_MODULE_AV2(cap_message_tags, NULL, NULL, NULL, NULL, cap_message_tags_hfnlist, cap_message_tags_cap_list, NULL, cap_message_tags_desc);
13 changes: 1 addition & 12 deletions modules/core/m_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include "inline/stringops.h"

static const char message_desc[] =
"Provides the PRIVMSG, NOTICE, TAGMSG commands to send messages to users and channels with message-tags support";
"Provides the PRIVMSG, NOTICE, TAGMSG commands to send messages to users and channels";

static void m_message(enum message_type, struct MsgBuf *, struct Client *, struct Client *, int, const char **);
static void m_privmsg(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
Expand Down Expand Up @@ -234,17 +234,6 @@ m_message(enum message_type msgtype, struct MsgBuf *msgbuf_p,

for(i = 0; i < ntargets; i++)
{
/* Process client tags for each target
*/
if (incoming_client != NULL) {
for (size_t tag_index = 0; tag_index < incoming_message->n_tags ; tag_index++) {
struct MsgTag tag = incoming_message->tags[tag_index];
if (!accept_client_tag(tag.key, tag.value, &targets[i])) {
msgbuf_append_tag(msgbuf_p, tag.key, tag.value, CLICAP_MESSAGE_TAGS);
}
}
}

switch (targets[i].type)
{
case ENTITY_CHANNEL:
Expand Down

0 comments on commit 5c7df7b

Please sign in to comment.