Update of /cvsroot/dhcp-agent/dhcp-agent/src
In directory sc8-pr-cvs1:/tmp/cvs-serv22211
Modified Files:
dhcp-option-guile.c dhcp-option-guile.h
Log Message:
cleaned up and added more functionality
Index: dhcp-option-guile.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option-guile.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** dhcp-option-guile.c 10 Aug 2003 01:20:58 -0000 1.1
--- dhcp-option-guile.c 12 Aug 2003 12:06:59 -0000 1.2
***************
*** 39,42 ****
--- 39,43 ----
* * * * * * * * * * */
+ /* take an SCM dhcp tag and convert it to C dhcp tag. */
static int scm_to_dhcp_tag(SCM scm_tag, dhcp_opt_tag_t *tag)
{
***************
*** 104,107 ****
--- 105,144 ----
}
+ /* take a list of options and return them as a cons. */
+ SCM scm_dhcp_opt_c_list_to_list(list_t *options)
+ {
+ dhcp_opt_t *option;
+ SCM dhcp_opt_cons = SCM_EOL;
+
+ list_rewind(options);
+ while((option = list_next(options)) != NULL) {
+
+ dhcp_opt_cons = scm_cons(scm_dhcp_opt_c2scm(option), dhcp_opt_cons);
+ }
+
+ return scm_reverse(dhcp_opt_cons);
+ }
+
+ /* take a list of options and return them as a list. */
+ list_t *scm_dhcp_opt_list_to_c_list(SCM options)
+ {
+ dhcp_opt_t *option;
+ list_t *list;
+ int i, list_length;
+ SCM scm_list_length;
+
+ list = list_create();
+ scm_list_length = scm_length(options);
+ list_length = scm_num2int(scm_list_length, SCM_ARG1, "scm_dhcp_opt_list_to_c_list");
+
+ for(i = 0; i < list_length; i++) {
+
+ option = scm_dhcp_opt2c(scm_list_ref(options, SCM_MAKINUM(i)));
+ list_add_to_end(list, option);
+ }
+
+ return list;
+ }
+
/* * * * * * * * * * *
* dhcp option smob. *
***************
*** 133,136 ****
--- 170,184 ----
}
+ /* create a dhcp_opt smob from a C level dhcp option: this does not make a copy of the option */
+ SCM scm_dhcp_opt_c2scm_x(dhcp_opt_t *dhcp_opt)
+ {
+ dhcp_opt_smob_t *dhcp_opt_smob;
+
+ dhcp_opt_smob = scm_must_malloc(sizeof(dhcp_opt_smob_t), "dhcp-opt-make!");
+ dhcp_opt_smob->dhcp_opt = dhcp_opt;
+
+ SCM_RETURN_NEWSMOB(dhcp_opt_tag, dhcp_opt_smob);
+ }
+
/* create a dhcp_opt smob from a C level dhcp option */
SCM scm_dhcp_opt_c2scm(dhcp_opt_t *dhcp_opt)
***************
*** 146,149 ****
--- 194,208 ----
}
+ dhcp_opt_t *scm_dhcp_opt2c(SCM scm_dhcp_opt)
+ {
+ dhcp_opt_smob_t *dhcp_opt_smob;
+
+ SCM_ASSERT(SCM_SMOB_PREDICATE(dhcp_opt_tag, scm_dhcp_opt), scm_dhcp_opt, SCM_ARG1, "scm_dhcp_opt2c");
+ dhcp_opt_smob = (dhcp_opt_smob_t *)SCM_SMOB_DATA(scm_dhcp_opt);
+
+ return dhcp_option_copy(dhcp_opt_smob->dhcp_opt);
+ }
+
+
/* create a dhcp option: called from scheme code. */
static SCM scm_dhcp_opt_make(SCM scm_dhcp_tag, SCM scm_dhcp_opt_data)
***************
*** 195,199 ****
}
! return scm_dhcp_opt_c2scm(option);
}
--- 254,258 ----
}
! return scm_dhcp_opt_c2scm_x(option);
}
***************
*** 264,268 ****
case DHCP_OPT_VAL_UINT16:
! return scm_str2symbol("dhcp-opt-val-type-int32");
case DHCP_OPT_VAL_INT16:
--- 323,327 ----
case DHCP_OPT_VAL_UINT16:
! return scm_str2symbol("dhcp-opt-val-type-uint16");
case DHCP_OPT_VAL_INT16:
***************
*** 318,321 ****
--- 377,381 ----
/* setters. */
+ /* FIXME: check if we're putting redundant code here, see above creation routines. */
/* set dhcp option data overwriting old data. */
static SCM scm_dhcp_opt_set_data(SCM scm_dhcp_opt, SCM scm_data)
***************
*** 378,382 ****
return SCM_BOOL_T;
}
-
/* initialization routine for option smob. */
--- 438,441 ----
Index: dhcp-option-guile.h
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option-guile.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** dhcp-option-guile.h 10 Aug 2003 01:20:58 -0000 1.1
--- dhcp-option-guile.h 12 Aug 2003 12:06:59 -0000 1.2
***************
*** 32,38 ****
} dhcp_opt_smob_t;
- extern SCM scm_dhcp_opt_c2scm(dhcp_opt_t *dhcp_opt);
extern void init_dhcp_opt_smob(void);
#endif /* DHCP_OPT_GUILE_H */
-
--- 32,41 ----
} dhcp_opt_smob_t;
extern void init_dhcp_opt_smob(void);
+ extern SCM scm_dhcp_opt_c_list_to_list(list_t *options);
+ extern SCM scm_dhcp_opt_c2scm(dhcp_opt_t *dhcp_opt);
+ extern SCM scm_dhcp_opt_c2scm_x(dhcp_opt_t *dhcp_opt);
+ extern dhcp_opt_t *scm_dhcp_opt2c(SCM scm_dhcp_opt);
+ extern list_t *scm_dhcp_opt_list_to_c_list(SCM options);
#endif /* DHCP_OPT_GUILE_H */
|