Implement more plugin invokers, and call them.
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
#include "uhub.h"
|
||||
#include "plugin_api/handle.h"
|
||||
|
||||
#define PLUGIN_INVOKE(HUB, FUNCNAME, CODE) \
|
||||
#define 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); \
|
||||
@@ -34,13 +34,17 @@
|
||||
|
||||
#define PLUGIN_INVOKE_STATUS(HUB, FUNCNAME, ARGS) \
|
||||
plugin_st status = st_default; \
|
||||
PLUGIN_INVOKE(HUB, FUNCNAME, { \
|
||||
INVOKE(HUB, FUNCNAME, { \
|
||||
status = plugin->funcs.FUNCNAME ARGS ; \
|
||||
if (status != st_default) \
|
||||
break; \
|
||||
}); \
|
||||
return status
|
||||
|
||||
#define PLUGIN_INVOKE(HUB, FUNCNAME, ARGS) \
|
||||
INVOKE(HUB, FUNCNAME, { \
|
||||
plugin->funcs.FUNCNAME ARGS ; \
|
||||
})
|
||||
|
||||
static void convert_user_type(struct plugin_user* puser, struct hub_user* user)
|
||||
{
|
||||
@@ -73,42 +77,80 @@ void plugin_log_connection_denied(struct hub_info* hub, struct ip_addr_encap* ip
|
||||
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_success(struct hub_info* hub, struct hub_user* who)
|
||||
{
|
||||
|
||||
struct plugin_user user;
|
||||
convert_user_type(&user, who);
|
||||
PLUGIN_INVOKE(hub, on_user_login, (&user));
|
||||
}
|
||||
|
||||
void plugin_log_user_login_error(struct hub_info* hub, struct hub_user* user)
|
||||
void plugin_log_user_login_error(struct hub_info* hub, struct hub_user* who, const char* reason)
|
||||
{
|
||||
struct plugin_user user;
|
||||
convert_user_type(&user, who);
|
||||
PLUGIN_INVOKE(hub, on_user_login_error, (&user, reason));
|
||||
}
|
||||
|
||||
void plugin_log_user_logout(struct hub_info* hub, struct hub_user* user)
|
||||
void plugin_log_user_logout(struct hub_info* hub, struct hub_user* who, const char* reason)
|
||||
{
|
||||
struct plugin_user user;
|
||||
convert_user_type(&user, who);
|
||||
PLUGIN_INVOKE(hub, on_user_logout, (&user, reason));
|
||||
}
|
||||
|
||||
void plugin_log_user_nick_change(struct hub_info* hub, struct hub_user* who, const char* new_nick)
|
||||
{
|
||||
struct plugin_user user;
|
||||
convert_user_type(&user, who);
|
||||
PLUGIN_INVOKE(hub, on_user_nick_change, (&user, new_nick));
|
||||
}
|
||||
|
||||
void plugin_log_user_update_error(struct hub_info* hub, struct hub_user* who, const char* reason)
|
||||
{
|
||||
struct plugin_user user;
|
||||
convert_user_type(&user, who);
|
||||
PLUGIN_INVOKE(hub, on_user_update_error, (&user, reason));
|
||||
}
|
||||
|
||||
plugin_st plugin_handle_chat_message(struct hub_info* hub, struct hub_user* from, const char* message, int flags)
|
||||
{
|
||||
return st_default;
|
||||
struct plugin_user user;
|
||||
convert_user_type(&user, from);
|
||||
PLUGIN_INVOKE_STATUS(hub, on_chat_msg, (&user, message));
|
||||
}
|
||||
|
||||
plugin_st plugin_handle_private_message(struct hub_info* hub, struct hub_user* from, struct hub_user* to, const char* message, int flags)
|
||||
{
|
||||
return st_default;
|
||||
struct plugin_user user1;
|
||||
struct plugin_user user2;
|
||||
convert_user_type(&user1, from);
|
||||
convert_user_type(&user2, to);
|
||||
PLUGIN_INVOKE_STATUS(hub, on_private_msg, (&user1, &user2, message));
|
||||
}
|
||||
|
||||
plugin_st plugin_handle_search(struct hub_info* hub, struct hub_user* user, const char* data)
|
||||
plugin_st plugin_handle_search(struct hub_info* hub, struct hub_user* from, const char* data)
|
||||
{
|
||||
return st_default;
|
||||
struct plugin_user user;
|
||||
convert_user_type(&user, from);
|
||||
PLUGIN_INVOKE_STATUS(hub, on_search, (&user, data));
|
||||
}
|
||||
|
||||
plugin_st plugin_handle_connect(struct hub_info* hub, struct hub_user* from, struct hub_user* to)
|
||||
{
|
||||
return st_default;
|
||||
struct plugin_user user1;
|
||||
struct plugin_user user2;
|
||||
convert_user_type(&user1, from);
|
||||
convert_user_type(&user2, to);
|
||||
PLUGIN_INVOKE_STATUS(hub, on_p2p_connect, (&user1, &user2));
|
||||
}
|
||||
|
||||
plugin_st plugin_handle_revconnect(struct hub_info* hub, struct hub_user* from, struct hub_user* to)
|
||||
{
|
||||
return st_default;
|
||||
struct plugin_user user1;
|
||||
struct plugin_user user2;
|
||||
convert_user_type(&user1, from);
|
||||
convert_user_type(&user2, to);
|
||||
PLUGIN_INVOKE_STATUS(hub, on_p2p_revconnect, (&user1, &user2));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user