libosmovty  0.6.3
Osmocom VTY library
vty.h
Go to the documentation of this file.
1 #ifndef _VTY_H
2 #define _VTY_H
3 
4 #include <stdio.h>
5 #include <stdarg.h>
6 
12 /* GCC have printf type attribute check. */
13 #ifdef __GNUC__
14 #define VTY_PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
15 #else
16 #define VTY_PRINTF_ATTRIBUTE(a,b)
17 #endif /* __GNUC__ */
18 
19 /* Does the I/O error indicate that the operation should be retried later? */
20 #define ERRNO_IO_RETRY(EN) \
21  (((EN) == EAGAIN) || ((EN) == EWOULDBLOCK) || ((EN) == EINTR))
22 
23 /* Vty read buffer size. */
24 #define VTY_READ_BUFSIZ 512
25 
26 #define VTY_BUFSIZ 512
27 #define VTY_MAXHIST 20
28 
30 enum event {
31  VTY_SERV,
32  VTY_READ,
33  VTY_WRITE,
34  VTY_CLOSED,
35  VTY_TIMEOUT_RESET,
36 #ifdef VTYSH
37  VTYSH_SERV,
38  VTYSH_READ,
39  VTYSH_WRITE
40 #endif /* VTYSH */
41 };
42 
43 enum vty_type {
44  VTY_TERM,
45  VTY_FILE,
46  VTY_SHELL,
47  VTY_SHELL_SERV
48 };
49 
51 struct vty {
53  FILE *file;
54 
56  void *priv;
57 
59  int fd;
60 
62  enum vty_type type;
63 
65  int node;
66 
68  int fail;
69 
71  struct buffer *obuf;
72 
74  char *buf;
75 
77  int cp;
78 
80  int length;
81 
83  int max;
84 
86  char *hist[VTY_MAXHIST];
87 
89  int hp;
90 
92  int hindex;
93 
96  void *index;
97 
99  void *index_sub;
100 
102  unsigned char escape;
103 
105  enum { VTY_NORMAL, VTY_CLOSE, VTY_MORE, VTY_MORELINE } status;
106 
112  unsigned char iac;
113 
115  unsigned char iac_sb_in_progress;
116  /* At the moment, we care only about the NAWS (window size) negotiation,
117  * and that requires just a 5-character buffer (RFC 1073):
118  * <NAWS char> <16-bit width> <16-bit height> */
119 #define TELNET_NAWS_SB_LEN 5
120 
121  unsigned char sb_buf[TELNET_NAWS_SB_LEN];
125  size_t sb_len;
126 
128  int width;
130  int height;
131 
133  int lines;
134 
135  int monitor;
136 
138  int config;
139 };
140 
141 /* Small macro to determine newline is newline only or linefeed needed. */
142 #define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\n")
143 
144 static inline const char *vty_newline(struct vty *vty)
145 {
146  return VTY_NEWLINE;
147 }
148 
150 struct vty_app_info {
152  const char *name;
154  const char *version;
156  const char *copyright;
158  void *tall_ctx;
160  enum node_type (*go_parent_cb)(struct vty *vty);
162  int (*is_config_node)(struct vty *vty, int node);
163 };
164 
165 /* Prototypes. */
166 void vty_init(struct vty_app_info *app_info);
167 int vty_read_config_file(const char *file_name, void *priv);
168 void vty_init_vtysh (void);
169 void vty_reset (void);
170 struct vty *vty_new (void);
171 struct vty *vty_create (int vty_sock, void *priv);
172 int vty_out (struct vty *, const char *, ...) VTY_PRINTF_ATTRIBUTE(2, 3);
173 int vty_out_newline(struct vty *);
174 int vty_read(struct vty *vty);
175 //void vty_time_print (struct vty *, int);
176 void vty_close (struct vty *);
177 char *vty_get_cwd (void);
178 void vty_log (const char *level, const char *proto, const char *fmt, va_list);
179 int vty_config_lock (struct vty *);
180 int vty_config_unlock (struct vty *);
181 int vty_shell (struct vty *);
182 int vty_shell_serv (struct vty *);
183 void vty_hello (struct vty *);
184 void *vty_current_index(struct vty *);
185 int vty_current_node(struct vty *vty);
186 enum node_type vty_go_parent(struct vty *vty);
187 
188 extern void *tall_vty_ctx;
189 
190 extern struct cmd_element cfg_description_cmd;
191 extern struct cmd_element cfg_no_description_cmd;
192 
195 #endif