Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:01:58 2007

Asterisk developer's documentation :: Codename Pineapple


utils.h File Reference


Detailed Description

Utility functions.

Definition in file utils.h.

#include "asterisk/compat.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <limits.h>
#include <string.h>
#include "asterisk/lock.h"
#include "asterisk/time.h"
#include "asterisk/logger.h"
#include "asterisk/compiler.h"
#include "asterisk/strings.h"

Include dependency graph for utils.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_flags
struct  ast_hostent

Defines

#define ast_asprintf(ret, fmt,)   _ast_asprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, __VA_ARGS__)
#define AST_BACKGROUND_STACKSIZE   240 * 1024
#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__)
#define ast_clear_flag(p, flag)
#define ast_clear_flag_nonstd(p, flag)
#define ast_copy_flags(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_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_realloc(p, len)   _ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define ast_set2_flag(p, value, flag)
#define ast_set2_flag_nonstd(p, value, flag)
#define ast_set_flag(p, flag)
#define ast_set_flag_nonstd(p, flag)
#define ast_set_flags_to(p, flag, value)
#define AST_STACKSIZE   240 * 1024
#define ast_strdup(str)   _ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define ast_strdupa(s)
#define ast_strndup(str, len)   _ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define ast_test_flag(p, flag)
#define ast_test_flag_nonstd(p, flag)   ((p)->flags & (flag))
#define ast_vasprintf(ret, fmt, ap)   _ast_vasprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, (fmt), (ap))
#define inet_ntoa   __dont__use__inet_ntoa__use__ast_inet_ntoa__instead__
#define MALLOC_FAILURE_MSG   ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file);

Functions

int ast_base64decode (unsigned char *dst, const char *src, int max)
 decode BASE64 encoded text
int ast_base64encode (char *dst, const unsigned char *src, int srclen, int max)
int ast_base64encode_full (char *dst, const unsigned char *src, int srclen, int max, int linebreaks)
 encode text to BASE64 coding
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.
hostent * ast_gethostbyname (const char *host, struct ast_hostent *hp)
 Re-entrant (thread safe) version of gethostbyname that replaces the standard gethostbyname (which is not thread safe).
const char * ast_inet_ntoa (struct in_addr ia)
 thread-safe replacement for inet_ntoa().
 AST_INLINE_API (void *attribute_malloc _ast_malloc(size_t len, const char *file, int lineno, const char *func),{void *p;if(!(p=malloc(len))) MALLOC_FAILURE_MSG;return p;}) AST_INLINE_API(void *attribute_malloc _ast_calloc(size_t num
 A wrapper for calloc().
void ast_md5_hash (char *output, char *input)
 Produce 32 char MD5 hash of value.
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_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_sha1_hash (char *output, char *input)
 Produce 40 char SHA1 hash of value.
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)
void ast_unregister_thread (void *id)
void ast_uri_decode (char *s)
 Decode URI, URN, URL (overwrite string).
char * ast_uri_encode (const char *string, char *outbuf, int buflen, int doreserved)
 Turn text string to URI-encoded XX version At this point, we're converting from ISO-8859-x (8-bit), not UTF8 as in the SIP protocol spec If doreserved == 1 we will convert reserved characters also. RFC 2396, section 2.4 outbuf needs to have more memory allocated than the instring to have room for the expansion. Every char that is converted is replaced by three ASCII characters.
int ast_utils_init (void)
int ast_wait_for_input (int fd, int ms)
static force_inline int inaddrcmp (const struct sockaddr_in *sin1, const struct sockaddr_in *sin2)
int test_for_thread_safety (void)

Variables

unsigned int __unsigned_int_flags_dummy
size_t const char * file
size_t const char int const
char * 
func
size_t len
size_t const char int lineno


Define Documentation

#define ast_asprintf ret,
fmt   )     _ast_asprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, __VA_ARGS__)
 

#define AST_BACKGROUND_STACKSIZE   240 * 1024
 

Definition at line 264 of file utils.h.

#define ast_calloc num,
len   )     _ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
 

Referenced by __ast_device_state_changed_literal(), __ast_format_register(), __ast_module_user_add(), __ast_pbx_run(), __sip_reliable_xmit(), accept_thread(), action_originate(), add_agent(), add_realm_authentication(), add_redirect(), add_sip_domain(), add_string_pool(), add_to_load_order(), aji_handle_message(), ALLOC_COMMENT(), alloc_jb_frame(), answer_exec_enable(), append_history_va(), append_mapping(), append_permission(), ast_add_extension2(), ast_add_hint(), ast_add_profile(), ast_autoservice_start(), ast_backtrace(), ast_category_new(), ast_cdr_alloc(), ast_cdr_detach(), ast_cdr_register(), ast_channel_alloc(), ast_channel_datastore_alloc(), ast_channel_register(), ast_channel_spy_add(), ast_channel_start_silence_generator(), ast_channel_whisper_start(), ast_config_new(), ast_context_add_ignorepat2(), ast_context_add_include2(), ast_context_add_switch2(), ast_devstate_add(), ast_devstate_prov_add(), ast_dial_append(), ast_dial_create(), ast_dnsmgr_get(), ast_dsp_new(), ast_frame_header_new(), ast_linear_stream(), ast_log(), ast_merge_contexts_and_delete(), ast_module_register(), ast_monitor_start(), ast_netsock_bindaddr(), ast_netsock_list_alloc(), ast_odbc_request_obj(), ast_park_call(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_register_application(), ast_register_atexit(), ast_register_file_version(), ast_register_thread(), ast_rtcp_new(), ast_rtp_new_with_bindaddr(), ast_speech_new(), ast_udptl_new_with_bindaddr(), ast_var_assign(), ast_variable_new(), ast_verbose(), build_context(), build_device(), build_mapping(), build_peer(), build_user(), builtin_atxfer(), callerid_new(), config_pgsql(), copy_request(), create_transaction(), do_monitor(), do_proxy_auth(), dundi_answer_entity(), dundi_answer_query(), dundi_send(), enum_newtoplev(), find_cache(), find_idle_thread(), find_tpeer(), fixed_jb_new(), get_filestream(), gtalk_add_candidate(), gtalk_alloc(), gtalk_create_candidates(), handle_add_indication(), iax2_register(), iax_frame_new(), iax_park(), ind_load_module(), init_logger_chain(), io_context_create(), jingle_add_candidate(), jingle_alloc(), jingle_create_candidates(), local_alloc(), local_call(), make_logchannel(), mkintf(), moh_add_file(), moh_class_malloc(), moh_files_alloc(), mohalloc(), new_iax(), newpvt(), parse_copy(), playtones_alloc(), queue_sip_request(), realtime_multi_pgsql(), realtime_pgsql(), req_alloc(), reschedule_precache(), sched_alloc(), sched_context_create(), server_root(), session_do(), sip_alloc(), sip_park(), sip_refer_allocate(), sip_register(), sip_request_call(), siprequest_alloc(), skinny_new(), skinny_req_parse(), smdi_read(), spawn_dp_lookup(), start_network_thread(), store_config(), temp_device(), temp_peer(), tonepair_alloc(), try_firmware(), and try_load_key().

#define ast_calloc_cache num,
len   )     _ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
 

