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:
Anthony Minessale 2012-07-17 17:01:10 -05:00
parent 19b7e30eea
commit 223244d491
4 changed files with 58 additions and 48 deletions

View File

@ -438,9 +438,11 @@ typedef enum {
struct sofia_gateway_subscription { struct sofia_gateway_subscription {
sofia_gateway_t *gateway; sofia_gateway_t *gateway;
nua_handle_t *nh;
char *expires_str; char *expires_str;
char *event; /* eg, 'message-summary' to subscribe to MWI events */ 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 *content_type; /* eg, application/simple-message-summary in the case of MWI events */
char *request_uri;
uint32_t freq; uint32_t freq;
int32_t retry_seconds; int32_t retry_seconds;
time_t expires; time_t expires;
@ -452,7 +454,6 @@ struct sofia_gateway_subscription {
struct sofia_gateway { struct sofia_gateway {
sofia_private_t *sofia_private; sofia_private_t *sofia_private;
nua_handle_t *nh; nua_handle_t *nh;
nua_handle_t *sub_nh;
sofia_profile_t *profile; sofia_profile_t *profile;
char *name; char *name;
char *register_scheme; char *register_scheme;
@ -491,7 +492,6 @@ struct sofia_gateway {
int32_t retry_seconds; int32_t retry_seconds;
int32_t reg_timeout_seconds; int32_t reg_timeout_seconds;
int32_t failure_status; int32_t failure_status;
sub_state_t sub_state;
reg_state_t state; reg_state_t state;
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
int deleted; int deleted;

View File

@ -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)))) { if ((gw_sub = switch_core_alloc(profile->pool, sizeof(*gw_sub)))) {
char *expire_seconds = "3600", *retry_seconds = "30", *content_type = "NO_CONTENT_TYPE"; 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"); char *event = (char *) switch_xml_attr_soft(subscription_tag, "event");
gw_sub->event = switch_core_strdup(gateway->pool, event); gw_sub->event = switch_core_strdup(gateway->pool, event);
gw_sub->gateway = gateway; gw_sub->gateway = gateway;
@ -2524,6 +2525,8 @@ static void parse_gateway_subscriptions(sofia_profile_t *profile, sofia_gateway_
retry_seconds = val; retry_seconds = val;
} else if (!strcmp(var, "content-type")) { } else if (!strcmp(var, "content-type")) {
content_type = val; 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); 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; 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->freq -= 2;
gw_sub->content_type = switch_core_strdup(gateway->pool, content_type); gw_sub->content_type = switch_core_strdup(gateway->pool, content_type);
gw_sub->next = gateway->subscriptions; gw_sub->next = gateway->subscriptions;
@ -2743,11 +2753,6 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag)
str_rfc_5626 = switch_core_sprintf(gateway->pool, ";reg-id=%s;+sip.instance=\"<urn:uuid:%s>\"",reg_id,str_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(realm)) {
if (zstr(proxy)) { if (zstr(proxy)) {
realm = name; realm = name;
@ -2960,6 +2965,9 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag)
gateway->freq = 3600; 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); sofia_reg_add_gateway(profile, gateway->name, gateway);

View File

@ -3979,10 +3979,10 @@ void sofia_presence_handle_sip_r_subscribe(int status,
gw_sub_ptr->state = SUB_STATE_FAILED; gw_sub_ptr->state = SUB_STATE_FAILED;
if (sofia_private) { if (sofia_private) {
if (sofia_private->gateway->sub_nh) { if (gw_sub_ptr->nh) {
nua_handle_bind(sofia_private->gateway->sub_nh, NULL); nua_handle_bind(gw_sub_ptr->nh, NULL);
nua_handle_destroy(sofia_private->gateway->sub_nh); nua_handle_destroy(gw_sub_ptr->nh);
sofia_private->gateway->sub_nh = NULL; gw_sub_ptr->nh = NULL;
} }
} else { } else {
nua_handle_destroy(nh); nua_handle_destroy(nh);

View File

@ -65,8 +65,9 @@ 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 *user_via = NULL;
char *register_host = sofia_glue_get_register_host(gateway_ptr->register_proxy); char *register_host = sofia_glue_get_register_host(gateway_ptr->register_proxy);
int ss_state = nua_callstate_authenticating; int ss_state = nua_callstate_authenticating;
@ -76,14 +77,14 @@ static void sofia_reg_new_sub_handle(sofia_gateway_t *gateway_ptr, int attach)
user_via = sofia_glue_create_external_via(NULL, gateway_ptr->profile, gateway_ptr->register_transport); user_via = sofia_glue_create_external_via(NULL, gateway_ptr->profile, gateway_ptr->register_transport);
} }
if (gateway_ptr->sub_nh) { if (gw_sub_ptr->nh) {
nua_handle_bind(gateway_ptr->sub_nh, NULL); nua_handle_bind(gw_sub_ptr->nh, NULL);
nua_handle_destroy(gateway_ptr->sub_nh); nua_handle_destroy(gw_sub_ptr->nh);
gateway_ptr->sub_nh = NULL; gw_sub_ptr->nh = NULL;
sofia_private_free(gateway_ptr->sofia_private); sofia_private_free(gateway_ptr->sofia_private);
} }
gateway_ptr->sub_nh = nua_handle(gateway_ptr->profile->nua, NULL, gw_sub_ptr->nh = nua_handle(gateway_ptr->profile->nua, NULL,
NUTAG_URL(gateway_ptr->register_proxy), NUTAG_URL(gateway_ptr->register_proxy),
TAG_IF(user_via, SIPTAG_VIA_STR(user_via)), TAG_IF(user_via, SIPTAG_VIA_STR(user_via)),
SIPTAG_TO_STR(gateway_ptr->register_to), SIPTAG_TO_STR(gateway_ptr->register_to),
@ -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)); memset(gateway_ptr->sofia_private, 0, sizeof(*gateway_ptr->sofia_private));
gateway_ptr->sofia_private->gateway = gateway_ptr; 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(register_host);
switch_safe_free(user_via); 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) { if (gw_sub_ptr->nh) {
nua_handle_bind(gateway_ptr->sub_nh, NULL); nua_handle_bind(gw_sub_ptr->nh, NULL);
} }
if (gateway_ptr->sub_state != SUB_STATE_SUBED && gateway_ptr->sub_state != SUB_STATE_UNSUBSCRIBE) { if (gw_sub_ptr->state != SUB_STATE_SUBED && gw_sub_ptr->state != SUB_STATE_UNSUBSCRIBE) {
if (gateway_ptr->sub_nh) { if (gw_sub_ptr->nh) {
nua_handle_destroy(gateway_ptr->sub_nh); nua_handle_destroy(gw_sub_ptr->nh);
gateway_ptr->sub_nh = NULL; gw_sub_ptr->nh = NULL;
} }
return; return;
} }
if (gateway_ptr->sub_nh) { if (gw_sub_ptr->nh) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "UN-Subbing %s\n", gateway_ptr->name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "UN-Subbing %s %s\n", gateway_ptr->name, gw_sub_ptr->event);
nua_unsubscribe(gateway_ptr->sub_nh, NUTAG_URL(gateway_ptr->register_url), TAG_END()); 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) { 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) { 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"; gw_sub_ptr->expires_str = "0";
} }
gateway_ptr->sub_state = gw_sub_ptr->state; //gateway_ptr->sub_state = gw_sub_ptr->state;
switch (ostate) { switch (ostate) {
case SUB_STATE_NOSUB: case SUB_STATE_NOSUB:
@ -222,19 +224,19 @@ void sofia_sub_check_gateway(sofia_profile_t *profile, time_t now)
break; break;
case SUB_STATE_UNSUBSCRIBE: case SUB_STATE_UNSUBSCRIBE:
gw_sub_ptr->state = SUB_STATE_NOSUB; gw_sub_ptr->state = SUB_STATE_NOSUB;
sofia_reg_kill_sub(gateway_ptr); sofia_reg_kill_sub(gw_sub_ptr);
break; break;
case SUB_STATE_UNSUBED: 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); 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) { if (now) {
nua_subscribe(gateway_ptr->sub_nh, nua_subscribe(gw_sub_ptr->nh,
NUTAG_URL(gateway_ptr->register_url), NUTAG_URL(gw_sub_ptr->request_uri),
SIPTAG_EVENT_STR(gw_sub_ptr->event), 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_TO_STR(gateway_ptr->register_from),
SIPTAG_FROM_STR(gateway_ptr->register_from), SIPTAG_FROM_STR(gateway_ptr->register_from),
SIPTAG_CONTACT_STR(gateway_ptr->register_contact), 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()); TAG_NULL());
gw_sub_ptr->retry = now + gw_sub_ptr->retry_seconds; gw_sub_ptr->retry = now + gw_sub_ptr->retry_seconds;
} else { } else {
nua_unsubscribe(gateway_ptr->sub_nh, nua_unsubscribe(gw_sub_ptr->nh,
NUTAG_URL(gateway_ptr->register_url), NUTAG_URL(gw_sub_ptr->request_uri),
SIPTAG_EVENT_STR(gw_sub_ptr->event), 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_FROM_STR(gateway_ptr->register_from),
SIPTAG_TO_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()); SIPTAG_CONTACT_STR(gateway_ptr->register_contact), SIPTAG_EXPIRES_STR(gw_sub_ptr->expires_str), TAG_NULL());