From: Adam Dickmeiss Date: Thu, 6 Oct 2011 10:21:13 +0000 (+0200) Subject: Minor refactor WRT databases X-Git-Tag: v1.6.4~5^2~20 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=b13c46b73ad2b8e85340396cfcb0b46421db1d15;p=pazpar2-moved-to-github.git Minor refactor WRT databases --- diff --git a/src/database.c b/src/database.c index fd88d0b..fb03b40 100644 --- a/src/database.c +++ b/src/database.c @@ -122,28 +122,22 @@ struct database *new_database(const char *id, NMEM nmem) return db; } -static struct database *load_database(const char *id, - struct conf_service *service) -{ - struct database *db; - - db = new_database(id, service->nmem); - - db->next = service->databases; - service->databases = db; - - return db; -} - // Return a database structure by ID. Load and add to list if necessary // new==1 just means we know it's not in the list -struct database *find_database(const char *id, struct conf_service *service) +struct database *create_database_for_service(const char *id, + struct conf_service *service) { struct database *p; for (p = service->databases; p; p = p->next) if (!strcmp(p->url, id)) return p; - return load_database(id, service); + + p = new_database(id, service->nmem); + + p->next = service->databases; + service->databases = p; + + return p; } // This whole session_grep database thing should be moved elsewhere diff --git a/src/database.h b/src/database.h index febe104..1394732 100644 --- a/src/database.h +++ b/src/database.h @@ -24,7 +24,8 @@ typedef struct database_hosts *database_hosts_t; struct session_database; struct session; struct conf_service; -struct database *find_database(const char *id, struct conf_service *service); +struct database *create_database_for_service(const char *id, + struct conf_service *service); int session_grep_databases(struct session *se, const char *filter, void (*fun)(struct session *se, struct session_database *db)); int predef_grep_databases(void *context, struct conf_service *service, diff --git a/src/settings.c b/src/settings.c index fe1b8c4..759d4bc 100644 --- a/src/settings.c +++ b/src/settings.c @@ -334,7 +334,7 @@ void expand_settings_array(struct setting ***set_ar, int *num, int offset, // This is called from grep_databases -- adds/overrides setting for a target // This is also where the rules for precedence of settings are implemented -static void update_database(void *context, struct database *db) +static void update_database_fun(void *context, struct database *db) { struct setting *set = ((struct update_database_context *) context)->set; @@ -402,7 +402,7 @@ static void update_databases(void *client_data, struct setting *set) struct update_database_context context; context.set = set; context.service = service; - predef_grep_databases(&context, service, update_database); + predef_grep_databases(&context, service, update_database_fun); } // This simply copies the 'hard' (application-specific) settings @@ -443,7 +443,7 @@ static void prepare_target_dictionary(void *client_data, struct setting *set) // If target address is not wildcard, add the database if (*set->target && !zurl_wildcard(set->target)) - find_database(set->target, service); + create_database_for_service(set->target, service); // Determine if we already have a dictionary entry if (!strncmp(set->name, "pz:", 3) && (p = strchr(set->name + 3, ':')))