FreeSWITCH API Documentation  1.7.0
Data Structures | Macros | 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)
 

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)
 
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_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, 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 (char *dir, 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_unload_module (char *dir, 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

char * filename
 

Detailed Description

Macro Definition Documentation

#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 340 of file switch_loadable_module.h.

#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 368 of file switch_loadable_module.h.

#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 360 of file switch_loadable_module.h.

#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 380 of file switch_loadable_module.h.

#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:729
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 415 of file switch_loadable_module.h.

Referenced by mod_g711_load(), and SWITCH_MODULE_LOAD_FUNCTION().

#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 392 of file switch_loadable_module.h.

#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 350 of file switch_loadable_module.h.

#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 400 of file switch_loadable_module.h.

Function Documentation

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 2520 of file switch_loadable_module.c.

References switch_api_interface::function, 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(), and UNPROTECT_INTERFACE.

Referenced by api_hook(), do_api_on(), API::execute(), API::executeString(), record_callback(), switch_channel_expand_variables_check(), switch_console_execute(), switch_event_expand_headers_check(), switch_ivr_record_file(), switch_nat_republish(), and switch_nat_status().

2521 {
2523  switch_status_t status;
2524  char *arg_used;
2525  char *cmd_used;
2526 
2527  switch_assert(stream != NULL);
2528  switch_assert(stream->data != NULL);
2529  switch_assert(stream->write_function != NULL);
2530 
2531  if (strcasecmp(cmd, "console_complete")) {
2532  cmd_used = switch_strip_whitespace(cmd);
2533  arg_used = switch_strip_whitespace(arg);
2534  } else {
2535  cmd_used = (char *) cmd;
2536  arg_used = (char *) arg;
2537  }
2538 
2539 
2540  if (!stream->param_event) {
2542  }
2543 
2544  if (stream->param_event) {
2545  if (cmd_used && *cmd_used) {
2546  switch_event_add_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "API-Command", cmd_used);
2547  }
2548  if (arg_used && *arg_used) {
2549  switch_event_add_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "API-Command-Argument", arg_used);
2550  }
2551  }
2552 
2553 
2554  if (cmd_used && (api = switch_loadable_module_get_api_interface(cmd_used)) != 0) {
2555  if ((status = api->function(arg_used, session, stream)) != SWITCH_STATUS_SUCCESS) {
2556  stream->write_function(stream, "COMMAND RETURNED ERROR!\n");
2557  }
2558  UNPROTECT_INTERFACE(api);
2559  } else {
2560  status = SWITCH_STATUS_FALSE;
2561  stream->write_function(stream, "INVALID COMMAND!\n");
2562  }
2563 
2564  if (stream->param_event) {
2565  switch_event_fire(&stream->param_event);
2566  }
2567 
2568  if (cmd_used != cmd) {
2569  switch_safe_free(cmd_used);
2570  }
2571 
2572  if (arg_used != arg) {
2573  switch_safe_free(arg_used);
2574  }
2575 
2576  return status;
2577 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:412
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:789
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:383
#define switch_assert(expr)
static int switch_check_interval ( uint32_t  rate,
uint32_t  ptime 
)
inlinestatic

Definition at line 424 of file switch_loadable_module.h.

References SWITCH_RECOMMENDED_BUFFER_SIZE.

Referenced by switch_core_codec_add_implementation().

425 {
426  uint32_t max_ms = 0, ptime_div = 0;
427 
428  switch (rate) {
429  case 22050:
430  case 11025:
431  if (ptime < 120)
432  return 1;
433  break;
434  case 48000:
435  max_ms = 40;
436  ptime_div = 2;
437  break;
438  case 44100:
439  max_ms = 40;
440  ptime_div = 2;
441  break;
442  case 32000:
443  case 24000:
444  case 16000:
445  max_ms = 60;
446  ptime_div = 2;
447  break;
448  case 12000:
449  max_ms = 100;
450  ptime_div = 2;
451  break;
452  case 8000:
453  max_ms = 120;
454  ptime_div = 2;
455  break;
456  }
457 
458  if (max_ms && ptime_div && (ptime <= max_ms && (ptime % ptime_div) == 0) && ((rate / 1000) * ptime) < SWITCH_RECOMMENDED_BUFFER_SIZE) {
459  return 1;
460  }
461 
462  return 0;
463 }
#define SWITCH_RECOMMENDED_BUFFER_SIZE
Definition: switch_types.h:557
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 465 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().

500 {
501 
502  if (decoded_bytes_per_packet > SWITCH_RECOMMENDED_BUFFER_SIZE) {
503  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",
504  iananame, actual_samples_per_second, microseconds_per_packet / 1000, number_of_channels, decoded_bytes_per_packet, SWITCH_RECOMMENDED_BUFFER_SIZE);
505  } else if (codec_type == SWITCH_CODEC_TYPE_VIDEO || switch_check_interval(actual_samples_per_second, microseconds_per_packet / 1000)) {
507  impl->codec_type = codec_type;
508  impl->ianacode = ianacode;
509  impl->iananame = switch_core_strdup(pool, iananame);
510  impl->fmtp = switch_core_strdup(pool, fmtp);
511  impl->samples_per_second = samples_per_second;
512  impl->actual_samples_per_second = actual_samples_per_second;
513  impl->bits_per_second = bits_per_second;
514  impl->microseconds_per_packet = microseconds_per_packet;
515  impl->samples_per_packet = samples_per_packet;
516  impl->decoded_bytes_per_packet = decoded_bytes_per_packet;
517  impl->encoded_bytes_per_packet = encoded_bytes_per_packet;
518  impl->number_of_channels = number_of_channels;
519  impl->codec_frames_per_packet = codec_frames_per_packet;
520  impl->init = init;
521  impl->encode = encode;
522  impl->decode = decode;
523  impl->destroy = destroy;
524  impl->codec_id = codec_interface->codec_id;
525  impl->next = codec_interface->implementations;
527  impl->modname = codec_interface->modname;
528  codec_interface->implementations = impl;
529  } else {
530  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Rejected codec name: %s rate: %u ptime: %d channels: %d\n",
531  iananame, actual_samples_per_second, microseconds_per_packet / 1000, number_of_channels);
532  }
533 }
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:557
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:729
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:682
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.
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_status_t switch_core_execute_chat_app ( switch_event_t message,
const char *  app,
const char *  data 
)

