From f18440d351145124f3953ead6caf34e30b5f77eb Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Thu, 7 Feb 2008 15:19:46 +0000 Subject: [PATCH] - fixed some memory leaks. - added 200 reply re-transmission timers in UAS INVITE transactions. git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@696 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- core/plug-in/sipctrl/SipCtrlInterface.cpp | 8 +++-- core/plug-in/sipctrl/hash_table.cpp | 26 ++++++++++++++++ core/plug-in/sipctrl/hash_table.h | 6 ++++ core/plug-in/sipctrl/main.cpp | 38 +++++++++++++++++------ core/plug-in/sipctrl/sip_trans.h | 3 +- core/plug-in/sipctrl/trans_layer.cpp | 32 ++++++++++++++----- 6 files changed, 93 insertions(+), 20 deletions(-) diff --git a/core/plug-in/sipctrl/SipCtrlInterface.cpp b/core/plug-in/sipctrl/SipCtrlInterface.cpp index add8e8fe..76c03339 100644 --- a/core/plug-in/sipctrl/SipCtrlInterface.cpp +++ b/core/plug-in/sipctrl/SipCtrlInterface.cpp @@ -258,7 +258,11 @@ int SipCtrlInterface::send(const AmSipReply &rep) return -1; } - string hdrs = rep.hdrs + rep.contact; + string hdrs = rep.hdrs; + + if(!rep.contact.empty()){ + hdrs += "Contact: " + rep.contact + "\r\n"; + } if(!rep.body.empty()) { if(rep.content_type.empty()){ @@ -314,7 +318,7 @@ void SipCtrlInterface::handleSipMsg(AmSipRequest &req) reply.reason = "OK"; reply.serKey = req.serKey; reply.local_tag = "12345"; - reply.contact = "sip:" + req.dstip + ":" + req.port; + reply.contact = "Contact: sip:" + req.dstip + ":" + req.port; int err = send(reply); if(err < 0){ diff --git a/core/plug-in/sipctrl/hash_table.cpp b/core/plug-in/sipctrl/hash_table.cpp index 38deba45..9a374dd3 100644 --- a/core/plug-in/sipctrl/hash_table.cpp +++ b/core/plug-in/sipctrl/hash_table.cpp @@ -458,3 +458,29 @@ trans_bucket* get_trans_bucket(unsigned int h) assert(h < H_TABLE_ENTRIES); return &_trans_table[h]; } + +void dumps_transactions() +{ + for(int i=0; ilock(); + bucket->dump(); + bucket->unlock(); + } +} + +void trans_bucket::dump() +{ + if(elmts.empty()) + return; + + DBG("*** Bucket ID: %i ***\n",get_id()); + + for(trans_list::iterator it = elmts.begin(); it != elmts.end(); ++it) { + + DBG("type=0x%x; msg=%p; to_tag=%.*s; reply_status=%i; state=%i; retr_buf=%p\n", + (*it)->type,(*it)->msg,(*it)->to_tag.len,(*it)->to_tag.s,(*it)->reply_status,(*it)->state,(*it)->retr_buf); + } +} diff --git a/core/plug-in/sipctrl/hash_table.h b/core/plug-in/sipctrl/hash_table.h index bfe33ab3..7023f88c 100644 --- a/core/plug-in/sipctrl/hash_table.h +++ b/core/plug-in/sipctrl/hash_table.h @@ -115,6 +115,10 @@ public: unsigned long get_id() { return id; } + + + // debug method + void dump(); }; trans_bucket* get_trans_bucket(const cstring& callid, const cstring& cseq_num); @@ -128,4 +132,6 @@ unsigned int hash(const cstring& ci, const cstring& cs); // char branch[BRANCH_BUF_LEN] void compute_branch(char* branch, const cstring& callid, const cstring& cseq); +void dumps_transactions(); + #endif diff --git a/core/plug-in/sipctrl/main.cpp b/core/plug-in/sipctrl/main.cpp index d0f11f9d..f6ef6bc4 100644 --- a/core/plug-in/sipctrl/main.cpp +++ b/core/plug-in/sipctrl/main.cpp @@ -30,6 +30,7 @@ #include "sip_parser.h" #include "parse_header.h" +#include "hash_table.h" #include "log.h" @@ -38,8 +39,20 @@ #include "AmSipMsg.h" #include "AmUtils.h" +#include + #define SERVER +static void sig_usr(int signo) +{ + WARN("signal %d received\n", signo); + + dumps_transactions(); + exit(0); + + return; +} + int main() { log_level = 3; @@ -67,16 +80,16 @@ int main() char* hdr = "Route: \r\n"; - char *c = hdr; - - sip_msg* msg = new sip_msg(); - int err = parse_headers(msg,&c); - - if(err){ - ERROR("Route headers parsing failed\n"); - ERROR("Faulty headers were: <%s>\n",hdr); - return -1; - } + char *c = hdr; + + sip_msg* msg = new sip_msg(); + int err = parse_headers(msg,&c); + + if(err){ + ERROR("Route headers parsing failed\n"); + ERROR("Faulty headers were: <%s>\n",hdr); + return -1; + } // char* buf = @@ -111,6 +124,11 @@ int main() //delete msg; #else + + if (signal(SIGINT, sig_usr) == SIG_ERR ) { + ERROR("no SIGINT signal handler can be installed\n"); + return -1; + } ctrl->start(); diff --git a/core/plug-in/sipctrl/sip_trans.h b/core/plug-in/sipctrl/sip_trans.h index 797f3f5f..6b45b458 100644 --- a/core/plug-in/sipctrl/sip_trans.h +++ b/core/plug-in/sipctrl/sip_trans.h @@ -80,7 +80,8 @@ enum sip_timer_type { STIMER_I, // Confirmed: -> Terminated // non-INVITE server transaction - STIMER_J, // Completed: -> Terminated + STIMER_J // Completed: -> Terminated + }; diff --git a/core/plug-in/sipctrl/trans_layer.cpp b/core/plug-in/sipctrl/trans_layer.cpp index 8e10bd56..916a4228 100644 --- a/core/plug-in/sipctrl/trans_layer.cpp +++ b/core/plug-in/sipctrl/trans_layer.cpp @@ -580,13 +580,12 @@ void trans_layer::received_msg(sip_msg* msg) // Anyway, there is nothing we can do... } else if(err == TS_TERMINATED){ - - } - // do not touch the transaction anymore: - // it could have been deleted !!! - - // should we forward the ACK to SEMS-App upstream? Yes + // do not touch the transaction anymore: + // it could have been deleted !!! + + // should we forward the ACK to SEMS-App upstream? Yes + } } else { DBG("Found retransmission\n"); @@ -809,8 +808,14 @@ int trans_layer::update_uas_reply(trans_bucket* bucket, sip_trans* t, int reply_ if(t->msg->u.request->method == sip_request::INVITE){ // final reply + //bucket->remove_trans(t); + //return TS_TERMINATED; + t->state = TS_TERMINATED_200; + t->reset_timer(STIMER_G,G_TIMER,bucket->get_id()); + t->reset_timer(STIMER_H,H_TIMER,bucket->get_id()); + } else { t->state = TS_COMPLETED; @@ -1067,7 +1072,18 @@ void trans_layer::timer_expired(timer* t, trans_bucket* bucket, sip_trans* tr) case STIMER_G: // Completed: (re-)send response n++; - retransmit(tr->msg); + + if(tr->state == TS_TERMINATED_200){ + + // Retransmit reply to INV + retransmit(tr); + } + else { + + // Retransmit request + retransmit(tr->msg); + } + if(T1_TIMER< T2_TIMER) { tr->reset_timer((n<<16) | type, T2_TIMER, bucket->get_id()); } @@ -1081,3 +1097,5 @@ void trans_layer::timer_expired(timer* t, trans_bucket* bucket, sip_trans* tr) break; } } + +