static void destroy_tables(void) { free_table(hash_1); free_table(hash_2); if (active_hash) shm_free(active_hash); if (domains_1) { free_domain_list(*domains_1); shm_free(domains_1); } if (domains_2) { free_domain_list(*domains_2); shm_free(domains_2); } }
int reload_domain_list(void) { struct hash_entry** new_table; domain_t** new_list; /* Choose new hash table and free its old contents */ if (*active_hash == hash_1) { free_table(hash_2); new_table = hash_2; new_list = domains_2; } else { free_table(hash_1); new_table = hash_1; new_list = domains_1; } if (load_domains(new_list) < 0) goto error; if (gen_domain_table(new_table, *new_list) < 0) goto error; *active_hash = new_table; return 0; error: free_table(new_table); free_domain_list(*new_list); return -1; }
/* * 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; }