Definition at line 820 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().

821 {
824  char *expanded;
825 
827  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid chat application interface [%s]!\n", app);
828  return SWITCH_STATUS_FALSE;
829  }
830 
831  if (switch_test_flag(message, EF_NO_CHAT_EXEC)) {
832  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Message is not allowed to execute apps\n");
834  }
835 
836  if (data && !strcmp(data, "__undef")) {
837  data = NULL;
838  }
839 
840  expanded = switch_event_expand_headers(message, data);
841 
842  status = cai->chat_application_function(message, expanded);
843 
844  if (expanded != data) {
845  free(expanded);
846  }
847 
848  end:
849 
850  UNPROTECT_INTERFACE(cai);
851 
852  return status;
853 
854 }
#define switch_event_expand_headers(_event, _in)
Definition: switch_event.h:354
#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's registered name.
#define switch_goto_status(_status, _label)
Definition: switch_utils.h:256
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
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_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 2579 of file switch_loadable_module.c.

References cJSON_AddItemToObject(), cJSON_CreateNull(), cJSON_CreateString(), cJSON_GetObjectItem(), switch_json_api_interface::function, switch_assert, switch_loadable_module_get_json_api_interface(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and UNPROTECT_INTERFACE.

2580 {
2581  switch_json_api_interface_t *json_api;
2582  switch_status_t status;
2583  cJSON *function, *json_reply = NULL;
2584 
2585  switch_assert(json);
2586 
2587  function = cJSON_GetObjectItem(json, "command");
2588 
2589  if (function && function->valuestring
2590  && cJSON_GetObjectItem(json, "data") && (json_api = switch_loadable_module_get_json_api_interface(function->valuestring)) != 0) {
2591  if ((status = json_api->function(json, session, &json_reply)) != SWITCH_STATUS_SUCCESS) {
2592  cJSON_AddItemToObject(json, "status", cJSON_CreateString("error"));
2593  cJSON_AddItemToObject(json, "message", cJSON_CreateString("The command returned an error"));
2594  } else {
2595  cJSON_AddItemToObject(json, "status", cJSON_CreateString("success"));
2596  }
2597 
2598  if (!json_reply) {
2599  json_reply = cJSON_CreateNull();
2600  }
2601 
2602  if (retval) {
2603  *retval = json_reply;
2604  } else {
2605  cJSON_AddItemToObject(json, "response", json_reply);
2606  }
2607 
2608  UNPROTECT_INTERFACE(json_api);
2609  } else {
2610  status = SWITCH_STATUS_FALSE;
2611  cJSON_AddItemToObject(json, "status", cJSON_CreateString("error"));
2612  cJSON_AddItemToObject(json, "message", cJSON_CreateString("Invalid request or non-existant command"));
2613  cJSON_AddItemToObject(json, "response", cJSON_CreateNull());
2614  }
2615 
2616  return status;
2617 }
cJSON * cJSON_CreateNull(void)
Definition: switch_json.c:537
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.
#define UNPROTECT_INTERFACE(_it)
void cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item)
Definition: switch_json.c:520
cJSON * cJSON_GetObjectItem(const cJSON *object, const char *string)
Definition: switch_json.c:498
cJSON * cJSON_CreateString(const char *string)
Definition: switch_json.c:542
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_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 1727 of file switch_loadable_module.c.

