[dhcp-agent-commits] dhcp-agent/src dhcp-client-conf.c,1.20,1.21 dhcp-client-conf.h,1.12,1.13
Status: Alpha
                
                Brought to you by:
                
                    actmodern
                    
                
            | 
     
      
      
      From: <act...@us...> - 2003-03-26 05:23:05
      
     
   | 
Update of /cvsroot/dhcp-agent/dhcp-agent/src
In directory sc8-pr-cvs1:/tmp/cvs-serv26563
Modified Files:
	dhcp-client-conf.c dhcp-client-conf.h 
Log Message:
added prepend/append to client-conf
Index: dhcp-client-conf.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** dhcp-client-conf.c	25 Mar 2003 20:26:47 -0000	1.20
--- dhcp-client-conf.c	26 Mar 2003 05:23:02 -0000	1.21
***************
*** 620,623 ****
--- 620,625 ----
      params->variables = list_create();
      params->lower_params = list_create();
+     params->append_options = list_create();
+     params->prepend_options = list_create();
  
      return params;
***************
*** 630,633 ****
--- 632,637 ----
      list_destroy(params->variables, dhcp_conf_var_destroy_l);
      list_destroy(params->lower_params, params_destroy_l);
+     list_destroy(params->append_options, cache_entry_destroy_l);
+     list_destroy(params->prepend_options, cache_entry_destroy_l);
  
      xfree(params);
***************
*** 809,820 ****
  }
  
! static int directive_append_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
  {
      return 0;
  }
  
  static int directive_prepend_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
  {
!     return 0;
  }
  
--- 813,908 ----
  }
  
! static int directive_static_cache_entry_handler_proc(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data,
!                                                      int var_type)
  {
+     char *option_name;
+     list_t *option_data_list;
+     char *data;
+     stringbuffer_t *sb;
+     cache_entry_t *ce = NULL;
+     directive_t *directive = directive_data;
+     uint8_t i;
+ 
+     const char **option_strings = dhcp_option_conf_string_get_array();
+ 
+     option_name = list_first(directive->arguments);
+     option_data_list = list_get_by_index(directive->arguments, 2);
+ 
+     
+     for(i = 0; i < MAX_OPTIONS_HANDLED; i++) {
+ 
+         if(!strcmp(option_strings[i], option_name)) {
+ 
+             /* found a match. create cache entry and break out.*/
+ 
+             /* FIXME: a ";" will wreck havoc on conversion list routines by causing them to split a datum.
+              * this a limitation because dhcp-convert.c was never written to take in string form. it was always
+              * assumed that this data came in from the network in network form. */
+ 
+             /* more hackery. there are two versions of
+              * options. those with lists and those without.  we
+              * actually can't tell the difference from here
+              * (FIXME: we should) so we check the list length. if
+              * it's more than one we append with a semicolon, and
+              * loop. otherwise we just pass. */
+              
+             if(list_get_len(option_data_list) == 1) {
+                 
+                 /* just pass data . */
+                 data = list_first(option_data_list);
+                 ce = create_cache_entry(i, dhcp_option_printable_string_get(i), data);
+                 break; /* done. */
+ 
+             } else {
+ 
+                 /* create a list out of it just dhcp-convert would.
+                  * this is too much hackery and needs to go soon. */
+ 
+                 sb = stringbuffer_create();
+ 
+                 while((data = list_next(option_data_list)) != NULL) {
+                     stringbuffer_aprintf(sb, "%s;", data);
+                 }
+ 
+                 ce = create_cache_entry(i, dhcp_option_printable_string_get(i), xstrdup(stringbuffer_getstring(sb)));
+                 stringbuffer_destroy(sb);
+ 
+                 break; /* done. */
+             }
+         }
+     }
+ 
+     if(ce == NULL) {
+         ERROR_MESSAGE("unknown option %s to append/prepend", option_name);
+         return 1;
+     }
+ 
+     /* check to make sure option name is valid. */
+     
+     switch(var_type) {
+ 
+     case CLIENT_VAR_APPEND_OPTIONS:
+         list_add(params->append_options, ce);
+         break;
+ 
+     case CLIENT_VAR_PREPEND_OPTIONS:        
+         list_add(params->prepend_options, ce);
+         break;
+ 
+     default:
+         FATAL_MESSAGE("i have encountered a bug. i shouldn't be here.");
+     }
+ 
      return 0;
  }
  
+ static int directive_append_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
+ {
+     return directive_static_cache_entry_handler_proc(params, directive_data, group_type, group_data, CLIENT_VAR_APPEND_OPTIONS);
+ }
+ 
  static int directive_prepend_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
  {
!     return directive_static_cache_entry_handler_proc(params, directive_data, group_type, group_data, CLIENT_VAR_PREPEND_OPTIONS);
  }
  
Index: dhcp-client-conf.h
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** dhcp-client-conf.h	25 Mar 2003 20:26:50 -0000	1.12
--- dhcp-client-conf.h	26 Mar 2003 05:23:02 -0000	1.13
***************
*** 53,57 ****
      list_t      *variables;                                /* variables of type var_t. */
      list_t      *lower_params;                             /* linked list to child parameters. */
!     
  } client_conf_params_t;
  
--- 53,59 ----
      list_t      *variables;                                /* variables of type var_t. */
      list_t      *lower_params;                             /* linked list to child parameters. */
!     list_t      *append_options;                           /* options append values to. */
!     list_t      *prepend_options;                          /* options prepend values to. */
! 
  } client_conf_params_t;
  
***************
*** 77,81 ****
  enum var_symbols { CLIENT_VAR_HOSTNAME = 0, CLIENT_VAR_DHCP_DISCOVERY_RETRIES, CLIENT_VAR_ICMP_RETRIES, 
                     CLIENT_VAR_INTERFACE_MTU, CLIENT_VAR_DO_MEASURE_ROUTER_LATENCY_ICMP, 
!                    CLIENT_VAR_REQUEST_OPTIONS, CLIENT_VAR_REQUIRE_OPTIONS, CLIENT_VAR_CONFIGURE_OPTIONS };
  
  /* server symbol substitution. */
--- 79,84 ----
  enum var_symbols { CLIENT_VAR_HOSTNAME = 0, CLIENT_VAR_DHCP_DISCOVERY_RETRIES, CLIENT_VAR_ICMP_RETRIES, 
                     CLIENT_VAR_INTERFACE_MTU, CLIENT_VAR_DO_MEASURE_ROUTER_LATENCY_ICMP, 
!                    CLIENT_VAR_REQUEST_OPTIONS, CLIENT_VAR_REQUIRE_OPTIONS, CLIENT_VAR_CONFIGURE_OPTIONS, CLIENT_VAR_APPEND_OPTIONS, 
!                    CLIENT_VAR_PREPEND_OPTIONS };
  
  /* server symbol substitution. */
 |