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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <glib-2.0/glib.h>
#include "common/common.h"
boolean g_debug = FALSE;
boolean g_verbose = FALSE;
static gboolean
dump_func(GNode *node, gpointer data);
extern GNode*
common_get_local_session_data();
/*
NOTES: reverse: use the n-nary tree in commit2.c and only encapuslate data store. pass in func pointer for processing of commands below.
also, the algorithm for collapsing the tree into a transaction list is:
1) iterate through tree and mark all explicit transactions
2) when done, prune the tree of all root explicit transactions
3) Now iterate through remaining tree and remove each node and append to transaction list.
*/
/**
*
*
**/
void
usage()
{
printf("dump_session\n");
printf("-d\t\tdebug mode\n");
printf("-v\t\tverbose mode\n");
printf("-h\t\thelp\n");
}
/**
*
*
**/
int
main(int argc, char** argv)
{
int ch;
//grab inputs
while ((ch = getopt(argc, argv, "dvh")) != -1) {
switch (ch) {
case 'd':
g_debug = TRUE;
break;
case 'v':
g_verbose = TRUE;
break;
case 'h':
usage();
exit(0);
break;
default:
usage();
exit(0);
}
}
//get local session data plus configuration data
GNode *config_root_node = common_get_local_session_data();
if (config_root_node == NULL) {
exit(0);
}
printf("Starting dump\n");
//iterate over config_data and dump...
g_node_traverse(config_root_node,
G_PRE_ORDER,
G_TRAVERSE_ALL,
-1,
(GNodeTraverseFunc)dump_func,
(gpointer)NULL);
return 0;
}
static gboolean
dump_func(GNode *node, gpointer data)
{
if (node != NULL) {
guint depth = g_node_depth(node);
gpointer gp = ((GNode*)node)->data;
if (((struct VyattaNode*)gp)->_data._name != NULL) {
int i;
if (IS_DELETE(((struct VyattaNode*)gp)->_data._operation)) {
printf("-");
}
else if (IS_CREATE(((struct VyattaNode*)gp)->_data._operation)) {
printf("+");
}
else if (IS_SET(((struct VyattaNode*)gp)->_data._operation)) {
printf(">");
}
else {
printf(" ");
}
for (i = 0; i < depth; ++i) {
printf(" ");
}
printf("%s (t: %d, p: %d)", ((struct VyattaNode*)gp)->_data._name,((struct VyattaNode*)gp)->_config._def.def_type,((struct VyattaNode*)gp)->_priority);
if (((struct VyattaNode*)gp)->_data._value == TRUE) {
printf(" [VALUE]");
}
if (((struct VyattaNode*)gp)->_config._multi == TRUE) {
printf(" [MULTI]");
}
if (((struct VyattaNode*)gp)->_config._def.actions[syntax_act].vtw_list_head &&
((struct VyattaNode*)gp)->_config._def.actions[syntax_act].vtw_list_head->vtw_node_aux == 0) {
printf(" [SYNTAX]");
}
if (((struct VyattaNode*)gp)->_config._def.actions[create_act].vtw_list_head) {
printf(" [CREATE]");
}
if (((struct VyattaNode*)gp)->_config._def.actions[activate_act].vtw_list_head) {
printf(" [ACTIVATE]");
}
if (((struct VyattaNode*)gp)->_config._def.actions[update_act].vtw_list_head) {
printf(" [UPDATE]");
}
if (((struct VyattaNode*)gp)->_config._def.actions[delete_act].vtw_list_head) {
printf(" [DELETE]");
}
if (((struct VyattaNode*)gp)->_config._def.actions[syntax_act].vtw_list_head &&
((struct VyattaNode*)gp)->_config._def.actions[syntax_act].vtw_list_head->vtw_node_aux == 1) {
printf(" [COMMIT]");
}
if (((struct VyattaNode*)gp)->_config._def.actions[begin_act].vtw_list_head) {
printf(" [BEGIN]");
}
if (((struct VyattaNode*)gp)->_config._def.actions[end_act].vtw_list_head) {
printf(" [END]");
}
if (g_verbose == TRUE) {
printf("\n");
for (i = 0; i < depth; ++i) {
printf(" ");
}
printf("%s\n",((struct VyattaNode*)gp)->_config._path);
for (i = 0; i < depth; ++i) {
printf(" ");
}
printf("%s\n",((struct VyattaNode*)gp)->_data._path);
}
if (((struct VyattaNode*)gp)->_config._help != NULL) {
// printf("[help: %s]",((struct VyattaNode*)gp)->_config._help);
}
printf("\n");
}
}
return FALSE;
}
|