Previous     Contents     Index     DocHome     Next     
iPlanet Web Server, Enterprise Edition NSAPI Programmer's Guide



Chapter 5   NSAPI Function Reference


This chapter lists all the public C functions and macros of the Netscape Server Applications Programming Interface (NSAPI) in alphabetic order. These are the functions you use when writing your own Server Application Functions (SAFs).

See Chapter 7 "Syntax and Use of magnus.conf," for a list of the pre-defined Init SAFs. See Chapter 3 "Predefined SAFs and the Request Handling Process," for a list of the rest of the pre-defined SAFs.

Each function provides the name, syntax, parameters, return value, a description of what the function does, and sometimes an example of its use and a list of related functions.

For more information on data structures, see Appendix A "Data Structure Reference," and also look in the nsapi.h header file in the include directory in the build for iPlanet Web Server 6.0.



NSAPI Functions (in Alphabetical Order)



For an alphabetical list of function names, see Appendix G "Alphabetical List of NSAPI Functions and Macros."

C

D

F

L

M

N

P

R

S

U

V



C




CALLOC

The CALLOC macro is a platform-independent substitute for the C library routine calloc. It allocates num*size bytes from the request's memory pool. If pooled memory has been disabled in the configuration file (with the pool-init built-in SAF), PERM_CALLOC and CALLOC both obtain their memory from the system heap.


Syntax
void *CALLOC(int num, int size)


Returns
A void pointer to a block of memory.


Parameters
int num is the number of elements to allocate.

int size is the size in bytes of each element.


Example
/* Allocate space for an array of 100 char pointers */
char *name;
name = (char *) CALLOC(100, sizeof(char *));


See also
FREE, REALLOC, STRDUP, PERM_MALLOC, PERM_FREE, PERM_REALLOC, PERM_STRDUP


cinfo_find

The cinfo_find() function uses the MIME types information to find the type, encoding, and/or language based on the extension(s) of the Universal Resource Identifier (URI) or local file name. Use this information to send headers (rq->srvhdrs) to the client indicating the content-type, content-encoding, and content-language of the data it will be receiving from the server.

The name used is everything after the last slash (/) or the whole string if no slash is found. File name extensions are not case-sensitive. The name may contain multiple extensions separated by period (.) to indicate type, encoding, or language. For example, the URI a/b/filename.jp.txt.zip could represent a Japanese language, text/plain type, zip encoded file.


Syntax
cinfo *cinfo_find(char *uri);


Returns
A pointer to a newly allocated cinfo structure if content info was found or NULL if no content was found

The cinfo structure that is allocated and returned contains pointers to the content-type, content-encoding, and content-language, if found. Each is a pointer into static data in the types database, or NULL if not found. Do not free these pointers. You should free the cinfo structure when you are done using it.


Parameters
char *uri is a Universal Resource Identifier (URI) or local file name. Multiple file name extensions should be separated by periods (.).


condvar_init

The condvar_init function is a critical-section function that initializes and returns a new condition variable associated with a specified critical-section variable. You can use the condition variable to prevent interference between two threads of execution.


Syntax
CONDVAR condvar_init(CRITICAL id);


Returns
A newly allocated condition variable (CONDVAR).


Parameters
CRITICAL id is a critical-section variable.


See also
condvar_notify, condvar_terminate, condvar_wait, crit_init, crit_enter, crit_exit, crit_terminate.


condvar_notify

The condvar_notify function is a critical-section function that awakens any threads that are blocked on the given critical-section variable. Use this function to awaken threads of execution of a given critical section. First, use crit_enter to gain ownership of the critical section. Then use the returned critical-section variable to call condvar_notify to awaken the threads. Finally, when condvar_notify returns, call crit_exit to surrender ownership of the critical section.


Syntax
void condvar_notify(CONDVAR cv);


Returns
void


Parameters
CONDVAR cv is a condition variable.


See also
condvar_init, condvar_terminate, condvar_wait, crit_init, crit_enter, crit_exit, crit_terminate.


condvar_terminate

The condvar_terminate function is a critical-section function that frees a condition variable. Use this function to free a previously allocated condition variable.


Warning
Terminating a condition variable that is in use can lead to unpredictable results.


Syntax
void condvar_terminate(CONDVAR cv);


Returns
void


Parameters
CONDVAR cv is a condition variable.


See also
condvar_init, condvar_notify, condvar_wait, crit_init, crit_enter, crit_exit, crit_terminate.


condvar_wait

Critical-section function that blocks on a given condition variable. Use this function to wait for a critical section (specified by a condition variable argument) to become available. The calling thread is blocked until another thread calls condvar_notify with the same condition variable argument. The caller must have entered the critical section associated with this condition variable before calling condvar_wait.


Syntax
void condvar_wait(CONDVAR cv);


Returns
void


Parameters
CONDVAR cv is a condition variable.


See also
condvar_init, condvar_notify, condvar_terminate, crit_init, crit_enter, crit_exit, crit_terminate.


crit_enter

Critical-section function that attempts to enter a critical section. Use this function to gain ownership of a critical section. If another thread already owns the section, the calling thread is blocked until the first thread surrenders ownership by calling crit_exit.


Syntax
void crit_enter(CRITICAL crvar);


Returns
void


Parameters
CRITICAL crvar is a critical-section variable.


See also
crit_init, crit_exit, crit_terminate.


crit_exit

Critical-section function that surrenders ownership of a critical section. Use this function to surrender ownership of a critical section. If another thread is blocked waiting for the section, the block will be removed and the waiting thread will be given ownership of the section.


Syntax
void crit_exit(CRITICAL crvar);


Returns
void


Parameters
CRITICAL crvar is a critical-section variable.


See also
crit_init, crit_enter, crit_terminate.


crit_init

Critical-section function that creates and returns a new critical-section variable (a variable of type CRITICAL). Use this function to obtain a new instance of a variable of type CRITICAL (a critical-section variable) to be used in managing the prevention of interference between two threads of execution. At the time of its creation, no thread owns the critical section.


Warning
Threads must not own or be waiting for the critical section when crit_terminate is called.


Syntax
CRITICAL crit_init(void);


Returns
A newly allocated critical-section variable (CRITICAL)


Parameters
none.


See also
crit_enter, crit_exit, crit_terminate.


crit_terminate

Critical-section function that removes a previously-allocated critical-section variable (a variable of type CRITICAL). Use this function to release a critical-section variable previously obtained by a call to crit_init.


Syntax
void crit_terminate(CRITICAL crvar);


Returns
void


Parameters
CRITICAL crvar is a critical-section variable.


See also
crit_init, crit_enter, crit_exit.



D




daemon_atrestart

The daemon_atrestart function lets you register a callback function named by fn to be used when the server terminates. Use this function when you need a callback function to deallocate resources allocated by an initialization function. The daemon_atrestart function is a generalization of the magnus_atrestart function.

The magnus.conf directives TerminateTimeout and ChildRestartCallback also affect the callback of NSAPI functions.


Syntax
void daemon_atrestart(void (*fn)(void *), void *data);


Returns
void


Parameters
void (* fn) (void *) is the callback function.

void *data is the parameter passed to the callback function when the server is restarted.


Example
/* Register the log_close function, passing it NULL */
/* to close *a log file when the server is */
/* restarted or shutdown. */
daemon_atrestart(log_close, NULL);
NSAPI_PUBLIC void log_close(void *parameter)
{
system_fclose(global_logfd);
}



F




fc_open

The fc_open function returns a pointer to PRFileDesc that refers to an open file (fileName). The fileName must be the full pathname of an exisiting file. The file is opened in Read Mode only. The application calling this function should not modify the currency of the file pointed by the PRFileDesc * unless the DUP_FILE_DESC is also passed to this function. In other words, the application (at minimum) should not issue a read operation based on this pointer that would modify the currency for the PRFileDesc *. If such a read operation is required (that may change the currency for the PRFileDesc * ), then the application should call this function with the argument DUP_FILE_DESC.

On a successful call to this function a valid pointer to PRFileDesc is returned and the handle 'FcHdl' is properly initialized. The size information for the file is stored in the 'fileSize' member of the handle.


Syntax
PRFileDesc *fc_open(const char *fileName, FcHdl *hDl,PRUint32 flags, Session *sn, Request *rq);


Returns
Pointer to PRFileDesc, NULL on failure


Parameters
const char *fileName is the full path name of the file to be opened

FcHdl*hDl is a valid pointer to a structure of type FcHdl

PRUint32 flags can be 0 or DUP_FILE_DESC

Session *sn is a pointer to the session

Request *rq is a pointer to the request


fc_close

The fc_close function closes a file opened using fc_open. This function should only be called with files opened using fc_open.


