[Dhcp-agent-commits] CVS: dhcp-agent dhcp-client-conf.c,1.1.1.1,1.2 dhcp-net.c,1.9,1.10
Status: Alpha
Brought to you by:
actmodern
From: Thamer Al-H. <act...@us...> - 2002-02-06 23:50:19
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv11080 Modified Files: dhcp-client-conf.c dhcp-net.c Log Message: config code for options added; Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-conf.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-client-conf.c 2002/01/29 18:05:03 1.1.1.1 --- dhcp-client-conf.c 2002/02/06 23:50:15 1.2 *************** *** 25,34 **** #include <dhcp-agent.h> ! /* ! * XXX - configuration is blah this whole thing needs to be designed properly ! * I'd still like to keep it as simple as possible. ! * This should be redone into something that's proper and works. ! * ! */ static const int default_config_options[] = { --- 25,30 ---- #include <dhcp-agent.h> ! /* Basic network configuration. ! * Here we keep the options we want by default. */ static const int default_config_options[] = { *************** *** 42,47 **** }; - static const int default_config_options_len = 6; client_conf_t *create_client_conf(dhcp_client_control_t *dc) { --- 38,49 ---- }; + static const int default_config_options_len = 7; + + static void client_conf_reset_options(client_conf_t *cc) + { + memset(cc->options, 0, sizeof(cc->options)); + } + client_conf_t *create_client_conf(dhcp_client_control_t *dc) { *************** *** 49,53 **** cc = xmalloc(sizeof(client_conf_t)); ! memset(cc->options, 0, sizeof(cc->options)); cc->interface = dc->interface; cc->conf_file = NULL; --- 51,55 ---- cc = xmalloc(sizeof(client_conf_t)); ! client_conf_reset_options(cc); cc->interface = dc->interface; cc->conf_file = NULL; *************** *** 64,87 **** } ! static void dump_default_configurations(FILE *fp) { int i; for(i = 0;i < default_config_options_len; i++) { ! fputs(dhcp_options_strings[default_config_options[i]], fp); ! fputs("\n", fp); } ! return; } - - int load_client_conf(client_conf_t *cc) - { - #ifdef not_yet - FILE *fp; - char *var; - unsigned char have_conf = 0; - #endif int i; --- 66,103 ---- } ! static char *get_conf_options_fname(client_conf_t *cc) ! { ! return(splice_string(cc->interface, ".opts")); ! } ! ! static int dump_config_options(client_conf_t *cc) { int i; + FILE *fp; + char *fname; + fname = get_conf_options_fname(cc); + fp = file_open_or_create_safe(fname, "w"); + xfree(fname); + + if(fp == NULL) + return -1; + for(i = 0;i < default_config_options_len; i++) { ! ! if((fputs(dhcp_options_strings[default_config_options[i]], fp) == EOF)|| ! (fputs("\n", fp) == EOF)) { ! ! fclose(fp); ! return -1; ! } } ! fclose(fp); ! return 0; } + static void use_default_options(client_conf_t *cc) + { int i; *************** *** 89,133 **** cc->options[default_config_options[i]] = 1; } - - return 0; ! #ifdef not_yet ! if(cc->conf_file == NULL) ! cc->conf_file = splice_string(cc->interface, ".conf"); ! fp = file_open_or_create_safe(cc->conf_file, "w+"); ! if(fp == NULL) ! return -1; ! /* Read up any vars. */ ! reread: while(!file_get_var_string(fp)) { ! if(file_parse_string(PARSE_SINGLE_STRING)) ! fatal_error("corrupt configuration: %s. exiting!", cc->conf_file); ! var = file_get_var_name(); ! ! for(i = 0;i < MAX_OPTIONS_HANDLED;i++) { ! if(!strcasecmp(var, dhcp_conf_options_strings[i])) { ! /* We have an option. */ cc->options[i] = 1; ! have_conf = 1; } } } ! /* Do we have an empty configuration? If so dump default. */ ! if(!have_conf) { ! fseek(fp, SEEK_SET, 0); ! dump_default_configurations(fp); ! fseek(fp, SEEK_SET, 0); ! goto reread; /* do it again, this time we'll get the options we wrote. */ ! } ! fclose(fp); ! #endif not_yet } --- 105,171 ---- cc->options[default_config_options[i]] = 1; } ! return; ! } ! static int client_conf_load_options(client_conf_t *cc) ! { ! char *fname; ! FILE *fp; ! int i; ! fname = get_conf_options_fname(cc); ! fp = file_open_or_create_safe(fname, "r"); ! xfree(fname); ! if(fp == NULL) ! return -1; while(!file_get_var_string(fp)) { ! if(file_parse_string(PARSE_SINGLE_STRING)) { ! fclose(fp); ! return -1; ! } ! for(i = 0;i < MAX_OPTIONS_HANDLED;i++) { ! ! /* as long as no error was returned from file_parse_string ! * we can just do a file_get_var_name() safely. */ ! ! if(string_matches(dhcp_options_strings[i], ! file_get_var_name())) { cc->options[i] = 1; ! break; } + } } + + fclose(fp); + return 0; + } + + int load_client_conf(client_conf_t *cc) + { ! char *fname; ! int retval; ! client_conf_reset_options(cc); ! /* check for options file. */ ! fname = get_conf_options_fname(cc); ! if(!file_exists(fname)) { ! /* it doesn't exist. use default options. */ ! use_default_options(cc); ! /* and dump it to file. */ ! retval = dump_config_options(cc); ! } else { ! /* read options file. */ ! retval = client_conf_load_options(cc); ! } ! ! xfree(fname); ! return retval; } Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-net.c 2002/02/02 12:28:05 1.9 --- dhcp-net.c 2002/02/06 23:50:15 1.10 *************** *** 517,521 **** char *packet_ptr; ! /* Dump packet images. */ packet_ptr = net->packet_data; --- 517,521 ---- char *packet_ptr; ! /* Dump packet images for DHCP. */ packet_ptr = net->packet_data; *************** *** 544,548 **** char *packet_ptr; ! /* Dump packet images. */ packet_ptr = net->packet_data; --- 544,548 ---- char *packet_ptr; ! /* Dump packet images for ARP/UNARP. */ packet_ptr = net->packet_data; |