From 5ad99fc1bf55e07171e5f175643378287667a181 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Fri, 12 Apr 2013 21:35:32 +0200 Subject: Added function to inspect a plug-in This will temporarily load a plug-in and extract information about it. The gathered information is returned in a struct on success. Signed-off-by: David Sommerseth --- auth/eurephia_authplugin_driver.c | 67 +++++++++++++++++++++++++++++++++++++++ auth/eurephia_authplugin_driver.h | 30 ++++++++++++++++++ auth/eurephia_authplugin_func.h | 4 +++ 3 files changed, 101 insertions(+) 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 #include +/** + * 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 diff --git a/auth/eurephia_authplugin_driver.h b/auth/eurephia_authplugin_driver.h index ebb43b0..97197ed 100644 --- a/auth/eurephia_authplugin_driver.h +++ b/auth/eurephia_authplugin_driver.h @@ -44,6 +44,12 @@ static const char *___ePluginTypeString[] = { NULL }; +static const char *___ePluginTypeShortString[] = { + "auth", /* eptAUTH */ + NULL +}; + + /** * Struct providing plug-in information */ @@ -56,6 +62,19 @@ typedef const struct __ePluginInfo { } ePluginInfo; +/** + * Struct providing plug-in information, a "read-write" + * version of ePluginInfo, used by ePluginInspect() + */ +typedef struct __ePluginInfoRW { + char *name; /**< Readable plug-in name */ + char *version; /**< Plug-in version string */ + char *copyright; /**< Copyright of the plug-in */ + ePluginType pluginType; /**< Plug-in type */ + int APIversion; /**< Plug-in API level support */ +} ePluginInfoRW; + + /** * Simple function for getting a readable string of the plug-in type. * @@ -67,6 +86,17 @@ static inline const char * ePluginTypeString(ePluginInfo *plginf) return ___ePluginTypeString[plginf->pluginType]; } +/** + * Simple function for getting a readable short string of the plug-in type. + * + * @return Returns a char pointer to a static const buffer containing the + * plug-in type. + */ +static inline const char * ePluginTypeShortString(ePluginInfo *plginf) +{ + return ___ePluginTypeShortString[plginf->pluginType]; +} + /** * Authentication result codes diff --git a/auth/eurephia_authplugin_func.h b/auth/eurephia_authplugin_func.h index 08ad728..372f262 100644 --- a/auth/eurephia_authplugin_func.h +++ b/auth/eurephia_authplugin_func.h @@ -65,6 +65,10 @@ void _eAuthPlugin_Close(eurephiaCTX *ctx, eAuthPluginCTX *apctx); * @return Returns a pointer to the plug-in API on success, otherwise NULL */ eAuthPlugin * eAuthPlugin_Get(eAuthPluginCTX *apctx, const int plgid); + +ePluginInfoRW * ePluginInspect(eurephiaCTX * ctx, const char * dlfilename); +void ePluginInfoFree(eurephiaCTX *ctx, ePluginInfoRW *plginf); + #endif /* EUREPHIA_AUTHPLUGIN_DRIVER_H_ */ #endif /* EUREPHIA_AUTHPLUGIN_FUNC_H */ -- cgit