Compare commits

..

1 Commits

Author SHA1 Message Date
Jan Vidar Krey
e8957db819 Minor work on getting history command to be configurable and also
display a certain number of main chat history lines after login.
2010-05-19 20:51:13 +02:00
28 changed files with 116 additions and 971 deletions

View File

@@ -12,7 +12,6 @@ RANLIB := ranlib
CFLAGS += -pipe -Wall CFLAGS += -pipe -Wall
USE_SSL ?= NO USE_SSL ?= NO
USE_BIGENDIAN ?= AUTO USE_BIGENDIAN ?= AUTO
USE_PLUGINS ?= YES
BITS ?= AUTO BITS ?= AUTO
SILENT ?= YES SILENT ?= YES
TERSE ?= NO TERSE ?= NO
@@ -43,7 +42,6 @@ UHUB_PREFIX ?= c:/uhub/
CFLAGS += -mno-cygwin CFLAGS += -mno-cygwin
LDFLAGS += -mno-cygwin LDFLAGS += -mno-cygwin
BIN_EXT ?= .exe BIN_EXT ?= .exe
USE_PLUGINS := NO
else else
DESTDIR ?= / DESTDIR ?= /
UHUB_CONF_DIR ?= $(DESTDIR)/etc/uhub UHUB_CONF_DIR ?= $(DESTDIR)/etc/uhub
@@ -120,12 +118,6 @@ CFLAGS += -DSSL_SUPPORT
LDLIBS += -lssl LDLIBS += -lssl
endif endif
ifeq ($(USE_PLUGINS),YES)
CFLAGS += -DPLUGIN_SUPPORT
LDLIBS += -ldl
endif
GIT_VERSION=$(shell git describe --tags 2>/dev/null || echo "") 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 "") 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 "\"") OLD_REVISION=$(shell grep GIT_REVISION revision.h 2>/dev/null | cut -f 3 -d " " | tr -d "\"")
@@ -146,8 +138,6 @@ libuhub_SOURCES := \
src/core/route.c \ src/core/route.c \
src/core/user.c \ src/core/user.c \
src/core/usermanager.c \ src/core/usermanager.c \
src/core/plugininvoke.c \
src/core/pluginloader.c \
src/network/backend.c \ src/network/backend.c \
src/network/connection.c \ src/network/connection.c \
src/network/epoll.c \ src/network/epoll.c \
@@ -193,13 +183,6 @@ autotest_SOURCES := \
autotest_OBJECTS = autotest.o autotest_OBJECTS = autotest.o
plugin_example_SOURCES := src/plugins/mod_example.c
plugin_example_TARGET := $(plugin_example_SOURCES:.c=.so)
plugin_logging_SOURCES := src/plugins/mod_logging.c
plugin_logging_TARGET := $(plugin_example_SOURCES:.c=.so)
# Source to objects # Source to objects
libuhub_OBJECTS := $(libuhub_SOURCES:.c=.o) libuhub_OBJECTS := $(libuhub_SOURCES:.c=.o)
libadc_client_OBJECTS := $(libadc_client_SOURCES:.c=.o) libadc_client_OBJECTS := $(libadc_client_SOURCES:.c=.o)
@@ -210,23 +193,14 @@ adcrush_OBJECTS := $(adcrush_SOURCES:.c=.o)
admin_OBJECTS := $(admin_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_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)
uhub_BINARY=uhub$(BIN_EXT) uhub_BINARY=uhub$(BIN_EXT)
adcrush_BINARY=adcrush$(BIN_EXT) adcrush_BINARY=adcrush$(BIN_EXT)
admin_BINARY=uhub-admin$(BIN_EXT) admin_BINARY=uhub-admin$(BIN_EXT)
autotest_BINARY=autotest/test$(BIN_EXT) autotest_BINARY=autotest/test$(BIN_EXT)
ifeq ($(USE_PLUGINS),YES)
all_OBJECTS += $(plugins)
endif
.PHONY: revision.h.tmp .PHONY: revision.h.tmp
%.so: %.c
$(MSG_CC) $(CC) -shared -fPIC -o $@ $< $(CFLAGS)
%.o: %.c version.h revision.h %.o: %.c version.h revision.h
$(MSG_CC) $(CC) -c $(CFLAGS) -o $@ $< $(MSG_CC) $(CC) -c $(CFLAGS) -o $@ $<

View File

@@ -756,7 +756,7 @@ char* adc_msg_get_argument(struct adc_message* cmd, int offset)
else else
{ {
argument = hub_strdup(&start[1]); argument = hub_strdup(&start[1]);
if (argument && *argument && argument[strlen(argument)-1] == '\n') if (argument && argument[strlen(argument)-1] == '\n')
argument[strlen(argument)-1] = 0; argument[strlen(argument)-1] = 0;
} }

View File

