RTS API Documentation  1.10.11
Data Structures | Macros | Enumerations | Functions | Variables
Loadable Module Functions
+ Collaboration diagram for Loadable Module Functions:

Data Structures

struct  switch_loadable_module_interface
 The abstraction of a loadable module. More...
 

Macros

#define SWITCH_ADD_API(api_int, int_name, descript, funcptr, syntax_string)
 
#define SWITCH_ADD_JSON_API(json_api_int, int_name, descript, funcptr, syntax_string)
 
#define SWITCH_ADD_CHAT(chat_int, int_name, funcptr)
 
#define SWITCH_ADD_APP(app_int, int_name, short_descript, long_descript, funcptr, syntax_string, app_flags)
 
#define SWITCH_ADD_CHAT_APP(app_int, int_name, short_descript, long_descript, funcptr, syntax_string, app_flags)
 
#define SWITCH_ADD_DIALPLAN(dp_int, int_name, funcptr)
 
#define SWITCH_ADD_LIMIT(limit_int, int_name, incrptr, releaseptr, usageptr, resetptr, statusptr, interval_resetptr)
 
#define SWITCH_ADD_CODEC(codec_int, int_name)
 

Enumerations

enum  switch_loadable_module_type_t { SWITCH_LOADABLE_MODULE_TYPE_PRELOAD, SWITCH_LOADABLE_MODULE_TYPE_COMMON, SWITCH_LOADABLE_MODULE_TYPE_POSTLOAD }
 List of loadable module types. More...
 

Functions

switch_status_t switch_loadable_module_init (switch_bool_t autoload)
 Initilize the module backend and load all the modules. More...
 
void switch_loadable_module_shutdown (void)
 Shutdown the module backend and call the shutdown routine in all loaded modules. More...
 
switch_endpoint_interface_tswitch_loadable_module_get_endpoint_interface (const char *name)
 Retrieve the endpoint interface by it's registered name. More...
 
switch_codec_interface_tswitch_loadable_module_get_codec_interface (const char *name, const char *modname)
 Retrieve the codec interface by it's registered name. More...
 
char * switch_parse_codec_buf (char *buf, uint32_t *interval, uint32_t *rate, uint32_t *bit, uint32_t *channels, char **modname, char **fmtp)
 
switch_dialplan_interface_tswitch_loadable_module_get_dialplan_interface (const char *name)
 Retrieve the dialplan interface by it's registered name. More...
 
switch_status_t switch_loadable_module_enumerate_available (const char *dir_path, switch_modulename_callback_func_t callback, void *user_data)
 Enumerates a list of all modules discovered in a directory. More...
 
switch_status_t switch_loadable_module_enumerate_loaded (switch_modulename_callback_func_t callback, void *user_data)
 Enumerates a list of all currently loaded modules. More...
 
switch_status_t switch_loadable_module_build_dynamic (char *filename, switch_module_load_t switch_module_load, switch_module_runtime_t switch_module_runtime, switch_module_shutdown_t switch_module_shutdown, switch_bool_t runtime)
 build a dynamic module object and register it (for use in double embeded modules) More...
 
switch_timer_interface_tswitch_loadable_module_get_timer_interface (const char *name)
 Retrieve the timer interface by it's registered name. More...
 
switch_application_interface_tswitch_loadable_module_get_application_interface (const char *name)
 Retrieve the application interface by it's registered name. More...
 
switch_chat_application_interface_tswitch_loadable_module_get_chat_application_interface (const char *name)
 Retrieve the chat application interface by it's registered name. More...
 
switch_status_t switch_core_execute_chat_app (switch_event_t *message, const char *app, const char *data)
 
switch_api_interface_tswitch_loadable_module_get_api_interface (const char *name)
 Retrieve the API interface by it's registered name. More...
 
switch_json_api_interface_tswitch_loadable_module_get_json_api_interface (const char *name)
 Retrieve the JSON API interface by it's registered name. More...
 
switch_file_interface_tswitch_loadable_module_get_file_interface (const char *name, const char *modname)
 Retrieve the file format interface by it's registered name. More...
 
switch_database_interface_tswitch_loadable_module_get_database_interface (const char *name, const char *modname)
 Retrieve the database interface by it's registered name. More...
 
switch_speech_interface_tswitch_loadable_module_get_speech_interface (const char *name)
 Retrieve the speech interface by it's registered name. More...
 
switch_asr_interface_tswitch_loadable_module_get_asr_interface (const char *name)
 Retrieve the asr interface by it's registered name. More...
 
switch_directory_interface_tswitch_loadable_module_get_directory_interface (const char *name)
 Retrieve the directory interface by it's registered name. More...
 
switch_chat_interface_tswitch_loadable_module_get_chat_interface (const char *name)
 Retrieve the chat interface by it's registered name. More...
 
switch_say_interface_tswitch_loadable_module_get_say_interface (const char *name)
 Retrieve the say interface by it's registered name. More...
 
switch_management_interface_tswitch_loadable_module_get_management_interface (const char *relative_oid)
 Retrieve the management interface by it's registered name. More...
 
switch_limit_interface_tswitch_loadable_module_get_limit_interface (const char *name)
 Retrieve the limit interface by it's registered name. More...
 
int switch_loadable_module_get_codecs (const switch_codec_implementation_t **array, int arraylen)
 Retrieve the list of loaded codecs into an array. More...
 
int switch_loadable_module_get_codecs_sorted (const switch_codec_implementation_t **array, char fmtp_array[SWITCH_MAX_CODECS][MAX_FMTP_LEN], int arraylen, char **prefs, int preflen)
 Retrieve the list of loaded codecs into an array based on another array showing the sorted order. More...
 
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. More...
 
switch_status_t switch_json_api_execute (cJSON *json, switch_core_session_t *session, cJSON **retval)
 Execute a registered JSON API command. More...
 
switch_status_t switch_loadable_module_load_module (const char *dir, const char *fname, switch_bool_t runtime, const char **err)
 Load a module. More...
 
switch_status_t switch_loadable_module_exists (const char *mod)
 Check if a module is loaded. More...
 
switch_status_t switch_loadable_module_protect (const char *mod)
 Protect module from beeing unloaded. More...
 
switch_status_t switch_loadable_module_unload_module (const char *dir, const char *fname, switch_bool_t force, const char **err)
 Unoad a module. More...
 
 SWITCH_MOD_DECLARE (switch_status_t) switch_module_load(switch_loadable_module_interface_t **module_interface
 Load a module. More...
 
uint32_t switch_core_codec_next_id (void)
 
static int switch_check_interval (uint32_t rate, uint32_t ptime)
 
static void switch_core_codec_add_implementation (switch_memory_pool_t *pool, switch_codec_interface_t *codec_interface, const switch_codec_type_t codec_type, switch_payload_t ianacode, const char *iananame, char *fmtp, uint32_t samples_per_second, uint32_t actual_samples_per_second, int bits_per_second, int microseconds_per_packet, uint32_t samples_per_packet, uint32_t decoded_bytes_per_packet, uint32_t encoded_bytes_per_packet, uint8_t number_of_channels, int codec_frames_per_packet, switch_core_codec_init_func_t init, switch_core_codec_encode_func_t encode, switch_core_codec_decode_func_t decode, switch_core_codec_destroy_func_t destroy)
 

Variables

const char * filename
 

Detailed Description

Macro Definition Documentation

◆ SWITCH_ADD_API

#define SWITCH_ADD_API (   api_int,
  int_name,
  descript,
  funcptr,
  syntax_string 
)
Value:
for (;;) { \
api_int->interface_name = int_name; \
api_int->desc = descript; \
api_int->function = funcptr; \
api_int->syntax = syntax_string; \
break; \
}
A module interface to implement an api function.
void * switch_loadable_module_create_interface(switch_loadable_module_interface_t *mod, switch_module_interface_name_t iname)

Definition at line 365 of file switch_loadable_module.h.

Referenced by switch_msrp_load_apis_and_applications().

◆ SWITCH_ADD_APP

#define SWITCH_ADD_APP (   app_int,
  int_name,
  short_descript,
  long_descript,
  funcptr,
  syntax_string,
  app_flags 
)
Value:
for (;;) { \
app_int->interface_name = int_name; \
app_int->application_function = funcptr; \
app_int->short_desc = short_descript; \
app_int->long_desc = long_descript; \
app_int->syntax = syntax_string; \
app_int->flags = app_flags; \
break; \
}
A module interface to implement an application.
void * switch_loadable_module_create_interface(switch_loadable_module_interface_t *mod, switch_module_interface_name_t iname)

Definition at line 393 of file switch_loadable_module.h.

Referenced by switch_msrp_load_apis_and_applications().

◆ SWITCH_ADD_CHAT

#define SWITCH_ADD_CHAT (   chat_int,
  int_name,
  funcptr 
)
Value:
for (;;) { \
chat_int->chat_send = funcptr; \
chat_int->interface_name = int_name; \
break; \
}
Abstract interface to a chat module.
void * switch_loadable_module_create_interface(switch_loadable_module_interface_t *mod, switch_module_interface_name_t iname)

Definition at line 385 of file switch_loadable_module.h.

◆ SWITCH_ADD_CHAT_APP

#define SWITCH_ADD_CHAT_APP (   app_int,
  int_name,
  short_descript,
  long_descript,
  funcptr,
  syntax_string,
  app_flags 
)
Value:
for (;;) { \
app_int->interface_name = int_name; \
app_int->chat_application_function = funcptr; \
app_int->short_desc = short_descript; \
app_int->long_desc = long_descript; \
app_int->syntax = syntax_string; \
app_int->flags = app_flags; \
break; \
}
A module interface to implement a chat application.
void * switch_loadable_module_create_interface(switch_loadable_module_interface_t *mod, switch_module_interface_name_t iname)

Definition at line 405 of file switch_loadable_module.h.

◆ SWITCH_ADD_CODEC

#define SWITCH_ADD_CODEC (   codec_int,
  int_name 
)
Value:
for (;;) { \
codec_int->modname = switch_core_strdup(pool, (*module_interface)->module_name); \
codec_int->interface_name = switch_core_strdup(pool, int_name); \
codec_int->codec_id = switch_core_codec_next_id(); \
break; \
}
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
switch_memory_pool_t * pool
Top level module interface to implement a series of codec implementations.
uint32_t switch_core_codec_next_id(void)
void * switch_loadable_module_create_interface(switch_loadable_module_interface_t *mod, switch_module_interface_name_t iname)