#define ast_clear_flag p,
flag   ) 
 

Definition at line 81 of file utils.h.

Referenced by __ast_read(), __sip_ack(), aji_filter_roster(), aji_pruneregister(), ast_app_parse_options(), ast_bridge_call(), ast_channel_spy_add(), ast_channel_spy_read_frame(), ast_channel_undefer_dtmf(), ast_channel_whisper_stop(), ast_deactivate_generator(), ast_jb_destroy(), ast_jb_put(), ast_rtp_stop(), ast_sendtext(), ast_speech_start(), ast_unload_resource(), ast_write(), authenticate_verify(), bridge_p2p_loop(), build_peer(), build_user(), builtin_atxfer(), check_pendings(), create_addr(), do_parking_thread(), dundi_lookup_local(), handle_common_options(), handle_request_invite(), handle_request_refer(), handle_request_subscribe(), iax2_destroy_helper(), linear_alloc(), load_resource(), local_ast_moh_stop(), local_attended_transfer(), local_hangup(), local_queue_frame(), phone_read(), playtones_alloc(), process_sdp(), queue_frame_to_spies(), register_verify(), reload_config(), reset_global_settings(), reset_transaction(), set_config_flags(), set_device_host(), sip_dtmfmode(), sip_hangup(), sip_no_debug(), socket_process(), update_call_counter(), and zt_read().

#define ast_clear_flag_nonstd p,
flag   ) 
 

Value:

do { \
               ((p)->flags &= ~(flag)); \
               } while(0)

Definition at line 126 of file utils.h.

Referenced by build_transactions(), cache_lookup_internal(), dundi_lookup_local(), and handle_command_response().

#define ast_copy_flags dest,
src,
flagz   ) 
 

Definition at line 88 of file utils.h.

Referenced by agent_read(), aji_create_client(), aji_filter_roster(), ast_cdr_reset(), ast_feature_interpret(), build_device(), build_peer(), build_user(), cache_lookup_internal(), check_access(), check_peer_ok(), check_user_full(), check_user_ok(), create_addr(), create_addr_from_peer(), dundi_lookup_local(), iax2_request(), register_verify(), reload_config(), set_device_defaults(), set_peer_defaults(), sip_alloc(), sip_poke_peer(), and transmit_response_using_temp().

#define ast_copy_flags_nonstd dest,
src,
flagz   ) 
 

Value:

do { \
               (dest)->flags &= ~(flagz); \
               (dest)->flags |= ((src)->flags & (flagz)); \
               } while (0)

Definition at line 130 of file utils.h.

#define AST_FLAGS_ALL   UINT_MAX
 

Definition at line 142 of file utils.h.

Referenced by aji_create_client(), ast_app_parse_options(), ast_cdr_reset(), ast_feature_interpret(), builtin_atxfer(), cache_lookup_internal(), dundi_lookup_local(), reload_config(), reset_global_settings(), and set_config_flags().

#define ast_free   free
 

free() wrapper

ast_free should be used when a function pointer for free() needs to be passed as the argument to a function. Otherwise, astmm will cause seg faults.

Definition at line 311 of file utils.h.

Referenced by add_extensions(), do_parking_thread(), and register_peer_exten().

#define ast_malloc len   )     _ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
 

A wrapper for malloc().

ast_malloc() is a wrapper for malloc() that will generate an Asterisk log message in the case that the allocation fails.

The argument and return value are the same as malloc()

Definition at line 326 of file utils.h.

Referenced by aji_act_hook(), append_event(), ast_append_ha(), ast_db_gettree(), ast_duplicate_ha(), ast_frisolate(), ast_io_add(), ast_loader_register(), ast_manager_register2(), ast_pthread_create_stack(), ast_read_textfile(), ast_register_indication(), ast_register_verbose(), ast_smoother_new(), build_route(), CB_INIT(), chandup(), cli_complete(), destroy_trans(), handle_commandmatchesarray(), iax2_setoption(), ind_load_module(), init_batch(), io_context_create(), jb_new(), pgsql_reconnect(), queue_put(), send_cwcidspill(), zt_call(), zt_callwait(), and zt_sendtext().

#define ast_pthread_create a,
b,
c,
 ) 
 

Value:

ast_pthread_create_stack(a, b, c, d,         \
                             0,           \
                             __FILE__, __FUNCTION__,     \
                             __LINE__, #c)

Definition at line 274 of file utils.h.

Referenced by accept_thread(), action_originate(), ast_bridge_call_thread_launch(), ast_dial_run(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_pbx_start(), dundi_answer_entity(), dundi_answer_query(), handle_hd_hf(), handle_init_event(), handle_offhook_message(), handle_soft_key_event_message(), handle_stimulus_message(), init_logger(), launch_service(), load_module(), show_console(), spawn_dp_lookup(), test_for_thread_safety(), and zt_handle_event().

#define ast_pthread_create_background a,
b,
c,
 ) 
 

Value:

ast_pthread_create_stack(a, b, c, d,         \
                              AST_BACKGROUND_STACKSIZE,  \
                              __FILE__, __FUNCTION__, \
                              __LINE__, #c)

Definition at line 279 of file utils.h.

Referenced by aji_reload(), ast_autoservice_start(), ast_cdr_submit_batch(), ast_device_state_engine_init(), ast_makesocket(), do_reload(), find_idle_thread(), iax_park(), listener(), load_module(), moh_register(), reload(), reload_config(), restart_monitor(), server_root(), server_start(), sip_park(), and start_network_thread().

#define ast_realloc p,
len   )     _ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
 

Referenced by ast_add_profile(), ast_cli_completion_matches(), ast_el_strtoarr(), ast_playtones_start(), CB_ADD(), CB_ADD_LEN(), cli_complete(), enum_callback(), handle_commandmatchesarray(), iax2_trunk_queue(), ind_load_module(), io_grow(), LLB_ADD(), and moh_add_file().

#define ast_set2_flag p,
value,
flag   ) 
 

Definition at line 98 of file utils.h.

Referenced by aji_create_client(), aji_load_config(), apply_outgoing(), ast_jb_read_conf(), ast_rtp_setdtmf(), ast_rtp_setdtmfcompensate(), ast_rtp_setstun(), build_device(), build_peer(), build_user(), check_access(), do_reload(), handle_common_options(), load_moh_classes(), pbx_load_config(), reload_config(), set_config(), and sip_alloc().

