blob: 4bb785b9ff1ab9652a67b20681aa147744db12bc [file] [log] [blame]
Harald Welte955049f2009-03-10 12:16:51 +00001#ifndef _VTY_H
2#define _VTY_H
3
4#include <stdio.h>
5#include <stdarg.h>
6
7/* GCC have printf type attribute check. */
8#ifdef __GNUC__
9#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
10#else
11#define PRINTF_ATTRIBUTE(a,b)
12#endif /* __GNUC__ */
13
14/* Does the I/O error indicate that the operation should be retried later? */
15#define ERRNO_IO_RETRY(EN) \
16 (((EN) == EAGAIN) || ((EN) == EWOULDBLOCK) || ((EN) == EINTR))
17
18/* Vty read buffer size. */
19#define VTY_READ_BUFSIZ 512
20
21#define VTY_BUFSIZ 512
22#define VTY_MAXHIST 20
23
Harald Weltec63e51d2009-03-10 19:46:16 +000024/* Vty events */
25enum event {
26 VTY_SERV,
27 VTY_READ,
28 VTY_WRITE,
29 VTY_TIMEOUT_RESET,
30#ifdef VTYSH
31 VTYSH_SERV,
32 VTYSH_READ,
33 VTYSH_WRITE
34#endif /* VTYSH */
35};
36
Harald Welte955049f2009-03-10 12:16:51 +000037struct vty {
38 FILE *file;
39
Harald Weltec63e51d2009-03-10 19:46:16 +000040 /* private data, specified by creator */
41 void *priv;
42
Harald Welte955049f2009-03-10 12:16:51 +000043 /* File descripter of this vty. */
44 int fd;
45
46 /* Is this vty connect to file or not */
47 enum { VTY_TERM, VTY_FILE, VTY_SHELL, VTY_SHELL_SERV } type;
48
49 /* Node status of this vty */
50 int node;
51
52 /* Failure count */
53 int fail;
54
55 /* Output buffer. */
56 struct buffer *obuf;
57
58 /* Command input buffer */
59 char *buf;
60
61 /* Command cursor point */
62 int cp;
63
64 /* Command length */
65 int length;
66
67 /* Command max length. */
68 int max;
69
70 /* Histry of command */
71 char *hist[VTY_MAXHIST];
72
73 /* History lookup current point */
74 int hp;
75
76 /* History insert end point */
77 int hindex;
78
79 /* For current referencing point of interface, route-map,
80 access-list etc... */
81 void *index;
82
83 /* For multiple level index treatment such as key chain and key. */
84 void *index_sub;
85
86 /* For escape character. */
87 unsigned char escape;
88
89 /* Current vty status. */
90 enum { VTY_NORMAL, VTY_CLOSE, VTY_MORE, VTY_MORELINE } status;
91
92 /* IAC handling: was the last character received the IAC
93 * (interpret-as-command) escape character (and therefore the next
94 * character will be the command code)? Refer to Telnet RFC 854. */
95 unsigned char iac;
96
97 /* IAC SB (option subnegotiation) handling */
98 unsigned char iac_sb_in_progress;
99 /* At the moment, we care only about the NAWS (window size) negotiation,
100 * and that requires just a 5-character buffer (RFC 1073):
101 * <NAWS char> <16-bit width> <16-bit height> */
102#define TELNET_NAWS_SB_LEN 5
103 unsigned char sb_buf[TELNET_NAWS_SB_LEN];
104 /* How many subnegotiation characters have we received? We just drop
105 * those that do not fit in the buffer. */
106 size_t sb_len;
107
108 /* Window width/height. */
109 int width;
110 int height;
111
112 /* Configure lines. */
113 int lines;
114
115 int monitor;
116
117 /* In configure mode. */
118 int config;
119};
120
121/* Small macro to determine newline is newline only or linefeed needed. */
122#define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\n")
123
124static inline char *vty_newline(struct vty *vty)
125{
126 return VTY_NEWLINE;
127}
128
129/* Prototypes. */
130void vty_init (void);
131void vty_init_vtysh (void);
132void vty_reset (void);
133struct vty *vty_new (void);
Harald Weltec63e51d2009-03-10 19:46:16 +0000134struct vty *vty_create (int vty_sock, void *priv);
Harald Welte955049f2009-03-10 12:16:51 +0000135int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
136int vty_out_newline(struct vty *);
137int vty_read(struct vty *vty);
138void vty_read_config (char *, char *);
139void vty_time_print (struct vty *, int);
140void vty_close (struct vty *);
141char *vty_get_cwd (void);
142void vty_log (const char *level, const char *proto, const char *fmt, va_list);
143int vty_config_lock (struct vty *);
144int vty_config_unlock (struct vty *);
145int vty_shell (struct vty *);
146int vty_shell_serv (struct vty *);
147void vty_hello (struct vty *);
148
149
150#endif