root/src/noit_console.h

Revision c207a54267f04ddc789cd4197932711153e43d9b, 6.5 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 5 years ago)

fix the console line

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  */
5
6 #ifndef _NOIT_CONSOLE_H
7 #define _NOIT_CONSOLE_H
8
9 #include "noit_defines.h"
10 #include "eventer/eventer.h"
11 #include "noitedit/histedit.h"
12 #include "noit_console_telnet.h"
13 #include "utils/noit_hash.h"
14 #include "utils/noit_skiplist.h"
15 #include <stdarg.h>
16
17 struct _console_state;
18 struct _console_state_stack;
19 struct __noit_console_closure;
20
21 typedef int (*console_cmd_func_t)(struct __noit_console_closure *,
22                                   int, char **,
23                                   struct _console_state *, void *);
24 typedef char * (*console_opt_func_t)(struct __noit_console_closure *,
25                                      struct _console_state_stack *stack,
26                                      struct _console_state *state,
27                                      int argc, char **argv,
28                                      int idx);
29 typedef char *(*console_prompt_func_t)(EditLine *);
30 typedef void (*state_free_func_t)(struct _console_state *);
31 typedef void (*state_userdata_free_func_t)(void *);
32
33 typedef struct {
34   const char            *name;
35   console_cmd_func_t     func;
36   console_opt_func_t     autocomplete;
37   struct _console_state *dstate;
38   void                  *closure;
39 } cmd_info_t;
40
41 /* This performs a pop (exiting if at toplevel) */
42 extern cmd_info_t console_command_exit;
43 extern cmd_info_t console_command_help;
44 extern cmd_info_t console_command_shutdown;
45 extern cmd_info_t console_command_restart;
46
47 typedef struct {
48   char                      *name;
49   void                      *data;
50   state_userdata_free_func_t freefunc;
51 } noit_console_userdata_t;
52
53 API_EXPORT(void)
54   noit_console_userdata_set(struct __noit_console_closure *,
55                             const char *name, void *data,
56                             state_userdata_free_func_t freefunc);
57 API_EXPORT(void *)
58   noit_console_userdata_get(struct __noit_console_closure *,
59                             const char *name);
60
61 typedef struct _console_state {
62   console_prompt_func_t      console_prompt_function;
63   /*noit_hash_table            cmds; */
64   noit_skiplist              cmds;
65   state_free_func_t          statefree;
66 } noit_console_state_t;
67
68 typedef struct _console_state_stack {
69   char *name;
70   noit_console_state_t *state;
71   void *userdata;
72   struct _console_state_stack *last;
73 } noit_console_state_stack_t;
74
75 typedef struct __noit_console_closure {
76   int initialized;
77   char feed_path[128];
78   eventer_t e;           /* The event it is attached to.  This
79                           * is needed so it can write itself out */
80   int   wants_shutdown;  /* Set this to 1 to have it die */
81
82   /* nice console support */
83   EditLine *el;
84   History *hist;
85   noit_hash_table userdata;
86   /* This is console completion magic */
87   int noit_edit_complete_cmdnum;
88   int rl_point;
89   int rl_end;
90
91   noit_console_state_stack_t *state_stack;
92
93   int   pty_master;
94   int   pty_slave;
95
96   /* Output buffer for non-blocking sends */
97   char *outbuf;
98   int   outbuf_allocd;
99   int   outbuf_len;
100   int   outbuf_cooked;
101   int   outbuf_completed;
102
103   /* This tracks telnet protocol state (if we're doing telnet) */
104   noit_console_telnet_closure_t telnet;
105   void (*output_cooker)(struct __noit_console_closure *);
106 } * noit_console_closure_t;
107
108 API_EXPORT(void) noit_console_init(const char *);
109
110 API_EXPORT(void) noit_console_set_default_prompt(const char *);
111
112 API_EXPORT(int)
113   noit_console_handler(eventer_t e, int mask, void *closure,
114                        struct timeval *now);
115
116
117 API_EXPORT(int)
118   nc_printf(noit_console_closure_t ncct, const char *fmt, ...);
119
120 API_EXPORT(int)
121   nc_vprintf(noit_console_closure_t ncct, const char *fmt, va_list arg);
122
123 API_EXPORT(int)
124   nc_write(noit_console_closure_t ncct, const void *buf, int len);
125
126 API_EXPORT(int)
127   noit_console_continue_sending(noit_console_closure_t ncct,
128                                 int *mask);
129
130 API_EXPORT(int)
131   noit_console_state_init(noit_console_closure_t ncct);
132
133 API_EXPORT(int)
134   noit_console_state_pop(noit_console_closure_t ncct, int argc, char **argv,
135                          noit_console_state_t *, void *);
136
137 API_EXPORT(int)
138   noit_console_help(noit_console_closure_t ncct, int argc, char **argv,
139                     noit_console_state_t *, void *);
140
141 API_EXPORT(int)
142   noit_console_shutdown(noit_console_closure_t ncct, int argc, char **argv,
143                         noit_console_state_t *, void *);
144
145 API_EXPORT(int)
146   noit_console_restart(noit_console_closure_t ncct, int argc, char **argv,
147                        noit_console_state_t *, void *);
148
149 API_EXPORT(int)
150   noit_console_state_add_cmd(noit_console_state_t *state,
151                              cmd_info_t *cmd);
152
153 API_EXPORT(cmd_info_t *)
154   noit_console_state_get_cmd(noit_console_state_t *state,
155                              const char *name);
156
157 API_EXPORT(noit_console_state_t *)
158   noit_console_state_build(console_prompt_func_t promptf, cmd_info_t **clist,
159                            state_free_func_t sfreef);
160
161 API_EXPORT(void)
162   noit_console_state_push_state(noit_console_closure_t ncct,
163                                 noit_console_state_t *);
164
165 API_EXPORT(noit_console_state_t *)
166   noit_console_state_initial();
167
168 API_EXPORT(noit_console_state_t *)
169   noit_console_state_alloc(void);
170
171 API_EXPORT(void)
172   noit_console_state_free(noit_console_state_t *st);
173
174 API_EXPORT(int)
175   noit_console_state_do(noit_console_closure_t ncct, int argc, char **argv);
176
177 API_EXPORT(int)
178   _noit_console_state_do(noit_console_closure_t ncct,
179                          noit_console_state_stack_t *stack,
180                          int argc, char **argv);
181
182 API_EXPORT(int)
183   noit_console_state_delegate(noit_console_closure_t ncct,
184                               int argc, char **argv,
185                               noit_console_state_t *dstate,
186                               void *closure);
187  
188 API_EXPORT(cmd_info_t *)
189   NCSCMD(const char *name, console_cmd_func_t func, console_opt_func_t ac,
190          noit_console_state_t *dstate, void *closure);
191
192 API_EXPORT(int)
193   noit_console_write_xml(void *vncct, const char *buffer, int len);
194
195 API_EXPORT(int)
196   noit_console_close_xml(void *vncct);
197
198 API_EXPORT(void)
199   noit_console_add_help(const char *topic, console_cmd_func_t topic_func,
200                         console_opt_func_t autocomplete);
201
202 API_EXPORT(unsigned char)
203   noit_edit_complete(EditLine *el, int invoking_key);
204
205 API_EXPORT(char *)
206   noit_console_opt_delegate(noit_console_closure_t ncct,
207                             noit_console_state_stack_t *stack,
208                             noit_console_state_t *state,
209                             int argc, char **argv,
210                             int idx);
211
212 #endif
Note: See TracBrowser for help on using the browser.