diff --git a/core/AmSession.cpp b/core/AmSession.cpp index 8274e8e2..8827f0ae 100644 --- a/core/AmSession.cpp +++ b/core/AmSession.cpp @@ -736,9 +736,6 @@ void AmSession::onSipReply(const AmSipReply& reply, int old_dlg_status) { CALL_EVENT_H(onSipReply,reply); - // int status = dlg.getStatus(); - // dlg.updateStatus(reply); - if (old_dlg_status != dlg.getStatus()) DBG("Dialog status changed %s -> %s (stopped=%s) \n", AmSipDialog::status2str[old_dlg_status], diff --git a/core/SipCtrlInterface.h b/core/SipCtrlInterface.h index 1cec2c1f..a0a2885d 100644 --- a/core/SipCtrlInterface.h +++ b/core/SipCtrlInterface.h @@ -66,12 +66,30 @@ public: int load(); void run(const string& bind_addr, unsigned short bind_port); - + + /** + * Sends a SIP request. + * + * @param req The request to send. If the request creates a transaction, + * its ticket is written into req.tt. + */ static int send(AmSipRequest &req); - static int cancel(trans_ticket* tt); + /** + * Sends a SIP reply. + * + * @param rep The reply to be sent. 'rep.tt' should be set to transaction + * ticket included in the SIP request. + */ static int send(const AmSipReply &rep); - + + /** + * CANCELs an INVITE transaction. + * + * @param tt transaction ticket of the request to cancel. + */ + static int cancel(trans_ticket* tt); + /** * From sip_ua */ diff --git a/core/sip/trans_layer.cpp b/core/sip/trans_layer.cpp index 00c8ac48..26ba19b0 100644 --- a/core/sip/trans_layer.cpp +++ b/core/sip/trans_layer.cpp @@ -537,11 +537,16 @@ int trans_layer::send_sl_reply(sip_msg* req, int reply_code, // // Ref. RFC 3261 "12.2.1.1 Generating the Request" // -int trans_layer::set_next_hop(list& route_hdrs, - cstring& r_uri, cstring& next_hop, - unsigned short& next_port, - sockaddr_storage* remote_ip) +int trans_layer::set_next_hop(sip_msg* msg) { + assert(msg); + + list& route_hdrs = msg->route; + cstring& r_uri = msg->u.request->ruri_str; + sockaddr_storage* remote_ip = &msg->remote_ip; + + cstring next_hop; + unsigned short next_port = 0; int err=0; if(!route_hdrs.empty()){ @@ -647,10 +652,14 @@ int trans_layer::set_next_hop(list& route_hdrs, DBG("Malformed first route header\n"); case RR_PARAMS: // remove current route header from message - DBG("delete (fr=0x%p)\n",fr); - delete fr; route_hdrs.pop_front(); DBG("route_hdrs.length() = %i\n",(int)route_hdrs.size()); + { + list::iterator h_it = std::find(msg->hdrs.begin(),msg->hdrs.end(),fr); + if(h_it != msg->hdrs.end()) msg->hdrs.erase(h_it); + } + DBG("delete (fr=0x%p)\n",fr); + delete fr; break; case RR_NXT_ROUTE: @@ -663,7 +672,7 @@ int trans_layer::set_next_hop(list& route_hdrs, // copy r_uri at the end of // the route set. - route_hdrs.push_back(new sip_header(0,"Route",r_uri)); + msg->hdrs.push_back(new sip_header(0,"Route",r_uri)); r_uri = na.addr; } @@ -736,15 +745,10 @@ int trans_layer::send_request(sip_msg* msg, trans_ticket* tt) assert(msg); assert(tt); - cstring next_hop; - unsigned short next_port = 0; - tt->_bucket = 0; tt->_t = 0; - if(trans_layer::instance()->set_next_hop(msg->route,msg->u.request->ruri_str, - next_hop,next_port, - &msg->remote_ip) < 0){ + if(trans_layer::instance()->set_next_hop(msg) < 0){ DBG("set_next_hop failed\n"); return -1; diff --git a/core/sip/trans_layer.h b/core/sip/trans_layer.h index dbf2aac7..740e27b3 100644 --- a/core/sip/trans_layer.h +++ b/core/sip/trans_layer.h @@ -125,9 +125,7 @@ class trans_layer * Fills the address structure passed and modifies * R-URI and Route headers as needed. */ - int set_next_hop(list& route_hdrs, cstring& r_uri, - cstring& next_hop, unsigned short& next_port, - sockaddr_storage* remote_ip); + int set_next_hop(sip_msg* req); /** * Transaction timeout