References switch_loadable_module::filename, switch_loadable_module::module_interface, switch_loadable_module_interface::module_name, switch_loadable_module::perm, switch_loadable_module::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.

1731 {
1732  switch_loadable_module_t *module = NULL;
1733  switch_module_load_t load_func_ptr = NULL;
1734  int loading = 1;
1735  const char *err = NULL;
1736  switch_loadable_module_interface_t *module_interface = NULL;
1738 
1739 
1742  abort();
1743  }
1744 
1745  if ((module = switch_core_alloc(pool, sizeof(switch_loadable_module_t))) == 0) {
1746  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Couldn't allocate memory\n");
1747  abort();
1748  }
1749 
1750 
1751 
1752  while (loading) {
1753  switch_status_t status;
1754  load_func_ptr = (switch_module_load_t) switch_module_load;
1755 
1756  if (load_func_ptr == NULL) {
1757  err = "Cannot Load";
1758  break;
1759  }
1760 
1761  status = load_func_ptr(&module_interface, pool);
1762 
1763  if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_NOUNLOAD) {
1764  err = "Module load routine returned an error";
1765  module_interface = NULL;
1766  break;
1767  }
1768 
1769  if ((module = switch_core_alloc(pool, sizeof(switch_loadable_module_t))) == 0) {
1770  err = "Could not allocate memory\n";
1771  abort();
1772  }
1773 
1774  if (status == SWITCH_STATUS_NOUNLOAD) {
1775  module->perm++;
1776  }
1777 
1778  loading = 0;
1779  }
1780 
1781  if (err) {
1783  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Error Loading module %s\n**%s**\n", filename, err);
1784  return SWITCH_STATUS_GENERR;
1785  }
1786 
1787  module->pool = pool;
1788  module->filename = switch_core_strdup(module->pool, filename);
1789  module->module_interface = module_interface;
1790  module->switch_module_load = load_func_ptr;
1791 
1792  if (switch_module_shutdown) {
1793  module->switch_module_shutdown = switch_module_shutdown;
1794  }
1795  if (switch_module_runtime) {
1796  module->switch_module_runtime = switch_module_runtime;
1797  }
1798  if (runtime && module->switch_module_runtime) {
1800  }
1801  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Successfully Loaded [%s]\n", module_interface->module_name);
1802  return switch_loadable_module_process((char *) module->filename, module);
1803 }
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
Definition: switch_core.h:631
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:729
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:640
struct switch_runtime runtime
Definition: switch_core.c:64
switch_memory_pool_t * pool
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:682
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.
static void *SWITCH_THREAD_FUNC switch_loadable_module_exec(switch_thread_t *thread, void *obj)
switch_module_runtime_t switch_module_runtime
struct apr_pool_t switch_memory_pool_t
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.
char * filename
static switch_status_t switch_loadable_module_process(char *key, switch_loadable_module_t *new_module)
switch_module_shutdown_t switch_module_shutdown
The abstraction of a loadable module.
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 1671 of file switch_loadable_module.c.

References 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().

1672 {
1673  switch_dir_t *dir = NULL;
1674  switch_status_t status;
1675  char buffer[256];
1676  const char *fname;
1677  const char *fname_ext;
1678  char *fname_base;
1679 
1680 #ifdef WIN32
1681  const char *ext = ".dll";
1682 #else
1683  const char *ext = ".so";
1684 #endif
1685 
1686  if ((status = switch_dir_open(&dir, dir_path, loadable_modules.pool)) != SWITCH_STATUS_SUCCESS) {
1687  return status;
1688  }
1689 
1690  while((fname = switch_dir_next_file(dir, buffer, sizeof(buffer)))) {
1691  if ((fname_ext = strrchr(fname, '.'))) {
1692  if (!strcmp(fname_ext, ext)) {
1693  if (!(fname_base = switch_mprintf("%.*s", (int)(fname_ext-fname), fname))) {
1694  status = SWITCH_STATUS_GENERR;
1695  goto end;
1696  }
1697  callback(user_data, fname_base);
1698  switch_safe_free(fname_base)
1699  }
1700  }
1701  }
1702 
1703 
1704  end:
1705  switch_dir_close(dir);
1706  return status;
1707 }
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:789
switch_status_t switch_dir_open(switch_dir_t **new_dir, const char *dirname, switch_memory_pool_t *pool)
Definition: switch_apr.c:538
const char * switch_dir_next_file(switch_dir_t *thedir, char *buf, switch_size_t len)
Definition: switch_apr.c:595
switch_status_t
Common return values.
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
switch_status_t switch_dir_close(switch_dir_t *thedir)
Definition: switch_apr.c:559
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 1709 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().

1710 {
1711  switch_hash_index_t *hi;
1712  void *val;
1713  switch_loadable_module_t *module;
1714 
1717  switch_core_hash_this(hi, NULL, NULL, &val);
1718  module = (switch_loadable_module_t *) val;
1719 
1720  callback(user_data, module->module_interface->module_name);
1721  }
1723 
1724  return SWITCH_STATUS_SUCCESS;
1725 }
static struct switch_loadable_module_container loadable_modules
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
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:1501
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 1610 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.

1611 {
1612  switch_status_t status;
1613 
1614  if (zstr(mod)) {
1615  return SWITCH_STATUS_FALSE;
1616  }
1617 
1620  status = SWITCH_STATUS_SUCCESS;
1621  } else {
1622  status = SWITCH_STATUS_FALSE;
1623  }
1625 
1626  return status;
1627 }
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:281
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_status_t
Common return values.
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_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_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_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_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_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 2148 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().

2149 {
2150  switch_codec_interface_t *codec = NULL;
2151  switch_codec_node_t *node, *head;
2152 
2154 
2155  if ((head = switch_core_hash_find(loadable_modules.codec_hash, name))) {
2156  if (modname) {
2157  for (node = head; node; node = node->next) {
2158  if (!strcasecmp(node->interface_name, modname)) {
2159  codec = (switch_codec_interface_t *) node->ptr;
2160  break;
2161  }
2162  }
2163  } else {
2164  codec = (switch_codec_interface_t *) head->ptr;
2165  }
2166  }
2167 
2169 
2170  if (codec) {
2171  PROTECT_INTERFACE(codec);
2172  }
2173 
2174  return codec;
2175 }
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:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
Top level module interface to implement a series of codec implementations.
struct switch_codec_node_s * next
#define PROTECT_INTERFACE(_it)
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 2296 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().