Syntax
void fc_close(PRFileDesc *fd, FcHdl *hDl;


Returns
void


Parameters
PRFileDesc *fd A valid pointer returned from a prior call to fc_open

FcHdl *hDl is a valid pointer to a structure of type FcHdl this pointer must have been initialized by a prior call to fc_open.


filebuf_buf2sd

The filebuf_buf2sd function sends a file buffer to a socket (descriptor) and returns the number of bytes sent.

Use this function to send the contents of an entire file to the client.


Syntax
int filebuf_buf2sd(filebuf *buf, SYS_NETFD sd);


Returns
The number of bytes sent to the socket, if successful, or the constant IO_ERROR if the file buffer could not be sent


Parameters
filebuf *buf is the file buffer which must already have been opened.

SYS_NETFD sd is the platform-independent socket descriptor. Normally this will be obtained from the csd (client socket descriptor) field of the sn (Session) structure.


Example
if (filebuf_buf2sd(buf, sn->csd) == IO_ERROR)
   return(REQ_EXIT);


See also
filebuf_close, filebuf_open, filebuf_open_nostat, filebuf_getc.


filebuf_close

The filebuf_close function deallocates a file buffer and closes its associated file.

Generally, use filebuf_open first to open a file buffer, and then filebuf_getc to access the information in the file. After you have finished using the file buffer, use filebuf_close to close it.


Syntax
void filebuf_close(filebuf *buf);


Returns
void


Parameters
filebuf *buf is the file buffer previously opened with filebuf_open.


Example
filebuf_close(buf);


See also
filebuf_open, filebuf_open_nostat, filebuf_buf2sd, filebuf_getc


filebuf_getc

The filebuf_getc function retrieves a character from the current file position and returns it as an integer. It then increments the current file position.

Use filebuf_getc to sequentially read characters from a buffered file.


Syntax
filebuf_getc(filebuf b);


Returns
An integer containing the character retrieved, or the constant IO_EOF or IO_ERROR upon an end of file or error.


Parameters
filebuf b is the name of the file buffer.


See also
filebuf_close, filebuf_buf2sd, filebuf_open, filebuf_open_nostat


filebuf_open

The filebuf_open function opens a new file buffer for a previously opened file. It returns a new buffer structure. Buffered files provide more efficient file access by guaranteeing the use of buffered file I/O in environments where it is not supported by the operating system.


Syntax
filebuf *filebuf_open(SYS_FILE fd, int sz);


Returns
A pointer to a new buffer structure to hold the data, if successful or NULL if no buffer could be opened.


Parameters
SYS_FILE fd is the platform-independent file descriptor of the file which has already been opened.

int sz is the size, in bytes, to be used for the buffer.


Example
filebuf *buf = filebuf_open(fd, FILE_BUFFERSIZE);
if (!buf) {
   system_fclose(fd);
}


See also
filebuf_getc, filebuf_buf2sd, filebuf_close, filebuf_open_nostat


filebuf_open_nostat

The filebuf_open_nostat function opens a new file buffer for a previously opened file. It returns a new buffer structure. Buffered files provide more efficient file access by guaranteeing the use of buffered file I/O in environments where it is not supported by the operating system.

This function is the same filebuf_open, but is more efficient, since it does not need to call the request_stat_path function. It requires that the stat information be passed in.


Syntax
filebuf* filebuf_open_nostat(SYS_FILE fd, int sz,
   struct stat *finfo);


Returns
A pointer to a new buffer structure to hold the data, if successful or NULL if no buffer could be opened.


Parameters
SYS_FILE fd is the platform-independent file descriptor of the file which has already been opened.

int sz is the size, in bytes, to be used for the buffer.

struct stat *finfo is the file information of the file. Before calling the filebuf_open_nostat function, you must call the request_stat_path function to retrieve the file information.


Example
filebuf *buf = filebuf_open_nostat(fd, FILE_BUFFERSIZE, &finfo);
if (!buf) {
   system_fclose(fd);
}


See also
filebuf_close, filebuf_open, filebuf_getc, filebuf_buf2sd


FREE

The FREE macro is a platform-independent substitute for the C library routine free. It deallocates the space previously allocated by MALLOC, CALLOC, or STRDUP from the request's memory pool.


Syntax
FREE(void *ptr);


Returns
void


Parameters
void *ptr is a (void *) pointer to a block of memory. If the pointer is not one created by MALLOC, CALLOC, or STRDUP, the behavior is undefined.


Example
char *name;
name = (char *) MALLOC(256);
...
FREE(name);


See also
MALLOC, CALLOC, REALLOC, STRDUP, PERM_MALLOC, PERM_FREE, PERM_REALLOC, PERM_STRDUP


func_exec

The func_exec function executes the function named by the fn entry in a specified pblock. If the function name is not found, it logs the error and returns REQ_ABORTED.

You can use this function to execute a built-in server application function (SAF) by identifying it in the pblock.


Syntax
int func_exec(pblock *pb, Session *sn, Request *rq);


Returns
The value returned by the executed function or the constant REQ_ABORTED if no function was executed.


Parameters
pblock pb is the pblock containing the function name (fn) and parameters.

Session *sn is the Session.

Request *rq is the Request.

The Session and Request parameters are the same as the ones passed into your SAF.


See also
log_error


func_find

The func_find function returns a pointer to the function specified by name. If the function does not exist, it returns NULL.


Syntax
FuncPtr func_find(char *name);


Returns
A pointer to the chosen function, suitable for dereferencing or NULL if the function could not be found.


Parameters
char *name is the name of the function.


Example
/* this block of code does the same thing as func_exec */
char *afunc = pblock_findval("afunction", pb);
FuncPtr afnptr = func_find(afunc);
if (afnptr)
   return (afnptr)(pb, sn, rq);


See also
func_exec



L




log_error

The log_error function creates an entry in an error log, recording the date, the severity, and a specified text.


Syntax
int log_error(int degree, char *func, Session *sn, Request *rq, char *fmt, ...);


Returns
0 if the log entry was created or -1 if the log entry was not created.


Parameters
int degree specifies the severity of the error. It must be one of the following constants:

LOG_WARN—warning
LOG_MISCONFIG—a syntax error or permission violation
LOG_SECURITY—an authentication failure or 403 error from a host
LOG_FAILURE—an internal problem
LOG_CATASTROPHE—a non-recoverable server error
LOG_INFORM—an informational message

char *func is the name of the function where the error has occurred.

Session *sn is the Session.

Request *rq is the Request.

The Session and Request parameters are the same as the ones passed into your SAF.

char *fmt specifies the format for the printf function that delivers the message.

... represents a sequence of parameters for the printf function.


Example
log_error(LOG_WARN, "send-file", sn, rq,
   "error opening buffer from %s (%s)"), path,
      system_errmsg(fd));


See also
func_exec



M




MALLOC

The MALLOC macro is a platform-independent substitute for the C library routine malloc. It normally allocates from the request's memory pool. If pooled memory has been disabled in the configuration file (with the pool-init built-in SAF), PERM_MALLOC and MALLOC both obtain their memory from the system heap.


Syntax
void *MALLOC(int size)


Returns
A void pointer to a block of memory.


Parameters
int size is the number of bytes to allocate.


Example
/* Allocate 256 bytes for a name */
char *name;
name = (char *) MALLOC(256);


See also
FREE, CALLOC, REALLOC, STRDUP, PERM_MALLOC, PERM_FREE, PERM_CALLOC, PERM_REALLOC, PERM_STRDUP



N




net_ip2host

The net_ip2host function transforms a textual IP address into a fully-qualified domain name and returns it.



Note This function works only if the DNS directive is enabled in the magnus.conf file. For more information, see Chapter 7 "Syntax and Use of magnus.conf."




Syntax
char *net_ip2host(char *ip, int verify);


Returns
A new string containing the fully-qualified domain name, if the transformation was accomplished or NULL if the transformation was not accomplished.


Parameters
char *ip is the IP (Internet Protocol) address as a character string in dotted-decimal notation: nnn.nnn.nnn.nnn

int verify, if non-zero, specifies that the function should verify the fully-qualified domain name. Though this requires an extra query, you should use it when checking access control.


net_read

The net_read function reads bytes from a specified socket into a specified buffer. The function waits to receive data from the socket until either at least one byte is available in the socket or the specified time has elapsed.


Syntax
int net_read (SYS_NETFD sd, char *buf, int sz, int timeout);


Returns
The number of bytes read, which will not exceed the maximum size, sz. A negative value is returned if an error has occurred, in which case errno is set to the constant ETIMEDOUT if the operation did not complete before timeout seconds elapsed.


Parameters
SYS_NETFD sd is the platform-independent socket descriptor.

char *buf is the buffer to receive the bytes.

int sz is the maximum number of bytes to read.

int timeout is the number of seconds to allow for the read operation before returning. The purpose of timeout is not to return because not enough bytes were read in the given time, but to limit the amount of time devoted to waiting until some data arrives.


See also
net_write


net_write

The net_write function writes a specified number of bytes to a specified socket from a specified buffer. It returns the number of bytes written.


Syntax
int net_write(SYS_NETFD sd, char *buf, int sz);


Returns
The number of bytes written, which may be less than the requested size if an error occurred.


Parameters
SYS_NETFD sd is the platform-independent socket descriptor.

char *buf is the buffer containing the bytes.

int sz is the number of bytes to write.


Example
if (net_write(sn->csd, FIRSTMSG, strlen(FIRSTMSG)) == IO_ERROR)
   return REQ_EXIT;


See also
net_read


netbuf_buf2sd

The netbuf_buf2sd function sends a buffer to a socket. You can use this function to send data from IPC pipes to the client.


Syntax
int netbuf_buf2sd(netbuf *buf, SYS_NETFD sd, int len);


Returns
The number of bytes transferred to the socket, if successful or the constant IO_ERROR if unsuccessful


Parameters
netbuf *buf is the buffer to send.

SYS_NETFD sd is the platform-independent identifier of the socket.

int len is the length of the buffer.


See also
netbuf_close, netbuf_getc, netbuf_grab, netbuf_open


netbuf_close

The netbuf_close function deallocates a network buffer and closes its associated files. Use this function when you need to deallocate the network buffer and close the socket.

You should never close the netbuf parameter in a Session structure.


Syntax
void netbuf_close(netbuf *buf);


Returns
void


Parameters
netbuf *buf is the buffer to close.


See also
netbuf_buf2sd, netbuf_getc, netbuf_grab, netbuf_open


netbuf_getc

The netbuf_getc function retrieves a character from the cursor position of the network buffer specified by b.


Syntax
netbuf_getc(netbuf b);


Returns
The integer representing the character, if one was retrieved or the constant IO_EOF or IO_ERROR, for end of file or error


Parameters
netbuf b is the buffer from which to retrieve one character.


See also
netbuf_buf2sd, netbuf_close, netbuf_grab, netbuf_open


netbuf_grab

The netbuf_grab function reads sz number of bytes from the network buffer's (buf) socket into the network buffer. If the buffer is not large enough it is resized. The data can be retrieved from buf->inbuf on success.

This function is used by the function netbuf_buf2sd.


Syntax
int netbuf_grab(netbuf *buf, int sz);


Returns
The number of bytes actually read (between 1 and sz), if the operation was successful or the constant IO_EOF or IO_ERROR, for end of file or error


Parameters
netbuf *buf is the buffer to read into.

int sz is the number of bytes to read.


See also
netbuf_buf2sd, netbuf_close, netbuf_getc, netbuf_open


netbuf_open

The netbuf_open function opens a new network buffer and returns it. You can use netbuf_open to create a netbuf structure and start using buffered I/O on a socket.


