buffer_put(b, c, strlen(c));
}
+/* Expand \n to \r\n */
+void
+buffer_put_crlf(struct buffer *b, const void *origp, size_t origsize)
+{
+ struct buffer_data *data = b->tail;
+ const char *p = origp, *end = p + origsize, *lf;
+ size_t size;
+
+ lf = memchr(p, '\n', end - p);
+
+ /* We use even last one byte of data buffer. */
+ while (p < end)
+ {
+ size_t avail, chunk;
+
+ /* If there is no data buffer add it. */
+ if (data == NULL || data->cp == b->size)
+ data = buffer_add (b);
+
+ size = (lf ? lf : end) - p;
+ avail = b->size - data->cp;
+
+ chunk = (size <= avail) ? size : avail;
+ memcpy (data->data + data->cp, p, chunk);
+
+ p += chunk;
+ data->cp += chunk;
+
+ if (lf && size <= avail)
+ {
+ /* we just copied up to (including) a '\n' */
+ if (data->cp == b->size)
+ data = buffer_add (b);
+ data->data[data->cp++] = '\r';
+ if (data->cp == b->size)
+ data = buffer_add (b);
+ data->data[data->cp++] = '\n';
+
+ p++;
+ lf = memchr(p, '\n', end - p);
+ }
+ }
+}
+
/* Keep flushing data to the fd until the buffer is empty or an error is
encountered or the operation would block. */
buffer_status_t
extern void buffer_putc (struct buffer *, u_char);
/* Add a NUL-terminated string to the end of the buffer. */
extern void buffer_putstr (struct buffer *, const char *);
+/* Add given data, inline-expanding \n to \r\n */
+extern void buffer_put_crlf(struct buffer *b, const void *p, size_t size);
/* Combine all accumulated (and unflushed) data inside the buffer into a
single NUL-terminated string allocated using XMALLOC(MTYPE_TMP). Note
static int do_log_commands = 0;
-static int
-vty_out_variadic (struct vty *vty, const char *format, va_list args)
+/* VTY standard output function. */
+int
+vty_out (struct vty *vty, const char *format, ...)
{
+ va_list args;
int len = 0;
int size = 1024;
char buf[1024];
char *p = NULL;
- va_list cp;
if (vty_shell (vty))
- vprintf (format, args);
+ {
+ va_start (args, format);
+ vprintf (format, args);
+ va_end (args);
+ }
else
{
/* Try to write to initial buffer. */
- va_copy (cp, args);
- len = vsnprintf (buf, sizeof(buf), format, cp);
- va_end (cp);
+ va_start (args, format);
+ len = vsnprintf (buf, sizeof(buf), format, args);
+ va_end (args);
/* Initial buffer is not enough. */
if (len < 0 || len >= size)
if (! p)
return -1;
- va_copy (cp, args);
- len = vsnprintf (p, size, format, cp);
- va_end (cp);
+ va_start (args, format);
+ len = vsnprintf (p, size, format, args);
+ va_end (args);
if (len > -1 && len < size)
break;
p = buf;
/* Pointer p must point out buffer. */
- buffer_put (vty->obuf, (u_char *) p, len);
+ if (vty->type != VTY_TERM)
+ buffer_put (vty->obuf, (u_char *) p, len);
+ else
+ buffer_put_crlf (vty->obuf, (u_char *) p, len);
/* If p is not different with buf, it is allocated buffer. */
if (p != buf)
return len;
}
-/* VTY standard output function. */
-int
-vty_out (struct vty *vty, const char *format, ...)
-{
- int len;
- va_list args;
-
- va_start (args, format);
- len = vty_out_variadic (vty, format, args);
- va_end (args);
-
- return len;
-}
-
-int
-vty_outln (struct vty *vty, const char *format, ...)
-{
- int len;
- va_list args;
-
- va_start (args, format);
- len = vty_out_variadic (vty, format, args);
- va_end (args);
-
- return len + vty_out (vty, "%s", VTYNL);
-}
static int
vty_log_out (struct vty *vty, const char *level, const char *proto_str,
/* Integrated configuration file. */
#define INTEGRATE_DEFAULT_CONFIG "frr.conf"
-/* Small macro to determine newline is newline only or linefeed needed. */
-#define VTYNL ((vty->type == VTY_TERM) ? "\r\n" : "\n")
-
/* for compatibility */
#if defined(__ICC)
#define CPP_WARN_STR(X) #X
#define CPP_WARN(text)
#endif
-#define VTY_NEWLINE VTYNL \
- CPP_WARN("VTY_NEWLINE has been replaced with VTYNL and/or vty_outln().")
+#define VNL "\n" \
+/* CPP_WARN("VNL has been replaced with \\n.") */
+#define VTYNL "\n" \
+/* CPP_WARN("VTYNL has been replaced with \\n.") */
+#define VTY_NEWLINE "\n" \
+ CPP_WARN("VTY_NEWLINE has been replaced with \\n.")
#define VTY_GET_INTEGER(desc,v,str) {(v)=strtoul ((str), NULL, 10);} \
CPP_WARN("VTY_GET_INTEGER is no longer useful, use strtoul() or DEFPY.")
#define VTY_GET_INTEGER_RANGE(desc,v,str,min,max) {(v)=strtoul ((str), NULL, 10);} \
CPP_WARN("VTY_GET_IPV4_ADDRESS is no longer useful, use inet_aton() or DEFPY.")
#define VTY_GET_IPV4_PREFIX(desc,v,str) str2prefix_ipv4 ((str), &(v)) \
CPP_WARN("VTY_GET_IPV4_PREFIX is no longer useful, use str2prefix_ipv4() or DEFPY.")
+#define vty_outln(vty, str, ...) \
+ vty_out(vty, str "\n", ## __VA_ARGS__) \
+/* CPP_WARN("vty_outln is no longer useful, use vty_out(...\\n...)") */
/* Default time out value */
#define VTY_TIMEOUT_DEFAULT 600
extern struct vty *vty_new (void);
extern struct vty *vty_stdio (void (*atclose)(void));
extern int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
-extern int vty_outln (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
extern void vty_read_config (const char *, char *);
extern void vty_time_print (struct vty *, int);
extern void vty_serv_sock (const char *, unsigned short, const char *);
#define OSPF6_ROUTER_ID_STR "Specify Router-ID\n"
#define OSPF6_LS_ID_STR "Specify Link State ID\n"
-#define VNL VTYNL
#define OSPF6_CMD_CHECK_RUNNING() \
if (ospf6 == NULL) \
{ \