Commit 847332a0 authored by Daniel Veillard's avatar Daniel Veillard

starting work to fix the HTTP/XML parser integration. Daniel

* nanohttp.c xmlIO.c include/libxml/nanohttp.h: starting work
  to fix the HTTP/XML parser integration.
Daniel
parent fc8dc355
Sat Oct 18 07:28:25 EDT 2003 Daniel Veillard <daniel@veillard.com>
* 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 <daniel@veillard.com>
* xmlreader.c include/libxml/xmlreader.h: added new APIs
......
......@@ -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,
......
......@@ -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
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment