diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2013-03-04 11:55:54 +0100 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2013-03-04 11:55:54 +0100 |
commit | 5da59efc978fce7b4da71dc967a22647721f78af (patch) | |
tree | 8d2864dac642e2ec52c5b59f42e9bd900d825f7f /auth/eurephia_authplugin.c | |
parent | c4b5ca206e7d9df745a8e74b54d3e3e2fc8dc048 (diff) | |
download | eurephia-5da59efc978fce7b4da71dc967a22647721f78af.tar.gz eurephia-5da59efc978fce7b4da71dc967a22647721f78af.tar.xz eurephia-5da59efc978fce7b4da71dc967a22647721f78af.zip |
auth plug-in: Extended the API to have a PluginInit() function
This can be used to pass a configuration to the authentication plug-in.
Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
Diffstat (limited to 'auth/eurephia_authplugin.c')
-rw-r--r-- | auth/eurephia_authplugin.c | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/auth/eurephia_authplugin.c b/auth/eurephia_authplugin.c index f459e7b..e67b7e6 100644 --- a/auth/eurephia_authplugin.c +++ b/auth/eurephia_authplugin.c @@ -29,6 +29,7 @@ #include <stdlib.h> #include <string.h> #include <dlfcn.h> +#include <assert.h> #define EUREPHIA_AUTHPLUGIN_C_ #define EUREPHIA_CONTEXT_H_ @@ -45,11 +46,58 @@ typedef struct __eurephiaCTX eurephiaCTX; eAuthPlugin * __eAuthPlugin_Setup(eurephiaCTX * ctx, const char * dlfilename, void * dlhandle); +struct __PluginDataSplit { + const char *dsofile; + const char *configstr; +}; + +/** + * Splits the plug-in data from the database into a more easily managable + * struct. This struct will only use pointers to the input string (dbstr) + * And the input string will be slightly modified. + * + * The format of the input data is: + * [<DSO filename>]<Configuration string> + * + * @param ret* The parsed result will be saved into in the provided struct + * @param dbstr* The string returned by the database, containing plug-in data + * + * @return Data is returned via the ret* pointer + */ +void __split_plugin_data_str(struct __PluginDataSplit *ret, char *dbstr) +{ + char *ptr = NULL; + + assert(ret != NULL); + assert(dbstr != NULL); + + ret->dsofile = NULL; + ret->configstr = NULL; + + /* The input string must start with '[' */ + if (dbstr[0] != '[') { + return; + } + + /* Locate the ']' part. This will be replaced by a NULL terminator */ + ptr = strpbrk(dbstr, "]"); + if (ptr == NULL) { + /* If not found, abort */ + return; + } + + dbstr[0] = 0; /* NULL terminate it on purpose */ + ret->dsofile = dbstr+1; + *ptr = 0; /* NULL terminate the ']' place */ + ret->configstr = ptr+1; +} + eAuthPluginCTX * eAuthPlugin_Init(eurephiaCTX * ctx) { eurephiaVALUES *plgs = NULL, *plgptr; eAuthPluginCTX *apctx = NULL, *apctxhead = NULL; + struct __PluginDataSplit plgdata; // Query the database for authentication plugins plgs = eDBget_plugins(ctx, "auth"); @@ -65,16 +113,20 @@ eAuthPluginCTX * eAuthPlugin_Init(eurephiaCTX * ctx) continue; } + __split_plugin_data_str(&plgdata, plgptr->val); + // Create a plug-in context apctx = malloc_nullsafe(ctx, sizeof(eAuthPluginCTX)+2); // Save some metadata about this plugin - apctx->filename = strdup(plgptr->val); + apctx->filename = strdup(plgdata.dsofile); apctx->plgid = atoi_nullsafe(plgptr->key); apctx->next = NULL; // Open the plugin apctx->dlhandle = dlopen(apctx->filename, RTLD_NOW); if (apctx->dlhandle != NULL) { + int success = 0; + // If we got a handle to the plug-in, it up apctx->plugin = __eAuthPlugin_Setup(ctx, apctx->filename, apctx->dlhandle); if (apctx->plugin != NULL) { @@ -84,6 +136,12 @@ eAuthPluginCTX * eAuthPlugin_Init(eurephiaCTX * ctx) "Loaded eurephia %s plugin: %s (v%s) %s", ePluginTypeString(plginfo), plginfo->name, plginfo->version, plginfo->copyright); + + // Initialise the plug-in + success = apctx->plugin->PluginInit(ctx, plgdata.configstr); + } + + if (success == 1) { // On success, add this plug-in to the context chain if( apctxhead != NULL ) { apctx->next = apctxhead; |