From 907fd760f429fa5f0da73b856221bdaac3ab45ee Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 20 Oct 2009 12:52:16 +0200 Subject: [PATCH] Preserve pz:metadata attributes Pazpar2 now preserves pz:metadata attributes for non-merged elements. This allows custom attributes to be passed through to a user interface from records. --- src/http_command.c | 10 +++++++++- src/logic.c | 28 +++++++++++++++++++++++++--- src/record.c | 1 + src/record.h | 6 ++++++ 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/http_command.c b/src/http_command.c index 9749ce6..752c329 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -531,8 +531,16 @@ static void write_metadata(WRBUF w, struct conf_service *service, continue; for (md = ml[imeta]; md; md = md->next) { - wrbuf_printf(w, "\n", cmd->name); + struct record_metadata_attr *attr = md->attributes; + wrbuf_printf(w, "\nname); + for (; attr; attr = attr->next) + { + wrbuf_printf(w, " %s=\"", attr->name); + wrbuf_xmlputs(w, attr->value); + wrbuf_puts(w, "\""); + } + wrbuf_puts(w, ">"); switch (cmd->type) { case Metadata_type_generic: diff --git a/src/logic.c b/src/logic.c index 0d578a0..d5c8f76 100644 --- a/src/logic.c +++ b/src/logic.c @@ -822,9 +822,31 @@ void pazpar2_event_loop() } static struct record_metadata *record_metadata_init( - NMEM nmem, const 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 = nmem_strdup(nmem, value); @@ -1123,7 +1145,7 @@ struct record *ingest_record(struct client *cl, const char *rec, // non-merged metadata rec_md = record_metadata_init(se->nmem, (const char *) value, - ser_md->type); + ser_md->type, n->properties); if (!rec_md) { yaz_log(YLOG_WARN, "bad metadata data '%s' for element '%s'", @@ -1137,7 +1159,7 @@ struct record *ingest_record(struct client *cl, const char *rec, // merged metadata rec_md = record_metadata_init(se->nmem, (const char *) value, - ser_md->type); + ser_md->type, 0); wheretoput = &cluster->metadata[md_field_id]; // and polulate with data: diff --git a/src/record.c b/src/record.c index 080822f..d5e1b81 100644 --- a/src/record.c +++ b/src/record.c @@ -85,6 +85,7 @@ struct record_metadata * record_metadata_create(NMEM nmem) struct record_metadata * rec_md = nmem_malloc(nmem, sizeof(struct record_metadata)); rec_md->next = 0; + rec_md->attributes = 0; return rec_md; } diff --git a/src/record.h b/src/record.h index 08ce3f4..872c36e 100644 --- a/src/record.h +++ b/src/record.h @@ -37,11 +37,17 @@ union data_types { }; +struct record_metadata_attr { + char *name; + char *value; + struct record_metadata_attr *next; +}; struct record_metadata { union data_types data; // next item of this name struct record_metadata *next; + struct record_metadata_attr *attributes; }; union data_types * data_types_assign(NMEM nmem, -- 1.7.10.4