RTS API Documentation  1.10.11
Data Structures | Macros | Typedefs | Enumerations | Functions
Eventing Engine
+ Collaboration diagram for Eventing Engine:

Data Structures

struct  switch_event_header
 An event Header. More...
 
struct  switch_event
 Representation of an event. More...
 
struct  switch_serial_event_s
 
struct  switch_serial_event_header_s
 

Macros

#define SWITCH_EVENT_SUBCLASS_ANY   NULL
 
#define switch_event_create_subclass(_e, _eid, _sn)   switch_event_create_subclass_detailed(__FILE__, (const char * )__SWITCH_FUNC__, __LINE__, _e, _eid, _sn)
 
#define switch_event_get_header(_e, _h)   switch_event_get_header_idx(_e, _h, -1)
 
#define switch_event_get_header_nil(e, h)   switch_str_nil(switch_event_get_header(e,h))
 
#define switch_event_del_header(_e, _h)   switch_event_del_header_val(_e, _h, NULL)
 
#define switch_event_safe_destroy(_event)   if (_event) switch_event_destroy(&_event)
 
#define switch_event_prep_for_delivery(_event)   switch_event_prep_for_delivery_detailed(__FILE__, (const char * )__SWITCH_FUNC__, __LINE__, _event)
 
#define switch_event_expand_headers(_event, _in)   switch_event_expand_headers_check(_event, _in, NULL, NULL, 0)
 
#define switch_event_create_pres_in(event)
 
#define switch_event_reserve_subclass(subclass_name)   switch_event_reserve_subclass_detailed(__FILE__, subclass_name)
 Reserve a subclass assuming the owner string is the current filename. More...
 
#define switch_event_free_subclass(subclass_name)   switch_event_free_subclass_detailed(__FILE__, subclass_name)
 
#define switch_event_create(event, id)   switch_event_create_subclass(event, id, SWITCH_EVENT_SUBCLASS_ANY)
 Create a new event assuming it will not be custom event and therefore hiding the unused parameters. More...
 
#define switch_event_fire(event)   switch_event_fire_detailed(__FILE__, (const char * )__SWITCH_FUNC__, __LINE__, event, NULL)
 Fire an event filling in most of the arguements with obvious values. More...
 
#define switch_event_fire_data(event, data)   switch_event_fire_detailed(__FILE__, (const char * )__SWITCH_FUNC__, __LINE__, event, data)
 Fire an event filling in most of the arguements with obvious values and allowing user_data to be sent. More...
 
#define NO_EVENT_CHANNEL_ID   0
 
#define SWITCH_EVENT_CHANNEL_GLOBAL   "__global__"
 

Typedefs

typedef struct switch_serial_event_s switch_serial_event_t
 
typedef struct switch_serial_event_header_s switch_serial_event_header_t
 
typedef void(* switch_live_array_command_handler_t) (switch_live_array_t *la, const char *cmd, const char *sessid, cJSON *jla, void *user_data)
 

Enumerations

enum  switch_event_flag_t { EF_UNIQ_HEADERS = (1 << 0), EF_NO_CHAT_EXEC = (1 << 1), EF_DEFAULT_ALLOW = (1 << 2) }
 

Functions

switch_status_t switch_event_init (switch_memory_pool_t *pool)
 Start the eventing system. More...
 
switch_status_t switch_event_shutdown (void)
 Stop the eventing system. More...
 
switch_status_t switch_event_create_subclass_detailed (const char *file, const char *func, int line, switch_event_t **event, switch_event_types_t event_id, const char *subclass_name)
 Create an event. More...
 
switch_status_t switch_event_set_priority (switch_event_t *event, switch_priority_t priority)
 Set the priority of an event. More...
 
switch_event_header_tswitch_event_get_header_ptr (switch_event_t *event, const char *header_name)
 Retrieve a header value from an event. More...
 
_Ret_opt_z_ char * switch_event_get_header_idx (switch_event_t *event, const char *header_name, int idx)
 
switch_status_t switch_event_rename_header (switch_event_t *event, const char *header_name, const char *new_header_name)
 
char * switch_event_get_body (switch_event_t *event)
 Retrieve the body value from an event. More...
 
switch_status_t switch_event_add_header (switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
 Add a header to an event. More...
 
switch_status_t switch_status_t switch_event_set_subclass_name (switch_event_t *event, const char *subclass_name)
 
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. More...
 
switch_status_t switch_event_add_header_string_nodup (switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
 
switch_status_t switch_event_del_header_val (switch_event_t *event, const char *header_name, const char *val)
 
int switch_event_add_array (switch_event_t *event, const char *var, const char *val)
 
void switch_event_destroy (switch_event_t **event)
 Destroy an event. More...
 
switch_status_t switch_event_dup (switch_event_t **event, switch_event_t *todup)
 Duplicate an event. More...
 
void switch_event_merge (switch_event_t *event, switch_event_t *tomerge)
 
switch_status_t switch_event_dup_reply (switch_event_t **event, switch_event_t *todup)
 
switch_status_t switch_event_fire_detailed (const char *file, const char *func, int line, switch_event_t **event, void *user_data)
 Fire an event with full arguement list. More...
 
void switch_event_prep_for_delivery_detailed (const char *file, const char *func, int line, switch_event_t *event)
 
switch_status_t switch_event_bind (const char *id, switch_event_types_t event, const char *subclass_name, switch_event_callback_t callback, void *user_data)
 Bind an event callback to a specific event. More...
 
switch_status_t switch_event_get_custom_events (switch_console_callback_match_t **matches)
 
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. More...
 
switch_status_t switch_event_unbind (switch_event_node_t **node)
 Unbind a bound event consumer. More...
 
switch_status_t switch_event_unbind_callback (switch_event_callback_t callback)
 
const char * switch_event_name (switch_event_types_t event)
 Render the name of an event id enumeration. More...
 
switch_status_t switch_name_event (const char *name, switch_event_types_t *type)
 return the event id that matches a given event name More...
 
switch_status_t switch_event_reserve_subclass_detailed (const char *owner, const char *subclass_name)
 Reserve a subclass name for private use with a custom event. More...
 
switch_status_t switch_event_free_subclass_detailed (const char *owner, const char *subclass_name)
 
switch_status_t switch_event_binary_deserialize (switch_event_t **eventp, void **data, switch_size_t len, switch_bool_t duplicate)
 Render a string representation of an event suitable for printing or network transport. More...
 
switch_status_t switch_event_binary_serialize (switch_event_t *event, void **data, switch_size_t *len)
 
switch_status_t switch_event_serialize (switch_event_t *event, char **str, switch_bool_t encode)
 
switch_status_t switch_event_serialize_json (switch_event_t *event, char **str)
 
switch_status_t switch_event_serialize_json_obj (switch_event_t *event, cJSON **json)
 
switch_status_t switch_event_create_json (switch_event_t **event, const char *json)
 
switch_status_t switch_event_create_brackets (char *data, char a, char b, char c, switch_event_t **event, char **new_data, switch_bool_t dup)
 
switch_status_t switch_event_create_array_pair (switch_event_t **event, char **names, char **vals, int len)
 
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. More...
 
switch_xml_t switch_status_t switch_event_running (void)
 Determine if the event system has been initialized. More...
 
switch_status_t switch_event_add_body (switch_event_t *event, const char *fmt,...) PRINTF_FUNCTION(2
 Add a body to an event. More...
 
switch_status_t switch_status_t switch_event_set_body (switch_event_t *event, const char *body)
 
char * switch_event_expand_headers_check (switch_event_t *event, const char *in, switch_event_t *var_list, switch_event_t *api_list, uint32_t recur)
 
switch_status_t switch_event_create_pres_in_detailed (_In_z_ char *file, _In_z_ char *func, _In_ int line, _In_z_ const char *proto, _In_z_ const char *login, _In_z_ const char *from, _In_z_ const char *from_domain, _In_z_ const char *status, _In_z_ const char *event_type, _In_z_ const char *alt_event_type, _In_ int event_count, _In_z_ const char *unique_id, _In_z_ const char *channel_state, _In_z_ const char *answer_state, _In_z_ const char *call_direction)
 
static switch_status_t switch_event_create_plain (switch_event_t **event, switch_event_types_t event_id)
 
void switch_event_deliver (switch_event_t **event)
 Deliver an event to all of the registered event listeners. More...
 
char * switch_event_build_param_string (switch_event_t *event, const char *prefix, switch_hash_t *vars_map)
 
int switch_event_check_permission_list (switch_event_t *list, const char *name)
 
void switch_event_add_presence_data_cols (switch_channel_t *channel, switch_event_t *event, const char *prefix)
 
void switch_json_add_presence_data_cols (switch_event_t *event, cJSON *json, const char *prefix)
 
void switch_event_launch_dispatch_threads (uint32_t max)
 
switch_status_t switch_event_channel_broadcast (const char *event_channel, cJSON **json, const char *key, switch_event_channel_id_t id)
 
switch_status_t switch_event_channel_deliver (const char *event_channel, cJSON **json, const char *key, switch_event_channel_id_t id)
 
uint32_t switch_event_channel_unbind (const char *event_channel, switch_event_channel_func_t func, void *user_data)
 
switch_status_t switch_event_channel_bind (const char *event_channel, switch_event_channel_func_t func, switch_event_channel_id_t *id, void *user_data)
 
switch_status_t switch_live_array_clear (switch_live_array_t *la)
 
switch_status_t switch_live_array_bootstrap (switch_live_array_t *la, const char *sessid, switch_event_channel_id_t channel_id)
 
switch_status_t switch_live_array_destroy (switch_live_array_t **live_arrayP)
 
switch_status_t switch_live_array_create (const char *event_channel, const char *name, switch_event_channel_id_t channel_id, switch_live_array_t **live_arrayP)
 
cJSONswitch_live_array_get (switch_live_array_t *la, const char *name)
 
cJSONswitch_live_array_get_idx (switch_live_array_t *la, int idx)
 
switch_status_t switch_live_array_del (switch_live_array_t *la, const char *name)
 
switch_status_t switch_live_array_add (switch_live_array_t *la, const char *name, int index, cJSON **obj, switch_bool_t destroy)
 
switch_status_t switch_live_array_visible (switch_live_array_t *la, switch_bool_t visible, switch_bool_t force)
 
switch_bool_t switch_live_array_isnew (switch_live_array_t *la)
 
void switch_live_array_lock (switch_live_array_t *la)
 
void switch_live_array_unlock (switch_live_array_t *la)
 
void switch_live_array_set_user_data (switch_live_array_t *la, void *user_data)
 
void switch_live_array_set_command_handler (switch_live_array_t *la, switch_live_array_command_handler_t command_handler)
 
void switch_live_array_parse_json (cJSON *json, switch_event_channel_id_t channel_id)
 
switch_bool_t switch_live_array_add_alias (switch_live_array_t *la, const char *event_channel, const char *name)
 
switch_bool_t switch_live_array_clear_alias (switch_live_array_t *la, const char *event_channel, const char *name)
 
switch_bool_t switch_event_channel_permission_verify (const char *cookie, const char *event_channel)
 
void switch_event_channel_permission_modify (const char *cookie, const char *event_channel, switch_bool_t set)
 
void switch_event_channel_permission_clear (const char *cookie)
 

Detailed Description

Macro Definition Documentation

◆ NO_EVENT_CHANNEL_ID

#define NO_EVENT_CHANNEL_ID   0

Definition at line 439 of file switch_event.h.

◆ SWITCH_EVENT_CHANNEL_GLOBAL

#define SWITCH_EVENT_CHANNEL_GLOBAL   "__global__"

Definition at line 440 of file switch_event.h.

Referenced by ecd_deliver().

◆ switch_event_create

#define switch_event_create (   event,
  id 
)    switch_event_create_subclass(event, id, SWITCH_EVENT_SUBCLASS_ANY)

Create a new event assuming it will not be custom event and therefore hiding the unused parameters.

Parameters
eventa NULL pointer on which to create the event
idthe event id enumeration of the desired event
Returns
SWITCH_STATUS_SUCCESS on success

Definition at line 384 of file switch_event.h.

Referenced by check_ip(), generate_on_dtmf(), handle_SIGHUP(), hanguphook(), process_device_hup(), record_callback(), rtp_common_write(), send_heartbeat(), send_record_stop_event(), signal_bridge_on_hangup(), signal_bridge_on_hibernate(), speech_thread(), switch_api_execute(), switch_channel_check_device_state(), switch_channel_clear_device_record(), switch_channel_dequeue_dtmf(), switch_channel_flip_cid(), switch_channel_get_variables(), switch_channel_get_variables_prefix(), switch_channel_mark_hold(), switch_channel_perform_hangup(), switch_channel_perform_mark_answered(), switch_channel_perform_mark_pre_answered(), switch_channel_perform_mark_ring_ready_value(), switch_channel_perform_presence(), switch_channel_perform_set_callstate(), switch_channel_perform_set_running_state(), switch_console_printf(), switch_core_chat_send_args(), switch_core_destroy(), switch_core_init_and_modload(), switch_core_media_bug_add(), switch_core_media_bug_destroy(), switch_core_media_read_frame(), switch_core_media_sdp_map(), switch_core_session_ctl(), switch_core_session_exec(), switch_core_session_execute_application_async(), switch_core_session_hupall_matching_var_ans(), switch_core_session_outgoing_channel(), switch_core_session_perform_destroy(), switch_core_session_read_frame(), switch_core_session_read_text_frame(), switch_core_session_reporting_state(), switch_core_session_run(), switch_core_session_set_read_codec(), switch_core_session_set_real_read_codec(), switch_core_session_set_uuid(), switch_core_session_set_video_read_codec(), switch_core_session_set_video_write_codec(), switch_core_session_set_write_codec(), switch_core_session_thread(), switch_event_binary_deserialize(), switch_event_create_array_pair(), switch_event_create_json(), switch_event_create_plain(), switch_event_import_xml(), switch_http_parse_header(), switch_ivr_broadcast(), switch_ivr_check_presence_mapping(), switch_ivr_hold(), switch_ivr_multi_threaded_bridge(), switch_ivr_park(), switch_ivr_phrase_macro_event(), switch_ivr_play_file(), switch_ivr_record_file_event(), switch_ivr_say(), switch_ivr_say_string(), switch_ivr_signal_bridge(), switch_ivr_unhold(), switch_load_network_lists(), switch_loadable_module_process(), switch_loadable_module_unprocess(), switch_log_meta_vprintf(), switch_msrp_msg_create(), switch_nat_add_mapping_internal(), switch_nat_del_mapping(), switch_nat_multicast_runtime(), switch_odbc_handle_disconnect(), switch_rtp_add_crypto_key(), switch_scheduler_add_task_ex(), switch_scheduler_execute(), switch_send_rtcp_event(), SWITCH_STANDARD_SCHED_FUNC(), switch_xml_locate_domain(), switch_xml_locate_group(), switch_xml_locate_user(), switch_xml_open_root(), task_thread_loop(), text_callback(), tone_detect_callback(), and uuid_bridge_on_soft_execute().

◆ switch_event_create_pres_in

#define switch_event_create_pres_in (   event)
Value:
switch_event_create_pres_in_detailed(__FILE__, (const char * )__SWITCH_FUNC__, __LINE__, \
proto, login, from, from_domain, status, event_type, alt_event_type, event_count, \
unique_id, channel_state, answer_state, call_direction)
#define __SWITCH_FUNC__
switch_status_t switch_event_create_pres_in_detailed(_In_z_ char *file, _In_z_ char *func, _In_ int line, _In_z_ const char *proto, _In_z_ const char *login, _In_z_ const char *from, _In_z_ const char *from_domain, _In_z_ const char *status, _In_z_ const char *event_type, _In_z_ const char *alt_event_type, _In_ int event_count, _In_z_ const char *unique_id, _In_z_ const char *channel_state, _In_z_ const char *answer_state, _In_z_ const char *call_direction)

Definition at line 364 of file switch_event.h.

◆ switch_event_create_subclass

#define switch_event_create_subclass (   _e,
  _eid,
  _sn 
)    switch_event_create_subclass_detailed(__FILE__, (const char * )__SWITCH_FUNC__, __LINE__, _e, _eid, _sn)

◆ switch_event_del_header

#define switch_event_del_header (   _e,
  _h 
)    switch_event_del_header_val(_e, _h, NULL)

◆ switch_event_expand_headers

#define switch_event_expand_headers (   _event,
  _in 
)    switch_event_expand_headers_check(_event, _in, NULL, NULL, 0)

◆ switch_event_fire

#define switch_event_fire (   event)    switch_event_fire_detailed(__FILE__, (const char * )__SWITCH_FUNC__, __LINE__, event, NULL)

Fire an event filling in most of the arguements with obvious values.

Parameters
eventthe event to send (will be nulled on success)
Returns
SWITCH_STATUS_SUCCESS if the operation was successful
Note
the body supplied by this function will supersede an existing body the event may have

Definition at line 413 of file switch_event.h.

Referenced by check_ip(), do_chat_send(), Event::fire(), generate_on_dtmf(), handle_SIGHUP(), hanguphook(), ivr_send_event(), record_callback(), rtp_common_write(), send_heartbeat(), send_record_stop_event(), signal_bridge_on_hangup(), signal_bridge_on_hibernate(), speech_thread(), switch_api_execute(), switch_channel_check_device_state(), switch_channel_clear_device_record(), switch_channel_dequeue_dtmf(), switch_channel_flip_cid(), switch_channel_mark_hold(), switch_channel_perform_hangup(), switch_channel_perform_mark_answered(), switch_channel_perform_mark_pre_answered(), switch_channel_perform_mark_ring_ready_value(), switch_channel_perform_presence(), switch_channel_perform_set_callstate(), switch_channel_perform_set_running_state(), switch_console_printf(), switch_core_destroy(), switch_core_init_and_modload(), switch_core_media_bug_add(), switch_core_media_bug_destroy(), switch_core_media_read_frame(), switch_core_session_ctl(), switch_core_session_exec(), switch_core_session_outgoing_channel(), switch_core_session_perform_destroy(), switch_core_session_read_frame(), switch_core_session_read_text_frame(), switch_core_session_reporting_state(), switch_core_session_run(), switch_core_session_set_read_codec(), switch_core_session_set_real_read_codec(), switch_core_session_set_uuid(), switch_core_session_set_video_read_codec(), switch_core_session_set_video_write_codec(), switch_core_session_set_write_codec(), switch_ivr_hold(), switch_ivr_multi_threaded_bridge(), switch_ivr_park(), switch_ivr_parse_next_event(), switch_ivr_play_file(), switch_ivr_record_file_event(), switch_ivr_signal_bridge(), switch_ivr_unhold(), switch_limit_fire_event(), switch_loadable_module_init(), switch_loadable_module_process(), switch_loadable_module_unprocess(), switch_log_meta_vprintf(), switch_nat_add_mapping_internal(), switch_nat_del_mapping(), switch_nat_multicast_runtime(), switch_odbc_handle_disconnect(), switch_rtp_add_crypto_key(), switch_scheduler_task_thread(), switch_send_rtcp_event(), SWITCH_STANDARD_SCHED_FUNC(), switch_xml_open_root(), text_callback(), tone_detect_callback(), and uuid_bridge_on_soft_execute().

◆ switch_event_fire_data

#define switch_event_fire_data (   event,
  data 
)    switch_event_fire_detailed(__FILE__, (const char * )__SWITCH_FUNC__, __LINE__, event, data)

Fire an event filling in most of the arguements with obvious values and allowing user_data to be sent.

Parameters
eventthe event to send (will be nulled on success)
datauser data to send to the event handlers
Returns
SWITCH_STATUS_SUCCESS if the operation was successful
Note
the body supplied by this function will supersede an existing body the event may have

Definition at line 422 of file switch_event.h.

◆ switch_event_free_subclass

#define switch_event_free_subclass (   subclass_name)    switch_event_free_subclass_detailed(__FILE__, subclass_name)

Definition at line 376 of file switch_event.h.

◆ switch_event_get_header

#define switch_event_get_header (   _e,
  _h 
)    switch_event_get_header_idx(_e, _h, -1)

◆ switch_event_get_header_nil

#define switch_event_get_header_nil (   e,
 
)    switch_str_nil(switch_event_get_header(e,h))

Definition at line 174 of file switch_event.h.

Referenced by core_event_handler(), and parse_presence_data_cols().

◆ switch_event_prep_for_delivery

#define switch_event_prep_for_delivery (   _event)    switch_event_prep_for_delivery_detailed(__FILE__, (const char * )__SWITCH_FUNC__, __LINE__, _event)

Definition at line 243 of file switch_event.h.

Referenced by switch_ivr_parse_next_event().

◆ switch_event_reserve_subclass

#define switch_event_reserve_subclass (   subclass_name)    switch_event_reserve_subclass_detailed(__FILE__, subclass_name)

Reserve a subclass assuming the owner string is the current filename.

Parameters
subclass_namethe subclass name to reserve
Returns
SWITCH_STATUS_SUCCESS if the operation was successful
Note
the body supplied by this function will supersede an existing body the event may have

Definition at line 375 of file switch_event.h.

Referenced by switch_limit_init().

◆ switch_event_safe_destroy

#define switch_event_safe_destroy (   _event)    if (_event) switch_event_destroy(&_event)

Definition at line 219 of file switch_event.h.

Referenced by record_helper_destroy().

◆ SWITCH_EVENT_SUBCLASS_ANY

#define SWITCH_EVENT_SUBCLASS_ANY   NULL

Typedef Documentation

◆ switch_live_array_command_handler_t

typedef void(* switch_live_array_command_handler_t) (switch_live_array_t *la, const char *cmd, const char *sessid, cJSON *jla, void *user_data)

Definition at line 437 of file switch_event.h.

◆ switch_serial_event_header_t

◆ switch_serial_event_t

Enumeration Type Documentation

◆ switch_event_flag_t

Enumerator
EF_UNIQ_HEADERS 
EF_NO_CHAT_EXEC 
EF_DEFAULT_ALLOW 

Definition at line 119 of file switch_event.h.

119  {
120  EF_UNIQ_HEADERS = (1 << 0),
121  EF_NO_CHAT_EXEC = (1 << 1),
122  EF_DEFAULT_ALLOW = (1 << 2)
switch_event_flag_t
Definition: switch_event.h:119

Function Documentation

◆ switch_event_add_array()

int switch_event_add_array ( switch_event_t event,
const char *  var,
const char *  val 
)

Definition at line 962 of file switch_event.c.

References memset(), switch_assert, switch_event_add_header_string(), switch_separate_string_string(), and SWITCH_STACK_PUSH.

Referenced by switch_event_base_add_header().

963 {
964  char *data;
965  char **array;
966  int max = 0;
967  int len;
968  const char *p;
969  int i;
970 
971  if (strlen(val) < 8) {
972  return -1;
973  }
974 
975  p = val + 7;
976 
977  max = 1;
978 
979  while((p = strstr(p, "|:"))) {
980  max++;
981  p += 2;
982  }
983 
984  data = strdup(val + 7);
985 
986  len = (sizeof(char *) * max) + 1;
987  switch_assert(len);
988 
989  array = malloc(len);
990  switch_assert(array);
991  memset(array, 0, len);
992 
993  switch_separate_string_string(data, "|:", array, max);
994 
995  for(i = 0; i < max; i++) {
996  switch_event_add_header_string(event, SWITCH_STACK_PUSH, var, array[i]);
997  }
998 
999  free(array);
1000  free(data);
1001 
1002  return 0;
1003 }
unsigned int switch_separate_string_string(char *buf, char *delim, _Post_count_(return) char **array, unsigned int arraylen)
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.
#define switch_assert(expr)
memset(buf, 0, buflen)

◆ switch_event_add_body()

switch_status_t switch_event_add_body ( switch_event_t event,
const char *  fmt,
  ... 
)

Add a body to an event.

Parameters
eventthe event to add to body to
fmtoptional body of the event (varargs see standard sprintf family)
Returns
SWITCH_STATUS_SUCCESS if the body was added to the event
Note
the body parameter can be shadowed by the switch_event_reserve_subclass_detailed function

Referenced by Event::addBody(), speech_thread(), switch_core_chat_send_args(), switch_core_session_read_text_frame(), switch_core_session_reporting_state(), and text_callback().

◆ switch_event_add_header()

switch_status_t switch_event_add_header ( switch_event_t event,
switch_stack_t  stack,
const char *  header_name,
const char *  fmt,
  ... 
)

◆ switch_event_add_header_string()

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.

Parameters
eventthe event to add the header to
stackthe stack sense (stack it on the top or on the bottom)
header_namethe name of the header to add
datathe value of the header
Returns
SWITCH_STATUS_SUCCESS if the header was added

Definition at line 1247 of file switch_event.c.

References DUP, switch_event_base_add_header(), and SWITCH_STATUS_GENERR.

Referenced by Event::addHeader(), check_ip(), do_chat_send(), generate_on_dtmf(), ivr_send_event(), merge_recording_variables(), record_callback(), send_record_stop_event(), signal_bridge_on_hangup(), signal_bridge_on_hibernate(), speech_thread(), switch_api_execute(), switch_caller_profile_event_set_data(), switch_channel_add_variable_var_check(), switch_channel_check_device_state(), switch_channel_clear_device_record(), switch_channel_event_set_basic_data(), switch_channel_event_set_extended_data(), switch_channel_flip_cid(), switch_channel_get_scope_variables(), switch_channel_get_variables_prefix(), switch_channel_perform_presence(), switch_channel_perform_set_callstate(), switch_channel_process_export(), switch_channel_set_log_tag(), switch_channel_set_variable_strip_quotes_var_check(), switch_channel_set_variable_var_check(), switch_console_printf(), switch_core_chat_deliver(), switch_core_chat_send(), switch_core_chat_send_args(), switch_core_hash_delete_multi(), switch_core_media_read_frame(), switch_core_media_sdp_map(), switch_core_session_exec(), switch_core_session_execute_application_async(), switch_core_session_hupall_matching_var_ans(), switch_core_session_reporting_state(), switch_core_session_set_read_codec(), switch_core_session_set_real_read_codec(), switch_core_session_set_uuid(), switch_core_session_set_video_read_codec(), switch_core_session_set_video_write_codec(), switch_core_session_set_write_codec(), switch_core_set_variable(), switch_dial_handle_add_global_var(), switch_dial_handle_add_leg_var(), switch_dial_handle_list_add_global_var(), switch_event_add_array(), switch_event_add_presence_data_cols(), switch_event_binary_deserialize(), switch_event_channel_permission_modify(), switch_event_create_array_pair(), switch_event_create_brackets(), switch_event_create_json(), switch_event_create_pres_in_detailed(), switch_event_create_subclass_detailed(), switch_event_dup(), switch_event_dup_reply(), switch_event_import_xml(), switch_event_merge(), switch_event_prep_for_delivery_detailed(), switch_event_set_priority(), switch_event_set_subclass_name(), switch_http_parse_header(), switch_http_parse_qs(), switch_ivr_broadcast(), switch_ivr_check_presence_mapping(), switch_ivr_create_message_reply(), switch_ivr_enterprise_originate(), switch_ivr_multi_threaded_bridge(), switch_ivr_originate(), switch_ivr_phrase_macro_event(), switch_ivr_play_file(), switch_ivr_record_file_event(), switch_ivr_say(), switch_ivr_say_string(), switch_ivr_signal_bridge(), switch_limit_fire_event(), switch_load_network_lists(), switch_loadable_module_process(), switch_loadable_module_unprocess(), switch_log_meta_vprintf(), switch_log_node_to_json(), switch_msrp_msg_add_header(), switch_nat_add_mapping_internal(), switch_nat_del_mapping(), switch_nat_multicast_runtime(), switch_regex_set_event_header_callback(), switch_rtp_add_crypto_key(), switch_scheduler_add_task_ex(), switch_scheduler_execute(), switch_send_rtcp_event(), switch_xml_locate_domain(), switch_xml_locate_group(), switch_xml_locate_language(), switch_xml_locate_user(), task_thread_loop(), tone_detect_callback(), and uuid_bridge_on_soft_execute().

1248 {
1249  if (data) {
1250  return switch_event_base_add_header(event, stack, header_name, DUP(data));
1251  }
1252  return SWITCH_STATUS_GENERR;
1253 }
#define DUP(str)
Definition: switch_event.c:126
static switch_status_t switch_event_base_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, char *data)

◆ switch_event_add_header_string_nodup()

switch_status_t switch_event_add_header_string_nodup ( switch_event_t event,
switch_stack_t  stack,
const char *  header_name,
const char *  data 
)

Definition at line 1239 of file switch_event.c.

References switch_event_base_add_header(), and SWITCH_STATUS_GENERR.

Referenced by switch_core_set_var_conditional().

1240 {
1241  if (data) {
1242  return switch_event_base_add_header(event, stack, header_name, (char *)data);
1243  }
1244  return SWITCH_STATUS_GENERR;
1245 }
static switch_status_t switch_event_base_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, char *data)

◆ switch_event_add_presence_data_cols()

void switch_event_add_presence_data_cols ( switch_channel_t channel,
switch_event_t event,
const char *  prefix 
)

Definition at line 2694 of file switch_event.c.

References switch_channel_get_variable, switch_event_add_header_string(), switch_safe_free, switch_snprintf(), switch_split, and SWITCH_STACK_BOTTOM.

Referenced by signal_bridge_on_hangup(), signal_bridge_on_hibernate(), switch_channel_event_set_basic_data(), and switch_ivr_multi_threaded_bridge().

2695 {
2696  const char *data;
2697 
2698  if (!prefix) prefix = "";
2699 
2700  if ((data = switch_channel_get_variable(channel, "presence_data_cols"))) {
2701  char *cols[128] = { 0 };
2702  char header_name[128] = "";
2703  int col_count = 0, i = 0;
2704  char *data_copy = NULL;
2705 
2706  data_copy = strdup(data);
2707 
2708  col_count = switch_split(data_copy, ':', cols);
2709 
2710  for (i = 0; i < col_count; i++) {
2711  const char *val = NULL;
2712  switch_snprintf(header_name, sizeof(header_name), "%s%s", prefix, cols[i]);
2713 
2714  val = switch_channel_get_variable(channel, cols[i]);
2715  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header_name, val);
2716  }
2717 
2718  switch_safe_free(data_copy);
2719  }
2720 
2721 }
#define switch_split(_data, _delim, _array)
Definition: switch_utils.h:375
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
#define switch_channel_get_variable(_c, _v)
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.
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885

◆ switch_event_binary_deserialize()

switch_status_t switch_event_binary_deserialize ( switch_event_t **  eventp,
void **  data,
switch_size_t  len,
switch_bool_t  duplicate 
)

Render a string representation of an event suitable for printing or network transport.

Parameters
eventthe event to render
stra string pointer to point at the allocated data
encodeurl encode the headers
Returns
SWITCH_STATUS_SUCCESS if the operation was successful
Note
you must free the resulting string when you are finished with it

Definition at line 1430 of file switch_event.c.

References switch_serial_event_s::body, switch_serial_event_s::event_id, switch_serial_event_s::flags, switch_serial_event_header_s::name, switch_serial_event_s::owner, switch_serial_event_s::priority, switch_serial_event_s::subclass_name, switch_assert, switch_event_add_header_string(), SWITCH_EVENT_CLONE, switch_event_create, SWITCH_SERIALIZED_EVENT_MAP, SWITCH_STACK_BOTTOM, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_serial_event_header_s::value.

1431 {
1432 #ifdef HAVE_LIBTPL
1433  switch_event_t *event;
1434  tpl_node *tn;
1437  int how = TPL_MEM;
1438 
1440  switch_assert(event);
1441 
1442  tn = tpl_map(SWITCH_SERIALIZED_EVENT_MAP, &e, &sh);
1443 
1444  if (!destroy) {
1445  how |= TPL_EXCESS_OK;
1446  }
1447 
1448  tpl_load(tn, how, data, len);
1449 
1450  tpl_unpack(tn, 0);
1451 
1452  event->event_id = e.event_id;
1453  event->priority = e.priority;
1454  event->flags = e.flags;
1455 
1456  event->owner = e.owner;
1457  event->subclass_name = e.subclass_name;
1458  event->body = e.body;
1459 
1460 
1461  while (tpl_unpack(tn, 1)) {
1463  }
1464 
1465  *eventp = event;
1466 
1467  tpl_free(tn);
1468 
1469  if (destroy) {
1470  free(*data);
1471  }
1472 
1473  *data = NULL;
1474 
1475  return SWITCH_STATUS_SUCCESS;
1476 #else
1477  return SWITCH_STATUS_FALSE;
1478 #endif
1479 
1480 }
#define SWITCH_SERIALIZED_EVENT_MAP
Representation of an event.
Definition: switch_event.h:80
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.
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384
#define switch_assert(expr)

◆ switch_event_binary_serialize()

switch_status_t switch_event_binary_serialize ( switch_event_t event,
void **  data,
switch_size_t len 
)

Definition at line 1482 of file switch_event.c.

References switch_serial_event_s::body, switch_serial_event_s::event_id, switch_serial_event_s::flags, switch_event::headers, switch_event_header::idx, switch_event_header::name, switch_serial_event_header_s::name, switch_event_header::next, switch_serial_event_s::owner, switch_serial_event_s::priority, switch_serial_event_s::subclass_name, SWITCH_SERIALIZED_EVENT_MAP, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_event_header::value, and switch_serial_event_header_s::value.

1483 {
1484 #ifdef HAVE_LIBTPL
1485  tpl_node *tn;
1489  int how = TPL_MEM;
1490 
1491  e.event_id = event->event_id;
1492  e.priority = event->priority;
1493  e.flags = event->flags;
1494 
1495  e.owner = event->owner;
1496  e.subclass_name = event->subclass_name;
1497  e.body = event->body;
1498 
1499  tn = tpl_map(SWITCH_SERIALIZED_EVENT_MAP, &e, &sh);
1500 
1501  tpl_pack(tn, 0);
1502 
1503  for (eh = event->headers; eh; eh = eh->next) {
1504  if (eh->idx) continue; // no arrays yet
1505 
1506  sh.name = eh->name;
1507  sh.value = eh->value;
1508 
1509  tpl_pack(tn, 1);
1510  }
1511 
1512  if (*len > 0) {
1513  how |= TPL_PREALLOCD;
1514  }
1515 
1516  tpl_dump(tn, how, data, len);
1517 
1518  tpl_free(tn);
1519 
1520  return SWITCH_STATUS_SUCCESS;
1521 #else
1522  return SWITCH_STATUS_FALSE;
1523 #endif
1524 }
#define SWITCH_SERIALIZED_EVENT_MAP
An event Header.
Definition: switch_event.h:65
struct switch_event_header * next
Definition: switch_event.h:76
switch_event_header_t * headers
Definition: switch_event.h:90

◆ switch_event_bind()

switch_status_t switch_event_bind ( const char *  id,
switch_event_types_t  event,
const char *  subclass_name,
switch_event_callback_t  callback,
void *  user_data 
)

Bind an event callback to a specific event.

Parameters
idan identifier token of the binder
eventthe event enumeration to bind to
subclass_namethe event subclass to bind to in the case if SWITCH_EVENT_CUSTOM
callbackthe callback functon to bind
user_dataoptional user specific data to pass whenever the callback is invoked
Returns
SWITCH_STATUS_SUCCESS if the event was binded

Definition at line 2127 of file switch_event.c.

References switch_event_bind_removable().

Referenced by switch_core_sqldb_start().

2129 {
2130  return switch_event_bind_removable(id, event, subclass_name, callback, user_data, NULL);
2131 }
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.

◆ switch_event_bind_removable()

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.

Parameters
idan identifier token of the binder
eventthe event enumeration to bind to
subclass_namethe event subclass to bind to in the case if SWITCH_EVENT_CUSTOM
callbackthe callback functon to bind
user_dataoptional user specific data to pass whenever the callback is invoked
nodebind handle to later remove the binding.
Returns
SWITCH_STATUS_SUCCESS if the event was binded

Definition at line 2060 of file switch_event.c.

References switch_event_subclass::bind, BLOCK, switch_event_node::callback, CUSTOM_HASH_MUTEX, DUP, switch_event_node::event_id, switch_event_node::id, switch_event_node::next, RUNTIME_POOL, RWLOCK, switch_event_node::subclass_name, switch_assert, SWITCH_CHANNEL_LOG, switch_core_hash_find(), SWITCH_EVENT_ALL, switch_event_reserve_subclass_detailed(), SWITCH_LOG_ERROR, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, SWITCH_STATUS_MEMERR, SWITCH_STATUS_SUCCESS, switch_thread_rwlock_unlock(), switch_thread_rwlock_wrlock(), switch_zmalloc, and switch_event_node::user_data.

Referenced by EventConsumer::bind(), switch_event_bind(), and SWITCH_MODULE_LOAD_FUNCTION().

2062 {
2063  switch_event_node_t *event_node;
2064  switch_event_subclass_t *subclass = NULL;
2065 
2066  switch_assert(BLOCK != NULL);
2067  switch_assert(RUNTIME_POOL != NULL);
2068 
2069  if (node) {
2070  *node = NULL;
2071  }
2072 
2073  if (subclass_name) {
2075 
2076  if (!(subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name))) {
2078  if ((subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name))) {
2079  subclass->bind = 1;
2080  }
2081  }
2082  }
2083 
2085 
2086  if (!subclass) {
2087  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not reserve subclass. '%s'\n", subclass_name);
2088 
2089  return SWITCH_STATUS_FALSE;
2090  }
2091  }
2092 
2093  if (event <= SWITCH_EVENT_ALL) {
2094  switch_zmalloc(event_node, sizeof(*event_node));
2097  /* <LOCKED> ----------------------------------------------- */
2098  event_node->id = DUP(id);
2099  event_node->event_id = event;
2100  if (subclass_name) {
2101  event_node->subclass_name = DUP(subclass_name);
2102  }
2103 
2104  event_node->callback = callback;
2105  event_node->user_data = user_data;
2106 
2107  if (EVENT_NODES[event]) {
2108  event_node->next = EVENT_NODES[event];
2109  }
2110 
2111  EVENT_NODES[event] = event_node;
2114  /* </LOCKED> ----------------------------------------------- */
2115 
2116  if (node) {
2117  *node = event_node;
2118  }
2119 
2120  return SWITCH_STATUS_SUCCESS;
2121  }
2122 
2123  return SWITCH_STATUS_MEMERR;
2124 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:286
#define SWITCH_CHANNEL_LOG
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
static switch_event_node_t * EVENT_NODES[SWITCH_EVENT_ALL+1]
Definition: switch_event.c:87
static switch_thread_rwlock_t * RWLOCK
Definition: switch_event.c:88
static switch_mutex_t * CUSTOM_HASH_MUTEX
Definition: switch_event.c:98
A node to store binded events.
Definition: switch_event.c:48
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:260
static switch_hash_t * CUSTOM_HASH
Definition: switch_event.c:99
switch_event_types_t event_id
Definition: switch_event.c:52
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static switch_memory_pool_t * RUNTIME_POOL
Definition: switch_event.c:91
#define switch_zmalloc(ptr, len)
static switch_mutex_t * BLOCK
Definition: switch_event.c:89
A registered custom event subclass.
Definition: switch_event.c:63
#define DUP(str)
Definition: switch_event.c:126
struct switch_event_node * next
Definition: switch_event.c:59
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_event_reserve_subclass_detailed(const char *owner, const char *subclass_name)
Reserve a subclass name for private use with a custom event.
Definition: switch_event.c:485
switch_event_callback_t callback
Definition: switch_event.c:56
#define switch_assert(expr)

◆ switch_event_build_param_string()

char* switch_event_build_param_string ( switch_event_t event,
const char *  prefix,
switch_hash_t vars_map 
)

Definition at line 2550 of file switch_event.c.

References switch_stream_handle::data, switch_event::headers, switch_event_header::name, switch_event_header::next, switch_assert, switch_core_hash_find(), switch_safe_free, SWITCH_STANDARD_STREAM, switch_url_encode(), switch_event_header::value, switch_stream_handle::write_function, and zstr.

2551 {
2552  switch_stream_handle_t stream = { 0 };
2553  switch_size_t encode_len = 1024, new_len = 0;
2554  char *encode_buf = NULL;
2555  const char *prof[12] = { 0 }, *prof_names[12] = {
2556  0};
2557  char *e = NULL;
2559  uint32_t x = 0;
2560  void *data = NULL;
2561 
2562  SWITCH_STANDARD_STREAM(stream);
2563 
2564  if (prefix) {
2565  stream.write_function(&stream, "%s&", prefix);
2566  }
2567 
2568  encode_buf = malloc(encode_len);
2569  switch_assert(encode_buf);
2570 
2571 
2572 
2573  for (x = 0; prof[x]; x++) {
2574  if (zstr(prof[x])) {
2575  continue;
2576  }
2577  new_len = (strlen(prof[x]) * 3) + 1;
2578  if (encode_len < new_len) {
2579  char *tmp;
2580 
2581  encode_len = new_len;
2582 
2583  if (!(tmp = realloc(encode_buf, encode_len))) {
2584  abort();
2585  }
2586 
2587  encode_buf = tmp;
2588  }
2589  switch_url_encode(prof[x], encode_buf, encode_len);
2590  stream.write_function(&stream, "%s=%s&", prof_names[x], encode_buf);
2591  }
2592 
2593  if (event) {
2594  if ((hi = event->headers)) {
2595 
2596  for (; hi; hi = hi->next) {
2597  char *var = hi->name;
2598  char *val = hi->value;
2599 
2600  if (vars_map != NULL) {
2601  if ((data = switch_core_hash_find(vars_map, var)) == NULL || strcasecmp(((char *) data), "enabled"))
2602  continue;
2603 
2604  }
2605 
2606  new_len = (strlen((char *) val) * 3) + 1;
2607  if (encode_len < new_len) {
2608  char *tmp;
2609 
2610  encode_len = new_len;
2611 
2612  tmp = realloc(encode_buf, encode_len);
2613  switch_assert(tmp);
2614  encode_buf = tmp;
2615  }
2616 
2617  switch_url_encode((char *) val, encode_buf, encode_len);
2618  stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
2619 
2620  }
2621  }
2622  }
2623 
2624  e = (char *) stream.data + (strlen((char *) stream.data) - 1);
2625 
2626  if (e && *e == '&') {
2627  *e = '\0';
2628  }
2629 
2630  switch_safe_free(encode_buf);
2631 
2632  return stream.data;
2633 }
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
An event Header.
Definition: switch_event.h:65
char * switch_url_encode(const char *url, char *buf, size_t len)
#define zstr(x)
Definition: switch_utils.h:314
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
uintptr_t switch_size_t
#define SWITCH_STANDARD_STREAM(s)
switch_stream_handle_write_function_t write_function
struct switch_event_header * next
Definition: switch_event.h:76
#define switch_assert(expr)
switch_event_header_t * headers
Definition: switch_event.h:90

◆ switch_event_channel_bind()

switch_status_t switch_event_channel_bind ( const char *  event_channel,
switch_event_channel_func_t  func,
switch_event_channel_id_t id,
void *  user_data 
)

Definition at line 3129 of file switch_event.c.

References event_channel_manager, switch_assert, switch_event_channel_sub_channel(), SWITCH_STATUS_SUCCESS, switch_thread_rwlock_unlock(), and switch_thread_rwlock_wrlock().

3130 {
3132 
3133  switch_assert(id);
3134 
3135  if (!*id) {
3137  *id = event_channel_manager.ID++;
3139  }
3140 
3141  status = switch_event_channel_sub_channel(event_channel, func, *id, user_data);
3142 
3143  return status;
3144 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:286
static struct @5 event_channel_manager
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:260
switch_status_t
Common return values.
static switch_status_t switch_event_channel_sub_channel(const char *event_channel, switch_event_channel_func_t func, switch_event_channel_id_t id, void *user_data)
#define switch_assert(expr)

◆ switch_event_channel_broadcast()

switch_status_t switch_event_channel_broadcast ( const char *  event_channel,
cJSON **  json,
const char *  key,
switch_event_channel_id_t  id 
)

Definition at line 3049 of file switch_event.c.

References switch_thread_data_s::alloc, destroy_ecd(), DISPATCH_QUEUE_LEN, event_channel_data_t::event_channel, EVENT_CHANNEL_DISPATCH_QUEUE, EVENT_CHANNEL_DISPATCH_THREAD_COUNT, EVENT_CHANNEL_DISPATCH_THREAD_STARTING, EVENT_QUEUE_MUTEX, switch_thread_data_s::func, switch_event_node::id, event_channel_data_t::id, event_channel_data_t::json, event_channel_data_t::key, MAX_DISPATCH, switch_thread_data_s::obj, switch_thread_data_s::pool, switch_assert, SWITCH_CHANNEL_LOG, switch_event_channel_deliver_thread(), SWITCH_LOG_CRIT, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_queue_create(), switch_queue_trypush(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_thread_pool_launch_thread(), switch_zmalloc, SYSTEM_RUNNING, and THRUNTIME_POOL.

Referenced by la_broadcast(), and switch_live_array_bootstrap().

3050 {
3051  event_channel_data_t *ecd = NULL;
3053  int launch = 0;
3054 
3055  if (!SYSTEM_RUNNING) {
3056  cJSON_Delete(*json);
3057  *json = NULL;
3058  return SWITCH_STATUS_FALSE;
3059  }
3060 
3061  switch_zmalloc(ecd, sizeof(*ecd));
3062 
3063  ecd->event_channel = strdup(event_channel);
3064  ecd->json = *json;
3065  ecd->key = strdup(key);
3066  ecd->id = id;
3067 
3068  *json = NULL;
3069 
3073  launch = 1;
3074  }
3076 
3077  if (launch) {
3079 
3082  }
3083 
3084  td = malloc(sizeof(*td));
3085  switch_assert(td);
3086 
3087  td->alloc = 1;
3090  td->pool = NULL;
3091 
3093  }
3094 
3096  cJSON_Delete(ecd->json);
3097  ecd->json = NULL;
3098  destroy_ecd(&ecd);
3099  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Event Channel Queue failure for channel %s, status = %d\n", event_channel, status);
3100  } else {
3101  ecd = NULL;
3102  }
3103 
3104  return status;
3105 }
#define SWITCH_CHANNEL_LOG
static unsigned int MAX_DISPATCH
Definition: switch_event.c:83
static int SYSTEM_RUNNING
Definition: switch_event.c:104
#define DISPATCH_QUEUE_LEN
Definition: switch_event.c:44
static switch_queue_t * EVENT_CHANNEL_DISPATCH_QUEUE
Definition: switch_event.c:96
switch_memory_pool_t * pool
Definition: switch_core.h:71
switch_event_channel_id_t id
static int EVENT_CHANNEL_DISPATCH_THREAD_STARTING
Definition: switch_event.c:103
static void destroy_ecd(event_channel_data_t **ecdP)
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
#define switch_zmalloc(ptr, len)
switch_thread_start_t func
Definition: switch_core.h:67
static switch_mutex_t * EVENT_QUEUE_MUTEX
Definition: switch_event.c:97
static int EVENT_CHANNEL_DISPATCH_THREAD_COUNT
Definition: switch_event.c:102
static switch_memory_pool_t * THRUNTIME_POOL
Definition: switch_event.c:92
switch_status_t
Common return values.
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1279
char * key
Definition: switch_msrp.c:64
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)
Definition: switch_apr.c:1233
#define switch_assert(expr)
static void *SWITCH_THREAD_FUNC switch_event_channel_deliver_thread(switch_thread_t *thread, void *obj)
switch_status_t switch_thread_pool_launch_thread(switch_thread_data_t **tdp)

◆ switch_event_channel_deliver()

switch_status_t switch_event_channel_deliver ( const char *  event_channel,
cJSON **  json,
const char *  key,
switch_event_channel_id_t  id 
)

Definition at line 3107 of file switch_event.c.

References ecd_deliver(), event_channel_data_t::event_channel, switch_event_node::id, event_channel_data_t::id, event_channel_data_t::json, event_channel_data_t::key, SWITCH_STATUS_SUCCESS, and switch_zmalloc.

3108 {
3109  event_channel_data_t *ecd = NULL;
3110  switch_zmalloc(ecd, sizeof(*ecd));
3111 
3112  ecd->event_channel = strdup(event_channel);
3113  ecd->json = *json;
3114  ecd->key = strdup(key);
3115  ecd->id = id;
3116 
3117  *json = NULL;
3118 
3119  ecd_deliver(&ecd);
3120 
3121  return SWITCH_STATUS_SUCCESS;
3122 }
switch_event_channel_id_t id
static void ecd_deliver(event_channel_data_t **ecdP)
#define switch_zmalloc(ptr, len)
char * key
Definition: switch_msrp.c:64

◆ switch_event_channel_permission_clear()

void switch_event_channel_permission_clear ( const char *  cookie)

Definition at line 3184 of file switch_event.c.

References event_channel_manager, switch_core_hash_delete(), switch_core_hash_find(), switch_event_destroy(), switch_thread_rwlock_unlock(), and switch_thread_rwlock_wrlock().

3185 {
3186  switch_event_t *vals;
3187 
3189  if ((vals = switch_core_hash_find(event_channel_manager.perm_hash, cookie))) {
3191  switch_event_destroy(&vals);
3192  }
3194 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:286
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
static struct @5 event_channel_manager
Representation of an event.
Definition: switch_event.h:80
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:260
void * switch_core_hash_delete(_In_ switch_hash_t *hash, _In_z_ const char *key)
Delete data from a hash based on desired key.
void switch_event_destroy(switch_event_t **event)
Destroy an event.

◆ switch_event_channel_permission_modify()

void switch_event_channel_permission_modify ( const char *  cookie,
const char *  event_channel,
switch_bool_t  set 
)

Definition at line 3160 of file switch_event.c.

References event_channel_manager, switch_core_hash_find(), switch_core_hash_insert, switch_event_add_header_string(), SWITCH_EVENT_CHANNEL_DATA, switch_event_create_plain(), switch_event_del_header, SWITCH_STACK_BOTTOM, switch_thread_rwlock_unlock(), and switch_thread_rwlock_wrlock().

3161 {
3162  switch_event_t *vals;
3163 
3165  if (!(vals = switch_core_hash_find(event_channel_manager.perm_hash, cookie))) {
3166  if (!set) goto end;
3167 
3169  switch_core_hash_insert(event_channel_manager.perm_hash, cookie, vals);
3170  }
3171 
3172  if (set) {
3173  switch_event_add_header_string(vals, SWITCH_STACK_BOTTOM, event_channel, "true");
3174  } else {
3175  switch_event_del_header(vals, event_channel);
3176  }
3177 
3178 
3179  end:
3180 
3182 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:286
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
#define switch_event_del_header(_e, _h)
Definition: switch_event.h:212
static struct @5 event_channel_manager
Representation of an event.
Definition: switch_event.h:80
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:260
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.
static switch_status_t switch_event_create_plain(switch_event_t **event, switch_event_types_t event_id)
Definition: switch_event.h:386
#define switch_core_hash_insert(_h, _k, _d)
Definition: switch_core.h:1479

◆ switch_event_channel_permission_verify()

switch_bool_t switch_event_channel_permission_verify ( const char *  cookie,
const char *  event_channel 
)

Definition at line 3146 of file switch_event.c.

References event_channel_manager, switch_core_hash_find(), switch_event_get_header, SWITCH_FALSE, switch_thread_rwlock_rdlock(), switch_thread_rwlock_unlock(), and switch_true().

3147 {
3148  switch_event_t *vals;
3150 
3152  if ((vals = switch_core_hash_find(event_channel_manager.perm_hash, cookie))) {
3153  r = switch_true(switch_event_get_header(vals, event_channel));
3154  }
3156 
3157  return r;
3158 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:286
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:519
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
static struct @5 event_channel_manager
switch_bool_t
Definition: switch_types.h:437
Representation of an event.
Definition: switch_event.h:80
switch_status_t switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:250
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172

◆ switch_event_channel_unbind()

uint32_t switch_event_channel_unbind ( const char *  event_channel,
switch_event_channel_func_t  func,
void *  user_data 
)

Definition at line 3124 of file switch_event.c.

References switch_event_channel_unsub_channel().

3125 {
3126  return switch_event_channel_unsub_channel(func, event_channel, user_data);
3127 }
static uint32_t switch_event_channel_unsub_channel(switch_event_channel_func_t func, const char *event_channel, void *user_data)

◆ switch_event_check_permission_list()

int switch_event_check_permission_list ( switch_event_t list,
const char *  name 
)

Definition at line 2635 of file switch_event.c.

References EF_DEFAULT_ALLOW, switch_event::headers, switch_event_get_header, and switch_test_flag.

Referenced by switch_channel_expand_variables_check(), and switch_event_expand_headers_check().

2636 {
2637  const char *v;
2638  int r = 0;
2639  int default_allow = 0;
2640 
2641  if (!list) {
2642  return 1;
2643  }
2644 
2645  default_allow = switch_test_flag(list, EF_DEFAULT_ALLOW);
2646 
2647  if (!list->headers) {
2648  return default_allow;
2649  }
2650 
2651  if ((v = switch_event_get_header(list, name))) {
2652  if (*v == 'd') {
2653  r = 0;
2654  } else {
2655  r = 1;
2656  }
2657  } else {
2658  r = default_allow;
2659  }
2660 
2661  return r;
2662 }
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
const char *const name
Definition: switch_cJSON.h:250
switch_event_header_t * headers
Definition: switch_event.h:90

◆ switch_event_create_array_pair()

switch_status_t switch_event_create_array_pair ( switch_event_t **  event,
char **  names,
char **  vals,
int  len 
)

Definition at line 1642 of file switch_event.c.

References name, switch_event_add_header_string(), SWITCH_EVENT_CLONE, switch_event_create, SWITCH_STACK_BOTTOM, SWITCH_STATUS_SUCCESS, switch_str_nil, and zstr.

Referenced by helper_callback().

1643 {
1644  int r;
1645  char *name, *val;
1646 
1648 
1649  for (r = 0; r < len; r++) {
1650  val = switch_str_nil(vals[r]);
1651  name = names[r];
1652 
1653  if (zstr(name)) {
1654  name = "Unknown";
1655  }
1656 
1658  }
1659 
1660  return SWITCH_STATUS_SUCCESS;
1661 
1662 }
#define zstr(x)
Definition: switch_utils.h:314
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.
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:993
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384
const char *const name
Definition: switch_cJSON.h:250

◆ switch_event_create_brackets()

switch_status_t switch_event_create_brackets ( char *  data,
char  a,
char  b,
char  c,
switch_event_t **  event,
char **  new_data,
switch_bool_t  dup 
)

Definition at line 1664 of file switch_event.c.

References EF_UNIQ_HEADERS, switch_event::flags, switch_event_node::next, SWITCH_CHANNEL_LOG, switch_event_add_header_string(), SWITCH_EVENT_CHANNEL_DATA, switch_event_create_plain(), switch_find_end_paren(), SWITCH_LOG_DEBUG1, switch_log_printf(), switch_separate_string(), SWITCH_STACK_BOTTOM, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_strchr_strict().

Referenced by switch_core_perform_file_open(), switch_core_session_exec(), switch_ivr_enterprise_originate(), switch_ivr_originate(), and switch_log_node_to_json().

1665 {
1666  char *vdata, *vdatap = NULL;
1667  char *end, *check_a, *check_b;
1668  switch_event_t *e = *event;
1669  char *var_array[1024] = { 0 };
1670  int var_count = 0;
1671  char *next = NULL, *vnext = NULL;
1672 
1673  if (dup) {
1674  vdatap = strdup(data);
1675  vdata = vdatap;
1676  } else {
1677  vdata = data;
1678  }
1679 
1680  end = switch_find_end_paren(vdata, a, b);
1681 
1682  check_a = end;
1683 
1684  while (check_a && (check_b = switch_strchr_strict(check_a, a, " "))) {
1685  if ((check_b = switch_find_end_paren(check_b, a, b))) {
1686  check_a = check_b;
1687  }
1688  }
1689 
1690  if (check_a) end = check_a;
1691 
1692  if (end) {
1693  next = end;
1694  vdata++;
1695  *end++ = '\0';
1696  } else {
1697  if (dup) {
1698  free(vdatap);
1699  }
1700  return SWITCH_STATUS_FALSE;
1701  }
1702 
1703  if (!e) {
1705  e->flags |= EF_UNIQ_HEADERS;
1706  }
1707 
1708 
1709  for (;;) {
1710  if (next) {
1711  char *pnext;
1712 
1713  *next++ = '\0';
1714 
1715  if ((pnext = switch_strchr_strict(next, a, " "))) {
1716  next = pnext + 1;
1717  }
1718 
1719  vnext = switch_find_end_paren(next, a, b);
1720  next = NULL;
1721  }
1722 
1723 
1724  if (vdata) {
1725  if (*vdata == '^' && *(vdata + 1) == '^') {
1726  vdata += 2;
1727  c = *vdata++;
1728  }
1729  }
1730 
1731  if ((var_count = switch_separate_string(vdata, c, var_array, (sizeof(var_array) / sizeof(var_array[0]))))) {
1732  int x = 0;
1733  for (x = 0; x < var_count; x++) {
1734  char *inner_var_array[2] = { 0 };
1735 
1736  if (switch_separate_string(var_array[x], '=', inner_var_array, (sizeof(inner_var_array) / sizeof(inner_var_array[0]))) == 2) {
1737  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Parsing variable [%s]=[%s]\n", inner_var_array[0], inner_var_array[1]);
1738  switch_event_add_header_string(e, SWITCH_STACK_BOTTOM, inner_var_array[0], inner_var_array[1]);
1739  }
1740  }
1741  }
1742 
1743  if (vnext) {
1744  vdata = vnext;
1745  vnext = NULL;
1746  } else {
1747  break;
1748  }
1749 
1750  }
1751 
1752  *event = e;
1753 
1754  if (dup) {
1755  *new_data = strdup(end);
1756  free(vdatap);
1757  } else {
1758  *new_data = end;
1759  }
1760 
1761  return SWITCH_STATUS_SUCCESS;
1762 
1763 }
#define SWITCH_CHANNEL_LOG
char * switch_find_end_paren(const char *s, char open, char close)
Definition: switch_utils.c:796
const cJSON *const b
Definition: switch_cJSON.h:243
Representation of an event.
Definition: switch_event.h:80
static char * switch_strchr_strict(const char *in, char find, const char *allowed)
Definition: switch_utils.h:334
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.
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.
static switch_status_t switch_event_create_plain(switch_event_t **event, switch_event_types_t event_id)
Definition: switch_event.h:386
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_event_create_json()

switch_status_t switch_event_create_json ( switch_event_t **  event,
const char *  json 
)

Definition at line 1767 of file switch_event.c.

References cJSON::child, cJSON_Array, cJSON_String, switch_event::event_id, item, name, cJSON::next, cJSON::string, switch_event_add_body(), switch_event_add_header_string(), SWITCH_EVENT_CLONE, switch_event_create, switch_event_del_header, switch_name_event(), SWITCH_STACK_BOTTOM, SWITCH_STACK_PUSH, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, SWITCH_VA_NONE, cJSON::type, value, and cJSON::valuestring.

Referenced by Event::Event().

1768 {
1769  switch_event_t *new_event;
1770  cJSON *cj, *cjp;
1771 
1772 
1773  if (!(cj = cJSON_Parse(json))) {
1774  return SWITCH_STATUS_FALSE;
1775  }
1776 
1778  cJSON_Delete(cj);
1779  return SWITCH_STATUS_FALSE;
1780  }
1781 
1782  for (cjp = cj->child; cjp; cjp = cjp->next) {
1783  char *name = cjp->string;
1784  char *value = cjp->valuestring;
1785 
1786  if (name && value) {
1787  if (!strcasecmp(name, "_body")) {
1788  switch_event_add_body(new_event, value, SWITCH_VA_NONE);
1789  } else {
1790  if (!strcasecmp(name, "event-name")) {
1791  switch_event_del_header(new_event, "event-name");
1792  switch_name_event(value, &new_event->event_id);
1793  }
1794 
1795  switch_event_add_header_string(new_event, SWITCH_STACK_BOTTOM, name, value);
1796  }
1797 
1798  } else if (name) {
1799  if (cjp->type == cJSON_Array) {
1800  int i, x = cJSON_GetArraySize(cjp);
1801 
1802  for (i = 0; i < x; i++) {
1803  cJSON *item = cJSON_GetArrayItem(cjp, i);
1804 
1805  if (item && item->type == cJSON_String && item->valuestring) {
1807  }
1808  }
1809  }
1810  }
1811  }
1812 
1813  cJSON_Delete(cj);
1814  *event = new_event;
1815  return SWITCH_STATUS_SUCCESS;
1816 }
switch_event_types_t event_id
Definition: switch_event.h:82
#define switch_event_del_header(_e, _h)
Definition: switch_event.h:212
switch_status_t switch_name_event(const char *name, switch_event_types_t *type)
return the event id that matches a given event name
Definition: switch_event.c:438
Representation of an event.
Definition: switch_event.h:80
const char *const const char *const const cJSON *const value
char * valuestring
Definition: switch_cJSON.h:107
#define cJSON_Array
Definition: switch_cJSON.h:87
#define cJSON_String
Definition: switch_cJSON.h:86
struct cJSON * child
Definition: switch_cJSON.h:101
char * string
Definition: switch_cJSON.h:114
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.
switch_status_t switch_event_add_body(switch_event_t *event, const char *fmt,...)
struct cJSON * next
Definition: switch_cJSON.h:98
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384
cJSON * item
Definition: switch_cJSON.h:210
#define SWITCH_VA_NONE
int type
Definition: switch_cJSON.h:104
const char *const name
Definition: switch_cJSON.h:250

◆ switch_event_create_plain()

static switch_status_t switch_event_create_plain ( switch_event_t **  event,
switch_event_types_t  event_id 
)
inlinestatic

Definition at line 386 of file switch_event.h.

References EF_UNIQ_HEADERS, switch_event_node::event_id, SWITCH_DECLARE, SWITCH_EVENT_CHANNEL_DATA, SWITCH_EVENT_CLONE, switch_event_create, switch_event_deliver(), SWITCH_EVENT_REQUEST_PARAMS, and SWITCH_STATUS_SUCCESS.

Referenced by switch_channel_alloc(), switch_channel_get_scope_variables(), switch_channel_set_log_tag(), switch_core_init(), switch_core_unset_variables(), switch_dial_handle_add_global_var(), switch_dial_handle_add_leg_var(), switch_dial_handle_list_add_global_var(), switch_event_channel_permission_modify(), switch_event_create_brackets(), switch_ivr_enterprise_originate(), switch_ivr_originate(), switch_ivr_uuid_bridge(), and switch_log_node_to_json().

387 {
389  if (status == SWITCH_STATUS_SUCCESS) {
390  (*event)->event_id = event_id;
391 
392  if (event_id == SWITCH_EVENT_REQUEST_PARAMS || event_id == SWITCH_EVENT_CHANNEL_DATA) {
393  (*event)->flags |= EF_UNIQ_HEADERS;
394  }
395  }
396 
397  return status;
398 }
switch_status_t
Common return values.
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384

◆ switch_event_create_pres_in_detailed()

switch_status_t switch_event_create_pres_in_detailed ( _In_z_ char *  file,
_In_z_ char *  func,
_In_ int  line,
_In_z_ const char *  proto,
_In_z_ const char *  login,
_In_z_ const char *  from,
_In_z_ const char *  from_domain,
_In_z_ const char *  status,
_In_z_ const char *  event_type,
_In_z_ const char *  alt_event_type,
_In_ int  event_count,
_In_z_ const char *  unique_id,
_In_z_ const char *  channel_state,
_In_z_ const char *  answer_state,
_In_z_ const char *  call_direction 
)

◆ switch_event_create_subclass_detailed()

switch_status_t switch_event_create_subclass_detailed ( const char *  file,
const char *  func,
int  line,
switch_event_t **  event,
switch_event_types_t  event_id,
const char *  subclass_name 
)

Create an event.

Parameters
eventa NULL pointer on which to create the event
event_idthe event id enumeration of the desired event
subclass_namethe subclass name for custom event (only valid when event_id is SWITCH_EVENT_CUSTOM)
Returns
SWITCH_STATUS_SUCCESS on success

Definition at line 747 of file switch_event.c.

References ALLOC, DUP, EF_UNIQ_HEADERS, switch_event_node::event_id, memset(), switch_assert, switch_event_add_header_string(), SWITCH_EVENT_CHANNEL_DATA, SWITCH_EVENT_CLONE, SWITCH_EVENT_CUSTOM, SWITCH_EVENT_MESSAGE, switch_event_prep_for_delivery_detailed(), SWITCH_EVENT_REQUEST_PARAMS, switch_queue_trypop(), SWITCH_STACK_BOTTOM, SWITCH_STATUS_GENERR, and SWITCH_STATUS_SUCCESS.

749 {
750 #ifdef SWITCH_EVENT_RECYCLE
751  void *pop;
752 #endif
753 
754  *event = NULL;
755 
756  if ((event_id != SWITCH_EVENT_CLONE && event_id != SWITCH_EVENT_CUSTOM) && subclass_name) {
757  return SWITCH_STATUS_GENERR;
758  }
759 #ifdef SWITCH_EVENT_RECYCLE
760  if (EVENT_RECYCLE_QUEUE && switch_queue_trypop(EVENT_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS && pop) {
761  *event = (switch_event_t *) pop;
762  } else {
763 #endif
764  *event = ALLOC(sizeof(switch_event_t));
765  switch_assert(*event);
766 #ifdef SWITCH_EVENT_RECYCLE
767  }
768 #endif
769 
770  memset(*event, 0, sizeof(switch_event_t));
771 
772  if (event_id == SWITCH_EVENT_REQUEST_PARAMS || event_id == SWITCH_EVENT_CHANNEL_DATA || event_id == SWITCH_EVENT_MESSAGE) {
773  (*event)->flags |= EF_UNIQ_HEADERS;
774  }
775 
776  if (event_id != SWITCH_EVENT_CLONE) {
777  (*event)->event_id = event_id;
778  switch_event_prep_for_delivery_detailed(file, func, line, *event);
779  }
780 
781  if (subclass_name) {
782  (*event)->subclass_name = DUP(subclass_name);
783  switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Subclass", subclass_name);
784  }
785 
786  return SWITCH_STATUS_SUCCESS;
787 }
Representation of an event.
Definition: switch_event.h:80
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1264
void switch_event_prep_for_delivery_detailed(const char *file, const char *func, int line, switch_event_t *event)
#define ALLOC(size)
Definition: switch_event.c:123
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.
#define DUP(str)
Definition: switch_event.c:126
#define switch_assert(expr)
memset(buf, 0, buflen)

◆ switch_event_del_header_val()

switch_status_t switch_event_del_header_val ( switch_event_t event,
const char *  header_name,
const char *  val 
)

Definition at line 872 of file switch_event.c.

References free_header(), switch_event_header::hash, hash, switch_event::last_header, switch_event_header::name, switch_event_header::next, switch_assert, switch_ci_hashfunc_default(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_event_header::value, and zstr.

873 {
874  switch_event_header_t *hp, *lp = NULL, *tp;
876  int x = 0;
877  switch_ssize_t hlen = -1;
878  unsigned long hash = 0;
879 
880  tp = event->headers;
881  hash = switch_ci_hashfunc_default(header_name, &hlen);
882  while (tp) {
883  hp = tp;
884  tp = tp->next;
885 
886  x++;
887  switch_assert(x < 1000000);
888 
889  if ((!hp->hash || hash == hp->hash) && !strcasecmp(header_name, hp->name) && (zstr(val) || !strcmp(hp->value, val))) {
890  if (lp) {
891  lp->next = hp->next;
892  } else {
893  event->headers = hp->next;
894  }
895  if (hp == event->last_header || !hp->next) {
896  event->last_header = lp;
897  }
898  free_header(&hp);
899  status = SWITCH_STATUS_SUCCESS;
900  } else {
901  lp = hp;
902  }
903  }
904 
905  return status;
906 }
An event Header.
Definition: switch_event.h:65
unsigned int switch_ci_hashfunc_default(const char *char_key, switch_ssize_t *klen)
Definition: switch_apr.c:121
switch_event_header_t * last_header
Definition: switch_event.h:92
switch_hash_t * hash
Definition: switch_event.c:76
#define zstr(x)
Definition: switch_utils.h:314
intptr_t switch_ssize_t
static void free_header(switch_event_header_t **header)
Definition: switch_event.c:931
switch_status_t
Common return values.
struct switch_event_header * next
Definition: switch_event.h:76
#define switch_assert(expr)
unsigned long hash
Definition: switch_event.h:75

◆ switch_event_deliver()

void switch_event_deliver ( switch_event_t **  event)

Deliver an event to all of the registered event listeners.

Parameters
eventthe event to send (will be nulled)
Note
normaly use switch_event_fire for delivering events (only use this when you wish to deliver the event blocking on your thread)

Definition at line 400 of file switch_event.c.

References switch_event_node::callback, switch_event_node::next, RWLOCK, SWITCH_EVENT_ALL, switch_event_destroy(), switch_events_match(), switch_thread_rwlock_rdlock(), switch_thread_rwlock_unlock(), SYSTEM_RUNNING, and switch_event_node::user_data.

Referenced by switch_event_create_plain(), switch_event_deliver_thread(), and switch_event_dispatch_thread().

401 {
403  switch_event_node_t *node;
404 
405  if (SYSTEM_RUNNING) {
407  for (e = (*event)->event_id;; e = SWITCH_EVENT_ALL) {
408  for (node = EVENT_NODES[e]; node; node = node->next) {
409  if (switch_events_match(*event, node)) {
410  (*event)->bind_user_data = node->user_data;
411  node->callback(*event);
412  }
413  }
414 
415  if (e == SWITCH_EVENT_ALL) {
416  break;
417  }
418  }
420  }
421 
422  switch_event_destroy(event);
423 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:286
static switch_event_node_t * EVENT_NODES[SWITCH_EVENT_ALL+1]
Definition: switch_event.c:87
static switch_thread_rwlock_t * RWLOCK
Definition: switch_event.c:88
static int SYSTEM_RUNNING
Definition: switch_event.c:104
switch_event_types_t
Built-in Events.
A node to store binded events.
Definition: switch_event.c:48
static int switch_events_match(switch_event_t *event, switch_event_node_t *node)
Definition: switch_event.c:233
switch_status_t switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:250
struct switch_event_node * next
Definition: switch_event.c:59
switch_event_callback_t callback
Definition: switch_event.c:56
void switch_event_destroy(switch_event_t **event)
Destroy an event.

◆ switch_event_destroy()

void switch_event_destroy ( switch_event_t **  event)

Destroy an event.

Parameters
eventpointer to the pointer to event to destroy

Definition at line 1289 of file switch_event.c.

References switch_event::body, FREE, free_header(), switch_event::headers, switch_event_header::next, switch_event::subclass_name, switch_queue_trypush(), and SWITCH_STATUS_SUCCESS.

Referenced by asr_set_json_text_params(), audio_bridge_thread(), chat_process_event(), EventConsumer::cleanup(), Event::Event(), event_handler(), Event::fire(), CoreSession::flushEvents(), helper_callback(), speech_thread(), switch_channel_api_on(), switch_channel_clear_device_record(), switch_channel_del_variable_prefix(), switch_channel_execute_on(), switch_channel_set_scope_variables(), switch_channel_uninit(), switch_core_destroy(), switch_core_file_close(), switch_core_hash_delete_multi(), switch_core_media_gen_local_sdp(), switch_core_perform_file_open(), switch_core_session_flush_private_events(), switch_core_session_hupall_matching_var_ans(), switch_core_session_perform_destroy(), switch_core_session_receive_event(), switch_core_session_thread(), switch_core_unset_variables(), switch_dial_handle_destroy(), switch_dial_handle_list_destroy(), switch_event_channel_permission_clear(), switch_event_deliver(), switch_event_fire_detailed(), switch_event_shutdown(), switch_http_free_request(), switch_ivr_check_presence_mapping(), switch_ivr_collect_digits_callback(), switch_ivr_eavesdrop_session(), switch_ivr_enterprise_originate(), switch_ivr_gentones(), switch_ivr_originate(), switch_ivr_park(), switch_ivr_phrase_macro_event(), switch_ivr_play_file(), switch_ivr_record_file_event(), switch_ivr_say(), switch_ivr_say_string(), switch_ivr_session_echo(), switch_ivr_sleep(), switch_ivr_speak_text_handle(), switch_ivr_transfer_variable(), switch_ivr_uuid_bridge(), switch_load_network_lists(), switch_log_node_free(), switch_log_node_to_json(), switch_msrp_msg_destroy(), switch_say_file_handle_destroy(), switch_scheduler_task_thread(), switch_xml_config_parse(), switch_xml_locate_domain(), switch_xml_locate_group(), switch_xml_locate_user(), switch_xml_open_root(), and unsub_all_switch_event_channel().

1290 {
1291  switch_event_t *ep = *event;
1292  switch_event_header_t *hp, *this;
1293 
1294  if (ep) {
1295  for (hp = ep->headers; hp;) {
1296  this = hp;
1297  hp = hp->next;
1298  free_header(&this);
1299  }
1300  FREE(ep->body);
1301  FREE(ep->subclass_name);
1302 #ifdef SWITCH_EVENT_RECYCLE
1303  if (switch_queue_trypush(EVENT_RECYCLE_QUEUE, ep) != SWITCH_STATUS_SUCCESS) {
1304  FREE(ep);
1305  }
1306 #else
1307  FREE(ep);
1308 #endif
1309 
1310  }
1311  *event = NULL;
1312 }
Representation of an event.
Definition: switch_event.h:80
An event Header.
Definition: switch_event.h:65
#define FREE(ptr)
Definition: switch_event.c:129
static void free_header(switch_event_header_t **header)
Definition: switch_event.c:931
struct switch_event_header * next
Definition: switch_event.h:76
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1279
char * subclass_name
Definition: switch_event.h:88
switch_event_header_t * headers
Definition: switch_event.h:90

◆ switch_event_dup()

switch_status_t switch_event_dup ( switch_event_t **  event,
switch_event_t todup 
)

Duplicate an event.

Parameters
eventa NULL pointer on which to duplicate the event
todupan event to duplicate
Returns
SWITCH_STATUS_SUCCESS if the event was duplicated

Definition at line 1334 of file switch_event.c.

References switch_event_header::array, switch_event::bind_user_data, switch_event::body, DUP, switch_event::event_id, switch_event::event_user_data, switch_event::flags, switch_event::headers, switch_event_header::idx, switch_event::key, switch_event_header::name, switch_event_header::next, switch_event::subclass_name, switch_event_add_header_string(), SWITCH_EVENT_CLONE, switch_event_create_subclass, SWITCH_STACK_BOTTOM, SWITCH_STACK_PUSH, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, and switch_event_header::value.

Referenced by do_chat_send(), event_handler(), Event::fire(), CoreSession::sendEvent(), speech_thread(), switch_channel_get_log_tags(), switch_channel_get_variables(), switch_core_chat_send(), switch_core_get_variables(), switch_core_session_read_text_frame(), switch_dial_handle_dup(), switch_ivr_enterprise_originate(), switch_ivr_originate(), switch_ivr_record_session_event(), switch_log_node_dup(), switch_log_node_to_json(), switch_msrp_msg_dup(), text_callback(), and tone_detect_callback().

1335 {
1337 
1339  return SWITCH_STATUS_GENERR;
1340  }
1341 
1342  (*event)->event_id = todup->event_id;
1343  (*event)->event_user_data = todup->event_user_data;
1344  (*event)->bind_user_data = todup->bind_user_data;
1345  (*event)->flags = todup->flags;
1346  for (hp = todup->headers; hp; hp = hp->next) {
1347  if (todup->subclass_name && !strcmp(hp->name, "Event-Subclass")) {
1348  continue;
1349  }
1350 
1351  if (hp->idx) {
1352  int i;
1353  for (i = 0; i < hp->idx; i++) {
1355  }
1356  } else {
1358  }
1359  }
1360 
1361  if (todup->body) {
1362  (*event)->body = DUP(todup->body);
1363  }
1364 
1365  (*event)->key = todup->key;
1366 
1367  return SWITCH_STATUS_SUCCESS;
1368 }
switch_event_types_t event_id
Definition: switch_event.h:82
unsigned long key
Definition: switch_event.h:100
An event Header.
Definition: switch_event.h:65
#define switch_event_create_subclass(_e, _eid, _sn)
Definition: switch_event.h:153
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.
struct switch_event_header * next
Definition: switch_event.h:76
void * event_user_data
Definition: switch_event.h:98
#define DUP(str)
Definition: switch_event.c:126
char * subclass_name
Definition: switch_event.h:88
void * bind_user_data
Definition: switch_event.h:96
switch_event_header_t * headers
Definition: switch_event.h:90

◆ switch_event_dup_reply()

switch_status_t switch_event_dup_reply ( switch_event_t **  event,
switch_event_t todup 
)

Definition at line 1371 of file switch_event.c.

References switch_event_header::array, switch_event::bind_user_data, switch_event::body, switch_event::event_id, switch_event::event_user_data, switch_event::flags, switch_event::headers, switch_event_header::idx, switch_event::key, switch_event_header::name, name, switch_event_header::next, switch_event::subclass_name, switch_event_add_header_string(), SWITCH_EVENT_CLONE, switch_event_create_subclass, switch_snprintf(), SWITCH_STACK_BOTTOM, SWITCH_STACK_PUSH, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, value, and switch_event_header::value.

Referenced by switch_ivr_create_message_reply().

1372 {
1374  char hname[1024] = "";
1375  char *p;
1376 
1378  return SWITCH_STATUS_GENERR;
1379  }
1380 
1381  (*event)->event_id = todup->event_id;
1382  (*event)->event_user_data = todup->event_user_data;
1383  (*event)->bind_user_data = todup->bind_user_data;
1384  (*event)->flags = todup->flags;
1385 
1386  for (hp = todup->headers; hp; hp = hp->next) {
1387  char *name = hp->name, *value = hp->value;
1388 
1389  if (todup->subclass_name && !strcmp(hp->name, "Event-Subclass")) {
1390  continue;
1391  }
1392 
1393  if (!strncasecmp(hp->name, "from_", 5)) {
1394  p = hp->name + 5;
1395  switch_snprintf(hname, sizeof(hname), "to_%s", p);
1396  name = hname;
1397  } else if (!strncasecmp(hp->name, "to_", 3)) {
1398  p = hp->name + 3;
1399  switch_snprintf(hname, sizeof(hname), "from_%s", p);
1400  name = hname;
1401  } else if (!strcasecmp(name, "to")) {
1402  name = "from";
1403  } else if (!strcasecmp(name, "from")) {
1404  name = "to";
1405  }
1406 
1407  if (hp->idx) {
1408  int i;
1409  for (i = 0; i < hp->idx; i++) {
1411  }
1412  } else {
1414  }
1415  }
1416 
1417  switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "replying", "true");
1418 
1419  if (todup->body) {
1420  switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "orig_body", todup->body);
1421  }
1422 
1423  (*event)->key = todup->key;
1424 
1425  return SWITCH_STATUS_SUCCESS;
1426 }
switch_event_types_t event_id
Definition: switch_event.h:82
unsigned long key
Definition: switch_event.h:100
An event Header.
Definition: switch_event.h:65
const char *const const char *const const cJSON *const value
#define switch_event_create_subclass(_e, _eid, _sn)
Definition: switch_event.h:153
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
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.
struct switch_event_header * next
Definition: switch_event.h:76
void * event_user_data
Definition: switch_event.h:98
const char *const name
Definition: switch_cJSON.h:250
char * subclass_name
Definition: switch_event.h:88
void * bind_user_data
Definition: switch_event.h:96
switch_event_header_t * headers
Definition: switch_event.h:90

◆ switch_event_expand_headers_check()

char* switch_event_expand_headers_check ( switch_event_t event,
const char *  in,
switch_event_t var_list,
switch_event_t api_list,
uint32_t  recur 
)

Definition at line 2251 of file switch_event.c.

References switch_stream_handle::data, end_of_p, in, memset(), resize, SCF_API_EXPANSION, switch_api_execute(), switch_assert, switch_core_get_variable_dup(), switch_core_test_flag(), switch_event_check_permission_list(), switch_event_get_header_idx(), switch_safe_free, SWITCH_STANDARD_STREAM, SWITCH_STATUS_SUCCESS, switch_string_has_escaped_data(), switch_string_var_check_const(), and zstr.

2252 {
2253  char *p, *c = NULL;
2254  char *data, *indup, *endof_indup;
2255  size_t sp = 0, len = 0, olen = 0, vtype = 0, br = 0, cpos, block = 128;
2256  const char *sub_val = NULL;
2257  char *cloned_sub_val = NULL, *expanded_sub_val = NULL;
2258  char *func_val = NULL;
2259  int nv = 0;
2260  char *gvar = NULL, *sb = NULL;
2261 
2262  if (recur > 100) {
2263  return (char *) in;
2264  }
2265 
2266  if (zstr(in)) {
2267  return (char *) in;
2268  }
2269 
2271 
2272  if (!nv) {
2273  return (char *) in;
2274  }
2275 
2276  nv = 0;
2277  olen = strlen(in) + 1;
2278  indup = strdup(in);
2279  switch_assert(indup);
2280  endof_indup = end_of_p(indup) + 1;
2281 
2282  if ((data = malloc(olen))) {
2283  memset(data, 0, olen);
2284  c = data;
2285  for (p = indup; p && p < endof_indup && *p; p++) {
2286  int global = 0;
2287  vtype = 0;
2288 
2289  if (*p == '\\') {
2290  if (*(p + 1) == '$') {
2291  nv = 1;
2292  p++;
2293  if (*(p + 1) == '$') {
2294  p++;
2295  }
2296  } else if (*(p + 1) == '\'') {
2297  p++;
2298  continue;
2299  } else if (*(p + 1) == '\\') {
2300  if (len + 1 >= olen) {
2301  resize(1);
2302  }
2303 
2304  *c++ = *p++;
2305  len++;
2306  continue;
2307  }
2308  }
2309 
2310  if (*p == '$' && !nv) {
2311  if (*(p + 1) == '$') {
2312  p++;
2313  global++;
2314  }
2315 
2316  if (*(p + 1)) {
2317  if (*(p + 1) == '{') {
2318  vtype = global ? 3 : 1;
2319  } else {
2320  nv = 1;
2321  }
2322  } else {
2323  nv = 1;
2324  }
2325  }
2326 
2327  if (nv) {
2328  if (len + 1 >= olen) {
2329  resize(1);
2330  }
2331 
2332  *c++ = *p;
2333  len++;
2334  nv = 0;
2335  continue;
2336  }
2337 
2338  if (vtype) {
2339  char *s = p, *e, *vname, *vval = NULL;
2340  size_t nlen;
2341 
2342  s++;
2343 
2344  if ((vtype == 1 || vtype == 3) && *s == '{') {
2345  br = 1;
2346  s++;
2347  }
2348 
2349  e = s;
2350  vname = s;
2351  while (*e) {
2352  if (br == 1 && *e == '}') {
2353  br = 0;
2354  *e++ = '\0';
2355  break;
2356  }
2357 
2358  if (br > 0) {
2359  if (e != s && *e == '{') {
2360  br++;
2361  } else if (br > 1 && *e == '}') {
2362  br--;
2363  }
2364  }
2365 
2366  e++;
2367  }
2368  p = e > endof_indup ? endof_indup : e;
2369 
2370  vval = NULL;
2371  for(sb = vname; sb && *sb; sb++) {
2372  if (*sb == ' ') {
2373  vval = sb;
2374  break;
2375  } else if (*sb == '(') {
2376  vval = sb;
2377  br = 1;
2378  break;
2379  }
2380  }
2381 
2382  if (vval) {
2383  e = vval - 1;
2384  *vval++ = '\0';
2385 
2386  while (*e == ' ') {
2387  *e-- = '\0';
2388  }
2389  e = vval;
2390 
2391  while (e && *e) {
2392  if (*e == '(') {
2393  br++;
2394  } else if (br > 1 && *e == ')') {
2395  br--;
2396  } else if (br == 1 && *e == ')') {
2397  *e = '\0';
2398  break;
2399  }
2400  e++;
2401  }
2402 
2403  vtype = 2;
2404  }
2405 
2406  if (vtype == 1 || vtype == 3) {
2407  char *expanded = NULL;
2408  int offset = 0;
2409  int ooffset = 0;
2410  char *ptr;
2411  int idx = -1;
2412 
2413  if ((expanded = switch_event_expand_headers_check(event, (char *) vname, var_list, api_list, recur+1)) == vname) {
2414  expanded = NULL;
2415  } else {
2416  vname = expanded;
2417  }
2418  if ((ptr = strchr(vname, ':'))) {
2419  *ptr++ = '\0';
2420  offset = atoi(ptr);
2421  if ((ptr = strchr(ptr, ':'))) {
2422  ptr++;
2423  ooffset = atoi(ptr);
2424  }
2425  }
2426 
2427  if ((ptr = strchr(vname, '[')) && strchr(ptr, ']')) {
2428  *ptr++ = '\0';
2429  idx = atoi(ptr);
2430  }
2431 
2432  if (vtype == 3 || !(sub_val = switch_event_get_header_idx(event, vname, idx))) {
2433  switch_safe_free(gvar);
2434  if ((gvar = switch_core_get_variable_dup(vname))) {
2435  sub_val = gvar;
2436  }
2437 
2438  if (var_list && !switch_event_check_permission_list(var_list, vname)) {
2439  sub_val = "<Variable Expansion Permission Denied>";
2440  }
2441 
2442 
2443  if ((expanded_sub_val = switch_event_expand_headers_check(event, sub_val, var_list, api_list, recur+1)) == sub_val) {
2444  expanded_sub_val = NULL;
2445  } else {
2446  sub_val = expanded_sub_val;
2447  }
2448  }
2449 
2450  if (sub_val) {
2451  if (offset || ooffset) {
2452  cloned_sub_val = strdup(sub_val);
2453  switch_assert(cloned_sub_val);
2454  sub_val = cloned_sub_val;
2455  }
2456 
2457  if (offset >= 0) {
2458  sub_val += offset;
2459  } else if ((size_t) abs(offset) <= strlen(sub_val)) {
2460  sub_val = cloned_sub_val + (strlen(cloned_sub_val) + offset);
2461  }
2462 
2463  if (ooffset > 0 && (size_t) ooffset < strlen(sub_val)) {
2464  if ((ptr = (char *) sub_val + ooffset)) {
2465  *ptr = '\0';
2466  }
2467  }
2468  }
2469 
2470  switch_safe_free(expanded);
2471  } else {
2472  switch_stream_handle_t stream = { 0 };
2473  char *expanded = NULL;
2474  char *expanded_vname = NULL;
2475 
2476  if ((expanded_vname = switch_event_expand_headers_check(event, (char *) vname, var_list, api_list, recur+1)) == vname) {
2477  expanded_vname = NULL;
2478  } else {
2479  vname = expanded_vname;
2480  }
2481 
2482  if ((expanded = switch_event_expand_headers_check(event, vval, var_list, api_list, recur+1)) == vval) {
2483  expanded = NULL;
2484  } else {
2485  vval = expanded;
2486  }
2487 
2488  if (!switch_core_test_flag(SCF_API_EXPANSION) || (api_list && !switch_event_check_permission_list(api_list, vname))) {
2489  func_val = NULL;
2490  sub_val = "<API execute Permission Denied>";
2491  } else {
2492  SWITCH_STANDARD_STREAM(stream);
2493  if (switch_api_execute(vname, vval, NULL, &stream) == SWITCH_STATUS_SUCCESS) {
2494  func_val = stream.data;
2495  sub_val = func_val;
2496  } else {
2497  free(stream.data);
2498  }
2499  }
2500 
2501  switch_safe_free(expanded);
2502  switch_safe_free(expanded_vname);
2503  }
2504  if ((nlen = sub_val ? strlen(sub_val) : 0)) {
2505  if (len + nlen >= olen) {
2506  resize(nlen);
2507  }
2508 
2509  len += nlen;
2510  strcat(c, sub_val);
2511  c += nlen;
2512  }
2513 
2514  switch_safe_free(func_val);
2515  switch_safe_free(cloned_sub_val);
2516  switch_safe_free(expanded_sub_val);
2517  sub_val = NULL;
2518  vname = NULL;
2519  br = 0;
2520  }
2521 
2522  if (sp) {
2523  if (len + 1 >= olen) {
2524  resize(1);
2525  }
2526 
2527  *c++ = ' ';
2528  sp = 0;
2529  len++;
2530  }
2531 
2532  if (*p == '$') {
2533  p--;
2534  } else {
2535  if (len + 1 >= olen) {
2536  resize(1);
2537  }
2538 
2539  *c++ = *p;
2540  len++;
2541  }
2542  }
2543  }
2544  free(indup);
2545  switch_safe_free(gvar);
2546 
2547  return data;
2548 }
char * switch_event_get_header_idx(switch_event_t *event, const char *header_name, int idx)
Definition: switch_event.c:846
int switch_core_test_flag(int flag)
Definition: switch_core.c:1792
static int switch_string_has_escaped_data(const char *in)
Definition: switch_utils.h:384
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.
int switch_event_check_permission_list(switch_event_t *list, const char *name)
#define end_of_p(_s)
Definition: switch_utils.h:686
#define zstr(x)
Definition: switch_utils.h:314
switch_byte_t in
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
static switch_bool_t switch_string_var_check_const(const char *s)
Definition: switch_utils.h:788
#define SWITCH_STANDARD_STREAM(s)
char * switch_event_expand_headers_check(switch_event_t *event, const char *in, switch_event_t *var_list, switch_event_t *api_list, uint32_t recur)
#define switch_assert(expr)
#define resize(l)
memset(buf, 0, buflen)
char * switch_core_get_variable_dup(_In_z_ const char *varname)

◆ switch_event_fire_detailed()

switch_status_t switch_event_fire_detailed ( const char *  file,
const char *  func,
int  line,
switch_event_t **  event,
void *  user_data 
)

Fire an event with full arguement list.

Parameters
filethe calling file
functhe calling function
linethe calling line number
eventthe event to send (will be nulled on success)
user_dataoptional private data to pass to the event handlers
Returns

Definition at line 2006 of file switch_event.c.

References BLOCK, check_dispatch(), EVENT_QUEUE_MUTEX, switch_runtime::events_use_dispatch, runtime, RUNTIME_POOL, switch_assert, switch_event_deliver_thread_pool(), switch_event_destroy(), switch_event_queue_dispatch_event(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, SYSTEM_RUNNING, and switch_event_node::user_data.

Referenced by switch_event_create_pres_in_detailed().

2007 {
2008 
2009  switch_assert(BLOCK != NULL);
2010  switch_assert(RUNTIME_POOL != NULL);
2012  switch_assert(RUNTIME_POOL != NULL);
2013 
2014  if (SYSTEM_RUNNING <= 0) {
2015  /* sorry we're closed */
2016  switch_event_destroy(event);
2017  return SWITCH_STATUS_SUCCESS;
2018  }
2019 
2020  if (user_data) {
2021  (*event)->event_user_data = user_data;
2022  }
2023 
2024 
2025 
2027  check_dispatch();
2028 
2030  switch_event_destroy(event);
2031  return SWITCH_STATUS_FALSE;
2032  }
2033  } else {
2035  }
2036 
2037  return SWITCH_STATUS_SUCCESS;
2038 }
static int SYSTEM_RUNNING
Definition: switch_event.c:104
struct switch_runtime runtime
Definition: switch_core.c:86
static void switch_event_deliver_thread_pool(switch_event_t **event)
Definition: switch_event.c:281
static switch_memory_pool_t * RUNTIME_POOL
Definition: switch_event.c:91
static switch_mutex_t * EVENT_QUEUE_MUTEX
Definition: switch_event.c:97
static switch_mutex_t * BLOCK
Definition: switch_event.c:89
static void check_dispatch(void)
Definition: switch_event.c:634
static switch_status_t switch_event_queue_dispatch_event(switch_event_t **eventp)
Definition: switch_event.c:358
void switch_event_destroy(switch_event_t **event)
Destroy an event.
#define switch_assert(expr)

