Simplify ZURL resolving and use regular getaddrinfo
[pazpar2-moved-to-github.git] / src / database.c
index 08359d6..1a450af 100644 (file)
@@ -65,29 +65,25 @@ 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, iochan_man_t iochan_man)
+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->ipport = 0;
     host->mutex = 0;
 
-    if (host_getaddrinfo(host, iochan_man))
-    {
-        xfree(host->hostport);
-        xfree(host);
-        return 0;
-    }
     pazpar2_mutex_create(&host->mutex, "host");
 
     yaz_cond_create(&host->cond_ready);
@@ -96,7 +92,7 @@ static struct host *create_host(const char *hostport, iochan_man_t iochan_man)
 }
 
 static struct host *find_host(database_hosts_t hosts,
-                              const char *hostport, iochan_man_t iochan_man)
+                              const char *hostport)
 {
     struct host *p;
     yaz_mutex_enter(hosts->mutex);
@@ -105,7 +101,7 @@ static struct host *find_host(database_hosts_t hosts,
             break;
     if (!p)
     {
-        p = create_host(hostport, iochan_man);
+        p = create_host(hostport);
         if (p)
         {
             p->next = hosts->hosts;
@@ -121,13 +117,7 @@ int resolve_database(struct conf_service *service, struct database *db)
     if (db->host == 0)
     {
         struct host *host;
-        char *p;
-        char hostport[256];
-        strcpy(hostport, db->url);
-        if ((p = strchr(hostport, '/')))
-            *p = '\0';
-        if (!(host = find_host(service->server->database_hosts,
-                               hostport, service->server->iochan_man)))
+        if (!(host = find_host(service->server->database_hosts, db->url)))
             return -1;
         db->host = host;
     }
@@ -144,30 +134,14 @@ void resolve_databases(struct conf_service *service)
 struct database *new_database(const char *id, NMEM nmem)
 {
     struct database *db;
-    char hostport[256];
-    char *dbname;
-    char *db_comment;
     struct setting *idset;
 
-    if (strlen(id) > 255)
-        return 0;
-    strcpy(hostport, id);
-    if ((dbname = strchr(hostport, '/')))
-        *(dbname++) = '\0';
-    else
-        dbname = "";
-    db_comment = strchr(dbname, '#');
-    if (db_comment)
-        *db_comment = '\0';
     db = nmem_malloc(nmem, sizeof(*db));
     memset(db, 0, sizeof(*db));
-    db->host = 0;
+
     db->url = nmem_strdup(nmem, id);
-    db->databases = nmem_malloc(nmem, 2 * sizeof(char *));
-    db->databases[0] = nmem_strdup(nmem, dbname);
-    db->databases[1] = 0;
     db->errors = 0;
-    db->explain = 0;
+    db->host = 0;
 
     db->num_settings = PZ_MAX_EOF;
     db->settings = nmem_malloc(nmem, sizeof(struct settings*) * 
@@ -188,10 +162,9 @@ static struct database *load_database(const char *id,
                                       struct conf_service *service)
 {
     struct database *db;
-    struct zr_explain *explain = 0;
 
     db = new_database(id, service->nmem);
-    db->explain = explain;
+    
     db->next = service->databases;
     service->databases = db;
 
@@ -344,7 +317,7 @@ static int database_match_criteria(struct setting **settings,
 // Cycles through databases, calling a handler function on the ones for
 // which all criteria matched.
 int session_grep_databases(struct session *se, const char *filter,
-                           void (*fun)(void *context, struct session_database *db))
+                           void (*fun)(struct session *se, struct session_database *db))
 {
     struct session_database *p;
     NMEM nmem = nmem_create();
@@ -401,7 +374,6 @@ void database_hosts_destroy(database_hosts_t *pp)
             struct host *p_next = p->next;
             yaz_mutex_destroy(&p->mutex);
             yaz_cond_destroy(&p->cond_ready);
-            xfree(p->ipport);
             xfree(p->hostport);
             xfree(p);
             p = p_next;