root/src/noit_console.h

Revision b7ec8071a69b07dca745fa521b287c9f4ffec06e, 4.6 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 7 years ago)

SSL support that doesn't quite work -- so so so close.

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