diff --git a/core/AmSipDialog.cpp b/core/AmSipDialog.cpp index eb045f5d..762aaf00 100644 --- a/core/AmSipDialog.cpp +++ b/core/AmSipDialog.cpp @@ -33,9 +33,6 @@ void AmSipDialog::updateStatus(const AmSipRequest& req) uas_trans[req.cseq] = AmSipTransaction(req.method,req.cseq); remote_uri = req.from_uri; - sip_ip = req.dstip; - sip_port = req.port; - if(callid.empty()){ callid = req.callid; remote_tag = req.from_tag; @@ -44,7 +41,11 @@ void AmSipDialog::updateStatus(const AmSipRequest& req) local_uri = req.r_uri; remote_party = req.from; local_party = req.to; - route = req.route; + + sip_ip = req.dstip; + sip_port = req.port; + + setRoute(req.route); next_hop = req.next_hop; } } @@ -97,8 +98,8 @@ int AmSipDialog::updateStatusReply(const AmSipRequest& req, unsigned int code) } if(code >= 200){ - DBG("req.method = %s; t.method = %s; status = %i\n", - req.method.c_str(),t.method.c_str(),status); + DBG("req.method = %s; t.method = %s\n", + req.method.c_str(),t.method.c_str()); uas_trans.erase(t_it); } @@ -123,11 +124,16 @@ void AmSipDialog::updateStatus(const AmSipReply& reply) remote_tag = reply.remote_tag; // allow route overwritting - if(!reply.route.empty()) { - route = reply.route; + if(status < Connected) { + + if(!reply.route.empty()) + setRoute(reply.route); + next_hop = reply.next_hop; } + remote_uri = reply.next_request_uri; + switch(status){ case Disconnecting: if( t.method == "INVITE" ){ @@ -165,8 +171,8 @@ void AmSipDialog::updateStatus(const AmSipReply& reply) string AmSipDialog::getContactHdr() { -// if(!contact_uri.empty()) -// return contact_uri; + if(!contact_uri.empty()) + return contact_uri; contact_uri = "Contact: ::iterator it = route.begin(); + it != route.end(); it++) { + + r_set += "Route: " + *it + "\n"; + } + + return r_set; +} + +void AmSipDialog::setRoute(const string& n_route) +{ + string m_route = n_route; + if(!m_route.empty() && (m_route.find("Route: ")!=string::npos)) + m_route = m_route.substr(7/*sizeof("Route: ")*/); + + route.clear(); + while(!m_route.empty()){ + + string::size_type comma_pos; + + comma_pos = m_route.find(','); + //route += "Route: " + m_route.substr(0,comma_pos) + "\n"; + route.push_back(m_route.substr(0,comma_pos)); + + if(comma_pos != string::npos) + m_route = m_route.substr(comma_pos+1); + else + m_route = ""; + } +} diff --git a/core/AmSipDialog.h b/core/AmSipDialog.h index 67c559a4..e42d05c1 100644 --- a/core/AmSipDialog.h +++ b/core/AmSipDialog.h @@ -5,8 +5,10 @@ #include "AmSipReply.h" #include +#include #include using std::string; +using std::vector; using std::map; #define CONTACT_USER_PREFIX "sems" @@ -57,6 +59,7 @@ class AmSipDialog TransMap uac_trans; AmSipDialogEventHandler* hdl; + vector route; // record routing static int send_reply(const string& msg, const string& reply_sock); @@ -90,7 +93,9 @@ public: string remote_party; // To/From string local_party; // To/From - string route; // record routing + string getRoute(); // record routing + void setRoute(const string& n_route); + string next_hop; // next_hop for t_uac_dlg int cseq; // CSeq for next request