patched to redirrect all "out of context" error messages to
a reconfigurable routine. The changes are:
* xmlerror.h : added the export of an error context type (void *)
an error handler type xmlGenericErrorFunc there is an interface
xmlSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler);
to reset the error handling routine and its argument
(by default it's equivalent to respectively fprintf and stderr.
* all the c files: all wild accesses to stderr or stdout within
the library have been replaced to calls to the handler.
Daniel
diff --git a/nanohttp.c b/nanohttp.c
index 0ac9d30..a92a9b3 100644
--- a/nanohttp.c
+++ b/nanohttp.c
@@ -302,9 +302,11 @@
}
#ifdef DEBUG_HTTP
if (URL == NULL)
- printf("Removing HTTP proxy info\n");
+ xmlGenericError(xmlGenericErrorContext,
+ "Removing HTTP proxy info\n");
else
- printf("Using HTTP proxy %s\n", URL);
+ xmlGenericError(xmlGenericErrorContext,
+ "Using HTTP proxy %s\n", URL);
#endif
if (URL == NULL) return;
buf[index] = 0;
@@ -749,7 +751,7 @@
if (h==NULL)
{
#ifdef DEBUG_HTTP
- fprintf(stderr,"unable to resolve '%s'.\n", host);
+ xmlGenericError(xmlGenericErrorContext,"unable to resolve '%s'.\n", host);
#endif
return(-1);
}
@@ -764,7 +766,8 @@
}
#ifdef DEBUG_HTTP
- fprintf(stderr, "unable to connect to '%s'.\n", host);
+ xmlGenericError(xmlGenericErrorContext,
+ "unable to connect to '%s'.\n", host);
#endif
return(-1);
}
@@ -935,9 +938,11 @@
else
strcpy(p, "\r\n");
#ifdef DEBUG_HTTP
- printf("-> %s%s", proxy? "(Proxy) " : "", bp);
+ xmlGenericError(xmlGenericErrorContext,
+ "-> %s%s", proxy? "(Proxy) " : "", bp);
if ((blen -= strlen(bp)+1) < 0)
- printf("ERROR: overflowed buffer by %d bytes\n", -blen);
+ xmlGenericError(xmlGenericErrorContext,
+ "ERROR: overflowed buffer by %d bytes\n", -blen);
#endif
ctxt->outptr = ctxt->out = bp;
ctxt->state = XML_NANO_HTTP_WRITE;
@@ -955,7 +960,7 @@
xmlNanoHTTPScanAnswer(ctxt, p);
#ifdef DEBUG_HTTP
- printf("<- %s\n", p);
+ xmlGenericError(xmlGenericErrorContext, "<- %s\n", p);
#endif
xmlFree(p);
}
@@ -963,7 +968,8 @@
if ((ctxt->location != NULL) && (ctxt->returnValue >= 300) &&
(ctxt->returnValue < 400)) {
#ifdef DEBUG_HTTP
- printf("\nRedirect to: %s\n", ctxt->location);
+ xmlGenericError(xmlGenericErrorContext,
+ "\nRedirect to: %s\n", ctxt->location);
#endif
while (xmlNanoHTTPRecv(ctxt)) ;
if (nbRedirects < XML_NANO_HTTP_MAX_REDIR) {
@@ -974,7 +980,8 @@
}
xmlNanoHTTPFreeCtxt(ctxt);
#ifdef DEBUG_HTTP
- printf("Too many redirects, aborting ...\n");
+ xmlGenericError(xmlGenericErrorContext,
+ "Too many redirects, aborting ...\n");
#endif
return(NULL);
@@ -989,10 +996,12 @@
#ifdef DEBUG_HTTP
if (ctxt->contentType != NULL)
- printf("\nCode %d, content-type '%s'\n\n",
+ xmlGenericError(xmlGenericErrorContext,
+ "\nCode %d, content-type '%s'\n\n",
ctxt->returnValue, ctxt->contentType);
else
- printf("\nCode %d, no content-type\n\n",
+ xmlGenericError(xmlGenericErrorContext,
+ "\nCode %d, no content-type\n\n",
ctxt->returnValue);
#endif
@@ -1107,8 +1116,10 @@
xmlNanoHTTPFetch(argv[1], "-", &contentType);
if (contentType != NULL) xmlFree(contentType);
} else {
- printf("%s: minimal HTTP GET implementation\n", argv[0]);
- printf("\tusage %s [ URL [ filename ] ]\n", argv[0]);
+ xmlGenericError(xmlGenericErrorContext,
+ "%s: minimal HTTP GET implementation\n", argv[0]);
+ xmlGenericError(xmlGenericErrorContext,
+ "\tusage %s [ URL [ filename ] ]\n", argv[0]);
}
xmlNanoHTTPCleanup();
xmlMemoryDump();
@@ -1119,7 +1130,8 @@
#ifdef STANDALONE
#include <stdio.h>
int main(int argc, char **argv) {
- printf("%s : HTTP support not compiled in\n", argv[0]);
+ xmlGenericError(xmlGenericErrorContext,
+ "%s : HTTP support not compiled in\n", argv[0]);
return(0);
}
#endif /* STANDALONE */