Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals

Utility functions


Functions

int u_asctime_to_tt (const char *str, time_t *tp)
 Convert an asctime(3) string to time_t.
int u_rfc850_to_tt (const char *str, time_t *tp)
 Convert an rfc850 time string to time_t.
int u_rfc822_to_tt (const char *str, time_t *tp)
 Convert an rfc822 time string to time_t.
int u_httpdate_to_tt (const char *str, time_t *tp)
 Convert an HTTP time string to time_t.
int u_tt_to_rfc822 (char dst[], time_t ts)
 Convert a time_t value to a rfc822 time string.
ssize_t u_urlncpy (char *dst, const char *src, size_t slen, int flags)
 Copy and URL escape/unescape a given string.
ssize_t u_hexncpy (char *dst, const char *src, size_t slen, int flags)
 Copy and HEX encode/decode a given string.
ssize_t u_htmlncpy (char *dst, const char *src, size_t slen, int flags)
 Copy and HTML escape/unescape a given string.
ssize_t u_sqlncpy (char *dst, const char *src, size_t slen, int flags)
 Copy and SQL escape/unescape a given string.
void u_tohex (char *hex, const char *src, size_t sz)
 Convert a given string in hexadecimal representation.
char u_tochex (int n)
int u_md5 (char *buf, size_t sz, char out[MD5_DIGEST_BUFSZ])
 Calculate the MD5 digest over a given buffer.
int u_md5io (io_t *io, char out[MD5_DIGEST_BUFSZ])
 Calculate the MD5 hash over an io_t stream.
const char * u_guess_mime_type (const char *file_name)
 Guess the MIME type of a file.
const mime_map_tu_get_mime_map (const char *file_name)
 Get the MIME type of a file.
int u_match_ext (const char *filename, const char *extension)
 Match filename extension.
int u_path_normalize (char *fqn)
 Removes /./, /../ and // from the path.
const char * klone_version (void)
 Return KLone version string (x.y.z).

Variables

const char * days3 []
const char * days []
const char * months []

Detailed Description


Function Documentation

int u_asctime_to_tt const char *  str,
time_t *  tp
 

Convert the asctime(3) string str to its time_t representation tp.

Parameters:
str the string to be converted
tp the time_t conversion of str as a value-result argument
Returns:
  • 0 successful
  • ~0 failure

Definition at line 66 of file date.c.

Referenced by u_httpdate_to_tt().

int u_rfc850_to_tt const char *  str,
time_t *  tp
 

Convert the rfc850 string str to its time_t representation tp.

Parameters:
str the string to be converted
tp the time_t conversion of str as a value-result argument
Returns:
  • 0 successful
  • ~0 failure

Definition at line 112 of file date.c.

Referenced by u_httpdate_to_tt().

int u_rfc822_to_tt const char *  str,
time_t *  tp
 

Convert the rfc822 string str to its time_t representation tp.

Parameters:
str the string to be converted
tp the time_t conversion of str as a value-result argument
Returns:
  • 0 successful
  • ~0 failure

Definition at line 164 of file date.c.

Referenced by u_httpdate_to_tt().

int u_httpdate_to_tt const char *  str,
time_t *  tp
 

Convert the HTTP time string str to its time_t representation tp.

Parameters:
str the string to be converted
tp the time_t conversion of str as a value-result argument
Returns:
  • 0 successful
  • ~0 failure

Definition at line 214 of file date.c.

References u_asctime_to_tt(), u_rfc822_to_tt(), and u_rfc850_to_tt().

int u_tt_to_rfc822 char  dst[],
time_t  ts
 

Convert the time_t value ts to a rfc822 time string

Parameters:
dst placeholder for the rfc822 time string. The buffer, of at least RFC822_DATE_BUFSZ bytes, must be preallocated by the caller.
ts the time_t value to be converted
Returns:
  • 0 successful
  • ~0 failure

Definition at line 242 of file date.c.

References days3, and months.

Referenced by response_set_cookie(), response_set_date(), and response_set_last_modified().

ssize_t u_urlncpy char *  d,
const char *  s,
size_t  slen,
int  flags
 

Copy an URL escaped/unescaped version of string s, depending on flags value, into d. The destination string is NULL terminated. The destination string d must be at least slen + 1 bytes long.

Parameters:
d the encoded/decoded string
s string to process
slen length of s
flags one of URLCPY_ENCODE or URLCPY_DECODE
Returns:
The number of characters written to d not including the trailing '\0' or -1 on error.

