X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcsim%2Fsilcsim.c;h=7a00dafdf318cbd3f03abe42fc4afddde9342ceb;hb=e7b6c157b80152bf9fb9266e6bdd93f9fb0db776;hp=ab9b3433615c6923d212c040773869922626aa46;hpb=d47a87b03b846e2333ef57b2c0d81f1644992964;p=silc.git diff --git a/lib/silcsim/silcsim.c b/lib/silcsim/silcsim.c index ab9b3433..7a00dafd 100644 --- a/lib/silcsim/silcsim.c +++ b/lib/silcsim/silcsim.c @@ -2,14 +2,13 @@ silcsim.c - Author: Pekka Riikonen + Author: Pekka Riikonen Copyright (C) 2000 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -41,47 +40,79 @@ */ -#include "silcincludes.h" +#include "silc.h" + +/* + SILC Module (SIM) Context. + + This context holds relevant information about the SIM loaded into + the system. Following short description of the fields. + + void *handle + + Pointer to the SIM. This is used to get the symbols out of + the SIM. This is initalized by system specific routine. + + SilcSimType type + + Type of the SIM. + + char *libname; + + Filename and path to the SIM library file. + + int flags + + Flags used with the SIM. These are system specific flags. + See below for more information. + +*/ +struct SilcSimStruct { + void *handle; + SilcSimType type; + char *libname; + int flags; +}; #ifdef SILC_SIM /* SIM upport enabled */ /* Allocates new SIM context. This is later send to all SIM routines. */ -SilcSimContext *silc_sim_alloc() +SilcSim silc_sim_alloc(SilcSimType type, const char *libname, + SilcUInt32 flags) { - SilcSimContext *new; + SilcSim sim; SILC_LOG_DEBUG(("Initializing new SIM context")); - new = silc_calloc(1, sizeof(*new)); - if (!new) { + sim = silc_calloc(1, sizeof(*sim)); + if (!sim) { SILC_LOG_ERROR(("Could not allocate new SIM context")); return NULL; } - new->handle = NULL; - new->type = SILC_SIM_NONE; - new->libname = NULL; - new->flags = SILC_SIM_FLAGS; + sim->handle = NULL; + sim->type = type; + sim->libname = strdup(libname); + sim->flags = !flags ? SILC_SIM_FLAGS : flags; - return new; + return sim; } /* Free's SIM context. SIM must be closed with silc_sim_close before calling this. */ -void silc_sim_free(SilcSimContext *sim) +void silc_sim_free(SilcSim sim) { assert(sim->handle == NULL); - - if (sim) - silc_free(sim); + silc_free(sim->libname); + silc_free(sim); } /* Loads SIM into the SILC system. */ -int silc_sim_load(SilcSimContext *sim) +int silc_sim_load(SilcSim sim) { assert(sim != NULL); @@ -90,7 +121,7 @@ int silc_sim_load(SilcSimContext *sim) /* Load the library */ sim->handle = dlopen(sim->libname, sim->flags); if (!sim->handle) { - SILC_LOG_ERROR(("Error loading SIM: %s", silc_sim_error())); + SILC_LOG_ERROR(("Error loading SIM: %s", silc_sim_error(sim))); return FALSE; } @@ -100,7 +131,7 @@ int silc_sim_load(SilcSimContext *sim) /* Closes SIM. This is called when execution of program is ending or one explicitly wants to remove this SIM from SILC. */ -int silc_sim_close(SilcSimContext *sim) +int silc_sim_close(SilcSim sim) { assert(sim != NULL); @@ -115,7 +146,7 @@ int silc_sim_close(SilcSimContext *sim) /* Returns error string if error has occured while processing SIM's. */ -char *silc_sim_error() +const char *silc_sim_error(SilcSim sim) { return dlerror(); } @@ -124,7 +155,7 @@ char *silc_sim_error() symbols they want to get from SIM and use the returned pointer to what ever it is intended. */ -void *silc_sim_getsym(SilcSimContext *sim, const char *symbol) +void *silc_sim_getsym(SilcSim sim, const char *symbol) { assert(sim != NULL);