Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagated server-time #283

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/msgbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ int msgbuf_vunparse_fmt(char *buf, size_t buflen, const struct MsgBuf *head, uns
int msgbuf_unparse_linebuf_tags(char *buf, size_t buflen, void *data);
int msgbuf_unparse_prefix(char *buf, size_t *buflen, const struct MsgBuf *msgbuf, unsigned int capmask);

const char *msgbuf_get_tag(const struct MsgBuf *buf, const char *name);

void msgbuf_cache_init(struct MsgBuf_cache *cache, const struct MsgBuf *msgbuf, const rb_strf_t *message);
void msgbuf_cache_initf(struct MsgBuf_cache *cache, const struct MsgBuf *msgbuf, const rb_strf_t *message, const char *format, ...) AFP(4, 5);
buf_head_t *msgbuf_cache_get(struct MsgBuf_cache *cache, unsigned int caps);
Expand Down
3 changes: 3 additions & 0 deletions include/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ extern char *reconstruct_parv(int parc, const char *parv[]);
extern rb_dictionary *alias_dict;
extern rb_dictionary *cmd_dict;

extern const struct MsgBuf *incoming_message;
extern const struct Client *incoming_client;

#endif /* INCLUDED_parse_h_h */
1 change: 1 addition & 0 deletions include/s_serv.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ extern unsigned int CAP_EUID; /* supports EUID (ext UID + nonencap CHGHOST) */
extern unsigned int CAP_EOPMOD; /* supports EOPMOD (ext +z + ext topic) */
extern unsigned int CAP_BAN; /* supports propagated bans */
extern unsigned int CAP_MLOCK; /* supports MLOCK messages */
extern unsigned int CAP_STAG; /* supports s2s tags and labeled-response */

/* XXX: added for backwards compatibility. --nenolod */
#define CAP_MASK (capability_index_mask(serv_capindex) & ~(CAP_TS6 | CAP_CAP))
Expand Down
13 changes: 13 additions & 0 deletions ircd/msgbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,19 @@ msgbuf_unparse_fmt(char *buf, size_t buflen, const struct MsgBuf *head, unsigned
return res;
}

const char *
msgbuf_get_tag(const struct MsgBuf *buf, const char *name)
{
for (size_t i = 0; i < buf->n_tags; i++)
{
if (strcmp(name, buf->tags[i].key))
continue;
const char *v = buf->tags[i].value;
return v != NULL ? v : "";
}
return NULL;
}

void
msgbuf_cache_init(struct MsgBuf_cache *cache, const struct MsgBuf *msgbuf, const rb_strf_t *message)
{
Expand Down
8 changes: 8 additions & 0 deletions ircd/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
rb_dictionary *cmd_dict = NULL;
rb_dictionary *alias_dict = NULL;

const struct MsgBuf *incoming_message = NULL;
const struct Client *incoming_client = NULL;

static void cancel_clients(struct Client *, struct Client *);
static void remove_unknown(struct Client *, const char *, char *);

Expand Down Expand Up @@ -153,6 +156,9 @@ parse(struct Client *client_p, char *pbuffer, char *bufend)
return;
}

incoming_message = &msgbuf;
incoming_client = client_p;

if(handle_command(mptr, &msgbuf, client_p, from) < -1)
{
char *p;
Expand All @@ -177,6 +183,8 @@ parse(struct Client *client_p, char *pbuffer, char *bufend)
}
}

incoming_message = NULL;
incoming_client = NULL;
}

/*
Expand Down
2 changes: 2 additions & 0 deletions ircd/s_serv.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ unsigned int CAP_EUID;
unsigned int CAP_EOPMOD;
unsigned int CAP_BAN;
unsigned int CAP_MLOCK;
unsigned int CAP_STAG;

unsigned int CLICAP_MULTI_PREFIX;
unsigned int CLICAP_ACCOUNT_NOTIFY;
Expand Down Expand Up @@ -126,6 +127,7 @@ init_builtin_capabs(void)
CAP_EOPMOD = capability_put(serv_capindex, "EOPMOD", NULL);
CAP_BAN = capability_put(serv_capindex, "BAN", NULL);
CAP_MLOCK = capability_put(serv_capindex, "MLOCK", NULL);
CAP_STAG = capability_put(serv_capindex, "STAG", NULL);

capability_require(serv_capindex, "QS");
capability_require(serv_capindex, "EX");
Expand Down
39 changes: 20 additions & 19 deletions ircd/send.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
/* send the message to the link the target is attached to */
#define send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b)

#define CLIENT_CAPS_ONLY(x) ((IsClient((x)) && (x)->localClient) ? (x)->localClient->caps : 0)
#define CLIENT_CAP_MASK(x) (MyClient((x)) ? (x)->localClient->caps : \
((x)->from == &me || ((x)->from && (x)->from->localClient->caps & CAP_STAG)) ? (unsigned)-1 : 0)

static void send_queued_write(rb_fde_t *F, void *data);

Expand Down Expand Up @@ -221,7 +222,7 @@ send_queued_write(rb_fde_t *F, void *data)
static void
linebuf_put_tags(buf_head_t *linebuf, const struct MsgBuf *msgbuf, const struct Client *target_p, rb_strf_t *message)
{
struct MsgBuf_str_data msgbuf_str_data = { .msgbuf = msgbuf, .caps = CLIENT_CAPS_ONLY(target_p) };
struct MsgBuf_str_data msgbuf_str_data = { .msgbuf = msgbuf, .caps = CLIENT_CAP_MASK(target_p) };
rb_strf_t strings = { .func = msgbuf_unparse_linebuf_tags, .func_args = &msgbuf_str_data, .length = TAGSLEN + 1, .next = message };

message->length = DATALEN + 1;
Expand Down Expand Up @@ -556,7 +557,7 @@ sendto_channel_flags(struct Client *one, int type, struct Client *source_p,
}
else
{
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p)));
}
}

