diff options
Diffstat (limited to 'res')
-rw-r--r-- | res/res_pjsip/location.c | 30 | ||||
-rw-r--r-- | res/res_pjsip_session.c | 5 |
2 files changed, 27 insertions, 8 deletions
diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c index d036ffa15..6ffb8fec3 100644 --- a/res/res_pjsip/location.c +++ b/res/res_pjsip/location.c @@ -144,30 +144,46 @@ struct ao2_container *ast_sip_location_retrieve_aor_contacts(const struct ast_si return contacts; } -struct ast_sip_contact *ast_sip_location_retrieve_contact_from_aor_list(const char *aor_list) +void ast_sip_location_retrieve_contact_and_aor_from_list(const char *aor_list, struct ast_sip_aor **aor, + struct ast_sip_contact **contact) { char *aor_name; char *rest; - struct ast_sip_contact *contact = NULL; /* If the location is still empty we have nowhere to go */ if (ast_strlen_zero(aor_list) || !(rest = ast_strdupa(aor_list))) { ast_log(LOG_WARNING, "Unable to determine contacts from empty aor list\n"); - return NULL; + return; } + *aor = NULL; + *contact = NULL; + while ((aor_name = strsep(&rest, ","))) { - RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup); + *aor = ast_sip_location_retrieve_aor(aor_name); - if (!aor) { + if (!(*aor)) { continue; } - contact = ast_sip_location_retrieve_first_aor_contact(aor); + *contact = ast_sip_location_retrieve_first_aor_contact(*aor); /* If a valid contact is available use its URI for dialing */ - if (contact) { + if (*contact) { break; } + + ao2_ref(*aor, -1); + *aor = NULL; } +} + +struct ast_sip_contact *ast_sip_location_retrieve_contact_from_aor_list(const char *aor_list) +{ + struct ast_sip_aor *aor; + struct ast_sip_contact *contact; + + ast_sip_location_retrieve_contact_and_aor_from_list(aor_list, &aor, &contact); + + ao2_cleanup(aor); return contact; } diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c index 46973ad29..606097700 100644 --- a/res/res_pjsip_session.c +++ b/res/res_pjsip_session.c @@ -956,6 +956,7 @@ static void session_destructor(void *obj) } ast_party_id_free(&session->id); ao2_cleanup(session->endpoint); + ao2_cleanup(session->aor); ao2_cleanup(session->contact); ao2_cleanup(session->req_caps); ao2_cleanup(session->direct_media_cap); @@ -1213,6 +1214,7 @@ struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint struct ast_format_cap *req_caps) { const char *uri = NULL; + RAII_VAR(struct ast_sip_aor *, found_aor, NULL, ao2_cleanup); RAII_VAR(struct ast_sip_contact *, found_contact, NULL, ao2_cleanup); pjsip_timer_setting timer; pjsip_dialog *dlg; @@ -1223,7 +1225,7 @@ struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint if (location || !contact) { location = S_OR(location, endpoint->aors); - found_contact = ast_sip_location_retrieve_contact_from_aor_list(location); + ast_sip_location_retrieve_contact_and_aor_from_list(location, &found_aor, &found_contact); if (!found_contact || ast_strlen_zero(found_contact->uri)) { uri = location; } else { @@ -1264,6 +1266,7 @@ struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint pjsip_inv_terminate(inv_session, 500, PJ_FALSE); return NULL; } + session->aor = ao2_bump(found_aor); ast_party_id_copy(&session->id, &endpoint->id.self); if (ast_format_cap_count(req_caps)) { |