diff options
Diffstat (limited to 'auth/eurephia_authplugin_driver.c')
-rw-r--r-- | auth/eurephia_authplugin_driver.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/auth/eurephia_authplugin_driver.c b/auth/eurephia_authplugin_driver.c index e5c1934..1eb76b1 100644 --- a/auth/eurephia_authplugin_driver.c +++ b/auth/eurephia_authplugin_driver.c @@ -35,6 +35,73 @@ #include <eurephia_log.h> #include <eurephia_getsym.h> +/** + * Opens an eurephia plug-in and retrieves a copy of the plug-in information. + * NB! The returned ePluginInfo struct must be explicitly freed, as this is + * a malloced memory region containing a copy of the plug-in info. + * + * @param eurephiaCTX* Pointer to the current eurephia context + * @param dlfilename String containing the filename to the plug-in to inspect + * + * @return Returns a pointer to a copy of the plug-in information on success. Otherwise + * NULL. If not NULL, this result must be freed by using ePluginInfoFree() + */ +ePluginInfoRW* ePluginInspect(eurephiaCTX * ctx, const char * dlfilename) +{ + ePluginInfo *plginf = NULL; + ePluginInfoRW *ret = NULL; + void *dlhandle = NULL; + ePluginInfo * (*PluginInfo)(); + + assert(ctx != NULL); + assert(dlfilename != NULL); + + dlhandle = dlopen(dlfilename, RTLD_NOW); + if (dlhandle == NULL) { + eurephia_log(ctx, LOG_FATAL, 0, "Could not load eurephia plugin %s", + dlfilename); + eurephia_log(ctx, LOG_FATAL, 1, "dlopen error: %s", dlerror()); + return NULL; + } + + PluginInfo = eGetSym(ctx, dlhandle, "PluginInfo"); + if (ctx->fatal_error > 0) { + dlclose(dlhandle); + return NULL; + } + + plginf = PluginInfo(); + + /* Make a copy of the plug-in info, so we can close the plug-in */ + ret = malloc_nullsafe(ctx, sizeof(ePluginInfo)+2); + ret->name = strdup_nullsafe((char *) plginf->name); + ret->version = strdup_nullsafe((char *) plginf->version); + ret->copyright = strdup_nullsafe((char *) plginf->copyright); + ret->pluginType = plginf->pluginType; + ret->APIversion = plginf->APIversion; + + dlclose(dlhandle); + return ret; +} + + +/** + * Frees the memory allocated by ePluginInspect() + * + * @param eurephiaCTX* Pointer to the current eurephia context + * @param ePluginInfo* Pointer to the ePluginInfo buffer to be freed + */ +void ePluginInfoFree(eurephiaCTX *ctx, ePluginInfoRW *plginf) +{ + assert( ctx != NULL ); + assert( plginf != NULL ); + + free_nullsafe(ctx, plginf->name); + free_nullsafe(ctx, plginf->version); + free_nullsafe(ctx, plginf->copyright); + free_nullsafe(ctx, plginf); +} + /** * Helper function used by eAuthPlugin_Init(). This will look-up symbols in an |