]> jfr.im git - solanum.git/blobdiff - include/msgbuf.h
tests: send1: fix sendto_channel_opmod (remote) to cover all scenarios
[solanum.git] / include / msgbuf.h
index 1a3eeb081041fb08a471e97b0960678963a0e86c..1bcff5edc6b1ac12cb4d2c39e55b73015f84e91d 100644 (file)
@@ -19,8 +19,6 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "s_assert.h"
-
 #ifndef CHARYBDIS__MSGBUF_H
 #define CHARYBDIS__MSGBUF_H
 
@@ -38,10 +36,10 @@ struct MsgBuf {
        struct MsgTag tags[MAXPARA];    /* the tags themselves, upto MAXPARA tags available */
 
        const char *origin;             /* the origin of the message (or NULL) */
-       const char *cmd;                /* the cmd/verb of the message (also para[0]) */
+       const char *target;             /* the target of the message (either NULL, or custom defined) */
+       const char *cmd;                /* the cmd/verb of the message (either NULL, or para[0]) */
 
-       size_t parselen;                /* the length of the message */
-       size_t n_para;                  /* the number of parameters (always at least 1) */
+       size_t n_para;                  /* the number of parameters (always at least 1 if a full message) */
        const char *para[MAXPARA];      /* parameters vector (starting with cmd as para[0]) */
 };
 
@@ -57,7 +55,7 @@ int msgbuf_parse(struct MsgBuf *msgbuf, char *line);
  * cmd may not be NULL.
  * returns 0 on success, 1 on error.
  */
-int msgbuf_unparse(char *buf, struct MsgBuf *msgbuf, unsigned int capmask);
+int msgbuf_unparse(char *buf, size_t buflen, const struct MsgBuf *msgbuf, unsigned int capmask);
 
 /*
  * unparse a MsgBuf header plus payload into a buffer.
@@ -65,8 +63,10 @@ int msgbuf_unparse(char *buf, struct MsgBuf *msgbuf, unsigned int capmask);
  * cmd may not be NULL.
  * returns 0 on success, 1 on error.
  */
-int msgbuf_unparse_fmt(char *buf, struct MsgBuf *head, unsigned int capmask, const char *fmt, ...) AFP(4, 5);
-int msgbuf_vunparse_fmt(char *buf, struct MsgBuf *head, unsigned int capmask, const char *fmt, va_list va);
+int msgbuf_unparse_fmt(char *buf, size_t buflen, const struct MsgBuf *head, unsigned int capmask, const char *fmt, ...) AFP(5, 6);
+int msgbuf_vunparse_fmt(char *buf, size_t buflen, const struct MsgBuf *head, unsigned int capmask, const char *fmt, va_list va);
+
+void msgbuf_unparse_prefix(char *buf, size_t *buflen, const struct MsgBuf *msgbuf, unsigned int capmask);
 
 static inline void
 msgbuf_init(struct MsgBuf *msgbuf)
@@ -75,22 +75,14 @@ msgbuf_init(struct MsgBuf *msgbuf)
 }
 
 static inline void
-msgbuf_append_tag(struct MsgBuf *msgbuf, const char *key, const char *value)
-{
-       s_assert(msgbuf->n_tags < MAXPARA);
-
-       msgbuf->tags[msgbuf->n_tags].key = key;
-       msgbuf->tags[msgbuf->n_tags].value = value;
-       msgbuf->n_tags++;
-}
-
-static inline void
-msgbuf_append_para(struct MsgBuf *msgbuf, const char *para)
+msgbuf_append_tag(struct MsgBuf *msgbuf, const char *key, const char *value, unsigned int capmask)
 {
-       s_assert(msgbuf->n_para < MAXPARA);
-
-       msgbuf->para[msgbuf->n_para] = para;
-       msgbuf->n_para++;
+       if (msgbuf->n_tags < MAXPARA) {
+               msgbuf->tags[msgbuf->n_tags].key = key;
+               msgbuf->tags[msgbuf->n_tags].value = value;
+               msgbuf->tags[msgbuf->n_tags].capmask = capmask;
+               msgbuf->n_tags++;
+       }
 }
 
 #endif