5 Author: Pekka Riikonen <priikone@silcnet.org>
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; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 These routines implement the SILC Module (SIM) support. SIM's are
21 dynamically run-time loaded shared objects that can implement some
22 routines SILC can use to extend its features. Currently all
23 SILC Crypto modules are implemented as SIM's. They all implement
24 the SILC Crypto API and can be loaded run-time into the SILC and
27 Basically any SILC API can be implemented as SIM, however, currently
28 only SILC Crypto modules (ciphers and hash functions (PKCS are not
29 supported)) are supported.
31 This implementation expects that no SILC specific symbols needs to
32 be exported into the SIM's. This means that SIM's cannot directly
33 use SILC specific symbols or definitions. This feature can be
34 supported with SIM's but currently (with Crypto modules) this is
37 NOTE: These routines maybe highly system dependant thus I can expect
38 some heavy #ifdef's here. However, I'm more happy to see some macro
39 SIM API and restrict the #ifdef's to silcsim.h file.
46 SILC Module (SIM) Context.
48 This context holds relevant information about the SIM loaded into
49 the system. Following short description of the fields.
53 Pointer to the SIM. This is used to get the symbols out of
54 the SIM. This is initalized by system specific routine.
62 Filename and path to the SIM library file.
66 Flags used with the SIM. These are system specific flags.
67 See below for more information.
70 struct SilcSimStruct {
77 #ifdef SILC_SIM /* SIM upport enabled */
79 /* Allocates new SIM context. This is later send to all SIM
82 SilcSim silc_sim_alloc(SilcSimType type, const char *libname,
87 SILC_LOG_DEBUG(("Initializing new SIM context"));
89 sim = silc_calloc(1, sizeof(*sim));
91 SILC_LOG_ERROR(("Could not allocate new SIM context"));
97 sim->libname = strdup(libname);
98 sim->flags = !flags ? SILC_SIM_FLAGS : flags;
103 /* Free's SIM context. SIM must be closed with silc_sim_close before
106 void silc_sim_free(SilcSim sim)
108 assert(sim->handle == NULL);
109 silc_free(sim->libname);
113 /* Loads SIM into the SILC system. */
115 int silc_sim_load(SilcSim sim)
119 SILC_LOG_DEBUG(("Loading SIM '%s'", sim->libname));
121 /* Load the library */
122 sim->handle = dlopen(sim->libname, sim->flags);
124 SILC_LOG_ERROR(("Error loading SIM: %s", silc_sim_error(sim)));
131 /* Closes SIM. This is called when execution of program is ending or
132 one explicitly wants to remove this SIM from SILC. */
134 int silc_sim_close(SilcSim sim)
138 SILC_LOG_DEBUG(("Closing SIM '%s'", sim->libname));
140 /* Close the library */
141 dlclose(sim->handle);
147 /* Returns error string if error has occured while processing SIM's. */
149 const char *silc_sim_error(SilcSim sim)
154 /* Returns opaque pointer for a symbol in SIM. Caller must know the
155 symbols they want to get from SIM and use the returned pointer to
156 what ever it is intended. */
158 void *silc_sim_getsym(SilcSim sim, const char *symbol)
162 SILC_LOG_DEBUG(("Getting symbol '%s' from SIM", symbol));
164 return dlsym(sim->handle, symbol);
167 #endif /* SILC_SIM */