[dhcp-agent-commits] dhcp-agent/src dhcp-conf.c,1.1,1.2 dhcp-conf.h,1.1,1.2
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2002-12-15 05:15:47
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv29093 Modified Files: dhcp-conf.c dhcp-conf.h Log Message: added destruction routines Index: dhcp-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-conf.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-conf.c 15 Dec 2002 00:22:02 -0000 1.1 --- dhcp-conf.c 15 Dec 2002 05:15:44 -0000 1.2 *************** *** 48,51 **** --- 48,57 ---- static void *compile_arg_group(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols); + /* forward declaration of argument destroyers */ + + /* we only need these two. */ + static void destroy_arg_string_list(void *data); + static void destroy_arg_group(void *data); + /* argument_compiler_dispatch table -- these are indexed by the types in dhcp-conf.h */ *************** *** 60,92 **** }; /* * * * * * * * * * * * * * * * constructors/destructors * * * * * * * * * * * * * * * */ - conf_t *conf_create(command_t **commands, const char *filename) - { - conf_t *conf; - - conf = xmalloc(sizeof(conf_t)); - conf->parser = create_parser(filename); - - if(conf->parser == NULL) { - ERROR_MESSAGE("could not open configuration file: %s", filename); - xfree(conf); - return NULL; - } - - conf->filename = xstrdup(filename); - conf->commands = commands; - conf->directives = NULL; - - return conf; - } - - void conf_destroy(conf_t *conf) - { - return; /* TODO: write cleanup code. */ - } - static directive_t *directive_create(void) { --- 66,85 ---- }; + /* argument destroyer dispatch table -- these are indexed by the types in dhcp-conf.h */ + + argument_destroy_t argument_destroyers[] = { + xfree, + xfree, + xfree, + xfree, + xfree, + destroy_arg_string_list, + destroy_arg_group, + }; + /* * * * * * * * * * * * * * * * constructors/destructors * * * * * * * * * * * * * * * */ static directive_t *directive_create(void) { *************** *** 113,117 **** static void directive_destroy(directive_t *directive) { ! arg_type_destroy(NULL); return; } --- 106,139 ---- static void directive_destroy(directive_t *directive) { ! list_t *type_ptr, *arg_ptr; ! list_t *tmp; ! arg_type_t arg_type; ! ! arg_ptr = directive->arguments; ! type_ptr = directive->argument_types; ! ! /* iterate through the list of arguments. ! * and call the destroy routine per argument. */ ! ! while(type_ptr) { ! ! /* FIXME: one of the limitations of the list code we're ! * using is that we cannot perform single purges. fix ! * later. just do raw list code here. */ ! ! arg_type = *(arg_type_t *)type_ptr->data; ! ! argument_destroyers[arg_type](arg_ptr->data); ! arg_type_destroy((arg_type_t *)type_ptr->data); ! ! tmp = type_ptr->next; ! xfree(type_ptr); ! type_ptr = tmp; ! ! tmp = arg_ptr->next; ! xfree(arg_ptr); ! arg_ptr = tmp; ! } ! return; } *************** *** 122,125 **** --- 144,177 ---- } + conf_t *conf_create(command_t **commands, const char *filename) + { + conf_t *conf; + + conf = xmalloc(sizeof(conf_t)); + conf->parser = create_parser(filename); + + if(conf->parser == NULL) { + ERROR_MESSAGE("could not open configuration file: %s", filename); + xfree(conf); + return NULL; + } + + conf->filename = xstrdup(filename); + conf->commands = commands; + conf->directives = NULL; + + return conf; + } + + void conf_destroy(conf_t *conf) + { + xfree(conf->filename); + destroy_parser(conf->parser); + purge_list(conf->directives, directive_destroy_l); + xfree(conf); + + return; + } + /* * * * * * * * * * * * * argument compilers * *************** *** 249,253 **** atom_t atom; - atom = get_next_atom_ignore_newlines(conf->parser); --- 301,304 ---- *************** *** 414,417 **** --- 465,491 ---- purge_list(directive_list, directive_destroy_l); return NULL; + } + + /* * * * * * * * * * * * * * * * * + * argument destruction routines * + * * * * * * * * * * * * * * * * */ + + /* most are just freed with xfree. these two are special because + * they contain lists. */ + + static void destroy_arg_string_list(void *data) + { + list_t *list = data; + + purge_list(list, NULL); /* just free up a list of strings. */ + } + + static void destroy_arg_group(void *data) + { + list_t *list = data; + + purge_list(list, directive_destroy_l); + + return; } Index: dhcp-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-conf.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-conf.h 15 Dec 2002 00:22:02 -0000 1.1 --- dhcp-conf.h 15 Dec 2002 05:15:44 -0000 1.2 *************** *** 63,66 **** --- 63,67 ---- /* typedef of configuration drivers. */ typedef void *(*argument_compiler_t)(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols); + typedef void (*argument_destroy_t)(void *); /* conf return types. */ |