#define ast_set2_flag_nonstd p,
value,
flag   ) 
 

Definition at line 135 of file utils.h.

#define ast_set_flag p,
flag   ) 
 

Definition at line 74 of file utils.h.

Referenced by __ast_pbx_run(), __ast_read(), __expire_registry(), __sip_reliable_xmit(), apply_peer(), ast_app_parse_options(), ast_call(), ast_cdr_detach(), ast_channel_bridge(), ast_channel_defer_dtmf(), ast_channel_spy_add(), ast_channel_whisper_start(), ast_hangup(), ast_jb_do_usecheck(), ast_jb_put(), ast_rtp_bridge(), ast_rtp_new_init(), ast_rtp_raw_write(), ast_rtp_read(), ast_speech_change_state(), authenticate_reply(), authenticate_request(), bridge_p2p_rtp_write(), build_device(), build_peer(), build_user(), builtin_atxfer(), check_access(), check_availability(), check_bridge(), check_peer_ok(), check_user_full(), check_user_ok(), check_via(), create_addr_from_peer(), create_transaction(), decrypt_frame(), delete_users(), do_parking_thread(), do_register(), dundi_encrypt(), dundi_lookup_local(), dundi_send(), find_call(), handle_common_options(), handle_invite_replaces(), handle_request(), handle_request_bye(), handle_request_cancel(), handle_request_invite(), handle_request_refer(), handle_request_subscribe(), handle_response(), handle_response_answer(), handle_response_bye(), handle_response_invite(), handle_response_message(), handle_response_notify(), handle_response_peerpoke(), handle_response_refer(), handle_response_register(), iax2_destroy(), iax2_predestroy(), iax2_provision(), iax2_prune_realtime(), init_outgoing(), linear_alloc(), load_resource(), local_alloc(), local_ast_moh_start(), local_attended_transfer(), local_call(), local_hangup(), local_queue_frame(), main(), match_or_create_dialog(), moh_register(), park_exec(), playtones_alloc(), post_cdr(), process_rfc3389(), process_sdp(), qualify_peer(), queue_frame_to_spies(), realtime_user(), register_verify(), reload_config(), reset_global_settings(), retrans_pkt(), set_config(), set_config_flags(), set_device_host(), set_initreq(), sip_alreadygone(), sip_call(), sip_do_debug(), sip_do_debug_device(), sip_do_debug_ip(), sip_do_debug_peer(), sip_dtmfmode(), sip_handle_t38_reinvite(), sip_hangup(), sip_indicate(), sip_poke_peer(), sip_read(), sip_reg_timeout(), sip_send_mwi_to_peer(), sip_set_rtp_peer(), sip_set_udptl_peer(), sip_write(), sipsock_read(), socket_process(), temp_device(), temp_peer(), temp_pvt_init(), tonepair_alloc(), transmit_register(), transmit_reinvite_with_sdp(), transmit_response_using_temp(), update_call_counter(), write_media_frame(), and zt_read().

#define ast_set_flag_nonstd p,
flag   ) 
 

Value:

do { \
               ((p)->flags |= (flag)); \
               } while(0)

Definition at line 122 of file utils.h.

Referenced by dundi_lookup_internal(), and dundi_query_eid_internal().

#define ast_set_flags_to p,
flag,
value   ) 
 

Definition at line 108 of file utils.h.

Referenced by build_peer(), build_user(), and set_config().

#define AST_STACKSIZE   240 * 1024
 

Definition at line 259 of file utils.h.

Referenced by ast_pthread_create_stack().

#define ast_strdup str   )     _ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__)
 

Referenced by __ast_cli_register(), __ast_http_load(), __oh323_new(), add_to_load_order(), aji_handle_message(), aji_handle_presence(), answer_exec_enable(), ast_add_profile(), ast_channel_datastore_alloc(), ast_cli_complete(), ast_complete_channels(), ast_ext_ctx(), ast_frisolate(), ast_iax2_new(), ast_register_indication(), ast_set_callerid(), autoanswer_complete(), begin_dial(), complete_agent_logoff_cmd(), complete_iax2_show_peer(), complete_peer_helper(), complete_show_dialplan_context(), complete_show_mancmd(), complete_show_version_files(), complete_sip_device(), complete_sip_peer(), complete_sip_user(), complete_sipch(), complete_sipnotify(), complete_skinny_reset(), complete_ulimit(), features_call(), gtalk_new(), init_manager(), jingle_new(), local_call(), mgcp_new(), moh_add_file(), oss_new(), parse_args(), phone_new(), register_peer_exten(), sip_new(), skinny_new(), spawn_dp_lookup(), split_ec(), start_monitor_action(), store_config(), and zt_handle_event().

#define ast_strdupa  ) 
 

Referenced by __ast_play_and_record(), __login_exec(), action_agents(), add_agent(), add_redirect(), add_var(), agent_logoff_maintenance(), aji_send_exec(), aji_status_exec(), answer_exec_enable(), ast_app_getdata(), ast_bridge_call(), ast_callerid_split(), ast_device_state(), ast_device_state_changed_literal(), ast_filehelper(), ast_func_read(), ast_func_write(), ast_get_group(), ast_monitor_start(), ast_netsock_bind(), ast_parse_allow_disallow(), ast_parseable_goto(), ast_playtones_start(), ast_register_file_version(), ast_writefile(), astman_get_variables(), authenticate(), authenticate_verify(), build_channels(), build_mapping(), build_user(), builtin_automonitor(), check_access(), check_day(), check_dow(), check_goto_on_transfer(), check_month(), check_peer_ok(), check_switch_expr(), check_timerange(), check_user_full(), check_user_ok(), cli_audio_convert(), create_addr(), create_addr_from_peer(), decrypt_frame(), do_message(), do_parking_thread(), features_alloc(), find_gtalk(), find_sdp(), find_via_branch(), function_agent(), function_iaxpeer(), get_refer_info(), gtalk_alloc(), gtalk_request(), handle_request_invite(), handle_request_subscribe(), handle_save_dialplan(), handle_show_dialplan(), iax2_call(), iax2_devicestate(), iax2_prov_app(), iax2_request(), ind_load_module(), is_prefix(), ivr_dispatch(), jingle_request(), launch_netscript(), local_devicestate(), metermaidstate(), mgcp_devicestate(), orig_app(), orig_exten(), oss_call(), oss_request(), parse_sip_options(), 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_waitexten(), pbx_retrieve_variable(), peer_set_srcaddr(), process_sdp(), realtime_common(), realtime_exec(), realtime_multi_odbc(), realtime_multi_pgsql(), register_verify(), reload_config(), replace_cid(), resource_name_match(), set_address_from_contact(), sip_devicestate(), sip_sipredirect(), start_monitor_exec(), transmit_invite(), transmit_refer(), update_common_options(), and zt_request().

