W3C home > Mailing lists > Public > www-lib@w3.org > July to September 1999

Re: Question about usage of HText-Callbacks - Have a very specific problem ...

From: Jan van der Steen <Jan.van.der.Steen@cwi.nl>
Date: Wed, 4 Aug 1999 04:25:34 -0400 (EDT)
Message-Id: <UTC199908040825.KAA01291.jansteen@mug.cwi.nl>
To: www-lib-request@w3.org

 |> > Some other callbacks e.g. in WIN-32-API allow to pass a void* to any
 |> > kind of data structures. In libwww ?
 |> >
 |>     Michael,
 |> I don't have the right code in front of me right now, but I
 |> think you can associate a context to the request object (
 |> HTRequest_setContext ) and retrieve it from the callback.
 |> Also, if you call HText_registerCDCallback you can set your
 |> own Text_new and Text_delete callback and have the Text_new
 |> create the context that will be passed

Right, and to elaborate a little (I have the code in front of me):

In the initialization phase of your program you do:

    HText_registerCDCallback              (text_new, text_delete);
    HText_registerBuildCallback           (text_build);
    HText_registerTextCallback            (text_add);
    HText_registerLinkCallback            (text_link);
    HText_registerElementCallback         (text_beginEl, text_endEl);
    HText_registerUnparsedElementCallback (text_beginUn, text_endUn);

This registers *your* functions for handling actions with the HText
datatype, which is an incomplete structure so you first have to
define that structure too, for example:

    struct struct _HText {
	int		ht_size;	/* size of document	*/
	size_t		ht_date;	/* last modified	*/
	CUSTOM *	ht_doc;		/* your datastructure	*/

In text_new() you allocate a new struct HText holder:

    HText *
    text_new (HTRequest      * request,
	      HTParentAnchor * anchor,
	      HTStream       * output_stream)
	HText *doc = (HText *) HT_CALLOC(1, sizeof(HText));

	HTRequest_setContext(request, doc);

	 * Other work (like http header parsing for example...)

All other HText callback functions now have a HText * pointer
with the value which was passed in HTRequest_setContext(), for

    text_delete (HText * doc)

	return YES;

I have some questions related to the HText environment as well.
I noticed that my text_delete() rarely or never get called. What
could be the reason for this? And another question, besides handling
the incoming HTML with the previously described callback functions
I also want a dump of the HTML code as is (litteral). Is that easy
to accomplish. I searched the documentation pages but could not
find information. I noticed that with -UNODEBUG (so with debugging
turned on) a file is created with all documents in it. But I would
prefer a handler per document.

kind regards,
Jan van der Steen
Received on Wednesday, 4 August 1999 14:26:33 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:33:51 UTC