The read filter method is called when input data is required. Filters that modify or consume incoming data should implement the read filter method.
Upon receiving control, a read implementation should fill buf with up to amount bytes of input data. This data may be obtained by calling the net_read function, as shown in the example below.
int read(FilterLayer *layer, void *buf, int amount, int timeout);
The number of bytes placed in buf on success, 0 if no data is available, or a negative value if an error occurred.
FilterLayer *layer is the filter layer in which the filter is installed.
void *buf is the buffer in which data should be placed.
int amount is the maximum number of bytes that should be placed in the buffer.
int timeout is the number of seconds to allow for the read operation before returning. Do not use timeoutto return because not enough bytes were read in the given time. Instead, use this function to limit the amount of time devoted to waiting until some data arrives.
int myfilter_read(FilterLayer *layer, void *buf, int amount, int timeout) { return net_read(layer->lower, buf, amount, timeout);}
The REALLOC macro is a platform-independent substitute for the C library routine realloc. It changes the size of a specified memory block that was originally created by MALLOC, CALLOC, or STRDUP. The contents of the object remains unchanged up to the lesser of the old and new sizes. If the new size is larger, the new space is uninitialized.
Calling REALLOC for a block that was allocated with PERM_MALLOC, PERM_CALLOC, or PERM_STRDUP will not work.
void *REALLOC(void *ptr, int size);
A pointer to the new space if the request could be satisfied.
void *ptr is a (void *) pointer to a block of memory. If the pointer was not created by MALLOC, CALLOC, or STRDUP, the behavior is undefined.
int size is the number of bytes to allocate.
char *name;name = (char *) MALLOC(256);if (NotBigEnough()) name = (char *) REALLOC(512);
MALLOC, FREE, STRDUP, CALLOC, PERM_MALLOC, PERM_FREE, PERM_REALLOC, PERM_CALLOC, PERM_STRDUP
The remove filter method is called when the filter stack is destroyed, or when a filter is removed from a filter stack by the filter_remove function or remove-filter SAF (applicable in Input-, Output-, Service-, and Error-class directives).
Waiting to flush buffered data when the remove method is invoked might be too late. For this reason, filters that buffer outgoing data should implement the flush filter method.
void remove(FilterLayer *layer);
void
FilterLayer *layer is the filter layer the filter is installed in.
The request_create function is a utility function that creates a new request structure.
#include <frame/req.h> Request *request_create(void);
A Request structure
No parameter is required.
The request_free function frees a specified request structure.
#include <frame/req.h> void request_free(Request *req);
void
Request *rq is the Request structure to be freed.
The request_header function finds an entry in the pblock containing the client’s HTTP request headers (rq->headers). You must use this function rather than pblock_findval when accessing the client headers because the server might begin processing the request before the headers have been completely read.
int request_header(char *name, char **value, Session *sn, Request *rq);
Returns REQ_PROCEED if the header was found, REQ_ABORTED if the header was not found, or REQ_EXIT if an error occurred reading from the client.
char *name is the name of the header.
char **value is the address where the function will place the value of the specified header. If none is found, the function stores NULL.
Session *sn identifies the Session structure.
Request *rq identifies the Request structure.
The Session and Request parameters are the same as the parameters passed into your SAF.