Refactor access to global variable channel_list. There were a few
[pazpar2-moved-to-github.git] / src / database.c
index ab6fa8b..70e556a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: database.c,v 1.15 2007-04-11 19:55:57 quinn Exp $
+/* $Id: database.c,v 1.19 2007-04-18 12:41:38 quinn Exp $
    Copyright (c) 2006-2007, Index Data.
 
 This file is part of Pazpar2.
@@ -126,7 +126,7 @@ static struct host *find_host(const char *hostport)
 
 static struct database *load_database(const char *id)
 {
-    xmlDoc *doc = get_explain_xml(id);
+    xmlDoc *doc = 0;
     struct zr_explain *explain = 0;
     struct database *db;
     struct host *host;
@@ -136,12 +136,15 @@ static struct database *load_database(const char *id)
     yaz_log(YLOG_LOG, "New database: %s", id);
     if (!nmem)
         nmem = nmem_create();
-    if (doc)
+
+    if (config && config->targetprofiles 
+        && (doc = get_explain_xml(id)))
     {
         explain = zr_read_xml(nmem, xmlDocGetRootElement(doc));
         if (!explain)
             return 0;
     }
+
     if (strlen(id) > 255)
         return 0;
     strcpy(hostport, id);
@@ -224,19 +227,18 @@ static int match_criterion(struct setting **settings, struct database_criterion
         if (offset == PZ_ID)
         {
             if (match_zurl(settings[offset]->value, v->value))
-                return 1;
-            else
-                return 0;
+                break;
         }
         else 
         {
             if (!strcmp(settings[offset]->value, v->value))
-                return 1;
-            else
-                return 0;
+                break;
         }
     }
-    return 0;
+    if (v)
+        return 1;
+    else
+        return 0;
 }
 
 int database_match_criteria(struct setting **settings, struct database_criterion *cl)
@@ -324,19 +326,20 @@ static void prepare_yazmarc(void *ignore, struct database *db)
 
             db->yaz_marc = yaz_marc_create();
             yaz_marc_subfield_str(db->yaz_marc, "\t");
+
             // See if a native encoding is specified
-            if ((s = db->settings[PZ_ENCODING]))
-            {
-                encoding = s->value;
-                break;
-            }
-            if (!(cm = yaz_iconv_open("utf-8", encoding)))
+            if (db->settings[PZ_ENCODING])
+                encoding = db->settings[PZ_ENCODING]->value;
+            
+            cm = yaz_iconv_open("utf-8", encoding);
+            if (!cm)
             {
-                yaz_log(YLOG_FATAL, "Unable to map from %s to UTF-8", encoding);
+                yaz_log(YLOG_FATAL, 
+                        "Unable to map from %s to UTF-8 for target %s", 
+                        encoding, db->url);
                 exit(1);
             }
             yaz_marc_iconv(db->yaz_marc, cm);
-            break;
         }
 }