X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Falvis.c;h=0822faba44331a1446d4ff2f3d7b915ef5b4b3c3;hb=1b5ef8265837240930862dddd2d7ef963a0cc211;hp=218e6ea6aab11493e0f78d5c57f48cdc334540db;hpb=f88bc82b3fd2296b35ddbc327b43d240304e0ee4;p=idzebra-moved-to-github.git diff --git a/index/alvis.c b/index/alvis.c index 218e6ea..0822fab 100644 --- a/index/alvis.c +++ b/index/alvis.c @@ -1,5 +1,5 @@ -/* $Id: alvis.c,v 1.6 2006-11-16 13:27:54 adam Exp $ - Copyright (C) 1995-2006 +/* $Id: alvis.c,v 1.17 2007-04-16 21:54:37 adam Exp $ + Copyright (C) 1995-2007 Index Data ApS This file is part of the Zebra server. @@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include +#include #include #include @@ -161,8 +162,8 @@ static void *filter_init(Res res, RecType recType) static int attr_content(struct _xmlAttr *attr, const char *name, const char **dst_content) { - if (!XML_STRCMP(attr->name, name) && attr->children && - attr->children->type == XML_TEXT_NODE) + if (!XML_STRCMP(attr->name, name) && attr->children + && attr->children->type == XML_TEXT_NODE) { *dst_content = (const char *)(attr->children->content); return 1; @@ -193,27 +194,29 @@ 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, + + if (yaz_filepath_resolve(tinfo->fname, tinfo->profile_path, NULL, tmp_full_name)) - tinfo->full_name = xstrdup(tmp_full_name); + tinfo->full_name = xstrdup(tmp_full_name); else - tinfo->full_name = xstrdup(tinfo->fname); - + 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){ + + 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")){ + if (!ptr || ptr->type != XML_ELEMENT_NODE + || XML_STRCMP(ptr->name, "schemaInfo")) + { yaz_log(YLOG_WARN, "alvis filter: config file %s :" " expected root element ", @@ -343,6 +346,7 @@ static void filter_destroy(void *clientData) { struct filter_info *tinfo = clientData; destroy_schemas(tinfo); + xfree(tinfo->full_name); if (tinfo->reader) xmlFreeTextReader(tinfo->reader); odr_destroy(tinfo->odr); @@ -432,8 +436,7 @@ static void index_record(struct filter_info *tinfo,struct recExtractCtrl *ctrl, sscanf(id_str, "%255s", ctrl->match_criteria); if (rank_str) - ctrl->staticrank = atoi(rank_str); - + ctrl->staticrank = atozint(rank_str); ptr = ptr->children; } @@ -506,7 +509,9 @@ static int extract_split(struct filter_info *tinfo, struct recExtractCtrl *p) p /* I/O handler */, 0 /* URL */, 0 /* encoding */, - XML_PARSE_XINCLUDE); + XML_PARSE_XINCLUDE + | XML_PARSE_NOENT + | XML_PARSE_NONET); } if (!tinfo->reader) return RECCTRL_EXTRACT_ERROR_GENERIC; @@ -516,9 +521,7 @@ static int extract_split(struct filter_info *tinfo, struct recExtractCtrl *p) { int type = xmlTextReaderNodeType(tinfo->reader); int depth = xmlTextReaderDepth(tinfo->reader); - if (tinfo->split_level == 0 || - (tinfo->split_level > 0 && - type == XML_READER_TYPE_ELEMENT && tinfo->split_level == depth)) + if (type == XML_READER_TYPE_ELEMENT && tinfo->split_level == depth) { xmlNodePtr ptr = xmlTextReaderExpand(tinfo->reader); if (ptr) @@ -544,13 +547,39 @@ static int extract_split(struct filter_info *tinfo, struct recExtractCtrl *p) return RECCTRL_EXTRACT_EOF; } +static int extract_full(struct filter_info *tinfo, struct recExtractCtrl *p) +{ + if (p->first_record) /* only one record per stream */ + { + xmlDocPtr doc = xmlReadIO(ioread_ex, ioclose_ex, p /* I/O handler */, + 0 /* URL */, + 0 /* encoding */, + XML_PARSE_XINCLUDE + | XML_PARSE_NOENT + | XML_PARSE_NONET); + if (!doc) + return RECCTRL_EXTRACT_ERROR_GENERIC; + /* else { + xmlNodePtr root = xmlDocGetRootElement(doc); + if (!root) + return RECCTRL_EXTRACT_ERROR_GENERIC; + } */ + + return extract_doc(tinfo, p, doc); + } + else + return RECCTRL_EXTRACT_EOF; +} + static int filter_extract(void *clientData, struct recExtractCtrl *p) { struct filter_info *tinfo = clientData; odr_reset(tinfo->odr); - - return extract_split(tinfo, p); + if (tinfo->split_level == 0) + return extract_full(tinfo, p); + else + return extract_split(tinfo, p); } static int ioread_ret(void *context, char *buffer, int len) @@ -604,10 +633,10 @@ static const char *snippet_doc(struct recRetrieveCtrl *p, int text_mode, else wrbuf_printf(wrbuf, "\n"); - xml_doc_str = odr_strdup(p->odr, wrbuf_buf(wrbuf)); + xml_doc_str = odr_strdup(p->odr, wrbuf_cstr(wrbuf)); zebra_snippets_destroy(res); - wrbuf_free(wrbuf, 1); + wrbuf_destroy(wrbuf); return xml_doc_str; } @@ -675,7 +704,7 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) doc = xmlReadIO(ioread_ret, ioclose_ret, p /* I/O handler */, 0 /* URL */, 0 /* encoding */, - XML_PARSE_XINCLUDE); + XML_PARSE_XINCLUDE | XML_PARSE_NOENT | XML_PARSE_NONET); if (!doc) { p->diagnostic = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS; @@ -701,7 +730,8 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) { p->diagnostic = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS; } - else if (p->input_format == VAL_NONE || p->input_format == VAL_TEXT_XML) + else if (!p->input_format + || !oid_oidcmp(p->input_format, yaz_oid_recsyn_xml)) { xmlChar *buf_out; int len_out; @@ -712,13 +742,13 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) else xmlDocDumpMemory(resDoc, &buf_out, &len_out); - p->output_format = VAL_TEXT_XML; + p->output_format = yaz_oid_recsyn_xml; p->rec_len = len_out; p->rec_buf = odr_malloc(p->odr, p->rec_len); memcpy(p->rec_buf, buf_out, p->rec_len); xmlFree(buf_out); } - else if (p->output_format == VAL_SUTRS) + else if (!oid_oidcmp(p->output_format, yaz_oid_recsyn_sutrs)) { xmlChar *buf_out; int len_out; @@ -729,7 +759,7 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) else xmlDocDumpMemory(resDoc, &buf_out, &len_out); - p->output_format = VAL_SUTRS; + p->output_format = yaz_oid_recsyn_sutrs; p->rec_len = len_out; p->rec_buf = odr_malloc(p->odr, p->rec_len); memcpy(p->rec_buf, buf_out, p->rec_len);