5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 2000 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
21 These routines implement the SILC Module (SIM) support. SIM's are
22 dynamically run-time loaded shared objects that can implement some
23 routines SILC can use to extend its features. Currently all
24 SILC Crypto modules are implemented as SIM's. They all implement
25 the SILC Crypto API and can be loaded run-time into the SILC and
28 Basically any SILC API can be implemented as SIM, however, currently
29 only SILC Crypto modules (ciphers and hash functions (PKCS are not
30 supported)) are supported.
32 This implementation expects that no SILC specific symbols needs to
33 be exported into the SIM's. This means that SIM's cannot directly
34 use SILC specific symbols or definitions. This feature can be
35 supported with SIM's but currently (with Crypto modules) this is
38 NOTE: These routines maybe highly system dependant thus I can expect
39 some heavy #ifdef's here. However, I'm more happy to see some macro
40 SIM API and restrict the #ifdef's to silcsim.h file.
44 #include "silcincludes.h"
47 SILC Module (SIM) Context.
49 This context holds relevant information about the SIM loaded into
50 the system. Following short description of the fields.
54 Pointer to the SIM. This is used to get the symbols out of
55 the SIM. This is initalized by system specific routine.
63 Filename and path to the SIM library file.
67 Flags used with the SIM. These are system specific flags.
68 See below for more information.
71 struct SilcSimStruct {
78 #ifdef SILC_SIM /* SIM upport enabled */
80 /* Allocates new SIM context. This is later send to all SIM
83 SilcSim silc_sim_alloc(SilcSimType type, const char *libname,
88 SILC_LOG_DEBUG(("Initializing new SIM context"));
90 sim = silc_calloc(1, sizeof(*sim));
92 SILC_LOG_ERROR(("Could not allocate new SIM context"));
98 sim->libname = strdup(libname);
99 sim->flags = !flags ? SILC_SIM_FLAGS : flags;
104 /* Free's SIM context. SIM must be closed with silc_sim_close before
107 void silc_sim_free(SilcSim sim)
109 assert(sim->handle == NULL);
110 silc_free(sim->libname);
114 /* Loads SIM into the SILC system. */
116 int silc_sim_load(SilcSim sim)
120 SILC_LOG_DEBUG(("Loading SIM '%s'", sim->libname));
122 /* Load the library */
123 sim->handle = dlopen(sim->libname, sim->flags);
125 SILC_LOG_ERROR(("Error loading SIM: %s", silc_sim_error(sim)));
132 /* Closes SIM. This is called when execution of program is ending or
133 one explicitly wants to remove this SIM from SILC. */
135 int silc_sim_close(SilcSim sim)
139 SILC_LOG_DEBUG(("Closing SIM '%s'", sim->libname));
141 /* Close the library */
142 dlclose(sim->handle);
148 /* Returns error string if error has occured while processing SIM's. */
150 const char *silc_sim_error(SilcSim sim)
155 /* Returns opaque pointer for a symbol in SIM. Caller must know the
156 symbols they want to get from SIM and use the returned pointer to
157 what ever it is intended. */
159 void *silc_sim_getsym(SilcSim sim, const char *symbol)
163 SILC_LOG_DEBUG(("Getting symbol '%s' from SIM", symbol));
165 return dlsym(sim->handle, symbol);
168 #endif /* SILC_SIM */