]> jfr.im git - solanum.git/blobdiff - ircd/send.c
IRCD_BUFSIZE is redundant with BUFSIZE, so kill it.
[solanum.git] / ircd / send.c
index f41355d9e84536c7a1404826c61d4ffb77e1c50f..44cb04984935454b1920a897588e9fc77244e7d1 100644 (file)
@@ -20,8 +20,6 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
- *
- *  $Id: send.c 3520 2007-06-30 22:15:35Z jilles $
  */
 
 #include "stdinc.h"
@@ -39,8 +37,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)
@@ -121,9 +118,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 +131,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 +140,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 +208,70 @@ send_queued_write(rb_fde_t *F, void *data)
        send_queued(to);
 }
 
+/*
+ * linebuf_put_msgvbuf
+ *
+ * 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_msgvbuf(struct MsgBuf *msgbuf, buf_head_t *linebuf, unsigned int capmask, const char *pattern, va_list *va)
+{
+       char buf[BUFSIZE];
+
+       rb_linebuf_newbuf(linebuf);
+       msgbuf_unparse_prefix(buf, sizeof buf, msgbuf, capmask);
+       rb_linebuf_putprefix(linebuf, pattern, va, buf);
+}
+
+/* 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, ...)
+{
+       va_list va;
+
+       va_start(va, pattern);
+       linebuf_put_msgvbuf(msgbuf, linebuf, capmask, pattern, &va);
+       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, const char *cmd)
+{
+       static char buf[BUFSIZE];
+       hook_data hdata;
+
+       msgbuf_init(msgbuf);
+
+       msgbuf->origin = buf;
+       msgbuf->cmd = cmd;
+
+       if (from != NULL && IsPerson(from))
+               snprintf(buf, sizeof buf, "%s!%s@%s", from->name, from->username, from->host);
+       else if (from != NULL)
+               rb_strlcpy(buf, from->name, sizeof buf);
+       else
+               rb_strlcpy(buf, me.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 +300,6 @@ sendto_one(struct Client *target_p, const char *pattern, ...)
        _send_linebuf(target_p, &linebuf);
 
        rb_linebuf_donebuf(&linebuf);
-
 }
 
 /* sendto_one_prefix()
@@ -463,7 +497,7 @@ void
 sendto_channel_flags(struct Client *one, int type, struct Client *source_p,
                     struct Channel *chptr, const char *pattern, ...)
 {
-       static char buf[BUFSIZE];
+       char buf[BUFSIZE];
        va_list args;
        buf_head_t rb_linebuf_local;
        buf_head_t rb_linebuf_id;
@@ -471,25 +505,21 @@ sendto_channel_flags(struct Client *one, int type, struct Client *source_p,
        struct membership *msptr;
        rb_dlink_node *ptr;
        rb_dlink_node *next_ptr;
+       int current_capmask = 0;
+       struct MsgBuf msgbuf;
 
        rb_linebuf_newbuf(&rb_linebuf_local);
        rb_linebuf_newbuf(&rb_linebuf_id);
 
        current_serial++;
 
+       build_msgbuf_from(&msgbuf, source_p, NULL);
+
        va_start(args, pattern);
-       vsnprintf(buf, sizeof(buf), pattern, args);
+       vsnprintf(buf, sizeof buf, pattern, args);
        va_end(args);
 
-       if(IsServer(source_p))
-               rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
-                              ":%s %s", source_p->name, buf);
-       else
-               rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
-                              ":%s!%s@%s %s",
-                              source_p->name, source_p->username,
-                              source_p->host, buf);
-
+       linebuf_put_msgbuf(&msgbuf, &rb_linebuf_local, NOCAPS, "%s", buf);
        rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf);
 
        RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head)
@@ -497,7 +527,10 @@ sendto_channel_flags(struct Client *one, int type, struct Client *source_p,
                msptr = ptr->data;
                target_p = msptr->client_p;
 
-               if(IsIOError(target_p->from) || target_p->from == one)
+               if(!MyClient(source_p) && (IsIOError(target_p->from) || target_p->from == one))
+                       continue;
+
+               if(MyClient(source_p) && !IsCapable(source_p, CLICAP_ECHO_MESSAGE) && target_p == one)
                        continue;
 
                if(type && ((msptr->flags & type) == 0))
@@ -521,7 +554,20 @@ sendto_channel_flags(struct Client *one, int type, struct Client *source_p,
                        }
                }
                else
+               {
+                       if (target_p->localClient->caps != current_capmask)
+                       {
+                               /* reset the linebuf */
+                               rb_linebuf_donebuf(&rb_linebuf_local);
+                               rb_linebuf_newbuf(&rb_linebuf_local);
+
+                               /* render the new linebuf and attach it */
+                               linebuf_put_msgbuf(&msgbuf, &rb_linebuf_local, target_p->localClient->caps, "%s", buf);
+                               current_capmask = target_p->localClient->caps;
+                       }
+
                        _send_linebuf(target_p, &rb_linebuf_local);
+               }
        }
 
        rb_linebuf_donebuf(&rb_linebuf_local);
@@ -581,7 +627,10 @@ sendto_channel_opmod(struct Client *one, struct Client *source_p,
                msptr = ptr->data;
                target_p = msptr->client_p;
 
-               if(IsIOError(target_p->from) || target_p->from == one)
+               if(!MyClient(source_p) && (IsIOError(target_p->from) || target_p->from == one))
+                       continue;
+
+               if(MyClient(source_p) && !IsCapable(source_p, CLICAP_ECHO_MESSAGE) && target_p == one)
                        continue;
 
                if((msptr->flags & CHFL_CHANOP) == 0)
@@ -749,11 +798,14 @@ sendto_channel_local_butone(struct Client *one, int type, struct Channel *chptr,
        buf_head_t linebuf;
        struct membership *msptr;
        struct Client *target_p;
+       struct MsgBuf msgbuf;
        rb_dlink_node *ptr;
        rb_dlink_node *next_ptr;
 
        rb_linebuf_newbuf(&linebuf);
 
+       build_msgbuf_from(&msgbuf, one, NULL);
+
        va_start(args, pattern);
        rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
        va_end(args);
@@ -772,6 +824,7 @@ sendto_channel_local_butone(struct Client *one, int type, struct Channel *chptr,
                if(type && ((msptr->flags & type) == 0))
                        continue;
 
+               /* attach the present linebuf to the target */
                _send_linebuf(target_p, &linebuf);
        }
 
@@ -867,6 +920,7 @@ sendto_common_channels_local_butone(struct Client *user, int cap, int negcap, co
        buf_head_t linebuf;
 
        rb_linebuf_newbuf(&linebuf);
+
        va_start(args, pattern);
        rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
        va_end(args);
@@ -1121,11 +1175,14 @@ sendto_anywhere(struct Client *target_p, struct Client *source_p,
                                       source_p->name, command,
                                       target_p->name);
                else
-                       rb_linebuf_putmsg(&linebuf, pattern, &args,
-                                      ":%s!%s@%s %s %s ",
-                                      source_p->name, source_p->username,
-                                      source_p->host, command,
-                                      target_p->name);
+               {
+                       struct MsgBuf msgbuf;
+
+                       build_msgbuf_from(&msgbuf, source_p, command);
+                       msgbuf.target = target_p->name;
+
+                       linebuf_put_msgvbuf(&msgbuf, &linebuf, target_p->localClient->caps, pattern, &args);
+               }
        }
        else
                rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ",