37 #pragma warning(disable:4127 4003)
62 if (!
zstr(event_name)) {
63 bind(event_name, subclass_name);
80 if (
zstr(subclass_name)) {
117 ret =
new Event(event, 1);
135 for (i = 0; i < node_index; i++) {
163 const char *greeting_sound,
164 const char *short_greeting_sound,
165 const char *invalid_sound,
166 const char *exit_sound,
167 const char *transfer_sound,
168 const char *confirm_macro,
169 const char *confirm_key,
170 const char *tts_engine,
171 const char *tts_voice,
172 int confirm_attempts,
187 exit_sound, transfer_sound, confirm_macro, confirm_key, tts_engine, tts_voice, confirm_attempts, inter_timeout,
188 digit_len, timeout, max_failures, max_timeouts,
pool);
250 return (
char *) stream.
data;
282 if ((arg = strchr(mycmd,
' '))) {
290 return (
char *) stream.
data;
297 if (!strcasecmp(type,
"json") && !
zstr(subclass_name)) {
302 event_id =
event->event_id;
350 if (
zstr(dest_proto)) {
368 if (format && !strcasecmp(format,
"xml")) {
373 return serialized_string;
377 }
else if (format && !strcasecmp(format,
"json")) {
379 return serialized_string;
382 char *new_serialized_string =
switch_mprintf(
"'%s'", serialized_string);
383 free(serialized_string);
384 serialized_string = new_serialized_string;
385 return serialized_string;
438 if (
zstr(header_name)) {
468 if (
zstr(header_name)) {
520 return (
char *)
"invalid";
528 if (iduration == 0) {
569 if (!stream_p->read_function)
return NULL;
571 buff = stream_p->read_function(stream_p, len);
573 if (!buff || *len <= 0) {
578 return (
const char *)buff;
584 stream_p->write_function(stream_p,
"%s", data);
590 stream_p->raw_write_function(stream_p, (uint8_t *)data, len);
597 return stream_p ? (
const char *)stream_p->data : NULL;
617 uuid = strdup(nuuid);
622 if (
switch_ivr_originate(a_leg ? a_leg->
session : NULL, &
session, &
cause, nuuid, 60, NULL, NULL, NULL, NULL, NULL,
SOF_NONE, NULL)
668 return (
char *) (xml_cdr_text ? xml_cdr_text :
"");
676 if (channel && e->event) {
711 this->begin_allow_threads();
715 this->end_allow_threads();
723 this->begin_allow_threads();
725 this->end_allow_threads();
767 begin_allow_threads();
777 cb_state.funcargs = funcargs;
778 cb_state.function = cbfunc;
780 args.buf = &cb_state;
781 args.buflen =
sizeof(cb_state);
826 begin_allow_threads();
839 tts_name = strdup(tts_name_p);
840 voice_name = strdup(voice_name_p);
849 tts_name = strdup(tts_name_p);
850 voice_name = strdup(voice_name_p);
854 return collectDigits(0, abs_timeout);
860 begin_allow_threads();
868 return getDigits(maxdigits, terminators, timeout, 0);
878 begin_allow_threads();
881 memset(dtmf_buf, 0,
sizeof(dtmf_buf));
888 (uint32_t) timeout, (uint32_t)interdigit, 0);
900 begin_allow_threads();
910 const
char *prompt_audio_file,
912 const
char *valid_terminators,
917 if (min_digits < 1) {
921 if (max_digits < 1) {
929 begin_allow_threads();
930 switch_ivr_read(session, min_digits, max_digits, prompt_audio_file, NULL, dtmf_buf,
931 sizeof(dtmf_buf), timeout, valid_terminators, (uint32_t)digit_timeout);
943 char *bad_input_audio_files,
945 const
char *var_name,
947 const
char *transfer_on_failure)
951 begin_allow_threads();
952 memset(dtmf_buf, 0,
sizeof(dtmf_buf));
954 (uint32_t) min_digits,
955 (uint32_t) max_digits,
956 (uint32_t) max_tries,
960 bad_input_audio_files,
965 (uint32_t) digit_timeout,
966 transfer_on_failure);
972 SWITCH_DECLARE(
void)
CoreSession::say(const
char *tosay, const
char *module_name, const
char *say_type, const
char *say_method, const
char *say_gender)
976 if (!(tosay && module_name && say_type && say_method)) {
980 begin_allow_threads();
981 switch_ivr_say(session, tosay, module_name, say_type, say_method, say_gender, ap);
990 if (!(phrase_name)) {
995 begin_allow_threads();
1010 memset(&local_fh, 0,
sizeof(local_fh));
1012 local_fh.
samples = starting_sample_count;
1016 int maybe = atoi(prebuf);
1022 begin_allow_threads();
1024 end_allow_threads();
1039 begin_allow_threads();
1041 end_allow_threads();
1151 if (a_leg_session != NULL) {
1152 aleg_core_session = a_leg_session->session;
1159 if (a_leg_session) a_leg_session->begin_allow_threads();
1178 if (a_leg_session) a_leg_session->end_allow_threads();
1188 if (a_leg_session) a_leg_session->end_allow_threads();
1200 memset(&local_fh, 0,
sizeof(local_fh));
1202 local_fh.
thresh = silence_threshold;
1205 begin_allow_threads();
1207 end_allow_threads();
1271 on_hangup = hangup_func;
1276 switch_core_event_hook_add_state_change(session,
hanguphook);
1309 if (
zstr(val)) val = NULL;
1310 if (
zstr(val2)) val2 = NULL;
1380 SWITCH_DECLARE(
bool)
email(
char *to,
char *from,
char *headers,
char *body,
char *file,
char *convert_cmd,
char *convert_ext)
1399 const char *err =
"Channels not ready\n";
1401 if (session_a.allocated && session_a.session && session_b.allocated && session_b.session) {
1406 session_a.begin_allow_threads();
1412 args = session_a.get_cb_args();
1417 session_a.end_allow_threads();
1430 if (session_hungup) {
switch_channel_t * channel
switch_status_t switch_event_serialize_json(switch_event_t *event, char **str)
void console_clean_log(char *msg)
void consoleCleanLog(char *msg)
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
void switch_core_session_hangup_state(switch_core_session_t *session, switch_bool_t force)
switch_channel_state_t switch_channel_get_state(switch_channel_t *channel)
Get the current state of a channel in the state engine.
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
#define switch_channel_hangup(channel, hangup_cause)
Hangup a channel flagging it's state machine to end.
void switch_xml_free(_In_opt_ switch_xml_t xml)
frees the memory allocated for an switch_xml structure
#define switch_channel_answer(channel)
Answer a channel (initiate/acknowledge a successful connection)
switch_status_t hanguphook(switch_core_session_t *session_hungup)
the actual hangup hook called back by freeswitch core which in turn gets the session and calls the ap...
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
#define SWITCH_CHANNEL_SESSION_LOG(x)
#define switch_core_session_force_locate(uuid_str)
Locate a session based on it's uuid even if the channel is not ready.
char * switch_xml_toxml(_In_ switch_xml_t xml, _In_ switch_bool_t prn_header)
Converts an switch_xml structure back to xml in html format. Returns a string of html data that \ mus...
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
switch_status_t switch_event_bind_removable(const char *id, switch_event_types_t event, const char *subclass_name, switch_event_callback_t callback, void *user_data, switch_event_node_t **node)
Bind an event callback to a specific event.
DTMF(char idigit, uint32_t iduration=SWITCH_DEFAULT_DTMF_DURATION)
#define SWITCH_CHANNEL_LOG
void setGlobalVariable(char *var_name, char *var_val)
#define switch_event_del_header(_e, _h)
switch_status_t switch_play_and_get_digits(switch_core_session_t *session, uint32_t min_digits, uint32_t max_digits, uint32_t max_tries, uint32_t timeout, const char *valid_terminators, const char *audio_file, const char *bad_input_audio_file, const char *var_name, char *digit_buffer, uint32_t digit_buffer_length, const char *digits_regex, uint32_t digit_timeout, const char *transfer_on_failure)
Play a sound and gather digits with the number of retries specified if the user doesn't give digits i...
#define switch_channel_set_state(channel, state)
Set the current state of a channel.
switch_status_t switch_channel_set_private(switch_channel_t *channel, const char *key, const void *private_info)
Set private data on channel.
const char * switch_channel_cause2str(_In_ switch_call_cause_t cause)
return a cause string for a given cause
switch_status_t switch_ivr_sleep(switch_core_session_t *session, uint32_t ms, switch_bool_t sync, switch_input_args_t *args)
Wait for time to pass for a specified number of milliseconds.
void switch_channel_flush_dtmf(_In_ switch_channel_t *channel)
EventConsumer(const char *event_name=NULL, const char *subclass_name="", int len=5000)
switch_event_types_t
Built-in Events.
void switch_sleep(switch_interval_time_t t)
switch_status_t switch_queue_pop_timeout(switch_queue_t *queue, void **data, switch_interval_time_t timeout)
switch_status_t switch_ivr_collect_digits_callback(switch_core_session_t *session, switch_input_args_t *args, uint32_t digit_timeout, uint32_t abs_timeout)
Wait for DTMF digits calling a pluggable callback function when digits are collected.
#define switch_channel_up(_channel)
switch_bool_t switch_core_running(void)
void switch_channel_event_set_data(_In_ switch_channel_t *channel, _In_ switch_event_t *event)
Add information about a given channel to an event object.
switch_status_t switch_name_event(const char *name, switch_event_types_t *type)
return the event id that matches a given event name
switch_priority_t
Priority Indication.
switch_bool_t switch_core_set_var_conditional(_In_z_ const char *varname, _In_opt_z_ const char *value, _In_opt_z_ const char *val2)
Conditionally add a global variable to the core.
switch_status_t switch_api_execute(const char *cmd, const char *arg, switch_core_session_t *session, switch_stream_handle_t *stream)
Execute a registered API command.
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
switch_memory_pool_t * pool
void console_log2(char *level_str, char *file, char *func, int line, char *msg)
Representation of an event.
#define switch_channel_ready(_channel)
void switch_core_set_variable(_In_z_ const char *varname, _In_opt_z_ const char *value)
Add a global variable to the core.
switch_status_t switch_event_add_body(switch_event_t *event, const char *fmt,...) PRINTF_FUNCTION(2
Add a body to an event.
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
switch_status_t switch_event_set_priority(switch_event_t *event, switch_priority_t priority)
Set the priority of an event.
#define switch_channel_media_ready(_channel)
switch_stream_handle_t mystream
switch_core_session_t * session
void consoleLog2(char *level_str, char *file, char *func, int line, char *msg)
switch_status_t switch_ivr_play_file(switch_core_session_t *session, switch_file_handle_t *fh, const char *file, switch_input_args_t *args)
play a file from the disk to the session
A representation of an XML tree.
#define SWITCH_DEFAULT_DTMF_DURATION
const char * switch_channel_state_name(_In_ switch_channel_state_t state)
Render the name of the provided state enum.
switch_status_t switch_ivr_speak_text(switch_core_session_t *session, const char *tts_name, const char *voice_name, char *text, switch_input_args_t *args)
Speak given text with given tts engine.
switch_status_t switch_queue_pop(switch_queue_t *queue, void **data)
switch_status_t switch_event_dup(switch_event_t **event, switch_event_t *todup)
Duplicate an event.
#define switch_event_create_subclass(_e, _eid, _sn)
uint32_t switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Test for presence of given flag on a given channel.
switch_status_t switch_ivr_session_transfer(_In_ switch_core_session_t *session, const char *extension, const char *dialplan, const char *context)
Transfer an existing session to another location.
switch_stream_handle_t * stream_p
#define switch_core_session_execute_application(_a, _b, _c)
Execute an application on a session.
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
switch_status_t switch_core_chat_send(const char *dest_proto, switch_event_t *message_event)
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
int main(int argc, char *argv[])
void switch_channel_wait_for_state(switch_channel_t *channel, switch_channel_t *other_channel, switch_channel_state_t want_state)
switch_memory_pool_t * pool
switch_status_t switch_ivr_collect_digits_count(switch_core_session_t *session, char *buf, switch_size_t buflen, switch_size_t maxdigits, const char *terminators, char *terminator, uint32_t first_timeout, uint32_t digit_timeout, uint32_t abs_timeout)
Wait for specified number of DTMF digits, untile terminator is received or until the channel hangs up...
switch_byte_t switch_byte_t * buf
void bridge(CoreSession &session_a, CoreSession &session_b)
bridge the audio of session_b into session_a
switch_status_t switch_ivr_multi_threaded_bridge(_In_ switch_core_session_t *session, _In_ switch_core_session_t *peer_session, switch_input_callback_function_t dtmf_callback, void *session_data, void *peer_session_data)
Bridge Audio from one session to another.
switch_status_t(* switch_input_callback_function_t)(switch_core_session_t *session, void *input, switch_input_type_t input_type, void *buf, unsigned int buflen)
switch_log_level_t switch_log_str2level(_In_z_ const char *str)
Return the level number of the specified log level name.
char * switch_event_get_body(switch_event_t *event)
Retrieve the body value from an event.
#define switch_channel_get_variable(_c, _v)
switch_core_session_t * session
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
int globalSetVariable(const char *var, const char *val, const char *val2)
const char * switch_event_name(switch_event_types_t event)
Render the name of an event id enumeration.
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
switch_status_t dtmf_callback(switch_core_session_t *session_cb, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
switch_call_cause_t switch_channel_str2cause(_In_ const char *str)
return a cause code for a given string
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype)=0
#define SWITCH_CHANNEL_LOG_CLEAN
switch_status_t switch_event_create_json(switch_event_t **event, const char *json)
virtual void destroy(void)
switch_byte_t switch_byte_t uint32_t buflen
int64_t switch_interval_time_t
#define SWITCH_STANDARD_STREAM(s)
switch_call_cause_t cause
switch_channel_state_t hook_state
#define this_check_void()
void switch_core_session_rwunlock(_In_ switch_core_session_t *session)
Unlock a read or write lock on as given session.
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.
switch_status_t switch_channel_set_variable_var_check(switch_channel_t *channel, const char *varname, const char *value, switch_bool_t var_check)
#define sanity_check_noreturn
switch_status_t switch_ivr_record_file(_In_ switch_core_session_t *session, _In_ switch_file_handle_t *fh, _In_z_ const char *file, _In_opt_ switch_input_args_t *args, _In_ uint32_t limit)
record a file from the session to a file
#define switch_str_nil(s)
Make a null string a blank string instead.
void switch_msleep(unsigned ms)
Event(const char *type, const char *subclass_name=NULL)
switch_channel_state_t
Channel States (these are the defaults, CS_SOFT_EXECUTE, CS_EXCHANGE_MEDIA, and CS_CONSUME_MEDIA are ...
bool email(char *to, char *from, char *headers, char *body, char *file, char *convert_cmd, char *convert_ext)
switch_stream_handle_write_function_t write_function
#define switch_channel_down(_channel)
switch_status_t
Common return values.
void * switch_channel_get_private(switch_channel_t *channel, const char *key)
Retrieve private from a given channel.
switch_status_t switch_core_session_read_lock_hangup(_In_ switch_core_session_t *session)
Acquire a read lock on the session.
switch_status_t switch_core_session_dequeue_event(_In_ switch_core_session_t *session, _Out_ switch_event_t **event, switch_bool_t force)
DE-Queue an event on a given session.
char * getGlobalVariable(char *var_name)
switch_status_t switch_core_session_receive_event(_In_ switch_core_session_t *session, _Inout_ switch_event_t **event)
Send an event to a session translating it to it's native message format.
switch_status_t switch_queue_interrupt_all(switch_queue_t *queue)
static void event_handler(switch_event_t *event)
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)
#define switch_event_get_header(_e, _h)
switch_call_direction_t switch_channel_direction(switch_channel_t *channel)
switch_status_t switch_core_execute_chat_app(switch_event_t *message, const char *app, const char *data)
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
virtual void check_hangup_hook()=0
Callback to the language specific hangup callback.
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
void switch_event_destroy(switch_event_t **event)
Destroy an event.
switch_status_t switch_ivr_generate_xml_cdr(switch_core_session_t *session, switch_xml_t *xml_cdr)
Generate an XML CDR report.
#define switch_channel_pre_answer(channel)
Indicate progress on a channel to attempt early media.
switch_status_t switch_event_serialize(switch_event_t *event, char **str, switch_bool_t encode)
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
void console_log(char *level_str, char *msg)
switch_status_t switch_ivr_originate(switch_core_session_t *session, switch_core_session_t **bleg, switch_call_cause_t *cause, const char *bridgeto, uint32_t timelimit_sec, const switch_state_handler_table_t *table, const char *cid_name_override, const char *cid_num_override, switch_caller_profile_t *caller_profile_override, switch_event_t *ovars, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
Make an outgoing call.
switch_log_level_t
Log Level Enumeration.
char * switch_core_get_variable_dup(_In_z_ const char *varname)
void consoleLog(char *level_str, char *msg)
switch_call_cause_t switch_channel_get_cause(_In_ switch_channel_t *channel)
return the cause code for a given channel
switch_xml_t switch_event_xmlize(switch_event_t *event, const char *fmt,...) PRINTF_FUNCTION(2
Render a XML representation of an event suitable for printing or network transport.
switch_status_t switch_event_unbind(switch_event_node_t **node)
Unbind a bound event consumer.
int bind(const char *event_name, const char *subclass_name="")