Asterisk - The Open Source Telephony Project
21.4.1
|
Utility functions. More...
#include "asterisk.h"
#include <ctype.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <unistd.h>
#include "asterisk/network.h"
#include "asterisk/ast_version.h"
#include "asterisk/lock.h"
#include "asterisk/io.h"
#include "asterisk/md5.h"
#include "asterisk/sha1.h"
#include "asterisk/cli.h"
#include "asterisk/linkedlists.h"
#include "asterisk/astobj2.h"
#include "asterisk/strings.h"
#include "asterisk/time.h"
#include "asterisk/utils.h"
#include "asterisk/threadstorage.h"
#include "asterisk/config.h"
#include "asterisk/alertpipe.h"
Go to the source code of this file.
Data Structures | |
struct | baseio |
Structure used for base64 encoding. More... | |
struct | thr_arg |
Macros | |
#define | AST_API_MODULE /* ensure that inlinable API functions will be built in lock.h if required */ |
#define | AST_API_MODULE /* ensure that inlinable API functions will be built in this module if required */ |
#define | AST_API_MODULE /* ensure that inlinable API functions will be built in this module if required */ |
#define | AST_API_MODULE /* ensure that inlinable API functions will be built in this module if required */ |
#define | AST_API_MODULE |
#define | AST_API_MODULE |
#define | AST_API_MODULE |
#define | BASELINELEN 72 |
#define | BASEMAXINLINE 256 |
#define | ONE_MILLION 1000000 |
Functions | |
void DO_CRASH_NORETURN | __ast_assert_failed (int condition, const char *condition_str, const char *file, int line, const char *function) |
int | __ast_fd_set_flags (int fd, int flags, enum ast_fd_flag_operation op, const char *file, int lineno, const char *function) |
static void | __init_inet_ntoa_buf (void) |
static void | __init_thread_user_interface_tl (void) |
A thread local indicating whether the current thread is a user interface. | |
int | ast_background_stacksize (void) |
int | ast_base64_encode_file (FILE *inputfile, FILE *outputfile, const char *endl) |
Performs a base 64 encode algorithm on the contents of a File. More... | |
int | ast_base64_encode_file_path (const char *filename, FILE *outputfile, const char *endl) |
Performs a base 64 encode algorithm on the contents of a File. More... | |
int | ast_base64decode (unsigned char *dst, const char *src, int max) |
decode BASE64 encoded text More... | |
char * | ast_base64decode_string (const char *src) |
Decode BASE64 encoded text and return the string. More... | |
int | ast_base64encode (char *dst, const unsigned char *src, int srclen, int max) |
Encode data in base64. More... | |
int | ast_base64encode_full (char *dst, const unsigned char *src, int srclen, int max, int linebreaks) |
encode text to BASE64 coding | |
char * | ast_base64encode_string (const char *src) |
Encode to BASE64 and return encoded string. More... | |
int | ast_base64url_decode (unsigned char *dst, const char *src, int max) |
Decode data from base64 URL. More... | |
char * | ast_base64url_decode_string (const char *src) |
Decode string from base64 URL. More... | |
int | ast_base64url_encode (char *dst, const unsigned char *src, int srclen, int max) |
Encode data in base64 URL. More... | |
int | ast_base64url_encode_full (char *dst, const unsigned char *src, int srclen, int max, int linebreaks) |
Same as ast_base64encode_full but for base64 URL. More... | |
char * | ast_base64url_encode_string (const char *src) |
Encode string in base64 URL. More... | |
int | ast_build_string (char **buffer, size_t *space, const char *fmt,...) |
Build a string in a buffer, designed to be called repeatedly. More... | |
int | ast_build_string_va (char **buffer, size_t *space, const char *fmt, va_list ap) |
Build a string in a buffer, designed to be called repeatedly. More... | |
int | ast_carefulwrite (int fd, char *s, int len, int timeoutms) |
Try to write string, but wait no more than ms milliseconds before timing out. More... | |
int | ast_check_command_in_path (const char *cmd) |
Test for the presence of an executable command in $PATH. More... | |
int | ast_check_ipv6 (void) |
Test that an OS supports IPv6 Networking. More... | |
int | ast_compare_versions (const char *version1, const char *version2) |
Compare 2 major.minor.patch.extra version strings. More... | |
void DO_CRASH_NORETURN | ast_do_crash (void) |
Force a crash if DO_CRASH is defined. More... | |
int | ast_eid_cmp (const struct ast_eid *eid1, const struct ast_eid *eid2) |
Compare two EIDs. More... | |
int | ast_eid_is_empty (const struct ast_eid *eid) |
Check if EID is empty. More... | |
char * | ast_eid_to_str (char *s, int maxlen, struct ast_eid *eid) |
Convert an EID to a string. More... | |
void | ast_enable_packet_fragmentation (int sock) |
Disable PMTU discovery on a socket. More... | |
char * | ast_escape (char *dest, const char *s, size_t size, const char *to_escape) |
Escape the 'to_escape' characters in the given string. More... | |
char * | ast_escape_alloc (const char *s, const char *to_escape) |
Escape the 'to_escape' characters in the given string. More... | |
char * | ast_escape_c (char *dest, const char *s, size_t size) |
Escape standard 'C' sequences in the given string. More... | |
char * | ast_escape_c_alloc (const char *s) |
Escape standard 'C' sequences in the given string. More... | |
char * | ast_escape_quoted (const char *string, char *outbuf, int buflen) |
Escape characters found in a quoted string. More... | |
char * | ast_escape_semicolons (const char *string, char *outbuf, int buflen) |
Escape semicolons found in a string. More... | |
int | ast_false (const char *s) |
Make sure something is false. Determine if a string containing a boolean value is "false". This function checks to see whether a string passed to it is an indication of an "false" value. It checks to see if the string is "no", "false", "n", "f", "off" or "0". More... | |
int | ast_file_is_readable (const char *filename) |
Test that a file exists and is readable by the effective user. More... | |
void | ast_format_duration_hh_mm_ss (int duration, char *buf, size_t length) |
Formats a duration into HH:MM:SS. More... | |
int | ast_get_tid (void) |
Get current thread ID. More... | |
int | ast_get_time_t (const char *src, time_t *dst, time_t _default, int *consumed) |
get values from config variables. More... | |
int | ast_get_timeval (const char *src, struct timeval *dst, struct timeval _default, int *consumed) |
get values from config variables. More... | |
struct hostent * | ast_gethostbyname (const char *host, struct ast_hostent *hp) |
Re-entrant (thread safe) version of gethostbyname that replaces the standard gethostbyname (which is not thread safe) More... | |
const char * | ast_inet_ntoa (struct in_addr ia) |
ast_inet_ntoa: Recursive thread safe replacement of inet_ntoa More... | |
void | ast_join_delim (char *s, size_t len, const char *const w[], unsigned int size, char delim) |
Join an array of strings into a single string. More... | |
void | ast_md5_hash (char *output, const char *input) |
Produce 32 char MD5 hash of value. More... | |
int | ast_mkdir (const char *path, int mode) |
Recursively create directory path. More... | |
int | ast_parse_digest (const char *digest, struct ast_http_digest *d, int request, int pedantic) |
Parse digest authorization header. More... | |
char * | ast_process_quotes_and_slashes (char *start, char find, char replace_with) |
Process a string to find and replace characters. More... | |
int | ast_pthread_create_detached_stack (pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *data, size_t stacksize, const char *file, const char *caller, int line, const char *start_fn) |
int | ast_pthread_create_stack (pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *data, size_t stacksize, const char *file, const char *caller, int line, const char *start_fn) |
long int | ast_random (void) |
int | ast_regex_string_to_regex_pattern (const char *regex_string, struct ast_str **regex_pattern) |
Given a string regex_string in the form of "/regex/", convert it into the form of "regex". More... | |
int | ast_remaining_ms (struct timeval start, int max_ms) |
Calculate remaining milliseconds given a starting timestamp and upper bound. More... | |
void | ast_replace_subargument_delimiter (char *s) |
Replace '^' in a string with ','. More... | |
int | ast_safe_mkdir (const char *base_path, const char *path, int mode) |
Recursively create directory path, but only if it resolves within the given base_path. More... | |
void | ast_set_default_eid (struct ast_eid *eid) |
Fill in an ast_eid with the default eid of this machine. More... | |
void | ast_sha1_hash (char *output, const char *input) |
Produce 40 char SHA1 hash of value. More... | |
void | ast_sha1_hash_uint (uint8_t *digest, const char *input) |
Produce a 20 byte SHA1 hash of value. More... | |
int | ast_str_to_eid (struct ast_eid *eid, const char *s) |
Convert a string into an EID. More... | |
char * | ast_strip_quoted (char *s, const char *beg_quotes, const char *end_quotes) |
Strip leading/trailing whitespace and quotes from a string. More... | |
char * | ast_strsep (char **iss, const char sep, uint32_t flags) |
Act like strsep but ignore separators inside quotes. More... | |
char * | ast_strsep_quoted (char **iss, const char sep, const char quote, uint32_t flags) |
Like ast_strsep() except you can specify a specific quote character. More... | |
int | ast_thread_is_user_interface (void) |
Indicates whether the current thread is a user interface. More... | |
int | ast_thread_user_interface_set (int is_user_interface) |
Set the current thread's user interface status. More... | |
char * | ast_to_camel_case_delim (const char *s, const char *delim) |
Attempts to convert the given string to camel case using the specified delimiter. More... | |
int | ast_true (const char *s) |
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1". More... | |
struct timeval | ast_tvadd (struct timeval a, struct timeval b) |
Returns the sum of two timevals a + b. | |
struct timeval | ast_tvsub (struct timeval a, struct timeval b) |
Returns the difference of two timevals a - b. | |
char * | ast_unescape_c (char *src) |
Convert some C escape sequences. More... | |
void | ast_unescape_quoted (char *quote_str) |
Unescape quotes in a string. More... | |
char * | ast_unescape_semicolon (char *s) |
Strip backslash for "escaped" semicolons, the string to be stripped (will be modified). More... | |
void | ast_uri_decode (char *s, struct ast_flags spec) |
Decode URI, URN, URL (overwrite string) More... | |
char * | ast_uri_encode (const char *string, char *outbuf, int buflen, struct ast_flags spec) |
Turn text string to URI-encoded XX version. More... | |
int | ast_utils_init (void) |
char * | ast_utils_which (const char *binary, char *fullpath, size_t fullpath_size) |
Resolve a binary to a full pathname. More... | |
int | ast_wait_for_input (int fd, int ms) |
int | ast_wait_for_output (int fd, int ms) |
int | ast_xml_escape (const char *string, char *const outbuf, const size_t buflen) |
Escape reserved characters for use in XML. More... | |
static void | base64_init (void) |
static void * | dummy_start (void *data) |
static char * | escape_alloc (const char *s, size_t *size) |
static int | inbuf (struct baseio *bio, FILE *fi) |
utility used by inchar(), for base_encode() | |
static int | inchar (struct baseio *bio, FILE *fi) |
utility used by base_encode() | |
static int | ochar (struct baseio *bio, int c, FILE *so, const char *endl) |
utility used by base_encode() | |
static int | safe_mkdir (const char *base_path, char *path, int mode) |
static struct timeval | tvfix (struct timeval a) |
static void | utils_shutdown (void) |
static int | wait_for_output (int fd, int timeoutms) |
Variables | |
const struct ast_flags | ast_uri_http = {AST_URI_UNRESERVED} |
const struct ast_flags | ast_uri_http_legacy = {AST_URI_LEGACY_SPACE | AST_URI_UNRESERVED} |
const struct ast_flags | ast_uri_sip_user = {AST_URI_UNRESERVED | AST_URI_SIP_USER_UNRESERVED} |
static char | b2a [256] |
static char | b2a_url [256] |
static char | base64 [64] |
static char | base64url [64] |
static int | dev_urandom_fd = -1 |
char | escape_sequences [] |
static char | escape_sequences_map [] |
static struct ast_threadstorage | inet_ntoa_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_inet_ntoa_buf , .custom_init = NULL , } |
static ast_mutex_t | randomlock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } |
static struct ast_threadstorage | thread_user_interface_tl = { .once = PTHREAD_ONCE_INIT , .key_init = __init_thread_user_interface_tl , .custom_init = NULL , } |
Utility functions.
Definition in file utils.c.
#define BASELINELEN 72 |
#define BASEMAXINLINE 256 |
Buffer size for Base 64 attachment encoding
Definition at line 576 of file utils.c.
Referenced by ast_base64_encode_file(), and inbuf().
int ast_base64_encode_file | ( | FILE * | inputfile, |
FILE * | outputfile, | ||
const char * | endl | ||
) |
Performs a base 64 encode algorithm on the contents of a File.
inputfile | A FILE handle to the input file to be encoded. Must be readable. This handle is not automatically closed. |
outputfile | A FILE handle to the output file to receive the base 64 encoded contents of the input file, identified by filename. |
endl | The line ending to use (e.g. either "\n" or "\r\n") |
Definition at line 648 of file utils.c.
References BASEMAXINLINE, inchar(), and ochar().
Referenced by ast_base64_encode_file_path().
int ast_base64_encode_file_path | ( | const char * | filename, |
FILE * | outputfile, | ||
const char * | endl | ||
) |
Performs a base 64 encode algorithm on the contents of a File.
filename | The path to the file to be encoded. Must be readable, file is opened in read mode. |
outputfile | A FILE handle to the output file to receive the base 64 encoded contents of the input file, identified by filename. |
endl | The line ending to use (e.g. either "\n" or "\r\n") |
Definition at line 702 of file utils.c.
References ast_base64_encode_file().
int ast_base64decode | ( | unsigned char * | dst, |
const char * | src, | ||
int | max | ||
) |
decode BASE64 encoded text
Decode data from base64.
Definition at line 296 of file utils.c.
Referenced by ast_base64decode_string(), ast_check_signature(), and ast_http_get_auth().
char* ast_base64decode_string | ( | const char * | src | ) |
Decode BASE64 encoded text and return the string.
Same as ast_base64decode, but does the math for you and returns a decoded string.
Definition at line 323 of file utils.c.
References ast_base64decode(), and ast_malloc.
int ast_base64encode | ( | char * | dst, |
const unsigned char * | src, | ||
int | srclen, | ||
int | max | ||
) |
Encode data in base64.
dst | the destination buffer |
src | the source data to be encoded |
srclen | the number of bytes present in the source buffer |
max | the maximum number of bytes to write into the destination buffer, including the terminating NULL character. |
Definition at line 406 of file utils.c.
References ast_base64encode_full().
Referenced by ast_base64encode_string(), ast_sign(), and xmpp_client_authenticate_sasl().
char* ast_base64encode_string | ( | const char * | src | ) |
Encode to BASE64 and return encoded string.
Same as ast_base64encode, but does hte math for you and returns an encoded string.
Definition at line 412 of file utils.c.
References ast_base64encode(), and ast_calloc.
int ast_base64url_decode | ( | unsigned char * | dst, |
const char * | src, | ||
int | max | ||
) |
Decode data from base64 URL.
dst | The destination buffer |
src | The source buffer |
max | The maximum number of bytes to write into the destination buffer. Note that this function will not ensure that the destination buffer is NULL terminated. So, in general, this parameter should be sizeof(dst) - 1 |
Definition at line 429 of file utils.c.
Referenced by ast_base64url_decode_string().
char* ast_base64url_decode_string | ( | const char * | src | ) |
Decode string from base64 URL.
src | The source buffer |
NULL | on failure |
Definition at line 450 of file utils.c.
References ast_base64url_decode(), and ast_malloc.
int ast_base64url_encode | ( | char * | dst, |
const unsigned char * | src, | ||
int | srclen, | ||
int | max | ||
) |
Encode data in base64 URL.
dst | The destination buffer |
src | The source data to be encoded |
srclen | The number of bytes present in the source buffer |
max | The maximum number of bytes to write into the destination buffer, including the terminating NULL character |
Definition at line 518 of file utils.c.
References ast_base64url_encode_full().
Referenced by ast_base64url_encode_string().
int ast_base64url_encode_full | ( | char * | dst, |
const unsigned char * | src, | ||
int | srclen, | ||
int | max, | ||
int | linebreaks | ||
) |
Same as ast_base64encode_full but for base64 URL.
dst | The destination buffer |
src | The source buffer |
srclen | The number of bytes present in the source buffer |
max | The maximum number of bytes to write into the destination buffer, including the terminating NULL character. |
linebreaks | Set to 1 if there should be linebreaks inserted in the result |
Definition at line 471 of file utils.c.
Referenced by ast_base64url_encode().
char* ast_base64url_encode_string | ( | const char * | src | ) |
Encode string in base64 URL.
src | The source data to be encoded |
NULL | on failure |
Definition at line 523 of file utils.c.
References ast_base64url_encode(), and ast_malloc.
int ast_build_string | ( | char ** | buffer, |
size_t * | space, | ||
const char * | fmt, | ||
... | |||
) |
Build a string in a buffer, designed to be called repeatedly.
This is a wrapper for snprintf, that properly handles the buffer pointer and buffer space available.
buffer | current position in buffer to place string into (will be updated on return) |
space | remaining space in buffer (will be updated on return) |
fmt | printf-style format string |
0 | on success |
non-zero | on failure. |
Definition at line 2167 of file utils.c.
References ast_build_string_va().
Referenced by generate_filenames_string().
int ast_build_string_va | ( | char ** | buffer, |
size_t * | space, | ||
const char * | fmt, | ||
va_list | ap | ||
) |
Build a string in a buffer, designed to be called repeatedly.
This is a wrapper for snprintf, that properly handles the buffer pointer and buffer space available.
zero | on success. |
non-zero | on failure. |
buffer | current position in buffer to place string into (will be updated on return) |
space | remaining space in buffer (will be updated on return) |
fmt | printf-style format string |
ap | varargs list of arguments for format |
Definition at line 2148 of file utils.c.
Referenced by ast_build_string().
int ast_carefulwrite | ( | int | fd, |
char * | s, | ||
int | len, | ||
int | timeoutms | ||
) |
Try to write string, but wait no more than ms milliseconds before timing out.
Try to write string, but wait no more than ms milliseconds before timing out.
Definition at line 1771 of file utils.c.
References ast_debug, ast_tvdiff_ms(), and ast_tvnow().
int ast_check_command_in_path | ( | const char * | cmd | ) |
Test for the presence of an executable command in $PATH.
cmd | Name of command to locate. |
True | (non-zero) if command is in $PATH. |
False | (zero) command not found. |
Definition at line 3263 of file utils.c.
References ast_strdup.
int ast_check_ipv6 | ( | void | ) |
Test that an OS supports IPv6 Networking.
True | (non-zero) if the IPv6 supported. |
False | (zero) if the OS doesn't support IPv6. |
Definition at line 2792 of file utils.c.
Referenced by load_module().
int ast_compare_versions | ( | const char * | version1, |
const char * | version2 | ||
) |
void DO_CRASH_NORETURN ast_do_crash | ( | void | ) |
Force a crash if DO_CRASH is defined.
Definition at line 2804 of file utils.c.
Referenced by optional_api_create(), and optional_api_user_create().
Compare two EIDs.
0 | if the two are the same |
non-zero | otherwise |
Definition at line 3094 of file utils.c.
Referenced by publish_cluster_discovery_to_stasis(), xmpp_pubsub_devstate_cb(), xmpp_pubsub_handle_event(), and xmpp_pubsub_mwi_cb().
int ast_eid_is_empty | ( | const struct ast_eid * | eid | ) |
Check if EID is empty.
1 | if the EID is empty |
0 | otherwise |
Definition at line 3099 of file utils.c.
Referenced by load_module().
char* ast_eid_to_str | ( | char * | s, |
int | maxlen, | ||
struct ast_eid * | eid | ||
) |
Convert an EID to a string.
Definition at line 2839 of file utils.c.
Referenced by app_send(), ast_ari_asterisk_get_info(), ast_ari_asterisk_ping(), ast_set_default_eid(), ast_str_retrieve_variable(), do_register(), do_register_expire(), handle_show_settings(), prometheus_config_post_apply(), publish_cluster_discovery_to_stasis_full(), publish_device_state_to_stasis(), publish_mwi_to_stasis(), xmpp_pubsub_publish_device_state(), and xmpp_pubsub_publish_mwi().
void ast_enable_packet_fragmentation | ( | int | sock | ) |
Disable PMTU discovery on a socket.
sock | The socket to manipulate |
On Linux, UDP sockets default to sending packets with the Dont Fragment (DF) bit set. This is supposedly done to allow the application to do PMTU discovery, but Asterisk does not do this.
Because of this, UDP packets sent by Asterisk that are larger than the MTU of any hop in the path will be lost. This function can be called on a socket to ensure that the DF bit will not be set.
Definition at line 2469 of file utils.c.
char* ast_escape | ( | char * | dest, |
const char * | s, | ||
size_t | size, | ||
const char * | to_escape | ||
) |
Escape the 'to_escape' characters in the given string.
dest | the escaped string |
s | the source string to escape |
size | The size of the destination buffer |
to_escape | an array of characters to escape |
Definition at line 2034 of file utils.c.
References ast_copy_string().
Referenced by ast_escape_alloc().
char* ast_escape_alloc | ( | const char * | s, |
const char * | to_escape | ||
) |
Escape the 'to_escape' characters in the given string.
s | the source string to escape |
to_escape | an array of characters to escape |
Definition at line 2132 of file utils.c.
References ast_escape().
char* ast_escape_c | ( | char * | dest, |
const char * | s, | ||
size_t | size | ||
) |
Escape standard 'C' sequences in the given string.
dest | the escaped string |
s | the source string to escape |
size | The size of the destination buffer |
Definition at line 2077 of file utils.c.
Referenced by ast_escape_c_alloc().
char* ast_escape_c_alloc | ( | const char * | s | ) |
Escape standard 'C' sequences in the given string.
s | the source string to escape |
Definition at line 2140 of file utils.c.
References ast_escape_c().
Referenced by ast_manager_build_channel_state_string_prefix().
char* ast_escape_quoted | ( | const char * | string, |
char * | outbuf, | ||
int | buflen | ||
) |
Escape characters found in a quoted string.
string | string to be escaped |
outbuf | resulting escaped string |
buflen | size of output buffer |
Definition at line 781 of file utils.c.
char* ast_escape_semicolons | ( | const char * | string, |
char * | outbuf, | ||
int | buflen | ||
) |
Escape semicolons found in a string.
string | string to be escaped |
outbuf | resulting escaped string |
buflen | size of output buffer |
Definition at line 811 of file utils.c.
Referenced by ast_config_text_file_save2(), and handle_cli_dialplan_save().
int ast_false | ( | const char * | val | ) |
Make sure something is false. Determine if a string containing a boolean value is "false". This function checks to see whether a string passed to it is an indication of an "false" value. It checks to see if the string is "no", "false", "n", "f", "off" or "0".
-1 | if "true". |
0 | otherwise, like NUL pointer. |
Definition at line 2216 of file utils.c.
Referenced by acf_faxopt_write(), bool_handler_fn(), boolflag_handler_fn(), build_peer(), build_user(), load_config(), manager_mute_mixmonitor(), parking_feature_flag_cfg(), reload_single_member(), rt_handle_member_record(), rtp_reload(), run_agi(), set_config(), and strings_to_mask().
int ast_file_is_readable | ( | const char * | filename | ) |
Test that a file exists and is readable by the effective user.
filename | File to test. |
True | (non-zero) if the file exists and is readable. |
False | (zero) if the file either doesn't exists or is not readable. |
Definition at line 3107 of file utils.c.
Referenced by ast_media_cache_retrieve(), and ast_rtp_dtls_cfg_parse().
void ast_format_duration_hh_mm_ss | ( | int | duration, |
char * | buf, | ||
size_t | length | ||
) |
Formats a duration into HH:MM:SS.
duration | The time (in seconds) to format |
buf | A buffer to hold the formatted string' |
length | The size of the buffer |
int ast_get_tid | ( | void | ) |
Get current thread ID.
Definition at line 2752 of file utils.c.
Referenced by ast_hangup().
int ast_get_time_t | ( | const char * | src, |
time_t * | dst, | ||
time_t | _default, | ||
int * | consumed | ||
) |
get values from config variables.
Parse a time (integer) string.
Definition at line 2446 of file utils.c.
Referenced by realtime_peer().
int ast_get_timeval | ( | const char * | src, |
struct timeval * | dst, | ||
struct timeval | _default, | ||
int * | consumed | ||
) |
get values from config variables.
Parse a time (float) string.
Definition at line 2419 of file utils.c.
Referenced by timeval_str2struct().
struct hostent* ast_gethostbyname | ( | const char * | host, |
struct ast_hostent * | hp | ||
) |
Re-entrant (thread safe) version of gethostbyname that replaces the standard gethostbyname (which is not thread safe)
Thread-safe gethostbyname function to use in Asterisk.
Definition at line 199 of file utils.c.
const char* ast_inet_ntoa | ( | struct in_addr | ia | ) |
ast_inet_ntoa: Recursive thread safe replacement of inet_ntoa
thread-safe replacement for inet_ntoa().
Definition at line 928 of file utils.c.
References ast_threadstorage_get().
Referenced by _stun_show_status(), ast_parse_arg(), rtp_add_candidates_to_ice(), rtp_reload(), score_address(), and stun_monitor_request().
void ast_join_delim | ( | char * | s, |
size_t | len, | ||
const char *const | w[], | ||
unsigned int | size, | ||
char | delim | ||
) |
Join an array of strings into a single string.
s | the resulting string buffer |
len | the length of the result buffer, s |
w | an array of strings to join. |
size | the number of elements to join |
delim | delimiter between elements |
This function will join all of the strings in the array 'w' into a single string. It will also place 'delim' in the result buffer in between each string from 'w'.
Definition at line 2378 of file utils.c.
void ast_md5_hash | ( | char * | output, |
const char * | input | ||
) |
int ast_mkdir | ( | const char * | path, |
int | mode | ||
) |
Recursively create directory path.
path | The directory path to create |
mode | The permissions with which to try to create the directory |
0 | on success |
Creates a directory path, creating parent directories as needed.
Definition at line 2479 of file utils.c.
References ast_alloca, and ast_strdupa.
Referenced by ast_file_fdtemp(), ast_logger_rotate_channel(), create_dirpath(), init_logger(), remove_from_queue(), setup_privacy_args(), sms_nextoutgoing(), and sms_writefile().
int ast_parse_digest | ( | const char * | digest, |
struct ast_http_digest * | d, | ||
int | request, | ||
int | pedantic | ||
) |
Parse digest authorization header.
Definition at line 2638 of file utils.c.
References ast_skip_blanks(), ast_str_buffer(), ast_str_create, ast_str_set(), ast_string_field_ptr_set, ast_string_field_set, and ast_unescape_c().
char* ast_process_quotes_and_slashes | ( | char * | start, |
char | find, | ||
char | replace_with | ||
) |
int ast_regex_string_to_regex_pattern | ( | const char * | regex_string, |
struct ast_str ** | regex_pattern | ||
) |
Given a string regex_string in the form of "/regex/", convert it into the form of "regex".
This function will trim one leading / and one trailing / from a given input string ast_str regex_pattern must be preallocated before calling this function
0 | on success, non-zero on failure. |
1 | if we only stripped a leading / |
2 | if we only stripped a trailing / |
3 | if we did not strip any / characters |
regex_string | the string containing /regex/ |
regex_pattern | the destination ast_str which will contain "regex" after execution |
Definition at line 2179 of file utils.c.
References ast_str_set(), and ast_str_truncate().
Referenced by ast_manager_hangup_helper().
int ast_remaining_ms | ( | struct timeval | start, |
int | max_ms | ||
) |
Calculate remaining milliseconds given a starting timestamp and upper bound.
If the upper bound is negative then this indicates that there is no upper bound on the amount of time to wait. This will result in a negative return.
start | When timing started being calculated |
max_ms | The maximum number of milliseconds to wait from start. May be negative. |
Definition at line 2281 of file utils.c.
References ast_tvdiff_ms(), and ast_tvnow().
Referenced by __ast_answer(), __ast_request_and_dial(), ast_iostream_write(), ast_recvtext(), ast_stun_request(), ast_waitfordigit_full(), generic_fax_exec(), parking_set_duration(), read_mf_digits(), read_sf_digits(), safe_sleep_conditional(), and wait_for_answer().
void ast_replace_subargument_delimiter | ( | char * | s | ) |
Replace '^' in a string with ','.
s | String within which to replace characters |
Definition at line 2343 of file utils.c.
Referenced by ast_bridge_set_after_go_on(), dial_exec_full(), and queue_exec().
int ast_safe_mkdir | ( | const char * | base_path, |
const char * | path, | ||
int | mode | ||
) |
Recursively create directory path, but only if it resolves within the given base_path.
If base_path does not exist, it will not be created and this function returns EPERM
.
base_path | |
path | The directory path to create |
mode | The permissions with which to try to create the directory |
0 | on success |
Definition at line 2584 of file utils.c.
References ast_strdup, and RAII_VAR.
Referenced by stasis_app_control_record().
void ast_set_default_eid | ( | struct ast_eid * | eid | ) |
Fill in an ast_eid with the default eid of this machine.
Definition at line 3001 of file utils.c.
References ast_debug, ast_eid_to_str(), and ast_malloc.
void ast_sha1_hash | ( | char * | output, |
const char * | input | ||
) |
Produce 40 char SHA1 hash of value.
Produces SHA1 hash based on input string.
Definition at line 266 of file utils.c.
References SHA1Input(), SHA1Reset(), and SHA1Result().
Referenced by ast_tcptls_server_start(), xmpp_client_authenticate_digest(), and xmpp_component_authenticate().
void ast_sha1_hash_uint | ( | uint8_t * | digest, |
const char * | input | ||
) |
Produce a 20 byte SHA1 hash of value.
Produces SHA1 hash based on input string, stored in uint8_t array.
Definition at line 284 of file utils.c.
References SHA1Input(), SHA1Reset(), and SHA1Result().
int ast_str_to_eid | ( | struct ast_eid * | eid, |
const char * | s | ||
) |
Convert a string into an EID.
This function expects an EID in the format: 00:11:22:33:44:55
0 | success |
non-zero | failure |
Definition at line 3077 of file utils.c.
Referenced by xmpp_pubsub_handle_event().
char* ast_strip_quoted | ( | char * | s, |
const char * | beg_quotes, | ||
const char * | end_quotes | ||
) |
Strip leading/trailing whitespace and quotes from a string.
s | The string to be stripped (will be modified). |
beg_quotes | The list of possible beginning quote characters. |
end_quotes | The list of matching ending quote characters. |
This functions strips all leading and trailing whitespace characters from the input string, and returns a pointer to the resulting string. The string is modified in place.
It can also remove beginning and ending quote (or quote-like) characters, in matching pairs. If the first character of the string matches any character in beg_quotes, and the last character of the string is the matching character in end_quotes, then they are removed from the string.
Examples:
Definition at line 1818 of file utils.c.
References ast_strip().
Referenced by ast_callerid_parse(), ast_strsep(), ast_strsep_quoted(), hfp_parse_clip(), and parse_dial_string().
char* ast_strsep | ( | char ** | s, |
const char | sep, | ||
uint32_t | flags | ||
) |
Act like strsep but ignore separators inside quotes.
s | Pointer to address of the string to be processed. Will be modified and can't be constant. |
sep | A single character delimiter. |
flags | Controls post-processing of the result. AST_STRSEP_TRIM trims all leading and trailing whitespace from the result. If the result containes only whitespace, it'll be passed through unchanged. AST_STRSEP_STRIP does a trim then strips the outermost quotes. You may want to trim again after the strip. Just OR both the TRIM and STRIP flags. AST_STRSEP_UNESCAPE unescapes '\' sequences. AST_STRSEP_ALL does all of the above processing. |
This function acts like strsep with three exceptions... The separator is a single character instead of a string. Separators inside quotes are treated literally instead of like separators. You can elect to have leading and trailing whitespace and quotes stripped from the result and have '\' sequences unescaped.
Like strsep, ast_strsep maintains no internal state and you can call it recursively using different separators on the same storage.
Also like strsep, for consistent results, consecutive separators are not collapsed so you may get an empty string as a valid result.
Examples:
Definition at line 1835 of file utils.c.
References ast_strip(), ast_strip_quoted(), AST_STRSEP_STRIP, AST_STRSEP_TRIM, AST_STRSEP_UNESCAPE, and ast_unescape_quoted().
Referenced by ast_app_getdata_terminator(), ast_sip_header_to_security_mechanism(), ast_sip_security_mechanism_vector_init(), ast_sip_str_to_security_mechanism(), does_category_match(), handle_updates(), and speech_background().
char* ast_strsep_quoted | ( | char ** | s, |
const char | sep, | ||
const char | quote, | ||
uint32_t | flags | ||
) |
Like ast_strsep() except you can specify a specific quote character.
s | Pointer to address of the string to be processed. Will be modified and can't be constant. |
sep | A single character delimiter. |
quote | The quote character |
flags | Controls post-processing of the result. AST_STRSEP_TRIM trims all leading and trailing whitespace from the result. AST_STRSEP_STRIP does a trim then strips the outermost quotes. You may want to trim again after the strip. Just OR both the TRIM and STRIP flags. AST_STRSEP_UNESCAPE unescapes '\' sequences. AST_STRSEP_ALL does all of the above processing. |
Definition at line 1899 of file utils.c.
References ast_strip(), ast_strip_quoted(), AST_STRSEP_STRIP, AST_STRSEP_TRIM, AST_STRSEP_UNESCAPE, and ast_unescape_quoted().
Referenced by ast_variable_list_from_quoted_string().
int ast_thread_is_user_interface | ( | void | ) |
Indicates whether the current thread is a user interface.
True | (non-zero) if thread is a user interface. |
False | (zero) if thread is not a user interface. |
Definition at line 3248 of file utils.c.
References ast_threadstorage_get().
Referenced by ast_autoservice_start(), and ast_autoservice_stop().
int ast_thread_user_interface_set | ( | int | is_user_interface | ) |
Set the current thread's user interface status.
is_user_interface | Non-zero to mark the thread as a user interface. |
True | (non-zero) if marking current thread failed. |
False | (zero) if successfuly marked current thread. |
Definition at line 3233 of file utils.c.
References ast_threadstorage_get().
Referenced by handle_tcptls_connection().
char* ast_to_camel_case_delim | ( | const char * | s, |
const char * | delim | ||
) |
Attempts to convert the given string to camel case using the specified delimiter.
note - returned string needs to be freed
s | the string to convert |
delim | delimiter to parse out |
Definition at line 2397 of file utils.c.
References ast_copy_string(), and ast_strdup.
int ast_true | ( | const char * | val | ) |
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
-1 | if "true". |
0 | otherwise, like NULL pointer. |
Definition at line 2199 of file utils.c.
Referenced by acf_faxopt_write(), action_status(), apply_general_options(), apply_option(), ast_ari_bridges_add_channel_cb(), ast_ari_bridges_record_cb(), ast_ari_channels_record_cb(), ast_ari_endpoints_refer_cb(), ast_ari_endpoints_refer_to_endpoint_cb(), ast_bridge_timelimit(), ast_jb_read_conf(), ast_rtp_dtls_cfg_parse(), ast_tls_read_conf(), bool_handler_fn(), boolflag_handler_fn(), build_calendar(), build_peer(), build_user(), custom_bitfield_handler(), encoding_format_handler(), func_mute_write(), init_logger_chain(), is_variable_true(), load_config(), manager_mute_mixmonitor(), mbl_load_adapter(), mbl_load_device(), new_realtime_sqlite3_db(), pbx_load_users(), permit_dtmf_interrupt(), pjsip_acf_moh_passthrough_write(), profile_set_param(), queue_rules_set_global_params(), queue_set_global_params(), queue_set_param(), reload_followme(), reload_single_member(), rt_handle_member_record(), rtp_reload(), run_agi(), set_config(), and strings_to_mask().
char* ast_unescape_c | ( | char * | s | ) |
Convert some C escape sequences.
(\b\f\n\r\t)
into the equivalent characters. The string to be converted (will be modified).
Definition at line 1983 of file utils.c.
Referenced by ast_parse_digest().
void ast_unescape_quoted | ( | char * | quote_str | ) |
Unescape quotes in a string.
quote_str | The string with quotes to be unescaped |
Definition at line 842 of file utils.c.
Referenced by ast_callerid_parse(), ast_strsep(), and ast_strsep_quoted().
char* ast_unescape_semicolon | ( | char * | s | ) |
Strip backslash for "escaped" semicolons, the string to be stripped (will be modified).
void ast_uri_decode | ( | char * | s, |
struct ast_flags | spec | ||
) |
Decode URI, URN, URL (overwrite string)
s | string to be decoded |
spec | flags describing how the decoding should be performed |
Definition at line 762 of file utils.c.
Referenced by ast_http_get_post_vars(), realtime_curl(), realtime_multi_curl(), and uridecode().
char* ast_uri_encode | ( | const char * | string, |
char * | outbuf, | ||
int | buflen, | ||
struct ast_flags | spec | ||
) |
Turn text string to URI-encoded XX version.
This function encodes characters according to the rules presented in RFC 2396 and/or RFC 3261 section 19.1.2 and section 25.1.
Outbuf needs to have more memory allocated than the instring to have room for the expansion. Every byte that is converted is replaced by three ASCII characters.
string | string to be converted |
outbuf | resulting encoded string |
buflen | size of output buffer |
spec | flags describing how the encoding should be performed |
Definition at line 723 of file utils.c.
Referenced by ast_ari_bridges_record(), ast_ari_channels_record(), destroy_curl(), realtime_curl(), realtime_multi_curl(), store_curl(), update_curl(), and uriencode().
char* ast_utils_which | ( | const char * | binary, |
char * | fullpath, | ||
size_t | fullpath_size | ||
) |
Resolve a binary to a full pathname.
binary | Name of the executable to resolve |
fullpath | Buffer to hold the complete pathname |
fullpath_size | Size of fullpath |
NULL | binary was not found or the environment variable PATH is not set |
Definition at line 2774 of file utils.c.
References ast_strdupa.
int ast_xml_escape | ( | const char * | string, |
char * | outbuf, | ||
size_t | buflen | ||
) |
Escape reserved characters for use in XML.
ast_xml_escape If outbuf is too short, the output string will be truncated. Regardless, the output will always be null terminated.
string | String to be converted |
outbuf | Resulting encoded string |
buflen | Size of output buffer |
0 | for success |
-1 | if buflen is too short. |
Definition at line 864 of file utils.c.
Referenced by ast_http_create_response().
char escape_sequences[] |