- From: Jan van der Steen <Jan.van.der.Steen@cwi.nl>
- Date: Wed, 4 Aug 1999 04:25:34 -0400 (EDT)
- 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
example:
BOOL
text_delete (HText * doc)
{
HT_FREE(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