@@ -1,6 +1,6 @@
/* /*
* uhub - A tiny ADC p2p connection hub * uhub - A tiny ADC p2p connection hub
* Copyright (C) 2007-2010, Jan Vidar Krey * Copyright (C) 2007-2009, Jan Vidar Krey
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -176,10 +176,14 @@ static int check_cmd_addr(const char* cmd, struct linked_list* list, char* line,
static int acl_parse_line(char* line, int line_count, void* ptr_data) static int acl_parse_line(char* line, int line_count, void* ptr_data)
{ {
char* pos;
struct acl_handle* handle = (struct acl_handle*) ptr_data; struct acl_handle* handle = (struct acl_handle*) ptr_data;
int ret; int ret;
strip_off_ini_line_comments(line, line_count); if ((pos = strchr(line, '#')) != NULL)
{
pos[0] = 0;
}
line = strip_white_space(line); line = strip_white_space(line);
if (!*line) if (!*line)

View File

@@ -1,6 +1,6 @@
/* /*
* uhub - A tiny ADC p2p connection hub * uhub - A tiny ADC p2p connection hub
* Copyright (C) 2007-2010, Jan Vidar Krey * Copyright (C) 2007-2009, Jan Vidar Krey
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -132,19 +132,40 @@ static int command_status_user_not_found(struct hub_info* hub, struct hub_user*
const char* command_get_syntax(struct commands_handler* handler) const char* command_get_syntax(struct commands_handler* handler)
{ {
static char args[128]; static char args[128];
int optional = 0;
size_t n = 0; size_t n = 0;
args[0] = 0; args[0] = 0;
if (handler->args) if (handler->args)
{ {
for (n = 0; n < strlen(handler->args); n++) for (n = 0; n < strlen(handler->args); n++)
{ {
// detect optionals
if (handler->args[n] == '?')
{
optional = 1;
continue;
}
if (n > 0) strcat(args, " "); if (n > 0) strcat(args, " ");
if (optional)
{
strcat(args, "[");
}
switch (handler->args[n]) switch (handler->args[n])
{ {
case 'n': strcat(args, "<nick>"); break; case 'n': strcat(args, "<nick>"); break;
case 'c': strcat(args, "<cid>"); break; case 'c': strcat(args, "<cid>"); break;
case 'a': strcat(args, "<addr>"); break; case 'a': strcat(args, "<addr>"); break;
case 'm': strcat(args, "<message>"); break; case 'm': strcat(args, "<message>"); break;
case 'i': strcat(args, "<number>"); break;
}
if (optional)
{
strcat(args, "]");
optional = 0;
} }
} }
} }
@@ -412,48 +433,11 @@ static int command_whoip(struct hub_info* hub, struct hub_user* user, struct hub
static int command_broadcast(struct hub_info* hub, struct hub_user* user, struct hub_command* cmd) static int command_broadcast(struct hub_info* hub, struct hub_user* user, struct hub_command* cmd)
{ {
size_t offset = 12; struct adc_message* command = adc_msg_construct(ADC_CMD_IMSG, strlen((cmd->message + 12)) + 6);
#if USE_OLD_BROADCAST_STYLE adc_msg_add_argument(command, (cmd->message + 12));
struct adc_message* command = adc_msg_construct(ADC_CMD_IMSG, strlen((cmd->message + offset)) + 6);
adc_msg_add_argument(command, (cmd->message + offset));
route_to_all(hub, command); route_to_all(hub, command);
adc_msg_free(command); adc_msg_free(command);
return 0; return 0;
#else
size_t message_len = strlen(cmd->message + offset);
struct adc_message* command = 0;
char pm_flag[7] = "PM";
char from_sid[5];
char buffer[128];
size_t recipients = 0;
memcpy(from_sid, sid_to_string(user->id.sid), sizeof(from_sid));
memcpy(pm_flag + 2, from_sid, sizeof(from_sid));
struct hub_user* target = (struct hub_user*) list_get_first(hub->users->list);
while (target)
{
if (target != user)
{
recipients++;
command = adc_msg_construct(ADC_CMD_DMSG, message_len + 23);
if (!command)
break;
adc_msg_add_argument(command, from_sid);
adc_msg_add_argument(command, sid_to_string(target->id.sid));
adc_msg_add_argument(command, (cmd->message + offset));
adc_msg_add_argument(command, pm_flag);
route_to_user(hub, target, command);
adc_msg_free(command);
}
target = (struct hub_user*) list_get_next(hub->users->list);
}
snprintf(buffer, sizeof(buffer), "*** %s: Delivered to " PRINTF_SIZE_T " user%s", cmd->prefix, recipients, (recipients != 1 ? "s" : ""));
return 0;
#endif
} }
static int command_history(struct hub_info* hub, struct hub_user* user, struct hub_command* cmd) static int command_history(struct hub_info* hub, struct hub_user* user, struct hub_command* cmd)
@@ -643,7 +627,7 @@ static struct commands_handler command_handlers[] = {
#endif #endif
{ "getip", 5, "n", cred_operator, command_getip, "Show IP address for a user" }, { "getip", 5, "n", cred_operator, command_getip, "Show IP address for a user" },
{ "help", 4, 0, cred_guest, command_help, "Show this help message." }, { "help", 4, 0, cred_guest, command_help, "Show this help message." },
{ "history", 7, 0, cred_guest, command_history, "Show the last chat messages." }, { "history", 7, "?i",cred_guest, command_history, "Show the last chat messages." },
{ "kick", 4, "n", cred_operator, command_kick, "Kick a user" }, { "kick", 4, "n", cred_operator, command_kick, "Kick a user" },
{ "log", 3, 0, cred_operator, command_log, "Display log" }, { "log", 3, 0, cred_operator, command_log, "Display log" },
{ "motd", 4, 0, cred_guest, command_motd, "Show the message of the day" }, { "motd", 4, 0, cred_guest, command_motd, "Show the message of the day" },

View File

@@ -85,8 +85,11 @@ static int config_parse_line(char* line, int line_count, void* ptr_data)
char* data; char* data;
struct hub_config* config = (struct hub_config*) ptr_data; struct hub_config* config = (struct hub_config*) ptr_data;
strip_off_ini_line_comments(line, line_count); if ((pos = strchr(line, '#')) != NULL)
{
pos[0] = 0;
}
if (!*line) return 0; if (!*line) return 0;
LOG_DUMP("config_parse_line(): '%s'", line); LOG_DUMP("config_parse_line(): '%s'", line);

View File

@@ -211,6 +211,17 @@
<since>0.3.0</since> <since>0.3.0</since>
</option> </option>
<option name="history_on_login" type="int" default="0">
<check min="0" max="250" />
<short>Send chat message history when logging in</short>
<description><![CDATA[
This specifies the number of chat messages that are sent to all users when logging in.
Users can use the "!history" command to list these messages later.
]]></description>
<since>0.3.2</since>
</option>
<option name="max_logout_log" type="int" default="20"> <option name="max_logout_log" type="int" default="20">
<check min="0" max="2000" /> <check min="0" max="2000" />
<short>Number of log entries for people leaving the hub</short> <short>Number of log entries for people leaving the hub</short>
@@ -490,19 +501,6 @@
]]></example> ]]></example>
</option> </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" > <option name="msg_hub_full" type="message" default="Hub is full" >
<description><![CDATA[This will be sent if the hub is full]]></description> <description><![CDATA[This will be sent if the hub is full]]></description>
<since>0.2.0</since> <since>0.2.0</since>

View File

@@ -47,7 +47,6 @@ void config_defaults(struct hub_config* config)
config->file_motd = hub_strdup(""); config->file_motd = hub_strdup("");
config->file_acl = hub_strdup(""); config->file_acl = hub_strdup("");
config->file_rules = hub_strdup(""); config->file_rules = hub_strdup("");
config->file_plugins = hub_strdup("");
config->msg_hub_full = hub_strdup("Hub is full"); config->msg_hub_full = hub_strdup("Hub is full");
config->msg_hub_disabled = hub_strdup("Hub is disabled"); config->msg_hub_disabled = hub_strdup("Hub is disabled");
config->msg_hub_registered_users_only = hub_strdup("Hub is for registered users only"); config->msg_hub_registered_users_only = hub_strdup("Hub is for registered users only");
@@ -546,16 +545,6 @@ static int apply_config(struct hub_config* config, char* key, char* data, int li
return 0; 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 (!strcmp(key, "msg_hub_full"))
{ {
if (!apply_string(key, data, &config->msg_hub_full, (char*) "")) if (!apply_string(key, data, &config->msg_hub_full, (char*) ""))
@@ -943,8 +932,6 @@ void free_config(struct hub_config* config)
hub_free(config->file_rules); hub_free(config->file_rules);
hub_free(config->file_plugins);
hub_free(config->msg_hub_full); hub_free(config->msg_hub_full);
hub_free(config->msg_hub_disabled); hub_free(config->msg_hub_disabled);
@@ -1156,9 +1143,6 @@ void dump_config(struct hub_config* config, int ignore_defaults)
if (!ignore_defaults || strcmp(config->file_rules, "") != 0) if (!ignore_defaults || strcmp(config->file_rules, "") != 0)
fprintf(stdout, "file_rules = \"%s\"\n", config->file_rules); 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) if (!ignore_defaults || strcmp(config->msg_hub_full, "Hub is full") != 0)
fprintf(stdout, "msg_hub_full = \"%s\"\n", config->msg_hub_full); fprintf(stdout, "msg_hub_full = \"%s\"\n", config->msg_hub_full);

View File

@@ -47,7 +47,6 @@ struct hub_config
char* file_motd; /*<<< File containing the 'message of the day (default: ) */ char* file_motd; /*<<< File containing the 'message of the day (default: ) */
char* file_acl; /*<<< File containing access control lists (default: ) */ char* file_acl; /*<<< File containing access control lists (default: ) */
char* file_rules; /*<<< File containing hub rules (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_full; /*<<< "Hub is full" */
char* msg_hub_disabled; /*<<< "Hub is disabled" */ char* msg_hub_disabled; /*<<< "Hub is disabled" */
char* msg_hub_registered_users_only; /*<<< "Hub is for registered users only" */ char* msg_hub_registered_users_only; /*<<< "Hub is for registered users only" */

