1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-13 20:58:16 +03:00

http: Improve error message for HTTPS redirects

This commit is contained in:
Nick Wellnhofer 2024-02-19 11:09:39 +01:00
parent e314109ad1
commit 67e475b78e
5 changed files with 12 additions and 8 deletions

View File

@ -1307,6 +1307,8 @@ xmlErrString(xmlParserErrors code) {
errmsg = "already in use"; break;
case XML_IO_EAFNOSUPPORT:
errmsg = "unknown address family"; break;
case XML_IO_UNSUPPORTED_PROTOCOL:
errmsg = "unsupported protocol"; break;
default:
errmsg = "Unregistered error message";

View File

@ -478,6 +478,7 @@ typedef enum {
XML_IO_EADDRINUSE, /* 1554 */
XML_IO_EALREADY, /* 1555 */
XML_IO_EAFNOSUPPORT, /* 1556 */
XML_IO_UNSUPPORTED_PROTOCOL, /* 1557 */
XML_XINCLUDE_RECURSION=1600,
XML_XINCLUDE_PARSE_VALUE, /* 1601 */
XML_XINCLUDE_ENTITY_DEF_MISMATCH, /* 1602 */

View File

@ -1388,7 +1388,7 @@ retry:
}
if ((ctxt->protocol == NULL) || (strcmp(ctxt->protocol, "http"))) {
__xmlIOErr(XML_FROM_HTTP, XML_HTTP_URL_SYNTAX, "Not a valid HTTP URI");
__xmlIOErr(XML_FROM_IO, XML_IO_UNSUPPORTED_PROTOCOL, ctxt->protocol);
xmlNanoHTTPFreeCtxt(ctxt);
if (redirURL != NULL) xmlFree(redirURL);
return(NULL);

View File

@ -100,7 +100,7 @@ run_test(desc="Loading entity with custom callback",
docpath=startURL, catalog=None,
exp_status="loaded", exp_err=[
( 3, 'failed to load "http://example.com/dtds/sample.dtd": Attempt to load network entity\n'),
( -1, "Attempt to load network entity http://example.com/dtds/sample.dtd"),
( -1, "Attempt to load network entity: http://example.com/dtds/sample.dtd"),
( 4, "Entity 'sample.entity' not defined\n")
])

13
xmlIO.c
View File

@ -140,7 +140,7 @@ __xmlIOErr(int domain, int code, const char *extra)
xmlStructuredErrorFunc schannel = NULL;
xmlGenericErrorFunc channel = NULL;
void *data = NULL;
const char *fmt, *arg;
const char *fmt, *arg1, *arg2;
int res;
if (code == 0) {
@ -309,18 +309,19 @@ __xmlIOErr(int domain, int code, const char *extra)
data = xmlGenericErrorContext;
}
if (code == XML_IO_NETWORK_ATTEMPT) {
fmt = "Attempt to load network entity %s";
arg = extra;
if (extra != NULL) {
fmt = "%s: %s";
} else {
fmt = "%s";
arg = xmlErrString(code);
}
arg1 = xmlErrString(code);
arg2 = extra;
res = __xmlRaiseError(schannel, channel, data, NULL, NULL,
domain, code, XML_ERR_ERROR, NULL, 0,
extra, NULL, NULL, 0, 0,
fmt, arg);
fmt, arg1, arg2);
if (res < 0) {
xmlIOErrMemory();
return(XML_ERR_NO_MEMORY);