Simplified plugin initialization by using a macro.
This commit is contained in:
parent
ff8b8f5175
commit
21c22288a2
@ -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.
|
||||
*
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user