+static ZEBRA_RES create_schemas(struct filter_info *tinfo, const char *fname)
+{
+ char tmp_full_name[1024];
+ xmlNodePtr ptr;
+ tinfo->fname = xstrdup(fname);
+
+ if (yaz_filepath_resolve(tinfo->fname, tinfo->profile_path,
+ NULL, tmp_full_name))
+ tinfo->full_name = xstrdup(tmp_full_name);
+ else
+ tinfo->full_name = xstrdup(tinfo->fname);
+
+ yaz_log(YLOG_LOG, "alvis filter: loading config file %s", tinfo->full_name);
+
+ tinfo->doc = xmlParseFile(tinfo->full_name);
+
+ if (!tinfo->doc){
+ yaz_log(YLOG_WARN, "alvis filter: could not parse config file %s",
+ tinfo->full_name);
+
+ return ZEBRA_FAIL;
+ }
+
+ ptr = xmlDocGetRootElement(tinfo->doc);
+ if (!ptr || ptr->type != XML_ELEMENT_NODE ||
+ XML_STRCMP(ptr->name, "schemaInfo")){
+ yaz_log(YLOG_WARN,
+ "alvis filter: config file %s :"
+ " expected root element <schemaInfo>",
+ tinfo->full_name);
+ return ZEBRA_FAIL;
+ }
+
+ for (ptr = ptr->children; ptr; ptr = ptr->next)
+ {
+ if (ptr->type != XML_ELEMENT_NODE)
+ continue;
+ if (!XML_STRCMP(ptr->name, "schema"))
+ {
+ char tmp_xslt_full_name[1024];
+ struct _xmlAttr *attr;
+ struct filter_schema *schema = xmalloc(sizeof(*schema));
+ schema->name = 0;
+ schema->identifier = 0;
+ schema->stylesheet = 0;
+ schema->default_schema = 0;
+ schema->next = tinfo->schemas;
+ schema->stylesheet_xsp = 0;
+ schema->include_snippet = 0;
+ tinfo->schemas = schema;
+ for (attr = ptr->properties; attr; attr = attr->next)
+ {
+ attr_content(attr, "identifier", &schema->identifier);
+ attr_content(attr, "name", &schema->name);
+ attr_content(attr, "stylesheet", &schema->stylesheet);
+ attr_content(attr, "default", &schema->default_schema);
+ attr_content(attr, "snippet", &schema->include_snippet);
+ }
+ /*yaz_log(YLOG_LOG, "XSLT add %s %s %s",
+ schema->name, schema->identifier, schema->stylesheet); */
+
+ /* find requested schema */
+
+ if (schema->stylesheet){
+ yaz_filepath_resolve(schema->stylesheet, tinfo->profile_path,
+ NULL, tmp_xslt_full_name);
+ schema->stylesheet_xsp
+ = xsltParseStylesheetFile((const xmlChar*) tmp_xslt_full_name);
+ if (!schema->stylesheet_xsp)
+ yaz_log(YLOG_WARN,
+ "alvis filter: could not parse xslt stylesheet %s",
+ tmp_xslt_full_name);
+ }
+
+
+ }
+ else if (!XML_STRCMP(ptr->name, "split"))
+ {
+ struct _xmlAttr *attr;
+ for (attr = ptr->properties; attr; attr = attr->next)
+ {
+ attr_content(attr, "level", &tinfo->split_level);
+ attr_content(attr, "path", &tinfo->split_path);
+ }
+ }
+ else
+ {
+ yaz_log(YLOG_WARN, "Bad element %s in %s", ptr->name, fname);
+ return ZEBRA_FAIL;
+ }
+ }
+ return ZEBRA_OK;
+}
+
+static struct filter_schema *lookup_schema(struct filter_info *tinfo,
+ const char *est)
+{
+ struct filter_schema *schema;
+
+ for (schema = tinfo->schemas; schema; schema = schema->next)
+ {
+ /* find requested schema */
+ if (est)
+ {
+ if (schema->identifier && !strcmp(schema->identifier, est))
+ return schema;
+
+ if (schema->name && !strcmp(schema->name, est))
+ return schema;
+ }
+ /* or return default schema if defined */
+ else if (schema->default_schema)
+ return schema;
+ }
+
+ /* return first schema if no default schema defined */
+ if (tinfo->schemas)
+ return tinfo->schemas;
+
+ return 0;
+}
+
+static ZEBRA_RES filter_config(void *clientData, Res res, const char *args)