mirror of https://github.com/sipwise/sems.git
commit
df5fb03f23
@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Stefan Sayer
|
||||
*
|
||||
* This file is part of SEMS, a free SIP media server.
|
||||
*
|
||||
* SEMS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* For a license to use the SEMS software under conditions
|
||||
* other than those described here, or to purchase support for this
|
||||
* software, please contact iptel.org by e-mail at the following addresses:
|
||||
* info@iptel.org
|
||||
*
|
||||
* SEMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "ReplacesMapper.h"
|
||||
#include "AmUtils.h"
|
||||
#include "AmUriParser.h"
|
||||
#include "AmSipHeaders.h"
|
||||
|
||||
bool findTag(const string replaces, const string& tag, size_t& p1, size_t& len);
|
||||
|
||||
void fixReplaces(AmSipRequest& req, bool is_invite) {
|
||||
|
||||
string replaces;
|
||||
string refer_to;
|
||||
AmUriParser refer_target;
|
||||
vector<string> hdrs; // headers from Refer-To URI
|
||||
vector<string>::iterator replaces_hdr_it; // Replaces header from Refer-To URI
|
||||
|
||||
DBG("Replaces handler: fixing %s request\n", is_invite?"INVITE":"REFER");
|
||||
|
||||
if (is_invite) {
|
||||
replaces = getHeader(req.hdrs, SIP_HDR_REPLACES, true);
|
||||
if (replaces.empty()) {
|
||||
DBG("Replaces handler: no Replaces in INVITE, ignoring\n");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
refer_to = getHeader(req.hdrs, SIP_HDR_REFER_TO, SIP_HDR_REFER_TO_COMPACT, true);
|
||||
if (refer_to.empty()) {
|
||||
DBG("Replaces handler: empty Refer-To header, ignoring\n");
|
||||
return;
|
||||
}
|
||||
|
||||
size_t pos=0; size_t end=0;
|
||||
if (!refer_target.parse_contact(refer_to, pos, end)) {
|
||||
DBG("Replaces handler: unable to parse Refer-To name-addr, ignoring\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (refer_target.uri_headers.empty()) {
|
||||
DBG("Replaces handler: no headers in Refer-To target, ignoring\n");
|
||||
return;
|
||||
}
|
||||
|
||||
hdrs = explode(refer_target.uri_headers, ";");
|
||||
for (replaces_hdr_it=hdrs.begin(); replaces_hdr_it != hdrs.end(); replaces_hdr_it++) {
|
||||
|
||||
string s = URL_decode(*replaces_hdr_it);
|
||||
const char* Replaces_str = "Replaces";
|
||||
if ((s.length() >= 8) &&
|
||||
!strncmp(Replaces_str, s.c_str(), 8)) {
|
||||
size_t pos = 8;
|
||||
while (s.length()>pos && (s[pos] == ' ' || s[pos] == '\t')) pos++;
|
||||
if (s[pos] != '=')
|
||||
continue;
|
||||
pos++;
|
||||
while (s.length()>pos && (s[pos] == ' ' || s[pos] == '\t')) pos++;
|
||||
replaces = s.substr(pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (replaces_hdr_it == hdrs.end()) {
|
||||
DBG("Replaces handler: no Replaces headers in Refer-To target, ignoring\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DBG("Replaces found: '%s'\n", replaces.c_str());
|
||||
size_t ftag_begin; size_t ftag_len;
|
||||
size_t ttag_begin; size_t ttag_len;
|
||||
size_t cid_len=0;
|
||||
|
||||
// todo: parse full replaces header and reconstruct including unknown params
|
||||
if (!findTag(replaces, "from-tag=", ftag_begin, ftag_len)) {
|
||||
WARN("Replaces missing 'from-tag', ignoring\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!findTag(replaces, "to-tag=", ttag_begin, ttag_len)) {
|
||||
WARN("Replaces missing 'to-tag', ignoring\n");
|
||||
return;
|
||||
}
|
||||
while (cid_len < replaces.size() && replaces[cid_len] != ';')
|
||||
cid_len++;
|
||||
|
||||
string ftag = replaces.substr(ftag_begin, ftag_len);
|
||||
string ttag = replaces.substr(ttag_begin, ttag_len);
|
||||
string callid = replaces.substr(0, cid_len);
|
||||
bool early_only = replaces.find("early-only") != string::npos;
|
||||
|
||||
DBG("Replaces handler: found callid='%s', ftag='%s', ttag='%s'\n",
|
||||
callid.c_str(), ftag.c_str(), ttag.c_str());
|
||||
|
||||
SBCCallRegistryEntry other_dlg;
|
||||
if (SBCCallRegistry::lookupCall(ttag, other_dlg)) {
|
||||
replaces = other_dlg.callid+
|
||||
";from-tag="+other_dlg.ltag+";to-tag="+other_dlg.rtag;
|
||||
if (early_only)
|
||||
replaces += ";early_only";
|
||||
DBG("Replaces handler: mapped Replaces to: '%s'\n", replaces.c_str());
|
||||
|
||||
if (is_invite) {
|
||||
removeHeader(req.hdrs, SIP_HDR_REPLACES);
|
||||
req.hdrs+=SIP_HDR_COLSP(SIP_HDR_REPLACES)+replaces+CRLF;
|
||||
} else {
|
||||
string replaces_enc = SIP_HDR_REPLACES "="+URL_encode(replaces);
|
||||
string new_hdrs;
|
||||
for (vector<string>::iterator it = hdrs.begin(); it != hdrs.end(); it++) {
|
||||
if (it != hdrs.begin())
|
||||
new_hdrs+=";";
|
||||
|
||||
if (it != replaces_hdr_it) {
|
||||
// different hdr, just add it
|
||||
new_hdrs+=*it;
|
||||
} else {
|
||||
//reconstructed replaces hdr
|
||||
new_hdrs+=replaces_enc;
|
||||
}
|
||||
}
|
||||
refer_target.uri_headers=new_hdrs;
|
||||
removeHeader(req.hdrs, SIP_HDR_REFER_TO);
|
||||
removeHeader(req.hdrs, SIP_HDR_REFER_TO_COMPACT);
|
||||
req.hdrs+=SIP_HDR_COLSP(SIP_HDR_REFER_TO)+refer_target.nameaddr_str()+CRLF;
|
||||
}
|
||||
|
||||
} else {
|
||||
DBG("Replaces handler: call with tag '%s' not found\n", ttag.c_str());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool findTag(const string replaces, const string& tag, size_t& p1, size_t& len)
|
||||
{
|
||||
size_t i = replaces.find(tag);
|
||||
if (i == string::npos) return false;
|
||||
|
||||
p1 = i+tag.length();
|
||||
size_t j = replaces.find(';', p1);
|
||||
|
||||
if (j != string::npos) {
|
||||
len = j - p1;
|
||||
} else {
|
||||
len = replaces.size() - i;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Stefan Sayer
|
||||
*
|
||||
* This file is part of SEMS, a free SIP media server.
|
||||
*
|
||||
* SEMS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* For a license to use the SEMS software under conditions
|
||||
* other than those described here, or to purchase support for this
|
||||
* software, please contact iptel.org by e-mail at the following addresses:
|
||||
* info@iptel.org
|
||||
*
|
||||
* SEMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef _ReplacesMapper_H
|
||||
#define _ReplacesMapper_H
|
||||
|
||||
#include "SBCCallRegistry.h"
|
||||
#include "AmSipMsg.h"
|
||||
|
||||
void fixReplaces(AmSipRequest& req, bool is_invite);
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Stefan Sayer
|
||||
*
|
||||
* This file is part of SEMS, a free SIP media server.
|
||||
*
|
||||
* SEMS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* For a license to use the SEMS software under conditions
|
||||
* other than those described here, or to purchase support for this
|
||||
* software, please contact iptel.org by e-mail at the following addresses:
|
||||
* info@iptel.org
|
||||
*
|
||||
* SEMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "SBCCallRegistry.h"
|
||||
#include "log.h"
|
||||
|
||||
AmMutex SBCCallRegistry::registry_mutex;
|
||||
std::map<string, SBCCallRegistryEntry> SBCCallRegistry::registry;
|
||||
|
||||
void SBCCallRegistry::addCall(const string& ltag, const SBCCallRegistryEntry& other_dlg) {
|
||||
registry_mutex.lock();
|
||||
registry[ltag] = other_dlg;
|
||||
registry_mutex.unlock();
|
||||
|
||||
DBG("SBCCallRegistry: Added call '%s' - mapped to: '%s'\n", ltag.c_str(), other_dlg.ltag.c_str());
|
||||
}
|
||||
|
||||
void SBCCallRegistry::updateCall(const string& ltag, const string& other_rtag) {
|
||||
registry_mutex.lock();
|
||||
|
||||
std::map<string, SBCCallRegistryEntry>::iterator it = registry.find(ltag);
|
||||
if (it != registry.end()) {
|
||||
it->second.rtag = other_rtag;
|
||||
}
|
||||
|
||||
registry_mutex.unlock();
|
||||
|
||||
DBG("SBCCallRegistry: Updated call '%s' - rtag to: '%s'\n", ltag.c_str(), other_rtag.c_str());
|
||||
}
|
||||
|
||||
bool SBCCallRegistry::lookupCall(const string& ltag, SBCCallRegistryEntry& other_dlg) {
|
||||
bool res = false;
|
||||
|
||||
registry_mutex.lock();
|
||||
std::map<string, SBCCallRegistryEntry>::iterator it = registry.find(ltag);
|
||||
if (it != registry.end()) {
|
||||
res = true;
|
||||
other_dlg = it->second;
|
||||
}
|
||||
registry_mutex.unlock();
|
||||
|
||||
if (res) {
|
||||
DBG("SBCCallRegistry: found call mapping '%s' -> '%s'/'%s'/'%s'\n",
|
||||
ltag.c_str(), other_dlg.ltag.c_str(), other_dlg.rtag.c_str(), other_dlg.callid.c_str());
|
||||
} else {
|
||||
DBG("SBCCallRegistry: no call mapping found for '%s'\n", ltag.c_str());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void SBCCallRegistry::removeCall(const string& ltag) {
|
||||
registry_mutex.lock();
|
||||
registry.erase(ltag);
|
||||
registry_mutex.unlock();
|
||||
|
||||
DBG("SBCCallRegistry: removed entry for call '%s'\n", ltag.c_str());
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Stefan Sayer
|
||||
*
|
||||
* This file is part of SEMS, a free SIP media server.
|
||||
*
|
||||
* SEMS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* For a license to use the SEMS software under conditions
|
||||
* other than those described here, or to purchase support for this
|
||||
* software, please contact iptel.org by e-mail at the following addresses:
|
||||
* info@iptel.org
|
||||
*
|
||||
* SEMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef _SBCCallRegistry_H
|
||||
#define _SBCCallRegistry_H
|
||||
|
||||
#include "AmThread.h"
|
||||
|
||||
#include <string>
|
||||
using std::string;
|
||||
#include <map>
|
||||
|
||||
struct SBCCallRegistryEntry
|
||||
{
|
||||
string ltag;
|
||||
string rtag;
|
||||
string callid;
|
||||
|
||||
SBCCallRegistryEntry() { }
|
||||
SBCCallRegistryEntry(const string& callid, const string& ltag, const string& rtag)
|
||||
: ltag(ltag), rtag(rtag), callid(callid) { }
|
||||
};
|
||||
|
||||
class SBCCallRegistry
|
||||
{
|
||||
static AmMutex registry_mutex;
|
||||
static std::map<string, SBCCallRegistryEntry> registry;
|
||||
|
||||
public:
|
||||
SBCCallRegistry() { }
|
||||
~SBCCallRegistry() { }
|
||||
|
||||
static void addCall(const string& ltag, const SBCCallRegistryEntry& other_dlg);
|
||||
static void updateCall(const string& ltag, const string& other_rtag);
|
||||
static bool lookupCall(const string& ltag, SBCCallRegistryEntry& other_dlg);
|
||||
static void removeCall(const string& ltag);
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,103 @@
|
||||
#include "fct.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#include "AmSipHeaders.h"
|
||||
#include "AmSipMsg.h"
|
||||
#include "AmUtils.h"
|
||||
#include "AmUriParser.h"
|
||||
|
||||
#include "../../apps/sbc/ReplacesMapper.h"
|
||||
#include "../../apps/sbc/SBCCallRegistry.h"
|
||||
|
||||
|
||||
FCTMF_SUITE_BGN(test_replaces) {
|
||||
|
||||
FCT_TEST_BGN(registry_simple) {
|
||||
SBCCallRegistryEntry e = SBCCallRegistryEntry("callid2", "ltag2", "rtag2");
|
||||
SBCCallRegistry::addCall("ltag", e);
|
||||
fct_chk(SBCCallRegistry::lookupCall("ltag",e));
|
||||
fct_chk(!SBCCallRegistry::lookupCall("ltag3",e));
|
||||
SBCCallRegistry::removeCall("ltag");
|
||||
} FCT_TEST_END();
|
||||
|
||||
FCT_TEST_BGN(replaces_fixup_invite) {
|
||||
SBCCallRegistryEntry e = SBCCallRegistryEntry("C2", "C2f", "C2t");
|
||||
SBCCallRegistry::addCall("Ct", e);
|
||||
SBCCallRegistryEntry e2 = SBCCallRegistryEntry("C", "Ct", "Cf");
|
||||
SBCCallRegistry::addCall("C2f", e2);
|
||||
|
||||
AmSipRequest r;
|
||||
r.hdrs="Replaces: C;from-tag=Cf;to-tag=Ct\r\n";
|
||||
fixReplaces(r, true);
|
||||
DBG("r.hdrs='%s'\n", r.hdrs.c_str());
|
||||
fct_chk(r.hdrs=="Replaces: C2;from-tag=C2f;to-tag=C2t\r\n");
|
||||
|
||||
SBCCallRegistry::removeCall("Ct");
|
||||
SBCCallRegistry::removeCall("C2f");
|
||||
} FCT_TEST_END();
|
||||
|
||||
FCT_TEST_BGN(replaces_fixup_refer) {
|
||||
SBCCallRegistryEntry e = SBCCallRegistryEntry("C2", "C2f", "C2t");
|
||||
SBCCallRegistry::addCall("Ct", e);
|
||||
SBCCallRegistryEntry e2 = SBCCallRegistryEntry("C", "Ct", "Cf");
|
||||
SBCCallRegistry::addCall("C2f", e2);
|
||||
|
||||
AmSipRequest r;
|
||||
string orig_str = "Refer-To: \"Mr. Watson\" <sip:watson@bell-telephone.com?Replaces=C%3Bto-tag%3DCt%3Bfrom-tag%3DCf>;q=0.1";
|
||||
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";
|
||||
|
||||
r.hdrs=orig_str+"\r\n";
|
||||
fixReplaces(r, false);
|
||||
DBG("r.hdrs='%s'\n", r.hdrs.c_str());
|
||||
DBG("new s='%s'\n", new_str.c_str());
|
||||
|
||||
fct_chk(r.hdrs==new_str);
|
||||
|
||||
SBCCallRegistry::removeCall("Ct");
|
||||
SBCCallRegistry::removeCall("C2f");
|
||||
} FCT_TEST_END();
|
||||
|
||||
FCT_TEST_BGN(replaces_fixup_refer2) {
|
||||
SBCCallRegistryEntry e = SBCCallRegistryEntry("C2", "C2f", "C2t");
|
||||
SBCCallRegistry::addCall("Ct", e);
|
||||
SBCCallRegistryEntry e2 = SBCCallRegistryEntry("C", "Ct", "Cf");
|
||||
SBCCallRegistry::addCall("C2f", e2);
|
||||
|
||||
AmSipRequest r;
|
||||
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";
|
||||
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";
|
||||
|
||||
r.hdrs=orig_str;
|
||||
fixReplaces(r, false);
|
||||
DBG("r.hdrs='%s'\n", r.hdrs.c_str());
|
||||
DBG("new s='%s'\n", new_str.c_str());
|
||||
|
||||
fct_chk(r.hdrs==new_str);
|
||||
|
||||
SBCCallRegistry::removeCall("Ct");
|
||||
SBCCallRegistry::removeCall("C2f");
|
||||
} FCT_TEST_END();
|
||||
|
||||
FCT_TEST_BGN(replaces_fixup_refer3) {
|
||||
SBCCallRegistryEntry e = SBCCallRegistryEntry("C2", "C2f", "C2t");
|
||||
SBCCallRegistry::addCall("Ct", e);
|
||||
SBCCallRegistryEntry e2 = SBCCallRegistryEntry("C", "Ct", "Cf");
|
||||
SBCCallRegistry::addCall("C2f", e2);
|
||||
|
||||
AmSipRequest r;
|
||||
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";
|
||||
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";
|
||||
|
||||
r.hdrs=orig_str;
|
||||
fixReplaces(r, false);
|
||||
DBG("r.hdrs='%s'\n", r.hdrs.c_str());
|
||||
DBG("new s='%s'\n", new_str.c_str());
|
||||
|
||||
fct_chk(r.hdrs==new_str);
|
||||
|
||||
SBCCallRegistry::removeCall("Ct");
|
||||
SBCCallRegistry::removeCall("C2f");
|
||||
} FCT_TEST_END();
|
||||
|
||||
} FCTMF_SUITE_END();
|
||||
@ -0,0 +1 @@
|
||||
|
||||
@ -0,0 +1,135 @@
|
||||
#include "fct.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#include "AmSipHeaders.h"
|
||||
#include "AmSipMsg.h"
|
||||
#include "AmUtils.h"
|
||||
#include "AmUriParser.h"
|
||||
|
||||
FCTMF_SUITE_BGN(test_uriparser) {
|
||||
|
||||
FCT_TEST_BGN(uriparser_simple) {
|
||||
AmUriParser p;
|
||||
size_t end;
|
||||
fct_chk( p.parse_contact("sip:u@d", 0, end) );
|
||||
fct_chk( p.uri_user=="u");
|
||||
fct_chk( p.uri_host=="d");
|
||||
} FCT_TEST_END();
|
||||
|
||||
FCT_TEST_BGN(uriparser_angle) {
|
||||
AmUriParser p;
|
||||
size_t end;
|
||||
fct_chk( p.parse_contact("<sip:u@d>", 0, end) );
|
||||
fct_chk( p.uri_user=="u");
|
||||
fct_chk( p.uri_host=="d");
|
||||
} FCT_TEST_END();
|
||||
|
||||
FCT_TEST_BGN(uriparser_angle_param) {
|
||||
AmUriParser p;
|
||||
size_t end;
|
||||
fct_chk( p.parse_contact("<sip:u@d>;tag=123", 0, end) );
|
||||
fct_chk( p.uri_user=="u");
|
||||
fct_chk( p.uri_host=="d");
|
||||
fct_chk( p.params["tag"]=="123");
|
||||
} FCT_TEST_END();
|
||||
|
||||
FCT_TEST_BGN(uriparser_uri_param) {
|
||||
AmUriParser p;
|
||||
size_t end;
|
||||
fct_chk( p.parse_contact("<sip:u@d;tag=123>", 0, end) );
|
||||
fct_chk( p.uri_user=="u");
|
||||
fct_chk( p.uri_host=="d");
|
||||
fct_chk( p.uri_param=="tag=123");
|
||||
} FCT_TEST_END();
|
||||
|
||||
FCT_TEST_BGN(uriparser_params_nobracket) {
|
||||
AmUriParser p;
|
||||
size_t end;
|
||||
fct_chk( p.parse_contact("sip:u@d;tag=123", 0, end) );
|
||||
fct_chk( p.uri_user=="u");
|
||||
fct_chk( p.uri_host=="d");
|
||||
fct_chk( p.params["tag"]=="123");
|
||||
} FCT_TEST_END();
|
||||
|
||||
FCT_TEST_BGN(uriparser_params_dname) {
|
||||
AmUriParser p;
|
||||
size_t end;
|
||||
fct_chk( p.parse_contact("hu <sip:u@d;tag=123>", 0, end) );
|
||||
// DBG("DN:: '%s'\n", p.display_name.c_str());
|
||||
fct_chk( p.display_name=="hu");
|
||||
fct_chk( p.uri_user=="u");
|
||||
fct_chk( p.uri_host=="d");
|
||||
} FCT_TEST_END();
|
||||
|
||||
FCT_TEST_BGN(uriparser_params_dname2) {
|
||||
AmUriParser p;
|
||||
size_t end;
|
||||
fct_chk( p.parse_contact(" hu bar <sip:u@d;tag=123>", 0, end) );
|
||||
// DBG("DN:: '%s'\n", p.display_name.c_str());
|
||||
|
||||
fct_chk( p.display_name=="hu bar");
|
||||
fct_chk( p.uri_user=="u");
|
||||
fct_chk( p.uri_host=="d");
|
||||
} FCT_TEST_END();
|
||||
|
||||
FCT_TEST_BGN(uriparser_params_dname3) {
|
||||
AmUriParser p;
|
||||
size_t end;
|
||||
fct_chk( p.parse_contact(" \"hu bar\" <sip:u@d;tag=123>", 0, end) );
|
||||
fct_chk( p.display_name=="hu bar");
|
||||
fct_chk( p.uri_user=="u");
|
||||
fct_chk( p.uri_host=="d");
|
||||
} FCT_TEST_END();
|
||||
|
||||
FCT_TEST_BGN(uriparser_params_dname4) {
|
||||
AmUriParser p;
|
||||
size_t end;
|
||||
fct_chk( p.parse_contact(" \"hu bar\\\\ \" <sip:u@d;tag=123>", 0, end) );
|
||||
fct_chk( p.display_name=="hu bar\\\\ ");
|
||||
fct_chk( p.uri_user=="u");
|
||||
fct_chk( p.uri_host=="d");
|
||||
} FCT_TEST_END();
|
||||
|
||||
FCT_TEST_BGN(uriparser_params_dname4) {
|
||||
AmUriParser p;
|
||||
size_t end;
|
||||
fct_chk(p.parse_contact("\"Mr. Watson\" <mailto:watson@bell-telephone.com> ;q=0.1", 0, end));
|
||||
fct_chk( p.display_name=="Mr. Watson");
|
||||
fct_chk( p.uri_user=="watson");
|
||||
fct_chk( p.uri_host=="bell-telephone.com");
|
||||
} FCT_TEST_END();
|
||||
|
||||
FCT_TEST_BGN(uriparser_headers) {
|
||||
AmUriParser p;
|
||||
size_t end;
|
||||
fct_chk(p.parse_contact("\"Mr. Watson\" <mailto:watson@bell-telephone.com?Replaces:%20lkancskjd%3Bto-tag=3123141ab%3Bfrom-tag=kjhkjcsd> ;q=0.1", 0, end));
|
||||
fct_chk( p.display_name=="Mr. Watson");
|
||||
fct_chk( p.uri_user=="watson");
|
||||
fct_chk( p.uri_host=="bell-telephone.com");
|
||||
fct_chk( p.uri_headers=="Replaces:\%20lkancskjd%3Bto-tag=3123141ab%3Bfrom-tag=kjhkjcsd");
|
||||
} FCT_TEST_END();
|
||||
|
||||
FCT_TEST_BGN(uriparser_headers_str) {
|
||||
AmUriParser p;
|
||||
string orig_str = "\"Mr. Watson\" <sip:watson@bell-telephone.com?Replaces:%20lkancskjd%3Bto-tag=3123141ab%3Bfrom-tag=kjhkjcsd>;q=0.1";
|
||||
fct_chk(p.parse_nameaddr(orig_str));
|
||||
fct_chk( p.display_name=="Mr. Watson");
|
||||
fct_chk( p.uri_user=="watson");
|
||||
fct_chk( p.uri_host=="bell-telephone.com");
|
||||
fct_chk( p.uri_headers=="Replaces:\%20lkancskjd%3Bto-tag=3123141ab%3Bfrom-tag=kjhkjcsd");
|
||||
string a_str = p.nameaddr_str();
|
||||
// DBG(" >>%s<< => >>%s<<\n", orig_str.c_str(), a_str.c_str());
|
||||
fct_chk(orig_str == a_str);
|
||||
} FCT_TEST_END();
|
||||
|
||||
FCT_TEST_BGN(uriparser_url_escape) {
|
||||
string src = "Replaces: CSADFSD;from-tag=31241231abc;to-tag=235123";
|
||||
string dst = "Replaces%3A%20CSADFSD%3Bfrom-tag%3D31241231abc%3Bto-tag%3D235123";
|
||||
fct_chk ( URL_decode(dst)==src );
|
||||
fct_chk ( URL_encode(src)==dst );
|
||||
fct_chk ( URL_decode(URL_encode(src))==src );
|
||||
|
||||
} FCT_TEST_END();
|
||||
|
||||
} FCTMF_SUITE_END();
|
||||
Loading…
Reference in new issue