[Home] [ToC] [Up] [Prev] [Next]
This module defines the types and functions needed to access a browser's internal networking and URL handling mechanism. This allows the system to take advantage of this functionality that is already built into the browser, and for the browser to regulate the system's network access. These services are typically implemented as part of the browser's glue, and must be implemented for the iHTML system to work.
typedef IHRetrieveRequestP (*IHRetrieveCallback) IH_PROTO((IHGlobalInfo* interface, IHRetrieveRequestP request, void* userdata));
(IHGlobalInfo*)
interface
(IHRetrieveRequestP)
request
(void*)
userdata
(IHRetrieveRequestP)
The
request that was handed to the callback, or NULL
if this callback is finished.
This is the definition of the function callback that is used to inform the owner of a transaction of data as it becomes available.
void*
(This is an
opaque type that is defined by the browser's internal
implementation.)
An abstract handle on a URL transaction that is currently active in the browser.
typedef enum { IHReqFinished = 0x0001, /* All data is available */ IHReqIncomplete = 0x0002, /* Not all data has been retrieved. */ IHReqInteractive = 0x0003 /* This is an interactive connection */ } IHReqStatus;
This type is used to represent the current status of a URL transaction. The currently defined values are shown above.
void
BR_DerefRetrieveRequest(IHRetrieveRequestP req)
(IHRetrieveRequestP)
req
Removes a reference from the IHRetrieveRequestP. If this is the last reference on it, it is deallocated. Normally, a request made by BR_RetrieveURL() starts with two references -- one for the callback hook, and one returned immediately to the caller. Both of these functions must dereference it for it to be deallocated.
IHBufferP
BR_GetRequestBuffer(IHRetrieveRequestP req, int
read)
IHBufferP
BR_SetRequestBuffer(IHRetrieveRequestP req, IHBufferP
buffer)
(IHRetrieveRequestP)
req
(int)
read
(IHBufferP)
buffer
(IHBufferP)
The current buffer
of URL data.
These functions are a higher-level interface for reading data from a URL. BR_GetRequestBuffer() returns the current data buffer; if read is TRUE, all available data will be read into the buffer before it is returned. This function detaches the buffer from the request -- it is now the responsibility of the caller to deallocate it when done.
BR_SetRequestBuffer() sets the current buffer for a request. This puts it under the respondibility of the request to deallocate or otherwise manipulate it; a subsequent call to BR_GetRequestBuffer() will return the given buffer.
Note that when the callback returns, any data that hasn't yet been read from the URL will automatically be appended to the current buffer. (Or a new buffer created, if one doesn't exist.)
These functions will typically be used together to read a URL. When the request callback starts, it can use BR_GetRequestBuffer() to retrieve the available data and examine it; if it wants to save that data for later and start fresh with the next batch, this is all that needs to be done.
For successively collecting data, the previously retrieved buffer (after any desired modifications) may be given back to the request with BR_SetRequestBuffer(). Further data can then be appended to the buffer after subsequent runs through the callback.
const char* =
BR_GetRequestHeader(IHRetrieveRequestP req, const char*
name)
(IHRetrieveRequestP)
req
(const char*)
name
(const char*)
The text
associated with the requested header.
Returns a string of the value that this transaction request has for the given header. Note that since these headers must be retrieved from the network, they are not immediately available; the program should wait until after its contact to access the transaction's header information.
The available header names are scheme-dependent. For the
http:
scheme, they are the standard MIME headers,
such as Content-type
. Note that the trailing ':'
is not included in header names.
IHReqStatus =
BR_GetRequestStatus(IHRetrieveRequestP req)
(IHRetrieveRequestP)
req
(IHReqStatus)
The current
status of this transaction.
Returns the current status of the given URL transaction request.
const char* =
BR_GetRequestURL(IHRetrieveRequestP req)
(IHRetrieveRequestP)
req
(const char*)
The ASCII URL
this transaction request is for.
Returns a string representing the URL that this transaction request was created to retrieve.
IHRetrieveRequestP
BR_RetrieveURL(IHGlobalInfo* gi, const char* url,
IHRetrieveCallback callback, void* userdata)
(IHGlobalInfo*)
gi
(const char*)
url
(IHRetrieveCallback)
callback
(void*)
userdata
(IHRetrieveRequestP)
The new
URL transaction request.
Retrieves the given URL from the network. This function may or may not finish before returning; you must not expect any data to be available until the callback is called, which may not be able to happen until control is eventually returned back the browser's event loop.
The resulting IHRetrieveRequestP is owned both by the caller and the given callback function; both must indicate that they are done with it for it to be deallocated. This is accomplished from the caller by calling BR_DerefRetrieveRequest() on the request returned by this function, and from the callback by returning a NULL result.
The function returns a IHRetrieveRequestP structure, which contains information about this request. If NULL is returned, the request failed.
A special URL scheme of the form
"tcp://machine:port
" is
defined by the iHTML system, and must be implemented by the
browser.
This opens an interactive TCP/IP socket with the
given machine and at the given port number. In this case, the
returned IHRetrieveRequest is guaranteed to be interactive; the
application may write data through calls to
BR_WriteRequestBuffer(), and the IHRetrieveCallback function is
called whenever one or more bytes of data come over the
network.
void
BR_WriteRequestBuffer(IHRetrieveRequestP req, IHBufferP
buffer)
(IHRetrieveRequestP)
req
(IHBufferP)
buffer
This function is used for interactive
sessions -- which currently only applies to the
"tcp
:" URL. The data in the given buffer is sent
over the network connection defined by the given
IHRetrieveRequestP. As soon as this function returns, the
buffer is available to the caller for re-use. Note that this
function does not block -- the data will probably not
be transmitted until after it returns.
[Home] [ToC] [Up] [Prev] [Next]
Dianne Kyra Hackborn <hackbod@angryredplanet.com> | Last modified: Tue Oct 8 04:01:26 PDT 1996 |