[Prev][Next][Index][Thread]

Re: misc. questions




> Two (probably very basic) questions.
> 
> I fetch a document from HTTP to a file using a piece of code based on
> libapp_3.c.

FYI: The Library has three very small examples on how to set it up and access 
a document using HTTP. You can find these examples (called libapp_[1..3].c) in 
the distribution file and on our server at

	http://www.w3.org/pub/WWW/Library/Examples/

> Would anybody explain me how to strip the : 
> - MIME header into structured fields

The metainformation is normally part of the anchor object but in order to get 
MIME headers parsed, you must register the MIME parser stream to convert 
rfc822 formatted messages. You register converters through the HTConverter 
methods just as is alerady showed in the example. I have included the full 
version of the small program below.

> - the body of document

The MIME parser stream takes out the metainformation and adds it to the 
anchor. When all the metainformation is parsed, thestream goes into 
transparent mode and lets the body pass untouched.

> Looking at the documentation, I guess this is certainly possible using
> anchors & request objects but I have just not found how to implement it.
> 
> If I want the output stream in memory buffer rather than in a file, I have
> see in the FAQs & mailing list archive that several method are described.
> One of the method suggest to rewrite a HTMemoryBuffer Stream-derived object
> but we could do it directly  with HTExtParse, did anybody use this
> successfuly and how?

This is a good way of doing it. Instead of registrering the "save to file" 
stream you just swap the stream so that the external buffer stream is called 
instead. Then you can modify the buffer as you like.

                         0
                          \ /
-- CLIP -- CLIP -- CLIP -- x -- CLIP -- CLIP -- CLIP -- CLIP -- CLIP -- CLIP --
                          / \
                         0

#include "WWWLib.h"
#include "HTTP.h"
#include "WWWMIME.h"			 /* Include the MIME parser interface */
#include "HTDialog.h"

int main (int argc, char ** argv)
{
    HTList * converters = HTList_new();
    HTRequest * request = HTRequest_new();	  /* Create a request object */
    WWWTRACE = SHOW_ALL_TRACE;
    HTLibInit("TestApp", "1.0");
    HTProtocol_add("http", YES, HTLoadHTTP, NULL);

    /* Registration of MIME parser */
    HTConversion_add(converters, "message/rfc822", "*/*", HTMIMEConvert,
		     1.0, 0.0, 0.0);

    HTConversion_add(converters, "*/*", "www/present", HTSaveLocally,
		     1.0, 0.0, 0.0);

    HTFormat_setConversion(converters);
    HTAlert_add(HTPrompt, HT_A_PROMPT);
    if (argc == 2) {
	HTLoadAbsolute(argv[1], request);
    } else
	printf("Type the URL to fetch\n");
    HTRequest_delete(request);			/* Delete the request object */
    HTConversion_deleteAll(converters);
    HTLibTerminate();
    return 0;
}

-- 

Henrik Frystyk Nielsen, <frystyk@w3.org>
World-Wide Web Consortium, MIT/LCS NE43-356
545 Technology Square, Cambridge MA 02139, USA





Follow-Ups: