Commit 9ad4e865 authored by Pekka Pessi's avatar Pekka Pessi

nta.c, nta.h: added nta_leg_make_replaces(), nta_leg_by_replaces().

Added tests to test_nta.c and test_nta_api.c.

darcs-hash:20060823115535-65a35-45f80cc3758c7f283d23dc6518f5d33e12f1320b.gz
parent 40cc6e5a
......@@ -3589,6 +3589,51 @@ int nta_leg_get_route(nta_leg_t *leg,
return 0;
}
/** Generate Replaces header */
SOFIAPUBFUN
sip_replaces_t *nta_leg_make_replaces(nta_leg_t *leg,
su_home_t *home,
int early_only)
{
char const *from_tag, *to_tag;
if (!leg)
return NULL;
if (!leg->leg_dialog || !leg->leg_local || !leg->leg_remote || !leg->leg_id)
return NULL;
from_tag = leg->leg_local->a_tag; if (!from_tag) from_tag = "0";
to_tag = leg->leg_remote->a_tag; if (!to_tag) to_tag = "0";
return sip_replaces_format(home, "%s;from-tag=%s;to-tag=%s%s",
leg->leg_id->i_id, from_tag, to_tag,
early_only ? ";early-only" : "");
}
/** Get dialog leg by Replaces header */
SOFIAPUBFUN
nta_leg_t *nta_leg_by_replaces(nta_agent_t *sa, sip_replaces_t const *rp)
{
nta_leg_t *leg = NULL;
if (sa && rp && rp->rp_call_id && rp->rp_from_tag && rp->rp_to_tag) {
char const *from_tag = rp->rp_from_tag, *to_tag = rp->rp_to_tag;
sip_call_id_t id[1];
sip_call_id_init(id);
id->i_hash = msg_hash_string(id->i_id = rp->rp_call_id);
leg = leg_find(sa, NULL, NULL, id, from_tag, NULL, to_tag, NULL);
if (leg == NULL && strcmp(from_tag, "0") == 0)
leg = leg_find(sa, NULL, NULL, id, NULL, NULL, to_tag, NULL);
if (leg == NULL && strcmp(to_tag, "0") == 0)
leg = leg_find(sa, NULL, NULL, id, from_tag, NULL, NULL, NULL);
}
return leg;
}
/** Calculate a simple case-insensitive hash over a string */
static inline
hash_value_t hash_istring(char const *s, char const *term, hash_value_t hash)
......
......@@ -238,6 +238,14 @@ nta_leg_t *nta_leg_by_dialog(nta_agent_t const *agent,
char const *to_tag,
url_t const *to_url);
/** Generate Replaces header */
SOFIAPUBFUN sip_replaces_t *nta_leg_make_replaces(nta_leg_t *leg,
su_home_t *home,
int early_only);
/** Get dialog leg by Replaces header */
SOFIAPUBFUN
nta_leg_t *nta_leg_by_replaces(nta_agent_t *, sip_replaces_t const *);
/* ----------------------------------------------------------------------
* 6) Prototypes for incoming transactions
*/
......
......@@ -2409,7 +2409,8 @@ int test_call(agent_t *ag)
{
sip_content_type_t *c = ag->ag_content_type;
sip_payload_t *sdp = ag->ag_payload;
nta_leg_t *old_leg;
nta_leg_t *leg, *old_leg;
sip_replaces_t *r1, *r2;
BEGIN();
......@@ -2455,6 +2456,13 @@ int test_call(agent_t *ag)
TEST(ag->ag_latest_leg, ag->ag_server_leg);
TEST_1(ag->ag_bob_leg != NULL);
TEST_1(r1 = nta_leg_make_replaces(ag->ag_alice_leg, ag->ag_home, 0));
TEST_1(r2 = sip_replaces_format(ag->ag_home, "%s;from-tag=%s;to-tag=%s",
r1->rp_call_id, r1->rp_to_tag, r1->rp_from_tag));
TEST(ag->ag_alice_leg, nta_leg_by_replaces(ag->ag_agent, r2));
TEST(ag->ag_bob_leg, nta_leg_by_replaces(ag->ag_agent, r1));
/* Re-INVITE from Bob to Alice.
*
* Alice first sends 183, waits for PRACK, then sends 184 and 185,
......
......@@ -979,6 +979,9 @@ static int api_test_errors(agent_t *ag)
TEST(nta_leg_by_dialog(NULL, NULL, NULL, NULL, NULL, NULL, NULL), NULL);
TEST(nta_leg_by_dialog(nta, NULL, NULL, NULL, NULL, NULL, NULL), NULL);
TEST(nta_leg_make_replaces(NULL, NULL, 1), NULL);
TEST(nta_leg_by_replaces(NULL, NULL), NULL);
TEST(nta_incoming_create(NULL, NULL, NULL, NULL, TAG_END()), NULL);
TEST(nta_incoming_create(nta, NULL, NULL, NULL, TAG_END()), NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment