report registration send failure; add method to get TS

sayer/1.4-spce2.6
Stefan Sayer 15 years ago committed by Stefan Sayer
parent 2899853dd2
commit 5f0f354287

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

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

Loading…
Cancel
Save