Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

klish / clish / shell.h @ b683ac25

History | View | Annotate | Download (9.16 KB)

1
/*
2
 * shell.h
3
 */
4
 /**
5
\ingroup clish
6
\defgroup clish_shell shell
7
@{
8

9
\brief This class represents the top level container for a CLI session.
10

11
*/
12
#ifndef _clish_shell_h
13
#define _clish_shell_h
14

    
15
#include <stdio.h>
16
#include <sys/types.h>
17
#include <pwd.h>
18

    
19
#include "lub/c_decl.h"
20
#include "lub/types.h"
21
#include "lub/argv.h"
22
#include "tinyrl/tinyrl.h"
23
#include "clish/view.h"
24
#include "clish/ptype.h"
25
#include "clish/var.h"
26
#include "clish/plugin.h"
27
#include "konf/net.h"
28

    
29
#define CLISH_LOCK_PATH "/tmp/clish.lock"
30
#define CLISH_LOCK_WAIT 20
31

    
32
#define CLISH_STDOUT_CHUNK 1024
33
#define CLISH_STDOUT_MAXBUF (CLISH_STDOUT_CHUNK * 1024)
34

    
35
#define CLISH_XML_ERROR_STR "Error parsing XML: "
36
#define CLISH_XML_ERROR_ATTR(attr) CLISH_XML_ERROR_STR"The \""attr"\" attribute is required.\n"
37

    
38
typedef struct clish_shell_s clish_shell_t;
39
typedef struct clish_context_s clish_context_t;
40

    
41
/* Context functions */
42
_BEGIN_C_DECL
43
clish_context_t *clish_context_new(clish_shell_t *shell);
44
int clish_context_init(clish_context_t *instance, clish_shell_t *shell);
45
void clish_context_free(clish_context_t *instance);
46
clish_shell_t *clish_context__get_shell(const void *instance);
47
void clish_context__set_cmd(void *instance, const clish_command_t *cmd);
48
const clish_command_t *clish_context__get_cmd(const void *instance);
49
void clish_context__set_pargv(void *instance, clish_pargv_t *pargv);
50
clish_pargv_t *clish_context__get_pargv(const void *instance);
51
void clish_context__set_action(void *instance, const clish_action_t *action);
52
const clish_action_t *clish_context__get_action(const void *instance);
53
_END_C_DECL
54

    
55
/* Shell */
56
typedef enum {
57
        SHELL_STATE_OK = 0,
58
        SHELL_STATE_UNKNOWN = 1,
59
        SHELL_STATE_IO_ERROR = 2,
60
        SHELL_STATE_SCRIPT_ERROR = 3,/* Script execution error */
61
        SHELL_STATE_SYNTAX_ERROR = 4, /* Illegal line entered */
62
        SHELL_STATE_SYSTEM_ERROR = 5, /* Some internal system error */
63
        SHELL_STATE_INITIALISING = 6,
64
        SHELL_STATE_HELPING = 7,
65
        SHELL_STATE_EOF = 8, /* EOF of input stream */
66
        SHELL_STATE_CLOSING = 9
67
} clish_shell_state_e;
68

    
69
typedef enum {
70
        SHELL_VAR_NONE, /* Nothing to escape */
71
        SHELL_VAR_ACTION, /* Variable expanding for ACTION script */
72
        SHELL_VAR_REGEX /* Variable expanding for regex usage */
73
} clish_shell_var_t;
74

    
75
typedef enum {
76
        SHELL_EXPAND_PARAM = 1,
77
        SHELL_EXPAND_VIEW = 2,
78
        SHELL_EXPAND_CONTEXT = 4,
79
        SHELL_EXPAND_VAR = 8,
80
        SHELL_EXPAND_ENV = 16,
81
        SHELL_EXPAND_ALL = 255
82
} clish_shell_expand_e;
83

    
84
_BEGIN_C_DECL
85

    
86
/*-----------------
87
 * meta functions
88
 *----------------- */
89

    
90
clish_shell_t *clish_shell_new(FILE * istream, FILE * ostream,
91
        bool_t stop_on_error);
