Added a chat only hub plugin that disables searching and connection setup.

This also deprecates the built-in chat_only configuration option.
If you need this functionality, then load the mod_chat_only plugin (if it is loaded then only operators
are able to search, connect, etc).
This commit is contained in:
Jan Vidar Krey
2012-01-09 19:54:03 +01:00
parent f44a420970
commit eee2636582
12 changed files with 226 additions and 31 deletions

View File

@@ -126,14 +126,6 @@
<since>0.3.1</since>
</option>
<option name="chat_only" type="boolean" default="0">
<short>Allow chat only operation on hub</short>
<description><![CDATA[
If this is enabled the hub will refuse to relay messages for search and connection setup. This effectively makes the hub viable for chat only.
]]></description>
<since>0.1.1</since>
</option>
<option name="chat_is_privileged" type="boolean" default="0">
<short>Allow chat for operators and above only</short>
<description><![CDATA[

View File

@@ -13,7 +13,6 @@ void config_defaults(struct hub_config* config)
config->registered_users_only = 0;
config->register_self = 0;
config->obsolete_clients = 0;
config->chat_only = 0;
config->chat_is_privileged = 0;
config->hub_name = hub_strdup("uhub");
config->hub_description = hub_strdup("no description");
@@ -203,16 +202,6 @@ static int apply_config(struct hub_config* config, char* key, char* data, int li
return 0;
}
if (!strcmp(key, "chat_only"))
{
if (!apply_boolean(key, data, &config->chat_only))
{
LOG_ERROR("Configuration parse error on line %d", line_count);
return -1;
}
return 0;
}
if (!strcmp(key, "chat_is_privileged"))
{
if (!apply_boolean(key, data, &config->chat_is_privileged))
@@ -1052,9 +1041,6 @@ void dump_config(struct hub_config* config, int ignore_defaults)
if (!ignore_defaults || config->obsolete_clients != 0)
fprintf(stdout, "obsolete_clients = %s\n", config->obsolete_clients ? "yes" : "no");
if (!ignore_defaults || config->chat_only != 0)
fprintf(stdout, "chat_only = %s\n", config->chat_only ? "yes" : "no");
if (!ignore_defaults || config->chat_is_privileged != 0)
fprintf(stdout, "chat_is_privileged = %s\n", config->chat_is_privileged ? "yes" : "no");

View File

@@ -13,7 +13,6 @@ struct hub_config
int registered_users_only; /*<<< Allow registered users only (default: 0) */
int register_self; /*<<< Allow users to register themselves on the hub. (default: 0) */
int obsolete_clients; /*<<< Support obsolete clients using a ADC protocol prior to 1.0 (default: 0) */
int chat_only; /*<<< Allow chat only operation on hub (default: 0) */
int chat_is_privileged; /*<<< Allow chat for operators and above only (default: 0) */
char* hub_name; /*<<< Name of hub (default: uhub) */
char* hub_description; /*<<< Short hub description, topic or subject. (default: no description) */

View File

@@ -21,10 +21,6 @@
struct hub_info* g_hub = 0;
#define CHECK_CHAT_ONLY \
if (hub->config->chat_only && u->credentials < auth_cred_operator) \
break
/* FIXME: Flood control should be done in a plugin! */
#define CHECK_FLOOD(TYPE, WARN) \
if (flood_control_check(&u->flood_ ## TYPE , hub->config->flood_ctl_ ## TYPE, hub->config->flood_ctl_interval, net_get_time())) \
@@ -81,6 +77,7 @@ int hub_handle_message(struct hub_info* hub, struct hub_user* u, const char* lin
case ADC_CMD_EINF:
case ADC_CMD_FINF:
/* these must never be allowed for security reasons, so we ignore them. */
CHECK_FLOOD(extras, 1);
break;
case ADC_CMD_EMSG:
@@ -96,20 +93,35 @@ int hub_handle_message(struct hub_info* hub, struct hub_user* u, const char* lin
case ADC_CMD_ESCH:
case ADC_CMD_FSCH:
cmd->priority = -1;
CHECK_CHAT_ONLY;
if (plugin_handle_search(hub, u, cmd->cache) == st_deny)
break;
CHECK_FLOOD(search, 1);
ROUTE_MSG;
case ADC_CMD_FRES: // spam
case ADC_CMD_BRES: // spam
case ADC_CMD_ERES: // pointless.
CHECK_FLOOD(extras, 1);
break;
case ADC_CMD_DRES:
cmd->priority = -1;
CHECK_CHAT_ONLY;
if (plugin_handle_search_result(hub, u, uman_get_user_by_sid(hub, cmd->target), cmd->cache) == st_deny)
break;
/* CHECK_FLOOD(search, 0); */
ROUTE_MSG;
case ADC_CMD_DRCM:
cmd->priority = -1;
if (plugin_handle_revconnect(hub, u, uman_get_user_by_sid(hub, cmd->target)) == st_deny)
break;
CHECK_FLOOD(connect, 1);
ROUTE_MSG;
case ADC_CMD_DCTM:
cmd->priority = -1;
CHECK_CHAT_ONLY;
if (plugin_handle_connect(hub, u, uman_get_user_by_sid(hub, cmd->target)) == st_deny)
break;
CHECK_FLOOD(connect, 1);
ROUTE_MSG;

View File

@@ -92,6 +92,20 @@ static int cbfunc_send_message(struct plugin_handle* plugin, struct plugin_user*
return 1;
}
static int cbfunc_send_status(struct plugin_handle* plugin, struct plugin_user* user, int code, const char* message)
{
// struct plugin_callback_data* data = get_callback_data(plugin);
char code_str[4];
char* buffer = adc_msg_escape(message);
struct adc_message* command = adc_msg_construct(ADC_CMD_ISTA, strlen(buffer) + 10);
snprintf(code_str, sizeof(code_str), "%03d", code);
adc_msg_add_argument(command, code_str);
adc_msg_add_argument(command, buffer);
route_to_user(plugin_get_hub(plugin), convert_user_type(user), command);
adc_msg_free(command);
hub_free(buffer);
return 1;
}
static int cbfunc_user_disconnect(struct plugin_handle* plugin, struct plugin_user* user)
{
@@ -136,6 +150,7 @@ static int cbfunc_command_del(struct plugin_handle* plugin, struct plugin_comman
void plugin_register_callback_functions(struct plugin_handle* handle)
{
handle->hub.send_message = cbfunc_send_message;
handle->hub.send_status_message = cbfunc_send_status;
handle->hub.user_disconnect = cbfunc_user_disconnect;
handle->hub.command_add = cbfunc_command_add;
handle->hub.command_del = cbfunc_command_del;

View File

@@ -155,6 +155,13 @@ plugin_st plugin_handle_search(struct hub_info* hub, struct hub_user* from, cons
PLUGIN_INVOKE_STATUS_2(hub, on_search, user, data);
}
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);
}
plugin_st plugin_handle_connect(struct hub_info* hub, struct hub_user* from, struct hub_user* to)
{
struct plugin_user* user1 = convert_user_type(from);

View File

@@ -50,6 +50,7 @@ plugin_st plugin_handle_private_message(struct hub_info* hub, struct hub_user* f
/* Handle searches */
plugin_st plugin_handle_search(struct hub_info* hub, struct hub_user* user, const char* data);
plugin_st plugin_handle_search_result(struct hub_info* hub, struct hub_user* from, struct hub_user* to, const char* data);
/* Handle p2p connections */
plugin_st plugin_handle_connect(struct hub_info* hub, struct hub_user* from, struct hub_user* to);