Fixed plugin handling when using the utils code from within a plugin.

This commit is contained in:
Jan Vidar Krey 2010-07-08 14:24:40 +02:00
parent b4fa508265
commit 849a791f79
3 changed files with 121 additions and 22 deletions

View File

@ -155,7 +155,14 @@ libuhub_SOURCES := \
src/network/network.c \
src/network/select.c \
src/network/timeout.c \
src/network/timer.c \
src/network/timer.c
libadc_common_SOURCES := \
src/adc/message.c \
src/adc/sid.c
libutils_SOURCES := \
src/util/ipcalc.c \
src/util/list.c \
src/util/log.c \
@ -164,10 +171,6 @@ libuhub_SOURCES := \
src/util/rbtree.c \
src/util/tiger.c
libadc_common_SOURCES := \
src/adc/message.c \
src/adc/sid.c
libadc_client_SOURCES := \
src/tools/adcclient.c
@ -193,15 +196,20 @@ autotest_SOURCES := \
autotest_OBJECTS = autotest.o
# Plugin targets:
plugin_example_SOURCES := src/plugins/mod_example.c
plugin_example_TARGET := $(plugin_example_SOURCES:.c=.so)
plugin_example_TARGET := mod_example.so
plugin_logging_SOURCES := src/plugins/mod_logging.c
plugin_logging_TARGET := $(plugin_example_SOURCES:.c=.so)
plugin_logging_TARGET := mod_logging.so
plugin_auth_SOURCES := src/plugins/mod_auth_simple.c
plugin_auth_TARGET := mod_auth_simple.so
# Source to objects
libuhub_OBJECTS := $(libuhub_SOURCES:.c=.o)
libutils_OBJECTS := $(libutils_SOURCES:.c=.o)
libadc_client_OBJECTS := $(libadc_client_SOURCES:.c=.o)
libadc_common_OBJECTS := $(libadc_common_SOURCES:.c=.o)
@ -209,8 +217,8 @@ uhub_OBJECTS := $(uhub_SOURCES:.c=.o)
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) $(plugin_logging_TARGET)
all_OBJECTS := $(libuhub_OBJECTS) $(uhub_OBJECTS) $(libutils_OBJECTS) $(adcrush_OBJECTS) $(autotest_OBJECTS) $(admin_OBJECTS) $(libadc_common_OBJECTS) $(libadc_client_OBJECTS)
all_plugins := $(plugin_example_TARGET) $(plugin_logging_TARGET) $(plugin_auth_TARGET)
uhub_BINARY=uhub$(BIN_EXT)
adcrush_BINARY=adcrush$(BIN_EXT)
@ -221,24 +229,31 @@ ifeq ($(USE_PLUGINS),YES)
all_OBJECTS += $(plugins)
endif
.PHONY: revision.h.tmp
%.so: %.c
$(MSG_CC) $(CC) -shared -fPIC -o $@ $< $(CFLAGS)
.PHONY: revision.h.tmp all plugins
%.o: %.c version.h revision.h
$(MSG_CC) $(CC) -c $(CFLAGS) -o $@ $<
$(MSG_CC) $(CC) -fPIC -c $(CFLAGS) -o $@ $<
all: $(uhub_BINARY)
$(adcrush_BINARY): $(adcrush_OBJECTS) $(libuhub_OBJECTS) $(libadc_common_OBJECTS) $(libadc_client_OBJECTS)
plugins: $(uhub_BINARY) $(all_plugins)
$(plugin_auth_TARGET): $(plugin_auth_SOURCES) $(libutils_OBJECTS)
$(MSG_CC) $(CC) -shared -fPIC -o $@ $^ $(CFLAGS)
$(plugin_example_TARGET): $(plugin_example_SOURCES)
$(MSG_CC) $(CC) -shared -fPIC -o $@ $^ $(CFLAGS)
$(plugin_logging_TARGET): $(plugin_logging_SOURCES)
$(MSG_CC) $(CC) -shared -fPIC -o $@ $^ $(CFLAGS)
$(adcrush_BINARY): $(adcrush_OBJECTS) $(libuhub_OBJECTS) $(libutils_OBJECTS) $(libadc_common_OBJECTS) $(libadc_client_OBJECTS)
$(MSG_LD) $(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
$(admin_BINARY): $(admin_OBJECTS) $(libuhub_OBJECTS) $(libadc_common_OBJECTS) $(libadc_client_OBJECTS)
$(admin_BINARY): $(admin_OBJECTS) $(libuhub_OBJECTS) $(libutils_OBJECTS) $(libadc_common_OBJECTS) $(libadc_client_OBJECTS)
$(MSG_LD) $(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
$(uhub_BINARY): $(uhub_OBJECTS) $(libuhub_OBJECTS) $(libadc_common_OBJECTS)
$(uhub_BINARY): $(uhub_OBJECTS) $(libuhub_OBJECTS) $(libutils_OBJECTS) $(libadc_common_OBJECTS)
$(MSG_LD) $(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
autotest.c: $(autotest_SOURCES)
@ -259,7 +274,7 @@ revision.h: revision.h.tmp
$(autotest_OBJECTS): autotest.c
$(MSG_CC) $(CC) -c $(CFLAGS) -Isrc -o $@ $<
$(autotest_BINARY): $(autotest_OBJECTS) $(libuhub_OBJECTS) $(libadc_common_OBJECTS) $(libadc_client_OBJECTS)
$(autotest_BINARY): $(autotest_OBJECTS) $(libuhub_OBJECTS) $(libutils_OBJECTS) $(libadc_common_OBJECTS) $(libadc_client_OBJECTS)
$(MSG_LD) $(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
autotest: $(autotest_BINARY)
@ -283,7 +298,7 @@ dist-clean:
@rm -rf $(all_OBJECTS) *~ core
clean:
@rm -rf $(libuhub_OBJECTS) *~ core $(uhub_BINARY) $(admin_BINARY) $(autotest_BINARY) $(adcrush_BINARY) $(all_OBJECTS) autotest.c revision.h revision.h.tmp && \
@rm -rf $(libuhub_OBJECTS) *~ core $(uhub_BINARY) $(admin_BINARY) $(autotest_BINARY) $(adcrush_BINARY) $(all_OBJECTS) $(all_plugins) autotest.c revision.h revision.h.tmp && \
echo $(MSG_CLEAN)

View File

@ -0,0 +1,84 @@
/*
* uhub - A tiny ADC p2p connection hub
* Copyright (C) 2010, Jan Vidar Krey
*/
#include "plugin_api/handle.h"
#include "util/memory.h"
#include "util/list.h"
#include "util/ipcalc.h"
struct user_access_info
{
char* username;
char* password;
enum auth_credentials credentials;
};
struct acl_list
{
struct linked_list* users; /* see struct user_access_info */
};
static void free_user_access_info(void* ptr)
{
struct user_access_info* info = (struct user_access_info*) ptr;
hub_free(info->username);
hub_free(info->password);
hub_free(info);
}
static struct acl_list* load_acl(const char* filename)
{
struct acl_list* list = (struct acl_list*) hub_malloc(sizeof(struct acl_list));
struct linked_list* users = list_create();
if (!list || !users)
{
list_destroy(users);
hub_free(list);
return 0;
}
list->users = users;
return list;
}
static void unload_acl(struct acl_list* list)
{
if (!list)
return;
list_clear(list->users, free_user_access_info);
list_destroy(list->users);
hub_free(list);
}
int plugin_register(struct uhub_plugin_handle* plugin, const char* config)
{
plugin->name = "File authentication plugin";
plugin->version = "0.1";
plugin->description = "Simple authentication plugin that authenticates users based on a 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->ptr = load_acl(config);
/*
plugin->funcs.on_connect = log_connect;
plugin->funcs.on_user_login = log_user_login;
plugin->funcs.on_user_logout = log_user_logout;
plugin->funcs.on_user_change_nick = log_change_nick;
*/
return 0;
}
int plugin_unregister(struct uhub_plugin_handle* plugin)
{
unload_acl(plugin->ptr);
return 0;
}

View File

@ -38,12 +38,12 @@ int plugin_register(struct uhub_plugin_handle* plugin, const char* config)
plugin->plugin_api_version = PLUGIN_API_VERSION;
plugin->plugin_funcs_size = sizeof(struct plugin_funcs);
memset(&plugin->funcs, 0, sizeof(struct plugin_funcs));
/*
plugin->funcs.on_connect = log_connect;
plugin->funcs.on_user_login = log_user_login;
plugin->funcs.on_user_logout = log_user_logout;
plugin->funcs.on_user_change_nick = log_change_nick;
*/
puts("* plugin register");
return 0;
}