Definition at line 440 of file switch_loadable_module.h.

Referenced by mod_g711_load(), and SWITCH_MODULE_LOAD_FUNCTION().

◆ SWITCH_ADD_DIALPLAN

#define SWITCH_ADD_DIALPLAN (   dp_int,
  int_name,
  funcptr 
)
Value:
for (;;) { \
dp_int->hunt_function = funcptr; \
dp_int->interface_name = int_name; \
break; \
}
Abstract interface to a dialplan module.
void * switch_loadable_module_create_interface(switch_loadable_module_interface_t *mod, switch_module_interface_name_t iname)

Definition at line 417 of file switch_loadable_module.h.

◆ SWITCH_ADD_JSON_API

#define SWITCH_ADD_JSON_API (   json_api_int,
  int_name,
  descript,
  funcptr,
  syntax_string 
)
Value:
for (;;) { \
json_api_int->interface_name = int_name; \
json_api_int->desc = descript; \
json_api_int->function = funcptr; \
json_api_int->syntax = syntax_string; \
break; \
}
A module interface to implement a json api function.
void * switch_loadable_module_create_interface(switch_loadable_module_interface_t *mod, switch_module_interface_name_t iname)

Definition at line 375 of file switch_loadable_module.h.

◆ SWITCH_ADD_LIMIT

#define SWITCH_ADD_LIMIT (   limit_int,
  int_name,
  incrptr,
  releaseptr,
  usageptr,
  resetptr,
  statusptr,
  interval_resetptr 
)
Value:
for (;;) { \
limit_int->incr = incrptr; \
limit_int->release = releaseptr; \
limit_int->usage = usageptr; \
limit_int->reset = resetptr; \
limit_int->interval_reset = interval_resetptr; \
limit_int->status = statusptr; \
limit_int->interface_name = int_name; \
break; \
}
Abstract interface to a limit module.
void * switch_loadable_module_create_interface(switch_loadable_module_interface_t *mod, switch_module_interface_name_t iname)

Definition at line 425 of file switch_loadable_module.h.

Enumeration Type Documentation

◆ switch_loadable_module_type_t

List of loadable module types.

Enumerator
SWITCH_LOADABLE_MODULE_TYPE_PRELOAD 
SWITCH_LOADABLE_MODULE_TYPE_COMMON 
SWITCH_LOADABLE_MODULE_TYPE_POSTLOAD 

Definition at line 57 of file switch_loadable_module.h.

Function Documentation

◆ switch_api_execute()

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.

Parameters
cmdthe name of the API command to execute
argthe optional arguement to the command
sessionan optional session
streamstream for output
Returns
the status returned by the API call

Definition at line 2933 of file switch_loadable_module.c.

References switch_stream_handle::data, switch_api_interface::function, switch_stream_handle::param_event, switch_assert, switch_event_add_header_string(), SWITCH_EVENT_API, switch_event_create, switch_event_fire, switch_loadable_module_get_api_interface(), switch_safe_free, SWITCH_STACK_BOTTOM, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_strip_whitespace(), UNPROTECT_INTERFACE, and switch_stream_handle::write_function.

Referenced by api_hook(), do_api_on(), API::execute(), API::executeString(), record_helper_post_process(), switch_channel_expand_variables_check(), switch_console_execute(), switch_core_perform_file_open(), switch_event_expand_headers_check(), switch_ivr_parse_event(), switch_ivr_record_file_event(), switch_nat_republish(), and switch_nat_status().

2934 {
2936  switch_status_t status;
2937  char *arg_used;
2938  char *cmd_used;
2939 
2940  switch_assert(stream != NULL);
2941  switch_assert(stream->data != NULL);
2942  switch_assert(stream->write_function != NULL);
2943 
2944  if (strcasecmp(cmd, "console_complete")) {
2945  cmd_used = switch_strip_whitespace(cmd);
2946  arg_used = switch_strip_whitespace(arg);
2947  } else {
2948  cmd_used = (char *) cmd;
2949  arg_used = (char *) arg;
2950  }
2951 
2952 
2953  if (!stream->param_event) {
2955  }
2956 
2957  if (stream->param_event) {
2958  if (cmd_used && *cmd_used) {
2959  switch_event_add_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "API-Command", cmd_used);
2960  }
2961  if (arg_used && *arg_used) {
2962  switch_event_add_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "API-Command-Argument", arg_used);
2963  }
2964  }
2965 
2966 
2967  if (cmd_used && (api = switch_loadable_module_get_api_interface(cmd_used)) != 0) {
2968  if ((status = api->function(arg_used, session, stream)) != SWITCH_STATUS_SUCCESS) {
2969  stream->write_function(stream, "COMMAND RETURNED ERROR!\n");
2970  }
2971  UNPROTECT_INTERFACE(api);
2972  } else {
2973  status = SWITCH_STATUS_FALSE;
2974  stream->write_function(stream, "INVALID COMMAND!\n");
2975  }
2976 
2977  if (stream->param_event) {
2978  switch_event_fire(&stream->param_event);
2979  }
2980 
2981  if (cmd_used != cmd) {
2982  switch_safe_free(cmd_used);
2983  }
2984 
2985  if (arg_used != arg) {
2986  switch_safe_free(arg_used);
2987  }
2988 
2989  return status;
2990 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:413
switch_api_function_t function
char * switch_strip_whitespace(const char *str)
switch_api_interface_t * switch_loadable_module_get_api_interface(const char *name)
Retrieve the API interface by it's registered name.
#define UNPROTECT_INTERFACE(_it)
A module interface to implement an api function.
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_stream_handle_write_function_t write_function
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
#define switch_assert(expr)

◆ switch_check_interval()

static int switch_check_interval ( uint32_t  rate,
uint32_t  ptime 
)
inlinestatic

Definition at line 449 of file switch_loadable_module.h.

References SWITCH_RECOMMENDED_BUFFER_SIZE.

Referenced by switch_core_codec_add_implementation().

450 {
451  uint32_t max_ms = 0, ptime_div = 0;
452 
453  switch (rate) {
454  case 22050:
455  case 11025:
456  if (ptime < 120)
457  return 1;
458  break;
459  case 48000:
460  case 44100:
461  max_ms = 40;
462  ptime_div = 2;
463  break;
464  case 32000:
465  case 24000:
466  case 16000:
467  max_ms = 60;
468  ptime_div = 2;
469  break;
470  case 12000:
471  max_ms = 100;
472  ptime_div = 2;
473  break;
474  case 8000:
475  max_ms = 120;
476  ptime_div = 2;
477  break;
478  }
479 
480  if (max_ms && ptime_div && (ptime <= max_ms && (ptime % ptime_div) == 0) && ((rate / 1000) * ptime) < SWITCH_RECOMMENDED_BUFFER_SIZE) {
481  return 1;
482  }
483 
484  return 0;
485 }
#define SWITCH_RECOMMENDED_BUFFER_SIZE
Definition: switch_types.h:590

◆ switch_core_codec_add_implementation()

static void switch_core_codec_add_implementation ( switch_memory_pool_t pool,
switch_codec_interface_t codec_interface,
const switch_codec_type_t  codec_type,
switch_payload_t  ianacode,
const char *  iananame,
char *  fmtp,
uint32_t  samples_per_second,
uint32_t  actual_samples_per_second,
int  bits_per_second,
int  microseconds_per_packet,
uint32_t  samples_per_packet,
uint32_t  decoded_bytes_per_packet,
uint32_t  encoded_bytes_per_packet,
uint8_t  number_of_channels,
int  codec_frames_per_packet,
switch_core_codec_init_func_t  init,
switch_core_codec_encode_func_t  encode,
switch_core_codec_decode_func_t  decode,
switch_core_codec_destroy_func_t  destroy 
)
inlinestatic
Parameters
codec_typeenumeration defining the type of the codec
ianacodethe IANA code number
iananamethe IANA code name
fmtpdefault fmtp to send (can be overridden by the init function)
samples_per_secondsamples transferred per second
actual_samples_per_secondactual samples transferred per second for those who are not moron g722 RFC writers
bits_per_secondbits transferred per second
microseconds_per_packetnumber of microseconds that denote one frame
samples_per_packetnumber of samples that denote one frame
decoded_bytes_per_packetnumber of bytes that denote one frame decompressed
encoded_bytes_per_packetnumber of bytes that denote one frame compressed
number_of_channelsnumber of channels represented
codec_frames_per_packetnumber of frames to send in one network packet
initfunction to initialize a codec handle using this implementation
encodefunction to encode raw data into encoded data
decodefunction to decode encoded data into raw data
destroydeinitalize a codec handle using this implementation

Definition at line 487 of file switch_loadable_module.h.

References switch_codec_implementation::actual_samples_per_second, switch_codec_implementation::bits_per_second, switch_codec_implementation::codec_frames_per_packet, switch_codec_implementation::codec_id, switch_codec_interface::codec_id, switch_codec_implementation::codec_type, switch_codec_implementation::decode, switch_codec_implementation::decoded_bytes_per_packet, switch_codec_implementation::destroy, switch_codec_implementation::encode, switch_codec_implementation::encoded_bytes_per_packet, switch_codec_implementation::fmtp, switch_codec_implementation::ianacode, switch_codec_implementation::iananame, switch_codec_implementation::impl_id, switch_codec_interface::implementations, switch_codec_implementation::init, switch_codec_implementation::microseconds_per_packet, switch_codec_implementation::modname, switch_codec_interface::modname, switch_codec_implementation::next, switch_codec_implementation::number_of_channels, switch_codec_implementation::samples_per_packet, switch_codec_implementation::samples_per_second, SWITCH_CHANNEL_LOG, switch_check_interval(), SWITCH_CODEC_TYPE_VIDEO, switch_core_alloc, switch_core_codec_next_id(), switch_core_strdup, SWITCH_LOG_CRIT, switch_log_printf(), and SWITCH_RECOMMENDED_BUFFER_SIZE.

Referenced by mod_g711_load(), and SWITCH_MODULE_LOAD_FUNCTION().