#define ast_strndup str,
len   )     _ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
 

Referenced by ast_recvtext().

#define ast_test_flag p,
flag   ) 
 

Definition at line 67 of file utils.h.

Referenced by __ast_answer(), __ast_pbx_run(), __ast_read(), __do_deliver(), __expire_registry(), __get_from_jb(), __get_header(), __iax2_show_peers(), __sip_ack(), __sip_destroy(), __sip_pretend_ack(), __sip_semi_ack(), __sip_show_channels(), _sip_show_device(), _sip_show_devices(), _sip_show_peer(), _sip_show_peers(), add_codec_to_sdp(), add_sdp(), agent_new(), aji_pruneregister(), ast_autoservice_stop(), ast_call(), ast_cdr_appenduserfield(), ast_cdr_busy(), ast_cdr_failed(), ast_cdr_free(), ast_cdr_init(), ast_cdr_reset(), ast_cdr_setaccount(), ast_cdr_setapp(), ast_cdr_setcid(), ast_cdr_setdestchan(), ast_cdr_setuserfield(), ast_cdr_start(), ast_cdr_update(), ast_channel_bridge(), ast_channel_defer_dtmf(), ast_channel_spy_add(), ast_channel_spy_free(), ast_channel_spy_read_frame(), ast_cli_netstats(), ast_explicit_goto(), ast_feature_interpret(), ast_hangup(), ast_indicate_data(), ast_jb_destroy(), ast_jb_do_usecheck(), ast_jb_get_and_deliver(), ast_jb_get_when_to_wakeup(), ast_jb_put(), ast_moh_files_next(), ast_queue_frame(), ast_readstring_full(), ast_rtp_bridge(), ast_rtp_early_bridge(), ast_rtp_getnat(), ast_rtp_make_compatible(), ast_rtp_raw_write(), ast_senddigit(), ast_sendtext(), ast_softhangup_nolock(), ast_transfer(), ast_unload_resource(), ast_waitfordigit_full(), ast_write(), authenticate_reply(), authenticate_request(), authenticate_verify(), bridge_native_loop(), bridge_p2p_rtp_write(), build_device(), build_peer(), build_user(), build_via(), check_access(), check_bridge(), check_peer_ok(), check_pendings(), check_post(), check_user_full(), check_user_ok(), complete_sip_device(), complete_sip_peer(), complete_sip_user(), copy_via_headers(), create_addr(), create_addr_from_peer(), create_jb(), decrypt_frame(), destroy_association(), destroy_trans(), dialog_activate_media(), do_monitor(), do_register_auth(), does_peer_need_mwi(), dundi_encrypt(), dundi_exec(), dundi_helper(), dundi_lookup_local(), dundi_precache_thread(), dundi_query_thread(), dundi_rexmit(), dundi_send(), dundifunc_read(), expire_register(), feature_exec_app(), find_cache(), find_via_branch(), function_iaxpeer(), function_sippeer(), get_destination(), handle_command_response(), handle_frame(), handle_invite_replaces(), handle_request(), handle_request_bye(), handle_request_info(), handle_request_invite(), handle_request_message(), handle_request_refer(), handle_request_register(), handle_request_subscribe(), handle_response(), handle_response_answer(), handle_response_invite(), handle_showchan(), iax2_call(), iax2_destroy_helper(), iax2_devicestate(), iax2_getpeername(), iax2_getpeertrunk(), iax2_hangup(), iax2_predestroy(), iax2_prune_realtime(), iax2_request(), iax2_send(), iax2_show_channels(), iax2_show_peer(), iax2_show_users(), iax2_trunk_queue(), iax2_write(), initialize_initreq(), initreqprep(), load_resource(), local_hangup(), local_queue_frame(), local_write(), moh_classes_show(), moh_files_alloc(), moh_on_off(), p2p_callback_disable(), parse_moved_contact(), parse_register_contact(), pbx_builtin_background(), pbx_builtin_waitexten(), precache_transactions(), process_cisco_dtmf(), process_rfc2833(), process_rfc3389(), process_sip_queue(), prune_peers(), prune_users(), queue_frame_to_spies(), realtime_update_peer(), realtime_user(), reg_source_db(), register_verify(), registry_authrequest(), remove_from_queue(), replace_cid(), reqprep(), respprep(), retrans_pkt(), schedule_delivery(), send_dtmf(), send_request(), send_response(), send_trunk(), set_address_from_contact(), set_config(), set_config_flags(), sip_addrcmp(), sip_alloc(), sip_destroy_device(), sip_destroy_peer(), sip_destroy_user(), sip_dtmfmode(), sip_fixup(), sip_get_rtp_peer(), sip_get_udptl_peer(), sip_get_vrtp_peer(), sip_handle_t38_reinvite(), sip_hangup(), sip_indicate(), sip_nat_mode(), sip_new(), sip_prune_realtime(), sip_read(), sip_real_dst(), sip_reregister(), sip_rtp_read(), sip_scheddestroy(), sip_senddigit_begin(), sip_senddigit_end(), sip_set_rtp_peer(), sip_set_udptl_peer(), sip_show_channel(), sip_show_settings(), sip_write(), sipsock_read(), socket_process(), socket_process_meta(), spawn_mp3(), spy_detach(), transmit_notify_with_mwi(), transmit_refer(), transmit_register(), transmit_reinvite_with_sdp(), transmit_response_using_temp(), transmit_response_with_attachment(), transmit_response_with_sdp(), update_call_counter(), update_peer(), update_registry(), and write_media_frame().

#define ast_test_flag_nonstd p,
flag   )     ((p)->flags & (flag))
 

Definition at line 119 of file utils.h.

Referenced by cache_save_hint(), and dundi_precache_thread().

#define ast_vasprintf ret,
fmt,
ap   )     _ast_vasprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, (fmt), (ap))
 

#define inet_ntoa   __dont__use__inet_ntoa__use__ast_inet_ntoa__instead__
 

Definition at line 236 of file utils.h.

#define MALLOC_FAILURE_MSG   ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file);
 

Definition at line 316 of file utils.h.


Function Documentation

int ast_base64decode unsigned char *  dst,
const char *  src,
int  max
 

decode BASE64 encoded text

Definition at line 326 of file utils.c.

Referenced by __ast_check_signature().

