![]() | Sources of the SimpleHTTPd |
Note:
This section may describe in a later version all aspects of the WWW server's
sources. But for now, it only gives details about the WWW server loadable
modules (module API) and the server's
API for module routines. At the end, there is a description of
how to write a module.
Basics |
When the WWW server starts-up or re-initializes, it gets a list of modules to load. These modules must be located to a system path, where the operation system searches for them. Loadable modules are implemented as
The loadable module itself has various entry points for the stuff to be handled. Some entry points are necessary, some optional. The next section gives a description of the module's API.
![]() |
The modules have an unique API (application programming interface) to the WWW server. There is a number of routines, which has to be implemented for working, and another number of other routines, which are optional. Further, a set of data structures is defined for information storage. Currently, the routines are:
modAbort() | ||
int modAbort( PHttpConnection pConn, HttpModAbort fReason ); | ||
type | optional | |
input | pConn | connection and request details of the request, which shall be aborted |
fReason |
| |
return | int |
|
The abort handler is called by the main process of the WWW server in order to terminate a connection due to an error condition or server shutdown. Please note, that the process or thread ID of the call to this routine may vary from the one that is handling the request! Also note, that an returned error does not delay a server shutdown or the abort process! |
modClear() | ||
int modClear( void ); | ||
type | optional | |
input | - | |
return | int |
|
This routine is called by the main server process to tell a module that it'll be unloaded. This routine is also called, when the server re-initializes itself after a configuration change. The module itself does not need to remove itself from memory - this is done by the WWW server. But this function call is provided in order to free ressources allocated by the initialization routine of the module. |
modConfig() | ||
int modConfig( PHttpConnection pConn, PTwoWayLinkedList *pCfg ); | ||
type | optional | |
input | pConn | connection and request details of the request |
pCfg | two-way linked list with parameters, the module has stored within the server's configuration data area. | |
return | int |
|
This routine provides modules with the ability of handling
their own configuration data. Each module has its own area within the server's
configuration data area. When a module is initialized (see
modInit()), it either gets this data
or may set new (default) values. These datas are given to
modConfig() by the pCfg parameter. The data
may be displayed. New data is sent back to the WWW server by using a HTML
form and HTTP method GET or POST (i.e. <form
action="..." method="GET"> ... </form> or
<form action="..." method="POST"> ...
</form>).
Because it is too difficult to explain it here, have a look at the MOD_test sample module program. Note: A module may refuse a configuration request be returning a value of +1. The administration tool then returns a note, that the module does not have a configuration entry - same, as if modConfig() wouldn't be implemented. |
modHandler() | ||
int modHandler( PHttpConnection pConn ); | ||
type | must be implemented! | |
input | pConn | connection and request details of the request, which shall be aborted |
return | int |
|
The handler routine is the main entry of a module. It processes an incoming request. The main WWW server process starts on each incoming request a new process (Unix) or thread (Win32, OS/2), which then results in a call to this routine, if the path maps to this module. The module the takes control over the request handling. For proper completion, after successful or unsuccessful processing of the request, the control must be returned to the WWW server - no exit() calls! |
modInit() | ||
int modInit( PHttpRoutines pRoutines, PTwoWayLinkedList *pCfg, int fNew ); | ||
type | optional | |
input | pRoutines | list of entry points of routines within the WWW server for the module. This list is a easy way of accessing public routines of the WWW server, without having the need of extracting them to a separate link-library, that has to be loaded by WWW server and module(s). |
pCfg | two-way linked list of configuration data for this module. You may use the LinkedList...() calls of the WWW server API for processing. | |
fNew | signal for the module, that a previous configuration of this module cannot be found. If fNew is set unequal 0, the module should set the defaults for its configuration. | |
return | int |
|
The module initializer may request ressources, which may then be used when handling requests. Configuration data is send by the WWW server. If there was no previous configuration and fNew != 0 is set, the module should initialize its configuration by the defaults. The WWW server then automatically stores this (default) configuration for further initialization calls. Online configuration shall be done via the modConfig() routine. |
![]() |
HttpConnection, PHttpConnection | ||
typedef struct s_HttpConnection { PHttpServer psServer; int (PROC_CALL_PTR pTCPsend)( struct s_HttpConnection *pConn, unsigned char *psz, int cb ); int (PROC_CALL_PTR pTCPrecv)( struct s_HttpConnection *pConn, unsigned char *psz, int cb ); int iCommSocket; int iPID; int iTimeOut; int iReadIdx; int iWriteIdx; int cLastChar; unsigned char szBuffer[8192]; unsigned char szTemp[8192]; char szRemoteAddr[32]; char szRemoteHost[64]; PTwoWayLinkedList pHttpSSLInfo; PTwoWayLinkedList pHttpCallHdr; HttpReqMethod fReqMethod; int fReqHttpVersion; unsigned long fReqInfo; unsigned char *pszAuthScheme; unsigned char *pszAuthUser; unsigned char *pszAuthPass; unsigned char *pszLocation; unsigned char *pszPath; unsigned char *pszPathInfo; unsigned char *pszQueryString; unsigned long cbContentLength; unsigned long cbContentRead; PTwoWayLinkedList pHttpRespHdr; int (PROC_CALL_PTR modAbort)( struct s_HttpConnection *pConn, HttpModAbort fReason ); void *pSSL; void *psZ; void *pZBuffer; unsigned long ulZCRC32; } HttpConnection, *PHttpConnection; | ||
member | purpose | |
---|---|---|
psServer | pointer to server structure HttpServer. | |
pTCPsend() | either NULL, if default TCP/IP sending routine should be used, or pointer to a TCP/IP sending routine (is used by the SSL part of the WWW server). | |
pTCPrecv() | either NULL, if default TCP/IP receiving routine should be used, or pointer to a TCP/IP receiving routine (is used by the SSL part of the WWW server). | |
iCommSocket | socket of current request. | |
iPID | process or thread ID of handler routine for the current request. | |
iTimeOut | current time-out in seconds, if this counter hits 0, a time-out is detected. | |
iReadIdx, iWriteIdx | used internally by HttpRead() and HttpWrite(). | |
cLastChar | ||
szBuffer | ||
szTemp | used by HttpPrintf(), but may also be used for personal purposes (temporary data storage). | |
szRemoteAddr | IP address of requester. | |
szRemoteHost | host name of requester. | |
pHttpSSLInfo | two-way linked list with SSL info about the current connection. The list will only be filled, when fReqInfo has bit HTTP_REQ_SSL_ACTIVE set! | |
pHttpCallHdr | two-way linked list with HTTP header of incoming request. | |
fReqMethod | HTTP request method. | |
fReqHttpVersion | version of incoming HTTP request header, main version ist stored in 10s, minor version in 1s. HTTP version HTTP/1.0 is stored as 10. | |
fReqInfo | a bit-wise coded data area, where
informations concerning the request and its handling is stored. These bits are
defined:
| |
pszAuthScheme | if not set NULL, references name of authorization scheme. | |
pszAuthUser | if set, specfies name of user. | |
pszAuthPass | if set, (decrypted) password of authorized user. Note: If the authorization is resolved by the WWW server (i.e. an authorization scheme is set within the WWW server's configuration), the original password is hidden and only a single '*' is set instead of it. | |
pszLocation | URI of request. | |
pszPath | resolved path of the request, e.g. the local system's path to the object. | |
pszPathInfo | if set, points to additional path informations within pszPath. | |
pszQueryString | if query data is given in the URI, this pointer is set on it. | |
cbContentLength | if set to a value greater 0, there is pending data, which may be read via HttpRead(). | |
cbContentRead | used by HttpRead() in order to determine, how many bytes were already read. | |
modAbort() | pointer to abort handler of the module if existing. Used by the abort and time-out handler of the WWW server. | |
pSSL | pointer to SSL specific data - this entry is not intended for user purposes. | |
psZ | pointer to on-the-fly data compression information block. | |
pZBuffer | pointer to on-the-fly data compression Z buffer. | |
ulZCRC32 | CRC-32 value on un-compressed data. |
HttpProtocol, PHttpProtocol | ||
typedef enum e_HttpProtocol { ... } HttpProtocol, *PHttpProtocol; | ||
value | meaning | |
---|---|---|
HTTP_UNKNOWN_PROTOCOL | unknown transfer protocol | |
HTTP_FTP | file transfer protocol (FTP) | |
HTTP_HTTP | hypertext transfer protocol (HTTP) | |
HTTP_HTTPS | hypertext transfer protocol over secure socket layer (HTTP over SSL) |
HttpReqMethod | ||
typedef enum e_HttpReqMethod { ... } HttpReqMethod; | ||
value | meaning | |
---|---|---|
HTTP_UNKNOWN_METHOD | HTTP method not known | |
HTTP_GET | HTTP request method for getting a document - mostly used on WWW servers for getting HTML pages. | |
HTTP_HEAD | HTTP request for header information on a document (size, type, etc.), without transfer of the data. | |
HTTP_POST | HTTP method for sending data to a WWW server - often used on HTML forms. Used for transfering more data than possible by HTTP_GET. | |
HTTP_PUT | like HTTP_POST. | |
HTTP_DELETE | HTTP method for deleting a data ressource. | |
HTTP_LINK | HTTP method for creating a link to a document. | |
HTTP_UNLINK | HTTP method for deleting a link on a document. |
HttpRoutines, PHttpRoutines | ||
typedef struct s_HttpRoutines { /* ... */ } HttpRoutines, *PHttpRoutines; | ||
Used by HttpInit() within a loadable module for initializing an internal list of WWW server API routines. The above mentioned routines are accessible via macros defined in include/http.h and the internal list. |
HttpServer, PHttpServer | ||
typedef struct s_HttpServer { int fSched; int cbConnections; int iTcpSocket; int iTcpSSLSocket; int iPort; int iSSLPort; char szLocalAddr[32]; char szLocalHost[64]; char szAdmin[64]; } HttpServer, *PHttpServer; | ||
member | purpose | |
---|---|---|
fSched | status of background
scheduler, is either
| |
cbConnections | number of open connections
to the WWW server
| |
iTcpSocket | main socket, where WWW server waits for incoming requests. | |
iTcpSocket | SSL socket, where WWW server waits for incoming SSL requests (0 = not available). | |
iPort | port number of TCP/IP port of WWW server. | |
iSSLPort | port number of TCP/IP port of WWW SSL server (0 = not available). | |
szLocalAddr | IP address of WWW server | |
szLocalHost | host name of WWW server | |
szAdmin | eMail address of WWW server's administrator | |
HttpSrvLaunch, PHttpSrvLaunch | ||
typedef struct s_HttpSrvLaunch { int iDay; int iHour; int iMin; void (* PROC_CALL pProc)(void *pArg); void *pArg; } HttpSrvLaunch, *PHttpSrvLaunch; | ||
member | purpose | |
---|---|---|
iDay | day of year/week, to launch
application, these values are possible:
| |
iHour | hour to launch application, with -1 = every hour and 0 .. 23 = given hour. | |
iMin | minute to launch application, with -1 = every minute and 0 .. 59 = given minute. | |
pProc | if set unequal NULL, this represents a pointer to the procedure to be launched at the given date or interval. | |
pArg | optional parameter on call to pProc. |
TwoWayLinkedList, PTwoWayLinkedList | ||
typedef struct s_TwoWayLinkedList { unsigned char *pszText; struct s_TwoWayLinkedList *pPrev, *pNext; } TwoWayLinkedList, *PTwoWayLinkedList; | ||
member | purpose | |
---|---|---|
pszText | text stored at this element. | |
pPrev | pointer to previous element or NULL if this is the first element in the list. | |
pNext | pointer to next element or NULL if this is the last element in the list. | |
Note: You may use the List...() for processing two-way linked lists. |
Definitions | ||
definition | description | |
---|---|---|
HTTP_REQ_... | used on HttpConnection.fReqInfo. See there for details. | |
- | HTTP response codes | |
HTTP_RC_CONTINUE | 100 | continue with request |
HTTP_RC_OK | 200 | request completed sucessfully |
HTTP_RC_MULTIPLE_CHOICES | 300 | URI fits more than one local object |
HTTP_RC_MOVED_PERMANENTLY | 301 | URI is no longer valid, use returned one instead |
HTTP_RC_MOVED_TEMPORARILY | 302 | URI is currently not valid, use returned one instead |
HTTP_RC_BAD_REQUEST | 400 | bad request (format) |
HTTP_RC_UNAUTHORIZED | 401 | un-authorized access to a protected ressource |
HTTP_RC_PAYMENT_REQUIRED | 402 | payment is required for access |
HTTP_RC_FORBIDDEN | 403 | access to ressource is forbidden |
HTTP_RC_NOT_FOUND | 404 | ressource not found |
HTTP_RC_METHOD_NOT_ALLOWED | 405 | invalid (or not-allowed) HTTP request method |
HTTP_RC_REQUEST_TIMEOUT | 408 | request timed out prior getting all request data |
HTTP_RC_CONFLICT | 409 | conflicting situation |
HTTP_RC_GONE | 410 | WWW server has gone |
HTTP_RC_LENGTH_REQUIRED | 411 | no content length given on request with HTTP method POST or PUT |
HTTP_RC_SSL_REQUIRED | 499 | (SimpleHTTPd-specific error code) a SSL connection is necessary for access to this information |
HTTP_RC_INTERNAL_ERROR | 500 | internal WWW server error |
HTTP_RC_NOT_IMPLEMENTED | 501 | not implemented feature or function requested |
HTTP_RC_BAD_GATEWAY | 502 | gateway (like common gateway interface - CGI) did not respond correctly |
HTTP_RC_SERVICE_UNAVAILABLE | 503 | service is not available |
HTTP_RC_GATEWAY_TIME_OUT | 504 | while waiting for the response to a request, there was a time-out situation on the gateway interface (e.g. CGI) |
HTTP_RC_UNSUPPORTED_VERSION | 505 | the given HTTP request version is not supported |
HttpAdmGetSequence() | ||
unsigned char * HttpAdmGetSequence( void ); | ||
input | - | |
return | u. char * |
|
returns the currently valid sequence number, which has to
be specified on configuration changes (see
modConfig(), too).
Note: Was first introduced in shttpd V 0.2. |
HttpBase64Decode() | ||
unsigned char * HttpBase64Decode( unsigned char *pszBase64 ); | ||
input | pszBase64 | string with Base-64 encoded data |
return | u. char * |
|
decodes Base-64 encoded data and returns it as string, which is duplicated via strdup(). I.e. you have to free the memory associated with the returned pointer! |
HttpCheckConns() | ||
int HttpCheckConns( void ); | ||
input | none | |
return | int |
|
returns the number of currently open connections to the WWW server. If the WWW server is being shut down, -1 is returned instead. |
HttpInit() | ||
void HttpInit( void ); | ||
input | none | |
return | none | |
Initializes the list of WWW server routines. Must be called at first in modInit(). |
HttpGetChar() | ||
int HttpGetChar( PHttpConnection pConn ); | ||
input | pConn | data structure containing information about the incoming request |
return | int |
|
returns the next character within the HTTP request's body. |
HttpGetHttpErrorText() | ||
unsigned char *HttpGetHttpErrorText( int iHttpRC ); | ||
input | iRC | HTTP return code, for which an error text should be returned |
return | unsigned char * |
|
returns an error text for the given HTTP return code.
Notes: - was first introduced in shttpd V 0.3. |
HttpGetLine() | ||
int HttpGetLine( PHttpConnection pConn, unsigned char *pszBuffer, int cbBuffer ); | ||
input | pConn | data structure containing information about the incoming request |
pszBuffer | buffer, where to write the data to | |
cbBuffer | max. number of bytes within pszBuffer | |
return | int |
|
reads the next sequence of characters within the HTTP request's body as if it were a line, i.e. up to the occurrence of a LF, CR or CR+LF (\n = 0x10, \r = 0x13, \r\n = 0x13, 0x10) sequence. The sequence is also copied to the buffer, that then is zero (\0 = 0x00 = NUL) terminated. |
HttpGetPathToBin() | ||
int HttpGetPathToBin( unsigned char *pszPath, int cbPath ); | ||
input | pszPath | pointer to string variable, that shall obtain the path |
cbPath | max. number of bytes within pszPath | |
return | int |
|
returns the directory, where the WWW server binary is
located. Modules may use this API call in order to put their own configuration
and data files in this central directory.
Notes: - was first introduced in shttpd V 0.3. |
HttpGetServerInternalData() | ||
PHttpServer HttpGetServerInternalData( void ); | ||
input | none | |
return | PHttpServer |
|
returns a pointer to the internal
HttpServer structure.
Notes: - was first introduced in shttpd V 0.6. |
HttpLog() | ||
int HttpLog( PHttpConnection pConn, ... ); | ||
input | pConn | data structure containing information about the incoming request |
... | string with format data and additional parameters, like printf() | |
return | int |
|
writes out the string to the logging facility. |
HttpParseQueryStr() | |||||||
int HttpParseQueryStr( unsigned char **ppszQueryStr, unsigned char *pszBuffer, unsigned long cbBuffer ); | |||||||
input | ppszQueryStr | pointer to pointer with query string | |||||
pszBuffer | buffer where to write parsed data | ||||||
cbBuffer | max. buffer length in bytes | ||||||
return | int |
| |||||
parses a given query string and move
ppszQueryStr to the next part of the query string to be parsed,
so that sub-sequent calls to this routine parse the entire query string. The
data in the query string is translated while parsed. See these notes:
|
HttpParseURL() | ||
int HttpParseURL( unsigned char *pszURL, PHttpProtocol pfProtocol, unsigned char *pszHost, unsigned long cbHost, unsigned int *piPort, unsigned char *pszPath, unsigned long cbPath ); | ||
input | pszURL | URL to be parsed |
pfProtocol | where to store the protocol info | |
pszHost | where to store the remote host | |
cbHost | max. length for remote host info | |
piPort | where to store the IP port number | |
pszPath | where to store the other stuff | |
cbPath | max. length for other stuff | |
return | int |
|
parses the given URL pszURL of the form
<protocol>://<host>:<port>/<path>
and returns information about the protocol, host, used TCP/IP port and path
(which includes all other stuff, too). Parameters not found will not be set,
i.e. if no protocol is specified, the variable referenced by
pfProtocol remains unchanged! So if default values have
to be set, they have to be set prior calling HttpParseURL().
That also means, that you may use this call subsequently - lets say you first
parse http://www.test.net/path/abc and afterwards you parse
https:def, you will receive as host www.test.net
and as path /path/def (if there is no absolute path given in
the URL, the routine adds the relative path to the end of the old path setting).
Notes: - was first introduced in shttpd V 0.2. - all parameters except pszURL may be set NULL - special characters (space, \n, \r, \t) are stripped from the path in pszURL before it is copied to pszPath |
HttpPrintf() | ||
int HttpPrintf( PHttpConnection pConn, ... ); | ||
input | pConn | data structure containing information about the incoming request |
... | string with format data and additional parameters, like printf() | |
return | int |
|
write data to the remote system in a free printf()-style. Note: Temporary storage is used in HttpConnection.szTemp. |
HttpPuts() | ||
int HttpPuts( PHttpConnection pConn, unsigned char *pszText ); | ||
input | pConn | data structure containing information about the incoming request |
pszText | text to be written | |
return | int |
|
writes the given string to the remote system and adds a \r\n (0x0D, 0x0A = CRLF) sequence to the end of it. Note: No temporary data is used. |
HttpRead() | ||
int HttpRead( PHttpConnection pConn, unsigned char *pszBuffer, int cbBuffer ); | ||
input | pConn | data structure containing information about the incoming request |
pszBuffer | buffer where to write the data | |
cbBuffer | number of bytes to be read | |
return | int |
|
reads the given number of bytes into the buffer. |
HttpRedirect() | ||
int HttpRead( PHttpConnection pConn, unsigned char *pszURL ); | ||
input | pConn | data structure containing information about the incoming request |
pszURL | new URL where browser shall request instead of the current one | |
return | int |
|
sends a HTTP response header with a suitable HTML page that redirects the browser request to the given URL. |
HttpScheduleAt() | ||
int HttpScheduleAt( PHttpSrvLaunch pEntry ); | ||
input | pEntry | data structure describing when and what to launch |
return | int |
|
adds an entry to the schedulers list, which is processed
every minute. The list is cleared on each system start or reconfiguration run.
So each and every procedure, that shall be scheduled, has to be added to the
scheduler's list at execution of
modInit().
Notes: - was first introduced in shttpd V 0.3. |
HttpSendHeader() | ||
int HttpSendHeader( PHttpConnection pConn, int fStatus ); | ||
input | pConn | data structure containing information about the incoming request |
fStatus | HTTP response status, a value of 0 (zero) is re-mapped to HTTP_RC_OK | |
return | int |
|
first sends the initial line of the HTTP response header, using the response code fStatus. If the channel should be kept open (see HttpConnection.fReqInfo and HTTP_REQ_REUSE_CHANNEL), a Keep-Alive:-line is generated. Then the HTTP response header lines described in the two-way linked list HttpConnection.pHttpRespHdr are written. If no such list is given a default Content-type: text/html line is written. |
HttpSockInit() | ||
int HttpSockInit( void ); | ||
input | - | |
return | int |
|
Initialization of the IP stack on Microsoft Windows
systems (Win95, Win98, WinNT, Win2000).
Notes: - was first introduced in shttpd V 0.3. - is used internally - it is not necessary to call this function directly, because it is called automatically by the WWW server and the wrapper TCP/IP calls (see include file os.h). |
HttpSystem() | ||
int HttpSystem( int fEnv, unsigned char *pszCmdLine ); | ||
input | fEnv |
|
pszCmdLine | command line to be executed | |
return | int |
|
executes the given command from command line - in-/output is not redirected!!! |
HttpUngetChar() | ||
int HttpUngetChar( PHttpConnection pConn, unsigned char cChar ); | ||
input | pConn | data structure containing information about the incoming request |
cChar | character to be un-getted | |
return | int |
|
deposits the given character on top of the input buffer, so that a following HttpGetChar(), HttpGetLine() or HttpRead() command gets it first. |
HttpWrite() | ||
int HttpWrite( PHttpConnection pConn, unsigned char *pszBuffer, int cbBuffer ); | ||
input | pConn | data structure containing information about the incoming request |
pszBuffer | buffer with data | |
cbBuffer | number of bytes to be written | |
return | int |
|
writes the number of given bytes directly to the remote system. |
ListAdd() | ||
int ListAdd( PTwoWayLinkedList *pList, unsigned char *pszText ); | ||
input | pList | pointer to pointer to two-way linked list |
pszText | text to be added to the list | |
return | int |
|
adds the given line to the end of the list. The string given is duplicated via strdup(). |
ListClear() | ||
int ListClear( PTwoWayLinkedList *pList ); | ||
input | pList | pointer to pointer to two-way linked list |
return | int |
|
removes all entries from the list and frees all associated memory. |
ListDelete() | ||
int ListDelete( PTwoWayLinkedList *pList, unsigned char *pszSearchText ); | ||
input | pList | pointer to pointer to two-way linked list |
pszSearchText | text to be searched for (at line start) | |
return | int |
|
searches for a line starting with the given text and deletes
it. Memory associated with the element is freed.
Note: Search is case-insensitive. |
ListFind() | ||
char * ListFind( PTwoWayLinkedList *pList, unsigned char *pszSearchText ); | ||
input | pList | pointer to pointer to two-way linked list |
pszSearchText | text to be searched for (at line start) | |
return | char * |
|
searches for an element, which has a line starting with the
same text as described by the search text. If found, a pointer to the data of
the element is returned and the element is selected.
Note: Search is case-insensitive. |
ListGet() | ||
char * ListGet( PTwoWayLinkedList *pList ); | ||
input | pList | pointer to pointer to two-way linked list |
return | char * |
|
ListNext() | ||
int ListNext( PTwoWayLinkedList *pList ); | ||
input | pList | pointer to pointer to two-way linked list |
return | int |
|
select next element in the list. |
ListPrev() | ||
int ListPrev( PTwoWayLinkedList *pList ); | ||
input | pList | pointer to pointer to two-way linked list |
return | int |
|
select previous element in the list. |
ListReplace() | ||
int ListReplace( PTwoWayLinkedList *pList, unsigned char *pszSearchText, unsigned char *pszReplaceText ); | ||
input | pList | pointer to pointer to two-way linked list |
pszSearchText | text to be searched for at each start of line within the list | |
pszReplaceText | text to be placed in the line matching the search criteria | |
return | int |
|
replaces an existing line within the list with a new one. If the line searched for does not exist, the new text is added to the end of the list instead. |
ListRewind() | ||
int ListRewind( PTwoWayLinkedList *pList ); | ||
input | pList | pointer to pointer to two-way linked list |
return | int |
|
rewinds the given two-way linked list. |
memShmAlloc() | ||
void * memShmAlloc( unsigned long cbMemSize ); | ||
input | cbMemSize | number of bytes to be allocated as shared memory |
return | void * |
|
creates a shared memory block with the given size. The
returned pointer may be given to child processes (Unix: fork())
which then have access to the same data - updates in that block are visible to
the parent!
Note: Was first introduced in shttpd V 0.2. |
memShmFree() | ||
int memShmFree( void **ppMemory, unsigned long cbMemSize ); | ||
input | ppMemory | pointer to pointer to shared memory block |
cbMemSize | number of bytes to be de-allocated (size of shared memory block, as specified at memShmAlloc() | |
return | int |
|
frees the shared memory block - the associated pointer will
be reset to NULL. Shared memory always should be allocated and
freed by the master process or thread, i.e. in the module initializer and
destructor routine, but nether in the module's handler routine!
Note: Was first introduced in shttpd V 0.2. |
memSrvAlloc() | ||
void * memSrvAlloc( unsigned long cbMemSize ); | ||
input | cbMemSize | number of bytes to be allocated as server allocated memory |
return | void * |
|
creates a server allocated memory block. This is memory
occupied by the WWW server and therefor is not vulnerable to unloads of
modules. If a memory block is already allocated, the pointer to this memory
is returned instead of allocating a new block. For identification of the
memory blocks, the definition of this command gets the file name and line
number in the source code.
Note: Was first introduced in shttpd V 0.5. |
memSrvFree() | ||
int memSrvFree( void **ppMemory ); | ||
input | ppMemory | pointer to pointer to server allocated memory block, which was returned by memSrvAlloc() |
return | int |
|
frees the server allocated memory block - the associated
pointer will be reset to NULL. Server allocated memory always
should be allocated and freed by the master process or thread, i.e. in the
module initializer and destructor routine, but nether in the module's handler
routine!
Note: Was first introduced in shttpd V 0.5. |
![]() |
A lots of things could be told. But it's much easier, to study the example MOD_test, a test / sample module (source code). You may also have a look at the sample module's output page.
There are some things to mention:
| ©. 1998-2000 by Dirk Ohme |