Asterisk - The Open Source Telephony Project
21.4.1
|
Utility functions. More...
#include "asterisk/network.h"
#include <time.h>
#include <unistd.h>
#include <string.h>
#include "asterisk/lock.h"
#include "asterisk/logger.h"
#include "asterisk/localtime.h"
#include "asterisk/stringfields.h"
#include "asterisk/strings.h"
Go to the source code of this file.
Data Structures | |
struct | ast_eid |
An Entity ID is essentially a MAC address, brief and unique. More... | |
struct | ast_flags |
Structure used to handle boolean flags. More... | |
struct | ast_flags64 |
Structure used to handle a large number of boolean flags == used only in app_dial? More... | |
struct | ast_hostent |
struct | ast_http_digest |
Macros | |
#define | ARRAY_IN_BOUNDS(v, a) IN_BOUNDS((int) (v), 0, ARRAY_LEN(a) - 1) |
Checks to see if value is within the bounds of the given array. More... | |
#define | ARRAY_LEN(a) (size_t) (sizeof(a) / sizeof(0[a])) |
#define | ast_align_for(offset, type) (((offset + __alignof__(type) - 1) / __alignof__(type)) * __alignof__(type)) |
Increase offset so it is a multiple of the required alignment of type. More... | |
#define | ast_alignof(type) __alignof__(type) |
Return the number of bytes used in the alignment of type. More... | |
#define | ast_assert(a) |
#define | ast_assert_return(a, ...) |
#define | AST_BACKGROUND_STACKSIZE ast_background_stacksize() |
#define | ast_clear_flag(p, flag) |
#define | ast_clear_flag64(p, flag) |
#define | ast_clear_flag_nonstd(p, flag) |
#define | ast_copy_flags(dest, src, flagz) |
#define | ast_copy_flags64(dest, src, flagz) |
#define | ast_copy_flags_nonstd(dest, src, flagz) |
#define | ast_fd_clear_flags(fd, flags) __ast_fd_set_flags((fd), (flags), AST_FD_FLAG_CLEAR, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
Clear flags on the given file descriptor. More... | |
#define | ast_fd_set_flags(fd, flags) __ast_fd_set_flags((fd), (flags), AST_FD_FLAG_SET, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
Set flags on the given file descriptor. More... | |
#define | AST_FLAGS_ALL UINT_MAX |
#define | ast_make_room_for(offset, type) (((offset + (2 * __alignof__(type) - 1)) / __alignof__(type)) * __alignof__(type)) |
Increase offset by the required alignment of type and make sure it is a multiple of said alignment. More... | |
#define | ast_pipe_nonblock(filedes) pipe2((filedes), O_NONBLOCK) |
Create a non-blocking pipe. More... | |
#define | ast_pthread_create(a, b, c, d) |
#define | ast_pthread_create_background(a, b, c, d) |
#define | ast_pthread_create_detached(a, b, c, d) |
#define | ast_pthread_create_detached_background(a, b, c, d) |
#define | ast_random_double() (((double)ast_random()) / RAND_MAX) |
Returns a random number between 0.0 and 1.0, inclusive. More... | |
#define | ast_set2_flag(p, value, flag) |
#define | ast_set2_flag64(p, value, flag) |
#define | ast_set2_flag_nonstd(p, value, flag) |
#define | ast_set_flag(p, flag) |
#define | ast_set_flag64(p, flag) |
#define | ast_set_flag_nonstd(p, flag) |
#define | ast_set_flags_to(p, flag, value) |
#define | ast_set_flags_to64(p, flag, value) |
#define | ast_socket_nonblock(domain, type, protocol) socket((domain), (type) | SOCK_NONBLOCK, (protocol)) |
Create a non-blocking socket. More... | |
#define | AST_STACKSIZE (((sizeof(void *) * 8 * 8) - 16) * 1024) |
#define | AST_STACKSIZE_LOW (((sizeof(void *) * 8 * 2) - 16) * 1024) |
#define | ast_test_flag(p, flag) |
#define | ast_test_flag64(p, flag) |
#define | ast_test_flag_nonstd(p, flag) ((p)->flags & (flag)) |
#define | AST_URI_ALPHANUM (1 << 0) |
#define | AST_URI_LEGACY_SPACE (1 << 2) |
#define | AST_URI_MARK (1 << 1) |
#define | AST_URI_SIP_USER_UNRESERVED (1 << 20) |
#define | AST_URI_UNRESERVED (AST_URI_ALPHANUM | AST_URI_MARK) |
#define | DO_CRASH_NORETURN |
#define | IN_BOUNDS(v, min, max) ((v) >= (min)) && ((v) <= (max)) |
Checks to see if value is within the given bounds. More... | |
#define | localtime_r __dont_use_localtime_r_use_ast_localtime_instead__ |
#define | MAX(a, b) ({ typeof(a) __a = (a); typeof(b) __b = (b); ((__a < __b) ? __b : __a);}) |
#define | MIN(a, b) ({ typeof(a) __a = (a); typeof(b) __b = (b); ((__a > __b) ? __b : __a);}) |
#define | RAII_VAR(vartype, varname, initval, dtor) |
Declare a variable that will call a destructor function when it goes out of scope. More... | |
#define | SWAP(a, b) do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) |
Enumerations | |
enum | ast_fd_flag_operation { AST_FD_FLAG_SET, AST_FD_FLAG_CLEAR } |
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) |
int | ast_background_stacksize (void) |
int | ast_base64_encode_file (FILE *inputfile, FILE *outputfile, const char *endl) |
Performs a base 64 encode algorithm on the contents of a File. More... | |
int | ast_base64_encode_file_path (const char *filename, FILE *outputfile, const char *endl) |
Performs a base 64 encode algorithm on the contents of a File. More... | |
int | ast_base64decode (unsigned char *dst, const char *src, int max) |
Decode data from base64. More... | |
char * | ast_base64decode_string (const char *src) |
Same as ast_base64decode, but does the math for you and returns a decoded string. More... | |
int | ast_base64encode (char *dst, const unsigned char *src, int srclen, int max) |
Encode data in base64. More... | |
int | ast_base64encode_full (char *dst, const unsigned char *src, int srclen, int max, int linebreaks) |
encode text to BASE64 coding | |
char * | ast_base64encode_string (const char *src) |
Same as ast_base64encode, but does hte math for you and returns an 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_careful_fwrite (FILE *f, int fd, const char *s, 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... | |
int | ast_check_command_in_path (const char *cmd) |
Test for the presence of an executable command in $PATH. More... | |
int | ast_check_ipv6 (void) |
Test that an OS supports IPv6 Networking. More... | |
int | ast_compare_versions (const char *version1, const char *version2) |
Compare 2 major.minor.patch.extra version strings. More... | |
char * | ast_crypt (const char *key, const char *salt) |
Asterisk wrapper around crypt(3). More... | |
char * | ast_crypt_encrypt (const char *key) |
Asterisk wrapper around crypt(3) for encrypting passwords. More... | |
int | ast_crypt_validate (const char *key, const char *expected) |
Asterisk wrapper around crypt(3) for validating passwords. More... | |
void DO_CRASH_NORETURN | ast_do_crash (void) |
Force a crash if DO_CRASH is defined. More... | |
int | ast_eid_cmp (const struct ast_eid *eid1, const struct ast_eid *eid2) |
Compare two EIDs. More... | |
int | ast_eid_is_empty (const struct ast_eid *eid) |
Check if EID is empty. More... | |
char * | ast_eid_to_str (char *s, int maxlen, struct ast_eid *eid) |
Convert an EID to a string. More... | |
void | ast_enable_packet_fragmentation (int sock) |
Disable PMTU discovery on a socket. More... | |
char * | ast_escape_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_file_is_readable (const char *filename) |
Test that a file exists and is readable by the effective user. More... | |
int | ast_get_tid (void) |
Get current thread ID. More... | |
struct hostent * | ast_gethostbyname (const char *host, struct ast_hostent *hp) |
Thread-safe gethostbyname function to use in Asterisk. More... | |
void | ast_md5_hash (char *output, const char *input) |
Produces MD5 hash based on input string. 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) |
void | ast_register_thread (char *name) |
void | ast_replace_subargument_delimiter (char *s) |
Replace '^' in a string with ','. More... | |
int | ast_safe_mkdir (const char *base_path, const char *path, int mode) |
Recursively create directory path, but only if it resolves within the given base_path. More... | |
void | ast_set_default_eid (struct ast_eid *eid) |
Fill in an ast_eid with the default eid of this machine. More... | |
void | ast_sha1_hash (char *output, const char *input) |
Produces SHA1 hash based on input string. More... | |
void | ast_sha1_hash_uint (uint8_t *digest, const char *input) |
Produces SHA1 hash based on input string, stored in uint8_t array. More... | |
static force_inline void | ast_slinear_saturated_add (short *input, short *value) |
static force_inline void | ast_slinear_saturated_divide (short *input, short *value) |
static force_inline void | ast_slinear_saturated_divide_float (short *input, float *value) |
static force_inline void | ast_slinear_saturated_multiply (short *input, short *value) |
static force_inline void | ast_slinear_saturated_multiply_float (short *input, float *value) |
static force_inline void | ast_slinear_saturated_subtract (short *input, short *value) |
int | ast_str_to_eid (struct ast_eid *eid, const char *s) |
Convert a string into an EID. More... | |
int | ast_thread_is_user_interface (void) |
Indicates whether the current thread is a user interface. More... | |
int | ast_thread_user_interface_set (int is_user_interface) |
Set the current thread's user interface status. More... | |
void | ast_unescape_quoted (char *quote_str) |
Unescape quotes in a string. More... | |
void | ast_unregister_thread (void *id) |
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 *outbuf, size_t buflen) |
Escape reserved characters for use in XML. More... | |
Variables | |
unsigned int | __unsigned_int_flags_dummy |
uint64_t | __unsigned_int_flags_dummy64 |
struct ast_eid | ast_eid_default |
Global EID. More... | |
const struct ast_flags | ast_uri_http |
const struct ast_flags | ast_uri_http_legacy |
const struct ast_flags | ast_uri_sip_user |
Utility functions.
Definition in file utils.h.
#define ARRAY_IN_BOUNDS | ( | v, | |
a | |||
) | IN_BOUNDS((int) (v), 0, ARRAY_LEN(a) - 1) |
#define ast_align_for | ( | offset, | |
type | |||
) | (((offset + __alignof__(type) - 1) / __alignof__(type)) * __alignof__(type)) |
Increase offset so it is a multiple of the required alignment of type.
offset | The value that should be increased. |
type | The data type that offset should be aligned to. |
Many systems prefer integers to be stored on aligned on memory locations. This macro will increase an offset so a value of the supplied type can be safely be stored on such a memory location.
Examples: ast_align_for(0x17, int64_t) ==> 0x18 ast_align_for(0x18, int64_t) ==> 0x18 ast_align_for(0x19, int64_t) ==> 0x20
Don't mind the ugliness, the compiler will optimize it.
#define ast_alignof | ( | type | ) | __alignof__(type) |
#define ast_assert_return | ( | a, | |
... | |||
) |
#define ast_clear_flag_nonstd | ( | p, | |
flag | |||
) |
#define ast_copy_flags_nonstd | ( | dest, | |
src, | |||
flagz | |||
) |
#define ast_fd_clear_flags | ( | fd, | |
flags | |||
) | __ast_fd_set_flags((fd), (flags), AST_FD_FLAG_CLEAR, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
Clear flags on the given file descriptor.
If getting or setting flags of the given file descriptor fails, logs an error message.
fd | File descriptor to clear flags on |
flags | The flag(s) to clear |
-1 | on error |
0 | if successful |
Definition at line 1055 of file utils.h.
Referenced by ast_tcptls_client_start_timeout().
#define ast_fd_set_flags | ( | fd, | |
flags | |||
) | __ast_fd_set_flags((fd), (flags), AST_FD_FLAG_SET, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
Set flags on the given file descriptor.
If getting or setting flags of the given file descriptor fails, logs an error message.
fd | File descriptor to set flags on |
flags | The flag(s) to set |
-1 | on error |
0 | if successful |
Definition at line 1039 of file utils.h.
Referenced by ast_alertpipe_init(), ast_iostream_nonblock(), and websocket_echo_callback().
#define ast_make_room_for | ( | offset, | |
type | |||
) | (((offset + (2 * __alignof__(type) - 1)) / __alignof__(type)) * __alignof__(type)) |
Increase offset by the required alignment of type and make sure it is a multiple of said alignment.
offset | The value that should be increased. |
type | The data type that room should be reserved for. |
A use case for this is when prepending length fields of type int to a buffer. If you keep the offset a multiple of the alignment of the integer type, a next block of length+buffer will have the length field automatically aligned.
Examples: ast_make_room_for(0x17, int64_t) ==> 0x20 ast_make_room_for(0x18, int64_t) ==> 0x20 ast_make_room_for(0x19, int64_t) ==> 0x28
Don't mind the ugliness, the compiler will optimize it.
#define ast_pipe_nonblock | ( | filedes | ) | pipe2((filedes), O_NONBLOCK) |
#define ast_pthread_create | ( | a, | |
b, | |||
c, | |||
d | |||
) |
#define ast_pthread_create_background | ( | a, | |
b, | |||
c, | |||
d | |||
) |
#define ast_pthread_create_detached | ( | a, | |
b, | |||
c, | |||
d | |||
) |
#define ast_pthread_create_detached_background | ( | a, | |
b, | |||
c, | |||
d | |||
) |
#define ast_random_double | ( | ) | (((double)ast_random()) / RAND_MAX) |
Returns a random number between 0.0 and 1.0, inclusive.
Definition at line 624 of file utils.h.
Referenced by gen_salt_char().
#define ast_set_flag_nonstd | ( | p, | |
flag | |||
) |
#define ast_socket_nonblock | ( | domain, | |
type, | |||
protocol | |||
) | socket((domain), (type) | SOCK_NONBLOCK, (protocol)) |
Create a non-blocking socket.
Wrapper around socket(2) that sets the O_NONBLOCK flag on the resulting socket.
For parameter and return information, see the man page for socket(2).
Definition at line 1073 of file utils.h.
Referenced by ast_audiosocket_connect(), ast_tcptls_client_create(), and ast_tcptls_server_start().
#define IN_BOUNDS | ( | v, | |
min, | |||
max | |||
) | ((v) >= (min)) && ((v) <= (max)) |
#define RAII_VAR | ( | vartype, | |
varname, | |||
initval, | |||
dtor | |||
) |
Declare a variable that will call a destructor function when it goes out of scope.
Resource Allocation Is Initialization (RAII) variable declaration.
vartype | The type of the variable |
varname | The name of the variable |
initval | The initial value of the variable |
dtor | The destructor function of type' void func(vartype *)' |
Definition at line 941 of file utils.h.
Referenced by __ast_bucket_scheme_register(), __ast_register_translator(), __ast_sorcery_apply_config(), __ast_sorcery_apply_default(), __ast_sorcery_object_field_register(), __ast_sorcery_object_register(), __ast_sorcery_object_type_insert_wizard(), __ast_sorcery_object_type_remove_wizard(), __ast_sorcery_remove_wizard_mapping(), __ast_vm_greeter_register(), __ast_vm_register(), aco_process_var(), aco_set_defaults(), action_bridge(), action_coreshowchannelmap(), add_format_information_cb(), admin_exec(), agent_login_exec(), agent_request_exec(), app_create(), apply_negotiated_sdp_stream(), ari_bridges_play_found(), ari_bridges_play_helper(), ast_ari_add_handler(), ast_ari_applications_list(), ast_ari_applications_subscribe(), ast_ari_applications_unsubscribe(), ast_ari_asterisk_delete_object(), ast_ari_asterisk_get_global_var(), ast_ari_asterisk_get_info(), ast_ari_asterisk_get_object(), ast_ari_asterisk_update_object(), ast_ari_bridges_add_channel(), ast_ari_bridges_create(), ast_ari_bridges_create_with_id(), ast_ari_bridges_destroy(), ast_ari_bridges_get(), ast_ari_bridges_list(), ast_ari_bridges_record(), ast_ari_bridges_remove_channel(), ast_ari_bridges_start_moh(), ast_ari_bridges_stop_moh(), ast_ari_channels_answer(), ast_ari_channels_continue_in_dialplan(), ast_ari_channels_create(), ast_ari_channels_dial(), ast_ari_channels_get_channel_var(), ast_ari_channels_hangup(), ast_ari_channels_hold(), ast_ari_channels_list(), ast_ari_channels_move(), ast_ari_channels_mute(), ast_ari_channels_record(), ast_ari_channels_redirect(), ast_ari_channels_ring(), ast_ari_channels_ring_stop(), ast_ari_channels_rtpstatistics(), ast_ari_channels_send_dtmf(), ast_ari_channels_set_channel_var(), ast_ari_channels_start_moh(), ast_ari_channels_start_silence(), ast_ari_channels_stop_moh(), ast_ari_channels_stop_silence(), ast_ari_channels_unhold(), ast_ari_channels_unmute(), ast_ari_config_validate_user(), ast_ari_endpoints_get(), ast_ari_endpoints_list(), ast_ari_endpoints_list_by_tech(), ast_ari_json_format(), ast_ari_playbacks_control(), ast_ari_playbacks_get(), ast_ari_playbacks_stop(), ast_ari_recordings_copy_stored(), ast_ari_recordings_delete_stored(), ast_ari_recordings_get_live(), ast_ari_recordings_get_stored(), ast_ari_recordings_get_stored_file(), ast_ari_recordings_list_stored(), ast_ari_response_created(), ast_ari_response_error(), ast_ari_sounds_list(), ast_ari_websocket_session_create(), ast_ari_websocket_session_read(), ast_ari_websocket_session_write(), ast_bridge_add_channel(), ast_bridge_transfer_attended(), ast_bridge_transfer_blind(), ast_bucket_alloc(), ast_bucket_file_alloc(), ast_bucket_file_copy(), ast_bucket_file_json(), ast_bucket_file_metadata_set(), ast_bucket_file_metadata_unset(), ast_bucket_json(), ast_cdr_engine_term(), ast_cdr_fork(), ast_cel_backend_register(), ast_cel_create_event_with_time(), ast_cel_fabricate_channel_from_event(), ast_cel_general_config_alloc(), ast_cel_get_config(), ast_cel_publish_user_event(), ast_channel_get_vars(), ast_channel_make_compatible_helper(), ast_channel_move(), ast_delete_mwi_state_full(), ast_destroy_realtime(), ast_dns_resolve_ipv6_and_ipv4(), ast_do_pickup(), ast_endpoint_shutdown(), ast_http_get_json(), ast_http_get_post_vars(), ast_load_realtime_multientry(), ast_manager_publish_event(), ast_media_get_description(), ast_media_get_format_cap(), ast_media_get_media(), ast_media_get_variants(), ast_named_acl_find(), ast_parked_call_payload_create(), ast_parking_blind_transfer_park(), ast_parking_is_exten_park(), ast_parking_park_bridge_channel(), ast_parking_park_call(), ast_parking_provider_registered(), ast_parking_register_bridge_features(), ast_parking_unregister_bridge_features(), ast_pickup_call(), ast_publish_device_state_full(), ast_queue_hangup_with_cause(), ast_rtcp_interpret(), ast_rtcp_write(), ast_rtp_dtmf_begin(), ast_rtp_publish_rtcp_message(), ast_rtp_read(), ast_safe_mkdir(), ast_set_hangupsource(), ast_softhangup(), ast_sorcery_alloc(), ast_sorcery_copy(), ast_sorcery_create(), ast_sorcery_delete(), ast_sorcery_diff(), ast_sorcery_force_reload_object(), ast_sorcery_get_wizard_mapping(), ast_sorcery_get_wizard_mapping_count(), ast_sorcery_is_stale(), ast_sorcery_load_object(), ast_sorcery_object_fields_register(), ast_sorcery_object_set_copy_handler(), ast_sorcery_object_set_diff_handler(), ast_sorcery_object_set_extended(), ast_sorcery_objectset_apply(), ast_sorcery_objectset_create2(), ast_sorcery_objectset_json_create(), ast_sorcery_observer_add(), ast_sorcery_observer_remove(), ast_sorcery_reload_object(), ast_sorcery_retrieve_by_fields(), ast_sorcery_retrieve_by_prefix(), ast_sorcery_retrieve_by_regex(), ast_sorcery_update(), ast_sorcery_wizard_observer_add(), ast_sorcery_wizard_observer_remove(), ast_speech_new(), ast_store_realtime(), AST_TEST_DEFINE(), ast_translator_best_choice(), ast_unreal_channel_push_to_bridge(), ast_unreal_new_channels(), ast_update2_realtime(), ast_update_realtime(), ast_xmldoc_build_documentation(), ast_xmldoc_query(), ast_xmpp_client_find(), authenticate_api_key(), authenticate_user(), bridge_agent_hold_push(), bridge_p2p_rtp_write(), bridge_timeout(), bucket_alloc(), bucket_file_alloc(), bucket_file_wizard_retrieve(), bucket_wizard_retrieve(), chan_pjsip_add_hold(), chan_pjsip_devicestate(), chan_pjsip_get_hold(), chan_pjsip_incoming_request(), chan_pjsip_new(), chan_pjsip_request_with_stream_topology(), chan_pjsip_session_begin(), change_outgoing_sdp_stream_media_address(), channel_dial_cb(), command_prestart_queue_command(), conf_announce_channel_push(), conf_find_bridge_profile(), conf_find_user_profile(), conf_set_menu_to_user(), confbridge_handle_atxfer(), create_outgoing_sdp_stream(), create_sound_blob(), curler(), event_session_alloc(), fax_detect_framehook(), fax_gateway_framehook(), find_bridge(), find_channel_control(), find_control(), func_get_parkingslot_channel(), generic_fax_exec(), get_languages(), get_media_encryption_type(), handle_attended_transfer(), handle_blind_transfer(), handle_exec(), handle_options(), handle_updates(), hep_queue_cb(), hepv3_config_post_apply(), hepv3_get_uuid_type(), hepv3_is_loaded(), hepv3_send_packet(), is_enabled(), jingle_endpoint_state_find_or_create(), jingle_request(), leave_queue(), local_optimization_finished_cb(), local_optimization_started_cb(), main(), manager_build_parked_call_string(), manager_mute_mixmonitor(), messaging_app_subscribe_endpoint(), messaging_app_unsubscribe_endpoint(), mwi_app_event_cb(), negotiate_incoming_sdp_stream(), object_type_loaded_observer(), park_application_setup(), parking_config_alloc(), parking_dynamic_lots_enabled(), parking_lot_cfg_create_extensions(), parking_lot_retrieve_parked_user(), pbx_outgoing_exec(), pjsip_acf_dial_contacts_read(), play_on_channel_in_bridge(), process_config(), process_description_file(), prometheus_config_post_apply(), prometheus_general_config_get(), prometheus_general_config_set(), publish_dahdichannel(), publish_load_message_type(), publish_parked_call(), publish_parked_call_failure(), realtime_ldap_base(), receivefax_exec(), record_abandoned(), recording_alloc(), report_fax_status(), report_receive_fax_status(), report_send_fax_status(), restrictedFile(), ring_entry(), rna(), send_agent_complete(), sendfax_exec(), session_refresh_state_get_or_alloc(), sfu_topologies_on_join(), skel_find_or_create_state(), sla_check_station_delay(), snoop_stasis_thread(), sorcery_astdb_retrieve_fields_common(), sorcery_is_criteria_met(), sorcery_reloadable(), spandsp_fax_gateway_start(), speech_background(), split_path(), stasis_app_bridge_playback_channel_add(), stasis_app_control_record(), stasis_app_control_snoop(), stasis_app_exec(), stasis_app_playback_to_json(), stasis_app_recording_options_create(), stasis_app_recording_to_json(), stasis_app_user_event(), stasis_message_sink_create(), stasis_test_message_create(), stasis_topic_pool_get_topic(), stun_monitor_request(), t38_automatic_reject(), t38_interpret_parameters(), t38_state_get_or_alloc(), test_cel_peer_strings_match(), transmit_info_with_vidupdate(), update_registry(), user_alloc(), xmpp_action_hook(), xmpp_cli_create_collection(), xmpp_cli_create_leafnode(), xmpp_cli_delete_pubsub_node(), xmpp_cli_list_pubsub_nodes(), xmpp_cli_purge_pubsub_nodes(), xmpp_client_find_or_create(), xmpp_client_reconnect(), xmpp_client_send_message(), xmpp_client_set_presence(), xmpp_client_thread(), xmpp_component_register_get_hook(), xmpp_component_service_discovery_get_hook(), xmpp_component_service_discovery_items_hook(), xmpp_connect_hook(), xmpp_init_event_distribution(), xmpp_join_exec(), xmpp_leave_exec(), xmpp_log_hook(), xmpp_pubsub_build_publish_skeleton(), xmpp_pubsub_iq_create(), xmpp_pubsub_publish_device_state(), xmpp_pubsub_subscribe(), xmpp_roster_hook(), and xmpp_sendgroup_exec().
int ast_base64_encode_file | ( | FILE * | inputfile, |
FILE * | outputfile, | ||
const char * | endl | ||
) |
Performs a base 64 encode algorithm on the contents of a File.
inputfile | A FILE handle to the input file to be encoded. Must be readable. This handle is not automatically closed. |
outputfile | A FILE handle to the output file to receive the base 64 encoded contents of the input file, identified by filename. |
endl | The line ending to use (e.g. either "\n" or "\r\n") |
Definition at line 648 of file utils.c.
References BASEMAXINLINE, inchar(), and ochar().
Referenced by ast_base64_encode_file_path().
int ast_base64_encode_file_path | ( | const char * | filename, |
FILE * | outputfile, | ||
const char * | endl | ||
) |
Performs a base 64 encode algorithm on the contents of a File.
filename | The path to the file to be encoded. Must be readable, file is opened in read mode. |
outputfile | A FILE handle to the output file to receive the base 64 encoded contents of the input file, identified by filename. |
endl | The line ending to use (e.g. either "\n" or "\r\n") |
Definition at line 702 of file utils.c.
References ast_base64_encode_file().
int ast_base64decode | ( | unsigned char * | dst, |
const char * | src, | ||
int | max | ||
) |
Decode data from base64.
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. |
Decode data from base64.
Definition at line 296 of file utils.c.
Referenced by ast_base64decode_string(), ast_check_signature(), and ast_http_get_auth().
char* ast_base64decode_string | ( | const char * | src | ) |
Same as ast_base64decode, but does the math for you and returns a decoded string.
src | The source buffer |
NULL | on failure |
Same as ast_base64decode, but does the math for you and returns a decoded string.
Definition at line 323 of file utils.c.
References ast_base64decode(), and ast_malloc.
int ast_base64encode | ( | char * | dst, |
const unsigned char * | src, | ||
int | srclen, | ||
int | max | ||
) |
Encode data in base64.
dst | the destination buffer |
src | the source data to be encoded |
srclen | the number of bytes present in the source buffer |
max | the maximum number of bytes to write into the destination buffer, including the terminating NULL character. |
Definition at line 406 of file utils.c.
References ast_base64encode_full().
Referenced by ast_base64encode_string(), ast_sign(), and xmpp_client_authenticate_sasl().
char* ast_base64encode_string | ( | const char * | src | ) |
Same as ast_base64encode, but does hte math for you and returns an encoded string.
src | The source buffer |
NULL | on failure |
Same as ast_base64encode, but does hte math for you and returns an encoded string.
Definition at line 412 of file utils.c.
References ast_base64encode(), and ast_calloc.
int ast_base64url_decode | ( | unsigned char * | dst, |
const char * | src, | ||
int | max | ||
) |
Decode data from base64 URL.
dst | The destination buffer |
src | The source buffer |
max | The maximum number of bytes to write into the destination buffer. Note that this function will not ensure that the destination buffer is NULL terminated. So, in general, this parameter should be sizeof(dst) - 1 |
Definition at line 429 of file utils.c.
Referenced by ast_base64url_decode_string().
char* ast_base64url_decode_string | ( | const char * | src | ) |
Decode string from base64 URL.
src | The source buffer |
NULL | on failure |
Definition at line 450 of file utils.c.
References ast_base64url_decode(), and ast_malloc.
int ast_base64url_encode | ( | char * | dst, |
const unsigned char * | src, | ||
int | srclen, | ||
int | max | ||
) |
Encode data in base64 URL.
dst | The destination buffer |
src | The source data to be encoded |
srclen | The number of bytes present in the source buffer |
max | The maximum number of bytes to write into the destination buffer, including the terminating NULL character |
Definition at line 518 of file utils.c.
References ast_base64url_encode_full().
Referenced by ast_base64url_encode_string().
int ast_base64url_encode_full | ( | char * | dst, |
const unsigned char * | src, | ||
int | srclen, | ||
int | max, | ||
int | linebreaks | ||
) |
Same as ast_base64encode_full but for base64 URL.
dst | The destination buffer |
src | The source buffer |
srclen | The number of bytes present in the source buffer |
max | The maximum number of bytes to write into the destination buffer, including the terminating NULL character. |
linebreaks | Set to 1 if there should be linebreaks inserted in the result |
Definition at line 471 of file utils.c.
Referenced by ast_base64url_encode().
char* ast_base64url_encode_string | ( | const char * | src | ) |
Encode string in base64 URL.
src | The source data to be encoded |
NULL | on failure |
Definition at line 523 of file utils.c.
References ast_base64url_encode(), and ast_malloc.
int ast_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 |
int ast_carefulwrite | ( | int | fd, |
char * | s, | ||
int | len, | ||
int | timeoutms | ||
) |
Try to write string, but wait no more than ms milliseconds before timing out.
Try to write string, but wait no more than ms milliseconds before timing out.
Definition at line 1771 of file utils.c.
References ast_debug, ast_tvdiff_ms(), and ast_tvnow().
int ast_check_command_in_path | ( | const char * | cmd | ) |
Test for the presence of an executable command in $PATH.
cmd | Name of command to locate. |
True | (non-zero) if command is in $PATH. |
False | (zero) command not found. |
Definition at line 3263 of file utils.c.
References ast_strdup.
int ast_check_ipv6 | ( | void | ) |
Test that an OS supports IPv6 Networking.
True | (non-zero) if the IPv6 supported. |
False | (zero) if the OS doesn't support IPv6. |
Definition at line 2792 of file utils.c.
Referenced by load_module().
int ast_compare_versions | ( | const char * | version1, |
const char * | version2 | ||
) |
char* ast_crypt | ( | const char * | key, |
const char * | salt | ||
) |
Asterisk wrapper around crypt(3).
The interpretation of the salt (which determines the password hashing algorithm) is system specific. Application code should prefer to use ast_crypt_encrypt() or ast_crypt_validate().
The returned string is heap allocated, and should be freed with ast_free().
key | User's password to crypt. |
salt | Salt to crypt with. |
NULL | on error. |
Definition at line 121 of file crypt.c.
References ast_begins_with(), and ast_strdup.
Referenced by ast_crypt_encrypt().
char* ast_crypt_encrypt | ( | const char * | key | ) |
Asterisk wrapper around crypt(3) for encrypting passwords.
This function will generate a random salt and encrypt the given password.
The returned string is heap allocated, and should be freed with ast_free().
key | User's password to crypt. |
NULL | on error. |
Definition at line 190 of file crypt.c.
References ast_crypt(), gen_salt(), and MAX_SALT_LEN.
int ast_crypt_validate | ( | const char * | key, |
const char * | expected | ||
) |
Asterisk wrapper around crypt(3) for validating passwords.
key | User's password to validate. |
expected | Expected result from crypt. |
True | (non-zero) if key matches expected. |
False | (zero) if key doesn't match. |
Definition at line 136 of file crypt.c.
Referenced by ast_ari_config_validate_user().
void DO_CRASH_NORETURN ast_do_crash | ( | void | ) |
Force a crash if DO_CRASH is defined.
Definition at line 2804 of file utils.c.
Referenced by optional_api_create(), and optional_api_user_create().
Compare two EIDs.
0 | if the two are the same |
non-zero | otherwise |
Definition at line 3094 of file utils.c.
Referenced by publish_cluster_discovery_to_stasis(), xmpp_pubsub_devstate_cb(), xmpp_pubsub_handle_event(), and xmpp_pubsub_mwi_cb().
int ast_eid_is_empty | ( | const struct ast_eid * | eid | ) |
Check if EID is empty.
1 | if the EID is empty |
0 | otherwise |
Definition at line 3099 of file utils.c.
Referenced by load_module().
char* ast_eid_to_str | ( | char * | s, |
int | maxlen, | ||
struct ast_eid * | eid | ||
) |
Convert an EID to a string.
Definition at line 2839 of file utils.c.
Referenced by app_send(), ast_ari_asterisk_get_info(), ast_ari_asterisk_ping(), ast_set_default_eid(), ast_str_retrieve_variable(), do_register(), do_register_expire(), handle_show_settings(), prometheus_config_post_apply(), publish_cluster_discovery_to_stasis_full(), publish_device_state_to_stasis(), publish_mwi_to_stasis(), xmpp_pubsub_publish_device_state(), and xmpp_pubsub_publish_mwi().
void ast_enable_packet_fragmentation | ( | int | sock | ) |
Disable PMTU discovery on a socket.
sock | The socket to manipulate |
On Linux, UDP sockets default to sending packets with the Dont Fragment (DF) bit set. This is supposedly done to allow the application to do PMTU discovery, but Asterisk does not do this.
Because of this, UDP packets sent by Asterisk that are larger than the MTU of any hop in the path will be lost. This function can be called on a socket to ensure that the DF bit will not be set.
Definition at line 2469 of file utils.c.
char* ast_escape_quoted | ( | const char * | string, |
char * | outbuf, | ||
int | buflen | ||
) |
Escape characters found in a quoted string.
string | string to be escaped |
outbuf | resulting escaped string |
buflen | size of output buffer |
Definition at line 781 of file utils.c.
char* ast_escape_semicolons | ( | const char * | string, |
char * | outbuf, | ||
int | buflen | ||
) |
Escape semicolons found in a string.
string | string to be escaped |
outbuf | resulting escaped string |
buflen | size of output buffer |
Definition at line 811 of file utils.c.
Referenced by ast_config_text_file_save2(), and handle_cli_dialplan_save().
int ast_file_is_readable | ( | const char * | filename | ) |
Test that a file exists and is readable by the effective user.
filename | File to test. |
True | (non-zero) if the file exists and is readable. |
False | (zero) if the file either doesn't exists or is not readable. |
Definition at line 3107 of file utils.c.
Referenced by ast_media_cache_retrieve(), and ast_rtp_dtls_cfg_parse().
int ast_get_tid | ( | void | ) |
Get current thread ID.
Definition at line 2752 of file utils.c.
Referenced by ast_hangup().
struct hostent* ast_gethostbyname | ( | const char * | host, |
struct ast_hostent * | hp | ||
) |
Thread-safe gethostbyname function to use in Asterisk.
ast_sockaddr_resolve()
and ast_sockaddr_resolve_first_af()
Thread-safe gethostbyname function to use in Asterisk.
Definition at line 199 of file utils.c.
void ast_md5_hash | ( | char * | output, |
const char * | input | ||
) |
int ast_mkdir | ( | const char * | path, |
int | mode | ||
) |
Recursively create directory path.
path | The directory path to create |
mode | The permissions with which to try to create the directory |
0 | on success |
Creates a directory path, creating parent directories as needed.
Definition at line 2479 of file utils.c.
References ast_alloca, and ast_strdupa.
Referenced by ast_file_fdtemp(), ast_logger_rotate_channel(), create_dirpath(), init_logger(), remove_from_queue(), setup_privacy_args(), sms_nextoutgoing(), and sms_writefile().
int ast_parse_digest | ( | const char * | digest, |
struct ast_http_digest * | d, | ||
int | request, | ||
int | pedantic | ||
) |
Parse digest authorization header.
Definition at line 2638 of file utils.c.
References ast_skip_blanks(), ast_str_buffer(), ast_str_create, ast_str_set(), ast_string_field_ptr_set, ast_string_field_set, and ast_unescape_c().
char* ast_process_quotes_and_slashes | ( | char * | start, |
char | find, | ||
char | replace_with | ||
) |
void ast_replace_subargument_delimiter | ( | char * | s | ) |
Replace '^' in a string with ','.
s | String within which to replace characters |
Definition at line 2343 of file utils.c.
Referenced by ast_bridge_set_after_go_on(), dial_exec_full(), and queue_exec().
int ast_safe_mkdir | ( | const char * | base_path, |
const char * | path, | ||
int | mode | ||
) |
Recursively create directory path, but only if it resolves within the given base_path.
If base_path does not exist, it will not be created and this function returns EPERM
.
base_path | |
path | The directory path to create |
mode | The permissions with which to try to create the directory |
0 | on success |
Definition at line 2584 of file utils.c.
References ast_strdup, and RAII_VAR.
Referenced by stasis_app_control_record().
void ast_set_default_eid | ( | struct ast_eid * | eid | ) |
Fill in an ast_eid with the default eid of this machine.
Definition at line 3001 of file utils.c.
References ast_debug, ast_eid_to_str(), and ast_malloc.
void ast_sha1_hash | ( | char * | output, |
const char * | input | ||
) |
Produces SHA1 hash based on input string.
Produces SHA1 hash based on input string.
Definition at line 266 of file utils.c.
References SHA1Input(), SHA1Reset(), and SHA1Result().
Referenced by ast_tcptls_server_start(), xmpp_client_authenticate_digest(), and xmpp_component_authenticate().
void ast_sha1_hash_uint | ( | uint8_t * | digest, |
const char * | input | ||
) |
Produces SHA1 hash based on input string, stored in uint8_t array.
Produces SHA1 hash based on input string, stored in uint8_t array.
Definition at line 284 of file utils.c.
References SHA1Input(), SHA1Reset(), and SHA1Result().
int ast_str_to_eid | ( | struct ast_eid * | eid, |
const char * | s | ||
) |
Convert a string into an EID.
This function expects an EID in the format: 00:11:22:33:44:55
0 | success |
non-zero | failure |
Definition at line 3077 of file utils.c.
Referenced by xmpp_pubsub_handle_event().
int ast_thread_is_user_interface | ( | void | ) |
Indicates whether the current thread is a user interface.
True | (non-zero) if thread is a user interface. |
False | (zero) if thread is not a user interface. |
Definition at line 3248 of file utils.c.
References ast_threadstorage_get().
Referenced by ast_autoservice_start(), and ast_autoservice_stop().
int ast_thread_user_interface_set | ( | int | is_user_interface | ) |
Set the current thread's user interface status.
is_user_interface | Non-zero to mark the thread as a user interface. |
True | (non-zero) if marking current thread failed. |
False | (zero) if successfuly marked current thread. |
Definition at line 3233 of file utils.c.
References ast_threadstorage_get().
Referenced by handle_tcptls_connection().
void ast_unescape_quoted | ( | char * | quote_str | ) |
Unescape quotes in a string.
quote_str | The string with quotes to be unescaped |
Definition at line 842 of file utils.c.
Referenced by ast_callerid_parse(), ast_strsep(), and ast_strsep_quoted().
void ast_uri_decode | ( | char * | s, |
struct ast_flags | spec | ||
) |
Decode URI, URN, URL (overwrite string)
s | string to be decoded |
spec | flags describing how the decoding should be performed |
Definition at line 762 of file utils.c.
Referenced by ast_http_get_post_vars(), realtime_curl(), realtime_multi_curl(), and uridecode().
char* ast_uri_encode | ( | const char * | string, |
char * | outbuf, | ||
int | buflen, | ||
struct ast_flags | spec | ||
) |
Turn text string to URI-encoded XX version.
This function encodes characters according to the rules presented in RFC 2396 and/or RFC 3261 section 19.1.2 and section 25.1.
Outbuf needs to have more memory allocated than the instring to have room for the expansion. Every byte that is converted is replaced by three ASCII characters.
string | string to be converted |
outbuf | resulting encoded string |
buflen | size of output buffer |
spec | flags describing how the encoding should be performed |
Definition at line 723 of file utils.c.
Referenced by ast_ari_bridges_record(), ast_ari_channels_record(), destroy_curl(), realtime_curl(), realtime_multi_curl(), store_curl(), update_curl(), and uriencode().
char* ast_utils_which | ( | const char * | binary, |
char * | fullpath, | ||
size_t | fullpath_size | ||
) |
Resolve a binary to a full pathname.
binary | Name of the executable to resolve |
fullpath | Buffer to hold the complete pathname |
fullpath_size | Size of fullpath |
NULL | binary was not found or the environment variable PATH is not set |
Definition at line 2774 of file utils.c.
References ast_strdupa.
int ast_xml_escape | ( | const char * | string, |
char * | outbuf, | ||
size_t | buflen | ||
) |
Escape reserved characters for use in XML.
ast_xml_escape If outbuf is too short, the output string will be truncated. Regardless, the output will always be null terminated.
string | String to be converted |
outbuf | Resulting encoded string |
buflen | Size of output buffer |
0 | for success |
-1 | if buflen is too short. |
Definition at line 864 of file utils.c.
Referenced by ast_http_create_response().
unsigned int __unsigned_int_flags_dummy |
Note: It is very important to use only unsigned variables to hold bit flags, as otherwise you can fall prey to the compiler's sign-extension antics if you try to use the top two bits in your variable. The flag macros below use a set of compiler tricks to verify that the caller is using an "unsigned int" variable to hold the flags, and nothing else. If the caller uses any other type of variable, a warning message similar to this: warning: comparison of distinct pointer types lacks cast will be generated. The "dummy" variable below is used to make these comparisons. Also note that at -O2 or above, this type-safety checking does _not_ produce any additional object code at all.
struct ast_eid ast_eid_default |
Global EID.
This is set in asterisk.conf, or determined automatically by taking the mac address of an Ethernet interface on the system.
Definition at line 93 of file options.c.
Referenced by app_send(), ast_ari_asterisk_get_info(), ast_ari_asterisk_ping(), ast_delete_mwi_state_full(), ast_device_state_clear_cache(), ast_event_append_eid(), ast_str_retrieve_variable(), handle_show_settings(), load_module(), prometheus_config_post_apply(), publish_cluster_discovery_to_stasis(), stasis_cache_dump(), stasis_cache_get(), stasis_message_create(), xmpp_pubsub_devstate_cb(), xmpp_pubsub_handle_event(), xmpp_pubsub_mwi_cb(), xmpp_pubsub_publish_device_state(), and xmpp_pubsub_publish_mwi().