00327 {
00328    int cnt = 0;
00329    unsigned int byte = 0;
00330    unsigned int bits = 0;
00331    int incnt = 0;
00332    while (*src && (cnt < max)) {
00333       /* Shift in 6 bits of input */
00334       byte <<= 6;
00335       byte |= (b2a[(int)(*src)]) & 0x3f;
00336       bits += 6;
00337       src++;
00338       incnt++;
00339       /* If we have at least 8 bits left over, take that character 
00340          off the top */
00341       if (bits >= 8)  {
00342          bits -= 8;
00343          *dst = (byte >> bits) & 0xff;
00344          dst++;
00345          cnt++;
00346       }
00347    }
00348    /* Dont worry about left over bits, they're extra anyway */
00349    return cnt;
00350 }

int ast_base64encode char *  dst,
const unsigned char *  src,
int  srclen,
int  max
 

Definition at line 404 of file utils.c.

References ast_base64encode_full().

Referenced by __ast_sign(), aji_act_hook(), and build_secret().

00405 {
00406    return ast_base64encode_full(dst, src, srclen, max, 0);
00407 }

int ast_base64encode_full char *  dst,
const unsigned char *  src,
int  srclen,
int  max,
int  linebreaks
 

encode text to BASE64 coding

Definition at line 353 of file utils.c.

Referenced by ast_base64encode().

00354 {
00355    int cnt = 0;
00356    int col = 0;
00357    unsigned int byte = 0;
00358    int bits = 0;
00359    int cntin = 0;
00360    /* Reserve space for null byte at end of string */
00361    max--;
00362    while ((cntin < srclen) && (cnt < max)) {
00363       byte <<= 8;
00364       byte |= *(src++);
00365       bits += 8;
00366       cntin++;
00367       if ((bits == 24) && (cnt + 4 <= max)) {
00368          *dst++ = base64[(byte >> 18) & 0x3f];
00369          *dst++ = base64[(byte >> 12) & 0x3f];
00370          *dst++ = base64[(byte >> 6) & 0x3f];
00371          *dst++ = base64[byte & 0x3f];
00372          cnt += 4;
00373          col += 4;
00374          bits = 0;
00375          byte = 0;
00376       }
00377       if (linebreaks && (cnt < max) && (col == 64)) {
00378          *dst++ = '\n';
00379          cnt++;
00380          col = 0;
00381       }
00382    }
00383    if (bits && (cnt + 4 <= max)) {
00384       /* Add one last character for the remaining bits, 
00385          padding the rest with 0 */
00386       byte <<= 24 - bits;
00387       *dst++ = base64[(byte >> 18) & 0x3f];
00388       *dst++ = base64[(byte >> 12) & 0x3f];
00389       if (bits == 16)
00390          *dst++ = base64[(byte >> 6) & 0x3f];
00391       else
00392          *dst++ = '=';
00393       *dst++ = '=';
00394       cnt += 4;
00395    }
00396    if (linebreaks && (cnt < max)) {
00397       *dst++ = '\n';
00398       cnt++;
00399    }
00400    *dst = '\0';
00401    return cnt;
00402 }

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.

Note:
The code assumes that the file descriptor has NONBLOCK set, so there is only one system call made to do a write, unless we actually have a need to wait. This way, we get better performance. If the descriptor is blocking, all assumptions on the guaranteed detail do not apply anymore. Also note that in the current implementation, the delay is per-write, so you still have no guarantees, anyways. Fortunately the routine is only used in a few places (cli.c, manager.c, res_agi.c) so it is reasonably easy to check how it behaves there.
XXX We either need to fix the code, or fix the documentation.

Definition at line 622 of file utils.c.

References pollfd::events, pollfd::fd, poll(), and POLLOUT.

Referenced by agi_debug_cli(), and ast_cli().

00623 {
00624    /* Try to write string, but wait no more than ms milliseconds
00625       before timing out */
00626    int res = 0;
00627    struct pollfd fds[1];
00628    while (len) {
00629       res = write(fd, s, len);
00630       if ((res < 0) && (errno != EAGAIN)) {
00631          return -1;
00632       }
00633       if (res < 0)
00634          res = 0;
00635       len -= res;
00636       s += res;
00637       res = 0;
00638       if (len) {
00639          fds[0].fd = fd;
00640          fds[0].events = POLLOUT;
00641          /* Wait until writable again */
00642          res = poll(fds, 1, timeoutms);
00643          if (res < 1)
00644             return -1;
00645       }
00646    }
00647    return res;
00648 }

struct hostent* ast_gethostbyname const char *  host,
struct ast_hostent hp
 

Re-entrant (thread safe) version of gethostbyname that replaces the standard gethostbyname (which is not thread safe).

Definition at line 182 of file utils.c.

References gethostbyname_r(), hp, and s.

Referenced by ast_dnsmgr_lookup(), ast_find_ourip(), ast_get_ip_or_srv(), ast_sip_ouraddrfor(), check_via(), create_addr(), dnsmgr_refresh(), gtalk_load_config(), gtalk_update_stun(), iax_template_parse(), init_manager(), jingle_update_stun(), launch_netscript(), parse_register_contact(), process_sdp(), reload_config(), rtcp_do_debug_ip(), rtp_do_debug_ip(), set_address_from_contact(), set_config(), set_destination(), sip_devicestate(), sip_do_debug_ip(), sip_ouraddrfor(), and udptl_do_debug_ip().

00183 {
00184    int res;
00185    int herrno;
00186    int dots=0;
00187    const char *s;
00188    struct hostent *result = NULL;
00189    /* Although it is perfectly legitimate to lookup a pure integer, for
00190       the sake of the sanity of people who like to name their peers as
00191       integers, we break with tradition and refuse to look up a
00192       pure integer */
00193    s = host;
00194    res = 0;
00195    while (s && *s) {
00196       if (*s == '.')
00197          dots++;
00198       else if (!isdigit(*s))
00199          break;
00200       s++;
00201    }
00202    if (!s || !*s) {
00203       /* Forge a reply for IP's to avoid octal IP's being interpreted as octal */
00204       if (dots != 3)
00205          return NULL;
00206       memset(hp, 0, sizeof(struct ast_hostent));
00207       hp->hp.h_addrtype = AF_INET;
00208       hp->hp.h_addr_list = (void *) hp->buf;
00209       hp->hp.h_addr = hp->buf + sizeof(void *);
00210       if (inet_pton(AF_INET, host, hp->hp.h_addr) > 0)
00211          return &hp->hp;
00212       return NULL;
00213       
00214    }
00215 #ifdef SOLARIS
00216    result = gethostbyname_r(host, &hp->hp, hp->buf, sizeof(hp->buf), &herrno);
00217 
00218    if (!result || !hp->hp.h_addr_list || !hp->hp.h_addr_list[0])
00219       return NULL;
00220 #else
00221    res = gethostbyname_r(host, &hp->hp, hp->buf, sizeof(hp->buf), &result, &herrno);
00222 
00223    if (res || !result || !hp->hp.h_addr_list || !hp->hp.h_addr_list[0])
00224       return NULL;
00225 #endif
00226    return &hp->hp;
00227 }

