Implement more plugin invokers, and call them.

This commit is contained in:
Jan Vidar Krey 2010-07-23 00:35:07 +02:00
parent 1ff0f54a4b
commit c6cf03614f
4 changed files with 84 additions and 22 deletions

View File

@ -20,6 +20,7 @@
#include "uhub.h" #include "uhub.h"
#include "plugin_api/handle.h" #include "plugin_api/handle.h"
#ifndef PLUGIN_SUPPORT
static void log_user_login(struct hub_user* u) static void log_user_login(struct hub_user* u)
{ {
const char* cred = auth_cred_to_string(u->credentials); const char* cred = auth_cred_to_string(u->credentials);
@ -52,7 +53,7 @@ static void log_user_nick_change(struct hub_user* u, const char* nick)
const char* addr = user_get_address(u); const char* addr = user_get_address(u);
LOG_USER("NickChange %s/%s %s \"%s\" -> \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, nick); LOG_USER("NickChange %s/%s %s \"%s\" -> \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, nick);
} }
#endif /* !PLUGIN_SUPPORT */
/* Send MOTD, do logging etc */ /* Send MOTD, do logging etc */
void on_login_success(struct hub_info* hub, struct hub_user* u) void on_login_success(struct hub_info* hub, struct hub_user* u)
@ -65,11 +66,11 @@ void on_login_success(struct hub_info* hub, struct hub_user* u)
user_set_state(u, state_normal); user_set_state(u, state_normal);
uman_add(hub, u); uman_add(hub, u);
/* Print log message */
log_user_login(u);
#ifdef PLUGIN_SUPPORT #ifdef PLUGIN_SUPPORT
plugin_log_user_login_success(hub, u); plugin_log_user_login_success(hub, u);
#else
/* Print log message */
log_user_login(u);
#endif #endif
/* Announce new user to all connected users */ /* Announce new user to all connected users */
@ -90,14 +91,22 @@ void on_login_success(struct hub_info* hub, struct hub_user* u)
void on_login_failure(struct hub_info* hub, struct hub_user* u, enum status_message msg) void on_login_failure(struct hub_info* hub, struct hub_user* u, enum status_message msg)
{ {
#ifdef PLUGIN_SUPPORT
plugin_log_user_login_error(hub, u, hub_get_status_message_log(hub, msg));
#else
log_user_login_error(u, msg); log_user_login_error(u, msg);
#endif
hub_send_status(hub, u, msg, status_level_fatal); hub_send_status(hub, u, msg, status_level_fatal);
hub_disconnect_user(hub, u, quit_logon_error); hub_disconnect_user(hub, u, quit_logon_error);
} }
void on_update_failure(struct hub_info* hub, struct hub_user* u, enum status_message msg) void on_update_failure(struct hub_info* hub, struct hub_user* u, enum status_message msg)
{ {
#ifdef PLUGIN_SUPPORT
plugin_log_user_update_error(hub, u, hub_get_status_message_log(hub, msg));
#else
log_user_update_error(u, msg); log_user_update_error(u, msg);
#endif
hub_send_status(hub, u, msg, status_level_fatal); hub_send_status(hub, u, msg, status_level_fatal);
hub_disconnect_user(hub, u, quit_update_error); hub_disconnect_user(hub, u, quit_update_error);
} }
@ -106,17 +115,22 @@ void on_nick_change(struct hub_info* hub, struct hub_user* u, const char* nick)
{ {
if (user_is_logged_in(u)) if (user_is_logged_in(u))
{ {
#ifdef PLUGIN_SUPPORT
plugin_log_user_nick_change(hub, u, nick);
#else
log_user_nick_change(u, nick); log_user_nick_change(u, nick);
#endif
} }
} }
void on_logout_user(struct hub_info* hub, struct hub_user* user) 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);
#ifdef PLUGIN_SUPPORT #ifdef PLUGIN_SUPPORT
plugin_log_user_logout(hub, user); plugin_log_user_logout(hub, user, reason);
#else
log_user_logout(user, reason);
#endif #endif
hub_logout_log(hub, user); hub_logout_log(hub, user);

