diff options
author | slioch <slioch@eng-140.vyatta.com> | 2008-12-15 17:03:00 -0800 |
---|---|---|
committer | slioch <slioch@eng-140.vyatta.com> | 2008-12-15 17:03:00 -0800 |
commit | 5da26e172a8c1ed5201527aefddabd6e277e5c03 (patch) | |
tree | 17b9536117774b0dfd76969b1b3b0aed82c24117 /src/dump_session.c | |
parent | 9ed9edcfe9aef3db9306a0d2b7c24f73831b1149 (diff) | |
download | vyatta-cfg-5da26e172a8c1ed5201527aefddabd6e277e5c03.tar.gz vyatta-cfg-5da26e172a8c1ed5201527aefddabd6e277e5c03.zip |
initial checkin of new commit code--building but does not replace original commit. New commit may be accessed through
my_commit2 binary.
Diffstat (limited to 'src/dump_session.c')
-rw-r--r-- | src/dump_session.c | 166 |
1 files changed, 166 insertions, 0 deletions
diff --git a/src/dump_session.c b/src/dump_session.c new file mode 100644 index 0000000..d6b85cf --- /dev/null +++ b/src/dump_session.c @@ -0,0 +1,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; +} |