Commit 891de826 authored by Yann Diorcet's avatar Yann Diorcet

Fix 487 issue on mediarelay module

Add log on RelaySession

Fix MediaRelay issues
Add/Modify log
parent 6c571fb4
......@@ -20,7 +20,7 @@
<folderInfo id="0.705448153." name="/" resourcePath="">
<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.1656713817" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
<targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.1656713817.1875049041" name=""/>
<builder id="org.eclipse.cdt.build.core.settings.default.builder.1433955799" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
<builder arguments="CLFAGS=&quot;-g -pthread&quot; CXXFLAGS=&quot;-g -pthread -std=c++0x&quot;" command="make" id="org.eclipse.cdt.build.core.settings.default.builder.1433955799" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.12566806" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.1848582440" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1152505156" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
......@@ -41,7 +41,9 @@
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="flexisip.null.1524628130" name="flexisip"/>
</storageModule>
<storageModule moduleId="refreshScope"/>
<storageModule moduleId="refreshScope" versionNumber="1">
<resource resourceType="PROJECT" workspacePath="/flexisip"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="0.705448153">
......
......@@ -23,7 +23,7 @@
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildArguments</key>
<value></value>
<value>CLFAGS=&quot;-g -pthread&quot; CXXFLAGS=&quot;-g -pthread -std=c++0x&quot;</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildCommand</key>
......@@ -59,7 +59,7 @@
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
<value>true</value>
<value>false</value>
</dictionary>
</arguments>
</buildCommand>
......
......@@ -92,20 +92,21 @@ static int get_local_ip_for_with_connect(int type, const char *dest, char *resul
return 0;
}
Agent::Agent(su_root_t* root, int port, int tlsport) : mPort(port), mTlsPort(tlsport) {
char sipuri[128]={0};
GenericStruct *cr=GenericManager::get()->getRoot();
GenericStruct *tls=cr->get<GenericStruct>("tls");
Agent::Agent(su_root_t* root, int port, int tlsport) :
mPort(port), mTlsPort(tlsport) {
char sipuri[128] = { 0 };
GenericStruct *cr = GenericManager::get()->getRoot();
GenericStruct *tls = cr->get<GenericStruct>("tls");
EtcHostsResolver::get();
mModules.push_back(ModuleFactory::get()->createModuleInstance(this,"NatHelper"));
mModules.push_back(ModuleFactory::get()->createModuleInstance(this,"Authentication"));
mModules.push_back(ModuleFactory::get()->createModuleInstance(this,"GatewayAdapter"));
mModules.push_back(ModuleFactory::get()->createModuleInstance(this,"Registrar"));
mModules.push_back(ModuleFactory::get()->createModuleInstance(this,"ContactRouteInserter"));
mModules.push_back(ModuleFactory::get()->createModuleInstance(this,"LoadBalancer"));
mModules.push_back(ModuleFactory::get()->createModuleInstance(this,"MediaRelay"));
mModules.push_back(ModuleFactory::get()->createModuleInstance(this, "NatHelper"));
mModules.push_back(ModuleFactory::get()->createModuleInstance(this, "Authentication"));
mModules.push_back(ModuleFactory::get()->createModuleInstance(this, "GatewayAdapter"));
mModules.push_back(ModuleFactory::get()->createModuleInstance(this, "Registrar"));
mModules.push_back(ModuleFactory::get()->createModuleInstance(this, "ContactRouteInserter"));
mModules.push_back(ModuleFactory::get()->createModuleInstance(this, "LoadBalancer"));
mModules.push_back(ModuleFactory::get()->createModuleInstance(this, "MediaRelay"));
#ifdef ENABLE_TRANSCODER
mModules.push_back(ModuleFactory::get()->createModuleInstance(this,"Transcoder"));
#endif
......@@ -118,15 +119,18 @@ Agent::Agent(su_root_t* root, int port, int tlsport) : mPort(port), mTlsPort(tls
for_each(mModules.begin(), mModules.end(), bind2nd(mem_fun(&Module::declare), cr));
/* we pass "" as localaddr when we just want to dump the default config. So don't go further*/
if (mPort==0) return;
if (mPort == 0)
return;
if (mPort==-1) mPort=cr->get<GenericStruct>("global")->get<ConfigInt>("port")->read();
if (mTlsPort==-1) mTlsPort=tls->get<ConfigInt>("port")->read();
if (mPort == -1)
mPort = cr->get<GenericStruct>("global")->get<ConfigInt>("port")->read();
if (mTlsPort == -1)
mTlsPort = tls->get<ConfigInt>("port")->read();
std::string bind_address=cr->get<GenericStruct>("global")->get<ConfigString>("bind-address")->read();
mPublicIp=cr->get<GenericStruct>("global")->get<ConfigString>("ip-address")->read();
if (mPublicIp.empty() || mPublicIp=="guess"){
string bind_address = cr->get<GenericStruct>("global")->get<ConfigString>("bind-address")->read();
mPublicIp = cr->get<GenericStruct>("global")->get<ConfigString>("ip-address")->read();
if (mPublicIp.empty() || mPublicIp == "guess") {
char localip[128];
get_local_ip_for_with_connect(AF_INET, "209.85.229.147", localip);
mPublicIp = localip;
......@@ -138,34 +142,28 @@ Agent::Agent(su_root_t* root, int port, int tlsport) : mPort(port), mTlsPort(tls
oss << mPublicIp << "_" << mPort;
mUniqueId = oss.str();
ostringstream transportUri;
mRoot=root;
snprintf(sipuri,sizeof(sipuri)-1,"sip:%s:%i;maddr=%s", mPublicIp.c_str(),mPort,bind_address.c_str());
LOGD("Enabling 'sip' listening point with uri '%s'.",sipuri);
mAgent=nta_agent_create(root,
(url_string_t*)sipuri,
&Agent::messageCallback,
(nta_agent_magic_t*)this,
NTATAG_CLIENT_RPORT(1),NTATAG_UDP_MTU(1460), TAG_END());
if (mAgent==NULL){
mRoot = root;
snprintf(sipuri, sizeof(sipuri) - 1, "sip:%s:%i;maddr=%s", mPublicIp.c_str(), mPort, bind_address.c_str());
LOGD("Enabling 'sip' listening point with uri '%s'.", sipuri);
mAgent = nta_agent_create(root, (url_string_t*) sipuri, &Agent::messageCallback, (nta_agent_magic_t*) this, NTATAG_CLIENT_RPORT(1), NTATAG_UDP_MTU(1460), TAG_END());
if (mAgent == NULL) {
LOGF("Could not create sofia mta, certainly SIP ports already in use.");
}
transportUri<<"<"<<sipuri<<">";
transportUri << "<" << sipuri << ">";
if (tls->get<ConfigBoolean>("enabled")->read()) {
string keys=tls->get<ConfigString>("certificates-dir")->read();
snprintf(sipuri,sizeof(sipuri)-1,"sips:%s:%i;maddr=%s", mPublicIp.c_str(),mTlsPort,bind_address.c_str());
LOGD("Enabling 'sips' listening point with uri '%s', keys in %s", sipuri,keys.c_str());
nta_agent_add_tport(mAgent,
(url_string_t*)sipuri,
TPTAG_CERTIFICATE(keys.c_str()), NTATAG_CLIENT_RPORT(1),NTATAG_UDP_MTU(1460), NTATAG_TLS_RPORT(1), TAG_END());
transportUri<<",<"<<sipuri<<">";
string keys = tls->get<ConfigString>("certificates-dir")->read();
snprintf(sipuri, sizeof(sipuri) - 1, "sips:%s:%i;maddr=%s", mPublicIp.c_str(), mTlsPort, bind_address.c_str());
LOGD("Enabling 'sips' listening point with uri '%s', keys in %s", sipuri, keys.c_str());
nta_agent_add_tport(mAgent, (url_string_t*) sipuri, TPTAG_CERTIFICATE(keys.c_str()), NTATAG_CLIENT_RPORT(1), NTATAG_UDP_MTU(1460), NTATAG_TLS_RPORT(1), TAG_END());
transportUri << ",<" << sipuri << ">";
}
mTransportUri=transportUri.str();
if (bind_address=="*"){
bind_address="0.0.0.0";
mTransportUri = transportUri.str();
if (bind_address == "*") {
bind_address = "0.0.0.0";
}
mBindIp=bind_address;
mBindIp = bind_address;
oss.str(mPreferredRoute);
oss << "sip:";
......@@ -189,9 +187,9 @@ const char *Agent::getServerString() const {
return mServerString.c_str();
}
void Agent::loadConfig(GenericManager *cm){
cm->loadStrict();//now that each module has declared its settings, we need to reload from the config file
mAliases=cm->getGlobal()->get<ConfigStringList>("aliases")->read();
void Agent::loadConfig(GenericManager *cm) {
cm->loadStrict(); //now that each module has declared its settings, we need to reload from the config file
mAliases = cm->getGlobal()->get<ConfigStringList>("aliases")->read();
discoverInterfaces();
LOGD("List of host aliases:");
for (list<string>::iterator it = mAliases.begin(); it != mAliases.end(); ++it) {
......@@ -255,6 +253,7 @@ bool Agent::isUs(const url_t *url, bool check_aliases) const {
}
void Agent::sendRequestEvent(shared_ptr<SipEvent> &ev) {
LOG_START
ev->getMsgSip()->log("Receiving new Request SIP message:");
list<Module*>::iterator it;
for (it = mModules.begin(); it != mModules.end(); ++it) {
......@@ -266,9 +265,11 @@ void Agent::sendRequestEvent(shared_ptr<SipEvent> &ev) {
if (!ev->isTerminated() && !ev->isSuspended()) {
LOGA("Event not handled");
}
LOG_END
}
void Agent::sendResponseEvent(shared_ptr<SipEvent> &ev) {
LOG_START
ev->getMsgSip()->log("Receiving new Response SIP message:");
list<Module*>::iterator it;
for (it = mModules.begin(); it != mModules.end(); ++it) {
......@@ -280,9 +281,11 @@ void Agent::sendResponseEvent(shared_ptr<SipEvent> &ev) {
if (!ev->isTerminated() && !ev->isSuspended()) {
LOGA("Event not handled");
}
LOG_END
}
void Agent::injectRequestEvent(shared_ptr<SipEvent> &ev) {
LOG_START
ev->getMsgSip()->log("Inject Request SIP message:");
list<Module*>::iterator it;
ev->restartProcessing();
......@@ -302,9 +305,11 @@ void Agent::injectRequestEvent(shared_ptr<SipEvent> &ev) {
if (!ev->isTerminated() && !ev->isSuspended()) {
LOGA("Event not handled");
}
LOG_END
}
void Agent::injectResponseEvent(shared_ptr<SipEvent> &ev) {
LOG_START
ev->getMsgSip()->log("Inject Response SIP message:");
list<Module*>::iterator it;
ev->restartProcessing();
......@@ -324,14 +329,17 @@ void Agent::injectResponseEvent(shared_ptr<SipEvent> &ev) {
if (!ev->isTerminated() && !ev->isSuspended()) {
LOGA("Event not handled");
}
LOG_END
}
void Agent::sendTransactionEvent(const std::shared_ptr<Transaction> &transaction, Transaction::Event event) {
void Agent::sendTransactionEvent(const shared_ptr<Transaction> &transaction, Transaction::Event event) {
LOG_START
LOGD("Receiving new Transaction Event %p %i", transaction.get(), event);
list<Module*>::iterator it;
for (it = mModules.begin(); it != mModules.end(); ++it) {
(*it)->processTransactionEvent(transaction, event);
}
LOG_END
}
int Agent::onIncomingMessage(msg_t *msg, sip_t *sip) {
......@@ -340,8 +348,7 @@ int Agent::onIncomingMessage(msg_t *msg, sip_t *sip) {
if (sip->sip_request) {
shared_ptr<SipEvent> ev(new RequestSipEvent(dynamic_pointer_cast<IncomingAgent>(shared_from_this()), ms));
sendRequestEvent(ev);
}
else {
} else {
shared_ptr<SipEvent> ev(new ResponseSipEvent(dynamic_pointer_cast<OutgoingAgent>(shared_from_this()), ms));
sendResponseEvent(ev);
}
......@@ -392,7 +399,7 @@ void Agent::discoverInterfaces() {
freeifaddrs(ifpstart);
}
void Agent::send(const std::shared_ptr<MsgSip> &ms, url_string_t const *u, tag_type_t tag, tag_value_t value, ...) {
void Agent::send(const shared_ptr<MsgSip> &ms, url_string_t const *u, tag_type_t tag, tag_value_t value, ...) {
ta_list ta;
ta_start(ta, tag, value);
msg_t* msg = msg_dup(ms->getMsg());
......@@ -400,12 +407,12 @@ void Agent::send(const std::shared_ptr<MsgSip> &ms, url_string_t const *u, tag_t
ta_end(ta);
}
void Agent::send(const std::shared_ptr<MsgSip> &ms) {
void Agent::send(const shared_ptr<MsgSip> &ms) {
msg_t* msg = msg_dup(ms->getMsg());
nta_msg_tsend(mAgent, msg, NULL, TAG_END());
}
void Agent::reply(const std::shared_ptr<MsgSip> &ms, int status, char const *phrase, tag_type_t tag, tag_value_t value, ...) {
void Agent::reply(const shared_ptr<MsgSip> &ms, int status, char const *phrase, tag_type_t tag, tag_value_t value, ...) {
ta_list ta;
ta_start(ta, tag, value);
msg_t* msg = msg_dup(ms->getMsg());
......
......@@ -178,20 +178,20 @@ CallStore::CallStore() : mCountCalls(NULL),mCountCallsFinished(NULL){
CallStore::~CallStore(){
}
void CallStore::store(const std::shared_ptr<CallContextBase> &ctx){
void CallStore::store(const shared_ptr<CallContextBase> &ctx){
if (mCountCalls) ++(*mCountCalls);
mCalls.push_back(ctx);
}
std::shared_ptr<CallContextBase> CallStore::find(Agent *ag, sip_t *sip, bool stateful){
shared_ptr<CallContextBase> CallStore::find(Agent *ag, sip_t *sip, bool stateful){
for(auto it=mCalls.begin();it!=mCalls.end();++it){
if ((*it)->match(ag,sip, stateful))
return *it;
}
return std::shared_ptr<CallContextBase>();
return shared_ptr<CallContextBase>();
}
void CallStore::remove(const std::shared_ptr<CallContextBase> &ctx){
void CallStore::remove(const shared_ptr<CallContextBase> &ctx){
if (mCountCallsFinished) ++(*mCountCallsFinished);
mCalls.remove(ctx);
}
......
......@@ -24,6 +24,7 @@
#include <cstdarg>
#include <ortp/ortp.h>
#include <map>
#include <sys/timeb.h>
extern bool sUseSyslog;
......@@ -58,6 +59,30 @@ extern bool sUseSyslog;
exit(-1); \
}while(0);
#define LOG_START { \
if(IS_LOGD) { \
char ___buffer[32]; \
struct timeb ___rawtime; \
struct tm *___gmtime; \
ftime ( &___rawtime ); \
___gmtime = gmtime ( &___rawtime.time ); \
strftime(___buffer, 64, "%x %X", ___gmtime); \
LOGD(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>%s.%03d>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", ___buffer, ___rawtime.millitm); \
} \
}
#define LOG_END { \
if(IS_LOGD) { \
char ___buffer[32]; \
struct timeb ___rawtime; \
struct tm *___gmtime; \
ftime ( &___rawtime ); \
___gmtime = gmtime ( &___rawtime.time ); \
strftime(___buffer, 64, "%x %X", ___gmtime); \
LOGD("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<%s.%03d<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<", ___buffer, ___rawtime.millitm); \
} \
}
class Mutex{
public:
Mutex(bool reentrant = false);
......
......@@ -221,7 +221,7 @@ void StatCounter64::setParent(GenericEntry *parent){
#endif
}
GenericStruct::GenericStruct(const std::string &name, const std::string &help,oid oid_index) : GenericEntry(name,Struct,help,oid_index){
GenericStruct::GenericStruct(const string &name, const string &help,oid oid_index) : GenericEntry(name,Struct,help,oid_index){
}
void GenericStruct::setParent(GenericEntry *parent){
......@@ -317,12 +317,12 @@ struct matchEntryNameApprox{
};
GenericEntry * GenericStruct::findApproximate(const char *name)const{
std::list<GenericEntry*>::const_iterator it=find_if(mEntries.begin(),mEntries.end(),matchEntryNameApprox(name));
list<GenericEntry*>::const_iterator it=find_if(mEntries.begin(),mEntries.end(),matchEntryNameApprox(name));
if (it!=mEntries.end()) return *it;
return NULL;
}
std::list<GenericEntry*> &GenericStruct::getChildren(){
list<GenericEntry*> &GenericStruct::getChildren(){
return mEntries;
}
......@@ -337,7 +337,7 @@ GenericStruct::~GenericStruct(){
}
ConfigBoolean::ConfigBoolean(const std::string &name, const std::string &help, const std::string &default_value,oid oid_index)
ConfigBoolean::ConfigBoolean(const string &name, const string &help, const string &default_value,oid oid_index)
: ConfigValue(name, Boolean, help, default_value,oid_index){
}
......@@ -350,7 +350,7 @@ bool ConfigBoolean::read()const{
}
ConfigInt::ConfigInt(const std::string &name, const std::string &help, const std::string &default_value,oid oid_index)
ConfigInt::ConfigInt(const string &name, const string &help, const string &default_value,oid oid_index)
: ConfigValue(name,Integer,help,default_value,oid_index){
}
......@@ -358,21 +358,21 @@ int ConfigInt::read()const{
return atoi(get().c_str());
}
StatCounter64::StatCounter64(const std::string &name, const std::string &help, oid oid_index)
StatCounter64::StatCounter64(const string &name, const string &help, oid oid_index)
: GenericEntry(name,Counter64,help,oid_index){
mValue=0;
}
ConfigString::ConfigString(const std::string &name, const std::string &help, const std::string &default_value,oid oid_index)
ConfigString::ConfigString(const string &name, const string &help, const string &default_value,oid oid_index)
: ConfigValue(name,String,help,default_value,oid_index){
}
const std::string & ConfigString::read()const{
const string & ConfigString::read()const{
return get();
}
ConfigStringList::ConfigStringList(const std::string &name, const std::string &help, const std::string &default_value,oid oid_index)
ConfigStringList::ConfigStringList(const string &name, const string &help, const string &default_value,oid oid_index)
: ConfigValue(name,StringList,help,default_value,oid_index){
}
......@@ -462,7 +462,7 @@ static ConfigItemDescriptor tls_conf[]={
};
RootConfigStruct::RootConfigStruct(const std::string &name, const std::string &help,vector<oid> oid_root_path)
RootConfigStruct::RootConfigStruct(const string &name, const string &help,vector<oid> oid_root_path)
: GenericStruct(name,help,1) {
mOid = new Oid(oid_root_path,1);
}
......@@ -513,7 +513,7 @@ ostream & FileConfigDumper::printHelp(ostream &os, const string &help, const str
return os;
}
std::ostream &FileConfigDumper::dump2(ostream & ostr, GenericEntry *entry, int level)const{
ostream &FileConfigDumper::dump2(ostream & ostr, GenericEntry *entry, int level)const{
GenericStruct *cs=dynamic_cast<GenericStruct*>(entry);
ConfigValue *val;
......@@ -537,10 +537,10 @@ std::ostream &FileConfigDumper::dump2(ostream & ostr, GenericEntry *entry, int l
return ostr;
}
std::ostream &MibDumper::dump(std::ostream & ostr)const {
const std::time_t t = std::time(NULL);
ostream &MibDumper::dump(ostream & ostr)const {
const time_t t = time(NULL);
char mbstr[100];
strftime(mbstr, sizeof(mbstr), "%Y%m%d0000Z", std::localtime(&t));
strftime(mbstr, sizeof(mbstr), "%Y%m%d0000Z", localtime(&t));
ostr << "FLEXISIP-MIB DEFINITIONS ::= BEGIN" << endl
<< "IMPORTS" << endl
......@@ -562,7 +562,7 @@ std::ostream &MibDumper::dump(std::ostream & ostr)const {
return ostr;
}
std::ostream &MibDumper::dump2(std::ostream & ostr, GenericEntry *entry, int level)const{
ostream &MibDumper::dump2(ostream & ostr, GenericEntry *entry, int level)const{
GenericStruct *cs=dynamic_cast<GenericStruct*>(entry);
ConfigValue *cVal;
StatCounter64 *sVal;
......@@ -572,11 +572,11 @@ std::ostream &MibDumper::dump2(std::ostream & ostr, GenericEntry *entry, int lev
--level;
}
if (cs){
std::list<GenericEntry*>::iterator it;
list<GenericEntry*>::iterator it;
cs->mibFragment(ostr, spacing);
for(it=cs->getChildren().begin();it!=cs->getChildren().end();++it){
dump2(ostr,*it,level+1);
ostr<<std::endl;
ostr<<endl;
}
}else if ((cVal=dynamic_cast<ConfigValue*>(entry))!=NULL){
cVal->mibFragment(ostr, spacing);
......
......@@ -57,15 +57,22 @@ MsgSip::~MsgSip() {
msg_destroy(mMsg);
}
SipEvent::SipEvent(const std::shared_ptr<MsgSip> msgSip) :
SipEvent::SipEvent(const shared_ptr<MsgSip> msgSip) :
mCurrModule(NULL), mMsgSip(msgSip), mState(STARTED) {
LOGD("New SipEvent %p", this);
}
SipEvent::SipEvent(const SipEvent &sipEvent) :
mCurrModule(sipEvent.mCurrModule), mMsgSip(sipEvent.mMsgSip), mIncomingAgent(sipEvent.mIncomingAgent), mOutgoingAgent(sipEvent.mOutgoingAgent), mState(sipEvent.mState) {
LOGD("New SipEvent %p", this);
}
SipEvent::~SipEvent() {
LOGD("Destroy SipEvent %p", this);
}
void SipEvent::terminateProcessing() {
LOGD("Terminate SipEvent %p", this);
if (mState == STARTED || mState == SUSPENDED) {
mState = TERMINATED;
} else {
......@@ -74,7 +81,7 @@ void SipEvent::terminateProcessing() {
}
void SipEvent::suspendProcessing() {
LOGD("Suspend SipEvent");
LOGD("Suspend SipEvent %p", this);
if (mState == STARTED) {
mState = SUSPENDED;
} else {
......@@ -83,6 +90,7 @@ void SipEvent::suspendProcessing() {
}
void SipEvent::restartProcessing() {
LOGD("Restart SipEvent %p", this);
if (mState == SUSPENDED) {
mState = STARTED;
} else {
......@@ -115,9 +123,8 @@ RequestSipEvent::RequestSipEvent(const shared_ptr<IncomingAgent> &incomingAgent,
mOutgoingAgent = incomingAgent->getAgent()->shared_from_this();
}
RequestSipEvent::RequestSipEvent(const std::shared_ptr<SipEvent> &sipEvent, const std::shared_ptr<MsgSip> &msgSip) :
RequestSipEvent::RequestSipEvent(const shared_ptr<SipEvent> &sipEvent) :
SipEvent(*sipEvent) {
mMsgSip = msgSip;
}
void RequestSipEvent::send(const shared_ptr<MsgSip> &msg, url_string_t const *u, tag_type_t tag, tag_value_t value, ...) {
......@@ -127,6 +134,8 @@ void RequestSipEvent::send(const shared_ptr<MsgSip> &msg, url_string_t const *u,
ta_start(ta, tag, value);
mOutgoingAgent->send(msg, u, ta_tags(ta));
ta_end(ta);
} else {
LOGD("The Request SIP message is not send");
}
terminateProcessing();
}
......@@ -135,6 +144,8 @@ void RequestSipEvent::send(const shared_ptr<MsgSip> &msg) {
if (mOutgoingAgent != NULL) {
msg->log("Sending Request SIP message:");
mOutgoingAgent->send(msg);
} else {
LOGD("The Request SIP message is not send");
}
terminateProcessing();
}
......@@ -146,11 +157,13 @@ void RequestSipEvent::reply(const shared_ptr<MsgSip> &msg, int status, char cons
ta_start(ta, tag, value);
mIncomingAgent->reply(msg, status, phrase, ta_tags(ta));
ta_end(ta);
} else {
LOGD("The Request SIP message is not reply");
}
terminateProcessing();
}
void RequestSipEvent::setIncomingAgent(const std::shared_ptr<IncomingAgent> &agent) {
void RequestSipEvent::setIncomingAgent(const shared_ptr<IncomingAgent> &agent) {
LOGA("Can't change incoming agent in request sip event");
}
......@@ -163,35 +176,38 @@ ResponseSipEvent::ResponseSipEvent(const shared_ptr<OutgoingAgent> &outgoingAgen
mIncomingAgent = outgoingAgent->getAgent()->shared_from_this();
}
ResponseSipEvent::ResponseSipEvent(const std::shared_ptr<SipEvent> &sipEvent, const std::shared_ptr<MsgSip> &msgSip) :
ResponseSipEvent::ResponseSipEvent(const shared_ptr<SipEvent> &sipEvent) :
SipEvent(*sipEvent) {
mMsgSip = msgSip;
}
void ResponseSipEvent::send(const std::shared_ptr<MsgSip> &msg, url_string_t const *u, tag_type_t tag, tag_value_t value, ...) {
void ResponseSipEvent::send(const shared_ptr<MsgSip> &msg, url_string_t const *u, tag_type_t tag, tag_value_t value, ...) {
if (mIncomingAgent != NULL) {
msg->log("Sending Response SIP message:");
ta_list ta;
ta_start(ta, tag, value);
mIncomingAgent->send(msg, u, ta_tags(ta));
ta_end(ta);
} else {
LOGD("The Response SIP message is not send");
}
terminateProcessing();
}
void ResponseSipEvent::send(const std::shared_ptr<MsgSip> &msg) {
void ResponseSipEvent::send(const shared_ptr<MsgSip> &msg) {
if (mIncomingAgent != NULL) {
msg->log("Sending Response SIP message:");
mIncomingAgent->send(msg);
} else {
LOGD("The Response SIP message is not send");
}
terminateProcessing();
}
void ResponseSipEvent::reply(const std::shared_ptr<MsgSip> &msg, int status, char const *phrase, tag_type_t tag, tag_value_t value, ...) {
void ResponseSipEvent::reply(const shared_ptr<MsgSip> &msg, int status, char const *phrase, tag_type_t tag, tag_value_t value, ...) {
LOGA("Can't reply to an response sip event");
}
void ResponseSipEvent::setOutgoingAgent(const std::shared_ptr<OutgoingAgent> &agent) {
void ResponseSipEvent::setOutgoingAgent(const shared_ptr<OutgoingAgent> &agent) {
LOGA("Can't change outgoing agent in response sip event");
}
......
......@@ -111,9 +111,8 @@ public:
virtual void reply(const std::shared_ptr<MsgSip> &msg, int status, char const *phrase, tag_type_t tag, tag_value_t value, ...) = 0;
virtual ~SipEvent() {
virtual ~SipEvent();
}
Module *getCurrentModule() { return mCurrModule; }
protected:
......@@ -130,7 +129,7 @@ protected:
class RequestSipEvent: public SipEvent {
public:
RequestSipEvent(const std::shared_ptr<IncomingAgent> &incomingAgent, const std::shared_ptr<MsgSip> &msgSip);
RequestSipEvent(const std::shared_ptr<SipEvent> &sipEvent, const std::shared_ptr<MsgSip> &msgSip);
RequestSipEvent(const std::shared_ptr<SipEvent> &sipEvent);
virtual void send(const std::shared_ptr<MsgSip> &msg, url_string_t const *u, tag_type_t tag, tag_value_t value, ...);
virtual void send(const std::shared_ptr<MsgSip> &msg);
......@@ -145,7 +144,7 @@ public:
class ResponseSipEvent: public SipEvent {
public:
ResponseSipEvent(const std::shared_ptr<OutgoingAgent> &outgoingAgent, const std::shared_ptr<MsgSip> &msgSip);
ResponseSipEvent(const std::shared_ptr<SipEvent> &sipEvent, const std::shared_ptr<MsgSip> &msgSip);
ResponseSipEvent(const std::shared_ptr<SipEvent> &sipEvent);
virtual void send(const std::shared_ptr<MsgSip> &msg, url_string_t const *u, tag_type_t tag, tag_value_t value, ...);
virtual void send(const std::shared_ptr<MsgSip> &msg);
......
......@@ -40,7 +40,7 @@ void ForkCallContext::cancel() {
cancelOthers();
}
void ForkCallContext::forward(const std::shared_ptr<SipEvent> &ev, bool force) {
void ForkCallContext::forward(const shared_ptr<SipEvent> &ev, bool force) {
sip_t *sip = ev->getMsgSip()->getSip();
bool fakeSipEvent = (mFinal > 0 && !force) || mIncoming == NULL;
......@@ -56,7 +56,6 @@ void ForkCallContext::forward(const std::shared_ptr<SipEvent> &ev, bool force) {
}
if (fakeSipEvent) {
LOGD("Don't forward message");
ev->setIncomingAgent(shared_ptr<IncomingAgent>());
}
......@@ -65,14 +64,13 @@ void ForkCallContext::forward(const std::shared_ptr<SipEvent> &ev, bool force) {
}
}
void ForkCallContext::decline(const std::shared_ptr<OutgoingTransaction> &transaction, std::shared_ptr<SipEvent> &ev) {
void ForkCallContext::decline(const shared_ptr<OutgoingTransaction> &transaction, shared_ptr<SipEvent> &ev) {
if (!mForkNoGlobalDecline) {
cancelOthers(transaction);
forward(ev);
} else {
if (mOutgoings.size() != 1) {
LOGD("Don't forward message");
ev->setIncomingAgent(shared_ptr<IncomingAgent>());
} else {
forward(ev);
......@@ -80,7 +78,7 @@ void ForkCallContext::decline(const std::shared_ptr<OutgoingTransaction> &transa
}
}
void ForkCallContext::cancelOthers(const std::shared_ptr<OutgoingTransaction> &transaction) {
void ForkCallContext::cancelOthers(const shared_ptr<OutgoingTransaction> &transaction) {
if (mFinal == 0) {
for (list<shared_ptr<OutgoingTransaction>>::iterator it = mOutgoings.begin(); it != mOutgoings.end();) {
if (*it != transaction) {
......@@ -107,7 +105,7 @@ void ForkCallContext::onRequest(const shared_ptr<IncomingTransaction> &transacti
}
}
void ForkCallContext::store(std::shared_ptr<SipEvent> &event) {
void ForkCallContext::store(shared_ptr<SipEvent> &event) {
bool best = true;
if (mBestResponse != NULL) {
......@@ -116,19 +114,14 @@ void ForkCallContext::store(std::shared_ptr<SipEvent> &event) {
}
}
if (!best || mIncoming == NULL) {
// Don't forward
event->setIncomingAgent(shared_ptr<IncomingAgent>());
} else {
// Swap
if (mBestResponse != NULL) {
event = mBestResponse;
} else {
event->suspendProcessing();
}
mBestResponse = event;
// Save
if (best) {
mBestResponse = make_shared<ResponseSipEvent>(event); // Copy event
mBestResponse->suspendProcessing();
}
// Don't forward
event->setIncomingAgent(shared_ptr<IncomingAgent>());
}
void ForkCallContext::onResponse(const shared_ptr<OutgoingTransaction> &transaction, shared_ptr<SipEvent> &event) {
......@@ -158,22 +151,22 @@ void ForkCallContext::onResponse(const shared_ptr<OutgoingTransaction> &transact
LOGW("Outgoing transaction: ignore message");
}
void ForkCallContext::onNew(const std::shared_ptr<IncomingTransaction> &transaction) {
void ForkCallContext::onNew(const shared_ptr<IncomingTransaction> &transaction) {
mIncoming = transaction;
}
void ForkCallContext::onDestroy(const std::shared_ptr<IncomingTransaction> &transaction) {
void ForkCallContext::onDestroy(const shared_ptr<IncomingTransaction> &transaction) {
mIncoming.reset();
}
void ForkCallContext::onNew(const std::shared_ptr<OutgoingTransaction> &transaction) {
void ForkCallContext::onNew(const shared_ptr<OutgoingTransaction> &transaction) {
mOutgoings.push_back(transaction);
}
void ForkCallContext::onDestroy(const std::shared_ptr<OutgoingTransaction> &transaction) {
void ForkCallContext::onDestroy(const shared_ptr<OutgoingTransaction> &transaction) {
mOutgoings.remove(transaction);
if (mOutgoings.size() == 0) {
if (mIncoming != NULL) {
if (mIncoming != NULL && mFinal == 0) {
if (mBestResponse == NULL) {
// Create response
shared_ptr<MsgSip> msgsip(mIncoming->createResponse(SIP_408_REQUEST_TIMEOUT));
......@@ -181,7 +174,7 @@ void ForkCallContext::onDestroy(const std::shared_ptr<OutgoingTransaction> &tran
ev->setIncomingAgent(mIncoming);
mAgent->sendResponseEvent(ev);
} else {
mAgent->injectResponseEvent(mBestResponse);
mAgent->injectResponseEvent(mBestResponse); // Reply
}
++mFinal;