92
/*-----------------
93
 * methods
94
 *----------------- */
95
/*
96
 * Called to invoke the startup command for this shell
97
 */
98
int clish_shell_startup(clish_shell_t * instance);
99
void clish_shell_delete(clish_shell_t * instance);
100
clish_view_t *clish_shell_find_create_view(clish_shell_t * instance,
101
        const char *name,
102
        const char *prompt);
103
clish_ptype_t *clish_shell_find_create_ptype(clish_shell_t * instance,
104
        const char *name,
105
        const char *text,
106
        const char *pattern,
107
        clish_ptype_method_e method,
108
        clish_ptype_preprocess_e preprocess);
109
clish_ptype_t *clish_shell_find_ptype(clish_shell_t *instance,
110
        const char *name);
111
void clish_shell_help(clish_shell_t * instance, const char *line);
112
int clish_shell_exec_action(clish_context_t *context, char **out);
113
int clish_shell_execute(clish_context_t *context, char **out);
114
int clish_shell_forceline(clish_shell_t *instance, const char *line, char ** out);
115
int clish_shell_readline(clish_shell_t *instance, char ** out);
116
void clish_shell_dump(clish_shell_t * instance);
117
/**
118
 * Push the specified file handle on to the stack of file handles
119
 * for this shell. The specified file will become the source of 
120
 * commands, until it is exhausted.
121
 *
122
 * \return
123
 * BOOL_TRUE - the file was successfully associated with the shell.
124
 * BOOL_FALSE - there was insufficient resource to associate this file.
125
 */
126
int clish_shell_push_file(clish_shell_t * instance, const char * fname,
127
        bool_t stop_on_error);
128
int clish_shell_push_fd(clish_shell_t * instance, FILE * file,
129
        bool_t stop_on_error);
130
void clish_shell_insert_var(clish_shell_t *instance, clish_var_t *var);
131
clish_var_t *clish_shell_find_var(clish_shell_t *instance, const char *name);
132
char *clish_shell_expand_var(const char *name, clish_context_t *context);
133
char *clish_shell_expand_var_ex(const char *name, clish_context_t *context, clish_shell_expand_e flags);
134
char *clish_shell_expand(const char *str, clish_shell_var_t vtype, clish_context_t *context);
135

    
136
/*-----------------
137
 * attributes
138
 *----------------- */
139
clish_view_t *clish_shell__get_view(const clish_shell_t * instance);
140
unsigned int clish_shell__get_depth(const clish_shell_t * instance);
141
void clish_shell__set_depth(clish_shell_t *instance, unsigned int depth);
142
const char *clish_shell__get_viewid(const clish_shell_t * instance);
143
const char *clish_shell__get_overview(const clish_shell_t * instance);
144
tinyrl_t *clish_shell__get_tinyrl(const clish_shell_t * instance);
145
void clish_shell__set_pwd(clish_shell_t *instance, const char * line,
146
        clish_view_t * view, char * viewid, clish_context_t *context);
147
char *clish_shell__get_pwd_line(const clish_shell_t * instance,
148
         unsigned int index);
149
char *clish_shell__get_pwd_full(const clish_shell_t * instance,
150
        unsigned int depth);
151
clish_view_t *clish_shell__get_pwd_view(const clish_shell_t * instance,
152
        unsigned int index);
153
konf_client_t *clish_shell__get_client(const clish_shell_t * instance);
154
FILE *clish_shell__get_istream(const clish_shell_t * instance);
155
FILE *clish_shell__get_ostream(const clish_shell_t * instance);
156
void clish_shell__set_lockfile(clish_shell_t * instance, const char * path);
157
char * clish_shell__get_lockfile(clish_shell_t * instance);
158
int clish_shell__set_socket(clish_shell_t * instance, const char * path);
159
int clish_shell_load_scheme(clish_shell_t * instance, const char * xml_path, const char *xslt_path);
160
int clish_shell_loop(clish_shell_t * instance);
161
clish_shell_state_e clish_shell__get_state(const clish_shell_t * instance);
162
void clish_shell__set_state(clish_shell_t * instance,
163
        clish_shell_state_e state);
