diff --git a/apps/registrar_client/SIPRegistrarClient.cpp b/apps/registrar_client/SIPRegistrarClient.cpp index 82122a82..2254ecff 100644 --- a/apps/registrar_client/SIPRegistrarClient.cpp +++ b/apps/registrar_client/SIPRegistrarClient.cpp @@ -132,10 +132,11 @@ void SIPRegistration::onSendRequest(const string& method, const string& content_type, const string& body, string& hdrs, + int flags, unsigned int cseq) { if (seh) seh->onSendRequest(method, content_type, body, - hdrs,cseq); + hdrs,flags,cseq); } void SIPRegistration::onSendReply(const AmSipRequest& req, @@ -143,10 +144,11 @@ void SIPRegistration::onSendReply(const AmSipRequest& req, const string& reason, const string& content_type, const string& body, - string& hdrs) { + string& hdrs, + int flags) { if (seh) seh->onSendReply(req,code,reason, - content_type,body,hdrs); + content_type,body,hdrs,flags); } SIPRegistration::RegistrationState SIPRegistration::getState() { diff --git a/apps/registrar_client/SIPRegistrarClient.h b/apps/registrar_client/SIPRegistrarClient.h index 21ad8d42..93767b86 100644 --- a/apps/registrar_client/SIPRegistrarClient.h +++ b/apps/registrar_client/SIPRegistrarClient.h @@ -105,6 +105,7 @@ class SIPRegistration : public AmSipDialogEventHandler, const string& content_type, const string& body, string& hdrs, + int flags, unsigned int cseq); void onSendReply(const AmSipRequest& req, @@ -112,7 +113,8 @@ class SIPRegistration : public AmSipDialogEventHandler, const string& reason, const string& content_type, const string& body, - string& hdrs); + string& hdrs, + int flags); // DialogControl if AmSipDialog* getDlg() { return &dlg; } // CredentialHolder diff --git a/core/AmB2BSession.cpp b/core/AmB2BSession.cpp index e4df8805..8aabb837 100644 --- a/core/AmB2BSession.cpp +++ b/core/AmB2BSession.cpp @@ -202,13 +202,13 @@ void AmB2BSession::terminateOtherLeg() void AmB2BSession::relaySip(const AmSipRequest& req) { relayed_req[dlg.cseq] = AmSipTransaction(req.method,req.cseq); - dlg.sendRequest(req.method,"application/sdp",req.body,req.hdrs); + dlg.sendRequest(req.method,"application/sdp",req.body,req.hdrs,SIP_FLAGS_VERBATIM); } void AmB2BSession::relaySip(const AmSipRequest& orig, const AmSipReply& reply) { string content_type = getHeader(reply.hdrs,"Content-Type"); - dlg.reply(orig,reply.code,reply.reason,content_type,reply.body); + dlg.reply(orig,reply.code,reply.reason,content_type,reply.body,"",SIP_FLAGS_VERBATIM); } // @@ -332,7 +332,7 @@ int AmB2BCallerSession::reinviteCaller(const AmSipReply& callee_reply) if (!content_type.length()) content_type = getHeader(callee_reply.hdrs,"Content-Type"); - return dlg.sendRequest("INVITE",content_type,callee_reply.body); + return dlg.sendRequest("INVITE",content_type,callee_reply.body, "", SIP_FLAGS_VERBATIM); } void AmB2BCallerSession::createCalleeSession() @@ -373,7 +373,7 @@ void AmB2BCalleeSession::onB2BEvent(B2BEvent* ev) relayed_req[dlg.cseq] = AmSipTransaction("INVITE", co_ev->r_cseq); } - dlg.sendRequest("INVITE",co_ev->content_type,co_ev->body,co_ev->hdrs); + dlg.sendRequest("INVITE",co_ev->content_type,co_ev->body,co_ev->hdrs,SIP_FLAGS_VERBATIM); return; } diff --git a/core/AmSession.cpp b/core/AmSession.cpp index f7c96718..de81cfbe 100644 --- a/core/AmSession.cpp +++ b/core/AmSession.cpp @@ -71,6 +71,7 @@ bool AmSessionEventHandler::onSendRequest(const string& method, const string& content_type, const string& body, string& hdrs, + int flags, unsigned int cseq) { return false; @@ -81,7 +82,8 @@ bool AmSessionEventHandler::onSendReply(const AmSipRequest& req, const string& reason, const string& content_type, const string& body, - string& hdrs) + string& hdrs, + int flags) { return false; } @@ -749,16 +751,16 @@ int AmSession::acceptAudio(const string& body, } void AmSession::onSendRequest(const string& method, const string& content_type, - const string& body, string& hdrs, unsigned int cseq) + const string& body, string& hdrs, int flags, unsigned int cseq) { - CALL_EVENT_H(onSendRequest,method,content_type,body,hdrs,cseq); + CALL_EVENT_H(onSendRequest,method,content_type,body,hdrs,flags,cseq); } void AmSession::onSendReply(const AmSipRequest& req, unsigned int code, const string& reason, const string& content_type, - const string& body, string& hdrs) + const string& body, string& hdrs, int flags) { - CALL_EVENT_H(onSendReply,req,code,reason,content_type,body,hdrs); + CALL_EVENT_H(onSendReply,req,code,reason,content_type,body,hdrs,flags); } void AmSession::onRtpTimeout() diff --git a/core/AmSession.h b/core/AmSession.h index 80c686e9..18a7763b 100644 --- a/core/AmSession.h +++ b/core/AmSession.h @@ -81,6 +81,7 @@ public: const string& content_type, const string& body, string& hdrs, + int flags, unsigned int cseq); virtual bool onSendReply(const AmSipRequest& req, @@ -88,7 +89,8 @@ public: const string& reason, const string& content_type, const string& body, - string& hdrs); + string& hdrs, + int flags); }; @@ -441,6 +443,7 @@ public: const string& content_type, const string& body, string& hdrs, + int flags, unsigned int cseq); virtual void onSendReply(const AmSipRequest& req, @@ -448,7 +451,8 @@ public: const string& reason, const string& content_type, const string& body, - string& hdrs); + string& hdrs, + int flags); }; #endif diff --git a/core/AmSipDialog.cpp b/core/AmSipDialog.cpp index 8c65b5d6..31e44b41 100644 --- a/core/AmSipDialog.cpp +++ b/core/AmSipDialog.cpp @@ -289,13 +289,14 @@ int AmSipDialog::reply(const AmSipRequest& req, const string& reason, const string& content_type, const string& body, - const string& hdrs) + const string& hdrs, + int flags) { string m_hdrs = hdrs; if(hdl) hdl->onSendReply(req,code,reason, - content_type,body,m_hdrs); + content_type,body,m_hdrs,flags); AmSipReply reply; @@ -305,6 +306,13 @@ int AmSipDialog::reply(const AmSipRequest& req, reply.serKey = req.serKey; reply.local_tag = local_tag; reply.hdrs = m_hdrs; + + if (!flags&SIP_FLAGS_VERBATIM) { + // add Signature + if (AmConfig::Signature.length()) + reply.hdrs += SIP_HDR_COLSP(SIP_HDR_SERVER) + AmConfig::Signature + CRLF; + } + if ((req.method!="CANCEL")&& !((req.method=="BYE")&&(code<300))) reply.contact = getContactHdr(); @@ -523,13 +531,14 @@ int AmSipDialog::cancel() int AmSipDialog::sendRequest(const string& method, const string& content_type, const string& body, - const string& hdrs) + const string& hdrs, + int flags) { string msg,ser_cmd; string m_hdrs = hdrs; if(hdl) - hdl->onSendRequest(method,content_type,body,m_hdrs,cseq); + hdl->onSendRequest(method,content_type,body,m_hdrs,flags,cseq); AmSipRequest req; @@ -553,6 +562,15 @@ int AmSipDialog::sendRequest(const string& method, if(!m_hdrs.empty()) req.hdrs = m_hdrs; + + if (!(flags&SIP_FLAGS_VERBATIM)) { + // add Signature + if (AmConfig::Signature.length()) + req.hdrs += SIP_HDR_COLSP(SIP_HDR_USER_AGENT) + AmConfig::Signature + CRLF; + + req.hdrs += SIP_HDR_COLSP(SIP_HDR_MAX_FORWARDS) /*TODO: configurable?!*/MAX_FORWARDS CRLF; + + } if(!route.empty()) req.route = getRoute(); diff --git a/core/AmSipDialog.h b/core/AmSipDialog.h index 9f705a3d..135b9d7d 100644 --- a/core/AmSipDialog.h +++ b/core/AmSipDialog.h @@ -37,6 +37,10 @@ using std::string; #define CONTACT_USER_PREFIX "sems" +// flags which may be used when sending request/reply +#define SIP_FLAGS_VERBATIM 1 // send request verbatim, + // i.e. modify as little as possible + /** \brief SIP transaction representation */ struct AmSipTransaction { @@ -68,6 +72,7 @@ class AmSipDialogEventHandler const string& content_type, const string& body, string& hdrs, + int flags, unsigned int cseq)=0; virtual void onSendReply(const AmSipRequest& req, @@ -75,7 +80,8 @@ class AmSipDialogEventHandler const string& reason, const string& content_type, const string& body, - string& hdrs)=0; + string& hdrs, + int flags)=0; virtual ~AmSipDialogEventHandler() {}; }; @@ -153,12 +159,14 @@ class AmSipDialog const string& reason, const string& content_type = "", const string& body = "", - const string& hdrs = ""); + const string& hdrs = "", + int flags = 0); int sendRequest(const string& method, const string& content_type = "", const string& body = "", - const string& hdrs = ""); + const string& hdrs = "", + int flags = 0); int bye(); int cancel(); diff --git a/core/AmSipHeaders.h b/core/AmSipHeaders.h index 65c9e2df..033fb5e5 100644 --- a/core/AmSipHeaders.h +++ b/core/AmSipHeaders.h @@ -11,6 +11,9 @@ #define SIP_HDR_CONTACT "Contact" #define SIP_HDR_SUPPORTED "Supported" #define SIP_HDR_REQUIRED "Required" +#define SIP_HDR_SERVER "Server" +#define SIP_HDR_USER_AGENT "User-Agent" +#define SIP_HDR_MAX_FORWARDS "Max-Forwards" #define SIP_HDR_COL(_hdr) _hdr ":" #define SIP_HDR_COLSP(_hdr) SIP_HDR_COL(_hdr) " " diff --git a/core/plug-in/sipctrl/SipCtrlInterface.cpp b/core/plug-in/sipctrl/SipCtrlInterface.cpp index 63f5de1f..0d24b39f 100644 --- a/core/plug-in/sipctrl/SipCtrlInterface.cpp +++ b/core/plug-in/sipctrl/SipCtrlInterface.cpp @@ -167,8 +167,6 @@ int SipCtrlInterface::send(const AmSipRequest &req, string &serKey) } } - msg->hdrs.push_back(new sip_header(0,"Max-Forwards","10")); // FIXME - if(!req.route.empty()){ char *c = (char*)req.route.c_str(); @@ -199,10 +197,6 @@ int SipCtrlInterface::send(const AmSipRequest &req, string &serKey) } } - if (AmConfig::Signature.length()) - msg->hdrs.push_back(new sip_header(0,"User-Agent", - stl2cstr(AmConfig::Signature))); - if(!req.hdrs.empty()) { char *c = (char*)req.hdrs.c_str(); @@ -300,12 +294,6 @@ int SipCtrlInterface::send(const AmSipReply &rep) hdrs_len += content_type_len(stl2cstr(rep.content_type)); } - if(!AmConfig::Signature.empty()) { - - hdrs_len += 10 /* "Server: " + CRLF */ - + AmConfig::Signature.length(); - } - char* hdrs_buf = NULL; char* c = hdrs_buf; @@ -314,19 +302,7 @@ int SipCtrlInterface::send(const AmSipReply &rep) c = hdrs_buf = new char[hdrs_len]; copy_hdrs_wr(&c,msg.hdrs); - - if(!AmConfig::Signature.empty()) { - - memcpy(c,"Server: ",8); - c += 8; - - memcpy(c,AmConfig::Signature.c_str(),AmConfig::Signature.length()); - c += AmConfig::Signature.length(); - - *(c++) = CR; - *(c++) = LF; - } - + if(!rep.body.empty()) { content_type_wr(&c,stl2cstr(rep.content_type)); } diff --git a/core/plug-in/unixsockctrl/UnixSocketAdapter.cpp b/core/plug-in/unixsockctrl/UnixSocketAdapter.cpp index a7adc84f..710ed39e 100644 --- a/core/plug-in/unixsockctrl/UnixSocketAdapter.cpp +++ b/core/plug-in/unixsockctrl/UnixSocketAdapter.cpp @@ -456,9 +456,6 @@ string UnixSocketAdapter::serialize(const AmSipReply &reply, string extraHdrs, bodyFrame; - if (AmConfig::Signature.length()) - extraHdrs += "Server: " + AmConfig::Signature + "\n"; - if (! reply.hdrs.empty()) extraHdrs += reply.hdrs; @@ -618,11 +615,6 @@ string UnixSocketAdapter::serialize(const AmSipRequest& req, if(!req.body.empty()) extraHdrs += "Content-Type: " + req.content_type + "\n"; - extraHdrs += "Max-Forwards: " /*TODO: configurable?!*/MAX_FORWARDS "\n"; - - if (AmConfig::Signature.length()) - extraHdrs += "User-Agent: " + AmConfig::Signature + "\n"; - #ifdef OpenSER extraHdrs = "\"" + lf2crlf(escape(extraHdrs)) + "\"\n"; #endif