Utility functions. More...
#include "asterisk.h"
#include <ctype.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <fcntl.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/strings.h"
#include "asterisk/time.h"
#include "asterisk/stringfields.h"
#include "asterisk/utils.h"
#include "asterisk/threadstorage.h"
#include "asterisk/config.h"
Go to the source code of this file.
Data Structures | |
struct | thr_arg |
Macros | |
#define | ALLOCATOR_OVERHEAD 48 |
#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 /* ensure that inlinable API functions will be built in this module if required */ |
#define | AST_API_MODULE |
#define | AST_API_MODULE |
#define | ONE_MILLION 1000000 |
Functions | |
void * | __ast_calloc_with_stringfields (unsigned int num_structs, size_t struct_size, size_t field_mgr_offset, size_t field_mgr_pool_offset, size_t pool_size, const char *file, int lineno, const char *func) |
ast_string_field | __ast_string_field_alloc_space (struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, size_t needed) |
int | __ast_string_field_init (struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, int needed, const char *file, int lineno, const char *func) |
void | __ast_string_field_ptr_build (struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, ast_string_field *ptr, const char *format,...) |
void | __ast_string_field_ptr_build_va (struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, ast_string_field *ptr, const char *format, va_list ap1, va_list ap2) |
int | __ast_string_field_ptr_grow (struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, size_t needed, const ast_string_field *ptr) |
void | __ast_string_field_release_active (struct ast_string_field_pool *pool_head, const ast_string_field ptr) |
static void | __init_inet_ntoa_buf (void) |
int | _ast_asprintf (char **ret, const char *file, int lineno, const char *func, const char *fmt,...) |
static int | add_string_pool (struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, size_t size, const char *file, int lineno, const char *func) |
add a new block to the pool. We can only allocate from the topmost pool, so the fields in *mgr reflect the size of that only. More... | |
int | ast_atomic_fetchadd_int_slow (volatile int *p, int v) |
int | ast_base64decode (unsigned char *dst, const char *src, int max) |
decode BASE64 encoded text 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... | |
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_careful_fwrite (FILE *f, int fd, const char *src, size_t len, int timeoutms) |
Write data to a file stream with a timeout. 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... | |
void | ast_do_crash (void) |
Force a crash if DO_CRASH is defined. More... | |
void | ast_enable_packet_fragmentation (int sock) |
Disable PMTU discovery on a socket. More... | |
char * | ast_escape_quoted (const char *string, char *outbuf, int buflen) |
escapes characters specified for quoted portions of sip messages 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_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 (char *s, size_t len, const char *const w[]) |
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_remaining_ms (struct timeval start, int max_ms) |
Calculate remaining milliseconds given a starting timestamp and upper bound. More... | |
void | ast_sha1_hash (char *output, const char *input) |
Produce 40 char SHA1 hash of value. 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... | |
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) |
ast_uri_decode: Decode SIP URI, URN, URL (overwrite the string) More... | |
char * | ast_uri_encode (const char *string, char *outbuf, int buflen, int do_special_char) |
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 size_t | optimal_alloc_size (size_t size) |
static struct timeval | tvfix (struct timeval a) |
static int | wait_for_output (int fd, int timeoutms) |
Variables | |
ast_string_field | __ast_string_field_empty = __ast_string_field_empty_buffer.string |
struct { | |
ast_string_field_allocation allocation | |
char string [1] | |
} | __ast_string_field_empty_buffer |
static char | b2a [256] |
static char | base64 [64] |
static int | dev_urandom_fd |
static ast_mutex_t | fetchadd_m = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 } |
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 } |
glibc puts a lock inside random(3), so that the results are thread-safe. BSD libc (and others) do not. More... | |
Utility functions.
Definition in file utils.c.
#define ALLOCATOR_OVERHEAD 48 |
Definition at line 1727 of file utils.c.
Referenced by optimal_alloc_size().
#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 /* ensure that inlinable API functions will be built in this module if required */ |
#define ONE_MILLION 1000000 |
Definition at line 1567 of file utils.c.
Referenced by ast_tvadd(), ast_tvsub(), and tvfix().
void* __ast_calloc_with_stringfields | ( | unsigned int | num_structs, |
size_t | struct_size, | ||
size_t | field_mgr_offset, | ||
size_t | field_mgr_pool_offset, | ||
size_t | pool_size, | ||
const char * | file, | ||
int | lineno, | ||
const char * | func | ||
) |
Definition at line 2026 of file utils.c.
References __ast_calloc(), __ast_string_field_empty, allocation, ast_calloc, ast_string_field_pool::base, ast_string_field_mgr::embedded_pool, optimal_alloc_size(), and ast_string_field_pool::size.
ast_string_field __ast_string_field_alloc_space | ( | struct ast_string_field_mgr * | mgr, |
struct ast_string_field_pool ** | pool_head, | ||
size_t | needed | ||
) |
Definition at line 1847 of file utils.c.
References add_string_pool(), ast_alignof, ast_assert, ast_make_room_for, AST_STRING_FIELD_ALLOCATION, and ast_string_field_mgr::last_alloc.
Referenced by __ast_string_field_ptr_build_va().
int __ast_string_field_init | ( | struct ast_string_field_mgr * | mgr, |
struct ast_string_field_pool ** | pool_head, | ||
int | needed, | ||
const char * | file, | ||
int | lineno, | ||
const char * | func | ||
) |
Definition at line 1780 of file utils.c.
References __ast_string_field_empty, ast_string_field_pool::active, add_string_pool(), ast_free, ast_log(), ast_string_field_mgr::embedded_pool, ast_string_field_mgr::last_alloc, LOG_WARNING, ast_string_field_pool::prev, and ast_string_field_pool::used.
void __ast_string_field_ptr_build | ( | struct ast_string_field_mgr * | mgr, |
struct ast_string_field_pool ** | pool_head, | ||
ast_string_field * | ptr, | ||
const char * | format, | ||
... | |||
) |
Definition at line 2011 of file utils.c.
References __ast_string_field_ptr_build_va().
void __ast_string_field_ptr_build_va | ( | struct ast_string_field_mgr * | mgr, |
struct ast_string_field_pool ** | pool_head, | ||
ast_string_field * | ptr, | ||
const char * | format, | ||
va_list | ap1, | ||
va_list | ap2 | ||
) |
Definition at line 1935 of file utils.c.
References __ast_string_field_alloc_space(), __ast_string_field_empty, __ast_string_field_release_active(), ast_align_for, ast_alignof, ast_assert, ast_make_room_for, AST_STRING_FIELD_ALLOCATION, available(), and ast_string_field_mgr::last_alloc.
Referenced by __ast_string_field_ptr_build().
int __ast_string_field_ptr_grow | ( | struct ast_string_field_mgr * | mgr, |
struct ast_string_field_pool ** | pool_head, | ||
size_t | needed, | ||
const ast_string_field * | ptr | ||
) |
Definition at line 1888 of file utils.c.
References AST_STRING_FIELD_ALLOCATION, and ast_string_field_mgr::last_alloc.
void __ast_string_field_release_active | ( | struct ast_string_field_pool * | pool_head, |
const ast_string_field | ptr | ||
) |
Definition at line 1910 of file utils.c.
References ast_string_field_pool::active, ast_free, AST_STRING_FIELD_ALLOCATION, and ast_string_field_pool::prev.
Referenced by __ast_string_field_ptr_build_va().
int _ast_asprintf | ( | char ** | ret, |
const char * | file, | ||
int | lineno, | ||
const char * | func, | ||
const char * | fmt, | ||
... | |||
) |
Definition at line 2331 of file utils.c.
References MALLOC_FAILURE_MSG, and vasprintf().
|
static |
add a new block to the pool. We can only allocate from the topmost pool, so the fields in *mgr reflect the size of that only.
Definition at line 1744 of file utils.c.
References __ast_calloc(), ast_calloc, ast_string_field_mgr::last_alloc, optimal_alloc_size(), ast_string_field_pool::prev, and ast_string_field_pool::size.
Referenced by __ast_string_field_alloc_space(), and __ast_string_field_init().
int ast_atomic_fetchadd_int_slow | ( | volatile int * | p, |
int | v | ||
) |
Definition at line 2078 of file utils.c.
References ast_mutex_lock, ast_mutex_unlock, and fetchadd_m.
int ast_base64decode | ( | unsigned char * | dst, |
const char * | src, | ||
int | max | ||
) |
decode BASE64 encoded text
Decode data from base64.
Definition at line 279 of file utils.c.
Referenced by aes_helper(), ast_check_signature(), base64_helper(), osp_validate_token(), sdp_crypto_process(), and sdp_crypto_setup().
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 357 of file utils.c.
References ast_base64encode_full().
Referenced by aes_helper(), aji_start_sasl(), ast_sign(), base64_helper(), build_secret(), osp_check_destination(), and sdp_crypto_setup().
int ast_base64encode_full | ( | char * | dst, |
const unsigned char * | src, | ||
int | srclen, | ||
int | max, | ||
int | linebreaks | ||
) |
encode text to BASE64 coding
Definition at line 306 of file utils.c.
Referenced by ast_base64encode().
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 1521 of file utils.c.
References ast_build_string_va().
Referenced by ast_fax_caps_to_str(), config_odbc(), generate_filenames_string(), and handle_speechrecognize().
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 1502 of file utils.c.
Referenced by ast_build_string().
int ast_careful_fwrite | ( | FILE * | f, |
int | fd, | ||
const char * | s, | ||
size_t | len, | ||
int | timeoutms | ||
) |
Write data to a file stream with a timeout.
f | the file stream to write to |
fd | the file description to poll on to know when the file stream can be written to without blocking. |
s | the buffer to write from |
len | the number of bytes to write |
timeoutms | The maximum amount of time to block in this function trying to write, specified in milliseconds. |
0 | success |
-1 | error |
Definition at line 1369 of file utils.c.
References ast_log(), ast_tvdiff_ms(), ast_tvnow(), errno, LOG_ERROR, and wait_for_output().
Referenced by send_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 1328 of file utils.c.
References ast_log(), ast_tvdiff_ms(), ast_tvnow(), errno, LOG_ERROR, and wait_for_output().
Referenced by ast_agi_send(), and ast_cli().
void ast_do_crash | ( | void | ) |
Force a crash if DO_CRASH is defined.
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 2141 of file utils.c.
References ast_log(), and LOG_WARNING.
Referenced by ast_netsock_bindaddr(), and reload_config().
char* ast_escape_quoted | ( | const char * | string, |
char * | outbuf, | ||
int | buflen | ||
) |
escapes characters specified for quoted portions of sip messages
Escape characters found in a quoted string.
Definition at line 431 of file utils.c.
References string.
Referenced by add_diversion_header(), add_rpid(), ast_callerid_merge(), and initreqprep().
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 1550 of file utils.c.
References ast_strlen_zero().
Referenced by __ast_udptl_reload(), acf_faxopt_write(), acf_transaction_write(), actual_load_config(), aji_create_client(), aji_load_config(), aoc_cli_debug_enable(), build_peer(), build_user(), dahdi_set_dnd(), find_realtime(), func_channel_write_real(), handle_common_options(), init_acf_query(), load_config(), load_odbc_config(), manager_mute_mixmonitor(), parse_empty_options(), reload_config(), rtp_reload(), run_agi(), set_config(), set_insecure_flags(), sla_build_trunk(), and strings_to_mask().
int ast_get_tid | ( | void | ) |
Get current thread ID.
Definition at line 2346 of file utils.c.
Referenced by __ao2_alloc_debug(), __ao2_ref_debug(), and ast_log().
int ast_get_time_t | ( | const char * | src, |
time_t * | dst, | ||
time_t | _default, | ||
int * | consumed | ||
) |
get values from config variables.
Definition at line 2118 of file utils.c.
References ast_strlen_zero().
Referenced by build_peer(), cache_lookup_internal(), 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 2091 of file utils.c.
References ast_strlen_zero().
Referenced by acf_strftime().
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 195 of file utils.c.
References ast_hostent::buf, and ast_hostent::hp.
Referenced by __ast_http_load(), app_exec(), ast_parse_arg(), build_peer(), config_load(), config_parse_variables(), create_addr(), festival_exec(), gtalk_load_config(), gtalk_update_stun(), iax_template_parse(), jingle_load_config(), jingle_update_stun(), launch_netscript(), process_sdp(), realtime_peer(), realtime_user(), reload_config(), and set_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 564 of file utils.c.
References ast_threadstorage_get(), and inet_ntoa_buf.
Referenced by __attempt_transmit(), __find_callno(), __iax2_show_peers(), _skinny_show_device(), _skinny_show_devices(), acf_channel_read(), action_login(), add_ipv4_ie(), add_sdp(), ast_apply_ha(), ast_netsock_bindaddr(), ast_parse_arg(), auth_http_callback(), authenticate(), calltoken_required(), check_access(), config_load(), create_client(), data_get_xml_add_child(), data_result_manager_output(), data_result_print_cli_node(), do_message(), dump_addr(), dump_ipaddr(), dundi_rexmit(), dundi_show_peer(), dundi_show_peers(), dundi_show_trans(), dundi_showframe(), dundi_xmit(), external_rtp_create(), find_command(), find_peer(), find_subchannel_and_lock(), find_tpeer(), function_iaxpeer(), generic_http_callback(), get_input(), gtalk_update_externip(), gtalk_update_stun(), handle_call_token(), handle_cli_iax2_set_debug(), handle_cli_iax2_show_callno_limits(), handle_cli_iax2_show_channels(), handle_cli_iax2_show_peer(), handle_cli_iax2_show_registry(), handle_command_response(), handle_error(), handle_mgcp_show_endpoints(), handle_open_receive_channel_ack_message(), handle_request(), handle_show_http(), handle_showmanconn(), handle_skinny_show_settings(), iax2_ack_registry(), iax2_prov_app(), iax2_trunk_queue(), iax_server(), iax_showframe(), jingle_create_candidates(), load_module(), manager_iax2_show_peer_list(), manager_iax2_show_registry(), mgcpsock_read(), oh323_addrcmp_str(), oh323_call(), oh323_set_rtp_peer(), parsing(), peercnt_add(), peercnt_modify(), peercnt_remove(), peers_data_provider_get(), process_request(), process_sdp(), purge_sessions(), raw_hangup(), realtime_peer(), realtime_user(), register_verify(), registry_rerequest(), reload_config(), resend_response(), sched_delay_remove(), score_address(), send_packet(), send_raw_client(), send_request(), send_response(), send_trunk(), session_do(), set_config(), set_peercnt_limit(), setup_incoming_call(), show_main_page(), skinny_session(), skinny_set_rtp_peer(), socket_process(), socket_process_meta(), start_rtp(), stun_monitor_request(), timing_read(), unistim_info(), unistimsock_read(), and update_registry().
void ast_join | ( | char * | s, |
size_t | len, | ||
const char *const | w[] | ||
) |
Definition at line 1690 of file utils.c.
References len().
Referenced by __ast_cli_generator(), ast_agi_register(), ast_agi_unregister(), ast_cli_command_full(), cli_console_sendtext(), console_sendtext(), find_best(), handle_cli_agi_show(), handle_cli_check_permissions(), handle_help(), help1(), help_workhorse(), set_full_cmd(), and write_htmldump().
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 245 of file utils.c.
References MD5Final(), MD5Init(), and MD5Update().
Referenced by __init_manager(), auth_exec(), auth_http_callback(), build_reply_digest(), check_auth(), and md5().
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 2151 of file utils.c.
References ast_alloca, ast_strdupa, errno, and len().
Referenced by ast_monitor_change_fname(), ast_monitor_start(), conf_run(), create_dirpath(), dictate_exec(), filename_parse(), init_logger(), load_module(), mixmonitor_exec(), record_exec(), reload_logger(), remove_from_queue(), setup_privacy_args(), sms_nextoutgoing(), sms_writefile(), 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 2216 of file 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(), ast_http_digest::cnonce, ast_http_digest::domain, LOG_WARNING, ast_http_digest::nc, ast_http_digest::nonce, ast_http_digest::opaque, ast_http_digest::qop, ast_http_digest::realm, ast_http_digest::response, 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 | ||
) |
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 1230 of file 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 1182 of file utils.c.
References ast_alloca, ast_asprintf, ast_log(), ast_malloc, AST_STACKSIZE, thr_arg::data, dummy_start(), errno, LOG_WARNING, thr_arg::name, pthread_create, and thr_arg::start_routine.
Referenced by ast_pthread_create_detached_stack().
long int ast_random | ( | void | ) |
Definition at line 1640 of file utils.c.
References ast_mutex_lock, ast_mutex_unlock, and randomlock.
Referenced by acf_rand_exec(), action_challenge(), add_sdp(), agent_new(), agi_handle_command(), ast_lock_path_lockfile(), ast_moh_files_next(), ast_rtp_change_source(), ast_rtp_new(), ast_udptl_new_with_bindaddr(), auth_http_callback(), authenticate_request(), build_gateway(), build_iv(), build_localtag_registry(), build_rand_pad(), build_reply_digest(), calc_metric(), calc_rxstamp(), caldav_write_event(), callno_hash(), create_channel_name(), generate_exchange_uuid(), generate_random_string(), generic_http_callback(), get_trans_id(), gtalk_alloc(), gtalk_create_candidates(), gtalk_new(), handle_incoming(), handle_response_invite(), iax2_key_rotate(), iax2_start_transfer(), jingle_alloc(), jingle_create_candidates(), jingle_new(), load_module(), make_email_file(), make_our_tag(), moh_files_alloc(), multicast_rtp_new(), ogg_vorbis_rewrite(), osp_create_uuid(), page_exec(), park_space_reserve(), process_weights(), reg_source_db(), registry_authrequest(), reqprep(), say_periodic_announcement(), sendmail(), set_nonce_randdata(), sip_alloc(), socket_read(), start_rtp(), stun_req_id(), transmit_invite(), transmit_register(), transmit_response_using_temp(), try_calling(), and try_firmware().
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 1615 of file utils.c.
References ast_tvdiff_ms(), and ast_tvnow().
Referenced by __analog_ss_thread(), __ast_answer(), __ast_request_and_dial(), agent_ack_sleep(), analog_ss_thread(), ast_recvtext(), ast_safe_sleep_conditional(), ast_waitfordigit_full(), async_wait(), dahdi_bridge(), disable_t38(), do_idle_thread(), find_cache(), generic_fax_exec(), local_bridge_loop(), receivefax_t38_init(), record_exec(), remote_bridge_loop(), sendfax_t38_init(), tcptls_stream_read(), tcptls_stream_write(), wait_for_answer(), and waitforring_exec().
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 261 of file utils.c.
References SHA1Input(), SHA1Reset(), and SHA1Result().
Referenced by aji_act_hook(), handle_call_token(), jabber_make_auth(), and sha1().
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 1431 of file utils.c.
References ast_strip().
Referenced by ast_callerid_parse(), ast_register_file_version(), get_rdnis(), iftime(), load_values_config(), parse_allowed_methods(), parse_cookies(), parse_dial_string(), and sip_parse_register_line().
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 1533 of file utils.c.
References ast_strlen_zero().
Referenced by __ast_http_load(), __ast_udptl_reload(), __init_manager(), _parse(), acf_curlopt_write(), acf_faxopt_write(), acf_transaction_write(), action_agent_logoff(), action_bridge(), action_originate(), action_updateconfig(), actual_load_config(), aji_create_client(), aji_load_config(), aoc_cli_debug_enable(), apply_general_options(), apply_option(), apply_outgoing(), ast_bridge_timelimit(), ast_jb_read_conf(), ast_plc_reload(), ast_readconfig(), ast_tls_read_conf(), autopause2int(), build_device(), build_gateway(), build_peer(), build_user(), config_parse_variables(), dahdi_accept_r2_call_exec(), dahdi_r2_answer(), dahdi_set_dnd(), data_search_cmp_bool(), do_reload(), festival_exec(), func_channel_write_real(), func_inheritance_write(), func_mute_write(), get_encrypt_methods(), gtalk_load_config(), handle_common_options(), handle_logger_set_level(), handle_mfcr2_call_files(), handle_t38_options(), init_logger_chain(), jingle_load_config(), load_config(), load_config_meetme(), load_module(), load_modules(), load_moh_classes(), load_odbc_config(), local_ast_moh_start(), login_exec(), manager_add_queue_member(), manager_mutestream(), manager_pause_queue_member(), message_template_build(), misdn_answer(), odbc_load_module(), osp_load(), osplookup_exec(), parkinglot_config_read(), parse_config(), parse_empty_options(), pbx_load_config(), pbx_load_users(), process_config(), process_dahdi(), process_echocancel(), queue_set_global_params(), queue_set_param(), read_agent_config(), realtime_directory(), reload_config(), rtp_reload(), run_startup_commands(), search_directory(), search_directory_sub(), set_active(), set_config(), sla_load_config(), smdi_load(), speex_write(), stackpeek_read(), start_monitor_action(), strings_to_mask(), tds_load_module(), update_common_options(), xmldoc_get_syntax_cmd(), 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 1587 of file utils.c.
References ONE_MILLION, and tvfix().
Referenced by __get_from_jb(), acf_jabberreceive_read(), agent_hangup(), ast_audiohook_trigger_wait(), ast_channel_bridge(), ast_channel_cmpwhentohangup_tv(), ast_channel_setwhentohangup_tv(), ast_generic_bridge(), ast_poll2(), ast_rtp_dtmf_begin(), ast_rtp_dtmf_end_with_duration(), ast_rtp_sendcng(), ast_sched_runq(), ast_smoother_read(), ast_translate(), calc_rxstamp(), calc_timestamp(), cli_tps_ping(), conf_run(), dial_exec_full(), do_cdr(), do_timing(), iax2_process_thread(), jb_get_and_deliver(), mb_poll_thread(), monmp3thread(), mp3_exec(), mwi_monitor_handler(), NBScat_exec(), sched_run(), sched_settime(), schedule_delivery(), sla_process_timers(), smdi_message_wait(), and timeout_write().
struct timeval ast_tvsub | ( | struct timeval | a, |
struct timeval | b | ||
) |
Returns the difference of two timevals a - b.
Definition at line 1601 of file utils.c.
References ONE_MILLION, and tvfix().
Referenced by ast_channel_bridge(), ast_poll2(), ast_sched_dump(), ast_translate(), ast_waitfor_nandfds(), calc_rxstamp(), calc_timestamp(), cli_tps_ping(), conf_run(), debug_check_frame_for_silence(), handle_showcalls(), handle_showuptime(), and pri_dchannel().
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 1467 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 461 of file utils.c.
Referenced by ast_callerid_parse().
char* ast_unescape_semicolon | ( | char * | s | ) |
Strip backslash for "escaped" semicolons, the string to be stripped (will be modified).
Definition at line 1448 of file utils.c.
Referenced by sip_cli_notify().
void ast_uri_decode | ( | char * | s | ) |
ast_uri_decode: Decode SIP URI, URN, URL (overwrite the string)
Decode URI, URN, URL (overwrite string)
Definition at line 484 of file utils.c.
Referenced by acf_curl_helper(), config_curl(), get_destination(), get_name_and_number(), get_refer_info(), handle_request_invite(), http_decode(), 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, | ||
int | do_special_char | ||
) |
Turn text string to URI-encoded XX version.
Definition at line 398 of file utils.c.
References string.
Referenced by add_rpid(), 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 2193 of file utils.c.
References ARRAY_LEN, ast_cli_register_multiple(), ast_register_atexit(), and base64_init().
Referenced by main().
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 2364 of file utils.c.
References ast_strdupa, and strsep().
Referenced by ast_bt_get_symbols().
int ast_wait_for_input | ( | int | fd, |
int | ms | ||
) |
Definition at line 1255 of file utils.c.
References ast_poll.
Referenced by action_waitevent(), ast_tcptls_server_root(), dahdi_test_timer(), get_input(), moh_class_destructor(), sip_tcptls_read(), tcptls_stream_read(), and tcptls_stream_write().
int ast_wait_for_output | ( | int | fd, |
int | ms | ||
) |
Definition at line 1265 of file utils.c.
References ast_poll.
Referenced by tcptls_stream_read(), and tcptls_stream_write().
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 500 of file utils.c.
References ast_assert, entity, len(), and string.
Referenced by state_notify_build_xml().
|
static |
|
static |
Definition at line 1140 of file utils.c.
References ast_free, AST_LIST_INSERT_TAIL, AST_MUTEX_KIND, ast_register_thread(), ast_threadstorage_get(), ast_unregister_thread(), thr_arg::data, lock_info, thr_arg::name, pthread_mutex_init, pthread_mutex_lock, pthread_mutex_unlock, thr_arg::start_routine, and strdup.
Referenced by ast_pthread_create_stack().
|
static |
Definition at line 1729 of file utils.c.
References ALLOCATOR_OVERHEAD.
Referenced by __ast_calloc_with_stringfields(), and add_string_pool().
|
static |
Definition at line 1572 of file utils.c.
References ast_log(), LOG_WARNING, and ONE_MILLION.
Referenced by ast_tvadd(), and ast_tvsub().
|
static |
Definition at line 1275 of file utils.c.
References ast_debug, ast_log(), ast_poll, ast_tvdiff_ms(), ast_tvnow(), errno, and LOG_ERROR.
Referenced by ast_careful_fwrite(), and ast_carefulwrite().
ast_string_field __ast_string_field_empty = __ast_string_field_empty_buffer.string |
Definition at line 1725 of file utils.c.
Referenced by __ast_calloc_with_stringfields(), __ast_string_field_init(), and __ast_string_field_ptr_build_va().
struct { ... } __ast_string_field_empty_buffer |
ast_string_field_allocation allocation |
Definition at line 1721 of file utils.c.
Referenced by __ast_calloc_with_stringfields().
|
static |
Definition at line 78 of file utils.c.
Referenced by aji_start_sasl().
|
static |
Definition at line 2076 of file utils.c.
Referenced by ast_atomic_fetchadd_int_slow().
|
static |
Definition at line 81 of file utils.c.
Referenced by ast_inet_ntoa().
|
static |
glibc puts a lock inside random(3), so that the results are thread-safe. BSD libc (and others) do not.
Definition at line 1637 of file utils.c.
Referenced by ast_random().
char string[1] |
Definition at line 1722 of file utils.c.
Referenced by ast_escape_quoted(), ast_uri_encode(), ast_xml_escape(), nword(), and private_enum_init().