Syntax
netbuf* netbuf_open(SYS_NETFD sd, int sz);


Returns
A pointer to a new netbuf structure (network buffer)


Parameters
SYS_NETFD sd is the platform-independent identifier of the socket.

int sz is the number of characters to allocate for the network buffer.


See also
netbuf_buf2sd, netbuf_close, netbuf_getc, netbuf_grab



P




param_create

The param_create function creates a pb_param structure containing a specified name and value. The name and value are copied. Use this function to prepare a pb_param structure to be used in calls to pblock routines such as pblock_pinsert.


Syntax
pb_param *param_create(char *name, char *value);


Returns
A pointer to a new pb_param structure.


Parameters
char *name is the string containing the name.

char *value is the string containing the value.


Example
pb_param *newpp = param_create("content-type","text/plain");
pblock_pinsert(newpp, rq->srvhdrs);


See also
param_free, pblock_pinsert, pblock_remove


param_free

The param_free function frees the pb_param structure specified by pp and its associated structures. Use the param_free function to dispose a pb_param after removing it from a pblock with pblock_remove.


Syntax
int param_free(pb_param *pp);


Returns
1 if the parameter was freed or 0 if the parameter was NULL.


Parameters
pb_param *pp is the name-value pair stored in a pblock.


Example
if (param_free(pblock_remove("content-type", rq-srvhdrs)))
   return; /* we removed it */


See also
param_create, pblock_pinsert, pblock_remove


pblock_copy

The pblock_copy function copies the entries of the source pblock and adds them into the destination pblock. Any previous entries in the destination pblock are left intact.


Syntax
void pblock_copy(pblock *src, pblock *dst);


Returns
void


Parameters
pblock *src is the source pblock.

pblock *dst is the destination pblock.

Names and values are newly allocated so that the original pblock may be freed, or the new pblock changed without affecting the original pblock.


See also
pblock_create, pblock_dup, pblock_free, pblock_find, pblock_findval, pblock_remove, pblock_nvinsert


pblock_create

The pblock_create function creates a new pblock. The pblock maintains an internal hash table for fast name-value pair lookups.


Syntax
pblock *pblock_create(int n);


Returns
A pointer to a newly allocated pblock.


Parameters
int n is the size of the hash table (number of name-value pairs) for the pblock.


See also
pblock_copy, pblock_dup, pblock_find, pblock_findval, pblock_free, pblock_nvinsert, pblock_remove


pblock_dup

The pblock_dup function duplicates a pblock. It is equivalent to a sequence of pblock_create and pblock_copy.


Syntax
pblock *pblock_dup(pblock *src);


Returns
A pointer to a newly allocated pblock.


Parameters
pblock *src is the source pblock.


See also
pblock_create, pblock_find, pblock_findval, pblock_free, pblock_find, pblock_remove, pblock_nvinsert


pblock_find

The pblock_find function finds a specified name-value pair entry in a pblock, and returns the pb_param structure. If you only want the value associated with the name, use the pblock_findval function.

This function is implemented as a macro.


Syntax
pb_param *pblock_find(char *name, pblock *pb);


Returns
A pointer to the pb_param structure, if one was found or NULL if name was not found.


Parameters
char *name is the name of a name-value pair.

pblock *pb is the pblock to be searched.


See also
pblock_copy, pblock_dup, pblock_findval, pblock_free, pblock_nvinsert, pblock_remove


pblock_findval

The pblock_findval function finds the value of a specified name in a pblock. If you just want the pb_param structure of the pblock, use the pblock_find function.

The pointer returned is a pointer into the pblock. Do not FREE it. If you want to modify it, do a STRDUP and modify the copy.


Syntax
char *pblock_findval(char *name, pblock *pb);


Returns
A string containing the value associated with the name or NULL if no match was found


Parameters
char *name is the name of a name-value pair.

pblock *pb is the pblock to be searched.


Example
see pblock_nvinsert.


See also
pblock_create, pblock_copy, pblock_find, pblock_free, pblock_nvinsert, pblock_remove, request_header


pblock_free

The pblock_free function frees a specified pblock and any entries inside it. If you want to save a variable in the pblock, remove the variable using the function pblock_remove and save the resulting pointer.


Syntax
void pblock_free(pblock *pb);


Returns
void


Parameters
pblock *pb is the pblock to be freed.


See also
pblock_copy, pblock_create, pblock_dup, pblock_find, pblock_findval, pblock_nvinsert, pblock_remove


pblock_nninsert

The pblock_nninsert function creates a new entry with a given name and a numeric value in the specified pblock. The numeric value is first converted into a string. The name and value parameters are copied.


Syntax
pb_param *pblock_nninsert(char *name, int value, pblock *pb);


Returns
A pointer to the new pb_param structure.


Parameters
char *name is the name of the new entry.

int value is the numeric value being inserted into the pblock. This parameter must be an integer. If the value you assign is not a number, then instead use the function pblock_nvinsert to create the parameter.

pblock *pb is the pblock into which the insertion occurs.


See also
pblock_copy, pblock_create, pblock_find, pblock_free, pblock_nvinsert, pblock_remove, pblock_str2pblock


pblock_nvinsert

The pblock_nvinsert function creates a new entry with a given name and character value in the specified pblock. The name and value parameters are copied.


Syntax
pb_param *pblock_nvinsert(char *name, char *value, pblock *pb);


Returns
A pointer to the newly allocated pb_param structure


Parameters
char *name is the name of the new entry.

char *value is the string value of the new entry.

pblock *pb is the pblock into which the insertion occurs.


Example
pblock_nvinsert("content-type", "text/html", rq->srvhdrs);


See also
pblock_copy, pblock_create, pblock_find, pblock_free, pblock_nninsert, pblock_remove, pblock_str2pblock


pblock_pb2env

The pblock_pb2env function copies a specified pblock into a specified environment. The function creates one new environment entry for each name-value pair in the pblock. Use this function to send pblock entries to a program that you are going to execute.


Syntax
char **pblock_pb2env(pblock *pb, char **env);


Returns
A pointer to the environment.


Parameters
pblock *pb is the pblock to be copied.

char **env is the environment into which the pblock is to be copied.


See also
pblock_copy, pblock_create, pblock_find, pblock_free, pblock_nvinsert, pblock_remove, pblock_str2pblock


pblock_pblock2str

The pblock_pblock2str function copies all parameters of a specified pblock into a specified string. The function allocates additional non-heap space for the string if needed.

Use this function to stream the pblock for archival and other purposes.


Syntax
char *pblock_pblock2str(pblock *pb, char *str);


Returns
The new version of the str parameter. If str is NULL, this is a new string; otherwise it is a reallocated string. In either case, it is allocated from the request's memory pool.


Parameters
pblock *pb is the pblock to be copied.

char *str is the string into which the pblock is to be copied. It must have been allocated by MALLOC or REALLOC, not by PERM_MALLOC or PERM_REALLOC (which allocate from the system heap).

Each name-value pair in the string is separated from its neighbor pair by a space and is in the format name="value".


See also
pblock_copy, pblock_create, pblock_find, pblock_free, pblock_nvinsert, pblock_remove, pblock_str2pblock


pblock_pinsert

The function pblock_pinsert inserts a pb_param structure into a pblock.


Syntax
void pblock_pinsert(pb_param *pp, pblock *pb);


Returns
void


Parameters
pb_param *pp is the pb_param structure to insert.

pblock *pb is the pblock.


See also
pblock_copy, pblock_create, pblock_find, pblock_free, pblock_nvinsert, pblock_remove, pblock_str2pblock


pblock_remove

The pblock_remove function removes a specified name-value entry from a specified pblock. If you use this function you should eventually call param_free in order to deallocate the memory used by the pb_param structure.


Syntax
pb_param *pblock_remove(char *name, pblock *pb);


Returns
A pointer to the named pb_param structure, if it was found or NULL if the named pb_param was not found.


Parameters
char *name is the name of the pb_param to be removed.

pblock *pb is the pblock from which the name-value entry is to be removed.


See also
pblock_copy, pblock_create, pblock_find, pblock_free, pblock_nvinsert, param_create, param_free


pblock_str2pblock

The pblock_str2pblock function scans a string for parameter pairs, adds them to a pblock, and returns the number of parameters added.


Syntax
int pblock_str2pblock(char *str, pblock *pb);


Returns
The number of parameter pairs added to the pblock, if any or -1 if an error occurred


Parameters
char *str is the string to be scanned.

The name-value pairs in the string can have the format name=value or name="value".

All back slashes (\) must be followed by a literal character. If string values are found with no unescaped = signs (no name=), it assumes the names 1, 2, 3, and so on, depending on the string position. For example, if pblock_str2pblock finds "some strings together", the function treats the strings as if they appeared in name-value pairs as 1="some" 2="strings" 3="together".

pblock *pb is the pblock into which the name-value pairs are stored.


See also
pblock_copy, pblock_create, pblock_find, pblock_free, pblock_nvinsert, pblock_remove, pblock_pblock2str


PERM_CALLOC

The PERM_CALLOC macro is a platform-independent substitute for the C library routine calloc. It allocates num*size bytes of memory that persists after the request that is being processed has been completed. If pooled memory has been disabled in the configuration file (with the pool-init built-in SAF), PERM_CALLOC and CALLOC both obtain their memory from the system heap.


Syntax
void *PERM_CALLOC(int num, int size)


Returns
A void pointer to a block of memory


Parameters
int num is the number of elements to allocate.

int size is the size in bytes of each element.


Example
/* Allocate 256 bytes for a name */
char **name;
name = (char **) PERM_CALLOC(100, sizeof(char *));


See also
PERM_FREE, PERM_STRDUP, PERM_MALLOC, PERM_REALLOC, MALLOC, FREE, CALLOC, STRDUP, REALLOC


PERM_FREE

The PERM_FREE macro is a platform-independent substitute for the C library routine free. It deallocates the persistent space previously allocated by PERM_MALLOC, PERM_CALLOC, or PERM_STRDUP. If pooled memory has been disabled in the configuration file (with the pool-init built-in SAF), PERM_FREE and FREE both deallocate memory in the system heap.


Syntax
PERM_FREE(void *ptr);


Returns
void