◆ switch_event_free_subclass_detailed()

switch_status_t switch_event_free_subclass_detailed ( const char *  owner,
const char *  subclass_name 
)

Definition at line 454 of file switch_event.c.

References switch_event_subclass::bind, CUSTOM_HASH_MUTEX, FREE, switch_event_subclass::name, switch_event_subclass::owner, RUNTIME_POOL, RWLOCK, switch_assert, SWITCH_CHANNEL_LOG, switch_core_hash_delete(), switch_core_hash_find(), SWITCH_LOG_NOTICE, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_thread_rwlock_unlock(), and switch_thread_rwlock_wrlock().

455 {
456  switch_event_subclass_t *subclass;
458 
460 
461  switch_assert(RUNTIME_POOL != NULL);
462  switch_assert(CUSTOM_HASH != NULL);
463 
464  if ((subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name))) {
465  if (!strcmp(owner, subclass->owner)) {
467  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Subclass reservation deleted for %s:%s\n", owner, subclass_name);
468  switch_core_hash_delete(CUSTOM_HASH, subclass_name);
469  FREE(subclass->owner);
470  FREE(subclass->name);
471  FREE(subclass);
472  status = SWITCH_STATUS_SUCCESS;
474  } else {
475  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Subclass reservation %s inuse by listeners, detaching..\n", subclass_name);
476  subclass->bind = 1;
477  }
478  }
479 
481 
482  return status;
483 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:286
#define SWITCH_CHANNEL_LOG
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
static switch_thread_rwlock_t * RWLOCK
Definition: switch_event.c:88
static switch_mutex_t * CUSTOM_HASH_MUTEX
Definition: switch_event.c:98
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
#define FREE(ptr)
Definition: switch_event.c:129
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:260
static switch_hash_t * CUSTOM_HASH
Definition: switch_event.c:99
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static switch_memory_pool_t * RUNTIME_POOL
Definition: switch_event.c:91
void * switch_core_hash_delete(_In_ switch_hash_t *hash, _In_z_ const char *key)
Delete data from a hash based on desired key.
switch_status_t
Common return values.
A registered custom event subclass.
Definition: switch_event.c:63
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.
#define switch_assert(expr)

◆ switch_event_get_body()

char* switch_event_get_body ( switch_event_t event)

Retrieve the body value from an event.

Parameters
eventthe event to read the body from
Returns
the value of the body or NULL

Definition at line 867 of file switch_event.c.

References switch_event::body.

Referenced by Event::getBody(), play_and_detect_input_callback(), switch_collect_input_callback(), and switch_ivr_parse_event().

868 {
869  return (event ? event->body : NULL);
870 }

◆ switch_event_get_custom_events()

switch_status_t switch_event_get_custom_events ( switch_console_callback_match_t **  matches)

Definition at line 2040 of file switch_event.c.

References CUSTOM_HASH_MUTEX, switch_console_push_match(), switch_core_hash_first, switch_core_hash_next(), switch_core_hash_this(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

2041 {
2042  switch_hash_index_t *hi = NULL;
2043  const void *var;
2044  void *val;
2045  int x = 0;
2046 
2048 
2049  for (hi = switch_core_hash_first(CUSTOM_HASH); hi; hi = switch_core_hash_next(&hi)) {
2050  switch_core_hash_this(hi, &var, NULL, &val);
2051  switch_console_push_match(matches, (const char *) var);
2052  x++;
2053  }
2054 
2056 
2058 }
static switch_mutex_t * CUSTOM_HASH_MUTEX
Definition: switch_event.c:98
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
static switch_hash_t * CUSTOM_HASH
Definition: switch_event.c:99
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
void switch_console_push_match(switch_console_callback_match_t **matches, const char *new_val)
void switch_core_hash_this(_In_ switch_hash_index_t *hi, _Out_opt_ptrdiff_cap_(klen) const void **key, _Out_opt_ switch_ssize_t *klen, _Out_ void **val)
Gets the key and value of the current hash element.
switch_hash_index_t * switch_core_hash_next(_In_ switch_hash_index_t **hi)
Gets the next element of a hashtable.
#define switch_core_hash_first(_h)
Definition: switch_core.h:1592

◆ switch_event_get_header_idx()

_Ret_opt_z_ char* switch_event_get_header_idx ( switch_event_t event,
const char *  header_name,
int  idx 
)

Definition at line 846 of file switch_event.c.

References switch_event_header::array, switch_event_get_header_ptr(), and switch_event_header::value.

Referenced by switch_channel_get_variable_dup(), and switch_event_expand_headers_check().

847 {
849 
850  if ((hp = switch_event_get_header_ptr(event, header_name))) {
851  if (idx > -1) {
852  if (idx < hp->idx) {
853  return hp->array[idx];
854  } else {
855  return NULL;
856  }
857  }
858 
859  return hp->value;
860  } else if (!strcmp(header_name, "_body")) {
861  return event->body;
862  }
863 
864  return NULL;
865 }
An event Header.
Definition: switch_event.h:65
switch_event_header_t * switch_event_get_header_ptr(switch_event_t *event, const char *header_name)
Retrieve a header value from an event.
Definition: switch_event.c:825

◆ switch_event_get_header_ptr()

switch_event_header_t* switch_event_get_header_ptr ( switch_event_t event,
const char *  header_name 
)

Retrieve a header value from an event.

Parameters
eventthe event to read the header from
header_namethe name of the header to read
Returns
the value of the requested header

Definition at line 825 of file switch_event.c.

References switch_event_header::hash, hash, switch_event::headers, switch_event_header::name, switch_event_header::next, switch_assert, and switch_ci_hashfunc_default().

Referenced by switch_event_base_add_header(), and switch_event_get_header_idx().

826 {
828  switch_ssize_t hlen = -1;
829  unsigned long hash = 0;
830 
831  switch_assert(event);
832 
833  if (!header_name)
834  return NULL;
835 
836  hash = switch_ci_hashfunc_default(header_name, &hlen);
837 
838  for (hp = event->headers; hp; hp = hp->next) {
839  if ((!hp->hash || hash == hp->hash) && !strcasecmp(hp->name, header_name)) {
840  return hp;
841  }
842  }
843  return NULL;
844 }
An event Header.
Definition: switch_event.h:65
unsigned int switch_ci_hashfunc_default(const char *char_key, switch_ssize_t *klen)
Definition: switch_apr.c:121
switch_hash_t * hash
Definition: switch_event.c:76
intptr_t switch_ssize_t
struct switch_event_header * next
Definition: switch_event.h:76
#define switch_assert(expr)
unsigned long hash
Definition: switch_event.h:75
switch_event_header_t * headers
Definition: switch_event.h:90

◆ switch_event_init()

switch_status_t switch_event_init ( switch_memory_pool_t pool)

Start the eventing system.

Parameters
poolthe memory pool to use for the event system (creates a new one if NULL)
Returns
SWITCH_STATUS_SUCCESS when complete

Definition at line 692 of file switch_event.c.

References BLOCK, check_dispatch(), CUSTOM_HASH_MUTEX, event_channel_manager, EVENT_QUEUE_MUTEX, guess_ip_v4, guess_ip_v6, MAX_DISPATCH, pool, POOL_LOCK, RUNTIME_POOL, RWLOCK, SCF_MINIMAL, switch_assert, SWITCH_CHANNEL_LOG, switch_core_cpu_count(), switch_core_hash_init, switch_core_test_flag(), switch_find_local_ip(), SWITCH_LOG_INFO, switch_log_printf(), switch_mutex_init(), switch_mutex_lock(), SWITCH_MUTEX_NESTED, switch_mutex_unlock(), switch_queue_create(), SWITCH_STATUS_SUCCESS, switch_thread_rwlock_create(), SYSTEM_RUNNING, and THRUNTIME_POOL.

Referenced by switch_core_init().

693 {
694 
695  /* don't need any more dispatch threads than we have CPU's*/
696  MAX_DISPATCH = (switch_core_cpu_count() / 2) + 1;
697  if (MAX_DISPATCH < 2) {
698  MAX_DISPATCH = 2;
699  }
700 
701  switch_assert(pool != NULL);
709 
711  return SWITCH_STATUS_SUCCESS;
712  }
713 
714  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Activate Eventing Engine.\n");
715 
718 
722  event_channel_manager.ID = 1;
723 
725  SYSTEM_RUNNING = -1;
727 
728  //switch_threadattr_create(&thd_attr, pool);
729  switch_find_local_ip(guess_ip_v4, sizeof(guess_ip_v4), NULL, AF_INET);
730  switch_find_local_ip(guess_ip_v6, sizeof(guess_ip_v6), NULL, AF_INET6);
731 
732 
733 #ifdef SWITCH_EVENT_RECYCLE
734  switch_queue_create(&EVENT_RECYCLE_QUEUE, 250000, THRUNTIME_POOL);
735  switch_queue_create(&EVENT_HEADER_RECYCLE_QUEUE, 250000, THRUNTIME_POOL);
736 #endif
737 
738  check_dispatch();
739 
741  SYSTEM_RUNNING = 1;
743 
744  return SWITCH_STATUS_SUCCESS;
745 }
#define SWITCH_CHANNEL_LOG
static char guess_ip_v6[80]
Definition: switch_event.c:86
static unsigned int MAX_DISPATCH
Definition: switch_event.c:83
static switch_thread_rwlock_t * RWLOCK
Definition: switch_event.c:88
int switch_core_test_flag(int flag)
Definition: switch_core.c:1792
#define switch_core_hash_init(_hash)
Definition: switch_core.h:1431
static int SYSTEM_RUNNING
Definition: switch_event.c:104
static switch_mutex_t * CUSTOM_HASH_MUTEX
Definition: switch_event.c:98
static struct @5 event_channel_manager
switch_memory_pool_t * pool
uint32_t switch_core_cpu_count(void)
Definition: switch_core.c:1055
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
static switch_mutex_t * POOL_LOCK
Definition: switch_event.c:90
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
static switch_hash_t * CUSTOM_HASH
Definition: switch_event.c:99
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static switch_memory_pool_t * RUNTIME_POOL
Definition: switch_event.c:91
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
static switch_mutex_t * EVENT_QUEUE_MUTEX
Definition: switch_event.c:97
static switch_mutex_t * BLOCK
Definition: switch_event.c:89
static switch_memory_pool_t * THRUNTIME_POOL
Definition: switch_event.c:92
static void check_dispatch(void)
Definition: switch_event.c:634
switch_status_t switch_thread_rwlock_create(switch_thread_rwlock_t **rwlock, switch_memory_pool_t *pool)
Definition: switch_apr.c:235
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.
static char guess_ip_v4[80]
Definition: switch_event.c:85
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
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
Definition: switch_apr.c:1233
#define switch_assert(expr)

◆ switch_event_launch_dispatch_threads()

void switch_event_launch_dispatch_threads ( uint32_t  max)

Definition at line 653 of file switch_event.c.

References check_dispatch(), EVENT_DISPATCH_QUEUE_RUNNING, EVENT_DISPATCH_QUEUE_THREADS, index, MAX_DISPATCH, pool, RUNTIME_POOL, SOFT_MAX_DISPATCH, SWITCH_CHANNEL_LOG, switch_event_dispatch_thread(), switch_log_printf(), SWITCH_LOG_WARNING, SWITCH_PRI_REALTIME, switch_thread_create(), SWITCH_THREAD_STACKSIZE, switch_threadattr_create(), switch_threadattr_priority_set(), switch_threadattr_stacksize_set(), and switch_yield.