Expand All @@ -565,7 +566,7 @@ sendto_channel_flags(struct Client *one, int type, struct Client *source_p,
{
target_p = one;

_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p)));
}

rb_linebuf_donebuf(&rb_linebuf_remote);
Expand Down Expand Up @@ -659,7 +660,7 @@ sendto_channel_opmod(struct Client *one, struct Client *source_p,
target_p->from->serial = current_serial;
}
} else {
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p)));
}
}

Expand All @@ -668,7 +669,7 @@ sendto_channel_opmod(struct Client *one, struct Client *source_p,
{
target_p = one;

_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p)));
}

rb_linebuf_donebuf(&rb_linebuf_old);
Expand Down Expand Up @@ -711,7 +712,7 @@ _sendto_channel_local(struct Client *source_p, int type, const char *priv, struc
if (priv != NULL && !HasPrivilege(target_p, priv))
continue;

_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p)));
}

msgbuf_cache_free(&msgbuf_cache);
Expand Down Expand Up @@ -783,7 +784,7 @@ _sendto_channel_local_with_capability_butone(struct Client *source_p, struct Cli
if(type && ((msptr->flags & type) == 0))
continue;

_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p)));
}

msgbuf_cache_free(&msgbuf_cache);
Expand Down Expand Up @@ -864,7 +865,7 @@ sendto_channel_local_butone(struct Client *one, int type, struct Channel *chptr,
continue;

/* attach the present linebuf to the target */
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p)));
}

msgbuf_cache_free(&msgbuf_cache);
Expand Down Expand Up @@ -923,7 +924,7 @@ sendto_common_channels_local(struct Client *user, int cap, int negcap, const cha
continue;

target_p->serial = current_serial;
send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p)));
}
}

Expand All @@ -932,7 +933,7 @@ sendto_common_channels_local(struct Client *user, int cap, int negcap, const cha
*/
if(MyConnect(user) && (user->serial != current_serial)
&& IsCapable(user, cap) && NotCapable(user, negcap)) {
send_linebuf(user, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(user)));
send_linebuf(user, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(user)));
}

msgbuf_cache_free(&msgbuf_cache);
Expand Down Expand Up @@ -992,7 +993,7 @@ sendto_common_channels_local_butone(struct Client *user, int cap, int negcap, co
continue;

target_p->serial = current_serial;
send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p)));
}
}

Expand Down Expand Up @@ -1040,7 +1041,7 @@ sendto_match_butone(struct Client *one, struct Client *source_p,
target_p = ptr->data;

if(match(mask, target_p->host))
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p)));
}
}
/* what = MATCH_SERVER, if it doesnt match us, just send remote */
Expand All @@ -1049,7 +1050,7 @@ sendto_match_butone(struct Client *one, struct Client *source_p,
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
{
target_p = ptr->data;
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p)));
}
}

Expand Down Expand Up @@ -1157,7 +1158,7 @@ sendto_local_clients_with_capability(int cap, const char *pattern, ...)
if(IsIOError(target_p) || !IsCapable(target_p, cap))
continue;

send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p)));
}

msgbuf_cache_free(&msgbuf_cache);
Expand Down Expand Up @@ -1193,7 +1194,7 @@ sendto_monitor(struct Client *source_p, struct monitor *monptr, const char *patt
if(IsIOError(target_p))
continue;

_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p)));
}

msgbuf_cache_free(&msgbuf_cache);
Expand Down Expand Up @@ -1336,7 +1337,7 @@ sendto_realops_snomask(int flags, int level, const char *pattern, ...)
continue;

if (client_p->snomask & flags) {
_send_linebuf(client_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(client_p)));
_send_linebuf(client_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(client_p)));
}
}

Expand Down Expand Up @@ -1379,7 +1380,7 @@ sendto_realops_snomask_from(int flags, int level, struct Client *source_p,
continue;

if (client_p->snomask & flags) {
_send_linebuf(client_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(client_p)));
_send_linebuf(client_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(client_p)));
}
}

Expand Down Expand Up @@ -1424,7 +1425,7 @@ sendto_wallops_flags(int flags, struct Client *source_p, const char *pattern, ..
client_p = ptr->data;

if (client_p->umodes & flags) {
_send_linebuf(client_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(client_p)));
_send_linebuf(client_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(client_p)));
}
}

Expand Down
10 changes: 10 additions & 0 deletions modules/cap_server_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "s_serv.h"
#include "numeric.h"
#include "chmode.h"
#include "parse.h"
#include "inline/stringops.h"

static const char cap_server_time_desc[] =
Expand All @@ -54,9 +55,18 @@ cap_server_time_process(void *data_)
{
hook_data *data = data_;
static char buf[BUFSIZE];
const char *tagged_time;
struct MsgBuf *msgbuf = data->arg1;
struct timeval tv;

if (incoming_client != NULL && IsServer(incoming_client) && !msgbuf_get_tag(msgbuf, "time") && (tagged_time = msgbuf_get_tag(incoming_message, "time")))
{
msgbuf_append_tag(msgbuf, "time", tagged_time, CLICAP_SERVER_TIME);
}

if (data->client != NULL && !IsMe(data->client) && !MyClient(data->client))
return;

if (!rb_gettimeofday(&tv, NULL)) {
if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S.", gmtime(&tv.tv_sec)) == 0)
return;
Expand Down
Loading