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; } } }
static int check_iax_register(void) { int res; if (strlen(regpeer) && strlen(server)) { registry = iax_session_new(); res = iax_register(registry, server,regpeer,regsecret, refresh); if (res) { fprintf(stderr, "Failed registration: %s\n", iax_errstr); return -1; } iax_regtimeout(5 * refresh / 6); } else { iax_regtimeout(0); refresh = 60; } return 0; }
EXPORT int iaxc_register_ex(const char * user, const char * pass, const char * host, int refresh) { struct iaxc_registration *newreg; newreg = (struct iaxc_registration *)malloc(sizeof (struct iaxc_registration)); if ( !newreg ) { iaxci_usermsg(IAXC_ERROR, "Can't make new registration"); return -1; } get_iaxc_lock(); newreg->session = iax_session_new(); if ( !newreg->session ) { iaxci_usermsg(IAXC_ERROR, "Can't make new registration session"); put_iaxc_lock(); return -1; } newreg->last = iax_tvnow(); newreg->refresh = refresh; strncpy(newreg->host, host, 256); strncpy(newreg->user, user, 256); strncpy(newreg->pass, pass, 256); /* send out the initial registration with refresh seconds */ iax_register(newreg->session, host, user, pass, refresh); /* add it to the list; */ newreg->id = ++next_registration_id; newreg->next = registrations; registrations = newreg; put_iaxc_lock(); return newreg->id; }
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); } }