522 {
523 
524  if (decoded_bytes_per_packet > SWITCH_RECOMMENDED_BUFFER_SIZE) {
525  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Rejected codec name: %s rate: %u ptime: %d channels %d not enough buffer space %u > %d\n",
526  iananame, actual_samples_per_second, microseconds_per_packet / 1000, number_of_channels, decoded_bytes_per_packet, SWITCH_RECOMMENDED_BUFFER_SIZE);
527  } else if (codec_type == SWITCH_CODEC_TYPE_VIDEO || switch_check_interval(actual_samples_per_second, microseconds_per_packet / 1000)) {
529  impl->codec_type = codec_type;
530  impl->ianacode = ianacode;
531  impl->iananame = switch_core_strdup(pool, iananame);
532  impl->fmtp = switch_core_strdup(pool, fmtp);
533  impl->samples_per_second = samples_per_second;
534  impl->actual_samples_per_second = actual_samples_per_second;
535  impl->bits_per_second = bits_per_second;
536  impl->microseconds_per_packet = microseconds_per_packet;
537  impl->samples_per_packet = samples_per_packet;
538  impl->decoded_bytes_per_packet = decoded_bytes_per_packet;
539  impl->encoded_bytes_per_packet = encoded_bytes_per_packet;
540  impl->number_of_channels = number_of_channels;
541  impl->codec_frames_per_packet = codec_frames_per_packet;
542  impl->init = init;
543  impl->encode = encode;
544  impl->decode = decode;
545  impl->destroy = destroy;
546  impl->codec_id = codec_interface->codec_id;
547  impl->next = codec_interface->implementations;
549  impl->modname = codec_interface->modname;
550  codec_interface->implementations = impl;
551  } else {
552  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Rejected codec name: %s rate: %u ptime: %d channels: %d\n",
553  iananame, actual_samples_per_second, microseconds_per_packet / 1000, number_of_channels);
554  }
555 }
static int switch_check_interval(uint32_t rate, uint32_t ptime)
#define SWITCH_CHANNEL_LOG
switch_core_codec_destroy_func_t destroy
#define SWITCH_RECOMMENDED_BUFFER_SIZE
Definition: switch_types.h:590
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
switch_memory_pool_t * pool
switch_codec_implementation_t * implementations
switch_core_codec_decode_func_t decode
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
uint32_t switch_core_codec_next_id(void)
switch_core_codec_init_func_t init
struct switch_codec_implementation * next
switch_core_codec_encode_func_t encode
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.
A table of settings and callbacks that define a paticular implementation of a codec.

◆ switch_core_codec_next_id()

uint32_t switch_core_codec_next_id ( void  )

Definition at line 41 of file switch_core_codec.c.

References CODEC_ID.

Referenced by switch_core_codec_add_implementation(), and switch_core_codec_add_video_implementation().

42 {
43  return CODEC_ID++;
44 }
static uint32_t CODEC_ID

◆ switch_core_execute_chat_app()

switch_status_t switch_core_execute_chat_app ( switch_event_t message,
const char *  app,
const char *  data 
)

Definition at line 995 of file switch_loadable_module.c.

References switch_chat_application_interface::chat_application_function, EF_NO_CHAT_EXEC, SWITCH_CHANNEL_LOG, switch_event_expand_headers, switch_goto_status, switch_loadable_module_get_chat_application_interface(), SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_test_flag, and UNPROTECT_INTERFACE.

Referenced by Event::chat_execute().

996 {
999  char *expanded;
1000 
1002  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid chat application interface [%s]!\n", app);
1003  return SWITCH_STATUS_FALSE;
1004  }
1005 
1006  if (switch_test_flag(message, EF_NO_CHAT_EXEC)) {
1007  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Message is not allowed to execute apps\n");
1009  }
1010 
1011  if (data && !strcmp(data, "__undef")) {
1012  data = NULL;
1013  }
1014 
1015  expanded = switch_event_expand_headers(message, data);
1016 
1017  status = cai->chat_application_function(message, expanded);
1018 
1019  if (expanded != data) {
1020  free(expanded);
1021  }
1022 
1023  end:
1024 
1025  UNPROTECT_INTERFACE(cai);
1026 
1027  return status;
1028 
1029 }
#define switch_event_expand_headers(_event, _in)
Definition: switch_event.h:355
#define SWITCH_CHANNEL_LOG
switch_chat_application_function_t chat_application_function
A module interface to implement a chat application.
#define UNPROTECT_INTERFACE(_it)
switch_status_t
Common return values.
switch_chat_application_interface_t * switch_loadable_module_get_chat_application_interface(const char *name)
Retrieve the chat application interface by it&#39;s registered name.
#define switch_goto_status(_status, _label)
Definition: switch_utils.h:287
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
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_json_api_execute()

switch_status_t switch_json_api_execute ( cJSON json,
switch_core_session_t session,
cJSON **  retval 
)

Execute a registered JSON API command.

Parameters
jsonthe name of the JSON API command to execute
argthe optional arguement to the command
sessionan optional session
streamstream for output
Returns
the status returned by the API call

Definition at line 2992 of file switch_loadable_module.c.

References switch_json_api_interface::function, switch_assert, switch_loadable_module_get_json_api_interface(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and UNPROTECT_INTERFACE.

2993 {
2994  switch_json_api_interface_t *json_api;
2995  switch_status_t status;
2996  cJSON *function, *json_reply = NULL;
2997 
2998  switch_assert(json);
2999 
3000  function = cJSON_GetObjectItem(json, "command");
3001 
3002  if (function && function->valuestring
3003  && cJSON_GetObjectItem(json, "data") && (json_api = switch_loadable_module_get_json_api_interface(function->valuestring)) != 0) {
3004  if ((status = json_api->function(json, session, &json_reply)) != SWITCH_STATUS_SUCCESS) {
3005  cJSON_AddItemToObject(json, "status", cJSON_CreateString("error"));
3006  cJSON_AddItemToObject(json, "message", cJSON_CreateString("The command returned an error"));
3007  } else {
3008  cJSON_AddItemToObject(json, "status", cJSON_CreateString("success"));
3009  }
3010 
3011  if (!json_reply) {
3012  json_reply = cJSON_CreateNull();
3013  }
3014 
3015  if (retval) {
3016  *retval = json_reply;
3017  } else {
3018  cJSON_AddItemToObject(json, "response", json_reply);
3019  }
3020 
3021  UNPROTECT_INTERFACE(json_api);
3022  } else {
3023  status = SWITCH_STATUS_FALSE;
3024  cJSON_AddItemToObject(json, "status", cJSON_CreateString("error"));
3025  cJSON_AddItemToObject(json, "message", cJSON_CreateString("Invalid request or non-existant command"));
3026  cJSON_AddItemToObject(json, "response", cJSON_CreateNull());
3027  }
3028 
3029  return status;
3030 }
switch_json_api_interface_t * switch_loadable_module_get_json_api_interface(const char *name)
Retrieve the JSON API interface by it&#39;s registered name.
#define UNPROTECT_INTERFACE(_it)
switch_status_t
Common return values.
A module interface to implement a json api function.
switch_json_api_function_t function
#define switch_assert(expr)

◆ switch_loadable_module_build_dynamic()

switch_status_t switch_loadable_module_build_dynamic ( char *  filename,
switch_module_load_t  switch_module_load,
switch_module_runtime_t  switch_module_runtime,
switch_module_shutdown_t  switch_module_shutdown,
switch_bool_t  runtime 
)

build a dynamic module object and register it (for use in double embeded modules)

Parameters
filenamethe name of the modules source file
switch_module_loadthe function to call when the module is loaded
switch_module_runtimea function requested to be started in it's own thread once loaded
switch_module_shutdownthe function to call when the system is shutdown
runtimestart the runtime thread or not
Returns
the resulting status
Note
only use this function if you are making a module that in turn gateways module loading to another technology

Definition at line 1987 of file switch_loadable_module.c.

References switch_loadable_module::filename, loadable_modules, switch_loadable_module::module_interface, switch_loadable_module_interface::module_name, path, switch_loadable_module::perm, switch_loadable_module::pool, switch_loadable_module_container::pool, pool, SWITCH_CHANNEL_LOG, switch_core_alloc, switch_core_destroy_memory_pool, switch_core_launch_thread(), switch_core_new_memory_pool, switch_core_strdup, switch_loadable_module_exec(), switch_loadable_module_process(), SWITCH_LOG_CONSOLE, SWITCH_LOG_CRIT, switch_log_printf(), switch_loadable_module::switch_module_load, switch_loadable_module::switch_module_runtime, switch_loadable_module::switch_module_shutdown, SWITCH_STATUS_GENERR, SWITCH_STATUS_NOUNLOAD, SWITCH_STATUS_SUCCESS, and switch_loadable_module::thread.

1991 {
1992  switch_loadable_module_t *module = NULL;
1993  switch_module_load_t load_func_ptr = NULL;
1994  int loading = 1;
1995  const char *err = NULL;
1996  switch_loadable_module_interface_t *module_interface = NULL;
1998 
1999 
2002  abort();
2003  }
2004 
2005  if ((module = switch_core_alloc(pool, sizeof(switch_loadable_module_t))) == 0) {
2006  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Couldn't allocate memory\n");
2007  abort();
2008  }
2009 
2010 
2011 
2012  while (loading) {
2013  switch_status_t status;
2014  load_func_ptr = (switch_module_load_t) switch_module_load;
2015 
2016  if (load_func_ptr == NULL) {
2017  err = "Cannot Load";
2018  break;
2019  }
2020 
2021  status = load_func_ptr(&module_interface, pool);
2022 
2023  if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_NOUNLOAD) {
2024  err = "Module load routine returned an error";
2025  module_interface = NULL;
2026  break;
2027  }
2028 
2029  if ((module = switch_core_alloc(pool, sizeof(switch_loadable_module_t))) == 0) {
2030  abort();
2031  }
2032 
2033  if (status == SWITCH_STATUS_NOUNLOAD) {
2034  module->perm++;
2035  }
2036 
2037  loading = 0;
2038  }
2039 
2040  if (err) {
2042  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Error Loading module %s\n**%s**\n", filename, err);
2043  return SWITCH_STATUS_GENERR;
2044  }
2045 
2046  module->pool = pool;
2047  module->filename = switch_core_strdup(module->pool, filename);
2048  module->module_interface = module_interface;
2049  module->switch_module_load = load_func_ptr;
2050 
2051  if (switch_module_shutdown) {
2052  module->switch_module_shutdown = switch_module_shutdown;
2053  }
2054  if (switch_module_runtime) {
2055  module->switch_module_runtime = switch_module_runtime;
2056  }
2057  if (runtime && module->switch_module_runtime) {
2059  }
2060  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Successfully Loaded [%s]\n", module_interface->module_name);
2061  return switch_loadable_module_process((char *) module->filename, module, NULL);
2062 }
#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
switch_module_load_t switch_module_load
switch_memory_pool_t * pool
#define SWITCH_CHANNEL_LOG
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:642
struct switch_runtime runtime
Definition: switch_core.c:86
switch_memory_pool_t * pool
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
switch_status_t
Common return values.
switch_loadable_module_interface_t * module_interface
switch_thread_t * switch_core_launch_thread(void *(SWITCH_THREAD_FUNC *func)(switch_thread_t *, void *), void *obj, switch_memory_pool_t *pool)
Launch a thread.
const char * filename
static void *SWITCH_THREAD_FUNC switch_loadable_module_exec(switch_thread_t *thread, void *obj)
static switch_status_t switch_loadable_module_process(char *key, switch_loadable_module_t *new_module, switch_hash_t *event_hash)
switch_module_runtime_t switch_module_runtime
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.
struct fspr_pool_t switch_memory_pool_t
switch_module_shutdown_t switch_module_shutdown
The abstraction of a loadable module.

