zoom: allow Torus record wrapped in single "record" elem
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 1 Aug 2012 11:14:47 +0000 (13:14 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 1 Aug 2012 11:14:47 +0000 (13:14 +0200)
src/filter_zoom.cpp

index b337b60..ae84b7b 100644 (file)
@@ -1164,27 +1164,44 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
             return b;
         }
         const xmlNode *ptr = xmlDocGetRootElement(doc);
-        if (ptr)
-        {   // presumably ptr is a records element node
-            // parse first record in document
-            for (ptr = ptr->children; ptr; ptr = ptr->next)
+        if (ptr && ptr->type == XML_ELEMENT_NODE)
+        {
+            if (!strcmp((const char *) ptr->name, "record"))
             {
-                if (ptr->type == XML_ELEMENT_NODE
-                    && !strcmp((const char *) ptr->name, "record"))
+                sptr = m_p->parse_torus_record(ptr);
+            }
+            else if (!strcmp((const char *) ptr->name, "records"))
+            {
+                for (ptr = ptr->children; ptr; ptr = ptr->next)
                 {
-                    if (sptr)
+                    if (ptr->type == XML_ELEMENT_NODE
+                        && !strcmp((const char *) ptr->name, "record"))
                     {
-                        *error = YAZ_BIB1_UNSPECIFIED_ERROR;
-                        *addinfo = (char*) odr_malloc(odr, 40 + database.length()),
-                        sprintf(*addinfo, "multiple records for udb=%s",
-                                 database.c_str());
-                        xmlFreeDoc(doc);
-                        BackendPtr b;
-                        return b;
+                        if (sptr)
+                        {
+                            *error = YAZ_BIB1_UNSPECIFIED_ERROR;
+                            *addinfo = (char*)
+                                odr_malloc(odr, 40 + torus_db.length());
+                            sprintf(*addinfo, "multiple records for udb=%s",
+                                    database.c_str());
+                            xmlFreeDoc(doc);
+                            BackendPtr b;
+                            return b;
+                        }
+                        sptr = m_p->parse_torus_record(ptr);
                     }
-                    sptr = m_p->parse_torus_record(ptr);
                 }
             }
+            else
+            {
+                *error = YAZ_BIB1_UNSPECIFIED_ERROR;
+                *addinfo = (char*) odr_malloc(
+                    odr, 40 + strlen((const char *) ptr->name));
+                sprintf(*addinfo, "bad root element for torus: %s", ptr->name);
+                xmlFreeDoc(doc);
+                BackendPtr b;
+                return b;
+            }
         }
         xmlFreeDoc(doc);
     }