Added plugin loader code, merely a wrapper around dlopen() and friends.
This commit is contained in:
parent
fc8965f1c5
commit
ed53034ad5
@ -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 \
|
||||
|
66
src/core/pluginloader.c
Normal file
66
src/core/pluginloader.c
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
struct uhub_plugin* uhub_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 uhub_plugin_close(struct uhub_plugin* plugin)
|
||||
{
|
||||
#ifdef HAVE_DLOPEN
|
||||
dlclose(plugin->handle);
|
||||
hub_free(plugin);
|
||||
#endif
|
||||
}
|
||||
|
||||
void* uhub_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
|
||||
}
|
||||
|
||||
#endif /* PLUGIN_SUPPORT */
|
41
src/core/pluginloader.h
Normal file
41
src/core/pluginloader.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 uhub_plugin
|
||||
{
|
||||
#ifdef HAVE_DLOPEN
|
||||
void* handle;
|
||||
#endif
|
||||
};
|
||||
|
||||
extern struct uhub_plugin* uhub_plugin_open(const char* filename);
|
||||
|
||||
extern void uhub_plugin_close(struct uhub_plugin*);
|
||||
|
||||
extern void* uhub_plugin_lookup_symbol(struct uhub_plugin*, const char* symbol);
|
||||
|
||||
#endif /* PLUGIN_SUPPORT */
|
||||
|
||||
#endif /* HAVE_UHUB_PLUGIN_LOADER_H */
|
||||
|
@ -23,9 +23,9 @@
|
||||
enum user_credentials
|
||||
{
|
||||
cred_none, /**<<< "User has no credentials (not yet logged in)" */
|
||||
cred_bot, /**<<< "User is a robot" */
|
||||
cred_bot, /**<<< "User is a robot" */
|
||||
cred_guest, /**<<< "User is a guest (unregistered user)" */
|
||||
cred_user, /**<<< "User is identified as a registered user" */
|
||||
cred_user, /**<<< "User is identified as a registered user" */
|
||||
cred_operator, /**<<< "User is identified as a hub operator" */
|
||||
cred_super, /**<<< "User is a super user" (not used) */
|
||||
cred_link, /**<<< "User is a link (not used currently)" */
|
||||
|
@ -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
|
||||
|
@ -84,6 +84,7 @@ extern "C" {
|
||||
#include "core/commands.h"
|
||||
#include "core/inf.h"
|
||||
#include "core/hubevent.h"
|
||||
#include "core/pluginloader.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user