Commit a2ac3e2e authored by Simon Morlat's avatar Simon Morlat

fix: automatically add a Content-Length: 0 when routing a message to a stream-based transport

parent 0238e5fc
......@@ -20,6 +20,7 @@
#include "event.hh"
#include "transaction.hh"
#include "common.hh"
#include "module.hh"
#include <sofia-sip/sip_protos.h>
#include <sofia-sip/su_tagarg.h>
#include <sofia-sip/msg_addr.h>
......@@ -150,6 +151,20 @@ std::shared_ptr<OutgoingTransaction> SipEvent::getOutgoingTransaction(){
return dynamic_pointer_cast<OutgoingTransaction>(getOutgoingAgent());
}
void RequestSipEvent::checkContentLength(const url_t *url){
sip_t *sip = mMsgSip->getSip();
if (sip->sip_content_length == NULL){
string transport = ModuleToolbox::urlGetTransport(url);
if (strcasecmp(transport.c_str(), "UDP") != 0){
/*if there is no Content-length and we are switching to a non-udp transport, we have to add a Content-Length, as requested by
* RFC3261 for reliable transports*/
LOGD("Automatically adding content-length because going to a stream-based transport");
sip->sip_content_length = sip_content_length_make(mMsgSip->getHome(), "0");
}
}
}
RequestSipEvent::RequestSipEvent(shared_ptr<IncomingAgent> incomingAgent,
const shared_ptr<MsgSip> &msgSip, tport_t *tport
) :
......@@ -280,6 +295,14 @@ ResponseSipEvent::ResponseSipEvent(const shared_ptr<ResponseSipEvent> &sipEvent)
SipEvent(*sipEvent), mPopVia(sipEvent->mPopVia) {
}
void ResponseSipEvent::checkContentLength(const shared_ptr<MsgSip> &msg, const sip_via_t *via){
if (msg->getSip()->sip_content_length == NULL && strcasecmp(via->v_protocol, "UDP") != 0){
/*if there is no Content-length and we are switching to a non-udp transport, we have to add a Content-Length, as requested by
* RFC3261 for reliable transports*/
LOGD("Automatically adding content-length because going to a stream-based transport");
msg->getSip()->sip_content_length = sip_content_length_make(mMsgSip->getHome(), "0");
}
}
void ResponseSipEvent::send(const shared_ptr<MsgSip> &msg, url_string_t const *u, tag_type_t tag, tag_value_t value, ...) {
if (mIncomingAgent != NULL) {
......@@ -288,6 +311,7 @@ void ResponseSipEvent::send(const shared_ptr<MsgSip> &msg, url_string_t const *u
sip_via_remove(msg->getMsg(), msg->getSip());
via_popped=true;
}
checkContentLength(msg, msg->getSip()->sip_via);
SLOGD << "Sending response:" << (via_popped ? " (via popped) " : "")<<endl<< *msg;
ta_list ta;
ta_start(ta, tag, value);
......
......@@ -190,6 +190,7 @@ public:
}
bool mRecordRouteAdded;
private:
void checkContentLength(const url_t *url);
void linkTransactions();
std::shared_ptr<tport_t> mIncomingTport;
};
......@@ -205,6 +206,7 @@ public:
~ResponseSipEvent();
private:
void checkContentLength(const std::shared_ptr<MsgSip> &msg, const sip_via_t *via);
bool mPopVia;//set to true if the response comes from an outgoing transaction.
};
......
......@@ -500,6 +500,10 @@ static const char * url_get_transport(const url_t *url){
return ret;
}
string ModuleToolbox::urlGetTransport(const url_t *url){
return url_get_transport(url);
}
bool ModuleToolbox::urlTransportMatch(const url_t *url1, const url_t *url2){
if (strcasecmp(url_get_transport(url1), url_get_transport(url2)) != 0) return false;
if (!urlHostMatch(url1->url_host, url2->url_host)) return false;
......
......@@ -233,6 +233,7 @@ class ModuleToolbox{
static bool viaContainsUrl(const sip_via_t *vias, const url_t* url);
/*returns true if the two url represent the same transport channel (IP, port and protocol)*/
static bool urlTransportMatch(const url_t *url1, const url_t *url2);
static string urlGetTransport(const url_t *url);
static void removeParamsFromContacts(su_home_t *home, sip_contact_t *c, std::list<std::string> &params);
static void removeParamsFromUrl(su_home_t *home, url_t *u, std::list<std::string> &params);
static sip_unknown_t *getCustomHeaderByName(sip_t *sip, const char *name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment