[dhcp-agent-commits] dhcp-agent/src dhcp-server-guile.c,NONE,1.1 dhcp-server-guile.h,1.1,1.2
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2003-07-28 00:34:06
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv24655/src Modified Files: dhcp-server-guile.h Added Files: dhcp-server-guile.c Log Message: initial server guile bindings --- NEW FILE: dhcp-server-guile.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-guile.c,v 1.1 2003/07/28 00:33:54 actmodern Exp $ * * Copyright 2002 Thamer Alharbash * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * Glue between dhcp-server and guile. * * */ #include "dhcp-local.h" #include "dhcp-libutil.h" #include "dhcp-librawnet.h" #include "dhcp-option.h" #include "dhcp-lease.h" #include "dhcp-server-conf.h" #include "dhcp-server.h" #include "dhcp-server-guile.h" static scm_t_bits server_control_tag; static SCM initialize_leases, get_next_lease, lease_lookup, lease_expire; /* * * * * * * * * * * * * * * * * * * * * dhcp server control smob * * * * * * * * * * * * * * * * * * * * */ /* mark a dhcp server control scm: we don't need to do any marking. */ static SCM dhcp_scm_server_control_mark(SCM scm_server_control) { return SCM_BOOL_F; } /* free a server control scm. */ static size_t dhcp_scm_server_control_free(SCM scm_server_control) { server_control_smob_t *server_control_smob; server_control_smob = (server_control_smob_t *)SCM_SMOB_DATA(scm_server_control); xfree(server_control_smob); return sizeof(server_control_smob_t); } /* print out a server control scm. */ static int dhcp_scm_server_control_print(SCM scm_server_control, SCM port, scm_print_state *pstate) { scm_puts("#<server_control>", port); return 1; } /* convert a server control handler to SCM. */ static SCM dhcp_scm_make_server_control(dhcp_server_control_t *sc) { server_control_smob_t *server_control_smob; server_control_smob = xmalloc(sizeof(server_control_smob_t)); server_control_smob->sc = sc; SCM_RETURN_NEWSMOB(server_control_tag, server_control_smob); } /* initialization routines for server control SMOB. */ static void init_server_control_smob(void) { server_control_tag = scm_make_smob_type("server_control", sizeof(server_control_smob_t)); /* bind mark, free, and print. */ scm_set_smob_mark(server_control_tag, dhcp_scm_server_control_mark); scm_set_smob_free(server_control_tag, dhcp_scm_server_control_free); scm_set_smob_print(server_control_tag, dhcp_scm_server_control_print); return; } /* * * * * * * * * * * * * * * * * * * * * * * bootstrap guile routines. * * * * * * * * * * * * * * * * * * * * * * */ /* load the guile dhcp backend script. */ static void load_guile_backend(dhcp_server_control_t *sc) { stringbuffer_t *sb; sb = stringbuffer_create(); stringbuffer_aprintf(sb, "%s/default.backend", DHCPSYSCONF_SERVERDIR); if(file_exists(stringbuffer_getstring(sb))) { scm_c_primitive_load(stringbuffer_getstring(sb)); stringbuffer_destroy(sb); return; } stringbuffer_clear(sb); stringbuffer_aprintf(sb, "%s/%s.backend", DHCPSYSCONF_SERVERDIR, sc->interface); if(file_exists(stringbuffer_getstring(sb))) { scm_c_primitive_load(stringbuffer_getstring(sb)); stringbuffer_destroy(sb); return; } /* otherwise there is no backend file and this is * bad. signal a fatal error. */ FATAL_MESSAGE("backend lease manager file missing -- looked for default.backend and <interface>.backend. exiting..."); exit(1); /* get rid of compiler warning. */ } /* * * * * * * * * * * * * * * * * public interface routines. * * * * * * * * * * * * * * * * */ void dhcp_guile_init(dhcp_server_control_t *sc) { /* initialize the server control smob. */ init_server_control_smob(); /* bind symbols to top level so that the user defined script can hook into them. */ initialize_leases = scm_str2symbol("initialize-leases"); get_next_lease = scm_str2symbol("get-next-lease"); lease_lookup = scm_str2symbol("lease-lookup"); lease_expire = scm_str2symbol("lease-expire"); /* NOTE: defining at the top level should keep the garbage * collector from swallowing these symbols up. */ scm_define(initialize_leases, SCM_BOOL_F); scm_define(get_next_lease, SCM_BOOL_F); scm_define(lease_lookup, SCM_BOOL_F); scm_define(lease_expire, SCM_BOOL_F); /* define all the subroutines. */ /* TODO. */ /* bind our server control object. */ scm_c_define("dhcp-server-control", dhcp_scm_make_server_control(sc)); /* load the backend code. */ load_guile_backend(sc); return; } /* initialize the lease manager. */ int dhcp_guile_initialize_leases(void) { scm_apply_0(initialize_leases, SCM_EOL); return 0; } /* get the next available lease. */ lease_definition_t *dhcp_guile_get_next_lease(const char *hostname, eth_addr_t mac_addr, ip_addr_t giaddr, list_t *client_options) { return NULL; } /* get the next available lease. */ lease_definition_t *dhcp_guile_lease_lookup(ip_addr_t ip_addr) { return NULL; } void dhcp_guile_lease_expire(void) { return; } Index: dhcp-server-guile.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-guile.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-server-guile.h 2 Jul 2003 15:23:30 -0000 1.1 --- dhcp-server-guile.h 28 Jul 2003 00:33:54 -0000 1.2 *************** *** 28,30 **** --- 28,40 ---- #include <libguile.h> + typedef struct client_control_smob { + dhcp_server_control_t *sc; + } server_control_smob_t; + + extern int dhcp_guile_initialize_leases(void); + extern lease_definition_t *dhcp_guile_get_next_lease(const char *hostname, eth_addr_t mac_addr, + ip_addr_t giaddr, list_t *client_options); + extern lease_definition_t *dhcp_guile_lease_lookup(ip_addr_t ip_addr); + extern void dhcp_guile_lease_expire(void); + #endif /* DHCP_SERVER_GUILE_H */ |