View File

@@ -257,15 +257,9 @@ int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc
int relay = 1; int relay = 1;
int offset; int offset;
if (!message) if (!message || !user_is_logged_in(u))
return 0; return 0;
if (!user_is_logged_in(u))
{
hub_free(message);
return 0;
}
if ((cmd->cache[0] == 'B') && (message[0] == '!' || message[0] == '+')) if ((cmd->cache[0] == 'B') && (message[0] == '!' || message[0] == '+'))
{ {
/* /*
@@ -486,11 +480,11 @@ void hub_send_flood_warning(struct hub_info* hub, struct hub_user* u, const char
adc_msg_add_argument(msg, "110"); adc_msg_add_argument(msg, "110");
adc_msg_add_argument(msg, tmp); adc_msg_add_argument(msg, tmp);
hub_free(tmp); hub_free(tmp);
route_to_user(hub, u, msg);
user_flag_set(u, flag_flood);
adc_msg_free(msg);
} }
route_to_user(hub, u, msg);
user_flag_set(u, flag_flood);
adc_msg_free(msg);
} }
static void hub_event_dispatcher(void* callback_data, struct event_data* message) static void hub_event_dispatcher(void* callback_data, struct event_data* message)
@@ -806,45 +800,6 @@ void hub_shutdown_service(struct hub_info* hub)
g_hub = 0; 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)
{
if (!hub->plugins || !hub->plugins->loaded)
{
return;
}
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) void hub_set_variables(struct hub_info* hub, struct acl_handle* acl)
{ {
int fd, ret; int fd, ret;
@@ -919,10 +874,6 @@ void hub_set_variables(struct hub_info* hub, struct acl_handle* acl)
hub_free(tmp); hub_free(tmp);
} }
#ifdef PLUGIN_SUPPORT
hub_plugins_load(hub);
#endif
hub->status = (hub->config->hub_enabled ? hub_status_running : hub_status_disabled); hub->status = (hub->config->hub_enabled ? hub_status_running : hub_status_disabled);
hub_free(server); hub_free(server);
} }
@@ -930,10 +881,6 @@ void hub_set_variables(struct hub_info* hub, struct acl_handle* acl)
void hub_free_variables(struct hub_info* hub) 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_info);
adc_msg_free(hub->command_banner); adc_msg_free(hub->command_banner);
@@ -997,7 +944,7 @@ void hub_send_status(struct hub_info* hub, struct hub_user* user, enum status_me
struct adc_message* cmd = adc_msg_construct(ADC_CMD_ISTA, 6); struct adc_message* cmd = adc_msg_construct(ADC_CMD_ISTA, 6);
struct adc_message* qui = adc_msg_construct(ADC_CMD_IQUI, 512); struct adc_message* qui = adc_msg_construct(ADC_CMD_IQUI, 512);
char code[4]; char code[4];
char buf[256]; char buf[250];
const char* text = 0; const char* text = 0;
const char* flag = 0; const char* flag = 0;
char* escaped_text = 0; char* escaped_text = 0;

View File

@@ -114,10 +114,6 @@ struct hub_info
struct linked_list* chat_history; /* Chat history */ struct linked_list* chat_history; /* Chat history */
struct linked_list* logout_info; /* Log of people logging out. */ struct linked_list* logout_info; /* Log of people logging out. */
#ifdef PLUGIN_SUPPORT
struct uhub_plugins* plugins;
#endif
#ifdef SSL_SUPPORT #ifdef SSL_SUPPORT
SSL_METHOD* ssl_method; SSL_METHOD* ssl_method;
SSL_CTX* ssl_ctx; SSL_CTX* ssl_ctx;

View File

@@ -18,7 +18,6 @@
*/ */
#include "uhub.h" #include "uhub.h"
#include "plugin_api/handle.h"
static void log_user_login(struct hub_user* u) static void log_user_login(struct hub_user* u)
{ {
@@ -68,10 +67,6 @@ void on_login_success(struct hub_info* hub, struct hub_user* u)
/* Print log message */ /* Print log message */
log_user_login(u); log_user_login(u);
#ifdef PLUGIN_SUPPORT
plugin_log_user_login_success(hub, u);
#endif
/* Announce new user to all connected users */ /* Announce new user to all connected users */
if (user_is_logged_in(u)) if (user_is_logged_in(u))
route_info_message(hub, u); route_info_message(hub, u);
@@ -114,11 +109,6 @@ void on_logout_user(struct hub_info* hub, struct hub_user* user)
{ {
const char* reason = user_get_quit_reason_string(user->quit_reason); const char* reason = user_get_quit_reason_string(user->quit_reason);
log_user_logout(user, reason); log_user_logout(user, reason);
#ifdef PLUGIN_SUPPORT
plugin_log_user_logout(hub, user);
#endif
hub_logout_log(hub, user); hub_logout_log(hub, user);
} }

View File

@@ -175,10 +175,8 @@ void net_on_accept(struct net_connection* con, int event, void *arg)
struct hub_info* hub = (struct hub_info*) arg; struct hub_info* hub = (struct hub_info*) arg;
struct hub_probe* probe = 0; struct hub_probe* probe = 0;
struct ip_addr_encap ipaddr; struct ip_addr_encap ipaddr;
const char* addr;
int server_fd = net_con_get_sd(con); int server_fd = net_con_get_sd(con);
#ifdef PLUGIN_SUPPORT
plugin_st status;
#endif
for (;;) for (;;)
{ {
@@ -196,18 +194,19 @@ void net_on_accept(struct net_connection* con, int event, void *arg)
} }
} }
#ifdef PLUGIN_SUPPORT addr = ip_convert_to_string(&ipaddr);
status = plugin_check_ip_early(hub, &ipaddr);
if (status == st_deny) /* FIXME: Should have a plugin log this */
LOG_TRACE("Got connection from %s", addr);
/* FIXME: A plugin should perform this check: is IP banned? */
if (acl_is_ip_banned(hub->acl, addr))
{ {
plugin_log_connection_denied(hub, &ipaddr); LOG_INFO("Denied [%s] (IP banned)", addr);
net_close(fd); net_close(fd);
continue; continue;
} }
plugin_log_connection_accepted(hub, &ipaddr);
#endif
probe = probe_create(hub, fd, &ipaddr); probe = probe_create(hub, fd, &ipaddr);
if (!probe) if (!probe)
{ {

View File

@@ -1,89 +0,0 @@
/*
* 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"
#include "plugin_api/handle.h"
#define PLUGIN_INVOKE(HUB, FUNCNAME, CODE) \
if (HUB->plugins && HUB->plugins->loaded) \
{ \
struct uhub_plugin_handle* plugin = (struct uhub_plugin_handle*) list_get_first(HUB->plugins->loaded); \
while (plugin) \
{ \
if (plugin->funcs.FUNCNAME) \
CODE \
plugin = (struct uhub_plugin_handle*) list_get_next(HUB->plugins->loaded); \
} \
}
plugin_st plugin_check_ip_early(struct hub_info* hub, struct ip_addr_encap* addr)
{
plugin_st status = st_default;
PLUGIN_INVOKE(hub, login_check_ip_early, {
status = plugin->funcs.login_check_ip_early(addr);
if (status != st_default)
break;
});
return status;
}
plugin_st plugin_check_ip_late(struct hub_info* hub, struct ip_addr_encap* addr)
{
plugin_st status = st_default;
PLUGIN_INVOKE(hub, login_check_ip_late, {
status = plugin->funcs.login_check_ip_late(addr);
if (status != st_default)
break;
});
return status;
}
void plugin_log_connection_accepted(struct hub_info* hub, struct ip_addr_encap* ipaddr)
{
const char* addr = ip_convert_to_string(ipaddr);
LOG_TRACE("Got connection from %s", addr);
}
void plugin_log_connection_denied(struct hub_info* hub, struct ip_addr_encap* ipaddr)
{
const char* addr = ip_convert_to_string(ipaddr);
LOG_INFO("Denied connection from %s", addr);
}
void plugin_log_user_login_success(struct hub_info* hub, struct hub_user* user)
{
}
void plugin_log_user_login_error(struct hub_info* hub, struct hub_user* user)
{
}
void plugin_log_user_logout(struct hub_info* hub, struct hub_user* user)
{
}
void convert_user_to_plugin_user(struct plugin_user* puser, struct hub_user* user)
{
puser->sid = user->id.sid;
puser->nick = user->id.nick;
puser->cid = user->id.cid;
puser->addr = user->id.addr;
}

View File

@@ -1,46 +0,0 @@
/*
* 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_INVOKE_H
#define HAVE_UHUB_PLUGIN_INVOKE_H
#include "uhub.h"
#include "plugin_api/handle.h"
#ifdef PLUGIN_SUPPORT
struct hub_info;
struct ip_addr_encap;
void plugin_log_connection_accepted(struct hub_info* hub, struct ip_addr_encap* addr);
void plugin_log_connection_denied(struct hub_info* hub, struct ip_addr_encap* addr);
void plugin_log_user_login_success(struct hub_info* hub, struct hub_user* user);
void plugin_log_user_login_error(struct hub_info* hub, struct hub_user* user);
void plugin_log_user_logout(struct hub_info* hub, struct hub_user* user);
plugin_st plugin_check_ip_early(struct hub_info* hub, struct ip_addr_encap* addr);
plugin_st plugin_check_ip_late(struct hub_info* hub, struct ip_addr_encap* addr);
plugin_st plugin_check_nickname_valid(struct hub_info* hub, const char* nick);
plugin_st plugin_check_nickname_reserved(struct hub_info* hub, const char* nick);
#endif
#endif // HAVE_UHUB_PLUGIN_INVOKE_H

View File

@@ -1,187 +0,0 @@
/*
* 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)
{
LOG_TRACE("plugin_open: \"%s\"", 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);
LOG_TRACE("Plugin API version: %d (func table size: " PRINTF_SIZE_T ")", handle->plugin_api_version, handle->plugin_funcs_size);
plugin->unregister = unregister_f;
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->handle->unregister(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 */

View File

@@ -1,62 +0,0 @@
/*
* 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
#include "plugin_api/handle.h"
#ifdef PLUGIN_SUPPORT
struct hub_config;
struct linked_list;
struct uhub_plugin_handle;
struct uhub_plugin
{
#ifdef HAVE_DLOPEN
void* handle;
#endif
plugin_unregister_f unregister;
};
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 */

View File

@@ -92,10 +92,9 @@ static void probe_net_event(struct net_connection* con, int events, void *arg)
net_con_ssl_handshake(con, net_con_ssl_mode_server, probe->hub->ssl_ctx); net_con_ssl_handshake(con, net_con_ssl_mode_server, probe->hub->ssl_ctx);
return; return;
} }
#else #endif
probe_destroy(probe); probe_destroy(probe);
return; return;
#endif
} }
} }
} }

View File

@@ -145,7 +145,7 @@ int route_to_all(struct hub_info* hub, struct adc_message* command) /* iterate u
route_to_user(hub, user, command); route_to_user(hub, user, command);
user = (struct hub_user*) list_get_next(hub->users->list); user = (struct hub_user*) list_get_next(hub->users->list);
} }
return 0; return 0;
} }

View File

@@ -79,8 +79,11 @@ int net_backend_init()
timeout_queue_initialize(&g_backend->timeout_queue, g_backend->now, 120); /* FIXME: max 120 secs! */ timeout_queue_initialize(&g_backend->timeout_queue, g_backend->now, 120); /* FIXME: max 120 secs! */
g_backend->cleaner = net_cleanup_initialize(g_backend->common.max); g_backend->cleaner = net_cleanup_initialize(g_backend->common.max);
for (n = 0; net_backend_init_funcs[n]; n++) for (n = 0; n < sizeof(net_backend_init_funcs); n++)
{ {
if (!net_backend_init_funcs[n])
break;
g_backend->data = net_backend_init_funcs[n](&g_backend->handler, &g_backend->common); g_backend->data = net_backend_init_funcs[n](&g_backend->handler, &g_backend->common);
if (g_backend->data) if (g_backend->data)
{ {

View File

@@ -32,29 +32,19 @@ struct net_connection_kqueue
NET_CON_STRUCT_COMMON NET_CON_STRUCT_COMMON
struct kevent ev_r; struct kevent ev_r;
struct kevent ev_w; struct kevent ev_w;
int change;
}; };
struct net_backend_kqueue struct net_backend_kqueue
{ {
int kqfd; int kqfd;
struct net_connection_kqueue** conns; struct net_connection_kqueue** conns;
struct kevent* changes; struct kevent** changes;
int* change_list; size_t nchanges;
size_t change_list_len;
struct kevent events[KQUEUE_EVBUFFER]; struct kevent events[KQUEUE_EVBUFFER];
struct net_backend_common* common; struct net_backend_common* common;
}; };
#define CHANGE_ACTION_ADD 0x0001
#define CHANGE_ACTION_MOD 0x0002
#define CHANGE_ACTION_DEL 0x0004
#define CHANGE_OP_WANT_READ 0x0100
#define CHANGE_OP_WANT_WRITE 0x0200
static void net_backend_set_handlers(struct net_backend_handler* handler); static void net_backend_set_handlers(struct net_backend_handler* handler);
static void add_change(struct net_backend_kqueue* backend, struct net_connection_kqueue* con, int actions);
static size_t create_change_list(struct net_backend_kqueue* backend);
const char* net_backend_name_kqueue() const char* net_backend_name_kqueue()
{ {
@@ -66,13 +56,12 @@ int net_backend_poll_kqueue(struct net_backend* data, int ms)
int res; int res;
struct timespec tspec = { 0, }; struct timespec tspec = { 0, };
struct net_backend_kqueue* backend = (struct net_backend_kqueue*) data; struct net_backend_kqueue* backend = (struct net_backend_kqueue*) data;
size_t changes;
tspec.tv_sec = (ms / 1000); tspec.tv_sec = (ms / 1000);
tspec.tv_nsec = ((ms % 1000) * 1000000); tspec.tv_nsec = ((ms % 1000) * 1000000);
changes = create_change_list(backend); res = kevent(backend->kqfd, *backend->changes, backend->nchanges, backend->events, KQUEUE_EVBUFFER, &tspec);
res = kevent(backend->kqfd, backend->changes, changes, backend->events, KQUEUE_EVBUFFER, &tspec); backend->nchanges = 0;
if (res == -1 && errno == EINTR) if (res == -1 && errno == EINTR)
return 0; return 0;
@@ -87,13 +76,11 @@ void net_backend_process_kqueue(struct net_backend* data, int res)
for (n = 0; n < res; n++) for (n = 0; n < res; n++)
{ {
struct net_connection_kqueue* con = (struct net_connection_kqueue*) backend->events[n].udata; struct net_connection_kqueue* con = (struct net_connection_kqueue*) backend->events[n].udata;
if (con && con->sd >= 0 && backend->conns[con->sd]) int ev = -1;
{ if (backend->events[n].filter == EVFILT_READ) ev = NET_EVENT_READ;
int ev = 0; else if (backend->events[n].filter == EVFILT_WRITE) ev = NET_EVENT_WRITE;
if (backend->events[n].filter == EVFILT_READ) ev = NET_EVENT_READ; if (con)
else if (backend->events[n].filter == EVFILT_WRITE) ev = NET_EVENT_WRITE;
net_con_callback((struct net_connection*) con, ev); net_con_callback((struct net_connection*) con, ev);
}
} }
} }
@@ -115,37 +102,58 @@ void net_con_initialize_kqueue(struct net_backend* data, struct net_connection*
void net_con_backend_add_kqueue(struct net_backend* data, struct net_connection* con_, int events) void net_con_backend_add_kqueue(struct net_backend* data, struct net_connection* con_, int events)
{ {
unsigned short flags_r = EV_ADD;
unsigned short flags_w = EV_ADD;
struct net_backend_kqueue* backend = (struct net_backend_kqueue*) data; struct net_backend_kqueue* backend = (struct net_backend_kqueue*) data;
struct net_connection_kqueue* con = (struct net_connection_kqueue*) con_; struct net_connection_kqueue* con = (struct net_connection_kqueue*) con_;
int operation;
backend->conns[con->sd] = con; backend->conns[con->sd] = con;
operation = CHANGE_ACTION_ADD;
if (events & NET_EVENT_READ) if (events & NET_EVENT_READ)
operation |= CHANGE_OP_WANT_READ; flags_r |= EV_ENABLE;
else
flags_r |= EV_DISABLE;
EV_SET(&con->ev_r, con->sd, EVFILT_READ, flags_r, 0, 0, con);
backend->changes[backend->nchanges++] = &con->ev_r;
if (events & NET_EVENT_WRITE) if (events & NET_EVENT_WRITE)
operation |= CHANGE_OP_WANT_WRITE; flags_w |= EV_ENABLE;
else
flags_w |= EV_DISABLE;
add_change(backend, con, operation); EV_SET(&con->ev_w, con->sd, EVFILT_WRITE, flags_w, 0, 0, con);
backend->changes[backend->nchanges++] = &con->ev_w;
} }
void net_con_backend_mod_kqueue(struct net_backend* data, struct net_connection* con_, int events) void net_con_backend_mod_kqueue(struct net_backend* data, struct net_connection* con_, int events)
{ {
unsigned short flags_r = 0;
unsigned short flags_w = 0;
struct net_backend_kqueue* backend = (struct net_backend_kqueue*) data; struct net_backend_kqueue* backend = (struct net_backend_kqueue*) data;
struct net_connection_kqueue* con = (struct net_connection_kqueue*) con_; struct net_connection_kqueue* con = (struct net_connection_kqueue*) con_;
int operation = CHANGE_ACTION_ADD;
if (events & NET_EVENT_READ) if (events & NET_EVENT_READ)
operation |= CHANGE_OP_WANT_READ; flags_r |= EV_ENABLE;
else
flags_r |= EV_DISABLE;
if (!(con->ev_r.flags & flags_r))
{
EV_SET(&con->ev_r, con->sd, EVFILT_READ, flags_r, 0, 0, con);
backend->changes[backend->nchanges++] = &con->ev_r;
}
if (events & NET_EVENT_WRITE) if (events & NET_EVENT_WRITE)
operation |= CHANGE_OP_WANT_WRITE; flags_r |= EV_ENABLE;
else
flags_r |= EV_DISABLE;
add_change(backend, con, operation); if (!(con->ev_w.flags & flags_w))
{
EV_SET(&con->ev_w, con->sd, EVFILT_WRITE, flags_w, 0, 0, con);
backend->changes[backend->nchanges++] = &con->ev_w;
}
} }
void net_con_backend_del_kqueue(struct net_backend* data, struct net_connection* con_) void net_con_backend_del_kqueue(struct net_backend* data, struct net_connection* con_)
@@ -154,8 +162,11 @@ void net_con_backend_del_kqueue(struct net_backend* data, struct net_connection*
struct net_connection_kqueue* con = (struct net_connection_kqueue*) con_; struct net_connection_kqueue* con = (struct net_connection_kqueue*) con_;
/* No need to remove it from the kqueue filter, the kqueue man page says /* No need to remove it from the kqueue filter, the kqueue man page says
it is automatically removed when the descriptor is closed... */ it is automatically removed when the descriptor is closed. */
add_change(backend, con, CHANGE_ACTION_DEL); EV_SET(&con->ev_r, con->sd, EVFILT_READ, EV_DELETE, 0, 0, 0);
backend->changes[backend->nchanges++] = &con->ev_r;
EV_SET(&con->ev_w, con->sd, EVFILT_WRITE, EV_DELETE, 0, 0, 0);
backend->changes[backend->nchanges++] = &con->ev_w;
// Unmap the socket descriptor. // Unmap the socket descriptor.
backend->conns[con->sd] = 0; backend->conns[con->sd] = 0;
@@ -167,7 +178,6 @@ void net_backend_shutdown_kqueue(struct net_backend* data)
close(backend->kqfd); close(backend->kqfd);
hub_free(backend->conns); hub_free(backend->conns);
hub_free(backend->changes); hub_free(backend->changes);
hub_free(backend->change_list);
hub_free(backend); hub_free(backend);
} }
@@ -187,8 +197,8 @@ struct net_backend* net_backend_init_kqueue(struct net_backend_handler* handler,
} }
backend->conns = hub_malloc_zero(sizeof(struct net_connection_kqueue*) * common->max); backend->conns = hub_malloc_zero(sizeof(struct net_connection_kqueue*) * common->max);
backend->changes = hub_malloc_zero(sizeof(struct kevent) * common->max * 2); backend->conns = hub_malloc_zero(sizeof(struct net_connection_kqueue*) * common->max);
backend->change_list = hub_malloc_zero(sizeof(int) * common->max); backend->changes = hub_malloc_zero(sizeof(struct kevent*) * common->max * 2);
backend->common = common; backend->common = common;
net_backend_set_handlers(handler); net_backend_set_handlers(handler);
@@ -208,71 +218,4 @@ static void net_backend_set_handlers(struct net_backend_handler* handler)
handler->con_del = net_con_backend_del_kqueue; handler->con_del = net_con_backend_del_kqueue;
} }
static void add_change(struct net_backend_kqueue* backend, struct net_connection_kqueue* con, int actions)
{
if (actions && !con->change)
{
backend->change_list[backend->change_list_len++] = con->sd;
con->change = actions;
}
}
static size_t create_change_list(struct net_backend_kqueue* backend)
{
size_t n = 0;
size_t changes = 0;
int sd;
struct net_connection_kqueue* con;
unsigned short flags_r = 0;
unsigned short flags_w = 0;
for (; n < backend->change_list_len; n++)
{
sd = backend->change_list[n];
con = backend->conns[sd];
if (con)
{
flags_r = 0;
flags_w = 0;
if (con->change & CHANGE_ACTION_ADD)
{
flags_r |= EV_ADD;
flags_w |= EV_ADD;
}
if (con->change & CHANGE_OP_WANT_READ)
flags_r |= EV_ENABLE;
else
flags_r |= EV_DISABLE;
if (con->change & CHANGE_OP_WANT_WRITE)
flags_w |= EV_ENABLE;
else
flags_w |= EV_DISABLE;
if (con->ev_r.flags != flags_r)
{
EV_SET(&con->ev_r, sd, EVFILT_READ, flags_r, 0, 0, con);
memcpy(&backend->changes[changes++], &con->ev_r, sizeof(struct kevent));
}
if (con->ev_w.flags != flags_w)
{
EV_SET(&con->ev_w, sd, EVFILT_WRITE, flags_w, 0, 0, con);
memcpy(&backend->changes[changes++], &con->ev_w, sizeof(struct kevent));
}
con->change = 0;
}
else
{
EV_SET(&backend->changes[changes++], sd, EVFILT_READ, EV_DELETE, 0, 0, 0);
EV_SET(&backend->changes[changes++], sd, EVFILT_READ, EV_DELETE, 0, 0, 0);
}
}
backend->change_list_len = 0;
return changes;
}
#endif /* USE_KQUEUE */ #endif /* USE_KQUEUE */

