]>
git.proxmox.com Git - mirror_frr.git/blob - lib/vty.h
1 /* Virtual terminal [aka TeletYpe] interface routine
2 Copyright (C) 1997 Kunihiro Ishiguro
4 This file is part of GNU Zebra.
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
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.
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
26 #define VTY_BUFSIZ 512
27 #define VTY_MAXHIST 20
32 /* File descripter of this vty. */
35 /* Is this vty connect to file or not */
36 enum {VTY_TERM
, VTY_FILE
, VTY_SHELL
, VTY_SHELL_SERV
} type
;
38 /* Node status of this vty */
41 /* What address is this vty comming from. */
44 /* Privilege level of this vty. */
53 /* Command input buffer */
56 /* Command cursor point */
62 /* Command max length. */
65 /* Histry of command */
66 char *hist
[VTY_MAXHIST
];
68 /* History lookup current point */
71 /* History insert end point */
74 /* For current referencing point of interface, route-map,
78 /* For multiple level index treatment such as key chain and key. */
81 /* For escape character. */
84 /* Current vty status. */
85 enum {VTY_NORMAL
, VTY_CLOSE
, VTY_MORE
, VTY_MORELINE
,
86 VTY_START
, VTY_CONTINUE
} status
;
92 unsigned char iac_sb_in_progress
;
93 struct buffer
*sb_buffer
;
95 /* Window width/height. */
101 /* Configure lines. */
104 /* Current executing function pointer. */
105 int (*func
) (struct vty
*, void *arg
);
107 /* Terminal monitor. */
110 /* In configure mode. */
113 /* Read and write thread. */
114 struct thread
*t_read
;
115 struct thread
*t_write
;
117 /* Timeout seconds and thread. */
118 unsigned long v_timeout
;
119 struct thread
*t_timeout
;
121 /* Thread output function. */
122 struct thread
*t_output
;
124 /* Output data pointer. */
125 int (*output_func
) (struct vty
*, int);
126 void (*output_clean
) (struct vty
*);
128 unsigned long output_count
;
133 /* Integrated configuration file. */
134 #define INTEGRATE_DEFAULT_CONFIG "Quagga.conf"
136 /* Small macro to determine newline is newline only or linefeed needed. */
137 #define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\n")
139 /* Default time out value */
140 #define VTY_TIMEOUT_DEFAULT 600
142 /* Vty read buffer size. */
143 #define VTY_READ_BUFSIZ 512
145 /* Directory separator. */
146 #ifndef DIRECTORY_SEP
147 #define DIRECTORY_SEP '/'
148 #endif /* DIRECTORY_SEP */
150 #ifndef IS_DIRECTORY_SEP
151 #define IS_DIRECTORY_SEP(c) ((c) == DIRECTORY_SEP)
154 /* GCC have printf type attribute check. */
156 #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
158 #define PRINTF_ATTRIBUTE(a,b)
159 #endif /* __GNUC__ */
161 /* Utility macro to convert VTY argument to unsigned integer. */
162 #define VTY_GET_INTEGER(NAME,V,STR) \
164 char *endptr = NULL; \
165 (V) = strtoul ((STR), &endptr, 10); \
166 if ((V) == ULONG_MAX || *endptr != '\0') \
168 vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
169 return CMD_WARNING; \
173 #define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX) \
175 char *endptr = NULL; \
176 (V) = strtoul ((STR), &endptr, 10); \
177 if ((V) == ULONG_MAX || *endptr != '\0' \
178 || (V) < (MIN) || (V) > (MAX)) \
180 vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
181 return CMD_WARNING; \
185 /* Exported variables */
186 extern char integrate_default
[];
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
*);
207 #endif /* _ZEBRA_VTY_H */