2010-06-22 14:04:33 +00:00
|
|
|
/*
|
|
|
|
* uhub - A tiny ADC p2p connection hub
|
2011-12-09 09:29:50 +00:00
|
|
|
* Copyright (C) 2007-2011, Jan Vidar Krey
|
2010-06-22 14:04:33 +00:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2011-12-09 15:36:14 +00:00
|
|
|
#define PLUGIN_DEBUG(hub, name) LOG_PLUGIN("Invoke %s on %d plugins", name, (int) (hub->plugins ? list_size(hub->plugins->loaded) : -1));
|
2010-07-29 06:43:22 +00:00
|
|
|
|
|
|
|
|
2010-07-22 22:35:07 +00:00
|
|
|
#define INVOKE(HUB, FUNCNAME, CODE) \
|
2010-07-29 06:43:22 +00:00
|
|
|
PLUGIN_DEBUG(HUB, # FUNCNAME) \
|
2010-06-22 14:04:33 +00:00
|
|
|
if (HUB->plugins && HUB->plugins->loaded) \
|
|
|
|
{ \
|
2010-07-29 06:43:22 +00:00
|
|
|
struct plugin_handle* plugin = (struct plugin_handle*) list_get_first(HUB->plugins->loaded); \
|
2010-06-22 14:04:33 +00:00
|
|
|
while (plugin) \
|
|
|
|
{ \
|
|
|
|
if (plugin->funcs.FUNCNAME) \
|
|
|
|
CODE \
|
2010-07-29 06:43:22 +00:00
|
|
|
plugin = (struct plugin_handle*) list_get_next(HUB->plugins->loaded); \
|
2010-06-22 14:04:33 +00:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2010-07-29 06:43:22 +00:00
|
|
|
#define PLUGIN_INVOKE_STATUS_1(HUB, FUNCNAME, ARG1) \
|
2011-01-02 01:39:25 +00:00
|
|
|
do { \
|
|
|
|
plugin_st status = st_default; \
|
|
|
|
INVOKE(HUB, FUNCNAME, { \
|
|
|
|
status = plugin->funcs.FUNCNAME(plugin, ARG1); \
|
|
|
|
if (status != st_default) \
|
|
|
|
break; \
|
|
|
|
}); \
|
|
|
|
return status; \
|
|
|
|
} while(0)
|
2010-07-29 06:43:22 +00:00
|
|
|
|
|
|
|
#define PLUGIN_INVOKE_STATUS_2(HUB, FUNCNAME, ARG1, ARG2) \
|
2011-01-02 01:39:25 +00:00
|
|
|
do { \
|
|
|
|
plugin_st status = st_default; \
|
|
|
|
INVOKE(HUB, FUNCNAME, { \
|
|
|
|
status = plugin->funcs.FUNCNAME(plugin, ARG1, ARG2); \
|
|
|
|
if (status != st_default) \
|
|
|
|
break; \
|
|
|
|
}); \
|
|
|
|
return status; \
|
|
|
|
} while(0)
|
2010-07-18 17:57:07 +00:00
|
|
|
|
2010-07-29 06:43:22 +00:00
|
|
|
#define PLUGIN_INVOKE_STATUS_3(HUB, FUNCNAME, ARG1, ARG2, ARG3) \
|
2011-01-02 01:39:25 +00:00
|
|
|
do { \
|
|
|
|
plugin_st status = st_default; \
|
|
|
|
INVOKE(HUB, FUNCNAME, { \
|
|
|
|
status = plugin->funcs.FUNCNAME(plugin, ARG1, ARG2, ARG3); \
|
|
|
|
if (status != st_default) \
|
|
|
|
break; \
|
|
|
|
}); \
|
|
|
|
return status; \
|
|
|
|
} while(0)
|
2010-07-29 06:43:22 +00:00
|
|
|
|
2010-08-11 16:44:02 +00:00
|
|
|
#define PLUGIN_INVOKE_1(HUB, FUNCNAME, ARG1) INVOKE(HUB, FUNCNAME, { plugin->funcs.FUNCNAME(plugin, ARG1); })
|
|
|
|
#define PLUGIN_INVOKE_2(HUB, FUNCNAME, ARG1, ARG2) INVOKE(HUB, FUNCNAME, { plugin->funcs.FUNCNAME(plugin, ARG1, ARG2); })
|
|
|
|
#define PLUGIN_INVOKE_3(HUB, FUNCNAME, ARG1, ARG2, ARG3) INVOKE(HUB, FUNCNAME, { plugin->funcs.FUNCNAME(plugin, ARG1, ARG2, ARG3); })
|
2010-07-29 06:43:22 +00:00
|
|
|
|
2010-07-18 17:57:07 +00:00
|
|
|
|
2011-12-09 09:29:50 +00:00
|
|
|
static struct plugin_user* convert_user_type(struct hub_user* user)
|
2010-07-18 17:57:07 +00:00
|
|
|
{
|
2011-12-09 09:29:50 +00:00
|
|
|
struct plugin_user* puser = (struct plugin_user*) user;
|
|
|
|
return puser;
|
2010-07-18 17:57:07 +00:00
|
|
|
}
|
|
|
|
|
2010-06-22 14:04:33 +00:00
|
|
|
plugin_st plugin_check_ip_early(struct hub_info* hub, struct ip_addr_encap* addr)
|
|
|
|
{
|
2012-05-09 21:33:03 +00:00
|
|
|
PLUGIN_INVOKE_STATUS_1(hub, on_check_ip_early, addr);
|
2010-06-22 14:04:33 +00:00
|
|
|
}
|
|
|
|
|
2012-05-09 21:33:03 +00:00
|
|
|
plugin_st plugin_check_ip_late(struct hub_info* hub, struct hub_user* who, struct ip_addr_encap* addr)
|
2010-06-22 14:04:33 +00:00
|
|
|
{
|
2012-05-09 21:33:03 +00:00
|
|
|
struct plugin_user* user = convert_user_type(who);
|
|
|
|
PLUGIN_INVOKE_STATUS_2(hub, on_check_ip_late, user, addr);
|
2010-06-22 14:04:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void plugin_log_connection_accepted(struct hub_info* hub, struct ip_addr_encap* ipaddr)
|
|
|
|
{
|
2010-08-11 16:51:22 +00:00
|
|
|
PLUGIN_INVOKE_1(hub, on_connection_accepted, ipaddr);
|
2010-06-22 14:04:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void plugin_log_connection_denied(struct hub_info* hub, struct ip_addr_encap* ipaddr)
|
|
|
|
{
|
2010-08-11 16:51:22 +00:00
|
|
|
PLUGIN_INVOKE_1(hub, on_connection_refused, ipaddr);
|
2010-06-22 14:04:33 +00:00
|
|
|
}
|
|
|
|
|
2010-07-22 22:35:07 +00:00
|
|
|
void plugin_log_user_login_success(struct hub_info* hub, struct hub_user* who)
|
2010-06-22 14:04:33 +00:00
|
|
|
{
|
2011-12-09 09:29:50 +00:00
|
|
|
struct plugin_user* user = convert_user_type(who);
|
|
|
|
PLUGIN_INVOKE_1(hub, on_user_login, user);
|
2010-07-22 22:35:07 +00:00
|
|
|
}
|
2010-07-12 15:00:42 +00:00
|
|
|
|
2010-07-22 22:35:07 +00:00
|
|
|
void plugin_log_user_login_error(struct hub_info* hub, struct hub_user* who, const char* reason)
|
|
|
|
{
|
2011-12-09 09:29:50 +00:00
|
|
|
struct plugin_user* user = convert_user_type(who);
|
|
|
|
PLUGIN_INVOKE_2(hub, on_user_login_error, user, reason);
|
2010-06-22 14:04:33 +00:00
|
|
|
}
|
|
|
|
|
2010-07-22 22:35:07 +00:00
|
|
|
void plugin_log_user_logout(struct hub_info* hub, struct hub_user* who, const char* reason)
|
2010-06-22 14:04:33 +00:00
|
|
|
{
|
2011-12-09 09:29:50 +00:00
|
|
|
struct plugin_user* user = convert_user_type(who);
|
|
|
|
PLUGIN_INVOKE_2(hub, on_user_logout, user, reason);
|
2010-06-22 14:04:33 +00:00
|
|
|
}
|
|
|
|
|
2010-07-22 22:35:07 +00:00
|
|
|
void plugin_log_user_nick_change(struct hub_info* hub, struct hub_user* who, const char* new_nick)
|
2010-06-22 14:04:33 +00:00
|
|
|
{
|
2011-12-09 09:29:50 +00:00
|
|
|
struct plugin_user* user = convert_user_type(who);
|
|
|
|
PLUGIN_INVOKE_2(hub, on_user_nick_change, user, new_nick);
|
2010-06-22 14:04:33 +00:00
|
|
|
}
|
|
|
|
|
2010-07-22 22:35:07 +00:00
|
|
|
void plugin_log_user_update_error(struct hub_info* hub, struct hub_user* who, const char* reason)
|
|
|
|
{
|
2011-12-09 09:29:50 +00:00
|
|
|
struct plugin_user* user = convert_user_type(who);
|
|
|
|
PLUGIN_INVOKE_2(hub, on_user_update_error, user, reason);
|
2010-08-11 16:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void plugin_log_chat_message(struct hub_info* hub, struct hub_user* who, const char* message, int flags)
|
|
|
|
{
|
2011-12-09 09:29:50 +00:00
|
|
|
struct plugin_user* user = convert_user_type(who);
|
|
|
|
PLUGIN_INVOKE_3(hub, on_user_chat_message, user, message, flags);
|
2010-08-11 16:44:02 +00:00
|
|
|
}
|
2010-07-22 22:35:07 +00:00
|
|
|
|
2010-07-18 17:57:07 +00:00
|
|
|
plugin_st plugin_handle_chat_message(struct hub_info* hub, struct hub_user* from, const char* message, int flags)
|
|
|
|
{
|
2011-12-09 09:29:50 +00:00
|
|
|
struct plugin_user* user = convert_user_type(from);
|
|
|
|
PLUGIN_INVOKE_STATUS_2(hub, on_chat_msg, user, message);
|
2010-07-18 17:57:07 +00:00
|
|
|
}
|
2010-06-22 14:04:33 +00:00
|
|
|
|
2010-07-18 17:57:07 +00:00
|
|
|
plugin_st plugin_handle_private_message(struct hub_info* hub, struct hub_user* from, struct hub_user* to, const char* message, int flags)
|
2010-06-22 14:04:33 +00:00
|
|
|
{
|
2011-12-09 09:29:50 +00:00
|
|
|
struct plugin_user* user1 = convert_user_type(from);
|
|
|
|
struct plugin_user* user2 = convert_user_type(to);
|
|
|
|
PLUGIN_INVOKE_STATUS_3(hub, on_private_msg, user1, user2, message);
|
2010-07-18 17:57:07 +00:00
|
|
|
}
|
|
|
|
|
2010-07-22 22:35:07 +00:00
|
|
|
plugin_st plugin_handle_search(struct hub_info* hub, struct hub_user* from, const char* data)
|
2010-07-18 17:57:07 +00:00
|
|
|
{
|
2011-12-09 09:29:50 +00:00
|
|
|
struct plugin_user* user = convert_user_type(from);
|
|
|
|
PLUGIN_INVOKE_STATUS_2(hub, on_search, user, data);
|
2010-07-18 17:57:07 +00:00
|
|
|
}
|
|
|
|
|
2012-01-09 18:54:03 +00:00
|
|
|
plugin_st plugin_handle_search_result(struct hub_info* hub, struct hub_user* from, struct hub_user* to, const char* data)
|
|
|
|
{
|
|
|
|
struct plugin_user* user1 = convert_user_type(from);
|
|
|
|
struct plugin_user* user2 = convert_user_type(to);
|
|
|
|
PLUGIN_INVOKE_STATUS_3(hub, on_search_result, user1, user2, data);
|
|
|
|
}
|
|
|
|
|
2010-07-18 17:57:07 +00:00
|
|
|
plugin_st plugin_handle_connect(struct hub_info* hub, struct hub_user* from, struct hub_user* to)
|
|
|
|
{
|
2011-12-09 09:29:50 +00:00
|
|
|
struct plugin_user* user1 = convert_user_type(from);
|
|
|
|
struct plugin_user* user2 = convert_user_type(to);
|
|
|
|
PLUGIN_INVOKE_STATUS_2(hub, on_p2p_connect, user1, user2);
|
2010-07-09 12:01:22 +00:00
|
|
|
}
|
2010-07-18 17:57:07 +00:00
|
|
|
|
|
|
|
plugin_st plugin_handle_revconnect(struct hub_info* hub, struct hub_user* from, struct hub_user* to)
|
|
|
|
{
|
2011-12-09 09:29:50 +00:00
|
|
|
struct plugin_user* user1 = convert_user_type(from);
|
|
|
|
struct plugin_user* user2 = convert_user_type(to);
|
|
|
|
PLUGIN_INVOKE_STATUS_2(hub, on_p2p_revconnect, user1, user2);
|
2010-07-18 17:57:07 +00:00
|
|
|
}
|
|
|
|
|
2010-07-22 23:23:13 +00:00
|
|
|
plugin_st plugin_auth_get_user(struct hub_info* hub, const char* nickname, struct auth_info* info)
|
|
|
|
{
|
2010-07-29 06:43:22 +00:00
|
|
|
PLUGIN_INVOKE_STATUS_2(hub, auth_get_user, nickname, info);
|
2010-07-22 23:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
plugin_st plugin_auth_register_user(struct hub_info* hub, struct auth_info* info)
|
|
|
|
{
|
2010-07-29 06:43:22 +00:00
|
|
|
PLUGIN_INVOKE_STATUS_1(hub, auth_register_user, info);
|
2010-07-22 23:23:13 +00:00
|
|
|
}
|
2010-07-18 17:57:07 +00:00
|
|
|
|
2010-07-22 23:23:13 +00:00
|
|
|
plugin_st plugin_auth_update_user(struct hub_info* hub, struct auth_info* info)
|
|
|
|
{
|
2010-07-29 06:43:22 +00:00
|
|
|
PLUGIN_INVOKE_STATUS_1(hub, auth_update_user, info);
|
2010-07-22 23:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
plugin_st plugin_auth_delete_user(struct hub_info* hub, struct auth_info* info)
|
|
|
|
{
|
2010-07-29 06:43:22 +00:00
|
|
|
PLUGIN_INVOKE_STATUS_1(hub, auth_delete_user, info);
|
2010-07-22 23:23:13 +00:00
|
|
|
}
|