1 #include "fct.h"
2 
3 #include "log.h"
4 
5 #include "AmSipHeaders.h"
6 #include "AmSipMsg.h"
7 #include "AmUtils.h"
8 #include "AmUriParser.h"
9 
10 #include "../../apps/sbc/ReplacesMapper.h"
11 #include "../../apps/sbc/SBCCallRegistry.h"
12 
13 
FCTMF_SUITE_BGN(test_replaces)14 FCTMF_SUITE_BGN(test_replaces) {
15 
16     FCT_TEST_BGN(registry_simple) {
17       SBCCallRegistryEntry e = SBCCallRegistryEntry("callid2", "ltag2", "rtag2");
18       SBCCallRegistry::addCall("ltag", e);
19       fct_chk(SBCCallRegistry::lookupCall("ltag",e));
20       fct_chk(!SBCCallRegistry::lookupCall("ltag3",e));
21       SBCCallRegistry::removeCall("ltag");
22     } FCT_TEST_END();
23 
24     FCT_TEST_BGN(replaces_fixup_invite) {
25       SBCCallRegistryEntry e = SBCCallRegistryEntry("C2", "C2f", "C2t");
26       SBCCallRegistry::addCall("Ct", e);
27       SBCCallRegistryEntry e2 = SBCCallRegistryEntry("C", "Ct", "Cf");
28       SBCCallRegistry::addCall("C2f", e2);
29 
30       AmSipRequest r;
31       r.hdrs="Replaces: C;from-tag=Cf;to-tag=Ct\r\n";
32       fixReplaces(r.hdrs, true);
33       DBG("r.hdrs='%s'\n", r.hdrs.c_str());
34       fct_chk(r.hdrs=="Replaces: C2;from-tag=C2f;to-tag=C2t\r\n");
35 
36       SBCCallRegistry::removeCall("Ct");
37       SBCCallRegistry::removeCall("C2f");
38     } FCT_TEST_END();
39 
40     FCT_TEST_BGN(replaces_fixup_refer) {
41       SBCCallRegistryEntry e = SBCCallRegistryEntry("C2", "C2f", "C2t");
42       SBCCallRegistry::addCall("Ct", e);
43       SBCCallRegistryEntry e2 = SBCCallRegistryEntry("C", "Ct", "Cf");
44       SBCCallRegistry::addCall("C2f", e2);
45 
46       AmSipRequest r;
47       string orig_str = "Refer-To: \"Mr. Watson\" <sip:watson@bell-telephone.com?Replaces=C%3Bto-tag%3DCt%3Bfrom-tag%3DCf>;q=0.1";
48       string new_str = "Refer-To: \"Mr. Watson\" <sip:watson@bell-telephone.com?Replaces=C2%3Bfrom-tag%3DC2f%3Bto-tag%3DC2t>;q=0.1\r\n";
49 
50       r.hdrs=orig_str+"\r\n";
51       fixReplaces(r.hdrs, false);
52       DBG("r.hdrs='%s'\n", r.hdrs.c_str());
53       DBG("new  s='%s'\n", new_str.c_str());
54 
55       fct_chk(r.hdrs==new_str);
56 
57       SBCCallRegistry::removeCall("Ct");
58       SBCCallRegistry::removeCall("C2f");
59     } FCT_TEST_END();
60 
61     FCT_TEST_BGN(replaces_fixup_refer2) {
62       SBCCallRegistryEntry e = SBCCallRegistryEntry("C2", "C2f", "C2t");
63       SBCCallRegistry::addCall("Ct", e);
64       SBCCallRegistryEntry e2 = SBCCallRegistryEntry("C", "Ct", "Cf");
65       SBCCallRegistry::addCall("C2f", e2);
66 
67       AmSipRequest r;
68       string orig_str = "Refer-To: \"Mr. Watson\" <sip:watson@bell-telephone.com?Require=replaces;Replaces=C%3Bto-tag%3DCt%3Bfrom-tag%3DCf>;q=0.1\r\n";
69       string new_str  = "Refer-To: \"Mr. Watson\" <sip:watson@bell-telephone.com?Require=replaces;Replaces=C2%3Bfrom-tag%3DC2f%3Bto-tag%3DC2t>;q=0.1\r\n";
70 
71       r.hdrs=orig_str;
72       fixReplaces(r.hdrs, false);
73       DBG("r.hdrs='%s'\n", r.hdrs.c_str());
74       DBG("new  s='%s'\n", new_str.c_str());
75 
76       fct_chk(r.hdrs==new_str);
77 
78       SBCCallRegistry::removeCall("Ct");
79       SBCCallRegistry::removeCall("C2f");
80     } FCT_TEST_END();
81 
82     FCT_TEST_BGN(replaces_fixup_refer3) {
83       SBCCallRegistryEntry e = SBCCallRegistryEntry("C2", "C2f", "C2t");
84       SBCCallRegistry::addCall("Ct", e);
85       SBCCallRegistryEntry e2 = SBCCallRegistryEntry("C", "Ct", "Cf");
86       SBCCallRegistry::addCall("C2f", e2);
87 
88       AmSipRequest r;
89       string orig_str = "Refer-To: \"Mr. Watson\" <sip:watson@bell-telephone.com?Require=replaces;Replaces=C%3Bto-tag%3DCt%3Bfrom-tag%3DCf;Bla=Blub>;q=0.1\r\n";
90       string new_str  = "Refer-To: \"Mr. Watson\" <sip:watson@bell-telephone.com?Require=replaces;Replaces=C2%3Bfrom-tag%3DC2f%3Bto-tag%3DC2t;Bla=Blub>;q=0.1\r\n";
91 
92       r.hdrs=orig_str;
93       fixReplaces(r.hdrs, false);
94       DBG("r.hdrs='%s'\n", r.hdrs.c_str());
95       DBG("new  s='%s'\n", new_str.c_str());
96 
97       fct_chk(r.hdrs==new_str);
98 
99       SBCCallRegistry::removeCall("Ct");
100       SBCCallRegistry::removeCall("C2f");
101     } FCT_TEST_END();
102 
103 } FCTMF_SUITE_END();
104