Definition at line 418 of file utils.c.

Referenced by response_set_cookie(), and vars_add_urlvar().

ssize_t u_hexncpy char *  d,
const char *  s,
size_t  slen,
int  flags
 

Copy an HEX encoded/decoded version of string s, depending on flags value, into d. The destination string d, which must be at least slen + 1 bytes long, is NULL terminated.

Parameters:
d the encoded/decoded string
s string to process
slen length of s
flags one of HEXCPY_ENCODE or HEXCPY_DECODE
Returns:
The number of characters written to d not including the trailing '\0' or -1 on error.

Definition at line 521 of file utils.c.

ssize_t u_htmlncpy char *  d,
const char *  s,
size_t  slen,
int  flags
 

Copy an HTML escaped/unescaped version of string s, depending on flags value, into d. The destination string is NULL terminated. The destination string d must be at least slen + 1 bytes long.

Parameters:
d the encoded/decoded string
s string to process
slen length of s
flags one of HTMLCPY_ENCODE or HTMLCPY_DECODE
Returns:
The number of characters written to d not including the trailing '\0' or -1 on error.

Definition at line 618 of file utils.c.

ssize_t u_sqlncpy char *  d,
const char *  s,
size_t  slen,
int  flags
 

Copy and SQL escape/unescape, depending on flags value, the string s into d. The destination string, which must be at least slen + 1 bytes long, is NULL terminated.

Parameters:
d the encoded/decoded string
s string to process
slen length of s
flags one of SQLCPY_ENCODE or SQLCPY_DECODE
Returns:
The number of characters written to d not including the trailing '\0' or -1 on error.

Definition at line 320 of file utils.c.

void u_tohex char *  hex,
const char *  src,
size_t  sz
 

Convert the string src of lenght sz into its hexadecimal representation hex. The string hex must be at least 2 * sz long.

Parameters:
hex the string holding the hexadecimal conversion of src
src the string that has to be converted
sz the length of src
Returns:
nothing

Definition at line 928 of file utils.c.

References u_tochex().

Referenced by u_md5(), and u_md5io().

int u_md5 char *  buf,
size_t  sz,
char  out[MD5_DIGEST_BUFSZ]
 

Calculate the MD5 digest over the supplied buffer buf of size sz and place it at out.

Parameters:
buf the buffer to be hashed
sz length in bytes of buf
out hexadecimal string containing the MD5 hash calculated over buf. It must be at least MD5_DIGEST_BUFSZ bytes long.
Returns:
  • 0 always successful

Definition at line 958 of file utils.c.

References u_tohex().

int u_md5io io_t io,
char  out[MD5_DIGEST_BUFSZ]
 

Calculate the MD5 hash over an io_t stream io and place the result as an hexadecimal string into out.

Parameters:
io the io_t stream to be hashed
out hexadecimal string containing the MD5 hash calculated over buf. It must be at least MD5_DIGEST_BUFSZ bytes long.
Returns:
  • 0 successful
  • ~0 error

Definition at line 990 of file utils.c.

References io_read(), and u_tohex().

const char * u_guess_mime_type const char *  file_name  ) 
 

Guess the MIME type of the given file file_name by its extension

Parameters:
file_name the path of the file
Returns:
the string corresponding to the guessed MIME type, or "application/octet-stream" in case no map could be found

Definition at line 1080 of file utils.c.

References mime_map_s::ext, and mime_map_s::mime_type.

const mime_map_t * u_get_mime_map const char *  file_name  ) 
 

Get the MIME type of the given file file_name by its extension

Parameters:
file_name the path of the file
Returns:
the found MIME map, or the first map if no match could be found

Definition at line 1048 of file utils.c.

References mime_map_s::ext, and mime_map_s::mime_type.

int u_match_ext const char *  filename,
const char *  extension
 

Return 1 if the filename externsion is equal to extension (case-insensitive comparison).

Parameters:
filename file name
extension file extension to match
Returns:
  • 1 if filename extension is extension
  • 0 if filename extension is not equal to extension

Definition at line 215 of file utils.c.

int u_path_normalize char *  path  ) 
 

Clean ups a path removing /./, /../ and multiple consecutive slashes from the given path.

Note that the function modifies the 'path' buffer.

Parameters:
path the path to normalize
Returns:
  • 0 successful
  • ~0 error

Definition at line 34 of file path.c.

const char* klone_version void   ) 
 

Return KLone version string in the format x.y.z.

Returns:
the version string

Definition at line 30 of file version.c.