Adding support for redirecting clients to other hubs when they fail to login

for various reasons.

Config variable is "redirect_addr".
This commit is contained in:
Jan Vidar Krey 2010-04-22 21:07:46 +02:00
parent b29f34af4a
commit c70119870a
4 changed files with 67 additions and 33 deletions

View File

@ -155,6 +155,16 @@
]]></example> ]]></example>
</option> </option>
<option name="redirect_addr" type="string" default="">
<check regexp="(adc|adcs|dchub)://.*" />
<short>A common hub redirect address.</short>
<description><![CDATA[
This is the redirect address used when the hub wants to redirect a client for not fulfilling some requirements.
]]></description>
<since>0.3.2</since>
</option>
<option name="max_recv_buffer" type="int" default="4096" advanced="true" > <option name="max_recv_buffer" type="int" default="4096" advanced="true" >
<check min="1024" max="1048576" /> <check min="1024" max="1048576" />
<short>Max read buffer before parse, per user</short> <short>Max read buffer before parse, per user</short>

View File

@ -16,6 +16,7 @@ void config_defaults(struct hub_config* config)
config->chat_is_privileged = 0; config->chat_is_privileged = 0;
config->hub_name = hub_strdup("uhub"); config->hub_name = hub_strdup("uhub");
config->hub_description = hub_strdup("no description"); config->hub_description = hub_strdup("no description");
config->redirect_addr = hub_strdup("");
config->max_recv_buffer = 4096; config->max_recv_buffer = 4096;
config->max_send_buffer = 131072; config->max_send_buffer = 131072;
config->max_send_buffer_soft = 98304; config->max_send_buffer_soft = 98304;
@ -231,6 +232,16 @@ static int apply_config(struct hub_config* config, char* key, char* data, int li
return 0; return 0;
} }
if (!strcmp(key, "redirect_addr"))
{
if (!apply_string(key, data, &config->redirect_addr, (char*) ""))
{
LOG_ERROR("Configuration parse error on line %d", line_count);
return -1;
}
return 0;
}
if (!strcmp(key, "max_recv_buffer")) if (!strcmp(key, "max_recv_buffer"))
{ {
if (!apply_integer(key, data, &config->max_recv_buffer, 0, 0)) if (!apply_integer(key, data, &config->max_recv_buffer, 0, 0))
@ -909,6 +920,8 @@ void free_config(struct hub_config* config)
hub_free(config->hub_description); hub_free(config->hub_description);
hub_free(config->redirect_addr);
hub_free(config->tls_certificate); hub_free(config->tls_certificate);
hub_free(config->tls_private_key); hub_free(config->tls_private_key);
@ -1037,6 +1050,9 @@ void dump_config(struct hub_config* config, int ignore_defaults)
if (!ignore_defaults || strcmp(config->hub_description, "no description") != 0) if (!ignore_defaults || strcmp(config->hub_description, "no description") != 0)
fprintf(stdout, "hub_description = \"%s\"\n", config->hub_description); fprintf(stdout, "hub_description = \"%s\"\n", config->hub_description);
if (!ignore_defaults || strcmp(config->redirect_addr, "") != 0)
fprintf(stdout, "redirect_addr = \"%s\"\n", config->redirect_addr);
if (!ignore_defaults || config->max_recv_buffer != 4096) if (!ignore_defaults || config->max_recv_buffer != 4096)
fprintf(stdout, "max_recv_buffer = %d\n", config->max_recv_buffer); fprintf(stdout, "max_recv_buffer = %d\n", config->max_recv_buffer);

View File

@ -16,6 +16,7 @@ struct hub_config
int chat_is_privileged; /*<<< Allow chat for operators and above only (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_name; /*<<< Name of hub (default: uhub) */
char* hub_description; /*<<< Short hub description, topic or subject. (default: no description) */ char* hub_description; /*<<< Short hub description, topic or subject. (default: no description) */
char* redirect_addr; /*<<< A common hub redirect address. (default: ) */
int max_recv_buffer; /*<<< Max read buffer before parse, per user (default: 4096) */ int max_recv_buffer; /*<<< Max read buffer before parse, per user (default: 4096) */
int max_send_buffer; /*<<< Max send buffer before disconnect, per user (default: 131072) */ int max_send_buffer; /*<<< Max send buffer before disconnect, per user (default: 131072) */
int max_send_buffer_soft; /*<<< Max send buffer before message drops, per user (default: 98304) */ int max_send_buffer_soft; /*<<< Max send buffer before message drops, per user (default: 98304) */

View File

@ -942,13 +942,14 @@ void hub_send_status(struct hub_info* hub, struct hub_user* user, enum status_me
{ {
struct hub_config* cfg = hub->config; struct hub_config* cfg = hub->config;
struct adc_message* cmd = adc_msg_construct(ADC_CMD_ISTA, 6); struct adc_message* cmd = adc_msg_construct(ADC_CMD_ISTA, 6);
struct adc_message* qui = adc_msg_construct(ADC_CMD_IQUI, 256); struct adc_message* qui = adc_msg_construct(ADC_CMD_IQUI, 512);
char code[4]; char code[4];
char buf[250]; char buf[250];
const char* text = 0; const char* text = 0;
const char* flag = 0; const char* flag = 0;
char* escaped_text = 0; char* escaped_text = 0;
int reconnect_time = 0; int reconnect_time = 0;
int redirect = 0;
if (!cmd || !qui) if (!cmd || !qui)
{ {
@ -957,40 +958,40 @@ void hub_send_status(struct hub_info* hub, struct hub_user* user, enum status_me
return; return;
} }
#define STATUS(CODE, MSG, FLAG, RCONTIME) case status_ ## MSG : set_status_code(level, CODE, code); text = cfg->MSG; flag = FLAG; reconnect_time = RCONTIME; break #define STATUS(CODE, MSG, FLAG, RCONTIME, REDIRECT) case status_ ## MSG : set_status_code(level, CODE, code); text = cfg->MSG; flag = FLAG; reconnect_time = RCONTIME; redirect = REDIRECT; break
switch (msg) switch (msg)
{ {
STATUS(11, msg_hub_full, 0, 600); /* FIXME: Proper timeout? */ STATUS(11, msg_hub_full, 0, 600, 1); /* FIXME: Proper timeout? */
STATUS(12, msg_hub_disabled, 0, -1); STATUS(12, msg_hub_disabled, 0, -1, 1);
STATUS(26, msg_hub_registered_users_only, 0, 0); STATUS(26, msg_hub_registered_users_only, 0, 0, 1);
STATUS(43, msg_inf_error_nick_missing, 0, 0); STATUS(43, msg_inf_error_nick_missing, 0, 0, 0);
STATUS(43, msg_inf_error_nick_multiple, 0, 0); STATUS(43, msg_inf_error_nick_multiple, 0, 0, 0);
STATUS(21, msg_inf_error_nick_invalid, 0, 0); STATUS(21, msg_inf_error_nick_invalid, 0, 0, 0);
STATUS(21, msg_inf_error_nick_long, 0, 0); STATUS(21, msg_inf_error_nick_long, 0, 0, 0);
STATUS(21, msg_inf_error_nick_short, 0, 0); STATUS(21, msg_inf_error_nick_short, 0, 0, 0);
STATUS(21, msg_inf_error_nick_spaces, 0, 0); STATUS(21, msg_inf_error_nick_spaces, 0, 0, 0);
STATUS(21, msg_inf_error_nick_bad_chars, 0, 0); STATUS(21, msg_inf_error_nick_bad_chars, 0, 0, 0);
STATUS(21, msg_inf_error_nick_not_utf8, 0, 0); STATUS(21, msg_inf_error_nick_not_utf8, 0, 0, 0);
STATUS(22, msg_inf_error_nick_taken, 0, 0); STATUS(22, msg_inf_error_nick_taken, 0, 0, 0);
STATUS(21, msg_inf_error_nick_restricted, 0, 0); STATUS(21, msg_inf_error_nick_restricted, 0, 0, 0);
STATUS(43, msg_inf_error_cid_invalid, "FBID", 0); STATUS(43, msg_inf_error_cid_invalid, "FBID", 0, 0);
STATUS(43, msg_inf_error_cid_missing, "FMID", 0); STATUS(43, msg_inf_error_cid_missing, "FMID", 0, 0);
STATUS(24, msg_inf_error_cid_taken, 0, 0); STATUS(24, msg_inf_error_cid_taken, 0, 0, 0);
STATUS(43, msg_inf_error_pid_missing, "FMPD", 0); STATUS(43, msg_inf_error_pid_missing, "FMPD", 0, 0);
STATUS(27, msg_inf_error_pid_invalid, "FBPD", 0); STATUS(27, msg_inf_error_pid_invalid, "FBPD", 0, 0);
STATUS(31, msg_ban_permanently, 0, 0); STATUS(31, msg_ban_permanently, 0, 0, 0);
STATUS(32, msg_ban_temporarily, "TL600", 600); /* FIXME: Proper timeout? */ STATUS(32, msg_ban_temporarily, "TL600", 600, 0); /* FIXME: Proper timeout? */
STATUS(23, msg_auth_invalid_password, 0, 0); STATUS(23, msg_auth_invalid_password, 0, 0, 0);
STATUS(20, msg_auth_user_not_found, 0, 0); STATUS(20, msg_auth_user_not_found, 0, 0, 0);
STATUS(30, msg_error_no_memory, 0, 0); STATUS(30, msg_error_no_memory, 0, 0, 0);
STATUS(43, msg_user_share_size_low, "FB" ADC_INF_FLAG_SHARED_SIZE, 0); STATUS(43, msg_user_share_size_low, "FB" ADC_INF_FLAG_SHARED_SIZE, 0, 1);
STATUS(43, msg_user_share_size_high, "FB" ADC_INF_FLAG_SHARED_SIZE, 0); STATUS(43, msg_user_share_size_high, "FB" ADC_INF_FLAG_SHARED_SIZE, 0, 1);
STATUS(43, msg_user_slots_low, "FB" ADC_INF_FLAG_UPLOAD_SLOTS, 0); STATUS(43, msg_user_slots_low, "FB" ADC_INF_FLAG_UPLOAD_SLOTS, 0, 1);
STATUS(43, msg_user_slots_high, "FB" ADC_INF_FLAG_UPLOAD_SLOTS, 0); STATUS(43, msg_user_slots_high, "FB" ADC_INF_FLAG_UPLOAD_SLOTS, 0, 1);
STATUS(43, msg_user_hub_limit_low, 0, 0); STATUS(43, msg_user_hub_limit_low, 0, 0, 1);
STATUS(43, msg_user_hub_limit_high, 0, 0); STATUS(43, msg_user_hub_limit_high, 0, 0, 1);
STATUS(47, msg_proto_no_common_hash, 0, -1); STATUS(47, msg_proto_no_common_hash, 0, -1, 1);
STATUS(40, msg_proto_obsolete_adc0, 0, -1); STATUS(40, msg_proto_obsolete_adc0, 0, -1, 1);
} }
#undef STATUS #undef STATUS
@ -1016,6 +1017,12 @@ void hub_send_status(struct hub_info* hub, struct hub_user* user, enum status_me
snprintf(buf, 10, "TL%d", reconnect_time); snprintf(buf, 10, "TL%d", reconnect_time);
adc_msg_add_argument(qui, buf); adc_msg_add_argument(qui, buf);
} }
if (redirect && *hub->config->redirect_addr)
{
snprintf(buf, 255, "RD%s", hub->config->redirect_addr);
adc_msg_add_argument(qui, buf);
}
route_to_user(hub, user, qui); route_to_user(hub, user, qui);
} }