Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usrloc: correct AOR value on usrloc:contact-expired #3366

Merged
merged 1 commit into from
Feb 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 31 additions & 8 deletions src/modules/usrloc/udomain.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,14 +955,17 @@ int udomain_contact_expired_cb(db1_con_t* _c, udomain_t* _d)
db_val_t query_vals[3];
int key_num = 2;
db1_res_t* res = NULL;
str user, contact;
str user, contact, domain;
int i;
int n;
urecord_t r;
ucontact_t* c;
#define RUIDBUF_SIZE 128
char ruidbuf[RUIDBUF_SIZE];
str ruid;
#define AORBUF_SIZE 512
char aorbuf[AORBUF_SIZE];
str aor;

if (ul_db_mode!=DB_ONLY) {
return 0;
Expand Down Expand Up @@ -1057,6 +1060,14 @@ int udomain_contact_expired_cb(db1_con_t* _c, udomain_t* _d)
continue;
}
user.len = strlen(user.s);
if(user.len < AORBUF_SIZE ) {
memcpy(aorbuf, user.s, user.len);
aor.s = aorbuf;
aor.len = user.len;
} else {
LM_ERR("user is too long %d\n", user.len);
continue;
}

ci = dbrow2info(ROW_VALUES(row)+1, &contact, 0);
if (ci==0) {
Expand All @@ -1065,18 +1076,30 @@ int udomain_contact_expired_cb(db1_con_t* _c, udomain_t* _d)
continue;
}

lock_udomain(_d, &user);
if(ul_use_domain) {
domain.s = (char*)VAL_STRING(ROW_VALUES(row)+20);
domain.len = strlen(domain.s);
if(domain.len + aor.len < AORBUF_SIZE) {
aorbuf[aor.len] = '@';
memcpy(aorbuf+aor.len+1, domain.s, domain.len);
aor.len += domain.len + 1;
} else {
LM_ERR("aor too long, using user part only\n");
}
}

lock_udomain(_d, &aor);
/* don't use the same static value from get_static_urecord() */
memset( &r, 0, sizeof(struct urecord) );
r.aor = user;
r.aorhash = ul_get_aorhash(&user);
r.aor = aor;
r.aorhash = ul_get_aorhash(&aor);
r.domain = _d->name;

if ( (c=mem_insert_ucontact(&r, &contact, ci)) == 0) {
LM_ERR("inserting temporary contact failed for %.*s\n",
user.len, user.s);
aor.len, aor.s);
release_urecord(&r);
unlock_udomain(_d, &user);
unlock_udomain(_d, &aor);
goto error;
}

Expand All @@ -1095,11 +1118,11 @@ int udomain_contact_expired_cb(db1_con_t* _c, udomain_t* _d)
ruid.len = c->ruid.len;
} else {
LM_ERR("ruid is too long %d for %.*s\n", c->ruid.len,
user.len, user.s);
aor.len, aor.s);
}
}
release_urecord(&r);
unlock_udomain(_d, &user);
unlock_udomain(_d, &aor);
if(ruid.len > 0 && ul_xavp_contact_name.s != NULL) {
/* delete attributes by ruid */
uldb_delete_attrs_ruid(_d->name, &ruid);
Expand Down