Referenced by check_dispatch(), switch_event_queue_dispatch_event(), and switch_load_core_config().

654 {
655  switch_threadattr_t *thd_attr;
656  uint32_t index = 0;
657  uint32_t sanity = 200;
658 
660 
661  check_dispatch();
662 
663  if (max > MAX_DISPATCH) {
664  return;
665  }
666 
667  if (max < SOFT_MAX_DISPATCH) {
668  return;
669  }
670 
671  for (index = SOFT_MAX_DISPATCH; index < max && index < MAX_DISPATCH; index++) {
672  if (EVENT_DISPATCH_QUEUE_THREADS[index]) {
673  continue;
674  }
675 
676  switch_threadattr_create(&thd_attr, pool);
680  while(--sanity && !EVENT_DISPATCH_QUEUE_RUNNING[index]) switch_yield(10000);
681 
682  if (index == 1) {
683  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Create event dispatch thread %d\n", index);
684  } else {
685  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Create additional event dispatch thread %d\n", index);
686  }
687  }
688 
690 }
#define SWITCH_CHANNEL_LOG
static uint8_t EVENT_DISPATCH_QUEUE_RUNNING[MAX_DISPATCH_VAL]
Definition: switch_event.c:94
static unsigned int MAX_DISPATCH
Definition: switch_event.c:83
static unsigned int SOFT_MAX_DISPATCH
Definition: switch_event.c:84
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:683
switch_memory_pool_t * pool
static switch_thread_t * EVENT_DISPATCH_QUEUE_THREADS[MAX_DISPATCH_VAL]
Definition: switch_event.c:93
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
static void *SWITCH_THREAD_FUNC switch_event_dispatch_thread(switch_thread_t *thread, void *obj)
Definition: switch_event.c:299
static switch_queue_t * EVENT_DISPATCH_QUEUE
Definition: switch_event.c:95
static switch_memory_pool_t * RUNTIME_POOL
Definition: switch_event.c:91
int index
Definition: switch_cJSON.h:160
#define SWITCH_THREAD_STACKSIZE
Definition: switch_types.h:584
static void check_dispatch(void)
Definition: switch_event.c:634
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_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
Definition: switch_apr.c:665
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
Definition: switch_apr.c:698
struct fspr_pool_t switch_memory_pool_t
switch_status_t switch_threadattr_priority_set(switch_threadattr_t *attr, switch_thread_priority_t priority)
Definition: switch_apr.c:688

◆ switch_event_merge()

void switch_event_merge ( switch_event_t event,
switch_event_t tomerge 
)

Definition at line 1315 of file switch_event.c.

References switch_event_header::array, switch_event::headers, switch_event_header::idx, switch_event_header::name, switch_event_header::next, switch_assert, switch_event_add_header_string(), SWITCH_STACK_BOTTOM, SWITCH_STACK_PUSH, and switch_event_header::value.

Referenced by asr_set_json_text_params(), Event::merge(), speech_thread(), switch_channel_execute_on(), switch_ivr_enterprise_originate(), switch_ivr_originate(), and switch_ivr_play_file().

1316 {
1318 
1319  switch_assert(tomerge && event);
1320 
1321  for (hp = tomerge->headers; hp; hp = hp->next) {
1322  if (hp->idx) {
1323  int i;
1324 
1325  for(i = 0; i < hp->idx; i++) {
1327  }
1328  } else {
1330  }
1331  }
1332 }
An event Header.
Definition: switch_event.h:65
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.
struct switch_event_header * next
Definition: switch_event.h:76
#define switch_assert(expr)
switch_event_header_t * headers
Definition: switch_event.h:90

◆ switch_event_name()

const char* switch_event_name ( switch_event_types_t  event)

Render the name of an event id enumeration.

Parameters
eventthe event id to render the name of
Returns
the rendered name

Definition at line 430 of file switch_event.c.

References BLOCK, EVENT_NAMES, RUNTIME_POOL, and switch_assert.

Referenced by Event::getType(), switch_event_prep_for_delivery_detailed(), switch_event_unbind(), and switch_event_unbind_callback().

431 {
432  switch_assert(BLOCK != NULL);
433  switch_assert(RUNTIME_POOL != NULL);
434 
435  return EVENT_NAMES[event];
436 }
static switch_memory_pool_t * RUNTIME_POOL
Definition: switch_event.c:91
static switch_mutex_t * BLOCK
Definition: switch_event.c:89
#define switch_assert(expr)
static char * EVENT_NAMES[]
Definition: switch_event.c:137

◆ switch_event_prep_for_delivery_detailed()

void switch_event_prep_for_delivery_detailed ( const char *  file,
const char *  func,
int  line,
switch_event_t event 
)

Definition at line 1972 of file switch_event.c.

References switch_event::event_id, EVENT_QUEUE_MUTEX, EVENT_SEQUENCE_NR, guess_ip_v4, guess_ip_v6, switch_core_get_hostname(), switch_core_get_switchname(), switch_core_get_uuid(), switch_cut_path(), switch_event_add_header(), switch_event_add_header_string(), switch_event_name(), switch_micro_time_now(), switch_mutex_lock(), switch_mutex_unlock(), switch_rfc822_date(), SWITCH_STACK_BOTTOM, switch_strftime_nocheck(), switch_time_exp_lt(), and SWITCH_UINT64_T_FMT.

Referenced by switch_event_create_subclass_detailed().

1973 {
1974  switch_time_exp_t tm;
1975  char date[80] = "";
1976  switch_size_t retsize;
1978  uint64_t seq;
1979 
1981  seq = ++EVENT_SEQUENCE_NR;
1983 
1984 
1991 
1992  switch_time_exp_lt(&tm, ts);
1993  switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
1994  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Event-Date-Local", date);
1995  switch_rfc822_date(date, ts);
1996  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Event-Date-GMT", date);
1997  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Event-Date-Timestamp", "%" SWITCH_UINT64_T_FMT, (uint64_t) ts);
1998  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Event-Calling-File", switch_cut_path(file));
1999  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Event-Calling-Function", func);
2000  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Event-Calling-Line-Number", "%d", line);
2001  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Event-Sequence", "%" SWITCH_UINT64_T_FMT, seq);
2002 
2003 
2004 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:311
const char * switch_core_get_switchname(void)
Definition: switch_core.c:361
switch_event_types_t event_id
Definition: switch_event.h:82
static char guess_ip_v6[80]
Definition: switch_event.c:86
switch_status_t switch_time_exp_lt(switch_time_exp_t *result, switch_time_t input)
Definition: switch_apr.c:346
switch_status_t switch_strftime_nocheck(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm)
Definition: switch_apr.c:202
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
int64_t switch_time_t
Definition: switch_apr.h:188
char * switch_core_get_uuid(void)
Retrieve the unique identifier from the core.
Definition: switch_core.c:495
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...)
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.
const char * switch_event_name(switch_event_types_t event)
Render the name of an event id enumeration.
Definition: switch_event.c:430
static switch_mutex_t * EVENT_QUEUE_MUTEX
Definition: switch_event.c:97
uintptr_t switch_size_t
switch_status_t switch_rfc822_date(char *date_str, switch_time_t t)
Definition: switch_apr.c:361
static uint64_t EVENT_SEQUENCE_NR
Definition: switch_event.c:105
#define SWITCH_UINT64_T_FMT
const char * switch_core_get_hostname(void)
Definition: switch_core.c:356
static char guess_ip_v4[80]
Definition: switch_event.c:85
const char * switch_cut_path(const char *in)
Create a pointer to the file name in a given file path eliminating the directory name.

◆ switch_event_rename_header()

switch_status_t switch_event_rename_header ( switch_event_t event,
const char *  header_name,
const char *  new_header_name 
)

Definition at line 796 of file switch_event.c.

References DUP, FREE, switch_event_header::hash, hash, switch_event::headers, switch_event_header::name, switch_event_header::next, switch_assert, switch_ci_hashfunc_default(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

797 {
799  switch_ssize_t hlen = -1;
800  unsigned long hash = 0;
801  int x = 0;
802 
803  switch_assert(event);
804 
805  if (!header_name) {
806  return SWITCH_STATUS_FALSE;
807  }
808 
809  hash = switch_ci_hashfunc_default(header_name, &hlen);
810 
811  for (hp = event->headers; hp; hp = hp->next) {
812  if ((!hp->hash || hash == hp->hash) && !strcasecmp(hp->name, header_name)) {
813  FREE(hp->name);
814  hp->name = DUP(new_header_name);
815  hlen = -1;
816  hp->hash = switch_ci_hashfunc_default(hp->name, &hlen);
817  x++;
818  }
819  }
820 
822 }
An event Header.
Definition: switch_event.h:65
unsigned int switch_ci_hashfunc_default(const char *char_key, switch_ssize_t *klen)
Definition: switch_apr.c:121
switch_hash_t * hash
Definition: switch_event.c:76
#define FREE(ptr)
Definition: switch_event.c:129
intptr_t switch_ssize_t
struct switch_event_header * next
Definition: switch_event.h:76
#define DUP(str)
Definition: switch_event.c:126
#define switch_assert(expr)
unsigned long hash
Definition: switch_event.h:75
switch_event_header_t * headers
Definition: switch_event.h:90

◆ switch_event_reserve_subclass_detailed()

switch_status_t switch_event_reserve_subclass_detailed ( const char *  owner,
const char *  subclass_name 
)

Reserve a subclass name for private use with a custom event.

Parameters
ownerthe owner of the event name
subclass_namethe name to reserve
Returns
SWITCH_STATUS_SUCCESS if the name was reserved
Note
There is nothing to enforce this but I recommend using module::event_name for the subclass names

Definition at line 485 of file switch_event.c.

References switch_event_subclass::bind, CUSTOM_HASH_MUTEX, DUP, switch_event_subclass::name, switch_event_subclass::owner, RUNTIME_POOL, switch_assert, switch_core_hash_find(), switch_core_hash_insert, switch_goto_status, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_INUSE, SWITCH_STATUS_SUCCESS, and switch_zmalloc.

Referenced by switch_event_bind_removable().

486 {
488  switch_event_subclass_t *subclass;
489 
491 
492  switch_assert(RUNTIME_POOL != NULL);
493  switch_assert(CUSTOM_HASH != NULL);
494 
495  if ((subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name))) {
496  /* a listener reserved it for us, now we can lock it so nobody else can have it */
497  if (subclass->bind) {
498  subclass->bind = 0;
500  }
502  }
503 
504  switch_zmalloc(subclass, sizeof(*subclass));
505 
506  subclass->owner = DUP(owner);
507  subclass->name = DUP(subclass_name);
508 
509  status = switch_core_hash_insert(CUSTOM_HASH, subclass->name, subclass);
510 
511  if (status != SWITCH_STATUS_SUCCESS) {
512  free(subclass->owner);
513  free(subclass->name);
514  free(subclass);
515  }
516 
517 end:
518 
520 
521  return status;
522 }
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
static switch_mutex_t * CUSTOM_HASH_MUTEX
Definition: switch_event.c:98
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
static switch_hash_t * CUSTOM_HASH
Definition: switch_event.c:99
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static switch_memory_pool_t * RUNTIME_POOL
Definition: switch_event.c:91
#define switch_zmalloc(ptr, len)
switch_status_t
Common return values.
#define switch_goto_status(_status, _label)
Definition: switch_utils.h:287
#define switch_core_hash_insert(_h, _k, _d)
Definition: switch_core.h:1479
A registered custom event subclass.
Definition: switch_event.c:63
#define DUP(str)
Definition: switch_event.c:126
#define switch_assert(expr)

◆ switch_event_running()

switch_xml_t switch_status_t switch_event_running ( void  )

Determine if the event system has been initialized.

Returns
SWITCH_STATUS_SUCCESS if the system is running

Definition at line 425 of file switch_event.c.

References SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and SYSTEM_RUNNING.

Referenced by switch_console_printf(), and switch_log_meta_vprintf().

◆ switch_event_serialize()

switch_status_t switch_event_serialize ( switch_event_t event,
char **  str,
switch_bool_t  encode 
)

Definition at line 1527 of file switch_event.c.

References switch_event_header::array, switch_event::body, buf, switch_event::headers, switch_event_header::idx, switch_event_header::name, switch_event_header::next, switch_safe_free, switch_snprintf(), SWITCH_STATUS_SUCCESS, switch_url_encode(), and switch_event_header::value.

Referenced by Event::serialize(), switch_core_session_thread(), and switch_ivr_originate().

1528 {
1529  switch_size_t len = 0;
1531  switch_size_t llen = 0, dlen = 0, blocksize = 512, encode_len = 1536, new_len = 0;
1532  char *buf;
1533  char *encode_buf = NULL; /* used for url encoding of variables to make sure unsafe things stay out of the serialized copy */
1534 
1535  *str = NULL;
1536 
1537  dlen = blocksize * 2;
1538 
1539  if (!(buf = malloc(dlen))) {
1540  abort();
1541  }
1542 
1543  /* go ahead and give ourselves some space to work with, should save a few reallocs */
1544  if (!(encode_buf = malloc(encode_len))) {
1545  abort();
1546  }
1547 
1548  /* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "hit serialized!.\n"); */
1549  for (hp = event->headers; hp; hp = hp->next) {
1550  /*
1551  * grab enough memory to store 3x the string (url encode takes one char and turns it into %XX)
1552  * so we could end up with a string that is 3 times the originals length, unlikely but rather
1553  * be safe than destroy the string, also add one for the null. And try to be smart about using
1554  * the memory, allocate and only reallocate if we need more. This avoids an alloc, free CPU
1555  * destroying loop.
1556  */
1557 
1558  if (hp->idx) {
1559  int i;
1560  new_len = 0;
1561  for(i = 0; i < hp->idx; i++) {
1562  new_len += (strlen(hp->array[i]) * 3) + 1;
1563  }
1564  } else {
1565  new_len = (strlen(hp->value) * 3) + 1;
1566  }
1567 
1568  if (encode_len < new_len) {
1569  char *tmp;
1570 
1571  /* keep track of the size of our allocation */
1572  encode_len = new_len;
1573 
1574  if (!(tmp = realloc(encode_buf, encode_len))) {
1575  abort();
1576  }
1577 
1578  encode_buf = tmp;
1579  }
1580 
1581  /* handle any bad things in the string like newlines : etc that screw up the serialized format */
1582 
1583 
1584  if (encode) {
1585  switch_url_encode(hp->value, encode_buf, encode_len);
1586  } else {
1587  switch_snprintf(encode_buf, encode_len, "[%s]", hp->value);
1588  }
1589 
1590 
1591  llen = strlen(hp->name) + strlen(encode_buf) + 8;
1592 
1593  if ((len + llen) > dlen) {
1594  char *m = NULL;
1595  dlen += (blocksize + (len + llen));
1596  if (!(m = realloc(buf, dlen))) {
1597  abort();
1598  }
1599  buf = m;
1600  }
1601 
1602  switch_snprintf(buf + len, dlen - len, "%s: %s\n", hp->name, *encode_buf == '\0' ? "_undef_" : encode_buf);
1603  len = strlen(buf);
1604  }
1605 
1606  /* we are done with the memory we used for encoding, give it back */
1607  switch_safe_free(encode_buf);
1608 
1609  if (event->body) {
1610  int blen = (int) strlen(event->body);
1611  llen = blen;
1612 
1613  if (blen) {
1614  llen += 25;
1615  } else {
1616  llen += 5;
1617  }
1618 
1619  if ((len + llen) > dlen) {
1620  char *m = NULL;
1621  dlen += (blocksize + (len + llen));
1622  if (!(m = realloc(buf, dlen))) {
1623  abort();
1624  }
1625  buf = m;
1626  }
1627 
1628  if (blen) {
1629  switch_snprintf(buf + len, dlen - len, "Content-Length: %d\n\n%s", blen, event->body);
1630  } else {
1631  switch_snprintf(buf + len, dlen - len, "\n");
1632  }
1633  } else {
1634  switch_snprintf(buf + len, dlen - len, "\n");
1635  }
1636 
1637  *str = buf;
1638 
1639  return SWITCH_STATUS_SUCCESS;
1640 }
An event Header.
Definition: switch_event.h:65
char * switch_url_encode(const char *url, char *buf, size_t len)
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
switch_byte_t switch_byte_t * buf
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
uintptr_t switch_size_t
struct switch_event_header * next
Definition: switch_event.h:76
switch_event_header_t * headers
Definition: switch_event.h:90

◆ switch_event_serialize_json()

switch_status_t switch_event_serialize_json ( switch_event_t event,
char **  str 
)

Definition at line 1856 of file switch_event.c.

References switch_event_serialize_json_obj(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by Event::serialize().

1857 {
1858 
1859  cJSON *cj;
1860  *str = NULL;
1861 
1863  *str = cJSON_PrintUnformatted(cj);
1864  cJSON_Delete(cj);
1865 
1866  return SWITCH_STATUS_SUCCESS;
1867  }
1868 
1869  return SWITCH_STATUS_FALSE;
1870 }
switch_status_t switch_event_serialize_json_obj(switch_event_t *event, cJSON **json)

◆ switch_event_serialize_json_obj()

switch_status_t switch_event_serialize_json_obj ( switch_event_t event,
cJSON **  json 
)

Definition at line 1818 of file switch_event.c.

References switch_event_header::array, switch_event::body, switch_event::headers, switch_event_header::idx, switch_event_header::name, switch_event_header::next, switch_snprintf(), SWITCH_STATUS_SUCCESS, and switch_event_header::value.

Referenced by switch_event_serialize_json().

1819 {
1821  cJSON *cj;
1822 
1823  cj = cJSON_CreateObject();
1824 
1825  for (hp = event->headers; hp; hp = hp->next) {
1826  if (hp->idx) {
1827  cJSON *a = cJSON_CreateArray();
1828  int i;
1829 
1830  for(i = 0; i < hp->idx; i++) {
1831  cJSON_AddItemToArray(a, cJSON_CreateString(hp->array[i]));
1832  }
1833 
1834  cJSON_AddItemToObject(cj, hp->name, a);
1835 
1836  } else {
1837  cJSON_AddItemToObject(cj, hp->name, cJSON_CreateString(hp->value));
1838  }
1839  }
1840 
1841  if (event->body) {
1842  int blen = (int) strlen(event->body);
1843  char tmp[25];
1844 
1845  switch_snprintf(tmp, sizeof(tmp), "%d", blen);
1846 
1847  cJSON_AddItemToObject(cj, "Content-Length", cJSON_CreateString(tmp));
1848  cJSON_AddItemToObject(cj, "_body", cJSON_CreateString(event->body));
1849  }
1850 
1851  *json = cj;
1852 
1853  return SWITCH_STATUS_SUCCESS;
1854 }
An event Header.
Definition: switch_event.h:65
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
struct switch_event_header * next
Definition: switch_event.h:76
switch_event_header_t * headers
Definition: switch_event.h:90

◆ switch_event_set_body()

switch_status_t switch_status_t switch_event_set_body ( switch_event_t event,
const char *  body 
)

Definition at line 1255 of file switch_event.c.

References switch_event::body, DUP, switch_safe_free, and SWITCH_STATUS_SUCCESS.

Referenced by switch_event_base_add_header().

1256 {
1257  switch_safe_free(event->body);
1258 
1259  if (body) {
1260  event->body = DUP(body);
1261  }
1262 
1263  return SWITCH_STATUS_SUCCESS;
1264 }
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
#define DUP(str)
Definition: switch_event.c:126

◆ switch_event_set_priority()

switch_status_t switch_event_set_priority ( switch_event_t event,
switch_priority_t  priority 
)

Set the priority of an event.

Parameters
eventthe event to set the priority on
prioritythe event priority
Returns
SWITCH_STATUS_SUCCESS

Definition at line 789 of file switch_event.c.

References switch_event_add_header_string(), switch_priority_name(), SWITCH_STACK_TOP, and SWITCH_STATUS_SUCCESS.

Referenced by Event::setPriority().

790 {
791  event->priority = priority;
793  return SWITCH_STATUS_SUCCESS;
794 }
const char * switch_priority_name(switch_priority_t priority)
Return a printable name of a switch_priority_t.
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.

◆ switch_event_set_subclass_name()

switch_status_t switch_status_t switch_event_set_subclass_name ( switch_event_t event,
const char *  subclass_name 
)

Definition at line 1227 of file switch_event.c.

References DUP, switch_event::subclass_name, switch_event_add_header_string(), switch_event_del_header, switch_safe_free, SWITCH_STACK_BOTTOM, SWITCH_STATUS_GENERR, and SWITCH_STATUS_SUCCESS.

