Previous Next Contents Index


Programming the Web Connector

This appendix describes how to filter input and output using a shared library provided in the Web Connector plug-in.

The Web Connector is a plug-in to your web server that enables it to communicate with Netscape Application Server (NAS). Normally this communication is handled automatically by the programs and protocols built into the plug-in and the server. However, you can override several functions stored in a C++ shared library in order to provide custom filters at the plug-in point. This allows you to optimize incoming pages by instructing the web server to deliver them to the application server, and it allows you to customize your outgoing pages in several ways.

This chapter contains the following sections:


The gxlogcli Shared Library
Customizable functions for the Web Connector plug-in are kept in a shared library called gxlogcli.dll (on NT) or gxlogcli.so (on UNIX systems). This library contains several function stubs that you can override.

The stub file is called gxlogcli.h; it can be found in FIXME. To customize any of the functions, create the code to override them in the stub file and compile it into a shared library, then upload it to the Web Connector.

Library Function Stubs
The following function stubs are available to the Web Connector. Detailed descriptions and programming notes are available in the stub file gxlogcli.h itself.

GXDLLEXPORT int gxclientlogcallback(pblock *pb, 
Session *sn,
Request *rq,
char **pFieldArray,
char *pTypeArray,
char **pValueArray);

GXDLLEXPORT int gxclientlogcallback(HTTP_FILTER_CONTEXT *pCtxt,
PHTTP_FILTER_LOG pLog,
char **pFieldArray,
char *pTypeArray,
char **pValueArray);

GXDLLEXPORT int gxclientreqcallback(char *pInput,
int len,
char **pOutput);

GXDLLEXPORT int gxclientheadercallback(const char* path_info,
char* header,
int headerLen,
char* value,
int valueLen,
char** newHeader,
char** newValue);

GXDLLEXPORT int gxclientstatuscallback(const char* path_info,
int *responseStatus,
char* respMessage,
int respSize,
char** newResp);

GXDLLEXPORT int gxclientpostcallback(const char* pathinfo,
const char* content_type,
char postHeader[],
int postHeaderLen);
GXDLLEXPORT int gxclientuserheadercallback(pblock *pb, 
Session *sn,
Request *rq,
const char* path_info,
const char* header,
char* value,
int valueLen);

GXDLLEXPORT
int gxclientuserheadercallback(EXTENSION_CONTROL_BLOCK *pECB,
const char* path_info,
const char* header,
char* value,
int valueLen);
Compiling the Library
To compile the library using a C++ compiler, do the following:

  1. Make sure you know where your #include files are located.
  2. Add your code to the function stubs.
  3. Compile the code using the C++ compiler provided by the platform of the Web Connector machine.
  4. Link with any other library you are using. You need to add these library names to the makefile you are using.
  5. Upload the code to the directory where the Web Connector binaries reside (libgxlogcli.so for Solaris and gxlogcli.dll for NT).
  6. Restart the Web Connector plug-in.

Customizing Input
The following functions can be customized to control the way incoming pages from a client to the Web Connector plug-in are handled. For more details, see the comments provided in the library.

gxclientuserheadercallback

This function is called when the Web Connector plug-in is unable to retrieve the value of a header that has been specified in the registry of the Web Connector. The function is called when the Web Connector has already tried unsuccessfully to retrieve the header from the server context—pblock for NES, HTTP_FILTER for IIS— as well as access environment variables using genenv(). The purpose of gxclientuserheadercallback is to fetch the value of the header and store it in value, one of the function's parameters.

The function returns these values:

Value
Definition
- 1
The default return value, indicating that nothing was written to value. In this case, the header is not sent to NAS. Also, this value indicates that the Web Connector will not call this method again during this run of the web server for any other header whose value could not be retrieved.
0
Returned if you want the Web Connector to call this function for other headers even though no value was found for the header in this call of the function.
>0
The number of characters written to value., which should not be greater than valuelen, one of the function's parameters. The Web Connector will continue to call this function for other headers that are not found.

