diff --git a/antd-config.ini b/antd-config.ini index be32ac8..dd5125b 100644 --- a/antd-config.ini +++ b/antd-config.ini @@ -112,6 +112,8 @@ name = fastcgi autoload = true ; file handle file_type = php,pp +; +; The following example configurations are application specific ; pluggin specific configurations here, for example socket = /var/php.sock bin = /usr/bin/phpfcgi diff --git a/lib/handle.h b/lib/handle.h index 7f34d39..f648770 100644 --- a/lib/handle.h +++ b/lib/handle.h @@ -28,6 +28,9 @@ #define ANTD_CLIENT_RQ_DATA_DECODE 0x7 #define ANTD_CLIENT_PROXY_MONITOR 0x8 +#define ANTD_PLUGIN_READY 0x0 +#define ANTD_PLUGIN_PANNIC 0x1 + typedef enum { ANTD_CGZ, @@ -111,6 +114,7 @@ typedef struct char* pdir; dictionary_t config; int raw_body; + int status; } plugin_header_t; int __attribute__((weak)) require_plugin(const char *); diff --git a/lib/plugin.h b/lib/plugin.h index f8f5bd3..0805cc2 100644 --- a/lib/plugin.h +++ b/lib/plugin.h @@ -33,6 +33,11 @@ void use_raw_body(); STATIC PART, should be included in any plugin */ #ifdef PLUGIN_IMPLEMENT + +#define PLUGIN_PANIC(a,...) \ + ERROR("%s: "a,__plugin__.name, ##__VA_ARGS__); \ + __plugin__.status = ANTD_PLUGIN_PANNIC; + static plugin_header_t __plugin__; // private function void __init_plugin__(const char* pl, dictionary_t* conf){ @@ -42,6 +47,7 @@ void __init_plugin__(const char* pl, dictionary_t* conf){ tmpdir(&__plugin__.tmpdir); __plugin__.config = conf; __plugin__.raw_body = 0; + __plugin__.status = ANTD_PLUGIN_READY; init(); }; void use_raw_body() diff --git a/plugin_manager.c b/plugin_manager.c index e993071..2b9bfee 100644 --- a/plugin_manager.c +++ b/plugin_manager.c @@ -45,6 +45,9 @@ struct plugin_entry *plugin_load(char *name, dictionary_t config) char* pname = NULL; struct plugin_entry *np; unsigned hashval; + plugin_header_t *(*metafn)(); + plugin_header_t *meta = NULL; + char* error; if(config) { pname = dvalue(config, "name"); @@ -75,7 +78,25 @@ struct plugin_entry *plugin_load(char *name, dictionary_t config) { LOG("The plugin %s id already loaded", name); } - + + // check if plugin is ready + metafn = (plugin_header_t * (*)()) dlsym(np->handle, "meta"); + if ((error = dlerror()) != NULL) + { + ERROR("Unable to fetch plugin meta-data: [%s] %s", name, error); + unload_plugin_by_name(name); + free(np); + return NULL; + } + meta = metafn(); + LOG("PLugin status: [%s] %d", name, meta->status); + if(!meta || meta->status != ANTD_PLUGIN_READY) + { + ERROR("Plugin is not ready or error: [%s].", name); + unload_plugin_by_name(name); + free(np); + return NULL; + } return np; } /**