View File

@ -20,7 +20,7 @@
#include "uhub.h" #include "uhub.h"
#include "plugin_api/handle.h" #include "plugin_api/handle.h"
#define PLUGIN_INVOKE(HUB, FUNCNAME, CODE) \ #define INVOKE(HUB, FUNCNAME, CODE) \
if (HUB->plugins && HUB->plugins->loaded) \ if (HUB->plugins && HUB->plugins->loaded) \
{ \ { \
struct uhub_plugin_handle* plugin = (struct uhub_plugin_handle*) list_get_first(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) \ #define PLUGIN_INVOKE_STATUS(HUB, FUNCNAME, ARGS) \
plugin_st status = st_default; \ plugin_st status = st_default; \
PLUGIN_INVOKE(HUB, FUNCNAME, { \ INVOKE(HUB, FUNCNAME, { \
status = plugin->funcs.FUNCNAME ARGS ; \ status = plugin->funcs.FUNCNAME ARGS ; \
if (status != st_default) \ if (status != st_default) \
break; \ break; \
}); \ }); \
return status 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) 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); 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) 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) 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) 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) 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));
} }

View File

@ -31,8 +31,10 @@ struct ip_addr_encap;
void plugin_log_connection_accepted(struct hub_info* hub, struct ip_addr_encap* addr); 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_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_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_login_error(struct hub_info* hub, struct hub_user* user, const char* 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* user, const char* reason);
void plugin_log_user_nick_change(struct hub_info* hub, struct hub_user* user, const char* new_nick);
void plugin_log_user_update_error(struct hub_info* hub, struct hub_user* user, const char* reason);
plugin_st plugin_check_ip_early(struct hub_info* hub, struct ip_addr_encap* addr); 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_ip_late(struct hub_info* hub, struct ip_addr_encap* addr);

View File

@ -67,8 +67,10 @@ typedef plugin_st (*on_p2p_revconnect_t)(struct plugin_user* from, struct plugin
typedef void (*on_user_connect_t)(struct ip_addr_encap*); typedef void (*on_user_connect_t)(struct ip_addr_encap*);
typedef void (*on_user_login_t)(struct plugin_user*); typedef void (*on_user_login_t)(struct plugin_user*);
typedef void (*on_user_logout_t)(struct plugin_user*); typedef void (*on_user_login_error_t)(struct plugin_user*, const char* reason);
typedef void (*on_user_logout_t)(struct plugin_user*, const char* reason);
typedef void (*on_user_nick_change_t)(struct plugin_user*, const char* new_nick); typedef void (*on_user_nick_change_t)(struct plugin_user*, const char* new_nick);
typedef void (*on_user_update_error_t)(struct plugin_user*, const char* reason);
typedef plugin_st (*on_change_nick_t)(struct plugin_user*, const char* new_nick); typedef plugin_st (*on_change_nick_t)(struct plugin_user*, const char* new_nick);
@ -84,11 +86,13 @@ typedef plugin_st (*auth_delete_user_t)(struct auth_info* user);
struct plugin_funcs struct plugin_funcs
{ {
// Users logging in and out // Log events for users
on_user_connect_t on_user_connect; /* A user has connected to the hub */ 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_login_t on_user_login; /* A user has successfully logged in to the hub */
on_user_login_error_t on_user_login_error; /* A user has failed to log 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_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 */ on_user_nick_change_t on_user_nick_change; /* A user has changed nickname */
on_user_update_error_t on_user_update_error;/* A user has failed to update - nickname, etc. */
// Activity events (can be intercepted and refused by a plugin) // 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_chat_msg_t on_chat_msg; /* A public chat message is about to be sent (can be intercepted) */