From 2561fd92e8b6e8b1d0926427175052ca25feecf0 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 28 Jan 2026 09:13:47 -0400 Subject: [PATCH] MT#62181 sip_destination: use strings Change-Id: I924e846a9400a38dba05b7f85a5a3f4d1f3badfb --- apps/sbc/ParamReplacer.cpp | 9 ++++----- core/AmBasicSipDialog.cpp | 4 ++-- core/sip/parse_next_hop.cpp | 22 +++++++++++----------- core/sip/parse_next_hop.h | 11 ++++++----- core/sip/resolver.cpp | 12 ++++++------ core/sip/resolver.h | 1 + core/sip/trans_layer.cpp | 27 +++++++++++++-------------- core/sip/trans_layer.h | 4 ++-- 8 files changed, 45 insertions(+), 45 deletions(-) diff --git a/apps/sbc/ParamReplacer.cpp b/apps/sbc/ParamReplacer.cpp index 2558c9c5..beef61dd 100644 --- a/apps/sbc/ParamReplacer.cpp +++ b/apps/sbc/ParamReplacer.cpp @@ -262,11 +262,10 @@ string replaceParameters(const string& s, } if(!call_profile->next_hop.empty()) { - cstring _next_hop = stl2cstr(call_profile->next_hop); list 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); diff --git a/core/AmBasicSipDialog.cpp b/core/AmBasicSipDialog.cpp index d24548f1..b850c8de 100644 --- a/core/AmBasicSipDialog.cpp +++ b/core/AmBasicSipDialog.cpp @@ -193,10 +193,10 @@ int AmBasicSipDialog::getOutboundIf() list 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)) { diff --git a/core/sip/parse_next_hop.cpp b/core/sip/parse_next_hop.cpp index ba5177cb..78f9adde 100644 --- a/core/sip/parse_next_hop.cpp +++ b/core/sip/parse_next_hop.cpp @@ -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& 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; } diff --git a/core/sip/parse_next_hop.h b/core/sip/parse_next_hop.h index d7e2123a..e60c5871 100644 --- a/core/sip/parse_next_hop.h +++ b/core/sip/parse_next_hop.h @@ -1,23 +1,24 @@ #ifndef _parse_next_hop_h_ #define _parse_next_hop_h_ -#include "cstring.h" - #include +#include + 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& dest_list); #endif diff --git a/core/sip/resolver.cpp b/core/sip/resolver.cpp index c1f72b9e..fbb6d78c 100644 --- a/core/sip/resolver.cpp +++ b/core/sip/resolver.cpp @@ -116,7 +116,7 @@ int dns_ip_entry::fill_ip_list(const list& 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& 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); diff --git a/core/sip/resolver.h b/core/sip/resolver.h index b28bf3ea..1d4254ba 100644 --- a/core/sip/resolver.h +++ b/core/sip/resolver.h @@ -34,6 +34,7 @@ #include "atomic_types.h" #include "parse_dns.h" #include "parse_next_hop.h" +#include "cstring.h" #include #include diff --git a/core/sip/trans_layer.cpp b/core/sip/trans_layer.cpp index ec760338..a77963d3 100644 --- a/core/sip/trans_layer.cpp +++ b/core/sip/trans_layer.cpp @@ -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 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); diff --git a/core/sip/trans_layer.h b/core/sip/trans_layer.h index e27693d9..1f02b20d 100644 --- a/core/sip/trans_layer.h +++ b/core/sip/trans_layer.h @@ -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