#include "asterisk/compat.h"
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <limits.h>
#include "asterisk/lock.h"
#include "asterisk/time.h"
#include "asterisk/strings.h"
Go to the source code of this file.
Data Structures | |
struct | ast_flags |
struct | ast_hostent |
Defines | |
#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_pthread_create(a, b, c, d) ast_pthread_create_stack(a,b,c,d,0) |
#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_STACKSIZE 256 * 1024 |
#define | ast_test_flag(p, flag) |
#define | ast_test_flag_nonstd(p, flag) |
#define | inet_ntoa __dont__use__inet_ntoa__use__ast_inet_ntoa__instead__ |
Functions | |
int | ast_base64decode (unsigned char *dst, const char *src, int max) |
int | ast_base64encode (char *dst, const unsigned char *src, int srclen, int max) |
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 (char *buf, int bufsiz, struct in_addr ia) |
ast_inet_ntoa: Recursive thread safe replacement of inet_ntoa | |
void | ast_md5_hash (char *output, char *input) |
ast_md5_hash: Produce 16 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) |
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_uri_decode (char *s) |
Decode URI, URN, URL (overwrite string). | |
char * | ast_uri_encode (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) |
int | getloadavg (double *list, int nelem) |
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 |
Definition in file utils.h.
#define ast_clear_flag | ( | p, | |||
flag | ) |
Definition at line 76 of file utils.h.
Referenced by ast_app_parse_options(), ast_bridge_call(), ast_cdr_reset(), ast_channel_bridge(), ast_channel_spy_add(), ast_channel_spy_read_frame(), ast_channel_undefer_dtmf(), ast_deactivate_generator(), ast_read(), ast_sendtext(), ast_waitfor_nandfds(), ast_write(), authenticate_verify(), build_peer(), build_user(), builtin_atxfer(), chanspy_exec(), check_goto_on_transfer(), check_pendings(), create_addr(), dictate_exec(), do_parking_thread(), dundi_lookup_local(), find_conf(), forward_message(), handle_common_options(), handle_request_invite(), handle_request_subscribe(), linear_alloc(), local_ast_moh_stop(), phone_read(), playtones_alloc(), process_sdp(), queue_frame_to_spies(), register_verify(), reload_config(), reset_transaction(), set_config_flags(), sip_dtmfmode(), sip_hangup(), socket_read(), wait_for_answer(), and zt_read().
#define ast_clear_flag_nonstd | ( | p, | |||
flag | ) |
Value:
do { \ ((p)->flags &= ~(flag)); \ } while(0)
Definition at line 114 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 83 of file utils.h.
Referenced by agent_read(), ast_cdr_reset(), ast_feature_interpret(), build_peer(), build_user(), cache_lookup_internal(), check_access(), check_user_full(), create_addr(), create_addr_from_peer(), dial_exec_full(), dundi_lookup_local(), find_callno(), iax2_request(), populate_defaults(), realtime_peer(), register_verify(), sip_alloc(), sip_poke_peer(), temp_peer(), vm_exec(), and wait_for_answer().
#define ast_copy_flags_nonstd | ( | dest, | |||
src, | |||||
flagz | ) |
#define AST_FLAGS_ALL UINT_MAX |
Definition at line 130 of file utils.h.
Referenced by ast_app_parse_options(), ast_cdr_reset(), ast_feature_interpret(), builtin_atxfer(), cache_lookup_internal(), check_goto_on_transfer(), dundi_lookup_local(), populate_defaults(), reload_config(), and set_config_flags().
#define ast_pthread_create | ( | a, | |||
b, | |||||
c, | |||||
d | ) | ast_pthread_create_stack(a,b,c,d,0) |
Definition at line 223 of file utils.h.
Referenced by accept_thread(), action_originate(), ast_autoservice_start(), ast_bridge_call_thread_launch(), ast_cdr_submit_batch(), ast_device_state_engine_init(), ast_makesocket(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_pbx_start(), conf_run(), do_reload(), dundi_answer_entity(), dundi_answer_query(), function_autopatchup(), handle_hd_hf(), handle_init_event(), handle_message(), iax_park(), init_manager(), launch_monitor_thread(), launch_page(), launch_service(), listener(), load_module(), moh_register(), reload_config(), restart_monitor(), rpt(), rpt_master(), rpt_telemetry(), show_console(), sip_park(), spawn_dp_lookup(), start_network_thread(), statechange_queue(), test_for_thread_safety(), vpb_answer(), and zt_handle_event().
#define ast_set2_flag | ( | p, | |||
value, | |||||
flag | ) |
Definition at line 93 of file utils.h.
Referenced by apply_option(), build_peer(), build_user(), check_access(), dial_exec_full(), find_user(), forkcdr_exec(), handle_common_options(), load_config(), load_moh_classes(), macro_exec(), reload_config(), and set_config().
#define ast_set_flag | ( | p, | |||
flag | ) |
Definition at line 69 of file utils.h.
Referenced by __ast_pbx_run(), __sip_reliable_xmit(), apply_peer(), ast_app_parse_options(), ast_cdr_detach(), ast_cdr_fork(), ast_cdr_reset(), ast_channel_bridge(), ast_channel_defer_dtmf(), ast_channel_spy_add(), ast_hangup(), ast_rtp_raw_write(), ast_rtp_read(), ast_waitfor_nandfds(), authenticate_reply(), authenticate_request(), build_peer(), build_user(), builtin_atxfer(), channel_spy(), chanspy_exec(), check_access(), check_availability(), check_user_full(), check_via(), conf_exec(), create_addr_from_peer(), create_transaction(), decrypt_frame(), delete_users(), dial_exec_full(), dictate_exec(), do_parking_thread(), do_register(), dundi_encrypt(), dundi_lookup_local(), dundi_send(), expire_registry(), find_call(), find_user_realtime(), handle_common_options(), handle_request(), handle_request_bye(), handle_request_cancel(), handle_request_info(), handle_request_invite(), handle_request_options(), handle_request_refer(), handle_request_subscribe(), handle_response(), handle_response_invite(), handle_response_peerpoke(), handle_response_register(), iax2_destroy(), iax2_predestroy(), iax2_provision(), iax2_prune_realtime(), launch_monitor_thread(), leave_voicemail(), linear_alloc(), load_config(), local_ast_moh_start(), macro_exec(), moh_register(), park_exec(), playtones_alloc(), post_cdr(), process_rfc3389(), process_sdp(), qualify_peer(), queue_frame_to_spies(), realtime_peer(), realtime_user(), receive_message(), register_verify(), reload_config(), retrans_pkt(), set_config(), set_config_flags(), sip_call(), sip_dtmfmode(), sip_hangup(), sip_indicate(), sip_poke_peer(), sip_reg_timeout(), sip_send_mwi_to_peer(), sip_set_rtp_peer(), sip_sipredirect(), sip_write(), sipsock_read(), socket_read(), temp_peer(), tonepair_alloc(), transmit_register(), transmit_reinvite_with_sdp(), try_calling(), update_call_counter(), vm_exec(), vm_execmain(), and zt_read().
#define ast_set_flag_nonstd | ( | p, | |||
flag | ) |
Value:
do { \ ((p)->flags |= (flag)); \ } while(0)
Definition at line 110 of file utils.h.
Referenced by dundi_lookup_internal(), dundi_query_eid_internal(), and handle_command_response().
#define AST_STACKSIZE 256 * 1024 |
#define ast_test_flag | ( | p, | |||
flag | ) |
Definition at line 62 of file utils.h.
Referenced by __ast_pbx_run(), __do_deliver(), __iax2_show_peers(), __sip_ack(), __sip_pretend_ack(), __sip_semi_ack(), __sip_show_channels(), __sip_xmit(), _sip_show_peer(), _sip_show_peers(), add_sdp(), agent_new(), app_exec(), ast_answer(), ast_autoservice_stop(), ast_call(), ast_cdr_answer(), ast_cdr_appenduserfield(), ast_cdr_busy(), ast_cdr_end(), ast_cdr_failed(), ast_cdr_fork(), 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(), ast_moh_files_next(), ast_queue_frame(), ast_read(), ast_readstring(), ast_readstring_full(), ast_rtp_bridge(), ast_rtp_raw_write(), ast_sendtext(), ast_serialize_showchan(), ast_softhangup_nolock(), ast_transfer(), ast_waitfordigit(), ast_waitfordigit_full(), ast_write(), authenticate_reply(), authenticate_request(), authenticate_verify(), build_peer(), build_user(), build_via(), chanspy_exec(), check_access(), check_auth(), check_pendings(), check_user_full(), check_via(), complete_sip_peer(), complete_sip_user(), conf_exec(), construct_rr(), copy_via_headers(), create_addr(), create_addr_from_peer(), decrypt_frame(), destroy_association(), destroy_trans(), dial_exec_full(), dictate_exec(), do_monitor(), dundi_encrypt(), dundi_exec(), dundi_helper(), dundi_lookup_exec(), dundi_lookup_local(), dundi_lookup_thread(), dundi_precache_thread(), dundi_query_thread(), dundi_rexmit(), dundi_send(), dundifunc_read(), expire_register(), expire_registry(), feature_exec_app(), find_cache(), find_conf(), find_user(), find_user_realtime(), forward_message(), free_user(), function_iaxpeer(), function_sippeer(), get_from_jb(), handle_command_response(), handle_frame(), handle_request(), handle_request_bye(), handle_request_info(), handle_request_invite(), handle_request_subscribe(), handle_response(), handle_response_invite(), handle_showchan(), iax2_call(), iax2_destroy(), 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(), initreqprep(), launch_monitor_thread(), leave_voicemail(), macro_exec(), mixmonitor_exec(), mixmonitor_thread(), moh_classes_show(), moh_on_off(), notify_new_message(), page_exec(), parse_moved_contact(), parse_ok_contact(), parse_register_contact(), pbx_builtin_background(), pbx_builtin_waitexten(), play_message(), play_record_review(), post_cdr(), precache_transactions(), process_rfc3389(), process_sdp(), prune_users(), queue_frame_to_spies(), realtime_peer(), realtime_user(), reg_source_db(), register_verify(), registry_authrequest(), reqprep(), respprep(), retrans_pkt(), retrydial_exec(), send_request(), send_response(), send_trunk(), sendmail(), set_config(), set_config_flags(), sip_addrcmp(), sip_alloc(), sip_debug_test_pvt(), sip_destroy_peer(), sip_destroy_user(), sip_dtmfmode(), sip_get_rtp_peer(), sip_get_vrtp_peer(), sip_hangup(), sip_indicate(), sip_new(), sip_prune_realtime(), sip_rtp_read(), sip_senddigit(), sip_set_rtp_peer(), sip_show_channel(), sip_show_settings(), sip_show_users(), sip_write(), sipsock_read(), socket_read(), spawn_mp3(), spy_detach(), start_spying(), startmon(), transmit_refer(), transmit_reinvite_with_sdp(), try_calling(), update_call_counter(), update_peer(), update_registry(), vm_exec(), vm_execmain(), vm_newuser(), and wait_for_answer().
#define ast_test_flag_nonstd | ( | p, | |||
flag | ) |
Value:
({ \ ((p)->flags & (flag)); \ })
Definition at line 106 of file utils.h.
Referenced by cache_save_hint(), dundi_lookup_thread(), dundi_precache_thread(), and handle_command_response().
#define inet_ntoa __dont__use__inet_ntoa__use__ast_inet_ntoa__instead__ |
int ast_base64decode | ( | unsigned char * | dst, | |
const char * | src, | |||
int | max | |||
) |
Definition at line 297 of file utils.c.
References MD5Context::bits.
Referenced by __ast_check_signature(), and ast_osp_validate().
00298 { 00299 int cnt = 0; 00300 unsigned int byte = 0; 00301 unsigned int bits = 0; 00302 int incnt = 0; 00303 #if 0 00304 unsigned char *odst = dst; 00305 #endif 00306 while(*src && (cnt < max)) { 00307 /* Shift in 6 bits of input */ 00308 byte <<= 6; 00309 byte |= (b2a[(int)(*src)]) & 0x3f; 00310 bits += 6; 00311 #if 0 00312 printf("Add: %c %s\n", *src, binary(b2a[(int)(*src)] & 0x3f, 6)); 00313 #endif 00314 src++; 00315 incnt++; 00316 /* If we have at least 8 bits left over, take that character 00317 off the top */ 00318 if (bits >= 8) { 00319 bits -= 8; 00320 *dst = (byte >> bits) & 0xff; 00321 #if 0 00322 printf("Remove: %02x %s\n", *dst, binary(*dst, 8)); 00323 #endif 00324 dst++; 00325 cnt++; 00326 } 00327 } 00328 #if 0 00329 dump(odst, cnt); 00330 #endif 00331 /* Dont worry about left over bits, they're extra anyway */ 00332 return cnt; 00333 }
int ast_base64encode | ( | char * | dst, | |
const unsigned char * | src, | |||
int | srclen, | |||
int | max | |||
) |
Definition at line 335 of file utils.c.
References MD5Context::bits.
Referenced by __ast_sign(), ast_osp_lookup(), ast_osp_next(), and build_secret().
00336 { 00337 int cnt = 0; 00338 unsigned int byte = 0; 00339 int bits = 0; 00340 int index; 00341 int cntin = 0; 00342 #if 0 00343 char *odst = dst; 00344 dump(src, srclen); 00345 #endif 00346 /* Reserve one bit for end */ 00347 max--; 00348 while((cntin < srclen) && (cnt < max)) { 00349 byte <<= 8; 00350 #if 0 00351 printf("Add: %02x %s\n", *src, binary(*src, 8)); 00352 #endif 00353 byte |= *(src++); 00354 bits += 8; 00355 cntin++; 00356 while((bits >= 6) && (cnt < max)) { 00357 bits -= 6; 00358 /* We want only the top */ 00359 index = (byte >> bits) & 0x3f; 00360 *dst = base64[index]; 00361 #if 0 00362 printf("Remove: %c %s\n", *dst, binary(index, 6)); 00363 #endif 00364 dst++; 00365 cnt++; 00366 } 00367 } 00368 if (bits && (cnt < max)) { 00369 /* Add one last character for the remaining bits, 00370 padding the rest with 0 */ 00371 byte <<= (6 - bits); 00372 index = (byte) & 0x3f; 00373 *(dst++) = base64[index]; 00374 cnt++; 00375 } 00376 *dst = '\0'; 00377 return cnt; 00378 }
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 173 of file utils.c.
Referenced by ast_dnsmgr_lookup(), ast_find_ourip(), ast_get_ip_or_srv(), ast_sip_ouraddrfor(), build_peer(), check_via(), create_addr(), festival_exec(), iax2_register(), iax_template_parse(), launch_netscript(), parse_ok_contact(), parse_register_contact(), process_sdp(), refresh_list(), reload_config(), rpt_exec(), rtp_do_debug_ip(), set_config(), set_destination(), sip_devicestate(), and sip_do_debug_ip().
00174 { 00175 int res; 00176 int herrno; 00177 int dots=0; 00178 const char *s; 00179 struct hostent *result = NULL; 00180 /* Although it is perfectly legitimate to lookup a pure integer, for 00181 the sake of the sanity of people who like to name their peers as 00182 integers, we break with tradition and refuse to look up a 00183 pure integer */ 00184 s = host; 00185 res = 0; 00186 while(s && *s) { 00187 if (*s == '.') 00188 dots++; 00189 else if (!isdigit(*s)) 00190 break; 00191 s++; 00192 } 00193 if (!s || !*s) { 00194 /* Forge a reply for IP's to avoid octal IP's being interpreted as octal */ 00195 if (dots != 3) 00196 return NULL; 00197 memset(hp, 0, sizeof(struct ast_hostent)); 00198 hp->hp.h_addr_list = (void *) hp->buf; 00199 hp->hp.h_addr = hp->buf + sizeof(void *); 00200 if (inet_pton(AF_INET, host, hp->hp.h_addr) > 0) 00201 return &hp->hp; 00202 return NULL; 00203 00204 } 00205 #ifdef SOLARIS 00206 result = gethostbyname_r(host, &hp->hp, hp->buf, sizeof(hp->buf), &herrno); 00207 00208 if (!result || !hp->hp.h_addr_list || !hp->hp.h_addr_list[0]) 00209 return NULL; 00210 #else 00211 res = gethostbyname_r(host, &hp->hp, hp->buf, sizeof(hp->buf), &result, &herrno); 00212 00213 if (res || !result || !hp->hp.h_addr_list || !hp->hp.h_addr_list[0]) 00214 return NULL; 00215 #endif 00216 return &hp->hp; 00217 }
const char* ast_inet_ntoa | ( | char * | buf, | |
int | bufsiz, | |||
struct in_addr | ia | |||
) |
ast_inet_ntoa: Recursive thread safe replacement of inet_ntoa
Definition at line 464 of file utils.c.
Referenced by __iax2_show_peers(), __sip_show_channels(), __sip_xmit(), _sip_show_peer(), _sip_show_peers(), add_sdp(), ast_apply_ha(), ast_netsock_bindaddr(), ast_osp_validate(), ast_rtcp_read(), ast_rtp_raw_write(), ast_rtp_read(), ast_rtp_sendcng(), ast_rtp_senddigit(), ast_sip_ouraddrfor(), attempt_transmit(), authenticate(), build_callid(), build_contact(), build_reply_digest(), build_rpid(), build_via(), check_access(), check_user_full(), check_via(), copy_via_headers(), create_addr_from_peer(), dump_addr(), dump_ipaddr(), dundi_rexmit(), dundi_show_peer(), dundi_show_trans(), dundi_showframe(), dundi_xmit(), external_rtp_create(), find_callno(), find_command(), find_peer(), find_subchannel_and_lock(), find_tpeer(), find_user(), function_iaxpeer(), function_sipchaninfo_read(), function_sippeer(), handle_command_response(), handle_error(), handle_message(), handle_request(), handle_request_bye(), handle_request_register(), handle_request_subscribe(), handle_response(), handle_showmanconn(), iax2_ack_registry(), iax2_prov_app(), iax2_show_channels(), iax2_show_peer(), iax2_show_registry(), iax2_trunk_queue(), iax_server(), iax_showframe(), initreqprep(), load_module(), mgcp_show_endpoints(), mgcpsock_read(), oh323_call(), oh323_set_rtp_peer(), parse_register_contact(), process_message(), process_rfc3389(), process_sdp(), raw_hangup(), realtime_peer(), realtime_update_peer(), reg_source_db(), register_verify(), registry_rerequest(), reload_config(), resend_response(), retrans_pkt(), rpt_exec(), rtp_do_debug_ip(), send_dtmf(), send_packet(), send_request(), send_response(), send_trunk(), set_config(), set_destination(), setup_incoming_call(), sip_do_debug_ip(), sip_do_debug_peer(), sip_new(), sip_poke_peer(), sip_set_rtp_peer(), sip_show_channel(), sip_show_settings(), sipsock_read(), skinny_session(), skinny_show_devices(), socket_read(), timing_read(), transmit_notify_with_mwi(), and update_registry().
void ast_md5_hash | ( | char * | output, | |
char * | input | |||
) |
ast_md5_hash: Produce 16 char MD5 hash of value. ---
Definition at line 282 of file utils.c.
References MD5Final(), MD5Init(), and MD5Update().
Referenced by auth_exec(), build_reply_digest(), builtin_function_checkmd5(), builtin_function_md5(), check_auth(), md5_exec(), and md5check_exec().
00283 { 00284 struct MD5Context md5; 00285 unsigned char digest[16]; 00286 char *ptr; 00287 int x; 00288 00289 MD5Init(&md5); 00290 MD5Update(&md5, (unsigned char *)input, strlen(input)); 00291 MD5Final(digest, &md5); 00292 ptr = output; 00293 for (x=0; x<16; x++) 00294 ptr += sprintf(ptr, "%2.2x", digest[x]); 00295 }
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 873 of file utils.c.
Referenced by __build_step(), handle_context_add_extension(), and pbx_load_module().
00874 { 00875 char *dataPut = start; 00876 int inEscape = 0; 00877 int inQuotes = 0; 00878 00879 for (; *start; start++) { 00880 if (inEscape) { 00881 *dataPut++ = *start; /* Always goes verbatim */ 00882 inEscape = 0; 00883 } else { 00884 if (*start == '\\') { 00885 inEscape = 1; /* Do not copy \ into the data */ 00886 } else if (*start == '\'') { 00887 inQuotes = 1-inQuotes; /* Do not copy ' into the data */ 00888 } else { 00889 /* Replace , with |, unless in quotes */ 00890 *dataPut++ = inQuotes ? *start : ((*start==find) ? replace_with : *start); 00891 } 00892 } 00893 } 00894 if (start != dataPut) 00895 *dataPut = 0; 00896 return dataPut; 00897 }
int ast_pthread_create_stack | ( | pthread_t * | thread, | |
pthread_attr_t * | attr, | |||
void *(*)(void *) | start_routine, | |||
void * | data, | |||
size_t | stacksize | |||
) |
Definition at line 479 of file utils.c.
References ast_log(), AST_STACKSIZE, LOG_WARNING, and pthread_create.
00480 { 00481 pthread_attr_t lattr; 00482 if (!attr) { 00483 pthread_attr_init(&lattr); 00484 attr = &lattr; 00485 } 00486 #ifdef __linux__ 00487 /* On Linux, pthread_attr_init() defaults to PTHREAD_EXPLICIT_SCHED, 00488 which is kind of useless. Change this here to 00489 PTHREAD_INHERIT_SCHED; that way the -p option to set realtime 00490 priority will propagate down to new threads by default. 00491 This does mean that callers cannot set a different priority using 00492 PTHREAD_EXPLICIT_SCHED in the attr argument; instead they must set 00493 the priority afterwards with pthread_setschedparam(). */ 00494 errno = pthread_attr_setinheritsched(attr, PTHREAD_INHERIT_SCHED); 00495 if (errno) 00496 ast_log(LOG_WARNING, "pthread_attr_setinheritsched returned non-zero: %s\n", strerror(errno)); 00497 #endif 00498 00499 if (!stacksize) 00500 stacksize = AST_STACKSIZE; 00501 errno = pthread_attr_setstacksize(attr, stacksize); 00502 if (errno) 00503 ast_log(LOG_WARNING, "pthread_attr_setstacksize returned non-zero: %s\n", strerror(errno)); 00504 return pthread_create(thread, attr, start_routine, data); /* We're in ast_pthread_create, so it's okay */ 00505 }
static force_inline void ast_slinear_saturated_add | ( | short * | input, | |
short * | value | |||
) | [static] |
static force_inline void ast_slinear_saturated_divide | ( | short * | input, | |
short * | value | |||
) | [static] |
Definition at line 198 of file utils.h.
Referenced by ast_frame_adjust_volume().
00199 { 00200 *input /= *value; 00201 }
static force_inline void ast_slinear_saturated_multiply | ( | short * | input, | |
short * | value | |||
) | [static] |
void ast_uri_decode | ( | char * | s | ) |
Decode URI, URN, URL (overwrite string).
s | String to be decoded |
Definition at line 447 of file utils.c.
Referenced by builtin_function_uridecode(), check_user_full(), get_destination(), get_refer_info(), and register_verify().
00448 { 00449 char *o; 00450 unsigned int tmp; 00451 00452 for (o = s; *s; s++, o++) { 00453 if (*s == '%' && strlen(s) > 2 && sscanf(s + 1, "%2x", &tmp) == 1) { 00454 /* have '%', two chars and correct parsing */ 00455 *o = tmp; 00456 s += 2; /* Will be incremented once more when we break out */ 00457 } else /* all other cases, just copy */ 00458 *o = *s; 00459 } 00460 *o = '\0'; 00461 }
char* ast_uri_encode | ( | 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.
ast_uri_encode
string | String to be converted | |
outbuf | Resulting encoded string | |
buflen | Size of output buffer | |
doreserved | Convert reserved characters |
Definition at line 416 of file utils.c.
Referenced by builtin_function_uriencode(), and initreqprep().
00417 { 00418 char *reserved = ";/?:@&=+$, "; /* Reserved chars */ 00419 00420 char *ptr = string; /* Start with the string */ 00421 char *out = NULL; 00422 char *buf = NULL; 00423 00424 strncpy(outbuf, string, buflen); 00425 00426 /* If there's no characters to convert, just go through and don't do anything */ 00427 while (*ptr) { 00428 if (((unsigned char) *ptr) > 127 || (doreserved && strchr(reserved, *ptr)) ) { 00429 /* Oops, we need to start working here */ 00430 if (!buf) { 00431 buf = outbuf; 00432 out = buf + (ptr - string) ; /* Set output ptr */ 00433 } 00434 out += sprintf(out, "%%%02x", (unsigned char) *ptr); 00435 } else if (buf) { 00436 *out = *ptr; /* Continue copying the string */ 00437 out++; 00438 } 00439 ptr++; 00440 } 00441 if (buf) 00442 *out = '\0'; 00443 return outbuf; 00444 }
int ast_utils_init | ( | void | ) |
Definition at line 469 of file utils.c.
References base64_init().
Referenced by main().
00470 { 00471 base64_init(); 00472 return 0; 00473 }
int ast_wait_for_input | ( | int | fd, | |
int | ms | |||
) |
int getloadavg | ( | double * | list, | |
int | nelem | |||
) |
Definition at line 861 of file utils.c.
Referenced by ast_readconfig(), and increase_call_count().
00862 { 00863 int i; 00864 00865 for (i = 0; i < nelem; i++) { 00866 list[i] = 0.1; 00867 } 00868 return -1; 00869 }
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 216 of file utils.h.
Referenced by ast_netsock_find(), find_peer(), find_tpeer(), find_transaction(), handle_command_response(), iax2_ack_registry(), parse_register_contact(), registry_rerequest(), sip_addrcmp(), socket_read(), and update_registry().
00217 { 00218 return ((sin1->sin_addr.s_addr != sin2->sin_addr.s_addr) 00219 || (sin1->sin_port != sin2->sin_port)); 00220 }
int test_for_thread_safety | ( | void | ) |
Definition at line 253 of file utils.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_pthread_create, and test_thread_body().
Referenced by main().
00254 { 00255 ast_mutex_lock(&test_lock2); 00256 ast_mutex_lock(&test_lock); 00257 lock_count += 1; 00258 ast_mutex_lock(&test_lock); 00259 lock_count += 1; 00260 ast_pthread_create(&test_thread, NULL, test_thread_body, NULL); 00261 usleep(100); 00262 if (lock_count != 2) 00263 test_errors++; 00264 ast_mutex_unlock(&test_lock); 00265 lock_count -= 1; 00266 usleep(100); 00267 if (lock_count != 1) 00268 test_errors++; 00269 ast_mutex_unlock(&test_lock); 00270 lock_count -= 1; 00271 if (lock_count != 0) 00272 test_errors++; 00273 ast_mutex_unlock(&test_lock2); 00274 usleep(100); 00275 if (lock_count != 0) 00276 test_errors++; 00277 pthread_join(test_thread, NULL); 00278 return(test_errors); /* return 0 on success. */ 00279 }
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.