static void iaxc_refresh_registrations() { struct iaxc_registration *cur; struct timeval now; now = iax_tvnow(); for ( cur = registrations; cur != NULL; cur = cur->next ) { // If there is less than three seconds before the registration is about // to expire, renew it. if ( iaxci_usecdiff(&now, &cur->last) > (cur->refresh - 3) * 1000 *1000 ) { if ( cur->session != NULL ) { iax_destroy( cur->session ); } cur->session = iax_session_new(); if ( !cur->session ) { iaxci_usermsg(IAXC_ERROR, "Can't make new registration session"); return; } iax_register(cur->session, cur->host, cur->user, cur->pass, cur->refresh); cur->last = now; } } }
void IAXVoIPLink::sendUnregister(Account *a) { if (regSession_) { ost::MutexLock m(mutexIAX_); iax_destroy(regSession_); regSession_ = NULL; } nextRefreshStamp_ = 0; dynamic_cast<IAXAccount*>(a)->setRegistrationState(Unregistered); }
/** * Handle the registration process */ void IAXVoIPLink::iaxHandleRegReply(iax_event* event) { IAXAccount *account = dynamic_cast<IAXAccount *>(Manager::instance().getAccount(accountID_)); if (event->etype != IAX_EVENT_REGREJ && event->etype != IAX_EVENT_REGACK) return; ost::MutexLock m(mutexIAX_); iax_destroy(regSession_); regSession_ = NULL; account->setRegistrationState((event->etype == IAX_EVENT_REGREJ) ? ErrorAuth : Registered); if (event->etype == IAX_EVENT_REGACK) nextRefreshStamp_ = time(NULL) + (event->ies.refresh ? event->ies.refresh : 60); }
static void iaxc_handle_regreply(struct iax_event *e, struct iaxc_registration *reg) { iaxci_do_registration_callback(reg->id, e->etype, e->ies.msgcount); // XXX I think the session is no longer valid.. at least, that's // what miniphone does, and re-using the session doesn't seem to // work! iax_destroy(reg->session); reg->session = NULL; if ( e->etype == IAX_EVENT_REGREJ ) { // we were rejected, so end the registration iaxc_remove_registration_by_id(reg->id); } }
static int iaxc_remove_registration_by_id(int id) { struct iaxc_registration *curr, *prev; int count = 0; for ( prev = NULL, curr = registrations; curr != NULL; prev = curr, curr = curr->next ) { if ( curr->id == id ) { count++; if ( curr->session != NULL ) iax_destroy( curr->session ); if ( prev != NULL ) prev->next = curr->next; else registrations = curr->next; free( curr ); break; } } return count; }
void IAXVoIPLink::sendRegister(Account *a) { IAXAccount *account = dynamic_cast<IAXAccount*>(a); if (account->getHostname().empty()) throw VoipLinkException("Account hostname is empty"); if (account->getUsername().empty()) throw VoipLinkException("Account username is empty"); ost::MutexLock m(mutexIAX_); if (regSession_) iax_destroy(regSession_); regSession_ = iax_session_new(); if (regSession_) { iax_register(regSession_, account->getHostname().data(), account->getUsername().data(), account->getPassword().data(), 120); nextRefreshStamp_ = time(NULL) + 10; account->setRegistrationState(Trying); } }