|
@@ -531,12 +531,18 @@ error:
|
|
|
*/
|
|
|
urecord_t* db_load_urecord(db1_con_t* _c, udomain_t* _d, str *_aor)
|
|
|
{
|
|
|
+ char tname_buf[64];
|
|
|
+ str tname;
|
|
|
ucontact_info_t *ci;
|
|
|
db_key_t columns[16];
|
|
|
db_key_t keys[2];
|
|
|
db_key_t order;
|
|
|
db_val_t vals[2];
|
|
|
db1_res_t* res = NULL;
|
|
|
+ db_row_t *row;
|
|
|
+ str aname;
|
|
|
+ str avalue;
|
|
|
+ sr_xval_t aval;
|
|
|
str contact;
|
|
|
char *domain;
|
|
|
int i;
|
|
@@ -630,6 +636,88 @@ urecord_t* db_load_urecord(db1_con_t* _c, udomain_t* _d, str *_aor)
|
|
|
}
|
|
|
|
|
|
ul_dbf.free_result(_c, res);
|
|
|
+
|
|
|
+ /* Retrieve ul attributes */
|
|
|
+ if(ul_xavp_contact_name.s==NULL) {
|
|
|
+ /* feature disabled by mod param */
|
|
|
+ goto done;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(_d->name->len + 6>=64) {
|
|
|
+ LM_ERR("attributes table name is too big\n");
|
|
|
+ goto done;
|
|
|
+ }
|
|
|
+ strncpy(tname_buf, _d->name->s, _d->name->len);
|
|
|
+ tname_buf[_d->name->len] = '\0';
|
|
|
+ strcat(tname_buf, "_attrs");
|
|
|
+ tname.s = tname_buf;
|
|
|
+ tname.len = _d->name->len + 6;
|
|
|
+
|
|
|
+ keys[0] = &ulattrs_ruid_col;
|
|
|
+ vals[0].type = DB1_STR;
|
|
|
+ vals[0].nul = 0;
|
|
|
+ columns[0] = &ulattrs_aname_col;
|
|
|
+ columns[1] = &ulattrs_atype_col;
|
|
|
+ columns[2] = &ulattrs_avalue_col;
|
|
|
+
|
|
|
+ if (ul_dbf.use_table(ul_dbh, &tname) < 0) {
|
|
|
+ LM_ERR("sql use_table failed for %.*s\n", tname.len, tname.s);
|
|
|
+ goto done;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (c = r->contacts; c != NULL; c = c->next) {
|
|
|
+ vals[0].val.str_val.s = c->ruid.s;
|
|
|
+ vals[0].val.str_val.len = c->ruid.len;
|
|
|
+
|
|
|
+ if (ul_dbf.query(ul_dbh, keys, 0, vals, columns, 1, 3, 0, &res) < 0) {
|
|
|
+ LM_ERR("db_query failed\n");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (RES_ROW_N(res) == 0) {
|
|
|
+ LM_DBG("location attrs table is empty\n");
|
|
|
+ ul_dbf.free_result(ul_dbh, res);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ for(i = 0; i < RES_ROW_N(res); i++) {
|
|
|
+ row = RES_ROWS(res) + i;
|
|
|
+
|
|
|
+ aname.s = (char*)VAL_STRING(ROW_VALUES(row));
|
|
|
+ aname.len = strlen(aname.s);
|
|
|
+ avalue.s = (char*)VAL_STRING(ROW_VALUES(row) + 2);
|
|
|
+ avalue.len = strlen(avalue.s);
|
|
|
+ memset(&aval, 0, sizeof(sr_xval_t));
|
|
|
+ if(VAL_INT(ROW_VALUES(row)+1)==0) {
|
|
|
+ /* string value */
|
|
|
+ aval.v.s = avalue;
|
|
|
+ aval.type = SR_XTYPE_STR;
|
|
|
+ } else if(VAL_INT(ROW_VALUES(row)+1)==1) {
|
|
|
+ /* int value */
|
|
|
+ str2sint(&avalue, &aval.v.i);
|
|
|
+ aval.type = SR_XTYPE_INT;
|
|
|
+ } else {
|
|
|
+ /* unknown type - ignore */
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* add xavp to contact */
|
|
|
+ if(c->xavp==NULL) {
|
|
|
+ if(xavp_add_xavp_value(&ul_xavp_contact_name, &aname,
|
|
|
+ &aval, &c->xavp)==NULL)
|
|
|
+ LM_INFO("cannot add first xavp to contact - ignoring\n");
|
|
|
+ } else {
|
|
|
+ if(c->xavp->val.type==SR_XTYPE_XAVP) {
|
|
|
+ if(xavp_add_value(&aname, &aval, &c->xavp->val.v.xavp)==NULL)
|
|
|
+ LM_INFO("cannot add values to contact xavp\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ul_dbf.free_result(ul_dbh, res);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+done:
|
|
|
return r;
|
|
|
}
|
|
|
|