1228 {
1229  if (!event || !subclass_name)
1230  return SWITCH_STATUS_GENERR;
1231 
1233  event->subclass_name = DUP(subclass_name);
1234  switch_event_del_header(event, "Event-Subclass");
1235  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Event-Subclass", event->subclass_name);
1236  return SWITCH_STATUS_SUCCESS;
1237 }
#define switch_event_del_header(_e, _h)
Definition: switch_event.h:212
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.
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
#define DUP(str)
Definition: switch_event.c:126
char * subclass_name
Definition: switch_event.h:88

◆ switch_event_shutdown()

switch_status_t switch_event_shutdown ( void  )

Stop the eventing system.

Returns
SWITCH_STATUS_SUCCESS when complete

Definition at line 549 of file switch_event.c.

References DISPATCH_THREAD_COUNT, event_channel_manager, EVENT_DISPATCH_QUEUE_THREADS, EVENT_QUEUE_MUTEX, switch_runtime::events_use_dispatch, FREE, MAX_DISPATCH, switch_event_subclass::name, switch_event_subclass::owner, runtime, SCF_MINIMAL, SWITCH_CHANNEL_LOG, switch_core_hash_destroy(), switch_core_hash_first, switch_core_hash_next(), switch_core_hash_this(), switch_core_memory_reclaim_events(), switch_core_test_flag(), switch_event_destroy(), SWITCH_LOG_CONSOLE, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_queue_interrupt_all(), switch_queue_trypop(), switch_queue_trypush(), SWITCH_STATUS_SUCCESS, switch_thread_join(), switch_yield, SYSTEM_RUNNING, THREAD_COUNT, and unsub_all_switch_event_channel().

Referenced by switch_core_destroy().

550 {
551  uint32_t x = 0;
552  int last = 0;
554  const void *var;
555  void *val;
556  switch_status_t res;
557 
559  return SWITCH_STATUS_SUCCESS;
560  }
561 
563  SYSTEM_RUNNING = 0;
565 
567 
570  (void)res;
572  }
573 
575  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping dispatch queues\n");
576 
577  for(x = 0; x < (uint32_t)DISPATCH_THREAD_COUNT; x++) {
579  (void)res;
580  }
581 
583 
584  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping dispatch threads\n");
585 
586  for(x = 0; x < (uint32_t)MAX_DISPATCH; x++) {
588  switch_status_t st;
590  }
591  }
592  }
593 
594  x = 0;
595  while (x < 100 && THREAD_COUNT) {
596  switch_yield(100000);
597  if (THREAD_COUNT == last) {
598  x++;
599  }
600 
601  last = THREAD_COUNT;
602  }
603 
605  void *pop = NULL;
606  switch_event_t *event = NULL;
607 
609  event = (switch_event_t *) pop;
610  switch_event_destroy(&event);
611  }
612  }
613 
614  for (hi = switch_core_hash_first(CUSTOM_HASH); hi; hi = switch_core_hash_next(&hi)) {
615  switch_event_subclass_t *subclass;
616  switch_core_hash_this(hi, &var, NULL, &val);
617  if ((subclass = (switch_event_subclass_t *) val)) {
618  FREE(subclass->name);
619  FREE(subclass->owner);
620  FREE(subclass);
621  }
622  }
623 
627 
630 
631  return SWITCH_STATUS_SUCCESS;
632 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_core_hash_destroy(_Inout_ switch_hash_t **hash)
Destroy an existing hash table.
static unsigned int MAX_DISPATCH
Definition: switch_event.c:83
int switch_core_test_flag(int flag)
Definition: switch_core.c:1792
static int SYSTEM_RUNNING
Definition: switch_event.c:104
static struct @5 event_channel_manager
Representation of an event.
Definition: switch_event.h:80
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1264
static switch_queue_t * EVENT_CHANNEL_DISPATCH_QUEUE
Definition: switch_event.c:96
static void unsub_all_switch_event_channel(void)
struct switch_runtime runtime
Definition: switch_core.c:86
static switch_thread_t * EVENT_DISPATCH_QUEUE_THREADS[MAX_DISPATCH_VAL]
Definition: switch_event.c:93
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
#define FREE(ptr)
Definition: switch_event.c:129
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
static switch_hash_t * CUSTOM_HASH
Definition: switch_event.c:99
static switch_queue_t * EVENT_DISPATCH_QUEUE
Definition: switch_event.c:95
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static int THREAD_COUNT
Definition: switch_event.c:100
static switch_mutex_t * EVENT_QUEUE_MUTEX
Definition: switch_event.c:97
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
Definition: switch_apr.c:1379
void switch_core_hash_this(_In_ switch_hash_index_t *hi, _Out_opt_ptrdiff_cap_(klen) const void **key, _Out_opt_ switch_ssize_t *klen, _Out_ void **val)
Gets the key and value of the current hash element.
switch_hash_index_t * switch_core_hash_next(_In_ switch_hash_index_t **hi)
Gets the next element of a hashtable.
void switch_core_memory_reclaim_events(void)
Definition: switch_event.c:524
switch_status_t
Common return values.
switch_status_t switch_queue_interrupt_all(switch_queue_t *queue)
Definition: switch_apr.c:1269
A registered custom event subclass.
Definition: switch_event.c:63
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1279
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.
void switch_event_destroy(switch_event_t **event)
Destroy an event.
#define switch_core_hash_first(_h)
Definition: switch_core.h:1592
static int DISPATCH_THREAD_COUNT
Definition: switch_event.c:101

◆ switch_event_unbind()

switch_status_t switch_event_unbind ( switch_event_node_t **  node)

Unbind a bound event consumer.

Parameters
nodenode to unbind
Returns
SWITCH_STATUS_SUCCESS if the consumer was unbinded

Definition at line 2175 of file switch_event.c.

References BLOCK, switch_event_node::event_id, FREE, switch_event_node::id, switch_event_node::next, RWLOCK, switch_event_node::subclass_name, SWITCH_CHANNEL_LOG, switch_event_name(), SWITCH_LOG_DEBUG, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_thread_rwlock_unlock(), and switch_thread_rwlock_wrlock().

Referenced by EventConsumer::cleanup(), and SWITCH_MODULE_SHUTDOWN_FUNCTION().

