-/* $Id: xmlread.c,v 1.4 2002-08-29 08:41:07 adam Exp $
+/* $Id: xmlread.c,v 1.9 2003-09-08 09:30:17 adam Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
Index Data Aps
#include <yaz/xmalloc.h>
#include <yaz/log.h>
-#include <yaz/data1.h>
+#include <data1.h>
#include <expat.h>
#define XML_CHUNK 1024
struct user_info {
+ int full_error_info;
data1_node *d1_stack[256];
int level;
data1_handle dh;
}
if (!XML_ParseBuffer (parser, r, done))
{
- yaz_log (LOG_WARN, "XML_ParseBuffer failed %s",
- XML_ErrorString(XML_GetErrorCode(parser)));
+ if (ui->full_error_info)
+ yaz_log (LOG_WARN, "%s:%d:%d:XML error: %s",
+ systemId,
+ XML_GetCurrentLineNumber(parser),
+ XML_GetCurrentColumnNumber(parser),
+ XML_ErrorString(XML_GetErrorCode(parser)));
+ else
+ yaz_log (LOG_WARN, "%s:%d:XML error: %s",
+ systemId,
+ XML_GetCurrentLineNumber(parser),
+ XML_ErrorString(XML_GetErrorCode(parser)));
}
}
fclose (inf);
char *inbuf = (char *) s;
unsigned short code;
+#if 1
+ yaz_log(LOG_LOG, "------------------------- cb_encoding_convert --- ");
+#endif
ret = iconv (t, &inbuf, &inleft, &outbuf, &outleft);
if (ret == (size_t) (-1) && errno != E2BIG)
{
if (errno == E2BIG)
{
info->map[i] = -1; /* no room for output */
- yaz_log (LOG_WARN, "Encoding %d: no room for output",
- i);
+ if (i != 0)
+ yaz_log (LOG_WARN, "Encoding %d: no room for output",
+ i);
}
}
else if (outleft == 0)
/* HAVE_ICONV_H */
#endif
+static void cb_ns_start(void *userData, const char *prefix, const char *uri)
+{
+ struct user_info *ui = (struct user_info*) userData;
+ if (prefix && uri)
+ yaz_log(ui->loglevel, "cb_ns_start %s %s", prefix, uri);
+}
+static void cb_ns_end(void *userData, const char *prefix)
+{
+ struct user_info *ui = (struct user_info*) userData;
+ if (prefix)
+ yaz_log(ui->loglevel, "cb_ns_end %s", prefix);
+}
data1_node *zebra_read_xml (data1_handle dh,
int (*rf)(void *, char *, size_t), void *fh,
- NMEM m)
+ NMEM m,
+ int full_error_info)
{
XML_Parser parser;
struct user_info uinfo;
int done = 0;
+ uinfo.full_error_info = full_error_info;
uinfo.loglevel = LOG_DEBUG;
uinfo.level = 1;
uinfo.dh = dh;
XML_SetDoctypeDeclHandler (parser, cb_doctype_start, cb_doctype_end);
XML_SetEntityDeclHandler (parser, cb_entity_decl);
XML_SetExternalEntityRefHandler (parser, cb_external_entity);
+ XML_SetNamespaceDeclHandler(parser, cb_ns_start, cb_ns_end);
#if HAVE_ICONV_H
XML_SetUnknownEncodingHandler (parser, cb_encoding_handler, &uinfo);
#endif
done = 1;
if (!XML_ParseBuffer (parser, r, done))
{
- yaz_log (LOG_WARN, "XML_ParseBuffer (1) failed %s",
- XML_ErrorString(XML_GetErrorCode(parser)));
+ if (full_error_info)
+ yaz_log (LOG_WARN, "%d:%d:XML error: %s",
+ XML_GetCurrentLineNumber(parser),
+ XML_GetCurrentColumnNumber(parser),
+ XML_ErrorString(XML_GetErrorCode(parser)));
+ else
+ yaz_log (LOG_WARN, "XML error: %s",
+ XML_ErrorString(XML_GetErrorCode(parser)));
}
}
XML_ParserFree (parser);
}
struct xml_info {
- int dummy;
+ XML_Expat_Version expat_version;
+ int full_error_info; /* true if we can safely use Expat's
+ XML_GetCurrent{Line,Column}Number */
};
static void *grs_init_xml(void)
{
struct xml_info *p = (struct xml_info *) xmalloc (sizeof(*p));
+
+ p->expat_version = XML_ExpatVersionInfo();
+
+ /* determine if we can use XML_GetCurrent{Line,Column}Number */
+ p->full_error_info = 0;
+ if (p->expat_version.major > 1)
+ p->full_error_info = 1;
+ else if (p->expat_version.major == 1 && p->expat_version.minor > 95)
+ p->full_error_info = 1;
+ else if (p->expat_version.major == 1 && p->expat_version.minor == 95
+ && p->expat_version.micro >= 3)
+ p->full_error_info = 1;
return p;
}
static data1_node *grs_read_xml (struct grs_read_info *p)
{
- return zebra_read_xml (p->dh, p->readf, p->fh, p->mem);
+ struct xml_info *x = (struct xml_info *) p->clientData;
+ return zebra_read_xml (p->dh, p->readf, p->fh, p->mem, x->full_error_info);
}
static void grs_destroy_xml(void *clientData)
{
- struct sgml_getc_info *p = (struct sgml_getc_info *) clientData;
+ struct xml_info *p = (struct xml_info *) clientData;
xfree (p);
}