1 |
13da9a6f
|
(no author)
|
#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 |
|
|
|
24 |
|
|
struct vty {
|
25 |
|
|
FILE *file;
|
26 |
|
|
|
27 |
|
|
/* File descripter of this vty. */
|
28 |
|
|
int fd;
|
29 |
|
|
|
30 |
|
|
/* Is this vty connect to file or not */
|
31 |
|
|
enum { VTY_TERM, VTY_FILE, VTY_SHELL, VTY_SHELL_SERV } type;
|
32 |
|
|
|
33 |
|
|
/* Node status of this vty */
|
34 |
|
|
int node;
|
35 |
|
|
|
36 |
|
|
/* Failure count */
|
37 |
|
|
int fail;
|
38 |
|
|
|
39 |
|
|
/* Output buffer. */
|
40 |
|
|
struct buffer *obuf;
|
41 |
|
|
|
42 |
|
|
/* Command input buffer */
|
43 |
|
|
char *buf;
|
44 |
|
|
|
45 |
|
|
/* Command cursor point */
|
46 |
|
|
int cp;
|
47 |
|
|
|
48 |
|
|
/* Command length */
|
49 |
|
|
int length;
|
50 |
|
|
|
51 |
|
|
/* Command max length. */
|
52 |
|
|
int max;
|
53 |
|
|
|
54 |
|
|
/* Histry of command */
|
55 |
|
|
char *hist[VTY_MAXHIST];
|
56 |
|
|
|
57 |
|
|
/* History lookup current point */
|
58 |
|
|
int hp;
|
59 |
|
|
|
60 |
|
|
/* History insert end point */
|
61 |
|
|
int hindex;
|
62 |
|
|
|
63 |
|
|
/* For current referencing point of interface, route-map,
|
64 |
|
|
access-list etc... */
|
65 |
|
|
void *index;
|
66 |
|
|
|
67 |
|
|
/* For multiple level index treatment such as key chain and key. */
|
68 |
|
|
void *index_sub;
|
69 |
|
|
|
70 |
|
|
/* For escape character. */
|
71 |
|
|
unsigned char escape;
|
72 |
|
|
|
73 |
|
|
/* Current vty status. */
|
74 |
|
|
enum { VTY_NORMAL, VTY_CLOSE, VTY_MORE, VTY_MORELINE } status;
|
75 |
|
|
|
76 |
|
|
/* Window width/height. */
|
77 |
|
|
int width;
|
78 |
|
|
int height;
|
79 |
|
|
|
80 |
|
|
/* Configure lines. */
|
81 |
|
|
int lines;
|
82 |
|
|
|
83 |
|
|
int monitor;
|
84 |
|
|
|
85 |
|
|
/* In configure mode. */
|
86 |
|
|
int config;
|
87 |
|
|
};
|
88 |
|
|
|
89 |
|
|
/* Small macro to determine newline is newline only or linefeed needed. */
|
90 |
|
|
#define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\n")
|
91 |
|
|
|
92 |
|
|
static inline char *vty_newline(struct vty *vty)
|
93 |
|
|
{
|
94 |
|
|
return VTY_NEWLINE;
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
/* Prototypes. */
|
98 |
|
|
void vty_init (void);
|
99 |
|
|
void vty_init_vtysh (void);
|
100 |
|
|
void vty_reset (void);
|
101 |
|
|
struct vty *vty_new (void);
|
102 |
|
|
struct vty *vty_create (int vty_sock);
|
103 |
|
|
int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
|
104 |
|
|
int vty_out_newline(struct vty *);
|
105 |
|
|
int vty_read(struct vty *vty);
|
106 |
|
|
void vty_read_config (char *, char *);
|
107 |
|
|
void vty_time_print (struct vty *, int);
|
108 |
|
|
void vty_close (struct vty *);
|
109 |
|
|
char *vty_get_cwd (void);
|
110 |
|
|
void vty_log (const char *level, const char *proto, const char *fmt, va_list);
|
111 |
|
|
int vty_config_lock (struct vty *);
|
112 |
|
|
int vty_config_unlock (struct vty *);
|
113 |
|
|
int vty_shell (struct vty *);
|
114 |
|
|
int vty_shell_serv (struct vty *);
|
115 |
|
|
void vty_hello (struct vty *);
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
#endif
|