send: implement linebuf_put_msgbuf() and msgbuf_build_from(), which build the core of the ircv3.2 tags support for outbound messages
This commit is contained in:
parent
5abeae60b8
commit
4f8ababae0
3 changed files with 53 additions and 5 deletions
|
@ -34,6 +34,7 @@ extern int h_privmsg_channel;
|
||||||
extern int h_privmsg_user;
|
extern int h_privmsg_user;
|
||||||
extern int h_conf_read_start;
|
extern int h_conf_read_start;
|
||||||
extern int h_conf_read_end;
|
extern int h_conf_read_end;
|
||||||
|
extern int h_outbound_msgbuf;
|
||||||
|
|
||||||
void init_hook(void);
|
void init_hook(void);
|
||||||
int register_hook(const char *name);
|
int register_hook(const char *name);
|
||||||
|
|
|
@ -63,6 +63,7 @@ int h_privmsg_user;
|
||||||
int h_privmsg_channel;
|
int h_privmsg_channel;
|
||||||
int h_conf_read_start;
|
int h_conf_read_start;
|
||||||
int h_conf_read_end;
|
int h_conf_read_end;
|
||||||
|
int h_outbound_msgbuf;
|
||||||
|
|
||||||
void
|
void
|
||||||
init_hook(void)
|
init_hook(void)
|
||||||
|
@ -84,6 +85,7 @@ init_hook(void)
|
||||||
h_privmsg_channel = register_hook("privmsg_channel");
|
h_privmsg_channel = register_hook("privmsg_channel");
|
||||||
h_conf_read_start = register_hook("conf_read_start");
|
h_conf_read_start = register_hook("conf_read_start");
|
||||||
h_conf_read_end = register_hook("conf_read_end");
|
h_conf_read_end = register_hook("conf_read_end");
|
||||||
|
h_outbound_msgbuf = register_hook("outbound_msgbuf");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* grow_hooktable()
|
/* grow_hooktable()
|
||||||
|
|
55
ircd/send.c
55
ircd/send.c
|
@ -39,8 +39,7 @@
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "hook.h"
|
#include "hook.h"
|
||||||
#include "monitor.h"
|
#include "monitor.h"
|
||||||
|
#include "msgbuf.h"
|
||||||
#define LOG_BUFSIZE 2048
|
|
||||||
|
|
||||||
/* send the message to the link the target is attached to */
|
/* 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 send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b)
|
||||||
|
@ -121,9 +120,7 @@ send_linebuf_remote(struct Client *to, struct Client *from, buf_head_t *linebuf)
|
||||||
to = to->from;
|
to = to->from;
|
||||||
|
|
||||||
/* we assume the caller has already tested for fake direction */
|
/* we assume the caller has already tested for fake direction */
|
||||||
|
|
||||||
_send_linebuf(to, linebuf);
|
_send_linebuf(to, linebuf);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* send_queued_write()
|
/* send_queued_write()
|
||||||
|
@ -213,6 +210,55 @@ send_queued_write(rb_fde_t *F, void *data)
|
||||||
send_queued(to);
|
send_queued(to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* linebuf_put_msgbuf
|
||||||
|
*
|
||||||
|
* inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
|
||||||
|
* outputs - none
|
||||||
|
* side effects - the linebuf object is cleared, then populated using rb_linebuf_putmsg().
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
linebuf_put_msgbuf(struct MsgBuf *msgbuf, buf_head_t *linebuf, unsigned int capmask, const char *pattern, ...)
|
||||||
|
{
|
||||||
|
char buf[IRCD_BUFSIZE];
|
||||||
|
va_list va;
|
||||||
|
|
||||||
|
rb_linebuf_newbuf(linebuf);
|
||||||
|
|
||||||
|
msgbuf_unparse_prefix(buf, sizeof buf, msgbuf, capmask);
|
||||||
|
|
||||||
|
va_start(va, pattern);
|
||||||
|
rb_linebuf_putprefix(linebuf, pattern, &va, buf);
|
||||||
|
va_end(va);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* build_msgbuf_from
|
||||||
|
*
|
||||||
|
* inputs - msgbuf object, client the message is from
|
||||||
|
* outputs - none
|
||||||
|
* side effects - a msgbuf object is populated with an origin and relevant tags
|
||||||
|
* notes - to make this reentrant, find a solution for `buf` below
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
build_msgbuf_from(struct MsgBuf *msgbuf, struct Client *from)
|
||||||
|
{
|
||||||
|
static char buf[BUFSIZE];
|
||||||
|
hook_data hdata;
|
||||||
|
|
||||||
|
msgbuf_init(msgbuf);
|
||||||
|
|
||||||
|
msgbuf->origin = buf;
|
||||||
|
|
||||||
|
if (IsPerson(from))
|
||||||
|
snprintf(buf, sizeof buf, "%s!%s@%s", from->name, from->username, from->host);
|
||||||
|
else
|
||||||
|
rb_strlcpy(buf, from->name, sizeof buf);
|
||||||
|
|
||||||
|
hdata.client = from;
|
||||||
|
hdata.arg1 = msgbuf;
|
||||||
|
|
||||||
|
call_hook(h_outbound_msgbuf, &hdata);
|
||||||
|
}
|
||||||
|
|
||||||
/* sendto_one()
|
/* sendto_one()
|
||||||
*
|
*
|
||||||
* inputs - client to send to, va_args
|
* inputs - client to send to, va_args
|
||||||
|
@ -241,7 +287,6 @@ sendto_one(struct Client *target_p, const char *pattern, ...)
|
||||||
_send_linebuf(target_p, &linebuf);
|
_send_linebuf(target_p, &linebuf);
|
||||||
|
|
||||||
rb_linebuf_donebuf(&linebuf);
|
rb_linebuf_donebuf(&linebuf);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sendto_one_prefix()
|
/* sendto_one_prefix()
|
||||||
|
|
Loading…
Reference in a new issue