X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Frecord_conv.c;h=372e827947ab402920f694cd4ea1e13732536ced;hb=52188379291c43d463d4ee6742cf81a700541723;hp=086eec50d3f857a5f13d86faecd5a8b2efac2902;hpb=8f8560e0ab3b370263683d8aea81b839c5927091;p=yaz-moved-to-github.git diff --git a/src/record_conv.c b/src/record_conv.c index 086eec5..372e827 100644 --- a/src/record_conv.c +++ b/src/record_conv.c @@ -1,8 +1,6 @@ -/* - * Copyright (C) 2005-2006, Index Data ApS +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2008 Index Data * See the file LICENSE for details. - * - * $Id: record_conv.c,v 1.13 2006-12-13 11:25:17 adam Exp $ */ /** * \file record_conv.c @@ -21,6 +19,7 @@ #include #include #include +#include #if YAZ_HAVE_XML2 #include @@ -107,7 +106,7 @@ static void yaz_record_conv_reset(yaz_record_conv_t p) yaz_record_conv_t yaz_record_conv_create() { - yaz_record_conv_t p = xmalloc(sizeof(*p)); + yaz_record_conv_t p = (yaz_record_conv_t) xmalloc(sizeof(*p)); p->nmem = nmem_create(); p->wr_error = wrbuf_alloc(); p->rules = 0; @@ -126,7 +125,7 @@ void yaz_record_conv_destroy(yaz_record_conv_t p) { yaz_record_conv_reset(p); nmem_destroy(p->nmem); - wrbuf_free(p->wr_error, 1); + wrbuf_destroy(p->wr_error); xfree(p->path); xfree(p); } @@ -136,7 +135,8 @@ void yaz_record_conv_destroy(yaz_record_conv_t p) static struct yaz_record_conv_rule *add_rule(yaz_record_conv_t p, enum YAZ_RECORD_CONV_RULE type) { - struct yaz_record_conv_rule *r = nmem_malloc(p->nmem, sizeof(*r)); + struct yaz_record_conv_rule *r = (struct yaz_record_conv_rule *) + nmem_malloc(p->nmem, sizeof(*r)); r->which = type; r->next = 0; *p->rules_p = r; @@ -176,21 +176,28 @@ static int conv_xslt(yaz_record_conv_t p, const xmlNode *ptr) if (!yaz_filepath_resolve(stylesheet, p->path, 0, fullpath)) { wrbuf_printf(p->wr_error, "Element :" - " could not locate stylesheet '%s' with path '%s'", - stylesheet, fullpath, p->path); + " could not locate stylesheet '%s'", + stylesheet, fullpath); + if (p->path) + wrbuf_printf(p->wr_error, " with path '%s'", p->path); + return -1; } xsp = xsltParseStylesheetFile((xmlChar*) fullpath); if (!xsp) { - wrbuf_printf(p->wr_error, "Element :" - " parsing stylesheet '%s' with path '%s' failed," + wrbuf_printf(p->wr_error, "Element: :" + " xslt parse failed: %s", stylesheet, fullpath); + if (p->path) + wrbuf_printf(p->wr_error, " with path '%s'", p->path); + wrbuf_printf(p->wr_error, " (" #if YAZ_HAVE_EXSLT - " EXSLT enabled", + + "EXSLT enabled" #else - " EXSLT not supported", + "EXSLT not supported" #endif - stylesheet, fullpath, p->path); + ")"); return -1; } else @@ -369,14 +376,56 @@ int yaz_record_conv_configure(yaz_record_conv_t p, const xmlNode *ptr) return 0; } +static int yaz_record_conv_record_rule(yaz_record_conv_t p, + struct yaz_record_conv_rule *r, + const char *input_record_buf, + size_t input_record_len, + WRBUF output_record); + +int yaz_record_conv_opac_record(yaz_record_conv_t p, + Z_OPACRecord *input_record, + WRBUF output_record) +{ + int ret = 0; + struct yaz_record_conv_rule *r = p->rules; + WRBUF res = wrbuf_alloc(); + yaz_marc_t mt = yaz_marc_create(); + + wrbuf_rewind(p->wr_error); + yaz_marc_xml(mt, r->u.marc.output_format); + if (r->u.marc.iconv_t) + yaz_marc_iconv(mt, r->u.marc.iconv_t); + yaz_opac_decode_wrbuf(mt, input_record, res); + if (ret != -1) + { + ret = yaz_record_conv_record_rule(p, + r->next, + wrbuf_buf(res), wrbuf_len(res), + output_record); + } + yaz_marc_destroy(mt); + wrbuf_destroy(res); + return ret; +} + int yaz_record_conv_record(yaz_record_conv_t p, const char *input_record_buf, size_t input_record_len, WRBUF output_record) { + return yaz_record_conv_record_rule(p, p->rules, + input_record_buf, + input_record_len, output_record); +} + +static int yaz_record_conv_record_rule(yaz_record_conv_t p, + struct yaz_record_conv_rule *r, + const char *input_record_buf, + size_t input_record_len, + WRBUF output_record) +{ int ret = 0; WRBUF record = output_record; /* pointer transfer */ - struct yaz_record_conv_rule *r = p->rules; wrbuf_rewind(p->wr_error); wrbuf_write(record, input_record_buf, input_record_len); @@ -484,7 +533,7 @@ int yaz_record_conv_record(yaz_record_conv_t p, const char *yaz_record_conv_get_error(yaz_record_conv_t p) { - return wrbuf_buf(p->wr_error); + return wrbuf_cstr(p->wr_error); } void yaz_record_conv_set_path(yaz_record_conv_t p, const char *path)