◆ switch_loadable_module_enumerate_available()

switch_status_t switch_loadable_module_enumerate_available ( const char *  dir_path,
switch_modulename_callback_func_t  callback,
void *  user_data 
)

Enumerates a list of all modules discovered in a directory.

Parameters
thedirectory to look for modules in
memorypool
callbackfunction to call for each module found
userdata argument to pass to the callback function
Returns
the resulting status

Definition at line 1931 of file switch_loadable_module.c.

References buffer, loadable_modules, switch_loadable_module_container::pool, switch_dir_close(), switch_dir_next_file(), switch_dir_open(), switch_mprintf(), switch_safe_free, SWITCH_STATUS_GENERR, and SWITCH_STATUS_SUCCESS.

Referenced by switch_console_list_available_modules().

1932 {
1933  switch_dir_t *dir = NULL;
1934  switch_status_t status;
1935  char buffer[256];
1936  const char *fname;
1937  const char *fname_ext;
1938  char *fname_base;
1939 
1940 #ifdef WIN32
1941  const char *ext = ".dll";
1942 #else
1943  const char *ext = ".so";
1944 #endif
1945 
1946  if ((status = switch_dir_open(&dir, dir_path, loadable_modules.pool)) != SWITCH_STATUS_SUCCESS) {
1947  return status;
1948  }
1949 
1950  while((fname = switch_dir_next_file(dir, buffer, sizeof(buffer)))) {
1951  if ((fname_ext = strrchr(fname, '.'))) {
1952  if (!strcmp(fname_ext, ext)) {
1953  if (!(fname_base = switch_mprintf("%.*s", (int)(fname_ext-fname), fname))) {
1954  status = SWITCH_STATUS_GENERR;
1955  goto end;
1956  }
1957  callback(user_data, fname_base);
1958  switch_safe_free(fname_base)
1959  }
1960  }
1961  }
1962 
1963 
1964  end:
1965  switch_dir_close(dir);
1966  return status;
1967 }
static struct switch_loadable_module_container loadable_modules
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
switch_status_t switch_dir_open(switch_dir_t **new_dir, const char *dirname, switch_memory_pool_t *pool)
Definition: switch_apr.c:561
const char * switch_dir_next_file(switch_dir_t *thedir, char *buf, switch_size_t len)
Definition: switch_apr.c:618
switch_status_t
Common return values.
char * buffer
Definition: switch_cJSON.h:153
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
switch_status_t switch_dir_close(switch_dir_t *thedir)
Definition: switch_apr.c:582

◆ switch_loadable_module_enumerate_loaded()

switch_status_t switch_loadable_module_enumerate_loaded ( switch_modulename_callback_func_t  callback,
void *  user_data 
)

Enumerates a list of all currently loaded modules.

Parameters
callbackfunction to call for each module found
userdata argument to pass to the callback function
Returns
the resulting status

Definition at line 1969 of file switch_loadable_module.c.

References loadable_modules, switch_loadable_module_container::module_hash, switch_loadable_module::module_interface, switch_loadable_module_interface::module_name, switch_loadable_module_container::mutex, switch_core_hash_first, switch_core_hash_next(), switch_core_hash_this(), switch_mutex_lock(), switch_mutex_unlock(), and SWITCH_STATUS_SUCCESS.

Referenced by switch_console_list_loaded_modules().

1970 {
1971  switch_hash_index_t *hi;
1972  void *val;
1973  switch_loadable_module_t *module;
1974 
1977  switch_core_hash_this(hi, NULL, NULL, &val);
1978  module = (switch_loadable_module_t *) val;
1979 
1980  callback(user_data, module->module_interface->module_name);
1981  }
1983 
1984  return SWITCH_STATUS_SUCCESS;
1985 }
static struct switch_loadable_module_container loadable_modules
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
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.
switch_loadable_module_interface_t * module_interface
#define switch_core_hash_first(_h)
Definition: switch_core.h:1592

◆ switch_loadable_module_exists()

switch_status_t switch_loadable_module_exists ( const char *  mod)

Check if a module is loaded.

Parameters
modthe module name
Returns
the status

Definition at line 1846 of file switch_loadable_module.c.

References loadable_modules, switch_loadable_module_container::module_hash, switch_loadable_module_container::mutex, switch_core_hash_find(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and zstr.

1847 {
1848  switch_status_t status;
1849 
1850  if (zstr(mod)) {
1851  return SWITCH_STATUS_FALSE;
1852  }
1853 
1856  status = SWITCH_STATUS_SUCCESS;
1857  } else {
1858  status = SWITCH_STATUS_FALSE;
1859  }
1861 
1862  return status;
1863 }
static struct switch_loadable_module_container loadable_modules
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
#define zstr(x)
Definition: switch_utils.h:314
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_status_t
Common return values.

◆ switch_loadable_module_get_api_interface()

switch_api_interface_t* switch_loadable_module_get_api_interface ( const char *  name)

Retrieve the API interface by it's registered name.

Parameters
namethe name of the API
Returns
the desired API interface

Referenced by switch_api_execute().

◆ switch_loadable_module_get_application_interface()

switch_application_interface_t* switch_loadable_module_get_application_interface ( const char *  name)

Retrieve the application interface by it's registered name.

Parameters
namethe name of the application
Returns
the desired application interface

Referenced by collect_thread_run(), switch_core_session_execute_application_get_flags(), switch_core_session_get_app_flags(), switch_ivr_menu_execute(), and switch_ivr_phrase_macro_event().

◆ switch_loadable_module_get_asr_interface()

switch_asr_interface_t* switch_loadable_module_get_asr_interface ( const char *  name)

Retrieve the asr interface by it's registered name.

Parameters
namethe name of the asr interface
Returns
the desired asr interface

Referenced by switch_core_asr_open().

◆ switch_loadable_module_get_chat_application_interface()

switch_chat_application_interface_t* switch_loadable_module_get_chat_application_interface ( const char *  name)

Retrieve the chat application interface by it's registered name.

Parameters
namethe name of the chat application
Returns
the desired chat application interface

Referenced by switch_core_execute_chat_app().

◆ switch_loadable_module_get_chat_interface()

switch_chat_interface_t* switch_loadable_module_get_chat_interface ( const char *  name)

Retrieve the chat interface by it's registered name.

Parameters
namethe name of the chat interface
Returns
the desired chat interface

Referenced by do_chat_send().

◆ switch_loadable_module_get_codec_interface()

switch_codec_interface_t* switch_loadable_module_get_codec_interface ( const char *  name,
const char *  modname 
)

Retrieve the codec interface by it's registered name.

Parameters
namethe name of the codec
Returns
the desired codec interface

Definition at line 2547 of file switch_loadable_module.c.

References switch_loadable_module_container::codec_hash, switch_codec_node_s::interface_name, loadable_modules, switch_loadable_module_container::mutex, switch_codec_node_s::next, PROTECT_INTERFACE, switch_codec_node_s::ptr, switch_core_hash_find(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_core_codec_init_with_bitrate(), switch_core_codec_parse_fmtp(), and switch_loadable_module_get_codecs_sorted().

2548 {
2549  switch_codec_interface_t *codec = NULL;
2550  switch_codec_node_t *node, *head;
2551 
2553 
2555  if (modname) {
2556  for (node = head; node; node = node->next) {
2557  if (!strcasecmp(node->interface_name, modname)) {
2558  codec = (switch_codec_interface_t *) node->ptr;
2559  break;
2560  }
2561  }
2562  } else {
2563  codec = (switch_codec_interface_t *) head->ptr;
2564  }
2565  }
2566 
2568 
2569  PROTECT_INTERFACE(codec);
2570 
2571  return codec;
2572 }
static struct switch_loadable_module_container loadable_modules
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
const switch_codec_interface_t * ptr
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
Top level module interface to implement a series of codec implementations.
struct switch_codec_node_s * next
#define PROTECT_INTERFACE(_it)
const char *const name
Definition: switch_cJSON.h:250

◆ switch_loadable_module_get_codecs()

int switch_loadable_module_get_codecs ( const switch_codec_implementation_t **  array,
int  arraylen 
)

Retrieve the list of loaded codecs into an array.

Parameters
arraythe array to populate
arraylenthe max size in elements of the array
Returns
the number of elements added to the array

Definition at line 2699 of file switch_loadable_module.c.

References switch_loadable_module_container::codec_hash, switch_codec_implementation::ianacode, switch_codec_implementation::iananame, switch_codec_interface::implementations, loadable_modules, switch_codec_implementation::microseconds_per_packet, switch_loadable_module_container::mutex, switch_codec_node_s::next, switch_codec_implementation::next, switch_codec_node_s::ptr, switch_core_hash_first, switch_core_hash_next(), switch_core_hash_this(), switch_default_ptime(), switch_loadable_module_sort_codecs(), switch_mutex_lock(), switch_mutex_unlock(), and switch_safe_free.