Parameters
void *ptr is a (void *) pointer to block of memory. If the pointer is not one created by PERM_MALLOC, PERM_CALLOC, or PERM_STRDUP, the behavior is undefined.


Example
char *name;
name = (char *) PERM_MALLOC(256);
...
PERM_FREE(name);


See also
FREE, MALLOC, CALLOC, REALLOC, STRDUP, PERM_MALLOC, PERM_CALLOC, PERM_REALLOC, PERM_STRDUP


PERM_MALLOC

The PERM_MALLOC macro is a platform-independent substitute for the C library routine malloc. It provides allocation of memory that persists after the request that is being processed has been completed. If pooled memory has been disabled in the configuration file (with the pool-init built-in SAF), PERM_MALLOC and MALLOC both obtain their memory from the system heap.


Syntax
void *PERM_MALLOC(int size)


Returns
A void pointer to a block of memory


Parameters
int size is the number of bytes to allocate.


Example
/* Allocate 256 bytes for a name */
char *name;
name = (char *) PERM_MALLOC(256);


See also
PERM_FREE, PERM_STRDUP, PERM_CALLOC, PERM_REALLOC, MALLOC, FREE, CALLOC, STRDUP, REALLOC


PERM_REALLOC

The PERM_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.


Warning
Calling PERM_REALLOC for a block that was allocated with MALLOC, CALLOC, or STRDUP will not work.


Syntax
void *PERM_REALLOC(vod *ptr, int size)


Returns
A void pointer to a block of memory


Parameters
void *ptr a void pointer to a block of memory created by PERM_MALLOC, PERM_CALLOC, or PERM_STRDUP.

int size is the number of bytes to which the memory block should be resized.


Example
char *name;
name = (char *) PERM_MALLOC(256);
if (NotBigEnough())
   name = (char *) PERM_REALLOC(512);


See also
PERM_MALLOC, PERM_FREE, PERM_CALLOC, PERM_STRDUP, MALLOC, FREE, STRDUP, CALLOC, REALLOC


PERM_STRDUP

The PERM_STRDUP macro is a platform-independent substitute for the C library routine strdup. It creates a new copy of a string in memory that persists after the request that is being processed has been completed. If pooled memory has been disabled in the configuration file (with the pool-init built-in SAF), PERM_STRDUP and STRDUP both obtain their memory from the system heap.

The PERM_STRDUP routine is functionally equivalent to


newstr = (char *) PERM_MALLOC(strlen(str) + 1);
strcpy(newstr, str);


A string created with PERM_STRDUP should be disposed with PERM_FREE.


Syntax
char *PERM_STRDUP(char *ptr);


Returns
A pointer to the new string


Parameters
char *ptr is a pointer to a string.


See also
PERM_MALLOC, PERM_FREE, PERM_CALLOC, PERM_REALLOC, MALLOC, FREE, STRDUP, CALLOC, REALLOC


prepare_nsapi_thread

The prepare_nsapi_thread function allows threads that are not created by the server to act like server-created threads. This function must be called before any NSAPI functions are called from a thread that is not server-created.


Syntax
void prepare_nsapi_thread(Request *rq, Session *sn);


Returns
void


Parameters
Request *rq is the Request.

Session *sn is the Session.

The Request and Session parameters are the same as the ones passed into your SAF.


See also
protocol_start_response


protocol_dump822

The protocol_dump822 function prints headers from a specified pblock into a specific buffer, with a specified size and position. Use this function to serialize the headers so that they can be sent, for example, in a mail message.


Syntax
char *protocol_dump822(pblock *pb, char *t, int *pos, int tsz);


Returns
A pointer to the buffer, which will be reallocated if necessary.

The function also modifies *pos to the end of the headers in the buffer.


Parameters
pblock *pb is the pblock structure.

char *t is the buffer, allocated with MALLOC, CALLOC, or STRDUP.

int *pos is the position within the buffer at which the headers are to be dumped.

int tsz is the size of the buffer.


See also
protocol_start_response, protocol_status


protocol_set_finfo

The protocol_set_finfo function retrieves the content-length and last-modified date from a specified stat structure and adds them to the response headers (rq->srvhdrs). Call protocol_set_finfo before calling protocol_start_response.


Syntax
int protocol_set_finfo(Session *sn, Request *rq, struct stat *finfo);


Returns
The constant REQ_PROCEED if the request can proceed normally or the constant REQ_ABORTED if the function should treat the request normally, but not send any output to the client


Parameters
Session *sn is the Session.

Request *rq is the Request.

The Session and Request parameters are the same as the ones passed into your SAF.

stat *finfo is the stat structure for the file.

The stat structure contains the information about the file from the file system. You can get the stat structure info using request_stat_path.


See also
protocol_start_response, protocol_status


protocol_start_response

The protocol_start_response function initiates the HTTP response for a specified session and request. If the protocol version is HTTP/0.9, the function does nothing, because that version has no concept of status. If the protocol version is HTTP/1.0, the function sends a status line followed by the response headers. Use this function to set up HTTP and prepare the client and server to receive the body (or data) of the response.


Syntax
int protocol_start_response(Session *sn, Request *rq);


Returns
The constant REQ_PROCEED if the operation succeeded, in which case you should send the data you were preparing to send.

The constant REQ_NOACTION if the operation succeeded, but the request method was HEAD in which case no data should be sent to the client.

The constant REQ_ABORTED if the operation did not succeed.


Parameters
Session *sn is the Session.

Request *rq is the Request.

The Session and Request parameters are the same as the ones passed into your SAF.


Example
/* A noaction response from this function means the request was HEAD */
if (protocol_start_response(sn, rq) == REQ_NOACTION) {
   filebuf_close(groupbuf); /* close our file*/
   return REQ_PROCEED;
}


See also
protocol_status


protocol_status

The protocol_status function sets the session status to indicate whether an error condition occurred. If the reason string is NULL, the server attempts to find a reason string for the given status code. If it finds none, it returns "Unknown reason." The reason string is sent to the client in the HTTP response line. Use this function to set the status of the response before calling the function protocol_start_response.

For the complete list of valid status code constants, please refer to the file "nsapi.h" in the server distribution


Syntax
void protocol_status(Session *sn, Request *rq, int n, char *r);


Returns
void, but it sets values in the Session/Request designated by sn/rq for the status code and the reason string


Parameters
Session *sn is the Session.

Request *rq is the Request.

The Session and Request parameters are the same as the ones passed into your SAF.

int n is one of the status code constants above.

char *r is the reason string.


Example
/* if we find extra path-info, the URL was bad so tell the */
/* browser it was not found */
if (t = pblock_findval("path-info", rq->vars)) {
    protocol_status(sn, rq, PROTOCOL_NOT_FOUND, NULL);
    log_error(LOG_WARN, "function-name", sn, rq, "%s not found",
      path);
    return REQ_ABORTED;
}


See also
protocol_start_response


protocol_uri2url

The protocol_uri2url function takes strings containing the given URI prefix and URI suffix, and creates a newly-allocated fully qualified URL in the form http://(server):(port)(prefix)(suffix). See protocol_uri2url_dynamic.

If you want to omit either the URI prefix or suffix, use "" instead of NULL as the value for either parameter.


Syntax
char *protocol_uri2url(char *prefix, char *suffix);


Returns
A new string containing the URL


Parameters
char *prefix is the prefix.

char *suffix is the suffix.


See also
protocol_start_response, protocol_status, pblock_nvinsert, protocol_uri2url_dynamic


protocol_uri2url_dynamic

The protocol_uri2url function takes strings containing the given URI prefix and URI suffix, and creates a newly-allocated fully qualified URL in the form http://(server):(port)(prefix)(suffix).

If you want to omit either the URI prefix or suffix, use "" instead of NULL as the value for either parameter.

The protocol_uri2url_dynamic function is similar to the protocol_uri2url function but should be used whenever the Session and Request structures are available. This ensures that the URL that it constructs refers to the host that the client specified.


Syntax
char *protocol_uri2url(char *prefix, char *suffix, Session *sn, Request *rq);


Returns
A new string containing the URL


Parameters
char *prefix is the prefix.

char *suffix is the suffix.

Session *sn is the Session.

Request *rq is the Request.

The Session and Request parameters are the same as the ones passed into your SAF.


See also
protocol_start_response, protocol_status, protocol_uri2url



R




REALLOC

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.


Warning
Calling REALLOC for a block that was allocated with PERM_MALLOC, PERM_CALLOC, or PERM_STRDUP will not work.


Syntax
void *REALLOC(void *ptr, int size);


Returns
A pointer to the new space if the request could be satisfied.


Parameters
void *ptr is a (void *) pointer to a block of memory. If the pointer is not one created by MALLOC, CALLOC, or STRDUP, the behavior is undefined.

int size is the number of bytes to allocate.


Example
char *name;
name = (char *) MALLOC(256);
if (NotBigEnough())
   name = (char *) REALLOC(512);


See also
MALLOC, FREE, STRDUP, CALLOC, PERM_MALLOC, PERM_FREE, PERM_REALLOC, PERM_CALLOC, PERM_STRDUP


request_get_vs

The request_get_vs function finds the VirtualServer* to which a request is directed.

The returned VirtualServer* is valid only for the current request. To retrieve a virtual server ID that is valid across requests, use vs_get_id.


Syntax
const VirtualServer* request_get_vs(Request* rq);


Returns
The VirtualServer* to which the request is directed.


Parameters
Request *rq is the request for which the VirtualServer* is returned.


See also
vs_get_id


request_header

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 since the server may begin processing the request before the headers have been completely read.


Syntax
int request_header(char *name, char **value, Session *sn, Request *rq);


Returns
A result code, REQ_PROCEED if the header was found, REQ_ABORTED if the header was not found, REQ_EXIT if there was an error reading from the client.


Parameters
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 a NULL.

Session *sn is the Session.

Request *rq is the Request.

The Session and Request parameters are the same as the ones passed into your SAF.


See also
request_create, request_free


request_stat_path

The request_stat_path function returns the file information structure for a specified path or, if none is specified, the path entry in the vars pblock in the specified Request structure. If the resulting file name points to a file that the server can read, request_stat_path returns a new file information structure. This structure contains information on the size of the file, its owner, when it was created, and when it was last modified.

