root/src/noit_console.h

Revision 4cdbcdb30a697d3227b7be9d7deed71656552d22, 4.7 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 6 years ago)

partial match works. apply command works, needs range expansion which I'll lean on pcre for. Didn't have pcre on the plain -- so here we are.

  • 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 __noit_console_closure;
19
20 typedef int (*console_cmd_func_t)(struct __noit_console_closure *,
21                                   int, char **,
22                                   struct _console_state *, void *);
23 typedef char *(*console_prompt_func_t)(EditLine *);
24 typedef void (*state_free_func_t)(struct _console_state *);
25 typedef void (*state_userdata_free_func_t)(void *);
26
27 typedef struct {
28   const char            *name;
29   console_cmd_func_t     func;
30   struct _console_state *dstate;
31   void                  *closure;
32 } cmd_info_t;
33
34 /* This performs a pop (exiting if at toplevel) */
35 extern cmd_info_t console_command_exit;
36
37 typedef struct {
38   char                      *name;
39   void                      *data;
40   state_userdata_free_func_t freefunc;
41 } noit_console_userdata_t;
42
43 API_EXPORT(void)
44   noit_console_userdata_set(struct __noit_console_closure *,
45                             const char *name, void *data,
46                             state_userdata_free_func_t freefunc);
47 API_EXPORT(void *)
48   noit_console_userdata_get(struct __noit_console_closure *,
49                             const char *name);
50
51 typedef struct _console_state {
52   console_prompt_func_t      console_prompt_function;
53   /*noit_hash_table            cmds; */
54   noit_skiplist              cmds;
55   state_free_func_t          statefree;
56 } noit_console_state_t;
57
58 typedef struct _console_state_stack {
59   noit_console_state_t *state;
60   void *userdata;
61   struct _console_state_stack *last;
62 } noit_console_state_stack_t;
63
64 typedef struct __noit_console_closure {
65   int initialized;
66   eventer_t e;           /* The event it is attached to.  This
67                           * is needed so it can write itself out */
68   int   wants_shutdown;  /* Set this to 1 to have it die */
69
70   /* nice console support */
71   EditLine *el;
72   History *hist;
73   noit_hash_table userdata;
74
75   noit_console_state_stack_t *state_stack;
76
77   int   pty_master;
78   int   pty_slave;
79
80   /* Output buffer for non-blocking sends */
81   char *outbuf;
82   int   outbuf_allocd;
83   int   outbuf_len;
84   int   outbuf_cooked;
85   int   outbuf_completed;
86
87   /* This tracks telnet protocol state (if we're doing telnet) */
88   noit_console_telnet_closure_t telnet;
89   void (*output_cooker)(struct __noit_console_closure *);
90 } * noit_console_closure_t;
91
92 API_EXPORT(void) noit_console_init();
93
94 API_EXPORT(int)
95   noit_console_handler(eventer_t e, int mask, void *closure,
96                        struct timeval *now);
97
98
99 API_EXPORT(int)
100   nc_printf(noit_console_closure_t ncct, const char *fmt, ...);
101
102 API_EXPORT(int)
103   nc_vprintf(noit_console_closure_t ncct, const char *fmt, va_list arg);
104
105 API_EXPORT(int)
106   nc_write(noit_console_closure_t ncct, const void *buf, int len);
107
108 API_EXPORT(int)
109   noit_console_continue_sending(noit_console_closure_t ncct,
110                                 int *mask);
111
112 API_EXPORT(int)
113   noit_console_state_init(noit_console_closure_t ncct);
114
115 API_EXPORT(int)
116   noit_console_state_pop(noit_console_closure_t ncct, int argc, char **argv,
117                          noit_console_state_t *, void *);
118
119 API_EXPORT(int)
120   noit_console_state_add_cmd(noit_console_state_t *state,
121                              cmd_info_t *cmd);
122
123 API_EXPORT(cmd_info_t *)
124   noit_console_state_get_cmd(noit_console_state_t *state,
125                              const char *name);
126
127 API_EXPORT(noit_console_state_t *)
128   noit_console_state_build(console_prompt_func_t promptf, cmd_info_t **clist,
129                            state_free_func_t sfreef);
130
131 API_EXPORT(void)
132   noit_console_state_push_state(noit_console_closure_t ncct,
133                                 noit_console_state_t *);
134
135 API_EXPORT(noit_console_state_t *)
136   noit_console_state_initial();
137
138 API_EXPORT(noit_console_state_t *)
139   noit_console_state_alloc(void);
140
141 API_EXPORT(void)
142   noit_console_state_free(noit_console_state_t *st);
143
144 API_EXPORT(int)
145   noit_console_state_do(noit_console_closure_t ncct, int argc, char **argv);
146
147 API_EXPORT(int)
148   _noit_console_state_do(noit_console_closure_t ncct,
149                          noit_console_state_stack_t *stack,
150                          int argc, char **argv);
151
152 API_EXPORT(int)
153   noit_console_state_delegate(noit_console_closure_t ncct,
154                               int argc, char **argv,
155                               noit_console_state_t *dstate,
156                               void *closure);
157  
158 API_EXPORT(cmd_info_t *)
159   NCSCMD(const char *name, console_cmd_func_t func,
160          noit_console_state_t *dstate, void *closure);
161
162 #endif
Note: See TracBrowser for help on using the browser.