[dhcp-agent-commits] dhcp-agent/src dhcp-client-info-guile.c,NONE,1.1 dhcp-client-info-guile.h,NONE,
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2003-08-12 12:05:23
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv21919 Added Files: dhcp-client-info-guile.c dhcp-client-info-guile.h Log Message: client info smob moved to seperate source; now more complete --- NEW FILE: dhcp-client-info-guile.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-info-guile.c,v 1.1 2003/08/12 12:05:20 actmodern Exp $ * * Copyright 2003 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. * * client info smob * */ #include "dhcp-local.h" #include "dhcp-libutil.h" #include "dhcp-librawnet.h" #include "dhcp-option.h" #include "dhcp-guile-util.h" #include "dhcp-server-conf.h" #include "dhcp-server.h" #include "dhcp-server-client-info.h" #include "dhcp-client-info-guile.h" #include "dhcp-limits.h" static scm_t_bits client_info_tag; /* 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. */ 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); } /* get the hostname. */ static SCM scm_client_info_get_hostname(SCM scm_client_info) { client_info_smob_t *client_info_smob; const char *hostname; SCM_ASSERT(SCM_SMOB_PREDICATE(client_info_tag, scm_client_info), scm_client_info, SCM_ARG1, "scm_client_info_get_hostname"); client_info_smob = (client_info_smob_t *)SCM_SMOB_DATA(scm_client_info); hostname = client_info_get_hostname(client_info_smob->client_info); if(hostname == NULL) return SCM_BOOL_F; else return scm_makfrom0str(hostname); } /* get the client_id. */ static SCM scm_client_info_get_client_id(SCM scm_client_info) { client_info_smob_t *client_info_smob; const char *client_id; SCM_ASSERT(SCM_SMOB_PREDICATE(client_info_tag, scm_client_info), scm_client_info, SCM_ARG1, "scm_client_get_client_id_"); client_info_smob = (client_info_smob_t *)SCM_SMOB_DATA(scm_client_info); client_id = client_info_get_client_id(client_info_smob->client_info); if(client_id == NULL) return SCM_BOOL_F; else return scm_makfrom0str(client_id); } /* get the chaddr. */ static SCM scm_client_info_get_chaddr(SCM scm_client_info) { client_info_smob_t *client_info_smob; char *chaddr_str; eth_addr_t chaddr; SCM scm_chaddr; SCM_ASSERT(SCM_SMOB_PREDICATE(client_info_tag, scm_client_info), scm_client_info, SCM_ARG1, "scm_client_info_get_chaddr"); client_info_smob = (client_info_smob_t *)SCM_SMOB_DATA(scm_client_info); chaddr = client_info_get_chaddr(client_info_smob->client_info); chaddr_str = eth_addr_to_string(chaddr); scm_chaddr = scm_makfrom0str(chaddr_str); xfree(chaddr_str); return scm_chaddr; } /* get the giaddr. */ static SCM scm_client_info_get_giaddr(SCM scm_client_info) { client_info_smob_t *client_info_smob; char *giaddr_str; ip_addr_t giaddr; SCM scm_giaddr; SCM_ASSERT(SCM_SMOB_PREDICATE(client_info_tag, scm_client_info), scm_client_info, SCM_ARG1, "scm_client_info_get_giaddr"); client_info_smob = (client_info_smob_t *)SCM_SMOB_DATA(scm_client_info); giaddr = client_info_get_giaddr(client_info_smob->client_info); giaddr_str = ip_addr_to_string(giaddr); scm_giaddr = scm_makfrom0str(giaddr_str); xfree(giaddr_str); return scm_giaddr; } /* get the max message size. */ static SCM scm_client_info_get_max_message_size(SCM scm_client_info) { client_info_smob_t *client_info_smob; uint16_t max_message_size; SCM scm_max_message_size; SCM_ASSERT(SCM_SMOB_PREDICATE(client_info_tag, scm_client_info), scm_client_info, SCM_ARG1, "scm_client_info_get_max_message_size"); client_info_smob = (client_info_smob_t *)SCM_SMOB_DATA(scm_client_info); max_message_size = client_info_get_max_message_size(client_info_smob->client_info); scm_max_message_size = SCM_MAKINUM(max_message_size); return scm_number_to_string(scm_max_message_size, SCM_MAKINUM(10)); } /* initialization routines for client info smob. */ 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); scm_c_define_gsubr("dhcp-client-info-get-hostname", 1, 0, 0, scm_client_info_get_hostname); scm_c_define_gsubr("dhcp-client-info-get-client-id", 1, 0, 0, scm_client_info_get_client_id); scm_c_define_gsubr("dhcp-client-info-get-chaddr", 1, 0, 0, scm_client_info_get_chaddr); scm_c_define_gsubr("dhcp-client-info-get-giaddr", 1, 0, 0, scm_client_info_get_giaddr); scm_c_define_gsubr("dhcp-client-info-get-max-message-size", 1, 0, 0, scm_client_info_get_max_message_size); return; } --- NEW FILE: dhcp-client-info-guile.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-info-guile.h,v 1.1 2003/08/12 12:05:20 actmodern Exp $ * * Copyright 2003 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. * * client info smob * */ #ifndef DHCP_CLIENT_INFO_GUILE_H #define DHCP_CLIENT_INFO_GUILE_H typedef struct { client_info_t *client_info; } client_info_smob_t; extern void init_client_info_smob(void); extern SCM scm_client_info_c_make(client_info_t *client_info); #endif /* DHCP_CLIENT_INFO_GUILE_H */ |