}
/*
- * linebuf_put_msgvbuf
+ * linebuf_put_tags_prefix
*
* inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
* outputs - none
- * side effects - the linebuf object is cleared, then populated using rb_linebuf_putmsg().
+ * side effects - the linebuf object is cleared, then populated using rb_linebuf_putprefix().
*/
static void
-linebuf_put_msgvbuf(struct MsgBuf *msgbuf, buf_head_t *linebuf, unsigned int capmask, const char *pattern, va_list *va)
+linebuf_put_tags_vprefix(struct MsgBuf *msgbuf, buf_head_t *linebuf, unsigned int capmask, const char *pattern, va_list *va)
{
static char buf[EXT_BUFSIZE];
size_t buflen = sizeof(buf);
rb_linebuf_newbuf(linebuf);
msgbuf_unparse_prefix(buf, &buflen, msgbuf, capmask);
- rb_linebuf_putprefix(linebuf, pattern, va, buf, buflen);
+ rb_linebuf_put_vtags_prefix(linebuf, pattern, va, buflen, buf);
}
-/* linebuf_put_msgbuf
+/* linebuf_put_tags_prefixf
*
* inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
* outputs - none
- * side effects - the linebuf object is cleared, then populated using rb_linebuf_putmsg().
+ * side effects - the linebuf object is cleared, then populated using rb_linebuf_putprefix().
*/
static void
-linebuf_put_msgbuf(struct MsgBuf *msgbuf, buf_head_t *linebuf, unsigned int capmask, const char *pattern, ...)
+linebuf_put_tags_prefixf(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);
+ linebuf_put_tags_vprefix(msgbuf, linebuf, capmask, pattern, &va);
va_end(va);
}
rb_linebuf_newbuf(&linebuf);
va_start(args, pattern);
- rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
+ rb_linebuf_put_vmsg(&linebuf, pattern, &args);
va_end(args);
_send_linebuf(target_p, &linebuf);
rb_linebuf_newbuf(&linebuf);
va_start(args, pattern);
- rb_linebuf_putmsg(&linebuf, pattern, &args,
+ rb_linebuf_put_vmsg_prefixf(&linebuf, pattern, &args,
":%s %s %s ",
get_id(source_p, target_p),
command, get_id(target_p, target_p));
rb_linebuf_newbuf(&linebuf);
va_start(args, pattern);
- rb_linebuf_putmsg(&linebuf, pattern, &args,
+ rb_linebuf_put_vmsg_prefixf(&linebuf, pattern, &args,
":%s NOTICE %s ",
get_id(&me, target_p), *(to = get_id(target_p, target_p)) != '\0' ? to : "*");
va_end(args);
rb_linebuf_newbuf(&linebuf);
va_start(args, pattern);
- rb_linebuf_putmsg(&linebuf, pattern, &args,
+ rb_linebuf_put_vmsg_prefixf(&linebuf, pattern, &args,
":%s %03d %s ",
get_id(&me, target_p),
numeric, *(to = get_id(target_p, target_p)) != '\0' ? to : "*");
rb_linebuf_newbuf(&linebuf);
va_start(args, format);
- rb_linebuf_putmsg(&linebuf, format, &args, NULL);
+ rb_linebuf_put_vmsg(&linebuf, format, &args);
va_end(args);
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head)
static char buf[BUFSIZE];
va_list args;
buf_head_t rb_linebuf_local;
- buf_head_t rb_linebuf_id;
+ buf_head_t rb_linebuf_remote;
struct Client *target_p;
struct membership *msptr;
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
- int current_capmask = 0;
+ int current_capmask = NOCAPS;
struct MsgBuf msgbuf;
rb_linebuf_newbuf(&rb_linebuf_local);
- rb_linebuf_newbuf(&rb_linebuf_id);
+ rb_linebuf_newbuf(&rb_linebuf_remote);
current_serial++;
vsnprintf(buf, sizeof buf, pattern, args);
va_end(args);
- 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);
+ linebuf_put_tags_prefixf(&msgbuf, &rb_linebuf_local, current_capmask, "%s", buf);
+ rb_linebuf_put_msgf(&rb_linebuf_remote, ":%s %s", use_id(source_p), buf);
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head)
{
if(target_p->from->serial != current_serial)
{
- send_linebuf_remote(target_p, source_p, &rb_linebuf_id);
+ send_linebuf_remote(target_p, source_p, &rb_linebuf_remote);
target_p->from->serial = current_serial;
}
}
/* render the new linebuf and attach it */
current_capmask = target_p->localClient->caps;
- linebuf_put_msgbuf(&msgbuf, &rb_linebuf_local, current_capmask, "%s", buf);
+ linebuf_put_tags_prefixf(&msgbuf, &rb_linebuf_local, current_capmask, "%s", buf);
}
_send_linebuf(target_p, &rb_linebuf_local);
/* render the new linebuf and attach it */
current_capmask = target_p->localClient->caps;
- linebuf_put_msgbuf(&msgbuf, &rb_linebuf_local, current_capmask, "%s", buf);
+ linebuf_put_tags_prefixf(&msgbuf, &rb_linebuf_local, current_capmask, "%s", buf);
}
_send_linebuf(target_p, &rb_linebuf_local);
}
rb_linebuf_donebuf(&rb_linebuf_local);
- rb_linebuf_donebuf(&rb_linebuf_id);
+ rb_linebuf_donebuf(&rb_linebuf_remote);
}
/* sendto_channel_flags()
current_serial++;
if(IsServer(source_p))
- rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
+ rb_linebuf_put_msgf(&rb_linebuf_local,
":%s %s %s :%s",
source_p->name, command, chptr->chname, text);
else
- rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
+ rb_linebuf_put_msgf(&rb_linebuf_local,
":%s!%s@%s %s %s :%s",
source_p->name, source_p->username,
source_p->host, command, chptr->chname, text);
if (chptr->mode.mode & MODE_MODERATED)
- rb_linebuf_putmsg(&rb_linebuf_old, NULL, NULL,
+ rb_linebuf_put_msgf(&rb_linebuf_old,
":%s %s %s :%s",
use_id(source_p), command, chptr->chname, text);
else
- rb_linebuf_putmsg(&rb_linebuf_old, NULL, NULL,
+ rb_linebuf_put_msgf(&rb_linebuf_old,
":%s NOTICE @%s :<%s:%s> %s",
use_id(source_p->servptr), chptr->chname,
source_p->name, chptr->chname, text);
- rb_linebuf_putmsg(&rb_linebuf_new, NULL, NULL,
+ rb_linebuf_put_msgf(&rb_linebuf_new,
":%s %s =%s :%s",
use_id(source_p), command, chptr->chname, text);
rb_linebuf_newbuf(&linebuf);
va_start(args, pattern);
- rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
+ rb_linebuf_put_vmsg(&linebuf, pattern, &args);
va_end(args);
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
rb_dlink_node *next_ptr;
rb_linebuf_newbuf(&linebuf);
- rb_linebuf_putmsg(&linebuf, pattern, args, NULL);
+ rb_linebuf_put_vmsg(&linebuf, pattern, args);
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
{
build_msgbuf_from(&msgbuf, one, NULL);
va_start(args, pattern);
- rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
+ rb_linebuf_put_vmsg(&linebuf, pattern, &args);
va_end(args);
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
rb_linebuf_newbuf(&linebuf);
va_start(args, pattern);
- rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
+ rb_linebuf_put_vmsg(&linebuf, pattern, &args);
va_end(args);
++current_serial;
rb_linebuf_newbuf(&linebuf);
va_start(args, pattern);
- rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
+ rb_linebuf_put_vmsg(&linebuf, pattern, &args);
va_end(args);
++current_serial;
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
buf_head_t rb_linebuf_local;
- buf_head_t rb_linebuf_id;
+ buf_head_t rb_linebuf_remote;
rb_linebuf_newbuf(&rb_linebuf_local);
- rb_linebuf_newbuf(&rb_linebuf_id);
+ rb_linebuf_newbuf(&rb_linebuf_remote);
va_start(args, pattern);
vsnprintf(buf, sizeof(buf), pattern, args);
va_end(args);
if(IsServer(source_p))
- rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
+ rb_linebuf_put_msgf(&rb_linebuf_local,
":%s %s", source_p->name, buf);
else
- rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
+ rb_linebuf_put_msgf(&rb_linebuf_local,
":%s!%s@%s %s",
source_p->name, source_p->username,
source_p->host, buf);
- rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf);
+ rb_linebuf_put_msgf(&rb_linebuf_remote, ":%s %s", use_id(source_p), buf);
if(what == MATCH_HOST)
{
if(target_p == one)
continue;
- send_linebuf_remote(target_p, source_p, &rb_linebuf_id);
+ send_linebuf_remote(target_p, source_p, &rb_linebuf_remote);
}
rb_linebuf_donebuf(&rb_linebuf_local);
- rb_linebuf_donebuf(&rb_linebuf_id);
+ rb_linebuf_donebuf(&rb_linebuf_remote);
}
/* sendto_match_servs()
vsnprintf(buf, sizeof(buf), pattern, args);
va_end(args);
- rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL,
- ":%s %s", use_id(source_p), buf);
+ rb_linebuf_put_msgf(&rb_linebuf_id, ":%s %s", use_id(source_p), buf);
current_serial++;
rb_linebuf_newbuf(&linebuf);
va_start(args, pattern);
- rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
+ rb_linebuf_put_vmsg(&linebuf, pattern, &args);
va_end(args);
RB_DLINK_FOREACH(ptr, lclient_list.head)
rb_linebuf_newbuf(&linebuf);
va_start(args, pattern);
- rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
+ rb_linebuf_put_vmsg(&linebuf, pattern, &args);
va_end(args);
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, monptr->users.head)
if(MyClient(dest_p))
{
if(IsServer(source_p))
- rb_linebuf_putmsg(&linebuf, pattern, args, ":%s %s %s ",
+ rb_linebuf_put_vmsg_prefixf(&linebuf, pattern, args, ":%s %s %s ",
source_p->name, command,
target_p->name);
else
build_msgbuf_from(&msgbuf, source_p, command);
msgbuf.target = target_p->name;
- linebuf_put_msgvbuf(&msgbuf, &linebuf, dest_p->localClient->caps, pattern, args);
+ linebuf_put_tags_vprefix(&msgbuf, &linebuf, dest_p->localClient->caps, pattern, args);
}
}
else
- rb_linebuf_putmsg(&linebuf, pattern, args, ":%s %s %s ",
+ rb_linebuf_put_vmsg_prefixf(&linebuf, pattern, args, ":%s %s %s ",
get_id(source_p, target_p), command,
get_id(target_p, target_p));
va_start(args, pattern);
vsnprintf(buf, sizeof(buf), pattern, args);
va_end(args);
- rb_linebuf_putmsg(&linebuf, pattern, NULL,
+
+ rb_linebuf_put_msgf(&linebuf,
":%s NOTICE * :*** Notice -- %s", me.name, buf);
snobuf = construct_snobuf(flags);
if (snobuf[1] != '\0')
va_start(args, pattern);
vsnprintf(buf, sizeof(buf), pattern, args);
va_end(args);
- rb_linebuf_putmsg(&linebuf, pattern, NULL,
+
+ rb_linebuf_put_msgf(&linebuf,
":%s NOTICE * :*** Notice -- %s", me.name, buf);
sendto_one_notice(remote_rehash_oper_p, ":*** Notice -- %s", buf);
}
else
{
va_start(args, pattern);
- rb_linebuf_putmsg(&linebuf, pattern, &args,
+ rb_linebuf_put_vmsg_prefixf(&linebuf, pattern, &args,
":%s NOTICE * :*** Notice -- ", me.name);
va_end(args);
}
rb_linebuf_newbuf(&linebuf);
va_start(args, pattern);
- rb_linebuf_putmsg(&linebuf, pattern, &args,
+ rb_linebuf_put_vmsg_prefixf(&linebuf, pattern, &args,
":%s NOTICE * :*** Notice -- ", source_p->name);
va_end(args);
va_start(args, pattern);
if(IsPerson(source_p))
- rb_linebuf_putmsg(&linebuf, pattern, &args,
+ rb_linebuf_put_vmsg_prefixf(&linebuf, pattern, &args,
":%s!%s@%s WALLOPS :", source_p->name,
source_p->username, source_p->host);
else
- rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s WALLOPS :", source_p->name);
+ rb_linebuf_put_vmsg_prefixf(&linebuf, pattern, &args, ":%s WALLOPS :", source_p->name);
va_end(args);
rb_linebuf_newbuf(&linebuf);
va_start(args, pattern);
- rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s KILL %s :",
+ rb_linebuf_put_vmsg_prefixf(&linebuf, pattern, &args, ":%s KILL %s :",
get_id(&me, target_p), get_id(diedie, target_p));
va_end(args);
vsnprintf(buf, sizeof(buf), pattern, args);
va_end(args);
- rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s KILL %s :%s",
+ rb_linebuf_put_msgf(&rb_linebuf_id, ":%s KILL %s :%s",
use_id(&me), use_id(target_p), buf);
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head)
/* If its full or terminated, ignore it */
bufline->raw = 0;
- lrb_assert(bufline->len <= LINEBUF_DATA_SIZE);
+ lrb_assert(bufline->len <= LINEBUF_SIZE);
if(bufline->terminated == 1)
return 0;
return -1;
/* This is the ~overflow case..This doesn't happen often.. */
- if(cpylen > (LINEBUF_DATA_SIZE - bufline->len))
+ if(cpylen > (LINEBUF_SIZE - bufline->len))
{
- cpylen = LINEBUF_DATA_SIZE - bufline->len;
+ cpylen = LINEBUF_SIZE - bufline->len;
memcpy(bufch, ch, cpylen);
- bufline->buf[LINEBUF_DATA_SIZE] = '\0';
- bufch = bufline->buf + LINEBUF_DATA_SIZE - 1;
+ bufline->buf[LINEBUF_SIZE] = '\0';
+ bufch = bufline->buf + LINEBUF_SIZE - 1;
while(cpylen && (*bufch == '\r' || *bufch == '\n'))
{
*bufch = '\0';
bufch--;
}
bufline->terminated = 1;
- bufline->len = LINEBUF_DATA_SIZE;
- bufhead->len += LINEBUF_DATA_SIZE;
+ bufline->len = LINEBUF_SIZE;
+ bufhead->len += LINEBUF_SIZE;
return clen;
}
/* If its full or terminated, ignore it */
bufline->raw = 1;
- lrb_assert(bufline->len <= LINEBUF_DATA_SIZE);
+ lrb_assert(bufline->len <= LINEBUF_SIZE);
if(bufline->terminated == 1)
return 0;
return -1;
/* This is the overflow case..This doesn't happen often.. */
- if(cpylen > (LINEBUF_DATA_SIZE - bufline->len))
+ if(cpylen > (LINEBUF_SIZE - bufline->len))
{
- clen = LINEBUF_DATA_SIZE - bufline->len;
+ clen = LINEBUF_SIZE - bufline->len;
memcpy(bufch, ch, clen);
- bufline->buf[LINEBUF_DATA_SIZE] = '\0';
+ bufline->buf[LINEBUF_SIZE] = '\0';
bufline->terminated = 1;
- bufline->len = LINEBUF_DATA_SIZE;
- bufhead->len += LINEBUF_DATA_SIZE;
+ bufline->len = LINEBUF_SIZE;
+ bufhead->len += LINEBUF_SIZE;
return clen;
}
}
/*
- * rb_linebuf_putmsg
+ * rb_linebuf_put_vstr_vprefix
*
- * Similar to rb_linebuf_put, but designed for use by send.c.
+ * prefix (with/without prefix_args) is inserted first, then format/va_args is
+ * appended to the buffer.
*
- * prefixfmt is used as a format for the varargs, and is inserted first.
- * Then format/va_args is appended to the buffer.
+ * max_buflen is the maximum size of the buffer that can be used
+ * (including the NULL terminator) so that the RFC1459 message is not too long
*/
-void
-rb_linebuf_putmsg(buf_head_t * bufhead, const char *format, va_list * va_args,
- const char *prefixfmt, ...)
+static void
+rb_linebuf_put_vstr_vprefix(buf_head_t *bufhead, const char *format, va_list *format_args,
+ size_t max_buflen, const char *prefix, va_list *prefix_args)
{
buf_line_t *bufline;
- int len = 0;
- va_list prefix_args;
+ ssize_t len = 0;
/* make sure the previous line is terminated */
- if(bufhead->list.tail)
- {
+ if (bufhead->list.tail) {
bufline = bufhead->list.tail->data;
lrb_assert(bufline->terminated);
}
- /* Create a new line */
+ /* create a new line */
bufline = rb_linebuf_new_line(bufhead);
- if(prefixfmt != NULL)
- {
- va_start(prefix_args, prefixfmt);
- len = vsnprintf(bufline->buf, LINEBUF_DATA_SIZE + 1, prefixfmt, prefix_args);
- va_end(prefix_args);
- }
-
- if(va_args != NULL)
- {
- len += vsnprintf((bufline->buf + len), (LINEBUF_DATA_SIZE - len) + 1, format, *va_args);
- }
+ if (max_buflen > LINEBUF_SIZE + 1)
+ max_buflen = LINEBUF_SIZE + 1;
- bufline->terminated = 1;
+ if (prefix != NULL) {
+ if (prefix_args != NULL) {
+ len = vsnprintf(bufline->buf, max_buflen, prefix, *prefix_args);
+ } else {
+ len = rb_strlcpy(bufline->buf, prefix, max_buflen);
+ }
- /* Truncate the data if required */
- if(len > LINEBUF_DATA_SIZE)
- {
- len = LINEBUF_DATA_SIZE;
- bufline->buf[len++] = '\r';
- bufline->buf[len++] = '\n';
- }
- else if(len == 0)
- {
- bufline->buf[len++] = '\r';
- bufline->buf[len++] = '\n';
- bufline->buf[len] = '\0';
+ if (len > max_buflen - 1)
+ len = max_buflen - 1;
}
- else
- {
- /* Chop trailing CRLF's .. */
- while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n')
- || (bufline->buf[len] == '\0'))
- {
- len--;
- }
- bufline->buf[++len] = '\r';
- bufline->buf[++len] = '\n';
- bufline->buf[++len] = '\0';
+ if (format != NULL) {
+ len += vsnprintf(bufline->buf + len, max_buflen - len, format, *format_args);
+ if (len > max_buflen - 1)
+ len = max_buflen - 1;
}
+ /* add trailing CRLF */
+ bufline->buf[len++] = '\r';
+ bufline->buf[len++] = '\n';
+ bufline->buf[len] = '\0';
+
+ bufline->terminated = 1;
+
bufline->len = len;
bufhead->len += len;
}
/*
- * rb_linebuf_putprefix
+ * rb_linebuf_put_vtags_prefix
*
- * Similar to rb_linebuf_put, but designed for use by send.c.
+ * prefix is inserted first, then format/va_args is
+ * appended to the buffer.
*
- * prefix is inserted first, then format/va_args is appended to the buffer.
- * prefix_buflen is the maximum size of the buffer that can be used so that the RFC1459 message is not too long
+ * prefix_buflen is the maximum size of the buffer that can be used
+ * (including the NULL terminator) so that the RFC1459 message is not too long
*/
void
-rb_linebuf_putprefix(buf_head_t * bufhead, const char *format, va_list * va_args,
- const char *prefix, size_t prefix_buflen)
+rb_linebuf_put_vtags_prefix(buf_head_t *bufhead, const char *format, va_list *va_args,
+ size_t prefix_buflen, const char *prefix)
{
- buf_line_t *bufline;
- int len = 0;
-
- /* make sure the previous line is terminated */
- if(bufhead->list.tail)
- {
- bufline = bufhead->list.tail->data;
- lrb_assert(bufline->terminated);
- }
-
- /* Create a new line */
- bufline = rb_linebuf_new_line(bufhead);
-
- if(prefix != NULL)
- len = rb_strlcpy(bufline->buf, prefix, LINEBUF_DATA_SIZE + 1);
-
- if(va_args != NULL)
- {
- if (prefix_buflen > LINEBUF_DATA_SIZE + 1)
- prefix_buflen = LINEBUF_DATA_SIZE + 1;
- len += vsnprintf((bufline->buf + len), prefix_buflen - len, format, *va_args);
- }
-
- bufline->terminated = 1;
-
- /* Truncate the data if required */
- if(len > LINEBUF_DATA_SIZE)
- {
- len = LINEBUF_DATA_SIZE;
- bufline->buf[len++] = '\r';
- bufline->buf[len++] = '\n';
- }
- else if(len == 0)
- {
- bufline->buf[len++] = '\r';
- bufline->buf[len++] = '\n';
- bufline->buf[len] = '\0';
- }
- else
- {
- /* Chop trailing CRLF's .. */
- while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n')
- || (bufline->buf[len] == '\0'))
- {
- len--;
- }
-
- bufline->buf[++len] = '\r';
- bufline->buf[++len] = '\n';
- bufline->buf[++len] = '\0';
- }
-
- bufline->len = len;
- bufhead->len += len;
+ rb_linebuf_put_vstr_vprefix(bufhead, format, va_args, prefix_buflen, prefix, NULL);
}
+/*
+ * rb_linebuf_put_vtags_prefixf
+ *
+ * prefixfmt is inserted first, then format/va_args is
+ * appended to the buffer.
+ *
+ * prefix_buflen is the maximum size of the buffer that can be used
+ * (including the NULL terminator) so that the RFC1459 message is not too long
+ */
void
-rb_linebuf_putbuf(buf_head_t * bufhead, const char *buffer)
+rb_linebuf_put_vtags_prefixf(buf_head_t *bufhead, const char *format, va_list *va_args,
+ size_t prefix_buflen, const char *prefixfmt, ...)
{
- buf_line_t *bufline;
- int len = 0;
-
- /* make sure the previous line is terminated */
- if(bufhead->list.tail)
- {
- bufline = bufhead->list.tail->data;
- lrb_assert(bufline->terminated);
- }
-
- /* Create a new line */
- bufline = rb_linebuf_new_line(bufhead);
-
- if(buffer != NULL)
- len = rb_strlcpy(bufline->buf, buffer, LINEBUF_DATA_SIZE + 1);
-
- bufline->terminated = 1;
-
- /* Truncate the data if required */
- if(len > LINEBUF_DATA_SIZE)
- {
- len = LINEBUF_DATA_SIZE;
- bufline->buf[len++] = '\r';
- bufline->buf[len++] = '\n';
- }
- else if(len == 0)
- {
- bufline->buf[len++] = '\r';
- bufline->buf[len++] = '\n';
- bufline->buf[len] = '\0';
- }
- else
- {
- /* Chop trailing CRLF's .. */
- while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n')
- || (bufline->buf[len] == '\0'))
- {
- len--;
- }
-
- bufline->buf[++len] = '\r';
- bufline->buf[++len] = '\n';
- bufline->buf[++len] = '\0';
- }
-
- bufline->len = len;
- bufhead->len += len;
-
+ va_list prefix_args;
+ va_start(prefix_args, prefixfmt);
+ rb_linebuf_put_vstr_vprefix(bufhead, format, va_args, prefix_buflen, prefixfmt, &prefix_args);
+ va_end(prefix_args);
}
+/*
+ * rb_linebuf_put_msgf
+ *
+ * format (with args) is appended to the buffer.
+ * Messages will be limited to the RFC1459 data length
+ */
void
-rb_linebuf_put(buf_head_t * bufhead, const char *format, ...)
+rb_linebuf_put_msgf(buf_head_t *bufhead, const char *format, ...)
{
- buf_line_t *bufline;
- int len = 0;
- va_list args;
-
- /* make sure the previous line is terminated */
- if(bufhead->list.tail)
- {
- bufline = bufhead->list.tail->data;
- lrb_assert(bufline->terminated);
- }
+ va_list va_args;
- /* Create a new line */
- bufline = rb_linebuf_new_line(bufhead);
-
- if(format != NULL)
- {
- va_start(args, format);
- len = vsnprintf(bufline->buf, LINEBUF_DATA_SIZE + 1, format, args);
- va_end(args);
- }
-
- bufline->terminated = 1;
+ va_start(va_args, format);
+ rb_linebuf_put_vstr_vprefix(bufhead, format, &va_args, LINEBUF_DATALEN + 1, NULL, NULL);
+ va_end(va_args);
+}
- /* Truncate the data if required */
- if(len > LINEBUF_DATA_SIZE)
- {
- len = LINEBUF_DATA_SIZE;
- bufline->buf[len++] = '\r';
- bufline->buf[len++] = '\n';
- }
- else if(len == 0)
- {
- bufline->buf[len++] = '\r';
- bufline->buf[len++] = '\n';
- bufline->buf[len] = '\0';
- }
- else
- {
- /* Chop trailing CRLF's .. */
- while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n')
- || (bufline->buf[len] == '\0'))
- {
- len--;
- }
+/*
+ * rb_linebuf_put_vmsg
+ *
+ * format/va_args is appended to the buffer.
+ * Messages will be limited to the RFC1459 data length
+ */
+void
+rb_linebuf_put_vmsg(buf_head_t *bufhead, const char *format, va_list *va_args)
+{
+ rb_linebuf_put_vstr_vprefix(bufhead, format, va_args, LINEBUF_DATALEN + 1, NULL, NULL);
+}
- bufline->buf[++len] = '\r';
- bufline->buf[++len] = '\n';
- bufline->buf[++len] = '\0';
- }
+/*
+ * rb_linebuf_put_vmsg_prefixf
+ *
+ * prefix is inserted first, then format/va_args is appended to the buffer.
+ * Messages will be limited to the RFC1459 data length
+ */
+void
+rb_linebuf_put_vmsg_prefixf(buf_head_t *bufhead, const char *format, va_list *va_args,
+ const char *prefixfmt, ...)
+{
+ va_list prefix_args;
- bufline->len = len;
- bufhead->len += len;
+ va_start(prefix_args, prefixfmt);
+ rb_linebuf_put_vstr_vprefix(bufhead, format, va_args, LINEBUF_DATALEN + 1, prefixfmt, &prefix_args);
+ va_end(prefix_args);
}