diff --git a/apps/registrar_client/SIPRegistrarClient.cpp b/apps/registrar_client/SIPRegistrarClient.cpp index e2d3c62d..a88374fc 100644 --- a/apps/registrar_client/SIPRegistrarClient.cpp +++ b/apps/registrar_client/SIPRegistrarClient.cpp @@ -49,7 +49,8 @@ SIPRegistration::SIPRegistration(const string& handle, reg_expires(0), remove(false), sess_link(sess_link), - reg_send_begin(0) + reg_send_begin(0), + waiting_result(false) { req.cmd = "sems"; req.user = info.user; @@ -78,6 +79,7 @@ void SIPRegistration::setSessionEventHandler(AmSessionEventHandler* new_seh) { } void SIPRegistration::doRegistration() { + waiting_result = true; req.to_tag = ""; dlg.remote_tag = ""; req.r_uri = "sip:"+info.domain; @@ -92,6 +94,7 @@ void SIPRegistration::doRegistration() { } void SIPRegistration::doUnregister() { + waiting_result = true; req.to_tag = ""; dlg.remote_tag = ""; req.r_uri = "sip:"+info.domain; @@ -205,7 +208,8 @@ void SIPRegistrarClient::checkTimeouts() { if (it->second->registerExpired(now.tv_sec)) { SIPRegistration* reg = it->second; reg->onRegisterExpired(); - } else if (it->second->timeToReregister(now.tv_sec)) { + } else if (!it->second->waiting_result && + it->second->timeToReregister(now.tv_sec)) { it->second->doRegistration(); } } else if (it->second->remove) { @@ -213,7 +217,8 @@ void SIPRegistrarClient::checkTimeouts() { SIPRegistration* reg = it->second; registrations.erase(it); delete reg; - } else if (it->second->registerSendTimeout(now.tv_sec)) { + } else if (it->second->waiting_result && + it->second->registerSendTimeout(now.tv_sec)) { SIPRegistration* reg = it->second; reg->onRegisterSendTimeout(); } @@ -261,7 +266,7 @@ bool SIPRegistration::registerSendTimeout(time_t now_sec) { bool SIPRegistration::timeToReregister(time_t now_sec) { // if (active) // DBG("compare %lu with %lu\n",(reg_begin+reg_expires), (unsigned long)now_sec); - return ((reg_begin+reg_expires/2) < (unsigned long)now_sec); + return ((reg_begin+reg_expires/20) < (unsigned long)now_sec); } bool SIPRegistration::registerExpired(time_t now_sec) { @@ -272,6 +277,8 @@ void SIPRegistration::onSipReply(AmSipReply& reply) { if ((seh!=NULL) && seh->onSipReply(reply)) return; + waiting_result = false; + dlg.updateStatus(reply); if ((reply.code>=200)&&(reply.code<300)) { diff --git a/apps/registrar_client/SIPRegistrarClient.h b/apps/registrar_client/SIPRegistrarClient.h index 905fcbb3..f0230c07 100644 --- a/apps/registrar_client/SIPRegistrarClient.h +++ b/apps/registrar_client/SIPRegistrarClient.h @@ -82,6 +82,7 @@ class SIPRegistration : public AmSipDialogEventHandler, time_t reg_begin; unsigned int reg_expires; time_t reg_send_begin; + public: SIPRegistration(const string& handle, const SIPRegistrationInfo& info, @@ -121,7 +122,8 @@ class SIPRegistration : public AmSipDialogEventHandler, bool active; /** should this registration be removed from container? */ bool remove; - + /** are we waiting for the response to a register? */ + bool waiting_result; }; class SIPNewRegistrationEvent;