Referenced by switch_core_media_set_r_sdp_codec_string().

2700 {
2701  switch_hash_index_t *hi;
2702  void *val;
2703  switch_codec_interface_t *codec_interface;
2704  int i = 0;
2705  const switch_codec_implementation_t *imp;
2706  switch_codec_node_t *node, *head;
2707 
2710  switch_core_hash_this(hi, NULL, NULL, &val);
2711  head = (switch_codec_node_t *) val;
2712 
2713  for (node = head; node; node = node->next) {
2714  codec_interface = (switch_codec_interface_t *) node->ptr;
2715 
2716  /* Look for the default ptime of the codec because it's the safest choice */
2717  for (imp = codec_interface->implementations; imp; imp = imp->next) {
2718  uint32_t default_ptime = switch_default_ptime(imp->iananame, imp->ianacode);
2719 
2720  if (imp->microseconds_per_packet / 1000 == (int)default_ptime) {
2721  array[i++] = imp;
2722  goto found;
2723  }
2724  }
2725  /* oh well we will use what we have */
2726  array[i++] = codec_interface->implementations;
2727  }
2728 
2729  found:
2730 
2731  if (i > arraylen) {
2732  break;
2733  }
2734 
2735  }
2736  switch_safe_free(hi);
2737 
2739 
2741 
2742  return i;
2743 
2744 }
static struct switch_loadable_module_container loadable_modules
const switch_codec_interface_t * ptr
switch_codec_implementation_t * implementations
static void switch_loadable_module_sort_codecs(const switch_codec_implementation_t **array, int arraylen)
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_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
Top level module interface to implement a series of codec implementations.
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.
uint32_t switch_default_ptime(const char *name, uint32_t number)
Definition: switch_core.c:2022
struct switch_codec_node_s * next
struct switch_codec_implementation * next
A table of settings and callbacks that define a paticular implementation of a codec.
#define switch_core_hash_first(_h)
Definition: switch_core.h:1592

◆ switch_loadable_module_get_codecs_sorted()

int switch_loadable_module_get_codecs_sorted ( const switch_codec_implementation_t **  array,
char  fmtp_array[SWITCH_MAX_CODECS][MAX_FMTP_LEN],
int  arraylen,
char **  prefs,
int  preflen 
)

Retrieve the list of loaded codecs into an array based on another array showing the sorted order.

Parameters
arraythe array to populate
arraylenthe max size in elements of the array
prefsthe array of preferred codec names
preflenthe size in elements of the prefs
Returns
the number of elements added to the array
Note
this function only considers codecs that are listed in the "prefs" array and ignores the rest.

Definition at line 2796 of file switch_loadable_module.c.

References switch_codec_implementation::actual_samples_per_second, switch_codec_implementation::bits_per_second, buf, switch_codec_implementation::codec_type, switch_codec_implementation::ianacode, switch_codec_implementation::iananame, switch_codec_interface::implementations, loadable_modules, switch_codec_implementation::microseconds_per_packet, switch_loadable_module_container::mutex, name, switch_codec_implementation::next, switch_codec_implementation::number_of_channels, switch_codec_implementation::samples_per_second, SWITCH_CODEC_TYPE_VIDEO, switch_copy_string(), switch_default_ptime(), switch_default_rate(), switch_loadable_module_get_codec_interface(), switch_loadable_module_sort_codecs(), switch_mutex_lock(), switch_mutex_unlock(), switch_parse_codec_buf(), switch_set_string, switch_str_nil, UNPROTECT_INTERFACE, and zstr.

Referenced by switch_core_media_negotiate_sdp(), switch_core_media_prepare_codecs(), switch_core_media_recover_session(), and switch_core_media_set_r_sdp_codec_string().

2797 {
2798  int x, i = 0, j = 0;
2799  switch_codec_interface_t *codec_interface;
2800  const switch_codec_implementation_t *imp;
2801 
2803 
2804  for (x = 0; x < preflen; x++) {
2805  char *name, buf[256], jbuf[256], *modname = NULL, *fmtp = NULL;
2806  uint32_t interval = 0, rate = 0, bit = 0, channels = 1;
2807 
2808  switch_copy_string(buf, prefs[x], sizeof(buf));
2809  name = switch_parse_codec_buf(buf, &interval, &rate, &bit, &channels, &modname, &fmtp);
2810 
2811  for(j = 0; j < x; j++) {
2812  char *jname, *jmodname = NULL, *jfmtp = NULL;
2813  uint32_t jinterval = 0, jrate = 0, jbit = 0, jchannels = 1;
2814  uint32_t ointerval = interval, orate = rate, ochannels = channels;
2815 
2816  if (ointerval == 0) {
2817  ointerval = switch_default_ptime(name, 0);
2818  }
2819 
2820  if (orate == 0) {
2821  orate = switch_default_rate(name, 0);
2822  }
2823 
2824  if (ochannels == 0) {
2825  ochannels = 1;
2826  }
2827 
2828  switch_copy_string(jbuf, prefs[j], sizeof(jbuf));
2829  jname = switch_parse_codec_buf(jbuf, &jinterval, &jrate, &jbit, &jchannels, &jmodname, &jfmtp);
2830 
2831  if (jinterval == 0) {
2832  jinterval = switch_default_ptime(jname, 0);
2833  }
2834 
2835  if (jrate == 0) {
2836  jrate = switch_default_rate(jname, 0);
2837  }
2838 
2839  if (jchannels == 0) {
2840  jchannels = 1;
2841  }
2842 
2843  if (!strcasecmp(name, jname) && ointerval == jinterval && orate == jrate && ochannels == jchannels &&
2844  !strcasecmp(switch_str_nil(fmtp), switch_str_nil(jfmtp))) {
2845  goto next_x;
2846  }
2847  }
2848 
2849  if ((codec_interface = switch_loadable_module_get_codec_interface(name, modname)) != 0) {
2850  /* If no specific codec interval is requested opt for the default above all else because lots of stuff assumes it */
2851  for (imp = codec_interface->implementations; imp; imp = imp->next) {
2852  uint32_t default_ptime = switch_default_ptime(imp->iananame, imp->ianacode);
2853  uint32_t default_rate = switch_default_rate(imp->iananame, imp->ianacode);
2854 
2855  if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) {
2856  uint32_t crate = !strcasecmp(imp->iananame, "g722") ? imp->samples_per_second : imp->actual_samples_per_second;
2857 
2858  if ((!interval && (uint32_t) (imp->microseconds_per_packet / 1000) != default_ptime) ||
2859  (interval && (uint32_t) (imp->microseconds_per_packet / 1000) != interval)) {
2860  continue;
2861  }
2862 
2863  if (((!rate && crate != default_rate) || (rate && (uint32_t) imp->actual_samples_per_second != rate))) {
2864  continue;
2865  }
2866 
2867  if (bit && (uint32_t) imp->bits_per_second != bit) {
2868  continue;
2869  }
2870 
2871  if (channels && imp->number_of_channels != channels) {
2872  continue;
2873  }
2874  }
2875 
2876  if (!zstr(fmtp)) {
2877  switch_set_string(fmtp_array[i], fmtp);
2878  }
2879  array[i++] = imp;
2880  goto found;
2881 
2882  }
2883 
2884  /* Either looking for a specific interval or there was no interval specified and there wasn't one at the default ptime available */
2885  for (imp = codec_interface->implementations; imp; imp = imp->next) {
2886  if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) {
2887  uint32_t crate = !strcasecmp(imp->iananame, "g722") ? imp->samples_per_second : imp->actual_samples_per_second;
2888 
2889  if (interval && (uint32_t) (imp->microseconds_per_packet / 1000) != interval) {
2890  continue;
2891  }
2892 
2893  if (rate && (uint32_t) crate != rate) {
2894  continue;
2895  }
2896 
2897  if (bit && (uint32_t) imp->bits_per_second != bit) {
2898  continue;
2899  }
2900 
2901  if (channels && imp->number_of_channels != channels) {
2902  continue;
2903  }
2904  }
2905 
2906  array[i++] = imp;
2907  goto found;
2908 
2909  }
2910 
2911  found:
2912 
2913  UNPROTECT_INTERFACE(codec_interface);
2914 
2915  if (i > arraylen) {
2916  break;
2917  }
2918 
2919  }
2920 
2921  next_x:
2922 
2923  continue;
2924  }
2925 
2927 
2929 
2930  return i;
2931 }
static struct switch_loadable_module_container loadable_modules
switch_codec_implementation_t * implementations
static void switch_loadable_module_sort_codecs(const switch_codec_implementation_t **array, int arraylen)
char * switch_parse_codec_buf(char *buf, uint32_t *interval, uint32_t *rate, uint32_t *bit, uint32_t *channels, char **modname, char **fmtp)
#define zstr(x)
Definition: switch_utils.h:314
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
#define UNPROTECT_INTERFACE(_it)
switch_byte_t switch_byte_t * buf
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
Top level module interface to implement a series of codec implementations.
uint32_t switch_default_ptime(const char *name, uint32_t number)
Definition: switch_core.c:2022
char * switch_copy_string(_Out_z_cap_(dst_size) char *dst, _In_z_ const char *src, _In_ switch_size_t dst_size)
switch_codec_interface_t * switch_loadable_module_get_codec_interface(const char *name, const char *modname)
Retrieve the codec interface by it&#39;s registered name.
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:993
#define switch_set_string(_dst, _src)
Definition: switch_utils.h:734
struct switch_codec_implementation * next
A table of settings and callbacks that define a paticular implementation of a codec.
const char *const name
Definition: switch_cJSON.h:250
uint32_t switch_default_rate(const char *name, uint32_t number)
Definition: switch_core.c:2033

◆ switch_loadable_module_get_database_interface()

switch_database_interface_t* switch_loadable_module_get_database_interface ( const char *  name,
const char *  modname 
)

Retrieve the database interface by it's registered name.

Parameters
namethe name of the dsn prefix
Returns
the desired database format interface

Definition at line 2519 of file switch_loadable_module.c.

