Added error-reporting for the case where a HTTP response is 200 OK but
[pazpar2-moved-to-github.git] / src / logic.c
index 9cfcd08..d5c8f76 100644 (file)
@@ -822,15 +822,38 @@ void pazpar2_event_loop()
 }
 
 static struct record_metadata *record_metadata_init(
-    NMEM nmem, char *value, enum conf_metadata_type type)
+    NMEM nmem, const char *value, enum conf_metadata_type type,
+    struct _xmlAttr *attr)
 {
     struct record_metadata *rec_md = record_metadata_create(nmem);
+    struct record_metadata_attr **attrp = &rec_md->attributes;
+    
+    for (; attr; attr = attr->next)
+    {
+        if (attr->children && attr->children->content)
+        {
+            if (strcmp((const char *) attr->name, "type"))
+            {  /* skip the "type" attribute.. Its value is already part of
+                  the element in output (md-%s) and so repeating it here
+                  is redundant */
+                *attrp = nmem_malloc(nmem, sizeof(**attrp));
+                (*attrp)->name =
+                    nmem_strdup(nmem, (const char *) attr->name);
+                (*attrp)->value =
+                    nmem_strdup(nmem, (const char *) attr->children->content);
+                attrp = &(*attrp)->next;
+            }
+        }
+    }
+    *attrp = 0;
+
     if (type == Metadata_type_generic)
     {
-        char * p = value;
+        char *p = nmem_strdup(nmem, value);
+
         p = normalize7bit_generic(p, " ,/.:([");
         
-        rec_md->data.text.disp = nmem_strdup(nmem, p);
+        rec_md->data.text.disp = p;
         rec_md->data.text.sort = 0;
     }
     else if (type == Metadata_type_year || type == Metadata_type_date)
@@ -1121,8 +1144,8 @@ struct record *ingest_record(struct client *cl, const char *rec,
             }
 
             // non-merged metadata
-            rec_md = record_metadata_init(se->nmem, (char *) value,
-                                          ser_md->type);
+            rec_md = record_metadata_init(se->nmem, (const char *) value,
+                                          ser_md->type, n->properties);
             if (!rec_md)
             {
                 yaz_log(YLOG_WARN, "bad metadata data '%s' for element '%s'",
@@ -1135,8 +1158,8 @@ struct record *ingest_record(struct client *cl, const char *rec,
             *wheretoput = rec_md;
 
             // merged metadata
-            rec_md = record_metadata_init(se->nmem, (char *) value,
-                                          ser_md->type);
+            rec_md = record_metadata_init(se->nmem, (const char *) value,
+                                          ser_md->type, 0);
             wheretoput = &cluster->metadata[md_field_id];
 
             // and polulate with data: