+ if (!pazpar2_decref(&service->ref_count, service->mutex))
+ {
+ pp2_charset_fact_destroy(service->charsets);
+ yaz_mutex_destroy(&service->mutex);
+ nmem_destroy(service->nmem);
+ }
+ }
+}
+
+void service_incref(struct conf_service *service)
+{
+ yaz_log(YLOG_LOG, "service_incref. p=%p cnt=%d", service,
+ service->ref_count);
+ pazpar2_incref(&service->ref_count, service->mutex);
+}
+
+static int parse_metadata(struct conf_service *service, xmlNode *n,
+ int *md_node, int *sk_node)
+{
+ enum conf_metadata_type type = Metadata_type_generic;
+ enum conf_metadata_merge merge = Metadata_merge_no;
+ enum conf_setting_type setting = Metadata_setting_no;
+ enum conf_metadata_mergekey mergekey_type = Metadata_mergekey_no;
+ int brief = 0;
+ int termlist = 0;
+ int rank = 0;
+ int sortkey_offset = 0;
+ xmlChar *xml_name = 0;
+ xmlChar *xml_brief = 0;
+ xmlChar *xml_sortkey = 0;
+ xmlChar *xml_merge = 0;
+ xmlChar *xml_type = 0;
+ xmlChar *xml_termlist = 0;
+ xmlChar *xml_rank = 0;
+ xmlChar *xml_setting = 0;
+ xmlChar *xml_mergekey = 0;
+ xmlChar *xml_icu_chain = 0;
+ struct _xmlAttr *attr;
+ for (attr = n->properties; attr; attr = attr->next)
+ {
+ if (!xmlStrcmp(attr->name, BAD_CAST "name") &&
+ attr->children && attr->children->type == XML_TEXT_NODE)
+ xml_name = attr->children->content;
+ else if (!xmlStrcmp(attr->name, BAD_CAST "brief") &&
+ attr->children && attr->children->type == XML_TEXT_NODE)
+ xml_brief = attr->children->content;
+ else if (!xmlStrcmp(attr->name, BAD_CAST "sortkey") &&
+ attr->children && attr->children->type == XML_TEXT_NODE)
+ xml_sortkey = attr->children->content;
+ else if (!xmlStrcmp(attr->name, BAD_CAST "merge") &&
+ attr->children && attr->children->type == XML_TEXT_NODE)
+ xml_merge = attr->children->content;
+ else if (!xmlStrcmp(attr->name, BAD_CAST "type") &&
+ attr->children && attr->children->type == XML_TEXT_NODE)
+ xml_type = attr->children->content;
+ else if (!xmlStrcmp(attr->name, BAD_CAST "termlist") &&
+ attr->children && attr->children->type == XML_TEXT_NODE)
+ xml_termlist = attr->children->content;
+ else if (!xmlStrcmp(attr->name, BAD_CAST "rank") &&
+ attr->children && attr->children->type == XML_TEXT_NODE)
+ xml_rank = attr->children->content;
+ else if (!xmlStrcmp(attr->name, BAD_CAST "setting") &&
+ attr->children && attr->children->type == XML_TEXT_NODE)
+ xml_setting = attr->children->content;
+ else if (!xmlStrcmp(attr->name, BAD_CAST "mergekey") &&
+ attr->children && attr->children->type == XML_TEXT_NODE)
+ xml_mergekey = attr->children->content;
+ else if (!xmlStrcmp(attr->name, BAD_CAST "facetrule") &&
+ attr->children && attr->children->type == XML_TEXT_NODE)
+ xml_icu_chain = attr->children->content;
+ else
+ {
+ yaz_log(YLOG_FATAL, "Unknown metadata attribute '%s'", attr->name);
+ return -1;
+ }
+ }
+
+ // now do the parsing logic
+ if (!xml_name)
+ {
+ yaz_log(YLOG_FATAL, "Must specify name in metadata element");
+ return -1;
+ }
+ if (xml_brief)
+ {
+ if (!strcmp((const char *) xml_brief, "yes"))
+ brief = 1;
+ else if (strcmp((const char *) xml_brief, "no"))
+ {
+ yaz_log(YLOG_FATAL, "metadata/brief must be yes or no");
+ return -1;
+ }
+ }
+
+ if (xml_termlist)
+ {
+ if (!strcmp((const char *) xml_termlist, "yes"))
+ termlist = 1;
+ else if (strcmp((const char *) xml_termlist, "no"))
+ {
+ yaz_log(YLOG_FATAL, "metadata/termlist must be yes or no");
+ return -1;
+ }