From 6b7ecc4ba910296c80c49eebfa9fc2bfd6c7e46e Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Tue, 10 Jul 2007 14:36:33 +0000 Subject: [PATCH] * Added CR before each LF in some OpenSER MI command arguments. git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@396 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- core/AmSipDialog.cpp | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/core/AmSipDialog.cpp b/core/AmSipDialog.cpp index 7bf8af73..18ccb767 100644 --- a/core/AmSipDialog.cpp +++ b/core/AmSipDialog.cpp @@ -293,6 +293,19 @@ string escape(string s) return s; } +/* Add CR before each LF */ +string lf2crlf(string s) +{ + string::size_type pos; + + pos = 0; + while ((pos = s.find("\n", pos)) != string::npos) { + s.insert(pos, "\r"); + pos = pos + 2; + } + return s; +} + int AmSipDialog::reply(const AmSipRequest& req, unsigned int code, const string& reason, @@ -327,34 +340,35 @@ int AmSipDialog::reply(const AmSipRequest& req, headers = 0; if(!m_hdrs.empty()) { - msg += "\"" + escape(m_hdrs); + msg += "\"" + lf2crlf(escape(m_hdrs)); headers = 1; } if ((req.method!="CANCEL")&& !((req.method=="BYE")&&(code<300))) { if (headers == 1) { - msg += escape(getContactHdr()); + msg += lf2crlf(escape(getContactHdr())); } else { - msg += "\"" + escape(getContactHdr()); + msg += "\"" + lf2crlf(escape(getContactHdr())); headers = 1; } } if(!body.empty()) { if (headers == 1) { - msg += "Content-Type: " + content_type + "\n"; + msg += "Content-Type: " + content_type + "\r\n"; } else { - msg += "\"Content-Type: " + content_type + "\n"; + msg += "\"Content-Type: " + content_type + "\r\n"; headers = 1; } } if (AmConfig::Signature.length()) { if (headers == 1) { - msg += "Server: " + AmConfig::Signature + "\n"; + msg += "Server: " + AmConfig::Signature + "\r\n"; } else { - msg += "\"Server: " + AmConfig::Signature + "\n"; + msg += "\"Server: " + AmConfig::Signature + "\r\n"; + headers = 1; } } @@ -684,29 +698,29 @@ int AmSipDialog::sendRequest(const string& method, + "Call-ID: " + callid + "\n"; if((method!="BYE")&&(method!="CANCEL")) - msg += escape(getContactHdr()); + msg += lf2crlf(escape(getContactHdr())); if(!m_hdrs.empty()){ - msg += escape(m_hdrs); + msg += lf2crlf(escape(m_hdrs)); if(m_hdrs[m_hdrs.length()-1] != '\n') - msg += "\n"; + msg += "\r\n"; } if(!route.empty()) - msg += getRoute(); + msg += lf2crlf(getRoute()); if(!body.empty()) - msg += "Content-Type: " + content_type + "\n"; + msg += "Content-Type: " + content_type + "\r\n"; - msg += "Max-Forwards: " MAX_FORWARDS "\n"; + msg += "Max-Forwards: " MAX_FORWARDS "\r\n"; if (AmConfig::Signature.length()) - msg += "User-Agent: " + AmConfig::Signature + "\n"; + msg += "User-Agent: " + AmConfig::Signature + "\r\n"; msg += "\"\n"; if (!body.empty()) - + "\"" + body + "\"\n"; + msg += "\"" + lf2crlf(body) + "\"\n"; if (AmServer::send_msg_replyhandler(msg)) return -1;