2297 {
2298  switch_hash_index_t *hi;
2299  void *val;
2300  switch_codec_interface_t *codec_interface;
2301  int i = 0;
2302  const switch_codec_implementation_t *imp;
2303  switch_codec_node_t *node, *head;
2304 
2307  switch_core_hash_this(hi, NULL, NULL, &val);
2308  head = (switch_codec_node_t *) val;
2309 
2310  for (node = head; node; node = node->next) {
2311  codec_interface = (switch_codec_interface_t *) node->ptr;
2312 
2313  /* Look for the default ptime of the codec because it's the safest choice */
2314  for (imp = codec_interface->implementations; imp; imp = imp->next) {
2315  uint32_t default_ptime = switch_default_ptime(imp->iananame, imp->ianacode);
2316 
2317  if (imp->microseconds_per_packet / 1000 == (int)default_ptime) {
2318  array[i++] = imp;
2319  goto found;
2320  }
2321  }
2322  /* oh well we will use what we have */
2323  array[i++] = codec_interface->implementations;
2324  }
2325 
2326  found:
2327 
2328  if (i > arraylen) {
2329  break;
2330  }
2331 
2332  }
2333  switch_safe_free(hi);
2334 
2336 
2338 
2339  return i;
2340 
2341 }
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:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
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:2026
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:1501
int switch_loadable_module_get_codecs_sorted ( const switch_codec_implementation_t **  array,
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 2386 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, 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(), and UNPROTECT_INTERFACE.

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().

2387 {
2388  int x, i = 0, j = 0;
2389  switch_codec_interface_t *codec_interface;
2390  const switch_codec_implementation_t *imp;
2391 
2393 
2394  for (x = 0; x < preflen; x++) {
2395  char *name, buf[256], jbuf[256], *modname = NULL;
2396  uint32_t interval = 0, rate = 0, bit = 0, channels = 1;
2397 
2398  switch_copy_string(buf, prefs[x], sizeof(buf));
2399  name = switch_parse_codec_buf(buf, &interval, &rate, &bit, &channels, &modname);
2400 
2401  for(j = 0; j < x; j++) {
2402  char *jname, *jmodname = NULL;
2403  uint32_t jinterval = 0, jrate = 0, jbit = 0, jchannels = 1;
2404  uint32_t ointerval = interval, orate = rate, ochannels = channels;
2405 
2406  if (ointerval == 0) {
2407  ointerval = switch_default_ptime(name, 0);
2408  }
2409 
2410  if (orate == 0) {
2411  orate = switch_default_rate(name, 0);
2412  }
2413 
2414  if (ochannels == 0) {
2415  ochannels = 1;
2416  }
2417 
2418  switch_copy_string(jbuf, prefs[j], sizeof(jbuf));
2419  jname = switch_parse_codec_buf(jbuf, &jinterval, &jrate, &jbit, &jchannels, &jmodname);
2420 
2421  if (jinterval == 0) {
2422  jinterval = switch_default_ptime(jname, 0);
2423  }
2424 
2425  if (jrate == 0) {
2426  jrate = switch_default_rate(jname, 0);
2427  }
2428 
2429  if (jchannels == 0) {
2430  jchannels = 1;
2431  }
2432 
2433  if (!strcasecmp(name, jname) && ointerval == jinterval && orate == jrate && ochannels == jchannels) {
2434  goto next_x;
2435  }
2436  }
2437 
2438  if ((codec_interface = switch_loadable_module_get_codec_interface(name, modname)) != 0) {
2439  /* If no specific codec interval is requested opt for the default above all else because lots of stuff assumes it */
2440  for (imp = codec_interface->implementations; imp; imp = imp->next) {
2441  uint32_t default_ptime = switch_default_ptime(imp->iananame, imp->ianacode);
2442  uint32_t default_rate = switch_default_rate(imp->iananame, imp->ianacode);
2443 
2444  if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) {
2445  uint32_t crate = !strcasecmp(imp->iananame, "g722") ? imp->samples_per_second : imp->actual_samples_per_second;
2446 
2447  if ((!interval && (uint32_t) (imp->microseconds_per_packet / 1000) != default_ptime) ||
2448  (interval && (uint32_t) (imp->microseconds_per_packet / 1000) != interval)) {
2449  continue;
2450  }
2451 
2452  if (((!rate && crate != default_rate) || (rate && (uint32_t) imp->actual_samples_per_second != rate))) {
2453  continue;
2454  }
2455 
2456  if (bit && (uint32_t) imp->bits_per_second != bit) {
2457  continue;
2458  }
2459 
2460  if (channels && imp->number_of_channels != channels) {
2461  continue;
2462  }
2463  }
2464 
2465 
2466  array[i++] = imp;
2467  goto found;
2468 
2469  }
2470 
2471  /* Either looking for a specific interval or there was no interval specified and there wasn't one at the default ptime available */
2472  for (imp = codec_interface->implementations; imp; imp = imp->next) {
2473  if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) {
2474  uint32_t crate = !strcasecmp(imp->iananame, "g722") ? imp->samples_per_second : imp->actual_samples_per_second;
2475 
2476  if (interval && (uint32_t) (imp->microseconds_per_packet / 1000) != interval) {
2477  continue;
2478  }
2479 
2480  if (rate && (uint32_t) crate != rate) {
2481  continue;
2482  }
2483 
2484  if (bit && (uint32_t) imp->bits_per_second != bit) {
2485  continue;
2486  }
2487 
2488  if (channels && imp->number_of_channels != channels) {
2489  continue;
2490  }
2491  }
2492 
2493  array[i++] = imp;
2494  goto found;
2495 
2496  }
2497 
2498  found:
2499 
2500  UNPROTECT_INTERFACE(codec_interface);
2501 
2502  if (i > arraylen) {
2503  break;
2504  }
2505 
2506  }
2507 
2508  next_x:
2509 
2510  continue;
2511  }
2512 
2514 
2516 
2517  return i;
2518 }
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)
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
#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:285
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:2026
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's registered name.
struct switch_codec_implementation * next
A table of settings and callbacks that define a paticular implementation of a codec.
char * switch_parse_codec_buf(char *buf, uint32_t *interval, uint32_t *rate, uint32_t *bit, uint32_t *channels, char **modname)
uint32_t switch_default_rate(const char *name, uint32_t number)
Definition: switch_core.c:2037
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_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_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 2106 of file switch_loadable_module.c.

References switch_loadable_module_container::endpoint_hash, loadable_modules, switch_loadable_module_container::mutex, PROTECT_INTERFACE, 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().

