CliXoN
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
cli_plugin.h
Go to the documentation of this file.
1 /*
2  *
3  ***** BEGIN LICENSE BLOCK *****
4 
5  Copyright (C) 2009-2017 Olof Hagsand and Benny Holmgren
6 
7  This file is part of CLIXON.
8 
9  Licensed under the Apache License, Version 2.0 (the "License");
10  you may not use this file except in compliance with the License.
11  You may obtain a copy of the License at
12 
13  http://www.apache.org/licenses/LICENSE-2.0
14 
15  Unless required by applicable law or agreed to in writing, software
16  distributed under the License is distributed on an "AS IS" BASIS,
17  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  See the License for the specific language governing permissions and
19  limitations under the License.
20 
21  Alternatively, the contents of this file may be used under the terms of
22  the GNU General Public License Version 3 or later (the "GPL"),
23  in which case the provisions of the GPL are applicable instead
24  of those above. If you wish to allow use of your version of this file only
25  under the terms of the GPL, and not to allow others to
26  use your version of this file under the terms of Apache License version 2,
27  indicate your decision by deleting the provisions above and replace them with
28  the notice and other provisions required by the GPL. If you do not delete
29  the provisions above, a recipient may use your version of this file under
30  the terms of any one of the Apache License version 2 or the GPL.
31 
32  ***** END LICENSE BLOCK *****
33 
34  */
35 
36 #ifndef _CLI_PLUGIN_H_
37 #define _CLI_PLUGIN_H_
38 
39 #include <stdio.h>
40 #include <inttypes.h>
41 #include <netinet/in.h>
42 
43 /* clicon generic callback pointer */
44 typedef void (clicon_callback_t)(clicon_handle h);
45 
46 /* clicon_set value callback */
47 typedef int (cli_valcb_t)(cvec *vars, cg_var *cgv, cg_var *arg);
48 
49 /* specific to cli. For common see clicon_plugin.h */
50 /* Hook to get prompt format before each getline */
51 typedef char *(cli_prompthook_t)(clicon_handle, char *mode);
52 
53 /* Ctrl-Z hook from getline() */
54 typedef int (cli_susphook_t)(clicon_handle, char *, int, int *);
55 
56 /* CLIgen parse failure hook. Retry other mode? */
57 typedef char *(cli_parsehook_t)(clicon_handle, char *, char *);
58 
59 typedef struct {
60  qelem_t csm_qelem; /* List header */
61  char csm_name[256]; /* Syntax mode name */
62  char csm_prompt[CLI_PROMPT_LEN]; /* Prompt for mode */
63  int csm_nsyntax; /* Num syntax specs registered by plugin */
64  parse_tree csm_pt; /* CLIgen parse tree */
65 
67 
68 /* A plugin list object */
69 struct cli_plugin {
70  qelem_t cp_qelem; /* List header */
71  char cp_name[256]; /* Plugin name */
72  void *cp_handle; /* Dynamic object handle */
73 };
74 
75 /* Plugin group object */
76 typedef struct {
77  char stx_cnklbl[128]; /* Plugin group name */
78  int stx_nplugins; /* Number of plugins */
79  struct cli_plugin *stx_plugins; /* List of plugins */
80  int stx_nmodes; /* Number of syntax modes */
81  cli_syntaxmode_t *stx_active_mode; /* Current active syntax mode */
82  cli_syntaxmode_t *stx_modes; /* List of syntax modes */
83  cli_prompthook_t *stx_prompt_hook; /* Prompt hook */
84  cli_parsehook_t *stx_parse_hook; /* Parse mode hook */
85  cli_susphook_t *stx_susp_hook; /* Ctrl-Z hook from getline() */
86 } cli_syntax_t;
87 
88 
89 void *clixon_str2fn(char *name, void *handle, char **error);
90 
91 int cli_plugin_start(clicon_handle, int argc, char **argv);
92 
93 int cli_plugin_init(clicon_handle h);
94 
95 int clicon_eval(clicon_handle h, char *cmd, cg_obj *match_obj, cvec *vr);
96 
97 int clicon_parse(clicon_handle h, char *cmd, char **mode, int *result);
98 
99 char *clicon_cliread(clicon_handle h);
100 
101 int cli_plugin_finish(clicon_handle h);
102 
103 #endif /* _CLI_PLUGIN_H_ */
Definition: cli_plugin.h:69
int clicon_parse(clicon_handle h, char *cmd, char **mode, int *result)
Definition: cli_plugin.c:688
qelem_t cp_qelem
Definition: cli_plugin.h:70
void * cp_handle
Definition: cli_plugin.h:72
struct cli_plugin * stx_plugins
Definition: cli_plugin.h:79
Definition: cli_plugin.h:59
cli_syntaxmode_t * stx_active_mode
Definition: cli_plugin.h:81
int csm_nsyntax
Definition: cli_plugin.h:63
char * clicon_cliread(clicon_handle h)
Definition: cli_plugin.c:781
#define CLI_PROMPT_LEN
Definition: clixon_cli_api.h:44
#define handle(h)
Definition: clixon_handle.c:59
cli_syntaxmode_t * stx_modes
Definition: cli_plugin.h:82
char *( cli_parsehook_t)(clicon_handle, char *, char *)
Definition: cli_plugin.h:57
int stx_nmodes
Definition: cli_plugin.h:80
int cli_plugin_init(clicon_handle h)
Definition: cli_plugin.c:825
parse_tree csm_pt
Definition: cli_plugin.h:64
Definition: cli_plugin.h:76
int( cli_susphook_t)(clicon_handle, char *, int, int *)
Definition: cli_plugin.h:54
int( cli_valcb_t)(cvec *vars, cg_var *cgv, cg_var *arg)
Definition: cli_plugin.h:47
char *( cli_prompthook_t)(clicon_handle, char *mode)
Definition: cli_plugin.h:51
char cp_name[256]
Definition: cli_plugin.h:71
int clicon_eval(clicon_handle h, char *cmd, cg_obj *match_obj, cvec *vr)
Definition: cli_plugin.c:648
int cli_plugin_finish(clicon_handle h)
Definition: cli_plugin.c:615
void * clixon_str2fn(char *name, void *handle, char **error)
Definition: cli_plugin.c:235
int stx_nplugins
Definition: cli_plugin.h:78
cli_parsehook_t * stx_parse_hook
Definition: cli_plugin.h:84
cli_susphook_t * stx_susp_hook
Definition: cli_plugin.h:85
cli_prompthook_t * stx_prompt_hook
Definition: cli_plugin.h:83
void( clicon_callback_t)(clicon_handle h)
Definition: cli_plugin.h:44
int cli_plugin_start(clicon_handle, int argc, char **argv)
Definition: cli_plugin.c:591
qelem_t csm_qelem
Definition: cli_plugin.h:60