diff --git a/src/plugin_api/handle.h b/src/plugin_api/handle.h index bc87959..f9004f0 100644 --- a/src/plugin_api/handle.h +++ b/src/plugin_api/handle.h @@ -24,7 +24,7 @@ #include "util/credentials.h" #include "util/ipcalc.h" -#define PLUGIN_API_VERSION 0 +#define PLUGIN_API_VERSION 1 #ifndef MAX_NICK_LEN #define MAX_NICK_LEN 64 @@ -158,6 +158,18 @@ struct plugin_handle struct plugin_funcs funcs; }; +#define PLUGIN_INITIALIZE(PTR, NAME, VERSION, DESCRIPTION) \ + do { \ + PTR->name = NAME; \ + PTR->version = VERSION; \ + PTR->description = DESCRIPTION; \ + PTR->ptr = NULL; \ + PTR->error_msg = NULL; \ + PTR->plugin_api_version = PLUGIN_API_VERSION; \ + PTR->plugin_funcs_size = sizeof(struct plugin_funcs); \ + memset(&PTR->funcs, 0, sizeof(struct plugin_funcs)); \ + } while (0) + /** * Implemented by the plugin. * diff --git a/src/plugins/mod_auth_simple.c b/src/plugins/mod_auth_simple.c index 0878bdb..5610be6 100644 --- a/src/plugins/mod_auth_simple.c +++ b/src/plugins/mod_auth_simple.c @@ -202,12 +202,7 @@ static plugin_st delete_user(struct plugin_handle* plugin, struct auth_info* use int plugin_register(struct plugin_handle* plugin, const char* config) { - plugin->name = "File authentication plugin"; - plugin->version = "0.1"; - plugin->description = "Authenticate users based on a read-only text file."; - plugin->plugin_api_version = PLUGIN_API_VERSION; - plugin->plugin_funcs_size = sizeof(struct plugin_funcs); - memset(&plugin->funcs, 0, sizeof(struct plugin_funcs)); + PLUGIN_INITIALIZE(plugin, "File authentication plugin", "0.1", "Authenticate users based on a read-only text file."); // Authentication actions. plugin->funcs.auth_get_user = get_user; diff --git a/src/plugins/mod_auth_sqlite.c b/src/plugins/mod_auth_sqlite.c index 87c6da4..08d1d95 100644 --- a/src/plugins/mod_auth_sqlite.c +++ b/src/plugins/mod_auth_sqlite.c @@ -174,12 +174,7 @@ static plugin_st delete_user(struct plugin_handle* plugin, struct auth_info* use int plugin_register(struct plugin_handle* plugin, const char* config) { - plugin->name = "SQLite authentication plugin"; - plugin->version = "0.1"; - plugin->description = "Authenticate users based on a SQLite database."; - plugin->plugin_api_version = PLUGIN_API_VERSION; - plugin->plugin_funcs_size = sizeof(struct plugin_funcs); - memset(&plugin->funcs, 0, sizeof(struct plugin_funcs)); + PLUGIN_INITIALIZE(plugin, "SQLite authentication plugin", "0.1", "Authenticate users based on a SQLite database."); // Authentication actions. plugin->funcs.auth_get_user = get_user; diff --git a/src/plugins/mod_example.c b/src/plugins/mod_example.c index 865ac23..4eaf99c 100644 --- a/src/plugins/mod_example.c +++ b/src/plugins/mod_example.c @@ -6,22 +6,13 @@ int plugin_register(struct plugin_handle* plugin, const char* config) { - plugin->name = "Example plugin"; - plugin->version = "1.0"; - plugin->description = "A simple example plugin"; - plugin->ptr = NULL; - plugin->plugin_api_version = PLUGIN_API_VERSION; - plugin->plugin_funcs_size = sizeof(struct plugin_funcs); - memset(&plugin->funcs, 0, sizeof(struct plugin_funcs)); - - puts("plugin register"); + PLUGIN_INITIALIZE(plugin, "Example plugin", "1.0", "A simple example plugin"); return 0; } int plugin_unregister(struct plugin_handle* plugin) { /* No need to do anything! */ - puts("plugin unregister"); return 0; } diff --git a/src/plugins/mod_logging.c b/src/plugins/mod_logging.c index 707ae4f..118512d 100644 --- a/src/plugins/mod_logging.c +++ b/src/plugins/mod_logging.c @@ -94,13 +94,7 @@ static void log_change_nick(struct plugin_handle* plugin, struct plugin_user* us int plugin_register(struct plugin_handle* plugin, const char* config) { - plugin->name = "Logging plugin"; - plugin->version = "1.0"; - plugin->description = "Logs users entering and leaving the hub."; - plugin->ptr = NULL; - plugin->plugin_api_version = PLUGIN_API_VERSION; - plugin->plugin_funcs_size = sizeof(struct plugin_funcs); - memset(&plugin->funcs, 0, sizeof(struct plugin_funcs)); + PLUGIN_INITIALIZE(plugin, "Logging plugin", "1.0", "Logs users entering and leaving the hub."); plugin->funcs.on_user_login = log_user_login; plugin->funcs.on_user_login_error = log_user_login_error;