2107 {
2109 
2112  if (ptr) {
2113  PROTECT_INTERFACE(ptr);
2114  }
2116 
2117 
2118  return ptr;
2119 }
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:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
#define PROTECT_INTERFACE(_it)
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 2121 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().

2122 {
2123  switch_file_interface_t *i = NULL;
2124  switch_file_node_t *node, *head;
2125 
2127 
2128  if ((head = switch_core_hash_find(loadable_modules.file_hash, name))) {
2129  if (modname) {
2130  for (node = head; node; node = node->next) {
2131  if (!strcasecmp(node->interface_name, modname)) {
2132  i = (switch_file_interface_t *) node->ptr;
2133  break;
2134  }
2135  }
2136  } else {
2137  i = (switch_file_interface_t *) head->ptr;
2138  }
2139  }
2140 
2142 
2143  if (i) PROTECT_INTERFACE(i);
2144 
2145  return i;
2146 }
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:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
struct switch_file_node_s * next
#define PROTECT_INTERFACE(_it)
const switch_file_interface_t * ptr
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_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_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 2204 of file switch_loadable_module.c.

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

Referenced by switch_core_management_exec().

2205 {
2207 }
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_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 2199 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().

2200 {
2202 }
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_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_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_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 1821 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, chat_thread_start(), switch_loadable_module_container::codec_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, 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_init, switch_core_hash_init_nocase, switch_core_new_memory_pool, SWITCH_FALSE, SWITCH_GLOBAL_dirs, switch_loadable_module_load_module(), switch_loadable_module_load_module_ex(), switch_loadable_module_runtime(), SWITCH_LOG_CONSOLE, SWITCH_LOG_CRIT, switch_log_printf(), switch_mutex_init(), SWITCH_MUTEX_NESTED, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, 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().

