]> git.proxmox.com Git - mirror_frr.git/blob - lib/vty.h
2003-08-12 Paul Jakma <paul@dishone.st>
[mirror_frr.git] / lib / vty.h
1 /* Virtual terminal [aka TeletYpe] interface routine
2 Copyright (C) 1997 Kunihiro Ishiguro
3
4 This file is part of GNU Zebra.
5
6 GNU Zebra is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
10
11 GNU Zebra is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA. */
20
21 #ifndef _ZEBRA_VTY_H
22 #define _ZEBRA_VTY_H
23
24 #include "thread.h"
25
26 #define VTY_BUFSIZ 512
27 #define VTY_MAXHIST 20
28
29 /* VTY struct. */
30 struct vty
31 {
32 /* File descripter of this vty. */
33 int fd;
34
35 /* Is this vty connect to file or not */
36 enum {VTY_TERM, VTY_FILE, VTY_SHELL, VTY_SHELL_SERV} type;
37
38 /* Node status of this vty */
39 int node;
40
41 /* What address is this vty comming from. */
42 char *address;
43
44 /* Privilege level of this vty. */
45 int privilege;
46
47 /* Failure count */
48 int fail;
49
50 /* Output buffer. */
51 struct buffer *obuf;
52
53 /* Command input buffer */
54 char *buf;
55
56 /* Command cursor point */
57 int cp;
58
59 /* Command length */
60 int length;
61
62 /* Command max length. */
63 int max;
64
65 /* Histry of command */
66 char *hist[VTY_MAXHIST];
67
68 /* History lookup current point */
69 int hp;
70
71 /* History insert end point */
72 int hindex;
73
74 /* For current referencing point of interface, route-map,
75 access-list etc... */
76 void *index;
77
78 /* For multiple level index treatment such as key chain and key. */
79 void *index_sub;
80
81 /* For escape character. */
82 unsigned char escape;
83
84 /* Current vty status. */
85 enum {VTY_NORMAL, VTY_CLOSE, VTY_MORE, VTY_MORELINE,
86 VTY_START, VTY_CONTINUE} status;
87
88 /* IAC handling */
89 unsigned char iac;
90
91 /* IAC SB handling */
92 unsigned char iac_sb_in_progress;
93 struct buffer *sb_buffer;
94
95 /* Window width/height. */
96 int width;
97 int height;
98
99 int scroll_one;
100
101 /* Configure lines. */
102 int lines;
103
104 /* Current executing function pointer. */
105 int (*func) (struct vty *, void *arg);
106
107 /* Terminal monitor. */
108 int monitor;
109
110 /* In configure mode. */
111 int config;
112
113 /* Read and write thread. */
114 struct thread *t_read;
115 struct thread *t_write;
116
117 /* Timeout seconds and thread. */
118 unsigned long v_timeout;
119 struct thread *t_timeout;
120
121 /* Thread output function. */
122 struct thread *t_output;
123
124 /* Output data pointer. */
125 int (*output_func) (struct vty *, int);
126 void (*output_clean) (struct vty *);
127 void *output_rn;
128 unsigned long output_count;
129 int output_type;
130 void *output_arg;
131 };
132
133 /* Integrated configuration file. */
134 #define INTEGRATE_DEFAULT_CONFIG "Quagga.conf"
135
136 /* Small macro to determine newline is newline only or linefeed needed. */
137 #define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\n")
138
139 /* Default time out value */
140 #define VTY_TIMEOUT_DEFAULT 600
141
142 /* Vty read buffer size. */
143 #define VTY_READ_BUFSIZ 512
144
145 /* Directory separator. */
146 #ifndef DIRECTORY_SEP
147 #define DIRECTORY_SEP '/'
148 #endif /* DIRECTORY_SEP */
149
150 #ifndef IS_DIRECTORY_SEP
151 #define IS_DIRECTORY_SEP(c) ((c) == DIRECTORY_SEP)
152 #endif
153
154 /* GCC have printf type attribute check. */
155 #ifdef __GNUC__
156 #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
157 #else
158 #define PRINTF_ATTRIBUTE(a,b)
159 #endif /* __GNUC__ */
160
161 /* Utility macro to convert VTY argument to unsigned integer. */
162 #define VTY_GET_INTEGER(NAME,V,STR) \
163 { \
164 char *endptr = NULL; \
165 (V) = strtoul ((STR), &endptr, 10); \
166 if ((V) == ULONG_MAX || *endptr != '\0') \
167 { \
168 vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
169 return CMD_WARNING; \
170 } \
171 }
172
173 #define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX) \
174 { \
175 char *endptr = NULL; \
176 (V) = strtoul ((STR), &endptr, 10); \
177 if ((V) == ULONG_MAX || *endptr != '\0' \
178 || (V) < (MIN) || (V) > (MAX)) \
179 { \
180 vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
181 return CMD_WARNING; \
182 } \
183 }
184
185 /* Exported variables */
186 extern char integrate_default[];
187
188 /* Prototypes. */
189 void vty_init (struct thread_master *);
190 void vty_init_vtysh (void);
191 void vty_reset (void);
192 void vty_finish (void);
193 struct vty *vty_new (void);
194 int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
195 void vty_read_config (char *, char *, char *);
196 void vty_time_print (struct vty *, int);
197 void vty_serv_sock (const char *, unsigned short, char *);
198 void vty_close (struct vty *);
199 char *vty_get_cwd (void);
200 void vty_log (const char *, const char *, va_list);
201 int vty_config_lock (struct vty *);
202 int vty_config_unlock (struct vty *);
203 int vty_shell (struct vty *);
204 int vty_shell_serv (struct vty *);
205 void vty_hello (struct vty *);
206
207 #endif /* _ZEBRA_VTY_H */