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"
46 #ifdef SILC_SIM /* SIM upport enabled */
48 /* Allocates new SIM context. This is later send to all SIM
51 SilcSimContext *silc_sim_alloc()
55 SILC_LOG_DEBUG(("Initializing new SIM context"));
57 new = silc_calloc(1, sizeof(*new));
59 SILC_LOG_ERROR(("Could not allocate new SIM context"));
64 new->type = SILC_SIM_NONE;
66 new->flags = SILC_SIM_FLAGS;
71 /* Free's SIM context. SIM must be closed with silc_sim_close before
74 void silc_sim_free(SilcSimContext *sim)
76 assert(sim->handle == NULL);
82 /* Loads SIM into the SILC system. */
84 int silc_sim_load(SilcSimContext *sim)
88 SILC_LOG_DEBUG(("Loading SIM '%s'", sim->libname));
90 /* Load the library */
91 sim->handle = dlopen(sim->libname, sim->flags);
93 SILC_LOG_ERROR(("Error loading SIM: %s", silc_sim_error()));
100 /* Closes SIM. This is called when execution of program is ending or
101 one explicitly wants to remove this SIM from SILC. */
103 int silc_sim_close(SilcSimContext *sim)
107 SILC_LOG_DEBUG(("Closing SIM '%s'", sim->libname));
109 /* Close the library */
110 dlclose(sim->handle);
116 /* Returns error string if error has occured while processing SIM's. */
118 char *silc_sim_error()
123 /* Returns opaque pointer for a symbol in SIM. Caller must know the
124 symbols they want to get from SIM and use the returned pointer to
125 what ever it is intended. */
127 void *silc_sim_getsym(SilcSimContext *sim, const char *symbol)
131 SILC_LOG_DEBUG(("Getting symbol '%s' from SIM", symbol));
133 return dlsym(sim->handle, symbol);
136 #endif /* SILC_SIM */