diff --git a/apps/sbc/RegisterCache.cpp b/apps/sbc/RegisterCache.cpp index 561309fa..71519bc3 100644 --- a/apps/sbc/RegisterCache.cpp +++ b/apps/sbc/RegisterCache.cpp @@ -671,7 +671,7 @@ bool RegisterCache::findAEByContact(const string& contact_uri, int RegisterCache::parseAoR(RegisterCacheCtx& ctx, const AmSipRequest& req, - msg_logger *logger) + const shared_ptr& logger) { if(ctx.aor_parsed) return 0; @@ -698,14 +698,14 @@ int RegisterCache::parseAoR(RegisterCacheCtx& ctx, int RegisterCache::parseContacts(RegisterCacheCtx& ctx, const AmSipRequest& req, - msg_logger *logger) + const shared_ptr& logger) { if(ctx.contacts_parsed) return 0; if ((RegisterDialog::parseContacts(req.contact, ctx.contacts) < 0) || (ctx.contacts.size() == 0)) { - AmBasicSipDialog::reply_error(req, 400, "Bad Request", + AmBasicSipDialog::reply_error(req, 400, "Bad Request", "Warning: Malformed contact\r\n", logger); return -1; } @@ -715,7 +715,7 @@ int RegisterCache::parseContacts(RegisterCacheCtx& ctx, int RegisterCache::parseExpires(RegisterCacheCtx& ctx, const AmSipRequest& req, - msg_logger *logger) + const shared_ptr& logger) { if(ctx.expires_parsed) return 0; @@ -723,7 +723,7 @@ int RegisterCache::parseExpires(RegisterCacheCtx& ctx, // move Expires as separate header to contact parameter string expires_str = getHeader(req.hdrs, "Expires"); if (!expires_str.empty() && str2int(expires_str, ctx.requested_expires)) { - AmBasicSipDialog::reply_error(req, 400, "Bad Request", + AmBasicSipDialog::reply_error(req, 400, "Bad Request", "Warning: Malformed expires\r\n", logger); return true; // error reply sent } @@ -733,7 +733,7 @@ int RegisterCache::parseExpires(RegisterCacheCtx& ctx, bool RegisterCache::throttleRegister(RegisterCacheCtx& ctx, const AmSipRequest& req, - msg_logger *logger) + const shared_ptr& logger) { if (req.method != SIP_METH_REGISTER) { ERROR("unsupported method '%s'\n", req.method.c_str()); @@ -863,7 +863,7 @@ bool RegisterCache::throttleRegister(RegisterCacheCtx& ctx, bool RegisterCache::saveSingleContact(RegisterCacheCtx& ctx, const AmSipRequest& req, - msg_logger *logger) + const shared_ptr& logger) { if (req.method != SIP_METH_REGISTER) { ERROR("unsupported method '%s'\n", req.method.c_str()); diff --git a/apps/sbc/RegisterCache.h b/apps/sbc/RegisterCache.h index aec06721..43c6ec0e 100644 --- a/apps/sbc/RegisterCache.h +++ b/apps/sbc/RegisterCache.h @@ -313,9 +313,9 @@ protected: sleep_cond.notify_all(); } - int parseAoR(RegisterCacheCtx& ctx, const AmSipRequest& req, msg_logger *logger); - int parseContacts(RegisterCacheCtx& ctx, const AmSipRequest& req, msg_logger *logger); - int parseExpires(RegisterCacheCtx& ctx, const AmSipRequest& req, msg_logger *logger); + int parseAoR(RegisterCacheCtx& ctx, const AmSipRequest& req, const shared_ptr& logger); + int parseContacts(RegisterCacheCtx& ctx, const AmSipRequest& req, const shared_ptr& logger); + int parseExpires(RegisterCacheCtx& ctx, const AmSipRequest& req, const shared_ptr& logger); void setAliasUATimer(AliasEntry* alias_e); void removeAliasUATimer(AliasEntry* alias_e); @@ -408,7 +408,7 @@ public: */ bool throttleRegister(RegisterCacheCtx& ctx, const AmSipRequest& req, - msg_logger *logger = NULL); + const shared_ptr& logger = NULL); /** * Save a single REGISTER contact into cache @@ -417,7 +417,7 @@ public: * - if request is not a REGISTER. * - more than one contact should be (un)registered. * - * If true has been returned, the request has already + * If true has been returned, the request has already * been replied with either an error or 200 (w/ contact). * * Note: this function also handles binding query. @@ -425,7 +425,7 @@ public: */ bool saveSingleContact(RegisterCacheCtx& ctx, const AmSipRequest& req, - msg_logger *logger = NULL); + const shared_ptr& logger = NULL); /** * Statistics diff --git a/apps/sbc/SBC.cpp b/apps/sbc/SBC.cpp index 0b2d7f66..8f29df34 100644 --- a/apps/sbc/SBC.cpp +++ b/apps/sbc/SBC.cpp @@ -318,7 +318,7 @@ AmSession* SBCFactory::onInvite(const AmSipRequest& req, const string& app_name, SBCCallLeg* b2b_dlg = callLegCreator->create(call_profile); - msg_logger* logger = b2b_dlg->getCallProfile().get_logger(req); + auto logger = b2b_dlg->getCallProfile().get_logger(req); if (logger && call_profile.log_sip) req.log(logger); if (call_profile.auth_aleg_enabled) { @@ -379,7 +379,7 @@ void SBCFactory::onOoDRequest(const AmSipRequest& req) SBCCallProfile call_profile(*p_call_profile); profiles_mut.unlock(); - msg_logger* logger = call_profile.get_logger(req); + auto logger = call_profile.get_logger(req); if (logger && call_profile.log_sip) req.log(logger); ctx.call_profile = &call_profile; diff --git a/apps/sbc/SBCCallLeg.cpp b/apps/sbc/SBCCallLeg.cpp index 71e874a9..9b60ef7f 100644 --- a/apps/sbc/SBCCallLeg.cpp +++ b/apps/sbc/SBCCallLeg.cpp @@ -513,7 +513,6 @@ SBCCallLeg::~SBCCallLeg() { if (auth) delete auth; - if (logger) dec_ref(logger); } void SBCCallLeg::onBeforeDestroy() @@ -1209,7 +1208,7 @@ bool SBCCallLeg::CCStart(const AmSipRequest& req) { if (!logger) { // open the logger if not already opened - msg_logger *l = call_profile.get_logger(req); + auto l = call_profile.get_logger(req); if (l) setLogger(l); } @@ -1949,11 +1948,10 @@ void SBCCallLeg::setMediaSession(AmB2BMedia *new_session) bool SBCCallLeg::openLogger(const std::string &path) { - file_msg_logger *log = new pcap_logger(); + shared_ptr log(new pcap_logger()); if(log->open(path.c_str()) != 0) { // open error - delete log; return false; } @@ -1962,12 +1960,9 @@ bool SBCCallLeg::openLogger(const std::string &path) return true; } -void SBCCallLeg::setLogger(msg_logger *_logger) +void SBCCallLeg::setLogger(const shared_ptr& _logger) { - if (logger) dec_ref(logger); // release the old one - logger = _logger; - if (logger) inc_ref(logger); if (call_profile.log_sip) dlg->setMsgLogger(logger); else dlg->setMsgLogger(NULL); diff --git a/apps/sbc/SBCCallLeg.h b/apps/sbc/SBCCallLeg.h index cb4b1c6d..02f1ea79 100644 --- a/apps/sbc/SBCCallLeg.h +++ b/apps/sbc/SBCCallLeg.h @@ -86,9 +86,9 @@ class SBCCallLeg : public CallLeg, public CredentialHolder list rtp_pegs; /** common logger for RTP/RTCP and SIP packets */ - msg_logger *logger; + shared_ptr logger; - void setLogger(msg_logger *_logger); + void setLogger(const shared_ptr& _logger); void fixupCCInterface(const string& val, CCInterface& cc_if); @@ -257,7 +257,7 @@ class SBCCallLeg : public CallLeg, public CredentialHolder int applySSTCfg(AmConfigReader& sst_cfg, const AmSipRequest* p_req); bool openLogger(const std::string &path); - msg_logger *getLogger() { return logger; } + const shared_ptr& getLogger() { return logger; } virtual double get491RetryTime() { return (get_random() % call_profile.max_491_retry_time) / 1000.0; } }; diff --git a/apps/sbc/SBCCallProfile.cpp b/apps/sbc/SBCCallProfile.cpp index dca0f21f..b78440cf 100644 --- a/apps/sbc/SBCCallProfile.cpp +++ b/apps/sbc/SBCCallProfile.cpp @@ -26,6 +26,7 @@ #include "SBCCallProfile.h" #include "SBC.h" #include +#include #include "log.h" #include "AmUtils.h" @@ -39,6 +40,7 @@ #include "sip/pcap_logger.h" +using std::make_shared; typedef vector::iterator PayloadIterator; static string payload2str(const SdpPayload &p); @@ -1673,22 +1675,21 @@ void SBCCallProfile::create_logger(const AmSipRequest& req) string log_path = ctx.replaceParameters(msg_logger_path, "msg_logger_path", req); if (log_path.empty()) return; - file_msg_logger *log = new pcap_logger(); + auto log = make_shared(); if(log->open(log_path.c_str()) != 0) { // open error - delete log; return; } // opened successfully - logger.reset(log); + logger = log; } -msg_logger* SBCCallProfile::get_logger(const AmSipRequest& req) +const shared_ptr& SBCCallProfile::get_logger(const AmSipRequest& req) { if (!logger.get() && !msg_logger_path.empty()) create_logger(req); - return logger.get(); + return logger; } ////////////////////////////////////////////////////////////////////////////////// @@ -1697,7 +1698,7 @@ bool PayloadDesc::match(const SdpPayload &p) const { string enc_name = p.encoding_name; transform(enc_name.begin(), enc_name.end(), enc_name.begin(), ::tolower); - + if ((name.size() > 0) && (name != enc_name)) return false; if (clock_rate && (p.clock_rate > 0) && clock_rate != (unsigned)p.clock_rate) return false; return true; diff --git a/apps/sbc/SBCCallProfile.h b/apps/sbc/SBCCallProfile.h index a72cf1ff..42abca59 100644 --- a/apps/sbc/SBCCallProfile.h +++ b/apps/sbc/SBCCallProfile.h @@ -61,24 +61,6 @@ typedef std::list CCInterfaceListT; typedef CCInterfaceListT::iterator CCInterfaceListIteratorT; typedef CCInterfaceListT::const_iterator CCInterfaceListConstIteratorT; -template -class ref_counted_ptr -{ - private: - T *ptr; - - public: - void reset(T *p) { if (ptr) dec_ref(ptr); ptr = p; if (ptr) inc_ref(ptr); } - T *get() const { return ptr; } - - ref_counted_ptr(): ptr(0) { } - ~ref_counted_ptr() { if (ptr) dec_ref(ptr); } - - ref_counted_ptr(const ref_counted_ptr &other): ptr(other.ptr) { if (ptr) inc_ref(ptr); } - ref_counted_ptr &operator=(const ref_counted_ptr &other) { reset(other.ptr); return *this; } - -}; - class PayloadDesc { protected: std::string name; @@ -328,7 +310,7 @@ struct SBCCallProfile private: // message logging feature string msg_logger_path; - ref_counted_ptr logger; + shared_ptr logger; void create_logger(const AmSipRequest& req); @@ -336,7 +318,7 @@ struct SBCCallProfile bool log_rtp; bool log_sip; bool has_logger() { return logger.get() != NULL; } - msg_logger* get_logger(const AmSipRequest& req); + const shared_ptr& get_logger(const AmSipRequest& req); void set_logger_path(const std::string path) { msg_logger_path = path; } const string &get_logger_path() { return msg_logger_path; } diff --git a/core/AmB2BMedia.cpp b/core/AmB2BMedia.cpp index 9672a9a3..c0465db6 100644 --- a/core/AmB2BMedia.cpp +++ b/core/AmB2BMedia.cpp @@ -513,7 +513,6 @@ AmB2BMedia::AmB2BMedia(AmB2BSession *_a, AmB2BSession *_b): AmB2BMedia::~AmB2BMedia() { - if (logger) dec_ref(logger); } void AmB2BMedia::addToMediaProcessor() { @@ -1203,11 +1202,9 @@ void AmB2BMedia::createHoldAnswer(bool a_leg, const AmSdp &offer, AmSdp &answer, } } -void AmB2BMedia::setRtpLogger(msg_logger* _logger) +void AmB2BMedia::setRtpLogger(const shared_ptr& _logger) { - if (logger) dec_ref(logger); logger = _logger; - if (logger) inc_ref(logger); // walk through all the streams and use logger for them for (AudioStreamIterator i = audio.begin(); i != audio.end(); ++i) i->setLogger(logger); diff --git a/core/AmB2BMedia.h b/core/AmB2BMedia.h index 0ced0167..1186a812 100644 --- a/core/AmB2BMedia.h +++ b/core/AmB2BMedia.h @@ -211,7 +211,7 @@ class AudioStreamData { void setInput(AmAudio *_in) { in = _in; } AmAudio *getInput() { return in; } - void setLogger(msg_logger *logger) { if (stream) stream->setLogger(logger); } + void setLogger(const shared_ptr& logger) { if (stream) stream->setLogger(logger); } void debug(); }; @@ -297,14 +297,14 @@ class AmB2BMedia: public AmMediaSession AudioStreamData a, b; int media_idx; AudioStreamPair(AmB2BSession *_a, AmB2BSession *_b, int _media_idx): a(_a), b(_b), media_idx(_media_idx) { } - void setLogger(msg_logger *logger) { a.setLogger(logger); b.setLogger(logger); } + void setLogger(const shared_ptr& logger) { a.setLogger(logger); b.setLogger(logger); } bool requiresProcessing() { return a.getInput() || b.getInput(); } }; struct RelayStreamPair { AmRtpStream a, b; RelayStreamPair(AmB2BSession *_a, AmB2BSession *_b); - void setLogger(msg_logger *logger) { a.setLogger(logger); b.setLogger(logger); } + void setLogger(const shared_ptr& logger) { a.setLogger(logger); b.setLogger(logger); } }; typedef std::vector::iterator AudioStreamIterator; @@ -356,7 +356,7 @@ class AmB2BMedia: public AmMediaSession void setMuteFlag(bool a_leg, bool set); void changeSessionUnsafe(bool a_leg, AmB2BSession *new_session); - msg_logger* logger; // log RTP traffic + shared_ptr logger; // log RTP traffic virtual ~AmB2BMedia(); @@ -472,7 +472,7 @@ class AmB2BMedia: public AmMediaSession void setFirstStreamInput(bool a_leg, AmAudio *in); void createHoldAnswer(bool a_leg, const AmSdp &offer, AmSdp &answer, bool use_zero_con); - void setRtpLogger(msg_logger* _logger); + void setRtpLogger(const shared_ptr& _logger); /** enable or disable DTMF receiving on relay streams */ void setRelayDTMFReceiving(bool enabled); diff --git a/core/AmBasicSipDialog.cpp b/core/AmBasicSipDialog.cpp index 769e44d5..08c8da8a 100644 --- a/core/AmBasicSipDialog.cpp +++ b/core/AmBasicSipDialog.cpp @@ -44,7 +44,6 @@ AmBasicSipDialog::~AmBasicSipDialog() { termUasTrans(); termUacTrans(); - if (logger) dec_ref(logger); dump(); } @@ -666,9 +665,9 @@ int AmBasicSipDialog::reply(const AmSipRequest& req, /* static */ -int AmBasicSipDialog::reply_error(const AmSipRequest& req, unsigned int code, +int AmBasicSipDialog::reply_error(const AmSipRequest& req, unsigned int code, const string& reason, const string& hdrs, - msg_logger* logger) + const shared_ptr& logger) { AmSipReply reply; @@ -787,21 +786,13 @@ void AmBasicSipDialog::dump() if(uas_trans.size()){ for(TransMap::iterator it = uas_trans.begin(); it != uas_trans.end(); it++){ - + ILOG_DLG(L_DBG, " cseq = %i; method = %s\n",it->first,it->second.method.c_str()); } } } -void AmBasicSipDialog::setMsgLogger(msg_logger* logger) +void AmBasicSipDialog::setMsgLogger(const shared_ptr& logger) { - if(this->logger) { - dec_ref(this->logger); - } - - if(logger){ - inc_ref(logger); - } - this->logger = logger; } diff --git a/core/AmBasicSipDialog.h b/core/AmBasicSipDialog.h index 5e50cbcb..ba9f7cbf 100644 --- a/core/AmBasicSipDialog.h +++ b/core/AmBasicSipDialog.h @@ -132,7 +132,7 @@ protected: /** * Message logger */ - msg_logger* logger; + shared_ptr logger; /** * Executed for replies sent by a local UA, @@ -400,15 +400,15 @@ public: * This method should only be used to send responses * to requests which are not referenced by any dialog. * - * WARNING: If the request has already been referenced - * (see uas_trans), this method cannot mark the request + * WARNING: If the request has already been referenced + * (see uas_trans), this method cannot mark the request * as replied, thus leaving it in the pending state forever. */ static int reply_error(const AmSipRequest& req, unsigned int code, const string& reason, const string& hdrs = "", - msg_logger* logger = NULL); + const shared_ptr& logger = NULL); /* dump transaction information (DBG) */ void dump(); @@ -416,12 +416,12 @@ public: /** * Enable or disable message logger */ - void setMsgLogger(msg_logger* logger); + void setMsgLogger(const shared_ptr& logger); /** * Get message logger */ - msg_logger* getMsgLogger() { return logger; } + const shared_ptr& getMsgLogger() { return logger; } }; /** diff --git a/core/AmRtpPacket.cpp b/core/AmRtpPacket.cpp index be01b6ea..08a4b854 100644 --- a/core/AmRtpPacket.cpp +++ b/core/AmRtpPacket.cpp @@ -282,13 +282,13 @@ int AmRtpPacket::recv(int sd) return ret; } -void AmRtpPacket::logReceived(msg_logger *logger, struct sockaddr_storage *laddr) +void AmRtpPacket::logReceived(const shared_ptr& logger, struct sockaddr_storage *laddr) { static const cstring empty; logger->log((const char *)buffer, b_size, &addr, laddr, empty); } -void AmRtpPacket::logSent(msg_logger *logger, struct sockaddr_storage *laddr) +void AmRtpPacket::logSent(const shared_ptr& logger, struct sockaddr_storage *laddr) { static const cstring empty; logger->log((const char *)buffer, b_size, laddr, &addr, empty); diff --git a/core/AmRtpPacket.h b/core/AmRtpPacket.h index 3a388f11..2659acf2 100644 --- a/core/AmRtpPacket.h +++ b/core/AmRtpPacket.h @@ -31,6 +31,9 @@ #include #include #include +#include + +using std::shared_ptr; class AmRtpPacketTracer; class msg_logger; @@ -81,8 +84,8 @@ public: unsigned char* getBuffer(); void setBufferSize(unsigned int b) { b_size = b; } - void logReceived(msg_logger *logger, struct sockaddr_storage *laddr); - void logSent(msg_logger *logger, struct sockaddr_storage *laddr); + void logReceived(const shared_ptr& logger, struct sockaddr_storage *laddr); + void logSent(const shared_ptr& logger, struct sockaddr_storage *laddr); }; #endif diff --git a/core/AmRtpSocket.cpp b/core/AmRtpSocket.cpp index 3bd2d726..318eaf02 100644 --- a/core/AmRtpSocket.cpp +++ b/core/AmRtpSocket.cpp @@ -132,7 +132,6 @@ AmRtpSocket::AmRtpSocket(AmRtpSocketPair* listener, int interface, AmRtpSocket::~AmRtpSocket() { - if (logger) dec_ref(logger); if(l_sd) { close(l_sd); } @@ -229,12 +228,10 @@ void AmRtpSocket::setRemoteAddress(const string& addr, unsigned short port) am_set_port(&r_saddr, port); } -void AmRtpSocket::setLogger(msg_logger *_logger) +void AmRtpSocket::setLogger(const shared_ptr& _logger) { // Set logger - if (logger) dec_ref(logger); logger = _logger; - if (logger) inc_ref(logger); } diff --git a/core/AmRtpSocket.h b/core/AmRtpSocket.h index ca7762f9..1c34483b 100644 --- a/core/AmRtpSocket.h +++ b/core/AmRtpSocket.h @@ -33,8 +33,10 @@ #include #include #include +#include using std::string; +using std::shared_ptr; class AmRtpSocketPair; class AmRtpPacket; @@ -54,7 +56,7 @@ class AmRtpSocket static void read_cb(evutil_socket_t sd, short what, void* arg); protected: - msg_logger *logger; + shared_ptr logger; AmRtpSocketPair* listener; @@ -113,7 +115,7 @@ public: inline int getLocalPort() { return am_get_port(&l_saddr); }; /** set destination for logging all received/sent RTP and RTCP packets */ - void setLogger(msg_logger *_logger); + void setLogger(const shared_ptr& _logger); AmRtpSocket(AmRtpSocketPair* listener, int interface, const string& ip, unsigned int port); diff --git a/core/AmRtpStream.cpp b/core/AmRtpStream.cpp index ae28aaed..900280d1 100644 --- a/core/AmRtpStream.cpp +++ b/core/AmRtpStream.cpp @@ -443,7 +443,6 @@ AmRtpStream::~AmRtpStream() close(l_sd); close(l_rtcp_sd); } - if (logger) dec_ref(logger); } int AmRtpStream::getLocalPort() @@ -1320,11 +1319,9 @@ inline void PacketMem::clear() n_used = cur_idx = 0; } -void AmRtpStream::setLogger(msg_logger* _logger) +void AmRtpStream::setLogger(const shared_ptr& _logger) { - if (logger) dec_ref(logger); logger = _logger; - if (logger) inc_ref(logger); } void AmRtpStream::debug() diff --git a/core/AmRtpStream.h b/core/AmRtpStream.h index 28875888..237c92ab 100644 --- a/core/AmRtpStream.h +++ b/core/AmRtpStream.h @@ -274,7 +274,7 @@ protected: /** Session owning this stream */ AmSession* session; - msg_logger *logger; + shared_ptr logger; /** Payload provider */ AmPayloadProvider* payload_provider; @@ -514,7 +514,7 @@ public: void changeSession(AmSession *_s) { session = _s; } /** set destination for logging all received/sent RTP and RTCP packets */ - void setLogger(msg_logger *_logger); + void setLogger(const shared_ptr& _logger); void debug(); }; diff --git a/core/AmSession.cpp b/core/AmSession.cpp index ced060d7..f48be078 100644 --- a/core/AmSession.cpp +++ b/core/AmSession.cpp @@ -53,6 +53,8 @@ #include #include +using std::make_shared; + #define GET_CALL_ID() (dlg->getCallid().c_str()) unsigned int AmSession::session_num = 0; @@ -128,7 +130,7 @@ AmSession::~AmSession() { for(vector::iterator evh = ev_handlers.begin(); evh != ev_handlers.end(); evh++) { - + if((*evh)->destroy) delete *evh; } diff --git a/core/AmSession.h b/core/AmSession.h index 621d25ad..11ed8ace 100644 --- a/core/AmSession.h +++ b/core/AmSession.h @@ -160,7 +160,7 @@ protected: AmCondition sess_stopped; - /** this is the group the media is processed with + /** this is the group the media is processed with - by default local tag */ string callgroup; diff --git a/core/AmSipMsg.cpp b/core/AmSipMsg.cpp index 0a6b822f..1b27f841 100644 --- a/core/AmSipMsg.cpp +++ b/core/AmSipMsg.cpp @@ -254,7 +254,7 @@ string AmSipRequest::print() const } -void AmSipRequest::log(msg_logger *logger) const +void AmSipRequest::log(const shared_ptr& logger) const { tt.lock_bucket(); const sip_trans* t = tt.get_trans(); diff --git a/core/AmSipMsg.h b/core/AmSipMsg.h index f6c081fe..08a70ced 100644 --- a/core/AmSipMsg.h +++ b/core/AmSipMsg.h @@ -102,14 +102,14 @@ class AmSipRequest : public _AmSipMsgInDlg AmSipRequest(); ~AmSipRequest() { } - + string print() const; - void log(msg_logger *logger) const; + void log(const shared_ptr& logger) const; }; string getHeader(const string& hdrs,const string& hdr_name, bool single = false); -string getHeader(const string& hdrs,const string& hdr_name, +string getHeader(const string& hdrs,const string& hdr_name, const string& compact_hdr_name, bool single = false); /** find a header, starting from char skip diff --git a/core/SipCtrlInterface.cpp b/core/SipCtrlInterface.cpp index f87fb796..9d65e570 100644 --- a/core/SipCtrlInterface.cpp +++ b/core/SipCtrlInterface.cpp @@ -223,10 +223,8 @@ int SipCtrlInterface::cancel(trans_ticket* tt, const string& dialog_id, } int SipCtrlInterface::send(AmSipRequest &req, const string& dialog_id, - const string& next_hop, - int out_interface, - unsigned int flags, - msg_logger* logger) + const string& next_hop, int out_interface, + unsigned int flags, const shared_ptr& logger) { if (req.method == "CANCEL") return cancel(&req.tt, dialog_id, req.cseq, req.hdrs); @@ -369,7 +367,7 @@ void SipCtrlInterface::cleanup() } int SipCtrlInterface::send(const AmSipReply &rep, const string& dialog_id, - msg_logger* logger) + const shared_ptr& logger) { sip_msg msg; diff --git a/core/SipCtrlInterface.h b/core/SipCtrlInterface.h index 29144aa6..8cf6d363 100644 --- a/core/SipCtrlInterface.h +++ b/core/SipCtrlInterface.h @@ -103,7 +103,7 @@ public: */ static int send(AmSipRequest &req, const string& dialog_id, const string& next_hop = "", int outbound_interface = -1, - unsigned int flags = 0, msg_logger* logger = NULL); + unsigned int flags = 0, const shared_ptr& logger = NULL); /** * Sends a SIP reply. @@ -112,7 +112,7 @@ public: * ticket included in the SIP request. */ static int send(const AmSipReply &rep, const string& dialog_id, - msg_logger* logger = NULL); + const shared_ptr& logger = NULL); /** * CANCELs an INVITE transaction. diff --git a/core/sip/msg_logger.h b/core/sip/msg_logger.h index a5d60d08..bc0fa32a 100644 --- a/core/sip/msg_logger.h +++ b/core/sip/msg_logger.h @@ -14,7 +14,6 @@ using std::string; struct sockaddr_storage; class msg_logger - : public atomic_ref_cnt { public: msg_logger() {} diff --git a/core/sip/sip_trans.cpp b/core/sip/sip_trans.cpp index b1aa79a5..5f311f78 100644 --- a/core/sip/sip_trans.cpp +++ b/core/sip/sip_trans.cpp @@ -96,9 +96,6 @@ sip_trans::~sip_trans() if(dialog_id.s) { delete [] dialog_id.s; } - if(logger) { - dec_ref(logger); - } } /** diff --git a/core/sip/sip_trans.h b/core/sip/sip_trans.h index 4a4d06c4..adfbacac 100644 --- a/core/sip/sip_trans.h +++ b/core/sip/sip_trans.h @@ -156,7 +156,7 @@ class sip_trans unsigned int flags; /** message logging */ - msg_logger* logger; + shared_ptr logger; /** request canceled? */ bool canceled; diff --git a/core/sip/trans_layer.cpp b/core/sip/trans_layer.cpp index cc034c02..1655e5e3 100644 --- a/core/sip/trans_layer.cpp +++ b/core/sip/trans_layer.cpp @@ -217,7 +217,7 @@ static int patch_contact_transport(sip_header* contact, const cstring& trsp, int trans_layer::send_reply(sip_msg* msg, const trans_ticket* tt, const cstring& dialog_id, const cstring& to_tag, - msg_logger* logger) + const shared_ptr& logger) { // Ref.: RFC 3261 8.2.6, 12.1.1 // @@ -629,7 +629,6 @@ int trans_layer::send_reply(sip_msg* msg, const trans_ticket* tt, if(!t->logger){ t->logger = logger; - inc_ref(logger); } } @@ -1202,7 +1201,7 @@ int trans_layer::send_request(sip_msg* msg, trans_ticket* tt, const cstring& dialog_id, const cstring& _next_hop, int out_interface, unsigned int flags, - msg_logger* logger) + const shared_ptr& logger) { // Request-URI // To @@ -1346,7 +1345,7 @@ int trans_layer::send_request(sip_msg* msg, trans_ticket* tt, } } - DBG("logger = %p\n",logger); + DBG("logger = %p\n",logger.get()); if(logger) { sockaddr_storage src_ip; @@ -1373,7 +1372,6 @@ int trans_layer::send_request(sip_msg* msg, trans_ticket* tt, if(tt->_t && !tt->_t->logger) { tt->_t->logger = logger; - inc_ref(logger); } } @@ -1558,7 +1556,6 @@ int trans_layer::cancel(trans_ticket* tt, const cstring& dialog_id, if(!cancel_t->logger) { cancel_t->logger = t->logger; - inc_ref(t->logger); } } } @@ -2624,7 +2621,6 @@ sip_trans* trans_layer::copy_uac_trans(sip_trans* tr) if(tr->logger) { n_tr->logger = tr->logger; - inc_ref(n_tr->logger); } return n_tr; diff --git a/core/sip/trans_layer.h b/core/sip/trans_layer.h index 6ade3e63..28d6a22a 100644 --- a/core/sip/trans_layer.h +++ b/core/sip/trans_layer.h @@ -170,7 +170,8 @@ public: * 'Content-Length' header. */ int send_reply(sip_msg* msg, const trans_ticket* tt, const cstring& dialog_id, - const cstring& to_tag, msg_logger* logger=NULL); + const cstring& to_tag, + const shared_ptr& logger=NULL); /** * Sends a UAC request. @@ -181,7 +182,7 @@ public: */ int send_request(sip_msg* msg, trans_ticket* tt, const cstring& dialog_id, const cstring& _next_hop, int out_interface = -1, - unsigned int flags=0, msg_logger* logger=NULL); + unsigned int flags=0, const shared_ptr& logger=NULL); /** * Cancels a request.