#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 |
Defines | |
| #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. | |
| #define | ast_alignof(type) __alignof__(type) |
| Return the number of bytes used in the alignment of type. | |
| #define | ast_asprintf(ret, fmt,...) _ast_asprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, __VA_ARGS__) |
| A wrapper for asprintf(). | |
| #define | ast_assert(a) |
| #define | AST_BACKGROUND_STACKSIZE AST_STACKSIZE |
| #define | ast_calloc(num, len) _ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) |
| A wrapper for calloc(). | |
| #define | ast_calloc_cache(num, len) _ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) |
| A wrapper for calloc() for use in cache pools. | |
| #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_FLAGS_ALL UINT_MAX |
| #define | ast_free free |
| free() wrapper | |
| #define | ast_free_ptr ast_free |
| #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. | |
| #define | ast_malloc(len) _ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__) |
| A wrapper for malloc(). | |
| #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_realloc(p, len) _ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) |
| A wrapper for realloc(). | |
| #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_STACKSIZE (((sizeof(void *) * 8 * 8) - 16) * 1024) |
| #define | ast_strdup(str) _ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__) |
| A wrapper for strdup(). | |
| #define | ast_strdupa(s) |
| duplicate a string in memory from the stack | |
| #define | ast_strndup(str, len) _ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) |
| A wrapper for strndup(). | |
| #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 | ast_vasprintf(ret, fmt, ap) _ast_vasprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, (fmt), (ap)) |
| A wrapper for vasprintf(). | |
| #define | localtime_r __dont_use_localtime_r_use_ast_localtime_instead__ |
| #define | MALLOC_FAILURE_MSG ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file); |
| #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);}) |
Functions | |
| int | _ast_asprintf (char **ret, const char *file, int lineno, const char *func, const char *fmt,...) |
| void * | _ast_calloc (size_t num, size_t len, const char *file, int lineno, const char *func) |
| void * | _ast_malloc (size_t len, const char *file, int lineno, const char *func) |
| void * | _ast_realloc (void *p, size_t len, const char *file, int lineno, const char *func) |
| char * | _ast_strdup (const char *str, const char *file, int lineno, const char *func) |
| char * | _ast_strndup (const char *str, size_t len, const char *file, int lineno, const char *func) |
| int | _ast_vasprintf (char **ret, const char *file, int lineno, const char *func, const char *fmt, va_list ap) |
| int | ast_base64decode (unsigned char *dst, const char *src, int max) |
| Decode data from base64. | |
| int | ast_base64encode (char *dst, const unsigned char *src, int srclen, int max) |
| Encode data in base64. | |
| int | ast_base64encode_full (char *dst, const unsigned char *src, int srclen, int max, int linebreaks) |
| encode text to BASE64 coding | |
| 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. | |
| 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. | |
| int | ast_eid_cmp (const struct ast_eid *eid1, const struct ast_eid *eid2) |
| Compare two EIDs. | |
| char * | ast_eid_to_str (char *s, int maxlen, struct ast_eid *eid) |
| void | ast_enable_packet_fragmentation (int sock) |
| Disable PMTU discovery on a socket. | |
| char * | ast_escape_quoted (const char *string, char *outbuf, int buflen) |
| Escape characters found in a quoted string. | |
| int | ast_get_tid (void) |
| Get current thread ID. | |
| struct hostent * | ast_gethostbyname (const char *host, struct ast_hostent *hp) |
| Thread-safe gethostbyname function to use in Asterisk. | |
| void | ast_md5_hash (char *output, const char *input) |
| Produces MD5 hash based on input string. | |
| int | ast_mkdir (const char *path, int mode) |
| Recursively create directory path. | |
| int | ast_parse_digest (const char *digest, struct ast_http_digest *d, int request, int pedantic) |
| Parse digest authorization header. | |
| char * | ast_process_quotes_and_slashes (char *start, char find, char replace_with) |
| Process a string to find and replace characters. | |
| 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_set_default_eid (struct ast_eid *eid) |
| Fill in an ast_eid with the default eid of this machine. | |
| void | ast_sha1_hash (char *output, const char *input) |
| Produces SHA1 hash based on input string. | |
| 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_multiply (short *input, short *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. | |
| void | ast_unregister_thread (void *id) |
| void | ast_uri_decode (char *s, struct ast_flags spec) |
| Decode URI, URN, URL (overwrite string). | |
| char * | ast_uri_encode (const char *string, char *outbuf, int buflen, struct ast_flags spec) |
| Turn text string to URI-encoded XX version. | |
| 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. | |
| int | ast_wait_for_input (int fd, int ms) |
Variables | |
| unsigned int | __unsigned_int_flags_dummy |
| uint64_t | __unsigned_int_flags_dummy64 |
| struct ast_eid | ast_eid_default |
| Global EID. | |
| struct ast_flags | ast_uri_http |
| struct ast_flags | ast_uri_http_legacy |
| struct ast_flags | ast_uri_sip_user |
Definition in file utils.h.
| #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. |
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.
Definition at line 771 of file utils.h.
Referenced by __ast_string_field_ptr_build_va().
Return the number of bytes used in the alignment of type.
| type |
Definition at line 751 of file utils.h.
Referenced by __ast_string_field_alloc_space(), and __ast_string_field_ptr_build_va().
| #define ast_asprintf | ( | ret, | |||
| fmt, | |||||
| ... | ) | _ast_asprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, __VA_ARGS__) |
A wrapper for asprintf().
ast_asprintf() is a wrapper for asprintf() that will generate an Asterisk log message in the case that the allocation fails.
The arguments and return value are the same as asprintf()
| #define ast_assert | ( | a | ) |
Definition at line 738 of file utils.h.
Referenced by __ast_string_field_alloc_space(), _ast_odbc_request_obj2(), append_ie(), ast_cc_is_recall(), ast_channel_get_cc_config_params(), ast_hangup(), ast_rtcp_read(), ast_rtp_read(), ast_sched_del(), ast_udptl_read(), cc_generic_agent_start_monitoring(), cc_generic_agent_start_offer_timer(), cc_generic_monitor_cancel_available_timer(), check_callback_sanity(), create_jb(), create_new_sip_etag(), determine_sip_publish_type(), find_timer(), handle_response_publish(), jb_get_and_deliver(), parkinglot_destroy(), pthread_timer_ack(), publish_expire(), read_pipe(), security_event_cb(), sip_cc_agent_init(), and sip_cc_monitor_unsuspend().
| #define ast_calloc | ( | num, | |||
| len | ) | _ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) |
| #define ast_calloc_cache | ( | num, | |||
| len | ) | _ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) |
A wrapper for calloc() for use in cache pools.
ast_calloc_cache() is a wrapper for calloc() that will generate an Asterisk log message in the case that the allocation fails. When memory debugging is in use, the memory allocated by this function will be marked as 'cache' so it can be distinguished from normal memory allocations.
The arguments and return value are the same as calloc()
| #define ast_clear_flag | ( | p, | |||
| flag | ) |
Definition at line 77 of file utils.h.
Referenced by __analog_ss_thread(), __ast_pbx_run(), __ast_read(), __do_deliver(), __transmit_response(), aji_create_client(), aji_filter_roster(), aji_load_config(), analog_ss_thread(), app_exec(), ast_audiohook_set_mute(), ast_autoservice_stop(), ast_bridge_call(), ast_cdr_reset(), ast_cdr_specialized_reset(), ast_channel_bridge(), ast_channel_undefer_dtmf(), ast_deactivate_generator(), ast_generic_bridge(), ast_jb_destroy(), ast_jb_put(), ast_rtp_raw_write(), ast_sendtext(), ast_speech_start(), ast_tls_read_conf(), ast_waitfor_nandfds(), ast_waitfordigit_full(), ast_write(), bridge_channel_feature(), bridge_p2p_rtp_write(), builtin_atxfer(), change_hold_state(), change_spy_mode(), channel_spy(), chanspy_exec(), check_goto_on_transfer(), check_pendings(), check_via(), common_exec(), config_function_read(), config_text_file_load(), dahdi_read(), dahdiscan_exec(), dial_exec_full(), dictate_exec(), disa_exec(), dundi_lookup_local(), extenspy_exec(), forward_message(), handle_command_response(), handle_common_options(), handle_exec(), handle_request_bye(), handle_request_invite(), handle_request_refer(), handle_response(), handle_response_notify(), handle_speechrecognize(), handle_t38_options(), handle_verbose(), init_acf_query(), initialize_udptl(), linear_alloc(), load_config(), load_moh_classes(), local_ast_moh_stop(), local_attended_transfer(), local_hangup(), main(), manage_parked_call(), manager_optimize_away(), odbc_load_module(), park_call_full(), parkandannounce_exec(), parse_options(), phone_read(), playtones_alloc(), process_sdp(), register_verify(), reload_config(), reset_transaction(), set_config(), set_config_flags(), setup_dahdi_int(), sip_call(), sip_dtmfmode(), sip_hangup(), sip_parse_nat_option(), socket_process(), speech_background(), try_calling(), update_call_counter(), update_connectedline(), and waitstream_core().
| #define ast_clear_flag64 | ( | p, | |||
| flag | ) |
Definition at line 134 of file utils.h.
Referenced by authenticate_verify(), build_peer(), build_user(), conf_run(), create_addr(), do_forward(), find_conf(), find_conf_realtime(), iax2_destroy_helper(), iax2_setoption(), set_config(), set_config_destroy(), socket_process(), and wait_for_answer().
| #define ast_clear_flag_nonstd | ( | p, | |||
| flag | ) |
Value:
do { \ ((p)->flags &= ~(flag)); \ } while(0)
Definition at line 180 of file utils.h.
Referenced by build_transactions(), cache_lookup_internal(), dundi_lookup_local(), dundi_prop_precache(), and handle_command_response().
| #define ast_copy_flags | ( | dest, | |||
| src, | |||||
| flagz | ) |
Definition at line 84 of file utils.h.
Referenced by add_features_datastores(), agent_read(), aji_create_client(), aji_filter_roster(), ast_call_forward(), ast_cdr_reset(), ast_cdr_specialized_reset(), ast_frdup(), ast_frisolate(), build_peer(), builtin_atxfer(), cache_lookup_internal(), channel_spy(), check_peer_ok(), create_addr_from_peer(), dundi_lookup_local(), feature_interpret(), framein(), minivm_greet_exec(), minivm_record_exec(), parked_call_exec(), populate_defaults(), realtime_peer(), register_verify(), set_peer_defaults(), sip_alloc(), sip_poke_peer(), transmit_response_using_temp(), and vm_exec().
| #define ast_copy_flags64 | ( | dest, | |||
| src, | |||||
| flagz | ) |
Definition at line 141 of file utils.h.
Referenced by __find_callno(), build_peer(), build_user(), check_access(), create_addr(), dial_exec_full(), find_conf_realtime(), iax2_request(), realtime_peer(), and wait_for_answer().
| #define ast_copy_flags_nonstd | ( | dest, | |||
| src, | |||||
| flagz | ) |
| #define AST_FLAGS_ALL UINT_MAX |
Definition at line 196 of file utils.h.
Referenced by add_features_datastores(), aji_create_client(), ast_cdr_reset(), ast_cdr_specialized_reset(), ast_frdup(), ast_frisolate(), builtin_atxfer(), cache_lookup_internal(), channel_spy(), chanspy_exec(), check_goto_on_transfer(), dahdiscan_exec(), dundi_lookup_local(), extenspy_exec(), feature_interpret(), handle_queue_reload(), load_module(), load_moh_classes(), manager_queue_reload(), parked_call_exec(), parse_options(), populate_defaults(), reload(), reload_config(), and set_config_flags().
| #define ast_free free |
| #define ast_free_ptr ast_free |
Definition at line 454 of file utils.h.
Referenced by add_extensions(), ast_extension_state(), ast_extension_state_add_destroy(), ast_merge_contexts_and_delete(), handle_cli_dialplan_add_extension(), load_module(), manage_parked_call(), park_call_full(), parkinglot_activate(), pbx_load_config(), pbx_load_users(), register_exten(), register_peer_exten(), sla_build_station(), and sla_build_trunk().
| #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. |
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.
Definition at line 794 of file utils.h.
Referenced by __ast_string_field_alloc_space(), and __ast_string_field_ptr_build_va().
| #define ast_malloc | ( | len | ) | _ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__) |
| #define ast_pthread_create | ( | a, | |||
| b, | |||||
| c, | |||||
| d | ) |
Value:
ast_pthread_create_stack(a, b, c, d, \ 0, __FILE__, __FUNCTION__, __LINE__, #c)
Definition at line 409 of file utils.h.
Referenced by accept_thread(), ast_bridge_impart(), ast_dial_run(), ast_features_init(), ast_taskprocessor_get(), bridge_call_thread_launch(), bridge_channel_join(), build_calendar(), function_autopatchup(), HandleCallOutgoing(), init_logger(), load_module(), local_dtmf_helper(), multiplexed_add_or_remove(), restart_monitor(), rpt_master(), rpt_telemetry(), setsubstate(), setup_dahdi_int(), sla_load_config(), and start_poll_thread().
| #define ast_pthread_create_background | ( | a, | |||
| b, | |||||
| c, | |||||
| d | ) |
Value:
ast_pthread_create_stack(a, b, c, d, \ AST_BACKGROUND_STACKSIZE, \ __FILE__, __FUNCTION__, __LINE__, #c)
Definition at line 417 of file utils.h.
Referenced by add_notify(), aji_reload(), ast_autoservice_start(), ast_device_state_engine_init(), ast_enable_distributed_devstate(), ast_makesocket(), ast_safe_fork(), ast_sched_start_thread(), ast_tcptls_server_start(), astdb_init(), calendar_event_notify(), conf_run(), conf_start_record(), config_load(), db_start_batch(), do_monitor(), do_reload(), find_idle_thread(), init_app_class(), init_timing_thread(), load_module(), local_ast_moh_start(), restart_monitor(), restart_pktc_thread(), sip_prepare_socket(), smdi_load(), start_network_thread(), start_stream(), store_config(), and usbradio_call().
| #define ast_pthread_create_detached | ( | a, | |||
| b, | |||||
| c, | |||||
| d | ) |
Value:
ast_pthread_create_detached_stack(a, b, c, d, \ 0, __FILE__, __FUNCTION__, __LINE__, #c)
Definition at line 413 of file utils.h.
Referenced by __analog_handle_event(), action_originate(), analog_handle_init_event(), analog_ss_thread_start(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_pbx_start(), dahdi_handle_event(), do_monitor(), dundi_answer_entity(), dundi_answer_query(), dundi_prop_precache(), handle_hd_hf(), handle_init_event(), launch_service(), main(), mwi_thread(), and spawn_dp_lookup().
| #define ast_pthread_create_detached_background | ( | a, | |||
| b, | |||||
| c, | |||||
| d | ) |
Value:
ast_pthread_create_detached_stack(a, b, c, d, \ AST_BACKGROUND_STACKSIZE, \ __FILE__, __FUNCTION__, __LINE__, #c)
Definition at line 422 of file utils.h.
Referenced by ast_cdr_submit_batch(), ast_tcptls_server_root(), cc_generic_agent_recall(), conf_run(), iax_park(), launch_monitor_thread(), listener(), load_module(), sip_park(), sip_pickup(), sla_handle_dial_state_event(), and sla_station_exec().
| #define ast_realloc | ( | p, | |||
| len | ) | _ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) |
| #define ast_set2_flag | ( | p, | |||
| value, | |||||
| flag | ) |
Definition at line 94 of file utils.h.
Referenced by __ast_pbx_run(), _macro_exec(), actual_load_config(), aji_create_client(), aji_load_config(), apply_general_options(), apply_option(), apply_outgoing(), ast_bridge_call(), ast_jb_read_conf(), ast_plc_reload(), ast_readconfig(), ast_tls_read_conf(), ast_translate(), build_peer(), dial_exec_full(), do_reload(), find_account(), find_user(), forkcdr_exec(), handle_common_options(), handle_t38_options(), load_config(), load_module(), load_moh_classes(), local_ast_moh_start(), reload_config(), and sip_setoption().
| #define ast_set2_flag64 | ( | p, | |||
| value, | |||||
| flag | ) |
Definition at line 151 of file utils.h.
Referenced by build_peer(), build_user(), check_access(), dial_exec_full(), and set_config().
| #define ast_set_flag | ( | p, | |||
| flag | ) |
Definition at line 70 of file utils.h.
Referenced by __analog_ss_thread(), __ast_pbx_run(), __ast_read(), __ast_request_and_dial(), __sip_subscribe_mwi_do(), _macro_exec(), action_redirect(), aji_create_client(), aji_load_config(), analog_ss_thread(), app_exec(), apply_peer(), ast_audiohook_set_mute(), ast_autoservice_start(), ast_bridge_call(), ast_bridge_features_set_flag(), ast_bridge_new(), ast_bridge_timelimit(), ast_call(), ast_cdr_detach(), ast_cdr_fork(), ast_cdr_merge(), ast_cdr_reset(), ast_cdr_specialized_reset(), ast_channel_bridge(), ast_channel_defer_dtmf(), ast_do_masquerade(), ast_do_pickup(), ast_generic_bridge(), ast_hangup(), ast_jb_do_usecheck(), ast_jb_put(), ast_rtp_change_source(), ast_rtp_local_bridge(), ast_rtp_raw_write(), ast_rtp_read(), ast_rtp_stop(), ast_rtp_update_source(), ast_speech_change_state(), AST_TEST_DEFINE(), ast_tls_read_conf(), ast_waitfor_nandfds(), ast_waitfordigit_full(), asyncgoto_exec(), bridge_channel_feature(), bridge_exec(), bridge_p2p_rtp_write(), build_peer(), builtin_atxfer(), builtin_blindtransfer(), cb_extensionstate(), cc_generic_agent_init(), change_hold_state(), change_spy_mode(), channel_spy(), chanspy_exec(), check_bridge(), check_peer_ok(), check_user_full(), check_via(), common_exec(), connect_link(), create_addr_from_peer(), create_transaction(), dahdiscan_exec(), destroy_trans(), dial_exec_full(), dictate_exec(), directory_exec(), disa_exec(), do_register(), dundi_encrypt(), dundi_lookup_local(), dundi_send(), extenspy_exec(), find_user_realtime(), free_vm_users(), handle_command_response(), handle_common_options(), handle_exec(), handle_invite_replaces(), handle_queue_reload(), handle_request_invite(), handle_request_refer(), handle_request_subscribe(), handle_response(), handle_response_invite(), handle_t38_options(), handle_verbose(), hangupcalls(), hanguptree(), init_acf_query(), init_app_class(), init_files_class(), init_outgoing(), interpret_t38_parameters(), launch_monitor_thread(), leave_voicemail(), linear_alloc(), load_config(), load_moh_classes(), local_alloc(), local_ast_moh_start(), local_attended_transfer(), local_call(), local_hangup(), login_exec(), main(), manage_parked_call(), manager_queue_reload(), manager_sipnotify(), minivm_greet_exec(), nocdr_exec(), odbc_load_module(), park_call_full(), parked_call_exec(), parse_options(), playtones_alloc(), post_cdr(), process_applicationmap_line(), process_cn_rfc3389(), process_crypto(), process_sdp(), qualify_peer(), record_exec(), register_verify(), reload_config(), ring_entry(), rpt(), rpt_call(), rpt_exec(), rpt_tele_thread(), sdp_crypto_process(), set_bridge_features_on_config(), set_config_flags(), set_insecure_flags(), sip_answer(), sip_call(), sip_cc_agent_init(), sip_cc_agent_respond(), sip_cc_monitor_request_cc(), sip_cli_notify(), sip_dtmfmode(), sip_find_peer_full(), sip_hangup(), sip_indicate(), sip_msg_send(), sip_parse_nat_option(), sip_poke_peer(), sip_reinvite_retry(), sip_send_mwi_to_peer(), sip_sendhtml(), sip_set_rtp_peer(), sip_set_udptl_peer(), sip_write(), socket_process(), start_spying(), t38_tx_packet_handler(), tonepair_alloc(), transmit_publish(), transmit_register(), transmit_reinvite_with_sdp(), try_calling(), update_call_counter(), update_connectedline(), vm_execmain(), volume_write(), and waitstream_core().
| #define ast_set_flag64 | ( | p, | |||
| flag | ) |
Definition at line 127 of file utils.h.
Referenced by authenticate_reply(), authenticate_request(), build_peer(), build_user(), check_access(), conf_run(), decrypt_frame(), dial_exec_full(), dial_trunk(), handle_cli_iax2_prune_realtime(), iax2_predestroy(), iax2_provision(), iax2_setoption(), iax2_start_transfer(), parse_options(), peer_delme_cb(), pvt_destructor(), realtime_peer(), realtime_user(), run_station(), set_config(), sla_station_exec(), sla_trunk_exec(), socket_process(), and user_delme_cb().
| #define ast_set_flag_nonstd | ( | p, | |||
| flag | ) |
Value:
do { \ ((p)->flags |= (flag)); \ } while(0)
Definition at line 176 of file utils.h.
Referenced by dundi_lookup_internal(), dundi_query_eid_internal(), and handle_command_response().
| #define ast_set_flags_to64 | ( | p, | |||
| flag, | |||||
| value | ) |
| #define AST_STACKSIZE (((sizeof(void *) * 8 * 8) - 16) * 1024) |
A wrapper for strdup().
ast_strdup() is a wrapper for strdup() that will generate an Asterisk log message in the case that the allocation fails.
ast_strdup(), unlike strdup(), can safely accept a NULL argument. If a NULL argument is provided, ast_strdup will return NULL without generating any kind of error log message.
The argument and return value are the same as strdup()
| #define ast_strdupa | ( | s | ) |
duplicate a string in memory from the stack
| s | The string to duplicate |
Definition at line 649 of file utils.h.
Referenced by __ast_channel_alloc_ap(), __ast_play_and_record(), _ast_device_state(), _build_port_config(), _macro_exec(), _parse(), _sip_show_peers(), _while_exec(), acf_jabberreceive_read(), acf_meetme_info(), acf_odbc_write(), acf_vm_info(), action_agents(), action_dialplan_exec(), action_playback(), action_playback_and_continue(), action_status(), actual_load_config(), add_agent(), add_peer_mailboxes(), add_realm_authentication(), add_redirect(), add_var(), admin_exec(), advanced_options(), aelsub_exec(), agent_hangup(), agi_exec_full(), agi_handle_command(), aji_join_exec(), aji_leave_exec(), aji_send_exec(), aji_sendgroup_exec(), aji_status_exec(), answer_exec_enable(), app_exec(), append_mailbox(), append_mailbox_mapping(), append_var_and_value_to_filter(), apply_directmedia_ha(), apply_options(), aqm_exec(), array(), ast_aji_get_client(), ast_app_getdata(), ast_append_ha(), ast_async_goto(), ast_bridge_call(), ast_bridge_timelimit(), ast_build_timing(), ast_callerid_split(), ast_cdr_fork(), ast_cdr_setaccount(), ast_cdr_setpeeraccount(), ast_cel_report_event(), ast_channel_connected_line_macro(), ast_channel_redirecting_macro(), ast_channel_set_linkgroup(), ast_data_iterator_init(), ast_do_pickup(), ast_eivr_senddtmf(), ast_eivr_setvariable(), ast_el_add_history(), ast_format_str_reduce(), ast_func_read(), ast_func_read2(), ast_func_write(), ast_get_group(), ast_http_get_cookies(), ast_masq_park_call(), ast_masq_park_call_exten(), ast_mkdir(), ast_monitor_change_fname(), ast_monitor_start(), ast_netsock_bind(), ast_ouraddrfor(), ast_park_call_exten(), ast_parse_allow_disallow(), ast_parse_arg(), ast_playtones_start(), ast_register_file_version(), ast_rtp_read(), ast_sockaddr_parse(), ast_sockaddr_resolve(), ast_str_retrieve_variable(), ast_utils_which(), ast_writefile(), asyncgoto_exec(), auth_exec(), authenticate_reply(), authenticate_verify(), background_detect_exec(), bridge_exec(), bridge_play_sounds(), build_channels(), build_gateway(), build_mapping(), build_peer(), build_profile(), build_route(), build_user(), builtin_atxfer(), builtin_automixmonitor(), builtin_automonitor(), cache_get_callno_locked(), callerid_read(), callerid_write(), celgenuserevent_exec(), chanavail_exec(), channel_admin_exec(), channel_spy(), chanspy_exec(), check_access(), check_blacklist(), check_day(), check_dow(), check_goto_on_transfer(), check_month(), check_peer_ok(), check_switch_expr(), check_timerange(), check_user_full(), check_via(), cli_odbc_read(), cli_odbc_write(), complete_meetmecmd(), conf_exec(), conf_run(), conf_start_moh(), confbridge_exec(), config_function_read(), config_line(), config_module(), connectedline_read(), connectedline_write(), controlplayback_exec(), count_exec(), create_addr(), create_addr_from_peer(), create_dynamic_parkinglot(), create_followme_number(), create_queue_member(), create_vmaccount(), cut_internal(), dahdi_call(), dahdiras_exec(), dahdiscan_exec(), data_filter_add_nodes(), data_filter_alloc(), data_filter_generate(), data_provider_create(), data_provider_release(), data_result_generate(), data_result_get_node(), data_search_create(), data_search_generate(), data_search_get_node(), decrypt_frame(), del_exec(), deltree_exec(), determine_starting_point(), dial_exec_full(), dial_trunk(), dialgroup_refreshdb(), dialgroup_write(), dictate_exec(), directory_exec(), disa_exec(), dnsmgr_refresh(), do_immediate_setup(), do_notify(), do_say(), dundi_query_read(), dundi_result_read(), dundifunc_read(), enum_query_read(), enum_result_read(), ewscal_write_event(), exec_exec(), execif_exec(), extenspy_exec(), feature_check(), feature_interpret(), festival_exec(), fileexists_core(), filehelper(), find_conf_realtime(), find_gtalk(), find_sdp(), find_table(), find_table_cb(), forkcdr_exec(), func_confbridge_info(), function_agent(), function_iaxpeer(), function_realtime_store(), generic_recall(), get_cid_name(), get_destination(), get_refer_info(), gosub_exec(), gosubif_exec(), gtalk_action(), gtalk_alloc(), gtalk_create_candidates(), gtalk_invite(), gtalk_request(), gtalk_update_externip(), handle_call_forward(), handle_cli_check_permissions(), handle_cli_dialplan_add_extension(), handle_cli_file_convert(), handle_cli_mixmonitor(), handle_common_options(), handle_debug_dialplan(), handle_mgcp_audit_endpoint(), handle_options(), handle_request_invite(), handle_request_notify(), handle_request_refer(), handle_request_subscribe(), handle_response(), handle_show_dialplan(), handle_t38_options(), handle_verbose(), has_voicemail(), iax2_call(), iax2_devicestate(), iax2_prov_app(), iax2_request(), iconv_read(), init_acf_query(), init_jack_data(), insert_penaltychange(), is_prefix(), is_valid_dtmf(), isAnsweringMachine(), isexten_function_read(), ivr_dispatch(), jb_framedata_init(), jingle_request(), launch_ha_netscript(), launch_monitor_thread(), launch_netscript(), leave_voicemail(), load_channelvars(), load_config(), local_call(), local_devicestate(), log_exec(), logger_print_normal(), login_exec(), lua_get_variable_value(), lua_pbx_exec(), lua_set_variable_value(), macroif_exec(), main(), make_components(), make_email_file(), man_do_variable_value(), manage_parked_call(), manager_mixmonitor(), meetmemute(), metermaidstate(), mgcp_devicestate(), minivm_accmess_exec(), minivm_account_func_read(), minivm_counter_func_read(), minivm_counter_func_write(), minivm_greet_exec(), minivm_mwi_exec(), minivm_notify_exec(), minivm_record_exec(), misdn_call(), misdn_check_l2l1(), misdn_facility_exec(), misdn_request(), misdn_set_opt_exec(), mixmonitor_exec(), mkintf(), moh_handle_digit(), monitor_dial(), msg_send_cb(), msg_send_exec(), multicast_rtp_request(), notify_message(), notify_new_message(), odbc_log(), on_dns_update_mwi(), on_dns_update_peer(), on_dns_update_registry(), orig_app(), orig_exten(), originate_exec(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), oss_call(), oss_request(), page_exec(), park_call_exec(), park_space_reserve(), parkandannounce_exec(), parked_call_exec(), parse_allowed_methods(), parse_apps(), parse_empty_options(), parse_events(), parse_register_contact(), parse_session_expires(), parse_sip_options(), parse_uri_full(), party_id_write(), party_name_write(), party_number_write(), pbx_builtin_answer(), pbx_builtin_background(), pbx_builtin_execiftime(), pbx_builtin_gotoif(), pbx_builtin_gotoiftime(), pbx_builtin_importvar(), pbx_builtin_pushvar_helper(), pbx_builtin_resetcdr(), pbx_builtin_setvar(), pbx_builtin_setvar_helper(), pbx_builtin_setvar_multiple(), pbx_builtin_waitexten(), pbx_find_extension(), pbx_parseable_goto(), peer_set_srcaddr(), pickup_exec(), pickupchan_exec(), play_message(), play_moh_exec(), playback_exec(), pqm_exec(), prep_email_sub_vars(), privacy_exec(), process_applicationmap_line(), process_dahdi(), process_echocancel(), process_sdp(), process_sdp_o(), ql_exec(), queue_exec(), queue_mwi_event(), queue_set_param(), rcvfax_exec(), read_exec(), readexten_exec(), readfile_exec(), realtime_common(), realtime_exec(), realtime_multi_curl(), realtime_multi_ldap(), realtime_multi_odbc(), realtime_multi_pgsql(), receive_message(), receivefax_exec(), record_exec(), redirecting_read(), redirecting_write(), register_verify(), registry_authrequest(), reload_config(), reload_single_member(), resource_name_match(), retrydial_exec(), rpt_exec(), rqm_exec(), rtcp_do_debug_ip(), rtp_do_debug_ip(), saycountedadj_exec(), saycountednoun_exec(), sayunixtime_exec(), sdp_crypto_process(), senddtmf_exec(), sendfax_exec(), sendmail(), sendurl_exec(), set_config_flags(), setup_privacy_args(), setup_stunaddr(), sip_acf_channel_read(), sip_devicestate(), sip_get_cc_information(), sip_msg_send(), sip_new(), sip_parse_nat_option(), sip_send_mwi_to_peer(), sip_show_settings(), sip_sipredirect(), sip_uri_cmp(), sip_uri_headers_cmp(), sip_uri_params_cmp(), skel_exec(), skinny_devicestate(), sla_add_trunk_to_station(), sla_check_device(), sla_queue_event_conf(), sla_ring_station(), sla_state(), sla_station_exec(), sla_trunk_exec(), smdi_msg_read(), smdi_msg_retrieve_read(), sms_exec(), sndfax_exec(), socket_process(), softhangup_exec(), sort_internal(), speech_background(), speech_load(), srv_result_read(), start_moh_exec(), start_monitor_action(), start_monitor_exec(), state_notify_build_xml(), stop_mixmonitor_exec(), stun_monitor_request(), timezone_add(), transfer_exec(), transmit_invite(), try_calling(), tryexec_exec(), unistim_send_mwi_to_peer(), update_bridge_vars(), update_common_options(), update_registry(), upqm_exec(), userevent_exec(), verbose_exec(), vm_box_exists(), vm_check_password_shell(), vm_exec(), vm_execmain(), vmauthenticate(), vmsayname_exec(), wait_for_answer(), wait_for_winner(), waitstream_core(), xfer_park_call_helper(), and zapateller_exec().
| #define ast_strndup | ( | str, | |||
| len | ) | _ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) |
A wrapper for strndup().
ast_strndup() is a wrapper for strndup() that will generate an Asterisk log message in the case that the allocation fails.
ast_strndup(), unlike strndup(), can safely accept a NULL argument for the string to duplicate. If a NULL argument is provided, ast_strdup will return NULL without generating any kind of error log message.
The arguments and return value are the same as strndup()
| #define ast_test_flag | ( | p, | |||
| flag | ) |
Definition at line 63 of file utils.h.
Referenced by __ast_channel_masquerade(), __ast_pbx_run(), __ast_queue_frame(), __ast_read(), __sip_destroy(), __ssl_setup(), __transmit_response(), _ast_odbc_request_obj2(), _macro_exec(), _sip_show_peer(), _sip_show_peers(), acf_odbc_read(), action_confbridgelist(), action_kick_last(), action_login(), action_toggle_mute(), action_toggle_mute_participants(), add_agent(), add_codec_to_sdp(), add_rpid(), add_sdp(), aji_build_publish_skeleton(), aji_cli_purge_pubsub_nodes(), aji_create_client(), aji_handle_pubsub_error(), aji_handle_subscribe(), aji_pruneregister(), aji_publish_device_state(), aji_pubsub_subscribe(), app_exec(), ast_audiohook_write_frame(), ast_autoservice_start(), ast_bridge_call(), ast_bridge_merge(), ast_call(), ast_can_pickup(), ast_cdr_answer(), ast_cdr_appenduserfield(), ast_cdr_busy(), ast_cdr_congestion(), ast_cdr_end(), ast_cdr_failed(), ast_cdr_fork(), ast_cdr_init(), ast_cdr_merge(), ast_cdr_noanswer(), ast_cdr_reset(), ast_cdr_setaccount(), ast_cdr_setamaflags(), ast_cdr_setanswer(), ast_cdr_setapp(), ast_cdr_setcid(), ast_cdr_setdestchan(), ast_cdr_setdisposition(), ast_cdr_setpeeraccount(), ast_cdr_setuserfield(), ast_cdr_setvar(), ast_cdr_specialized_reset(), ast_cdr_start(), ast_cdr_update(), ast_channel_bridge(), ast_channel_defer_dtmf(), ast_config_internal_load(), ast_do_masquerade(), ast_explicit_goto(), ast_frisolate(), ast_generic_bridge(), ast_hangup(), ast_indicate_data(), ast_jb_destroy(), ast_jb_do_usecheck(), ast_jb_empty_and_reset(), ast_jb_get_and_deliver(), ast_jb_get_when_to_wakeup(), ast_jb_put(), ast_moh_files_next(), ast_pbx_run_args(), ast_pbx_start(), ast_quiet_chan(), ast_raw_answer(), ast_readstring_full(), ast_rtp_raw_write(), ast_sendtext(), ast_softhangup_nolock(), ast_streamfile(), AST_TEST_DEFINE(), ast_transfer(), ast_translate(), ast_uri_decode(), ast_uri_encode(), ast_waitfordigit_full(), ast_write(), auth_exec(), authenticate_verify(), bridge_channel_join(), bridge_check_dissolve(), bridge_exec(), bridge_p2p_rtp_write(), build_peer(), build_radius_record(), build_via(), builtin_atxfer(), call_forward_inherit(), callback_dialoptions(), cb_extensionstate(), cdr_read(), cdr_write(), change_hold_state(), channel_data_add_flags(), channel_spy(), chanspy_exec(), check_bridge(), check_peer_ok(), check_pendings(), check_post(), check_rtp_timeout(), check_user_full(), check_via(), close_mailbox(), comedia_string(), common_exec(), complete_sip_peer(), complete_sip_registered_peer(), confbridge_exec(), config_text_file_load(), connectedline_write(), controlplayback_exec(), copy_via_headers(), create_addr_from_peer(), create_jb(), destroy_trans(), dial_exec_full(), dialog_initialize_rtp(), dictate_exec(), directory_exec(), disa_exec(), display_nat_warning(), do_directory(), do_setnat(), dtmf_audiohook_write_list(), dundi_encrypt(), dundi_exec(), dundi_helper(), dundi_lookup_local(), dundi_lookup_thread(), dundi_precache_thread(), dundi_query_read(), dundi_query_thread(), dundi_rexmit(), dundi_send(), dundifunc_read(), eivr_comm(), enable_dsp_detect(), execute_cb(), execute_menu_entry(), expire_register(), extenspy_exec(), fax_gateway_framehook(), feature_exec_app(), feature_interpret_helper(), find_cache(), find_or_create(), find_user(), find_user_realtime(), findmeexec(), force_rport_string(), forkcdr_exec(), forward_message(), free_user(), func_confbridge_info(), function_sippeer(), get_crypto_attrib(), get_destination(), get_insecure_variable_from_config(), get_insecure_variable_from_sipregs(), get_rpid(), gosub_exec(), handle_cli_moh_show_classes(), handle_cli_wait_fullybooted(), handle_command_response(), handle_exec(), handle_frame(), handle_minivm_show_settings(), handle_options(), handle_request_bye(), handle_request_cancel(), handle_request_info(), handle_request_invite(), handle_request_refer(), handle_request_subscribe(), handle_response(), handle_response_invite(), handle_response_message(), handle_response_notify(), handle_show_settings(), handle_showchan(), handle_skinny_show_settings(), handle_speechrecognize(), handle_tcptls_connection(), handle_video_on_exit(), handle_video_on_join(), hint_read(), hook_event_cb(), iax2_write(), initialize_udptl(), initreqprep(), interpret_t38_parameters(), is_state_change_valid(), join_conference_bridge(), leave_conference_bridge(), leave_voicemail(), load_resource(), local_alloc(), local_ast_moh_start(), local_bridgedchannel(), local_call(), local_hangup(), local_indicate(), local_write(), main(), make_email_file(), manager_list_voicemail_users(), manager_mixmonitor(), masq_park_call(), match_nat_options(), match_req_to_dialog(), minivm_accmess_exec(), minivm_account_func_read(), minivm_greet_exec(), minivm_notify_exec(), minivm_record_exec(), mixmonitor_exec(), mixmonitor_save_prep(), mixmonitor_thread(), mod_load_cmp(), moh_files_alloc(), moh_scan_files(), notify_new_message(), odbc_load_module(), page_exec(), park_call_exec(), park_call_full(), park_space_reserve(), parse_moved_contact(), parse_register_contact(), pbx_builtin_background(), pbx_builtin_waitexten(), peer_ipcmp_cb_full(), pick_unlocked_cdr(), play_mailbox_owner(), play_message(), play_record_review(), post_cdr(), post_join_marked(), post_join_unmarked(), precache_transactions(), process_cn_rfc3389(), process_crypto(), process_sdp(), process_sdp_a_audio(), process_sdp_o(), process_text_line(), read_exec(), readexten_exec(), realtime_peer(), realtime_switch_common(), receivefax_exec(), record_exec(), redirecting_write(), register_verify(), reload_config(), reload_handler(), reload_queues(), reload_single_queue(), remote_bridge_loop(), remove_from_queue(), reqprep(), respprep(), retrans_pkt(), retrydial_exec(), rpt_master(), search_directory_sub(), select_entry(), select_item_pause(), send_request(), sendfax_exec(), sendmail(), sendurl_exec(), serialize_showchan(), set_address_from_contact(), set_config_flags(), set_pvt_allowed_methods(), set_t38_capabilities(), should_skip_dtmf(), show_channels_cb(), sip_alloc(), sip_call(), sip_cc_agent_destructor(), sip_destroy_peer(), sip_dtmfmode(), sip_fixup(), sip_get_rtp_peer(), sip_get_trtp_peer(), sip_get_udptl_peer(), sip_get_vrtp_peer(), sip_hangup(), sip_indicate(), sip_nat_mode(), sip_new(), sip_parse_nat_option(), sip_prune_realtime(), sip_queryoption(), sip_read(), sip_real_dst(), sip_rtp_read(), sip_send_mwi_to_peer(), sip_senddigit_begin(), sip_senddigit_end(), sip_sendhtml(), sip_set_rtp_peer(), sip_set_udptl_peer(), sip_setoption(), sip_show_channel(), sip_show_settings(), sip_show_users(), sip_write(), sla_trunk_exec(), smdi_msg_find(), sms_exec(), socket_process(), socket_process_meta(), softhangup_exec(), spawn_mp3(), speech_background(), speech_read(), spy_generate(), start_spying(), startmon(), transmit_info_with_digit(), transmit_invite(), transmit_notify_with_mwi(), transmit_refer(), transmit_reinvite_with_sdp(), transmit_request_with_auth(), transmit_response_with_sdp(), try_calling(), update_call_counter(), update_connectedline(), update_peer(), update_redirecting(), update_registry(), vm_exec(), vm_execmain(), vm_instructions_en(), vm_intro(), vm_newuser(), volume_callback(), wait_for_winner(), waitstream_core(), and xfer_park_call_helper().
| #define ast_test_flag64 | ( | p, | |||
| flag | ) |
Definition at line 120 of file utils.h.
Referenced by __do_deliver(), __expire_registry(), __get_from_jb(), __iax2_show_peers(), action_meetmelist(), admin_exec(), ast_app_options2str64(), ast_cli_netstats(), authenticate_reply(), authenticate_request(), authenticate_verify(), build_peer(), build_user(), can_write(), check_access(), complete_iax2_peers(), conf_exec(), conf_run(), decrypt_frame(), dial_exec_full(), do_forward(), find_conf(), find_conf_realtime(), function_iaxpeer(), handle_cli_iax2_prune_realtime(), handle_cli_iax2_show_channels(), handle_cli_iax2_show_peer(), handle_cli_iax2_show_users(), iax2_bridge(), iax2_call(), iax2_destroy_helper(), iax2_getpeertrunk(), iax2_hangup(), iax2_indicate(), iax2_predestroy(), iax2_queryoption(), iax2_request(), iax2_send(), iax2_trunk_queue(), iax2_write(), log_jitterstats(), manager_iax2_show_peer_list(), meetme_show_cmd(), peers_data_provider_get(), prune_peers(), prune_users(), realtime_peer(), realtime_update_peer(), realtime_user(), reg_source_db(), register_verify(), retrydial_exec(), sayunixtime_exec(), schedule_delivery(), send_trunk(), set_config(), setup_privacy_args(), socket_process(), update_registry(), user_set_hangup_cb(), user_set_kickme_cb(), user_set_muted_cb(), user_set_unmuted_cb(), users_data_provider_get(), valid_priv_reply(), and wait_for_answer().
| #define ast_test_flag_nonstd | ( | p, | |||
| flag | ) | ((p)->flags & (flag)) |
Definition at line 173 of file utils.h.
Referenced by cache_save_hint(), dundi_lookup_thread(), dundi_precache_thread(), and handle_command_response().
| #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 ast_vasprintf | ( | ret, | |||
| fmt, | |||||
| ap | ) | _ast_vasprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, (fmt), (ap)) |
A wrapper for vasprintf().
ast_vasprintf() is a wrapper for vasprintf() that will generate an Asterisk log message in the case that the allocation fails.
The arguments and return value are the same as vasprintf()
| #define localtime_r __dont_use_localtime_r_use_ast_localtime_instead__ |
| #define MALLOC_FAILURE_MSG ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file); |
| #define MAX | ( | a, | |||
| b | ) | ({ typeof(a) __a = (a); typeof(b) __b = (b); ((__a < __b) ? __b : __a);}) |
Definition at line 228 of file utils.h.
Referenced by __ast_answer(), ast_dsp_busydetect(), audiohook_list_translate_to_slin(), gather_softmix_stats(), handle_response_register(), mixmonitor_save_prep(), and silk_getjoint().
| #define MIN | ( | a, | |||
| b | ) | ({ typeof(a) __a = (a); typeof(b) __b = (b); ((__a > __b) ? __b : __a);}) |
Definition at line 226 of file utils.h.
Referenced by _sip_tcp_helper_thread(), analyse_softmix_stats(), autoanswer_complete(), calculate_local_max_datagram(), celt_getjoint(), h263p_encap(), h264_encap(), interpret_t38_parameters(), mpeg4_encap(), set_message_vars_from_req(), and silk_getjoint().
| int _ast_asprintf | ( | char ** | ret, | |
| const char * | file, | |||
| int | lineno, | |||
| const char * | func, | |||
| const char * | fmt, | |||
| ... | ||||
| ) |
Definition at line 2104 of file main/utils.c.
References MALLOC_FAILURE_MSG, and vasprintf.
02105 { 02106 int res; 02107 va_list ap; 02108 02109 va_start(ap, fmt); 02110 if ((res = vasprintf(ret, fmt, ap)) == -1) { 02111 MALLOC_FAILURE_MSG; 02112 } 02113 va_end(ap); 02114 02115 return res; 02116 }
| void * _ast_calloc | ( | size_t | num, | |
| size_t | len, | |||
| const char * | file, | |||
| int | lineno, | |||
| const char * | func | |||
| ) | [inline] |
| void * _ast_malloc | ( | size_t | len, | |
| const char * | file, | |||
| int | lineno, | |||
| const char * | func | |||
| ) | [inline] |
| void * _ast_realloc | ( | void * | p, | |
| size_t | len, | |||
| const char * | file, | |||
| int | lineno, | |||
| const char * | func | |||
| ) | [inline] |
| char * _ast_strdup | ( | const char * | str, | |
| const char * | file, | |||
| int | lineno, | |||
| const char * | func | |||
| ) | [inline] |
| char * _ast_strndup | ( | const char * | str, | |
| size_t | len, | |||
| const char * | file, | |||
| int | lineno, | |||
| const char * | func | |||
| ) | [inline] |
| int _ast_vasprintf | ( | char ** | ret, | |
| const char * | file, | |||
| int | lineno, | |||
| const char * | func, | |||
| const char * | fmt, | |||
| va_list | ap | |||
| ) | [inline] |
| 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. |
Definition at line 274 of file main/utils.c.
Referenced by aes_helper(), ast_check_signature(), base64_helper(), osp_validate_token(), sdp_crypto_process(), and sdp_crypto_setup().
00275 { 00276 int cnt = 0; 00277 unsigned int byte = 0; 00278 unsigned int bits = 0; 00279 int incnt = 0; 00280 while(*src && *src != '=' && (cnt < max)) { 00281 /* Shift in 6 bits of input */ 00282 byte <<= 6; 00283 byte |= (b2a[(int)(*src)]) & 0x3f; 00284 bits += 6; 00285 src++; 00286 incnt++; 00287 /* If we have at least 8 bits left over, take that character 00288 off the top */ 00289 if (bits >= 8) { 00290 bits -= 8; 00291 *dst = (byte >> bits) & 0xff; 00292 dst++; 00293 cnt++; 00294 } 00295 } 00296 /* Don't worry about left over bits, they're extra anyway */ 00297 return cnt; 00298 }
| 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 352 of file main/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().
00353 { 00354 return ast_base64encode_full(dst, src, srclen, max, 0); 00355 }
| int ast_base64encode_full | ( | char * | dst, | |
| const unsigned char * | src, | |||
| int | srclen, | |||
| int | max, | |||
| int | linebreaks | |||
| ) |
encode text to BASE64 coding
Definition at line 301 of file main/utils.c.
Referenced by ast_base64encode().
00302 { 00303 int cnt = 0; 00304 int col = 0; 00305 unsigned int byte = 0; 00306 int bits = 0; 00307 int cntin = 0; 00308 /* Reserve space for null byte at end of string */ 00309 max--; 00310 while ((cntin < srclen) && (cnt < max)) { 00311 byte <<= 8; 00312 byte |= *(src++); 00313 bits += 8; 00314 cntin++; 00315 if ((bits == 24) && (cnt + 4 <= max)) { 00316 *dst++ = base64[(byte >> 18) & 0x3f]; 00317 *dst++ = base64[(byte >> 12) & 0x3f]; 00318 *dst++ = base64[(byte >> 6) & 0x3f]; 00319 *dst++ = base64[byte & 0x3f]; 00320 cnt += 4; 00321 col += 4; 00322 bits = 0; 00323 byte = 0; 00324 } 00325 if (linebreaks && (cnt < max) && (col == 64)) { 00326 *dst++ = '\n'; 00327 cnt++; 00328 col = 0; 00329 } 00330 } 00331 if (bits && (cnt + 4 <= max)) { 00332 /* Add one last character for the remaining bits, 00333 padding the rest with 0 */ 00334 byte <<= 24 - bits; 00335 *dst++ = base64[(byte >> 18) & 0x3f]; 00336 *dst++ = base64[(byte >> 12) & 0x3f]; 00337 if (bits == 16) 00338 *dst++ = base64[(byte >> 6) & 0x3f]; 00339 else 00340 *dst++ = '='; 00341 *dst++ = '='; 00342 cnt += 4; 00343 } 00344 if (linebreaks && (cnt < max)) { 00345 *dst++ = '\n'; 00346 cnt++; 00347 } 00348 *dst = '\0'; 00349 return cnt; 00350 }
| 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 1196 of file main/utils.c.
References ast_log(), ast_tvdiff_ms(), ast_tvnow(), ast_wait_for_output(), errno, and LOG_ERROR.
Referenced by send_string().
01197 { 01198 struct timeval start = ast_tvnow(); 01199 int n = 0; 01200 int elapsed = 0; 01201 01202 while (len) { 01203 if (ast_wait_for_output(fd, timeoutms - elapsed)) { 01204 /* poll returned a fatal error, so bail out immediately. */ 01205 return -1; 01206 } 01207 01208 /* Clear any errors from a previous write */ 01209 clearerr(f); 01210 01211 n = fwrite(src, 1, len, f); 01212 01213 if (ferror(f) && errno != EINTR && errno != EAGAIN) { 01214 /* fatal error from fwrite() */ 01215 if (!feof(f)) { 01216 /* Don't spam the logs if it was just that the connection is closed. */ 01217 ast_log(LOG_ERROR, "fwrite() returned error: %s\n", strerror(errno)); 01218 } 01219 n = -1; 01220 break; 01221 } 01222 01223 /* Update for data already written to the socket */ 01224 len -= n; 01225 src += n; 01226 01227 elapsed = ast_tvdiff_ms(ast_tvnow(), start); 01228 if (elapsed >= timeoutms) { 01229 /* We've taken too long to write 01230 * This is only an error condition if we haven't finished writing. */ 01231 n = len ? -1 : 0; 01232 break; 01233 } 01234 } 01235 01236 while (fflush(f)) { 01237 if (errno == EAGAIN || errno == EINTR) { 01238 continue; 01239 } 01240 if (!feof(f)) { 01241 /* Don't spam the logs if it was just that the connection is closed. */ 01242 ast_log(LOG_ERROR, "fflush() returned error: %s\n", strerror(errno)); 01243 } 01244 n = -1; 01245 break; 01246 } 01247 01248 return n < 0 ? -1 : 0; 01249 }
| 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.
Definition at line 1155 of file main/utils.c.
References ast_log(), ast_tvdiff_ms(), ast_tvnow(), ast_wait_for_output(), errno, and LOG_ERROR.
Referenced by ast_agi_send(), ast_cli(), and cleanup_module().
01156 { 01157 struct timeval start = ast_tvnow(); 01158 int res = 0; 01159 int elapsed = 0; 01160 01161 while (len) { 01162 if (ast_wait_for_output(fd, timeoutms - elapsed)) { 01163 return -1; 01164 } 01165 01166 res = write(fd, s, len); 01167 01168 if (res < 0 && errno != EAGAIN && errno != EINTR) { 01169 /* fatal error from write() */ 01170 ast_log(LOG_ERROR, "write() returned error: %s\n", strerror(errno)); 01171 return -1; 01172 } 01173 01174 if (res < 0) { 01175 /* It was an acceptable error */ 01176 res = 0; 01177 } 01178 01179 /* Update how much data we have left to write */ 01180 len -= res; 01181 s += res; 01182 res = 0; 01183 01184 elapsed = ast_tvdiff_ms(ast_tvnow(), start); 01185 if (elapsed >= timeoutms) { 01186 /* We've taken too long to write 01187 * This is only an error condition if we haven't finished writing. */ 01188 res = len ? -1 : 0; 01189 break; 01190 } 01191 } 01192 01193 return res; 01194 }
Compare two EIDs.
Definition at line 318 of file netsock.c.
Referenced by aji_devstate_cb(), aji_handle_pubsub_event(), aji_mwi_cb(), ast_event_cb(), build_peer(), build_transactions(), 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(), and register_request().
| char* ast_eid_to_str | ( | char * | s, | |
| int | maxlen, | |||
| struct ast_eid * | eid | |||
| ) |
/brief Convert an EID to a string
Definition at line 220 of file netsock.c.
References ast_eid::eid.
Referenced by aji_publish_device_state(), aji_publish_mwi(), append_transaction(), ast_set_default_eid(), ast_str_retrieve_variable(), build_peer(), build_transactions(), cache_lookup(), cache_lookup_internal(), check_key(), complete_peer_helper(), destroy_trans(), do_autokill(), do_register(), do_register_expire(), dump_answer(), dump_eid(), dump_raw_ie(), 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_entityid(), dundi_show_peer(), dundi_show_peers(), dundi_show_requests(), handle_command_response(), handle_show_settings(), populate_addr(), register_request(), and update_key().
00221 { 00222 int x; 00223 char *os = s; 00224 if (maxlen < 18) { 00225 if (s && (maxlen > 0)) 00226 *s = '\0'; 00227 } else { 00228 for (x = 0; x < 5; x++) { 00229 sprintf(s, "%02x:", eid->eid[x]); 00230 s += 3; 00231 } 00232 sprintf(s, "%02x", eid->eid[5]); 00233 } 00234 return os; 00235 }
| void ast_enable_packet_fragmentation | ( | int | sock | ) |
Disable PMTU discovery on a socket.
| sock | The socket to manipulate |
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 1924 of file main/utils.c.
References ast_log(), and LOG_WARNING.
Referenced by ast_netsock_bindaddr(), and reload_config().
01925 { 01926 #if defined(HAVE_IP_MTU_DISCOVER) 01927 int val = IP_PMTUDISC_DONT; 01928 01929 if (setsockopt(sock, IPPROTO_IP, IP_MTU_DISCOVER, &val, sizeof(val))) 01930 ast_log(LOG_WARNING, "Unable to disable PMTU discovery. Large UDP packets may fail to be delivered when sent from this socket.\n"); 01931 #endif /* HAVE_IP_MTU_DISCOVER */ 01932 }
| 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 443 of file main/utils.c.
Referenced by initreqprep().
00444 { 00445 const char *ptr = string; 00446 char *out = outbuf; 00447 char *allow = "\t\v !"; /* allow LWS (minus \r and \n) and "!" */ 00448 00449 while (*ptr && out - outbuf < buflen - 1) { 00450 if (!(strchr(allow, *ptr)) 00451 && !(*ptr >= '#' && *ptr <= '[') /* %x23 - %x5b */ 00452 && !(*ptr >= ']' && *ptr <= '~') /* %x5d - %x7e */ 00453 && !((unsigned char) *ptr > 0x7f)) { /* UTF8-nonascii */ 00454 00455 if (out - outbuf >= buflen - 2) { 00456 break; 00457 } 00458 out += sprintf(out, "\\%c", (unsigned char) *ptr); 00459 } else { 00460 *out = *ptr; 00461 out++; 00462 } 00463 ptr++; 00464 } 00465 00466 if (buflen) { 00467 *out = '\0'; 00468 } 00469 00470 return outbuf; 00471 }
| int ast_get_tid | ( | void | ) |
Get current thread ID.
| None |
Definition at line 2119 of file main/utils.c.
Referenced by ast_log(), and ast_register_thread().
02120 { 02121 int ret = -1; 02122 #if defined (__linux) && defined(SYS_gettid) 02123 ret = syscall(SYS_gettid); /* available since Linux 1.4.11 */ 02124 #elif defined(__sun) 02125 ret = pthread_self(); 02126 #elif defined(__APPLE__) 02127 ret = mach_thread_self(); 02128 mach_port_deallocate(mach_task_self(), ret); 02129 #elif defined(__FreeBSD__) && defined(HAVE_SYS_THR_H) 02130 long lwpid; 02131 thr_self(&lwpid); /* available since sys/thr.h creation 2003 */ 02132 ret = lwpid; 02133 #endif 02134 return ret; 02135 }
| struct hostent* ast_gethostbyname | ( | const char * | host, | |
| struct ast_hostent * | hp | |||
| ) | [read] |
Thread-safe gethostbyname function to use in Asterisk.
Definition at line 190 of file main/utils.c.
References ast_hostent::buf, gethostbyname_r(), and ast_hostent::hp.
Referenced by 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(), rpt_exec(), and set_config().
00191 { 00192 int res; 00193 int herrno; 00194 int dots = 0; 00195 const char *s; 00196 struct hostent *result = NULL; 00197 /* Although it is perfectly legitimate to lookup a pure integer, for 00198 the sake of the sanity of people who like to name their peers as 00199 integers, we break with tradition and refuse to look up a 00200 pure integer */ 00201 s = host; 00202 res = 0; 00203 while (s && *s) { 00204 if (*s == '.') 00205 dots++; 00206 else if (!isdigit(*s)) 00207 break; 00208 s++; 00209 } 00210 if (!s || !*s) { 00211 /* Forge a reply for IP's to avoid octal IP's being interpreted as octal */ 00212 if (dots != 3) 00213 return NULL; 00214 memset(hp, 0, sizeof(struct ast_hostent)); 00215 hp->hp.h_addrtype = AF_INET; 00216 hp->hp.h_addr_list = (void *) hp->buf; 00217 hp->hp.h_addr = hp->buf + sizeof(void *); 00218 /* For AF_INET, this will always be 4 */ 00219 hp->hp.h_length = 4; 00220 if (inet_pton(AF_INET, host, hp->hp.h_addr) > 0) 00221 return &hp->hp; 00222 return NULL; 00223 00224 } 00225 #ifdef HAVE_GETHOSTBYNAME_R_5 00226 result = gethostbyname_r(host, &hp->hp, hp->buf, sizeof(hp->buf), &herrno); 00227 00228 if (!result || !hp->hp.h_addr_list || !hp->hp.h_addr_list[0]) 00229 return NULL; 00230 #else 00231 res = gethostbyname_r(host, &hp->hp, hp->buf, sizeof(hp->buf), &result, &herrno); 00232 00233 if (res || !result || !hp->hp.h_addr_list || !hp->hp.h_addr_list[0]) 00234 return NULL; 00235 #endif 00236 return &hp->hp; 00237 }
| void ast_md5_hash | ( | char * | output, | |
| const char * | input | |||
| ) |
Produces MD5 hash based on input string.
Definition at line 240 of file main/utils.c.
References MD5Final(), MD5Init(), and MD5Update().
Referenced by __init_manager(), auth_exec(), auth_http_callback(), build_reply_digest(), check_auth(), and md5().
00241 { 00242 struct MD5Context md5; 00243 unsigned char digest[16]; 00244 char *ptr; 00245 int x; 00246 00247 MD5Init(&md5); 00248 MD5Update(&md5, (const unsigned char *) input, strlen(input)); 00249 MD5Final(digest, &md5); 00250 ptr = output; 00251 for (x = 0; x < 16; x++) 00252 ptr += sprintf(ptr, "%2.2x", digest[x]); 00253 }
| 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 |
Definition at line 1934 of file main/utils.c.
References ast_strdupa, errno, and len().
Referenced by ast_monitor_change_fname(), ast_monitor_start(), conf_rec_name(), conf_run(), create_dirpath(), dictate_exec(), filename_parse(), init_logger(), load_module(), record_exec(), reload_logger(), remove_from_queue(), setup_privacy_args(), sms_nextoutgoing(), sms_writefile(), testclient_exec(), testserver_exec(), and write_history().
01935 { 01936 char *ptr; 01937 int len = strlen(path), count = 0, x, piececount = 0; 01938 char *tmp = ast_strdupa(path); 01939 char **pieces; 01940 char *fullpath = alloca(len + 1); 01941 int res = 0; 01942 01943 for (ptr = tmp; *ptr; ptr++) { 01944 if (*ptr == '/') 01945 count++; 01946 } 01947 01948 /* Count the components to the directory path */ 01949 pieces = alloca(count * sizeof(*pieces)); 01950 for (ptr = tmp; *ptr; ptr++) { 01951 if (*ptr == '/') { 01952 *ptr = '\0'; 01953 pieces[piececount++] = ptr + 1; 01954 } 01955 } 01956 01957 *fullpath = '\0'; 01958 for (x = 0; x < piececount; x++) { 01959 /* This looks funky, but the buffer is always ideally-sized, so it's fine. */ 01960 strcat(fullpath, "/"); 01961 strcat(fullpath, pieces[x]); 01962 res = mkdir(fullpath, mode); 01963 if (res && errno != EEXIST) 01964 return errno; 01965 } 01966 return 0; 01967 }
| int ast_parse_digest | ( | const char * | digest, | |
| struct ast_http_digest * | d, | |||
| int | request, | |||
| int | pedantic | |||
| ) |
Parse digest authorization header.
Definition at line 1991 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_set, ast_strlen_zero(), ast_http_digest::cnonce, LOG_WARNING, ast_http_digest::nc, ast_http_digest::nonce, ast_http_digest::qop, ast_http_digest::realm, ast_http_digest::response, ast_http_digest::uri, and ast_http_digest::username.
Referenced by auth_http_callback().
01991 { 01992 int i; 01993 char *c, key[512], val[512]; 01994 struct ast_str *str = ast_str_create(16); 01995 01996 if (ast_strlen_zero(digest) || !d || !str) { 01997 ast_free(str); 01998 return -1; 01999 } 02000 02001 ast_str_set(&str, 0, "%s", digest); 02002 02003 c = ast_skip_blanks(ast_str_buffer(str)); 02004 02005 if (strncasecmp(c, "Digest ", strlen("Digest "))) { 02006 ast_log(LOG_WARNING, "Missing Digest.\n"); 02007 ast_free(str); 02008 return -1; 02009 } 02010 c += strlen("Digest "); 02011 02012 /* lookup for keys/value pair */ 02013 while (*c && *(c = ast_skip_blanks(c))) { 02014 /* find key */ 02015 i = 0; 02016 while (*c && *c != '=' && *c != ',' && !isspace(*c)) { 02017 key[i++] = *c++; 02018 } 02019 key[i] = '\0'; 02020 c = ast_skip_blanks(c); 02021 if (*c == '=') { 02022 c = ast_skip_blanks(++c); 02023 i = 0; 02024 if (*c == '\"') { 02025 /* in quotes. Skip first and look for last */ 02026 c++; 02027 while (*c && *c != '\"') { 02028 if (*c == '\\' && c[1] != '\0') { /* unescape chars */ 02029 c++; 02030 } 02031 val[i++] = *c++; 02032 } 02033 } else { 02034 /* token */ 02035 while (*c && *c != ',' && !isspace(*c)) { 02036 val[i++] = *c++; 02037 } 02038 } 02039 val[i] = '\0'; 02040 } 02041 02042 while (*c && *c != ',') { 02043 c++; 02044 } 02045 if (*c) { 02046 c++; 02047 } 02048 02049 if (!strcasecmp(key, "username")) { 02050 ast_string_field_set(d, username, val); 02051 } else if (!strcasecmp(key, "realm")) { 02052 ast_string_field_set(d, realm, val); 02053 } else if (!strcasecmp(key, "nonce")) { 02054 ast_string_field_set(d, nonce, val); 02055 } else if (!strcasecmp(key, "uri")) { 02056 ast_string_field_set(d, uri, val); 02057 } else if (!strcasecmp(key, "domain")) { 02058 ast_string_field_set(d, domain, val); 02059 } else if (!strcasecmp(key, "response")) { 02060 ast_string_field_set(d, response, val); 02061 } else if (!strcasecmp(key, "algorithm")) { 02062 if (strcasecmp(val, "MD5")) { 02063 ast_log(LOG_WARNING, "Digest algorithm: \"%s\" not supported.\n", val); 02064 return -1; 02065 } 02066 } else if (!strcasecmp(key, "cnonce")) { 02067 ast_string_field_set(d, cnonce, val); 02068 } else if (!strcasecmp(key, "opaque")) { 02069 ast_string_field_set(d, opaque, val); 02070 } else if (!strcasecmp(key, "qop") && !strcasecmp(val, "auth")) { 02071 d->qop = 1; 02072 } else if (!strcasecmp(key, "nc")) { 02073 unsigned long u; 02074 if (sscanf(val, "%30lx", &u) != 1) { 02075 ast_log(LOG_WARNING, "Incorrect Digest nc value: \"%s\".\n", val); 02076 return -1; 02077 } 02078 ast_string_field_set(d, nc, val); 02079 } 02080 } 02081 ast_free(str); 02082 02083 /* Digest checkout */ 02084 if (ast_strlen_zero(d->realm) || ast_strlen_zero(d->nonce)) { 02085 /* "realm" and "nonce" MUST be always exist */ 02086 return -1; 02087 } 02088 02089 if (!request) { 02090 /* Additional check for Digest response */ 02091 if (ast_strlen_zero(d->username) || ast_strlen_zero(d->uri) || ast_strlen_zero(d->response)) { 02092 return -1; 02093 } 02094 02095 if (pedantic && d->qop && (ast_strlen_zero(d->cnonce) || ast_strlen_zero(d->nc))) { 02096 return -1; 02097 } 02098 } 02099 02100 return 0; 02101 }
| 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 1467 of file main/utils.c.
01468 { 01469 char *dataPut = start; 01470 int inEscape = 0; 01471 int inQuotes = 0; 01472 01473 for (; *start; start++) { 01474 if (inEscape) { 01475 *dataPut++ = *start; /* Always goes verbatim */ 01476 inEscape = 0; 01477 } else { 01478 if (*start == '\\') { 01479 inEscape = 1; /* Do not copy \ into the data */ 01480 } else if (*start == '\'') { 01481 inQuotes = 1 - inQuotes; /* Do not copy ' into the data */ 01482 } else { 01483 /* Replace , with |, unless in quotes */ 01484 *dataPut++ = inQuotes ? *start : ((*start == find) ? replace_with : *start); 01485 } 01486 } 01487 } 01488 if (start != dataPut) 01489 *dataPut = 0; 01490 return dataPut; 01491 }
| 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 1068 of file main/utils.c.
References ast_log(), ast_pthread_create_stack(), errno, LOG_WARNING, and thr_arg::start_routine.
01071 { 01072 unsigned char attr_destroy = 0; 01073 int res; 01074 01075 if (!attr) { 01076 attr = alloca(sizeof(*attr)); 01077 pthread_attr_init(attr); 01078 attr_destroy = 1; 01079 } 01080 01081 if ((errno = pthread_attr_setdetachstate(attr, PTHREAD_CREATE_DETACHED))) 01082 ast_log(LOG_WARNING, "pthread_attr_setdetachstate: %s\n", strerror(errno)); 01083 01084 res = ast_pthread_create_stack(thread, attr, start_routine, data, 01085 stacksize, file, caller, line, start_fn); 01086 01087 if (attr_destroy) 01088 pthread_attr_destroy(attr); 01089 01090 return res; 01091 }
| 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 1019 of file main/utils.c.
References 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().
01022 { 01023 #if !defined(LOW_MEMORY) 01024 struct thr_arg *a; 01025 #endif 01026 01027 if (!attr) { 01028 attr = alloca(sizeof(*attr)); 01029 pthread_attr_init(attr); 01030 } 01031 01032 #ifdef __linux__ 01033 /* On Linux, pthread_attr_init() defaults to PTHREAD_EXPLICIT_SCHED, 01034 which is kind of useless. Change this here to 01035 PTHREAD_INHERIT_SCHED; that way the -p option to set realtime 01036 priority will propagate down to new threads by default. 01037 This does mean that callers cannot set a different priority using 01038 PTHREAD_EXPLICIT_SCHED in the attr argument; instead they must set 01039 the priority afterwards with pthread_setschedparam(). */ 01040 if ((errno = pthread_attr_setinheritsched(attr, PTHREAD_INHERIT_SCHED))) 01041 ast_log(LOG_WARNING, "pthread_attr_setinheritsched: %s\n", strerror(errno)); 01042 #endif 01043 01044 if (!stacksize) 01045 stacksize = AST_STACKSIZE; 01046 01047 if ((errno = pthread_attr_setstacksize(attr, stacksize ? stacksize : AST_STACKSIZE))) 01048 ast_log(LOG_WARNING, "pthread_attr_setstacksize: %s\n", strerror(errno)); 01049 01050 #if !defined(LOW_MEMORY) 01051 if ((a = ast_malloc(sizeof(*a)))) { 01052 a->start_routine = start_routine; 01053 a->data = data; 01054 start_routine = dummy_start; 01055 if (asprintf(&a->name, "%-20s started at [%5d] %s %s()", 01056 start_fn, line, file, caller) < 0) { 01057 ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); 01058 a->name = NULL; 01059 } 01060 data = a; 01061 } 01062 #endif /* !LOW_MEMORY */ 01063 01064 return pthread_create(thread, attr, start_routine, data); /* We're in ast_pthread_create, so it's okay */ 01065 }
| long int ast_random | ( | void | ) |
Definition at line 1443 of file main/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_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(), local_new(), make_email_file(), make_our_tag(), mktemp_internal(), moh_files_alloc(), multicast_rtp_new(), ogg_vorbis_rewrite(), osp_create_uuid(), page_exec(), park_space_reserve(), process_weights(), rec_request(), 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().
01444 { 01445 long int res; 01446 #ifdef HAVE_DEV_URANDOM 01447 if (dev_urandom_fd >= 0) { 01448 int read_res = read(dev_urandom_fd, &res, sizeof(res)); 01449 if (read_res > 0) { 01450 long int rm = RAND_MAX; 01451 res = res < 0 ? ~res : res; 01452 rm++; 01453 return res % rm; 01454 } 01455 } 01456 #endif 01457 #ifdef linux 01458 res = random(); 01459 #else 01460 ast_mutex_lock(&randomlock); 01461 res = random(); 01462 ast_mutex_unlock(&randomlock); 01463 #endif 01464 return res; 01465 }
| void ast_register_thread | ( | char * | name | ) |
Definition at line 401 of file asterisk.c.
References ast_calloc, ast_get_tid(), AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.
Referenced by dummy_start().
00402 { 00403 struct thread_list_t *new = ast_calloc(1, sizeof(*new)); 00404 00405 if (!new) 00406 return; 00407 new->id = pthread_self(); 00408 new->lwp = ast_get_tid(); 00409 new->name = name; /* steal the allocated memory for the thread name */ 00410 AST_RWLIST_WRLOCK(&thread_list); 00411 AST_RWLIST_INSERT_HEAD(&thread_list, new, list); 00412 AST_RWLIST_UNLOCK(&thread_list); 00413 }
| void ast_set_default_eid | ( | struct ast_eid * | eid | ) |
Fill in an ast_eid with the default eid of this machine.
Definition at line 237 of file netsock.c.
References ARRAY_LEN, ast_debug, ast_eid_to_str(), and ast_eid::eid.
Referenced by ast_readconfig().
00238 { 00239 #if defined(SIOCGIFHWADDR) && defined(HAVE_STRUCT_IFREQ_IFR_IFRU_IFRU_HWADDR) 00240 int s, x = 0; 00241 char eid_str[20]; 00242 struct ifreq ifr; 00243 static const unsigned int MAXIF = 10; 00244 00245 s = socket(AF_INET, SOCK_STREAM, 0); 00246 if (s < 0) 00247 return; 00248 for (x = 0; x < MAXIF; x++) { 00249 static const char *prefixes[] = { "eth", "em" }; 00250 unsigned int i; 00251 00252 for (i = 0; i < ARRAY_LEN(prefixes); i++) { 00253 memset(&ifr, 0, sizeof(ifr)); 00254 snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s%d", prefixes[i], x); 00255 if (!ioctl(s, SIOCGIFHWADDR, &ifr)) { 00256 break; 00257 } 00258 } 00259 00260 if (i == ARRAY_LEN(prefixes)) { 00261 /* Try pciX#[1..N] */ 00262 for (i = 0; i < MAXIF; i++) { 00263 memset(&ifr, 0, sizeof(ifr)); 00264 snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "pci%u#%u", x, i); 00265 if (!ioctl(s, SIOCGIFHWADDR, &ifr)) { 00266 break; 00267 } 00268 } 00269 if (i == MAXIF) { 00270 continue; 00271 } 00272 } 00273 00274 memcpy(eid, ((unsigned char *)&ifr.ifr_hwaddr) + 2, sizeof(*eid)); 00275 ast_debug(1, "Seeding global EID '%s' from '%s' using 'siocgifhwaddr'\n", ast_eid_to_str(eid_str, sizeof(eid_str), eid), ifr.ifr_name); 00276 close(s); 00277 return; 00278 } 00279 close(s); 00280 #else 00281 #if defined(ifa_broadaddr) && !defined(SOLARIS) 00282 char eid_str[20]; 00283 struct ifaddrs *ifap; 00284 00285 if (getifaddrs(&ifap) == 0) { 00286 struct ifaddrs *p; 00287 for (p = ifap; p; p = p->ifa_next) { 00288 if ((p->ifa_addr->sa_family == AF_LINK) && !(p->ifa_flags & IFF_LOOPBACK) && (p->ifa_flags & IFF_RUNNING)) { 00289 struct sockaddr_dl* sdp = (struct sockaddr_dl*) p->ifa_addr; 00290 memcpy(&(eid->eid), sdp->sdl_data + sdp->sdl_nlen, 6); 00291 ast_debug(1, "Seeding global EID '%s' from '%s' using 'getifaddrs'\n", ast_eid_to_str(eid_str, sizeof(eid_str), eid), p->ifa_name); 00292 freeifaddrs(ifap); 00293 return; 00294 } 00295 } 00296 freeifaddrs(ifap); 00297 } 00298 #endif 00299 #endif 00300 ast_debug(1, "No ethernet interface found for seeding global EID. You will have to set it manually.\n"); 00301 }
| void ast_sha1_hash | ( | char * | output, | |
| const char * | input | |||
| ) |
Produces SHA1 hash based on input string.
Definition at line 256 of file main/utils.c.
References SHA1Input(), SHA1Reset(), and SHA1Result().
Referenced by aji_act_hook(), handle_call_token(), jabber_make_auth(), and sha1().
00257 { 00258 struct SHA1Context sha; 00259 char *ptr; 00260 int x; 00261 uint8_t Message_Digest[20]; 00262 00263 SHA1Reset(&sha); 00264 00265 SHA1Input(&sha, (const unsigned char *) input, strlen(input)); 00266 00267 SHA1Result(&sha, Message_Digest); 00268 ptr = output; 00269 for (x = 0; x < 20; x++) 00270 ptr += sprintf(ptr, "%2.2x", Message_Digest[x]); 00271 }
| static force_inline void ast_slinear_saturated_add | ( | short * | input, | |
| short * | value | |||
| ) | [static] |
Definition at line 304 of file utils.h.
Referenced by ast_frame_slinear_sum(), audio_audiohook_write_list(), audiohook_read_frame_both(), and softmix_bridge_thread().
00305 { 00306 int res; 00307 00308 res = (int) *input + *value; 00309 if (res > 32767) 00310 *input = 32767; 00311 else if (res < -32767) 00312 *input = -32767; 00313 else 00314 *input = (short) res; 00315 }
| static force_inline void ast_slinear_saturated_divide | ( | short * | input, | |
| short * | value | |||
| ) | [static] |
Definition at line 343 of file utils.h.
Referenced by ast_frame_adjust_volume(), and audiohook_read_frame_both().
| static force_inline void ast_slinear_saturated_multiply | ( | short * | input, | |
| short * | value | |||
| ) | [static] |
Definition at line 330 of file utils.h.
Referenced by ast_frame_adjust_volume(), and audiohook_read_frame_both().
00331 { 00332 int res; 00333 00334 res = (int) *input * *value; 00335 if (res > 32767) 00336 *input = 32767; 00337 else if (res < -32767) 00338 *input = -32767; 00339 else 00340 *input = (short) res; 00341 }
| static force_inline void ast_slinear_saturated_subtract | ( | short * | input, | |
| short * | value | |||
| ) | [static] |
| 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 303 of file netsock.c.
References ast_eid::eid.
Referenced by aji_handle_pubsub_event(), ast_readconfig(), build_peer(), dundi_do_query(), and set_config().
00304 { 00305 unsigned int eid_int[6]; 00306 int x; 00307 00308 if (sscanf(s, "%2x:%2x:%2x:%2x:%2x:%2x", &eid_int[0], &eid_int[1], &eid_int[2], 00309 &eid_int[3], &eid_int[4], &eid_int[5]) != 6) 00310 return -1; 00311 00312 for (x = 0; x < 6; x++) 00313 eid->eid[x] = eid_int[x]; 00314 00315 return 0; 00316 }
| void ast_unregister_thread | ( | void * | id | ) |
Definition at line 415 of file asterisk.c.
References ast_free, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, thread_list_t::id, ast_atexit::list, and thread_list_t::name.
Referenced by dummy_start().
00416 { 00417 struct thread_list_t *x; 00418 00419 AST_RWLIST_WRLOCK(&thread_list); 00420 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&thread_list, x, list) { 00421 if ((void *) x->id == id) { 00422 AST_RWLIST_REMOVE_CURRENT(list); 00423 break; 00424 } 00425 } 00426 AST_RWLIST_TRAVERSE_SAFE_END; 00427 AST_RWLIST_UNLOCK(&thread_list); 00428 if (x) { 00429 ast_free(x->name); 00430 ast_free(x); 00431 } 00432 }
| 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 424 of file main/utils.c.
References ast_test_flag, and AST_URI_LEGACY_SPACE.
Referenced by acf_curl_helper(), ast_http_get_post_vars(), 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().
00425 { 00426 char *o; 00427 unsigned int tmp; 00428 00429 for (o = s; *s; s++, o++) { 00430 if (ast_test_flag(&spec, AST_URI_LEGACY_SPACE) && *s == '+') { 00431 /* legacy mode, decode '+' as space */ 00432 *o = ' '; 00433 } else if (*s == '%' && s[1] != '\0' && s[2] != '\0' && sscanf(s + 1, "%2x", &tmp) == 1) { 00434 /* have '%', two chars and correct parsing */ 00435 *o = tmp; 00436 s += 2; /* Will be incremented once more when we break out */ 00437 } else /* all other cases, just copy */ 00438 *o = *s; 00439 } 00440 *o = '\0'; 00441 }
| 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 385 of file main/utils.c.
References ast_test_flag, AST_URI_ALPHANUM, AST_URI_LEGACY_SPACE, AST_URI_MARK, and AST_URI_SIP_USER_UNRESERVED.
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().
00386 { 00387 const char *ptr = string; /* Start with the string */ 00388 char *out = outbuf; 00389 const char *mark = "-_.!~*'()"; /* no encode set, RFC 2396 section 2.3, RFC 3261 sec 25 */ 00390 const char *user_unreserved = "&=+$,;?/"; /* user-unreserved set, RFC 3261 sec 25 */ 00391 00392 while (*ptr && out - outbuf < buflen - 1) { 00393 if (ast_test_flag(&spec, AST_URI_LEGACY_SPACE) && *ptr == ' ') { 00394 /* for legacy encoding, encode spaces as '+' */ 00395 *out = '+'; 00396 out++; 00397 } else if (!(ast_test_flag(&spec, AST_URI_MARK) 00398 && strchr(mark, *ptr)) 00399 && !(ast_test_flag(&spec, AST_URI_ALPHANUM) 00400 && ((*ptr >= '0' && *ptr <= '9') 00401 || (*ptr >= 'A' && *ptr <= 'Z') 00402 || (*ptr >= 'a' && *ptr <= 'z'))) 00403 && !(ast_test_flag(&spec, AST_URI_SIP_USER_UNRESERVED) 00404 && strchr(user_unreserved, *ptr))) { 00405 00406 if (out - outbuf >= buflen - 3) { 00407 break; 00408 } 00409 out += sprintf(out, "%%%02X", (unsigned char) *ptr); 00410 } else { 00411 *out = *ptr; /* Continue copying the string */ 00412 out++; 00413 } 00414 ptr++; 00415 } 00416 00417 if (buflen) { 00418 *out = '\0'; 00419 } 00420 00421 return outbuf; 00422 }
| int ast_utils_init | ( | void | ) |
Definition at line 1969 of file main/utils.c.
References ARRAY_LEN, ast_cli_register_multiple(), and base64_init().
Referenced by main().
01970 { 01971 #ifdef HAVE_DEV_URANDOM 01972 dev_urandom_fd = open("/dev/urandom", O_RDONLY); 01973 #endif 01974 base64_init(); 01975 #ifdef DEBUG_THREADS 01976 #if !defined(LOW_MEMORY) 01977 ast_cli_register_multiple(utils_cli, ARRAY_LEN(utils_cli)); 01978 #endif 01979 #endif 01980 return 0; 01981 }
| 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 2137 of file main/utils.c.
References ast_strdupa, and strsep().
02138 { 02139 const char *envPATH = getenv("PATH"); 02140 char *tpath, *path; 02141 struct stat unused; 02142 if (!envPATH) { 02143 return NULL; 02144 } 02145 tpath = ast_strdupa(envPATH); 02146 while ((path = strsep(&tpath, ":"))) { 02147 snprintf(fullpath, fullpath_size, "%s/%s", path, binary); 02148 if (!stat(fullpath, &unused)) { 02149 return fullpath; 02150 } 02151 } 02152 return NULL; 02153 }
| int ast_wait_for_input | ( | int | fd, | |
| int | ms | |||
| ) |
Definition at line 1093 of file main/utils.c.
References ast_poll.
Referenced by _sip_tcp_helper_thread(), action_waitevent(), ast_tcptls_server_root(), dahdi_test_timer(), get_input(), and moh_class_destructor().
01094 { 01095 struct pollfd pfd[1]; 01096 memset(pfd, 0, sizeof(pfd)); 01097 pfd[0].fd = fd; 01098 pfd[0].events = POLLIN|POLLPRI; 01099 return ast_poll(pfd, 1, ms); 01100 }
| 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.
| uint64_t __unsigned_int_flags_dummy64 |
| 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 191 of file asterisk.c.
Referenced by aji_devstate_cb(), aji_handle_pubsub_event(), aji_mwi_cb(), aji_publish_device_state(), aji_publish_mwi(), ast_event_append_eid(), ast_event_cb(), ast_readconfig(), ast_str_retrieve_variable(), cpg_confchg_cb(), cpg_deliver_cb(), handle_show_settings(), and set_config().
| struct ast_flags ast_uri_http |
Definition at line 381 of file main/utils.c.
Referenced by acf_curl_helper(), config_curl(), destroy_curl(), launch_asyncagi(), realtime_curl(), realtime_multi_curl(), require_curl(), store_curl(), update2_curl(), update_curl(), uridecode(), and uriencode().
| struct ast_flags ast_uri_http_legacy |
Definition at line 382 of file main/utils.c.
Referenced by acf_curl_helper(), ast_http_get_post_vars(), and handle_uri().
| struct ast_flags ast_uri_sip_user |
Definition at line 383 of file main/utils.c.
Referenced by add_rpid(), build_contact(), get_destination(), get_name_and_number(), get_refer_info(), handle_request_invite(), initreqprep(), parse_moved_contact(), sip_new(), and sip_uri_cmp().
1.5.6