References switch_loadable_module_container::database_hash, switch_database_node_s::interface_name, loadable_modules, switch_loadable_module_container::mutex, switch_database_node_s::next, PROTECT_INTERFACE, switch_database_node_s::ptr, switch_core_hash_find(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by _switch_cache_db_get_db_handle_dsn_ex(), and switch_database_available().

2520 {
2521  switch_database_interface_t *i = NULL;
2522  switch_database_node_t *node, *head;
2523 
2525 
2527  if (modname) {
2528  for (node = head; node; node = node->next) {
2529  if (!strcasecmp(node->interface_name, modname)) {
2530  i = (switch_database_interface_t *)node->ptr;
2531  break;
2532  }
2533  }
2534  }
2535  else {
2536  i = (switch_database_interface_t *)head->ptr;
2537  }
2538  }
2539 
2541 
2542  if (i) PROTECT_INTERFACE(i);
2543 
2544  return i;
2545 }
static struct switch_loadable_module_container loadable_modules
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
const switch_database_interface_t * ptr
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
struct switch_database_node_s * next
#define PROTECT_INTERFACE(_it)
const char *const name
Definition: switch_cJSON.h:250
Abstract interface to a database module.

◆ switch_loadable_module_get_dialplan_interface()

switch_dialplan_interface_t* switch_loadable_module_get_dialplan_interface ( const char *  name)

Retrieve the dialplan interface by it's registered name.

Parameters
namethe name of the dialplan
Returns
the desired dialplan interface

Referenced by switch_core_session_execute_exten(), and switch_core_standard_on_routing().

◆ switch_loadable_module_get_directory_interface()

switch_directory_interface_t* switch_loadable_module_get_directory_interface ( const char *  name)

Retrieve the directory interface by it's registered name.

Parameters
namethe name of the directory interface
Returns
the desired directory interface

Referenced by switch_core_directory_open().

◆ switch_loadable_module_get_endpoint_interface()

switch_endpoint_interface_t* switch_loadable_module_get_endpoint_interface ( const char *  name)

Retrieve the endpoint interface by it's registered name.

Parameters
namethe name of the endpoint
Returns
the desired endpoint interface

Definition at line 2479 of file switch_loadable_module.c.

References switch_loadable_module_container::endpoint_hash, loadable_modules, switch_loadable_module_container::mutex, PROTECT_INTERFACE, switch_file_node_s::ptr, switch_core_hash_find(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by recover_callback(), switch_core_session_outgoing_channel(), and switch_core_session_request_by_name().

2480 {
2482 
2485  PROTECT_INTERFACE(ptr);
2487 
2488 
2489  return ptr;
2490 }
static struct switch_loadable_module_container loadable_modules
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
Abstraction of an module endpoint interface This is the glue between the abstract idea of a "channel"...
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 PROTECT_INTERFACE(_it)
const char *const name
Definition: switch_cJSON.h:250

◆ switch_loadable_module_get_file_interface()

switch_file_interface_t* switch_loadable_module_get_file_interface ( const char *  name,
const char *  modname 
)

Retrieve the file format interface by it's registered name.

Parameters
namethe name of the file format
Returns
the desired file format interface

Definition at line 2492 of file switch_loadable_module.c.

References switch_loadable_module_container::file_hash, switch_file_node_s::interface_name, loadable_modules, switch_loadable_module_container::mutex, switch_file_node_s::next, PROTECT_INTERFACE, switch_file_node_s::ptr, switch_core_hash_find(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_core_perform_file_open().

2493 {
2494  switch_file_interface_t *i = NULL;
2495  switch_file_node_t *node, *head;
2496 
2498 
2500  if (modname) {
2501  for (node = head; node; node = node->next) {
2502  if (!strcasecmp(node->interface_name, modname)) {
2503  i = (switch_file_interface_t *) node->ptr;
2504  break;
2505  }
2506  }
2507  } else {
2508  i = (switch_file_interface_t *) head->ptr;
2509  }
2510  }
2511 
2513 
2514  if (i) PROTECT_INTERFACE(i);
2515 
2516  return i;
2517 }
static struct switch_loadable_module_container loadable_modules
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
Abstract interface to a file format module.
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
struct switch_file_node_s * next
#define PROTECT_INTERFACE(_it)
const switch_file_interface_t * ptr
const char *const name
Definition: switch_cJSON.h:250

◆ switch_loadable_module_get_json_api_interface()

switch_json_api_interface_t* switch_loadable_module_get_json_api_interface ( const char *  name)

Retrieve the JSON API interface by it's registered name.

Parameters
namethe name of the API
Returns
the desired API interface

Referenced by switch_json_api_execute().

◆ switch_loadable_module_get_limit_interface()

switch_limit_interface_t* switch_loadable_module_get_limit_interface ( const char *  name)

Retrieve the limit interface by it's registered name.

Parameters
namethe name of the limit interface
Returns
the desired limit interface

Referenced by get_backend().

◆ switch_loadable_module_get_management_interface()

switch_management_interface_t* switch_loadable_module_get_management_interface ( const char *  relative_oid)

Retrieve the management interface by it's registered name.

Parameters
relative_oidthe relative oid of the management interface
Returns
the desired management interface

Definition at line 2601 of file switch_loadable_module.c.

References loadable_modules, switch_loadable_module_container::management_hash, switch_loadable_module_container::mutex, SWITCH_CHANNEL_LOG, switch_core_hash_find_locked(), SWITCH_LOG_ERROR, and switch_log_printf().

Referenced by switch_core_management_exec().

2602 {
2604 }
void * switch_core_hash_find_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_mutex_t *mutex)
Retrieve data from a given hash.
static struct switch_loadable_module_container loadable_modules

◆ switch_loadable_module_get_say_interface()

switch_say_interface_t* switch_loadable_module_get_say_interface ( const char *  name)

Retrieve the say interface by it's registered name.

Parameters
namethe name of the say interface
Returns
the desired say interface

Definition at line 2596 of file switch_loadable_module.c.

References loadable_modules, switch_loadable_module_container::mutex, switch_loadable_module_container::say_hash, and switch_core_hash_find_locked().

Referenced by switch_ivr_phrase_macro_event(), switch_ivr_say(), and switch_ivr_say_string().

2597 {
2599 }
void * switch_core_hash_find_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_mutex_t *mutex)
Retrieve data from a given hash.
static struct switch_loadable_module_container loadable_modules
const char *const name
Definition: switch_cJSON.h:250

◆ switch_loadable_module_get_speech_interface()

switch_speech_interface_t* switch_loadable_module_get_speech_interface ( const char *  name)

Retrieve the speech interface by it's registered name.

Parameters
namethe name of the speech interface
Returns
the desired speech interface

Referenced by switch_core_speech_open().

◆ switch_loadable_module_get_timer_interface()

switch_timer_interface_t* switch_loadable_module_get_timer_interface ( const char *  name)

Retrieve the timer interface by it's registered name.

Parameters
namethe name of the timer
Returns
the desired timer interface

Referenced by switch_core_timer_init().

◆ switch_loadable_module_init()

switch_status_t switch_loadable_module_init ( switch_bool_t  autoload)

Initilize the module backend and load all the modules.

Returns
SWITCH_STATUS_SUCCESS when complete

Definition at line 2080 of file switch_loadable_module.c.

References switch_loadable_module_container::api_hash, switch_loadable_module_container::application_hash, switch_loadable_module_container::asr_hash, switch_loadable_module_container::chat_application_hash, chat_globals, switch_loadable_module_container::chat_hash, switch_loadable_module_container::chat_rwlock, chat_thread_start(), switch_loadable_module_container::codec_hash, count, switch_loadable_module_container::database_hash, switch_loadable_module_container::dialplan_hash, switch_loadable_module_container::directory_hash, switch_loadable_module_container::endpoint_hash, switch_loadable_module_container::file_hash, switch_loadable_module_container::json_api_hash, switch_loadable_module_container::limit_hash, loadable_modules, switch_loadable_module_container::management_hash, memset(), switch_directories::mod_dir, switch_loadable_module_container::module_hash, switch_loadable_module_container::mutex, switch_xml::next, path, switch_loadable_module_container::pool, switch_loadable_module_container::say_hash, switch_loadable_module_container::secondary_recover_hash, switch_loadable_module_container::speech_hash, SWITCH_CHANNEL_LOG, switch_core_hash_destroy(), switch_core_hash_first, switch_core_hash_init, switch_core_hash_init_nocase, switch_core_hash_next(), switch_core_hash_this(), switch_core_new_memory_pool, switch_core_sqldb_init(), switch_event_fire, SWITCH_FALSE, SWITCH_GLOBAL_dirs, switch_loadable_module_load_module(), switch_loadable_module_load_module_ex(), switch_loadable_module_runtime(), SWITCH_LOADABLE_MODULE_TYPE_COMMON, SWITCH_LOADABLE_MODULE_TYPE_POSTLOAD, SWITCH_LOADABLE_MODULE_TYPE_PRELOAD, SWITCH_LOG_CONSOLE, SWITCH_LOG_CRIT, switch_log_printf(), switch_mutex_init(), SWITCH_MUTEX_NESTED, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, switch_thread_rwlock_create(), switch_true(), switch_xml_attr_soft(), switch_xml_child(), switch_xml_free(), switch_xml_open_cfg(), switch_loadable_module_container::timer_hash, and zstr.

Referenced by fs_loadable_module_init(), main(), and switch_core_init_and_modload().

