26#include <libxml/parser.h>
27#include <libxml/xpath.h>
28#include <libxml/xpathInternals.h>
40 char *to_set =
"utf-8";
41 if (record_charset && *record_charset)
43 char *cp = charset_buf;
45 strncpy(charset_buf, record_charset,
sizeof(charset_buf)-1);
46 charset_buf[
sizeof(charset_buf)-1] =
'\0';
49 while (*cp && *cp !=
',' && *cp !=
'/')
55 while (*cp && *cp !=
',')
86 const char *buf,
int sz,
87 const char *record_charset)
91 const char *ret_string = 0;
111 const char *record_charset)
114 const char *marc_buf = 0;
150 const char *buf,
int sz,
151 const char *record_charset)
170 int marctype,
const char *charset)
195 wrbuf, marctype, len,
223 int marctype,
const char *charset,
232 xmlKeepBlanksDefault(0);
233 doc = xmlParseMemory(res, *len);
238 xmlDocDumpFormatMemory(doc, &xml_mem, &xml_size, 1);
253 const char *type_spec,
char *record_buf)
273 xmlDoc *doc = xmlParseMemory(res, strlen(res));
276 xmlNode *nptr = xmlCopyNode(xmlDocGetRootElement(doc), 1);
277 xmlReplaceNode(ptr, nptr);
282 xmlNode *nptr = xmlNewText(BAD_CAST res);
283 xmlReplaceNode(ptr, nptr);
294 const char *buf,
int *len,
295 const char *expr,
const char *type_spec)
298 xmlDocPtr doc = xmlParseMemory(buf, *len);
303 xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc);
306 xmlXPathObjectPtr xpathObj =
307 xmlXPathEvalExpression((
const xmlChar *) expr, xpathCtx);
310 xmlNodeSetPtr nodes = xpathObj->nodesetval;
314 for (i = 0; i < nodes->nodeNr; i++)
316 xmlNode *ptr = nodes->nodeTab[i];
317 if (ptr->type == XML_TEXT_NODE)
322 nmem, strlen(input) + 1);
331 nodes->nodeTab[i] = 0;
337 xmlXPathFreeObject(xpathObj);
339 xmlXPathFreeContext(xpathCtx);
341 xmlDocDumpMemory(doc, &buf_out, &len_out);
358 const char *type_spec,
int *len)
362 char *base64_xpath = 0;
367 const char *cp = type_spec;
373 for (i = 0; cp[i] && cp[i] !=
';' && cp[i] !=
' ' && i <
sizeof(
type)-1;
388 if (!strncmp(cp + i,
"charset=", 8))
394 for (j = 0; cp[i] && cp[i] !=
';' && cp[i] !=
' '; i++)
396 if (j <
sizeof(charset)-1)
397 charset[j++] = cp[i];
401 else if (!strncmp(cp + i,
"format=", 7))
407 for (j = 0; cp[i] && cp[i] !=
';' && cp[i] !=
' '; i++)
409 if (j <
sizeof(format)-1)
414 else if (!strncmp(cp + i,
"base64=", 7))
421 while (cp[i] && cp[i] !=
';')
428 if (!strcmp(
type,
"database"))
433 else if (!strcmp(
type,
"schema"))
435 *len = schema ? strlen(schema) : 0;
438 else if (!strcmp(
type,
"syntax"))
440 const char *desc = 0;
453 else if (!strcmp(
type,
"render"))
457 else if (!strcmp(
type,
"xml"))
462 else if (!strcmp(
type,
"txml"))
467 else if (!strcmp(
type,
"json"))
472 else if (!strcmp(
type,
"raw"))
477 else if (!strcmp(
type,
"ext"))
482 else if (!strcmp(
type,
"opac"))
489 if (base64_xpath && *len != -1)
492 strlen(
type) + strlen(charset) + 11);
493 strcpy(type_spec,
type);
496 strcat(type_spec,
"; charset=");
497 strcat(type_spec, charset);
int atoi_n_check(const char *buf, int size, int *val)
like atoi_n but checks for proper formatting
int yaz_base64decode(const char *in, char *out)
decodes Base64 string
Header for Base64 utilities.
Header for errno utilities.
void yaz_display_grs1(WRBUF wrbuf, Z_GenericRecord *r, int flags)
Performs "pretty" display of GRS-1 record to WRBUF.
int yaz_marc_check_marc21_coding(const char *charset, const char *marc_buf, int sz)
check if MARC21 is UTF-8 encoded
yaz_marc_t yaz_marc_create(void)
construct yaz_marc_t handle
void yaz_marc_iconv(yaz_marc_t mt, yaz_iconv_t cd)
set iconv handle for character set conversion
void yaz_marc_xml(yaz_marc_t mt, int xmlmode)
set XML mode YAZ_MARC_LINE, YAZ_MARCXML, YAZ_MARC_ISO2709 ..
void yaz_marc_destroy(yaz_marc_t mt)
destroy yaz_marc_t handle
int yaz_marc_decode_wrbuf(yaz_marc_t mt, const char *buf, int bsize, WRBUF wr)
decodes ISO2709/MARC buffer and stores result in WRBUF
#define YAZ_MARC_MARCXML
Output format: MARCXML.
#define YAZ_MARC_ISO2709
Output format: ISO2709.
#define YAZ_MARC_LINE
Output format: Line-format.
#define YAZ_MARC_JSON
Output format: JSON.
#define YAZ_MARC_TURBOMARC
Output format: Turbo MARC Index Data format (XML based)
NMEM nmem_create(void)
returns new NMEM handle
void * nmem_malloc(NMEM n, size_t size)
allocates memory block on NMEM handle
void nmem_destroy(NMEM n)
destroys NMEM handle and memory associated with it
Header for Nibble Memory functions + Libxml2 specific stuff.
char * nmem_strdupn(NMEM mem, const char *src, size_t n)
allocates string of certain size on NMEM handle
char * nmem_text_node_cdata(const xmlNode *ptr_cdata, NMEM nmem)
copies TEXT Libxml2 node data to NMEM
ODR odr_createmem(int direction)
void * odr_malloc(ODR o, size_t size)
int yaz_oid_is_iso2709(const Odr_oid *oid)
checks if OID refers to MARC transfer syntax
const char * yaz_oid_to_string(yaz_oid_db_t oid_db, const Odr_oid *oid, oid_class *oclass)
maps raw OID to string
yaz_oid_db_t yaz_oid_std(void)
returns standard OID database
const Odr_oid yaz_oid_recsyn_html[]
const Odr_oid yaz_oid_recsyn_mab[]
const Odr_oid yaz_oid_recsyn_xml[]
const Odr_oid yaz_oid_recsyn_application_xml[]
int oid_oidcmp(const Odr_oid *o1, const Odr_oid *o2)
compares OIDs
void yaz_opac_decode_wrbuf(yaz_marc_t mt, Z_OPACRecord *r, WRBUF wrbuf)
Performs "pretty" display of OPAC record to WRBUF using marc_t.
void yaz_opac_decode_wrbuf2(yaz_marc_t mt, Z_OPACRecord *r, WRBUF wrbuf, yaz_iconv_t cd2)
Performs "pretty" display of OPAC record to WRBUF using marc_t.
Header for Z39.50 Protocol.
Z_External * z_ext_record_xml(ODR o, const char *buf, int len)
encodes EXTERNAL XML record
Z_External * z_ext_record_usmarc(ODR o, const char *buf, int len)
encodes EXTERNAL USMARC/MARC21 record
static const char * return_opac_record(WRBUF wrbuf, int marc_type, int *len, Z_OPACRecord *opac_rec, const char *record_charset)
static yaz_iconv_t iconv_create_charset(const char *record_charset, yaz_iconv_t *cd2, const char *marc_buf, int sz)
static const char * return_record_wrbuf(WRBUF wrbuf, int *len, Z_NamePlusRecord *npr, int marctype, const char *charset)
static const char * base64_render(NMEM nmem, WRBUF wrbuf, const char *buf, int *len, const char *expr, const char *type_spec)
static const char * return_marc_record(WRBUF wrbuf, int marc_type, int *len, const char *buf, int sz, const char *record_charset)
static const char * return_string_record(WRBUF wrbuf, int *len, const char *buf, int sz, const char *record_charset)
const char * yaz_record_render(Z_NamePlusRecord *npr, const char *schema, WRBUF wrbuf, const char *type_spec, int *len)
render records (ZOOM style)
static int replace_node(NMEM nmem, xmlNode *ptr, const char *type_spec, char *record_buf)
static const char * get_record_format(WRBUF wrbuf, int *len, Z_NamePlusRecord *npr, int marctype, const char *charset, const char *format)
int yaz_iconv_close(yaz_iconv_t cd)
just like iconv_close(3)
yaz_iconv_t yaz_iconv_open(const char *tocode, const char *fromcode)
just like iconv_open(3)
structure for all known EXTERNALs
Odr_oid * direct_reference
Z_External * databaseRecord
Z_DatabaseName * databaseName
union Z_NamePlusRecord::@54 u
Z_External * bibliographicRecord
the internals of a yaz_marc_t handle
void wrbuf_destroy(WRBUF b)
destroy WRBUF and its buffer
void wrbuf_iconv_reset(WRBUF b, yaz_iconv_t cd)
iconv reset(flush) to WRBUF
const char * wrbuf_cstr(WRBUF b)
returns WRBUF content as C-string
void wrbuf_rewind(WRBUF b)
empty WRBUF content (length of buffer set to 0)
WRBUF wrbuf_alloc(void)
construct WRBUF
void wrbuf_iconv_write(WRBUF b, yaz_iconv_t cd, const char *buf, size_t size)
Converts buffer using iconv and appends to WRBUF.
void wrbuf_write(WRBUF b, const char *buf, size_t size)
append constant size buffer to WRBUF
Header for YAZ iconv interface.
#define Z_NamePlusRecord_databaseRecord