View File

@@ -1,153 +0,0 @@
/*
* 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_HANDLE_H
#define HAVE_UHUB_PLUGIN_HANDLE_H
#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 */
};
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_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_connect_t)(struct ip_addr_encap*);
typedef void (*on_user_login_t)(struct plugin_user*);
typedef void (*on_user_logout_t)(struct plugin_user*);
typedef void (*on_user_nick_change_t)(struct plugin_user*, const char* new_nick);
typedef plugin_st (*on_change_nick_t)(struct plugin_user*, const char* new_nick);
typedef plugin_st (*on_check_ip_early_t)(struct ip_addr_encap*);
typedef plugin_st (*on_check_ip_late_t)(struct ip_addr_encap*);
typedef plugin_st (*on_validate_nick_t)(const char* nick);
typedef plugin_st (*on_validate_cid_t)(const char* cid);
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_user_connect_t on_user_connect; /* A user has connected to the hub */
on_user_login_t on_user_login; /* A user has successfully logged in to the hub */
on_user_logout_t on_user_logout; /* A user has logged out of the hub (was previously logged in) */
on_user_nick_change_t on_user_nick_change; /* A user has changed nickname */
// Activity events (can be intercepted and refused by a plugin)
on_chat_msg_t on_chat_msg; /* A public chat message is about to be sent (can be intercepted) */
on_private_msg_t on_private_msg; /* A public chat message is about to be sent (can be intercepted) */
on_search_t on_search; /* A search is about to be sent (can be intercepted) */
on_p2p_connect_t on_p2p_connect; /* A user is about to connect to another user (can be intercepted) */
on_p2p_revconnect_t on_p2p_revconnect; /* A user is about to connect to another user (can be intercepted) */
// Authentication actions.
auth_get_user_t auth_get_user; /* Get authentication info from plugin */
auth_register_user_t auth_register_user; /* Register user */
auth_update_user_t auth_update_user; /* Update a registered user */
auth_delete_user_t auth_delete_user; /* Delete a registered user */
// Login check functions
on_check_ip_early_t login_check_ip_early;
on_check_ip_late_t login_check_ip_late;
};
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*);
#endif /* HAVE_UHUB_PLUGIN_HANDLE_H */

