#include <switch.h>
Include dependency graph for switch_utils.h:
This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Data Structures | |
| union | ip_t |
Defines | |
| #define | switch_goto_status(_status, _label) status = _status; goto _label |
| #define | switch_goto_int(_n, _i, _label) _n = _i; goto _label |
| #define | switch_samples_per_packet(rate, interval) ((uint32_t)((float)rate / (1000.0f / (float)interval))) |
| #define | SWITCH_SMAX 32767 |
| #define | SWITCH_SMIN -32768 |
| #define | switch_normalize_to_16bit(n) if (n > SWITCH_SMAX) n = SWITCH_SMAX; else if (n < SWITCH_SMIN) n = SWITCH_SMIN; |
| #define | switch_codec2str(codec, buf, len) |
| #define | zstr(x) _zstr(x) |
| #define | switch_strlen_zero(x) zstr(x) |
| #define | switch_strlen_zero_buf(x) zstr_buf(x) |
| #define | zstr_buf(s) (*(s) == '\0') |
| #define | switch_arraylen(_a) (sizeof(_a) / sizeof(_a[0])) |
| #define | switch_split(_data, _delim, _array) switch_separate_string(_data, _delim, _array, switch_arraylen(_array)) |
| #define | switch_is_valid_rate(_tmp) (_tmp == 8000 || _tmp == 12000 || _tmp == 16000 || _tmp == 24000 || _tmp == 32000 || _tmp == 11025 || _tmp == 22050 || _tmp == 44100 || _tmp == 48000) |
| #define | switch_true_buf(expr) |
| #define | SWITCH_STATUS_IS_BREAK(x) (x == SWITCH_STATUS_BREAK || x == 730035 || x == 35 || x == SWITCH_STATUS_INTR) |
| #define | is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119 || key == 70 || key == 102) |
| determine if a character is a valid DTMF key | |
| #define | end_of(_s) *(*_s == '\0' ? _s : _s + strlen(_s) - 1) |
| #define | end_of_p(_s) (*_s == '\0' ? _s : _s + strlen(_s) - 1) |
| #define | switch_test_flag(obj, flag) ((obj)->flags & flag) |
| Test for the existance of a flag on an arbitary object. | |
| #define | switch_set_flag(obj, flag) (obj)->flags |= (flag) |
| Set a flag on an arbitrary object. | |
| #define | switch_set_flag_locked(obj, flag) |
| Set a flag on an arbitrary object while locked. | |
| #define | switch_clear_flag_locked(obj, flag) switch_mutex_lock(obj->flag_mutex); (obj)->flags &= ~(flag); switch_mutex_unlock(obj->flag_mutex); |
| Clear a flag on an arbitrary object. | |
| #define | switch_clear_flag(obj, flag) (obj)->flags &= ~(flag) |
| Clear a flag on an arbitrary object while locked. | |
| #define | switch_copy_flags(dest, src, flags) (dest)->flags &= ~(flags); (dest)->flags |= ((src)->flags & (flags)) |
| Copy flags from one arbitrary object to another. | |
| #define | switch_set_string(_dst, _src) switch_copy_string(_dst, _src, sizeof(_dst)) |
| #define | switch_safe_free(it) if (it) {free(it);it=NULL;} |
| Free a pointer and set it to NULL unless it already is NULL. | |
| #define | switch_str_nil(s) (s ? s : "") |
| Make a null string a blank string instead. | |
| #define | switch_yield(ms) switch_sleep(ms); |
| Wait a desired number of microseconds and yield the CPU. | |
| #define | switch_time_from_sec(sec) ((switch_time_t)(sec) * 1000000) |
| #define | SWITCH_DECLARE_GLOBAL_STRING_FUNC(fname, vname) |
| Declares a function designed to set a dynamic global string. | |
| #define | SWITCH_READ_ACCEPTABLE(status) (status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK) |
| #define | switch_network_list_add_cidr(_list, _cidr_str, _ok) switch_network_list_add_cidr_token(_list, _cidr_str, _ok, NULL) |
| #define | switch_network_list_validate_ip(_list, _ip) switch_network_list_validate_ip_token(_list, _ip, NULL); |
| #define | switch_test_subnet(_ip, _net, _mask) (_mask ? ((_net & _mask) == (_ip & _mask)) : _net ? _net == _ip : 1) |
| #define | switch_malloc(ptr, len) (void)(assert(((ptr) = malloc((len)))),ptr) |
| #define | switch_zmalloc(ptr, len) (void)(assert((ptr = calloc(1, (len)))),ptr) |
| #define | switch_strdup(ptr, s) (void)(assert(((ptr) = strdup((s)))),ptr) |
| #define | DUMP_EVENT(_e) {char *event_str;switch_event_serialize(_e, &event_str, SWITCH_FALSE);switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "DUMP\n%s\n", event_str);free(event_str);} |
| #define | switch_inet_ntop inet_ntop |
Enumerations | |
| enum | switch_uri_flags { SWITCH_URI_NUMERIC_HOST = 1, SWITCH_URI_NUMERIC_PORT = 2, SWITCH_URI_NO_SCOPE = 4 } |
| flags to be used with switch_build_uri() More... | |
Functions | |
| SWITCH_BEGIN_EXTERN_C int | switch_toupper (int c) |
| int | switch_tolower (int c) |
| int | switch_isalnum (int c) |
| int | switch_isalpha (int c) |
| int | switch_iscntrl (int c) |
| int | switch_isdigit (int c) |
| int | switch_isgraph (int c) |
| int | switch_islower (int c) |
| int | switch_isprint (int c) |
| int | switch_ispunct (int c) |
| int | switch_isspace (int c) |
| int | switch_isupper (int c) |
| int | switch_isxdigit (int c) |
| switch_bool_t | switch_testv6_subnet (ip_t _ip, ip_t _net, ip_t _mask) |
| static _Check_return_ int | _zstr (_In_opt_z_ const char *s) |
| Test for NULL or zero length string. | |
| static switch_bool_t | switch_is_moh (const char *s) |
| static char * | switch_strchr_strict (const char *in, char find, const char *allowed) |
| static int | switch_string_has_escaped_data (const char *in) |
| switch_status_t | switch_b64_encode (unsigned char *in, switch_size_t ilen, unsigned char *out, switch_size_t olen) |
| switch_size_t | switch_b64_decode (char *in, char *out, switch_size_t olen) |
| char * | switch_amp_encode (char *s, char *buf, switch_size_t len) |
| static switch_bool_t | switch_is_digit_string (const char *s) |
| static char | switch_itodtmf (char i) |
| static int | switch_dtmftoi (char *s) |
| static uint32_t | switch_known_bitrate (switch_payload_t payload) |
| switch_size_t | switch_fd_read_line (int fd, char *buf, switch_size_t len) |
| switch_status_t | switch_frame_alloc (switch_frame_t **frame, switch_size_t size) |
| switch_status_t | switch_frame_dup (switch_frame_t *orig, switch_frame_t **clone) |
| switch_status_t | switch_frame_free (switch_frame_t **frame) |
| switch_bool_t | switch_is_number (const char *str) |
| char * | switch_find_parameter (const char *str, const char *param, switch_memory_pool_t *pool) |
| static int | switch_true (const char *expr) |
| Evaluate the truthfullness of a string expression. | |
| static int | switch_false (const char *expr) |
| Evaluate the falsefullness of a string expression. | |
| switch_status_t | switch_resolve_host (const char *host, char *buf, size_t buflen) |
| switch_status_t | switch_find_local_ip (_Out_opt_bytecapcount_(len) char *buf, _In_ int len, _In_opt_ int *mask, _In_ int family) |
| find local ip of the box | |
| char * | get_addr (char *buf, switch_size_t len, struct sockaddr *sa, socklen_t salen) |
| find the char representation of an ip adress | |
| char * | get_addr6 (char *buf, switch_size_t len, struct sockaddr_in6 *sa, socklen_t salen) |
| int | get_addr_int (switch_sockaddr_t *sa) |
| int | switch_cmp_addr (switch_sockaddr_t *sa1, switch_sockaddr_t *sa2) |
| unsigned short | get_port (struct sockaddr *sa) |
| get the port number of an ip address | |
| int | switch_build_uri (char *uri, switch_size_t size, const char *scheme, const char *user, const switch_sockaddr_t *sa, int flags) |
| build a URI string from components | |
| const char * | switch_priority_name (switch_priority_t priority) |
| Return a printable name of a switch_priority_t. | |
| char | switch_rfc2833_to_char (int event) |
| Return the RFC2833 character based on an event id. | |
| unsigned char | switch_char_to_rfc2833 (char key) |
| Return the RFC2833 event based on an key character. | |
| static char * | switch_sanitize_number (char *number) |
| static switch_bool_t | switch_string_var_check (char *s, switch_bool_t disable) |
| static switch_bool_t | switch_string_var_check_const (const char *s) |
| static char * | switch_var_clean_string (char *s) |
| static char * | switch_clean_string (char *s) |
| static char * | switch_clean_name_string (char *s) |
| static int | switch_safe_atoi (const char *nptr, int dft) |
| Turn a string into a number (default if NULL). | |
| static char * | switch_safe_strdup (const char *it) |
| static char * | switch_lc_strdup (const char *it) |
| static char * | switch_uc_strdup (const char *it) |
| static switch_bool_t | switch_strstr (char *s, char *q) |
| Test if one string is inside another with extra case checking. | |
| switch_time_t | switch_str_time (const char *in) |
| Converts a string representation of a date into a switch_time_t. | |
| unsigned int | switch_separate_string (_In_ char *buf, char delim, _Post_count_(return) char **array, unsigned int arraylen) |
| Separate a string into an array based on a character delimiter. | |
| unsigned int | switch_separate_string_string (char *buf, char *delim, _Post_count_(return) char **array, unsigned int arraylen) |
| char * | switch_strip_spaces (char *str, switch_bool_t dup) |
| char * | switch_strip_whitespace (const char *str) |
| char * | switch_strip_commas (char *in, char *out, switch_size_t len) |
| char * | switch_strip_nonnumerics (char *in, char *out, switch_size_t len) |
| char * | switch_separate_paren_args (char *str) |
| const char * | switch_stristr (const char *instr, const char *str) |
| switch_bool_t | switch_is_lan_addr (const char *ip) |
| char * | switch_replace_char (char *str, char from, char to, switch_bool_t dup) |
| switch_bool_t | switch_ast2regex (const char *pat, char *rbuf, size_t len) |
| char * | switch_escape_char (switch_memory_pool_t *pool, char *in, const char *delim, char esc) |
| Escape a string by prefixing a list of characters with an escape character. | |
| char * | switch_escape_string (const char *in, char *out, switch_size_t outlen) |
| char * | switch_escape_string_pool (const char *in, switch_memory_pool_t *pool) |
| int | switch_socket_waitfor (switch_pollfd_t *poll, int ms) |
| Wait for a socket. | |
| const char * | switch_cut_path (const char *in) |
| Create a pointer to the file name in a given file path eliminating the directory name. | |
| char * | switch_string_replace (const char *string, const char *search, const char *replace) |
| switch_status_t | switch_string_match (const char *string, size_t string_len, const char *search, size_t search_len) |
| char * | switch_util_quote_shell_arg (const char *string) |
| Quote shell argument. | |
| char * | switch_url_encode (const char *url, char *buf, size_t len) |
| char * | switch_url_decode (char *s) |
| switch_bool_t | switch_simple_email (const char *to, const char *from, const char *headers, const char *body, const char *file, const char *convert_cmd, const char *convert_ext) |
| char * | switch_find_end_paren (const char *s, char open, char close) |
| static switch_bool_t | switch_is_file_path (const char *file) |
| int | switch_parse_cidr (const char *string, ip_t *ip, ip_t *mask, uint32_t *bitp) |
| switch_status_t | switch_network_list_create (switch_network_list_t **list, const char *name, switch_bool_t default_type, switch_memory_pool_t *pool) |
| switch_status_t | switch_network_list_add_cidr_token (switch_network_list_t *list, const char *cidr_str, switch_bool_t ok, const char *token) |
| switch_status_t | switch_network_list_add_host_mask (switch_network_list_t *list, const char *host, const char *mask_str, switch_bool_t ok) |
| switch_bool_t | switch_network_list_validate_ip_token (switch_network_list_t *list, uint32_t ip, const char **token) |
| switch_bool_t | switch_network_list_validate_ip6_token (switch_network_list_t *list, ip_t ip, const char **token) |
| int | switch_inet_pton (int af, const char *src, void *dst) |
| const char * | switch_dow_int2str (int val) |
| int | switch_dow_str2int (const char *exp) |
| switch_bool_t | switch_dow_cmp (const char *exp, int val) |
| int | switch_number_cmp (const char *exp, int val) |
| int | switch_tod_cmp (const char *exp, int val) |
| int | switch_fulldate_cmp (const char *exp, switch_time_t *ts) |
| void | switch_split_date (const char *exp, int *year, int *month, int *day) |
| void | switch_split_time (const char *exp, int *hour, int *min, int *sec) |
| int | switch_split_user_domain (char *in, char **user, char **domain) |
| Split a user string as user and domain. | |
| char * | switch_uuid_str (char *buf, switch_size_t len) |
| char * | switch_format_number (const char *num) |
| unsigned int | switch_atoui (const char *nptr) |
| unsigned long | switch_atoul (const char *nptr) |
Just a miscelaneaous set of general utility/helper functions.
Definition in file switch_utils.h.
| #define DUMP_EVENT | ( | _e | ) | {char *event_str;switch_event_serialize(_e, &event_str, SWITCH_FALSE);switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "DUMP\n%s\n", event_str);free(event_str);} |
Definition at line 826 of file switch_utils.h.
| #define end_of | ( | _s | ) | *(*_s == '\0' ? _s : _s + strlen(_s) - 1) |
Definition at line 372 of file switch_utils.h.
Referenced by parse_presence_data_cols(), and switch_load_core_config().
| #define end_of_p | ( | _s | ) | (*_s == '\0' ? _s : _s + strlen(_s) - 1) |
Definition at line 373 of file switch_utils.h.
Referenced by switch_cache_db_execute_sql_chunked(), switch_channel_expand_variables_check(), switch_console_complete(), and switch_event_expand_headers_check().
| #define is_dtmf | ( | key | ) | ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119 || key == 70 || key == 102) |
determine if a character is a valid DTMF key
| key | the key to test |
Definition at line 370 of file switch_utils.h.
Referenced by meta_on_dtmf(), speech_thread(), switch_channel_queue_dtmf(), switch_channel_queue_dtmf_string(), switch_core_session_send_dtmf_string(), and switch_ivr_bind_dtmf_meta_session().
| #define switch_arraylen | ( | _a | ) | (sizeof(_a) / sizeof(_a[0])) |
Definition at line 143 of file switch_utils.h.
Referenced by switch_dow_int2str(), and switch_dow_str2int().
| #define switch_clear_flag | ( | obj, | |||
| flag | ) | (obj)->flags &= ~(flag) |
Clear a flag on an arbitrary object while locked.
| obj | the object to test | |
| flag | the or'd list of flags to clear |
Definition at line 411 of file switch_utils.h.
Referenced by do_flush(), rtp_common_read(), rtp_common_write(), CoreSession::setAutoHangup(), switch_core_codec_destroy(), switch_core_file_close(), switch_core_file_read(), switch_core_init_and_modload(), switch_core_media_bug_clear_flag(), switch_core_media_bug_prune(), switch_core_media_bug_set_flag(), switch_core_session_ctl(), switch_core_session_perform_destroy(), switch_core_session_reset(), switch_core_session_run(), switch_core_session_thread_launch(), switch_core_session_write_frame(), switch_core_speech_close(), switch_core_speech_read_tts(), switch_core_sqldb_start(), switch_ivr_eavesdrop_session(), switch_ivr_menu_execute(), switch_ivr_play_file(), switch_ivr_process_fh(), switch_ivr_record_file(), switch_load_core_config(), SWITCH_MODULE_LOAD_FUNCTION(), switch_rtp_destroy(), switch_rtp_kill_socket(), switch_rtp_udptl_mode(), switch_rtp_write_frame(), and switch_rtp_zerocopy_read_frame().
| #define switch_clear_flag_locked | ( | obj, | |||
| flag | ) | switch_mutex_lock(obj->flag_mutex); (obj)->flags &= ~(flag); switch_mutex_unlock(obj->flag_mutex); |
Clear a flag on an arbitrary object.
| obj | the object to test | |
| flag | the or'd list of flags to clear |
Definition at line 404 of file switch_utils.h.
Referenced by do_flush(), read_rtp_packet(), rtp_common_read(), rtp_common_write(), rtp_flush_read_buffer(), switch_ivr_deactivate_unicast(), switch_rtp_clear_flag(), switch_rtp_create(), switch_rtp_disable_vad(), switch_rtp_udptl_mode(), switch_rtp_write_manual(), and unicast_thread_run().
| #define switch_codec2str | ( | codec, | |||
| buf, | |||||
| len | ) |
Value:
snprintf(buf, len, "%s@%uh@%ui", \ codec->implementation->iananame, \ codec->implementation->samples_per_second, \ codec->implementation->microseconds_per_packet / 1000)
Definition at line 70 of file switch_utils.h.
Referenced by switch_core_session_outgoing_channel().
| #define switch_copy_flags | ( | dest, | |||
| src, | |||||
| flags | ) | (dest)->flags &= ~(flags); (dest)->flags |= ((src)->flags & (flags)) |
Copy flags from one arbitrary object to another.
| dest | the object to copy the flags to | |
| src | the object to copy the flags from | |
| flags | the flags to copy |
Definition at line 419 of file switch_utils.h.
| #define SWITCH_DECLARE_GLOBAL_STRING_FUNC | ( | fname, | |||
| vname | ) |
Value:
static void fname(const char *string) { if (!string) return;\ if (vname) {free(vname); vname = NULL;}vname = strdup(string);} static void fname(const char *string)
| fname | the function name to declare | |
| vname | the name of the global pointer to modify with the new function |
Definition at line 679 of file switch_utils.h.
| #define switch_goto_int | ( | _n, | |||
| _i, | |||||
| _label | ) | _n = _i; goto _label |
Definition at line 65 of file switch_utils.h.
| #define switch_goto_status | ( | _status, | |||
| _label | ) | status = _status; goto _label |
Definition at line 64 of file switch_utils.h.
Referenced by setup_ringback(), switch_core_execute_chat_app(), switch_core_perform_file_open(), switch_core_session_execute_application_get_flags(), switch_ivr_enterprise_originate(), switch_ivr_menu_execute(), switch_ivr_originate(), switch_limit_incr(), switch_limit_interval_reset(), switch_limit_release(), switch_limit_reset(), and switch_limit_status().
| #define switch_inet_ntop inet_ntop |
Definition at line 829 of file switch_utils.h.
| #define switch_is_valid_rate | ( | _tmp | ) | (_tmp == 8000 || _tmp == 12000 || _tmp == 16000 || _tmp == 24000 || _tmp == 32000 || _tmp == 11025 || _tmp == 22050 || _tmp == 44100 || _tmp == 48000) |
Definition at line 146 of file switch_utils.h.
Referenced by switch_ivr_record_file(), and switch_ivr_record_session().
| #define switch_malloc | ( | ptr, | |||
| len | ) | (void)(assert(((ptr) = malloc((len)))),ptr) |
Definition at line 820 of file switch_utils.h.
| #define switch_network_list_add_cidr | ( | _list, | |||
| _cidr_str, | |||||
| _ok | ) | switch_network_list_add_cidr_token(_list, _cidr_str, _ok, NULL) |
| #define switch_network_list_validate_ip | ( | _list, | |||
| _ip | ) | switch_network_list_validate_ip_token(_list, _ip, NULL); |
Definition at line 783 of file switch_utils.h.
| #define switch_normalize_to_16bit | ( | n | ) | if (n > SWITCH_SMAX) n = SWITCH_SMAX; else if (n < SWITCH_SMIN) n = SWITCH_SMIN; |
Definition at line 69 of file switch_utils.h.
Referenced by early_thread_run(), read_displace_callback(), switch_change_sln_volume(), switch_change_sln_volume_granular(), switch_core_media_bug_read(), switch_merge_sln(), switch_mux_channels(), and write_displace_callback().
| #define SWITCH_READ_ACCEPTABLE | ( | status | ) | (status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK) |
Definition at line 741 of file switch_utils.h.
Referenced by audio_bridge_thread(), early_thread_run(), switch_ivr_collect_digits_callback(), switch_ivr_collect_digits_count(), switch_ivr_delay_echo(), switch_ivr_eavesdrop_session(), switch_ivr_gentones(), switch_ivr_park(), switch_ivr_parse_event(), switch_ivr_play_file(), switch_ivr_record_file(), switch_ivr_session_echo(), switch_ivr_sleep(), switch_ivr_sound_test(), switch_ivr_speak_text_handle(), switch_ivr_wait_for_answer(), and switch_ivr_wait_for_silence().
| #define switch_safe_free | ( | it | ) | if (it) {free(it);it=NULL;} |
Free a pointer and set it to NULL unless it already is NULL.
| it | the pointer |
Definition at line 545 of file switch_utils.h.
Referenced by api_hook(), audio_bridge_thread(), check_channel_status(), comp_callback(), CoreSession::destroy(), API::execute(), API::executeString(), CoreSession::getXMLCDR(), load_mime_types(), CoreSession::originate(), parse_presence_data_cols(), play_and_collect(), record_callback(), Event::serialize(), CoreSession::set_tts_parms(), setup_ringback(), speech_thread(), switch_api_execute(), switch_buffer_destroy(), switch_cache_db_persistant_execute(), switch_channel_build_param_string(), switch_channel_expand_variables_check(), switch_channel_export_variable_var_check(), switch_channel_set_presence_data_vals(), switch_channel_uninit(), switch_console_complete(), switch_console_execute(), switch_console_expand_alias(), switch_console_process(), switch_console_set_alias(), switch_console_set_complete(), switch_core_asr_load_grammar(), switch_core_destroy(), switch_core_file_close(), switch_core_session_exec(), switch_core_session_free_message(), switch_core_session_reporting_state(), switch_core_speech_feed_tts(), switch_event_add_body(), switch_event_add_presence_data_cols(), switch_event_build_param_string(), switch_event_expand_headers_check(), switch_event_serialize(), switch_event_set_body(), switch_event_set_subclass_name(), switch_find_local_ip(), switch_frame_free(), switch_fulldate_cmp(), switch_ivr_broadcast(), switch_ivr_digit_stream_destroy(), switch_ivr_eavesdrop_session(), switch_ivr_insert_file(), switch_ivr_multi_threaded_bridge(), switch_ivr_park(), switch_ivr_phrase_macro_event(), switch_ivr_play_file(), switch_ivr_record_file(), switch_ivr_set_json_chan_vars(), switch_ivr_sleep(), switch_ivr_speak_text_handle(), switch_ivr_wait_for_answer(), switch_loadable_module_enumerate_available(), switch_loadable_module_load_file(), switch_log_node_free(), switch_log_vprintf(), switch_nat_init(), switch_nat_multicast_runtime(), switch_nat_republish(), switch_nat_shutdown(), switch_network_list_add_cidr_token(), switch_odbc_handle_destroy(), switch_odbc_handle_new(), switch_regex_perform(), switch_rtp_destroy(), switch_say_file_handle_destroy(), switch_simple_email(), switch_split_date(), switch_split_time(), switch_stream_write_file_contents(), switch_strstr(), switch_tod_cmp(), switch_xml_config_cleanup(), switch_xml_free(), switch_xml_parse_file(), task_thread_loop(), API::~API(), and Stream::~Stream().
| #define switch_samples_per_packet | ( | rate, | |||
| interval | ) | ((uint32_t)((float)rate / (1000.0f / (float)interval))) |
| #define switch_set_flag | ( | obj, | |||
| flag | ) | (obj)->flags |= (flag) |
Set a flag on an arbitrary object.
| obj | the object to set the flags on | |
| flag | the or'd list of flags to set |
Definition at line 387 of file switch_utils.h.
Referenced by CoreSession::CoreSession(), rtp_common_read(), rtp_common_write(), CoreSession::setAutoHangup(), switch_buffer_create_dynamic(), switch_caller_profile_new(), switch_core_asr_close(), switch_core_asr_open(), switch_core_codec_copy(), switch_core_codec_init_with_bitrate(), switch_core_destroy(), switch_core_directory_open(), switch_core_file_read(), switch_core_file_seek(), switch_core_init(), switch_core_media_bug_pop(), switch_core_media_bug_set_flag(), switch_core_perform_file_open(), switch_core_session_ctl(), switch_core_session_hangup_state(), switch_core_session_queue_indication(), switch_core_session_run(), switch_core_session_sync_clock(), switch_core_session_thread(), switch_core_session_thread_launch(), switch_core_session_write_frame(), switch_core_speech_open(), switch_core_speech_read_tts(), switch_core_timer_init(), switch_frame_alloc(), switch_frame_dup(), switch_ivr_activate_unicast(), switch_ivr_detect_speech(), switch_ivr_eavesdrop_session(), switch_ivr_menu_execute(), switch_ivr_menu_init(), switch_ivr_menu_stack_xml_build(), switch_ivr_play_file(), switch_ivr_process_fh(), switch_ivr_sleep(), switch_load_core_config(), switch_rtp_activate_rtcp(), switch_rtp_add_crypto_key(), switch_rtp_break(), switch_rtp_enable_vad(), switch_rtp_set_cng_pt(), switch_rtp_zerocopy_read_frame(), and switch_xml_set_root().
| #define switch_set_flag_locked | ( | obj, | |||
| flag | ) |
Value:
assert(obj->flag_mutex != NULL);\ switch_mutex_lock(obj->flag_mutex);\ (obj)->flags |= (flag);\ switch_mutex_unlock(obj->flag_mutex);
| obj | the object to set the flags on | |
| flag | the or'd list of flags to set |
Definition at line 394 of file switch_utils.h.
Referenced by do_flush(), rtp_flush_read_buffer(), switch_ivr_activate_unicast(), switch_rtp_create(), switch_rtp_destroy(), switch_rtp_enable_vad(), switch_rtp_flush(), switch_rtp_set_flag(), switch_rtp_set_local_address(), switch_rtp_udptl_mode(), and unicast_thread_launch().
| #define switch_set_string | ( | _dst, | |||
| _src | ) | switch_copy_string(_dst, _src, sizeof(_dst)) |
Definition at line 421 of file switch_utils.h.
Referenced by add_handle(), check_ip(), get_handle(), switch_config_open_file(), switch_core_asr_open(), switch_core_session_request_uuid(), switch_core_session_set_uuid(), switch_core_speech_open(), switch_ivr_dmachine_check_match(), switch_ivr_dmachine_ping(), switch_load_network_lists(), switch_log_vprintf(), and switch_nat_multicast_runtime().
| #define SWITCH_SMAX 32767 |
| #define SWITCH_SMIN -32768 |
| #define switch_split | ( | _data, | |||
| _delim, | |||||
| _array | ) | switch_separate_string(_data, _delim, _array, switch_arraylen(_array)) |
Definition at line 144 of file switch_utils.h.
Referenced by main(), parse_presence_data_cols(), switch_channel_set_presence_data_vals(), and switch_event_add_presence_data_cols().
| #define SWITCH_STATUS_IS_BREAK | ( | x | ) | (x == SWITCH_STATUS_BREAK || x == 730035 || x == 35 || x == SWITCH_STATUS_INTR) |
Definition at line 342 of file switch_utils.h.
Referenced by rtp_common_read(), switch_ivr_menu_execute(), and switch_nat_multicast_runtime().
| #define switch_str_nil | ( | s | ) | (s ? s : "") |
Make a null string a blank string instead.
| s | the string to test |
Definition at line 659 of file switch_utils.h.
Referenced by api_hook(), audio_bridge_thread(), EventConsumer::bind(), console_clean_log(), console_log(), core_event_handler(), do_api_on(), is_valid_action(), switch_channel_flip_cid(), switch_channel_set_timestamps(), switch_console_complete(), switch_console_set_complete(), switch_core_add_registration(), switch_core_session_exec(), switch_core_session_execute_application_get_flags(), switch_core_session_execute_exten(), switch_ivr_displace_session(), switch_ivr_generate_json_cdr(), switch_ivr_parse_event(), switch_ivr_phrase_macro_event(), switch_ivr_play_file(), switch_ivr_record_file(), switch_ivr_record_session(), switch_loadable_module_process(), switch_loadable_module_unprocess(), switch_network_list_perform_add_cidr_token(), switch_odbc_handle_callback_exec_detailed(), switch_odbc_handle_exec(), switch_scheduler_add_task(), switch_scheduler_del_task_group(), switch_scheduler_del_task_id(), switch_scheduler_execute(), switch_stun_host_lookup(), and task_thread_loop().
| #define switch_strdup | ( | ptr, | |||
| s | ) | (void)(assert(((ptr) = strdup((s)))),ptr) |
| #define switch_strlen_zero | ( | x | ) | zstr(x) |
Definition at line 91 of file switch_utils.h.
| #define switch_strlen_zero_buf | ( | x | ) | zstr_buf(x) |
Definition at line 92 of file switch_utils.h.
| #define switch_test_flag | ( | obj, | |||
| flag | ) | ((obj)->flags & flag) |
Test for the existance of a flag on an arbitary object.
| obj | the object to test | |
| flag | the or'd list of flags to test |
Definition at line 380 of file switch_utils.h.
Referenced by _switch_core_db_handle(), audio_bridge_thread(), CoreSession::destroy(), do_2833(), do_flush(), eavesdrop_callback(), enable_local_rtcp_socket(), enable_remote_rtcp_socket(), get_handle(), handle_rfc2833(), ping_socket(), read_rtcp_packet(), read_rtp_packet(), rtp_common_read(), rtp_common_write(), rtp_flush_read_buffer(), set_dtmf_delay(), setup_ringback(), speech_thread(), sql_close(), switch_buffer_destroy(), switch_buffer_freespace(), switch_buffer_write(), switch_cache_db_test_reactive(), switch_caller_get_field_by_name(), switch_caller_profile_event_set_data(), switch_core_add_registration(), switch_core_asr_close(), switch_core_codec_decode(), switch_core_codec_destroy(), switch_core_codec_encode(), switch_core_db_test_reactive(), switch_core_del_registration(), switch_core_destroy(), switch_core_directory_close(), switch_core_execute_chat_app(), switch_core_expire_registration(), switch_core_file_close(), switch_core_file_get_string(), switch_core_file_read(), switch_core_file_seek(), switch_core_file_set_string(), switch_core_file_truncate(), switch_core_file_write(), switch_core_init(), switch_core_init_and_modload(), switch_core_media_bug_add(), switch_core_media_bug_close(), switch_core_media_bug_count(), switch_core_media_bug_exec_all(), switch_core_media_bug_inuse(), switch_core_media_bug_read(), switch_core_media_bug_remove_all_function(), switch_core_media_bug_test_flag(), switch_core_perform_file_open(), switch_core_port_allocator_free_port(), switch_core_port_allocator_new(), switch_core_port_allocator_request_port(), switch_core_ready(), switch_core_ready_inbound(), switch_core_ready_outbound(), switch_core_session_ctl(), switch_core_session_execute_application_get_flags(), switch_core_session_force_locate(), switch_core_session_free_message(), switch_core_session_hangup_state(), switch_core_session_perform_destroy(), switch_core_session_read_lock(), switch_core_session_read_lock_hangup(), switch_core_session_read_video_frame(), switch_core_session_recv_dtmf(), switch_core_session_running(), switch_core_session_send_dtmf(), switch_core_session_started(), switch_core_session_thread_launch(), switch_core_session_write_frame(), switch_core_set_signal_handlers(), switch_core_speech_close(), switch_core_speech_read_tts(), switch_core_sql_db_thread(), switch_core_sql_thread(), switch_core_sqldb_start(), switch_core_timer_destroy(), switch_event_base_add_header(), switch_event_check_permission_list(), switch_frame_free(), switch_ivr_activate_unicast(), switch_ivr_deactivate_unicast(), switch_ivr_eavesdrop_session(), switch_ivr_insert_file(), switch_ivr_menu_execute(), switch_ivr_menu_stack_free(), switch_ivr_park(), switch_ivr_parse_event(), switch_ivr_play_file(), switch_ivr_process_fh(), switch_ivr_record_file(), switch_ivr_session_echo(), switch_ivr_sound_test(), switch_ivr_speak_text_handle(), switch_ivr_wait_for_answer(), switch_loadable_module_load_file(), SWITCH_MODULE_LOAD_FUNCTION(), switch_rtcp_zerocopy_read_frame(), switch_rtp_add_crypto_key(), switch_rtp_break(), switch_rtp_create(), switch_rtp_destroy(), switch_rtp_disable_vad(), switch_rtp_enable_vad(), switch_rtp_kill_socket(), switch_rtp_ready(), switch_rtp_set_local_address(), switch_rtp_set_remote_address(), switch_rtp_test_flag(), switch_rtp_udptl_mode(), switch_rtp_write_frame(), switch_rtp_write_manual(), switch_rtp_zerocopy_read_frame(), switch_scheduler_del_task_group(), switch_scheduler_del_task_id(), switch_system(), switch_xml_config_item_print_doc(), switch_xml_config_parse_event(), switch_xml_free(), task_thread_loop(), and unicast_thread_run().
| #define switch_test_subnet | ( | _ip, | |||
| _net, | |||||
| _mask | ) | (_mask ? ((_net & _mask) == (_ip & _mask)) : _net ? _net == _ip : 1) |
Definition at line 785 of file switch_utils.h.
Referenced by switch_check_network_list_ip_token(), and switch_network_list_validate_ip_token().
| #define switch_time_from_sec | ( | sec | ) | ((switch_time_t)(sec) * 1000000) |
Definition at line 672 of file switch_utils.h.
| #define switch_true_buf | ( | expr | ) |
Value:
((( !strcasecmp(expr, "yes") ||\ !strcasecmp(expr, "on") ||\ !strcasecmp(expr, "true") ||\ !strcasecmp(expr, "enabled") ||\ !strcasecmp(expr, "active") ||\ !strcasecmp(expr, "allow") ||\ (switch_is_number(expr) && atoi(expr)))) ? SWITCH_TRUE : SWITCH_FALSE)
Definition at line 261 of file switch_utils.h.
| #define switch_yield | ( | ms | ) | switch_sleep(ms); |
Wait a desired number of microseconds and yield the CPU.
Definition at line 664 of file switch_utils.h.
Referenced by _switch_cache_db_get_db_handle(), audio_bridge_thread(), launch_dispatch_threads(), originate_on_consume_media_transmit(), pool_thread(), rtp_common_read(), signal_bridge_on_hibernate(), switch_cache_db_persistant_execute(), switch_cache_db_persistant_execute_trans(), switch_core_db_exec(), switch_core_db_persistant_execute(), switch_core_db_persistant_execute_trans(), switch_core_runtime_loop(), switch_core_session_ctl(), switch_core_session_send_dtmf(), switch_core_session_thread(), switch_core_sql_db_thread(), switch_core_sql_thread(), switch_core_sqldb_start(), switch_ivr_deactivate_unicast(), switch_ivr_eavesdrop_session(), switch_ivr_enterprise_originate(), switch_ivr_media(), switch_ivr_nomedia(), switch_ivr_park(), switch_ivr_play_file(), switch_ivr_sleep(), switch_ivr_speak_text_handle(), switch_ivr_wait_for_answer(), switch_loadable_module_shutdown(), switch_loadable_module_unload_module(), switch_nat_multicast_runtime(), switch_nat_thread_stop(), switch_scheduler_task_thread(), switch_scheduler_task_thread_stop(), switch_socket_send(), switch_thread_rwlock_trywrlock_timeout(), uuid_bridge_on_soft_execute(), and wait_for_cause().
| #define switch_zmalloc | ( | ptr, | |||
| len | ) | (void)(assert((ptr = calloc(1, (len)))),ptr) |
Definition at line 821 of file switch_utils.h.
Referenced by generate_on_dtmf(), switch_channel_queue_dtmf(), switch_console_push_match(), switch_core_hash_init_case(), switch_event_bind_removable(), switch_event_reserve_subclass_detailed(), switch_frame_alloc(), switch_ivr_collect_digits_count(), switch_ivr_digit_stream_new(), switch_ivr_insert_file(), switch_ivr_originate(), switch_ivr_park(), switch_ivr_play_file(), switch_ivr_schedule_broadcast(), switch_ivr_schedule_hangup(), switch_ivr_schedule_transfer(), switch_ivr_sleep(), switch_ivr_wait_for_answer(), switch_ivr_wait_for_silence(), switch_mux_channels(), switch_resample_perform_create(), and switch_scheduler_add_task().
| #define zstr | ( | x | ) | _zstr(x) |
Definition at line 89 of file switch_utils.h.
Referenced by __switch_xml_open_root(), _switch_core_db_handle(), api_hook(), audio_bridge_thread(), EventConsumer::bind(), Event::chat_send(), check_channel_status(), collect_thread_run(), comp_callback(), core_event_handler(), enterprise_originate_ringback_thread(), Event::Event(), EventConsumer::EventConsumer(), fs_core_init(), globalSetVariable(), is_valid_action(), IVRMenu::IVRMenu(), limit_state_handler(), main(), parse_array(), parse_presence_data_cols(), play_and_collect(), play_and_detect_input_callback(), send_display(), setup_ringback(), signal_bridge_on_hangup(), switch_cache_db_persistant_execute_trans(), switch_caller_profile_event_set_data(), switch_caller_profile_new(), switch_channel_add_variable_var_check(), switch_channel_build_param_string(), switch_channel_del_variable_prefix(), switch_channel_expand_variables_check(), switch_channel_get_name(), switch_channel_get_variable_partner(), switch_channel_pass_callee_id(), switch_channel_process_export(), switch_channel_queue_dtmf_string(), switch_channel_set_name(), switch_channel_set_presence_data_vals(), switch_channel_set_profile_var(), switch_channel_set_timestamps(), switch_channel_set_variable_partner_var_check(), switch_channel_set_variable_printf(), switch_channel_set_variable_var_check(), switch_console_complete(), switch_console_list_uuid(), switch_core_asr_load_grammar(), switch_core_codec_parse_fmtp(), switch_core_del_registration(), switch_core_get_switchname(), switch_core_media_bug_remove_all_function(), switch_core_perform_file_open(), switch_core_perform_permanent_strdup(), switch_core_perform_session_strdup(), switch_core_perform_strdup(), switch_core_session_exec(), switch_core_session_execute_exten(), switch_core_session_outgoing_channel(), switch_core_session_perform_receive_message(), switch_core_session_reporting_state(), switch_core_session_send_dtmf_string(), switch_core_set_var_conditional(), switch_core_speech_feed_tts(), switch_core_speech_open(), switch_core_standard_on_routing(), switch_event_base_add_header(), switch_event_build_param_string(), switch_event_del_header_val(), switch_event_expand_headers_check(), switch_event_xmlize(), switch_file_exists(), switch_format_number(), switch_is_lan_addr(), switch_is_moh(), switch_ivr_bind_dtmf_meta_session(), switch_ivr_blind_transfer_ack(), switch_ivr_check_presence_mapping(), switch_ivr_collect_digits_count(), switch_ivr_displace_session(), switch_ivr_dmachine_bind(), switch_ivr_dmachine_clear_realm(), switch_ivr_dmachine_feed(), switch_ivr_dmachine_ping(), switch_ivr_eavesdrop_session(), switch_ivr_enterprise_originate(), switch_ivr_generate_json_cdr(), switch_ivr_generate_xml_cdr(), switch_ivr_intercept_session(), switch_ivr_kill_uuid(), switch_ivr_menu_execute(), switch_ivr_menu_init(), switch_ivr_menu_stack_xml_build(), switch_ivr_menu_str2action(), switch_ivr_originate(), switch_ivr_parse_event(), switch_ivr_phrase_macro_event(), switch_ivr_play_file(), switch_ivr_process_fh(), switch_ivr_read(), switch_ivr_say(), switch_ivr_session_transfer(), switch_ivr_set_json_chan_vars(), switch_ivr_set_user(), switch_ivr_set_xml_chan_var(), switch_ivr_soft_hold(), switch_ivr_tone_detect_session(), switch_ivr_wait_for_answer(), switch_load_core_config(), switch_load_network_lists(), switch_load_timezones(), switch_loadable_module_exists(), switch_loadable_module_init(), switch_log_node_dup(), switch_log_vprintf(), switch_network_list_perform_add_cidr_token(), switch_odbc_handle_callback_exec_detailed(), switch_odbc_handle_exec(), switch_play_and_get_digits(), switch_rtp_create(), switch_rtp_get_remote_host(), switch_rtp_new(), switch_rtp_set_local_address(), switch_say_file_handle_create(), switch_scheduler_del_task_group(), switch_simple_email(), switch_strftime_tz(), switch_strip_spaces(), switch_strip_whitespace(), switch_time_exp_tz_name(), switch_url_decode(), switch_xml_locate(), switch_xml_std_datetime_check(), and transfer_after_bridge().
| #define zstr_buf | ( | s | ) | (*(s) == '\0') |
Definition at line 93 of file switch_utils.h.
Referenced by get_upnp_pubaddr(), and switch_strftime_tz().
| enum switch_uri_flags |
flags to be used with switch_build_uri()
Definition at line 324 of file switch_utils.h.
00324 { 00325 SWITCH_URI_NUMERIC_HOST = 1, 00326 SWITCH_URI_NUMERIC_PORT = 2, 00327 SWITCH_URI_NO_SCOPE = 4 00328 };
| static _Check_return_ int _zstr | ( | _In_opt_z_ const char * | s | ) | [inline, static] |
Test for NULL or zero length string.
| s | the string to test |
Definition at line 82 of file switch_utils.h.
| char* get_addr | ( | char * | buf, | |
| switch_size_t | len, | |||
| struct sockaddr * | sa, | |||
| socklen_t | salen | |||
| ) |
find the char representation of an ip adress
| buf | the buffer to write the ip adress found into | |
| len | the length of the buf | |
| sa | the struct sockaddr * to get the adress from | |
| salen | the length of sa |
Definition at line 1726 of file switch_utils.c.
References switch_assert.
Referenced by switch_find_local_ip(), switch_get_addr(), and switch_resolve_host().
01727 { 01728 switch_assert(buf); 01729 *buf = '\0'; 01730 01731 if (sa) { 01732 getnameinfo(sa, salen, buf, (socklen_t) len, NULL, 0, NI_NUMERICHOST); 01733 } 01734 return buf; 01735 }
| char* get_addr6 | ( | char * | buf, | |
| switch_size_t | len, | |||
| struct sockaddr_in6 * | sa, | |||
| socklen_t | salen | |||
| ) |
Definition at line 1710 of file switch_utils.c.
References switch_assert.
Referenced by switch_get_addr().
01711 { 01712 switch_assert(buf); 01713 *buf = '\0'; 01714 01715 if (sa) { 01716 #if defined(NTDDI_VERSION) 01717 switch_inet_ntop6((unsigned char*)&(sa->sin6_addr), buf, len); 01718 #else 01719 inet_ntop(AF_INET6, &(sa->sin6_addr), buf, len); 01720 #endif 01721 } 01722 01723 return buf; 01724 }
| int get_addr_int | ( | switch_sockaddr_t * | sa | ) |
Definition at line 1655 of file switch_utils.c.
01656 { 01657 struct sockaddr_in *s = (struct sockaddr_in *) &sa->sa; 01658 01659 return ntohs((unsigned short) s->sin_addr.s_addr); 01660 }
| unsigned short get_port | ( | struct sockaddr * | sa | ) |
get the port number of an ip address
| sa | the struct sockaddr * to get the port from |
Definition at line 1737 of file switch_utils.c.
01738 { 01739 unsigned short port = 0; 01740 if (sa) { 01741 switch (sa->sa_family) { 01742 case AF_INET: 01743 port = ntohs(((struct sockaddr_in *) sa)->sin_port); 01744 break; 01745 case AF_INET6: 01746 port = ntohs(((struct sockaddr_in6 *) sa)->sin6_port); 01747 break; 01748 } 01749 } 01750 return port; 01751 }
| char* switch_amp_encode | ( | char * | s, | |
| char * | buf, | |||
| switch_size_t | len | |||
| ) |
Definition at line 456 of file switch_utils.c.
References switch_assert.
00457 { 00458 char *p, *q; 00459 switch_size_t x = 0; 00460 switch_assert(s); 00461 00462 q = buf; 00463 00464 for (p = s; x < len; p++) { 00465 switch (*p) { 00466 case '<': 00467 if (x + 4 > len - 1) { 00468 goto end; 00469 } 00470 *q++ = '&'; 00471 *q++ = 'l'; 00472 *q++ = 't'; 00473 *q++ = ';'; 00474 x += 4; 00475 break; 00476 case '>': 00477 if (x + 4 > len - 1) { 00478 goto end; 00479 } 00480 *q++ = '&'; 00481 *q++ = 'g'; 00482 *q++ = 't'; 00483 *q++ = ';'; 00484 x += 4; 00485 break; 00486 default: 00487 if (x + 1 > len - 1) { 00488 goto end; 00489 } 00490 *q++ = *p; 00491 x++; 00492 if (*p == '\0') { 00493 goto end; 00494 } 00495 break; 00496 } 00497 } 00498 00499 end: 00500 00501 return buf; 00502 }
| switch_bool_t switch_ast2regex | ( | const char * | pat, | |
| char * | rbuf, | |||
| size_t | len | |||
| ) |
Definition at line 833 of file switch_utils.c.
References SWITCH_FALSE, and SWITCH_TRUE.
Referenced by switch_regex_perform().
00834 { 00835 const char *p = pat; 00836 00837 if (!pat) { 00838 return SWITCH_FALSE; 00839 } 00840 00841 memset(rbuf, 0, len); 00842 00843 *(rbuf + strlen(rbuf)) = '^'; 00844 00845 while (p && *p) { 00846 if (*p == 'N') { 00847 strncat(rbuf, "[2-9]", len - strlen(rbuf)); 00848 } else if (*p == 'X') { 00849 strncat(rbuf, "[0-9]", len - strlen(rbuf)); 00850 } else if (*p == 'Z') { 00851 strncat(rbuf, "[1-9]", len - strlen(rbuf)); 00852 } else if (*p == '.') { 00853 strncat(rbuf, ".*", len - strlen(rbuf)); 00854 } else if (strlen(rbuf) < len - 1) { 00855 *(rbuf + strlen(rbuf)) = *p; 00856 } 00857 p++; 00858 } 00859 *(rbuf + strlen(rbuf)) = '$'; 00860 00861 return strcmp(pat, rbuf) ? SWITCH_TRUE : SWITCH_FALSE; 00862 }
| unsigned int switch_atoui | ( | const char * | nptr | ) |
Definition at line 2946 of file switch_utils.c.
Referenced by switch_ivr_process_fh().
02947 { 02948 int tmp = atoi(nptr); 02949 if (tmp < 0) return 0; 02950 else return (unsigned int) tmp; 02951 }
| unsigned long switch_atoul | ( | const char * | nptr | ) |
Definition at line 2953 of file switch_utils.c.
Referenced by switch_load_core_config().
02954 { 02955 long tmp = atol(nptr); 02956 if (tmp < 0) return 0; 02957 else return (unsigned long) tmp; 02958 }
| switch_size_t switch_b64_decode | ( | char * | in, | |
| char * | out, | |||
| switch_size_t | olen | |||
| ) |
Definition at line 538 of file switch_utils.c.
References switch_b64_table.
00539 { 00540 00541 char l64[256]; 00542 int b = 0, c, l = 0, i; 00543 char *ip, *op = out; 00544 size_t ol = 0; 00545 00546 for (i = 0; i < 256; i++) { 00547 l64[i] = -1; 00548 } 00549 00550 for (i = 0; i < 64; i++) { 00551 l64[(int) switch_b64_table[i]] = (char) i; 00552 } 00553 00554 for (ip = in; ip && *ip; ip++) { 00555 c = l64[(int) *ip]; 00556 if (c == -1) { 00557 continue; 00558 } 00559 00560 b = (b << 6) + c; 00561 l += 6; 00562 00563 while (l >= 8) { 00564 op[ol++] = (char) ((b >> (l -= 8)) % 256); 00565 if (ol >= olen - 2) { 00566 goto end; 00567 } 00568 } 00569 } 00570 00571 end: 00572 00573 op[ol++] = '\0'; 00574 00575 return ol; 00576 }
| switch_status_t switch_b64_encode | ( | unsigned char * | in, | |
| switch_size_t | ilen, | |||
| unsigned char * | out, | |||
| switch_size_t | olen | |||
| ) |
Definition at line 506 of file switch_utils.c.
References switch_b64_table, and SWITCH_STATUS_SUCCESS.
00507 { 00508 int y = 0, bytes = 0; 00509 size_t x = 0; 00510 unsigned int b = 0, l = 0; 00511 00512 for (x = 0; x < ilen; x++) { 00513 b = (b << 8) + in[x]; 00514 l += 8; 00515 00516 while (l >= 6) { 00517 out[bytes++] = switch_b64_table[(b >> (l -= 6)) % 64]; 00518 if (++y != 72) { 00519 continue; 00520 } 00521 /* out[bytes++] = '\n'; */ 00522 y = 0; 00523 } 00524 } 00525 00526 if (l > 0) { 00527 out[bytes++] = switch_b64_table[((b % 16) << (6 - l)) % 64]; 00528 } 00529 if (l != 0) { 00530 while (l < 6) { 00531 out[bytes++] = '=', l += 2; 00532 } 00533 } 00534 00535 return SWITCH_STATUS_SUCCESS; 00536 }
| int switch_build_uri | ( | char * | uri, | |
| switch_size_t | size, | |||
| const char * | scheme, | |||
| const char * | user, | |||
| const switch_sockaddr_t * | sa, | |||
| int | flags | |||
| ) |
build a URI string from components
| uri | output string | |
| size | maximum size of output string (including trailing null) | |
| scheme | URI scheme | |
| user | user part or null if none | |
| sa | host address | |
| flags | logical OR-ed combination of flags from switch_uri_flags |
Definition at line 1753 of file switch_utils.c.
References switch_snprintf(), SWITCH_URI_NO_SCOPE, SWITCH_URI_NUMERIC_HOST, and SWITCH_URI_NUMERIC_PORT.
01754 { 01755 char host[NI_MAXHOST], serv[NI_MAXSERV]; 01756 struct sockaddr_in6 si6; 01757 const struct sockaddr *addr; 01758 const char *colon; 01759 01760 if (flags & SWITCH_URI_NO_SCOPE && sa->family == AF_INET6) { 01761 memcpy(&si6, &sa->sa, sa->salen); 01762 si6.sin6_scope_id = 0; 01763 01764 addr = (const struct sockaddr *) &si6; 01765 } else { 01766 addr = (const struct sockaddr *) (intptr_t) & sa->sa; 01767 } 01768 01769 if (getnameinfo(addr, sa->salen, host, sizeof(host), serv, sizeof(serv), 01770 ((flags & SWITCH_URI_NUMERIC_HOST) ? NI_NUMERICHOST : 0) | ((flags & SWITCH_URI_NUMERIC_PORT) ? NI_NUMERICSERV : 0)) != 0) { 01771 return 0; 01772 } 01773 01774 colon = strchr(host, ':'); 01775 01776 return switch_snprintf(uri, size, "%s:%s%s%s%s%s%s%s", scheme, 01777 user ? user : "", user ? "@" : "", colon ? "[" : "", host, colon ? "]" : "", serv[0] ? ":" : "", serv[0] ? serv : ""); 01778 }
| unsigned char switch_char_to_rfc2833 | ( | char | key | ) |
Return the RFC2833 event based on an key character.
| key | the charecter to encode |
Definition at line 1788 of file switch_utils.c.
References switch_toupper().
01789 { 01790 char *c; 01791 unsigned char counter = 0; 01792 01793 key = (char) switch_toupper(key); 01794 for (c = RFC2833_CHARS; *c; c++) { 01795 if (*c == key) { 01796 return counter; 01797 } 01798 counter++; 01799 } 01800 return '\0'; 01801 }
| static char* switch_clean_name_string | ( | char * | s | ) | [inline, static] |
Definition at line 511 of file switch_utils.h.
00512 { 00513 char *p; 00514 for (p = s; p && *p; p++) { 00515 uint8_t x = (uint8_t) * p; 00516 if ((x < 32) || x == '\'' || x == '"' || x == '<' || x == '>' || x == '\\' || x == ':' || x == '@' || x == '/') { 00517 *p = ' '; 00518 } 00519 if ( (p == s) && (*p == ' ') ) { 00520 s++; 00521 } 00522 } 00523 00524 return s; 00525 }
| static char* switch_clean_string | ( | char * | s | ) | [inline, static] |
Definition at line 497 of file switch_utils.h.
00498 { 00499 char *p; 00500 for (p = s; p && *p; p++) { 00501 uint8_t x = (uint8_t) * p; 00502 if ((x < 32) && x != '\n' && x != '\r') { 00503 *p = ' '; 00504 } 00505 } 00506 00507 return s; 00508 }
| int switch_cmp_addr | ( | switch_sockaddr_t * | sa1, | |
| switch_sockaddr_t * | sa2 | |||
| ) |
Definition at line 1662 of file switch_utils.c.
Referenced by rtp_common_read().
01663 { 01664 struct sockaddr_in *s1; 01665 struct sockaddr_in *s2; 01666 01667 struct sockaddr_in6 *s16; 01668 struct sockaddr_in6 *s26; 01669 01670 struct sockaddr *ss1; 01671 struct sockaddr *ss2; 01672 01673 if (!(sa1 && sa2)) 01674 return 0; 01675 01676 s1 = (struct sockaddr_in *) &sa1->sa; 01677 s2 = (struct sockaddr_in *) &sa2->sa; 01678 01679 s16 = (struct sockaddr_in6 *) &sa1->sa; 01680 s26 = (struct sockaddr_in6 *) &sa2->sa; 01681 01682 ss1 = (struct sockaddr *) &sa1->sa; 01683 ss2 = (struct sockaddr *) &sa2->sa; 01684 01685 if (ss1->sa_family != ss2->sa_family) 01686 return 0; 01687 01688 switch (ss1->sa_family) { 01689 case AF_INET: 01690 return (s1->sin_addr.s_addr == s2->sin_addr.s_addr && s1->sin_port == s2->sin_port); 01691 case AF_INET6: 01692 if (s16->sin6_addr.s6_addr && s26->sin6_addr.s6_addr) { 01693 int i; 01694 01695 if (s16->sin6_port != s26->sin6_port) 01696 return 0; 01697 01698 for (i = 0; i < 4; i++) { 01699 if (*((int32_t *) s16->sin6_addr.s6_addr + i) != *((int32_t *) s26->sin6_addr.s6_addr + i)) 01700 return 0; 01701 } 01702 01703 return 1; 01704 } 01705 } 01706 01707 return 0; 01708 }
| const char* switch_cut_path | ( | const char * | in | ) |
Create a pointer to the file name in a given file path eliminating the directory name.
Definition at line 2100 of file switch_utils.c.
Referenced by switch_console_printf(), switch_event_prep_for_delivery_detailed(), switch_loadable_module_load_module_ex(), switch_log_vprintf(), and switch_simple_email().
02101 { 02102 const char *p, *ret = in; 02103 const char delims[] = "/\\"; 02104 const char *i; 02105 02106 if (in) { 02107 for (i = delims; *i; i++) { 02108 p = in; 02109 while ((p = strchr(p, *i)) != 0) { 02110 ret = ++p; 02111 } 02112 } 02113 return ret; 02114 } else { 02115 return NULL; 02116 } 02117 }
| switch_bool_t switch_dow_cmp | ( | const char * | exp, | |
| int | val | |||
| ) |
Definition at line 2734 of file switch_utils.c.
References _dow_read_token(), DOW_COMA, DOW_EOF, DOW_ERR, DOW_HYPHEN, SWITCH_CHANNEL_LOG, SWITCH_FALSE, SWITCH_LOG_ERROR, switch_log_printf(), and SWITCH_TRUE.
Referenced by switch_xml_std_datetime_check().
02735 { 02736 dow_t cur, prev = DOW_EOF, range_start = DOW_EOF; 02737 const char *p = exp; 02738 02739 while ((cur = _dow_read_token(&p)) != DOW_EOF) { 02740 if (cur == DOW_COMA) { 02741 /* Reset state */ 02742 cur = prev = DOW_EOF; 02743 } else if (cur == DOW_HYPHEN) { 02744 /* Save the previous token and move to the next one */ 02745 range_start = prev; 02746 } else if (cur == DOW_ERR) { 02747 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse error for [%s] at position %ld (%.6s)\n", exp, (long) (p - exp), p); 02748 break; 02749 } else { 02750 /* Valid day found */ 02751 if (range_start != DOW_EOF) { /* Evaluating a range */ 02752 if (val >= range_start && val <= cur) { 02753 return SWITCH_TRUE; 02754 } 02755 range_start = DOW_EOF; 02756 } else if (val == cur) { 02757 return SWITCH_TRUE; 02758 } 02759 } 02760 02761 prev = cur; 02762 } 02763 02764 return SWITCH_FALSE; 02765 }
| const char* switch_dow_int2str | ( | int | val | ) |
Definition at line 2676 of file switch_utils.c.
References switch_arraylen.
Referenced by switch_xml_std_datetime_check().
02676 { 02677 if (val >= switch_arraylen(DOW)) { 02678 val = val % switch_arraylen(DOW); 02679 } 02680 return DOW[val]; 02681 }
| int switch_dow_str2int | ( | const char * | exp | ) |
Definition at line 2683 of file switch_utils.c.
References switch_arraylen.
Referenced by _dow_read_token().
02683 { 02684 int ret = -1; 02685 int x; 02686 02687 for (x = 0; x < switch_arraylen(DOW); x++) { 02688 if (!strncasecmp(DOW[x], exp, 3)) { 02689 ret = x + 1; 02690 break; 02691 } 02692 } 02693 return ret; 02694 }
| static int switch_dtmftoi | ( | char * | s | ) | [inline, static] |
Definition at line 204 of file switch_utils.h.
References switch_assert.
Referenced by meta_on_dtmf(), and switch_ivr_bind_dtmf_meta_session().
00205 { 00206 int r; 00207 00208 switch_assert(s); 00209 00210 if (!(r = atoi(s))) { 00211 int l = tolower(*s); 00212 if (l > 96 && l < 101) { 00213 r = l - 87; 00214 } 00215 } 00216 00217 return r; 00218 }
| char* switch_escape_char | ( | switch_memory_pool_t * | pool, | |
| char * | in, | |||
| const char * | delim, | |||
| char | esc | |||
| ) |
Escape a string by prefixing a list of characters with an escape character.
| pool | a memory pool to use | |
| in | the string | |
| delim | the list of characters to escape | |
| esc | the escape character |
Definition at line 1803 of file switch_utils.c.
References switch_core_alloc.
01804 { 01805 char *data; 01806 const char *p, *d; 01807 int count = 1, i = 0; 01808 01809 p = in; 01810 while (*p) { 01811 d = delim; 01812 while (*d) { 01813 if (*p == *d) { 01814 count++; 01815 } 01816 d++; 01817 } 01818 p++; 01819 } 01820 01821 if (count == 1) { 01822 return in; 01823 } 01824 01825 data = switch_core_alloc(pool, strlen(in) + count); 01826 01827 p = in; 01828 while (*p) { 01829 d = delim; 01830 while (*d) { 01831 if (*p == *d) { 01832 data[i++] = esc; 01833 } 01834 d++; 01835 } 01836 data[i++] = *p; 01837 p++; 01838 } 01839 return data; 01840 }
| char* switch_escape_string | ( | const char * | in, | |
| char * | out, | |||
| switch_size_t | outlen | |||
| ) |
Definition at line 1874 of file switch_utils.c.
Referenced by switch_escape_string_pool().
01875 { 01876 const char *p; 01877 char *o = out; 01878 01879 for (p = in; *p; p++) { 01880 switch (*p) { 01881 case '\n': 01882 *o++ = '\\'; 01883 *o++ = 'n'; 01884 break; 01885 case '\r': 01886 *o++ = '\\'; 01887 *o++ = 'r'; 01888 break; 01889 case '\t': 01890 *o++ = '\\'; 01891 *o++ = 't'; 01892 break; 01893 case ' ': 01894 *o++ = '\\'; 01895 *o++ = 's'; 01896 break; 01897 case '$': 01898 *o++ = '\\'; 01899 *o++ = '$'; 01900 break; 01901 default: 01902 *o++ = *p; 01903 break; 01904 } 01905 } 01906 01907 *o++ = '\0'; 01908 01909 return out; 01910 }
| char* switch_escape_string_pool | ( | const char * | in, | |
| switch_memory_pool_t * | pool | |||
| ) |
Definition at line 1912 of file switch_utils.c.
References buf, switch_core_alloc, and switch_escape_string().
01913 { 01914 int len = strlen(in) * 2; 01915 char *buf = switch_core_alloc(pool, len); 01916 return switch_escape_string(in, buf, len); 01917 }
| static int switch_false | ( | const char * | expr | ) | [inline, static] |
Evaluate the falsefullness of a string expression.
| expr | a string expression |
Definition at line 275 of file switch_utils.h.
References SWITCH_FALSE, switch_is_number(), and SWITCH_TRUE.
00276 { 00277 return ((expr && ( !strcasecmp(expr, "no") || 00278 !strcasecmp(expr, "off") || 00279 !strcasecmp(expr, "false") || 00280 !strcasecmp(expr, "disabled") || 00281 !strcasecmp(expr, "inactive") || 00282 !strcasecmp(expr, "disallow") || 00283 (switch_is_number(expr) && !atoi(expr)))) ? SWITCH_TRUE : SWITCH_FALSE); 00284 }
| switch_size_t switch_fd_read_line | ( | int | fd, | |
| char * | buf, | |||
| switch_size_t | len | |||
| ) |
Definition at line 436 of file switch_utils.c.
Referenced by load_mime_types(), preprocess(), and switch_stream_write_file_contents().
00437 { 00438 char c, *p; 00439 int cur; 00440 switch_size_t total = 0; 00441 00442 p = buf; 00443 while (total + 2 < len && (cur = read(fd, &c, 1)) == 1) { 00444 total += cur; 00445 *p++ = c; 00446 if (c == '\r' || c == '\n') { 00447 break; 00448 } 00449 } 00450 00451 *p++ = '\0'; 00452 assert(total < len); 00453 return total; 00454 }
| char* switch_find_end_paren | ( | const char * | s, | |
| char | open, | |||
| char | close | |||
| ) |
Definition at line 410 of file switch_utils.c.
Referenced by expand_vars(), switch_core_asr_load_grammar(), switch_core_perform_file_open(), switch_core_speech_feed_tts(), switch_event_create_brackets(), switch_is_file_path(), switch_ivr_displace_session(), switch_ivr_play_file(), switch_ivr_record_file(), and switch_ivr_record_session().
00411 { 00412 const char *e = NULL; 00413 int depth = 0; 00414 00415 while (s && *s && *s == ' ') { 00416 s++; 00417 } 00418 00419 if (s && *s == open) { 00420 depth++; 00421 for (e = s + 1; e && *e; e++) { 00422 if (*e == open && open != close) { 00423 depth++; 00424 } else if (*e == close) { 00425 depth--; 00426 if (!depth) { 00427 break; 00428 } 00429 } 00430 } 00431 } 00432 00433 return (e && *e == close) ? (char *) e : NULL; 00434 }
| switch_status_t switch_find_local_ip | ( | _Out_opt_bytecapcount_(len) char * | buf, | |
| _In_ int | len, | |||
| _In_opt_ int * | mask, | |||
| _In_ int | family | |||
| ) |
find local ip of the box
| buf | the buffer to write the ip adress found into | |
| len | the length of the buf | |
| family | the address family to return (AF_INET or AF_INET6) |
Referenced by check_ip(), switch_core_init(), switch_event_init(), switch_load_network_lists(), and switch_nat_init().
| char* switch_find_parameter | ( | const char * | str, | |
| const char * | param, | |||
| switch_memory_pool_t * | pool | |||
| ) |
Definition at line 126 of file switch_utils.c.
References switch_network_node::next, switch_core_alloc, and switch_snprintf().
00127 { 00128 char *e, *r = NULL, *ptr = NULL, *next = NULL; 00129 size_t len; 00130 00131 ptr = (char *) str; 00132 00133 while (ptr) { 00134 len = strlen(param); 00135 e = ptr+len; 00136 next = strchr(ptr, ';'); 00137 00138 if (!strncasecmp(ptr, param, len) && *e == '=') { 00139 int mlen; 00140 00141 ptr = ++e; 00142 00143 if (next) { 00144 e = next; 00145 } else { 00146 e = ptr + strlen(ptr); 00147 } 00148 00149 mlen = (e - ptr) + 1; 00150 00151 if (pool) { 00152 r = switch_core_alloc(pool, mlen); 00153 } else { 00154 r = malloc(mlen); 00155 } 00156 00157 *(r + mlen) = '\0'; 00158 00159 switch_snprintf(r, mlen, "%s", ptr); 00160 00161 break; 00162 } 00163 00164 if (next) { 00165 ptr = next + 1; 00166 } else break; 00167 } 00168 00169 return r; 00170 }
| char* switch_format_number | ( | const char * | num | ) |
Definition at line 2909 of file switch_utils.c.
References switch_is_number(), switch_mprintf(), and zstr.
02910 { 02911 char *r; 02912 size_t len; 02913 const char *p = num; 02914 02915 if (!p) { 02916 return (char*)p; 02917 } 02918 02919 if (zstr(p)) { 02920 return strdup(p); 02921 } 02922 02923 if (*p == '+') { 02924 p++; 02925 } 02926 02927 if (!switch_is_number(p)) { 02928 return strdup(p); 02929 } 02930 02931 len = strlen(p); 02932 02933 /* region 1, TBD add more....*/ 02934 if (len == 11 && p[0] == '1') { 02935 r = switch_mprintf("%c (%c%c%c) %c%c%c-%c%c%c%c", p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8],p[9],p[10]); 02936 } else if (len == 10) { 02937 r = switch_mprintf("1 (%c%c%c) %c%c%c-%c%c%c%c", p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8],p[9]); 02938 } else { 02939 r = strdup(num); 02940 } 02941 02942 return r; 02943 }
| switch_status_t switch_frame_alloc | ( | switch_frame_t ** | frame, | |
| switch_size_t | size | |||
| ) |
Definition at line 67 of file switch_utils.c.
References SFF_DYNAMIC, switch_assert, switch_set_flag, SWITCH_STATUS_SUCCESS, and switch_zmalloc.
00068 { 00069 switch_frame_t *new_frame; 00070 00071 switch_zmalloc(new_frame, sizeof(*new_frame)); 00072 00073 switch_set_flag(new_frame, SFF_DYNAMIC); 00074 new_frame->buflen = size; 00075 new_frame->data = malloc(size); 00076 switch_assert(new_frame->data); 00077 00078 *frame = new_frame; 00079 00080 return SWITCH_STATUS_SUCCESS; 00081 }
| switch_status_t switch_frame_dup | ( | switch_frame_t * | orig, | |
| switch_frame_t ** | clone | |||
| ) |
Definition at line 84 of file switch_utils.c.
References SFF_DYNAMIC, switch_assert, switch_set_flag, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.
00085 { 00086 switch_frame_t *new_frame; 00087 00088 if (!orig) { 00089 return SWITCH_STATUS_FALSE; 00090 } 00091 00092 switch_assert(orig->buflen); 00093 00094 new_frame = malloc(sizeof(*new_frame)); 00095 00096 switch_assert(new_frame); 00097 00098 *new_frame = *orig; 00099 switch_set_flag(new_frame, SFF_DYNAMIC); 00100 00101 new_frame->data = malloc(new_frame->buflen); 00102 switch_assert(new_frame->data); 00103 00104 memcpy(new_frame->data, orig->data, orig->datalen); 00105 new_frame->codec = NULL; 00106 00107 *clone = new_frame; 00108 00109 return SWITCH_STATUS_SUCCESS; 00110 }
| switch_status_t switch_frame_free | ( | switch_frame_t ** | frame | ) |
Definition at line 112 of file switch_utils.c.
References SFF_DYNAMIC, switch_safe_free, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_test_flag.
00113 { 00114 if (!frame || !*frame || !switch_test_flag((*frame), SFF_DYNAMIC)) { 00115 return SWITCH_STATUS_FALSE; 00116 } 00117 00118 switch_safe_free((*frame)->data); 00119 free(*frame); 00120 *frame = NULL; 00121 00122 return SWITCH_STATUS_SUCCESS; 00123 }
| int switch_fulldate_cmp | ( | const char * | exp, | |
| switch_time_t * | ts | |||
| ) |
Definition at line 2358 of file switch_utils.c.
References switch_assert, switch_safe_free, switch_split_date(), and switch_split_time().
Referenced by switch_xml_std_datetime_check().
02359 { 02360 char *dup = strdup(exp); 02361 char *sStart; 02362 char *sEnd; 02363 char *sDate; 02364 char *sTime; 02365 switch_time_t tsStart; 02366 switch_time_t tsEnd; 02367 struct tm tmTmp; 02368 int year, month, day; 02369 int hour, min, sec; 02370 02371 switch_assert(dup); 02372 02373 sStart = dup; 02374 if ((sEnd=strchr(dup, '~'))) { 02375 *sEnd++ = '\0'; 02376 sDate = sStart; 02377 if ((sTime=strchr(sStart, ' '))) { 02378 *sTime++ = '\0'; 02379 02380 memset(&tmTmp, 0, sizeof(tmTmp)); 02381 switch_split_date(sDate, &year, &month, &day); 02382 switch_split_time(sTime, &hour, &min, &sec); 02383 tmTmp.tm_year = year-1900; 02384 tmTmp.tm_mon = month-1; 02385 tmTmp.tm_mday = day; 02386 02387 tmTmp.tm_hour = hour; 02388 tmTmp.tm_min = min; 02389 tmTmp.tm_sec = sec; 02390 tmTmp.tm_isdst = 0; 02391 tsStart = mktime(&tmTmp); 02392 02393 sDate = sEnd; 02394 if ((sTime=strchr(sEnd, ' '))) { 02395 *sTime++ = '\0'; 02396 02397 memset(&tmTmp, 0, sizeof(tmTmp)); 02398 switch_split_date(sDate, &year, &month, &day); 02399 switch_split_time(sTime, &hour, &min, &sec); 02400 tmTmp.tm_year = year-1900; 02401 tmTmp.tm_mon = month-1; 02402 tmTmp.tm_mday = day; 02403 02404 tmTmp.tm_hour = hour; 02405 tmTmp.tm_min = min; 02406 tmTmp.tm_sec = sec; 02407 tmTmp.tm_isdst = 0; 02408 tsEnd = mktime(&tmTmp); 02409 02410 if (tsStart <= *ts/1000000 && tsEnd > *ts/1000000) { 02411 switch_safe_free(dup); 02412 return 1; 02413 } 02414 } 02415 } 02416 } 02417 switch_safe_free(dup); 02418 return 0; 02419 02420 }
| int switch_inet_pton | ( | int | af, | |
| const char * | src, | |||
| void * | dst | |||
| ) |
Definition at line 73 of file inet_pton.c.
Referenced by switch_check_network_list_ip_token(), switch_core_set_serial(), switch_find_local_ip(), switch_network_list_add_host_mask(), and switch_parse_cidr().
00074 { 00075 switch (af) { 00076 case AF_INET: 00077 return (inet_pton4(src, (unsigned char *) dst)); 00078 #ifdef ENABLE_IPV6 00079 #ifndef AF_INET6 00080 #define AF_INET6 (AF_MAX+1) /* just to let this compile */ 00081 #endif 00082 case AF_INET6: 00083 return (inet_pton6(src, (unsigned char *) dst)); 00084 #endif 00085 default: 00086 errno = EAFNOSUPPORT; 00087 return (-1); 00088 } 00089 /* NOTREACHED */ 00090 }
| static switch_bool_t switch_is_digit_string | ( | const char * | s | ) | [inline, static] |
Definition at line 178 of file switch_utils.h.
References SWITCH_FALSE, and SWITCH_TRUE.
00179 { 00180 00181 while (s && *s) { 00182 if (*s < 48 || *s > 57) { 00183 return SWITCH_FALSE; 00184 } 00185 s++; 00186 } 00187 00188 return SWITCH_TRUE; 00189 }
| static switch_bool_t switch_is_file_path | ( | const char * | file | ) | [inline, static] |
Definition at line 751 of file switch_utils.h.
References SWITCH_FALSE, switch_find_end_paren(), SWITCH_PATH_SEPARATOR, SWITCH_TRUE, and SWITCH_URL_SEPARATOR.
Referenced by db_pick_path(), enterprise_originate_ringback_thread(), preprocess_glob(), setup_ringback(), switch_config_open_file(), switch_ivr_displace_session(), switch_ivr_play_file(), switch_ivr_record_file(), switch_ivr_record_session(), switch_ivr_wait_for_answer(), switch_loadable_module_load_module_ex(), and switch_stream_write_file_contents().
00752 { 00753 const char *e; 00754 int r; 00755 00756 if (*file == '[' && *(file + 1) == *SWITCH_PATH_SEPARATOR) { 00757 if ((e = switch_find_end_paren(file, '[', ']'))) { 00758 file = e + 1; 00759 } 00760 } 00761 #ifdef WIN32 00762 r = (file && (*file == '\\' || *(file + 1) == ':' || *file == '/' || strstr(file, SWITCH_URL_SEPARATOR))); 00763 #else 00764 r = (file && ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR))); 00765 #endif 00766 00767 return r ? SWITCH_TRUE : SWITCH_FALSE; 00768 00769 }
| switch_bool_t switch_is_lan_addr | ( | const char * | ip | ) |
Definition at line 800 of file switch_utils.c.
References SWITCH_FALSE, SWITCH_TRUE, and zstr.
00801 { 00802 if (zstr(ip)) 00803 return SWITCH_FALSE; 00804 00805 return (strncmp(ip, "10.", 3) && /* 10.0.0.0 - 10.255.255.255 (10/8 prefix) */ 00806 strncmp(ip, "192.168.", 8) && /* 192.168.0.0 - 192.168.255.255 (192.168/16 prefix) */ 00807 strncmp(ip, "127.", 4) && /* 127.0.0.0 - 127.255.255.255 (127/8 prefix) */ 00808 strncmp(ip, "255.", 4) && 00809 strncmp(ip, "0.", 2) && 00810 strncmp(ip, "1.", 2) && 00811 strncmp(ip, "2.", 2) && 00812 strncmp(ip, "172.16.", 7) && /* 172.16.0.0 - 172.31.255.255 (172.16/12 prefix) */ 00813 strncmp(ip, "172.17.", 7) && 00814 strncmp(ip, "172.18.", 7) && 00815 strncmp(ip, "172.19.", 7) && 00816 strncmp(ip, "172.20.", 7) && 00817 strncmp(ip, "172.21.", 7) && 00818 strncmp(ip, "172.22.", 7) && 00819 strncmp(ip, "172.23.", 7) && 00820 strncmp(ip, "172.24.", 7) && 00821 strncmp(ip, "172.25.", 7) && 00822 strncmp(ip, "172.26.", 7) && 00823 strncmp(ip, "172.27.", 7) && 00824 strncmp(ip, "172.28.", 7) && 00825 strncmp(ip, "172.29.", 7) && 00826 strncmp(ip, "172.30.", 7) && 00827 strncmp(ip, "172.31.", 7) && 00828 strncmp(ip, "192.0.2.", 8) && /* 192.0.2.0 - 192.0.2.255 (192.0.2/24 prefix) */ 00829 strncmp(ip, "169.254.", 8) /* 169.254.0.0 - 169.254.255.255 (169.254/16 prefix) */ 00830 )? SWITCH_FALSE : SWITCH_TRUE; 00831 }
| static switch_bool_t switch_is_moh | ( | const char * | s | ) | [inline, static] |
Definition at line 94 of file switch_utils.h.
References SWITCH_FALSE, SWITCH_TRUE, and zstr.
Referenced by switch_ivr_parse_event().
00095 { 00096 if (zstr(s) || !strcasecmp(s, "silence") || !strcasecmp(s, "indicate_hold")) { 00097 return SWITCH_FALSE; 00098 } 00099 return SWITCH_TRUE; 00100 }
| switch_bool_t switch_is_number | ( | const char * | str | ) |
Definition at line 1024 of file switch_utils.c.
References SWITCH_FALSE, and SWITCH_TRUE.
Referenced by switch_channel_perform_mark_answered(), switch_false(), switch_format_number(), switch_log_str2level(), switch_true(), switch_xml_config_parse_event(), and switch_xml_std_datetime_check().
01025 { 01026 const char *p; 01027 switch_bool_t r = SWITCH_TRUE; 01028 01029 if (*str == '-' || *str == '+') { 01030 str++; 01031 } 01032 01033 for (p = str; p && *p; p++) { 01034 if (!(*p == '.' || (*p > 47 && *p < 58))) { 01035 r = SWITCH_FALSE; 01036 break; 01037 } 01038 } 01039 01040 return r; 01041 }
| int switch_isalnum | ( | int | c | ) |
Definition at line 2612 of file switch_utils.c.
02613 { 02614 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & (_U | _L | _N))); 02615 }
| int switch_isalpha | ( | int | c | ) |
Definition at line 2617 of file switch_utils.c.
02618 { 02619 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & (_U | _L))); 02620 }
| int switch_iscntrl | ( | int | c | ) |
Definition at line 2622 of file switch_utils.c.
References _C.
02623 { 02624 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & _C)); 02625 }
| int switch_isdigit | ( | int | c | ) |
Definition at line 2627 of file switch_utils.c.
References _N.
02628 { 02629 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & _N)); 02630 }
| int switch_isgraph | ( | int | c | ) |
Definition at line 2632 of file switch_utils.c.
02633 { 02634 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & (_P | _U | _L | _N))); 02635 }
| int switch_islower | ( | int | c | ) |
Definition at line 2637 of file switch_utils.c.
References _L.
02638 { 02639 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & _L)); 02640 }
| int switch_isprint | ( | int | c | ) |
| int switch_ispunct | ( | int | c | ) |
Definition at line 2647 of file switch_utils.c.
02648 { 02649 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & _P)); 02650 }
| int switch_isspace | ( | int | c | ) |
Definition at line 2652 of file switch_utils.c.
References _S.
02653 { 02654 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & _S)); 02655 }
| int switch_isupper | ( | int | c | ) |
Definition at line 2657 of file switch_utils.c.
References _U.
02658 { 02659 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & _U)); 02660 }
| int switch_isxdigit | ( | int | c | ) |
Definition at line 2662 of file switch_utils.c.
02663 { 02664 return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & (_N | _X))); 02665 }
| static char switch_itodtmf | ( | char | i | ) | [inline, static] |
Definition at line 191 of file switch_utils.h.
Referenced by switch_ivr_bind_dtmf_meta_session().
00192 { 00193 char r = i; 00194 00195 if (i > 9 && i < 14) { 00196 r += 55; 00197 } else { 00198 r += 48; 00199 } 00200 00201 return r; 00202 }
| static uint32_t switch_known_bitrate | ( | switch_payload_t | payload | ) | [inline, static] |
Definition at line 220 of file switch_utils.h.
00221 { 00222 switch(payload) { 00223 case 0: /* PCMU */ return 64000; 00224 case 3: /* GSM */ return 13200; 00225 case 4: /* G723 */ return 6300; 00226 case 7: /* LPC */ return 2400; 00227 case 8: /* PCMA */ return 64000; 00228 case 9: /* G722 */ return 64000; 00229 case 18: /* G729 */ return 8000; 00230 default: break; 00231 } 00232 00233 return 0; 00234 }
| static char* switch_lc_strdup | ( | const char * | it | ) | [inline, static] |
Definition at line 560 of file switch_utils.h.
References switch_tolower().
00561 { 00562 char *dup; 00563 char *p; 00564 00565 if (it) { 00566 dup = strdup(it); 00567 for (p = dup; p && *p; p++) { 00568 *p = (char) switch_tolower(*p); 00569 } 00570 return dup; 00571 } 00572 00573 return NULL; 00574 }
| switch_status_t switch_network_list_add_cidr_token | ( | switch_network_list_t * | list, | |
| const char * | cidr_str, | |||
| switch_bool_t | ok, | |||
| const char * | token | |||
| ) |
Definition at line 301 of file switch_utils.c.
References switch_assert, switch_network_list_perform_add_cidr_token(), switch_safe_free, switch_separate_string(), and SWITCH_STATUS_SUCCESS.
Referenced by switch_load_network_lists().
00302 { 00303 char *cidr_str_dup = NULL; 00304 switch_status_t status = SWITCH_STATUS_SUCCESS; 00305 00306 if (strchr(cidr_str, ',')) { 00307 char *argv[32] = { 0 }; 00308 int i, argc; 00309 cidr_str_dup = strdup(cidr_str); 00310 00311 switch_assert(cidr_str_dup); 00312 if ((argc = switch_separate_string(cidr_str_dup, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) { 00313 for (i = 0; i < argc; i++) { 00314 switch_status_t this_status; 00315 if ((this_status = switch_network_list_perform_add_cidr_token(list, argv[i], ok, token)) != SWITCH_STATUS_SUCCESS) { 00316 status = this_status; 00317 } 00318 } 00319 } 00320 } else { 00321 status = switch_network_list_perform_add_cidr_token(list, cidr_str, ok, token); 00322 } 00323 00324 switch_safe_free(cidr_str_dup); 00325 return status; 00326 }
| switch_status_t switch_network_list_add_host_mask | ( | switch_network_list_t * | list, | |
| const char * | host, | |||
| const char * | mask_str, | |||
| switch_bool_t | ok | |||
| ) |
Definition at line 328 of file switch_utils.c.
References switch_core_alloc, switch_core_sprintf(), switch_inet_pton(), SWITCH_STATUS_SUCCESS, and ip_t::v4.
Referenced by switch_load_network_lists().
00329 { 00330 ip_t ip, mask; 00331 switch_network_node_t *node; 00332 00333 switch_inet_pton(AF_INET, host, &ip); 00334 switch_inet_pton(AF_INET, mask_str, &mask); 00335 00336 node = switch_core_alloc(list->pool, sizeof(*node)); 00337 00338 node->ip.v4 = ntohl(ip.v4); 00339 node->mask.v4 = ntohl(mask.v4); 00340 node->ok = ok; 00341 00342 /* http://graphics.stanford.edu/~seander/bithacks.html */ 00343 mask.v4 = mask.v4 - ((mask.v4 >> 1) & 0x55555555); 00344 mask.v4 = (mask.v4 & 0x33333333) + ((mask.v4 >> 2) & 0x33333333); 00345 node->bits = (((mask.v4 + (mask.v4 >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; 00346 00347 node->str = switch_core_sprintf(list->pool, "%s:%s", host, mask_str); 00348 00349 node->next = list->node_head; 00350 list->node_head = node; 00351 00352 return SWITCH_STATUS_SUCCESS; 00353 }
| switch_status_t switch_network_list_create | ( | switch_network_list_t ** | list, | |
| const char * | name, | |||
| switch_bool_t | default_type, | |||
| switch_memory_pool_t * | pool | |||
| ) |
Definition at line 172 of file switch_utils.c.
References switch_network_list::default_type, switch_network_list::name, switch_network_list::pool, switch_core_alloc, switch_core_new_memory_pool, switch_core_strdup, and SWITCH_STATUS_SUCCESS.
Referenced by switch_load_network_lists().
00174 { 00175 switch_network_list_t *new_list; 00176 00177 if (!pool) { 00178 switch_core_new_memory_pool(&pool); 00179 } 00180 00181 new_list = switch_core_alloc(pool, sizeof(**list)); 00182 new_list->pool = pool; 00183 new_list->default_type = default_type; 00184 new_list->name = switch_core_strdup(new_list->pool, name); 00185 00186 *list = new_list; 00187 00188 return SWITCH_STATUS_SUCCESS; 00189 }
| switch_bool_t switch_network_list_validate_ip6_token | ( | switch_network_list_t * | list, | |
| ip_t | ip, | |||
| const char ** | token | |||
| ) |
Definition at line 209 of file switch_utils.c.
References switch_network_node::bits, switch_network_node::family, switch_network_node::ip, switch_network_node::mask, switch_network_node::next, switch_network_node::ok, SWITCH_FALSE, switch_testv6_subnet(), SWITCH_TRUE, and switch_network_node::token.
Referenced by switch_check_network_list_ip_token().
00210 { 00211 switch_network_node_t *node; 00212 switch_bool_t ok = list->default_type; 00213 uint32_t bits = 0; 00214 00215 for (node = list->node_head; node; node = node->next) { 00216 if (node->family == AF_INET) continue; 00217 if (node->bits > bits && switch_testv6_subnet(ip, node->ip, node->mask)) { 00218 if (node->ok) { 00219 ok = SWITCH_TRUE; 00220 } else { 00221 ok = SWITCH_FALSE; 00222 } 00223 00224 bits = node->bits; 00225 00226 if (token) { 00227 *token = node->token; 00228 } 00229 } 00230 } 00231 00232 return ok; 00233 }
| switch_bool_t switch_network_list_validate_ip_token | ( | switch_network_list_t * | list, | |
| uint32_t | ip, | |||
| const char ** | token | |||
| ) |
Definition at line 235 of file switch_utils.c.
References switch_network_node::bits, switch_network_node::family, switch_network_node::ip, switch_network_node::mask, switch_network_node::next, switch_network_node::ok, SWITCH_FALSE, switch_test_subnet, SWITCH_TRUE, switch_network_node::token, and ip_t::v4.
Referenced by switch_check_network_list_ip_token().
00236 { 00237 switch_network_node_t *node; 00238 switch_bool_t ok = list->default_type; 00239 uint32_t bits = 0; 00240 00241 for (node = list->node_head; node; node = node->next) { 00242 if (node->family == AF_INET6) continue; /* want AF_INET */ 00243 if (node->bits > bits && switch_test_subnet(ip, node->ip.v4, node->mask.v4)) { 00244 if (node->ok) { 00245 ok = SWITCH_TRUE; 00246 } else { 00247 ok = SWITCH_FALSE; 00248 } 00249 00250 bits = node->bits; 00251 00252 if (token) { 00253 *token = node->token; 00254 } 00255 } 00256 } 00257 00258 return ok; 00259 }
| int switch_number_cmp | ( | const char * | exp, | |
| int | val | |||
| ) |
Definition at line 2767 of file switch_utils.c.
Referenced by switch_xml_std_datetime_check().
02768 { 02769 char *p; 02770 02771 if ((p = strchr(exp, '-'))) { 02772 int min; 02773 int max; 02774 02775 min = atol(exp); 02776 p++; 02777 max = atol(p); 02778 02779 if (val >= min && val <= max) { 02780 return 1; 02781 } 02782 } else if ((p = strchr(exp, ','))) { 02783 const char *cur = exp; 02784 p++; 02785 while (cur) { 02786 if (atol(cur) == val) { 02787 return 1; 02788 } 02789 02790 cur = p; 02791 if (p && p + 1) { 02792 if ((p = strchr((p + 1), ','))) { 02793 p++; 02794 } 02795 } 02796 } 02797 } else { 02798 if (atol(exp) == val) { 02799 return 1; 02800 } 02801 } 02802 02803 return 0; 02804 02805 }
Definition at line 356 of file switch_utils.c.
References switch_copy_string(), switch_inet_pton(), ip_t::v4, and ip_t::v6.
Referenced by switch_check_network_list_ip_token(), and switch_network_list_perform_add_cidr_token().
00357 { 00358 char host[128]; 00359 char *bit_str; 00360 int32_t bits; 00361 const char *ipv6; 00362 ip_t *maskv = mask; 00363 ip_t *ipv = ip; 00364 00365 switch_copy_string(host, string, sizeof(host)-1); 00366 bit_str = strchr(host, '/'); 00367 00368 if (!bit_str) { 00369 return -1; 00370 } 00371 00372 *bit_str++ = '\0'; 00373 bits = atoi(bit_str); 00374 ipv6 = strchr(string, ':'); 00375 if (ipv6) { 00376 int i,n; 00377 if (bits < 0 || bits > 128) { 00378 return -2; 00379 } 00380 bits = atoi(bit_str); 00381 switch_inet_pton(AF_INET6, host, (unsigned char *)ip); 00382 for (n=bits,i=0 ;i < 16; i++){ 00383 if (n >= 8) { 00384 maskv->v6.s6_addr[i] = 0xFF; 00385 n -= 8; 00386 } else if (n < 8) { 00387 maskv->v6.s6_addr[i] = 0xFF & ~(0xFF >> n); 00388 n -= n; 00389 } else if (n == 0) { 00390 maskv->v6.s6_addr[i] = 0x00; 00391 } 00392 } 00393 } else { 00394 if (bits < 0 || bits > 32) { 00395 return -2; 00396 } 00397 00398 bits = atoi(bit_str); 00399 switch_inet_pton(AF_INET, host, (unsigned char *)ip); 00400 ipv->v4 = htonl(ipv->v4); 00401 00402 maskv->v4 = 0xFFFFFFFF & ~(0xFFFFFFFF >> bits); 00403 } 00404 *bitp = bits; 00405 00406 return 0; 00407 }
| const char* switch_priority_name | ( | switch_priority_t | priority | ) |
Return a printable name of a switch_priority_t.
| priority | the priority to get the name of |
Definition at line 1461 of file switch_utils.c.
References SWITCH_PRIORITY_HIGH, SWITCH_PRIORITY_LOW, and SWITCH_PRIORITY_NORMAL.
Referenced by switch_event_set_priority().
01462 { 01463 switch (priority) { /*lol */ 01464 case SWITCH_PRIORITY_NORMAL: 01465 return "NORMAL"; 01466 case SWITCH_PRIORITY_LOW: 01467 return "LOW"; 01468 case SWITCH_PRIORITY_HIGH: 01469 return "HIGH"; 01470 default: 01471 return "INVALID"; 01472 } 01473 }
| char* switch_replace_char | ( | char * | str, | |
| char | from, | |||
| char | to, | |||
| switch_bool_t | dup | |||
| ) |
Definition at line 864 of file switch_utils.c.
References switch_assert.
00865 { 00866 char *p; 00867 00868 if (dup) { 00869 p = strdup(str); 00870 switch_assert(p); 00871 } else { 00872 p = str; 00873 } 00874 00875 for (; p && *p; p++) { 00876 if (*p == from) { 00877 *p = to; 00878 } 00879 } 00880 00881 return p; 00882 }
| switch_status_t switch_resolve_host | ( | const char * | host, | |
| char * | buf, | |||
| size_t | buflen | |||
| ) |
Definition at line 1211 of file switch_utils.c.
References get_addr(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.
01212 { 01213 01214 struct addrinfo *ai; 01215 int err; 01216 01217 if ((err = getaddrinfo(host, 0, 0, &ai))) { 01218 return SWITCH_STATUS_FALSE; 01219 } 01220 01221 get_addr(buf, buflen, ai->ai_addr, sizeof(*ai->ai_addr)); 01222 01223 freeaddrinfo(ai); 01224 01225 return SWITCH_STATUS_SUCCESS; 01226 }
| char switch_rfc2833_to_char | ( | int | event | ) |
Return the RFC2833 character based on an event id.
| event | the event id to convert |
Definition at line 1780 of file switch_utils.c.
Referenced by handle_rfc2833().
01781 { 01782 if (event > -1 && event < (int32_t) sizeof(RFC2833_CHARS)) { 01783 return RFC2833_CHARS[event]; 01784 } 01785 return '\0'; 01786 }
| static int switch_safe_atoi | ( | const char * | nptr, | |
| int | dft | |||
| ) | [inline, static] |
Turn a string into a number (default if NULL).
| nptr | the string | |
| dft | the default |
Definition at line 535 of file switch_utils.h.
| static char* switch_safe_strdup | ( | const char * | it | ) | [inline, static] |
| static char* switch_sanitize_number | ( | char * | number | ) | [inline, static] |
Definition at line 424 of file switch_utils.h.
References switch_assert.
00425 { 00426 char *p = number, *q; 00427 char warp[] = "/:"; 00428 int i; 00429 00430 switch_assert(number); 00431 00432 if (!(strchr(p, '/') || strchr(p, ':') || strchr(p, '@'))) { 00433 return number; 00434 } 00435 00436 while ((q = strrchr(p, '@'))) 00437 *q = '\0'; 00438 00439 for (i = 0; i < (int) strlen(warp); i++) { 00440 while (p && (q = strchr(p, warp[i]))) 00441 p = q + 1; 00442 } 00443 00444 return p; 00445 }
| char* switch_separate_paren_args | ( | char * | str | ) |
Definition at line 995 of file switch_utils.c.
Referenced by switch_ivr_phrase_macro_event().
00996 { 00997 char *e, *args; 00998 switch_size_t br; 00999 01000 if ((args = strchr(str, '('))) { 01001 e = args - 1; 01002 *args++ = '\0'; 01003 while (*e == ' ') { 01004 *e-- = '\0'; 01005 } 01006 e = args; 01007 br = 1; 01008 while (e && *e) { 01009 if (*e == '(') { 01010 br++; 01011 } else if (br > 1 && *e == ')') { 01012 br--; 01013 } else if (br == 1 && *e == ')') { 01014 *e = '\0'; 01015 break; 01016 } 01017 e++; 01018 } 01019 } 01020 01021 return args; 01022 }
| unsigned int switch_separate_string | ( | _In_ char * | buf, | |
| char | delim, | |||
| _Post_count_(return) char ** | array, | |||
| unsigned int | arraylen | |||
| ) |
Separate a string into an array based on a character delimiter.
| buf | the string to parse | |
| delim | the character delimiter | |
| array | the array to split the values into | |
| arraylen | the max number of elements in the array |
Referenced by add_playback_vars_to_event(), check_channel_status(), comp_callback(), limit_state_handler(), main(), switch_channel_caller_extension_masquerade(), switch_channel_process_export(), switch_channel_queue_dtmf_string(), switch_check_network_list_ip_token(), switch_console_complete(), switch_console_set_alias(), switch_console_set_complete(), switch_core_asr_load_grammar(), switch_core_mime_add_type(), switch_core_session_execute_exten(), switch_core_session_perform_receive_message(), switch_core_session_send_dtmf_string(), switch_core_speech_feed_tts(), switch_core_standard_on_routing(), switch_event_create_brackets(), switch_ivr_eavesdrop_session(), switch_ivr_play_file(), switch_ivr_preprocess_session(), switch_log_str2mask(), switch_network_list_add_cidr_token(), switch_play_and_get_digits(), switch_process_import(), and transfer_after_bridge().
| unsigned int switch_separate_string_string | ( | char * | buf, | |
| char * | delim, | |||
| _Post_count_(return) char ** | array, | |||
| unsigned int | arraylen | |||
| ) |
Referenced by switch_console_execute(), switch_event_add_array(), and switch_ivr_enterprise_originate().
| switch_bool_t switch_simple_email | ( | const char * | to, | |
| const char * | from, | |||
| const char * | headers, | |||
| const char * | body, | |||
| const char * | file, | |||
| const char * | convert_cmd, | |||
| const char * | convert_ext | |||
| ) |
Definition at line 590 of file switch_utils.c.
References B64BUFFLEN, buf, filename, switch_runtime::mailer_app, switch_runtime::mailer_app_args, O_BINARY, runtime, switch_b64_table, SWITCH_CHANNEL_LOG, switch_core_mime_ext2type(), switch_cut_path(), switch_epoch_time_now(), SWITCH_FALSE, SWITCH_GLOBAL_dirs, SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_LOG_WARNING, switch_mprintf(), SWITCH_PATH_SEPARATOR, switch_safe_free, switch_snprintf(), switch_stristr(), switch_system(), SWITCH_TRUE, switch_directories::temp_dir, write_buf(), and zstr.
Referenced by email().
00594 { 00595 char *bound = "XXXX_boundary_XXXX"; 00596 const char *mime_type = "audio/inline"; 00597 char filename[80], buf[B64BUFFLEN]; 00598 int fd = -1, ifd = -1; 00599 int x = 0, y = 0, bytes = 0, ilen = 0; 00600 unsigned int b = 0, l = 0; 00601 unsigned char in[B64BUFFLEN]; 00602 unsigned char out[B64BUFFLEN + 512]; 00603 char *dupfile = NULL, *ext = NULL; 00604 char *newfile = NULL; 00605 switch_bool_t rval = SWITCH_FALSE; 00606 const char *err = NULL; 00607 00608 if (!zstr(file) && !zstr(convert_cmd) && !zstr(convert_ext)) { 00609 if ((ext = strrchr(file, '.'))) { 00610 dupfile = strdup(file); 00611 if ((ext = strrchr(dupfile, '.'))) { 00612 *ext++ = '\0'; 00613 newfile = switch_mprintf("%s.%s", dupfile, convert_ext); 00614 } 00615 } 00616 00617 if (newfile) { 00618 char cmd[1024] = ""; 00619 switch_snprintf(cmd, sizeof(cmd), "%s %s %s", convert_cmd, file, newfile); 00620 switch_system(cmd, SWITCH_TRUE); 00621 if (strcmp(file, newfile)) { 00622 file = newfile; 00623 } else { 00624 switch_safe_free(newfile); 00625 } 00626 } 00627 00628 switch_safe_free(dupfile); 00629 } 00630 00631 switch_snprintf(filename, 80, "%s%smail.%d%04x", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, (int) switch_epoch_time_now(NULL), rand() & 0xffff); 00632 00633 if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) > -1) { 00634 if (file) { 00635 if ((ifd = open(file, O_RDONLY | O_BINARY)) < 0) { 00636 rval = SWITCH_FALSE; 00637 err = "Cannot open tmp file\n"; 00638 goto end; 00639 } 00640 } 00641 switch_snprintf(buf, B64BUFFLEN, "MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"%s\"\n", bound); 00642 if (!write_buf(fd, buf)) { 00643 rval = SWITCH_FALSE; 00644 err = "write error."; 00645 goto end; 00646 } 00647 00648 if (headers && !write_buf(fd, headers)) { 00649 rval = SWITCH_FALSE; 00650 err = "write error."; 00651 goto end; 00652 } 00653 00654 if (!write_buf(fd, "\n\n")) { 00655 rval = SWITCH_FALSE; 00656 err = "write error."; 00657 goto end; 00658 } 00659 00660 if (body && switch_stristr("content-type", body)) { 00661 switch_snprintf(buf, B64BUFFLEN, "--%s\n", bound); 00662 } else { 00663 switch_snprintf(buf, B64BUFFLEN, "--%s\nContent-Type: text/plain\n\n", bound); 00664 } 00665 if (!write_buf(fd, buf)) { 00666 rval = SWITCH_FALSE; 00667 err = "write error."; 00668 goto end; 00669 } 00670 00671 if (body) { 00672 if (!write_buf(fd, body)) { 00673 rval = SWITCH_FALSE; 00674 err = "write error."; 00675 goto end; 00676 } 00677 } 00678 00679 if (file) { 00680 const char *stipped_file = switch_cut_path(file); 00681 const char *new_type; 00682 char *ext; 00683 00684 if ((ext = strrchr(stipped_file, '.'))) { 00685 ext++; 00686 if ((new_type = switch_core_mime_ext2type(ext))) { 00687 mime_type = new_type; 00688 } 00689 } 00690 00691 switch_snprintf(buf, B64BUFFLEN, 00692 "\n\n--%s\nContent-Type: %s; name=\"%s\"\n" 00693 "Content-ID: <ATTACHED@freeswitch.org>\n" 00694 "Content-Transfer-Encoding: base64\n" 00695 "Content-Description: Sound attachment.\n" 00696 "Content-Disposition: attachment; filename=\"%s\"\n\n", bound, mime_type, stipped_file, stipped_file); 00697 if (!write_buf(fd, buf)) { 00698 rval = SWITCH_FALSE; 00699 err = "write error."; 00700 goto end; 00701 } 00702 00703 while ((ilen = read(ifd, in, B64BUFFLEN))) { 00704 for (x = 0; x < ilen; x++) { 00705 b = (b << 8) + in[x]; 00706 l += 8; 00707 while (l >= 6) { 00708 out[bytes++] = switch_b64_table[(b >> (l -= 6)) % 64]; 00709 if (++y != 72) 00710 continue; 00711 out[bytes++] = '\n'; 00712 y = 0; 00713 } 00714 } 00715 if (write(fd, &out, bytes) != bytes) { 00716 rval = -1; 00717 break; 00718 } else { 00719 bytes = 0; 00720 } 00721 00722 } 00723 00724 if (l > 0) { 00725 out[bytes++] = switch_b64_table[((b % 16) << (6 - l)) % 64]; 00726 } 00727 if (l != 0) 00728 while (l < 6) { 00729 out[bytes++] = '=', l += 2; 00730 } 00731 if (write(fd, &out, bytes) != bytes) { 00732 rval = -1; 00733 } 00734 00735 } 00736 00737 switch_snprintf(buf, B64BUFFLEN, "\n\n--%s--\n.\n", bound); 00738 00739 if (!write_buf(fd, buf)) { 00740 rval = SWITCH_FALSE; 00741 err = "write error."; 00742 goto end; 00743 } 00744 } 00745 00746 00747 if (zstr(from)) { 00748 from = "freeswitch"; 00749 } 00750 #ifdef WIN32 00751 switch_snprintf(buf, B64BUFFLEN, "type %s | %s -f %s %s %s", filename, runtime.mailer_app, from, runtime.mailer_app_args, to); 00752 #else 00753 switch_snprintf(buf, B64BUFFLEN, "/bin/cat %s | %s -f %s %s %s", filename, runtime.mailer_app, from, runtime.mailer_app_args, to); 00754 #endif 00755 if (switch_system(buf, SWITCH_TRUE) < 0) { 00756 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to execute command: %s\n", buf); 00757 err = "execute error"; 00758 rval = SWITCH_FALSE; 00759 } 00760 00761 if (zstr(err)) { 00762 if (file) { 00763 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Emailed file [%s] to [%s]\n", filename, to); 00764 } else { 00765 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Emailed data to [%s]\n", to); 00766 } 00767 00768 rval = SWITCH_TRUE; 00769 } 00770 00771 end: 00772 00773 if (fd > -1) { 00774 close(fd); 00775 } 00776 00777 if (unlink(filename) != 0) { 00778 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Failed to delete file [%s]\n", filename); 00779 } 00780 00781 if (ifd > -1) { 00782 close(ifd); 00783 } 00784 00785 00786 if (newfile) { 00787 unlink(newfile); 00788 free(newfile); 00789 } 00790 00791 if (rval != SWITCH_TRUE) { 00792 if (zstr(err)) err = "Unknown Error"; 00793 00794 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "EMAIL NOT SENT, error [%s]\n", err); 00795 } 00796 00797 return rval; 00798 }
| int switch_socket_waitfor | ( | switch_pollfd_t * | poll, | |
| int | ms | |||
| ) |
Wait for a socket.
| poll | the pollfd to wait on | |
| ms | the number of milliseconds to wait |
Definition at line 2227 of file switch_utils.c.
References switch_poll().
02228 { 02229 int nsds = 0; 02230 02231 switch_poll(poll, 1, &nsds, ms); 02232 02233 return nsds; 02234 }
| void switch_split_date | ( | const char * | exp, | |
| int * | year, | |||
| int * | month, | |||
| int * | day | |||
| ) |
Definition at line 2327 of file switch_utils.c.
References switch_assert, and switch_safe_free.
Referenced by switch_fulldate_cmp().
02328 { 02329 char *dup = strdup(exp); 02330 char *syear = NULL; 02331 char *smonth = NULL; 02332 char *sday = NULL; 02333 02334 switch_assert(dup); 02335 02336 syear = dup; 02337 if ((smonth=strchr(dup, '-'))) { 02338 *smonth++ = '\0'; 02339 if ((sday=strchr(smonth, '-'))) { 02340 *sday++ = '\0'; 02341 if (year && syear) { 02342 *year = atol(syear); 02343 } 02344 if (month && smonth) { 02345 *month = atol(smonth); 02346 } 02347 if (day && sday) { 02348 *day = atol(sday); 02349 } 02350 } 02351 } 02352 switch_safe_free(dup); 02353 return; 02354 02355 }
| void switch_split_time | ( | const char * | exp, | |
| int * | hour, | |||
| int * | min, | |||
| int * | sec | |||
| ) |
Definition at line 2294 of file switch_utils.c.
References switch_assert, and switch_safe_free.
Referenced by switch_fulldate_cmp().
02295 { 02296 char *dup = strdup(exp); 02297 char *shour = NULL; 02298 char *smin = NULL; 02299 char *ssec = NULL; 02300 02301 switch_assert(dup); 02302 02303 shour = dup; 02304 if ((smin=strchr(dup, ':'))) { 02305 *smin++ = '\0'; 02306 if ((ssec=strchr(smin, ':'))) { 02307 *ssec++ = '\0'; 02308 } else { 02309 ssec = "00"; 02310 } 02311 if (hour && shour) { 02312 *hour = atol(shour); 02313 } 02314 if (min && smin) { 02315 *min = atol(smin); 02316 } 02317 if (sec && ssec) { 02318 *sec = atol(ssec); 02319 } 02320 02321 } 02322 switch_safe_free(dup); 02323 return; 02324 02325 }
| int switch_split_user_domain | ( | char * | in, | |
| char ** | user, | |||
| char ** | domain | |||
| ) |
Split a user string as user and domain.
| in | the input string | |
| user | the string to put the user into | |
| domain | the string to put the domain into |
Definition at line 2850 of file switch_utils.c.
02851 { 02852 char *p = NULL, *h = NULL, *u = in; 02853 02854 if (!in) { 02855 return 0; 02856 } 02857 02858 /* First isolate the host part from the user part */ 02859 if ((h = strchr(u, '@'))) { 02860 *h++ = '\0'; 02861 } 02862 02863 /* Clean out the user part of its protocol prefix (if any) */ 02864 if ((p = strchr(u, ':'))) { 02865 *p++ = '\0'; 02866 u = p; 02867 } 02868 02869 /* Clean out the host part of any suffix */ 02870 if (h) { 02871 if ((p = strchr(h, ':'))) { 02872 *p = '\0'; 02873 } 02874 02875 if ((p = strchr(h, ';'))) { 02876 *p = '\0'; 02877 } 02878 02879 if ((p = strchr(h, ' '))) { 02880 *p = '\0'; 02881 } 02882 } 02883 if (user) { 02884 *user = u; 02885 } 02886 if (domain) { 02887 *domain = h; 02888 } 02889 02890 return 1; 02891 }
| switch_time_t switch_str_time | ( | const char * | in | ) |
Converts a string representation of a date into a switch_time_t.
| in | the string |
Definition at line 1400 of file switch_utils.c.
References switch_micro_time_now(), switch_regex_copy_substring(), switch_regex_perform(), switch_regex_safe_free, switch_time_exp_gmt_get(), switch_time_exp_lt(), switch_time_exp_t::tm_hour, switch_time_exp_t::tm_mday, switch_time_exp_t::tm_min, switch_time_exp_t::tm_mon, switch_time_exp_t::tm_sec, and switch_time_exp_t::tm_year.
01401 { 01402 switch_time_exp_t tm = { 0 }; 01403 int proceed = 0, ovector[30]; 01404 switch_regex_t *re = NULL; 01405 char replace[1024] = ""; 01406 switch_time_t ret = 0; 01407 char *pattern = "^(\\d+)-(\\d+)-(\\d+)\\s*(\\d*):{0,1}(\\d*):{0,1}(\\d*)"; 01408 char *pattern2 = "^(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})"; 01409 01410 switch_time_exp_lt(&tm, switch_micro_time_now()); 01411 tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = 0; 01412 01413 if (!(proceed = switch_regex_perform(in, pattern, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) { 01414 switch_regex_safe_free(re); 01415 proceed = switch_regex_perform(in, pattern2, &re, ovector, sizeof(ovector) / sizeof(ovector[0])); 01416 } 01417 01418 if (proceed) { 01419 01420 if (proceed > 1) { 01421 switch_regex_copy_substring(in, ovector, proceed, 1, replace, sizeof(replace)); 01422 tm.tm_year = atoi(replace) - 1900; 01423 } 01424 01425 if (proceed > 2) { 01426 switch_regex_copy_substring(in, ovector, proceed, 2, replace, sizeof(replace)); 01427 tm.tm_mon = atoi(replace) - 1; 01428 } 01429 01430 if (proceed > 3) { 01431 switch_regex_copy_substring(in, ovector, proceed, 3, replace, sizeof(replace)); 01432 tm.tm_mday = atoi(replace); 01433 } 01434 01435 if (proceed > 4) { 01436 switch_regex_copy_substring(in, ovector, proceed, 4, replace, sizeof(replace)); 01437 tm.tm_hour = atoi(replace); 01438 } 01439 01440 if (proceed > 5) { 01441 switch_regex_copy_substring(in, ovector, proceed, 5, replace, sizeof(replace)); 01442 tm.tm_min = atoi(replace); 01443 } 01444 01445 if (proceed > 6) { 01446 switch_regex_copy_substring(in, ovector, proceed, 6, replace, sizeof(replace)); 01447 tm.tm_sec = atoi(replace); 01448 } 01449 01450 switch_regex_safe_free(re); 01451 01452 switch_time_exp_gmt_get(&ret, &tm); 01453 return ret; 01454 } 01455 01456 switch_regex_safe_free(re); 01457 01458 return ret; 01459 }
| static char* switch_strchr_strict | ( | const char * | in, | |
| char | find, | |||
| const char * | allowed | |||
| ) | [inline, static] |
Definition at line 105 of file switch_utils.h.
References switch_assert.
Referenced by switch_event_create_brackets().
00106 { 00107 const char *p; 00108 00109 switch_assert(in); 00110 00111 p = in; 00112 00113 while(p && *p) { 00114 const char *a = allowed; 00115 int acceptable = 0; 00116 00117 if (*p == find) break; 00118 00119 if (!a) { 00120 acceptable = 1; 00121 } else { 00122 00123 while(a && *a) { 00124 00125 if (*p == *a) { 00126 acceptable = 1; 00127 break; 00128 } 00129 00130 a++; 00131 } 00132 00133 } 00134 00135 if (!acceptable) return NULL; 00136 00137 p++; 00138 } 00139 00140 return (char *) p; 00141 }
| static int switch_string_has_escaped_data | ( | const char * | in | ) | [inline, static] |
Definition at line 152 of file switch_utils.h.
References switch_assert.
Referenced by switch_channel_expand_variables_check(), and switch_event_expand_headers_check().
00153 { 00154 const char *i; 00155 00156 switch_assert(in); 00157 00158 i = strchr(in, '\\'); 00159 00160 while (i && *i == '\\') { 00161 i++; 00162 if (*i == '\\' || *i == 'n' || *i == 's' || *i == 't' || *i == '\'') { 00163 return 1; 00164 } 00165 i = strchr(i, '\\'); 00166 } 00167 00168 return 0; 00169 }
| switch_status_t switch_string_match | ( | const char * | string, | |
| size_t | string_len, | |||
| const char * | search, | |||
| size_t | search_len | |||
| ) |
Definition at line 2119 of file switch_utils.c.
References SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.
Referenced by switch_string_replace().
02120 { 02121 size_t i; 02122 02123 for (i = 0; (i < search_len) && (i < string_len); i++) { 02124 if (string[i] != search[i]) { 02125 return SWITCH_STATUS_FALSE; 02126 } 02127 } 02128 02129 if (i == search_len) { 02130 return SWITCH_STATUS_SUCCESS; 02131 } 02132 02133 return SWITCH_STATUS_FALSE; 02134 }
| char* switch_string_replace | ( | const char * | string, | |
| const char * | search, | |||
| const char * | replace | |||
| ) |
Definition at line 2136 of file switch_utils.c.
References switch_assert, SWITCH_STATUS_SUCCESS, and switch_string_match().
Referenced by switch_core_sqldb_start().
02137 { 02138 size_t string_len = strlen(string); 02139 size_t search_len = strlen(search); 02140 size_t replace_len = strlen(replace); 02141 size_t i, n; 02142 size_t dest_len = 0; 02143 char *dest, *tmp; 02144 02145 dest = (char *) malloc(sizeof(char)); 02146 switch_assert(dest); 02147 02148 for (i = 0; i < string_len; i++) { 02149 if (switch_string_match(string + i, string_len - i, search, search_len) == SWITCH_STATUS_SUCCESS) { 02150 for (n = 0; n < replace_len; n++) { 02151 dest[dest_len] = replace[n]; 02152 dest_len++; 02153 tmp = (char *) realloc(dest, sizeof(char) * (dest_len + 1)); 02154 switch_assert(tmp); 02155 dest = tmp; 02156 } 02157 i += search_len - 1; 02158 } else { 02159 dest[dest_len] = string[i]; 02160 dest_len++; 02161 tmp = (char *) realloc(dest, sizeof(char) * (dest_len + 1)); 02162 switch_assert(tmp); 02163 dest = tmp; 02164 } 02165 } 02166 02167 dest[dest_len] = 0; 02168 return dest; 02169 }
| static switch_bool_t switch_string_var_check | ( | char * | s, | |
| switch_bool_t | disable | |||
| ) | [inline, static] |
Definition at line 447 of file switch_utils.h.
References SWITCH_FALSE, and SWITCH_TRUE.
Referenced by switch_core_set_var_conditional(), switch_core_set_variable(), and switch_var_clean_string().
00448 { 00449 char *p; 00450 char *dol = NULL; 00451 00452 for (p = s; p && *p; p++) { 00453 if (*p == '$') { 00454 dol = p; 00455 } else if (dol) { 00456 if (*p == '{') { 00457 if (disable) { 00458 *dol = '%'; 00459 dol = NULL; 00460 } else { 00461 return SWITCH_TRUE; 00462 } 00463 } else if (*p != '\\') { 00464 dol = NULL; 00465 } 00466 } 00467 } 00468 return SWITCH_FALSE; 00469 }
| static switch_bool_t switch_string_var_check_const | ( | const char * | s | ) | [inline, static] |
Definition at line 472 of file switch_utils.h.
References SWITCH_FALSE, and SWITCH_TRUE.
Referenced by switch_channel_add_variable_var_check(), switch_channel_expand_variables_check(), switch_channel_set_variable_var_check(), and switch_event_expand_headers_check().
00473 { 00474 const char *p; 00475 int dol = 0; 00476 00477 for (p = s; p && *p; p++) { 00478 if (*p == '$') { 00479 dol = 1; 00480 } else if (dol) { 00481 if (*p == '{') { 00482 return SWITCH_TRUE; 00483 } else if (*p != '\\') { 00484 dol = 0; 00485 } 00486 } 00487 } 00488 return SWITCH_FALSE; 00489 }
| char* switch_strip_commas | ( | char * | in, | |
| char * | out, | |||
| switch_size_t | len | |||
| ) |
Definition at line 952 of file switch_utils.c.
00953 { 00954 char *p = in, *q = out; 00955 char *ret = out; 00956 switch_size_t x = 0; 00957 00958 for (; p && *p; p++) { 00959 if ((*p > 47 && *p < 58)) { 00960 *q++ = *p; 00961 } else if (*p != ',') { 00962 ret = NULL; 00963 break; 00964 } 00965 00966 if (++x > len) { 00967 ret = NULL; 00968 break; 00969 } 00970 } 00971 00972 return ret; 00973 }
| char* switch_strip_nonnumerics | ( | char * | in, | |
| char * | out, | |||
| switch_size_t | len | |||
| ) |
Definition at line 975 of file switch_utils.c.
00976 { 00977 char *p = in, *q = out; 00978 char *ret = out; 00979 switch_size_t x = 0; 00980 /* valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others */ 00981 for (; p && *p; p++) { 00982 if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') { 00983 *q++ = *p; 00984 } 00985 00986 if (++x > len) { 00987 ret = NULL; 00988 break; 00989 } 00990 } 00991 00992 return ret; 00993 }
| char* switch_strip_spaces | ( | char * | str, | |
| switch_bool_t | dup | |||
| ) |
Definition at line 916 of file switch_utils.c.
References switch_assert, SWITCH_BLANK_STRING, and zstr.
00917 { 00918 char *sp = str; 00919 char *p, *s = NULL; 00920 size_t len; 00921 00922 if (zstr(sp)) { 00923 return dup ? strdup(SWITCH_BLANK_STRING) : sp; 00924 } 00925 00926 while (*sp == ' ') { 00927 sp++; 00928 } 00929 00930 if (dup) { 00931 s = strdup(sp); 00932 switch_assert(s); 00933 } else { 00934 s = sp; 00935 } 00936 00937 if (zstr(s)) { 00938 return s; 00939 } 00940 00941 if ((len = strlen(s)) > 0) { 00942 p = s + (len - 1); 00943 00944 while (p && *p && (p >= s) && *p == ' ') { 00945 *p-- = '\0'; 00946 } 00947 } 00948 00949 return s; 00950 }
| char* switch_strip_whitespace | ( | const char * | str | ) |
Definition at line 884 of file switch_utils.c.
References switch_assert, SWITCH_BLANK_STRING, and zstr.
Referenced by switch_api_execute().
00885 { 00886 const char *sp = str; 00887 char *p, *s = NULL; 00888 size_t len; 00889 00890 if (zstr(sp)) { 00891 return strdup(SWITCH_BLANK_STRING); 00892 } 00893 00894 while ((*sp == 13 ) || (*sp == 10 ) || (*sp == 9 ) || (*sp == 32) || (*sp == 11) ) { 00895 sp++; 00896 } 00897 00898 if (zstr(sp)) { 00899 return strdup(SWITCH_BLANK_STRING); 00900 } 00901 00902 s = strdup(sp); 00903 switch_assert(s); 00904 00905 if ((len = strlen(s)) > 0) { 00906 p = s + (len - 1); 00907 00908 while ((p >= s) && ((*p == 13 ) || (*p == 10 ) || (*p == 9 ) || (*p == 32) || (*p == 11))) { 00909 *p-- = '\0'; 00910 } 00911 } 00912 00913 return s; 00914 }
| const char* switch_stristr | ( | const char * | instr, | |
| const char * | str | |||
| ) |
Definition at line 1043 of file switch_utils.c.
References switch_toupper().
Referenced by audio_bridge_thread(), core_event_handler(), do_chat_send(), inherit_codec(), init_upnp(), preprocess(), speech_thread(), switch_cache_db_execute_sql_real(), switch_ivr_originate(), switch_odbc_handle_exec(), switch_simple_email(), and switch_xml_free().
01044 { 01045 /* 01046 ** Rev History: 16/07/97 Greg Thayer Optimized 01047 ** 07/04/95 Bob Stout ANSI-fy 01048 ** 02/03/94 Fred Cole Original 01049 ** 09/01/03 Bob Stout Bug fix (lines 40-41) per Fred Bulback 01050 ** 01051 ** Hereby donated to public domain. 01052 */ 01053 const char *pptr, *sptr, *start; 01054 01055 if (!str || !instr) 01056 return NULL; 01057 01058 for (start = str; *start; start++) { 01059 /* find start of pattern in string */ 01060 for (; ((*start) && (switch_toupper(*start) != switch_toupper(*instr))); start++); 01061 01062 if (!*start) 01063 return NULL; 01064 01065 pptr = instr; 01066 sptr = start; 01067 01068 while (switch_toupper(*sptr) == switch_toupper(*pptr)) { 01069 sptr++; 01070 pptr++; 01071 01072 /* if end of pattern then pattern was found */ 01073 if (!*pptr) 01074 return (start); 01075 01076 if (!*sptr) 01077 return NULL; 01078 } 01079 } 01080 return NULL; 01081 }
| static switch_bool_t switch_strstr | ( | char * | s, | |
| char * | q | |||
| ) | [inline, static] |
Test if one string is inside another with extra case checking.
| s | the inner string | |
| q | the big string |
Definition at line 603 of file switch_utils.h.
References SWITCH_FALSE, switch_safe_free, switch_toupper(), and SWITCH_TRUE.
00604 { 00605 char *p, *S = NULL, *Q = NULL; 00606 switch_bool_t tf = SWITCH_FALSE; 00607 00608 if (!s || !q) { 00609 return SWITCH_FALSE; 00610 } 00611 00612 if (strstr(s, q)) { 00613 return SWITCH_TRUE; 00614 } 00615 00616 S = strdup(s); 00617 00618 assert(S != NULL); 00619 00620 for (p = S; p && *p; p++) { 00621 *p = (char) switch_toupper(*p); 00622 } 00623 00624 if (strstr(S, q)) { 00625 tf = SWITCH_TRUE; 00626 goto done; 00627 } 00628 00629 Q = strdup(q); 00630 assert(Q != NULL); 00631 00632 for (p = Q; p && *p; p++) { 00633 *p = (char) switch_toupper(*p); 00634 } 00635 00636 if (strstr(s, Q)) { 00637 tf = SWITCH_TRUE; 00638 goto done; 00639 } 00640 00641 if (strstr(S, Q)) { 00642 tf = SWITCH_TRUE; 00643 goto done; 00644 } 00645 00646 done: 00647 switch_safe_free(S); 00648 switch_safe_free(Q); 00649 00650 return tf; 00651 }
| switch_bool_t switch_testv6_subnet | ( | ip_t | _ip, | |
| ip_t | _net, | |||
| ip_t | _mask | |||
| ) |
Definition at line 196 of file switch_utils.c.
References IN6_AND_MASK, and SWITCH_TRUE.
Referenced by switch_check_network_list_ip_token(), and switch_network_list_validate_ip6_token().
00196 { 00197 if (!IN6_IS_ADDR_UNSPECIFIED(&_mask.v6)) { 00198 struct in6_addr a, b; 00199 IN6_AND_MASK(&a, &_net, &_mask); 00200 IN6_AND_MASK(&b, &_ip, &_mask); 00201 return !memcmp(&a,&b, sizeof(struct in6_addr)); 00202 } else { 00203 if (!IN6_IS_ADDR_UNSPECIFIED(&_net.v6)) { 00204 return !memcmp(&_net,&_ip,sizeof(struct in6_addr)); 00205 } 00206 else return SWITCH_TRUE; 00207 } 00208 }
| int switch_tod_cmp | ( | const char * | exp, | |
| int | val | |||
| ) |
Definition at line 2807 of file switch_utils.c.
References switch_assert, and switch_safe_free.
Referenced by switch_xml_std_datetime_check().
02808 { 02809 char *dup = strdup(exp); 02810 char *minh; 02811 char *minm; 02812 char *mins; 02813 char *maxh; 02814 char *maxm; 02815 char *maxs; 02816 02817 switch_assert(dup); 02818 02819 minh = dup; 02820 if ((minm=strchr(dup, ':'))) { 02821 *minm++ = '\0'; 02822 if ((maxh=strchr(minm, '-'))) { 02823 if ((maxm=strchr(maxh, ':'))) { 02824 *maxh++ = '\0'; 02825 *maxm++ = '\0'; 02826 /* Check if min/max seconds are present */ 02827 if ((mins=strchr(minm, ':'))) { 02828 *mins++ = '\0'; 02829 } else { 02830 mins = "00"; 02831 } 02832 if ((maxs=strchr(maxm, ':'))) { 02833 *maxs++ = '\0'; 02834 } else { 02835 maxs = "00"; 02836 } 02837 02838 if (val >= (atol(minh) * 60 * 60) + (atol(minm) * 60) + atol(mins) && val < (atol(maxh) * 60 * 60) + (atol(maxm) * 60) + atol(maxs)) { 02839 switch_safe_free(dup); 02840 return 1; 02841 } 02842 } 02843 } 02844 } 02845 switch_safe_free(dup); 02846 return 0; 02847 02848 }
| int switch_tolower | ( | int | c | ) |
Definition at line 2511 of file switch_utils.c.
Referenced by switch_lc_strdup().
02512 { 02513 if ((unsigned int) c > 255) 02514 return (c); 02515 if (c < -1) 02516 return EOF; 02517 return ((_switch_tolower_tab_ + 1)[c]); 02518 }
| SWITCH_BEGIN_EXTERN_C int switch_toupper | ( | int | c | ) |
Definition at line 2464 of file switch_utils.c.
Referenced by switch_char_to_rfc2833(), switch_stristr(), switch_strstr(), and switch_uc_strdup().
02465 { 02466 if ((unsigned int) c > 255) 02467 return (c); 02468 if (c < -1) 02469 return EOF; 02470 return ((_switch_toupper_tab_ + 1)[c]); 02471 }
| static int switch_true | ( | const char * | expr | ) | [inline, static] |
Evaluate the truthfullness of a string expression.
| expr | a string expression |
Definition at line 250 of file switch_utils.h.
References SWITCH_FALSE, switch_is_number(), and SWITCH_TRUE.
Referenced by audio_bridge_on_exchange_media(), audio_bridge_thread(), core_event_handler(), do_chat_send(), inherit_codec(), limit_state_handler(), signal_bridge_on_hangup(), speech_thread(), switch_channel_mark_hold(), switch_channel_perform_mark_answered(), switch_channel_perform_presence(), switch_core_media_bug_add(), switch_core_session_exec(), switch_core_session_hangup_state(), switch_core_session_perform_receive_message(), switch_core_session_reporting_state(), switch_core_session_thread(), switch_ivr_detect_speech(), switch_ivr_intercept_session(), switch_ivr_multi_threaded_bridge(), switch_ivr_originate(), switch_ivr_parse_event(), switch_ivr_phrase_macro_event(), switch_ivr_preprocess_session(), switch_ivr_record_file(), switch_ivr_record_session(), switch_ivr_say(), switch_ivr_say_string(), switch_ivr_speak_text(), switch_load_core_config(), switch_load_network_lists(), switch_loadable_module_init(), switch_rtp_create(), switch_rtp_enable_vad(), switch_rtp_init(), switch_xml_locate_user_merged(), and uuid_bridge_on_soft_execute().
00251 { 00252 return ((expr && ( !strcasecmp(expr, "yes") || 00253 !strcasecmp(expr, "on") || 00254 !strcasecmp(expr, "true") || 00255 !strcasecmp(expr, "enabled") || 00256 !strcasecmp(expr, "active") || 00257 !strcasecmp(expr, "allow") || 00258 (switch_is_number(expr) && atoi(expr)))) ? SWITCH_TRUE : SWITCH_FALSE); 00259 }
| static char* switch_uc_strdup | ( | const char * | it | ) | [inline, static] |
Definition at line 577 of file switch_utils.h.
References switch_toupper().
00578 { 00579 char *dup; 00580 char *p; 00581 00582 if (it) { 00583 dup = strdup(it); 00584 for (p = dup; p && *p; p++) { 00585 *p = (char) switch_toupper(*p); 00586 } 00587 return dup; 00588 } 00589 00590 return NULL; 00591 }
| char* switch_url_decode | ( | char * | s | ) |
Definition at line 2273 of file switch_utils.c.
References zstr.
Referenced by switch_core_session_request_xml().
02274 { 02275 char *o; 02276 unsigned int tmp; 02277 02278 if (zstr(s)) { 02279 return s; 02280 } 02281 02282 for (o = s; *s; s++, o++) { 02283 if (*s == '%' && strlen(s) > 2 && sscanf(s + 1, "%2x", &tmp) == 1) { 02284 *o = (char) tmp; 02285 s += 2; 02286 } else { 02287 *o = *s; 02288 } 02289 } 02290 *o = '\0'; 02291 return s; 02292 }
| char* switch_url_encode | ( | const char * | url, | |
| char * | buf, | |||
| size_t | len | |||
| ) |
Definition at line 2236 of file switch_utils.c.
Referenced by add_xml_header(), switch_channel_build_param_string(), switch_event_build_param_string(), switch_event_serialize(), switch_ivr_set_json_chan_vars(), and switch_ivr_set_xml_chan_var().
02237 { 02238 const char *p; 02239 size_t x = 0; 02240 const char urlunsafe[] = "\r\n \"#%&+:;<=>?@[\\]^`{|}"; 02241 const char hex[] = "0123456789ABCDEF"; 02242 02243 if (!buf) { 02244 return 0; 02245 } 02246 02247 if (!url) { 02248 return 0; 02249 } 02250 02251 len--; 02252 02253 for (p = url; *p; p++) { 02254 if (x >= len) { 02255 break; 02256 } 02257 if (*p < ' ' || *p > '~' || strchr(urlunsafe, *p)) { 02258 if ((x + 3) > len) { 02259 break; 02260 } 02261 buf[x++] = '%'; 02262 buf[x++] = hex[(*p >> 4) & 0x0f]; 02263 buf[x++] = hex[*p & 0x0f]; 02264 } else { 02265 buf[x++] = *p; 02266 } 02267 } 02268 buf[x] = '\0'; 02269 02270 return buf; 02271 }
| char* switch_util_quote_shell_arg | ( | const char * | string | ) |
Quote shell argument.
| string | the string to quote (example: a ' b"' c) |
Definition at line 2171 of file switch_utils.c.
References switch_assert.
02172 { 02173 size_t string_len = strlen(string); 02174 size_t i; 02175 size_t n = 0; 02176 size_t dest_len = string_len + 1; /* +1 for the opening quote */ 02177 char *dest, *tmp; 02178 02179 dest = (char *) malloc(sizeof(char) * dest_len); 02180 switch_assert(dest); 02181 02182 #ifdef WIN32 02183 dest[n++] = '"'; 02184 #else 02185 dest[n++] = '\''; 02186 #endif 02187 02188 for (i = 0; i < string_len; i++) { 02189 switch (string[i]) { 02190 #ifdef WIN32 02191 case '"': 02192 case '%': 02193 dest[n++] = ' '; 02194 break; 02195 #else 02196 case '\'': 02197 /* We replace ' by '\'' */ 02198 dest_len += 3; 02199 tmp = (char *) realloc(dest, sizeof(char) * (dest_len)); 02200 switch_assert(tmp); 02201 dest = tmp; 02202 dest[n++] = '\''; 02203 dest[n++] = '\\'; 02204 dest[n++] = '\''; 02205 dest[n++] = '\''; 02206 break; 02207 #endif 02208 default: 02209 dest[n++] = string[i]; 02210 } 02211 } 02212 02213 dest_len += 2; /* +2 for the closing quote and the null character */ 02214 tmp = (char *) realloc(dest, sizeof(char) * (dest_len)); 02215 switch_assert(tmp); 02216 dest = tmp; 02217 #ifdef WIN32 02218 dest[n++] = '"'; 02219 #else 02220 dest[n++] = '\''; 02221 #endif 02222 dest[n++] = 0; 02223 switch_assert(n == dest_len); 02224 return dest; 02225 }
| char* switch_uuid_str | ( | char * | buf, | |
| switch_size_t | len | |||
| ) |
Definition at line 2894 of file switch_utils.c.
References switch_snprintf(), switch_uuid_format(), SWITCH_UUID_FORMATTED_LENGTH, and switch_uuid_get().
Referenced by switch_caller_profile_dup(), and switch_caller_profile_new().
02895 { 02896 switch_uuid_t uuid; 02897 02898 if (len < (SWITCH_UUID_FORMATTED_LENGTH + 1)) { 02899 switch_snprintf(buf, len, "INVALID"); 02900 } else { 02901 switch_uuid_get(&uuid); 02902 switch_uuid_format(buf, &uuid); 02903 } 02904 02905 return buf; 02906 }
| static char* switch_var_clean_string | ( | char * | s | ) | [inline, static] |
Definition at line 491 of file switch_utils.h.
References switch_string_var_check(), and SWITCH_TRUE.
00492 { 00493 switch_string_var_check(s, SWITCH_TRUE); 00494 return s; 00495 }
1.4.7