2081 {
2082 
2083  fspr_finfo_t finfo = { 0 };
2084  fspr_dir_t *module_dir_handle = NULL;
2085  fspr_int32_t finfo_flags = APR_FINFO_DIRENT | APR_FINFO_TYPE | APR_FINFO_NAME;
2086  char *precf = "pre_load_modules.conf";
2087  char *cf = "modules.conf";
2088  char *pcf = "post_load_modules.conf";
2089  switch_xml_t cfg, xml;
2090  unsigned char all = 0;
2091  unsigned int count = 0;
2092  const char *err;
2093  switch_hash_t *event_hash;
2094  switch_hash_index_t *hi;
2095  void *hash_val;
2096  switch_event_t *event;
2097 
2098 
2099 #ifdef WIN32
2100  const char *ext = ".dll";
2101  const char *EXT = ".DLL";
2102 #elif defined (MACOSX) || defined (DARWIN)
2103  const char *ext = ".dylib";
2104  const char *EXT = ".DYLIB";
2105 #else
2106  const char *ext = ".so";
2107  const char *EXT = ".SO";
2108 #endif
2109 
2112 
2113 
2114 #ifdef WIN32
2115  switch_loadable_module_path_init();
2116 #endif
2117 
2139 
2140  if (!autoload) return SWITCH_STATUS_SUCCESS;
2141 
2142  /*
2143  switch_core_sqldb_init() is not yet ready and is executed after starting modules from pre_load_modules.conf
2144  Modules loading procedure generates events used by sqldb.
2145  This is why we should hold those events (storing in the event_hash) not firing them until sqldb is ready.
2146  */
2147  switch_core_hash_init(&event_hash);
2148 
2149  /*
2150  Pre-load core modules.
2151  Do not pre-load modules which may use databases,
2152  use appropriate section.
2153  */
2157 
2158  /*
2159  Loading pre-load modules.
2160  Database modules must be loaded here.
2161  */
2162  if ((xml = switch_xml_open_cfg(precf, &cfg, NULL))) {
2163  switch_xml_t mods, ld;
2164  if ((mods = switch_xml_child(cfg, "modules"))) {
2165  for (ld = switch_xml_child(mods, "load"); ld; ld = ld->next) {
2166  switch_bool_t global = SWITCH_FALSE;
2167  const char *val = switch_xml_attr_soft(ld, "module");
2168  const char *path = switch_xml_attr_soft(ld, "path");
2169  const char *critical = switch_xml_attr_soft(ld, "critical");
2170  const char *sglobal = switch_xml_attr_soft(ld, "global");
2171 
2172  if (zstr(val) || (strchr(val, '.') && !strstr(val, ext) && !strstr(val, EXT))) {
2173  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Invalid extension for %s\n", val);
2174  continue;
2175  }
2176  global = switch_true(sglobal);
2177 
2178  if (path && zstr(path)) {
2179  path = SWITCH_GLOBAL_dirs.mod_dir;
2180  }
2181  if (switch_loadable_module_load_module_ex((char *)path, (char *)val, SWITCH_FALSE, global, &err, SWITCH_LOADABLE_MODULE_TYPE_PRELOAD, event_hash) == SWITCH_STATUS_GENERR) {
2182  if (critical && switch_true(critical)) {
2183  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to load critical module '%s', abort()\n", val);
2184  switch_core_hash_destroy(&event_hash);
2185 
2186  abort();
2187  }
2188  }
2189  count++;
2190  }
2191  }
2192  switch_xml_free(xml);
2193 
2194  }
2195  else {
2196  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "open of %s failed\n", precf);
2197  }
2198 
2200  {
2201  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Loading modules interrupted. [Error: %s]\n", err);
2202  switch_core_hash_destroy(&event_hash);
2203  return SWITCH_STATUS_GENERR;
2204  }
2205 
2206  /* sqldb is ready. Fire holding events! */
2207  for (hi = switch_core_hash_first(event_hash); hi; hi = switch_core_hash_next(&hi)) {
2208  switch_core_hash_this(hi, NULL, NULL, &hash_val);
2209  event = (switch_event_t *)hash_val;
2210  switch_event_fire(&event);
2211  }
2212 
2213  switch_core_hash_destroy(&event_hash);
2214 
2215  /*
2216  To perevent locking.
2217  Core modules which may use databases should be pre-loaded here
2218  (databases are loaded already).
2219  */
2220 #ifdef SWITCH_HAVE_YUV
2221 #ifdef SWITCH_HAVE_VPX
2222  switch_loadable_module_load_module("", "CORE_VPX_MODULE", SWITCH_FALSE, &err);
2223 #endif
2224 #endif
2225 
2226  /* Loading common modules */
2227  if ((xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
2228  switch_xml_t mods, ld;
2229  if ((mods = switch_xml_child(cfg, "modules"))) {
2230  for (ld = switch_xml_child(mods, "load"); ld; ld = ld->next) {
2231  switch_bool_t global = SWITCH_FALSE;
2232  const char *val = switch_xml_attr_soft(ld, "module");
2233  const char *path = switch_xml_attr_soft(ld, "path");
2234  const char *critical = switch_xml_attr_soft(ld, "critical");
2235  const char *sglobal = switch_xml_attr_soft(ld, "global");
2236  if (zstr(val) || (strchr(val, '.') && !strstr(val, ext) && !strstr(val, EXT))) {
2237  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Invalid extension for %s\n", val);
2238  continue;
2239  }
2240  global = switch_true(sglobal);
2241 
2242  if (path && zstr(path)) {
2243  path = SWITCH_GLOBAL_dirs.mod_dir;
2244  }
2246  if (critical && switch_true(critical)) {
2247  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to load critical module '%s', abort()\n", val);
2248  abort();
2249  }
2250  }
2251  count++;
2252  }
2253  }
2254  switch_xml_free(xml);
2255 
2256  } else {
2257  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "open of %s failed\n", cf);
2258  }
2259 
2260  if ((xml = switch_xml_open_cfg(pcf, &cfg, NULL))) {
2261  switch_xml_t mods, ld;
2262 
2263  if ((mods = switch_xml_child(cfg, "modules"))) {
2264  for (ld = switch_xml_child(mods, "load"); ld; ld = ld->next) {
2265  switch_bool_t global = SWITCH_FALSE;
2266  const char *val = switch_xml_attr_soft(ld, "module");
2267  const char *path = switch_xml_attr_soft(ld, "path");
2268  const char *sglobal = switch_xml_attr_soft(ld, "global");
2269  if (zstr(val) || (strchr(val, '.') && !strstr(val, ext) && !strstr(val, EXT))) {
2270  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Invalid extension for %s\n", val);
2271  continue;
2272  }
2273  global = switch_true(sglobal);
2274 
2275  if (path && zstr(path)) {
2276  path = SWITCH_GLOBAL_dirs.mod_dir;
2277  }
2279  count++;
2280  }
2281  }
2282  switch_xml_free(xml);
2283 
2284  } else {
2285  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "open of %s failed\n", pcf);
2286  }
2287 
2288  if (!count) {
2289  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "No modules loaded, assuming 'load all'\n");
2290  all = 1;
2291  }
2292 
2293  if (all) {
2294  if (fspr_dir_open(&module_dir_handle, SWITCH_GLOBAL_dirs.mod_dir, loadable_modules.pool) != APR_SUCCESS) {
2296  return SWITCH_STATUS_GENERR;
2297  }
2298 
2299  while (fspr_dir_read(&finfo, finfo_flags, module_dir_handle) == APR_SUCCESS) {
2300  const char *fname = finfo.fname;
2301 
2302  if (finfo.filetype != APR_REG) {
2303  continue;
2304  }
2305 
2306  if (!fname) {
2307  fname = finfo.name;
2308  }
2309 
2310  if (!fname) {
2311  continue;
2312  }
2313 
2314  if (zstr(fname) || (!strstr(fname, ext) && !strstr(fname, EXT))) {
2315  continue;
2316  }
2317 
2319  }
2320  fspr_dir_close(module_dir_handle);
2321  }
2322 
2324 
2325  memset(&chat_globals, 0, sizeof(chat_globals));
2326  chat_globals.running = 1;
2329 
2330  chat_thread_start(1);
2331 
2332  return SWITCH_STATUS_SUCCESS;
2333 }
static struct switch_loadable_module_container loadable_modules
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:413
void switch_xml_free(_In_opt_ switch_xml_t xml)
frees the memory allocated for an switch_xml structure
#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
const char * switch_xml_attr_soft(_In_ switch_xml_t xml, _In_z_ const char *attr)
returns the value of the requested tag attribute, or "" if not found
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:519
#define SWITCH_CHANNEL_LOG
switch_status_t switch_core_hash_destroy(_Inout_ switch_hash_t **hash)
Destroy an existing hash table.
#define switch_core_hash_init(_hash)
Definition: switch_core.h:1431
switch_bool_t
Definition: switch_types.h:437
Representation of an event.
Definition: switch_event.h:80
A representation of an XML tree.
Definition: switch_xml.h:79
#define zstr(x)
Definition: switch_utils.h:314
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
switch_xml_t next
Definition: switch_xml.h:91
static void switch_loadable_module_runtime(void)
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
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.
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:82
switch_status_t switch_loadable_module_load_module(const char *dir, const char *fname, switch_bool_t runtime, const char **err)
Load a module.
const char *const const char *const path
switch_xml_t switch_xml_open_cfg(_In_z_ const char *file_path, _Out_ switch_xml_t *node, _In_opt_ switch_event_t *params)
open a config in the core registry
switch_xml_t switch_xml_child(_In_ switch_xml_t xml, _In_z_ const char *name)
returns the first child tag (one level deeper) with the given name or NULL \ if not found ...
static void chat_thread_start(int idx)
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.
int count
Definition: switch_cJSON.h:204
static struct @6 chat_globals
#define switch_core_hash_first(_h)
Definition: switch_core.h:1592
memset(buf, 0, buflen)
switch_status_t switch_core_sqldb_init(const char **err)
Definition: switch_core.c:2428
#define switch_core_hash_init_nocase(_hash)
Definition: switch_core.h:1432
static switch_status_t switch_loadable_module_load_module_ex(const char *dir, const char *fname, switch_bool_t runtime, switch_bool_t global, const char **err, switch_loadable_module_type_t type, switch_hash_t *event_hash)

◆ switch_loadable_module_load_module()

switch_status_t switch_loadable_module_load_module ( const char *  dir,
const char *  fname,
switch_bool_t  runtime,
const char **  err 
)

Load a module.

Parameters
dirthe directory where the module resides
fnamethe file name of the module
runtimeoption to start the runtime thread if it exists
errpointer to error message
Returns
the status

Definition at line 1779 of file switch_loadable_module.c.

References SWITCH_FALSE, switch_loadable_module_load_module_ex(), and SWITCH_LOADABLE_MODULE_TYPE_COMMON.

Referenced by main(), and switch_loadable_module_init().

1780 {
1782 }
struct switch_runtime runtime
Definition: switch_core.c:86
static switch_status_t switch_loadable_module_load_module_ex(const char *dir, const char *fname, switch_bool_t runtime, switch_bool_t global, const char **err, switch_loadable_module_type_t type, switch_hash_t *event_hash)

◆ switch_loadable_module_protect()

switch_status_t switch_loadable_module_protect ( const char *  mod)

Protect module from beeing unloaded.

