Module: sip-router
Branch: 4.0
Commit: 060c8cd03ee745aa48b21d946ebfa9e3671d89c3
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=060c8cd…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Fri Mar 29 11:02:31 2013 +0100
usrloc: use NULL domain for updating ul attributes for use_domain=0
- use counter var for db matching keys
(cherry picked from commit 50b116cf4c9c33c4f23c1d5b66fd313a7f40c572)
---
modules/usrloc/ucontact.c | 117 ++++++++++++++++++++++++++------------------
1 files changed, 69 insertions(+), 48 deletions(-)
diff --git a/modules/usrloc/ucontact.c b/modules/usrloc/ucontact.c
index 91ecddc..c265580 100644
--- a/modules/usrloc/ucontact.c
+++ b/modules/usrloc/ucontact.c
@@ -633,6 +633,7 @@ int db_update_ucontact(ucontact_t* _c)
char* dom;
db_key_t keys1[4];
db_val_t vals1[4];
+ int n1;
db_key_t keys2[14];
db_val_t vals2[14];
@@ -643,10 +644,6 @@ int db_update_ucontact(ucontact_t* _c)
return 0;
}
- keys1[0] = &user_col;
- keys1[1] = &contact_col;
- keys1[2] = &callid_col;
- keys1[3] = &domain_col;
keys2[0] = &expires_col;
keys2[1] = &q_col;
keys2[2] = &cseq_col;
@@ -662,17 +659,24 @@ int db_update_ucontact(ucontact_t* _c)
keys2[12] = &instance_col;
keys2[13] = ®_id_col;
- vals1[0].type = DB1_STR;
- vals1[0].nul = 0;
- vals1[0].val.str_val = *_c->aor;
-
- vals1[1].type = DB1_STR;
- vals1[1].nul = 0;
- vals1[1].val.str_val = _c->c;
-
- vals1[2].type = DB1_STR;
- vals1[2].nul = 0;
- vals1[2].val.str_val = _c->callid;
+ n1 = 0;
+ keys1[n1] = &user_col;
+ vals1[n1].type = DB1_STR;
+ vals1[n1].nul = 0;
+ vals1[n1].val.str_val = *_c->aor;
+ n1++;
+
+ keys1[n1] = &contact_col;
+ vals1[n1].type = DB1_STR;
+ vals1[n1].nul = 0;
+ vals1[n1].val.str_val = _c->c;
+ n1++;
+
+ keys1[n1] = &callid_col;
+ vals1[n1].type = DB1_STR;
+ vals1[n1].nul = 0;
+ vals1[n1].val.str_val = _c->callid;
+ n1++;
vals2[0].type = DB1_DATETIME;
vals2[0].nul = 0;
@@ -761,17 +765,19 @@ int db_update_ucontact(ucontact_t* _c)
nr_cols2++;
if (use_domain) {
- vals1[3].type = DB1_STR;
- vals1[3].nul = 0;
+ keys1[n1] = &domain_col;
+ vals1[n1].type = DB1_STR;
+ vals1[n1].nul = 0;
dom = memchr(_c->aor->s, '@', _c->aor->len);
if (dom==0) {
vals1[0].val.str_val.len = 0;
- vals1[3].val.str_val = *_c->aor;
+ vals1[n1].val.str_val = *_c->aor;
} else {
vals1[0].val.str_val.len = dom - _c->aor->s;
- vals1[3].val.str_val.s = dom + 1;
- vals1[3].val.str_val.len = _c->aor->s + _c->aor->len - dom - 1;
+ vals1[n1].val.str_val.s = dom + 1;
+ vals1[n1].val.str_val.len = _c->aor->s + _c->aor->len - dom - 1;
}
+ n1++;
}
if (ul_dbf.use_table(ul_dbh, _c->domain) < 0) {
@@ -779,8 +785,8 @@ int db_update_ucontact(ucontact_t* _c)
return -1;
}
- if (ul_dbf.update(ul_dbh, keys1, 0, vals1, keys2, vals2,
- (use_domain) ? (4) : (3), nr_cols2) < 0) {
+ if (ul_dbf.update(ul_dbh, keys1, 0, vals1, keys2, vals2, n1,
+ nr_cols2) < 0) {
LM_ERR("updating database failed\n");
return -1;
}
@@ -795,10 +801,17 @@ int db_update_ucontact(ucontact_t* _c)
}
}
/* delete old db attrs and add the current list */
- uldb_delete_attrs(_c->domain, &vals1[0].val.str_val,
- &vals1[3].val.str_val, &_c->ruid);
- uldb_insert_attrs(_c->domain, &vals1[0].val.str_val, &vals1[3].val.str_val,
- &_c->ruid, _c->xavp);
+ if (use_domain) {
+ uldb_delete_attrs(_c->domain, &vals1[0].val.str_val,
+ &vals1[n1-1].val.str_val, &_c->ruid);
+ uldb_insert_attrs(_c->domain, &vals1[0].val.str_val,
+ &vals1[n1-1].val.str_val, &_c->ruid, _c->xavp);
+ } else {
+ uldb_delete_attrs(_c->domain, &vals1[0].val.str_val,
+ NULL, &_c->ruid);
+ uldb_insert_attrs(_c->domain, &vals1[0].val.str_val,
+ NULL, &_c->ruid, _c->xavp);
+ }
return 0;
}
@@ -814,51 +827,59 @@ int db_delete_ucontact(ucontact_t* _c)
char* dom;
db_key_t keys[4];
db_val_t vals[4];
+ int n;
if (_c->flags & FL_MEM) {
return 0;
}
- keys[0] = &user_col;
- keys[1] = &contact_col;
- keys[2] = &callid_col;
- keys[3] = &domain_col;
- vals[0].type = DB1_STR;
- vals[0].nul = 0;
- vals[0].val.str_val = *_c->aor;
+ n = 0;
+ keys[n] = &user_col;
+ vals[n].type = DB1_STR;
+ vals[n].nul = 0;
+ vals[n].val.str_val = *_c->aor;
+ n++;
- vals[1].type = DB1_STR;
- vals[1].nul = 0;
- vals[1].val.str_val = _c->c;
+ keys[n] = &contact_col;
+ vals[n].type = DB1_STR;
+ vals[n].nul = 0;
+ vals[n].val.str_val = _c->c;
+ n++;
- vals[2].type = DB1_STR;
- vals[2].nul = 0;
- vals[2].val.str_val = _c->callid;
+ keys[n] = &callid_col;
+ vals[n].type = DB1_STR;
+ vals[n].nul = 0;
+ vals[n].val.str_val = _c->callid;
+ n++;
if (use_domain) {
- vals[3].type = DB1_STR;
- vals[3].nul = 0;
+ keys[n] = &domain_col;
+ vals[n].type = DB1_STR;
+ vals[n].nul = 0;
dom = memchr(_c->aor->s, '@', _c->aor->len);
if (dom==0) {
vals[0].val.str_val.len = 0;
- vals[3].val.str_val = *_c->aor;
+ vals[n].val.str_val = *_c->aor;
} else {
vals[0].val.str_val.len = dom - _c->aor->s;
- vals[3].val.str_val.s = dom + 1;
- vals[3].val.str_val.len = _c->aor->s + _c->aor->len - dom - 1;
+ vals[n].val.str_val.s = dom + 1;
+ vals[n].val.str_val.len = _c->aor->s + _c->aor->len - dom - 1;
}
+ uldb_delete_attrs(_c->domain, &vals[0].val.str_val,
+ &vals[n].val.str_val, &_c->ruid);
+ n++;
+ } else {
+ uldb_delete_attrs(_c->domain, &vals[0].val.str_val,
+ NULL, &_c->ruid);
}
- uldb_delete_attrs(_c->domain, &vals[0].val.str_val,
- &vals[3].val.str_val, &_c->ruid);
-
if (ul_dbf.use_table(ul_dbh, _c->domain) < 0) {
LM_ERR("sql use_table failed\n");
return -1;
}
- if (ul_dbf.delete(ul_dbh, keys, 0, vals, (use_domain) ? (4) : (3)) < 0) {
+ if (ul_dbf.delete(ul_dbh, keys, 0, vals, n) < 0) {
LM_ERR("deleting from database failed\n");
return -1;
}