View File

@@ -1,28 +0,0 @@
/**
* 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;
}

View File

@@ -1,57 +0,0 @@
/**
* This is a minimal example plugin for uhub.
*/
// #include "uhub.h"
#include "plugin_api/handle.h"
struct ip_addr_encap;
plugin_st log_connect(struct ip_addr_encap* addr)
{
return st_default;
}
void log_user_login(struct plugin_user* user)
{
printf("login: \"%s\"\n", user->nick);
}
void log_user_logout(struct plugin_user* user)
{
printf("logout: \"%s\"\n", user->nick);
}
plugin_st log_change_nick(struct plugin_user* user, const char* new_nick)
{
printf("\"%s\" -> \"%s\"\n", user->nick, new_nick);
return st_default;
}
int plugin_register(struct uhub_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->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;
}
int plugin_unregister(struct uhub_plugin_handle* plugin)
{
/* No need to do anything! */
puts("* plugin unregister");
return 0;
}

View File

@@ -89,8 +89,6 @@
#include <pwd.h> #include <pwd.h>
#include <sys/resource.h> #include <sys/resource.h>
#define HAVE_STRNDUP #define HAVE_STRNDUP
#define HAVE_DLOPEN
#include <dlfcn.h>
#ifndef __HAIKU__ #ifndef __HAIKU__
#define HAVE_MEMMEM #define HAVE_MEMMEM
#endif #endif

