Skip to content

Commit cd36b6a

Browse files
committed
m_message: proper tag propagation
This introduces an handler to accept or not the propagation of a tag. Basic sketch API is provided for modules to hook for providing their own policy for specific tag propagation.
1 parent 5f018ae commit cd36b6a

File tree

7 files changed

+123
-9
lines changed

7 files changed

+123
-9
lines changed

include/client_tags.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Solanum: a slightly advanced ircd
3+
* client_tags.h: client tags (message-tags)
4+
*
5+
* Copyright (C) 2022 Ryan Lahfa
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are
9+
* met:
10+
*
11+
* 1.Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimer.
13+
* 2.Redistributions in binary form must reproduce the above copyright
14+
* notice, this list of conditions and the following disclaimer in the
15+
* documentation and/or other materials provided with the distribution.
16+
* 3.The name of the author may not be used to endorse or promote products
17+
* derived from this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+
* POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
32+
#ifndef INCLUDED_client_tags_h
33+
#define INCLUDED_client_tags_h
34+
35+
// TODO: uniformize this
36+
struct entity;
37+
38+
extern int accept_client_tag(const char *, const char*, struct entity*);
39+
40+
#endif /* INCLUDED_client_tags_h */

include/hook.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ enum message_type {
160160
MESSAGE_TYPE_NOTICE,
161161
MESSAGE_TYPE_PRIVMSG,
162162
MESSAGE_TYPE_PART,
163+
MESSAGE_TYPE_TAGMSG,
163164
MESSAGE_TYPE_COUNT
164165
};
165166

include/s_serv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ extern unsigned int CLICAP_USERHOST_IN_NAMES;
6868
extern unsigned int CLICAP_CAP_NOTIFY;
6969
extern unsigned int CLICAP_CHGHOST;
7070
extern unsigned int CLICAP_ECHO_MESSAGE;
71+
extern unsigned int CLICAP_MESSAGE_TAGS;
7172

