1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#ifndef CLI_DEF_H
#define CLI_DEF_H
#include <stdio.h>
#include <cli_cstore.h>
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif
/* allocation unit for vals in valstruct */
#define MULTI_ALLOC 5 /* we have room if cnt%MULTI_ALLOC != 0 */
typedef enum {
do_del_mode,
del_mode,
create_mode,
update_mode
}vtw_cmode;
typedef enum {
EQ_COND = 1,
NE_COND,
LT_COND,
LE_COND,
GT_COND,
GE_COND,
IN_COND,
TOP_COND
}vtw_cond_e;
/* IN_COND is like EQ for singular compare, but OR for multivalue right operand */
typedef struct {
const char *f_segp;
int f_seglen;
int f_segoff;
} first_seg;
/* the first segment might be ADIR, or CDIR, or MDIR
we reserve space large enough for any one.
If the shorter one is used, it right aligned.
path points to the start of the current first
segment
*/
typedef struct {
char *path_buf; /* path buffer */
char *path; /* path */
int path_len; /* path length used */
int path_alloc; /* allocated - 1*/
int *path_ends; /* path ends for dif levels*/
int path_lev; /* how many used */
int path_ends_alloc; /* how many allocated */
int print_offset; /* for additional optional output information */
} vtw_path; /* vyatta tree walk */
extern int char2val(vtw_def *def, char *value, valstruct *valp);
extern int get_value(char **valpp, vtw_path *pathp);
extern vtw_node * make_node(vtw_oper_e oper, vtw_node *left,
vtw_node *right);
extern vtw_node *make_str_node(char *str);
extern vtw_node *make_var_node(char *str);
extern vtw_node *make_str_node0(char *str, vtw_oper_e op);
extern void append(vtw_list *l, vtw_node *n, int aux);
extern int yy_cli_val_lex(void);
extern void init_path(vtw_path *path, const char *root);
extern void pop_path(vtw_path *path);
extern void push_path(vtw_path *path, const char *segm);
extern void push_path_no_escape(vtw_path *path, char *segm);
extern void free_def(vtw_def *defp);
extern vtw_path m_path, t_path;
/*************************************************
GLOBAL FUNCTIONS
***************************************************/
extern void add_val(valstruct *first, valstruct *second);
extern int cli_val_read(char *buf, int max_size);
extern vtw_node *make_val_node(valstruct *val);
extern valstruct str2val(char *cp);
extern void switch_path(first_seg *seg);
extern void free_val(valstruct *val);
extern int mkdir_p(const char *path);
extern boolean execute_list(vtw_node *cur, vtw_def *def, const char *outbuf,boolean format);
extern void free_path(vtw_path *path);
extern int get_config_lock(void);
extern void release_config_lock(void);
#define VTWERR_BADPATH -2
#define VTWERR_OK 0
#define TAG_NAME "node.tag"
#define DEF_NAME "node.def"
#define VAL_NAME "node.val"
#define MOD_NAME ".modified"
#define OPQ_NAME ".wh.__dir_opaque"
/*** output ***/
#define LOGFILE_STDOUT "/tmp/cfg-stdout.log"
#define LOGFILE_STDERR "/tmp/cfg-stderr.log"
extern int out_fd;
extern FILE *err_stream;
/* debug hooks? */
#define my_malloc(size, name) malloc(size)
#define my_realloc(ptr, size, name) realloc(ptr, size)
#define my_strdup(str, name) strdup(str)
#define my_free(ptr) free(ptr)
/*** debug ***/
#undef CLI_DEBUG
#ifdef CLI_DEBUG
#define DPRINT(fmt, arg...) printf(fmt, #arg)
#else
#define DPRINT(fmt, arg...) while (0) { printf(fmt, ##arg); }
#endif
#endif
|