const char* ast_inet_ntoa struct in_addr  ia  ) 
 

thread-safe replacement for inet_ntoa().

Note:
It is very important to note that even though this is a thread-safe replacement for inet_ntoa(), it is *not* reentrant. In a single thread, the result from a previous call to this function is no longer valid once it is called again. If the result from multiple calls to this function need to be kept or used at once, then the result must be copied to a local buffer before calling this function again.

Definition at line 493 of file utils.c.

Referenced by __attempt_transmit(), __iax2_show_peers(), __sip_show_channels(), __sip_xmit(), _sip_show_device(), _sip_show_devices(), _sip_show_peer(), _sip_show_peers(), action_login(), add_sdp(), add_t38_sdp(), ast_apply_ha(), ast_netsock_bindaddr(), ast_rtcp_read(), ast_rtcp_write_rr(), ast_rtcp_write_sr(), ast_rtp_raw_write(), ast_rtp_read(), ast_rtp_sendcng(), ast_rtp_senddigit_begin(), ast_rtp_senddigit_continuation(), ast_rtp_senddigit_end(), ast_sip_ouraddrfor(), ast_udptl_read(), ast_udptl_write(), authenticate(), bridge_p2p_rtp_write(), build_callid_pvt(), build_callid_registry(), build_contact(), build_reply_digest(), build_rpid(), build_via(), check_access(), check_peer_ok(), check_user_full(), check_via(), copy_via_headers(), create_addr_from_peer(), dnsmgr_refresh(), dump_addr(), dump_ipaddr(), dundi_rexmit(), dundi_show_peer(), dundi_show_peers(), dundi_show_trans(), dundi_showframe(), dundi_xmit(), external_rtp_create(), find_command(), find_peer(), find_subchannel_and_lock(), find_tpeer(), function_iaxpeer(), function_sipchaninfo_read(), function_sippeer(), handle_command_response(), handle_error(), handle_open_receive_channel_ack_message(), handle_request(), handle_request_bye(), handle_request_register(), handle_request_subscribe(), handle_response(), handle_response_bye(), handle_response_refer(), handle_show_http(), handle_showmanconn(), httpstatus_callback(), iax2_ack_registry(), iax2_prov_app(), iax2_show_peer(), iax2_show_registry(), iax2_trunk_queue(), iax_server(), iax_showframe(), load_module(), mgcp_show_endpoints(), mgcpsock_read(), oh323_addrcmp_str(), oh323_call(), oh323_set_rtp_peer(), parse_register_contact(), process_rfc3389(), process_sdp(), purge_sessions(), raw_hangup(), realtime_peer(), realtime_update_peer(), reg_source_db(), register_verify(), registry_rerequest(), reload_config(), resend_response(), retrans_pkt(), rtcp_do_debug_ip(), rtp_do_debug_ip(), send_dtmf(), send_packet(), send_request(), send_response(), send_trunk(), server_start(), set_config(), set_destination(), setup_incoming_call(), sip_do_debug_device(), sip_do_debug_ip(), sip_do_debug_peer(), sip_handle_t38_reinvite(), sip_ouraddrfor(), sip_poke_peer(), sip_set_rtp_peer(), sip_set_udptl_peer(), sip_show_channel(), sip_show_settings(), sipsock_read(), sipsocket_open(), skinny_session(), socket_process(), socket_process_meta(), timing_read(), transmit_notify_with_mwi(), udptl_do_debug_ip(), and update_registry().

00494 {
00495    char *buf;
00496 
00497    if (!(buf = ast_threadstorage_get(&inet_ntoa_buf, INET_ADDRSTRLEN)))
00498       return "";
00499 
00500    return inet_ntop(AF_INET, &ia, buf, INET_ADDRSTRLEN);
00501 }

AST_INLINE_API void *attribute_malloc   _ast_malloc(size_t len, const char *file, int lineno, const char *func)  ) 
 

A wrapper for calloc().

ast_calloc() is a wrapper for calloc() that will generate an Asterisk log message in the case that the allocation fails.

The arguments and return value are the same as calloc()

void ast_md5_hash char *  output,
char *  input
 

Produce 32 char MD5 hash of value.

Definition at line 292 of file utils.c.

References MD5Final(), MD5Init(), and MD5Update().

Referenced by build_reply_digest().

00293 {
00294    struct MD5Context md5;
00295    unsigned char digest[16];
00296    char *ptr;
00297    int x;
00298 
00299    MD5Init(&md5);
00300    MD5Update(&md5, (unsigned char *)input, strlen(input));
00301    MD5Final(digest, &md5);
00302    ptr = output;
00303    for (x = 0; x < 16; x++)
00304       ptr += sprintf(ptr, "%2.2x", digest[x]);
00305 }

char* ast_process_quotes_and_slashes char *  start,
char  find,
char  replace_with
 

Process a string to find and replace characters.

Parameters:
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 797 of file utils.c.

Referenced by handle_context_add_extension().

00798 {
00799    char *dataPut = start;
00800    int inEscape = 0;
00801    int inQuotes = 0;
00802 
00803    for (; *start; start++) {
00804       if (inEscape) {
00805          *dataPut++ = *start;       /* Always goes verbatim */
00806          inEscape = 0;
00807       } else {
00808          if (*start == '\\') {
00809             inEscape = 1;      /* Do not copy \ into the data */
00810          } else if (*start == '\'') {
00811             inQuotes = 1 - inQuotes;   /* Do not copy ' into the data */
00812          } else {
00813             /* Replace , with |, unless in quotes */
00814             *dataPut++ = inQuotes ? *start : ((*start == find) ? replace_with : *start);
00815          }
00816       }
00817    }
00818    if (start != dataPut)
00819       *dataPut = 0;
00820    return dataPut;
00821 }

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 553 of file utils.c.

References asprintf, ast_log(), ast_malloc, AST_STACKSIZE, dummy_start(), LOG_WARNING, and pthread_create.

