reg_uac_t *reg_ht_get_byuser(str *user, str *domain) { unsigned int hash; unsigned int slot; reg_item_t *it = NULL; if(_reg_htable==NULL) { LM_ERR("reg hash table not initialized\n"); return NULL; } hash = reg_compute_hash(user); slot = reg_get_entry(hash, _reg_htable->htsize); it = _reg_htable->entries[slot].byuser; while(it) { if((it->r->h_uuid==hash) && (it->r->l_username.len==user->len) && (strncmp(it->r->l_username.s, user->s, user->len)==0)) { if(domain!=NULL && domain->s!=NULL) { if((it->r->l_domain.len==domain->len) && (strncmp(it->r->l_domain.s, domain->s, domain->len)==0)) { return it->r; } } else { return it->r; } } it = it->next; } return NULL; }
int reg_ht_add_byuser(reg_uac_t *reg) { unsigned int slot; reg_item_t *ri = NULL; if(_reg_htable==NULL) { LM_ERR("reg hash table not initialized\n"); return -1; } ri = (reg_item_t*)shm_malloc(sizeof(reg_item_t)); if(ri==NULL) { LM_ERR("no more shm\n"); return -1; } memset(ri, 0, sizeof(reg_item_t)); slot = reg_get_entry(reg->h_user, _reg_htable->htsize); ri->r = reg; lock_get(&_reg_htable->entries[slot].lock); ri->next = _reg_htable->entries[slot].byuser; _reg_htable->entries[slot].byuser = ri; _reg_htable->entries[slot].usize++; lock_release(&_reg_htable->entries[slot].lock); return 0; }
reg_uac_t *reg_ht_get_byuuid(str *uuid) { unsigned int hash; unsigned int slot; reg_item_t *it = NULL; if(_reg_htable==NULL) { LM_ERR("reg hash table not initialized\n"); return NULL; } hash = reg_compute_hash(uuid); slot = reg_get_entry(hash, _reg_htable->htsize); it = _reg_htable->entries[slot].byuuid; while(it) { if((it->r->h_uuid==hash) && (it->r->l_uuid.len==uuid->len) && (strncmp(it->r->l_uuid.s, uuid->s, uuid->len)==0)) { return it->r; } it = it->next; } return NULL; }
int reg_ht_update_attrs(reg_uac_t *reg) { unsigned int slot; reg_item_t *ri = NULL; if(_reg_htable==NULL) { LM_ERR("reg hash table not initialized\n"); return -1; } if(reg->auth_password.len>UAC_REG_MAX_PASSWD_SIZE) { LM_ERR("password is too big: %d\n", reg->auth_password.len); return -1; } if(reg->auth_proxy.len>UAC_REG_MAX_URI_SIZE) { LM_ERR("proxy uri is too big: %d\n", reg->auth_proxy.len); return -1; } slot = reg_get_entry(reg->h_user, _reg_htable->htsize); lock_get(&_reg_htable->entries[slot].lock); ri = _reg_htable->entries[slot].byuser; while(ri) { if(ri->r->l_uuid.len == reg->l_uuid.len && strncmp(ri->r->l_uuid.s, reg->l_uuid.s, reg->l_uuid.len)==0) { /* record found */ strncpy(ri->r->auth_password.s, reg->auth_password.s, reg->auth_password.len); ri->r->auth_password.len = reg->auth_password.len; ri->r->auth_password.s[reg->auth_password.len] = '\0'; strncpy(ri->r->auth_proxy.s, reg->auth_proxy.s, reg->auth_proxy.len); ri->r->auth_proxy.len = reg->auth_proxy.len; ri->r->auth_proxy.s[reg->auth_proxy.len] = '\0'; if(reg->flags & UAC_REG_DISABLED) ri->r->flags |= UAC_REG_DISABLED; else ri->r->flags &= ~UAC_REG_DISABLED; lock_release(&_reg_htable->entries[slot].lock); return 0; } ri = ri->next; } lock_release(&_reg_htable->entries[slot].lock); return -1; }