Now that we have covered the main structures used by modules, we can detail the functions available to use and manipulate those structures.
ap_make_sub_pool | create a subpool |
pool *ap_make_sub_pool(pool *p) |
ap_clear_pool | clear a pool without destroying it |
void ap_clear_pool(pool *p) |
ap_destroy_pool | destroy a pool and all its contents |
void ap_destroy_pool(pool *p) |
ap_bytes_in_pool | report the size of a pool |
long ap_bytes_in_pool(pool *p) |
ap_bytes_in_free_blocks | report the total size of free blocks in the pool system |
long ap_bytes_in_free_blocks(void) |
ap_palloc | allocate memory within a pool |
void *ap_palloc(pool *p, int size) |
ap_pcalloc | allocate and clear memory within a pool |
void *ap_pcalloc(pool *p, int size) |
ap_pstrdup | duplicate a string in a pool |
char *ap_pstrdup(pool *p,const char *s) |
ap_pstrndup | duplicate a string in a pool with limited length |
char *ap_pstrndup(pool *p, const char *s, int n) |
ap_pstrcat | concatenate and duplicate a list of strings |
char *ap_pstrcat(pool *p, ...) |
pstrcat(p,"Hello,","world!",NULL);
returns a block of memory containing Hello, world!
ap_make_array | allocate an array of arbitrary-size elements |
array_header *ap_make_array(pool *p, int nelts, int elt_size) |
ap_push_array | add a new element to an array |
void *ap_push_array(array_header *arr) |
ap_array_cat | concatenate two arrays |
void ap_array_cat(array_header *dst, const array_header *src) |
ap_copy_array | create a copy of an array |
array_header *ap_copy_array(pool *p, const array_header *arr) |
ap_copy_array_hdr | create a copy of an array with copy-on-write |
array_header *ap_copy_array_hdr(pool *p, const array_header *arr) |
There are at least two pitfalls with this function. First, if the array is not extended, its memory is destroyed when the original array is destroyed; second, any changes made to the original array may also affect the new array if they occur before the new array is extended.
ap_append_arrays | concatenate two arrays into a new array |
array_header*ap_append_arrays(pool*p, const array_haeder*first, const array_header *second) |
A table is an association between two strings known as the key and the value, accessible by the key.
ap_make_table | create a new table |
table *ap_make_table(pool *p, int nelts) |
ap_copy_table | copy a table |
table *ap_copy_table(pool *p, const table *t) |
ap_table_elts | access the array that underlies a table |
array_header *ap_table_elts(table *t) |
ap_is_empty_table | test whether a table is empty |
int ap_is_empty_table(table *t) |
ap_table_set | create or replace an entry in a table |
void ap_table_set(table *t, const char *key, const char *value) |
ap_table_setn | create or replace an entry in a table without duplication |
void ap_table_setn(table *t, const char *key, const char *value) |
ap_table_merge | merge a new value into a table |
void ap_table_merge(table *t, const char *key, const char *value) |
pool *p; /* Assumed to be set elsewhere */ table *t; char *v; t=make_table(1); table_set(t,"somekey","Hello"); table_merge(t,"somekey","world!"); v=table_get(t,"somekey"); /* v now contains "Hello, world!" */
ap_table_mergen | merge a new value into a table without duplication |
void ap_table_mergen(table *t, const char *key, const char *value) |
ap_table_add | add a new key/value pair to a table |
void ap_table_add(table *t, const char *key, const char *value) |
ap_table_addn | add a new key/value pair to a table without duplication |
void ap_table_addn(table *t, const char *key, const char *value) |
ap_table_unset | remove an entry from a table |
void ap_table_unset(table *t, const char *key) |
ap_table_get | find the value in a table corresponding to a key |
const char *ap_table_ get(const table *t, const char *key) |
ap_table_do | apply a function to each element of a table |
void ap_table_do(int(*comp)(void*, const char*, const char*), void*rec, const table *t,...) |
In either case it may happen that the comp() function is called multiple times for the same key. The table may again contain various entries of the same key; and if the vararg list is non-empty, the traversal is repeated for any vararg item, even if they are equal.
ap_overlay_tables | concatenate two tables to give a new table |
table *ap_overlay_tables(pool *p, const table *overlay, const table *base) |
ap_clear_table | clear a table without deleting it |
API_EXPORT(void) ap_clear_table(table *t) |
An important part of the pool is the cleanup functions that are run when the pool is destroyed. These functions deal with those cleanup functions.
ap_register_cleanup | register a cleanup function |
void ap_register_cleanup(pool*p, void*data, void(*plain_cleanup)(void*),void (*child_cleanup)(void *)) |
ap_kill_cleanup | remove a cleanup function |
void ap_kill_cleanup(pool *p, void *data, void (*plain_cleanup)(void *)) |
ap_cleanup_for_exec | clear all pools in preparation for an exec |
void ap_cleanup_for_exec(void) |
Note that on Win32 this actually does nothing, on the slightly dubious grounds that we aren't forked. Unfortunately, there isn't really much alternative.
ap_note_cleanups_for_fd | register a cleanup for a file descriptor |
void ap_note_cleanups_for_fd(pool *p, int fd) |
ap_kill_cleanups_for_fd | remove the cleanup for a file descriptor |
void ap_kill_cleanups_for_fd(pool *p, int fd) |
ap_note_cleanups_for_socket | register a cleanup for a socket |
void ap_note_cleanups_for_socket(pool *p, int fd) |
ap_kill_cleanups_for_socket | remove the cleanup for a socket |
void ap_kill_cleanups_for_socket(pool *p, int sock) |
ap_note_cleanups_for_file | register a cleanup for a FILE * |
void ap_note_cleanups_for_file(pool *p, FILE *f) |
ap_run_cleanup | run a cleanup function, blocking alarms |
void ap_run_cleanup(pool *p, void *data, void (*cleanup)(void *)) |
These functions are used to open and close files and sockets with automatic cleanup registration and killing.
ap_popenf | open a file with automatic cleanup |
int ap_popenf(pool *p, const char *name, int flg, int mode) |
ap_pclosef | close a file opened with popenf |
int ap_pclosef(pool *p, int fd) |
ap_pfopen | open a stream with automatic cleanup |
FILE *ap_pfopen(pool *p, const char *name, const char *mode) |
ap_pfdopen | open a stream from a file descriptor with automatic cleanup |
FILE *ap_pfdopen(pool *p, int fd, const char *mode) |
ap_pfclose | close a stream opened with pfopen( ) or pfdopen( ) |
int ap_pfclose(pool *p, FILE *fd) |
ap_psocket | open a socket with automatic cleanup |
int ap_psocket(pool *p, int domain, int type, int protocol) |
ap_pclosesocket | close a socket created with ap_psocket( ) |
int ap_pclosesocket(pool *a, int sock) |
Note that only the functions that allocate memory are wrapped by Apache API functions.
ap_pregcomp | compile a regular expression with automatic cleanup |
regex_t *ap_pregcomp(pool *p, const char *pattern, int cflags) |
ap_pregsub | substitute for regular expression submatches |
char *ap_pregsub(pool *p, const char *input, const char *source, size_t nmatch, regmatch_t pmatch[]) |
ap_pregfree | free a regular expression compiled with ap_pregcomp( ) |
void ap_pregfree(pool *p, regex_t * reg) |
ap_os_is_path_absolute | determine whether a path is absolute |
int ap_os_is_path_absolute(const char *file) |
ap_note_subprocess | register a subprocess for killing on pool destruction |
void ap_note_subprocess(pool *p, int pid, enum kill_conditions how) |
Don't kill the process or wait for it. This is normally used internally.
Send the process a SIGTERM, wait three seconds, send a SIGKILL, and wait for the process to die.
Send the process a SIGKILL and wait for the process to die.
Don't send the process any kind of kill.
Send a SIGTERM, then wait.
Note that all three-second delays are carried out at once, rather than one after the other.
ap_spawn_child | spawn a child process |
int ap_spawn_child(pool *p, void(*func)(void *,child_info *), void *data, enum kill_conditions kill_how, FILE **pipe_in, FILE **pipe_out, FILE **pipe_err) |
ap_bspawn_child | spawn a child process |
int ap_bspawn_child(pool *p, int (*func) (void *, child_info *), void *data, enum kill_conditions kill_how, BUFF **pipe_in, BUFF **pipe_out, BUFF **pipe_err) |
The child_info structure carries information needed to spawn the child under Win32; it is normally passed straight on to ap_call_exec(). If func() wants cleanup to occur, it calls cleanup_for_exec. func() will normally actually execute the child process with ap_call_exec(). If any of pipe_in, pipe_out, or pipe_err are NULL, those pipes aren't created; otherwise, they are filled in with pointers to BUFFs that are connected to the subprocesses' standard input, output, and error, respectively. Note that on Win32, the pipes use Win32 native handles rather than C file handles. This function only returns in the parent. Returns the PID of the child process, or -1 on error. This function was called spawn_child_err_buff in previous versions of Apache.
ap_call_exec | exec, spawn, or call setuid wrapper |
int ap_call_exec(request_rec*r, child_info*pinfo, char*argv0, char**env, int shellcmd) |
ap_can_exec | check whether a path can be executed |
int ap_can_exec(const struct stat *finfo) |
ap_add_cgi_vars | set environment variables for CGIs |
void ap_add_cgi_vars(request_rec *r) |
ap_add_common_vars | set environment variables for subprograms |
void ap_add_common_vars(request_rec *r) |
ap_scan_script_header_err | scan the headers output by a CGI |
int ap_scan_script_header_err(request_rec *r, FILE *f, char *buffer) |
If this is set, it is used as the HTTP response code.
If this is set, the result is a redirect to the URL specified.
If buffer is provided (it can be NULL), then, should the script send an illegal header, it will be left in buffer, which must be at least MAX_STRING_LEN bytes long. The return value is HTTP_OK, the status set by the script, or SERVER_ERROR if an error occurred.
ap_scan_script_header_err_buff | scan the headers output by a CGI |
int ap_scan_script_header_err_buff(request_rec *r, BUFF *fb, char*buffer) |
ap_scan_script_header | scan the headers output by a CGI |
int ap_scan_script_header(request_rec *r, FILE *f) |
ap_md5 | calculate the MD5 hash of a string |
char *ap_md5(pool *p, unsigned char *string) |
ap_md5contextTo64 | convert an MD5 context to base 64 encoding |
char *ap_md5contextTo64(pool *a, AP_MD5_CTX * context) |
ap_md5digest | make a base 64 MD5 digest of an open file |
char *ap_md5digest(pool *p, FILE *infile) |
ap_MD5Init | initialize an MD5 digest |
void ap_MD5Init(AP_MD5_CTX *context) |
ap_MD5Final | finalize an MD5 digest |
void ap_MD5Final(unsigned char digest[16], AP_MD5_CTX *context) |
ap_MD5Update | add a block to an MD5 digest |
void ap_MD5Update(AP_MD5_CTX * context, const unsigned char *input, unsigned int inputLen) |
These functions hide operating system-dependent functions. On platforms that do not use threads for Apache, these functions exist but do not do anything; they simulate success if called.
Note that of these functions, only the mutex functions are actually implemented. The rest are documented for completeness (and in case they get implemented).
ap_create_mutex | create a mutual exclusion object |
mutex *ap_create_mutex(char *name) |
ap_open_mutex | open a mutual exclusion object |
mutex *ap_open_mutex(char *name) |
ap_acquire_mutex | lock an open mutex object |
int ap_acquire_mutex(mutex *mutex_id) |
ap_release_mutex | release a locked mutex |
int ap_release_mutex(mutex *mutex_id) |
ap_destroy_mutex | destroy an open mutex |
void ap_destroy_mutex(mutex *mutex_id); |
create_semaphore | create a semaphore |
semaphore *create_semaphore(int initial) |
acquire_semaphore | acquire a semaphore |
int acquire_semaphore(semaphore *semaphore_id) |
release_semaphore | release a semaphore |
int release_semaphore(semaphore *semaphore_id) |
destroy_semaphore | destroy an open semaphore |
void destroy_semaphore(semaphore *semaphore_id) |
create_event | create an event |
event *create_event(int manual, int initial, char *name) |
open_event | open an existing event |
event *open_event(char *name) |
acquire_event | wait for an event to be signaled |
int acquire_event(event *event_id) |
set_event | signal an event |
int set_event(event *event_id) |
reset_event | clear an event |
int reset_event(event *event_id) |
destroy_event | destroy an open event |
void destroy_event(event *event_id) |
create_thread | create a thread |
thread *create_thread(void (thread_fn) (void *thread_arg), void *thread_arg) |
kill_thread | kill a thread |
int kill_thread(thread *thread_id) |
await_thread | wait for a thread to complete |
int await_thread(thread *thread_id, int sec_to_wait) |
exit_thread | exit the current thread |
void exit_thread(int status) |
free_thread | free a thread's resources |
void free_thread(thread *thread_id) |
ap_get_time | return a human-readable version of the current time |
char *ap_get_time(void) |
ap_ht_time | return a pool-allocated string describing a time |
char *ap_ht_time(pool *p, time_t t, const char *fmt, int gmt) |
ap_gm_timestr_822 | format a time according to RFC 822 |
char *ap_gm_timestr_822(pool *p, time_t t) |
[72]Or, in other words, mail. Since HTTP has elements borrowed from MIME, and MIME is for mail, you can see the connection.
ap_get_gmtoff | get the time and calculate the local time zone offset from GMT |
struct tm *ap_get_gmtoff(long *tz) |
ap_tm2sec | convert a struct tm to standard Unix time |
time_t ap_tm2sec(const struct tm *t) |
ap_parseHTTPdate | convert an HTTP date to Unix time |
time_t ap_parseHTTPdate(const char *date) |
Sun, 06 Nov 1994 08:49:37 GMT (RFC 822, updated by RFC 1123)
Sunday, 06-Nov-94 08:49:37 GMT (RFC 850, made obsolete by RFC 1036)
Sun Nov 6 08:49:37 1994 (ANSI C asctime() format)
Note that since HTTP requires dates to be in GMT, this routine ignores the timezone field.
ap_strcmp_match | wildcard match two strings |
int ap_strcmp_match(const char *str, const char *exp) |
ap_strcasecmp_match | case-blind wildcard match two strings |
int ap_strcasecmp_match(const char *str, const char *exp) |
ap_is_matchexp | does a string contain wildcards? |
int ap_is_matchexp(const char *exp) |
ap_getword | extract one word from a list of words |
char *ap_getword(pool *p, const char **line, char stop) char *ap_getword_nc(pool *p, char **line, char stop) |
ap_getword_white | extract one word from a list of words |
char *ap_getword_white(pool *p, const char **line) char *ap_getword_white_nc(pool *p, char **line) |
ap_getword_nulls | extract one word from a list of words |
char *ap_getword_nulls(pool *p, const char **line, char stop) char *ap_getword_nulls_nc(pool *p, char **line, char stop) |
ap_getword_conf | extract one word from a list of words |
char *ap_getword_conf(pool *p, const char **line) char *ap_getword_conf_nc(pool *p, char **line) |
ap_get_token | extract a token from a string |
char *ap_get_token(pool *p, const char **line, int accept_white) |
ap_find_token | look for a token in a line (usually an HTTP header) |
int ap_find_token(pool *p, const char *line, const char *tok) |
()<>@,;\\/[]?={}
This corresponds to the definition of a token in RFC 2068.
ap_find_last_token | check if the last token is a particular string |
int ap_find_last_token(pool *p, const char *line, const char *tok) |
ap_escape_shell_cmd | escape dangerous characters in a shell command |
char *ap_escape_shell_cmd(pool *p, const char *s) |
&;`'\"|*?~<>^()[]{}$\\\n
Under OS/2, & is converted to a space.[73]
[73]Don't think that using this function makes shell scripts safe: it doesn't. See Chapter 13, "Security".
ap_uudecode | uudecode a block of characters |
char *ap_uudecode(pool *p, const char *coded) |
ap_escape_html | escape some HTML |
char *ap_escape_html(pool *p, const char *s) |
ap_checkmask | check whether a string matches a mask |
int ap_checkmask(const char *data, const char *mask) |
An uppercase letter
A lowercase letter
A hexadecimal digit
A decimal digit
A decimal digit or a space
Any number of any character
Itself
data is arbitrarily limited to 256 characters. Returns 1 for a match, 0 if not. For example, the following code checks for RFC 1123 date format:
if(ap_checkmask(date, "## @$$ #### ##:##:## *")) ...
ap_str_tolower | convert a string to lowercase |
void ap_str_tolower(char *str) |
ap_psprintf | format a string |
char *ap_psprintf(pool *p, const char *fmt, ...) |
ap_pvsprintf | format a string |
char *ap_pvsprintf(pool *p, const char *fmt, va_list ap) |
ap_ind | find the first index of a character in a string |
int ap_ind(const char *s, char c) |
ap_rind | find the last index of a character in a string |
int ap_rind(const char *s, char c) |
ap_getparents | remove "." and ".." segments from a path |
void ap_getparents(char *name) |
ap_no2slash | remove "//" from a path |
void ap_no2slash(char *name) |
ap_make_dirstr | make a copy of a path with a trailing slash, if needed |
char *ap_make_dirstr(pool *p, const char *path, int n) |
ap_make_dirstr_parent | make the path of the parent directory |
char * ap_make_dirstr_parent(pool *p, const char *s) |
ap_make_dirstr_prefix | copy part of a path |
char *ap_make_dirstr_prefix(char *d, const char *s, int n) |
ap_count_dirs | count the number of slashes in a path |
int ap_count_dirs(const char *path) |
ap_chdir_file | change to the directory containing file |
void ap_chdir_file(const char *file) |
ap_unescape_url | remove escape sequences from a URL |
int ap_unescape_url(char *url) |
ap_construct_server | make the server part of a URL |
char *ap_construct_server(pool *p, const char *hostname, int port, request_rec *r) |
ap_construct_url | make an HTTP URL |
char *ap_construct_url(pool *p, const char *uri, const request_rec *r) |
ap_escape_path_segment | escape a path segment as per RFC 1808 |
char *ap_escape_path_segment(pool *p, const char *segment) |
ap_os_escape_path | escape a path as per RFC 1808 |
char *ap_os_escape_path(pool *p, const char *path, int partial) |
ap_is_directory | checks whether a path refers to a directory |
int ap_is_directory(const char *path) |
ap_make_full_path | combines two paths into one |
char *ap_make_full_path(pool *p, const char *path1, const char *path2) |
ap_is_url | checks whether a string is in fact a URL |
int ap_is_url(const char *url) |
ap_fnmatch | match a filename |
int ap_fnmatch(const char *pattern, const char *string, int flags) |
Match a single character.
Match any number of characters.
A closure, like in regular expressions. A leading caret (^) inverts the closure.
If FNM_NOESCAPE is not set, removes any special meaning from next character.
flags is a combination of the following:
Treat a "\" as a normal character.
*, ?, and [...] don't match "/.".
*, ?, and [...] don't match leading dots. "Leading" means either at the beginning of the string, or after a "/" if FNM_PATHNAME is set.
ap_is_fnmatch | check whether a string is a pattern |
int ap_is_fnmatch(const char *pattern) |
ap_server_root_relative | make a path relative to the server root |
char *ap_server_root_relative(pool *p, char *file) |
ap_os_canonical_filename | convert a filename to its canonical form |
char *ap_os_canonical_filename(pool *pPool, const char *szFile) |
Win32, for example, is case blind, ignores trailing dots and spaces, and so on.[74] This function is generally used before checking a filename against a pattern or other similar operations.
[74]In fact, exactly what Windows does with filenames is very poorly documented and is a seemingly endless source of security holes.
ap_uname2id | convert a username to a user ID (UID) |
uid_t ap_uname2id(const char *name) |
ap_gname2id | convert a group name to a group ID (GID) |
gid_t ap_gname2id(const char *name) |
ap_get_virthost_addr | convert a hostname or port to an address |
unsigned long ap_get_virthost_addr(const char *hostname, short *ports) |
If the host has multiple IP addresses, an error message is printed and exit() is called.
ap_get_local_host | get the FQDN for the local host |
char *ap_get_local_host(pool *p) |
ap_get_remote_host | get client hostname or IP address |
const char *ap_get_remote_host(conn_rec *conn, void *dir_config, int type) |
Returns the hostname or NULL (if it either couldn't be found or hostname lookups are disabled with the HostnameLookups directive).
Returns the hostname or, if it can't be found, returns the IP address.
Similar to REMOTE_NAME, except that a DNS lookup is not performed (note that the name can still be returned if a previous call did do a DNS lookup).
Do a double-reverse lookup (that is, look up the hostname from the IP address, then look up the IP address from the name). If the double reverse works and the IP addresses match, return the name; otherwise, return a NULL.
ap_send_fd | copy an open file to the client |
long ap_send_fd(FILE *f, request_rec *r) |
ap_send_fd_length | copy a number of bytes from an open file to the client |
long ap_send_fd_length(FILE *f, request_rec *r, long length) |
ap_send_fb | copy an open stream to a client |
long ap_send_fb(BUFF *fb, request_rec *r) |
ap_send_fb_length | copy a number of bytes from an open stream to a client |
long ap_send_fb_length(BUFF *fb, request_rec *r, long length) |
ap_send_mmap | send data from an in-memory buffer |
size_t ap_send_mmap(void *mm, request_rec *r, size_t offset, size_t length) |
ap_rwrite | write a buffer to the client |
int ap_rwrite(const void *buf, int nbyte, request_rec *r) |
ap_rputc | send a character to the client |
int ap_rputc(int c, request_rec *r) |
ap_rputs | send a string to the client |
int ap_rputs(const char *s, request_rec *r) |
ap_rvputs | send a list of strings to the client |
int ap_rvputs(request_rec *r, ...) |
ap_rprintf | send a formatted string to the client |
int ap_rprintf(request_rec *r, const char *fmt,...) |
ap_rflush | flush client output |
int ap_rflush(request_rec *r) |
ap_setup_client_block | prepare to receive data from the client |
int ap_setup_client_block(request_rec *r, int read_policy) |
read_policy is one of the following:
Return HTTP_REQUEST_ENTITY_TOO_LARGE if the request has any body.
If the Transfer-Encoding is chunked, return HTTP_BAD_REQUEST if there is a Content-Length header, or HTTP_LENGTH_REQUIRED if not.[75]
[75]This may seem perverse, but the idea is that by asking for a Content-Length, we are implicitly requesting that there is no Transfer-Encoding (at least, not a chunked one). Getting both is an error.
Handles chunked encoding in ap_ get_client_block(), returning just the data.
Handles chunked encoding in ap_ get_client_block(), returning the data and the chunk headers.
ap_should_client_block | ready to receive data from the client |
int ap_should_client_block(request_rec *r) |
ap_get_client_block | read a block of data from the client |
long ap_get_client_block(request_rec *r, char *buffer, int bufsiz) |
ap_send_http_header | send the response headers to the client |
void ap_send_http_header(request_rec *r) |
ap_send_size | send a size approximately |
void ap_send_size(size_t size, request_rec *r) |
ap_sub_req_lookup_uri | look up a URI as if it were a request |
request_rec *ap_sub_req_lookup_uri(const char *new_uri, const request_rec *r) |
ap_sub_req_lookup_file | look up a file as if it were a request |
request_rec *ap_sub_req_lookup_file(const char *new_file, const request_rec *r) |
ap_run_sub_req | run a subrequest |
int ap_run_sub_req(request_rec *r) |
ap_destroy_sub_req | destroy a subrequest |
void ap_destroy_sub_req(request_rec *r) |
ap_internal_redirect | internally redirect a request |
void ap_internal_redirect(const char *uri, request_rec *r) |
ap_internal_redirect_handler | internally redirect a request, preserving handler |
void ap_internal_redirect_handler(const char *uri, request_rec *r) |
ap_hard_timeout | set a hard timeout on a request |
void ap_hard_timeout(char *name, request_rec *r) |
ap_keepalive_timeout | set the keepalive timeout on a request |
void ap_keepalive_timeout(char *name, request_rec *r) |
ap_soft_timeout | set a soft timeout on a request |
void ap_soft_timeout(char *name, request_rec *r) |
ap_reset_timeout | resets a hard or soft timeout to its original time |
void ap_reset_timeout(request_rec *r) |
ap_kill_timeout | clears a timeout |
void ap_kill_timeout(request_rec *r) |
ap_block_alarms( ) | temporarily prevents a timeout from occurring |
void ap_block_alarms(void) |
ap_unblock_alarms( ) | unblock a blocked alarm |
void ap_unblock_alarms(void) |
ap_check_alarm | check alarm (Win32 only) |
int ap_check_alarm(void) |
ap_pcfg_openfile | open a file as a configuration |
configfile_t *ap_pcfg_openfile(pool *p, const char *name) |
ap_pcfg_open_custom | create a custom configuration |
configfile_t *ap_pcfg_open_custom(pool *p, const char *descr, void *synopsism, int(*getch)(void *param), void *(*getstr) (void *buf, size_t bufsiz, void *param), int(*close_func)(void *param)) |
ap_cfg_getc | read a character from a configuration |
int ap_cfg_ getc(configfile_t *cfp) |
ap_cfg_getline | read a line from a configuration, stripping whitespace |
int ap_cfg_ getline(char *s, int n, configfile_t *cfp) |
ap_cfg_closefile | close a configuration |
int ap_cfg_closefile(configfile_t *cfp) |
ap_check_cmd_context | check if configuration cmd allowed in current context |
const char *ap_check_cmd_context(cmd_parms *cmd, unsigned forbidden) |
Command cannot appear in a <VirtualHost> section.
Command cannot occur in a <Limit> section.
Command cannot occur in a <Directory> section.
Command cannot occur in a <Location> section.
Command cannot occur in a <Files> section.
Shorthand for NOT_IN_DIRECTORY|NOT_IN_LOCATION|NOT_IN_FILES.
Shorthand for NOT_IN_VIRTUALHOST|NOT_IN_LIMIT|NOT_IN_DIR_LOC_FILE.
ap_set_file_slot | set a file slot in a configuration structure |
const char *ap_set_file_slot(cmd_parms *cmd, char *struct_ptr, char *arg) |
ap_set_flag_slot | set a flag slot in a configuration structure. |
const char * ap_set_flag_slot(cmd_parms *cmd, char *struct_ptr, int arg) |
ap_set_string_slot | set a string slot in a configuration structure |
const char *ap_set_string_slot(cmd_parms *cmd, char *struct_ptr, char *arg) |
ap_set_string_slot_lower | set a lowercase string slot in a configuration structure |
const char *ap_set_string_slot_lower(cmd_parms *cmd, char *struct_ptr, char *arg) |
Modules may need to know how some things have been configured. These functions give access to that information.
ap_allow_options | return options set with the Options directive |
int ap_allow_options (request_rec *r) |
No options set.
The Indexes option.
The Includes option.
The FollowSymLinks option.
The ExecCGI option.
The IncludesNOEXEC option.
The FollowSymLinksIfOwnerMatch option.
The MultiViews option.
ap_allow_overrides | return overrides set with the AllowOverride option |
int ap_allow_overrides (request_rec *r) |
No overrides are permitted.
The Limit override.
The Options override.
The FileInfo override.
The AuthConfig override.
The Indexes override.
ap_auth_type | return the authentication type for this request |
const char *ap_auth_type (request_rec *r) |
ap_auth_name | return the authentication domain name |
const char *ap_auth_name (request_rec *r) |
ap_requires | return the require array |
const array_header *ap_requires (request_rec *r) |
typedef struct { int method_mask; char *requirement; } require_line;
method_mask is the bitwise OR of:
1 << M_GET 1 << M_PUT 1 << M_POST 1 << M_DELETE 1 << M_CONNECT 1 << M_OPTIONS 1 << M_TRACE 1 << M_INVALID
as set by a Limit directive.
ap_satisfies | return the satisfy setting |
int ap_satisfies (request_rec *r) |
ap_get_server_built | get the date and time Apache was built |
const char *ap_get_server_built(void) |
ap_get_server_version | get the Apache version string |
const char *ap_get_server_version( ) |
ap_add_version_component | add a module version string |
void ap_add_version_component(const char *component) |
ap_error_log2stderr | map stderr to an error log |
void ap_error_log2stderr (server_rec *s) |
ap_log_error | log an error |
void ap_log_error(const char*file, int line, int level, const server_rec*s, const char *fmt, ...) |
ap_log_error(APLOG_MARK, APLOG_ERR, server_conf,"some error");
APLOG_MARK is a #define that uses __FILE__ and __LINE__ to generate the filename and line number of the call.
level is a combination of one of the following:
The system is unusable.
Action must be taken immediately.
Critical conditions.
Error conditions.
Warnings.
Normal but significant condition.
Informational.
Debugging messages.
optionally ORed with:
Do not log errno.
On Win32 use GetLastError() instead of
errno.
ap_log_reason | log an access failure |
void ap_log_reason (const char *reason, const char *file, request_rec *r) |
Apache provides functions to manage reliable piped logs. These are logs which are piped to another program. Apache restarts the program if it dies. This functionality is disabled if NO_RELIABLE_PIPED_LOGS is defined. The functions still exist and work, but the "reliability" is disabled.
ap_open_piped_log | open a piped log program |
piped_log *ap_open_piped_log (pool *p, const char *program) |
ap_close_piped_log | close a piped log |
void ap_close_piped_log (piped_log *pl) |
ap_piped_log_write_fd | get the file descriptor of a log pipe |
int ap_piped_log_write_fd(piped_log *pl) |
Apache provides its own I/O buffering interface. This allows chunked transfers to be done transparently and hides differences between files and sockets under Win32.
ap_bcreate | create a buffered stream |
BUFF *ap_bcreate(pool *p, int flags) |
Reading is buffered.
Writing is buffered.
Reading and writing are buffered.
and, optionally:
The stream will be buffering a socket. Note that this flag also causes ASCII/EBCDIC translation to be enabled on platforms that use EBCDIC (see ap_bsetflag()).
ap_bpushfd | set the file descriptors for a stream |
void ap_bpushfd(BUFF *fb, int fd_in, int fd_out) |
ap_bpushh | set a Win32 handle for a stream |
void ap_bpushh(BUFF *fb, HANDLE hFH) |
ap_bsetopt | set an option |
int ap_bsetopt(BUFF *fb, int optname, const void *optval) |
[76]Not really an option, in our view, but we didn't name the function.
ap_bgetopt | get the value of an option |
int ap_bgetopt(BUFF *fb, int optname, void *optval) |
ap_bsetflag | set or clear a flag |
int ap_bsetflag(BUFF *fb, int flag, int value) |
Prevent further I/O.
Use chunked writing.
Force an ap_bflush() if a read would block.
Convert ASCII to EBCDIC when reading. Only available on systems that support EBCDIC.
Convert EBCDIC to ASCII when writing. Only available on systems that support EBCDIC.
ap_bgetflag | get a flag's setting |
int ap_bgetflag(BUFF *fb, int flag) |
ap_bonerror | register an error function |
void ap_bonerror(BUFF *fb, void (*error) (BUFF *, int, void *), void *data) |
ap_bnonblock | set a stream to nonblocking mode |
int ap_bnonblock(BUFF *fb, int direction) |
ap_bfileno | get a file descriptor from a stream |
int ap_bfileno(BUFF *fb, int direction) |
ap_bread | read from a stream |
int ap_bread(BUFF *fb, void *buf, int nbyte) |
ap_bgetc | get a character from a stream |
int ap_bgetc(BUFF *fb) |
ap_bgets | read a line from a stream |
int ap_bgets(char *buff, int n, BUFF *fb) |
ap_blookc | peek at the next character in a stream |
int ap_blookc(char *buff, BUFF *fb) |
ap_bskiplf | discard until an LF is read |
int ap_bskiplf(BUFF *fb) |
ap_bwrite | write to a stream |
int ap_bwrite(BUFF *fb, const void *buf, int nbyte) |
ap_bputc | write a single character to a stream |
int ap_bputc(char c, BUFF *fb) |
ap_bputs | write a NUL-terminated string to a stream |
int ap_bputs(const char *buf, BUFF *fb) |
ap_bvputs | write several NUL-terminated strings to a stream |
int ap_bvputs(BUFF *fb,...) |
if(ap_bvputs(fb,buf1,buf2,buf3,NULL) < 0) ...
ap_bprintf | write formatted output to a stream |
int ap_bprintf(BUFF *fb, const char *fmt, ...) |
ap_vbprintf | write formatted output to a stream |
int ap_vbprintf(BUFF *fb, const char *fmt, va_list ap) |
ap_bflush | flush output buffers |
int ap_bflush(BUFF *fb) |
ap_bclose | close a stream |
int ap_bclose(BUFF *fb) |
Some of these functions use the uri_components structure:
typedef struct { char *scheme; /* scheme ("http"/"ftp"/...) */ char *hostinfo; /* combined [user[:password]@]host[:port] */ char *user; /* username, as in http://user:passwd@host:port/ */ char *password; /* password, as in http://user:passwd@host:port/ */ char *hostname; /* hostname from URI (or from Host: header) */ char *port_str; /* port string (integer representation is in "port") */ char *path; /* The request path (or "/" if only scheme://host was /* given) */ char *query; /* Everything after a '?' in the path, if present */ char *fragment; /* Trailing "#fragment" string, if present */ struct hostent *hostent; unsigned short port; /* The port number, numeric, valid only if /* port_str != NULL */ unsigned is_initialized:1; unsigned dns_looked_up:1; unsigned dns_resolved:1; } uri_components;
ap_parse_uri_components | dissect a full URI |
int ap_parse_uri_components(pool *p, const char *uri, uri_components *uptr) |
ap_parse_hostinfo_components | dissect host:port |
int ap_parse_hostinfo_components(pool *p, const char *hostinfo, uri_components *uptr) |
ap_unparse_uri_components | convert back to a URI |
char *ap_unparse_uri_components(pool *p, const uri_components *uptr, unsigned flags) |
Leave out "scheme://user:password@site:port".
Leave out the user.
Leave out the password.
Shorthand for UNP_OMITUSER|UNP_OMITPASSWORD.
Show the password (instead of replacing it with XXX).
ap_pgethostbyname | resolve a hostname |
struct hostent *ap_pgethostbyname(pool *p, const char *hostname) |
ap_pduphostent | duplicate a hostent structure |
struct hostent *ap_pduphostent(pool *p, const struct hostent *hp) |
ap_child_terminate | cause the current process to terminate |
void ap_child_terminate(request_rec *r) |
ap_default_port | return the default port for a request |
unsigned short ap_default_port(request_rec *r) |
ap_is_default_port | check whether a port is the default port |
int ap_is_default_port(int port, request_rec *r) |
ap_default_port_for_scheme | return the default port for a scheme |
unsigned short ap_default_port_for_scheme(const char *scheme_str) |
ap_http_method | return the scheme for a request |
const char *ap_http_method(request_rec *r) |
ap_default_type | returns default content type |
const char *ap_default_type(request_rec *r) |
ap_get_basic_auth_pw | get the password supplied for basic authentication |
int ap_get_basic_auth_pw(request_rec *r, const char **pw) |
If the request does not require basic authentication
If no authentication domain name has been set (with AuthName)
If authentication is required but has not been sent by the client
If the password has been put in *pw
ap_get_module_config | get module-specific configuration information |
void *ap_get_module_config(void *conf_vector, module *m) |
ap_get_remote_logname | get the login name of the client's user |
const char *ap_get_remote_logname(request_rec *r) |
ap_get_server_name | get the name of the current server |
const char *ap_get_server_name(const request_rec *r) |
ap_get_server_port | get the port of the current server |
unsigned ap_get_server_port(const request_rec *r) |
[77]Though what practical difference this makes is somewhat mysterious to us.
ap_is_initial_req | is this the main request_rec? |
int ap_is_initial_req(request_rec *r) |
ap_matches_request_vhost | does a host match a request's virtual host? |
int ap_matches_request_vhost(request_rec *r, const char *host, unsigned port) |
ap_os_dso_load | load a dynamic shared object (DSO) |
void *ap_os_dso_load(const char *path) |
ap_os_dso_unload | unload a dynamic shared object |
void ap_os_dso_unload(void *handle) |
ap_os_dso_sym | return the address of a symbol |
void *ap_os_dso_sym(void *handle, const char *symname) |
ap_os_dso_error | get a string describing a DSO error |
const char *ap_os_dso_error(void) |
ap_popendir | do an opendir( ) with cleanup |
DIR *ap_popendir(pool *p, const char *name) |
ap_pclosedir | close a DIR opened with ap_popendir( ) |
void ap_pclosedir(pool *p, DIR * d) |
ap_psignature | create the server "signature" |
const char *ap_psignature(const char *prefix, request_rec *r) |
ap_vformatter | general-purpose formatter |
int ap_vformatter(int (*flush_func)(ap_vformatter_buff *),ap_vformatter_buff *vbuff, const char *fmt, va_list ap) |
typedef struct { char *curpos; char *endpos; } ap_vformatter_buff;
as well as the usual format string, fmt, and varargs list, ap. ap_vformatter() fills the buffer (at vbuff->curpos) until vbuff->curpos == vbuff->endpos; then flush_func() is called with vbuff as the argument. flush_func() should empty the buffer and reset the values in vbuff to allow the formatting to proceed. flush_func() is not called when formatting is complete (unless it happens to fill the buffer). It is the responsibility of the function that calls ap_vformatter() to finish things off.
Since flush_func() almost always needs more information than that found in vbuff, the following ghastly hack is frequently employed. First, a structure with an ap_vformatter_buff as its first element[78] is defined:
[78]Of course, if you don't mind the hack being even more ghastly, it doesn't have to be first.
struct extra_data { ap_vformatter_buff vbuff; int some_extra_data; ... };
Next, the printf()-style routine calls ap_vformatter with an instance of this structure:
struct extra_data mine; ... mine.some_extra_data=123; ap_vformatter(my_flush,&mine.vbuff,fmt,ap); ...
Finally, my_flush() does this:
API_EXPORT(int) my_flush(ap_vformatter_buff *vbuff) { struct extra_data *pmine=(struct extra_data *)vbuff; assert(pmine->some_extra_data == 123); ...
As you can probably guess, we don't entirely approve of this technique, but it works.
ap_vformatter() does all the usual formatting, except that %p has been changed to %pp, and %pA formats a struct in_addr * as a.b.c.d , and %pI formats a struct sockaddr_in * as a.b.c.d:port. The reason for these strange-looking formats is to take advantage of gcc 's format string checking, which will make sure a %p corresponds to a pointer.
Copyright © 2001 O'Reilly & Associates. All rights reserved.