+/* This file is part of the Zebra server.
+ Copyright (C) 1995-2008 Index Data
-/* $Id: mod_dom.c,v 1.33 2007-04-02 16:57:08 adam Exp $
- Copyright (C) 1995-2007
- Index Data ApS
+Zebra is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
- This file is part of the Zebra server.
+Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
- Zebra is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free
- Software Foundation; either version 2, or (at your option) any later
- version.
-
- Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <idzebra/util.h>
#include <idzebra/recctrl.h>
+#include <yaz/oid_db.h>
/* DOM filter style indexing */
#define ZEBRA_DOM_NS "http://indexdata.com/zebra-2.0"
char *fname;
char *full_name;
const char *profile_path;
- ODR odr_record;
- ODR odr_config;
+ NMEM nmem_record;
+ NMEM nmem_config;
xmlDocPtr doc_config;
struct filter_extract *extract;
struct filter_retrieve *retrieve_list;
static void set_param_str(const char **params, const char *name,
- const char *value, ODR odr)
+ const char *value, NMEM nmem)
{
- char *quoted = odr_malloc(odr, 3 + strlen(value));
+ char *quoted = nmem_malloc(nmem, 3 + strlen(value));
sprintf(quoted, "'%s'", value);
while (*params)
params++;
}
static void set_param_int(const char **params, const char *name,
- zint value, ODR odr)
+ zint value, NMEM nmem)
{
- char *quoted = odr_malloc(odr, 30); /* 25 digits enough for 2^64 */
+ char *quoted = nmem_malloc(nmem, 30); /* 25 digits enough for 2^64 */
while (*params)
params++;
sprintf(quoted, "'" ZINT_FORMAT "'", value);
tinfo->fname = 0;
tinfo->full_name = 0;
tinfo->profile_path = 0;
- tinfo->odr_record = odr_createmem(ODR_ENCODE);
- tinfo->odr_config = odr_createmem(ODR_ENCODE);
+ tinfo->nmem_record = nmem_create();
+ tinfo->nmem_config = nmem_create();
tinfo->extract = 0;
tinfo->retrieve_list = 0;
tinfo->input_list = 0;
xmlFreeDoc(tinfo->doc_config);
tinfo->doc_config = 0;
}
- odr_reset(tinfo->odr_config);
+ nmem_reset(tinfo->nmem_config);
}
static ZEBRA_RES parse_convert(struct filter_info *tinfo, xmlNodePtr ptr,
{
struct _xmlAttr *attr;
struct convert_s *p
- = odr_malloc(tinfo->odr_config, sizeof(*p));
+ = nmem_malloc(tinfo->nmem_config, sizeof(*p));
p->next = 0;
p->stylesheet = 0;
struct filter_input **np = &tinfo->input_list;
for (;*np; np = &(*np)->next)
;
- p = *np = odr_malloc(tinfo->odr_config, sizeof(*p));
+ p = *np = nmem_malloc(tinfo->nmem_config, sizeof(*p));
p->next = 0;
p->syntax = 0;
p->name = 0;
xmlNodePtr ptr;
xmlDocPtr doc;
- tinfo->fname = odr_strdup(tinfo->odr_config, fname);
+ tinfo->fname = nmem_strdup(tinfo->nmem_config, fname);
if (yaz_filepath_resolve(tinfo->fname, tinfo->profile_path,
NULL, tmp_full_name))
- tinfo->full_name = odr_strdup(tinfo->odr_config, tmp_full_name);
+ tinfo->full_name = nmem_strdup(tinfo->nmem_config, tmp_full_name);
else
- tinfo->full_name = odr_strdup(tinfo->odr_config, tinfo->fname);
+ tinfo->full_name = nmem_strdup(tinfo->nmem_config, tinfo->fname);
yaz_log(YLOG_LOG, "%s dom filter: "
"loading config file %s", tinfo->fname, tinfo->full_name);
*/
struct _xmlAttr *attr;
struct filter_extract *f =
- odr_malloc(tinfo->odr_config, sizeof(*f));
+ nmem_malloc(tinfo->nmem_config, sizeof(*f));
tinfo->extract = f;
f->name = 0;
struct _xmlAttr *attr;
struct filter_retrieve **fp = &tinfo->retrieve_list;
struct filter_retrieve *f =
- odr_malloc(tinfo->odr_config, sizeof(*f));
+ nmem_malloc(tinfo->nmem_config, sizeof(*f));
while (*fp)
fp = &(*fp)->next;
</retrieve>
*/
struct filter_store *f =
- odr_malloc(tinfo->odr_config, sizeof(*f));
+ nmem_malloc(tinfo->nmem_config, sizeof(*f));
tinfo->store = f;
f->convert = 0;
{
struct filter_info *tinfo = clientData;
destroy_dom(tinfo);
- odr_destroy(tinfo->odr_config);
- odr_destroy(tinfo->odr_record);
+ nmem_destroy(tinfo->nmem_config);
+ nmem_destroy(tinfo->nmem_record);
xfree(tinfo);
}
{
xmlChar *text = xmlNodeGetContent(node);
size_t text_len = strlen((const char *)text);
-
+
/* if there is no text, we do not need to proceed */
if (text_len)
{
}
/* actually indexing the text given */
- dom_log(YLOG_DEBUG, tinfo, 0,
- "INDEX '%s:%s' '%s'",
- index ? (const char *) index : "null",
- type ? (const char *) type : "null",
- text ? (const char *) text : "null");
recword->index_name = (const char *)index;
- if (type && *type)
- recword->index_type = *type;
+ if (*type)
+ recword->index_type = (const char *) type;
/* writing debug out */
if (extctr->flagShowRecords)
dom_log(YLOG_LOG, tinfo, 0,
"INDEX '%s:%s' '%s'",
- index ? (const char *) index : "null",
- type ? (const char *) type : "null",
- text ? (const char *) text : "null");
+ (const char *) index,
+ (const char *) type,
+ (const char *) text);
- /* actually indexing the text given */
- recword->index_name = (const char *)index;
- if (type && *type)
- recword->index_type = *type;
(extctr->tokenAdd)(recword);
/* eat whitespaces */
else
dom_log(YLOG_WARN, tinfo, node, "bad @type value: %s", type_p);
extctr->action = action;
- yaz_log(YLOG_LOG, "In mod_dom.c: setting action to %d", action);
}
if (tinfo->record_info_invoked == 1)
/* we actuallu have a document which needs to be processed further */
params[0] = 0;
- set_param_str(params, "schema", zebra_dom_ns, tinfo->odr_record);
+ set_param_str(params, "schema", zebra_dom_ns, tinfo->nmem_record);
+
+ if (p && p->flagShowRecords)
+ {
+ xmlChar *buf_out;
+ int len_out;
+#if 0
+ FILE *outf = fopen("extract.xml", "w");
+ xmlDocDumpMemory(doc, &buf_out, &len_out);
+ fwrite(buf_out, 1, len_out, outf);
+#endif
+ yaz_log(YLOG_LOG, "Extract Doc: %.*s", len_out, buf_out);
+#if 0
+ fclose(outf);
+#endif
+ }
/* input conversion */
perform_convert(tinfo, p, input->convert, params, &doc, 0);
+
if (tinfo->store)
{
/* store conversion */
else
xmlDocDumpMemory(store_doc ? store_doc : doc, &buf_out, &len_out);
- (*p->setStoreData)(p, buf_out, len_out);
+ if (p->setStoreData)
+ (*p->setStoreData)(p, buf_out, len_out);
xmlFree(buf_out);
if (store_doc)
{
xmlDocPtr rdoc;
xmlNode *root_ptr;
- yaz_marc_write_xml(input->u.marc.handle, &root_ptr, 0, 0, 0);
+ yaz_marc_write_xml(input->u.marc.handle, &root_ptr,
+ "http://www.loc.gov/MARC21/slim", 0, 0);
rdoc = xmlNewDoc((const xmlChar*) "1.0");
xmlDocSetRootElement(rdoc, root_ptr);
return convert_extract_doc(tinfo, input, p, rdoc);
if (!input)
return RECCTRL_EXTRACT_ERROR_GENERIC;
- odr_reset(tinfo->odr_record);
+ nmem_reset(tinfo->nmem_record);
+
+ if (p->setStoreData == 0)
+ return extract_xml_full(tinfo, input, p);
switch(input->type)
{
case DOM_INPUT_XMLREADER:
{
p->diagnostic =
YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_;
+ p->addinfo = odr_strdup(p->odr, esn);
return 0;
}
params[0] = 0;
- set_param_int(params, "id", p->localno, p->odr);
+ set_param_int(params, "id", p->localno, p->odr->mem);
if (p->fname)
- set_param_str(params, "filename", p->fname, p->odr);
+ set_param_str(params, "filename", p->fname, p->odr->mem);
if (p->staticrank >= 0)
- set_param_int(params, "rank", p->staticrank, p->odr);
+ set_param_int(params, "rank", p->staticrank, p->odr->mem);
if (esn)
- set_param_str(params, "schema", esn, p->odr);
+ set_param_str(params, "schema", esn, p->odr->mem);
else
if (retrieve->name)
- set_param_str(params, "schema", retrieve->name, p->odr);
+ set_param_str(params, "schema", retrieve->name, p->odr->mem);
else if (retrieve->identifier)
- set_param_str(params, "schema", retrieve->identifier, p->odr);
+ set_param_str(params, "schema", retrieve->identifier, p->odr->mem);
else
- set_param_str(params, "schema", "", p->odr);
+ set_param_str(params, "schema", "", p->odr->mem);
if (p->score >= 0)
- set_param_int(params, "score", p->score, p->odr);
- set_param_int(params, "size", p->recordSize, p->odr);
+ set_param_int(params, "score", p->score, p->odr->mem);
+ set_param_int(params, "size", p->recordSize, p->odr->mem);
doc = xmlReadIO(ioread_ret, ioclose_ret, p /* I/O handler */,
0 /* URL */,
{
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;
else
xmlDocDumpMemory(doc, &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;
else
xmlDocDumpMemory(doc, &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);