Show command may re-search for targets that support it
[pazpar2-moved-to-github.git] / src / database.c
index 2844d1b..41e0f06 100644 (file)
@@ -21,8 +21,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <config.h>
 #endif
 
-#include <libxml/parser.h>
-#include <libxml/tree.h>
 #include <assert.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -38,15 +36,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include "database.h"
 
 #include <sys/types.h>
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#if HAVE_NETDB_H
-#include <netdb.h>
-#endif
-#if HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
 
 enum pazpar2_database_criterion_type {
     PAZPAR2_STRING_MATCH,
@@ -91,8 +80,7 @@ static struct host *create_host(const char *hostport)
     return host;
 }
 
-static struct host *find_host(database_hosts_t hosts,
-                              const char *hostport)
+struct host *find_host(database_hosts_t hosts, const char *hostport)
 {
     struct host *p;
     yaz_mutex_enter(hosts->mutex);
@@ -112,67 +100,44 @@ static struct host *find_host(database_hosts_t hosts,
     return p;
 }
 
-int resolve_database(struct conf_service *service, struct database *db)
-{
-    if (db->host == 0)
-    {
-        struct host *host;
-        if (!(host = find_host(service->server->database_hosts, db->url)))
-            return -1;
-        db->host = host;
-    }
-    return 0;
-}
-
 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->errors = 0;
-    db->host = 0;
-
+    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