You should use request_stat_path to retrieve information on the file you are currently accessing (instead of calling stat directly), because this function keeps track of previous calls for the same path and returns its cached information.


Syntax
struct stat *request_stat_path(char *path, Request *rq);


Returns
Returns a pointer to the file information structure for the file named by the path parameter. Do not free this structure. Returns NULL if the file is not valid or the server cannot read it. In this case, it also leaves an error message describing the problem in rq->staterr.


Parameters
char *path is the string containing the name of the path. If the value of path is NULL, the function uses the path entry in the vars pblock in the Request structure denoted by rq.

Request *rq is the request identifier for a server application function call.


Example
fi = request_stat_path(path, rq);


See also
request_create, request_free, request_header


request_translate_uri

The request_translate_uri function performs virtual to physical mapping on a specified URI during a specified session. Use this function when you want to determine which file would be sent back if a given URI is accessed.


Syntax
char *request_translate_uri(char *uri, Session *sn);


Returns
A path string, if it performed the mapping or NULL if it could not perform the mapping


Parameters
char *uri is the name of the URI.

Session *sn is the Session parameter that is passed into your SAF.


See also
request_create, request_free, request_header



S




session_dns

The session_dns function resolves the IP address of the client associated with a specified session into its DNS name. It returns a newly allocated string. You can use session_dns to change the numeric IP address into something more readable.

The session_maxdns function verifies that the client is who it claims to be; the session_dns function does not perform this verification.



Note This function works only if the DNS directive is enabled in the magnus.conf file. For more information, see Chapter 7 "Syntax and Use of magnus.conf."




Syntax
char *session_dns(Session *sn);


Returns
A string containing the host name or NULL if the DNS name cannot be found for the IP address


Parameters
Session *sn is the Session.

The Session is the same as the one passed to your SAF.


session_maxdns

The session_maxdns function resolves the IP address of the client associated with a specified session into its DNS name. It returns a newly allocated string. You can use session_maxdns to change the numeric IP address into something more readable.



Note This function works only if the DNS directive is enabled in the magnus.conf file. For more information, see Chapter 7 "Syntax and Use of magnus.conf."




Syntax
char *session_maxdns(Session *sn);


Returns
A string containing the host name or NULL if the DNS name cannot be found for the IP address


Parameters
Session *sn is the Session.

The Session is the same as the one passed to your SAF.


shexp_casecmp

The shexp_casecmp function validates a specified shell expression and compares it with a specified string. It returns one of three possible values representing match, no match, and invalid comparison. The comparison (in contrast to that of the shexp_cmp function) is not case-sensitive.

Use this function if you have a shell expression like *.netscape.com and you want to make sure that a string matches it, such as foo.netscape.com.


Syntax
int shexp_casecmp(char *str, char *exp);


Returns
0 if a match was found.

1 if no match was found.

-1 if the comparison resulted in an invalid expression.


Parameters
char *str is the string to be compared.

char *exp is the shell expression (wildcard pattern) to compare against.


See also
shexp_cmp, shexp_match, shexp_valid


shexp_cmp

The shexp_casecmp function validates a specified shell expression and compares it with a specified string. It returns one of three possible values representing match, no match, and invalid comparison. The comparison (in contrast to that of the shexp_casecmp function) is case-sensitive.

Use this function if you have a shell expression like *.netscape.com and you want to make sure that a string matches it, such as foo.netscape.com.


Syntax
int shexp_cmp(char *str, char *exp);


Returns
0 if a match was found.

1 if no match was found.

-1 if the comparison resulted in an invalid expression.


Parameters
char *str is the string to be compared.

char *exp is the shell expression (wildcard pattern) to compare against.


Example
/* Use wildcard match to see if this path is one we want */
char *path;
char *match = "/usr/netscape/*";
if (shexp_cmp(path, match) != 0)
   return REQ_NOACTION; /* no match */


See also
shexp_casecmp, shexp_match, shexp_valid


shexp_match

The shexp_match function compares a specified pre-validated shell expression against a specified string. It returns one of three possible values representing match, no match, and invalid comparison. The comparison (in contrast to that of the shexp_casecmp function) is case-sensitive.

The shexp_match function doesn't perform validation of the shell expression; instead the function assumes that you have already called shexp_valid.

Use this function if you have a shell expression like *.netscape.com and you want to make sure that a string matches it, such as foo.netscape.com.


Syntax
int shexp_match(char *str, char *exp);


Returns
0 if a match was found.

1 if no match was found.

-1 if the comparison resulted in an invalid expression.


Parameters
char *str is the string to be compared.

char *exp is the pre-validated shell expression (wildcard pattern) to compare against.


See also
shexp_casecmp, shexp_cmp, shexp_valid


shexp_valid

The shexp_valid function validates a specified shell expression named by exp. Use this function to validate a shell expression before using the function shexp_match to compare the expression with a string.


Syntax
int shexp_valid(char *exp);


Returns
The constant NON_SXP if exp is a standard string.

The constant INVALID_SXP if exp is a shell expression, but invalid.

The constant VALID_SXP if exp is a valid shell expression.


Parameters
char *exp is the shell expression (wildcard pattern) to be validated.


See also
shexp_casecmp, shexp_match, shexp_cmp


STRDUP

The STRDUP macro is a platform-independent substitute for the C library routine strdup. It creates a new copy of a string in the request's memory pool.

The STRDUP routine is functionally equivalent to:


newstr = (char *) MALLOC(strlen(str) + 1);
strcpy(newstr, str);

A string created with STRDUP should be disposed with FREE.


Syntax
char *STRDUP(char *ptr);


Returns
A pointer to the new string.


Parameters
char *ptr is a pointer to a string.


Example
char *name1 = "MyName";
char *name2 = STRDUP(name1);


See also
MALLOC, FREE, CALLOC, REALLOC, PERM_MALLOC, PERM_FREE, PERM_CALOC, PERM_REALLOC, PERM_STRDUP


system_errmsg

The system_errmsg function returns the last error that occurred from the most recent system call. This function is implemented as a macro that returns an entry from the global array sys_errlist. Use this macro to help with I/O error diagnostics.


Syntax
char *system_errmsg(int param1);


Returns
A string containing the text of the latest error message that resulted from a system call. Do not FREE this string.


Parameters
int param1 is reserved, and should always have the value 0.


See also
system_fopenRO, system_fopenRW, system_fopenWA, system_lseek, system_fread, system_fwrite, system_fwrite_atomic, system_flock, system_ulock, system_fclose


system_fclose

The system_fclose function closes a specified file descriptor. The system_fclose function must be called for every file descriptor opened by any of the system_fopen functions.


Syntax
int system_fclose(SYS_FILE fd);


Returns
0 if the close succeeded or the constant IO_ERROR if the close failed.


Parameters
SYS_FILE fd is the platform-independent file descriptor.


Example
SYS_FILE logfd;
system_fclose(logfd);


See also   
system_errmsg, system_fopenRO, system_fopenRW, system_fopenWA, system_lseek, system_fread, system_fwrite, system_fwrite_atomic, system_flock, system_ulock


system_flock

The system_flock function locks the specified file against interference from other processes. Use system_flock if you do not want other processes using the file you currently have open. Overusing file locking can cause performance degradation and possibly lead to deadlocks.


Syntax
int system_flock(SYS_FILE fd);


Returns
The constant IO_OKAY if the lock succeeded or the constant IO_ERROR if the lock failed


Parameters
SYS_FILE fd is the platform-independent file descriptor.


See also
system_errmsg, system_fopenRO, system_fopenRW, system_fopenWA, system_lseek, system_fread, system_fwrite, system_fwrite_atomic, system_ulock, system_fclose


system_fopenRO

The system_fopenRO function opens the file identified by path in read-only mode and returns a valid file descriptor. Use this function to open files that will not be modified by your program. In addition, you can use system_fopenRO to open a new file buffer structure using filebuf_open.


Syntax
SYS_FILE system_fopenRO(char *path);


Returns
The system-independent file descriptor (SYS_FILE) if the open succeeded or 0 if the open failed


Parameters
char *path is the file name.


See also
system_errmsg, system_fopenRW, system_fopenWA, system_lseek, system_fread, system_fwrite, system_fwrite_atomic, system_flock, system_ulock, system_fclose


system_fopenRW

The system_fopenRW function opens the file identified by path in read-write mode and returns a valid file descriptor. If the file already exists, system_fopenRW does not truncate it. Use this function to open files that will be read from and written to by your program.


Syntax
SYS_FILE system_fopenRW(char *path);


Returns
The system-independent file descriptor (SYS_FILE) if the open succeeded or 0 if the open failed.


Parameters
char *path is the file name.


Example
SYS_FILE fd;
fd = system_fopenRO(pathname);
if (fd == SYS_ERROR_FD)
   break;


See also
system_errmsg, system_fopenRO, system_fopenWA, system_lseek, system_fread, system_fwrite, system_fwrite_atomic, system_flock, system_ulock, system_fclose


system_fopenWA

The system_fopenWA function opens the file identified by path in write-append mode and returns a valid file descriptor. Use this function to open those files that your program will append data to.


Syntax
SYS_FILE system_fopenWA(char *path);


Returns
The system-independent file descriptor (SYS_FILE) if the open succeeded or 0 if the open failed.


Parameters
char *path is the file name.


See also
system_errmsg, system_fopenRO, system_fopenRW, system_lseek, system_fread, system_fwrite, system_fwrite_atomic, system_flock, system_ulock, system_fclose


system_fread

The system_fread function reads a specified number of bytes from a specified file into a specified buffer. It returns the number of bytes read. Before system_fread can be used, you must open the file using any of the system_fopen functions, except system_fopenWA.


Syntax
int system_fread(SYS_FILE fd, char *buf, int sz);


Returns
The number of bytes read, which may be less than the requested size if an error occurred or the end of the file was reached before that number of characters were obtained.


Parameters
SYS_FILE fd is the platform-independent file descriptor.

char *buf is the buffer to receive the bytes.

int sz is the number of bytes to read.


See also
system_errmsg, system_fopenRO, system_fopenRW, system_fopenWA, system_lseek, system_fwrite, system_fwrite_atomic, system_flock, system_ulock, system_fclose


