cinfo_find                                                                 base/cinfo.h
The cinfo_find function finds the content information for the Universal Resource Identifier (URI) and returns a pointer to a structure containing the information. Use this function to retrieve information on a URI or a local file name in order to tell the client the type of file it will be receiving from the server.
Syntax
#include </base/cinfo.h>
cinfo *cinfo_find(char *uri);
Returns
\
) in the URI. In addition, multiple file name extensions should be separated by CINFO_SEPARATOR
(currently defined as a period).
#include <base/crit.h> CONDVAR condvar_init(CRITICAL id);
Parameters
CRITICAL id is a critical-section variable.
See also
condvar_notify, condvar_terminate, condvar_wait, crit_init.
condvar_notify                                                                 base/crit.h
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
#include <base/crit.h>
void condvar_notify(CONDVAR cv);
Returns
void
Parameters
CONDVAR cv is a condition variable.
See also
condvar_init, condvar_terminate, condvar_wait, crit_enter, crit_exit, crit_init.
condvar_terminate                                                                 base/crit.h
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
#include <base/crit.h>
void condvar_terminate(CONDVAR cv);
Returns
void
Parameters
CONDVAR cv is a condition variable.
See also
condvar_init, condvar_notify, condvar_wait, crit_init.
condvar_wait                                                                 base/crit.h
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
#include <base/crit.h>
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                                                                 base/crit.h
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
#include <base/crit.h>
void crit_enter(CRITICAL crvar);
Returns
void
Parameters
CRITICAL crvar is a critical-section variable.
See also
crit_exit, crit_init, crit_terminate.
crit_exit                                                                 base/crit.h
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
#include <base/crit.h>
void crit_exit(CRITICAL crvar);
Returns
void
Parameters
CRITICAL crvar is a critical-section variable.
See also
crit_enter, crit_init, crit_terminate.
crit_init                                                                 base/crit.h
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
#include <base/crit.h>
CRITICAL crit_init(void);
Returns
A newly allocated critical-section variable (CRITICAL)
Parameters
No parameter is required.
See also
crit_enter, crit_exit, crit_terminate.
crit_terminate                                                                 base/crit.h
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
#include <base/crit.h>
void crit_terminate(CRITICAL crvar);
Returns
void
Parameters
CRITICAL crvar is a critical-section variable.
See also
crit_enter, crit_exit, crit_init.
daemon_atrestart                                                                 netsite.h
The daemon_atrestart function lets you register a callback function named by fn to be used when the server receives a restart signal. 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.
Syntax
#include <netsite.h>
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
/* Close log file when server is restarted */
daemon_atrestart(brief_terminate, NULL);
return REQPROCEED;
See also
http_start_response.
filebuf_buf2sd                                                                 base/buffer.h
The filebuf_buf2sd function sends a file buffer to a socket and returns the number of bytes sent.
Use this function to send the contents of a file to a server.
Syntax
#include <base/buffer.h>
int filebuf_buf2sd(filebuf *buf, SYS_NETFD sd);
Returns
if(filebuf_buf2sd(buf, sn->csd) == IO_ERROR)
ret = REQ_EXIT;
filebuf_close(buf);
#include <base/buffer.h> void filebuf_close(filebuf *buf);
if(filebuf_buf2sd(buf, sn->csd) == IO_ERROR)
ret = REQ_EXIT;
filebuf_close(buf);
#include <base/buffer.h> netbuf_getc(netbuf b);
#include <base/buffer.h> filebuf *filebuf_open(SYS_FILE fd, int sz);
buf = filebuf_open(fd, &finfo);
if (!buf){
system_fclose(fd);
goto done;
}
#include <base/buffer.h> #include <sys/stat.h> filebuf* filebuf_open_nostat(SYS_FILE fd, int sz, struct stat *finfo);
buf = filebuf_open_nostat(fd, FILE_BUFFERSIZE, &finfo); if (!buf){ system_fclose(fd); goto done; }
#include <netsite.h> FREE(ptr);
void
if(alt) {
pb_param *pp = pblock_find("ppath", rq->vars);
/* Trash the old value */
FREE(pp->value);
/* Dup it because the library will later free this pblock */
pp->value = STRDUP(alt);
return REQ_PROCEED;
}
/* Else do nothing */
return REQ_NOACTION;
LOG_MISCONFIG
message for the missing function parameter.
You can use this function to execute a server application function (SAF) by identifying it in the parameter block.
#include <frame/func.h> int func_exec(pblock *pb, Session *sn, Request *rq);
REQ_ABORTED
if no function was executed
#include <frame/func.h> FuncPtr func_find(char *name);
/* 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);
#include <frame/log.h> int log_error(int degree, char *func, Session *sn, Request *rq, char *fmt, ...);
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
if(!groupbuf) { log_error(LOG_WARN, "send-file", sn, rq, "error opening buffer from %s (%s)"), path, system_errmsg(fd)); return REQ_ABORTED; }
Use the daemon-atrestart function in place of the obsolete magnus_atrestart function.The magnus_atrestart function lets you register a callback function named by fn to be used when the server receives a restart signal. Use this function when you need a callback function to deallocate resources allocated by an initialization function.
#include <netsite.h> void magnus_atrestart(void (*fn)(void *), void *data);
void
/* Close log file when server is restarted */
magnus_atrestart(brief_terminate, NULL);
return REQPROCEED;
#include <netsite.h> MALLOC(size)
/* Initialize hosts array */ num_hosts = 0; hosts = (char **) MALLOC(1 * sizeof(char *)); hosts[0] = NULL;
#include <base/net.h> char *net_ip2host(char *ip, int verify);
#include <base/net.h int net_read (SYS_NETFD sd, char *buf, int sz, int timeout);
#include <base/net.h> SYS_NETFD net_socket (int domain, int type, int protocol);
AF_INET
.
int type must be the constant SOCK_STREAM
.
int protocol must be the constant IPPROTO_TCP
.
#include <base/net.h> int net_write (SYS_NETFD sd, char *buf, int sz);
/* Start response by giving boundary string */ if(net_write(sn->csd, FIRSTMSG, strlen(FIRSTMSG)) == IO_ERROR) return REQ_EXIT;
#include <base/buffer.h> int netbuf_buf2sd(netbuf *buf, SYSNETFD sd, int len);
IO_ERROR
if unsuccessful
#include <base/buffer.h> void netbuf_close(netbuf *buf);
void
#include <base/buffer.h> netbuf_getc(netbuf b);
IO_EOF
or IO_ERROR
, for end of file or error
#include <base/buffer.h> int netbuf_grab(netbuf *buf, int sz);
IO_EOF
or IO_ERROR
, for end of file or error
#include <base/buffer.h> netbuf* netbuf_open(SYS_NETFD sd, int sz);
#include <base/pblock.h> pb_param *param_create(char *name, char *value);
pblock *pb = pblock_create(4); pb_param *newpp = param_create("hello","world"); pblock_pinsert(newpp, pb);
#include <base/pblock.h> int param_free(pb_param *pp);
int check(pblock *pb) { if(param_free(pblock_remove("hello", pb))) return 1; /* signal that we removed it */ else return 0; /* We didn't remove it. */ }
#include <base/pblock.h> void pblock_copy(pblock *src, pblock *dst);
void
#include <base/pblock.h> pblock *pblock_create(int n);
#include <base/pblock.h> pblock *pblock_dup(pblock *src);
#include <base/pblock.h> pb_param *pblock_find(char *name, pblock *pb);
#include <base/pblock.h> char *pblock_findval(char *name, pblock *pb);
#include <base/pblock.h> void pblock_free(pblock *pb);
void
#include <base/pblock.h> pb_param *pblick_nninsert(char *name, int value, pblock *pb);
The pblock_nninsert function requires that the parameter value be an integer. If the value you assign is not a number, then instead use the function pblock_nvinsert to create the parameter.
#include <base/pblock.h> pb_param *pblock_nvinsert(char *name, char *value, pblock *pb);
int brief_init(pblock *pb, Session *sn, Request *rq) { /* find "find" value in the parameter blcock */ char *fn = pblock_findval("file", pb); /* if "file" is not found, insert an "error" value asking to supply a file name*/ if(!fn) { pblock_nvinsert("error", "brief-init: please supply a file name", pb); return REQ_ABORTED; } /* open a file in write/append mode*/ logfd = system_fopenWA(fn); if(logfd == SYS_ERROR_FD) { pblock_nvinsert("error", "brief-init: please supply a file name", pb); return REQ_ABORTED; }
#include <base/pblock.h> char **pblock_pb2env(pblock *pb, char **env);
#include <base/pblock.h> char *pblock_pblock2str(pblock *pb, char *str);
name="value"
.
#include <base/pblock.h> void pblock_pinsert(pb_param *pp, pblock *pb);
void
#include <base/pblock.h> pb_param *pblock_remove(char *name, pblock *pb);
#include <base/pblock.h> int pblock_str2pblock(char *str, pblock *pb);
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 (zero doesn't count). For
example, if pblock_str2pblock finds "some"
"strings"
"together"
,
the function treats the strings as if they appeared in the name-value pairs as
1="some"
2 ="strings" 3="together"
.
#include <netsite.h> PERM_FREE(ptr);
void
#include <netsite.h> PERM_MALLOC(size)
/* Initialize hosts array */ num_hosts = 0; hosts = (char **) PERM_MALLOC(1 * sizeof(char *)); hosts[0] = NULL;
char *newstr = (char *) malloc(strlen(str) + 1);
strcpy(newstr, str);
Syntax
#include <netsite.h>
PERM_STRDUP(ptr);
Returns
A pointer to the new string
Parameters
ptr is a pointer to a string.
See also
MALLOC, FREE, REALLOC
protocol_dump822                                                                 frame/protocol.h
The protocol_dump822 function prints headers from a specified parameter block 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
#include <frame/protocol.h>
char *protocol_dump822(pblock *pb, char *t, int *pos, int tsz);
Returns
A pointer to the buffer, reallocated if necessary
The function also modifies pos to denote a new position in the buffer.
Parameters
pblock *pb is the parameter block structure.
char *t is the name of the buffer.
int *pos is the position within the buffer at which the headers are to be inserted.
int *tsz is the size of the buffer.
See also
protocol_handle_session, protocol_scan_headers, protocol_start_response, protocol_status
protocol_set_finfo                                                                 frame/protocol.h
The protocol_set_finfo function retrieves the content-length and last-modified date from a specified stat structure, for a specified session and the request generated by that session. Use protocol_set_finfo only after receiving a start_response from a Service-class server application function (SAF).
Syntax
#include <frame/protocol.h>
int protocol_set_finfo(Session *sn, Request *rq, struct stat *finfo);
Returns
REQ_PROCEED
if the request can proceed normally
REQ_ABORTED
if the function should treat the request normally, but not send any output to the client
The stat structure contains the information about the file you are sending back to the client. The full description of the stat structure should be available from the documentation for your system. For the basic elements of the stat structure, see "The stat data structure" on page 199.
#include <frame/protocol.h> int protocol_start_response(Session *sn, Request *rq);
REQ_PROCEED
if the operation succeeded, in which case you can send the data you were preparing to send
REQ_NOACTION
if the operation succeeded, but the client has requested that the server not send the data because the client has it in cache
REQ_ABORTED
if the operation did not succeed
/* A noaction response from this function means the request was HEAD */ if(protocol_start_response(sn, rq) == REQ_NOACTION) { filebuf_close(groupbuf); /* this also closes fd */ return REQ_PROCEED; }
"Unknown reason."
This reason string is sent to the client in the status line. Use this function to set the status of the session before calling the function protocol_start_response.
The following is a list of valid status codes:PROTOCOL_OK
PROTOCOL_NO_RESPONSE
PROTOCOL_REDIRECT
PROTOCOL_NOT_MODIFIED
PROTOCOL_BAD_REQUEST
PROTOCOL_UNAUTHORIZED
PROTOCOL_FORBIDDEN
PROTOCOL_NOT_FOUND
PROTOCOL_PROXY_UNAUTHORIZED
PROTOCOL_SERVER_ERROR
PROTOCOL_NOT_IMPLEMENTED
Syntax
#include <frame/protocol.h>
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 that generated the request.
Request *rq is the request that is being checked on.
int n is the value to set the status code to.
char *r is the reason string.
Example
if( (t = pblock_findval("path-info", rq->vars)) ) {
protocol_status(sn, rq, PROTOCOL_NOT_FOUND, NULL);
log_error(LOG_WARN, "send-images", sn, rq,
"%s%s not found", path, t);
return REQ_ABORTED;
}
See also
protocol_handle_session, protocol_scan_headers, protocol_start_response
protocol_uri2url                                                                 frame/protocol.h
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. To redirect the client somewhere else, use the function pblock_nvinsert to create a new entry in the vars pblock in your Request structure.
Syntax
#include <frame/protocol.h>
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_handle_session, protocol_scan_headers, protocol_start_response, protocol_status
protocol_uri2url_dynamic                                                                 frame/protocol.h
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. To redirect the client somewhere else, use the function pblock_nvinsert to create a new entry in the vars in the pblock in your Request structure.
The protocol_uri2url_dynamic function is exactly like 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
#include <frame/protocol.h>
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 that generated the request.
Request *rq is the request that is being processed.
See also
protocol_handle_session, protocol_scan_headers, protocol_start_response, protocol_status
REALLOC                                                                 netsite.h
The REALLOC macro is a platform-independent substitute for the C library routine realloc. It changes the size of a specified object that was originally created by MALLOC or STRDUP. The contents of the object remain unchanged up to the minimum 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 will not
work.
Syntax
#include <netsite.h>
REALLOC(ptr, size);
Returns
A pointer to the new space if the request could be satisfied.
Parameters
ptr is a (void) pointer to an object. If the pointer is not one created by MALLOC or STRDUP, the behavior is undefined.
size (an int) is the number of bytes to allocate.
Example
while(fgets(buf, MAX_ACF_LINE, f)) {
/* Blast linefeed that stdio leaves on there */
uf[strlen(buf) - 1] = '0';
hosts = (char **) REALLOC(hosts, (num_hosts + 2) * sizeof(char *));
hosts[num_hosts++] = STRDUP(buf);
hosts[num_hosts] = NULL;
}
See also
MALLOC, FREE, STRDUP
request_create                                                                 frame/req.h
Utility function that creates a new request structure.
Syntax
#include <frame/req.h>
Request *request_create(void);
Returns
A pointer to a Request structure
Parameters
No parameter is required.
See also
request_free, request_header
request_free                                                                 frame/req.h
The request_free function frees a specified request structure.
Syntax
#include <frame/req.h>
void request_free(Request *req);
Returns
void
Parameters
Request *rq is the request structure to be freed.
See also
request_header
request_header                                                                 frame/req.h
The request_header function finds the parameter block containing the client's HTTP headers. You can use this function to access a parameter block indirectly, thereby avoiding multiple and unnecessary calls. In addition, request_header allows you to access the parameter block headers in your copy of the request structure.
Syntax
#include <frame/req.h>
int request_header(char *name, char **value, Session *sn, Request *rq);
Returns
A REQ return code, such as REQ_ABORTED
to signal that an error occurred or REQ_PROCEED
to signal that all went well
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 identifier for the server application function call that generated the request.
Request *rq is the request identifier for a server application function call.
The sn and rq parameters can also be used to identify a specific request in asynchronous operations, as well as for other internal housekeeping purposes.
path
entry in the vars
pblock in a 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, when it was last accessed, and when it was last changed.
You can 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 other calls.
#include <frame/req.h> struct stat *request_stat_path(char *path, Request *rq);
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.
if( (!(fi = request_stat_path(path, rq)) ) ||
( (fd = system_fopenRO(path)) == IO_ERROR) )
...
#include <frame/req.h> char *request_translate_uri(char *uri, Session *sn);
#include <base/sem.h> int sem_grab(SEMAPHORE id);
#include <base/sem.h> SEMAPHORE sem_init(char *name, int number);
The file name of the semaphore should be a file accessible to the process.
#include <base/sem.h> int sem_release(SEMAPHORE id);
#include <base/sem.h> void sem_terminate(SEMAPHORE id);
void
#include <base/sem.h> int sem_grab(SEMAPHORE id);
#include <base/session.h> Session *session_create(SYS_NETFD csd, struct sockaddr_in *sac);
#include <base/session.h> void session_free(Session *sn);
void
#include <base/session.h> char *session_maxdns(Session *sn);
*.netscape.com
and you want to make sure that a string matches it, such as foo.netscape.com
.
#include <base/shexp.h> int shexp_casecmp(char *str, char *exp);
*.netscape.com
and you want to make sure that a string matches it, such as foo.netscape.com
.
#include <base/shexp.h> int shexp_cmp(char *str, char *exp);
#include "base/util.h" /* is_mozilla */
#include "frame/protocol.h" /* protocol_status */
#include "base/shexp.h" /* shexp_cmp */
int https_redirect(pblock *pb, Session *sn, Request *rq)
{
/* Server Variable */
char *ppath = pblock_findval("ppath", rq->vars);
/* Parameters */
char *from = pblock_findval("from", pb);
char *url = pblock_findval("url", pb);
char *alt = pblock_ /* Work vars */
/* Check usage */
if((!from) || (!url)) {
log_error(LOG_MISCONFIG, "https-redirect", sn, rq,
"missing parameter (need from, url)");
return REQ_ABORTED;
}
/* Use wildcard match to see if this path is one to redirect */
if(shexp_cmp(ppath, from) != 0)
return REQ_NOACTION; /* no match */
/* The only way to check for SSL capability is to check UA */
if(request_header("user-agent", &ua, sn, rq) == REQ_ABORTED)
return REQ_ABORTED;
/* The is_mozilla fn checks for Mozilla version 0.96 or greater */
f(util_is_mozilla(ua, "0", "96")) {
/* Set the return code to 302 Redirect */
protocol_status(sn, rq, PROTOCOL_REDIRECT, NULL);
/* The error handling fns use this to set Location: */
pblock_nvinsert("url", url, rq->vars);
return REQ_ABORTED;
}
/* No match. Old client. */
/* If there is an alternate document specified, use it. */
if(alt) {
pb_param *pp = pblock_find("ppath", rq->vars);
/* Trash the old value */
FREE(pp->value);
/* Dup it because the library will later free this pblock */
pp->value = STRDUP(alt);
return REQ_PROCEED;
}
/* Else do nothing */
return REQ_NOACTION;
}
*.netscape.com
and you want to make sure that a string matches it, such as foo.netscape.com
.
#include <base/shexp.h> int shexp_match(char *str, char *exp);
#include <base/shexp.h> int shexp_valid(char *exp);
NON_SXP
if exp is a standard string
INVALID_SXP
if exp is a shell expression, but invalid
VALID_SXP
if exp is a valid shell expression
#include <base/shmem.h> shmem_s *shmem_alloc(char *name, int size, int expose);
#include <base/shmem.h> void *shmem_free(shmem_s *region);
void
char *newstr = (char *) MALLOC(strlen(str) + 1);
strcpy(newstr, str);
Syntax
#include <netsite.h>
STRDUP(ptr);
Returns
A pointer to the new string.
Parameters
ptr is a pointer to a string.
Example
while(fgets(buf, MAX_ACF_LINE, f)) {
/* Blast linefeed that stdio leaves on there */
uf[strlen(buf) - 1] = '0';
hosts = (char **) REALLOC(hosts, (num_hosts + 2) * sizeof(char *));
hosts[num_hosts++] = STRDUP(buf);
hosts[num_hosts] = NULL;
}
See also
MALLOC, FREE, REALLOC
system_errmsg                                                                 base/file.h
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
#include <base/file.h>
char *system_errmsg(int para1);
Returns
A string containing the text of the latest error message that resulted from a system call.
Parameters
int para1 is reserved, and should always have the value 0.
See also
system_fclose, system_fread, system_fopenRO, system_fwrite
system_fclose                                                                 base/file.h
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
#include <base/file.h>
int system_fclose(SYS_FILE fd);
Returns
IO_ERROR
if the close failed
static SYS_FILE logfd = SYS_ERROR_FD;
// this function closes global logfile
void brief_terminate()
{
system_fclose(logfd);
logfd = SYS_ERROR_FD;
}
#include <base/file.h> int system_flock(SYS_FILE fd);
IO_OK
if the lock succeeded
IO_ERROR
if the lock failed
#include <base/file.h> SYS_FILE system_fopenRO(char *path);
#include <base/file.h> SYS_FILE system_fopenRW(char *path);
/* If any errors, just skip it. */ if(stat(pathname, &finfo) == -1) break; fd = system_fopenRO(pathname); if(fd == SYS_ERROR_FD) break;
#include <base/file.h> SYS_FILE system_fopenWA(char *path);
#include <base/file.h> int system_fread(SYS_FILE fd, char *buf, int sz);
#include <base/file.h> int system_fwrite(SYS_FILE fd, char *buf, int sz);
IO_OK
if the write succeeded
IO_ERROR
if the write failed
#include <base/file.h> int system_fwrite_atomic(SYS_FILE fd, char *buf, int sz);
IO_OK
if the write/lock succeeded
IO_ERROR
if the write/lock failed
logmsg = (char *) MALLOC(strlen(ip) + 1 + strlen(method) + 1 + strlen(uri) + 1 + 1); len = util_sprintf(logmsg, "%s %s %sn", ip, method, uri); /* The atomic version uses locking to prevent interference */ system_fwrite_atomic(logfd, logmsg, len); FREE(logmsg);
#include <base/file.h> struct tm *system_gmtime(const time_t *tp, const struct tm *res);
time_t tp; struct tm res, *resp; ... tp = time(NULL); resp = system_gmtime(&tp, &res);
#include <base/file.h> struct tm *system_localtime(const time_t *tp, const struct tm *res);
time_t tp; struct tm res, *resp; ... tp = time(NULL); resp = system_localtime(&tp, &res);
#include <base/file.h> system_lseek(SYS_FILE fd, int offset, int whence);
SEEK_SET
, the position is set to offset bytes.
SEEK_CUR
, the position is set to its current location plus offset.
SEEK_END
, the position is set to the size of the file plus offset.
#include <base/file.h> system_rename(char *old, char *new);
#include <base/file.h> int system_ulock(SYS_FILE fd);
IO_OK
if the unlock succeeded
IO_ERROR
if the unlock failed
#include <base/file.h> char *system_unix2local(char *path, char *lp);
You must allocate the parameter lp, and that 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_current                                                                 base/systhr.h
The systhread_current function returns a pointer to the current thread.
Syntax
#include <base/systhr.h>
SYS_THREAD systhread_current(void);
Returns
A pointer to the current thread
Parameters
void
See also
systhread_getdata, systhread_newkey, systhread_setdata, systhread_sleep,systhread_start, systhread_terminate, systhread_timerset
systhread_getdata                                                                 base/systhr.h
The systhread_getdata function gets data that is associated with a specified key in the current thread
Syntax
#include <base/systhr.h>
void *systhread_getdata(int key);
Returns
#include <base/systhr.h> int systhread_newkey(void);
void
#include <base/systhr.h> void systhread_setdata(int key, void *data);
void
#include <base/systhr.h> void systhread_sleep(int milliseconds);
void
#include <base/systhr.h> SYS_THREAD systhread_start(int prio, int stksz, void (*fn)(void *), void *arg);
#include <base/systhr.h> void systhread_terminate(SYS_THREAD thr);
Because most systems don't allow the timer interval to be changed, this should be considered a suggestion, rather than a command.
#include <base/systhr.h> void systhread_timerset(int usec);
#include <base/util.h> int util_can_exec(struct stat *finfo, uid_t uid, gid_t gid);
#include <base/util.h> int util_chdir2path(char *path);
The parameter must be a writable string because it isn't permanently modified.
#include <base/util.h> char **util_env_create(char **env, int n, int *pos);
#include <base/util.h> char *util_env_find(char **env, char *name);
#include <base/util.h> void util_env_free(char **env);
void
#include <base/util.h> void util_env_replace(char **env, char *name, char *value);
void
"="
). You can use this function to create a new environment entry.
#include <base/util.h> char *util_env_str(char *name, char *value);
#include <base/util.h> int util_getline(filebuf *buf, int lineno, int maxlen, char *l);
#include <base/util.h>} char *util_hostname(void);
#include <base/util.h> int util_is_mozilla(char *ua, char *major, char *minor);
#include <base/util.h> int util_is_url(char *url);
#include <base/util.h> int util_itoa(int i, char *a);
#include <base/util.h> int util_later_than(struct tm *lms, char *ims);
\
) 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.
#include <base/util.h> char *util_sh_escape(char *);
#include <base/util.h> int util_snprintf(char *s, int n, char *fmt, ...);
%d
and %s
strings; it does not handle any width or precision strings.
... represents a sequence of parameters for the printf function.
#include <base/util.h> int util_sprintf(char *s, char *fmt, ...);
%d
and %s
strings; it does not handle any width or precision strings.
... represents a sequence of parameters for the printf function.
int brief_log(pblock *pb, Session *sn, Request *rq) { char *method = pblock_findval("method", rq->reqpb); char *uri = pblock_findval("uri", rq->reqpb); char *ip = pblock_findval("ip", sn->client); /* Temp vars */ char *logmsg; int len; logmsg = (char *) MALLOC(strlen(ip) + 1 + strlen(method) + 1 + strlen(uri) + 1 + 1); len = util_sprintf(logmsg, "%s %s %sn", ip, method, uri); /* The atomic version uses locking to prevent interference */ system_fwrite_atomic(logfd, logmsg, len); FREE(logmsg); return REQ_PROCEED; }
#include <base/systems.h> int util_strcasecmp(const char *s1, const char *s2);
#include <base/systems.h> int util_strftime(char *s, const char *format, const struct tm *t);
%x
substrings. For more information, see the documentation on the printf function for the run-time library of your compiler.
const struct tm *t is a pointer to a calendar time (tm) struct, usually created by the function system_localtime or system_gmtime.
#include <base/systems.h> int util_strncasecmp(const char *s1, const char *s2, int n);
#include <base/util.h> char *util_uri_escape(char *d, char *s);
The util_uri_escape function does not check bounds for the parameter d. Therefore, d should be at least three times as large as s.
#include <base/util.h> int util_uri_is_evil(char *t);
#include <base/util.h> void util_uri_parse(char *uri);
void
#include <base/util.h> void util_uri_unescape(char *uri);
void
#include <base/util.h> int util_vsnprintf(char *s, int n, register char *fmt, va_list args);
%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.
#include <base/util.h> int util_vsprintf(char *s, register char *fmt, va_list args);
%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.