26 #include <libxml/xpath.h>
27 #include <libxml/xpathInternals.h>
39 char *to_set =
"utf-8";
40 if (record_charset && *record_charset)
42 char *cp = charset_buf;
44 strncpy(charset_buf, record_charset,
sizeof(charset_buf)-1);
45 charset_buf[
sizeof(charset_buf)-1] =
'\0';
48 while (*cp && *cp !=
',' && *cp !=
'/')
54 while (*cp && *cp !=
',')
85 const char *buf,
int sz,
86 const char *record_charset)
90 const char *ret_string = 0;
110 const char *record_charset)
113 const char *marc_buf = 0;
149 const char *buf,
int sz,
150 const char *record_charset)
169 int marctype,
const char *charset)
194 wrbuf, marctype, len,
222 int marctype,
const char *charset,
231 xmlKeepBlanksDefault(0);
232 doc = xmlParseMemory(res, *len);
237 xmlDocDumpFormatMemory(doc, &xml_mem, &xml_size, 1);
252 const char *type_spec,
char *record_buf)
272 xmlDoc *doc = xmlParseMemory(res, strlen(res));
275 xmlNode *nptr = xmlCopyNode(xmlDocGetRootElement(doc), 1);
276 xmlReplaceNode(ptr, nptr);
281 xmlNode *nptr = xmlNewText(BAD_CAST res);
282 xmlReplaceNode(ptr, nptr);
293 const char *buf,
int *len,
294 const char *expr,
const char *type_spec)
297 xmlDocPtr doc = xmlParseMemory(buf, *len);
302 xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc);
305 xmlXPathObjectPtr xpathObj =
306 xmlXPathEvalExpression((
const xmlChar *) expr, xpathCtx);
309 xmlNodeSetPtr nodes = xpathObj->nodesetval;
313 for (i = 0; i < nodes->nodeNr; i++)
315 xmlNode *ptr = nodes->nodeTab[i];
316 if (ptr->type == XML_TEXT_NODE)
321 nmem, strlen(input) + 1);
330 nodes->nodeTab[i] = 0;
336 xmlXPathFreeObject(xpathObj);
338 xmlXPathFreeContext(xpathCtx);
340 xmlDocDumpMemory(doc, &buf_out, &len_out);
357 const char *type_spec,
int *len)
361 char *base64_xpath = 0;
366 const char *cp = type_spec;
372 for (i = 0; cp[i] && cp[i] !=
';' && cp[i] !=
' ' && i <
sizeof(
type)-1;
387 if (!strncmp(cp + i,
"charset=", 8))
393 for (j = 0; cp[i] && cp[i] !=
';' && cp[i] !=
' '; i++)
395 if (j <
sizeof(charset)-1)
396 charset[j++] = cp[i];
400 else if (!strncmp(cp + i,
"format=", 7))
406 for (j = 0; cp[i] && cp[i] !=
';' && cp[i] !=
' '; i++)
408 if (j <
sizeof(format)-1)
413 else if (!strncmp(cp + i,
"base64=", 7))
420 while (cp[i] && cp[i] !=
';')
427 if (!strcmp(
type,
"database"))
432 else if (!strcmp(
type,
"schema"))
434 *len = schema ? strlen(schema) : 0;
437 else if (!strcmp(
type,
"syntax"))
439 const char *desc = 0;
452 else if (!strcmp(
type,
"render"))
456 else if (!strcmp(
type,
"xml"))
461 else if (!strcmp(
type,
"txml"))
466 else if (!strcmp(
type,
"json"))
471 else if (!strcmp(
type,
"raw"))
476 else if (!strcmp(
type,
"ext"))
481 else if (!strcmp(
type,
"opac"))
488 if (base64_xpath && *len != -1)
491 strlen(
type) + strlen(charset) + 11);
492 strcpy(type_spec,
type);
495 strcat(type_spec,
"; charset=");
496 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_text_node_cdata(const xmlNode *ptr_cdata, NMEM nmem)
copies TEXT Libxml2 node data to NMEM
char * nmem_strdupn(NMEM mem, const char *src, size_t n)
allocates string of certain size on NMEM handle
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
yaz_oid_db_t yaz_oid_std(void)
returns standard OID database
const char * yaz_oid_to_string(yaz_oid_db_t oid_db, const Odr_oid *oid, oid_class *oclass)
maps raw OID to string
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 yaz_iconv_t iconv_create_charset(const char *record_charset, yaz_iconv_t *cd2, const char *marc_buf, int sz)
const char * yaz_record_render(Z_NamePlusRecord *npr, const char *schema, WRBUF wrbuf, const char *type_spec, int *len)
render records (ZOOM style)
static const char * return_string_record(WRBUF wrbuf, int *len, const char *buf, int sz, const char *record_charset)
static const char * get_record_format(WRBUF wrbuf, int *len, Z_NamePlusRecord *npr, int marctype, const char *charset, const char *format)
static const char * return_record_wrbuf(WRBUF wrbuf, int *len, Z_NamePlusRecord *npr, int marctype, const char *charset)
static const char * return_opac_record(WRBUF wrbuf, int marc_type, int *len, Z_OPACRecord *opac_rec, const char *record_charset)
static int replace_node(NMEM nmem, xmlNode *ptr, const char *type_spec, char *record_buf)
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 * base64_render(NMEM nmem, WRBUF wrbuf, const char *buf, int *len, const char *expr, const char *type_spec)
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
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.
const char * wrbuf_cstr(WRBUF b)
returns WRBUF content as C-string
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