TT#71906 sca: clang-format

* refresh sca patches
* add more debug for PAI

Change-Id: I9abaa6e403bbe3fab8c37ac07385a92ec7070f76
changes/03/40903/2
Victor Seva 6 years ago
parent c9cf5bacf8
commit 99ac7fbbbc

@ -25,6 +25,7 @@ sipwise/tmrec-ical.patch
sipwise/registrar_add_path.patch sipwise/registrar_add_path.patch
sipwise/switch_from_python2_to_python3.patch sipwise/switch_from_python2_to_python3.patch
## SCA Patches ## SCA Patches
upstream/sca-clang-format-code.patch
sipwise/sca-line-seize.patch sipwise/sca-line-seize.patch
sipwise/sca-fallback-if-no-contact.patch sipwise/sca-fallback-if-no-contact.patch
sipwise/sca-call-info-unsubscribe.patch sipwise/sca-call-info-unsubscribe.patch

@ -3,72 +3,74 @@ Date: Thu, 26 Mar 2020 10:06:46 +0100
Subject: sca-call-info-unsubscribe Subject: sca-call-info-unsubscribe
--- ---
src/modules/sca/sca_subscribe.c | 26 ++++++++++++++++++++++++-- src/modules/sca/sca_subscribe.c | 28 ++++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-) 1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/src/modules/sca/sca_subscribe.c b/src/modules/sca/sca_subscribe.c diff --git a/src/modules/sca/sca_subscribe.c b/src/modules/sca/sca_subscribe.c
index d568729..6fd6e52 100644 index 6d7eb03..5a31a8e 100644
--- a/src/modules/sca/sca_subscribe.c --- a/src/modules/sca/sca_subscribe.c
+++ b/src/modules/sca/sca_subscribe.c +++ b/src/modules/sca/sca_subscribe.c
@@ -1137,6 +1137,8 @@ int ki_sca_handle_subscribe(sip_msg_t *msg, str *uri_to, str *uri_from) @@ -1154,6 +1154,8 @@ int ki_sca_handle_subscribe(sip_msg_t *msg, str *uri_to, str *uri_from)
int released = 0; int released = 0;
int_str val; int_str val;
struct to_body *tmp_to; struct to_body *tmp_to;
+ sca_hash_slot *slot = NULL; + sca_hash_slot *slot = NULL;
+ sca_hash_entry *ent = NULL; + sca_hash_entry *ent = NULL;
if (parse_headers(msg, HDR_EOH_F, 0) < 0) { if(parse_headers(msg, HDR_EOH_F, 0) < 0) {
LM_ERR("header parsing failed: bad request\n"); LM_ERR("header parsing failed: bad request\n");
@@ -1223,12 +1225,17 @@ int ki_sca_handle_subscribe(sip_msg_t *msg, str *uri_to, str *uri_from) @@ -1245,12 +1247,17 @@ int ki_sca_handle_subscribe(sip_msg_t *msg, str *uri_to, str *uri_from)
} }
} }
+ slot = sca_hash_table_slot_for_index(sca->subscriptions, idx); + slot = sca_hash_table_slot_for_index(sca->subscriptions, idx);
sca_hash_table_lock_index(sca->subscriptions, idx); sca_hash_table_lock_index(sca->subscriptions, idx);
- sub = sca_hash_table_index_kv_find_unsafe(sca->subscriptions, idx, - sub = sca_hash_table_index_kv_find_unsafe(
- &req_sub.subscriber); - sca->subscriptions, idx, &req_sub.subscriber);
+ ent = sca_hash_table_slot_kv_find_entry_unsafe( slot, &req_sub.subscriber ); + ent = sca_hash_table_slot_kv_find_entry_unsafe(slot, &req_sub.subscriber);
+ if (ent!=NULL) { + if(ent != NULL) {
+ sub = (sca_subscription *)ent->value; + sub = (sca_subscription *)ent->value;
+ } + }
if (sub != NULL) { if(sub != NULL) {
+ LM_DBG("sca_handle_subscribe: subscription[%.*s] found\n", + LM_DBG("sca_handle_subscribe: subscription[%.*s] found\n",
+ STR_FMT(&req_sub.subscriber)); + STR_FMT(&req_sub.subscriber));
// this will remove the subscription if expires == 0 // this will remove the subscription if expires == 0
if (sca_subscription_update_unsafe(sca, sub, &req_sub, idx) < 0) { if(sca_subscription_update_unsafe(sca, sub, &req_sub, idx) < 0) {
SCA_SUB_REPLY_ERROR(sca, 500, "Internal Server Error - " SCA_SUB_REPLY_ERROR(sca, 500,
@@ -1278,10 +1285,24 @@ int ki_sca_handle_subscribe(sip_msg_t *msg, str *uri_to, str *uri_from) @@ -1307,10 +1314,25 @@ int ki_sca_handle_subscribe(sip_msg_t *msg, str *uri_to, str *uri_from)
LM_INFO("sca_handle_subscribe: released %d appearances " LM_INFO("sca_handle_subscribe: released %d appearances "
"for subscriber %.*s\n", released, "for subscriber %.*s\n",
STR_FMT(&req_sub.subscriber)); released, STR_FMT(&req_sub.subscriber));
+ } else { + } else {
+ LM_DBG("sca_handle_subscribe: subscriber[%.*s] doesn't " + LM_DBG("sca_handle_subscribe: subscriber[%.*s] doesn't "
+ "own any active appearances using target[%.*s]\n", + "own any active appearances using target[%.*s]\n",
+ STR_FMT(&req_sub.subscriber), + STR_FMT(&req_sub.subscriber),
+ STR_FMT(&req_sub.target_aor)); + STR_FMT(&req_sub.target_aor));
} }
} }
+ if( req_sub.expires == 0 ) { + if(req_sub.expires == 0) {
+ ent = sca_hash_table_slot_unlink_entry_unsafe(slot, ent); + ent = sca_hash_table_slot_unlink_entry_unsafe(slot, ent);
+ sub->expires = 0; + sub->expires = 0;
+ sub->dialog.notify_cseq += 1; + sub->dialog.notify_cseq += 1;
+ sub->state = SCA_SUBSCRIPTION_STATE_TERMINATED; + sub->state = SCA_SUBSCRIPTION_STATE_TERMINATED;
+ if(ent) sca_hash_entry_free(ent); + if(ent)
+ sca_hash_entry_free(ent);
+ } + }
} }
} else { } else {
+ LM_DBG("sca_handle_subscribe: subscription[%.*s] not found\n", + LM_DBG("sca_handle_subscribe: subscription[%.*s] not found\n",
+ STR_FMT(&req_sub.subscriber)); + STR_FMT(&req_sub.subscriber));
// in-dialog request, but we didn't find it. // in-dialog request, but we didn't find it.
if (!SCA_STR_EMPTY(to_tag)) { if(!SCA_STR_EMPTY(to_tag)) {
SCA_SUB_REPLY_ERROR(sca, 481, "Call Leg/Transaction Does Not Exist", SCA_SUB_REPLY_ERROR(
@@ -1315,6 +1336,7 @@ int ki_sca_handle_subscribe(sip_msg_t *msg, str *uri_to, str *uri_from) @@ -1349,6 +1371,8 @@ int ki_sca_handle_subscribe(sip_msg_t *msg, str *uri_to, str *uri_from)
// we got an in-dialog SUBSCRIBE with an "Expires: 0" header, // we got an in-dialog SUBSCRIBE with an "Expires: 0" header,
// but the dialog wasn't in our table. just reply with the // but the dialog wasn't in our table. just reply with the
// subscription info we got, without saving or creating anything. // subscription info we got, without saving or creating anything.
+ LM_DBG("sca_handle_subscribe: expires=0 in-dialog but dialog not found\n"); + LM_DBG("sca_handle_subscribe: expires=0 in-dialog but dialog not "
+ "found\n");
sub = &req_sub; sub = &req_sub;
} }
} }

@ -3,104 +3,127 @@ Date: Thu, 26 Mar 2020 10:06:46 +0100
Subject: sca-debug Subject: sca-debug
--- ---
src/modules/sca/sca_appearance.c | 6 ++++++ src/modules/sca/sca_appearance.c | 11 ++++++++++-
src/modules/sca/sca_call_info.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/modules/sca/sca_call_info.c | 39 +++++++++++++++++++++++++++++++++++++++
src/modules/sca/sca_dialog.c | 10 ++++++++++ src/modules/sca/sca_dialog.c | 10 ++++++++++
3 files changed, 56 insertions(+) 3 files changed, 59 insertions(+), 1 deletion(-)
diff --git a/src/modules/sca/sca_appearance.c b/src/modules/sca/sca_appearance.c diff --git a/src/modules/sca/sca_appearance.c b/src/modules/sca/sca_appearance.c
index 9d94890..b675262 100644 index 78ee5d8..dca2421 100644
--- a/src/modules/sca/sca_appearance.c --- a/src/modules/sca/sca_appearance.c
+++ b/src/modules/sca/sca_appearance.c +++ b/src/modules/sca/sca_appearance.c
@@ -1144,7 +1144,12 @@ sca_appearance *sca_appearance_for_dialog_unsafe(sca_mod *scam, str *aor, @@ -911,8 +911,10 @@ int sca_appearance_update_index(sca_mod *scam, str *aor, int idx, int state,
rc = SCA_APPEARANCE_ERR_NOT_IN_USE;
goto done;
}
-
+ LM_DBG("search for index[%d] dialog.id[%.*s]\n", idx, STR_FMT(&dialog->id));
for(app = app_list->appearances; app != NULL; app = app->next) {
+ LM_DBG("app.index[%d] app.dialog.id[%.*s]\n", app->index,
+ STR_FMT(&app->dialog.id));
if(app->index == idx) {
break;
} else if(idx == 0) {
@@ -1157,7 +1159,12 @@ sca_appearance *sca_appearance_for_dialog_unsafe(
return (NULL); return (NULL);
} }
+ LM_DBG("search for call_id[%.*s] from_tag[%.*s]\n", + LM_DBG("search for call_id[%.*s] from_tag[%.*s]\n",
+ STR_FMT(&dialog->call_id), STR_FMT(&dialog->from_tag)); + STR_FMT(&dialog->call_id), STR_FMT(&dialog->from_tag));
for (app = app_list->appearances; app != NULL; app = app->next) { for(app = app_list->appearances; app != NULL; app = app->next) {
+ LM_DBG("app.call_id[%.*s] app.from_tag[%.*s] app.to_tag[%.*s]\n", + LM_DBG("app.call_id[%.*s] app.from_tag[%.*s] app.to_tag[%.*s]\n",
+ STR_FMT(&app->dialog.call_id), STR_FMT(&app->dialog.from_tag), + STR_FMT(&app->dialog.call_id), STR_FMT(&app->dialog.from_tag),
+ STR_FMT(&app->dialog.to_tag)); + STR_FMT(&app->dialog.to_tag));
if (SCA_STR_EQ(&app->dialog.call_id, &dialog->call_id) && if(SCA_STR_EQ(&app->dialog.call_id, &dialog->call_id)
SCA_STR_EQ(&app->dialog.from_tag, &dialog->from_tag)) { && SCA_STR_EQ(&app->dialog.from_tag, &dialog->from_tag)) {
#ifdef notdef #ifdef notdef
@@ -1154,6 +1159,7 @@ sca_appearance *sca_appearance_for_dialog_unsafe(sca_mod *scam, str *aor, @@ -1167,6 +1174,8 @@ sca_appearance *sca_appearance_for_dialog_unsafe(
continue; continue;
} }
#endif // notdef #endif // notdef
+ LM_DBG("%.*s appearance-index %d found\n", STR_FMT(aor), app->index); + LM_DBG("%.*s appearance-index %d found\n", STR_FMT(aor),
+ app->index);
break; break;
} }
} }
diff --git a/src/modules/sca/sca_call_info.c b/src/modules/sca/sca_call_info.c diff --git a/src/modules/sca/sca_call_info.c b/src/modules/sca/sca_call_info.c
index da8e6d3..bb96374 100644 index b5b2a86..e8fccf2 100644
--- a/src/modules/sca/sca_call_info.c --- a/src/modules/sca/sca_call_info.c
+++ b/src/modules/sca/sca_call_info.c +++ b/src/modules/sca/sca_call_info.c
@@ -940,6 +940,7 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg, @@ -965,6 +965,8 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg,
if (!upstream && !SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) { if(!upstream && !SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) {
// caller isn't SCA, no more to do. update callee in reply handler. // caller isn't SCA, no more to do. update callee in reply handler.
+ LM_DBG("caller isn't SCA, no more to do. update callee in reply handler\n"); + LM_DBG("caller isn't SCA, no more to do. update callee in reply "
+ "handler\n");
rc = 1; rc = 1;
goto done; goto done;
} }
@@ -955,6 +956,7 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg, @@ -982,6 +984,7 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg,
} }
if (sca_call_is_held(msg)) { if(sca_call_is_held(msg)) {
+ LM_DBG("call_is_held\n"); + LM_DBG("call_is_held\n");
state = SCA_APPEARANCE_STATE_HELD; state = SCA_APPEARANCE_STATE_HELD;
if (call_info->state == SCA_APPEARANCE_STATE_HELD_PRIVATE) { if(call_info->state == SCA_APPEARANCE_STATE_HELD_PRIVATE) {
state = SCA_APPEARANCE_STATE_HELD_PRIVATE; state = SCA_APPEARANCE_STATE_HELD_PRIVATE;
@@ -963,13 +965,17 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg, @@ -990,13 +993,17 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg,
} }
} else if (!SCA_STR_EMPTY(&to->tag_value)) { } else if(!SCA_STR_EMPTY(&to->tag_value)) {
// this is a reINVITE from an SCA line that put the call on hold // this is a reINVITE from an SCA line that put the call on hold
+ LM_DBG("reINVITE from an SCA line that put the call on hold\n"); + LM_DBG("reINVITE from an SCA line that put the call on hold\n");
state = SCA_APPEARANCE_STATE_ACTIVE; state = SCA_APPEARANCE_STATE_ACTIVE;
} else if (sca_call_info_is_line_seize_reinvite(msg, call_info, from, to, } else if(sca_call_info_is_line_seize_reinvite(
from_aor, to_aor)) { msg, call_info, from, to, from_aor, to_aor)) {
+ LM_DBG("line_seize_reinvite\n"); + LM_DBG("line_seize_reinvite\n");
rc = sca_call_info_seize_held_call(msg, call_info, from, to, from_aor, rc = sca_call_info_seize_held_call(
to_aor, contact_uri); msg, call_info, from, to, from_aor, to_aor, contact_uri);
if (rc <= 0) { if(rc <= 0) {
goto done; goto done;
+ } else { + } else {
+ LM_DBG("Initial INVITE\n"); + LM_DBG("Initial INVITE\n");
} }
} }
@@ -1177,11 +1183,19 @@ static int sca_call_info_invite_reply_200_handler(sip_msg_t *msg, @@ -1169,6 +1176,8 @@ static int sca_call_info_insert_asserted_identity(
memcpy(hdr.s + hdr.len, CRLF, CRLF_LEN);
hdr.len += CRLF_LEN;
+ LM_DBG("hdr[%.*s](%d) display[%.*s](%d) aor[%.*s](%d)\n", STR_FMT(&hdr),
+ hdr.len, STR_FMT(display), display->len, STR_FMT(&aor), aor.len);
// append the PAI header before the sdp body
if(insert_new_lump_before(anchor, hdr.s, hdr.len, HDR_PAI_T) == NULL) {
LM_ERR("Failed to add PAI header %.*s\n", STR_FMT(&hdr));
@@ -1210,11 +1219,19 @@ static int sca_call_info_invite_reply_200_handler(sip_msg_t *msg,
if (SCA_CALL_INFO_IS_SHARED_CALLEE(call_info) && if(SCA_CALL_INFO_IS_SHARED_CALLEE(call_info)
(!SCA_STR_EQ(from_aor, to_aor))) { && (!SCA_STR_EQ(from_aor, to_aor))) {
+ LM_DBG("SCA_CALL_INFO_IS_SHARED_CALLEE\n"); + LM_DBG("SCA_CALL_INFO_IS_SHARED_CALLEE\n");
+ if(sca->rr_api->is_direction(msg, RR_FLOW_DOWNSTREAM)==0) { + if(sca->rr_api->is_direction(msg, RR_FLOW_DOWNSTREAM) == 0) {
+ LM_DBG("downstream detected\n"); + LM_DBG("downstream detected\n");
+ } + }
+ if(sca->rr_api->is_direction(msg, RR_FLOW_UPSTREAM)==0) { + if(sca->rr_api->is_direction(msg, RR_FLOW_UPSTREAM) == 0) {
+ LM_DBG("upstream detected\n"); + LM_DBG("upstream detected\n");
+ } + }
rc = sca_call_info_uri_update(to_aor, call_info, from, to, contact_uri, rc = sca_call_info_uri_update(
&msg->callid->body); to_aor, call_info, from, to, contact_uri, &msg->callid->body);
} }
if (!SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) { if(!SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) {
+ LM_DBG("NOT SCA_CALL_INFO_IS_SHARED_CALLER\n"); + LM_DBG("NOT SCA_CALL_INFO_IS_SHARED_CALLER\n");
goto done; goto done;
} }
@@ -1208,6 +1222,8 @@ static int sca_call_info_invite_reply_200_handler(sip_msg_t *msg, @@ -1242,6 +1259,8 @@ static int sca_call_info_invite_reply_200_handler(sip_msg_t *msg,
&from->tag_value, NULL, slot_idx); &from->tag_value, NULL, slot_idx);
if (app == NULL) { if(app == NULL) {
// no SCA line is involved with this call // no SCA line is involved with this call
+ LM_DBG("no SCA line is involved with this call[%.*s]\n", + LM_DBG("no SCA line is involved with this call[%.*s]\n",
+ STR_FMT(from_aor)); + STR_FMT(from_aor));
rc = 1; rc = 1;
goto done; goto done;
} }
@@ -1372,6 +1388,8 @@ void sca_call_info_ack_from_handler(sip_msg_t *msg, str *from_aor, str *to_aor) @@ -1414,6 +1433,8 @@ void sca_call_info_ack_from_handler(sip_msg_t *msg, str *from_aor, str *to_aor)
sca_appearance_update_state_unsafe(app, state); sca_appearance_update_state_unsafe(app, state);
// can't send NOTIFYs until we unlock the slot below // can't send NOTIFYs until we unlock the slot below
} }
@ -108,90 +131,86 @@ index da8e6d3..bb96374 100644
+ LM_DBG("from_aor[%.*s] not shared appearance\n", STR_FMT(from_aor)); + LM_DBG("from_aor[%.*s] not shared appearance\n", STR_FMT(from_aor));
} }
done: if (slot_idx >= 0) { done:
@@ -1518,7 +1536,11 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info, @@ -1564,7 +1585,11 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info,
str *tag = NULL; str *tag = NULL;
if (msg->first_line.type == SIP_REQUEST) { if(msg->first_line.type == SIP_REQUEST) {
+ LM_DBG("SIP_REQUEST\n"); + LM_DBG("SIP_REQUEST\n");
if (SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) { if(SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) {
+ LM_DBG("SCA_CALL_INFO_IS_SHARED_CALLER " + LM_DBG("SCA_CALL_INFO_IS_SHARED_CALLER "
+ "from_aor[%.*s] to_aor[%.*s]\n", + "from_aor[%.*s] to_aor[%.*s]\n",
+ STR_FMT(from_aor), STR_FMT(to_aor)); + STR_FMT(from_aor), STR_FMT(to_aor));
slot_idx = sca_uri_lock_shared_appearance(sca, from_aor); slot_idx = sca_uri_lock_shared_appearance(sca, from_aor);
if (slot_idx < 0) { if(slot_idx < 0) {
LM_ERR("sca_call_info_bye_handler: failed to acquire " LM_ERR("sca_call_info_bye_handler: failed to acquire "
@@ -1572,6 +1594,10 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info, @@ -1618,6 +1643,10 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info,
goto done; goto done;
} }
} }
+ } else { + } else {
+ LM_DBG("NOT SCA_CALL_INFO_IS_SHARED_CALLER " + LM_DBG("NOT SCA_CALL_INFO_IS_SHARED_CALLER "
+ "from_aor[%.*s] to_aor[%.*s]\n", + "from_aor[%.*s] to_aor[%.*s]\n",
+ STR_FMT(from_aor), STR_FMT(to_aor)); + STR_FMT(from_aor), STR_FMT(to_aor));
} }
if (slot_idx >= 0) { if(slot_idx >= 0) {
@@ -1627,6 +1653,7 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info, @@ -1673,6 +1702,7 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info,
} }
} }
} else { } else {
+ LM_DBG("SIP_REPLY\n"); + LM_DBG("SIP_REPLY\n");
// this is just a backup to catch anything missed on the BYE request // this is just a backup to catch anything missed on the BYE request
if (SCA_CALL_INFO_IS_SHARED_CALLEE(call_info)) { if(SCA_CALL_INFO_IS_SHARED_CALLEE(call_info)) {
slot_idx = sca_hash_table_index_for_key(sca->appearances, to_aor); slot_idx = sca_hash_table_index_for_key(sca->appearances, to_aor);
@@ -1994,28 +2021,41 @@ int sca_call_info_update(sip_msg_t *msg, int update_mask, str *uri_to, @@ -2046,28 +2076,37 @@ int sca_call_info_update(
if (sca_uri_is_shared_appearance(sca, &from_aor)) { if(sca_uri_is_shared_appearance(sca, &from_aor)) {
if ((update_mask & SCA_CALL_INFO_SHARED_CALLER)) { if((update_mask & SCA_CALL_INFO_SHARED_CALLER)) {
call_info.ua_shared |= SCA_CALL_INFO_SHARED_CALLER; call_info.ua_shared |= SCA_CALL_INFO_SHARED_CALLER;
+ LM_DBG("SCA_CALL_INFO_SHARED_CALLER[%.*s]\n", + LM_DBG("SCA_CALL_INFO_SHARED_CALLER[%.*s]\n", STR_FMT(&from_aor));
+ STR_FMT(&from_aor));
} }
} }
if (sca_uri_is_shared_appearance(sca, &to_aor)) { if(sca_uri_is_shared_appearance(sca, &to_aor)) {
if ((update_mask & SCA_CALL_INFO_SHARED_CALLEE)) { if((update_mask & SCA_CALL_INFO_SHARED_CALLEE)) {
call_info.ua_shared |= SCA_CALL_INFO_SHARED_CALLEE; call_info.ua_shared |= SCA_CALL_INFO_SHARED_CALLEE;
+ LM_DBG("SCA_CALL_INFO_SHARED_CALLEE[%.*s]\n", + LM_DBG("SCA_CALL_INFO_SHARED_CALLEE[%.*s]\n", STR_FMT(&to_aor));
+ STR_FMT(&to_aor));
} }
} }
if (call_info_hdr == NULL) { if(call_info_hdr == NULL) {
+ LM_DBG("call_info_hdr is NULL\n"); + LM_DBG("call_info_hdr is NULL\n");
if (SCA_CALL_INFO_IS_SHARED_CALLER(&call_info) && if(SCA_CALL_INFO_IS_SHARED_CALLER(&call_info)
msg->first_line.type == SIP_REQUEST) { && msg->first_line.type == SIP_REQUEST) {
+ LM_DBG("SCA_CALL_INFO_IS_SHARED_CALLER && SIP_REQUEST\n"); + LM_DBG("SCA_CALL_INFO_IS_SHARED_CALLER && SIP_REQUEST\n");
if (!sca_subscription_aor_has_subscribers(SCA_EVENT_TYPE_CALL_INFO, if(!sca_subscription_aor_has_subscribers(
&from_aor)) { SCA_EVENT_TYPE_CALL_INFO, &from_aor)) {
call_info.ua_shared &= ~SCA_CALL_INFO_SHARED_CALLER; call_info.ua_shared &= ~SCA_CALL_INFO_SHARED_CALLER;
sca_appearance_unregister(sca, &from_aor); sca_appearance_unregister(sca, &from_aor);
+ } else { + } else {
+ LM_DBG("from_aor[%.*s] has subscribers\n", + LM_DBG("from_aor[%.*s] has subscribers\n", STR_FMT(&from_aor));
+ STR_FMT(&from_aor));
} }
} else if (SCA_CALL_INFO_IS_SHARED_CALLEE(&call_info) && } else if(SCA_CALL_INFO_IS_SHARED_CALLEE(&call_info)
msg->first_line.type == SIP_REPLY) { && msg->first_line.type == SIP_REPLY) {
+ LM_DBG("SCA_CALL_INFO_IS_SHARED_CALLEE && SIP_REPLY\n"); + LM_DBG("SCA_CALL_INFO_IS_SHARED_CALLEE && SIP_REPLY\n");
if (!sca_subscription_aor_has_subscribers(SCA_EVENT_TYPE_CALL_INFO, if(!sca_subscription_aor_has_subscribers(
&to_aor)) { SCA_EVENT_TYPE_CALL_INFO, &to_aor)) {
call_info.ua_shared &= ~SCA_CALL_INFO_SHARED_CALLEE; call_info.ua_shared &= ~SCA_CALL_INFO_SHARED_CALLEE;
sca_appearance_unregister(sca, &to_aor); sca_appearance_unregister(sca, &to_aor);
+ } else { + } else {
+ LM_DBG("to_aor[%.*s] has subscribers\n", + LM_DBG("to_aor[%.*s] has subscribers\n", STR_FMT(&from_aor));
+ STR_FMT(&from_aor));
} }
} }
} }
diff --git a/src/modules/sca/sca_dialog.c b/src/modules/sca/sca_dialog.c diff --git a/src/modules/sca/sca_dialog.c b/src/modules/sca/sca_dialog.c
index a5e6924..e855743 100644 index 1076caa..0314159 100644
--- a/src/modules/sca/sca_dialog.c --- a/src/modules/sca/sca_dialog.c
+++ b/src/modules/sca/sca_dialog.c +++ b/src/modules/sca/sca_dialog.c
@@ -45,6 +45,9 @@ int sca_dialog_build_from_tags(sca_dialog *dialog, int maxlen, str *call_id, @@ -45,6 +45,9 @@ int sca_dialog_build_from_tags(sca_dialog *dialog, int maxlen, str *call_id,
return (-1); return (-1);
} }
+ LM_DBG("call-id:%.*s from_tag:%.*s to_tag:%.*s\n", + LM_DBG("call-id:%.*s from_tag:%.*s to_tag:%.*s\n", STR_FMT(call_id),
+ STR_FMT(call_id), STR_FMT(from_tag), STR_FMT(to_tag)); + STR_FMT(from_tag), STR_FMT(to_tag));
+ +
memcpy(dialog->id.s, call_id->s, call_id->len); memcpy(dialog->id.s, call_id->s, call_id->len);
dialog->call_id.s = dialog->id.s; dialog->call_id.s = dialog->id.s;
@ -207,8 +226,8 @@ index a5e6924..e855743 100644
dialog->id.len = len; dialog->id.len = len;
+ LM_DBG("id:%.*s call-id:%.*s from_tag:%.*s to_tag:%.*s\n", + LM_DBG("id:%.*s call-id:%.*s from_tag:%.*s to_tag:%.*s\n",
+ STR_FMT(&dialog->id), STR_FMT(&dialog->call_id), + STR_FMT(&dialog->id), STR_FMT(&dialog->call_id),
+ STR_FMT(&dialog->from_tag), STR_FMT(&dialog->to_tag)); + STR_FMT(&dialog->from_tag), STR_FMT(&dialog->to_tag));
+ +
return (len); return (len);
} }

@ -7,30 +7,30 @@ Subject: sca-fallback-if-no-contact
1 file changed, 7 insertions(+), 3 deletions(-) 1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/modules/sca/sca_call_info.c b/src/modules/sca/sca_call_info.c diff --git a/src/modules/sca/sca_call_info.c b/src/modules/sca/sca_call_info.c
index 4ae93f9..8b940c3 100644 index 867421b..a173294 100644
--- a/src/modules/sca/sca_call_info.c --- a/src/modules/sca/sca_call_info.c
+++ b/src/modules/sca/sca_call_info.c +++ b/src/modules/sca/sca_call_info.c
@@ -1891,9 +1891,6 @@ int sca_call_info_update(sip_msg_t *msg, int update_mask, str *uri_to, @@ -1944,9 +1944,6 @@ int sca_call_info_update(
rc = -1; rc = -1;
goto done; goto done;
} }
- } else if (rc < 0) { - } else if(rc < 0) {
- LM_ERR("Bad Contact\n"); - LM_ERR("Bad Contact\n");
- goto done; - goto done;
} }
// reset rc to -1 so we don't end up returning 0 to the script // reset rc to -1 so we don't end up returning 0 to the script
rc = -1; rc = -1;
@@ -1940,6 +1937,13 @@ int sca_call_info_update(sip_msg_t *msg, int update_mask, str *uri_to, @@ -1992,6 +1989,13 @@ int sca_call_info_update(
LM_DBG("to_aor[%.*s] from_aor[%.*s]\n", LM_DBG("to_aor[%.*s] from_aor[%.*s]\n", STR_FMT(&to_aor),
STR_FMT(&to_aor), STR_FMT(&from_aor)); STR_FMT(&from_aor));
+ if(contact_uri.s==NULL) { + if(contact_uri.s == NULL) {
+ contact_uri.s = "sip:127.0.0.1:5085;transport=udp"; + contact_uri.s = "sip:127.0.0.1:5085;transport=udp";
+ contact_uri.len = strlen(contact_uri.s); + contact_uri.len = strlen(contact_uri.s);
+ LM_DBG("No Contact header, using default owner[%.*s]\n", + LM_DBG("No Contact header, using default owner[%.*s]\n",
+ STR_FMT(&contact_uri)); + STR_FMT(&contact_uri));
+ } + }
+ +
// early check to see if we're dealing with any SCA endpoints // early check to see if we're dealing with any SCA endpoints
if (sca_uri_is_shared_appearance(sca, &from_aor)) { if(sca_uri_is_shared_appearance(sca, &from_aor)) {
if ((update_mask & SCA_CALL_INFO_SHARED_CALLER)) { if((update_mask & SCA_CALL_INFO_SHARED_CALLER)) {

@ -7,24 +7,24 @@ Subject: sca-fix-memleaks
1 file changed, 4 insertions(+) 1 file changed, 4 insertions(+)
diff --git a/src/modules/sca/sca_util.c b/src/modules/sca/sca_util.c diff --git a/src/modules/sca/sca_util.c b/src/modules/sca/sca_util.c
index 46d04c5..65a5a26 100644 index e1ef561..9fa64ca 100644
--- a/src/modules/sca/sca_util.c --- a/src/modules/sca/sca_util.c
+++ b/src/modules/sca/sca_util.c +++ b/src/modules/sca/sca_util.c
@@ -178,6 +178,8 @@ int sca_get_msg_from_header( sip_msg_t *msg, struct to_body **from ) { @@ -180,6 +180,8 @@ int sca_get_msg_from_header(sip_msg_t *msg, struct to_body **from)
} else { } else {
LM_DBG("using $avp(%.*s)[%.*s] as from uri\n", LM_DBG("using $avp(%.*s)[%.*s] as from uri\n", STR_FMT(&from_uri_avp.s),
STR_FMT(&from_uri_avp.s), STR_FMT(&uri)); STR_FMT(&uri));
+ free_to_params(&sf); + free_to_params(&sf);
+ memset(&sf, 0, sizeof(sf)); + memset(&sf, 0, sizeof(sf));
if(sca_parse_uri(&sf, &uri)<0) return -1; if(sca_parse_uri(&sf, &uri) < 0)
return -1;
*from = &sf; *from = &sf;
} @@ -224,6 +226,8 @@ int sca_get_msg_to_header(sip_msg_t *msg, struct to_body **to)
@@ -220,6 +222,8 @@ int sca_get_msg_to_header(sip_msg_t *msg, struct to_body **to)
} else { } else {
LM_DBG("using $avp(%.*s)[%.*s] as to uri\n", LM_DBG("using $avp(%.*s)[%.*s] as to uri\n", STR_FMT(&to_uri_avp.s),
STR_FMT(&to_uri_avp.s), STR_FMT(&uri)); STR_FMT(&uri));
+ free_to_params(&parsed_to); + free_to_params(&parsed_to);
+ memset(&parsed_to, 0, sizeof(parsed_to)); + memset(&parsed_to, 0, sizeof(parsed_to));
if(sca_parse_uri(&parsed_to, &uri)<0) return -1; if(sca_parse_uri(&parsed_to, &uri) < 0)
return -1;
*to = &parsed_to; *to = &parsed_to;
}

@ -2,24 +2,20 @@ From: Sipwise Development Team <support@sipwise.com>
Date: Thu, 26 Mar 2020 10:06:46 +0100 Date: Thu, 26 Mar 2020 10:06:46 +0100
Subject: sca-fix-notify-after-bye Subject: sca-fix-notify-after-bye
# Revert of upstream commit 57c4ec824fdd6c6c797bd7d6bfb3d65159a8d7c6
# sca: reversed the from_tag and to_tag variables in the function call
--- ---
src/modules/sca/sca_call_info.c | 4 ++-- src/modules/sca/sca_call_info.c | 2 +-
1 file changed, 2 insertions(+), 2 deletions(-) 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/modules/sca/sca_call_info.c b/src/modules/sca/sca_call_info.c diff --git a/src/modules/sca/sca_call_info.c b/src/modules/sca/sca_call_info.c
index bb96374..c35c4ed 100644 index e8fccf2..42710a1 100644
--- a/src/modules/sca/sca_call_info.c --- a/src/modules/sca/sca_call_info.c
+++ b/src/modules/sca/sca_call_info.c +++ b/src/modules/sca/sca_call_info.c
@@ -704,8 +704,8 @@ static int sca_call_info_uri_update(str *aor, sca_call_info *call_info, @@ -714,7 +714,7 @@ static int sca_call_info_uri_update(str *aor, sca_call_info *call_info,
}
dialog.id.s = dlg_buf; dialog.id.s = dlg_buf;
- if (sca_dialog_build_from_tags(&dialog, sizeof(dlg_buf), call_id, from_tag, if(sca_dialog_build_from_tags(
- to_tag) < 0) { - &dialog, sizeof(dlg_buf), call_id, from_tag, to_tag)
+ if (sca_dialog_build_from_tags(&dialog, sizeof(dlg_buf), call_id, to_tag, + &dialog, sizeof(dlg_buf), call_id, to_tag, from_tag)
+ from_tag) < 0) { < 0) {
LM_ERR("sca_call_info_uri_update: Failed to build dialog from tags\n"); LM_ERR("sca_call_info_uri_update: Failed to build dialog from tags\n");
return (-1); return (-1);
}

@ -3,35 +3,33 @@ Date: Thu, 26 Mar 2020 10:06:46 +0100
Subject: sca-fix-on-hold-detection-when-upstream-flow Subject: sca-fix-on-hold-detection-when-upstream-flow
--- ---
src/modules/sca/sca_call_info.c | 6 ++++-- src/modules/sca/sca_call_info.c | 4 +++-
1 file changed, 4 insertions(+), 2 deletions(-) 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/modules/sca/sca_call_info.c b/src/modules/sca/sca_call_info.c diff --git a/src/modules/sca/sca_call_info.c b/src/modules/sca/sca_call_info.c
index 65c21ac..da8e6d3 100644 index 0a72427..b5b2a86 100644
--- a/src/modules/sca/sca_call_info.c --- a/src/modules/sca/sca_call_info.c
+++ b/src/modules/sca/sca_call_info.c +++ b/src/modules/sca/sca_call_info.c
@@ -914,12 +914,14 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg, @@ -938,11 +938,13 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg,
str state_str = STR_NULL;
int state = SCA_APPEARANCE_STATE_UNKNOWN; int state = SCA_APPEARANCE_STATE_UNKNOWN;
int rc = -1; int rc = -1;
- str *target_aor = from_aor; str *target_aor = from_aor;
+ str *target_aor = from_aor;
+ int upstream = 0; + int upstream = 0;
if(SCA_CALL_INFO_IS_SHARED_CALLEE(call_info) && if(SCA_CALL_INFO_IS_SHARED_CALLEE(call_info)
sca->rr_api->is_direction(msg, RR_FLOW_UPSTREAM)==0) { && sca->rr_api->is_direction(msg, RR_FLOW_UPSTREAM) == 0) {
LM_DBG("callee is SCA and direction is 'upstream'\n"); LM_DBG("callee is SCA and direction is 'upstream'\n");
target_aor = to_aor; target_aor = to_aor;
+ upstream = 1; + upstream = 1;
} }
LM_DBG("For From-AOR %.*s To-AOR: %.*s: From: <%.*s> To: <%.*s> " LM_DBG("For From-AOR %.*s To-AOR: %.*s: From: <%.*s> To: <%.*s> "
@@ -936,7 +938,7 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg, @@ -961,7 +963,7 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg,
goto done; goto done;
} }
- if (!SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) { - if(!SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) {
+ if (!upstream && !SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) { + if(!upstream && !SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) {
// caller isn't SCA, no more to do. update callee in reply handler. // caller isn't SCA, no more to do. update callee in reply handler.
rc = 1; rc = 1;
goto done; goto done;

@ -7,84 +7,82 @@ Subject: sca-fix-pickup-when-upstream-flow
1 file changed, 30 insertions(+), 17 deletions(-) 1 file changed, 30 insertions(+), 17 deletions(-)
diff --git a/src/modules/sca/sca_call_info.c b/src/modules/sca/sca_call_info.c diff --git a/src/modules/sca/sca_call_info.c b/src/modules/sca/sca_call_info.c
index 0fc0cd4..65c21ac 100644 index 00a4c0e..0a72427 100644
--- a/src/modules/sca/sca_call_info.c --- a/src/modules/sca/sca_call_info.c
+++ b/src/modules/sca/sca_call_info.c +++ b/src/modules/sca/sca_call_info.c
@@ -914,6 +914,13 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg, @@ -937,6 +937,13 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg,
str state_str = STR_NULL; str state_str = STR_NULL;
int state = SCA_APPEARANCE_STATE_UNKNOWN; int state = SCA_APPEARANCE_STATE_UNKNOWN;
int rc = -1; int rc = -1;
+ str *target_aor = from_aor; + str *target_aor = from_aor;
+ +
+ if(SCA_CALL_INFO_IS_SHARED_CALLEE(call_info) && + if(SCA_CALL_INFO_IS_SHARED_CALLEE(call_info)
+ sca->rr_api->is_direction(msg, RR_FLOW_UPSTREAM)==0) { + && sca->rr_api->is_direction(msg, RR_FLOW_UPSTREAM) == 0) {
+ LM_DBG("callee is SCA and direction is 'upstream'\n"); + LM_DBG("callee is SCA and direction is 'upstream'\n");
+ target_aor = to_aor; + target_aor = to_aor;
+ } + }
LM_DBG("For From-AOR %.*s To-AOR: %.*s: From: <%.*s> To: <%.*s> " LM_DBG("For From-AOR %.*s To-AOR: %.*s: From: <%.*s> To: <%.*s> "
"Contact: <%.*s> Call-Info: appearance-index=%d\n", "Contact: <%.*s> Call-Info: appearance-index=%d\n",
@@ -925,7 +932,7 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg, @@ -950,7 +957,7 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg,
if (sca->tm_api->register_tmcb(msg, NULL, TMCB_E2EACK_IN, < 0) {
sca_call_info_ack_cb, NULL, NULL) < 0) {
LM_ERR("sca_call_info_invite_request_handler: failed to register " LM_ERR("sca_call_info_invite_request_handler: failed to register "
- "callback for INVITE %.*s ACK\n", STR_FMT(from_aor)); "callback for INVITE %.*s ACK\n",
+ "callback for INVITE %.*s ACK\n", STR_FMT(target_aor)); - STR_FMT(from_aor));
+ STR_FMT(target_aor));
goto done; goto done;
} }
@@ -941,7 +948,7 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg, @@ -968,7 +975,7 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg,
if (sca->tm_api->register_tmcb(msg, NULL, TMCB_RESPONSE_READY, < 0) {
sca_call_info_response_ready_cb, NULL, NULL) < 0) {
LM_ERR("sca_call_info_invite_request_handler: failed to register " LM_ERR("sca_call_info_invite_request_handler: failed to register "
- "callback for INVITE %.*s ACK\n", STR_FMT(from_aor)); "callback for INVITE %.*s ACK\n",
+ "callback for INVITE %.*s ACK\n", STR_FMT(target_aor)); - STR_FMT(from_aor));
+ STR_FMT(target_aor));
goto done; goto done;
} }
@@ -972,17 +979,17 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg, @@ -1001,16 +1008,16 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg,
return (-1);
} }
- if (sca_appearance_update_index(sca, from_aor, call_info->index, state, if(sca_appearance_update_index(
+ if (sca_appearance_update_index(sca, target_aor, call_info->index, state, - sca, from_aor, call_info->index, state, NULL, NULL, &dialog)
NULL, NULL, &dialog) != SCA_APPEARANCE_OK) { + sca, target_aor, call_info->index, state, NULL, NULL, &dialog)
!= SCA_APPEARANCE_OK) {
sca_appearance_state_to_str(state, &state_str); sca_appearance_state_to_str(state, &state_str);
LM_ERR("Failed to update %.*s appearance-index %d to %.*s\n", LM_ERR("Failed to update %.*s appearance-index %d to %.*s\n",
- STR_FMT(from_aor), call_info->index, - STR_FMT(from_aor), call_info->index, STR_FMT(&state_str));
+ STR_FMT(target_aor), call_info->index, + STR_FMT(target_aor), call_info->index, STR_FMT(&state_str));
STR_FMT(&state_str));
} }
- if (sca_notify_call_info_subscribers(sca, from_aor) < 0) { - if(sca_notify_call_info_subscribers(sca, from_aor) < 0) {
+ if (sca_notify_call_info_subscribers(sca, target_aor) < 0) { + if(sca_notify_call_info_subscribers(sca, target_aor) < 0) {
LM_ERR("Failed to call-info NOTIFY %.*s subscribers on INVITE\n", LM_ERR("Failed to call-info NOTIFY %.*s subscribers on INVITE\n",
- STR_FMT(from_aor)); - STR_FMT(from_aor));
+ STR_FMT(target_aor)); + STR_FMT(target_aor));
goto done; goto done;
} }
@@ -1315,6 +1322,7 @@ void sca_call_info_ack_from_handler(sip_msg_t *msg, str *from_aor, str *to_aor) @@ -1356,6 +1363,7 @@ void sca_call_info_ack_from_handler(sip_msg_t *msg, str *from_aor, str *to_aor)
str *tag; str *tag;
int slot_idx = -1; int slot_idx = -1;
int state = SCA_APPEARANCE_STATE_IDLE; int state = SCA_APPEARANCE_STATE_IDLE;
+ str *target_aor; + str *target_aor;
if (sca_get_msg_from_header(msg, &from) < 0) { if(sca_get_msg_from_header(msg, &from) < 0) {
LM_ERR("sca_call_info_ack_cb: failed to get From-header\n"); LM_ERR("sca_call_info_ack_cb: failed to get From-header\n");
@@ -1325,18 +1333,23 @@ void sca_call_info_ack_from_handler(sip_msg_t *msg, str *from_aor, str *to_aor) @@ -1366,19 +1374,24 @@ void sca_call_info_ack_from_handler(sip_msg_t *msg, str *from_aor, str *to_aor)
return; return;
} }
- if (sca_uri_lock_if_shared_appearance(sca, from_aor, &slot_idx)) { - if(sca_uri_lock_if_shared_appearance(sca, from_aor, &slot_idx)) {
- if(sca->rr_api->is_direction(msg, RR_FLOW_UPSTREAM)==0) { - if(sca->rr_api->is_direction(msg, RR_FLOW_UPSTREAM) == 0) {
- LM_DBG("upstream direction detected\n"); - LM_DBG("upstream direction detected\n");
- tag = &to->tag_value; - tag = &to->tag_value;
- } else { - } else {
- tag = &from->tag_value; - tag = &from->tag_value;
- } - }
- app = sca_appearance_for_tags_unsafe(sca, from_aor, &msg->callid->body, + if(sca->rr_api->is_direction(msg, RR_FLOW_UPSTREAM) == 0) {
+ if(sca->rr_api->is_direction(msg, RR_FLOW_UPSTREAM)==0) {
+ LM_DBG("upstream direction detected\n"); + LM_DBG("upstream direction detected\n");
+ target_aor = to_aor; + target_aor = to_aor;
+ tag = &to->tag_value; + tag = &to->tag_value;
@ -95,23 +93,26 @@ index 0fc0cd4..65c21ac 100644
+ +
+ LM_DBG("target_aor[%.*s]\n", STR_FMT(target_aor)); + LM_DBG("target_aor[%.*s]\n", STR_FMT(target_aor));
+ +
+ if (sca_uri_lock_if_shared_appearance(sca, target_aor, &slot_idx)) { + if(sca_uri_lock_if_shared_appearance(sca, target_aor, &slot_idx)) {
+ app = sca_appearance_for_tags_unsafe(sca, target_aor, &msg->callid->body, app = sca_appearance_for_tags_unsafe(
tag, NULL, slot_idx); - sca, from_aor, &msg->callid->body, tag, NULL, slot_idx);
if (app == NULL) { + sca, target_aor, &msg->callid->body, tag, NULL, slot_idx);
if(app == NULL) {
LM_ERR("sca_call_info_ack_cb: No appearance for %.*s matching " LM_ERR("sca_call_info_ack_cb: No appearance for %.*s matching "
- "call-id <%.*s> and from-tag <%.*s>\n", STR_FMT(from_aor), "call-id <%.*s> and from-tag <%.*s>\n",
+ "call-id <%.*s> and from-tag <%.*s>\n", STR_FMT(target_aor), - STR_FMT(from_aor), STR_FMT(&msg->callid->body),
STR_FMT(&msg->callid->body), STR_FMT(tag)); + STR_FMT(target_aor), STR_FMT(&msg->callid->body),
STR_FMT(tag));
goto done; goto done;
} }
@@ -1363,9 +1376,9 @@ void sca_call_info_ack_from_handler(sip_msg_t *msg, str *from_aor, str *to_aor) @@ -1406,10 +1419,10 @@ done:
sca_hash_table_unlock_index(sca->appearances, slot_idx); sca_hash_table_unlock_index(sca->appearances, slot_idx);
if (state != SCA_APPEARANCE_STATE_IDLE) { if(state != SCA_APPEARANCE_STATE_IDLE) {
- if (sca_notify_call_info_subscribers(sca, from_aor) < 0) { - if(sca_notify_call_info_subscribers(sca, from_aor) < 0) {
+ if (sca_notify_call_info_subscribers(sca, target_aor) < 0) { + if(sca_notify_call_info_subscribers(sca, target_aor) < 0) {
LM_ERR("Failed to call-info NOTIFY %.*s subscribers on INVITE\n", LM_ERR("Failed to call-info NOTIFY %.*s subscribers on "
"INVITE\n",
- STR_FMT(from_aor)); - STR_FMT(from_aor));
+ STR_FMT(target_aor)); + STR_FMT(target_aor));
} }

@ -3,21 +3,24 @@ Date: Thu, 26 Mar 2020 10:06:46 +0100
Subject: sca-line-seize Subject: sca-line-seize
--- ---
src/modules/sca/sca.c | 103 ++++++++++++++++++++++++++- src/modules/sca/sca.c | 107 ++++++++++++++++++++++++++-
src/modules/sca/sca.h | 6 ++ src/modules/sca/sca.h | 6 ++
src/modules/sca/sca_call_info.c | 77 +++++++++----------- src/modules/sca/sca_appearance.h | 2 +-
src/modules/sca/sca_subscribe.c | 56 +++++++++------ src/modules/sca/sca_call_info.c | 78 +++++++++-----------
src/modules/sca/sca_subscribe.h | 4 +- src/modules/sca/sca_call_info.h | 6 +-
src/modules/sca/sca_util.c | 153 +++++++++++++++++++++++----------------- src/modules/sca/sca_dialog.h | 2 +-
6 files changed, 263 insertions(+), 136 deletions(-) src/modules/sca/sca_subscribe.c | 61 ++++++++-------
src/modules/sca/sca_subscribe.h | 6 +-
src/modules/sca/sca_util.c | 155 +++++++++++++++++++++++----------------
9 files changed, 279 insertions(+), 144 deletions(-)
diff --git a/src/modules/sca/sca.c b/src/modules/sca/sca.c diff --git a/src/modules/sca/sca.c b/src/modules/sca/sca.c
index dba9ff0..698da84 100644 index 07dac39..c2347bb 100644
--- a/src/modules/sca/sca.c --- a/src/modules/sca/sca.c
+++ b/src/modules/sca/sca.c +++ b/src/modules/sca/sca.c
@@ -64,6 +64,12 @@ db_func_t dbf; // db api @@ -64,6 +64,12 @@ db_func_t dbf; // db api
struct tm_binds tmb; // tm functions for sending messages struct tm_binds tmb; // tm functions for sending messages
sl_api_t slb; // sl callback, function for getting to-tag sl_api_t slb; // sl callback, function for getting to-tag
+/* avps */ +/* avps */
+unsigned short from_uri_avp_type; +unsigned short from_uri_avp_type;
@ -32,30 +35,30 @@ index dba9ff0..698da84 100644
static int sca_child_init(int); static int sca_child_init(int);
static void sca_mod_destroy(void); static void sca_mod_destroy(void);
static int sca_set_config(sca_mod *); static int sca_set_config(sca_mod *);
+static int sca_handle_subscribe_0_f(sip_msg_t* msg); +static int sca_handle_subscribe_0_f(sip_msg_t *msg);
+static int sca_handle_subscribe_1_f(sip_msg_t* msg, char*); +static int sca_handle_subscribe_1_f(sip_msg_t *msg, char *);
+static int sca_handle_subscribe_2_f(sip_msg_t* msg, char*, char *); +static int sca_handle_subscribe_2_f(sip_msg_t *msg, char *, char *);
+int fixup_hs(void **, int); +int fixup_hs(void **, int);
+int fixup_free_hs(void **param, int param_no); +int fixup_free_hs(void **param, int param_no);
static int sca_call_info_update_0_f(sip_msg_t* msg, char*, char*); static int sca_call_info_update_0_f(sip_msg_t *msg, char *, char *);
static int sca_call_info_update_1_f(sip_msg_t* msg, char*, char*); static int sca_call_info_update_1_f(sip_msg_t *msg, char *, char *);
static int sca_call_info_update_2_f(sip_msg_t* msg, char*, char*); static int sca_call_info_update_2_f(sip_msg_t *msg, char *, char *);
@@ -82,8 +93,12 @@ int fixup_free_ciu(void **param, int param_no); @@ -82,8 +93,12 @@ int fixup_free_ciu(void **param, int param_no);
* EXPORTED COMMANDS * EXPORTED COMMANDS
*/ */
static cmd_export_t cmds[] = { static cmd_export_t cmds[] = {
- {"sca_handle_subscribe", (cmd_function)sca_handle_subscribe, 0, NULL, 0, - {"sca_handle_subscribe", (cmd_function)sca_handle_subscribe, 0, NULL, 0,
- REQUEST_ROUTE}, - REQUEST_ROUTE},
+ { "sca_handle_subscribe", (cmd_function)sca_handle_subscribe_0_f, 0, + {"sca_handle_subscribe", (cmd_function)sca_handle_subscribe_0_f, 0,
+ NULL, NULL, REQUEST_ROUTE }, + NULL, NULL, REQUEST_ROUTE},
+ { "sca_handle_subscribe", (cmd_function)sca_handle_subscribe_1_f, 1, + {"sca_handle_subscribe", (cmd_function)sca_handle_subscribe_1_f, 1,
+ fixup_hs, fixup_free_hs, REQUEST_ROUTE }, + fixup_hs, fixup_free_hs, REQUEST_ROUTE},
+ { "sca_handle_subscribe", (cmd_function)sca_handle_subscribe_2_f, 2, + {"sca_handle_subscribe", (cmd_function)sca_handle_subscribe_2_f, 2,
+ fixup_hs, fixup_free_hs, REQUEST_ROUTE }, + fixup_hs, fixup_free_hs, REQUEST_ROUTE},
{"sca_call_info_update", (cmd_function)sca_call_info_update_0_f, 0, NULL, 0, {"sca_call_info_update", (cmd_function)sca_call_info_update_0_f, 0,
REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE}, NULL, 0, REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE},
{"sca_call_info_update", (cmd_function)sca_call_info_update_1_f, 1, {"sca_call_info_update", (cmd_function)sca_call_info_update_1_f, 1,
@@ -139,6 +154,8 @@ int line_seize_max_expires = 15; @@ -141,6 +156,8 @@ int line_seize_max_expires = 15;
int purge_expired_interval = 120; int purge_expired_interval = 120;
int onhold_bflag = -1; int onhold_bflag = -1;
str server_address = STR_NULL; str server_address = STR_NULL;
@ -64,7 +67,7 @@ index dba9ff0..698da84 100644
static param_export_t params[] = { static param_export_t params[] = {
{"outbound_proxy", PARAM_STR, &outbound_proxy}, {"outbound_proxy", PARAM_STR, &outbound_proxy},
@@ -152,6 +169,8 @@ static param_export_t params[] = { @@ -154,6 +171,8 @@ static param_export_t params[] = {
{"purge_expired_interval", INT_PARAM, &purge_expired_interval}, {"purge_expired_interval", INT_PARAM, &purge_expired_interval},
{"onhold_bflag", INT_PARAM, &onhold_bflag}, {"onhold_bflag", INT_PARAM, &onhold_bflag},
{"server_address", PARAM_STR, &server_address}, {"server_address", PARAM_STR, &server_address},
@ -73,24 +76,25 @@ index dba9ff0..698da84 100644
{NULL, 0, NULL}, {NULL, 0, NULL},
}; };
@@ -319,6 +338,31 @@ static int sca_child_init(int rank) @@ -329,6 +348,32 @@ static int sca_child_init(int rank)
return (0); return (0);
} }
+static int +static int sca_process_avps(
+sca_process_avps(str *avp_param, int_str *avp, unsigned short *avp_type) + str *avp_param, int_str *avp, unsigned short *avp_type)
+{ +{
+ pv_spec_t *avp_spec; + pv_spec_t *avp_spec;
+ unsigned short avp_flags; + unsigned short avp_flags;
+ +
+ if (avp_param && avp_param->len > 0) { + if(avp_param && avp_param->len > 0) {
+ avp_spec = pv_cache_get(avp_param); + avp_spec = pv_cache_get(avp_param);
+ if (avp_spec==NULL|| avp_spec->type!=PVT_AVP) { + if(avp_spec == NULL || avp_spec->type != PVT_AVP) {
+ LM_ERR("malformed or non AVP definition <%.*s>\n", STR_FMT(avp_param)); + LM_ERR("malformed or non AVP definition <%.*s>\n",
+ STR_FMT(avp_param));
+ return -1; + return -1;
+ } + }
+ +
+ if (pv_get_avp_name(0, &(avp_spec->pvp), avp, &avp_flags) != 0) { + if(pv_get_avp_name(0, &(avp_spec->pvp), avp, &avp_flags) != 0) {
+ LM_ERR("invalid AVP definition <%.*s>\n", STR_FMT(avp_param)); + LM_ERR("invalid AVP definition <%.*s>\n", STR_FMT(avp_param));
+ return -1; + return -1;
+ } + }
@ -104,45 +108,48 @@ index dba9ff0..698da84 100644
+ +
static int sca_mod_init(void) static int sca_mod_init(void)
{ {
sca = (sca_mod *) shm_malloc(sizeof(sca_mod)); sca = (sca_mod *)shm_malloc(sizeof(sca_mod));
@@ -377,6 +421,11 @@ static int sca_mod_init(void) @@ -389,6 +434,14 @@ static int sca_mod_init(void)
// timer process forks in sca_child_init, above. // timer process forks in sca_child_init, above.
register_dummy_timers(1); register_dummy_timers(1);
+ if(sca_process_avps(&from_uri_avp_param, &from_uri_avp, &from_uri_avp_type)<0 || + if(sca_process_avps(&from_uri_avp_param, &from_uri_avp, &from_uri_avp_type)
+ sca_process_avps(&to_uri_avp_param, &to_uri_avp, &to_uri_avp_type)<0) { + < 0
+ || sca_process_avps(
+ &to_uri_avp_param, &to_uri_avp, &to_uri_avp_type)
+ < 0) {
+ goto error; + goto error;
+ } + }
+ +
LM_INFO("SCA initialized \n"); LM_INFO("SCA initialized \n");
return (0); return (0);
@@ -414,6 +463,56 @@ void sca_mod_destroy(void) @@ -428,6 +481,56 @@ void sca_mod_destroy(void)
sca_db_disconnect(); sca_db_disconnect();
} }
+static int sca_handle_subscribe_0_f(sip_msg_t* msg) { +static int sca_handle_subscribe_0_f(sip_msg_t *msg)
+{
+ return sca_handle_subscribe(msg, NULL, NULL); + return sca_handle_subscribe(msg, NULL, NULL);
+} +}
+static int sca_handle_subscribe_1_f(sip_msg_t* msg, char* p1) { +static int sca_handle_subscribe_1_f(sip_msg_t *msg, char *p1)
+{
+ str uri_to = STR_NULL; + str uri_to = STR_NULL;
+ if(get_str_fparam(&uri_to, msg, (gparam_p)p1)!=0) + if(get_str_fparam(&uri_to, msg, (gparam_p)p1) != 0) {
+ {
+ LM_ERR("unable to get value from param pvar_to\n"); + LM_ERR("unable to get value from param pvar_to\n");
+ return -1; + return -1;
+ } + }
+ return sca_handle_subscribe(msg, &uri_to, NULL); + return sca_handle_subscribe(msg, &uri_to, NULL);
+} +}
+static int sca_handle_subscribe_2_f(sip_msg_t* msg, char* p1, char* p2) { +static int sca_handle_subscribe_2_f(sip_msg_t *msg, char *p1, char *p2)
+{
+ str uri_to = STR_NULL; + str uri_to = STR_NULL;
+ str uri_from = STR_NULL; + str uri_from = STR_NULL;
+ if(get_str_fparam(&uri_to, msg, (gparam_p)p1)!=0) + if(get_str_fparam(&uri_to, msg, (gparam_p)p1) != 0) {
+ {
+ LM_ERR("unable to get value from param pvar_to\n"); + LM_ERR("unable to get value from param pvar_to\n");
+ return -1; + return -1;
+ } + }
+ if(get_str_fparam(&uri_from, msg, (gparam_p)p2)!=0) + if(get_str_fparam(&uri_from, msg, (gparam_p)p2) != 0) {
+ {
+ LM_ERR("unable to get value from param pvar_from\n"); + LM_ERR("unable to get value from param pvar_from\n");
+ return -1; + return -1;
+ } + }
@ -151,7 +158,7 @@ index dba9ff0..698da84 100644
+ +
+int fixup_hs(void **param, int param_no) +int fixup_hs(void **param, int param_no)
+{ +{
+ switch (param_no) { + switch(param_no) {
+ case 1: + case 1:
+ case 2: + case 2:
+ return fixup_spve_null(param, 1); + return fixup_spve_null(param, 1);
@ -162,23 +169,23 @@ index dba9ff0..698da84 100644
+ +
+int fixup_free_hs(void **param, int param_no) +int fixup_free_hs(void **param, int param_no)
+{ +{
+ switch (param_no) { + switch(param_no) {
+ case 1: + case 1:
+ case 2: + case 2:
+ return fixup_free_spve_null(param, 1); + return fixup_free_spve_null(param, 1);
+ default: + default:
+ return E_UNSPEC; + return E_UNSPEC;
+ } + }
+} +}
+ +
static int sca_call_info_update_0_f(sip_msg_t* msg, char* p1, char* p2) static int sca_call_info_update_0_f(sip_msg_t *msg, char *p1, char *p2)
{ {
return sca_call_info_update(msg, SCA_CALL_INFO_SHARED_BOTH, NULL, NULL); return sca_call_info_update(msg, SCA_CALL_INFO_SHARED_BOTH, NULL, NULL);
diff --git a/src/modules/sca/sca.h b/src/modules/sca/sca.h diff --git a/src/modules/sca/sca.h b/src/modules/sca/sca.h
index 04d3c1e..2425bc3 100644 index cceae17..7a80847 100644
--- a/src/modules/sca/sca.h --- a/src/modules/sca/sca.h
+++ b/src/modules/sca/sca.h +++ b/src/modules/sca/sca.h
@@ -55,4 +55,10 @@ typedef struct _sca_mod sca_mod; @@ -57,4 +57,10 @@ typedef struct _sca_mod sca_mod;
extern sca_mod *sca; extern sca_mod *sca;
@ -189,11 +196,24 @@ index 04d3c1e..2425bc3 100644
+extern int_str to_uri_avp; +extern int_str to_uri_avp;
+ +
#endif // SCA_H #endif // SCA_H
diff --git a/src/modules/sca/sca_appearance.h b/src/modules/sca/sca_appearance.h
index bd94e14..6ce3112 100644
--- a/src/modules/sca/sca_appearance.h
+++ b/src/modules/sca/sca_appearance.h
@@ -40,7 +40,7 @@ enum
#define sca_appearance_is_held(app1) \
((app1) \
&& ((app1)->state == SCA_APPEARANCE_STATE_HELD \
- || (app1)->state == SCA_APPEARANCE_STATE_HELD_PRIVATE))
+ || (app1)->state == SCA_APPEARANCE_STATE_HELD_PRIVATE))
enum
{
diff --git a/src/modules/sca/sca_call_info.c b/src/modules/sca/sca_call_info.c diff --git a/src/modules/sca/sca_call_info.c b/src/modules/sca/sca_call_info.c
index 5592efd..4ae93f9 100644 index c443f23..867421b 100644
--- a/src/modules/sca/sca_call_info.c --- a/src/modules/sca/sca_call_info.c
+++ b/src/modules/sca/sca_call_info.c +++ b/src/modules/sca/sca_call_info.c
@@ -1798,11 +1798,11 @@ int sca_call_info_update(sip_msg_t *msg, int update_mask, str *uri_to, @@ -1851,11 +1851,11 @@ int sca_call_info_update(
str to_aor = STR_NULL; str to_aor = STR_NULL;
str contact_uri = STR_NULL; str contact_uri = STR_NULL;
int aor_flags = SCA_CALL_INFO_UPDATE_FLAG_DEFAULT; int aor_flags = SCA_CALL_INFO_UPDATE_FLAG_DEFAULT;
@ -206,176 +226,233 @@ index 5592efd..4ae93f9 100644
method = sca_get_msg_method(msg); method = sca_get_msg_method(msg);
@@ -1846,6 +1846,9 @@ int sca_call_info_update(sip_msg_t *msg, int update_mask, str *uri_to, @@ -1868,7 +1868,7 @@ int sca_call_info_update(
if(i >= n_dispatch) {
if(msg->cseq == NULL
&& ((parse_headers(msg, HDR_CSEQ_F, 0) == -1)
- || (msg->cseq == NULL))) {
+ || (msg->cseq == NULL))) {
LM_ERR("no CSEQ header\n");
return (1);
}
@@ -1900,6 +1900,9 @@ int sca_call_info_update(
} }
} }
+ delete_avp(from_uri_avp_type|AVP_VAL_STR, from_uri_avp); + delete_avp(from_uri_avp_type | AVP_VAL_STR, from_uri_avp);
+ delete_avp(to_uri_avp_type|AVP_VAL_STR, to_uri_avp); + delete_avp(to_uri_avp_type | AVP_VAL_STR, to_uri_avp);
+ +
memset(&call_info, 0, sizeof(sca_call_info)); memset(&call_info, 0, sizeof(sca_call_info));
call_info_hdr = get_hdr(msg, HDR_CALLINFO_T); call_info_hdr = get_hdr(msg, HDR_CALLINFO_T);
if (!SCA_HEADER_EMPTY(call_info_hdr)) { if(!SCA_HEADER_EMPTY(call_info_hdr)) {
@@ -1858,36 +1861,22 @@ int sca_call_info_update(sip_msg_t *msg, int update_mask, str *uri_to, @@ -1912,34 +1915,22 @@ int sca_call_info_update(
} }
if (uri_from != NULL) { if(uri_from != NULL) {
- if(sca_build_to_body_from_uri(msg, &from, uri_from)<0){ - if(sca_build_to_body_from_uri(msg, &from, uri_from) < 0) {
- LM_ERR("Bad From uri from param\n"); - LM_ERR("Bad From uri from param\n");
- return (-1); - return (-1);
- } - }
+ val.s.s = uri_from->s; + val.s.s = uri_from->s;
+ val.s.len = uri_from->len; + val.s.len = uri_from->len;
+ add_avp(from_uri_avp_type|AVP_VAL_STR, from_uri_avp, val); + add_avp(from_uri_avp_type | AVP_VAL_STR, from_uri_avp, val);
LM_DBG("from[%.*s] param\n", STR_FMT(uri_from)); LM_DBG("from[%.*s] param\n", STR_FMT(uri_from));
- to_body_flags |= SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC; - to_body_flags |= SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC;
- if (sca_uri_extract_aor(&from->uri, &from_aor) < 0) { - if(sca_uri_extract_aor(&from->uri, &from_aor) < 0) {
- LM_ERR("Failed to extract AoR from From URI %.*s\n", - LM_ERR("Failed to extract AoR from From URI %.*s\n",
- STR_FMT(&from->uri)); - STR_FMT(&from->uri));
- goto done; - goto done;
- } - }
} - } else if(sca_get_msg_from_header(msg, &from) < 0) {
- else if (sca_get_msg_from_header(msg, &from) < 0) {
- LM_ERR("Bad From header\n"); - LM_ERR("Bad From header\n");
+ if (sca_get_msg_from_header(msg, &from) < 0) { + }
+ LM_ERR( "Bad From header" ); + if(sca_get_msg_from_header(msg, &from) < 0) {
+ LM_ERR("Bad From header");
return (-1); return (-1);
} }
if (uri_to != NULL) { if(uri_to != NULL) {
- if(sca_build_to_body_from_uri(msg, &to, uri_to)<0){ - if(sca_build_to_body_from_uri(msg, &to, uri_to) < 0) {
- LM_ERR("Bad From uri to param\n"); - LM_ERR("Bad From uri to param\n");
- goto done; - goto done;
- } - }
+ val.s.s = uri_to->s; + val.s.s = uri_to->s;
+ val.s.len = uri_to->len; + val.s.len = uri_to->len;
+ add_avp(to_uri_avp_type|AVP_VAL_STR, to_uri_avp, val); + add_avp(to_uri_avp_type | AVP_VAL_STR, to_uri_avp, val);
LM_DBG("to[%.*s] param\n", STR_FMT(uri_to)); LM_DBG("to[%.*s] param\n", STR_FMT(uri_to));
- to_body_flags |= SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC; - to_body_flags |= SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC;
- if (sca_uri_extract_aor(&to->uri, &to_aor) < 0) { - if(sca_uri_extract_aor(&to->uri, &to_aor) < 0) {
- LM_ERR("Failed to extract AoR from To URI %.*s\n", - LM_ERR("Failed to extract AoR from To URI %.*s\n",
- STR_FMT(&to->uri)); - STR_FMT(&to->uri));
- goto done; - goto done;
- } - }
} - } else if(sca_get_msg_to_header(msg, &to) < 0) {
- else if (sca_get_msg_to_header(msg, &to) < 0) { + }
+ if (sca_get_msg_to_header(msg, &to) < 0) { + if(sca_get_msg_to_header(msg, &to) < 0) {
LM_ERR("Bad To header\n"); LM_ERR("Bad To header\n");
goto done; goto done;
} }
@@ -1916,27 +1905,35 @@ int sca_call_info_update(sip_msg_t *msg, int update_mask, str *uri_to, @@ -1967,27 +1958,34 @@ int sca_call_info_update(
goto done; goto done;
} }
aor_flags |= SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC; aor_flags |= SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC;
- } - }
- if (uri_to==NULL) { - if(uri_to == NULL) {
- if (sca_uri_extract_aor(&to->uri, &to_aor) < 0) { - if(sca_uri_extract_aor(&to->uri, &to_aor) < 0) {
- LM_ERR("Failed to extract AoR from To URI %.*s\n", - LM_ERR("Failed to extract AoR from To URI %.*s\n",
- STR_FMT(&to->uri)); - STR_FMT(&to->uri));
- goto done; - goto done;
- } - }
- } - }
- } else { - } else {
- if (uri_from==NULL) { - if(uri_from == NULL) {
+ } else { + } else {
if (sca_uri_extract_aor(&from->uri, &from_aor) < 0) { if(sca_uri_extract_aor(&from->uri, &from_aor) < 0) {
LM_ERR("Failed to extract AoR from From URI %.*s\n", LM_ERR("Failed to extract AoR from From URI %.*s\n",
- STR_FMT(&from->uri)); STR_FMT(&from->uri));
+ STR_FMT(&from->uri));
goto done; goto done;
} }
} }
+ if (sca_uri_extract_aor(&to->uri, &to_aor) < 0) { + if(sca_uri_extract_aor(&to->uri, &to_aor) < 0) {
+ LM_ERR( "Failed to extract AoR from To URI %.*s", + LM_ERR("Failed to extract AoR from To URI %.*s", STR_FMT(&to->uri));
+ STR_FMT(&to->uri));
+ goto done; + goto done;
+ } + }
+ } else { + } else {
+ if (sca_uri_extract_aor(&from->uri, &from_aor) < 0) { + if(sca_uri_extract_aor(&from->uri, &from_aor) < 0) {
+ LM_ERR( "Failed to extract AoR from From URI %.*s", + LM_ERR("Failed to extract AoR from From URI %.*s",
+ STR_FMT(&from->uri)); + STR_FMT(&from->uri));
+ goto done; + goto done;
+ } + }
if (uri_to==NULL) { if(uri_to == NULL) {
if (sca_create_canonical_aor(msg, &to_aor) < 0) { if(sca_create_canonical_aor(msg, &to_aor) < 0) {
goto done; goto done;
} }
aor_flags |= SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC; aor_flags |= SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC;
+ } else { + } else {
+ if ( sca_uri_extract_aor( &to->uri, &to_aor ) < 0 ) { + if(sca_uri_extract_aor(&to->uri, &to_aor) < 0) {
+ LM_ERR( "Failed to extract AoR from To URI %.*s", + LM_ERR("Failed to extract AoR from To URI %.*s",
+ STR_FMT( &to->uri )); + STR_FMT(&to->uri));
+ goto done; + goto done;
+ } + }
} }
} }
@@ -2006,16 +2003,6 @@ int sca_call_info_update(sip_msg_t *msg, int update_mask, str *uri_to, @@ -2058,16 +2056,6 @@ done:
pkg_free(to_aor.s); pkg_free(to_aor.s);
} }
} }
- if ((to_body_flags & SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC)) { - if((to_body_flags & SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC)) {
- if (from != NULL) { - if(from != NULL) {
- free_to(from); - free_to(from);
- } - }
- } - }
- if ((to_body_flags & SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC)) { - if((to_body_flags & SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC)) {
- if (to != NULL) { - if(to != NULL) {
- free_to(to); - free_to(to);
- } - }
- } - }
return (rc); return (rc);
} }
diff --git a/src/modules/sca/sca_call_info.h b/src/modules/sca/sca_call_info.h
index 914f36f..0f2d53c 100644
--- a/src/modules/sca/sca_call_info.h
+++ b/src/modules/sca/sca_call_info.h
@@ -49,17 +49,17 @@ typedef struct _sca_call_info sca_call_info;
#define SCA_CALL_INFO_EMPTY(ci1) \
((void *)(ci1) == NULL \
|| ((ci1)->index == SCA_CALL_INFO_APPEARANCE_INDEX_ANY \
- && (ci1)->state == SCA_APPEARANCE_STATE_UNKNOWN))
+ && (ci1)->state == SCA_APPEARANCE_STATE_UNKNOWN))
#define SCA_CALL_INFO_IS_SHARED_CALLER(ci1) \
(!SCA_CALL_INFO_EMPTY((ci1)) \
&& (((sca_call_info *)(ci1))->ua_shared \
- & SCA_CALL_INFO_SHARED_CALLER))
+ & SCA_CALL_INFO_SHARED_CALLER))
#define SCA_CALL_INFO_IS_SHARED_CALLEE(ci1) \
(!SCA_CALL_INFO_EMPTY((ci1)) \
&& (((sca_call_info *)(ci1))->ua_shared \
- & SCA_CALL_INFO_SHARED_CALLEE))
+ & SCA_CALL_INFO_SHARED_CALLEE))
extern const str SCA_CALL_INFO_HEADER_STR;
diff --git a/src/modules/sca/sca_dialog.h b/src/modules/sca/sca_dialog.h
index d308954..dee234c 100644
--- a/src/modules/sca/sca_dialog.h
+++ b/src/modules/sca/sca_dialog.h
@@ -35,7 +35,7 @@ typedef struct _sca_dialog sca_dialog;
#define SCA_DIALOG_EMPTY(d) \
((d) == NULL \
|| (SCA_STR_EMPTY(&(d)->call_id) && SCA_STR_EMPTY(&(d)->from_tag) \
- && SCA_STR_EMPTY(&(d)->to_tag)))
+ && SCA_STR_EMPTY(&(d)->to_tag)))
int sca_dialog_build_from_tags(sca_dialog *, int, str *, str *, str *);
int sca_dialog_create_replaces_header(sca_dialog *, str *);
diff --git a/src/modules/sca/sca_subscribe.c b/src/modules/sca/sca_subscribe.c diff --git a/src/modules/sca/sca_subscribe.c b/src/modules/sca/sca_subscribe.c
index 8040d49..d568729 100644 index dc33f00..6d7eb03 100644
--- a/src/modules/sca/sca_subscribe.c --- a/src/modules/sca/sca_subscribe.c
+++ b/src/modules/sca/sca_subscribe.c +++ b/src/modules/sca/sca_subscribe.c
@@ -1005,10 +1005,6 @@ int sca_subscription_from_request(sca_mod *scam, sip_msg_t *msg, int event_type, @@ -844,8 +844,8 @@ static int sca_subscription_update_unsafe(sca_mod *scam,
// this is allocated separately from the rest of the subscription
len = sizeof(char *)
* (update_sub->dialog.call_id.len
- + update_sub->dialog.from_tag.len
- + update_sub->dialog.to_tag.len);
+ + update_sub->dialog.from_tag.len
+ + update_sub->dialog.to_tag.len);
dlg_id_tmp = (char *)shm_malloc(len);
if(dlg_id_tmp == NULL) {
@@ -1023,10 +1023,6 @@ int sca_subscription_from_request(sca_mod *scam, sip_msg_t *msg, int event_type,
expires = max_expires; expires = max_expires;
} }
- if (SCA_HEADER_EMPTY(msg->to)) { - if(SCA_HEADER_EMPTY(msg->to)) {
- LM_ERR("Empty To header\n"); - LM_ERR("Empty To header\n");
- goto error; - goto error;
- } - }
if (SCA_HEADER_EMPTY(msg->callid)) { if(SCA_HEADER_EMPTY(msg->callid)) {
LM_ERR("Empty Call-ID header\n"); LM_ERR("Empty Call-ID header\n");
goto error; goto error;
@@ -1030,29 +1026,18 @@ int sca_subscription_from_request(sca_mod *scam, sip_msg_t *msg, int event_type, @@ -1048,30 +1044,18 @@ int sca_subscription_from_request(sca_mod *scam, sip_msg_t *msg, int event_type,
goto error; goto error;
} }
- if (SCA_HEADER_EMPTY(msg->from)) { - if(SCA_HEADER_EMPTY(msg->from)) {
- LM_ERR("Empty From header\n"); - LM_ERR("Empty From header\n");
- goto error; - goto error;
- } - }
- if (parse_from_header(msg) < 0) { - if(parse_from_header(msg) < 0) {
+ if (sca_get_msg_from_header(msg, &from) < 0) { + if(sca_get_msg_from_header(msg, &from) < 0) {
LM_ERR("Bad From header\n"); LM_ERR("Bad From header\n");
goto error; goto error;
} }
- from = (struct to_body *) msg->from->parsed; - from = (struct to_body *)msg->from->parsed;
if (SCA_STR_EMPTY(&from->tag_value)) { if(SCA_STR_EMPTY(&from->tag_value)) {
LM_ERR("No from-tag in From header\n"); LM_ERR("No from-tag in From header\n");
goto error; goto error;
} }
- if ((to = (struct to_body *) msg->to->parsed) == NULL) { - if((to = (struct to_body *)msg->to->parsed) == NULL) {
- parse_to(msg->to->body.s, msg->to->body.s + msg->to->body.len + 1, // end of buffer - parse_to(msg->to->body.s,
- &tmp_to); - msg->to->body.s + msg->to->body.len + 1, // end of buffer
- &tmp_to);
- -
- if (tmp_to.error != PARSE_OK) { - if(tmp_to.error != PARSE_OK) {
- LM_ERR("Bad To header\n"); - LM_ERR("Bad To header\n");
- goto error; - goto error;
- } - }
- to = &tmp_to; - to = &tmp_to;
+ if ( sca_get_msg_to_header( msg, &to ) < 0 ) { + if(sca_get_msg_to_header(msg, &to) < 0) {
+ LM_ERR( "Bad To header" ); + LM_ERR("Bad To header");
+ goto error; + goto error;
} }
if (parse_sip_msg_uri(msg) < 0) { if(parse_sip_msg_uri(msg) < 0) {
@@ -1135,7 +1120,7 @@ int sca_subscription_from_request(sca_mod *scam, sip_msg_t *msg, int event_type, @@ -1153,7 +1137,7 @@ error:
return (-1); return (-1);
} }
@ -384,46 +461,46 @@ index 8040d49..d568729 100644
{ {
sca_subscription req_sub; sca_subscription req_sub;
sca_subscription *sub = NULL; sca_subscription *sub = NULL;
@@ -1150,6 +1135,8 @@ int ki_sca_handle_subscribe(sip_msg_t *msg) @@ -1168,6 +1152,8 @@ int ki_sca_handle_subscribe(sip_msg_t *msg)
int idx = -1; int idx = -1;
int rc = -1; int rc = -1;
int released = 0; int released = 0;
+ int_str val; + int_str val;
+ struct to_body *tmp_to; + struct to_body *tmp_to;
if (parse_headers(msg, HDR_EOH_F, 0) < 0) { if(parse_headers(msg, HDR_EOH_F, 0) < 0) {
LM_ERR("header parsing failed: bad request\n"); LM_ERR("header parsing failed: bad request\n");
@@ -1174,6 +1161,21 @@ int ki_sca_handle_subscribe(sip_msg_t *msg) @@ -1192,6 +1178,21 @@ int ki_sca_handle_subscribe(sip_msg_t *msg)
return (-1); return (-1);
} }
+ delete_avp(from_uri_avp_type|AVP_VAL_STR, from_uri_avp); + delete_avp(from_uri_avp_type | AVP_VAL_STR, from_uri_avp);
+ delete_avp(to_uri_avp_type|AVP_VAL_STR, to_uri_avp); + delete_avp(to_uri_avp_type | AVP_VAL_STR, to_uri_avp);
+ if (uri_from != NULL) { + if(uri_from != NULL) {
+ val.s.s = uri_from->s; + val.s.s = uri_from->s;
+ val.s.len = uri_from->len; + val.s.len = uri_from->len;
+ add_avp(from_uri_avp_type|AVP_VAL_STR, from_uri_avp, val); + add_avp(from_uri_avp_type | AVP_VAL_STR, from_uri_avp, val);
+ LM_DBG("from[%.*s] param\n", STR_FMT(uri_from)); + LM_DBG("from[%.*s] param\n", STR_FMT(uri_from));
+ } + }
+ if (uri_to != NULL) { + if(uri_to != NULL) {
+ val.s.s = uri_to->s; + val.s.s = uri_to->s;
+ val.s.len = uri_to->len; + val.s.len = uri_to->len;
+ add_avp(to_uri_avp_type|AVP_VAL_STR, to_uri_avp, val); + add_avp(to_uri_avp_type | AVP_VAL_STR, to_uri_avp, val);
+ LM_DBG("to[%.*s] param\n", STR_FMT(uri_to)); + LM_DBG("to[%.*s] param\n", STR_FMT(uri_to));
+ } + }
+ +
if (sca_subscription_from_request(sca, msg, event_type, &req_sub) < 0) { if(sca_subscription_from_request(sca, msg, event_type, &req_sub) < 0) {
SCA_SUB_REPLY_ERROR(sca, 400, "Bad Shared Call Appearance Request", SCA_SUB_REPLY_ERROR(
msg); sca, 400, "Bad Shared Call Appearance Request", msg);
@@ -1187,7 +1189,15 @@ int ki_sca_handle_subscribe(sip_msg_t *msg) @@ -1207,7 +1208,15 @@ int ki_sca_handle_subscribe(sip_msg_t *msg)
sca_subscription_print(&req_sub); sca_subscription_print(&req_sub);
// check to see if the message has a to-tag // check to see if the message has a to-tag
- to_tag = &(get_to(msg)->tag_value); - to_tag = &(get_to(msg)->tag_value);
+ if(uri_to!=NULL) { + if(uri_to != NULL) {
+ if (sca_get_msg_to_header(msg, &tmp_to) < 0) { + if(sca_get_msg_to_header(msg, &tmp_to) < 0) {
+ LM_ERR( "Bad To header" ); + LM_ERR("Bad To header");
+ return(-1); + return (-1);
+ } + }
+ to_tag = &(tmp_to->tag_value); + to_tag = &(tmp_to->tag_value);
+ } else { + } else {
@ -432,7 +509,7 @@ index 8040d49..d568729 100644
// XXX should lock starting here and use unsafe methods below? // XXX should lock starting here and use unsafe methods below?
@@ -1354,9 +1364,9 @@ int ki_sca_handle_subscribe(sip_msg_t *msg) @@ -1391,9 +1400,9 @@ done:
return (rc); return (rc);
} }
@ -445,49 +522,74 @@ index 8040d49..d568729 100644
int sca_subscription_reply(sca_mod *scam, int status_code, char *status_msg, int sca_subscription_reply(sca_mod *scam, int status_code, char *status_msg,
diff --git a/src/modules/sca/sca_subscribe.h b/src/modules/sca/sca_subscribe.h diff --git a/src/modules/sca/sca_subscribe.h b/src/modules/sca/sca_subscribe.h
index e919717..5ee2cbc 100644 index e27883e..44f93b7 100644
--- a/src/modules/sca/sca_subscribe.h --- a/src/modules/sca/sca_subscribe.h
+++ b/src/modules/sca/sca_subscribe.h +++ b/src/modules/sca/sca_subscribe.h
@@ -75,7 +75,7 @@ extern const str SCA_METHOD_SUBSCRIBE; @@ -50,7 +50,7 @@ struct _sca_subscription
sca_subscription_reply((mod), (scode), (smsg), \ str rr; // Record-Route header values
SCA_EVENT_TYPE_CALL_INFO, -1, (sreply))
int db_cmd_flag; // track whether to INSERT or UPDATE
- int server_id; // server
+ int server_id; // server
};
typedef struct _sca_subscription sca_subscription;
@@ -79,7 +79,7 @@ extern const str SCA_METHOD_SUBSCRIBE;
sca_subscription_reply( \
(mod), (scode), (smsg), SCA_EVENT_TYPE_CALL_INFO, -1, (sreply))
-int sca_handle_subscribe(sip_msg_t *, char *, char *); -int sca_handle_subscribe(sip_msg_t *, char *, char *);
+int sca_handle_subscribe(sip_msg_t *, str *, str *); +int sca_handle_subscribe(sip_msg_t *, str *, str *);
int sca_subscription_reply(sca_mod *, int, char *, int, int, sip_msg_t *); int sca_subscription_reply(sca_mod *, int, char *, int, int, sip_msg_t *);
int sca_subscription_from_db_result(db1_res_t *, sca_subscription *); int sca_subscription_from_db_result(db1_res_t *, sca_subscription *);
@@ -88,6 +88,6 @@ void sca_subscription_state_to_str(int, str *); @@ -93,6 +93,6 @@ int sca_subscription_aor_has_subscribers(int, str *);
int sca_subscription_aor_has_subscribers(int, str *); int sca_subscription_delete_subscriber_for_event(
int sca_subscription_delete_subscriber_for_event(sca_mod *, str *, str *, str *); sca_mod *, str *, str *, str *);
int sca_subscription_terminate(sca_mod *, str *, int, str *, int, int); int sca_subscription_terminate(sca_mod *, str *, int, str *, int, int);
-int ki_sca_handle_subscribe(sip_msg_t *msg); -int ki_sca_handle_subscribe(sip_msg_t *msg);
+int ki_sca_handle_subscribe(sip_msg_t *msg, str *, str *); +int ki_sca_handle_subscribe(sip_msg_t *msg, str *, str *);
#endif // SCA_SUBSCRIBE_H #endif // SCA_SUBSCRIBE_H
diff --git a/src/modules/sca/sca_util.c b/src/modules/sca/sca_util.c diff --git a/src/modules/sca/sca_util.c b/src/modules/sca/sca_util.c
index b586c8f..46d04c5 100644 index 4ab4c6f..e1ef561 100644
--- a/src/modules/sca/sca_util.c --- a/src/modules/sca/sca_util.c
+++ b/src/modules/sca/sca_util.c +++ b/src/modules/sca/sca_util.c
@@ -112,93 +112,118 @@ int sca_get_msg_cseq_method(sip_msg_t *msg) @@ -112,94 +112,123 @@ int sca_get_msg_cseq_method(sip_msg_t *msg)
return (get_cseq(msg)->method_id); return (get_cseq(msg)->method_id);
} }
-int sca_get_msg_from_header(sip_msg_t *msg, struct to_body **from) -int sca_get_msg_from_header(sip_msg_t *msg, struct to_body **from)
+int sca_get_avp_value(unsigned short avp_type, int_str avp, str *result) { +int sca_get_avp_value(unsigned short avp_type, int_str avp, str *result)
{
- struct to_body *f;
+ int_str val; + int_str val;
+ struct usr_avp *_avp; + struct usr_avp *_avp;
+
- assert(msg != NULL);
- assert(from != NULL);
+ assert(result != NULL); + assert(result != NULL);
+
+ if (avp.s.len > 0) { - if(SCA_HEADER_EMPTY(msg->from)) {
- LM_ERR("Empty From header\n");
- return (-1);
- }
- if(parse_from_header(msg) < 0) {
- LM_ERR("Bad From header\n");
- return (-1);
- }
- f = get_from(msg);
- if(SCA_STR_EMPTY(&f->tag_value)) {
- LM_ERR("Bad From header: no tag parameter\n");
- return (-1);
+ if(avp.s.len > 0) {
+ _avp = search_first_avp(avp_type, avp, &val, 0); + _avp = search_first_avp(avp_type, avp, &val, 0);
+ if(_avp) { + if(_avp) {
+ result->s = val.s.s; + result->s = val.s.s;
+ result->len = val.s.len; + result->len = val.s.len;
+ return 0; + return 0;
+ } + }
+ } }
+ return -1; + return -1;
+} +}
+ +
@ -495,160 +597,148 @@ index b586c8f..46d04c5 100644
+ * caller needs to call free_to for *body + * caller needs to call free_to for *body
+ */ + */
+int sca_parse_uri(struct to_body *body, str *uri) +int sca_parse_uri(struct to_body *body, str *uri)
{ +{
+ assert(body != NULL); + assert(body != NULL);
+ assert(uri != NULL); + assert(uri != NULL);
+
- // ensure the URI is parsed for future use
- if(parse_uri(f->uri.s, f->uri.len, GET_FROM_PURI(msg)) < 0) {
- LM_ERR("Failed to parse From URI %.*s\n", STR_FMT(&f->uri));
+ parse_to(uri->s, uri->s + uri->len + 1, body); + parse_to(uri->s, uri->s + uri->len + 1, body);
+ if (body->error != PARSE_OK) { + if(body->error != PARSE_OK) {
+ LM_ERR("Bad uri value[%.*s]\n", STR_FMT(uri)); + LM_ERR("Bad uri value[%.*s]\n", STR_FMT(uri));
+ return(-1); return (-1);
+ } }
+ return (0); -
+} - *from = f;
+ -
+int sca_get_msg_from_header( sip_msg_t *msg, struct to_body **from ) { return (0);
struct to_body *f; }
-int sca_get_msg_to_header(sip_msg_t *msg, struct to_body **to)
+int sca_get_msg_from_header(sip_msg_t *msg, struct to_body **from)
{
- struct to_body parsed_to;
- struct to_body *t = NULL;
+ struct to_body *f;
+ static struct to_body sf; + static struct to_body sf;
+ str uri = STR_NULL; + str uri = STR_NULL;
- assert(msg != NULL); - assert(msg != NULL);
assert(from != NULL); - assert(to != NULL);
+ assert(from != NULL);
- if (SCA_HEADER_EMPTY(msg->from)) { - if(SCA_HEADER_EMPTY(msg->to)) {
- LM_ERR("Empty From header\n"); - LM_ERR("Empty To header\n");
- return (-1);
- }
- if (parse_from_header(msg) < 0) {
- LM_ERR("Bad From header\n");
- return (-1);
- }
- f = get_from(msg);
- if (SCA_STR_EMPTY(&f->tag_value)) {
- LM_ERR("Bad From header: no tag parameter\n");
- return (-1); - return (-1);
- } - }
+ if(sca_get_avp_value(from_uri_avp_type, from_uri_avp, &uri)<0) { - t = get_to(msg);
+ assert( msg != NULL ); - if(t == NULL) {
+ if (SCA_HEADER_EMPTY(msg->from)) { - parse_to(msg->to->body.s,
- msg->to->body.s + msg->to->body.len + 1, // end of buffer
- &parsed_to);
- if(parsed_to.error != PARSE_OK) {
- LM_ERR("Bad To header\n");
+ if(sca_get_avp_value(from_uri_avp_type, from_uri_avp, &uri) < 0) {
+ assert(msg != NULL);
+ if(SCA_HEADER_EMPTY(msg->from)) {
+ LM_ERR("Empty From header\n"); + LM_ERR("Empty From header\n");
+ return (-1); + return (-1);
+ } + }
+ if (parse_from_header(msg) < 0) { + if(parse_from_header(msg) < 0) {
+ LM_ERR("Bad From header\n"); + LM_ERR("Bad From header\n");
+ return (-1); + return (-1);
+ } + }
+ f = get_from(msg); + f = get_from(msg);
+ if (SCA_STR_EMPTY(&f->tag_value)) { + if(SCA_STR_EMPTY(&f->tag_value)) {
+ LM_ERR("Bad From header: no tag parameter\n"); + LM_ERR("Bad From header: no tag parameter\n");
+ return (-1); return (-1);
+ } }
- t = &parsed_to;
- }
- // ensure the URI is parsed for future use - // ensure the URI is parsed for future use
- if (parse_uri(f->uri.s, f->uri.len, GET_FROM_PURI(msg)) < 0) { - if(parse_uri(t->uri.s, t->uri.len, GET_TO_PURI(msg)) < 0) {
- LM_ERR("Failed to parse From URI %.*s\n", STR_FMT(&f->uri)); - LM_ERR("Failed to parse To URI %.*s\n", STR_FMT(&t->uri));
- return (-1); - return (-1);
- } - }
+ // ensure the URI is parsed for future use + // ensure the URI is parsed for future use
+ if (parse_uri(f->uri.s, f->uri.len, GET_FROM_PURI(msg)) < 0) { + if(parse_uri(f->uri.s, f->uri.len, GET_FROM_PURI(msg)) < 0) {
+ LM_ERR("Failed to parse From URI %.*s\n", STR_FMT(&f->uri)); + LM_ERR("Failed to parse From URI %.*s\n", STR_FMT(&f->uri));
+ return (-1); + return (-1);
+ } + }
- *from = f; - *to = t;
+ *from = f; + *from = f;
+ } else { + } else {
+ LM_DBG("using $avp(%.*s)[%.*s] as from uri\n", + LM_DBG("using $avp(%.*s)[%.*s] as from uri\n", STR_FMT(&from_uri_avp.s),
+ STR_FMT(&from_uri_avp.s), STR_FMT(&uri)); + STR_FMT(&uri));
+ if(sca_parse_uri(&sf, &uri)<0) return -1; + if(sca_parse_uri(&sf, &uri) < 0)
+ return -1;
+ *from = &sf; + *from = &sf;
+ } + }
return (0); return (0);
} }
int sca_get_msg_to_header(sip_msg_t *msg, struct to_body **to) -/*
- * caller needs to call free_to for *body
- */
-int sca_build_to_body_from_uri(sip_msg_t *msg, struct to_body **body, str *uri)
+int sca_get_msg_to_header(sip_msg_t *msg, struct to_body **to)
{ {
- struct to_body parsed_to; - assert(msg != NULL);
- assert(body != NULL);
- assert(uri != NULL);
+ static struct to_body parsed_to; + static struct to_body parsed_to;
struct to_body *t = NULL; + struct to_body *t = NULL;
+ str uri = STR_NULL; + str uri = STR_NULL;
- assert(msg != NULL); - *body = pkg_malloc(sizeof(struct to_body));
assert(to != NULL); - if(*body == NULL) {
+ if(sca_get_avp_value(to_uri_avp_type, to_uri_avp, &uri)<0) { - LM_ERR("cannot allocate pkg memory\n");
- return (-1);
- }
+ assert(to != NULL);
+ if(sca_get_avp_value(to_uri_avp_type, to_uri_avp, &uri) < 0) {
+ assert(msg != NULL); + assert(msg != NULL);
- if (SCA_HEADER_EMPTY(msg->to)) { - parse_to(uri->s, uri->s + uri->len + 1, *body);
- LM_ERR("Empty To header\n"); - if((*body)->error != PARSE_OK) {
- LM_ERR("Bad uri value[%.*s]\n", STR_FMT(uri));
- free_to(*body);
- return (-1); - return (-1);
- } + if(SCA_HEADER_EMPTY(msg->to)) {
- t = get_to(msg);
- if (t == NULL) {
- parse_to(msg->to->body.s, msg->to->body.s + msg->to->body.len + 1, // end of buffer
- &parsed_to);
- if (parsed_to.error != PARSE_OK) {
- LM_ERR("Bad To header\n");
+ if (SCA_HEADER_EMPTY(msg->to)) {
+ LM_ERR("Empty To header\n"); + LM_ERR("Empty To header\n");
return (-1); + return (-1);
} + }
- t = &parsed_to;
- }
-
- // ensure the URI is parsed for future use
- if (parse_uri(t->uri.s, t->uri.len, GET_TO_PURI(msg)) < 0) {
- LM_ERR("Failed to parse To URI %.*s\n", STR_FMT(&t->uri));
- return (-1);
- }
-
- *to = t;
-
- return (0);
-}
+ t = get_to(msg); + t = get_to(msg);
+ if (t == NULL) { + if(t == NULL) {
+ parse_to(msg->to->body.s, msg->to->body.s + msg->to->body.len + 1, // end of buffer + parse_to(msg->to->body.s,
+ &parsed_to); + msg->to->body.s + msg->to->body.len + 1, // end of buffer
+ if (parsed_to.error != PARSE_OK) { + &parsed_to);
+ if(parsed_to.error != PARSE_OK) {
+ LM_ERR("Bad To header\n"); + LM_ERR("Bad To header\n");
+ return (-1); + return (-1);
+ } + }
+ t = &parsed_to; + t = &parsed_to;
+ } + }
+
-/*
- * caller needs to call free_to for *body
- */
-int sca_build_to_body_from_uri(sip_msg_t *msg, struct to_body **body, str *uri)
-{
- assert(msg != NULL);
- assert(body != NULL);
- assert(uri != NULL);
+ // ensure the URI is parsed for future use + // ensure the URI is parsed for future use
+ if (parse_uri(t->uri.s, t->uri.len, GET_TO_PURI(msg)) < 0) { + if(parse_uri(t->uri.s, t->uri.len, GET_TO_PURI(msg)) < 0) {
+ LM_ERR("Failed to parse To URI %.*s\n", STR_FMT(&t->uri)); + LM_ERR("Failed to parse To URI %.*s\n", STR_FMT(&t->uri));
+ return (-1); + return (-1);
+ } + }
+
- *body = pkg_malloc(sizeof(struct to_body));
- if(*body == NULL) {
- LM_ERR("cannot allocate pkg memory\n");
- return(-1);
+ *to = t; + *to = t;
+ } else { + } else {
+ LM_DBG("using $avp(%.*s)[%.*s] as to uri\n", + LM_DBG("using $avp(%.*s)[%.*s] as to uri\n", STR_FMT(&to_uri_avp.s),
+ STR_FMT(&to_uri_avp.s), STR_FMT(&uri)); + STR_FMT(&uri));
+ if(sca_parse_uri(&parsed_to, &uri)<0) return -1; + if(sca_parse_uri(&parsed_to, &uri) < 0)
+ return -1;
+ *to = &parsed_to; + *to = &parsed_to;
} }
+
- parse_to(uri->s, uri->s + uri->len + 1, *body);
- if ((*body)->error != PARSE_OK) {
- LM_ERR("Bad uri value[%.*s]\n", STR_FMT(uri));
- free_to(*body);
- return(-1);
- }
return (0); return (0);
} }

@ -3,54 +3,54 @@ Date: Thu, 26 Mar 2020 10:06:46 +0100
Subject: sca-rr-is-direction Subject: sca-rr-is-direction
--- ---
src/modules/sca/sca.c | 7 +++++++ src/modules/sca/sca.c | 7 ++++++
src/modules/sca/sca.h | 1 + src/modules/sca/sca.h | 1 +
src/modules/sca/sca_call_info.c | 45 ++++++++++++++++++++++++++++++++++------- src/modules/sca/sca_call_info.c | 53 ++++++++++++++++++++++++++++++++---------
src/modules/sca/sca_common.h | 1 + src/modules/sca/sca_common.h | 1 +
4 files changed, 47 insertions(+), 7 deletions(-) 4 files changed, 51 insertions(+), 11 deletions(-)
diff --git a/src/modules/sca/sca.c b/src/modules/sca/sca.c diff --git a/src/modules/sca/sca.c b/src/modules/sca/sca.c
index 698da84..f743a24 100644 index c2347bb..c0042b9 100644
--- a/src/modules/sca/sca.c --- a/src/modules/sca/sca.c
+++ b/src/modules/sca/sca.c +++ b/src/modules/sca/sca.c
@@ -62,6 +62,7 @@ sca_mod *sca = NULL; @@ -62,6 +62,7 @@ sca_mod *sca = NULL;
*/ */
db_func_t dbf; // db api db_func_t dbf; // db api
struct tm_binds tmb; // tm functions for sending messages struct tm_binds tmb; // tm functions for sending messages
+struct rr_binds rrb; // rr functions for detecting direction +struct rr_binds rrb; // rr functions for detecting direction
sl_api_t slb; // sl callback, function for getting to-tag sl_api_t slb; // sl callback, function for getting to-tag
/* avps */ /* avps */
@@ -393,6 +394,12 @@ static int sca_mod_init(void) @@ -405,6 +406,12 @@ static int sca_mod_init(void)
} }
sca->tm_api = &tmb; sca->tm_api = &tmb;
+ if (load_rr_api(&rrb) != 0) { + if(load_rr_api(&rrb) != 0) {
+ LM_ERR( "Failed to initialize required rr API" ); + LM_ERR("Failed to initialize required rr API");
+ goto error; + goto error;
+ } + }
+ sca->rr_api = &rrb; + sca->rr_api = &rrb;
+ +
if (sca_bind_sl(sca, &slb) != 0) { if(sca_bind_sl(sca, &slb) != 0) {
LM_ERR("Failed to initialize required sl API. Check that the \"sl\" module is loaded before this module.\n"); LM_ERR("Failed to initialize required sl API. Check that the \"sl\" "
goto error; "module is loaded before this module.\n");
diff --git a/src/modules/sca/sca.h b/src/modules/sca/sca.h diff --git a/src/modules/sca/sca.h b/src/modules/sca/sca.h
index 2425bc3..8a7008d 100644 index 7a80847..3d08921 100644
--- a/src/modules/sca/sca.h --- a/src/modules/sca/sca.h
+++ b/src/modules/sca/sca.h +++ b/src/modules/sca/sca.h
@@ -49,6 +49,7 @@ struct _sca_mod { @@ -51,6 +51,7 @@ struct _sca_mod
db_func_t *db_api; db_func_t *db_api;
struct tm_binds *tm_api; struct tm_binds *tm_api;
+ struct rr_binds *rr_api; + struct rr_binds *rr_api;
sl_api_t *sl_api; sl_api_t *sl_api;
}; };
typedef struct _sca_mod sca_mod; typedef struct _sca_mod sca_mod;
diff --git a/src/modules/sca/sca_call_info.c b/src/modules/sca/sca_call_info.c diff --git a/src/modules/sca/sca_call_info.c b/src/modules/sca/sca_call_info.c
index 8b940c3..0fc0cd4 100644 index a173294..00a4c0e 100644
--- a/src/modules/sca/sca_call_info.c --- a/src/modules/sca/sca_call_info.c
+++ b/src/modules/sca/sca_call_info.c +++ b/src/modules/sca/sca_call_info.c
@@ -1312,6 +1312,7 @@ void sca_call_info_ack_from_handler(sip_msg_t *msg, str *from_aor, str *to_aor) @@ -1353,6 +1353,7 @@ void sca_call_info_ack_from_handler(sip_msg_t *msg, str *from_aor, str *to_aor)
sca_appearance *app; sca_appearance *app;
struct to_body *from; struct to_body *from;
struct to_body *to; struct to_body *to;
@ -58,28 +58,30 @@ index 8b940c3..0fc0cd4 100644
int slot_idx = -1; int slot_idx = -1;
int state = SCA_APPEARANCE_STATE_IDLE; int state = SCA_APPEARANCE_STATE_IDLE;
@@ -1325,12 +1326,18 @@ void sca_call_info_ack_from_handler(sip_msg_t *msg, str *from_aor, str *to_aor) @@ -1366,13 +1367,19 @@ void sca_call_info_ack_from_handler(sip_msg_t *msg, str *from_aor, str *to_aor)
} }
if (sca_uri_lock_if_shared_appearance(sca, from_aor, &slot_idx)) { if(sca_uri_lock_if_shared_appearance(sca, from_aor, &slot_idx)) {
+ if(sca->rr_api->is_direction(msg, RR_FLOW_UPSTREAM)==0) { - app = sca_appearance_for_tags_unsafe(sca, from_aor, &msg->callid->body,
- &from->tag_value, NULL, slot_idx);
+ if(sca->rr_api->is_direction(msg, RR_FLOW_UPSTREAM) == 0) {
+ LM_DBG("upstream direction detected\n"); + LM_DBG("upstream direction detected\n");
+ tag = &to->tag_value; + tag = &to->tag_value;
+ } else { + } else {
+ tag = &from->tag_value; + tag = &from->tag_value;
+ } + }
app = sca_appearance_for_tags_unsafe(sca, from_aor, &msg->callid->body, + app = sca_appearance_for_tags_unsafe(
- &from->tag_value, NULL, slot_idx); + sca, from_aor, &msg->callid->body, tag, NULL, slot_idx);
+ tag, NULL, slot_idx); if(app == NULL) {
if (app == NULL) {
LM_ERR("sca_call_info_ack_cb: No appearance for %.*s matching " LM_ERR("sca_call_info_ack_cb: No appearance for %.*s matching "
"call-id <%.*s> and from-tag <%.*s>\n", STR_FMT(from_aor), "call-id <%.*s> and from-tag <%.*s>\n",
- STR_FMT(&msg->callid->body), STR_FMT(&from->tag_value)); STR_FMT(from_aor), STR_FMT(&msg->callid->body),
+ STR_FMT(&msg->callid->body), STR_FMT(tag)); - STR_FMT(&from->tag_value));
+ STR_FMT(tag));
goto done; goto done;
} }
@@ -1367,11 +1374,12 @@ void sca_call_info_ack_from_handler(sip_msg_t *msg, str *from_aor, str *to_aor) @@ -1411,11 +1418,12 @@ done:
/* XXX needs extract routines */ /* XXX needs extract routines */
void sca_call_info_ack_cb(struct cell *t, int type, struct tmcb_params *params) void sca_call_info_ack_cb(struct cell *t, int type, struct tmcb_params *params)
{ {
@ -91,78 +93,80 @@ index 8b940c3..0fc0cd4 100644
int slot_idx = -1; int slot_idx = -1;
+ str *tag; + str *tag;
if (!(type & TMCB_E2EACK_IN)) { if(!(type & TMCB_E2EACK_IN)) {
return; return;
@@ -1400,8 +1408,18 @@ void sca_call_info_ack_cb(struct cell *t, int type, struct tmcb_params *params) @@ -1444,8 +1452,18 @@ void sca_call_info_ack_cb(struct cell *t, int type, struct tmcb_params *params)
} }
// on ACK, ensure SCA callee state is promoted to ACTIVE. // on ACK, ensure SCA callee state is promoted to ACTIVE.
+ if(sca->rr_api->is_direction(params->req, RR_FLOW_UPSTREAM)==0) { - app = sca_appearance_for_tags_unsafe(sca, &to_aor,
- &params->req->callid->body, &to->tag_value, NULL, slot_idx);
+ if(sca->rr_api->is_direction(params->req, RR_FLOW_UPSTREAM) == 0) {
+ LM_DBG("upstream direction detected\n"); + LM_DBG("upstream direction detected\n");
+ if (sca_get_msg_from_header(params->req, &from) < 0) { + if(sca_get_msg_from_header(params->req, &from) < 0) {
+ LM_ERR( "failed to get From-header" ); + LM_ERR("failed to get From-header");
+ goto done; + goto done;
+ } + }
+ tag = &from->tag_value; + tag = &from->tag_value;
+ } else { + } else {
+ tag = &to->tag_value; + tag = &to->tag_value;
+ } + }
app = sca_appearance_for_tags_unsafe(sca, &to_aor, + app = sca_appearance_for_tags_unsafe(
- &params->req->callid->body, &to->tag_value, NULL, slot_idx); + sca, &to_aor, &params->req->callid->body, tag, NULL, slot_idx);
+ &params->req->callid->body, tag, NULL, slot_idx); if(app && app->state == SCA_APPEARANCE_STATE_ACTIVE_PENDING) {
if (app && app->state == SCA_APPEARANCE_STATE_ACTIVE_PENDING) {
LM_DBG("promoting %.*s appearance-index %d to active\n", LM_DBG("promoting %.*s appearance-index %d to active\n",
STR_FMT(&to_aor), app->index); STR_FMT(&to_aor), app->index);
@@ -1482,6 +1500,7 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info, @@ -1528,6 +1546,7 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info,
sca_appearance *app = NULL; sca_appearance *app = NULL;
int slot_idx = -1; int slot_idx = -1;
int rc = -1; int rc = -1;
+ str *tag = NULL; + str *tag = NULL;
if (msg->first_line.type == SIP_REQUEST) { if(msg->first_line.type == SIP_REQUEST) {
if (SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) { if(SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) {
@@ -1499,15 +1518,21 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info, @@ -1545,14 +1564,20 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info,
} }
if (app == NULL) { if(app == NULL) {
// try to find it by tags // try to find it by tags
+ if(sca->rr_api->is_direction(msg, RR_FLOW_UPSTREAM)==0) { - app = sca_appearance_for_tags_unsafe(sca, from_aor,
- &msg->callid->body, &from->tag_value, NULL, slot_idx);
+ if(sca->rr_api->is_direction(msg, RR_FLOW_UPSTREAM) == 0) {
+ LM_DBG("upstream direction detected\n"); + LM_DBG("upstream direction detected\n");
+ tag = &to->tag_value; + tag = &to->tag_value;
+ } else { + } else {
+ tag = &from->tag_value; + tag = &from->tag_value;
+ } + }
app = sca_appearance_for_tags_unsafe(sca, from_aor, + app = sca_appearance_for_tags_unsafe(
- &msg->callid->body, &from->tag_value, NULL, slot_idx); + sca, from_aor, &msg->callid->body, tag, NULL, slot_idx);
+ &msg->callid->body, tag, NULL, slot_idx);
} }
if (app == NULL) { if(app == NULL) {
LM_ERR("sca_call_info_bye_handler: %.*s " LM_ERR("sca_call_info_bye_handler: %.*s "
"dialog leg %.*s;%.*s is not active\n", "dialog leg %.*s;%.*s is not active\n",
STR_FMT(from_aor), STR_FMT(from_aor), STR_FMT(&msg->callid->body),
STR_FMT(&msg->callid->body),
- STR_FMT(&from->tag_value)); - STR_FMT(&from->tag_value));
+ STR_FMT(tag)); + STR_FMT(tag));
goto done; goto done;
} }
@@ -1547,8 +1572,14 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info, @@ -1593,8 +1618,14 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info,
goto done; goto done;
} }
+ if(sca->rr_api->is_direction(msg, RR_FLOW_UPSTREAM)==0) { - app = sca_appearance_for_tags_unsafe(sca, to_aor,
- &msg->callid->body, &to->tag_value, NULL, slot_idx);
+ if(sca->rr_api->is_direction(msg, RR_FLOW_UPSTREAM) == 0) {
+ LM_DBG("upstream direction detected\n"); + LM_DBG("upstream direction detected\n");
+ tag = &from->tag_value; + tag = &from->tag_value;
+ } else { + } else {
+ tag = &to->tag_value; + tag = &to->tag_value;
+ } + }
app = sca_appearance_for_tags_unsafe(sca, to_aor, + app = sca_appearance_for_tags_unsafe(
- &msg->callid->body, &to->tag_value, + sca, to_aor, &msg->callid->body, tag, NULL, slot_idx);
+ &msg->callid->body, tag, if(app == NULL) {
NULL, slot_idx);
if (app == NULL) {
LM_INFO("sca_call_info_bye_handler: no in-use callee " LM_INFO("sca_call_info_bye_handler: no in-use callee "
"appearance for BYE %.*s from %.*s, call-ID %.*s\n",
diff --git a/src/modules/sca/sca_common.h b/src/modules/sca/sca_common.h diff --git a/src/modules/sca/sca_common.h b/src/modules/sca/sca_common.h
index acf967b..316a802 100644 index 5c4520a..3a7c1b4 100644
--- a/src/modules/sca/sca_common.h --- a/src/modules/sca/sca_common.h
+++ b/src/modules/sca/sca_common.h +++ b/src/modules/sca/sca_common.h
@@ -47,6 +47,7 @@ @@ -47,6 +47,7 @@

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save