Asterisk - The Open Source Telephony Project
18.5.0
|
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 | lock_infos |
A list of each thread's lock info. More... | |
struct | thr_arg |
struct | thr_lock_info |
Keep track of which locks a thread holds. More... | |
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 | AST_MAX_LOCKS 64 |
A reasonable maximum number of locks a thread would be holding ... More... | |
#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_lock_info (void) |
The thread storage key for per-thread lock info. More... | |
static void | __init_thread_user_interface_tl (void) |
A thread local indicating whether the current thread is a user interface. More... | |
static void | append_backtrace_information (struct ast_str **str, struct ast_bt *bt) |
static void | append_lock_information (struct ast_str **str, struct thr_lock_info *lock_info, int i) |
int | ast_background_stacksize (void) |
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 More... | |
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_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... | |
struct ast_str * | ast_dump_locks (void) |
Generate a lock dump equivalent to "core show locks". 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... | |
int | ast_find_lock_info (void *lock_addr, char *filename, size_t filename_size, int *lineno, char *func, size_t func_size, char *mutex_name, size_t mutex_name_size) |
retrieve lock info for the specified mutex 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) |
void | ast_log_show_lock (void *this_lock_addr) |
log info for the current lock with ast_log(). More... | |
void | ast_mark_lock_acquired (void *lock_addr) |
Mark the last lock as acquired. More... | |
void | ast_mark_lock_failed (void *lock_addr) |
Mark the last lock as failed (trylock) 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_remove_lock_info (void *lock_addr, struct ast_bt *bt) |
remove lock info for the current thread More... | |
void | ast_replace_subargument_delimiter (char *s) |
Replace '^' in a string with ','. More... | |
void | ast_restore_lock_info (void *lock_addr) |
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... | |
void | ast_store_lock_info (enum ast_lock_type type, const char *filename, int line_num, const char *func, const char *lock_name, void *lock_addr, struct ast_bt *bt) |
Store lock info for the current thread. 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... | |
void | ast_suspend_lock_info (void *lock_addr) |
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) |
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. More... | |
struct timeval | ast_tvsub (struct timeval a, struct timeval b) |
Returns the difference of two timevals a - b. More... | |
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 char * | handle_show_locks (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static void | lock_info_destroy (void *data) |
Destroy a thread's lock info. More... | |
static const char * | locktype2str (enum ast_lock_type type) |
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 struct lock_infos | lock_infos = { .first = NULL, .last = NULL, } |
static ast_mutex_t | lock_infos_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } |
Locked when accessing the lock_infos list. More... | |
static ast_mutex_t | randomlock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } |
static struct ast_threadstorage | thread_lock_info = { .once = PTHREAD_ONCE_INIT , .key_init = __init_thread_lock_info , .custom_init = NULL , } |
static struct ast_threadstorage | thread_user_interface_tl = { .once = PTHREAD_ONCE_INIT , .key_init = __init_thread_user_interface_tl , .custom_init = NULL , } |
static struct ast_cli_entry | utils_cli [] |
Utility functions.
Definition in file main/utils.c.
#define AST_API_MODULE /* ensure that inlinable API functions will be built in lock.h if required */ |
Definition at line 70 of file main/utils.c.
#define AST_API_MODULE /* ensure that inlinable API functions will be built in this module if required */ |
Definition at line 70 of file main/utils.c.
#define AST_API_MODULE /* ensure that inlinable API functions will be built in this module if required */ |
Definition at line 70 of file main/utils.c.
#define AST_API_MODULE /* ensure that inlinable API functions will be built in this module if required */ |
Definition at line 70 of file main/utils.c.
#define AST_API_MODULE |
Definition at line 70 of file main/utils.c.
#define AST_API_MODULE |
Definition at line 70 of file main/utils.c.
#define AST_API_MODULE |
Definition at line 70 of file main/utils.c.
#define AST_MAX_LOCKS 64 |
A reasonable maximum number of locks a thread would be holding ...
Definition at line 802 of file main/utils.c.
Referenced by ast_store_lock_info().
#define ONE_MILLION 1000000 |
Definition at line 1985 of file main/utils.c.
Referenced by ast_tvadd(), ast_tvsub(), and tvfix().
void DO_CRASH_NORETURN __ast_assert_failed | ( | int | condition, |
const char * | condition_str, | ||
const char * | file, | ||
int | line, | ||
const char * | function | ||
) |
Definition at line 2564 of file main/utils.c.
References __LOG_ERROR, ast_do_crash(), ast_log, and ast_log_backtrace().
Referenced by __ao2_container_clone(), __ao2_iterator_next(), __ao2_link(), __ao2_ref(), _ast_assert(), internal_ao2_traverse(), and log_bad_ao2().
int __ast_fd_set_flags | ( | int | fd, |
int | flags, | ||
enum ast_fd_flag_operation | op, | ||
const char * | file, | ||
int | lineno, | ||
const char * | function | ||
) |
Definition at line 2898 of file main/utils.c.
References __LOG_ERROR, ast_assert, AST_FD_FLAG_CLEAR, AST_FD_FLAG_SET, ast_fd_set_flags, ast_log, ast_pipe_nonblock, ast_socket_nonblock, errno, and thr_lock_info::type.
|
static |
Definition at line 83 of file main/utils.c.
|
static |
|
static |
A thread local indicating whether the current thread is a user interface.
Definition at line 2979 of file main/utils.c.
Definition at line 1147 of file main/utils.c.
References ast_bt::addresses, ast_bt_free_symbols, ast_bt_get_symbols, ast_str_append(), AST_VECTOR_GET, AST_VECTOR_SIZE, and ast_bt::num_frames.
Referenced by append_lock_information().
|
static |
Definition at line 1174 of file main/utils.c.
References append_backtrace_information(), AST_MUTEX, ast_reentrancy_lock(), ast_reentrancy_unlock(), ast_str_append(), thr_lock_info::backtrace, ast_lock_track::file, thr_lock_info::file, ast_lock_track::func, thr_lock_info::func, thr_lock_info::line_num, ast_lock_track::lineno, thr_lock_info::lock, thr_lock_info::lock_addr, thr_lock_info::lock_name, thr_lock_info::locks, locktype2str(), thr_lock_info::pending, ast_lock_track::reentrancy, thr_lock_info::suspended, thr_lock_info::times_locked, ast_mutex_info::track, and thr_lock_info::type.
Referenced by ast_dump_locks(), and ast_log_show_lock().
int ast_background_stacksize | ( | void | ) |
int ast_base64decode | ( | unsigned char * | dst, |
const char * | src, | ||
int | max | ||
) |
decode BASE64 encoded text
Decode data from base64.
Definition at line 294 of file main/utils.c.
References b2a.
Referenced by action_messagesend(), aes_helper(), ast_base64decode_string(), ast_check_signature(), ast_http_get_auth(), AST_TEST_DEFINE(), base64_helper(), crypto_init_keys(), custom_presence_callback(), osp_validate_token(), presence_write(), and res_sdp_crypto_parse_offer().
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 321 of file main/utils.c.
References ast_base64decode(), ast_malloc, ast_strlen_zero, and NULL.
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 404 of file main/utils.c.
References ast_base64encode_full().
Referenced by aes_helper(), ast_base64encode_string(), ast_sign(), AST_TEST_DEFINE(), base64_helper(), build_secret(), crypto_init_keys(), osp_check_destination(), presence_read(), websocket_client_create_key(), websocket_combine_key(), and xmpp_client_authenticate_sasl().
int ast_base64encode_full | ( | char * | dst, |
const unsigned char * | src, | ||
int | srclen, | ||
int | max, | ||
int | linebreaks | ||
) |
encode text to BASE64 coding
Definition at line 353 of file main/utils.c.
Referenced by ast_base64encode().
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 410 of file main/utils.c.
References ast_base64encode(), ast_calloc, ast_strlen_zero, and NULL.
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 427 of file main/utils.c.
References b2a_url.
Referenced by ast_base64url_decode_string(), and stir_shaken_verify_signature().
char* ast_base64url_decode_string | ( | const char * | src | ) |
Decode string from base64 URL.
src | The source buffer |
NULL | on failure |
Decoded | string on success |
Definition at line 448 of file main/utils.c.
References ast_base64url_decode(), ast_malloc, ast_strlen_zero, and NULL.
Referenced by stir_shaken_incoming_request().
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 516 of file main/utils.c.
References ast_base64url_encode_full().
Referenced by ast_base64url_encode_string(), and stir_shaken_sign().
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 469 of file main/utils.c.
References base64url, and max.
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 |
Encoded | string on success |
Definition at line 521 of file main/utils.c.
References ast_base64url_encode(), ast_malloc, ast_strlen_zero, and NULL.
Referenced by add_identity_header().
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 1919 of file main/utils.c.
References ast_build_string_va(), and result.
Referenced by ast_fax_caps_to_str(), generate_filenames_string(), handle_speechrecognize(), pp_each_extension_helper(), and vm_allocate_dh().
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.
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 1900 of file main/utils.c.
References result.
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 1592 of file main/utils.c.
References ast_debug, ast_log, ast_tvdiff_ms(), ast_tvnow(), errno, LOG_ERROR, and wait_for_output().
Referenced by ast_agi_send(), AST_VECTOR(), and cleanup_module().
int ast_check_ipv6 | ( | void | ) |
Test that an OS supports IPv6 Networking.
Definition at line 2540 of file main/utils.c.
Referenced by load_module().
int ast_compare_versions | ( | const char * | version1, |
const char * | version2 | ||
) |
Compare 2 major.minor.patch.extra version strings.
version1. | |
version2. |
Definition at line 2872 of file main/utils.c.
Referenced by transport_apply().
void DO_CRASH_NORETURN ast_do_crash | ( | void | ) |
Force a crash if DO_CRASH is defined.
Definition at line 2552 of file main/utils.c.
Referenced by __ast_assert_failed(), _ast_assert(), ast_optional_api_use(), optional_api_create(), optional_api_user_create(), and sip_route_process_header().
struct ast_str* ast_dump_locks | ( | void | ) |
Generate a lock dump equivalent to "core show locks".
The lock dump generated is generally too large to be output by a single ast_verbose/log/debug/etc. call. Only ast_cli() handles it properly without changing BUFSIZ in logger.c.
Note: This must be ast_free()d when you're done with it.
An | ast_str containing the lock dump |
NULL | on error |
Definition at line 1264 of file main/utils.c.
References append_lock_information(), ast_get_version(), AST_LIST_TRAVERSE, ast_str_append(), ast_str_create, thr_lock_info::lock, lock_info, lock_infos_lock, thr_lock_info::locks, thr_lock_info::lwp, ast_mutex_info::mutex, NULL, thr_lock_info::num_locks, pthread_mutex_lock, pthread_mutex_unlock, str, thr_lock_info::suspended, thr_lock_info::thread_id, and thr_lock_info::thread_name.
Referenced by handle_show_locks().
Compare two EIDs.
Definition at line 2842 of file main/utils.c.
Referenced by AST_TEST_DEFINE(), asterisk_publisher_devstate_cb(), asterisk_publisher_mwistate_cb(), build_peer(), build_transactions(), cache_entry_by_eid(), cache_entry_create(), cache_remove(), cache_udpate(), clear_node_cache(), cpg_deliver_cb(), destroy_trans(), dundi_answer_entity(), dundi_answer_query(), dundi_ie_append_eid_appropriately(), dundi_lookup_internal(), dundi_prop_precache(), dundi_query_thread(), find_peer(), handle_command_response(), optimize_transactions(), publish_cluster_discovery_to_stasis(), publish_to_corosync(), register_request(), state_find_and_remove_eid(), state_find_or_add_eid(), 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.
Definition at line 2847 of file main/utils.c.
Referenced by load_module(), and set_config().
char* ast_eid_to_str | ( | char * | s, |
int | maxlen, | ||
struct ast_eid * | eid | ||
) |
Convert an EID to a string.
Definition at line 2587 of file main/utils.c.
References ast_debug, ast_free, ast_log, ast_malloc, ast_set_default_eid(), buf, ast_eid::eid, LOG_WARNING, and NULL.
Referenced by app_send(), append_transaction(), ast_ari_asterisk_get_info(), ast_ari_asterisk_ping(), ast_set_default_eid(), ast_str_retrieve_variable(), AST_TEST_DEFINE(), asterisk_publication_send_refresh(), asterisk_publisher_devstate_cb(), asterisk_publisher_mwistate_cb(), bridges_scrape_cb(), build_peer(), build_transactions(), cache_lookup(), cache_lookup_internal(), channels_scrape_cb(), check_key(), complete_peer_helper(), cpg_deliver_cb(), destroy_trans(), do_autokill(), do_register(), do_register_expire(), dump_answer(), dump_eid(), dundi_answer_entity(), dundi_lookup_internal(), dundi_lookup_local(), dundi_lookup_thread(), dundi_precache_thread(), dundi_prop_precache(), dundi_query_thread(), dundi_send(), dundi_show_cache(), dundi_show_entityid(), dundi_show_hints(), dundi_show_peer(), dundi_show_peers(), dundi_show_requests(), endpoints_scrape_cb(), handle_command_response(), handle_show_settings(), populate_addr(), prometheus_config_post_apply(), publish_cluster_discovery_to_stasis_full(), publish_device_state_to_stasis(), publish_mwi_to_stasis(), publish_to_corosync(), register_request(), registry_message_cb(), update_key(), 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 2221 of file main/utils.c.
References ast_log, and LOG_WARNING.
Referenced by ast_netsock_bindaddr(), and reload_config().
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 1786 of file main/utils.c.
References ast_copy_string(), ast_strlen_zero, c, and escape_sequences.
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 1884 of file main/utils.c.
References ast_escape(), and escape_alloc().
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 1829 of file main/utils.c.
References ast_strlen_zero, c, and escape_sequences.
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 1892 of file main/utils.c.
References ast_escape_c(), and escape_alloc().
Referenced by ast_manager_build_channel_state_string_prefix(), channel_new_callerid(), presence_state_to_ami(), and varset_to_ami().
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 635 of file main/utils.c.
Referenced by add_diversion(), add_rpid(), ast_callerid_merge(), ast_sip_modify_id_header(), AST_TEST_DEFINE(), channel_read_pjsip(), create_new_id_hdr(), initreqprep(), print_escaped_uri(), and receive_message().
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 665 of file main/utils.c.
References ast_assert, NULL, out, and string.
Referenced by ast_config_text_file_save2(), handle_cli_dialplan_save(), and test_semi().
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".
0 | if val is a NULL pointer. |
-1 | if "true". |
0 | otherwise. |
Definition at line 1968 of file main/utils.c.
References ast_strlen_zero.
Referenced by acf_faxopt_write(), acf_transaction_write(), actual_load_config(), announce_user_count_all_handler(), aoc_cli_debug_enable(), bool_handler_fn(), boolflag_handler_fn(), build_peer(), build_user(), check_debug(), dahdi_set_dnd(), find_realtime(), function_ooh323_write(), handle_common_options(), handle_queue_set_member_ringinuse(), hook_write(), init_acf_query(), load_config(), manager_mute_mixmonitor(), manager_queue_member_ringinuse(), parking_feature_flag_cfg(), parse_empty_options(), parse_playtone(), prack_handler(), process_config(), process_dahdi(), process_echocancel(), read_pjproject_startup_options(), reload(), reload_config(), reload_single_member(), rt_handle_member_record(), rtp_reload(), run_agi(), set_config(), set_insecure_flags(), sip_parse_nat_option(), sla_build_trunk(), strings_to_mask(), and timers_handler().
int ast_file_is_readable | ( | const char * | filename | ) |
Test that a file exists and is readable by the effective user.
filename | File to test. |
Definition at line 2855 of file main/utils.c.
Referenced by add_email_attachment(), ast_media_cache_retrieve(), ast_rtp_dtls_cfg_parse(), on_load_ca_file(), on_load_ca_path(), and transport_tls_file_handler().
int ast_find_lock_info | ( | void * | lock_addr, |
char * | filename, | ||
size_t | filename_size, | ||
int * | lineno, | ||
char * | func, | ||
size_t | func_size, | ||
char * | mutex_name, | ||
size_t | mutex_name_size | ||
) |
retrieve lock info for the specified mutex
this gets called during deadlock avoidance, so that the information may be preserved as to what location originally acquired the lock.
Definition at line 995 of file main/utils.c.
References ast_copy_string(), ast_threadstorage_get(), thr_lock_info::file, thr_lock_info::func, thr_lock_info::line_num, thr_lock_info::lock, thr_lock_info::lock_addr, lock_info, thr_lock_info::lock_name, thr_lock_info::locks, thr_lock_info::num_locks, pthread_mutex_lock, pthread_mutex_unlock, and thread_lock_info.
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 |
Definition at line 2049 of file main/utils.c.
Referenced by cli_channel_print_body(), cli_channelstats_print_body(), handle_bridge_show_all(), handle_bridge_show_specific(), show_chanstats_cb(), and stasis_show_topic().
int ast_get_tid | ( | void | ) |
Get current thread ID.
Definition at line 2504 of file main/utils.c.
Referenced by __ao2_ref(), ast_hangup(), ast_register_thread(), dummy_start(), format_log_message_ap(), and internal_ao2_alloc().
int ast_get_time_t | ( | const char * | src, |
time_t * | dst, | ||
time_t | _default, | ||
int * | consumed | ||
) |
get values from config variables.
Definition at line 2198 of file main/utils.c.
References ast_strlen_zero, and NULL.
Referenced by build_peer(), cache_lookup_internal(), dundi_show_cache(), dundi_show_hints(), handle_saydatetime(), load_password(), play_message_datetime(), process_clearcache(), realtime_peer(), and sayunixtime_exec().
int ast_get_timeval | ( | const char * | src, |
struct timeval * | dst, | ||
struct timeval | _default, | ||
int * | consumed | ||
) |
get values from config variables.
Definition at line 2171 of file main/utils.c.
References ast_strlen_zero, and NULL.
Referenced by acf_strftime(), expiration_str2struct(), persistence_expires_str2struct(), and 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 197 of file main/utils.c.
References ast_hostent::buf, host, ast_hostent::hp, and NULL.
Referenced by ast_parse_arg(), config_load(), config_parse_variables(), festival_exec(), iax_template_parse(), process_sdp(), and reload_config().
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 782 of file main/utils.c.
References ast_threadstorage_get(), buf, and inet_ntoa_buf.
Referenced by _skinny_show_device(), _skinny_show_devices(), _stun_show_status(), add_sdp(), ast_dns_get_nameservers(), ast_parse_arg(), config_load(), create_client(), find_command(), find_subchannel_and_lock(), get_defaults(), get_to_address(), handle_error(), handle_mgcp_show_endpoints(), handle_open_receive_channel_ack_message(), handle_request(), handle_skinny_show_settings(), iax_server(), mgcpsock_read(), parsing(), process_request(), process_sdp(), reload_config(), resend_response(), rtp_add_candidates_to_ice(), rtp_reload(), score_address(), send_raw_client(), send_request(), send_response(), send_start_rtp(), send_trunk(), show_main_page(), skinny_session(), skinny_session_cleanup(), skinny_set_rtp_peer(), start_rtp(), stun_monitor_request(), transmit_serverres(), transmit_startmediatransmission(), unistim_show_devices(), unistim_show_info(), and unistimsock_read().
void ast_join_delim | ( | char * | s, |
size_t | len, | ||
const char *const | w[], | ||
unsigned int | size, | ||
char | delim | ||
) |
Definition at line 2130 of file main/utils.c.
References len().
Referenced by ast_sip_auths_to_str().
void ast_log_show_lock | ( | void * | this_lock_addr | ) |
log info for the current lock with ast_log().
This function can help you find highly temporal locks; locks that happen for a short time, but at unexpected times, usually at times that create a deadlock, Why is this thing locked right then? Who is locking it? Who am I fighting with for this lock?
To answer such questions, just call this routine before you would normally try to aquire a lock. It doesn't do anything if the lock is not acquired. If the lock is taken, it will publish a line or two to the console via ast_log().
Sometimes, the lock message is pretty uninformative. For instance, you might find that the lock is being aquired deep within the astobj2 code; this tells you little about higher level routines that call the astobj2 routines. But, using gdb, you can set a break at the ast_log below, and for that breakpoint, you can set the commands: where cont which will give a stack trace and continue. – that aught to do the job!
Definition at line 1231 of file main/utils.c.
References append_lock_information(), ast_free, AST_LIST_TRAVERSE, ast_log, ast_str_buffer(), ast_str_create, thr_lock_info::lock, thr_lock_info::lock_addr, lock_info, lock_infos_lock, thr_lock_info::locks, LOG_NOTICE, ast_mutex_info::mutex, thr_lock_info::num_locks, pthread_mutex_lock, pthread_mutex_unlock, and str.
void ast_mark_lock_acquired | ( | void * | lock_addr | ) |
Mark the last lock as acquired.
Definition at line 962 of file main/utils.c.
References ast_threadstorage_get(), thr_lock_info::lock, thr_lock_info::lock_addr, lock_info, thr_lock_info::locks, thr_lock_info::num_locks, thr_lock_info::pending, pthread_mutex_lock, pthread_mutex_unlock, and thread_lock_info.
void ast_mark_lock_failed | ( | void * | lock_addr | ) |
Mark the last lock as failed (trylock)
Definition at line 978 of file main/utils.c.
References ast_threadstorage_get(), thr_lock_info::lock, thr_lock_info::lock_addr, lock_info, thr_lock_info::locks, thr_lock_info::num_locks, thr_lock_info::pending, pthread_mutex_lock, pthread_mutex_unlock, thread_lock_info, and thr_lock_info::times_locked.
void ast_md5_hash | ( | char * | output, |
const char * | input | ||
) |
Produce 32 char MD5 hash of value.
Produces MD5 hash based on input string.
Definition at line 248 of file main/utils.c.
References MD5Final(), MD5Init(), and MD5Update().
Referenced by __init_manager(), ast_sip_location_create_contact(), AST_TEST_DEFINE(), auth_exec(), auth_http_callback(), build_nonce(), build_reply_digest(), check_auth(), md5(), and permanent_uri_handler().
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 |
Creates a directory path, creating parent directories as needed.
Definition at line 2231 of file main/utils.c.
References ast_alloca, ast_strdupa, errno, len(), and tmp().
Referenced by ast_logger_rotate_channel(), ast_monitor_change_fname(), ast_monitor_start(), conf_rec_name(), conf_run(), create_destination_directory(), create_dirpath(), create_temp_file(), dictate_exec(), filename_parse(), init_logger(), load_module(), reload_logger(), remove_from_queue(), setup_privacy_args(), sms_nextoutgoing(), sms_writefile(), test_vm_api_create_voicemail_folder(), testclient_exec(), testserver_exec(), and write_history().
int ast_parse_digest | ( | const char * | digest, |
struct ast_http_digest * | d, | ||
int | request, | ||
int | pedantic | ||
) |
Parse digest authorization header.
Definition at line 2390 of file main/utils.c.
References ast_free, ast_log, ast_skip_blanks(), ast_str_buffer(), ast_str_create, ast_str_set(), ast_string_field_ptr_set, ast_string_field_set, ast_strlen_zero, ast_unescape_c(), c, ast_http_digest::cnonce, ast_http_digest::domain, LOG_WARNING, ast_http_digest::nc, ast_http_digest::nonce, NULL, ast_http_digest::opaque, ast_http_digest::qop, ast_http_digest::realm, ast_http_digest::response, str, strsep(), ast_http_digest::uri, and ast_http_digest::username.
Referenced by auth_http_callback().
char* ast_process_quotes_and_slashes | ( | char * | start, |
char | find, | ||
char | replace_with | ||
) |
Process a string to find and replace characters.
start | The string to analyze |
find | The character to find |
replace_with | The character that will replace the one we are looking for |
Definition at line 2104 of file main/utils.c.
int ast_pthread_create_detached_stack | ( | pthread_t * | thread, |
pthread_attr_t * | attr, | ||
void *(*)(void *) | start_routine, | ||
void * | data, | ||
size_t | stacksize, | ||
const char * | file, | ||
const char * | caller, | ||
int | line, | ||
const char * | start_fn | ||
) |
Definition at line 1494 of file main/utils.c.
References ast_alloca, ast_log, ast_pthread_create_stack(), errno, LOG_WARNING, and thr_arg::start_routine.
int ast_pthread_create_stack | ( | pthread_t * | thread, |
pthread_attr_t * | attr, | ||
void *(*)(void *) | start_routine, | ||
void * | data, | ||
size_t | stacksize, | ||
const char * | file, | ||
const char * | caller, | ||
int | line, | ||
const char * | start_fn | ||
) |
Definition at line 1446 of file main/utils.c.
References a, ast_alloca, ast_asprintf, ast_log, ast_malloc, AST_STACKSIZE, thr_arg::data, dummy_start(), errno, LOG_WARNING, thr_arg::name, NULL, pthread_create, and thr_arg::start_routine.
Referenced by ast_pthread_create_detached_stack().
long int ast_random | ( | void | ) |
Definition at line 2064 of file main/utils.c.
References ast_mutex_lock, ast_mutex_unlock, and randomlock.
Referenced by __sip_alloc(), acf_rand_exec(), action_challenge(), add_sdp(), agi_handle_command(), app_exec(), ast_generate_random_string(), ast_lock_path_lockfile(), ast_moh_files_next(), ast_rtp_change_source(), ast_rtp_new(), AST_TEST_DEFINE(), ast_udptl_new_with_bindaddr(), astobj2_test_1_helper(), auth_http_callback(), authenticate_request(), build_gateway(), build_iv(), build_localtag_registry(), build_nonce(), build_rand_pad(), build_reply_digest(), calc_metric(), calc_rxstamp(), caldav_write_event(), closefrom(), create_channel_name(), create_local_sdp(), dns_srv_sort(), drop_packets_data_update(), fill_with_garbage(), generate_parked_user(), generate_random_string(), generic_http_callback(), get_trans_id(), get_unused_callno(), handle_cli_sched_bench(), handle_incoming(), handle_response_invite(), iax2_key_rotate(), jingle_add_ice_udp_candidates_to_transport(), jingle_alloc(), jingle_new(), load_module(), make_email_file(), make_our_tag(), mbl_new(), moh_files_alloc(), multicast_rtp_new(), ogg_vorbis_rewrite(), osp_create_uuid(), page_exec(), process_weights(), reg_source_db(), registry_authrequest(), reqprep(), reschedule_reinvite(), rtp_allocate_transport(), say_periodic_announcement(), sendmail(), sip_outbound_registration_perform(), socket_read(), sorcery_memory_cache_thrash_retrieve(), sorcery_memory_cache_thrash_update(), start_rtp(), stun_req_id(), test_ao2_find_w_no_flags(), test_ao2_find_w_OBJ_KEY(), test_ao2_find_w_OBJ_PARTIAL_KEY(), test_ao2_find_w_OBJ_POINTER(), test_files_get_one(), transmit_invite(), transmit_register(), transmit_response_using_temp(), try_calling(), try_firmware(), websocket_client_create_key(), and websocket_mask_payload().
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
regex_string | the string containing /regex/ |
regex_pattern | the destination ast_str which will contain "regex" after execution |
Definition at line 1931 of file main/utils.c.
References ast_str_set(), and ast_str_truncate().
Referenced by action_hangup(), mwi_mailbox_delete(), and mwi_mailbox_get().
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 2033 of file main/utils.c.
References ast_tvdiff_ms(), and ast_tvnow().
Referenced by __analog_ss_thread(), __ast_answer(), __ast_request_and_dial(), analog_ss_thread(), ast_iostream_write(), ast_recvtext(), ast_stun_request(), ast_waitfordigit_full(), disable_t38(), find_cache(), generic_fax_exec(), iostream_read(), parking_set_duration(), read_mf_digits(), read_sf_digits(), receivefax_t38_init(), record_exec(), safe_sleep_conditional(), sendfax_t38_init(), wait_exec(), wait_for_answer(), wait_for_cache_update(), and waitforring_exec().
void ast_remove_lock_info | ( | void * | lock_addr, |
struct ast_bt * | bt | ||
) |
remove lock info for the current thread
this gets called by ast_mutex_unlock so that information on the lock can be removed from the current thread's lock info struct.
Definition at line 1088 of file main/utils.c.
References ast_threadstorage_get(), thr_lock_info::backtrace, thr_lock_info::lock, thr_lock_info::lock_addr, lock_info, thr_lock_info::locks, thr_lock_info::num_locks, pthread_mutex_lock, pthread_mutex_unlock, thread_lock_info, and thr_lock_info::times_locked.
void ast_replace_subargument_delimiter | ( | char * | s | ) |
Replace '^' in a string with ','.
s | String within which to replace characters |
Definition at line 2095 of file main/utils.c.
Referenced by app_exec(), ast_bridge_set_after_go_on(), dial_exec_full(), originate_exec(), page_exec(), and queue_exec().
void ast_restore_lock_info | ( | void * | lock_addr | ) |
Definition at line 1059 of file main/utils.c.
References ast_threadstorage_get(), thr_lock_info::lock, thr_lock_info::lock_addr, lock_info, thr_lock_info::locks, thr_lock_info::num_locks, pthread_mutex_lock, pthread_mutex_unlock, thr_lock_info::suspended, and thread_lock_info.
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
.
path | The directory path to create |
mode | The permissions with which to try to create the directory |
Definition at line 2336 of file main/utils.c.
References ast_free, ast_std_free(), ast_strdup, errno, NULL, RAII_VAR, and safe_mkdir().
Referenced by AST_TEST_DEFINE(), and 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 2749 of file main/utils.c.
References ast_debug, ast_eid_to_str(), ast_free, ast_log, ast_malloc, buf, if(), LOG_WARNING, and NULL.
Referenced by ast_eid_to_str(), and load_asterisk_conf().
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 264 of file main/utils.c.
References SHA1Input(), SHA1Reset(), and SHA1Result().
Referenced by add_public_key_to_astdb(), ast_tcptls_server_start(), AST_TEST_DEFINE(), get_path_to_public_key(), handle_call_token(), media_cache_item_sync_to_astdb(), public_key_is_expired(), remove_public_key_from_astdb(), set_public_key_expiration(), sha1(), test_stir_shaken_add_fake_astdb_entry(), 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 282 of file main/utils.c.
References SHA1Input(), SHA1Reset(), and SHA1Result().
Referenced by websocket_combine_key().
void ast_store_lock_info | ( | enum ast_lock_type | type, |
const char * | filename, | ||
int | line_num, | ||
const char * | func, | ||
const char * | lock_name, | ||
void * | lock_addr, | ||
struct ast_bt * | bt | ||
) |
Store lock info for the current thread.
This function gets called in ast_mutex_lock() and ast_mutex_trylock() so that information about this lock can be stored in this thread's lock info struct. The lock is marked as pending as the thread is waiting on the lock. ast_mark_lock_acquired() will mark it as held by this thread.
Definition at line 905 of file main/utils.c.
References AST_MAX_LOCKS, ast_threadstorage_get(), thr_lock_info::backtrace, thr_lock_info::file, thr_lock_info::func, thr_lock_info::line_num, thr_lock_info::lock, thr_lock_info::lock_addr, lock_info, thr_lock_info::lock_name, thr_lock_info::locks, thr_lock_info::num_locks, thr_lock_info::pending, pthread_mutex_lock, pthread_mutex_unlock, thread_lock_info, thr_lock_info::times_locked, and thr_lock_info::type.
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
Definition at line 2825 of file main/utils.c.
References ast_eid::eid.
Referenced by asterisk_publication_devicestate_state_change(), asterisk_publication_mwi_state_change(), build_peer(), dundi_do_query(), load_asterisk_conf(), set_config(), and 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 1639 of file main/utils.c.
References ast_strip().
Referenced by applicationmap_handler(), ast_callerid_parse(), ast_sip_validate_uri_length(), ast_strsep(), dialog_info_generate_body_content(), get_rdnis(), hfp_parse_clip(), iftime(), load_values_config(), parse_allowed_methods(), parse_cookies(), parse_dial_string(), pidf_allocate_body(), set_redirecting_reason(), sip_parse_register_line(), and xpidf_allocate_body().
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. 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 1656 of file main/utils.c.
References ast_strip(), ast_strip_quoted(), ast_strlen_zero, AST_STRSEP_STRIP, AST_STRSEP_TRIM, AST_STRSEP_UNESCAPE, ast_unescape_quoted(), and NULL.
Referenced by AST_TEST_DEFINE(), does_category_match(), handle_updates(), originate_exec(), test_xml_entry(), and wizard_apply_handler().
void ast_suspend_lock_info | ( | void * | lock_addr | ) |
Definition at line 1030 of file main/utils.c.
References ast_threadstorage_get(), thr_lock_info::lock, thr_lock_info::lock_addr, lock_info, thr_lock_info::locks, thr_lock_info::num_locks, pthread_mutex_lock, pthread_mutex_unlock, thr_lock_info::suspended, and thread_lock_info.
int ast_thread_is_user_interface | ( | void | ) |
Indicates whether the current thread is a user interface.
Definition at line 2996 of file main/utils.c.
References ast_log, ast_threadstorage_get(), LOG_ERROR, NULL, and thread_user_interface_tl.
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. |
Definition at line 2981 of file main/utils.c.
References ast_log, ast_threadstorage_get(), LOG_ERROR, NULL, and thread_user_interface_tl.
Referenced by handle_tcptls_connection().
char* ast_to_camel_case_delim | ( | const char * | s, |
const char * | delim | ||
) |
Definition at line 2149 of file main/utils.c.
References ast_copy_string(), ast_strdup, and NULL.
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".
0 | if val is a NULL pointer. |
-1 | if "true". |
0 | otherwise. |
Definition at line 1951 of file main/utils.c.
References ast_strlen_zero.
Referenced by __ast_http_load(), __init_manager(), _parse(), acf_curlopt_write(), acf_faxopt_write(), acf_transaction_write(), action_agent_logoff(), action_originate(), action_status(), action_updateconfig(), actual_load_config(), agent_login_channel_config(), announce_user_count_all_handler(), aoc_cli_debug_enable(), apply_general_options(), apply_option(), ast_ari_bridges_add_channel_cb(), ast_ari_bridges_record_cb(), ast_ari_channels_record_cb(), ast_ari_events_event_websocket_ws_attempted_cb(), ast_ari_events_event_websocket_ws_established_cb(), ast_bridge_timelimit(), ast_jb_read_conf(), ast_rtp_dtls_cfg_parse(), AST_TEST_DEFINE(), ast_tls_read_conf(), autopause2int(), bool_handler_fn(), boolflag_handler_fn(), build_calendar(), build_device(), build_gateway(), build_peer(), build_user(), cdr_prop_write_callback(), check_debug(), client_bitfield_handler(), config_parse_variables(), custom_bitfield_handler(), customopt_handler(), dahdi_cc_callback(), dahdi_set_dnd(), destroy_all_channels(), do_reload(), encoding_format_handler(), festival_exec(), func_channel_write_real(), func_mute_write(), function_ooh323_write(), get_encrypt_methods(), global_bitfield_handler(), handle_clear_alarms(), handle_common_options(), handle_logger_set_level(), handle_queue_set_member_ringinuse(), handle_t38_options(), hook_write(), init_logger_chain(), internal_feature_write(), is_variable_true(), load_asterisk_conf(), load_config(), load_config_meetme(), load_module(), load_moh_classes(), load_odbc_config(), loader_config_init(), manager_add_queue_member(), manager_dialplan_extension_add(), manager_mute_mixmonitor(), manager_mutestream(), manager_pause_queue_member(), manager_play_dtmf(), manager_queue_member_ringinuse(), mbl_load_adapter(), mbl_load_device(), message_template_build(), misdn_answer(), moh_parse_options(), my_load_module(), new_realtime_sqlite3_db(), odbc_load_module(), osp_load(), osplookup_exec(), parse_config(), parse_empty_options(), parse_line(), parse_playtone(), pbx_builtin_saycharacters(), pbx_builtin_saycharacters_case(), pbx_builtin_saydigits(), pbx_builtin_saymoney(), pbx_builtin_saynumber(), pbx_builtin_sayphonetic(), pbx_load_config(), pbx_load_users(), pjsip_acf_moh_passthrough_write(), pjsip_set_logger_verbose(), prack_handler(), process_dahdi(), process_echocancel(), process_my_load_module(), profile_set_param(), queue_rules_set_global_params(), queue_set_global_params(), queue_set_param(), realtime_directory(), reload(), reload_config(), reload_followme(), reload_module(), reload_single_member(), rt_handle_member_record(), rtp_reload(), run_agi(), run_startup_commands(), sayunixtime_exec(), search_directory(), search_directory_sub(), set_active(), set_config(), sla_load_config(), smdi_load(), sorcery_config_open(), sorcery_memory_cache_ami_stale_object(), sorcery_memory_cache_open(), speex_write(), stackpeek_read(), start_monitor_action(), strings_to_mask(), tds_load_module(), timers_handler(), transport_tls_bool_handler(), xfer_set(), xmldoc_get_syntax_cmd(), xmldoc_get_syntax_config_object(), xmldoc_get_syntax_fun(), and xmldoc_get_syntax_manager().
struct timeval ast_tvadd | ( | struct timeval | a, |
struct timeval | b | ||
) |
Returns the sum of two timevals a + b.
Definition at line 2005 of file main/utils.c.
References a, b, ONE_MILLION, and tvfix().
struct timeval ast_tvsub | ( | struct timeval | a, |
struct timeval | b | ||
) |
Returns the difference of two timevals a - b.
Definition at line 2019 of file main/utils.c.
References a, b, ONE_MILLION, and tvfix().
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 1735 of file main/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 696 of file main/utils.c.
Referenced by ast_callerid_parse(), ast_strsep(), and AST_TEST_DEFINE().
char* ast_unescape_semicolon | ( | char * | s | ) |
Strip backslash for "escaped" semicolons, the string to be stripped (will be modified).
Definition at line 1716 of file main/utils.c.
Referenced by sip_cli_notify().
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 616 of file main/utils.c.
References ast_test_flag, AST_URI_LEGACY_SPACE, and tmp().
Referenced by acf_curl_helper(), ast_ari_invoke(), ast_http_get_post_vars(), AST_TEST_DEFINE(), config_curl(), get_destination(), get_name_and_number(), get_refer_info(), handle_request_invite(), handle_uri(), parse_moved_contact(), realtime_curl(), realtime_multi_curl(), sip_new(), sip_uri_cmp(), 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 577 of file main/utils.c.
References ast_test_flag, AST_URI_ALPHANUM, AST_URI_LEGACY_SPACE, AST_URI_MARK, AST_URI_SIP_USER_UNRESERVED, out, and string.
Referenced by add_diversion(), add_rpid(), ast_ari_bridges_record(), ast_ari_channels_record(), AST_TEST_DEFINE(), build_contact(), config_curl(), destroy_curl(), initreqprep(), launch_asyncagi(), realtime_curl(), realtime_multi_curl(), require_curl(), store_curl(), update2_curl(), update_curl(), and uriencode().
int ast_utils_init | ( | void | ) |
Definition at line 2369 of file main/utils.c.
References ARRAY_LEN, ast_cli_register_multiple, ast_register_cleanup(), base64_init(), and utils_shutdown().
Referenced by asterisk_daemon().
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 2522 of file main/utils.c.
References ast_strdupa, NULL, and strsep().
int ast_wait_for_input | ( | int | fd, |
int | ms | ||
) |
Definition at line 1519 of file main/utils.c.
References ast_poll.
Referenced by action_waitevent(), ast_ari_websocket_session_read(), ast_iostream_wait_for_input(), ast_iostream_write(), ast_tcptls_server_root(), dahdi_test_timer(), get_input(), iostream_read(), moh_class_destructor(), sip_tcptls_read(), sip_websocket_callback(), and unbound_resolver_thread().
int ast_wait_for_output | ( | int | fd, |
int | ms | ||
) |
Definition at line 1529 of file main/utils.c.
References ast_poll.
Referenced by ast_iostream_write(), and iostream_read().
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 |
Definition at line 718 of file main/utils.c.
References ast_assert, end, entity, len(), NULL, and string.
Referenced by ast_http_create_response(), state_notify_build_xml(), and test_xml().
|
static |
Definition at line 538 of file main/utils.c.
References b2a, b2a_url, base64, and base64url.
Referenced by ast_utils_init().
|
static |
Definition at line 1394 of file main/utils.c.
References ast_free, ast_get_tid(), AST_LIST_INSERT_TAIL, AST_MUTEX_KIND, ast_register_thread(), ast_strdup, ast_threadstorage_get(), ast_unregister_thread(), thr_arg::data, thr_lock_info::lock, lock_info, lock_infos_lock, thr_lock_info::lwp, ast_mutex_info::mutex, thr_arg::name, NULL, pthread_mutex_init, pthread_mutex_lock, pthread_mutex_unlock, thr_arg::start_routine, thr_lock_info::thread_id, thread_lock_info, and thr_lock_info::thread_name.
Referenced by ast_pthread_create_stack().
|
static |
Definition at line 1870 of file main/utils.c.
References ast_malloc, and NULL.
Referenced by ast_escape_alloc(), and ast_escape_c_alloc().
|
static |
Definition at line 1339 of file main/utils.c.
References ast_cli(), ast_cli_allow_at_shutdown(), ast_dump_locks(), ast_free, ast_str_buffer(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, NULL, str, and ast_cli_entry::usage.
|
static |
Destroy a thread's lock info.
This gets called automatically when the thread stops
Definition at line 864 of file main/utils.c.
References ast_free, AST_LIST_REMOVE, ast_log, thr_lock_info::file, thr_lock_info::func, thr_lock_info::line_num, thr_lock_info::lock, thr_lock_info::lock_addr, lock_info, lock_infos_lock, thr_lock_info::lock_name, thr_lock_info::locks, LOG_ERROR, ast_mutex_info::mutex, thr_lock_info::num_locks, thr_lock_info::pending, pthread_mutex_destroy, pthread_mutex_lock, pthread_mutex_unlock, and thr_lock_info::thread_name.
|
static |
Definition at line 1132 of file main/utils.c.
References AST_MUTEX, AST_RDLOCK, and AST_WRLOCK.
Referenced by append_lock_information().
|
static |
Definition at line 2266 of file main/utils.c.
References ast_assert, ast_begins_with(), ast_std_free(), c, errno, NULL, and RAII_VAR.
Referenced by ast_safe_mkdir().
|
static |
Definition at line 1990 of file main/utils.c.
References a, ast_log, LOG_WARNING, and ONE_MILLION.
Referenced by ast_tvadd(), and ast_tvsub().
|
static |
Definition at line 2360 of file main/utils.c.
References ARRAY_LEN, and ast_cli_unregister_multiple().
Referenced by ast_utils_init().
|
static |
Definition at line 1539 of file main/utils.c.
References ast_debug, ast_log, ast_poll, ast_tvdiff_ms(), ast_tvnow(), errno, and LOG_ERROR.
Referenced by ast_carefulwrite().
const struct ast_flags ast_uri_http = {AST_URI_UNRESERVED} |
Definition at line 573 of file main/utils.c.
Referenced by acf_curl_helper(), ast_ari_bridges_record(), ast_ari_channels_record(), AST_TEST_DEFINE(), config_curl(), destroy_curl(), launch_asyncagi(), realtime_curl(), realtime_multi_curl(), require_curl(), store_curl(), update2_curl(), update_curl(), uridecode(), and uriencode().
const struct ast_flags ast_uri_http_legacy = {AST_URI_LEGACY_SPACE | AST_URI_UNRESERVED} |
Definition at line 574 of file main/utils.c.
Referenced by acf_curl_helper(), ast_ari_invoke(), ast_http_get_post_vars(), AST_TEST_DEFINE(), and handle_uri().
const struct ast_flags ast_uri_sip_user = {AST_URI_UNRESERVED | AST_URI_SIP_USER_UNRESERVED} |
Definition at line 575 of file main/utils.c.
Referenced by add_diversion(), add_rpid(), AST_TEST_DEFINE(), build_contact(), get_destination(), get_name_and_number(), get_refer_info(), handle_request_invite(), initreqprep(), parse_moved_contact(), sip_new(), and sip_uri_cmp().
|
static |
Definition at line 80 of file main/utils.c.
Referenced by ast_base64decode(), and base64_init().
|
static |
Definition at line 81 of file main/utils.c.
Referenced by ast_base64url_decode(), and base64_init().
|
static |
Definition at line 78 of file main/utils.c.
Referenced by ast_base64encode_full(), ast_http_get_auth(), ast_websocket_uri_cb(), base64_init(), websocket_client_handshake_get_response(), and xmpp_client_authenticate_sasl().
|
static |
Definition at line 79 of file main/utils.c.
Referenced by ast_base64url_encode_full(), and base64_init().
|
static |
Definition at line 792 of file main/utils.c.
Referenced by ast_uuid_init().
char escape_sequences[] |
Definition at line 1774 of file main/utils.c.
Referenced by ast_escape(), and ast_escape_c().
|
static |
Definition at line 1782 of file main/utils.c.
|
static |
Definition at line 83 of file main/utils.c.
Referenced by ast_inet_ntoa().
|
static |
|
static |
Locked when accessing the lock_infos list.
Definition at line 853 of file main/utils.c.
Referenced by ast_dump_locks(), ast_log_show_lock(), dummy_start(), and lock_info_destroy().
|
static |
Definition at line 2061 of file main/utils.c.
Referenced by ast_random().
|
static |
Definition at line 902 of file main/utils.c.
Referenced by ast_find_lock_info(), ast_mark_lock_acquired(), ast_mark_lock_failed(), ast_remove_lock_info(), ast_restore_lock_info(), ast_store_lock_info(), ast_suspend_lock_info(), and dummy_start().
|
static |
Definition at line 2979 of file main/utils.c.
Referenced by ast_thread_is_user_interface(), and ast_thread_user_interface_set().
|
static |
Definition at line 1369 of file main/utils.c.