YAZ
5.34.0
|
Record Conversions utility. More...
#include <string.h>
#include <yaz/log.h>
#include <yaz/yaz-iconv.h>
#include <yaz/marcdisp.h>
#include <yaz/record_conv.h>
#include <yaz/wrbuf.h>
#include <yaz/xmalloc.h>
#include <yaz/nmem.h>
#include <yaz/tpath.h>
#include <yaz/z-opac.h>
#include <yaz/xml_get.h>
#include <yaz/url.h>
#include <yaz/srw.h>
#include <yaz/timing.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xinclude.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include <libxslt/xsltutils.h>
#include <libxslt/transform.h>
Go to the source code of this file.
Data Structures | |
struct | yaz_record_conv_struct |
The internal structure for yaz_record_conv_t. More... | |
struct | marc_info |
struct | yaz_record_conv_rule |
transformation info (rule info) More... | |
struct | xslt_info |
struct | select_info |
struct | rdf_lookup_info |
Macros | |
#define | RDF_LOOKUP_MAX_KEYS 20 |
#define | RDF_LOOKUP_MAX_NAMESPACES 20 |
Functions | |
static void | yaz_record_conv_reset (yaz_record_conv_t p) |
reset rules+configuration More... | |
void | yaz_record_conv_destroy (yaz_record_conv_t p) |
static void * | construct_xslt (const xmlNode *ptr, const char *path, WRBUF wr_error) |
static int | convert_xslt (void *vinfo, WRBUF record, WRBUF wr_error) |
static void | destroy_xslt (void *vinfo) |
static void * | construct_select (const xmlNode *ptr, const char *path, WRBUF wr_error) |
static int | convert_select (void *vinfo, WRBUF record, WRBUF wr_error) |
static void | destroy_select (void *vinfo) |
static void * | construct_solrmarc (const xmlNode *ptr, const char *path, WRBUF wr_error) |
static int | convert_solrmarc (void *info, WRBUF record, WRBUF wr_error) |
static void | destroy_solrmarc (void *info) |
static void * | construct_marc (const xmlNode *ptr, const char *path, WRBUF wr_error) |
static int | convert_marc (void *info, WRBUF record, WRBUF wr_error) |
static void | destroy_marc (void *info) |
static struct rdf_lookup_info * | construct_one_rdf_lookup (NMEM nmem, const xmlNode *ptr, WRBUF wr_error, int timeout) |
static void * | construct_rdf_lookup (const xmlNode *ptr, const char *path, WRBUF wr_error) |
static void | destroy_rdf_lookup (void *info) |
static void | rdf_lookup_debug_comment (xmlNode *n, WRBUF uri, Z_HTTP_Response *resp, struct rdf_lookup_info *info, yaz_timing_t tim, const char *msg, int yloglevel) |
static void | rdf_lookup_node (xmlNode *n, xmlXPathContextPtr xpathCtx, struct rdf_lookup_info *info) |
static int | convert_rdf_lookup (void *rinfo, WRBUF record, WRBUF wr_error) |
int | yaz_record_conv_configure_t (yaz_record_conv_t p, const xmlNode *ptr, struct yaz_record_conv_type *types) |
int | yaz_record_conv_configure (yaz_record_conv_t p, const xmlNode *ptr) |
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) |
const char * | yaz_record_get_output_charset (yaz_record_conv_t p) |
int | yaz_record_conv_opac_record (yaz_record_conv_t p, Z_OPACRecord *input_record, WRBUF output_record) |
int | yaz_record_conv_record (yaz_record_conv_t p, const char *input_record_buf, size_t input_record_len, WRBUF output_record) |
const char * | yaz_record_conv_get_error (yaz_record_conv_t p) |
void | yaz_record_conv_set_path (yaz_record_conv_t p, const char *path) |
yaz_record_conv_t | yaz_record_conv_create () |
Record Conversions utility.
Definition in file record_conv.c.
#define RDF_LOOKUP_MAX_KEYS 20 |
Definition at line 689 of file record_conv.c.
#define RDF_LOOKUP_MAX_NAMESPACES 20 |
Definition at line 690 of file record_conv.c.
|
static |
Libxml2 generates UTF-8 encoding by default . So we convert from UTF-8 to outputcharset (if defined)
Definition at line 448 of file record_conv.c.
References marc_info::input_charset, marc_info::input_format_mode, marc_info::leader_spec, marc_info::nmem, select_info::nmem, nmem_create(), nmem_destroy(), nmem_malloc(), nmem_strdup(), marc_info::output_charset, marc_info::output_format_mode, wrbuf_printf(), yaz_iconv_close(), yaz_iconv_open(), YAZ_MARC_ISO2709, YAZ_MARC_JSON, YAZ_MARC_LINE, YAZ_MARC_MARCXML, YAZ_MARC_TURBOMARC, and YAZ_MARC_XCHANGE.
Referenced by yaz_record_conv_configure_t(), yaz_record_conv_opac_record(), and yaz_record_get_output_charset().
|
static |
Definition at line 703 of file record_conv.c.
References rdf_lookup_info::debug, rdf_lookup_info::keys, rdf_lookup_info::method, rdf_lookup_info::namespacelist, rdf_lookup_info::next, rdf_lookup_info::nmem, nmem_malloc(), nmem_strdup(), RDF_LOOKUP_MAX_KEYS, rdf_lookup_info::server, rdf_lookup_info::timeout, wrbuf_printf(), and rdf_lookup_info::xpath.
Referenced by construct_rdf_lookup().
|
static |
Definition at line 793 of file record_conv.c.
References construct_one_rdf_lookup(), debug(), rdf_lookup_info::debug, rdf_lookup_info::keys, rdf_lookup_info::method, rdf_lookup_info::namespacelist, rdf_lookup_info::next, rdf_lookup_info::nmem, nmem_create(), nmem_destroy(), nmem_malloc(), nmem_strdup(), RDF_LOOKUP_MAX_NAMESPACES, rdf_lookup_info::server, rdf_lookup_info::timeout, wrbuf_printf(), rdf_lookup_info::xpath, yaz_log(), and YLOG_DEBUG.
Referenced by yaz_record_conv_configure_t().
|
static |
Definition at line 331 of file record_conv.c.
References select_info::nmem, nmem_create(), nmem_destroy(), nmem_malloc(), nmem_strdup(), wrbuf_printf(), select_info::xpath_expr, and yaz_xml_get_prop().
Referenced by yaz_record_conv_configure_t().
|
static |
Definition at line 415 of file record_conv.c.
Referenced by yaz_record_conv_configure_t().
|
static |
Definition at line 114 of file record_conv.c.
References xslt_info::nmem, and wrbuf_printf().
Referenced by yaz_record_conv_configure_t().
Definition at line 614 of file record_conv.c.
References marc_info::input_charset, marc_info::input_format_mode, marc_info::leader_spec, marc_info::output_charset, marc_info::output_format_mode, wrbuf_buf, wrbuf_len, wrbuf_printf(), wrbuf_rewind(), yaz_iconv_close(), yaz_iconv_open(), yaz_marc_check_marc21_coding(), yaz_marc_create(), yaz_marc_destroy(), yaz_marc_iconv(), YAZ_MARC_ISO2709, yaz_marc_leader_spec(), YAZ_MARC_MARCXML, yaz_marc_read_iso2709(), yaz_marc_read_xml(), YAZ_MARC_TURBOMARC, yaz_marc_write_mode(), and yaz_marc_xml().
Referenced by yaz_record_conv_configure_t().
Definition at line 1056 of file record_conv.c.
References rdf_lookup_info::namespacelist, rdf_lookup_info::next, rdf_lookup_node(), wrbuf_buf, wrbuf_len, wrbuf_printf(), wrbuf_rewind(), wrbuf_write(), rdf_lookup_info::xpath, yaz_log(), and YLOG_DEBUG.
Referenced by yaz_record_conv_configure_t().
Definition at line 359 of file record_conv.c.
References wrbuf_buf, wrbuf_len, wrbuf_printf(), wrbuf_puts(), wrbuf_rewind(), and select_info::xpath_expr.
Referenced by yaz_record_conv_configure_t().
Definition at line 423 of file record_conv.c.
References atoi_n_check(), wrbuf_alloc(), wrbuf_buf, wrbuf_destroy(), wrbuf_len, wrbuf_putc, wrbuf_rewind(), and wrbuf_write().
Referenced by yaz_record_conv_configure_t().
Definition at line 259 of file record_conv.c.
References wrbuf_buf, wrbuf_len, wrbuf_printf(), wrbuf_rewind(), wrbuf_write(), xslt_info::xsl_parms, and xslt_info::xsp_doc.
Referenced by yaz_record_conv_configure_t().
|
static |
Definition at line 680 of file record_conv.c.
References marc_info::nmem, and nmem_destroy().
Referenced by yaz_record_conv_configure_t().
|
static |
Definition at line 911 of file record_conv.c.
References rdf_lookup_info::nmem, nmem_destroy(), yaz_log(), and YLOG_DEBUG.
Referenced by yaz_record_conv_configure_t().
|
static |
Definition at line 406 of file record_conv.c.
References select_info::nmem, and nmem_destroy().
Referenced by yaz_record_conv_configure_t().
|
static |
Definition at line 444 of file record_conv.c.
Referenced by yaz_record_conv_configure_t().
|
static |
Definition at line 312 of file record_conv.c.
References xslt_info::nmem, nmem_destroy(), and xslt_info::xsp_doc.
Referenced by yaz_record_conv_configure_t().
|
static |
Definition at line 919 of file record_conv.c.
References Z_HTTP_Response::code, rdf_lookup_info::debug, rdf_lookup_info::method, wrbuf_alloc(), wrbuf_cstr(), wrbuf_destroy(), wrbuf_printf(), wrbuf_puts(), wrbuf_puts_replace_str(), yaz_log(), and yaz_timing_get_real().
Referenced by rdf_lookup_node().
|
static |
Definition at line 948 of file record_conv.c.
References Z_HTTP_Response::code, Z_HTTP_Response::content_buf, Z_HTTP_Response::content_len, Z_HTTP_Response::headers, rdf_lookup_info::keys, rdf_lookup_info::method, Z_HTTP_Header::name, Z_HTTP_Header::next, rdf_lookup_debug_comment(), rdf_lookup_info::server, rdf_lookup_info::timeout, Z_HTTP_Header::value, wrbuf_alloc(), wrbuf_cstr(), wrbuf_destroy(), wrbuf_printf(), wrbuf_rewind(), xfree, xmalloc, yaz_encode_uri_component(), yaz_log(), yaz_timing_create(), yaz_timing_destroy(), yaz_timing_start(), yaz_timing_stop(), yaz_url_create(), yaz_url_destroy(), yaz_url_exec(), yaz_url_get_error(), yaz_url_set_max_redirects(), yaz_url_set_timeout(), YLOG_DEBUG, YLOG_LOG, and z_HTTP_header_lookup().
Referenced by convert_rdf_lookup().
int yaz_record_conv_configure | ( | yaz_record_conv_t | p, |
const xmlNode * | node | ||
) |
configures record conversion
p | record conversion handle |
node | xmlNode pointer (root element of XML config) |
0 | success |
-1 | failure |
On failure, use yaz_record_conv_get_error to get error string.
<backend syntax='xml'> <xslt stylesheet="dc2marcxml.xsl"/> <marc inputformat="xml" outputformat="marcxml" outputcharset="marc-8"/> </backend>
<backend syntax='usmarc' name='F'> <marc inputformat="marc" outputformat="marcxml" inputcharset="marc-8"/> <xslt stylesheet="marcxml2mods.xsl"/> <xslt stylesheet="mods2dc.xsl"/> </backend>
Definition at line 1208 of file record_conv.c.
References yaz_record_conv_configure_t().
int yaz_record_conv_configure_t | ( | yaz_record_conv_t | p, |
const xmlNode * | node, | ||
struct yaz_record_conv_type * | types | ||
) |
configures record conversion with user-defined conversion types
p | record conversion handle |
node | xmlNode pointer (root element of XML config) |
types | conversion types |
0 | success |
-1 | failure |
Definition at line 1135 of file record_conv.c.
References yaz_record_conv_type::construct, construct_marc(), construct_rdf_lookup(), construct_select(), construct_solrmarc(), construct_xslt(), yaz_record_conv_type::convert, convert_marc(), convert_rdf_lookup(), convert_select(), convert_solrmarc(), convert_xslt(), yaz_record_conv_type::destroy, destroy_marc(), destroy_rdf_lookup(), destroy_select(), destroy_solrmarc(), destroy_xslt(), yaz_record_conv_rule::info, yaz_record_conv_rule::next, yaz_record_conv_type::next, yaz_record_conv_struct::nmem, nmem_malloc(), yaz_record_conv_struct::path, yaz_record_conv_struct::rules_p, yaz_record_conv_rule::type, yaz_record_conv_struct::wr_error, wrbuf_len, wrbuf_printf(), wrbuf_rewind(), and yaz_record_conv_reset().
Referenced by conf_retrieval(), and yaz_record_conv_configure().
yaz_record_conv_t yaz_record_conv_create | ( | void | ) |
creates record handle
Definition at line 1311 of file record_conv.c.
References yaz_record_conv_struct::nmem, nmem_create(), yaz_record_conv_struct::path, yaz_record_conv_struct::rules, yaz_record_conv_struct::wr_error, wrbuf_alloc(), and xmalloc.
Referenced by conf_retrieval().
void yaz_record_conv_destroy | ( | yaz_record_conv_t | p | ) |
destroys record handle
p | record conversion handle |
Definition at line 94 of file record_conv.c.
References yaz_record_conv_struct::nmem, nmem_destroy(), yaz_record_conv_struct::path, yaz_record_conv_struct::wr_error, wrbuf_destroy(), xfree, and yaz_record_conv_reset().
Referenced by conf_retrieval(), and yaz_retrieval_reset().
const char* yaz_record_conv_get_error | ( | yaz_record_conv_t | p | ) |
returns error string (for last error)
p | record conversion handle |
Definition at line 1298 of file record_conv.c.
References yaz_record_conv_struct::wr_error, and wrbuf_cstr().
Referenced by conf_retrieval(), and retrieve_fetch().
int yaz_record_conv_opac_record | ( | yaz_record_conv_t | p, |
Z_OPACRecord * | input_record, | ||
WRBUF | output_record | ||
) |
performs record conversion on OPAC record
p | record conversion handle |
input_record | Z39.50 OPAC record |
output_record | resultint record (WRBUF string) |
0 | success |
-1 | failure |
On failure, use yaz_record_conv_get_error to get error string.
Definition at line 1240 of file record_conv.c.
References yaz_record_conv_type::construct, construct_marc(), yaz_record_conv_rule::info, marc_info::input_charset, marc_info::leader_spec, yaz_record_conv_rule::next, marc_info::output_format_mode, yaz_record_conv_struct::rules, yaz_record_conv_rule::type, yaz_record_conv_struct::wr_error, wrbuf_alloc(), wrbuf_buf, wrbuf_destroy(), wrbuf_len, wrbuf_puts(), wrbuf_rewind(), yaz_iconv_close(), yaz_iconv_open(), yaz_marc_create(), yaz_marc_destroy(), yaz_marc_iconv(), yaz_marc_leader_spec(), yaz_marc_xml(), yaz_opac_check_marc21_coding(), yaz_opac_decode_wrbuf(), and yaz_record_conv_record_rule().
Referenced by retrieve_fetch().
int yaz_record_conv_record | ( | yaz_record_conv_t | p, |
const char * | input_record_buf, | ||
size_t | input_record_len, | ||
WRBUF | output_record | ||
) |
performs record conversion on record buffer (OCTET aligned)
p | record conversion handle |
input_record_buf | input record buffer |
input_record_len | length of input record buffer |
output_record | resultint record (WRBUF string) |
0 | success |
-1 | failure |
On failure, use yaz_record_conv_get_error to get error string.
Definition at line 1288 of file record_conv.c.
References yaz_record_conv_struct::rules, and yaz_record_conv_record_rule().
Referenced by retrieve_fetch().
|
static |
Definition at line 1213 of file record_conv.c.
References yaz_record_conv_type::convert, yaz_record_conv_rule::info, yaz_record_conv_rule::next, yaz_record_conv_rule::type, yaz_record_conv_struct::wr_error, wrbuf_rewind(), and wrbuf_write().
Referenced by yaz_record_conv_opac_record(), and yaz_record_conv_record().
|
static |
reset rules+configuration
Definition at line 78 of file record_conv.c.
References yaz_record_conv_type::destroy, yaz_record_conv_rule::info, yaz_record_conv_rule::next, yaz_record_conv_struct::nmem, nmem_reset(), yaz_record_conv_struct::rules, yaz_record_conv_struct::rules_p, yaz_record_conv_rule::type, yaz_record_conv_struct::wr_error, and wrbuf_rewind().
Referenced by yaz_record_conv_configure_t(), and yaz_record_conv_destroy().
void yaz_record_conv_set_path | ( | yaz_record_conv_t | p, |
const char * | path | ||
) |
set path for opening stylesheets etc.
p | record conversion handle |
path | file path (UNIX style with : / Windows with ;) |
Definition at line 1303 of file record_conv.c.
References yaz_record_conv_struct::path, xfree, and xstrdup.
Referenced by conf_retrieval().
const char* yaz_record_get_output_charset | ( | yaz_record_conv_t | p | ) |
get output charset for last marc rule
p | record conversion handle |
Definition at line 1229 of file record_conv.c.
References yaz_record_conv_type::construct, construct_marc(), yaz_record_conv_rule::info, marc_info::output_charset, yaz_record_conv_struct::rules, and yaz_record_conv_rule::type.
Referenced by retrieve_fetch().