1822 {
1823 
1824  apr_finfo_t finfo = { 0 };
1825  apr_dir_t *module_dir_handle = NULL;
1826  apr_int32_t finfo_flags = APR_FINFO_DIRENT | APR_FINFO_TYPE | APR_FINFO_NAME;
1827  char *cf = "modules.conf";
1828  char *pcf = "post_load_modules.conf";
1829  switch_xml_t cfg, xml;
1830  unsigned char all = 0;
1831  unsigned int count = 0;
1832  const char *err;
1833 
1834 
1835 #ifdef WIN32
1836  const char *ext = ".dll";
1837  const char *EXT = ".DLL";
1838 #elif defined (MACOSX) || defined (DARWIN)
1839  const char *ext = ".dylib";
1840  const char *EXT = ".DYLIB";
1841 #else
1842  const char *ext = ".so";
1843  const char *EXT = ".SO";
1844 #endif
1845 
1848 
1849 
1850 #ifdef WIN32
1851  switch_loadable_module_path_init();
1852 #endif
1853 
1873 
1874  if (!autoload) return SWITCH_STATUS_SUCCESS;
1875 
1876  switch_loadable_module_load_module("", "CORE_SOFTTIMER_MODULE", SWITCH_FALSE, &err);
1877  switch_loadable_module_load_module("", "CORE_PCM_MODULE", SWITCH_FALSE, &err);
1878  switch_loadable_module_load_module("", "CORE_SPEEX_MODULE", SWITCH_FALSE, &err);
1879 #ifdef SWITCH_HAVE_YUV
1880 #ifdef SWITCH_HAVE_VPX
1881  switch_loadable_module_load_module("", "CORE_VPX_MODULE", SWITCH_FALSE, &err);
1882 #endif
1883 #endif
1884 
1885  if ((xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
1886  switch_xml_t mods, ld;
1887  if ((mods = switch_xml_child(cfg, "modules"))) {
1888  for (ld = switch_xml_child(mods, "load"); ld; ld = ld->next) {
1889  switch_bool_t global = SWITCH_FALSE;
1890  const char *val = switch_xml_attr_soft(ld, "module");
1891  const char *path = switch_xml_attr_soft(ld, "path");
1892  const char *critical = switch_xml_attr_soft(ld, "critical");
1893  const char *sglobal = switch_xml_attr_soft(ld, "global");
1894  if (zstr(val) || (strchr(val, '.') && !strstr(val, ext) && !strstr(val, EXT))) {
1895  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Invalid extension for %s\n", val);
1896  continue;
1897  }
1898  global = switch_true(sglobal);
1899 
1900  if (path && zstr(path)) {
1901  path = SWITCH_GLOBAL_dirs.mod_dir;
1902  }
1903  if (switch_loadable_module_load_module_ex((char *) path, (char *) val, SWITCH_FALSE, global, &err) == SWITCH_STATUS_GENERR) {
1904  if (critical && switch_true(critical)) {
1905  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to load critical module '%s', abort()\n", val);
1906  abort();
1907  }
1908  }
1909  count++;
1910  }
1911  }
1912  switch_xml_free(xml);
1913 
1914  } else {
1915  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "open of %s failed\n", cf);
1916  }
1917 
1918  if ((xml = switch_xml_open_cfg(pcf, &cfg, NULL))) {
1919  switch_xml_t mods, ld;
1920 
1921  if ((mods = switch_xml_child(cfg, "modules"))) {
1922  for (ld = switch_xml_child(mods, "load"); ld; ld = ld->next) {
1923  switch_bool_t global = SWITCH_FALSE;
1924  const char *val = switch_xml_attr_soft(ld, "module");
1925  const char *path = switch_xml_attr_soft(ld, "path");
1926  const char *sglobal = switch_xml_attr_soft(ld, "global");
1927  if (zstr(val) || (strchr(val, '.') && !strstr(val, ext) && !strstr(val, EXT))) {
1928  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Invalid extension for %s\n", val);
1929  continue;
1930  }
1931  global = switch_true(sglobal);
1932 
1933  if (path && zstr(path)) {
1934  path = SWITCH_GLOBAL_dirs.mod_dir;
1935  }
1936  switch_loadable_module_load_module_ex((char *) path, (char *) val, SWITCH_FALSE, global, &err);
1937  count++;
1938  }
1939  }
1940  switch_xml_free(xml);
1941 
1942  } else {
1943  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "open of %s failed\n", pcf);
1944  }
1945 
1946  if (!count) {
1947  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "No modules loaded, assuming 'load all'\n");
1948  all = 1;
1949  }
1950 
1951  if (all) {
1952  if (apr_dir_open(&module_dir_handle, SWITCH_GLOBAL_dirs.mod_dir, loadable_modules.pool) != APR_SUCCESS) {
1954  return SWITCH_STATUS_GENERR;
1955  }
1956 
1957  while (apr_dir_read(&finfo, finfo_flags, module_dir_handle) == APR_SUCCESS) {
1958  const char *fname = finfo.fname;
1959 
1960  if (finfo.filetype != APR_REG) {
1961  continue;
1962  }
1963 
1964  if (!fname) {
1965  fname = finfo.name;
1966  }
1967 
1968  if (!fname) {
1969  continue;
1970  }
1971 
1972  if (zstr(fname) || (!strstr(fname, ext) && !strstr(fname, EXT))) {
1973  continue;
1974  }
1975 
1977  }
1978  apr_dir_close(module_dir_handle);
1979  }
1980 
1982 
1983  memset(&chat_globals, 0, sizeof(chat_globals));
1984  chat_globals.running = 1;
1987 
1988  chat_thread_start(1);
1989 
1990  return SWITCH_STATUS_SUCCESS;
1991 }
static struct switch_loadable_module_container loadable_modules
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's master pool.
Definition: switch_core.h:631
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
#define SWITCH_CHANNEL_LOG
switch_status_t switch_loadable_module_load_module(char *dir, char *fname, switch_bool_t runtime, const char **err)
Load a module.
#define switch_core_hash_init(_hash)
Definition: switch_core.h:1390
switch_bool_t
Definition: switch_types.h:405
A representation of an XML tree.
Definition: switch_xml.h:76
static int switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:450
#define zstr(x)
Definition: switch_utils.h:281
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
switch_xml_t next
Definition: switch_xml.h:88
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:270
static switch_status_t switch_loadable_module_load_module_ex(char *dir, char *fname, switch_bool_t runtime, switch_bool_t global, const char **err)
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:60
static struct @5 chat_globals
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)
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.
memset(buf, 0, buflen)
#define switch_core_hash_init_nocase(_hash)
Definition: switch_core.h:1391
switch_status_t switch_loadable_module_load_module ( char *  dir,
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 1545 of file switch_loadable_module.c.

References SWITCH_FALSE, and switch_loadable_module_load_module_ex().

Referenced by main(), and switch_loadable_module_init().

1546 {
1548 }
struct switch_runtime runtime
Definition: switch_core.c:64
static switch_status_t switch_loadable_module_load_module_ex(char *dir, char *fname, switch_bool_t runtime, switch_bool_t global, const char **err)
void switch_loadable_module_shutdown ( void  )

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

Definition at line 2044 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::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, 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::speech_hash, switch_core_destroy_memory_pool, switch_core_hash_destroy(), switch_core_hash_first, switch_core_hash_next(), switch_core_hash_this(), SWITCH_FALSE, switch_queue_push(), switch_thread_join(), SWITCH_TRUE, switch_yield, and switch_loadable_module_container::timer_hash.

Referenced by fs_loadable_module_shutdown(), and switch_core_destroy().

2045 {
2046  switch_hash_index_t *hi;
2047  void *val;
2048  switch_loadable_module_t *module;
2049  int i;
2050 
2052  return;
2053  }
2054 
2055  chat_globals.running = 0;
2056 
2057  for (i = 0; i < chat_globals.msg_queue_len; i++) {
2058  switch_queue_push(chat_globals.msg_queue[i], NULL);
2059  }
2060 
2061  for (i = 0; i < chat_globals.msg_queue_len; i++) {
2062  switch_status_t st;
2063  switch_thread_join(&st, chat_globals.msg_queue_thread[i]);
2064  }
2065 
2066 
2068  switch_core_hash_this(hi, NULL, NULL, &val);
2069  module = (switch_loadable_module_t *) val;
2070  if (!module->perm) {
2072  }
2073  }
2074 
2075  switch_yield(1000000);
2076 
2078  switch_core_hash_this(hi, NULL, NULL, &val);
2079  module = (switch_loadable_module_t *) val;
2080  if (!module->perm) {
2082  }
2083  }
2084 
2102 
2104 }
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:640
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
Definition: switch_apr.c:1255
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:908
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.
static struct @5 chat_globals
switch_status_t
Common return values.
switch_status_t switch_queue_push(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1129
#define switch_core_hash_first(_h)
Definition: switch_core.h:1501
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_status_t switch_loadable_module_unload_module ( char *  dir,
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 1629 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.

1630 {
1631  switch_loadable_module_t *module = NULL;
1633 
1634  if (force) {
1635  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Spin the barrel and pull the trigger.......!\n");
1636  }
1637 
1639  if ((module = switch_core_hash_find(loadable_modules.module_hash, fname))) {
1640  if (module->perm) {
1641  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Module is not unloadable.\n");
1642  *err = "Module is not unloadable";
1643  status = SWITCH_STATUS_NOUNLOAD;
1644  goto unlock;
1645  } else {
1646  /* Prevent anything from using the module while it's shutting down */
1649  if ((status = do_shutdown(module, SWITCH_TRUE, SWITCH_TRUE, !force, err)) != SWITCH_STATUS_SUCCESS) {
1650  /* Something went wrong in the module's shutdown function, add it again */
1652  }
1653  goto end;
1654  }
1655  } else {
1656  *err = "No such module!";
1657  status = SWITCH_STATUS_FALSE;
1658  }
1659 unlock:
1661  end:
1662  if (force) {
1663  switch_yield(1000000);
1665  }
1666 
1667  return status;
1668 
1669 }
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:290
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:908
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:285
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_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
char* switch_parse_codec_buf ( char *  buf,
uint32_t *  interval,
uint32_t *  rate,
uint32_t *  bit,
uint32_t *  channels,
char **  modname 
)

Definition at line 2343 of file switch_loadable_module.c.

References buf, cur, SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, and switch_log_printf().

Referenced by switch_loadable_module_get_codecs_sorted().

2344 {
2345  char *cur, *next = NULL, *name, *p;
2346 
2347  name = next = cur = buf;
2348 
2349  *channels = 1;
2350 
2351  for (;;) {
2352  if (!next) {
2353  break;
2354  }
2355 
2356  if ((p = strchr(next, '@'))) {
2357  *p++ = '\0';
2358  }
2359  next = p;
2360 
2361  if (cur != name) {
2362  if (strchr(cur, 'i')) {
2363  *interval = atoi(cur);
2364  } else if ((strchr(cur, 'k') || strchr(cur, 'h'))) {
2365  *rate = atoi(cur);
2366  } else if (strchr(cur, 'b')) {
2367  *bit = atoi(cur);
2368  } else if (strchr(cur, 'c')) {
2369  *channels = atoi(cur);
2370  } else {
2371  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);
2372  }
2373  }
2374  cur = next;
2375  }
2376 
2377  if ((p = strchr(name, '.'))) {
2378  *p++ = '\0';
2379  *modname = name;
2380  name = p;
2381  }
2382 
2383  return name;
2384 }
#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.

Variable Documentation

char* filename

Definition at line 331 of file switch_loadable_module.h.

Referenced by core_event_handler(), and switch_simple_email().