Module: sems Branch: master Commit: aef1d22985c54a1955b76d16ebc0d573d714746e URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=aef1d22985c54a1955b76d16ebc0d573d714746e
Author: Stefan Sayer <[email protected]> Committer: Stefan Sayer <[email protected]> Date: Wed May 25 15:19:26 2011 +0200 report registration send failure; add method to get TS --- core/AmSipRegistration.cpp | 41 ++++++++++++++++++++++++----------------- core/AmSipRegistration.h | 8 +++++--- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/core/AmSipRegistration.cpp b/core/AmSipRegistration.cpp index 20e8ab1..40fd73a 100644 --- a/core/AmSipRegistration.cpp +++ b/core/AmSipRegistration.cpp @@ -80,8 +80,10 @@ void AmSIPRegistration::setExpiresInterval(unsigned int desired_expires) { expires_interval = desired_expires; } -void AmSIPRegistration::doRegistration() +bool AmSIPRegistration::doRegistration() { + bool res = true; + waiting_result = true; req.to_tag = ""; dlg.remote_tag = ""; @@ -102,17 +104,21 @@ void AmSIPRegistration::doRegistration() if (dlg.sendRequest(req.method, "", "", SIP_HDR_COLSP(SIP_HDR_EXPIRES)+ - int2str(expires_interval)+CRLF) < 0) + int2str(expires_interval)+CRLF) < 0) { ERROR("failed to send registration.\n"); + res = false; + waiting_result = false; + } // save TS - struct timeval now; - gettimeofday(&now, NULL); - reg_send_begin = now.tv_sec; + reg_send_begin = time(NULL); + return res; } -void AmSIPRegistration::doUnregister() +bool AmSIPRegistration::doUnregister() { + bool res = true; + waiting_result = true; req.to_tag = ""; dlg.remote_tag = ""; @@ -132,13 +138,15 @@ void AmSIPRegistration::doUnregister() } if (dlg.sendRequest(req.method, "", "", - SIP_HDR_COLSP(SIP_HDR_EXPIRES) "0" CRLF) < 0) + SIP_HDR_COLSP(SIP_HDR_EXPIRES) "0" CRLF) < 0) { ERROR("failed to send deregistration.\n"); + res = false; + waiting_result = false; + } // save TS - struct timeval now; - gettimeofday(&now, NULL); - reg_send_begin = now.tv_sec; + reg_send_begin = time(NULL); + return res; } void AmSIPRegistration::onSendRequest(const string& method, @@ -174,15 +182,16 @@ AmSIPRegistration::RegistrationState AmSIPRegistration::getState() { } unsigned int AmSIPRegistration::getExpiresLeft() { - struct timeval now; - gettimeofday(&now, NULL); - - int diff = reg_begin + reg_expires - now.tv_sec; + long diff = reg_begin + reg_expires - time(NULL); if (diff < 0) return 0; else return diff; } + +time_t AmSIPRegistration::getExpiresTS() { + return reg_begin + reg_expires; +} void AmSIPRegistration::onRegisterExpired() { if (sess_link.length()) { @@ -268,9 +277,7 @@ void AmSIPRegistration::onSipReply(const AmSipReply& reply, int old_dlg_status, } DBG("got an expires of %d\n", reg_expires); // save TS - struct timeval now; - gettimeofday(&now, NULL); - reg_begin = now.tv_sec; + reg_begin = time(0); if (sess_link.length()) { DBG("posting SIPRegistrationEvent to '%s'\n", sess_link.c_str()); diff --git a/core/AmSipRegistration.h b/core/AmSipRegistration.h index db74348..a0f3eca 100644 --- a/core/AmSipRegistration.h +++ b/core/AmSipRegistration.h @@ -97,8 +97,8 @@ class AmSIPRegistration void setExpiresInterval(unsigned int desired_expires); - void doRegistration(); - void doUnregister(); + bool doRegistration(); + bool doUnregister(); bool timeToReregister(time_t now_sec); bool registerExpired(time_t now_sec); @@ -152,7 +152,9 @@ class AmSIPRegistration /** return the state of the registration */ RegistrationState getState(); /** return the expires left for the registration */ - unsigned int getExpiresLeft(); + unsigned int getExpiresLeft(); + /** return the expires TS for the registration */ + time_t getExpiresTS(); SIPRegistrationInfo& getInfo() { return info; } const string& getEventSink() { return sess_link; } _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
