MT#62181 sip_destination: use strings

Change-Id: I924e846a9400a38dba05b7f85a5a3f4d1f3badfb
mr26.1.1
Richard Fuchs 7 months ago
parent a1a7eec0ea
commit 2561fd92e8

@ -262,11 +262,10 @@ string replaceParameters(const string& s,
}
if(!call_profile->next_hop.empty()) {
cstring _next_hop = stl2cstr(call_profile->next_hop);
list<sip_destination> dest_list;
if(parse_next_hop(_next_hop,dest_list)) {
WARN("parse_next_hop %.*s failed\n",
_next_hop.len, _next_hop.s);
if(parse_next_hop(call_profile->next_hop, dest_list)) {
WARN("parse_next_hop %s failed\n",
call_profile->next_hop.c_str());
break;
}
@ -277,7 +276,7 @@ string replaceParameters(const string& s,
const sip_destination& dest = dest_list.front();
if (s[p+1] == 'i') { // $di remote UAS IP address
res += c2stlstr(dest.host);
res += dest.host;
break;
} else if (s[p+1] == 'p') { // $dp remote UAS port
res += int2str(dest.port);

@ -193,10 +193,10 @@ int AmBasicSipDialog::getOutboundIf()
list<sip_destination> ip_list;
if(!next_hop.empty() &&
!parse_next_hop(stl2cstr(next_hop),ip_list) &&
!parse_next_hop(next_hop, ip_list) &&
!ip_list.empty()) {
dest_ip = c2stlstr(ip_list.front().host);
dest_ip = ip_list.front().host;
}
else if(!outbound_proxy.empty() &&
(remote_tag.empty() || force_outbound_proxy)) {

@ -3,7 +3,7 @@
#include "parse_common.h"
#include "log.h"
int parse_next_hop(const cstring& next_hop,
int parse_next_hop(const string& next_hop,
list<sip_destination>& dest_list)
{
enum {
@ -17,8 +17,8 @@ int parse_next_hop(const cstring& next_hop,
int st = IPL_BEG;
const char* c = next_hop.s;
const char* end = c + next_hop.len;
const char* c = next_hop.c_str();
const char* end = c + next_hop.length();
const char* beg = NULL;
sip_destination dest;
@ -48,22 +48,22 @@ int parse_next_hop(const cstring& next_hop,
break;
case ':':
st = IPL_PORT;
dest.host.set(beg,c-beg);
dest.host.assign(beg, c-beg);
break;
case '/':
st = IPL_TRSP;
dest.host.set(beg,c-beg);
dest.host.assign(beg, c-beg);
beg = c+1;
break;
case ',':
st = IPL_BEG;
dest.host.set(beg,c-beg);
dest.host.assign(beg, c-beg);
dest_list.push_back(dest);
break;
case SP:
case HTAB:
st = IPL_HOST_SEP;
dest.host.set(beg,c-beg);
dest.host.assign(beg, c-beg);
break;
default:
break;
@ -74,7 +74,7 @@ int parse_next_hop(const cstring& next_hop,
switch(*c){
case ']':
st = IPL_HOST_SEP;
dest.host.set(beg,c-beg);
dest.host.assign(beg, c-beg);
break;
default:
break;
@ -129,7 +129,7 @@ int parse_next_hop(const cstring& next_hop,
switch(*c){
case ',':
st = IPL_BEG;
dest.trsp.set(beg,c-beg);
dest.trsp.assign(beg, c-beg);
dest_list.push_back(dest);
break;
default:
@ -151,7 +151,7 @@ int parse_next_hop(const cstring& next_hop,
// possibly, the string was empty
break;
case IPL_HOST:
dest.host.set(beg,c-beg);
dest.host.assign(beg, c-beg);
dest_list.push_back(dest);
break;
case IPL_V6:
@ -160,7 +160,7 @@ int parse_next_hop(const cstring& next_hop,
dest_list.push_back(dest);
break;
case IPL_TRSP:
dest.trsp.set(beg,c-beg);
dest.trsp.assign(beg, c-beg);
dest_list.push_back(dest);
break;
}

@ -1,23 +1,24 @@
#ifndef _parse_next_hop_h_
#define _parse_next_hop_h_
#include "cstring.h"
#include <list>
#include <string>
using std::list;
using std::string;
struct sip_destination
{
cstring host;
string host;
unsigned short port;
cstring trsp;
string trsp;
sip_destination()
: host(), port(0), trsp()
{}
};
int parse_next_hop(const cstring& next_hop,
int parse_next_hop(const string& next_hop,
list<sip_destination>& dest_list);
#endif

@ -116,7 +116,7 @@ int dns_ip_entry::fill_ip_list(const list<sip_destination>& ip_list)
it != ip_list.end(); ++it) {
e.port = it->port;
ip = c2stlstr(it->host);
ip = it->host;
res = inet_pton(AF_INET6,ip.c_str(),&e.addr6);
if(res == 1) {
@ -1060,16 +1060,16 @@ int resolver::resolve_targets(const list<sip_destination>& dest_list,
sip_target t;
dns_handle h_dns;
DBG("sip_destination: %.*s:%u/%.*s",
it->host.len,it->host.s,
DBG("sip_destination: %s:%u/%s",
it->host.c_str(),
it->port,
it->trsp.len,it->trsp.s);
it->trsp.c_str());
if(set_destination_ip(it->host,it->port,it->trsp,&t.ss,&h_dns) != 0) {
if(set_destination_ip(stl2cstr(it->host), it->port, stl2cstr(it->trsp), &t.ss, &h_dns) != 0) {
ERROR("Unresolvable destination");
return -478;
}
t.trsp = c2stlstr(it->trsp);
t.trsp = it->trsp;
do {
targets->dest_list.push_back(t);

@ -34,6 +34,7 @@
#include "atomic_types.h"
#include "parse_dns.h"
#include "parse_next_hop.h"
#include "cstring.h"
#include <string>
#include <vector>

@ -768,9 +768,9 @@ static void prepare_strict_routing(sip_msg* msg, string& ext_uri_buffer)
// Ref. RFC 3261 "12.2.1.1 Generating the Request"
//
int trans_layer::set_next_hop(sip_msg& msg,
cstring& next_hop,
string& next_hop,
unsigned short& next_port,
cstring& next_trsp)
string& next_trsp)
{
static const cstring default_trsp("udp");
@ -787,12 +787,12 @@ int trans_layer::set_next_hop(sip_msg& msg,
return -1;
}
if (next_hop.len == 0) {
next_hop = route_uri->host;
if (next_hop.empty()) {
next_hop = c2stlstr(route_uri->host);
if(route_uri->port_str.len)
next_port = route_uri->port;
if(route_uri->trsp && route_uri->trsp->value.len)
next_trsp = route_uri->trsp->value;
next_trsp = c2stlstr(route_uri->trsp->value);
}
}
else {
@ -806,23 +806,22 @@ int trans_layer::set_next_hop(sip_msg& msg,
return -1;
}
DBG("setting next-hop based on request-URI\n");
next_hop = parsed_r_uri.host;
next_hop = c2stlstr(parsed_r_uri.host);
if(parsed_r_uri.port_str.len)
next_port = parsed_r_uri.port;
if(parsed_r_uri.trsp)
next_trsp = parsed_r_uri.trsp->value;
next_trsp = c2stlstr(parsed_r_uri.trsp->value);
}
if(!next_trsp.len) {
if(next_trsp.empty()) {
DBG("no transport specified, setting default one (%.*s)",
default_trsp.len,default_trsp.s);
next_trsp = default_trsp;
next_trsp = c2stlstr(default_trsp);
}
DBG("next_hop:next_port is <%.*s:%u/%.*s>\n",
next_hop.len, next_hop.s, next_port,
next_trsp.len,
next_trsp.s);
DBG("next_hop:next_port is <%s:%u/%s>\n",
next_hop.c_str(), next_port,
next_trsp.c_str());
return 0;
}
@ -1096,7 +1095,7 @@ int trans_layer::send_request(sip_msg* msg, trans_ticket* tt,
list<sip_destination> dest_list;
if (_next_hop.len) {
res = parse_next_hop(_next_hop,dest_list);
res = parse_next_hop(c2stlstr(_next_hop), dest_list);
if(res || dest_list.empty()) {
DBG("parse_next_hop %.*s failed (%i)\n",
_next_hop.len, _next_hop.s, res);

@ -257,8 +257,8 @@ protected:
* Fills the address structure passed and modifies
* R-URI and Route headers as needed.
*/
int set_next_hop(sip_msg& msg, cstring& next_hop,
unsigned short& next_port, cstring& next_trsp);
int set_next_hop(sip_msg& msg, string& next_hop,
unsigned short& next_port, string& next_trsp);
/**
* Fills the local_socket attribute using the given

Loading…
Cancel
Save