]> jfr.im git - solanum.git/blobdiff - ircd/msgbuf.c
Merge pull request #196 from jevolk/master
[solanum.git] / ircd / msgbuf.c
index 0e33fd6fd15d11824540000aeb0178e2c4d630db..50538d27031d049c231bdedd9e4ebc1c0aab584d 100644 (file)
@@ -35,7 +35,6 @@ msgbuf_parse(struct MsgBuf *msgbuf, char *line)
        char *ch;
        char *parv[MAXPARA];
        size_t n_para;
-       int i;
 
        /* skip any leading spaces */
        for (ch = line; *ch && *ch == ' '; ch++)
@@ -108,20 +107,33 @@ msgbuf_parse(struct MsgBuf *msgbuf, char *line)
                return 1;
 
        msgbuf->cmd = parv[0];
-       for (i = 0; i < n_para; i++)
+       for (size_t i = 0; i < n_para; i++)
                msgbuf_append_para(msgbuf, parv[i]);
 
        return 0;
 }
 
+static int
+msgbuf_has_matching_tags(struct MsgBuf *msgbuf, unsigned int capmask)
+{
+       for (size_t i = 0; i < msgbuf->n_tags; i++)
+       {
+               if ((msgbuf->tags[i].capmask & capmask) != 0)
+                       return 1;
+       }
+
+       return 0;
+}
+
 static void
 msgbuf_unparse_tags(char *buf, size_t buflen, struct MsgBuf *msgbuf, unsigned int capmask)
 {
-       int i;
+       if (!msgbuf_has_matching_tags(msgbuf, capmask))
+               return;
 
        *buf = '@';
 
-       for (i = 0; i < msgbuf->n_tags; i++)
+       for (size_t i = 0; i < msgbuf->n_tags; i++)
        {
                if ((msgbuf->tags[i].capmask & capmask) == 0)
                        continue;
@@ -145,8 +157,6 @@ msgbuf_unparse_tags(char *buf, size_t buflen, struct MsgBuf *msgbuf, unsigned in
 void
 msgbuf_unparse_prefix(char *buf, size_t buflen, struct MsgBuf *msgbuf, unsigned int capmask)
 {
-       int i;
-
        memset(buf, 0, buflen);
 
        if (msgbuf->n_tags > 0)
@@ -170,11 +180,9 @@ msgbuf_unparse_prefix(char *buf, size_t buflen, struct MsgBuf *msgbuf, unsigned
 int
 msgbuf_unparse(char *buf, size_t buflen, struct MsgBuf *msgbuf, unsigned int capmask)
 {
-       int i;
-
        msgbuf_unparse_prefix(buf, buflen, msgbuf, capmask);
 
-       for (i = msgbuf->cmd != NULL ? 0 : 1; i < msgbuf->n_para; i++)
+       for (size_t i = msgbuf->cmd != NULL ? 0 : 1; i < msgbuf->n_para; i++)
        {
                if (i == (msgbuf->n_para - 1))
                {