int run_timer_check(void *e_data, void *data, void *r_data) { unsigned int i=hash_index; reg_record_t *rec = (reg_record_t*)e_data; struct timer_check_data *t_check_data = (struct timer_check_data*)data; time_t now = t_check_data->now; str *s_now = t_check_data->s_now; switch(rec->state){ case REGISTERING_STATE: case AUTHENTICATING_STATE: break; case WRONG_CREDENTIALS_STATE: case REGISTER_TIMEOUT_STATE: case INTERNAL_ERROR_STATE: case REGISTRAR_ERROR_STATE: reg_print_record(rec); new_call_id_ftag_4_record(rec, s_now); if(send_register(i, rec, NULL)==1) { rec->last_register_sent = now; rec->state = REGISTERING_STATE; } else { rec->registration_timeout = now + rec->expires - timer_interval; rec->state = INTERNAL_ERROR_STATE; } break; case REGISTERED_STATE: /* check if we need to re-register */ if (now < rec->registration_timeout) { break; } case NOT_REGISTERED_STATE: if(send_register(i, rec, NULL)==1) { rec->last_register_sent = now; rec->state = REGISTERING_STATE; } else { rec->registration_timeout = now + rec->expires - timer_interval; rec->state = INTERNAL_ERROR_STATE; } break; default: LM_ERR("Unexpected state [%d] for rec [%p]\n", rec->state, rec); } return 0; /* continue list traversal */ }
void timer_check(unsigned int ticks, void* param) { unsigned int i=hash_index; reg_record_t *rec; char *p; int len; time_t now; str str_now = {NULL, 0}; now = time(0); p = int2str((unsigned long)(time(0)), &len); if (p && len>0) { str_now.s = (char *)pkg_malloc(len); if (str_now.s) { memcpy(str_now.s, p, len); str_now.len = len; } else { LM_ERR("oom\n"); return; } } lock_get(®_htable[i].lock); //LM_DBG("checking ... [%d] on htable[%d]\n", (unsigned int)now, i); rec = reg_htable[i].first; while (rec) { switch(rec->state){ case REGISTERING_STATE: case AUTHENTICATING_STATE: case WRONG_CREDENTIALS_STATE: break; case REGISTER_TIMEOUT_STATE: case INTERNAL_ERROR_STATE: case REGISTRAR_ERROR_STATE: reg_print_record(rec); new_call_id_ftag_4_record(rec, &str_now); if(send_register(i, rec, NULL)==1) { rec->last_register_sent = now; rec->state = REGISTERING_STATE; } else { rec->registration_timeout = now + rec->expires - timer_interval; rec->state = INTERNAL_ERROR_STATE; } break; case REGISTERED_STATE: /* check if we need to re-register */ if (now < rec->registration_timeout) { break; } case NOT_REGISTERED_STATE: if(send_register(i, rec, NULL)==1) { rec->last_register_sent = now; rec->state = REGISTERING_STATE; } else { rec->registration_timeout = now + rec->expires - timer_interval; rec->state = INTERNAL_ERROR_STATE; } break; default: LM_ERR("Unexpected state [%d] for rec [%p]\n", rec->state, rec); } rec = rec->next; } lock_release(®_htable[i].lock); if (str_now.s) {pkg_free(str_now.s);} hash_index = (++i)%reg_hsize; return; }