Parameters
modthe module name
Returns
the status

Definition at line 1865 of file switch_loadable_module.c.

References loadable_modules, switch_loadable_module_container::module_hash, switch_loadable_module_container::mutex, switch_loadable_module::perm, switch_core_hash_find(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and zstr.

Referenced by _switch_cache_db_get_db_handle().

1866 {
1867  switch_loadable_module_t *module = NULL;
1869 
1870  if (zstr(mod)) {
1871  return SWITCH_STATUS_FALSE;
1872  }
1873 
1875  if ((module = switch_core_hash_find(loadable_modules.module_hash, mod))) {
1876  if (!module->perm) {
1877  module->perm++;
1878  }
1879  status = SWITCH_STATUS_SUCCESS;
1880  }
1881  else {
1882  status = SWITCH_STATUS_FALSE;
1883  }
1885 
1886  return status;
1887 }
static struct switch_loadable_module_container loadable_modules
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
#define zstr(x)
Definition: switch_utils.h:314
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_status_t
Common return values.

◆ switch_loadable_module_shutdown()

void switch_loadable_module_shutdown ( void  )

Shutdown the module backend and call the shutdown routine in all loaded modules.

Definition at line 2386 of file switch_loadable_module.c.

References switch_loadable_module_container::api_hash, switch_loadable_module_container::application_hash, switch_loadable_module_container::asr_hash, switch_loadable_module_container::chat_application_hash, chat_globals, switch_loadable_module_container::chat_hash, switch_loadable_module_container::codec_hash, switch_loadable_module_container::database_hash, switch_loadable_module_container::dialplan_hash, switch_loadable_module_container::directory_hash, do_shutdown(), switch_loadable_module_container::endpoint_hash, switch_loadable_module_container::file_hash, switch_loadable_module_container::json_api_hash, key, switch_loadable_module_container::limit_hash, loadable_modules, switch_loadable_module_container::management_hash, switch_loadable_module_container::module_hash, switch_loadable_module::perm, switch_loadable_module_container::pool, switch_loadable_module_container::say_hash, switch_loadable_module_container::secondary_recover_hash, switch_loadable_module_container::speech_hash, switch_core_destroy_memory_pool, switch_core_hash_delete(), switch_core_hash_destroy(), switch_core_hash_first, switch_core_hash_next(), switch_core_hash_this(), switch_core_sqldb_destroy(), SWITCH_FALSE, SWITCH_LOADABLE_MODULE_TYPE_PRELOAD, switch_queue_push(), SWITCH_STATUS_SUCCESS, switch_thread_join(), SWITCH_TRUE, switch_yield, switch_loadable_module_container::timer_hash, and switch_loadable_module::type.

Referenced by fs_loadable_module_shutdown(), and switch_core_destroy().

2387 {
2388  switch_hash_index_t *hi;
2389  void *val;
2390  const void *key;
2391  switch_loadable_module_t *module;
2392  int i;
2393 
2395  return;
2396  }
2397 
2398  chat_globals.running = 0;
2399 
2400  for (i = 0; i < chat_globals.msg_queue_len; i++) {
2401  switch_queue_push(chat_globals.msg_queue[i], NULL);
2402  }
2403 
2404  for (i = 0; i < chat_globals.msg_queue_len; i++) {
2405  switch_status_t st;
2406  switch_thread_join(&st, chat_globals.msg_queue_thread[i]);
2407  }
2408 
2409 
2411  switch_core_hash_this(hi, NULL, NULL, &val);
2412  module = (switch_loadable_module_t *)val;
2413  if (module->type != SWITCH_LOADABLE_MODULE_TYPE_PRELOAD && !module->perm) {
2415  }
2416  }
2417 
2418  switch_yield(1000000);
2419 
2421  switch_core_hash_this(hi, &key, NULL, &val);
2422  module = (switch_loadable_module_t *)val;
2423 
2424  hi = switch_core_hash_next(&hi);
2425 
2426  if (module->type != SWITCH_LOADABLE_MODULE_TYPE_PRELOAD && !module->perm) {
2428  {
2430  }
2431  }
2432  }
2433 
2435 
2437  switch_core_hash_this(hi, NULL, NULL, &val);
2438  if ((module = (switch_loadable_module_t *)val)) {
2439  if (module->type == SWITCH_LOADABLE_MODULE_TYPE_PRELOAD && !module->perm) {
2441  }
2442  }
2443  }
2444 
2445  switch_yield(1000000);
2446 
2448  switch_core_hash_this(hi, NULL, NULL, &val);
2449  if ((module = (switch_loadable_module_t *)val)) {
2450  if (module->type == SWITCH_LOADABLE_MODULE_TYPE_PRELOAD && !module->perm) {
2452  }
2453  }
2454  }
2455 
2475 
2477 }
static struct switch_loadable_module_container loadable_modules
switch_status_t switch_core_hash_destroy(_Inout_ switch_hash_t **hash)
Destroy an existing hash table.
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:642
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
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_hash_delete(_In_ switch_hash_t *hash, _In_z_ const char *key)
Delete data from a hash based on desired key.
switch_loadable_module_type_t type
switch_status_t
Common return values.
char * key
Definition: switch_msrp.c:64
switch_status_t switch_queue_push(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1253
static struct @6 chat_globals
#define switch_core_hash_first(_h)
Definition: switch_core.h:1592
static switch_status_t do_shutdown(switch_loadable_module_t *module, switch_bool_t shutdown, switch_bool_t unload, switch_bool_t fail_if_busy, const char **err)
void switch_core_sqldb_destroy(void)
Definition: switch_core.c:3013

◆ switch_loadable_module_unload_module()

switch_status_t switch_loadable_module_unload_module ( const char *  dir,
const char *  fname,
switch_bool_t  force,
const char **  err 
)

Unoad a module.

Parameters
dirthe directory where the module resides
fnamethe file name of the module
errpointer to error message
Returns
the status

Definition at line 1889 of file switch_loadable_module.c.

References do_shutdown(), loadable_modules, switch_loadable_module_container::module_hash, switch_loadable_module_container::mutex, switch_loadable_module::perm, SWITCH_CHANNEL_LOG, switch_core_hash_delete(), switch_core_hash_find(), switch_core_hash_insert_locked(), SWITCH_LOG_CRIT, switch_log_printf(), SWITCH_LOG_WARNING, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, SWITCH_STATUS_NOUNLOAD, SWITCH_STATUS_SUCCESS, SWITCH_TRUE, and switch_yield.

1890 {
1891  switch_loadable_module_t *module = NULL;
1893 
1894  if (force) {
1895  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Spin the barrel and pull the trigger.......!\n");
1896  }
1897 
1899  if ((module = switch_core_hash_find(loadable_modules.module_hash, fname))) {
1900  if (module->perm) {
1901  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Module is not unloadable.\n");
1902  *err = "Module is not unloadable";
1903  status = SWITCH_STATUS_NOUNLOAD;
1904  goto unlock;
1905  } else {
1906  /* Prevent anything from using the module while it's shutting down */
1909  if ((status = do_shutdown(module, SWITCH_TRUE, SWITCH_TRUE, !force, err)) != SWITCH_STATUS_SUCCESS) {
1910  /* Something went wrong in the module's shutdown function, add it again */
1912  }
1913  goto end;
1914  }
1915  } else {
1916  *err = "No such module!";
1917  status = SWITCH_STATUS_FALSE;
1918  }
1919 unlock:
1921  end:
1922  if (force) {
1923  switch_yield(1000000);
1925  }
1926 
1927  return status;
1928 
1929 }
static struct switch_loadable_module_container loadable_modules
#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.
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
switch_status_t switch_core_hash_insert_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ const void *data, _In_opt_ switch_mutex_t *mutex)
Insert data into a hash.
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
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.
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 switch_status_t do_shutdown(switch_loadable_module_t *module, switch_bool_t shutdown, switch_bool_t unload, switch_bool_t fail_if_busy, const char **err)

◆ SWITCH_MOD_DECLARE()

SWITCH_MOD_DECLARE ( switch_status_t  )

Load a module.

Shutdown a module.

Parameters
module_interfacea pointer to a pointer to aim at your module's local interface
filenamethe path to the module's dll or so file
Returns
SWITCH_STATUS_SUCCESS on a successful load
SWITCH_STATUS_SUCCESS on a successful shutdown

◆ switch_parse_codec_buf()

char* switch_parse_codec_buf ( char *  buf,
uint32_t *  interval,
uint32_t *  rate,
uint32_t *  bit,
uint32_t *  channels,
char **  modname,
char **  fmtp 
)

Definition at line 2746 of file switch_loadable_module.c.

References buf, cur, name, switch_file_node_s::next, SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, and switch_log_printf().

Referenced by switch_loadable_module_get_codecs_sorted().

2747 {
2748  char *cur, *next = NULL, *name, *p;
2749 
2750  name = next = cur = buf;
2751 
2752  *channels = 1;
2753 
2754  for (;;) {
2755  if (!next) {
2756  break;
2757  }
2758 
2759  if ((p = strchr(next, '@'))) {
2760  *p++ = '\0';
2761  }
2762  next = p;
2763 
2764  if (cur != name) {
2765  if (strchr(cur, 'i')) {
2766  *interval = atoi(cur);
2767  } else if ((strchr(cur, 'k') || strchr(cur, 'h'))) {
2768  *rate = atoi(cur);
2769  } else if (strchr(cur, 'b')) {
2770  *bit = atoi(cur);
2771  } else if (strchr(cur, 'c')) {
2772  *channels = atoi(cur);
2773  } else {
2774  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Bad syntax for codec string. Missing qualifier [h|k|i|b|c] for part [%s]!\n", cur);
2775  }
2776  }
2777  cur = next;
2778  }
2779 
2780  if ((p = strchr(name, '.'))) {
2781  *p++ = '\0';
2782  *modname = name;
2783  name = p;
2784  }
2785 
2786  if ((p = strchr(name, '~'))) {
2787  *p++ = '\0';
2788  if (fmtp) {
2789  *fmtp = p;
2790  }
2791  }
2792 
2793  return name;
2794 }
#define SWITCH_CHANNEL_LOG
pack cur
switch_byte_t switch_byte_t * buf
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.
const char *const name
Definition: switch_cJSON.h:250

Variable Documentation

◆ filename

const char* filename