X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fdatabase.c;h=139950be3a2f88bddae460fd13fe3caba72cef8a;hb=6d01755305a7afba15ed4bc90ac9c149ee7d130e;hp=2a871a4e7021beaac1cc80d65c273903f004894f;hpb=da186c5b5656cd210b2a8a8d9c75d2af0c8c3f66;p=pazpar2-moved-to-github.git diff --git a/src/database.c b/src/database.c index 2a871a4..139950b 100644 --- a/src/database.c +++ b/src/database.c @@ -1,5 +1,5 @@ /* This file is part of Pazpar2. - Copyright (C) 2006-2011 Index Data + Copyright (C) 2006-2012 Index Data Pazpar2 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -54,99 +54,44 @@ struct database_criterion { struct database_criterion *next; }; -struct database_hosts { - struct host *hosts; - YAZ_MUTEX mutex; -}; - -// Create a new host structure for hostport -static struct host *create_host(const char *hostport) -{ - struct host *host; - char *db_comment; - - host = xmalloc(sizeof(struct host)); - host->hostport = xstrdup(hostport); - db_comment = strchr(host->hostport, '#'); - if (db_comment) - *db_comment = '\0'; - host->connections = 0; - host->mutex = 0; - - pazpar2_mutex_create(&host->mutex, "host"); - - yaz_cond_create(&host->cond_ready); - - return host; -} - -struct host *find_host(database_hosts_t hosts, const char *hostport) -{ - struct host *p; - yaz_mutex_enter(hosts->mutex); - for (p = hosts->hosts; p; p = p->next) - if (!strcmp(p->hostport, hostport)) - break; - if (!p) - { - p = create_host(hostport); - if (p) - { - p->next = hosts->hosts; - hosts->hosts = p; - } - } - yaz_mutex_leave(hosts->mutex); - return p; -} - struct database *new_database(const char *id, NMEM nmem) { struct database *db; struct setting *idset; db = nmem_malloc(nmem, sizeof(*db)); - memset(db, 0, sizeof(*db)); - - db->url = nmem_strdup(nmem, id); - + db->id = nmem_strdup(nmem, id); db->num_settings = PZ_MAX_EOF; db->settings = nmem_malloc(nmem, sizeof(struct settings*) * db->num_settings); + db->next = 0; memset(db->settings, 0, sizeof(struct settings*) * db->num_settings); idset = nmem_malloc(nmem, sizeof(*idset)); idset->precedence = 0; idset->name = "pz:id"; - idset->target = idset->value = db->url; + idset->target = idset->value = db->id; idset->next = 0; db->settings[PZ_ID] = idset; - db->next = 0; - - 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)) + if (!strcmp(p->id, 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 @@ -172,7 +117,7 @@ int match_zurl(const char *zurl, const char *pattern) if (!strncmp(pattern, zurl, len)) return 1; else - return 2; + return 0; } else if (!strcmp(pattern, zurl)) return 1; @@ -322,34 +267,6 @@ int predef_grep_databases(void *context, struct conf_service *service, return i; } -database_hosts_t database_hosts_create(void) -{ - database_hosts_t p = xmalloc(sizeof(*p)); - p->hosts = 0; - p->mutex = 0; - pazpar2_mutex_create(&p->mutex, "database"); - return p; -} - -void database_hosts_destroy(database_hosts_t *pp) -{ - if (*pp) - { - struct host *p = (*pp)->hosts; - while (p) - { - struct host *p_next = p->next; - yaz_mutex_destroy(&p->mutex); - yaz_cond_destroy(&p->cond_ready); - xfree(p->hostport); - xfree(p); - p = p_next; - } - yaz_mutex_destroy(&(*pp)->mutex); - xfree(*pp); - } -} - /* * Local variables: * c-basic-offset: 4