system_fwrite

The system_fwrite function writes a specified number of bytes from a specified buffer into a specified file.

Before system_fwrite can be used, you must open the file using any of the system_fopen functions, except system_fopenRO.


Syntax
int system_fwrite(SYS_FILE fd, char *buf, int sz);


Returns
The constant IO_OKAY if the write succeeded or the constant IO_ERROR if the write failed.


Parameters
SYS_FILE fd is the platform-independent file descriptor.

char *buf is the buffer containing the bytes to be written.

int sz is the number of bytes to write to the file.


See also
system_errmsg, system_fopenRO, system_fopenRW, system_fopenWA, system_lseek, system_fread, system_fwrite_atomic, system_flock, system_ulock, system_fclose


system_fwrite_atomic

The system_fwrite_atomic function writes a specified number of bytes from a specified buffer into a specified file. The function also locks the file prior to performing the write, and then unlocks it when done, thereby avoiding interference between simultaneous write actions. Before system_fwrite_atomic can be used, you must open the file using any of the system_fopen functions, except system_fopenRO.


Syntax
int system_fwrite_atomic(SYS_FILE fd, char *buf, int sz);


Returns
The constant IO_OKAY if the write/lock succeeded or the constant IO_ERROR if the write/lock failed.


Parameters
SYS_FILE fd is the platform-independent file descriptor.

char *buf is the buffer containing the bytes to be written.

int sz is the number of bytes to write to the file.


Example
SYS_FILE logfd;

char *logmsg = "An error occurred.";
system_fwrite_atomic(logfd, logmsg, strlen(logmsg));


See also
system_errmsg, system_fopenRO, system_fopenRW, system_fopenWA, system_lseek, system_fread, system_fwrite, system_flock, system_ulock, system_fclose


system_gmtime

The system_gmtime function is a thread-safe version of the standard gmtime function. It returns the current time adjusted to Greenwich Mean Time.


Syntax
struct tm *system_gmtime(const time_t *tp, const struct tm *res);


Returns
A pointer to a calendar time (tm) structure containing the GMT time. Depending on your system, the pointer may point to the data item represented by the second parameter, or it may point to a statically-allocated item. For portability, do not assume either situation.


Parameters
time_t *tp is an arithmetic time.

tm *res is a pointer to a calendar time (tm) structure.


Example
time_t tp;
struct tm res, *resp;
tp = time(NULL);
resp = system_gmtime(&tp, &res);


See also
system_localtime, util_strftime


system_localtime

The system_localtime function is a thread-safe version of the standard localtime function. It returns the current time in the local time zone.


Syntax
struct tm *system_localtime(const time_t *tp, const struct tm *res);


Returns
A pointer to a calendar time (tm) structure containing the local time. Depending on your system, the pointer may point to the data item represented by the second parameter, or it may point to a statically-allocated item. For portability, do not assume either situation.


Parameters
time_t *tp is an arithmetic time.

tm *res is a pointer to a calendar time (tm) structure.


See also
system_gmtime, util_strftime


system_lseek

The system_lseek function sets the file position of a file. This affects where data from system_fread or system_fwrite is read or written.


Syntax
int system_lseek(SYS_FILE fd, int offset, int whence);


Returns
the offset, in bytes, of the new position from the beginning of the file if the operation succeeded or -1 if the operation failed.


Parameters
SYS_FILE fd is the platform-independent file descriptor.

int offset is a number of bytes relative to whence. It may be negative.

int whence is a one of the following constants:

   SEEK_SET, from the beginning of the file.

   SEEK_CUR, from the current file position.

   SEEK_END, from the end of the file.


See also
system_errmsg, system_fopenRO, system_fopenRW, system_fopenWA, system_fread, system_fwrite, system_fwrite_atomic, system_flock, system_ulock, system_fclose


system_rename

The system_rename function renames a file. It may not work on directories if the old and new directories are on different file systems.


Syntax
int system_rename(char *old, char *new);


Returns
0 if the operation succeeded or -1 if the operation failed.


Parameters
char *old is the old name of the file.

char *new is the new name for the file:


system_ulock

The system_ulock function unlocks the specified file that has been locked by the function system_lock. For more information about locking, see system_flock.


Syntax
int system_ulock(SYS_FILE fd);


Returns
The constant IO_OKAY if the operation succeeded or the constant IO_ERROR if the operation failed


Parameters
SYS_FILE fd is the platform-independent file descriptor.


See also
system_errmsg, system_fopenRO, system_fopenRW, system_fopenWA, system_fread, system_fwrite, system_fwrite_atomic, system_flock, system_fclose


system_unix2local

The system_unix2local function converts a specified Unix-style pathname to a local file system pathname. Use this function when you have a file name in the Unix format (such as one containing forward slashes), and you need to access a file on another system like Windows NT. You can use system_unix2local to convert the Unix file name into the format that Windows NT accepts. In the Unix environment, this function does nothing, but may be called for portability.


Syntax
char *system_unix2local(char *path, char *lp);


Returns
A pointer to the local file system path string


Parameters
char *path is the Unix-style pathname to be converted.

char *lp is the local pathname.

You must allocate the parameter lp, and it must contain enough space to hold the local pathname.


See also
system_fclose, system_flock, system_fopenRO, system_fopenRW, system_fopenWA, system_fwrite


systhread_attach

The systhread_attach function makes an existing thread into a platform-independent thread.


Syntax
SYS_THREAD systhread_attach(void);


Returns
A SYS_THREAD pointer to the platform-independent thread.


Parameters
none.


See also
systhread_current, systhread_getdata, systhread_init, systhread_newkey, systhread_setdata, systhread_sleep, systhread_start, systhread_timerset


systhread_current

The systhread_current function returns a pointer to the current thread.


Syntax
SYS_THREAD systhread_current(void);


Returns
A SYS_THREAD pointer to the current thread


Parameters
none.


See also
systhread_getdata, systhread_newkey, systhread_setdata, systhread_sleep, systhread_start, systhread_timerset


systhread_getdata

The systhread_getdata function gets data that is associated with a specified key in the current thread.


Syntax
void *systhread_getdata(int key);


Returns
A pointer to the data that was earlier used with the systhread_setkey function from the current thread, using the same value of key if the call succeeds. Returns NULL if the call did not succeed, for example if the systhread_setkey function was never called with the specified key during this session


Parameters
int key is the value associated with the stored data by a systhread_setdata function. Keys are assigned by the systhread_newkey function.


See also
systhread_current, systhread_newkey, systhread_setdata, systhread_sleep, systhread_start, systhread_timerset


systhread_newkey

The systhread_newkey function allocates a new integer key (identifier) for thread-private data. Use this key to identify a variable that you want to localize to the current thread; then use the systhread_setdata function to associate a value with the key.


Syntax
int systhread_newkey(void);


Returns
An integer key.


Parameters
none.


See also
systhread_current, systhread_getdata, systhread_setdata, systhread_sleep, systhread_start, systhread_timerset


systhread_setdata

The systhread_setdata function associates data with a specified key number for the current thread. Keys are assigned by the systhread_newkey function.


Syntax
void systhread_setdata(int key, void *data);


Returns
void


Parameters
int key is the priority of the thread.

void *data is the pointer to the string of data to be associated with the value of key.


See also
systhread_current, systhread_getdata, systhread_newkey, systhread_sleep, systhread_start, systhread_timerset


systhread_sleep

The systhread_sleep function puts the calling thread to sleep for a given time.


Syntax
void systhread_sleep(int milliseconds);


Returns
void


Parameters
int milliseconds is the number of milliseconds the thread is to sleep.


See also
systhread_current, systhread_getdata, systhread_newkey, systhread_setdata, systhread_start, systhread_timerset


systhread_start

The systhread_start function creates a thread with the given priority, allocates a stack of a specified number of bytes, and calls a specified function with a specified argument.


Syntax
SYS_THREAD systhread_start(int prio, int stksz,
   void (*fn)(void *), void *arg);


Returns
A new SYS_THREAD pointer if the call succeeded or the constant SYS_THREAD_ERROR if the call did not succeed.


Parameters
int prio is the priority of the thread. Priorities are system-dependent.

int stksz is the stack size in bytes. If stksz is zero, the function allocates a default size.

void (*fn)(void *) is the function to call.

void *arg is the argument for the fn function.


See also
systhread_current, systhread_getdata, systhread_newkey, systhread_setdata, systhread_sleep, systhread_timerset


systhread_timerset

The systhread_timerset function starts or resets the interrupt timer interval for a thread system.

Because most systems don't allow the timer interval to be changed, this should be considered a suggestion, rather than a command.


Syntax
void systhread_timerset(int usec);


Returns
void


Parameters
int usec is the time, in microseconds


See also
systhread_current, systhread_getdata, systhread_newkey, systhread_setdata, systhread_sleep,systhread_start



U




util_can_exec


Unix only
The util_can_exec function checks that a specified file can be executed, returning either a 1 (executable) or a 0. The function checks to see if the file can be executed by the user with the given user and group ID.

Use this function before executing a program using the exec system call.


Syntax
int util_can_exec(struct stat *finfo, uid_t uid, gid_t gid);


Returns
1 if the file is executable or 0 if the file is not executable.


Parameters
stat *finfo is the stat structure associated with a file.

uid_t uid is the Unix user id.

gid_t gid is the Unix group id. Together with uid, this determines the permissions of the Unix user.


See also
util_env_create, util_getline, util_hostname


util_chdir2path

The util_chdir2path function changes the current directory to a specified directory, where you will access a file.

When running under Windows NT, use a critical section to ensure that more than one thread does not call this function at the same time.

Use util_chdir2path when you want to make file access a little quicker, because you do not need to use a full paths.


Syntax
int util_chdir2path(char *path);


Returns
0 if the directory was changed or -1 if the directory could not be changed.


Parameters
char *path is the name of a directory.

The parameter must be a writable string because it isn't permanently modified.


util_chdir2path

The util_chdir2path function changes the current directory to a specified directory, where you will access a file.

When running under Windows NT, use a critical section to ensure that more than one thread does not call this function at the same time.

