Merge branch 'plugin_work' of git://github.com/janvidar/uhub
This commit is contained in:
commit
7b96e2c912
22
GNUmakefile
22
GNUmakefile
|
@ -12,6 +12,7 @@ RANLIB := ranlib
|
|||
CFLAGS += -pipe -Wall
|
||||
USE_SSL ?= NO
|
||||
USE_BIGENDIAN ?= AUTO
|
||||
USE_PLUGINS ?= YES
|
||||
BITS ?= AUTO
|
||||
SILENT ?= YES
|
||||
TERSE ?= NO
|
||||
|
@ -42,6 +43,7 @@ UHUB_PREFIX ?= c:/uhub/
|
|||
CFLAGS += -mno-cygwin
|
||||
LDFLAGS += -mno-cygwin
|
||||
BIN_EXT ?= .exe
|
||||
USE_PLUGINS := NO
|
||||
else
|
||||
DESTDIR ?= /
|
||||
UHUB_CONF_DIR ?= $(DESTDIR)/etc/uhub
|
||||
|
@ -118,6 +120,12 @@ CFLAGS += -DSSL_SUPPORT
|
|||
LDLIBS += -lssl
|
||||
endif
|
||||
|
||||
ifeq ($(USE_PLUGINS),YES)
|
||||
CFLAGS += -DPLUGIN_SUPPORT
|
||||
LDLIBS += -ldl
|
||||
endif
|
||||
|
||||
|
||||
GIT_VERSION=$(shell git describe --tags 2>/dev/null || echo "")
|
||||
GIT_REVISION=$(shell git show --abbrev-commit 2>/dev/null | head -n 1 | cut -f 2 -d " " || echo "")
|
||||
OLD_REVISION=$(shell grep GIT_REVISION revision.h 2>/dev/null | cut -f 3 -d " " | tr -d "\"")
|
||||
|
@ -138,6 +146,7 @@ libuhub_SOURCES := \
|
|||
src/core/route.c \
|
||||
src/core/user.c \
|
||||
src/core/usermanager.c \
|
||||
src/core/pluginloader.c \
|
||||
src/network/backend.c \
|
||||
src/network/connection.c \
|
||||
src/network/epoll.c \
|
||||
|
@ -183,6 +192,10 @@ autotest_SOURCES := \
|
|||
|
||||
autotest_OBJECTS = autotest.o
|
||||
|
||||
plugin_example_SOURCES := src/plugins/mod_example.c
|
||||
plugin_example_TARGET := $(plugin_example_SOURCES:.c=.so)
|
||||
|
||||
|
||||
# Source to objects
|
||||
libuhub_OBJECTS := $(libuhub_SOURCES:.c=.o)
|
||||
libadc_client_OBJECTS := $(libadc_client_SOURCES:.c=.o)
|
||||
|
@ -193,14 +206,23 @@ adcrush_OBJECTS := $(adcrush_SOURCES:.c=.o)
|
|||
admin_OBJECTS := $(admin_SOURCES:.c=.o)
|
||||
|
||||
all_OBJECTS := $(libuhub_OBJECTS) $(uhub_OBJECTS) $(adcrush_OBJECTS) $(autotest_OBJECTS) $(admin_OBJECTS) $(libadc_common_OBJECTS) $(libadc_client_OBJECTS)
|
||||
all_plugins := $(plugin_example_TARGET)
|
||||
|
||||
uhub_BINARY=uhub$(BIN_EXT)
|
||||
adcrush_BINARY=adcrush$(BIN_EXT)
|
||||
admin_BINARY=uhub-admin$(BIN_EXT)
|
||||
autotest_BINARY=autotest/test$(BIN_EXT)
|
||||
|
||||
ifeq ($(USE_PLUGINS),YES)
|
||||
all_OBJECTS += $(plugins)
|
||||
endif
|
||||
|
||||
|
||||
.PHONY: revision.h.tmp
|
||||
|
||||
%.so: %.c
|
||||
$(MSG_CC) $(CC) -shared -fPIC -o $@ $< $(CFLAGS)
|
||||
|
||||
%.o: %.c version.h revision.h
|
||||
$(MSG_CC) $(CC) -c $(CFLAGS) -o $@ $<
|
||||
|
||||
|
|
|
@ -490,6 +490,19 @@
|
|||
]]></example>
|
||||
</option>
|
||||
|
||||
<option name="file_plugins" type="file" default="">
|
||||
<short>Plugin configuration file</short>
|
||||
<description><![CDATA[
|
||||
Plugin configuration file.
|
||||
]]></description>
|
||||
<since>0.3.3</since>
|
||||
<example><![CDATA[
|
||||
<p>
|
||||
file_plugins = "/etc/uhub/plugins.conf"
|
||||
</p>
|
||||
]]></example>
|
||||
</option>
|
||||
|
||||
<option name="msg_hub_full" type="message" default="Hub is full" >
|
||||
<description><![CDATA[This will be sent if the hub is full]]></description>
|
||||
<since>0.2.0</since>
|
||||
|
|
|
@ -47,6 +47,7 @@ void config_defaults(struct hub_config* config)
|
|||
config->file_motd = hub_strdup("");
|
||||
config->file_acl = hub_strdup("");
|
||||
config->file_rules = hub_strdup("");
|
||||
config->file_plugins = hub_strdup("");
|
||||
config->msg_hub_full = hub_strdup("Hub is full");
|
||||
config->msg_hub_disabled = hub_strdup("Hub is disabled");
|
||||
config->msg_hub_registered_users_only = hub_strdup("Hub is for registered users only");
|
||||
|
@ -545,6 +546,16 @@ static int apply_config(struct hub_config* config, char* key, char* data, int li
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (!strcmp(key, "file_plugins"))
|
||||
{
|
||||
if (!apply_string(key, data, &config->file_plugins, (char*) ""))
|
||||
{
|
||||
LOG_ERROR("Configuration parse error on line %d", line_count);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!strcmp(key, "msg_hub_full"))
|
||||
{
|
||||
if (!apply_string(key, data, &config->msg_hub_full, (char*) ""))
|
||||
|
@ -932,6 +943,8 @@ void free_config(struct hub_config* config)
|
|||
|
||||
hub_free(config->file_rules);
|
||||
|
||||
hub_free(config->file_plugins);
|
||||
|
||||
hub_free(config->msg_hub_full);
|
||||
|
||||
hub_free(config->msg_hub_disabled);
|
||||
|
@ -1143,6 +1156,9 @@ void dump_config(struct hub_config* config, int ignore_defaults)
|
|||
if (!ignore_defaults || strcmp(config->file_rules, "") != 0)
|
||||
fprintf(stdout, "file_rules = \"%s\"\n", config->file_rules);
|
||||
|
||||
if (!ignore_defaults || strcmp(config->file_plugins, "") != 0)
|
||||
fprintf(stdout, "file_plugins = \"%s\"\n", config->file_plugins);
|
||||
|
||||
if (!ignore_defaults || strcmp(config->msg_hub_full, "Hub is full") != 0)
|
||||
fprintf(stdout, "msg_hub_full = \"%s\"\n", config->msg_hub_full);
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ struct hub_config
|
|||
char* file_motd; /*<<< File containing the 'message of the day (default: ) */
|
||||
char* file_acl; /*<<< File containing access control lists (default: ) */
|
||||
char* file_rules; /*<<< File containing hub rules (default: ) */
|
||||
char* file_plugins; /*<<< Plugin configuration file (default: ) */
|
||||
char* msg_hub_full; /*<<< "Hub is full" */
|
||||
char* msg_hub_disabled; /*<<< "Hub is disabled" */
|
||||
char* msg_hub_registered_users_only; /*<<< "Hub is for registered users only" */
|
||||
|
|
|
@ -806,6 +806,40 @@ void hub_shutdown_service(struct hub_info* hub)
|
|||
g_hub = 0;
|
||||
}
|
||||
|
||||
#ifdef PLUGIN_SUPPORT
|
||||
void hub_plugins_load(struct hub_info* hub)
|
||||
{
|
||||
if (!hub->config->file_plugins || !*hub->config->file_plugins)
|
||||
return;
|
||||
|
||||
hub->plugins = hub_malloc_zero(sizeof(struct uhub_plugins));
|
||||
if (!hub->plugins)
|
||||
return;
|
||||
|
||||
if (plugin_initialize(hub->config, hub->plugins) < 0)
|
||||
{
|
||||
hub_free(hub->plugins);
|
||||
hub->plugins = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void hub_plugins_unload(struct hub_info* hub)
|
||||
{
|
||||
struct uhub_plugin_handle* plugin = (struct uhub_plugin_handle*) list_get_first(hub->plugins->loaded);
|
||||
while (plugin)
|
||||
{
|
||||
plugin_unload(plugin);
|
||||
plugin = (struct uhub_plugin_handle*) list_get_next(hub->plugins->loaded);
|
||||
}
|
||||
|
||||
list_destroy(hub->plugins->loaded);
|
||||
hub_free(hub->plugins->plugin_dir);
|
||||
hub_free(hub->plugins);
|
||||
hub->plugins = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void hub_set_variables(struct hub_info* hub, struct acl_handle* acl)
|
||||
{
|
||||
int fd, ret;
|
||||
|
@ -880,6 +914,10 @@ void hub_set_variables(struct hub_info* hub, struct acl_handle* acl)
|
|||
hub_free(tmp);
|
||||
}
|
||||
|
||||
#ifdef PLUGIN_SUPPORT
|
||||
hub_plugins_load(hub);
|
||||
#endif
|
||||
|
||||
hub->status = (hub->config->hub_enabled ? hub_status_running : hub_status_disabled);
|
||||
hub_free(server);
|
||||
}
|
||||
|
@ -887,6 +925,10 @@ void hub_set_variables(struct hub_info* hub, struct acl_handle* acl)
|
|||
|
||||
void hub_free_variables(struct hub_info* hub)
|
||||
{
|
||||
#ifdef PLUGIN_SUPPORT
|
||||
hub_plugins_unload(hub);
|
||||
#endif
|
||||
|
||||
adc_msg_free(hub->command_info);
|
||||
adc_msg_free(hub->command_banner);
|
||||
|
||||
|
|
|
@ -114,6 +114,10 @@ struct hub_info
|
|||
struct linked_list* chat_history; /* Chat history */
|
||||
struct linked_list* logout_info; /* Log of people logging out. */
|
||||
|
||||
#ifdef PLUGIN_SUPPORT
|
||||
struct uhub_plugins* plugins;
|
||||
#endif
|
||||
|
||||
#ifdef SSL_SUPPORT
|
||||
SSL_METHOD* ssl_method;
|
||||
SSL_CTX* ssl_ctx;
|
||||
|
|
|
@ -0,0 +1,183 @@
|
|||
/*
|
||||
* uhub - A tiny ADC p2p connection hub
|
||||
* Copyright (C) 2007-2010, Jan Vidar Krey
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "uhub.h"
|
||||
|
||||
#ifdef PLUGIN_SUPPORT
|
||||
#include "plugin_api/handle.h"
|
||||
|
||||
struct uhub_plugin* plugin_open(const char* filename)
|
||||
{
|
||||
#ifdef HAVE_DLOPEN
|
||||
struct uhub_plugin* plugin = (struct uhub_plugin*) hub_malloc_zero(sizeof(struct uhub_plugin));
|
||||
if (!plugin)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
plugin->handle = dlopen(filename, RTLD_LAZY);
|
||||
|
||||
if (!plugin->handle)
|
||||
{
|
||||
LOG_ERROR("Unable to open plugin %s: %s", filename, dlerror());
|
||||
hub_free(plugin);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return plugin;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void plugin_close(struct uhub_plugin* plugin)
|
||||
{
|
||||
#ifdef HAVE_DLOPEN
|
||||
dlclose(plugin->handle);
|
||||
hub_free(plugin);
|
||||
#endif
|
||||
}
|
||||
|
||||
void* plugin_lookup_symbol(struct uhub_plugin* plugin, const char* symbol)
|
||||
{
|
||||
#ifdef HAVE_DLOPEN
|
||||
void* addr = dlsym(plugin->handle, symbol);
|
||||
return addr;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
struct uhub_plugin_handle* plugin_load(const char* filename, const char* config)
|
||||
{
|
||||
plugin_register_f register_f;
|
||||
plugin_unregister_f unregister_f;
|
||||
int ret;
|
||||
struct uhub_plugin_handle* handle = hub_malloc_zero(sizeof(struct uhub_plugin_handle));
|
||||
struct uhub_plugin* plugin = plugin_open(filename);
|
||||
|
||||
if (!plugin)
|
||||
return NULL;
|
||||
|
||||
if (!handle)
|
||||
{
|
||||
plugin_close(plugin);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle->handle = plugin;
|
||||
register_f = plugin_lookup_symbol(plugin, "plugin_register");
|
||||
unregister_f = plugin_lookup_symbol(plugin, "plugin_unregister");
|
||||
|
||||
if (register_f && unregister_f)
|
||||
{
|
||||
ret = register_f(handle, config);
|
||||
if (ret == 0)
|
||||
{
|
||||
if (handle->plugin_api_version == PLUGIN_API_VERSION && handle->plugin_funcs_size == sizeof(struct plugin_funcs))
|
||||
{
|
||||
LOG_INFO("Loaded plugin: %s: \"%s\", version %s.", filename, handle->name, handle->version);
|
||||
return handle;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Unable to load plugin: %s - API version mistmatch", filename);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Unable to load plugin: %s - Failed to initialize", filename);
|
||||
}
|
||||
}
|
||||
|
||||
plugin_close(plugin);
|
||||
hub_free(handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void plugin_unload(struct uhub_plugin_handle* plugin)
|
||||
{
|
||||
plugin_close(plugin->handle);
|
||||
}
|
||||
|
||||
static int plugin_parse_line(char* line, int line_count, void* ptr_data)
|
||||
{
|
||||
struct uhub_plugins* handle = (struct uhub_plugins*) ptr_data;
|
||||
char* pos;
|
||||
|
||||
strip_off_ini_line_comments(line, line_count);
|
||||
|
||||
line = strip_white_space(line);
|
||||
if (!*line)
|
||||
return 0;
|
||||
|
||||
LOG_TRACE("plugin: parse line %d: \"%s\"", line_count, line);
|
||||
|
||||
// Set plugin directory.
|
||||
pos = strstr(line, "plugin_directory");
|
||||
if (pos && is_white_space(line[(pos - line) + strlen("plugin_directory")]))
|
||||
{
|
||||
if (handle->plugin_dir)
|
||||
hub_free(handle->plugin_dir);
|
||||
handle->plugin_dir = strdup(strip_white_space(pos + strlen("plugin_directory") + 1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Load plugin
|
||||
pos = strstr(line, "plugin");
|
||||
if (pos && is_white_space(line[(pos - line) + strlen("plugin")]))
|
||||
{
|
||||
char* data = strip_white_space(pos + strlen("plugin") + 1);
|
||||
if (*data)
|
||||
{
|
||||
LOG_TRACE("Load plugin: \"%s\"", data);
|
||||
struct uhub_plugin_handle* plugin = plugin_load(data, "");
|
||||
if (plugin)
|
||||
{
|
||||
list_append(handle->loaded, plugin);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int plugin_initialize(struct hub_config* config, struct uhub_plugins* handle)
|
||||
{
|
||||
int ret;
|
||||
|
||||
handle->loaded = list_create();
|
||||
if (!handle->loaded)
|
||||
return -1;
|
||||
|
||||
if (config)
|
||||
{
|
||||
if (!*config->file_plugins)
|
||||
return 0;
|
||||
|
||||
ret = file_read_lines(config->file_plugins, handle, &plugin_parse_line);
|
||||
if (ret == -1)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif /* PLUGIN_SUPPORT */
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* uhub - A tiny ADC p2p connection hub
|
||||
* Copyright (C) 2007-2010, Jan Vidar Krey
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HAVE_UHUB_PLUGIN_LOADER_H
|
||||
#define HAVE_UHUB_PLUGIN_LOADER_H
|
||||
|
||||
#ifdef PLUGIN_SUPPORT
|
||||
|
||||
struct hub_config;
|
||||
struct linked_list;
|
||||
struct uhub_plugin_handle;
|
||||
|
||||
struct uhub_plugin
|
||||
{
|
||||
#ifdef HAVE_DLOPEN
|
||||
void* handle;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct uhub_plugins
|
||||
{
|
||||
struct linked_list* loaded;
|
||||
char* plugin_dir;
|
||||
};
|
||||
|
||||
// High level plugin loader ode
|
||||
extern struct uhub_plugin_handle* plugin_load(const char* filename, const char* config);
|
||||
extern void plugin_unload(struct uhub_plugin_handle* plugin);
|
||||
|
||||
// extern void plugin_unload(struct uhub_plugin_handle*);
|
||||
extern int plugin_initialize(struct hub_config* config, struct uhub_plugins* handle);
|
||||
|
||||
// Low level plugin loader code (used internally)
|
||||
extern struct uhub_plugin* plugin_open(const char* filename);
|
||||
extern void plugin_close(struct uhub_plugin*);
|
||||
extern void* plugin_lookup_symbol(struct uhub_plugin*, const char* symbol);
|
||||
|
||||
|
||||
|
||||
#endif /* PLUGIN_SUPPORT */
|
||||
|
||||
#endif /* HAVE_UHUB_PLUGIN_LOADER_H */
|
||||
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* uhub - A tiny ADC p2p connection hub
|
||||
* Copyright (C) 2007-2010, Jan Vidar Krey
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "util/ipcalc.h"
|
||||
|
||||
#define PLUGIN_API_VERSION 0
|
||||
|
||||
#ifndef MAX_NICK_LEN
|
||||
#define MAX_NICK_LEN 64
|
||||
#endif
|
||||
|
||||
#ifndef MAX_PASS_LEN
|
||||
#define MAX_PASS_LEN 64
|
||||
#endif
|
||||
|
||||
struct ip_addr_encap;
|
||||
|
||||
struct plugin_user
|
||||
{
|
||||
unsigned int sid;
|
||||
const char* nick;
|
||||
const char* cid;
|
||||
struct ip_addr_encap addr;
|
||||
};
|
||||
|
||||
enum plugin_status
|
||||
{
|
||||
st_default = 0, /* Use default */
|
||||
st_allow = 1, /* Allow action */
|
||||
st_deny = -1, /* Deny action */
|
||||
st_restrict = -2, /* Further action required */
|
||||
};
|
||||
|
||||
typedef enum plugin_status plugin_st;
|
||||
|
||||
enum auth_credentials
|
||||
{
|
||||
auth_cred_none, /**<<< "User has no credentials (not yet logged in)" */
|
||||
auth_cred_bot, /**<<< "User is a robot" */
|
||||
auth_cred_guest, /**<<< "User is a guest (unregistered user)" */
|
||||
auth_cred_user, /**<<< "User is identified as a registered user" */
|
||||
auth_cred_operator, /**<<< "User is identified as a hub operator" */
|
||||
auth_cred_super, /**<<< "User is a super user" (not used) */
|
||||
auth_cred_link, /**<<< "User is a link (not used currently)" */
|
||||
auth_cred_admin, /**<<< "User is identified as a hub administrator/owner" */
|
||||
};
|
||||
|
||||
struct auth_info
|
||||
{
|
||||
char nickname[MAX_NICK_LEN+1];
|
||||
char password[MAX_PASS_LEN+1];
|
||||
enum auth_credentials credentials;
|
||||
};
|
||||
|
||||
typedef plugin_st (*on_connect_t)(struct ip_addr_encap*);
|
||||
typedef plugin_st (*on_chat_msg_t)(struct plugin_user* from, const char* message);
|
||||
typedef plugin_st (*on_private_msg_t)(struct plugin_user* from, struct plugin_user* to, const char* message);
|
||||
typedef plugin_st (*on_search_t)(struct plugin_user* from, const char* data);
|
||||
typedef plugin_st (*on_p2p_connect_t)(struct plugin_user* from, struct plugin_user* to);
|
||||
typedef plugin_st (*on_p2p_revconnect_t)(struct plugin_user* from, struct plugin_user* to);
|
||||
typedef void (*on_user_login_t)(struct plugin_user*);
|
||||
typedef void (*on_user_logout_t)(struct plugin_user*);
|
||||
typedef plugin_st (*on_validate_nick_t)(const char* nick);
|
||||
typedef plugin_st (*on_validate_cid_t)(const char* cid);
|
||||
typedef plugin_st (*on_change_nick_t)(struct plugin_user*, const char* new_nick);
|
||||
typedef int (*auth_get_user_t)(const char* nickname, struct auth_info* info);
|
||||
typedef plugin_st (*auth_register_user_t)(struct auth_info* user);
|
||||
typedef plugin_st (*auth_update_user_t)(struct auth_info* user);
|
||||
typedef plugin_st (*auth_delete_user_t)(struct auth_info* user);
|
||||
|
||||
struct plugin_funcs
|
||||
{
|
||||
// Users logging in and out
|
||||
on_connect_t on_connect;
|
||||
on_user_login_t on_user_login;
|
||||
on_user_logout_t on_user_logout;
|
||||
on_change_nick_t on_user_change_nick;
|
||||
|
||||
// Activity events
|
||||
on_chat_msg_t on_chat_msg;
|
||||
on_private_msg_t on_private_msg;
|
||||
on_search_t on_search;
|
||||
on_p2p_connect_t on_p2p_connect;
|
||||
on_p2p_revconnect_t on_p2p_revconnect;
|
||||
|
||||
// Authentication
|
||||
auth_get_user_t auth_get_user;
|
||||
auth_register_user_t auth_register_user;
|
||||
auth_update_user_t auth_update_user;
|
||||
auth_delete_user_t auth_delete_user;
|
||||
};
|
||||
|
||||
struct uhub_plugin_handle
|
||||
{
|
||||
struct uhub_plugin* handle; /* Must NOT be modified by the plugin */
|
||||
const char* name; /* plugin name */
|
||||
const char* version; /* plugin version */
|
||||
const char* description; /* plugin description */
|
||||
void* ptr; /* Plugin specific data */
|
||||
size_t plugin_api_version; /* Plugin API version */
|
||||
size_t plugin_funcs_size; /* Size of the plugin funcs */
|
||||
struct plugin_funcs funcs;
|
||||
};
|
||||
|
||||
/**
|
||||
* Implemented by the plugin.
|
||||
*
|
||||
* @param handle[out] Sets all information by the plugin
|
||||
* @param config A configuration string
|
||||
* @return 0 on success, -1 on error.
|
||||
*/
|
||||
extern int plugin_register(struct uhub_plugin_handle* handle, const char* config);
|
||||
|
||||
/**
|
||||
* @return 0 on success, -1 on error.
|
||||
*/
|
||||
extern int plugin_unregister(struct uhub_plugin_handle*);
|
||||
|
||||
typedef int (*plugin_register_f)(struct uhub_plugin_handle* handle, const char* config);
|
||||
typedef int (*plugin_unregister_f)(struct uhub_plugin_handle*);
|
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
* This is a minimal example plugin for uhub.
|
||||
*/
|
||||
|
||||
// #include "uhub.h"
|
||||
#include "plugin_api/handle.h"
|
||||
|
||||
int plugin_register(struct uhub_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");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int plugin_unregister(struct uhub_plugin_handle* plugin)
|
||||
{
|
||||
/* No need to do anything! */
|
||||
puts("plugin unregister");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -89,6 +89,8 @@
|
|||
#include <pwd.h>
|
||||
#include <sys/resource.h>
|
||||
#define HAVE_STRNDUP
|
||||
#define HAVE_DLOPEN
|
||||
#include <dlfcn.h>
|
||||
#ifndef __HAIKU__
|
||||
#define HAVE_MEMMEM
|
||||
#endif
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
|
||||
#define MAX_CID_LEN 39
|
||||
#define MAX_NICK_LEN 64
|
||||
#define MAX_PASS_LEN 64
|
||||
#define MAX_UA_LEN 32
|
||||
#define TIGERSIZE 24
|
||||
|
||||
|
@ -80,10 +81,12 @@ extern "C" {
|
|||
#include "core/user.h"
|
||||
#include "core/usermanager.h"
|
||||
#include "core/route.h"
|
||||
#include "core/pluginloader.h"
|
||||
#include "core/hub.h"
|
||||
#include "core/commands.h"
|
||||
#include "core/inf.h"
|
||||
#include "core/hubevent.h"
|
||||
#include "core/pluginloader.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue