X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Fdatabase.c;h=c933181ca1dd9a1850664fb28ba90103ed56d6a4;hb=7b13bb9165493bdef71e929ebcdc02b6a6605aca;hp=fb03b403ee05bbd49200b40cd691c21ace73f3b4;hpb=b13c46b73ad2b8e85340396cfcb0b46421db1d15;p=pazpar2-moved-to-github.git diff --git a/src/database.c b/src/database.c index fb03b40..c933181 100644 --- a/src/database.c +++ b/src/database.c @@ -54,59 +54,13 @@ 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)); - 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); @@ -115,7 +69,7 @@ struct database *new_database(const char *id, NMEM nmem) 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; @@ -129,7 +83,7 @@ struct database *create_database_for_service(const char *id, { struct database *p; for (p = service->databases; p; p = p->next) - if (!strcmp(p->url, id)) + if (!strcmp(p->id, id)) return p; p = new_database(id, service->nmem); @@ -313,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