diff --git a/ChangeLog b/ChangeLog index 05874b3c..7dc0f121 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Oct 18 07:28:25 EDT 2003 Daniel Veillard + + * nanohttp.c xmlIO.c include/libxml/nanohttp.h: starting work + to fix the HTTP/XML parser integration. + Sat Oct 18 11:04:32 CEST 2003 Daniel Veillard * xmlreader.c include/libxml/xmlreader.h: added new APIs diff --git a/include/libxml/nanohttp.h b/include/libxml/nanohttp.h index 87990aa0..be2ba78e 100644 --- a/include/libxml/nanohttp.h +++ b/include/libxml/nanohttp.h @@ -51,7 +51,11 @@ XMLPUBFUN void * XMLCALL XMLPUBFUN int XMLCALL xmlNanoHTTPReturnCode (void *ctx); XMLPUBFUN const char * XMLCALL - xmlNanoHTTPAuthHeader(void *ctx); + xmlNanoHTTPAuthHeader (void *ctx); +XMLPUBFUN const char * XMLCALL + xmlNanoHTTPRedir (void * ctx); +XMLPUBFUN const char * XMLCALL + xmlNanoHTTPEncoding (void * ctx); XMLPUBFUN int XMLCALL xmlNanoHTTPRead (void *ctx, void *dest, diff --git a/nanohttp.c b/nanohttp.c index c02136a8..08dd932d 100644 --- a/nanohttp.c +++ b/nanohttp.c @@ -149,6 +149,7 @@ typedef struct xmlNanoHTTPCtxt { char *contentType; /* the MIME type for the input */ char *location; /* the new URL in case of redirect */ char *authHeader; /* contents of {WWW,Proxy}-Authenticate header */ + char *encoding; /* encoding extracted from the contentType */ } xmlNanoHTTPCtxt, *xmlNanoHTTPCtxtPtr; static int initialized = 0; @@ -528,6 +529,7 @@ xmlNanoHTTPFreeCtxt(xmlNanoHTTPCtxtPtr ctxt) { if (ctxt->out != NULL) xmlFree(ctxt->out); if (ctxt->in != NULL) xmlFree(ctxt->in); if (ctxt->contentType != NULL) xmlFree(ctxt->contentType); + if (ctxt->encoding != NULL) xmlFree(ctxt->encoding); if (ctxt->location != NULL) xmlFree(ctxt->location); if (ctxt->authHeader != NULL) xmlFree(ctxt->authHeader); ctxt->state = XML_NANO_HTTP_NONE; @@ -1576,6 +1578,36 @@ xmlNanoHTTPContentLength( void * ctx ) { return ( ( ctxt == NULL ) ? -1 : ctxt->ContentLength ); } +/** + * xmlNanoHTTPRedir: + * @ctx: the HTTP context + * + * Provides the specified redirection URL if available from the HTTP header. + * + * Return the specified redirection URL or NULL if not redirected. + */ +const char * +xmlNanoHTTPRedir( void * ctx ) { + xmlNanoHTTPCtxtPtr ctxt = ctx; + + return ( ( ctxt == NULL ) ? NULL : ctxt->location ); +} + +/** + * xmlNanoHTTPEncoding: + * @ctx: the HTTP context + * + * Provides the specified encoding if specified in the HTTP headers. + * + * Return the specified encoding or NULL if not available + */ +const char * +xmlNanoHTTPEncoding( void * ctx ) { + xmlNanoHTTPCtxtPtr ctxt = ctx; + + return ( ( ctxt == NULL ) ? NULL : ctxt->encoding ); +} + /** * xmlNanoHTTPFetchContent: * @ctx: the HTTP context diff --git a/xmlIO.c b/xmlIO.c index 67d9c415..d8508cda 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -2108,6 +2108,7 @@ xmlOutputBufferClose(xmlOutputBufferPtr out) xmlParserInputBufferPtr xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) { xmlParserInputBufferPtr ret; + int is_http = 0; int i = 0; void *context = NULL; @@ -2125,8 +2126,11 @@ xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) { if ((xmlInputCallbackTable[i].matchcallback != NULL) && (xmlInputCallbackTable[i].matchcallback(URI) != 0)) { context = xmlInputCallbackTable[i].opencallback(URI); - if (context != NULL) + if (context != NULL) { + if (xmlInputCallbackTable[i].opencallback == xmlIOHTTPOpen) + is_http = 1; break; + } } } } @@ -3080,6 +3084,22 @@ xmlDefaultExternalEntityLoader(const char *URL, const char *ID, xmlLoaderErr(ctxt, "failed to load external entity \"%s\"\n", (const char *) resource); } + if ((ret->buf != NULL) && (ret->buf->readcallback == xmlIOHTTPRead)) { + const char *encoding; + const char *redir; + + encoding = xmlNanoHTTPEncoding(ret->buf->context); + redir = xmlNanoHTTPRedir(ret->buf->context); + if (redir != NULL) { + if (ret->filename != NULL) + xmlFree((xmlChar *) ret->filename); + if (ret->directory != NULL) { + xmlFree((xmlChar *) ret->directory); + ret->directory = NULL; + } + ret->filename = (char *) xmlStrdup((const xmlChar *)redir); + } + } if ((resource != NULL) && (resource != (xmlChar *) URL)) xmlFree(resource); return(ret);