7273
/*
7374
* XXX: this is kind of ugly, but this allows us to have backwards

ircd/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ libircd_la_SOURCES = \
2323
chmode.c \
2424
class.c \
2525
client.c \
26+
client_tags.c \
2627
dns.c \
2728
extban.c \
2829
getopt.c \

ircd/client_tags.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Solanum: a slightly advanced ircd
3+
* client_tags.c: client tags support
4+
*
5+
* Copyright (C) 2022 Ryan Lahfa
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are
9+
* met:
10+
*
11+
* 1.Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimer.
13+
* 2.Redistributions in binary form must reproduce the above copyright
14+
* notice, this list of conditions and the following disclaimer in the
15+
* documentation and/or other materials provided with the distribution.
16+
* 3.The name of the author may not be used to endorse or promote products
17+
* derived from this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+
* POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
32+
#include "stdinc.h"
33+
#include "client_tags.h"
34+
35+
int
36+
accept_client_tag(const char* tag_key, const char* tag_value, struct entity* target)
37+
{
38+
return (1); // accepts
39+
return (0); // refuses
40+
}

ircd/s_serv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ unsigned int CLICAP_USERHOST_IN_NAMES;
9696
unsigned int CLICAP_CAP_NOTIFY;
9797
unsigned int CLICAP_CHGHOST;
9898
unsigned int CLICAP_ECHO_MESSAGE;
99+
unsigned int CLICAP_MESSAGE_TAGS;
99100

100101
/*
101102
* initialize our builtin capability table. --nenolod
@@ -144,6 +145,7 @@ init_builtin_capabs(void)
144145
CLICAP_CAP_NOTIFY = capability_put(cli_capindex, "cap-notify", NULL);
145146
CLICAP_CHGHOST = capability_put(cli_capindex, "chghost", &high_priority);
146147
CLICAP_ECHO_MESSAGE = capability_put(cli_capindex, "echo-message", NULL);
148+
CLICAP_MESSAGE_TAGS = capability_put(cli_capindex, "message-tags", NULL);
147149
}
148150

149151
static CNCB serv_connect_callback;

modules/core/m_message.c

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@
4141
#include "s_newconf.h"
4242
#include "s_stats.h"
4343
#include "tgchange.h"
44+
#include "client_tags.h"
4445
#include "inline/stringops.h"
4546

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

4950
static void m_message(enum message_type, struct MsgBuf *, struct Client *, struct Client *, int, const char **);
5051
static void m_privmsg(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
5152
static void m_notice(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
53+
static void m_tagmsg(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
5254
static void m_echo(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
5355

5456
static void echo_msg(struct Client *, struct Client *, enum message_type, const char *);
@@ -57,6 +59,14 @@ static void expire_tgchange(void *unused);
5759
static struct ev_entry *expire_tgchange_event;
5860

5961
static unsigned int CAP_ECHO;
62+
static unsigned int CAP_TAGS;
63+
64+
struct entity
65+
{
66+
void* ptr;
67+
int type;
68+
int flags;
69+
};
6070

6171
static int
6272
modinit(void)
@@ -80,27 +90,25 @@ struct Message notice_msgtab = {
8090
"NOTICE", 0, 0, 0, 0,
8191
{mg_unreg, {m_notice, 0}, {m_notice, 0}, {m_notice, 0}, mg_ignore, {m_notice, 0}}
8292
};
93+
struct Message tagmsg_msgtab = {
94+
"TAGMSG", 0, 0, 0, 0,
95+
{mg_unreg, {m_tagmsg, 0}, {m_tagmsg, 0}, mg_ignore, mg_ignore, {m_tagmsg, 0}}
96+
};
8397
struct Message echo_msgtab = {
8498
"ECHO", 0, 0, 0, 0,
8599
{mg_unreg, mg_ignore, {m_echo, 3}, mg_ignore, mg_ignore, mg_ignore}
86100
};
87101

88-
mapi_clist_av1 message_clist[] = { &privmsg_msgtab, &notice_msgtab, &echo_msgtab, NULL };
102+
mapi_clist_av1 message_clist[] = { &privmsg_msgtab, &notice_msgtab, &echo_msgtab, &tagmsg_msgtab, NULL };
89103

90104
mapi_cap_list_av2 message_cap_list[] = {
91105
{ MAPI_CAP_SERVER, "ECHO", NULL, &CAP_ECHO },
106+
{ MAPI_CAP_SERVER, "TAGS", NULL, &CAP_TAGS },
92107
{ 0, NULL, NULL, NULL }
93108
};
94109

95110
DECLARE_MODULE_AV2(message, modinit, moddeinit, message_clist, NULL, NULL, message_cap_list, NULL, message_desc);
96111

97-
struct entity
98-
{
99-
void *ptr;
100-
int type;
101-
int flags;
102-
};
103-
104112
static int build_target_list(enum message_type msgtype,
105113
struct Client *client_p,
106114
struct Client *source_p, const char *nicks_channels, const char *text);
@@ -163,6 +171,7 @@ static void handle_special(enum message_type msgtype,
163171
const char *cmdname[MESSAGE_TYPE_COUNT] = {
164172
[MESSAGE_TYPE_PRIVMSG] = "PRIVMSG",
165173
[MESSAGE_TYPE_NOTICE] = "NOTICE",
174+
[MESSAGE_TYPE_TAGMSG] = "TAGMSG"
166175
};
167176

168177
static void
@@ -177,6 +186,14 @@ m_notice(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
177186
m_message(MESSAGE_TYPE_NOTICE, msgbuf_p, client_p, source_p, parc, parv);
178187
}
179188

189+
190+
static void
191+
m_tagmsg(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) {
192+
// TODO: test if target supports tags, if not, ignore.
193+
m_message(MESSAGE_TYPE_TAGMSG, msgbuf_p, client_p, source_p, parc, parv);
194+
}
195+
196+
180197
/*
181198
* inputs - flag privmsg or notice
182199
* - pointer to client_p
@@ -217,6 +234,17 @@ m_message(enum message_type msgtype, struct MsgBuf *msgbuf_p,
217234

218235
for(i = 0; i < ntargets; i++)
219236
{
237+
/* Process client tags for each target
238+
*/
239+
if (incoming_client != NULL) {
240+
for (size_t tag_index = 0; tag_index < incoming_message->n_tags ; tag_index++) {
241+
struct MsgTag tag = incoming_message->tags[tag_index];
242+
if (!accept_client_tag(tag.key, tag.value, &targets[i])) {
243+
msgbuf_append_tag(msgbuf_p, tag.key, tag.value, CLICAP_MESSAGE_TAGS);
244+
}
245+
}
246+
}
247+
220248
switch (targets[i].type)
221249
{
222250
case ENTITY_CHANNEL:
@@ -257,6 +285,7 @@ m_echo(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p
257285
{
258286
case 'P': msgtype = MESSAGE_TYPE_PRIVMSG; break;
259287
case 'N': msgtype = MESSAGE_TYPE_NOTICE; break;
288+
case 'T': msgtype = MESSAGE_TYPE_TAGMSG; break;
260289
default: return;
261290
}
262291

0 commit comments

Comments
 (0)