Cleanup code and allow for plugins to provide an error message.
This commit is contained in:
@@ -32,29 +32,35 @@
|
||||
} \
|
||||
}
|
||||
|
||||
#define PLUGIN_INVOKE_STATUS(HUB, FUNCNAME, ARGS) \
|
||||
plugin_st status = st_default; \
|
||||
PLUGIN_INVOKE(HUB, FUNCNAME, { \
|
||||
status = plugin->funcs.FUNCNAME ARGS ; \
|
||||
if (status != st_default) \
|
||||
break; \
|
||||
}); \
|
||||
return status
|
||||
|
||||
|
||||
static void convert_user_type(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;
|
||||
puser->credentials = user->credentials;
|
||||
}
|
||||
|
||||
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_INVOKE_STATUS(hub, login_check_ip_early, (addr));
|
||||
}
|
||||
|
||||
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;
|
||||
PLUGIN_INVOKE_STATUS(hub, login_check_ip_late, (addr));
|
||||
}
|
||||
|
||||
|
||||
void plugin_log_connection_accepted(struct hub_info* hub, struct ip_addr_encap* ipaddr)
|
||||
{
|
||||
const char* addr = ip_convert_to_string(ipaddr);
|
||||
@@ -80,12 +86,29 @@ void plugin_log_user_logout(struct hub_info* hub, struct hub_user* user)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static void convert_user_to_plugin_user(struct plugin_user* puser, struct hub_user* user)
|
||||
plugin_st plugin_handle_chat_message(struct hub_info* hub, struct hub_user* from, const char* message, int flags)
|
||||
{
|
||||
puser->sid = user->id.sid;
|
||||
puser->nick = user->id.nick;
|
||||
puser->cid = user->id.cid;
|
||||
puser->addr = user->id.addr;
|
||||
puser->credentials = user->credentials;
|
||||
return st_default;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
plugin_st plugin_handle_search(struct hub_info* hub, struct hub_user* user, const char* data)
|
||||
{
|
||||
return st_default;
|
||||
}
|
||||
|
||||
plugin_st plugin_handle_connect(struct hub_info* hub, struct hub_user* from, struct hub_user* to)
|
||||
{
|
||||
return st_default;
|
||||
}
|
||||
|
||||
plugin_st plugin_handle_revconnect(struct hub_info* hub, struct hub_user* from, struct hub_user* to)
|
||||
{
|
||||
return st_default;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +40,16 @@ 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);
|
||||
|
||||
/* Handle chat messages */
|
||||
plugin_st plugin_handle_chat_message(struct hub_info* hub, struct hub_user* from, 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);
|
||||
|
||||
/* Handle searches */
|
||||
plugin_st plugin_handle_search(struct hub_info* hub, struct hub_user* user, const char* data);
|
||||
|
||||
/* Handle p2p connections */
|
||||
plugin_st plugin_handle_connect(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);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -123,18 +123,18 @@ void plugin_unload(struct uhub_plugin_handle* plugin)
|
||||
static int plugin_parse_line(char* line, int line_count, void* ptr_data)
|
||||
{
|
||||
struct uhub_plugins* handle = (struct uhub_plugins*) ptr_data;
|
||||
struct linked_list* tokens = cfg_tokenize(line);
|
||||
struct cfg_tokens* tokens = cfg_tokenize(line);
|
||||
char *directive, *soname, *params;
|
||||
|
||||
if (list_size(tokens) == 0)
|
||||
if (cfg_token_count(tokens) == 0)
|
||||
return 0;
|
||||
|
||||
if (list_size(tokens) < 2)
|
||||
if (cfg_token_count(tokens) < 2)
|
||||
return -1;
|
||||
|
||||
directive = list_get_first(tokens);
|
||||
soname = list_get_next(tokens);
|
||||
params = list_get_next(tokens);
|
||||
directive = cfg_token_get_first(tokens);
|
||||
soname = cfg_token_get_next(tokens);
|
||||
params = cfg_token_get_next(tokens);
|
||||
|
||||
if (strcmp(directive, "plugin") == 0 && soname && *soname)
|
||||
{
|
||||
@@ -151,6 +151,7 @@ static int plugin_parse_line(char* line, int line_count, void* ptr_data)
|
||||
}
|
||||
}
|
||||
|
||||
cfg_tokens_free(tokens);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user