00556 {
00557 #if !defined(LOW_MEMORY)
00558    struct thr_arg *a;
00559 #endif
00560 
00561    if (!attr) {
00562       attr = alloca(sizeof(*attr));
00563       pthread_attr_init(attr);
00564    }
00565 
00566 #ifdef __linux__
00567    /* On Linux, pthread_attr_init() defaults to PTHREAD_EXPLICIT_SCHED,
00568       which is kind of useless. Change this here to
00569       PTHREAD_INHERIT_SCHED; that way the -p option to set realtime
00570       priority will propagate down to new threads by default.
00571       This does mean that callers cannot set a different priority using
00572       PTHREAD_EXPLICIT_SCHED in the attr argument; instead they must set
00573       the priority afterwards with pthread_setschedparam(). */
00574    if ((errno = pthread_attr_setinheritsched(attr, PTHREAD_INHERIT_SCHED)))
00575       ast_log(LOG_WARNING, "pthread_attr_setinheritsched: %s\n", strerror(errno));
00576 #endif
00577 
00578    if (!stacksize)
00579       stacksize = AST_STACKSIZE;
00580 
00581    if ((errno = pthread_attr_setstacksize(attr, stacksize ? stacksize : AST_STACKSIZE)))
00582       ast_log(LOG_WARNING, "pthread_attr_setstacksize: %s\n", strerror(errno));
00583 
00584 #if !defined(LOW_MEMORY)
00585    if ((a = ast_malloc(sizeof(*a)))) {
00586       a->start_routine = start_routine;
00587       a->data = data;
00588       start_routine = dummy_start;
00589       asprintf(&a->name, "%-20s started at [%5d] %s %s()",
00590           start_fn, line, file, caller);
00591       data = a;
00592    }
00593 #endif /* !LOW_MEMORY */
00594 
00595    return pthread_create(thread, attr, start_routine, data); /* We're in ast_pthread_create, so it's okay */
00596 }

long int ast_random void   ) 
 

Definition at line 787 of file utils.c.

References ast_mutex_lock(), and ast_mutex_unlock().

Referenced by action_challenge(), agent_new(), ast_lock_path(), ast_rtp_new_init(), ast_rtp_new_with_bindaddr(), authenticate_request(), build_gateway(), build_iv(), build_reply_digest(), calc_rxstamp(), check_auth(), generate_random_string(), get_trans_id(), gtalk_alloc(), gtalk_new(), iax2_start_transfer(), jingle_alloc(), jingle_new(), local_new(), make_our_tag(), moh_files_alloc(), ourdialogbranch(), reg_source_db(), registry_authrequest(), reqprep(), sip_alloc(), socket_read(), start_rtp(), stun_req_id(), transmit_fake_auth_response(), transmit_invite(), transmit_register(), transmit_response_using_temp(), try_firmware(), and zt_new().

00788 {
00789    long int res;
00790    ast_mutex_lock(&randomlock);
00791    res = random();
00792    ast_mutex_unlock(&randomlock);
00793    return res;
00794 }

void ast_register_thread char *  name  ) 
 

Definition at line 298 of file asterisk.c.

References ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, and AST_LIST_UNLOCK.

Referenced by dummy_start().

00299 { 
00300    struct thread_list_t *new = ast_calloc(1, sizeof(*new));
00301 
00302    if (!new)
00303       return;
00304    new->id = pthread_self();
00305    new->name = name; /* steal the allocated memory for the thread name */
00306    AST_LIST_LOCK(&thread_list);
00307    AST_LIST_INSERT_HEAD(&thread_list, new, list);
00308    AST_LIST_UNLOCK(&thread_list);
00309 }

void ast_sha1_hash char *  output,
char *  input
 

Produce 40 char SHA1 hash of value.

Definition at line 308 of file utils.c.

References SHA1Input(), SHA1Reset(), and SHA1Result().

Referenced by aji_act_hook(), and jabber_make_auth().

00309 {
00310    struct SHA1Context sha;
00311    char *ptr;
00312    int x;
00313    uint8_t Message_Digest[20];
00314 
00315    SHA1Reset(&sha);
00316    
00317    SHA1Input(&sha, (const unsigned char *) input, strlen(input));
00318 
00319    SHA1Result(&sha, Message_Digest);
00320    ptr = output;
00321    for (x = 0; x < 20; x++)
00322       ptr += sprintf(ptr, "%2.2x", Message_Digest[x]);
00323 }

static force_inline void ast_slinear_saturated_add short *  input,
short *  value
[static]
 

Definition at line 188 of file utils.h.

Referenced by ast_frame_slinear_sum().

00189 {
00190    int res;
00191 
00192    res = (int) *input + *value;
00193    if (res > 32767)
00194       *input = 32767;
00195    else if (res < -32767)
00196       *input = -32767;
00197    else
00198       *input = (short) res;
00199 }

static force_inline void ast_slinear_saturated_divide short *  input,
short *  value
[static]
 

Definition at line 214 of file utils.h.

00215 {
00216    *input /= *value;
00217 }

static force_inline void ast_slinear_saturated_multiply short *  input,
short *  value
[static]
 

Definition at line 201 of file utils.h.

Referenced by ast_frame_adjust_volume().

00202 {
00203    int res;
00204 
00205    res = (int) *input * *value;
00206    if (res > 32767)
00207       *input = 32767;
00208    else if (res < -32767)
00209       *input = -32767;
00210    else
00211       *input = (short) res;
00212 }

void ast_unregister_thread void *  id  ) 
 

Definition at line 311 of file asterisk.c.

References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, and free.

Referenced by dummy_start().

00312 {
00313    struct thread_list_t *x;
00314 
00315    AST_LIST_LOCK(&thread_list);
00316    AST_LIST_TRAVERSE_SAFE_BEGIN(&thread_list, x, list) {
00317       if ((void *) x->id == id) {
00318          AST_LIST_REMOVE_CURRENT(&thread_list, list);
00319          break;
00320       }
00321    }
00322    AST_LIST_TRAVERSE_SAFE_END;
00323    AST_LIST_UNLOCK(&thread_list);
00324    if (x) {
00325       free(x->name);
00326       free(x);
00327    }
00328 }

void ast_uri_decode char *  s  ) 
 

Decode URI, URN, URL (overwrite string).

Parameters:
s String to be decoded

Definition at line 476 of file utils.c.

Referenced by check_user_full(), get_also_info(), get_destination(), get_refer_info(), handle_request_invite(), handle_uri(), register_verify(), and uri_decode().

00477 {
00478    char *o;
00479    unsigned int tmp;
00480 
00481    for (o = s; *s; s++, o++) {
00482       if (*s == '%' && strlen(s) > 2 && sscanf(s + 1, "%2x", &tmp) == 1) {
00483          /* have '%', two chars and correct parsing */
00484          *o = tmp;
00485          s += 2;  /* Will be incremented once more when we break out */
00486       } else /* all other cases, just copy */
00487          *o = *s;
00488    }
00489    *o = '\0';
00490 }

char* ast_uri_encode const char *  string,
char *  outbuf,
int  buflen,
int  doreserved
 