2176 {
2177  switch_event_node_t *n, *np, *lnp = NULL;
2179 
2180  n = *node;
2181 
2182  if (!n) {
2183  return status;
2184  }
2185 
2188  /* <LOCKED> ----------------------------------------------- */
2189  for (np = EVENT_NODES[n->event_id]; np; np = np->next) {
2190  if (np == n) {
2191  if (lnp) {
2192  lnp->next = n->next;
2193  } else {
2194  EVENT_NODES[n->event_id] = n->next;
2195  }
2196  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Event Binding deleted for %s:%s\n", n->id, switch_event_name(n->event_id));
2197  FREE(n->subclass_name);
2198  FREE(n->id);
2199  FREE(n);
2200  *node = NULL;
2201  status = SWITCH_STATUS_SUCCESS;
2202  break;
2203  }
2204  lnp = np;
2205  }
2208  /* </LOCKED> ----------------------------------------------- */
2209 
2210  return status;
2211 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:286
#define SWITCH_CHANNEL_LOG
static switch_event_node_t * EVENT_NODES[SWITCH_EVENT_ALL+1]
Definition: switch_event.c:87
static switch_thread_rwlock_t * RWLOCK
Definition: switch_event.c:88
A node to store binded events.
Definition: switch_event.c:48
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
#define FREE(ptr)
Definition: switch_event.c:129
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:260
switch_event_types_t event_id
Definition: switch_event.c:52
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
const char * switch_event_name(switch_event_types_t event)
Render the name of an event id enumeration.
Definition: switch_event.c:430
static switch_mutex_t * BLOCK
Definition: switch_event.c:89
switch_status_t
Common return values.
struct switch_event_node * next
Definition: switch_event.c:59
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_event_unbind_callback()

switch_status_t switch_event_unbind_callback ( switch_event_callback_t  callback)

Definition at line 2134 of file switch_event.c.

References BLOCK, switch_event_node::callback, switch_event_node::event_id, FREE, switch_event_node::id, switch_event_node::next, RWLOCK, switch_event_node::subclass_name, SWITCH_CHANNEL_LOG, SWITCH_EVENT_ALL, switch_event_name(), SWITCH_LOG_DEBUG, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_thread_rwlock_unlock(), and switch_thread_rwlock_wrlock().

Referenced by switch_core_sqldb_stop().

2135 {
2136  switch_event_node_t *n, *np, *lnp = NULL;
2138  int id;
2139 
2142  /* <LOCKED> ----------------------------------------------- */
2143  for (id = 0; id <= SWITCH_EVENT_ALL; id++) {
2144  lnp = NULL;
2145 
2146  for (np = EVENT_NODES[id]; np;) {
2147  n = np;
2148  np = np->next;
2149  if (n->callback == callback) {
2150  if (lnp) {
2151  lnp->next = n->next;
2152  } else {
2153  EVENT_NODES[n->event_id] = n->next;
2154  }
2155 
2156  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Event Binding deleted for %s:%s\n", n->id, switch_event_name(n->event_id));
2157  FREE(n->subclass_name);
2158  FREE(n->id);
2159  FREE(n);
2160  status = SWITCH_STATUS_SUCCESS;
2161  } else {
2162  lnp = n;
2163  }
2164  }
2165  }
2168  /* </LOCKED> ----------------------------------------------- */
2169 
2170  return status;
2171 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:286
#define SWITCH_CHANNEL_LOG
static switch_event_node_t * EVENT_NODES[SWITCH_EVENT_ALL+1]
Definition: switch_event.c:87
static switch_thread_rwlock_t * RWLOCK
Definition: switch_event.c:88
A node to store binded events.
Definition: switch_event.c:48
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
#define FREE(ptr)
Definition: switch_event.c:129
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:260
switch_event_types_t event_id
Definition: switch_event.c:52
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
const char * switch_event_name(switch_event_types_t event)
Render the name of an event id enumeration.
Definition: switch_event.c:430
static switch_mutex_t * BLOCK
Definition: switch_event.c:89
switch_status_t
Common return values.
struct switch_event_node * next
Definition: switch_event.c:59
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_event_callback_t callback
Definition: switch_event.c:56

◆ switch_event_xmlize()

switch_xml_t switch_event_xmlize ( switch_event_t event,
const char *  fmt,
  ... 
)

Render a XML representation of an event suitable for printing or network transport.

Parameters
eventthe event to render
fmtoptional body of the event (varargs see standard sprintf family)
Returns
the xml object if the operation was successful
Note
the body supplied by this function will supersede an existing body the event may have

Referenced by Event::serialize().

◆ switch_json_add_presence_data_cols()

void switch_json_add_presence_data_cols ( switch_event_t event,
cJSON json,
const char *  prefix 
)

Definition at line 2664 of file switch_event.c.

References json_add_child_string(), switch_event_get_header, switch_safe_free, switch_snprintf(), and switch_split.

2665 {
2666  const char *data;
2667 
2668  if (!prefix) prefix = "";
2669 
2670  if ((data = switch_event_get_header(event, "presence_data_cols"))) {
2671  char *cols[128] = { 0 };
2672  char header_name[128] = "";
2673  int col_count = 0, i = 0;
2674  char *data_copy = NULL;
2675 
2676  data_copy = strdup(data);
2677 
2678  col_count = switch_split(data_copy, ':', cols);
2679 
2680  for (i = 0; i < col_count; i++) {
2681  const char *val = NULL;
2682  switch_snprintf(header_name, sizeof(header_name), "%s%s", prefix, cols[i]);
2683 
2684  val = switch_event_get_header(event, cols[i]);
2685  json_add_child_string(json, header_name, val);
2686  }
2687 
2688  switch_safe_free(data_copy);
2689  }
2690 
2691 }
#define switch_split(_data, _delim, _array)
Definition: switch_utils.h:375
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172
static cJSON * json_add_child_string(cJSON *json, const char *name, const char *val)
Definition: switch_json.h:82

◆ switch_live_array_add()

switch_status_t switch_live_array_add ( switch_live_array_t la,
const char *  name,
int  index,
cJSON **  obj,
switch_bool_t  destroy 
)

Definition at line 3629 of file switch_event.c.

References cJSON_GetObjectCstr(), switch_live_array_s::event_channel, switch_live_array_s::hash, switch_live_array_s::head, json_add_child_obj(), la_broadcast(), switch_live_array_s::mutex, la_node_s::name, switch_live_array_s::name, la_node_s::next, la_node_s::obj, la_node_s::pos, switch_live_array_s::pos, switch_live_array_s::serno, switch_core_hash_find(), switch_core_hash_insert, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_SUCCESS, switch_zmalloc, and switch_live_array_s::tail.

3630 {
3631  la_node_t *node;
3633  const char *action = "add";
3634  cJSON *msg = NULL, *data = NULL;
3635  const char *visibility = NULL;
3636 
3637  switch_mutex_lock(la->mutex);
3638 
3639  if ((node = switch_core_hash_find(la->hash, name))) {
3640 
3641  action = "modify";
3642 
3643  if (node->obj) {
3644  if (duplicate) {
3645  cJSON_Delete(node->obj);
3646  node->obj = NULL;
3647  }
3648  }
3649  } else {
3650  switch_zmalloc(node, sizeof(*node));
3651 
3652  node->name = strdup(name);
3653  switch_core_hash_insert(la->hash, name, node);
3654 
3655  if (index > -1 && index < la->pos && la->head) {
3656  la_node_t *np, *last = NULL;
3657  int i = 0;
3658 
3659  for(np = la->head; np; np = np->next) {
3660 
3661  if (i == index) {
3662  if (last) {
3663  node->next = last->next;
3664  last->next = node;
3665  np = node;
3666  } else {
3667  node->next = la->head;
3668  la->head = node;
3669  np = node;
3670  }
3671  }
3672 
3673  np->pos = i;
3674  la->tail = np;
3675  last = np;
3676  i++;
3677  }
3678 
3679 
3680  } else {
3681 
3682  node->pos = la->pos++;
3683  index = node->pos;
3684 
3685  if (!la->head) {
3686  la->head = node;
3687  } else {
3688  la->tail->next = node;
3689  }
3690 
3691  la->tail = node;
3692  }
3693  }
3694 
3695  if (duplicate) {
3696  node->obj = cJSON_Duplicate(*obj, 1);
3697  } else {
3698  node->obj = *obj;
3699  }
3700 
3701  msg = cJSON_CreateObject();
3702  data = json_add_child_obj(msg, "data", NULL);
3703  if ((visibility = cJSON_GetObjectCstr(node->obj, "contentVisibility"))) {
3704  cJSON_AddItemToObject(msg, "contentVisibility", cJSON_CreateString(visibility));
3705  }
3706  cJSON_AddItemToObject(msg, "eventChannel", cJSON_CreateString(la->event_channel));
3707  cJSON_AddItemToObject(data, "action", cJSON_CreateString(action));
3708 
3709  if (index > -1) {
3710  cJSON_AddItemToObject(data, "arrIndex", cJSON_CreateNumber(index));
3711  }
3712 
3713  cJSON_AddItemToObject(data, "name", cJSON_CreateString(la->name));
3714  cJSON_AddItemToObject(data, "hashKey", cJSON_CreateString(node->name));
3715  cJSON_AddItemToObject(data, "wireSerno", cJSON_CreateNumber(la->serno++));
3716  cJSON_AddItemToObject(data, "data", cJSON_Duplicate(node->obj, 1));
3717 
3718  la_broadcast(la, &msg);
3719 
3721 
3722  return status;
3723 }
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
cJSON * obj
char * name
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
static cJSON * json_add_child_obj(cJSON *json, const char *name, cJSON *obj)
Definition: switch_json.h:49
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_hash_t * hash
int index
Definition: switch_cJSON.h:160
#define switch_zmalloc(ptr, len)
static switch_status_t la_broadcast(switch_live_array_t *la, cJSON **json)
const char * cJSON_GetObjectCstr(const cJSON *object, const char *string)
Definition: switch_json.c:22
switch_status_t
Common return values.
#define switch_core_hash_insert(_h, _k, _d)
Definition: switch_core.h:1479
const char *const name
Definition: switch_cJSON.h:250
switch_mutex_t * mutex
struct la_node_s * next

◆ switch_live_array_add_alias()

switch_bool_t switch_live_array_add_alias ( switch_live_array_t la,
const char *  event_channel,
const char *  name 
)

Definition at line 3459 of file switch_event.c.

References switch_live_array_s::aliases, alias_node_s::event_channel, event_channel_manager, alias_node_s::key, switch_live_array_s::mutex, alias_node_s::name, alias_node_s::next, switch_live_array_s::pool, switch_core_alloc, switch_core_hash_insert, switch_core_sprintf(), switch_core_strdup, SWITCH_FALSE, switch_mutex_lock(), switch_mutex_unlock(), and SWITCH_TRUE.

3460 {
3461  alias_node_t *node = 0, *np;
3462  switch_bool_t exist = SWITCH_FALSE;
3463 
3464  switch_mutex_lock(la->mutex);
3465  for (np = la->aliases; np && np->next; np = np->next) {
3466  if (!strcmp(np->event_channel, event_channel) && !strcmp(np->name, name)) {
3467  exist = SWITCH_TRUE;
3468  break;
3469  }
3470  }
3471 
3472  if (!exist) {
3473  node = switch_core_alloc(la->pool, sizeof(*node));
3474  node->event_channel = switch_core_strdup(la->pool, event_channel);
3475  node->name = switch_core_strdup(la->pool, name);
3476  node->key = switch_core_sprintf(la->pool, "%s.%s", event_channel, name);
3477 
3478  if (np) {
3479  np->next = node;
3480  } else {
3481  la->aliases = node;
3482  }
3483  }
3484 
3486 
3487  if (!exist) {
3491  }
3492 
3493 
3494  return !exist;
3495 }
struct alias_node_s * next
char * event_channel
static struct @5 event_channel_manager
switch_bool_t
Definition: switch_types.h:437
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
alias_node_t * aliases
#define switch_core_hash_insert(_h, _k, _d)
Definition: switch_core.h:1479
switch_memory_pool_t * pool
const char *const name
Definition: switch_cJSON.h:250
char * switch_core_sprintf(_In_ switch_memory_pool_t *pool, _In_z_ _Printf_format_string_ const char *fmt,...)
printf-style style printing routine. The data is output to a string allocated from the pool ...
switch_mutex_t * mutex

◆ switch_live_array_bootstrap()

switch_status_t switch_live_array_bootstrap ( switch_live_array_t la,
const char *  sessid,
switch_event_channel_id_t  channel_id 
)

Definition at line 3312 of file switch_event.c.

References switch_live_array_s::event_channel, switch_live_array_s::head, json_add_child_array(), json_add_child_obj(), switch_live_array_s::mutex, la_node_s::name, switch_live_array_s::name, la_node_s::next, la_node_s::obj, switch_live_array_s::serno, switch_event_channel_broadcast(), SWITCH_FALSE, switch_live_array_visible(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_SUCCESS, SWITCH_TRUE, and switch_live_array_s::visible.

Referenced by switch_live_array_parse_json().

3313 {
3314  la_node_t *np;
3315  cJSON *msg, *data;
3316 
3317  switch_mutex_lock(la->mutex);
3318 
3319 #if OLD_WAY
3320  msg = cJSON_CreateObject();
3321  data = json_add_child_obj(msg, "data", NULL);
3322 
3323  cJSON_AddItemToObject(msg, "eventChannel", cJSON_CreateString(la->event_channel));
3324  cJSON_AddItemToObject(data, "action", cJSON_CreateString("clear"));
3325  cJSON_AddItemToObject(data, "name", cJSON_CreateString(la->name));
3326  cJSON_AddItemToObject(data, "wireSerno", cJSON_CreateNumber(-1));
3327  cJSON_AddItemToObject(data, "data", cJSON_CreateObject());
3328 
3329  switch_event_channel_broadcast(la->event_channel, &msg, __FILE__, channel_id);
3330 
3331  for (np = la->head; np; np = np->next) {
3332  msg = cJSON_CreateObject();
3333  data = json_add_child_obj(msg, "data", NULL);
3334 
3335  cJSON_AddItemToObject(msg, "eventChannel", cJSON_CreateString(la->event_channel));
3336  cJSON_AddItemToObject(data, "action", cJSON_CreateString("add"));
3337  cJSON_AddItemToObject(data, "name", cJSON_CreateString(la->name));
3338  cJSON_AddItemToObject(data, "hashKey", cJSON_CreateString(np->name));
3339  cJSON_AddItemToObject(data, "wireSerno", cJSON_CreateNumber(la->serno++));
3340  cJSON_AddItemToObject(data, "data", cJSON_Duplicate(np->obj, 1));
3341  if (sessid) {
3342  cJSON_AddItemToObject(msg, "sessid", cJSON_CreateString(sessid));
3343  }
3344  switch_event_channel_broadcast(la->event_channel, &msg, __FILE__, channel_id);
3345  }
3346 #else
3347 
3348 
3349  msg = cJSON_CreateObject();
3350  data = json_add_child_obj(msg, "data", NULL);
3351 
3352  cJSON_AddItemToObject(msg, "eventChannel", cJSON_CreateString(la->event_channel));
3353  cJSON_AddItemToObject(data, "action", cJSON_CreateString("bootObj"));
3354  cJSON_AddItemToObject(data, "name", cJSON_CreateString(la->name));
3355  cJSON_AddItemToObject(data, "wireSerno", cJSON_CreateNumber(-1));
3356 
3357  if (sessid) {
3358  cJSON_AddItemToObject(msg, "sessid", cJSON_CreateString(sessid));
3359  }
3360 
3361  data = json_add_child_array(data, "data");
3362 
3363  for (np = la->head; np; np = np->next) {
3364  cJSON *row = cJSON_CreateArray();
3365  cJSON_AddItemToArray(row, cJSON_CreateString(np->name));
3366  cJSON_AddItemToArray(row, cJSON_Duplicate(np->obj, 1));
3367  cJSON_AddItemToArray(data, row);
3368  }
3369 
3370  switch_event_channel_broadcast(la->event_channel, &msg, __FILE__, channel_id);
3371 
3372 
3373 #endif
3374 
3375  if (!la->visible) {
3377  }
3378 
3380 
3381  return SWITCH_STATUS_SUCCESS;
3382 }
switch_status_t switch_live_array_visible(switch_live_array_t *la, switch_bool_t visible, switch_bool_t force)
cJSON * obj
switch_bool_t visible
char * name
static cJSON * json_add_child_array(cJSON *json, const char *name)
Definition: switch_json.h:68
switch_status_t switch_event_channel_broadcast(const char *event_channel, cJSON **json, const char *key, switch_event_channel_id_t id)
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
static cJSON * json_add_child_obj(cJSON *json, const char *name, cJSON *obj)
Definition: switch_json.h:49
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_mutex_t * mutex
struct la_node_s * next

◆ switch_live_array_clear()

switch_status_t switch_live_array_clear ( switch_live_array_t la)

Definition at line 3278 of file switch_event.c.

References cur, switch_live_array_s::event_channel, switch_live_array_s::head, json_add_child_obj(), la_broadcast(), switch_live_array_s::mutex, la_node_s::name, switch_live_array_s::name, la_node_s::next, la_node_s::obj, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_SUCCESS, and switch_live_array_s::tail.

Referenced by switch_live_array_destroy().

3279 {
3280  la_node_t *cur, *np;
3281  cJSON *msg, *data;
3282 
3283  switch_mutex_lock(la->mutex);
3284  np = la->head;
3285 
3286  msg = cJSON_CreateObject();
3287  data = json_add_child_obj(msg, "data", NULL);
3288 
3289  cJSON_AddItemToObject(msg, "eventChannel", cJSON_CreateString(la->event_channel));
3290  cJSON_AddItemToObject(data, "action", cJSON_CreateString("clear"));
3291  cJSON_AddItemToObject(data, "name", cJSON_CreateString(la->name));
3292  cJSON_AddItemToObject(data, "wireSerno", cJSON_CreateNumber(-1));
3293  cJSON_AddItemToObject(data, "data", cJSON_CreateObject());
3294 
3295  la_broadcast(la, &msg);
3296 
3297  while(np) {
3298  cur = np;
3299  np = np->next;
3300  cJSON_Delete(cur->obj);
3301  free(cur->name);
3302  free(cur);
3303  }
3304 
3305  la->head = la->tail = NULL;
3306 
3308 
3309  return SWITCH_STATUS_SUCCESS;
3310 }
cJSON * obj
char * name
pack cur
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
static cJSON * json_add_child_obj(cJSON *json, const char *name, cJSON *obj)
Definition: switch_json.h:49
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static switch_status_t la_broadcast(switch_live_array_t *la, cJSON **json)
switch_mutex_t * mutex
struct la_node_s * next

◆ switch_live_array_clear_alias()

switch_bool_t switch_live_array_clear_alias ( switch_live_array_t la,
const char *  event_channel,
const char *  name 
)

Definition at line 3427 of file switch_event.c.

References switch_live_array_s::aliases, alias_node_s::event_channel, event_channel_manager, switch_live_array_s::mutex, alias_node_s::name, alias_node_s::next, switch_core_hash_delete(), SWITCH_FALSE, switch_mutex_lock(), switch_mutex_unlock(), and SWITCH_TRUE.

3428 {
3429  alias_node_t *np, *last = NULL, *del = NULL;
3431 
3432  switch_mutex_lock(la->mutex);
3433  for (np = la->aliases; np; np = np->next) {
3434  if (!strcmp(np->event_channel, event_channel) && !strcmp(np->name, name)) {
3435  r = SWITCH_TRUE;
3436  del = np;
3437 
3438  if (last) {
3439  last->next = np->next;
3440  } else {
3441  la->aliases = np->next;
3442  }
3443  } else {
3444  last = np;
3445  }
3446  }
3448 
3449  if (r) {
3453  }
3454 
3455 
3456  return r;
3457 }
struct alias_node_s * next
char * event_channel
static struct @5 event_channel_manager
switch_bool_t
Definition: switch_types.h:437
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
alias_node_t * aliases
void * switch_core_hash_delete(_In_ switch_hash_t *hash, _In_z_ const char *key)
Delete data from a hash based on desired key.
const char *const name
Definition: switch_cJSON.h:250
switch_mutex_t * mutex

◆ switch_live_array_create()

switch_status_t switch_live_array_create ( const char *  event_channel,
const char *  name,
switch_event_channel_id_t  channel_id,
switch_live_array_t **  live_arrayP 
)

Definition at line 3497 of file switch_event.c.

References switch_live_array_s::channel_id, switch_live_array_s::event_channel, event_channel_manager, switch_live_array_s::hash, key, switch_live_array_s::key, switch_live_array_s::mutex, switch_live_array_s::name, switch_live_array_s::new, pool, switch_live_array_s::pool, switch_live_array_s::refs, switch_live_array_s::serno, switch_core_alloc, switch_core_hash_find(), switch_core_hash_init, switch_core_hash_insert, switch_core_new_memory_pool, switch_core_sprintf(), switch_core_strdup, SWITCH_FALSE, switch_mutex_init(), switch_mutex_lock(), SWITCH_MUTEX_NESTED, switch_mutex_unlock(), SWITCH_STATUS_SUCCESS, SWITCH_TRUE, and switch_live_array_s::visible.

Referenced by switch_live_array_parse_json().

3499 {
3500  switch_live_array_t *la = NULL;
3502  char *key = NULL;
3503 
3505  key = switch_core_sprintf(pool, "%s.%s", event_channel, name);
3506 
3508  la = switch_core_hash_find(event_channel_manager.lahash, key);
3510 
3511  if (la) {
3512  la->new = SWITCH_FALSE;
3513  } else {
3514  la = switch_core_alloc(pool, sizeof(*la));
3515  la->pool = pool;
3516  la->serno = 1;
3517  la->visible = SWITCH_TRUE;
3518  la->event_channel = switch_core_strdup(la->pool, event_channel);
3519  la->name = switch_core_strdup(la->pool, name);
3520  la->key = key;
3521  la->new = SWITCH_TRUE;
3522  la->channel_id = channel_id;
3525 
3529  }
3530 
3531  switch_mutex_lock(la->mutex);
3532  la->refs++;
3534 
3535  *live_arrayP = la;
3536 
3537  return SWITCH_STATUS_SUCCESS;
3538 }
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core&#39;s master pool.
Definition: switch_core.h:633
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
#define switch_core_hash_init(_hash)
Definition: switch_core.h:1431
static struct @5 event_channel_manager
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
switch_bool_t visible
switch_memory_pool_t * pool
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_hash_t * hash
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
switch_event_channel_id_t channel_id
#define switch_core_hash_insert(_h, _k, _d)
Definition: switch_core.h:1479
char * key
Definition: switch_msrp.c:64
switch_memory_pool_t * pool
switch_bool_t new
struct fspr_pool_t switch_memory_pool_t
const char *const name
Definition: switch_cJSON.h:250
char * switch_core_sprintf(_In_ switch_memory_pool_t *pool, _In_z_ _Printf_format_string_ const char *fmt,...)
printf-style style printing routine. The data is output to a string allocated from the pool ...
switch_mutex_t * mutex

◆ switch_live_array_del()

switch_status_t switch_live_array_del ( switch_live_array_t la,
const char *  name 
)

Definition at line 3581 of file switch_event.c.

References cur, switch_live_array_s::event_channel, switch_live_array_s::hash, switch_live_array_s::head, json_add_child_obj(), la_broadcast(), switch_live_array_s::mutex, la_node_s::name, switch_live_array_s::name, la_node_s::next, la_node_s::obj, la_node_s::pos, switch_live_array_s::pos, switch_live_array_s::serno, switch_core_hash_delete(), switch_core_hash_find(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, and switch_live_array_s::tail.

3582 {
3584  la_node_t *node, *cur, *np, *last = NULL;
3585  cJSON *msg, *data = NULL;
3586 
3587  switch_mutex_lock(la->mutex);
3588  if ((node = switch_core_hash_find(la->hash, name))) {
3589  np = la->head;
3590 
3591  while(np) {
3592  cur = np;
3593  np = np->next;
3594 
3595  if (cur == node) {
3596  if (last) {
3597  last->next = cur->next;
3598  } else {
3599  la->head = cur->next;
3600  }
3602 
3603  msg = cJSON_CreateObject();
3604  data = json_add_child_obj(msg, "data", NULL);
3605 
3606  cJSON_AddItemToObject(msg, "eventChannel", cJSON_CreateString(la->event_channel));
3607  cJSON_AddItemToObject(data, "name", cJSON_CreateString(la->name));
3608  cJSON_AddItemToObject(data, "action", cJSON_CreateString("del"));
3609  cJSON_AddItemToObject(data, "hashKey", cJSON_CreateString(cur->name));
3610  cJSON_AddItemToObject(data, "wireSerno", cJSON_CreateNumber(la->serno++));
3611  cJSON_AddItemToObject(data, "data", cur->obj);
3612  cur->obj = NULL;
3613 
3614  la_broadcast(la, &msg);
3615  free(cur->name);
3616  free(cur);
3617  } else {
3618  cur->pos = la->pos++;
3619  la->tail = cur;
3620  last = cur;
3621  }
3622  }
3623  }
3625 
3626  return status;
3627 }
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
cJSON * obj
char * name
pack cur
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
static cJSON * json_add_child_obj(cJSON *json, const char *name, cJSON *obj)
Definition: switch_json.h:49
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_hash_t * hash
static switch_status_t la_broadcast(switch_live_array_t *la, cJSON **json)
void * switch_core_hash_delete(_In_ switch_hash_t *hash, _In_z_ const char *key)
Delete data from a hash based on desired key.
switch_status_t
Common return values.
const char *const name
Definition: switch_cJSON.h:250
switch_mutex_t * mutex
struct la_node_s * next

◆ switch_live_array_destroy()

switch_status_t switch_live_array_destroy ( switch_live_array_t **  live_arrayP)

Definition at line 3384 of file switch_event.c.

References switch_live_array_s::aliases, event_channel_manager, switch_live_array_s::hash, alias_node_s::key, switch_live_array_s::key, switch_live_array_s::mutex, alias_node_s::next, pool, switch_live_array_s::pool, switch_live_array_s::refs, switch_core_destroy_memory_pool, switch_core_hash_delete(), switch_core_hash_destroy(), switch_live_array_clear(), switch_mutex_lock(), switch_mutex_unlock(), and SWITCH_STATUS_SUCCESS.

Referenced by switch_live_array_parse_json().

3385 {
3386  switch_live_array_t *la = *live_arrayP;
3388  alias_node_t *np;
3389  int done = 0;
3390 
3391  *live_arrayP = NULL;
3392 
3393  switch_mutex_lock(la->mutex);
3394  if (la->refs) {
3395  la->refs--;
3396  }
3397  if (la->refs) done = 1;
3399 
3400  if (done) {
3401  return SWITCH_STATUS_SUCCESS;
3402  }
3403 
3404  pool = la->pool;
3405 
3407 
3409 
3412  for (np = la->aliases; np; np = np->next) {
3414  }
3416 
3418 
3419  return SWITCH_STATUS_SUCCESS;
3420 }
struct alias_node_s * next
switch_status_t switch_core_hash_destroy(_Inout_ switch_hash_t **hash)
Destroy an existing hash table.
static struct @5 event_channel_manager
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:642
switch_memory_pool_t * pool
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_live_array_clear(switch_live_array_t *la)
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_hash_t * hash
alias_node_t * aliases
void * switch_core_hash_delete(_In_ switch_hash_t *hash, _In_z_ const char *key)
Delete data from a hash based on desired key.
switch_memory_pool_t * pool
struct fspr_pool_t switch_memory_pool_t
switch_mutex_t * mutex

◆ switch_live_array_get()

cJSON* switch_live_array_get ( switch_live_array_t la,
const char *  name 
)

Definition at line 3540 of file switch_event.c.

References switch_live_array_s::hash, switch_live_array_s::mutex, la_node_s::obj, switch_core_hash_find(), switch_mutex_lock(), and switch_mutex_unlock().

3541 {
3542  la_node_t *node;
3543  cJSON *dup = NULL;
3544 
3545  switch_mutex_lock(la->mutex);
3546  if ((node = switch_core_hash_find(la->hash, name))) {
3547  dup = cJSON_Duplicate(node->obj, 1);
3548  }
3550 
3551  return dup;
3552 }
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
cJSON * obj
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_hash_t * hash
const char *const name
Definition: switch_cJSON.h:250
switch_mutex_t * mutex

◆ switch_live_array_get_idx()

cJSON* switch_live_array_get_idx ( switch_live_array_t la,
int  idx 
)

Definition at line 3554 of file switch_event.c.

References switch_live_array_s::head, switch_live_array_s::mutex, la_node_s::next, la_node_s::obj, la_node_s::pos, switch_mutex_lock(), and switch_mutex_unlock().

3555 {
3556  la_node_t *node;
3557  cJSON *dup = NULL;
3558 
3559  switch_mutex_lock(la->mutex);
3560  for (node = la->head; node; node = node->next) {
3561  if (node->pos == idx) {
3562  dup = cJSON_Duplicate(node->obj, 1);
3563  break;
3564  }
3565  }
3567 
3568  return dup;
3569 }
cJSON * obj
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_mutex_t * mutex
struct la_node_s * next

◆ switch_live_array_isnew()

switch_bool_t switch_live_array_isnew ( switch_live_array_t la)

Definition at line 3422 of file switch_event.c.

References switch_live_array_s::new.

3423 {
3424  return la->new;
3425 }
switch_bool_t new

◆ switch_live_array_lock()

void switch_live_array_lock ( switch_live_array_t la)

Definition at line 3571 of file switch_event.c.

References switch_live_array_s::mutex, and switch_mutex_lock().

3572 {
3573  switch_mutex_lock(la->mutex);
3574 }
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_mutex_t * mutex

◆ switch_live_array_parse_json()

void switch_live_array_parse_json ( cJSON json,
switch_event_channel_id_t  channel_id 
)

Definition at line 3738 of file switch_event.c.

References cJSON_GetObjectCstr(), switch_live_array_s::command_handler, name, switch_live_array_bootstrap(), switch_live_array_create(), switch_live_array_destroy(), SWITCH_STATUS_SUCCESS, and switch_live_array_s::user_data.

3739 {
3740  const char *context = NULL, *name = NULL;
3741  switch_live_array_t *la = NULL;
3742  cJSON *jla = NULL;
3743 
3744  if ((jla = cJSON_GetObjectItem(json, "data")) && (jla = cJSON_GetObjectItem(jla, "liveArray"))) {
3745 
3746  if ((context = cJSON_GetObjectCstr(jla, "context")) && (name = cJSON_GetObjectCstr(jla, "name"))) {
3747  const char *command = cJSON_GetObjectCstr(jla, "command");
3748  const char *sessid = cJSON_GetObjectCstr(json, "sessid");
3749 
3750  if (command) {
3751  if (switch_live_array_create(context, name, channel_id, &la) == SWITCH_STATUS_SUCCESS) {
3752 
3753  if (!strcasecmp(command, "bootstrap")) {
3754  switch_live_array_bootstrap(la, sessid, channel_id);
3755  } else {
3756  if (la->command_handler) {
3757  la->command_handler(la, command, sessid, jla, la->user_data);
3758  }
3759  }
3761  }
3762  }
3763  }
3764  }
3765 
3766 }
switch_status_t switch_live_array_destroy(switch_live_array_t **live_arrayP)
const char * cJSON_GetObjectCstr(const cJSON *object, const char *string)
Definition: switch_json.c:22
switch_live_array_command_handler_t command_handler
switch_status_t switch_live_array_bootstrap(switch_live_array_t *la, const char *sessid, switch_event_channel_id_t channel_id)
switch_status_t switch_live_array_create(const char *event_channel, const char *name, switch_event_channel_id_t channel_id, switch_live_array_t **live_arrayP)
const char *const name
Definition: switch_cJSON.h:250

◆ switch_live_array_set_command_handler()

void switch_live_array_set_command_handler ( switch_live_array_t la,
switch_live_array_command_handler_t  command_handler 
)

Definition at line 3731 of file switch_event.c.

References switch_live_array_s::command_handler, and switch_assert.

3732 {
3733  switch_assert(la);
3734  la->command_handler = command_handler;
3735 }
switch_live_array_command_handler_t command_handler
#define switch_assert(expr)

◆ switch_live_array_set_user_data()

void switch_live_array_set_user_data ( switch_live_array_t la,
void *  user_data 
)

Definition at line 3725 of file switch_event.c.

References switch_assert, switch_event_node::user_data, and switch_live_array_s::user_data.

3726 {
3727  switch_assert(la);
3728  la->user_data = user_data;
3729 }
#define switch_assert(expr)

◆ switch_live_array_unlock()

void switch_live_array_unlock ( switch_live_array_t la)

Definition at line 3576 of file switch_event.c.

References switch_live_array_s::mutex, and switch_mutex_unlock().

3577 {
3579 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_mutex_t * mutex

◆ switch_live_array_visible()

switch_status_t switch_live_array_visible ( switch_live_array_t la,
switch_bool_t  visible,
switch_bool_t  force 
)

Definition at line 3254 of file switch_event.c.

References switch_live_array_s::event_channel, json_add_child_obj(), la_broadcast(), switch_live_array_s::mutex, switch_live_array_s::serno, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, and switch_live_array_s::visible.

Referenced by switch_live_array_bootstrap().

3255 {
3257 
3258  switch_mutex_lock(la->mutex);
3259  if (la->visible != visible || force) {
3260  cJSON *msg, *data;
3261 
3262  msg = cJSON_CreateObject();
3263  data = json_add_child_obj(msg, "data", NULL);
3264 
3265  cJSON_AddItemToObject(msg, "eventChannel", cJSON_CreateString(la->event_channel));
3266  cJSON_AddItemToObject(data, "action", cJSON_CreateString(visible ? "hide" : "show"));
3267  cJSON_AddItemToObject(data, "wireSerno", cJSON_CreateNumber(la->serno++));
3268 
3269  la_broadcast(la, &msg);
3270 
3271  la->visible = visible;
3272  }
3274 
3275  return status;
3276 }
switch_bool_t visible
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
static cJSON * json_add_child_obj(cJSON *json, const char *name, cJSON *obj)
Definition: switch_json.h:49
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static switch_status_t la_broadcast(switch_live_array_t *la, cJSON **json)
switch_status_t
Common return values.
switch_mutex_t * mutex

◆ switch_name_event()

switch_status_t switch_name_event ( const char *  name,
switch_event_types_t type 
)

return the event id that matches a given event name

Parameters
namethe name of the event
typethe event id to return
Returns
SWITCH_STATUS_SUCCESS if there was a match

Definition at line 438 of file switch_event.c.

References BLOCK, EVENT_NAMES, RUNTIME_POOL, switch_assert, SWITCH_EVENT_ALL, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by EventConsumer::bind(), Event::Event(), and switch_event_create_json().

439 {
441  switch_assert(BLOCK != NULL);
442  switch_assert(RUNTIME_POOL != NULL);
443 
444  for (x = 0; x <= SWITCH_EVENT_ALL; x++) {
445  if ((strlen(name) > 13 && !strcasecmp(name + 13, EVENT_NAMES[x])) || !strcasecmp(name, EVENT_NAMES[x])) {
446  *type = x;
447  return SWITCH_STATUS_SUCCESS;
448  }
449  }
450 
451  return SWITCH_STATUS_FALSE;
452 }
switch_event_types_t
Built-in Events.
static switch_memory_pool_t * RUNTIME_POOL
Definition: switch_event.c:91
static switch_mutex_t * BLOCK
Definition: switch_event.c:89
const char *const name
Definition: switch_cJSON.h:250
#define switch_assert(expr)
static char * EVENT_NAMES[]
Definition: switch_event.c:137