static int db_load_domain(domain_t** d, unsigned long flags, str* domain) { int ret; int_str name, val; domain_t* p; str name_s = STR_STATIC_INIT(AVP_DID); if (flags & AVP_TRACK_FROM) { p = &dom_buf[0]; } else { p = &dom_buf[1]; } free_old_domain(p); ret = db_get_did(&p->did, domain); if (ret != 1) return ret; if (load_domain_attrs) { if (db_load_domain_attrs(p) < 0) return -1; } /* Create an attribute containing did of the domain */ name.s = name_s; val.s = p->did; if (add_avp_list(&p->attrs, AVP_CLASS_DOMAIN | AVP_NAME_STR | AVP_VAL_STR, name, val) < 0) return -1; *d = p; return 0; }
/* * Create domain list from domain table */ int load_domains(domain_t** dest) { db_res_t* res = NULL; db_rec_t* rec; unsigned int flags; domain_t* d, *list; list = 0; if (db_exec(&res, load_domains_cmd) < 0) { ERR("Error while querying database\n"); return -1; } rec = db_first(res); while(rec) { /* Do not assume that the database server performs any constrain * checking (dbtext does not) and perform sanity checks here to * make sure that we only load good entried */ if (rec->fld[0].flags & DB_NULL || rec->fld[1].flags & DB_NULL || rec->fld[2].flags & DB_NULL) { ERR("Row with NULL column(s), skipping\n"); goto skip; } flags = rec->fld[2].v.int4; /* Skip entries that are disabled/scheduled for removal */ if (flags & SRDB_DISABLED) goto skip; /* Skip entries that are for serweb/ser-ctl only */ if (!(flags & SRDB_LOAD_SER)) goto skip; DBG("Processing entry (%.*s, %.*s, %u)\n", rec->fld[0].v.lstr.len, ZSW(rec->fld[0].v.lstr.s), rec->fld[1].v.lstr.len, ZSW(rec->fld[1].v.lstr.s), flags); d = domain_search(list, &rec->fld[0].v.lstr); if (d) { /* DID exists in the list, update it */ if (domain_add(d, &rec->fld[1].v.lstr, flags) < 0) goto error; } else { /* DID does not exist yet, create a new entry */ d = new_domain(&rec->fld[0].v.lstr, &rec->fld[1].v.lstr, flags); if (!d) goto error; d->next = list; list = d; } skip: rec = db_next(res); } db_res_free(res); if (load_domain_attrs) { d = list; while(d) { if (db_load_domain_attrs(d) < 0) goto error; d = d->next; } } *dest = list; return 0; error: if (res) db_res_free(res); free_domain_list(list); return 1; }