View File

@@ -45,7 +45,6 @@
#define MAX_CID_LEN 39 #define MAX_CID_LEN 39
#define MAX_NICK_LEN 64 #define MAX_NICK_LEN 64
#define MAX_PASS_LEN 64
#define MAX_UA_LEN 32 #define MAX_UA_LEN 32
#define TIGERSIZE 24 #define TIGERSIZE 24
@@ -81,13 +80,10 @@ extern "C" {
#include "core/user.h" #include "core/user.h"
#include "core/usermanager.h" #include "core/usermanager.h"
#include "core/route.h" #include "core/route.h"
#include "core/pluginloader.h"
#include "core/hub.h" #include "core/hub.h"
#include "core/commands.h" #include "core/commands.h"
#include "core/inf.h" #include "core/inf.h"
#include "core/hubevent.h" #include "core/hubevent.h"
#include "core/plugininvoke.h"
#include "core/pluginloader.h"
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -400,51 +400,3 @@ const char* get_timestamp(time_t now)
sprintf(ts, "[%02d:%02d]", t->tm_hour, t->tm_min); sprintf(ts, "[%02d:%02d]", t->tm_hour, t->tm_min);
return ts; return ts;
} }
void strip_off_ini_line_comments(char* line, int line_count)
{
char* p = line;
char* out = line;
int backslash = 0;
if (!*line)
return;
for (; *p; p++)
{
if (!backslash)
{
if (*p == '\\')
{
backslash = 1;
}
else if (*p == '#')
{
*out = '\0';
out++;
break;
}
else
{
*out = *p;
out++;
}
}
else
{
if (*p == '\\' || *p == '#' || *p == '\"')
{
*out = *p;
out++;
}
else
{
LOG_WARN("Invalid backslash escape on line %d", line_count);
*out = *p;
out++;
}
backslash = 0;
}
}
*out = '\0';
}

View File

@@ -33,12 +33,10 @@ extern int is_valid_base32_char(char c);
extern void base32_encode(const unsigned char* buffer, size_t len, char* result); extern void base32_encode(const unsigned char* buffer, size_t len, char* result);
extern void base32_decode(const char* src, unsigned char* dst, size_t len); extern void base32_decode(const char* src, unsigned char* dst, size_t len);
extern char* strip_white_space(char* string); extern char* strip_white_space(char* string);
extern void strip_off_ini_line_comments(char* line, int line_count);
extern int file_read_lines(const char* file, void* data, file_line_handler_t handler); extern int file_read_lines(const char* file, void* data, file_line_handler_t handler);
extern const char* uhub_itoa(int val); extern const char* uhub_itoa(int val);
extern const char* uhub_ulltoa(uint64_t val); extern const char* uhub_ulltoa(uint64_t val);