fixes small register bug (registrations sent out more than one time)

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@168 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Stefan Sayer 20 years ago
parent 7b4faa3631
commit fbfa027e39

@ -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)) {

@ -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;

Loading…
Cancel
Save