Added logging of chat messages in the plugin API.

This commit is contained in:
Jan Vidar Krey 2010-08-11 18:44:02 +02:00
parent 5419d07efe
commit 4c960cb977
4 changed files with 89 additions and 80 deletions

View File

@ -257,6 +257,7 @@ int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc
int ret = 0;
int relay = 1;
int broadcast;
int private_msg;
int command;
int offset;
@ -269,7 +270,8 @@ int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc
return 0;
}
broadcast = (cmd->cache[0] == 'B' || cmd->cache[0] == 'F');
broadcast = (cmd->cache[0] == 'B');
private_msg = (cmd->cache[0] == 'D' || cmd->cache[0] == 'E');
command = (message[0] == '!' || message[0] == '+');
if (broadcast && command)
@ -297,7 +299,6 @@ int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc
relay = 0;
}
if (relay)
{
plugin_st status;
@ -305,7 +306,7 @@ int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc
{
status = plugin_handle_chat_message(hub, u, message, 0);
}
else
else if (private_msg)
{
struct hub_user* target = uman_get_user_by_sid(hub, cmd->target);
status = plugin_handle_private_message(hub, u, target, message, 0);
@ -318,10 +319,11 @@ int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc
if (relay)
{
/* adc_msg_remove_named_argument(cmd, "PM"); */
/* FIXME: Plugin should do history management */
if (cmd->cache[0] == 'B')
if (broadcast)
{
hub_chat_history_add(hub, u, cmd);
plugin_log_chat_message(hub, u, message, 0);
}
ret = route_message(hub, u, cmd);
}
hub_free(message);
@ -1146,42 +1148,42 @@ const char* hub_get_status_message(struct hub_info* hub, enum status_message msg
const char* hub_get_status_message_log(struct hub_info* hub, enum status_message msg)
{
#define STATUS(MSG) case status_ ## MSG : return #MSG; break
switch (msg)
{
STATUS(msg_hub_full);
STATUS(msg_hub_disabled);
STATUS(msg_hub_registered_users_only);
STATUS(msg_inf_error_nick_missing);
STATUS(msg_inf_error_nick_multiple);
STATUS(msg_inf_error_nick_invalid);
STATUS(msg_inf_error_nick_long);
STATUS(msg_inf_error_nick_short);
STATUS(msg_inf_error_nick_spaces);
STATUS(msg_inf_error_nick_bad_chars);
STATUS(msg_inf_error_nick_not_utf8);
STATUS(msg_inf_error_nick_taken);
STATUS(msg_inf_error_nick_restricted);
STATUS(msg_inf_error_cid_invalid);
STATUS(msg_inf_error_cid_missing);
STATUS(msg_inf_error_cid_taken);
STATUS(msg_inf_error_pid_missing);
STATUS(msg_inf_error_pid_invalid);
STATUS(msg_ban_permanently);
STATUS(msg_ban_temporarily);
STATUS(msg_auth_invalid_password);
STATUS(msg_auth_user_not_found);
STATUS(msg_error_no_memory);
STATUS(msg_user_share_size_low);
STATUS(msg_user_share_size_high);
STATUS(msg_user_slots_low);
STATUS(msg_user_slots_high);
STATUS(msg_user_hub_limit_low);
STATUS(msg_user_hub_limit_high);
switch (msg)
{
STATUS(msg_hub_full);
STATUS(msg_hub_disabled);
STATUS(msg_hub_registered_users_only);
STATUS(msg_inf_error_nick_missing);
STATUS(msg_inf_error_nick_multiple);
STATUS(msg_inf_error_nick_invalid);
STATUS(msg_inf_error_nick_long);
STATUS(msg_inf_error_nick_short);
STATUS(msg_inf_error_nick_spaces);
STATUS(msg_inf_error_nick_bad_chars);
STATUS(msg_inf_error_nick_not_utf8);
STATUS(msg_inf_error_nick_taken);
STATUS(msg_inf_error_nick_restricted);
STATUS(msg_inf_error_cid_invalid);
STATUS(msg_inf_error_cid_missing);
STATUS(msg_inf_error_cid_taken);
STATUS(msg_inf_error_pid_missing);
STATUS(msg_inf_error_pid_invalid);
STATUS(msg_ban_permanently);
STATUS(msg_ban_temporarily);
STATUS(msg_auth_invalid_password);
STATUS(msg_auth_user_not_found);
STATUS(msg_error_no_memory);
STATUS(msg_user_share_size_low);
STATUS(msg_user_share_size_high);
STATUS(msg_user_slots_low);
STATUS(msg_user_slots_high);
STATUS(msg_user_hub_limit_low);
STATUS(msg_user_hub_limit_high);
STATUS(msg_proto_no_common_hash);
STATUS(msg_proto_obsolete_adc0);
}
}
#undef STATUS
return "unknown";
return "unknown";
}

View File

@ -63,15 +63,10 @@
}); \
return status
#define PLUGIN_INVOKE_1(HUB, FUNCNAME, ARG1) \
INVOKE(HUB, FUNCNAME, { \
plugin->funcs.FUNCNAME(plugin, ARG1); \
})
#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); })
#define PLUGIN_INVOKE_2(HUB, FUNCNAME, ARG1, ARG2) \
INVOKE(HUB, FUNCNAME, { \
plugin->funcs.FUNCNAME(plugin, ARG1, ARG2); \
})
static void convert_user_type(struct plugin_user* puser, struct hub_user* user)
{
@ -140,6 +135,13 @@ void plugin_log_user_update_error(struct hub_info* hub, struct hub_user* who, co
PLUGIN_INVOKE_2(hub, on_user_update_error, &user, reason);
}
void plugin_log_chat_message(struct hub_info* hub, struct hub_user* who, const char* message, int flags)
{
struct plugin_user user;
convert_user_type(&user, who);
PLUGIN_INVOKE_3(hub, on_user_chat_message, &user, message, flags);
}
plugin_st plugin_handle_chat_message(struct hub_info* hub, struct hub_user* from, const char* message, int flags)
{
struct plugin_user user;

View File

@ -28,6 +28,7 @@
struct hub_info;
struct ip_addr_encap;
/* All log related functions */
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);
@ -35,11 +36,13 @@ void plugin_log_user_login_error(struct hub_info* hub, struct hub_user* user, co
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);
void plugin_log_chat_message(struct hub_info* hub, struct hub_user* from, const char* message, int flags);
/* IP ban related */
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);
/* Nickname allow/deny handling */
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);

View File

@ -96,6 +96,7 @@ typedef void (*on_user_login_error_t)(struct plugin_handle*, struct plugin_user*
typedef void (*on_user_logout_t)(struct plugin_handle*, struct plugin_user*, const char* reason);
typedef void (*on_user_nick_change_t)(struct plugin_handle*, struct plugin_user*, const char* new_nick);
typedef void (*on_user_update_error_t)(struct plugin_handle*, struct plugin_user*, const char* reason);
typedef void (*on_user_chat_msg_t)(struct plugin_handle*, struct plugin_user*, const char* message, int flags);
typedef plugin_st (*on_change_nick_t)(struct plugin_handle*, struct plugin_user*, const char* new_nick);
@ -112,12 +113,13 @@ typedef plugin_st (*auth_delete_user_t)(struct plugin_handle*, struct auth_info*
struct plugin_funcs
{
// Log events for users
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_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_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. */
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_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_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. */
on_user_chat_msg_t on_user_chat_message;/* A user has sent a public chat message */
// 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) */