Use util_chdir2path when you want to make file access a little quicker, because you do not need to use a full paths.


Syntax
int util_chdir2path(char *path);


Returns
0 if the directory was changed or -1 if the directory could not be changed.


Parameters
char *path is the name of a directory.

The parameter must be a writable string because it isn't permanently modified.


util_cookie_find

The util_cookie_find function finds a specific cookie in a cookie string and returns its value.


Syntax
char *util_cookie_find(char *cookie, char *name);


Returns
If successful, returns a pointer to the NULL-terminated value of the cookie. Otherwise, returns NULL. This function modifies the cookie string parameter by null-terminating the name and value.


Parameters
char *cookie is the value of the Cookie: request header.

char *name is the name of the cookie whose value is to be retrieved.


util_env_find

The util_env_find function locates the string denoted by a name in a specified environment and returns the associated value. Use this function to find an entry in an environment.


Syntax
char *util_env_find(char **env, char *name);


Returns
The value of the environment variable if it is found or NULL if the string was not found.


Parameters
char **env is the environment.

char *name is the name of an environment variable in env.


See also
util_env_replace, util_env_str, util_env_free, util_env_create


util_env_free

The util_env_free function frees a specified environment. Use this function to deallocate an environment you created using the function util_env_create.


Syntax
void util_env_free(char **env);


Returns
void


Parameters
char **env is the environment to be freed.


See also
util_env_replace, util_env_str, util_env_find, util_env_create


util_env_replace

The util_env_replace function replaces the occurrence of the variable denoted by a name in a specified environment with a specified value. Use this function to change the value of a setting in an environment.


Syntax
void util_env_replace(char **env, char *name, char *value);


Returns
void


Parameters
char **env is the environment.

char *name is the name of a name-value pair.

char *value is the new value to be stored.


See also
util_env_str, util_env_free, util_env_find, util_env_create


util_env_str

The util_env_str function creates an environment entry and returns it. This function does not check for non alphanumeric symbols in the name (such as the equal sign "="). You can use this function to create a new environment entry.


Syntax
char *util_env_str(char *name, char *value);


Returns
A newly-allocated string containing the name-value pair


Parameters
char *name is the name of a name-value pair.

char *value is the new value to be stored.


See also
util_env_replace, util_env_free, util_env_find, util_env_create


util_getline

The util_getline function scans the specified file buffer to find a line-feed or carriage-return/line-feed terminated string. The string is copied into the specified buffer, and NULL-terminates it. The function returns a value that indicates whether the operation stored a string in the buffer, encountered an error, or reached the end of the file.

Use this function to scan lines out of a text file, such as a configuration file.


Syntax
int util_getline(filebuf *buf, int lineno, int maxlen, char *line);


Returns
0 if successful. line contains the string.

1 if the end of file was reached. line contains the string.

-1 if an error occurred. line contains a description of the error.


Parameters
filebuf *buf is the file buffer to be scanned.

int lineno is used to include the line number in the error message when an error occurs. The caller is responsible for making sure the line number is accurate.

int maxlen is the maximum number of characters that can be written into l.

char *l is the buffer in which to store the string. The user is responsible for allocating and deallocating line.


See also
util_can_exec, util_env_create, util_hostname


util_hostname

The util_hostname function retrieves the local host name and returns it as a string. If the function cannot find a fully-qualified domain name, it returns NULL. You may reallocate or free this string. Use this function to determine the name of the system you are on.


Syntax
char *util_hostname(void);


Returns
If a fully-qualified domain name was found, returns a string containing that name otherwise returns NULL if the fully-qualified domain name was not found.


Parameters
none.


util_is_mozilla

The util_is_mozilla function checks whether a specified user-agent header string is a Netscape browser of at least a specified revision level, returning a 1 if it is and 0 otherwise. It uses strings to specify the revision level to avoid ambiguities like 1.56 > 1.5.


Syntax
int util_is_mozilla(char *ua, char *major, char *minor);


Returns
1 if the user-agent is a Netscape browser or 0 if the user-agent is not a Netscape browser


Parameters
char *ua is the user-agent string from the request headers.

char *major is the major release number (to the left of the decimal point).

char *minor is the minor release number (to the right of the decimal point).


See also
util_is_url, util_later_than


util_is_url

The util_is_url function checks whether a string is a URL, returning 1 if it is and 0 otherwise. The string is a URL if it begins with alphabetic characters followed by a colon.


Syntax
int util_is_url(char *url);


Returns
1 if the string specified by url is a URL or 0 if the string specified by url is not a URL.


Parameters
char *url is the string to be examined.


See also
util_is_mozilla, util_later_than


util_itoa

The util_itoa function converts a specified integer to a string, and returns the length of the string. Use this function to create a textual representation of a number.


Syntax
int util_itoa(int i, char *a);


Returns
The length of the string created


Parameters
int i is the integer to be converted.

char *a is the ASCII string that represents the value. The user is responsible for the allocation and deallocation of a, and it should be at least 32 bytes long.


util_later_than

The util_later_than function compares the date specified in a time structure against a date specified in a string. If the date in the string is later than or equal to the one in the time structure, the function returns 1. Use this function to handle RFC 822, RFC 850, and ctime formats.


Syntax
int util_later_than(struct tm *lms, char *ims);


Returns
1 if the date represented by ims is the same as or later than that represented by the lms or 0 if the date represented by ims is earlier than that represented by the lms.


Parameters
tm *lms is the time structure containing a date.

char *ims is the string containing a date.


See also
util_strftime


util_sh_escape

The util_sh_escape function parses a specified string and places a backslash (\) in front of any shell-special characters, returning the resultant string. Use this function to ensure that strings from clients won't cause a shell to do anything unexpected.

The shell-special characters are the space plus the following characters:

