FS-4435 looks ok at a glance, at least this code is isolated to the small few who actually use it so i will put it in for testing
This commit is contained in:
parent
19b7e30eea
commit
223244d491
|
@ -438,9 +438,11 @@ typedef enum {
|
|||
|
||||
struct sofia_gateway_subscription {
|
||||
sofia_gateway_t *gateway;
|
||||
nua_handle_t *nh;
|
||||
char *expires_str;
|
||||
char *event; /* eg, 'message-summary' to subscribe to MWI events */
|
||||
char *content_type; /* eg, application/simple-message-summary in the case of MWI events */
|
||||
char *request_uri;
|
||||
uint32_t freq;
|
||||
int32_t retry_seconds;
|
||||
time_t expires;
|
||||
|
@ -452,7 +454,6 @@ struct sofia_gateway_subscription {
|
|||
struct sofia_gateway {
|
||||
sofia_private_t *sofia_private;
|
||||
nua_handle_t *nh;
|
||||
nua_handle_t *sub_nh;
|
||||
sofia_profile_t *profile;
|
||||
char *name;
|
||||
char *register_scheme;
|
||||
|
@ -491,7 +492,6 @@ struct sofia_gateway {
|
|||
int32_t retry_seconds;
|
||||
int32_t reg_timeout_seconds;
|
||||
int32_t failure_status;
|
||||
sub_state_t sub_state;
|
||||
reg_state_t state;
|
||||
switch_memory_pool_t *pool;
|
||||
int deleted;
|
||||
|
|
|
@ -2510,6 +2510,7 @@ static void parse_gateway_subscriptions(sofia_profile_t *profile, sofia_gateway_
|
|||
|
||||
if ((gw_sub = switch_core_alloc(profile->pool, sizeof(*gw_sub)))) {
|
||||
char *expire_seconds = "3600", *retry_seconds = "30", *content_type = "NO_CONTENT_TYPE";
|
||||
uint32_t username_in_request = 0;
|
||||
char *event = (char *) switch_xml_attr_soft(subscription_tag, "event");
|
||||
gw_sub->event = switch_core_strdup(gateway->pool, event);
|
||||
gw_sub->gateway = gateway;
|
||||
|
@ -2524,6 +2525,8 @@ static void parse_gateway_subscriptions(sofia_profile_t *profile, sofia_gateway_
|
|||
retry_seconds = val;
|
||||
} else if (!strcmp(var, "content-type")) {
|
||||
content_type = val;
|
||||
} else if (!strcmp(var, "username-in-request")) {
|
||||
username_in_request = switch_true(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2539,6 +2542,13 @@ static void parse_gateway_subscriptions(sofia_profile_t *profile, sofia_gateway_
|
|||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid Freq: %d. Setting Register-Frequency to 3600\n", gw_sub->freq);
|
||||
gw_sub->freq = 3600;
|
||||
}
|
||||
|
||||
if(username_in_request) {
|
||||
gw_sub->request_uri = gateway->register_to;
|
||||
} else {
|
||||
gw_sub->request_uri = gateway->register_url;
|
||||
}
|
||||
|
||||
gw_sub->freq -= 2;
|
||||
gw_sub->content_type = switch_core_strdup(gateway->pool, content_type);
|
||||
gw_sub->next = gateway->subscriptions;
|
||||
|
@ -2741,12 +2751,7 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag)
|
|||
su_guid_generate(guid);
|
||||
su_guid_sprintf(str_guid, su_guid_strlen + 1, guid);
|
||||
str_rfc_5626 = switch_core_sprintf(gateway->pool, ";reg-id=%s;+sip.instance=\"<urn:uuid:%s>\"",reg_id,str_guid);
|
||||
}
|
||||
|
||||
|
||||
if ((gw_subs_tag = switch_xml_child(gateway_tag, "subscriptions"))) {
|
||||
parse_gateway_subscriptions(profile, gateway, gw_subs_tag);
|
||||
}
|
||||
}
|
||||
|
||||
if (zstr(realm)) {
|
||||
if (zstr(proxy)) {
|
||||
|
@ -2960,7 +2965,10 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag)
|
|||
gateway->freq = 3600;
|
||||
}
|
||||
|
||||
|
||||
if ((gw_subs_tag = switch_xml_child(gateway_tag, "subscriptions"))) {
|
||||
parse_gateway_subscriptions(profile, gateway, gw_subs_tag);
|
||||
}
|
||||
|
||||
sofia_reg_add_gateway(profile, gateway->name, gateway);
|
||||
|
||||
}
|
||||
|
|
|
@ -3979,10 +3979,10 @@ void sofia_presence_handle_sip_r_subscribe(int status,
|
|||
gw_sub_ptr->state = SUB_STATE_FAILED;
|
||||
|
||||
if (sofia_private) {
|
||||
if (sofia_private->gateway->sub_nh) {
|
||||
nua_handle_bind(sofia_private->gateway->sub_nh, NULL);
|
||||
nua_handle_destroy(sofia_private->gateway->sub_nh);
|
||||
sofia_private->gateway->sub_nh = NULL;
|
||||
if (gw_sub_ptr->nh) {
|
||||
nua_handle_bind(gw_sub_ptr->nh, NULL);
|
||||
nua_handle_destroy(gw_sub_ptr->nh);
|
||||
gw_sub_ptr->nh = NULL;
|
||||
}
|
||||
} else {
|
||||
nua_handle_destroy(nh);
|
||||
|
|
|
@ -65,26 +65,27 @@ static void sofia_reg_new_handle(sofia_gateway_t *gateway_ptr, int attach)
|
|||
}
|
||||
}
|
||||
|
||||
static void sofia_reg_new_sub_handle(sofia_gateway_t *gateway_ptr, int attach)
|
||||
{
|
||||
static void sofia_reg_new_sub_handle(sofia_gateway_subscription_t *gw_sub_ptr, int attach)
|
||||
{
|
||||
sofia_gateway_t *gateway_ptr = gw_sub_ptr->gateway;
|
||||
char *user_via = NULL;
|
||||
char *register_host = sofia_glue_get_register_host(gateway_ptr->register_proxy);
|
||||
int ss_state = nua_callstate_authenticating;
|
||||
|
||||
|
||||
/* check for NAT and place a Via header if necessary (hostname or non-local IP) */
|
||||
if (register_host && sofia_glue_check_nat(gateway_ptr->profile, register_host)) {
|
||||
user_via = sofia_glue_create_external_via(NULL, gateway_ptr->profile, gateway_ptr->register_transport);
|
||||
}
|
||||
|
||||
if (gateway_ptr->sub_nh) {
|
||||
nua_handle_bind(gateway_ptr->sub_nh, NULL);
|
||||
nua_handle_destroy(gateway_ptr->sub_nh);
|
||||
gateway_ptr->sub_nh = NULL;
|
||||
|
||||
if (gw_sub_ptr->nh) {
|
||||
nua_handle_bind(gw_sub_ptr->nh, NULL);
|
||||
nua_handle_destroy(gw_sub_ptr->nh);
|
||||
gw_sub_ptr->nh = NULL;
|
||||
sofia_private_free(gateway_ptr->sofia_private);
|
||||
}
|
||||
|
||||
gateway_ptr->sub_nh = nua_handle(gateway_ptr->profile->nua, NULL,
|
||||
NUTAG_URL(gateway_ptr->register_proxy),
|
||||
|
||||
gw_sub_ptr->nh = nua_handle(gateway_ptr->profile->nua, NULL,
|
||||
NUTAG_URL(gateway_ptr->register_proxy),
|
||||
TAG_IF(user_via, SIPTAG_VIA_STR(user_via)),
|
||||
SIPTAG_TO_STR(gateway_ptr->register_to),
|
||||
NUTAG_CALLSTATE_REF(ss_state), SIPTAG_FROM_STR(gateway_ptr->register_from), TAG_END());
|
||||
|
@ -96,31 +97,32 @@ static void sofia_reg_new_sub_handle(sofia_gateway_t *gateway_ptr, int attach)
|
|||
memset(gateway_ptr->sofia_private, 0, sizeof(*gateway_ptr->sofia_private));
|
||||
|
||||
gateway_ptr->sofia_private->gateway = gateway_ptr;
|
||||
nua_handle_bind(gateway_ptr->sub_nh, gateway_ptr->sofia_private);
|
||||
nua_handle_bind(gw_sub_ptr->nh, gateway_ptr->sofia_private);
|
||||
}
|
||||
|
||||
switch_safe_free(register_host);
|
||||
switch_safe_free(user_via);
|
||||
}
|
||||
|
||||
static void sofia_reg_kill_sub(sofia_gateway_t *gateway_ptr)
|
||||
{
|
||||
static void sofia_reg_kill_sub(sofia_gateway_subscription_t *gw_sub_ptr)
|
||||
{
|
||||
sofia_gateway_t *gateway_ptr = gw_sub_ptr->gateway;
|
||||
|
||||
if (gateway_ptr->sub_nh) {
|
||||
nua_handle_bind(gateway_ptr->sub_nh, NULL);
|
||||
if (gw_sub_ptr->nh) {
|
||||
nua_handle_bind(gw_sub_ptr->nh, NULL);
|
||||
}
|
||||
|
||||
if (gateway_ptr->sub_state != SUB_STATE_SUBED && gateway_ptr->sub_state != SUB_STATE_UNSUBSCRIBE) {
|
||||
if (gateway_ptr->sub_nh) {
|
||||
nua_handle_destroy(gateway_ptr->sub_nh);
|
||||
gateway_ptr->sub_nh = NULL;
|
||||
|
||||
if (gw_sub_ptr->state != SUB_STATE_SUBED && gw_sub_ptr->state != SUB_STATE_UNSUBSCRIBE) {
|
||||
if (gw_sub_ptr->nh) {
|
||||
nua_handle_destroy(gw_sub_ptr->nh);
|
||||
gw_sub_ptr->nh = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (gateway_ptr->sub_nh) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "UN-Subbing %s\n", gateway_ptr->name);
|
||||
nua_unsubscribe(gateway_ptr->sub_nh, NUTAG_URL(gateway_ptr->register_url), TAG_END());
|
||||
if (gw_sub_ptr->nh) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "UN-Subbing %s %s\n", gateway_ptr->name, gw_sub_ptr->event);
|
||||
nua_unsubscribe(gw_sub_ptr->nh, NUTAG_URL(gw_sub_ptr->request_uri), TAG_END());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,7 +184,7 @@ void sofia_reg_unregister(sofia_profile_t *profile)
|
|||
|
||||
for (gw_sub_ptr = gateway_ptr->subscriptions; gw_sub_ptr; gw_sub_ptr = gw_sub_ptr->next) {
|
||||
if (gw_sub_ptr->state == SUB_STATE_SUBED) {
|
||||
sofia_reg_kill_sub(gateway_ptr);
|
||||
sofia_reg_kill_sub(gw_sub_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,7 +213,7 @@ void sofia_sub_check_gateway(sofia_profile_t *profile, time_t now)
|
|||
gw_sub_ptr->expires_str = "0";
|
||||
}
|
||||
|
||||
gateway_ptr->sub_state = gw_sub_ptr->state;
|
||||
//gateway_ptr->sub_state = gw_sub_ptr->state;
|
||||
|
||||
switch (ostate) {
|
||||
case SUB_STATE_NOSUB:
|
||||
|
@ -222,19 +224,19 @@ void sofia_sub_check_gateway(sofia_profile_t *profile, time_t now)
|
|||
break;
|
||||
case SUB_STATE_UNSUBSCRIBE:
|
||||
gw_sub_ptr->state = SUB_STATE_NOSUB;
|
||||
sofia_reg_kill_sub(gateway_ptr);
|
||||
sofia_reg_kill_sub(gw_sub_ptr);
|
||||
break;
|
||||
case SUB_STATE_UNSUBED:
|
||||
|
||||
sofia_reg_new_sub_handle(gateway_ptr, 1);
|
||||
sofia_reg_new_sub_handle(gw_sub_ptr, 1);
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "subscribing to [%s] on gateway [%s]\n", gw_sub_ptr->event, gateway_ptr->name);
|
||||
|
||||
|
||||
if (now) {
|
||||
nua_subscribe(gateway_ptr->sub_nh,
|
||||
NUTAG_URL(gateway_ptr->register_url),
|
||||
nua_subscribe(gw_sub_ptr->nh,
|
||||
NUTAG_URL(gw_sub_ptr->request_uri),
|
||||
SIPTAG_EVENT_STR(gw_sub_ptr->event),
|
||||
SIPTAG_ACCEPT_STR(gw_sub_ptr->content_type),
|
||||
TAG_IF(strcmp(gw_sub_ptr->content_type, "NO_CONTENT_TYPE"), SIPTAG_ACCEPT_STR(gw_sub_ptr->content_type)),
|
||||
SIPTAG_TO_STR(gateway_ptr->register_from),
|
||||
SIPTAG_FROM_STR(gateway_ptr->register_from),
|
||||
SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
|
||||
|
@ -242,10 +244,10 @@ void sofia_sub_check_gateway(sofia_profile_t *profile, time_t now)
|
|||
TAG_NULL());
|
||||
gw_sub_ptr->retry = now + gw_sub_ptr->retry_seconds;
|
||||
} else {
|
||||
nua_unsubscribe(gateway_ptr->sub_nh,
|
||||
NUTAG_URL(gateway_ptr->register_url),
|
||||
nua_unsubscribe(gw_sub_ptr->nh,
|
||||
NUTAG_URL(gw_sub_ptr->request_uri),
|
||||
SIPTAG_EVENT_STR(gw_sub_ptr->event),
|
||||
SIPTAG_ACCEPT_STR(gw_sub_ptr->content_type),
|
||||
TAG_IF(strcmp(gw_sub_ptr->content_type, "NO_CONTENT_TYPE"), SIPTAG_ACCEPT_STR(gw_sub_ptr->content_type)),
|
||||
SIPTAG_FROM_STR(gateway_ptr->register_from),
|
||||
SIPTAG_TO_STR(gateway_ptr->register_from),
|
||||
SIPTAG_CONTACT_STR(gateway_ptr->register_contact), SIPTAG_EXPIRES_STR(gw_sub_ptr->expires_str), TAG_NULL());
|
||||
|
|
Loading…
Reference in New Issue