[dhcp-agent-commits] dhcp-agent/src dhcp-server-guile.c,1.5,1.6 dhcp-server-guile.h,1.5,1.6
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2003-08-12 12:23:10
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv22274 Modified Files: dhcp-server-guile.c dhcp-server-guile.h Log Message: integrated smobs back into server guile code Index: dhcp-server-guile.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-guile.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-server-guile.c 7 Aug 2003 01:14:27 -0000 1.5 --- dhcp-server-guile.c 12 Aug 2003 12:07:25 -0000 1.6 *************** *** 37,220 **** #include "dhcp-server-guile.h" ! static scm_t_bits server_control_tag, lease_tag, client_info_tag; ! SCM leases_initialize, lease_available, lease_lookup, lease_acquire, lease_release, lease_expire; ! ! /* * * * * * * * * * * * * * * * * * * * ! * client info smob * ! * * * * * * * * * * * * * * * * * * * */ ! ! /* mark a client_info: we don't need to do any marking. */ ! static SCM scm_client_info_mark(SCM scm_client_info) ! { ! return SCM_BOOL_F; ! } ! ! /* free a client_info. */ ! static size_t scm_client_info_free(SCM scm_client_info) ! { ! client_info_smob_t *client_info_smob; ! ! client_info_smob = (client_info_smob_t *)SCM_SMOB_DATA(scm_client_info); ! client_info_destroy(client_info_smob->client_info); ! xfree(client_info_smob); ! ! return sizeof(client_info_smob); ! } ! ! /* print out a client info scm. */ ! static int scm_client_info_print(SCM scm_client_info, SCM port, scm_print_state *pstate) ! { ! scm_puts("#<client_info>", port); ! return 1; ! } ! ! /* create a client info scm. */ ! static SCM scm_client_info_c_make(client_info_t *client_info) ! { ! client_info_smob_t *client_info_smob; ! client_info_t *new_client_info; ! ! new_client_info = client_info_copy(client_info); ! client_info_smob = scm_must_malloc(sizeof(client_info_smob_t), "client-info-make"); ! client_info_smob->client_info = new_client_info; ! ! SCM_RETURN_NEWSMOB(client_info_tag, client_info_smob); ! } ! ! /* initialization routines for client info smob. */ ! static void init_client_info_smob(void) ! { ! client_info_tag = scm_make_smob_type("client_info_smob", sizeof(client_info_smob_t)); ! ! scm_set_smob_free(client_info_tag, scm_client_info_free); ! scm_set_smob_mark(client_info_tag, scm_client_info_mark); ! scm_set_smob_print(client_info_tag, scm_client_info_print); ! ! return; ! } ! ! /* * * * * * * * * * * * * * * * * * * * ! * lease smob * ! * * * * * * * * * * * * * * * * * * * */ ! ! /* mark a lease: we don't need to do any marking. */ ! static SCM scm_lease_mark(SCM scm_lease) ! { ! return SCM_BOOL_F; ! } ! ! /* free a lease scm. */ ! static size_t scm_lease_free(SCM scm_lease) ! { ! lease_smob_t *lease; ! ! lease = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); ! lease_destroy(lease->lease); ! xfree(lease); ! ! return sizeof(lease_smob_t); ! } ! ! /* print out a lease scm. */ ! static int scm_lease_print(SCM scm_lease, SCM port, scm_print_state *pstate) ! { ! scm_puts("#<lease>", port); ! return 1; ! } ! ! /* create a lease: this is called from within the scheme environment. */ ! static SCM scm_make_lease(SCM scm_ip_address, SCM scm_subnet_mask, SCM scm_lease_expiry, ! SCM scm_renew_time, SCM scm_rebind_time) ! { ! lease_smob_t *lease_smob; ! lease_t *lease; ! ip_addr_t ip_address, subnet_mask; ! uint32_t lease_expiry, renew_time, rebind_time; ! ! /* do assertions: all arguments can either be strings or inums */ ! ! SCM_ASSERT(SCM_STRINGP(scm_ip_address)|SCM_INUMP(scm_ip_address), ! scm_ip_address, SCM_ARG1, "make-lease"); ! ! SCM_ASSERT(SCM_STRINGP(scm_subnet_mask)|SCM_INUMP(scm_subnet_mask), ! scm_subnet_mask, SCM_ARG2, "make-lease"); ! ! SCM_ASSERT(SCM_STRINGP(scm_lease_expiry)|SCM_INUMP(scm_lease_expiry), ! scm_lease_expiry, SCM_ARG3, "make-lease"); ! ! SCM_ASSERT(SCM_STRINGP(scm_renew_time)|SCM_INUMP(scm_renew_time), ! scm_renew_time, SCM_ARG4, "make-lease"); ! ! SCM_ASSERT(SCM_STRINGP(scm_rebind_time)|SCM_INUMP(scm_rebind_time), ! scm_rebind_time, SCM_ARG5, "make-lease"); ! ! /* if string change to number first. */ ! ! if(SCM_STRINGP(scm_ip_address)) { ! ip_address = ntohl(scm_num2ulong(scm_inet_aton(scm_ip_address), 1, "make-lease")); ! } else { ! ip_address = scm_num2ulong(scm_ip_address, 1, "make-lease"); ! } ! ! if(SCM_STRINGP(scm_subnet_mask)) { ! subnet_mask = ntohl(scm_num2ulong(scm_inet_aton(scm_subnet_mask), 1, "make-lease")); ! } else { ! subnet_mask = scm_num2ulong(scm_subnet_mask, 1, "make-lease"); ! } ! ! if(SCM_STRINGP(scm_lease_expiry)) { ! lease_expiry = scm_num2ulong(scm_inet_aton(scm_lease_expiry), 1, "make-lease"); ! } else { ! lease_expiry = scm_num2ulong(scm_lease_expiry, 1, "make-lease"); ! } ! ! if(SCM_STRINGP(scm_renew_time)) { ! renew_time = scm_num2ulong(scm_inet_aton(scm_renew_time), 1, "make-lease"); ! } else { ! renew_time = scm_num2ulong(scm_renew_time, 1, "make-lease"); ! } ! ! if(SCM_STRINGP(scm_rebind_time)) { ! rebind_time = scm_num2ulong(scm_inet_aton(scm_rebind_time), 1, "make-lease"); ! } else { ! rebind_time = scm_num2ulong(scm_rebind_time, 1, "make-lease"); ! } ! ! lease = lease_create(ip_address, subnet_mask, lease_expiry, renew_time, rebind_time); ! lease_smob = scm_must_malloc(sizeof(lease_smob_t), "lease-make"); ! lease_smob->lease = lease; ! ! SCM_RETURN_NEWSMOB(lease_tag, lease); ! } ! ! /* create an SCM lease: this is called from the C code: a copy is ! made so garbage collection doesn't clubber our copy */ ! static SCM scm_c_make_lease(lease_t *lease) ! { ! return scm_make_lease(SCM_MAKINUM(lease_get_address(lease)), SCM_MAKINUM(lease_get_subnet_mask(lease)), ! SCM_MAKINUM(lease_get_expiry(lease)), SCM_MAKINUM(lease_get_renew(lease)), ! SCM_MAKINUM(lease_get_rebind(lease))); ! } ! ! /* get a copy of the lease from the scm lease: caled from C code. */ ! static lease_t * scm_c_get_lease(SCM scm_lease) ! { ! lease_smob_t *lease_smob; ! ! lease_smob = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); ! return lease_copy(lease_smob->lease); ! } ! ! /* initialization routines for lease smob. */ ! static void init_lease_smob(void) ! { ! lease_tag = scm_make_smob_type("lease", sizeof(lease_smob_t)); ! ! scm_set_smob_free(lease_tag, scm_lease_free); ! scm_set_smob_mark(lease_tag, scm_lease_mark); ! scm_set_smob_print(lease_tag, scm_lease_print); ! return; ! } /* * * * * * * * * * * * * * * * * * * * --- 37,46 ---- #include "dhcp-server-guile.h" ! #include "dhcp-lease-guile.h" ! #include "dhcp-client-info-guile.h" ! #include "dhcp-option-guile.h" ! static scm_t_bits server_control_tag; ! SCM leases_initialize, lease_available, lease_lookup, lease_acquire, lease_release, lease_expire; /* * * * * * * * * * * * * * * * * * * * *************** *** 394,398 **** SCM scm_return; ! scm_lease = scm_c_make_lease(lease); scm_return = scm_call_1(scm_variable_ref(lease_acquire), scm_lease); --- 220,224 ---- SCM scm_return; ! scm_lease = scm_lease_c2scm(lease); scm_return = scm_call_1(scm_variable_ref(lease_acquire), scm_lease); *************** *** 410,414 **** SCM scm_return; ! scm_lease = scm_c_make_lease(lease); scm_return = scm_call_1(scm_variable_ref(lease_release), scm_lease); --- 236,240 ---- SCM scm_return; ! scm_lease = scm_lease_c2scm(lease); scm_return = scm_call_1(scm_variable_ref(lease_release), scm_lease); Index: dhcp-server-guile.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-guile.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-server-guile.h 7 Aug 2003 01:14:27 -0000 1.5 --- dhcp-server-guile.h 12 Aug 2003 12:07:25 -0000 1.6 *************** *** 30,41 **** } server_control_smob_t; - typedef struct { - lease_t *lease; - } lease_smob_t; - - typedef struct { - client_info_t *client_info; - } client_info_smob_t; - /* prototypes. */ --- 30,33 ---- |