This is a set of application functions that can be useful not only within this project.
More...
|
| | List macros |
| | Lite list implementation from Linux kernel.
|
| |
| | String routines |
| | Functionality for creating SQL queries, making strong passwords, trimming a string if there are any space characters, parsing string as URL.
|
| |
| | Network routines |
| | HTTP server, HTTP client, socket functionality.
|
| |
| | Input/Output routines |
| | Functionality includes closing descriptors of current process, running server as a daemon, recursive remove of a directory or a file, opening and locking file, closing file.
|
| |
|
| #define | SHA1_STRING_LENGTH (SHA_DIGEST_LENGTH * 2 + 1) |
| | length of SHA1 string More...
|
| |
| #define | countof(x) (sizeof(x) / sizeof(x[0])) |
| | Calculate length of array. More...
|
| |
| #define | unused(x) ((void)x) |
| | Variable can be not used in Release build, to suppress compiler warning this macro should be used. More...
|
| |
| #define | min(a, b) |
| | return minimal number More...
|
| |
| #define | max(a, b) |
| | return maximum number More...
|
| |
| #define | cast_ptr(t, x) |
| | cast pointer More...
|
| |
|
| void | strdump (const void *str, size_t len) |
| | print pritable characters of buffer More...
|
| |
| void | hexdump8 (const void *buf, size_t len) |
| | print hexdump More...
|
| |
| void | cdump8 (const char *name, const void *buf, size_t len) |
| | print data like a C array More...
|
| |
| char * | read_env (const char *env, char *s, size_t len) |
| | read environment variable More...
|
| |
| char * | bin2hex (const void *data, size_t len, char *hex, size_t hex_len) |
| | convert binary data to hex string More...
|
| |
| size_t | hex2bin (const char *hex, void *data, size_t data_len) |
| | convert hex string to binary data More...
|
| |
| mailbox_t | mailbox_alloc (mailbox_t *mb, unsigned len) __attribute__((warn_unused_result)) |
| | allocate new mailbox More...
|
| |
| void | mailbox_destroy (mailbox_t mb) |
| | destroy mailbox More...
|
| |
| int | mailbox_post (mailbox_t mb, void *data) |
| | post message into mailbox More...
|
| |
| int | mailbox_wait (mailbox_t mb, void **data) |
| | retrive message from mailbox More...
|
| |
| int | mailbox_timedwait (mailbox_t mb, void **data, unsigned timeout) |
| | retrive message from mailbox with or wait for message More...
|
| |
| char * | mysql_vasprintf (MYSQL *mysql, char **str, const char *format, va_list args) |
| | allocate and format mysql query string More...
|
| |
| char * | mysql_asprintf (MYSQL *mysql, char **str, const char *format,...) |
| | allocate and format mysql query string More...
|
| |
| int | mysql_transaction (MYSQL *mysql) |
| | Start new transaction. More...
|
| |
| int | mysql_qprintf (MYSQL *mysql, const char *format,...) |
| | Send a MySQL query. More...
|
| |
| int | sha1_file (const char *path, sha1_t *hash) |
| | calculate SHA1 hash for specified file More...
|
| |
This is a set of application functions that can be useful not only within this project.
This set contains functionality for working with sockets, files, MySQL, strings, regular expressions, directories, etc.
| #define cast_ptr |
( |
|
t, |
|
|
|
x |
|
) |
| |
Value:__extension__ ({ \
(typeof(t)*)x; \
})
cast pointer
- Parameters
-
| [in] | t | target type |
| [in] | x | pointer |
| #define countof |
( |
|
x | ) |
(sizeof(x) / sizeof(x[0])) |
Calculate length of array.
Value:__extension__ ({ \
typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a < _b ? _b : _a; \
})
return maximum number
Value:__extension__ ({ \
typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a > _b ? _b : _a; \
})
return minimal number
| #define SHA1_STRING_LENGTH (SHA_DIGEST_LENGTH * 2 + 1) |
| #define unused |
( |
|
x | ) |
((void)x) |
Variable can be not used in Release build, to suppress compiler warning this macro should be used.
| typedef uint8_t sha1_t[SHA_DIGEST_LENGTH] |
variable type for storing SHA1 hash
| char* bin2hex |
( |
const void * |
data, |
|
|
size_t |
len, |
|
|
char * |
hex, |
|
|
size_t |
hex_len |
|
) |
| |
convert binary data to hex string
- Parameters
-
| [in] | data | pointer to binary data |
| [in] | len | length of binary data |
| [out] | hex | pointer to result buffer |
| [in] | hex_len | length of buffet at pointer hex |
- Returns
- pointer to hex string
- Return values
-
| void cdump8 |
( |
const char * |
name, |
|
|
const void * |
buf, |
|
|
size_t |
len |
|
) |
| |
print data like a C array
- Parameters
-
| [in] | name | name of C array |
| [in] | buf | pointer to data |
| [in] | len | length of data |
| size_t hex2bin |
( |
const char * |
hex, |
|
|
void * |
data, |
|
|
size_t |
data_len |
|
) |
| |
convert hex string to binary data
- Parameters
-
| [in] | hex | pointer to string with hex numbers |
| [out] | data | pointer to data buffer |
| [in] | data_len | length of data buffer at pointer data |
- Returns
- length of converted data
| void hexdump8 |
( |
const void * |
buf, |
|
|
size_t |
len |
|
) |
| |
print hexdump
- Parameters
-
| [in] | buf | pointer to data |
| [in] | len | length of data |
allocate new mailbox
- Parameters
-
| [out] | mb | pointer to new mailbox |
| [in] | len | length of mailbox |
- Returns
- pointer to new mailbox
- Return values
-
Function update errno if error occurred.
destroy mailbox
- Parameters
-
If mailbox is NULL, no operation is performed.
| int mailbox_post |
( |
mailbox_t |
mb, |
|
|
void * |
data |
|
) |
| |
post message into mailbox
- Parameters
-
| [in] | mb | pointer to mailbox |
| [in] | data | message |
- Returns
- on success, zero is returned
- Return values
-
If the mailbox is full, the function will wait for the availability of space.
| int mailbox_timedwait |
( |
mailbox_t |
mb, |
|
|
void ** |
data, |
|
|
unsigned |
timeout |
|
) |
| |
retrive message from mailbox with or wait for message
- Parameters
-
| [in] | mb | pointer to mailbox |
| [out] | data | message |
| [in] | timeout | timeout for message |
- Returns
- on success, zero is returned
- Return values
-
If the mailbox is empty, the function will wait for message until timeout expired.
| int mailbox_wait |
( |
mailbox_t |
mb, |
|
|
void ** |
data |
|
) |
| |
retrive message from mailbox
- Parameters
-
| [in] | mb | pointer to mailbox |
| [out] | data | message |
- Returns
- on success, zero is returned
- Return values
-
If the mailbox is empty, the function will wait for message.
| char* mysql_asprintf |
( |
MYSQL * |
mysql, |
|
|
char ** |
str, |
|
|
const char * |
format, |
|
|
|
... |
|
) |
| |
allocate and format mysql query string
- Parameters
-
| [in] | mysql | mysql connection handle |
| [out] | str | mysql query string |
| [in] | format | format of output string |
- Returns
- pointer to allocated string
- Return values
-
This function is similar to asprintf(), but has another string format. Next interpreted sequences supported:
- %int% argument is integer
- %double% argument is double
- %bool% same as %int%, boolean
- %str% NULL-terminated string, can be NULL
- %time% unix time, time_t
- %% one character '%'
Zero %int% values, empty or NULL strings (%str%) serialized to SQL NULL. Boolean values serialized to TRUE (!= 0) or FALSE (0)
Next sequences never serialized to NULL:
- %INT% argument is integer
- %DOUBLE% argument is double
- %STR% NULL-terminated string, can be NULL
- %RSTR% string without quotes
Function updates errno, if error occurred:
- EINVAL argument
format have invalid interpreted sequences
| int mysql_qprintf |
( |
MYSQL * |
mysql, |
|
|
const char * |
format, |
|
|
|
... |
|
) |
| |
Send a MySQL query.
- Parameters
-
| [in] | mysql | mysql connection handle |
| [in] | format | mysql query string |
- Returns
- on success, zero is returned
- Return values
-
- See also
- mysql_asprintf
Function update errno, if error occurred:
- EIO I/O error (in most cases MySQL error)
| int mysql_transaction |
( |
MYSQL * |
mysql | ) |
|
Start new transaction.
- Parameters
-
| [in] | mysql | connection handle |
- Returns
- on success, zero is returned
- Return values
-
| char* mysql_vasprintf |
( |
MYSQL * |
mysql, |
|
|
char ** |
str, |
|
|
const char * |
format, |
|
|
va_list |
args |
|
) |
| |
allocate and format mysql query string
- Parameters
-
| [in] | mysql | mysql connection handle |
| [out] | str | mysql query string |
| [in] | format | format of output string |
- Returns
- pointer to allocated string
- Return values
-
This function is similar to asprintf(), but has another string format. Next interpreted sequences supported:
- %int% argument is integer
- %double% argument is double
- %bool% same as %int%, boolean
- %str% NULL-terminated string, can be NULL
- %time% unix time, time_t
- %% one character '%'
Zero %int% values, empty or NULL strings (%str%) serialized to SQL NULL. Boolean values serialized to TRUE (!= 0) or FALSE (0)
Next sequences never serialized to NULL:
- %INT% argument is integer
- %DOUBLE% argument is double
- %STR% NULL-terminated string, can be NULL
- %RSTR% string without quotes
Function updates errno, if error occurred:
- EINVAL argument
format have invalid interpreted sequences - Parameters
-
| [in] | args | list of arguments |
| char* read_env |
( |
const char * |
env, |
|
|
char * |
s, |
|
|
size_t |
len |
|
) |
| |
read environment variable
- Parameters
-
| [in] | env | variable name |
| [in] | s | pointer to string buffer |
| [in] | len | length of buffer at s |
- Returns
- pointer to string buffer
s
- Return values
-
| NULL | environment variable don't exist |
| int sha1_file |
( |
const char * |
path, |
|
|
sha1_t * |
hash |
|
) |
| |
calculate SHA1 hash for specified file
- Parameters
-
| [in] | path | filename |
| [out] | hash | SHA1 hash sum |
- Returns
- on success, zero is returned
- Return values
-
| void strdump |
( |
const void * |
str, |
|
|
size_t |
len |
|
) |
| |
print pritable characters of buffer
- Parameters
-
| [in] | str | pointer to buffer |
| [in] | len | length |