Turn text string to URI-encoded XX version At this point, we're converting from ISO-8859-x (8-bit), not UTF8 as in the SIP protocol spec If doreserved == 1 we will convert reserved characters also. RFC 2396, section 2.4 outbuf needs to have more memory allocated than the instring to have room for the expansion. Every char that is converted is replaced by three ASCII characters.

Note:
At this point, we're converting from ISO-8859-x (8-bit), not UTF8 as in the SIP protocol spec If doreserved == 1 we will convert reserved characters also. RFC 2396, section 2.4 outbuf needs to have more memory allocated than the instring to have room for the expansion. Every char that is converted is replaced by three ASCII characters.
Note: The doreserved option is needed for replaces header in SIP transfers.

Definition at line 445 of file utils.c.

Referenced by handle_request_refer().

00446 {
00447    char *reserved = ";/?:@&=+$, ";  /* Reserved chars */
00448 
00449    const char *ptr  = string; /* Start with the string */
00450    char *out = NULL;
00451    char *buf = NULL;
00452 
00453    ast_copy_string(outbuf, string, buflen);
00454 
00455    /* If there's no characters to convert, just go through and don't do anything */
00456    while (*ptr) {
00457       if (((unsigned char) *ptr) > 127 || (doreserved && strchr(reserved, *ptr)) ) {
00458          /* Oops, we need to start working here */
00459          if (!buf) {
00460             buf = outbuf;
00461             out = buf + (ptr - string) ;  /* Set output ptr */
00462          }
00463          out += sprintf(out, "%%%02x", (unsigned char) *ptr);
00464       } else if (buf) {
00465          *out = *ptr;   /* Continue copying the string */
00466          out++;
00467       } 
00468       ptr++;
00469    }
00470    if (buf)
00471       *out = '\0';
00472    return outbuf;
00473 }

int ast_utils_init void   ) 
 

Definition at line 503 of file utils.c.

References base64_init().

00504 {
00505    base64_init();
00506    return 0;
00507 }

int ast_wait_for_input int  fd,
int  ms
 

Definition at line 598 of file utils.c.

References poll(), POLLIN, and POLLPRI.

Referenced by action_waitevent(), ast_moh_destroy(), and server_root().

00599 {
00600    struct pollfd pfd[1];
00601    memset(pfd, 0, sizeof(pfd));
00602    pfd[0].fd = fd;
00603    pfd[0].events = POLLIN|POLLPRI;
00604    return poll(pfd, 1, ms);
00605 }

static force_inline int inaddrcmp const struct sockaddr_in *  sin1,
const struct sockaddr_in *  sin2
[static]
 

Compares the source address and port of two sockaddr_in

Definition at line 253 of file utils.h.

Referenced by ast_netsock_find(), find_tpeer(), find_transaction(), handle_command_response(), iax2_ack_registry(), oh323_addrcmp(), parse_register_contact(), register_verify(), registry_rerequest(), sip_addrcmp(), socket_process(), and update_registry().

00254 {
00255    return ((sin1->sin_addr.s_addr != sin2->sin_addr.s_addr) 
00256       || (sin1->sin_port != sin2->sin_port));
00257 }

int test_for_thread_safety void   ) 
 

Definition at line 263 of file utils.c.

References ast_mutex_lock(), ast_mutex_unlock(), ast_pthread_create, and test_thread_body().

00264 { 
00265    ast_mutex_lock(&test_lock2);
00266    ast_mutex_lock(&test_lock);
00267    lock_count += 1;
00268    ast_mutex_lock(&test_lock);
00269    lock_count += 1;
00270    ast_pthread_create(&test_thread, NULL, test_thread_body, NULL); 
00271    usleep(100);
00272    if (lock_count != 2) 
00273       test_errors++;
00274    ast_mutex_unlock(&test_lock);
00275    lock_count -= 1;
00276    usleep(100); 
00277    if (lock_count != 1) 
00278       test_errors++;
00279    ast_mutex_unlock(&test_lock);
00280    lock_count -= 1;
00281    if (lock_count != 0) 
00282       test_errors++;
00283    ast_mutex_unlock(&test_lock2);
00284    usleep(100);
00285    if (lock_count != 0) 
00286       test_errors++;
00287    pthread_join(test_thread, NULL);
00288    return(test_errors);          /* return 0 on success. */
00289 }


Variable Documentation

unsigned int __unsigned_int_flags_dummy
 

Note:
   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.
 

size_t const char* file
 

Definition at line 353 of file utils.h.

size_t const char int const char* func
 

Definition at line 353 of file utils.h.

size_t len
 

Definition at line 353 of file utils.h.

Referenced by __get_header(), _parse(), add_sdp(), add_t38_sdp(), aji_act_hook(), alsa_write(), ast_cdr_appenduserfield(), ast_cli_complete(), ast_codec_get_len(), ast_dsp_digitdetect(), ast_dsp_process(), ast_dsp_silence(), ast_feature_request_and_dial(), ast_frdup(), ast_getformatname_multiple(), ast_http_uri_link(), ast_read_image(), ast_rtcp_read(), ast_rtcp_write_rr(), ast_rtcp_write_sr(), ast_rtp_lookup_mime_multiple(), ast_rtp_read(), ast_smoother_read(), ast_translate(), ast_udptl_read(), ast_udptl_write(), build_route(), builtin_automonitor(), callerid_generate(), cli_complete(), complete_agent_logoff_cmd(), complete_context_add_extension(), complete_context_add_ignorepat(), complete_context_add_include(), complete_context_remove_extension(), complete_context_remove_ignorepat(), complete_context_remove_include(), complete_peer_helper(), config_jitterbuffer(), copy(), dundi_encrypt(), dundi_parse_ies(), dundi_send(), expr2_token_subst(), get_body(), get_sdp(), get_sdp_iterate(), handle_commandmatchesarray(), handle_request(), handle_response(), iax_parse_ies(), iax_str2flags(), listener(), local_call(), method_match(), mgcp_ss(), mgcpsock_read(), misdn_read(), monmp3thread(), newpvt(), parse_ie(), pbx_substitute_variables_helper_full(), process_sdp(), reschedule_precache(), schedule_delivery(), send_string(), sip_show_channel(), sip_show_history(), sipsock_read(), skinny_ss(), socket_process_meta(), socket_read(), ss_thread(), static_callback(), strndup(), strnlen(), term_filter_escapes(), transmit_message_with_text(), try_firmware(), udptl_build_packet(), vmwi_generate(), and zt_setoption().

size_t const char int lineno
 

Definition at line 353 of file utils.h.

Referenced by action_getconfig(), apply_outgoing(), and config_text_file_load().


Asterisk is a trademark for Digium, inc.. | Edvina.net | Asterisk.org | This documentation was generated with Doxygen