summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoe <joe@61a7d7f5-40b7-0310-9c16-bb0ea8cb1845>2005-04-04 17:30:50 +0000
committerjoe <joe@61a7d7f5-40b7-0310-9c16-bb0ea8cb1845>2005-04-04 17:30:50 +0000
commit48212d53e078d28b7e52b9d542b40691c9326c3f (patch)
treec1f6e903caa88e9f7e6a908c7c18197bdd8efda2
parentccb3c141c3ecc888845354473add3fd5e4e64002 (diff)
downloadneon-48212d53e078d28b7e52b9d542b40691c9326c3f.tar.gz
* src/ne_xmlreq.h (ne_xml_parse_response, ne_xml_dispatch_request):
Specify that session error string is set for XML parse errors. * src/ne_xmlreq.c (parse_error): New function. (ne_xml_parse_response): On successful end-of-response, tell the the XML parser the end of the document is reached. Use parse_error() for error handling. git-svn-id: http://svn.webdav.org/repos/projects/neon/trunk@541 61a7d7f5-40b7-0310-9c16-bb0ea8cb1845
-rw-r--r--src/ne_xmlreq.c34
-rw-r--r--src/ne_xmlreq.h10
2 files changed, 33 insertions, 11 deletions
diff --git a/src/ne_xmlreq.c b/src/ne_xmlreq.c
index 11778c0..f676dd1 100644
--- a/src/ne_xmlreq.c
+++ b/src/ne_xmlreq.c
@@ -1,6 +1,6 @@
/*
XML/HTTP response handling
- Copyright (C) 2004, Joe Orton <joe@manyfish.co.uk>
+ Copyright (C) 2004-2005, Joe Orton <joe@manyfish.co.uk>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -22,21 +22,39 @@
#include "config.h"
#include "ne_xmlreq.h"
+#include "ne_i18n.h"
+
+/* Handle an XML response parse error, setting session error string
+ * and closing the connection. */
+static int parse_error(ne_session *sess, ne_xml_parser *parser)
+{
+ ne_set_error(sess, _("Could not parse response: %s"),
+ ne_xml_get_error(parser));
+ ne_close_connection(sess);
+ return NE_ERROR;
+}
int ne_xml_parse_response(ne_request *req, ne_xml_parser *parser)
{
char buf[8000];
ssize_t bytes;
+ int ret = 0;
while ((bytes = ne_read_response_block(req, buf, sizeof buf)) > 0) {
- int ret = ne_xml_parse(parser, buf, bytes);
- if (ret) {
- ne_close_connection(ne_get_session(req));
- return NE_ERROR;
- }
+ ret = ne_xml_parse(parser, buf, bytes);
+ if (ret)
+ return parse_error(ne_get_session(req), parser);
}
-
- return bytes == 0 ? NE_OK : NE_ERROR;
+
+ if (bytes == 0) {
+ /* Tell the parser that end of document was reached: */
+ if (ne_xml_parse(parser, NULL, 0) == 0)
+ return NE_OK;
+ else
+ return parse_error(ne_get_session(req), parser);
+ } else {
+ return NE_ERROR;
+ }
}
int ne_xml_dispatch_request(ne_request *req, ne_xml_parser *parser)
diff --git a/src/ne_xmlreq.h b/src/ne_xmlreq.h
index 1276655..0cb7d7c 100644
--- a/src/ne_xmlreq.h
+++ b/src/ne_xmlreq.h
@@ -1,6 +1,6 @@
/*
XML/HTTP response handling
- Copyright (C) 2004, Joe Orton <joe@manyfish.co.uk>
+ Copyright (C) 2004-2005, Joe Orton <joe@manyfish.co.uk>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -30,12 +30,16 @@ BEGIN_NEON_DECLS
/* Read the HTTP response body using calls to ne_read_response_block
* (so must be enclosed by ne_begin_request/ne_end_request calls), and
* parse it as an XML document, using the given parser. Returns NE_*
- * error codes. */
+ * error codes. If an XML parse error occurs, the session error
+ * string is set to the XML parser's error string, and NE_ERROR is
+ * returned. */
int ne_xml_parse_response(ne_request *req, ne_xml_parser *parser);
/* Dispatch the HTTP request, parsing the response body as an XML
* document using * the given parser, if the response status class is
- * 2xx. Returns NE_* error codes. */
+ * 2xx. Returns NE_* error codes. If an XML parse error occurs, the
+ * session error string is set to the XML parser's error string, and
+ * NE_ERROR is returned. */
int ne_xml_dispatch_request(ne_request *req, ne_xml_parser *parser);
END_NEON_DECLS