summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/vty.c25
-rw-r--r--lib/vty.h7
2 files changed, 32 insertions, 0 deletions
diff --git a/lib/vty.c b/lib/vty.c
index 9c58b50d..fa3f7718 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -90,6 +90,25 @@ static u_char restricted_mode = 0;
char integrate_default[] = SYSCONFDIR INTEGRATE_DEFAULT_CONFIG;
+void
+vty_prepend (struct vty *vty, const char *format, ...)
+{
+ va_list args;
+
+ va_start (args, format);
+ vsnprintf (vty->prepend + vty->prepend_pos,
+ sizeof(vty->prepend) - vty->prepend_pos,
+ format, args);
+ vty->prepend_pos = strlen (vty->prepend);
+ va_end (args);
+}
+
+void
+vty_unprepend (struct vty *vty)
+{
+ vty->prepend_pos = 0;
+}
+
/* VTY standard output function. */
int
vty_out (struct vty *vty, const char *format, ...)
@@ -100,6 +119,12 @@ vty_out (struct vty *vty, const char *format, ...)
char buf[1024];
char *p = NULL;
+ if (vty->prepend_pos)
+ {
+ vty->prepend_pos = 0;
+ vty_out (vty, "%s", vty->prepend);
+ }
+
if (vty_shell (vty))
{
va_start (args, format);
diff --git a/lib/vty.h b/lib/vty.h
index 7df04b5f..d8f47d86 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -118,6 +118,10 @@ struct vty
/* Timeout seconds and thread. */
unsigned long v_timeout;
struct thread *t_timeout;
+
+ /* Auto-prepending; any vty_out will print this buffer, then clear it: */
+ int prepend_pos;
+ char prepend[1024];
};
/* Integrated configuration file. */
@@ -207,6 +211,9 @@ extern void vty_terminate (void);
extern void vty_reset (void);
extern struct vty *vty_new (void);
extern int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
+extern void vty_prepend (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
+extern void vty_unprepend (struct vty *);
+#define vty_prepending(v) ((v)->prepend_pos)
extern void vty_read_config (char *, char *);
extern void vty_time_print (struct vty *, int);
extern void vty_serv_sock (const char *, unsigned short, const char *);