for (param = switch_xml_child(gateway_tag, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
-
+
if (!strcmp(var, "register")) {
register_str = val;
} else if (!strcmp(var, "scheme")) {
expire_seconds = val;
} else if (!strcmp(var, "retry-seconds")) {
retry_seconds = val;
+ } else if (!strcmp(var, "retry_seconds")) { // support typo for back compat
+ retry_seconds = val;
} else if (!strcmp(var, "from-user")) {
from_user = val;
} else if (!strcmp(var, "from-domain")) {
if (!switch_true(register_str)) {
gateway->state = REG_STATE_NOREG;
+ gateway->status = SOFIA_GATEWAY_UP;
}
if (switch_strlen_zero(from_domain)) {
}
gateway->retry_seconds = atoi(retry_seconds);
- if (gateway->retry_seconds < 10) {
+ if (gateway->retry_seconds < 5) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid retry-seconds of %d on gateway %s, using the value of 30 instead.\n",
gateway->retry_seconds, name);
gateway->retry_seconds = 30;
if (status == 200 || status == 404 || status == 501) {
if (gateway->state == REG_STATE_FAILED) {
gateway->state = REG_STATE_UNREGED;
- gateway->retry = 0;
}
gateway->status = SOFIA_GATEWAY_UP;
} else {
switch (ostate) {
case REG_STATE_NOREG:
- gateway_ptr->status = SOFIA_GATEWAY_UP;
+ if (!gateway_ptr->ping && !gateway_ptr->pinging) {
+ gateway_ptr->status = SOFIA_GATEWAY_UP;
+ }
break;
case REG_STATE_REGISTER:
if (profile->debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Registered %s\n", gateway_ptr->name);
}
- if (gateway_ptr->expires > 60) {
+
+ gateway_ptr->failures = 0;
+
+ if (gateway_ptr->freq > 60) {
gateway_ptr->expires = now + (gateway_ptr->freq - 15);
} else {
gateway_ptr->expires = now + (gateway_ptr->freq - 2);
case REG_STATE_UNREGED:
gateway_ptr->status = SOFIA_GATEWAY_DOWN;
sofia_reg_kill_reg(gateway_ptr, 0);
-
+
if ((gateway_ptr->nh = nua_handle(gateway_ptr->profile->nua, NULL,
SIPTAG_CALL_ID_STR(gateway_ptr->uuid_str),
NUTAG_URL(gateway_ptr->register_proxy),
NUTAG_REGISTRAR(gateway_ptr->register_proxy),
NUTAG_OUTBOUND("no-options-keepalive"), NUTAG_OUTBOUND("no-validate"), NUTAG_KEEPALIVE(0), TAG_NULL());
}
-
+ gateway_ptr->retry = now + gateway_ptr->retry_seconds;
gateway_ptr->state = REG_STATE_TRYING;
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error registering %s\n", gateway_ptr->name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error registering %s failure #%d\n", gateway_ptr->name, ++gateway_ptr->failures);
gateway_ptr->state = REG_STATE_FAILED;
}
break;
case REG_STATE_FAILED:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s Failed Registration, setting retry to %d seconds.\n",
+ gateway_ptr->name, gateway_ptr->retry_seconds * (gateway_ptr->failures + 1));
+ gateway_ptr->retry = now + (gateway_ptr->retry_seconds * (gateway_ptr->failures + 1));
sofia_reg_kill_reg(gateway_ptr, 0);
gateway_ptr->status = SOFIA_GATEWAY_DOWN;
- case REG_STATE_TRYING:
- if (gateway_ptr->retry && now >= gateway_ptr->retry) {
+ gateway_ptr->state = REG_STATE_FAIL_WAIT;
+ break;
+ case REG_STATE_FAIL_WAIT:
+ if (!gateway_ptr->retry || now >= gateway_ptr->retry) {
gateway_ptr->state = REG_STATE_UNREGED;
- gateway_ptr->retry = 0;
+ }
+ break;
+ case REG_STATE_TRYING:
+ if (!gateway_ptr->retry || now >= gateway_ptr->retry) {
+ gateway_ptr->state = REG_STATE_FAILED;
}
break;
default:
break;
default:
sofia_private->gateway->state = REG_STATE_FAILED;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Registration Failed with status %d\n", status);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Registration Failed with status %d. failure #%d\n",
+ sofia_private->gateway->name, status, ++sofia_private->gateway->failures);
break;
}
if (ostate != sofia_private->gateway->state) {