]> jfr.im git - solanum.git/blobdiff - ircd/send.c
send: implement linebuf_put_msgbuf() and msgbuf_build_from(), which build the core...
[solanum.git] / ircd / send.c
index a15d9d6427f3a7ce0e7eb112e767e45735fa61b3..8aaba7d730dd680ba8042910a9c27b34166f3f8f 100644 (file)
@@ -39,8 +39,7 @@
 #include "logger.h"
 #include "hook.h"
 #include "monitor.h"
-
-#define LOG_BUFSIZE 2048
+#include "msgbuf.h"
 
 /* send the message to the link the target is attached to */
 #define send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b)
@@ -69,20 +68,20 @@ _send_linebuf(struct Client *to, buf_head_t *linebuf)
        if(!MyConnect(to) || IsIOError(to))
                return 0;
 
-       if(rb_linebuf_len(&to->localClient->buf_sendq) > get_sendq_hard(to))
+       if(rb_linebuf_len(&to->localClient->buf_sendq) > get_sendq(to))
        {
                if(IsServer(to))
                {
                        sendto_realops_snomask(SNO_GENERAL, L_ALL,
-                                            "Hard SendQ limit exceeded for %s: %u > %lu",
+                                            "Max SendQ limit exceeded for %s: %u > %lu",
                                             to->name,
                                             rb_linebuf_len(&to->localClient->buf_sendq),
-                                            get_sendq_hard(to));
+                                            get_sendq(to));
 
-                       ilog(L_SERVER, "Hard SendQ limit exceeded for %s: %u > %lu",
+                       ilog(L_SERVER, "Max SendQ limit exceeded for %s: %u > %lu",
                             log_client_name(to, SHOW_IP),
                             rb_linebuf_len(&to->localClient->buf_sendq),
-                            get_sendq_hard(to));
+                            get_sendq(to));
                }
 
                dead_link(to, 1);
@@ -121,9 +120,7 @@ send_linebuf_remote(struct Client *to, struct Client *from, buf_head_t *linebuf)
                to = to->from;
 
        /* we assume the caller has already tested for fake direction */
-
        _send_linebuf(to, linebuf);
-       return;
 }
 
 /* send_queued_write()
@@ -136,9 +133,7 @@ void
 send_queued(struct Client *to)
 {
        int retlen;
-#ifdef USE_IODEBUG_HOOKS
-       hook_data_int hd;
-#endif
+
        rb_fde_t *F = to->localClient->F;
        if (!F)
                return;
@@ -147,38 +142,16 @@ send_queued(struct Client *to)
        if(IsIOError(to))
                return;
 
-       /* Something wants us to not send anything currently */
-       /* if(IsCork(to))
-               return; */
-
        /* try to flush later when the write event resets this */
        if(IsFlush(to))
                return;
 
-#ifdef USE_IODEBUG_HOOKS
-       hd.client = to;
-       if(to->localClient->buf_sendq.list.head)
-               hd.arg1 = ((buf_line_t *) to->localClient->buf_sendq.list.head->data)->buf +
-                            to->localClient->buf_sendq.writeofs;
-#endif
-
        if(rb_linebuf_len(&to->localClient->buf_sendq))
        {
                while ((retlen =
                        rb_linebuf_flush(F, &to->localClient->buf_sendq)) > 0)
                {
                        /* We have some data written .. update counters */
-#ifdef USE_IODEBUG_HOOKS
-                        hd.arg2 = retlen;
-                        call_hook(h_iosend_id, &hd);
-
-                        if(to->localClient->buf_sendq.list.head)
-                                hd.arg1 =
-                                        ((buf_line_t *) to->localClient->buf_sendq.list.head->
-                                         data)->buf + to->localClient->buf_sendq.writeofs;
-#endif
-
-
                        ClearFlush(to);
 
                        to->localClient->sendB += retlen;
@@ -237,6 +210,55 @@ send_queued_write(rb_fde_t *F, void *data)
        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()
  *
  * inputs      - client to send to, va_args
@@ -265,7 +287,6 @@ sendto_one(struct Client *target_p, const char *pattern, ...)
        _send_linebuf(target_p, &linebuf);
 
        rb_linebuf_donebuf(&linebuf);
-
 }
 
 /* sendto_one_prefix()
@@ -478,7 +499,7 @@ sendto_channel_flags(struct Client *one, int type, struct Client *source_p,
        current_serial++;
 
        va_start(args, pattern);
-       rb_vsnprintf(buf, sizeof(buf), pattern, args);
+       vsnprintf(buf, sizeof(buf), pattern, args);
        va_end(args);
 
        if(IsServer(source_p))
@@ -646,7 +667,12 @@ sendto_channel_local(int type, struct Channel *chptr, const char *pattern, ...)
                if(IsIOError(target_p))
                        continue;
 
-               if(type && ((msptr->flags & type) == 0))
+               if(type == ONLY_OPERS)
+               {
+                       if (!IsOper(target_p))
+                               continue;
+               }
+               else if(type && ((msptr->flags & type) == 0))
                        continue;
 
                _send_linebuf(target_p, &linebuf);
@@ -916,7 +942,7 @@ sendto_match_butone(struct Client *one, struct Client *source_p,
        rb_linebuf_newbuf(&rb_linebuf_id);
 
        va_start(args, pattern);
-       rb_vsnprintf(buf, sizeof(buf), pattern, args);
+       vsnprintf(buf, sizeof(buf), pattern, args);
        va_end(args);
 
        if(IsServer(source_p))
@@ -986,7 +1012,7 @@ sendto_match_servs(struct Client *source_p, const char *mask, int cap,
        rb_linebuf_newbuf(&rb_linebuf_id);
 
        va_start(args, pattern);
-       rb_vsnprintf(buf, sizeof(buf), pattern, args);
+       vsnprintf(buf, sizeof(buf), pattern, args);
        va_end(args);
 
        rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL,
@@ -1161,7 +1187,7 @@ sendto_realops_snomask(int flags, int level, const char *pattern, ...)
        {
                /* rather a lot of copying around, oh well -- jilles */
                va_start(args, pattern);
-               rb_vsnprintf(buf, sizeof(buf), pattern, args);
+               vsnprintf(buf, sizeof(buf), pattern, args);
                va_end(args);
                rb_linebuf_putmsg(&linebuf, pattern, NULL,
                                ":%s NOTICE * :*** Notice -- %s", me.name, buf);
@@ -1175,7 +1201,7 @@ sendto_realops_snomask(int flags, int level, const char *pattern, ...)
        {
                /* rather a lot of copying around, oh well -- jilles */
                va_start(args, pattern);
-               rb_vsnprintf(buf, sizeof(buf), pattern, args);
+               vsnprintf(buf, sizeof(buf), pattern, args);
                va_end(args);
                rb_linebuf_putmsg(&linebuf, pattern, NULL,
                                ":%s NOTICE * :*** Notice -- %s", me.name, buf);
@@ -1338,7 +1364,7 @@ kill_client_serv_butone(struct Client *one, struct Client *target_p, const char
        rb_linebuf_newbuf(&rb_linebuf_id);
 
        va_start(args, pattern);
-       rb_vsnprintf(buf, sizeof(buf), pattern, args);
+       vsnprintf(buf, sizeof(buf), pattern, args);
        va_end(args);
 
        rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s KILL %s :%s",