164
void clish_shell__set_startup_view(clish_shell_t * instance, const char * viewname);
165
void clish_shell__set_startup_viewid(clish_shell_t * instance, const char * viewid);
166
void clish_shell__set_default_shebang(clish_shell_t * instance, const char * shebang);
167
const char * clish_shell__get_default_shebang(const clish_shell_t * instance);
168
const char * clish_shell__get_fifo(clish_shell_t * instance);
169
void clish_shell__set_interactive(clish_shell_t * instance, bool_t interactive);
170
bool_t clish_shell__get_interactive(const clish_shell_t * instance);
171
bool_t clish_shell__get_utf8(const clish_shell_t * instance);
172
void clish_shell__set_utf8(clish_shell_t * instance, bool_t utf8);
173
void clish_shell__set_timeout(clish_shell_t *instance, int timeout);
174
char *clish_shell__get_line(clish_context_t *context);
175
char *clish_shell__get_full_line(clish_context_t *context);
176
char *clish_shell__get_params(clish_context_t *context);
177

    
178
/* Log functions */
179
void clish_shell__set_log(clish_shell_t *instance, bool_t log);
180
bool_t clish_shell__get_log(const clish_shell_t *instance);
181
void clish_shell__set_facility(clish_shell_t *instance, int facility);
182
int clish_shell__get_facility(clish_shell_t *instance);
183

    
184
int clish_shell_wdog(clish_shell_t *instance);
185
void clish_shell__set_wdog_timeout(clish_shell_t *instance,
186
        unsigned int timeout);
187
unsigned int clish_shell__get_wdog_timeout(const clish_shell_t *instance);
188
int clish_shell__save_history(const clish_shell_t *instance, const char *fname);
189
int clish_shell__restore_history(clish_shell_t *instance, const char *fname);
190
void clish_shell__stifle_history(clish_shell_t *instance, unsigned int stifle);
191
struct passwd *clish_shell__get_user(clish_shell_t *instance);
192
void clish_shell__set_dryrun(clish_shell_t *instance, bool_t dryrun);
193
bool_t clish_shell__get_dryrun(const clish_shell_t *instance);
194

    
195
/* Plugin functions */
196
clish_plugin_t * clish_shell_find_plugin(clish_shell_t *instance,
197
        const char *name);
198
clish_plugin_t * clish_shell_find_create_plugin(clish_shell_t *instance,
199
        const char *name);
200
int clish_shell_load_plugins(clish_shell_t *instance);
201
int clish_shell_link_plugins(clish_shell_t *instance);
202

    
203
/* Unresolved symbols functions */
204
clish_sym_t *clish_shell_find_sym(clish_shell_t *instance,
205
        const char *name, int type);
206
clish_sym_t *clish_shell_add_sym(clish_shell_t *instance,
207
        void *func, const char *name, int type);
208
clish_sym_t *clish_shell_add_unresolved_sym(clish_shell_t *instance,
209
        const char *name, int type);
210
clish_sym_t *clish_shell_get_hook(const clish_shell_t *instance, int type);
211

    
212
/* Hook wrappers */
213
void *clish_shell_check_hook(const clish_context_t *clish_context, int type);
214
CLISH_HOOK_CONFIG(clish_shell_exec_config);
215
CLISH_HOOK_LOG(clish_shell_exec_log);
216

    
217
/* User data functions */
218
void *clish_shell__get_udata(const clish_shell_t *instance, const char *name);
219
void *clish_shell__del_udata(clish_shell_t *instance, const char *name);
220
int clish_shell__set_udata(clish_shell_t *instance,
221
        const char *name, void *data);
222

    
223
/* Access functions */
224
int clish_shell_prepare(clish_shell_t *instance);
225

    
226
/*
227
 * Non shell specific functions.
228
 * Start and Stop XML parser engine.
229
 */
230
int clish_xmldoc_start(void);
231
int clish_xmldoc_stop(void);
232

    
233
_END_C_DECL
234

    
235
#endif                                /* _clish_shell_h */
236
/** @} clish_shell */