gxclientpostcallback

This function is used to determine how to handle post data, the data sent from the client. The parameters of this function are:

If the function is inactive, then all application components will handle data according to content-type. If content-type is application/www-urlencoded, then the Web Connector converts the post data into a name-value list before sending it to NAS.

The function returns these values:

Value
Definition
>0
If this function returns a positive number, then the post data is sent as a binary blob to NAS. This blob is identified by postHeader. This value also indicates that this function will be called again for the next request.
0
The post data is converted into a name-value pair list and then sent to NAS. This function will be called again for the next request.
-1
The post data is sent as a binary blob but the function is not called again. For subsequent requests, the post data is sent as a blob.


Customizing Output
The following functions can be customized to control the way outgoing pages from the Web Connector plug-in to the requesting client are handled.

gxlclientlogcallback

This function is called from inside gxclientlog. It collects a list of information about a request, after the request has been sent back from the Web Connector plug-in to the client. The HTTLOG parameter in the NAS registry determines what information needs to collected and stored in the log. The gxclientlogcallback function can specify additional information to be stored in the log.

When the gxclientlogcallbackfunction is called, it receives the following three arrays of pointers to characters:

Note that the Web Connector does not delete any of the entries contained in these arrays.

The function returns the following values:

Value
Definition
0
The default return value. The function is called after the Web Connector completes a request. Indicates that there are not items to be logged and therefore the Web Connector will resort to default logging.
-1
The Web Connector assumes that the callback function is requesting no logging of request data. No information is logged.
<-1
If the function returns a value less than -1, then the Web Connector logs those many items from the arrays and also performs default logging. For example, if the function returns a value of -20, then 20 items from the arrays are logged.

gxclientheadercallback

This callback function, which controls the headers that are sent to the client, is called before returning HTTP headers back to the client. The parameters of the function are:

This function returns the following values:

Value
Definition
-1
The default return value. The Web Connector will not call this function again until the server is restarted.
0
The function is not modifying the output being sent. The Web Connector will send just the existing header and value to the requesting client.
>0
If the return value is greater than 0, then send the new header and value instead of the existing header and value. Both newHeader and newValue should point to null, terminated strings and their buffers should have been allocated using the new() operator. They are deleted after the contents are sent to the client.
<-1
If the function returns a value less than -1, it send the user defined header as well as the existing contents of the header and value. After sending this information, the newHeader and newValue are deleted.

gxclientstatuscallback

Every response to a client request contains only one status header with an HTTP status code. The gxclientstatuscallback function is called before the web server returns to the client the HTTP status code (int *responseStatus), which is used by the browser to determine what happened to the request. The status code is associated with an HTTP response, for example "HTTP/1.1 404 Not Found." The function allows you to modify the value of the HTTP status code, in this example 404. A status code is called only once per request.

The parameters of this function are:

To modify the message, use one of the following three return values:

Value
Definition
0
Modify the message in place and return 0. In this case, respSize indicates the number of bytes available in respMessage. You can fill them in place. respMessage must always point to a null terminated string. In this case, return 0 to the caller.
>0
If the return value is greater than 0, create a new response message and return it in the pointer newResp, which is deleted when processing is completed. newResp must always point to a null terminated string. In this case, return a positive number.
-1
The default return value. The Web Connector should not call this function again.

gxclientreqcallback

This function controls the output sent to the client. The parameters of the function are:

This function returns the following values:

Value
Definition
-1
The default return value. The Web Connector will not call this function again until the server is restarted.
0
The function will not modify the output. The Web Connector will send just the contents of *pInput to the requesting client.
>0
The number of bytes to be written back to the client from the address in ppOutput. This buffer, which should already have been allocated using the new() operator, will be deleted after the contents are written to the client. In this case, the contents of pInput are not sent to the client.

 

© Copyright 1999 Netscape Communications Corp.