&;`'"|*?~<>^()[]{}$\#!


Syntax
char *util_sh_escape(char *s);


Returns
A newly allocated string


Parameters
char *s is the string to be parsed.


See also
util_uri_escape


util_snprintf

The util_snprintf function formats a specified string, using a specified format, into a specified buffer using the printf-style syntax and performs bounds checking. It returns the number of characters in the formatted buffer.

For more information, see the documentation on the printf function for the run-time library of your compiler.


Syntax
int util_snprintf(char *s, int n, char *fmt, ...);


Returns
The number of characters formatted into the buffer.


Parameters
char *s is the buffer to receive the formatted string.

int n is the maximum number of bytes allowed to be copied.

char *fmt is the format string. The function handles only %d and %s strings; it does not handle any width or precision strings.

... represents a sequence of parameters for the printf function.


See also
util_sprintf, util_vsnprintf, util_vsprintf


util_sprintf

The util_sprintf function formats a specified string, using a specified format, into a specified buffer using the printf-style syntax without bounds checking. It returns the number of characters in the formatted buffer.

Because util_sprintf doesn't perform bounds checking, use this function only if you are certain that the string fits the buffer. Otherwise, use the function util_snprintf. For more information, see the documentation on the printf function for the run-time library of your compiler.


Syntax
int util_sprintf(char *s, char *fmt, ...);


Returns
The number of characters formatted into the buffer.


Parameters
char *s is the buffer to receive the formatted string.

char *fmt is the format string. The function handles only %d and %s strings; it does not handle any width or precision strings.

... represents a sequence of parameters for the printf function.


Example
char *logmsg;
int len;

logmsg = (char *) MALLOC(256);
len = util_sprintf(logmsg, "%s %s %s\n", ip, method, uri);


See also
util_snprintf, util_vsnprintf, util_vsprintf


util_strcasecmp

The util_strcasecmp function performs a comparison of two alpha-numeric strings and returns a -1, 0, or 1 to signal which is larger or that they are identical.

The comparison is not case-sensitive.


Syntax
int util_strcasecmp(const char *s1, const char *s2);


Returns
1 if s1 is greater than s2.

0 if s1 is equal to s2.

-1 if s1 is less than s2.


Parameters
char *s1 is the first string.

char *s2 is the second string.


See also
util_strncasecmp


util_strftime

The util_strftime function translates a tm structure, which is a structure describing a system time, into a textual representation. It is a thread-safe version of the standard strftime function


Syntax
int util_strftime(char *s, const char *format, const struct tm *t);


Returns
The number of characters placed into s, not counting the terminating NULL character.


Parameters
char *s is the string buffer to put the text into. There is no bounds checking, so you must make sure that your buffer is large enough for the text of the date.

const char *format is a format string, a bit like a printf string in that it consists of text with certain %x substrings. You may use the constant HTTP_DATE_FMT to create date strings in the standard internet format. For more information, see the documentation on the printf function for the run-time library of your compiler. Refer to Appendix D "Time Formats" for details on time formats.

const struct tm *t is a pointer to a calendar time (tm) struct, usually created by the function system_localtime or system_gmtime.


See also
system_localtime, system_gmtime


util_strncasecmp

The util_strncasecmp function performs a comparison of the first n characters in the alpha-numeric strings and returns a -1, 0, or 1 to signal which is larger or that they are identical.

The function's comparison is not case-sensitive.


Syntax
int util_strncasecmp(const char *s1, const char *s2, int n);


Returns
1 if s1 is greater than s2.

0 if s1 is equal to s2.

-1 if s1 is less than s2.


Parameters
char *s1 is the first string.

char *s2 is the second string.

int n is the number of initial characters to compare.


See also
util_strcasecmp


util_uri_escape

The util_uri_escape function converts any special characters in the URI into the URI format (%XX where XX is the hexadecimal equivalent of the ASCII character), and returns the escaped string. The special characters are %?#:+&*"<>, space, carriage-return, and line-feed.

Use util_uri_escape before sending a URI back to the client.


Syntax
char *util_uri_escape(char *d, char *s);


Returns
The string (possibly newly allocated) with escaped characters replaced.


Parameters
char *d is a string. If d is not NULL, the function copies the formatted string into d and returns it. If d is NULL, the function allocates a properly-sized string and copies the formatted special characters into the new string, then returns it.

The util_uri_escape function does not check bounds for the parameter d. Therefore, if d is not NULL, it should be at least three times as large as the string s.

char *s is the string containing the original unescaped URI.


See also
util_uri_is_evil, util_uri_parse, util_uri_unescape


util_uri_is_evil

The util_uri_is_evil function checks a specified URI for insecure path characters. Insecure path characters include //, /./, /../ and/., /.. (also for NT./) at the end of the URI. Use this function to see if a URI requested by the client is insecure.


Syntax
int util_uri_is_evil(char *t);


Returns
1 if the URI is insecure or 0 if the URI is OK.


Parameters
char *t is the URI to be checked.


See also
util_uri_escape, util_uri_parse


util_uri_parse

The util_uri_parse function converts //, /./, and /*/../ into / in the specified URI (where * is any character other than /). You can use this function to convert a URI's bad sequences into valid ones. First use the function util_uri_is_evil to determine whether the function has a bad sequence.


Syntax
void util_uri_parse(char *uri);


Returns
void


Parameters
char *uri is the URI to be converted.


See also
util_uri_is_evil, util_uri_unescape


util_uri_unescape

The util_uri_unescape function converts the encoded characters of a URI into their ASCII equivalents. Encoded characters appear as %XX where XX is a hexadecimal equivalent of the character.



Note You cannot use an embedded null in a string, because NSAPI functions assume that a null is the end of the string. Therefore, passing unicode-encoded content through an NSAPI plug-in doesn't work.




Syntax
void util_uri_unescape(char *uri);


Returns
void


Parameters
char *uri is the URI to be converted.


See also
util_uri_escape, util_uri_is_evil, util_uri_parse


util_vsnprintf

The util_vsnprintf function formats a specified string, using a specified format, into a specified buffer using the vprintf-style syntax and performs bounds checking. It returns the number of characters in the formatted buffer.

For more information, see the documentation on the printf function for the run-time library of your compiler.


Syntax
int util_vsnprintf(char *s, int n, register char *fmt, va_list args);


Returns
The number of characters formatted into the buffer


Parameters
char *s is the buffer to receive the formatted string.

int n is the maximum number of bytes allowed to be copied.

register char *fmt is the format string. The function handles only %d and %s strings; it does not handle any width or precision strings.

va_list args is an STD argument variable obtained from a previous call to va_start.


See also
util_sprintf, util_vsprintf


util_vsprintf

The util_vsprintf function formats a specified string, using a specified format, into a specified buffer using the vprintf-style syntax without bounds checking. It returns the number of characters in the formatted buffer.

For more information, see the documentation on the printf function for the run-time library of your compiler.


Syntax
int util_vsprintf(char *s, register char *fmt, va_list args);


Returns
The number of characters formatted into the buffer.


Parameters
char *s is the buffer to receive the formatted string.

register char *fmt is the format string. The function handles only %d and %s strings; it does not handle any width or precision strings.

va_list args is an STD argument variable obtained from a previous call to va_start.


See also
util_snprintf, util_vsnprintf



V




vs_alloc_slot

The vs_alloc_slot function allocates a new slot for storing a pointer to data specific to a certain VirtualServer*. The returned slot number may be used in subsequent vs_set_data and vs_get_data calls. The returned slot number is valid for any VirtualServer*.

The value of the pointer (which may be returned by a call to vs_set_data) defaults to NULL for every VirtualServer*.


Syntax
int vs_alloc_slot(void);


Returns
A slot number on success, or -1 on failure.


See also
vs_get_data, vs_set_data


vs_get_data

The vs_get_data function finds the value of a pointer to data for a given VirtualServer* and slot. The slot must be a slot number returned from vs_alloc_slot or vs_set_data.


Syntax
void* vs_get_data(const VirtualServer* vs, int slot);


Returns
The value of the pointer previously stored via vs_set_data, or NULL on failure.


Parameters
const VirtualServer* vs represents the virtual server to query the pointer for.

int slot is the slot number to retrieve the pointer from.


See also
vs_set_data, vs_alloc_slot


vs_get_default_httpd_object

The vs_get_default_httpd_object function obtains a pointer to the default (or root) httpd_object from the virtual server's httpd_objset (in the configuration defined by the obj.conf file of the virtual server class). The default object is typically named default. Plugins may only modify the httpd_object at VSInitFunc time (see vs_register_cb for an explanation of VSInitFunc time).

Do not FREE the returned object.


Syntax
httpd_object* vs_get_default_httpd_object(VirtualServer* vs);


Returns
A pointer the default httpd_object, or NULL on failure. Do not FREE this object.


Parameters
VirtualServer* vs represents the virtual server for which to find the default object.


See also
vs_get_httpd_objset, vs_register_cb


vs_get_doc_root

The vs_get_doc_root function finds the document root for a virtual server. The returned string is the full operating system path to the document root.

The caller should FREE the returned string when done with it.


Syntax
char* vs_get_doc_root(const VirtualServer* vs);


Returns
A pointer to a string representing the full operating system path to the document root. It is the caller's responsibility to FREE this string.


Parameters
const VirtualServer* vs represents the virtual server for which to find the document root.


vs_get_httpd_objset

The vs_get_httpd_objset function obtains a pointer to the httpd_objset (the configuration defined by the obj.conf file of the virtual server class) for a given virtual server. Plugins may only modify the httpd_objset at VSInitFunc time (see vs_register_cb for an explanation of VSInitFunc time).

Do not FREE the returned objset.


Syntax
httpd_objset* vs_get_httpd_objset(VirtualServer* vs);


Returns
A pointer to the httpd_objset, or NULL on failure. Do not FREE this objset.


Parameters
VirtualServer* vs represents the virtual server for which to find the objset.


See also
vs_get_default_httpd_object, vs_register_cb


vs_get_id

The vs_get_id function finds the ID of a VirtualServer*.

The ID of a virtual server is a unique null-terminated string that remains constant across configurations. Note that while IDs remain constant across configurations, the value of VirtualServer* pointers do not.

Do not FREE the virtual server ID string. If called during request processing, the string will remain valid for the duration of the current request. If called during VSInitFunc processing, the string will remain valid until after the corresponding VSDestroyFunc function has returned (see vs_register_cb).

To retrieve a VirtualServer* that is valid only for the current request, use request_get_vs.


Syntax
const char* vs_get_id(const VirtualServer* vs);


Returns
A pointer to a string representing the virtual server ID. Do not FREE this string.


Parameters
const VirtualServer* vs represents the virtual server of interest.


See also
vs_register_cb, request_get_vs


vs_get_mime_type

The vs_get_mime_type function determines the MIME type that would be returned in the Content-type: header for the given URI.

The caller should FREE the returned string when done with it.


Syntax
char* vs_get_mime_type(const VirtualServer* vs, const char* uri);


Returns
A pointer to a string representing the MIME type. It is the caller's responsibility to FREE this string.


Parameters
const VirtualServer* vs represents the virtual server of interest.

const char* uri is the URI whose MIME type is of interest.


vs_lookup_config_var

The vs_lookup_config_var function finds the value of a configuration variable for a given virtual server.

Do not FREE the returned string.


Syntax
const char* vs_lookup_config_var(const VirtualServer* vs, const char* name);


Returns
A pointer to a string representing the value of variable name on success, or NULL if variable name was not found. Do not FREE this string.


Parameters
const VirtualServer* vs represents the virtual server of interest.

const char* name is the name of the configuration variable.


vs_register_cb

The vs_register_cb function allows a plugin to register functions that will receive notifications of virtual server initialization and destruction events. The vs_register_cb function would typically be called from an Init SAF in magnus.conf.

When a new configuration is loaded, all registered VSInitFunc (virtual server initialization) callbacks are called for each of the virtual servers before any requests are served from the new configuration. VSInitFunc callbacks are called in the same order they were registered; that is, the first callback registered is the first called.

When the last request has been served from an old configuration, all registered VSDestroyFunc (virtual server destruction) callbacks are called for each of the virtual servers before any virtual servers are destroyed. VSDestroyFunc callbacks are called in reverse order; that is, the first callback registered is the last called.

Either initfn or destroyfn may be NULL if the caller is not interested in callbacks for initialization or destruction, respectively.


Syntax
int vs_register_cb(VSInitFunc* initfn, VSDestroyFunc* destroyfn);


Returns
The constant REQ_PROCEED if the operation succeeded.

The constant REQ_ABORTED if the operation failed.


Parameters
VSInitFunc* initfn is a pointer to the function to call at virtual server initialization time, or NULL if the caller is not interested in virtual server initialization events.

VSDestroyFunc* destroyfn is a pointer to the function to call at virtual server destruction time, or NULL if the caller is not interested in virtual server destruction events.


vs_set_data

The vs_set_data function sets the value of a pointer to data for a given virtual server and slot. The *slot must be -1 or a slot number returned from vs_alloc_slot. If *slot is -1, vs_set_data calls vs_alloc_slot implicitly and returns the new slot number in *slot.

Note that the stored pointer is maintained on a per-VirtualServer* basis, not a per-ID basis. Distinct VirtualServer*s from different configurations may exist simultaneously with the same virtual server IDs. However, since these are distinct VirtualServer*s, they each have their own VirtualServer*-specific data. As a result, vs_set_data should generally not be called outside of VSInitFunc processing (see vs_register_cb for an explanation of VSInitFunc processing).


Syntax
void* vs_set_data(const VirtualServer* vs, int* slot, void* data);


Returns
Data on success, NULL on failure.


Parameters
const VirtualServer* vs represents the virtual server to set the pointer for.

int* slot is the slot number to store the pointer at.

void* data is the pointer to store.


See also
vs_get_data, vs_alloc_slot, vs_register_cb


vs_translate_uri

The vs_translate_uri function translates a URI as though it were part of a request for a specific virtual server. The returned string is the full operating system path.

The caller should FREE the returned string when done with it.


Syntax
char* vs_translate_uri(const VirtualServer* vs, const char* uri);


Returns
A pointer to a string representing the full operating system path for the given URI. It is the caller's responsibility to FREE this string.


Parameters
const VirtualServer* vs represents the virtual server for which to translate the URI.

const char* uri is the URI to translate to an operating system path.


Previous     Contents     Index     DocHome     Next     
Copyright © 2001 Sun Microsystems, Inc. Some preexisting portions Copyright © 2001 Netscape Communications Corp. All rights reserved.

Last Updated May 15, 2001