Asterisk - The Open Source Telephony Project  GIT-master-a1fa8df
Data Structures | Macros | Enumerations | Functions | Variables
module.h File Reference

Asterisk module definitions. More...

#include "asterisk/utils.h"

Go to the source code of this file.

Data Structures

struct  ast_module_info
 

Macros

#define AST_MODULE_CONFIG   "modules.conf"
 Module configuration file. More...
 
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
 
#define AST_MODULE_INFO_STANDARD(keystr, desc)
 
#define AST_MODULE_INFO_STANDARD_DEPRECATED(keystr, desc)
 
#define AST_MODULE_INFO_STANDARD_EXTENDED(keystr, desc)
 
#define ast_module_ref(mod)   __ast_module_ref(mod, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 Hold a reference to the module. More...
 
#define ast_module_running_ref(mod)   __ast_module_running_ref(mod, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 Hold a reference to the module if it is running. More...
 
#define ast_module_shutdown_ref(mod)   __ast_module_shutdown_ref(mod, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 Prevent unload of the module before shutdown. More...
 
#define ast_module_unref(mod)   __ast_module_unref(mod, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 Release a reference to the module. More...
 
#define ast_module_user_add(chan)   __ast_module_user_add(AST_MODULE_SELF, chan)
 
#define ast_module_user_hangup_all()   __ast_module_user_hangup_all(AST_MODULE_SELF)
 
#define ast_module_user_remove(user)   __ast_module_user_remove(AST_MODULE_SELF, user)
 
#define ast_register_application(app, execute, synopsis, description)   ast_register_application2(app, execute, synopsis, description, AST_MODULE_SELF)
 Register an application. More...
 
#define ast_register_application_xml(app, execute)   ast_register_application(app, execute, NULL, NULL)
 Register an application using XML documentation. More...
 
#define ASTERISK_GPL_KEY   "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n"
 The text the key() function should return. More...
 
#define SCOPED_MODULE_USE(module)   RAII_VAR(struct ast_module *, __self__ ## __LINE__, ast_module_ref(module), ast_module_unref)
 

Enumerations

enum  ast_module_flags { AST_MODFLAG_DEFAULT = 0, AST_MODFLAG_GLOBAL_SYMBOLS = (1 << 0), AST_MODFLAG_LOAD_ORDER = (1 << 1) }
 
enum  ast_module_helper_type {
  AST_MODULE_HELPER_LOADED = 0, AST_MODULE_HELPER_RELOAD = 1, AST_MODULE_HELPER_LOAD, AST_MODULE_HELPER_UNLOAD,
  AST_MODULE_HELPER_RUNNING
}
 
enum  ast_module_load_priority {
  AST_MODPRI_REALTIME_DEPEND = 10, AST_MODPRI_REALTIME_DEPEND2 = 20, AST_MODPRI_REALTIME_DRIVER = 30, AST_MODPRI_CORE = 40,
  AST_MODPRI_TIMING = 50, AST_MODPRI_CHANNEL_DEPEND = 60, AST_MODPRI_CHANNEL_DRIVER = 70, AST_MODPRI_APP_DEPEND = 80,
  AST_MODPRI_DEVSTATE_PROVIDER = 90, AST_MODPRI_DEVSTATE_PLUGIN = 100, AST_MODPRI_CDR_DRIVER = 110, AST_MODPRI_DEFAULT = 128,
  AST_MODPRI_DEVSTATE_CONSUMER = 150
}
 
enum  ast_module_load_result {
  AST_MODULE_LOAD_SUCCESS = 0, AST_MODULE_LOAD_DECLINE = 1, AST_MODULE_LOAD_SKIP = 2, AST_MODULE_LOAD_PRIORITY = 3,
  AST_MODULE_LOAD_FAILURE = -1
}
 
enum  ast_module_reload_result {
  AST_MODULE_RELOAD_SUCCESS = 0, AST_MODULE_RELOAD_QUEUED, AST_MODULE_RELOAD_NOT_FOUND, AST_MODULE_RELOAD_ERROR,
  AST_MODULE_RELOAD_IN_PROGRESS, AST_MODULE_RELOAD_UNINITIALIZED, AST_MODULE_RELOAD_NOT_IMPLEMENTED
}
 Possible return types for ast_module_reload. More...
 
enum  ast_module_support_level { AST_MODULE_SUPPORT_UNKNOWN, AST_MODULE_SUPPORT_CORE, AST_MODULE_SUPPORT_EXTENDED, AST_MODULE_SUPPORT_DEPRECATED }
 
enum  ast_module_unload_mode { AST_FORCE_SOFT = 0, AST_FORCE_FIRM = 1, AST_FORCE_HARD = 2 }
 

Functions

struct ast_module__ast_module_ref (struct ast_module *mod, const char *file, int line, const char *func)
 
struct ast_module__ast_module_running_ref (struct ast_module *mod, const char *file, int line, const char *func)
 
void __ast_module_shutdown_ref (struct ast_module *mod, const char *file, int line, const char *func)
 
void __ast_module_unref (struct ast_module *mod, const char *file, int line, const char *func)
 
struct ast_module_user__ast_module_user_add (struct ast_module *, struct ast_channel *)
 
void __ast_module_user_hangup_all (struct ast_module *)
 
void __ast_module_user_remove (struct ast_module *, struct ast_module_user *)
 
enum ast_module_load_result ast_load_resource (const char *resource_name)
 Load a module. More...
 
int ast_loader_register (int(*updater)(void))
 Add a procedure to be run when modules have been updated. More...
 
int ast_loader_unregister (int(*updater)(void))
 Remove a procedure to be run when modules are updated. More...
 
int ast_module_check (const char *name)
 Check if module with the name given is loaded. More...
 
char * ast_module_helper (const char *line, const char *word, int pos, int state, int rpos, enum ast_module_helper_type type)
 Match modules names for the Asterisk cli. More...
 
const char * ast_module_name (const struct ast_module *mod)
 Get the name of a module. More...
 
void ast_module_register (const struct ast_module_info *)
 
enum ast_module_reload_result ast_module_reload (const char *name)
 Reload asterisk modules. More...
 
const char * ast_module_support_level_to_string (enum ast_module_support_level support_level)
 
void ast_module_unregister (const struct ast_module_info *)
 
int ast_register_application2 (const char *app, int(*execute)(struct ast_channel *, const char *), const char *synopsis, const char *description, void *mod)
 Register an application. More...
 
int ast_unload_resource (const char *resource_name, enum ast_module_unload_mode)
 Unload a module. More...
 
int ast_unregister_application (const char *app)
 Unregister an application. More...
 
int ast_update_module_list (int(*modentry)(const char *module, const char *description, int usecnt, const char *status, const char *like, enum ast_module_support_level support_level), const char *like)
 Ask for a list of modules, descriptions, use counts and status. More...
 
int ast_update_module_list_condition (int(*modentry)(const char *module, const char *description, int usecnt, const char *status, const char *like, enum ast_module_support_level support_level, void *data, const char *condition), const char *like, void *data, const char *condition)
 Ask for a list of modules, descriptions, use counts and status. More...
 
int ast_update_module_list_data (int(*modentry)(const char *module, const char *description, int usecnt, const char *status, const char *like, enum ast_module_support_level support_level, void *data), const char *like, void *data)
 Ask for a list of modules, descriptions, use counts and status. More...
 
void ast_update_use_count (void)
 Notify when usecount has been changed. More...
 

Variables

static const struct ast_module_infoast_module_info
 

Detailed Description

Asterisk module definitions.

This file contains the definitons for functions Asterisk modules should provide and some other module related functions.

Definition in file module.h.

Macro Definition Documentation

◆ AST_MODULE_CONFIG

#define AST_MODULE_CONFIG   "modules.conf"

Module configuration file.

Definition at line 59 of file module.h.

Referenced by loader_config_init().

◆ AST_MODULE_INFO

#define AST_MODULE_INFO (   keystr,
  flags_to_set,
  desc,
  fields... 
)

Definition at line 543 of file module.h.

◆ AST_MODULE_INFO_STANDARD

#define AST_MODULE_INFO_STANDARD (   keystr,
  desc 
)

Definition at line 567 of file module.h.

◆ AST_MODULE_INFO_STANDARD_DEPRECATED

#define AST_MODULE_INFO_STANDARD_DEPRECATED (   keystr,
  desc 
)

Definition at line 583 of file module.h.

◆ AST_MODULE_INFO_STANDARD_EXTENDED

#define AST_MODULE_INFO_STANDARD_EXTENDED (   keystr,
  desc 
)

Definition at line 575 of file module.h.

◆ ast_module_ref

#define ast_module_ref (   mod)    __ast_module_ref(mod, __FILE__, __LINE__, __PRETTY_FUNCTION__)

◆ ast_module_running_ref

#define ast_module_running_ref (   mod)    __ast_module_running_ref(mod, __FILE__, __LINE__, __PRETTY_FUNCTION__)

Hold a reference to the module if it is running.

Parameters
modModule to reference
Return values
modif running
NULLif not running

The returned pointer should be released with ast_module_unref.

Note
A module reference will prevent the module from being unloaded.
Examples:
/tmp/asterisk-shallow/main/app.c.

Definition at line 455 of file module.h.

Referenced by __ast_cli_generator(), __ast_sorcery_object_type_insert_wizard(), agi_handle_command(), ast_app_exec_sub(), ast_app_expand_sub_args(), ast_cli_command_full(), ast_hook_send_action(), ast_rtp_instance_new(), ast_timer_open(), fax_session_new(), fax_session_reserve(), find_best_technology(), get_filestream(), and process_message().

◆ ast_module_shutdown_ref

#define ast_module_shutdown_ref (   mod)    __ast_module_shutdown_ref(mod, __FILE__, __LINE__, __PRETTY_FUNCTION__)

Prevent unload of the module before shutdown.

Parameters
modModule to hold
Note
This should not be balanced by a call to ast_module_unref.

Definition at line 464 of file module.h.

Referenced by __ast_bucket_scheme_register(), __ast_codec_register_with_format(), __ast_format_interface_register(), load_module(), and start_resource().

◆ ast_module_unref

#define ast_module_unref (   mod)    __ast_module_unref(mod, __FILE__, __LINE__, __PRETTY_FUNCTION__)

◆ ast_module_user_add

#define ast_module_user_add (   chan)    __ast_module_user_add(AST_MODULE_SELF, chan)

◆ ast_module_user_hangup_all

#define ast_module_user_hangup_all ( )    __ast_module_user_hangup_all(AST_MODULE_SELF)

Definition at line 428 of file module.h.

◆ ast_module_user_remove

#define ast_module_user_remove (   user)    __ast_module_user_remove(AST_MODULE_SELF, user)

◆ ast_register_application

#define ast_register_application (   app,
  execute,
  synopsis,
  description 
)    ast_register_application2(app, execute, synopsis, description, AST_MODULE_SELF)

Register an application.

Parameters
appShort name of the application
executea function callback to execute the application. It should return non-zero if the channel needs to be hung up.
synopsisa short description (one line synopsis) of the application
descriptionlong description with all of the details about the use of the application

This registers an application with Asterisk's internal application list.

Note
The individual applications themselves are responsible for registering and unregistering and unregistering their own CLI commands.
Return values
0success
-1failure.

Definition at line 610 of file module.h.

Referenced by load_module().

◆ ast_register_application_xml

#define ast_register_application_xml (   app,
  execute 
)    ast_register_application(app, execute, NULL, NULL)

Register an application using XML documentation.

Parameters
appShort name of the application
executea function callback to execute the application. It should return non-zero if the channel needs to be hung up.

This registers an application with Asterisk's internal application list.

Note
The individual applications themselves are responsible for registering and unregistering and unregistering their own CLI commands.
Return values
0success
-1failure.

Definition at line 626 of file module.h.

Referenced by load_module(), and load_parking_applications().

◆ ASTERISK_GPL_KEY

#define ASTERISK_GPL_KEY   "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n"

◆ SCOPED_MODULE_USE

#define SCOPED_MODULE_USE (   module)    RAII_VAR(struct ast_module *, __self__ ## __LINE__, ast_module_ref(module), ast_module_unref)

Enumeration Type Documentation

◆ ast_module_flags

Enumerator
AST_MODFLAG_DEFAULT 
AST_MODFLAG_GLOBAL_SYMBOLS 
AST_MODFLAG_LOAD_ORDER 

Definition at line 314 of file module.h.

◆ ast_module_helper_type

Used to specify which modules should be returned by ast_module_helper.

Enumerator
AST_MODULE_HELPER_LOADED 

Modules that are loaded by dlopen.

AST_MODULE_HELPER_RELOAD 

Running modules that include a reload callback.

AST_MODULE_HELPER_LOAD 

Modules that can be loaded or started.

AST_MODULE_HELPER_UNLOAD 

Modules that can be unloaded.

AST_MODULE_HELPER_RUNNING 

Running modules

Definition at line 127 of file module.h.

127  {
128  /*! Modules that are loaded by dlopen. */
130  /*! Running modules that include a reload callback. */
132  /*! Modules that can be loaded or started. */
134  /*! Modules that can be unloaded. */
136  /*! Running modules */
138 };

◆ ast_module_load_priority

Enumerator
AST_MODPRI_REALTIME_DEPEND 

Dependency for a realtime driver

AST_MODPRI_REALTIME_DEPEND2 

Second level dependency for a realtime driver (func_curl needs res_curl, but is needed by res_config_curl)

AST_MODPRI_REALTIME_DRIVER 

A realtime driver, which provides configuration services for other modules

AST_MODPRI_CORE 

A core module originally meant to start between preload and load.

AST_MODPRI_TIMING 

Dependency for a channel (MOH needs timing interfaces to be fully loaded)

AST_MODPRI_CHANNEL_DEPEND 

Channel driver dependency (may depend upon realtime, e.g. MOH)

AST_MODPRI_CHANNEL_DRIVER 

Channel drivers (provide devicestate)

AST_MODPRI_APP_DEPEND 

Dependency for an application

AST_MODPRI_DEVSTATE_PROVIDER 

Applications and other modules that provide devicestate (e.g. meetme)

AST_MODPRI_DEVSTATE_PLUGIN 

Plugin for a module that provides devstate (e.g. res_calendar_*)

AST_MODPRI_CDR_DRIVER 

CDR or CEL backend

AST_MODPRI_DEFAULT 

Modules not otherwise defined (such as most apps) will load here

AST_MODPRI_DEVSTATE_CONSUMER 

Certain modules, which consume devstate, need to load after all others (e.g. app_queue)

Definition at line 320 of file module.h.

320  {
321  AST_MODPRI_REALTIME_DEPEND = 10, /*!< Dependency for a realtime driver */
322  AST_MODPRI_REALTIME_DEPEND2 = 20, /*!< Second level dependency for a realtime driver (func_curl needs res_curl, but is needed by res_config_curl) */
323  AST_MODPRI_REALTIME_DRIVER = 30, /*!< A realtime driver, which provides configuration services for other modules */
324  AST_MODPRI_CORE = 40, /*!< A core module originally meant to start between preload and load. */
325  AST_MODPRI_TIMING = 50, /*!< Dependency for a channel (MOH needs timing interfaces to be fully loaded) */
326  AST_MODPRI_CHANNEL_DEPEND = 60, /*!< Channel driver dependency (may depend upon realtime, e.g. MOH) */
327  AST_MODPRI_CHANNEL_DRIVER = 70, /*!< Channel drivers (provide devicestate) */
328  AST_MODPRI_APP_DEPEND = 80, /*!< Dependency for an application */
329  AST_MODPRI_DEVSTATE_PROVIDER = 90, /*!< Applications and other modules that _provide_ devicestate (e.g. meetme) */
330  AST_MODPRI_DEVSTATE_PLUGIN = 100, /*!< Plugin for a module that provides devstate (e.g. res_calendar_*) */
331  AST_MODPRI_CDR_DRIVER = 110, /*!< CDR or CEL backend */
332  AST_MODPRI_DEFAULT = 128, /*!< Modules not otherwise defined (such as most apps) will load here */
333  AST_MODPRI_DEVSTATE_CONSUMER = 150, /*!< Certain modules, which consume devstate, need to load after all others (e.g. app_queue) */
334 };

◆ ast_module_load_result

Enumerator
AST_MODULE_LOAD_SUCCESS 

Module is loaded and configured.

AST_MODULE_LOAD_DECLINE 

Module has failed to load, may be in an inconsistent state.

This value is used when a module fails to start but does not risk system-wide stability. Declined modules will prevent any other dependent module from starting.

AST_MODULE_LOAD_SKIP 
AST_MODULE_LOAD_PRIORITY 
AST_MODULE_LOAD_FAILURE 

Module could not be loaded properly.

This return should only be returned by modules for unrecoverable failures that cause the whole system to become unstable. In almost all cases AST_MODULE_LOAD_DECLINE should be used instead.

Warning
Returning this code from any module will cause startup to abort. If startup is already completed this code has the same effect as AST_MODULE_LOAD_DECLINE.

Definition at line 68 of file module.h.

68  {
69  /*! Module is loaded and configured. */
71  /*!
72  * \brief Module has failed to load, may be in an inconsistent state.
73  *
74  * This value is used when a module fails to start but does not risk
75  * system-wide stability. Declined modules will prevent any other
76  * dependent module from starting.
77  */
79  /*! \internal
80  * \brief Module was skipped for some reason.
81  *
82  * \note For loader.c use only. Should never be returned by modules.
83  */
85  /*! \internal
86  * \brief Module is not loaded yet, but is added to priority list.
87  *
88  * \note For loader.c use only. Should never be returned by modules.
89  */
91  /*!
92  * \brief Module could not be loaded properly.
93  *
94  * This return should only be returned by modules for unrecoverable
95  * failures that cause the whole system to become unstable. In almost
96  * all cases \ref AST_MODULE_LOAD_DECLINE should be used instead.
97  *
98  * \warning Returning this code from any module will cause startup to abort.
99  * If startup is already completed this code has the same effect as
100  * \ref AST_MODULE_LOAD_DECLINE.
101  */
103 };
Module could not be loaded properly.
Definition: module.h:102
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78

◆ ast_module_reload_result

Possible return types for ast_module_reload.

Since
12
Enumerator
AST_MODULE_RELOAD_SUCCESS 

The module was reloaded succesfully

AST_MODULE_RELOAD_QUEUED 

The module reload request was queued

AST_MODULE_RELOAD_NOT_FOUND 

The requested module was not found

AST_MODULE_RELOAD_ERROR 

An error occurred while reloading the module

AST_MODULE_RELOAD_IN_PROGRESS 

A module reload request is already in progress

AST_MODULE_RELOAD_UNINITIALIZED 

The module has not been initialized

AST_MODULE_RELOAD_NOT_IMPLEMENTED 

This module doesn't support reloading

Definition at line 109 of file module.h.

109  {
110  AST_MODULE_RELOAD_SUCCESS = 0, /*!< The module was reloaded succesfully */
111  AST_MODULE_RELOAD_QUEUED, /*!< The module reload request was queued */
112  AST_MODULE_RELOAD_NOT_FOUND, /*!< The requested module was not found */
113  AST_MODULE_RELOAD_ERROR, /*!< An error occurred while reloading the module */
114  AST_MODULE_RELOAD_IN_PROGRESS, /*!< A module reload request is already in progress */
115  AST_MODULE_RELOAD_UNINITIALIZED, /*!< The module has not been initialized */
116  AST_MODULE_RELOAD_NOT_IMPLEMENTED, /*!< This module doesn't support reloading */
117 };

◆ ast_module_support_level

Enumerator
AST_MODULE_SUPPORT_UNKNOWN 
AST_MODULE_SUPPORT_CORE 
AST_MODULE_SUPPORT_EXTENDED 
AST_MODULE_SUPPORT_DEPRECATED 

Definition at line 119 of file module.h.

◆ ast_module_unload_mode

Enumerator
AST_FORCE_SOFT 

Softly unload a module, only if not in use

AST_FORCE_FIRM 

Firmly unload a module, even if in use

AST_FORCE_HARD 

as FIRM, plus dlclose() on the module. Not recommended as it may cause crashes

Definition at line 61 of file module.h.

61  {
62  AST_FORCE_SOFT = 0, /*!< Softly unload a module, only if not in use */
63  AST_FORCE_FIRM = 1, /*!< Firmly unload a module, even if in use */
64  AST_FORCE_HARD = 2, /*!< as FIRM, plus dlclose() on the module. Not recommended
65  as it may cause crashes */
66 };

Function Documentation

◆ __ast_module_ref()

struct ast_module* __ast_module_ref ( struct ast_module mod,
const char *  file,
int  line,
const char *  func 
)

Definition at line 2698 of file loader.c.

References __ao2_ref(), ast_atomic_fetchadd_int(), ast_update_use_count(), NULL, ast_module::ref_debug, and ast_module::usecount.

Referenced by __ast_module_running_ref(), and __ast_module_shutdown_ref().

2699 {
2700  if (!mod) {
2701  return NULL;
2702  }
2703 
2704  if (mod->ref_debug) {
2705  __ao2_ref(mod->ref_debug, +1, "", file, line, func);
2706  }
2707 
2708  ast_atomic_fetchadd_int(&mod->usecount, +1);
2710 
2711  return mod;
2712 }
void ast_update_use_count(void)
Notify when usecount has been changed.
Definition: loader.c:2528
int usecount
Definition: loader.c:300
#define NULL
Definition: resample.c:96
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
int __ao2_ref(void *o, int delta, const char *tag, const char *file, int line, const char *func)
Definition: astobj2.c:498
void * ref_debug
Definition: loader.c:296

◆ __ast_module_running_ref()

struct ast_module* __ast_module_running_ref ( struct ast_module mod,
const char *  file,
int  line,
const char *  func 
)

Definition at line 2714 of file loader.c.

References __ast_module_ref(), ast_module::flags, NULL, and ast_module::running.

2716 {
2717  if (!mod || !mod->flags.running) {
2718  return NULL;
2719  }
2720 
2721  return __ast_module_ref(mod, file, line, func);
2722 }
unsigned int running
Definition: loader.c:320
struct ast_module::@385 flags
#define NULL
Definition: resample.c:96
struct ast_module * __ast_module_ref(struct ast_module *mod, const char *file, int line, const char *func)
Definition: loader.c:2698

◆ __ast_module_shutdown_ref()

void __ast_module_shutdown_ref ( struct ast_module mod,
const char *  file,
int  line,
const char *  func 
)

Definition at line 2724 of file loader.c.

References __ast_module_ref(), ast_module::flags, and ast_module::keepuntilshutdown.

2725 {
2726  if (!mod || mod->flags.keepuntilshutdown) {
2727  return;
2728  }
2729 
2730  __ast_module_ref(mod, file, line, func);
2731  mod->flags.keepuntilshutdown = 1;
2732 }
struct ast_module::@385 flags
unsigned int keepuntilshutdown
Definition: loader.c:324
struct ast_module * __ast_module_ref(struct ast_module *mod, const char *file, int line, const char *func)
Definition: loader.c:2698

◆ __ast_module_unref()

void __ast_module_unref ( struct ast_module mod,
const char *  file,
int  line,
const char *  func 
)

Definition at line 2734 of file loader.c.

References __ao2_ref(), ast_atomic_fetchadd_int(), ast_update_use_count(), ast_module::ref_debug, and ast_module::usecount.

2735 {
2736  if (!mod) {
2737  return;
2738  }
2739 
2740  if (mod->ref_debug) {
2741  __ao2_ref(mod->ref_debug, -1, "", file, line, func);
2742  }
2743 
2744  ast_atomic_fetchadd_int(&mod->usecount, -1);
2746 }
void ast_update_use_count(void)
Notify when usecount has been changed.
Definition: loader.c:2528
int usecount
Definition: loader.c:300
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
int __ao2_ref(void *o, int delta, const char *tag, const char *file, int line, const char *func)
Definition: astobj2.c:498
void * ref_debug
Definition: loader.c:296

◆ __ast_module_user_add()

struct ast_module_user* __ast_module_user_add ( struct ast_module ,
struct ast_channel  
)

Definition at line 800 of file loader.c.

References ao2_ref, ast_atomic_fetchadd_int(), ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_update_use_count(), ast_module_user::chan, NULL, ast_module::ref_debug, ast_module::usecount, and ast_module::users.

Referenced by ast_func_read(), ast_func_read2(), ast_func_write(), and pbx_exec().

801 {
802  struct ast_module_user *u;
803 
804  u = ast_calloc(1, sizeof(*u));
805  if (!u) {
806  return NULL;
807  }
808 
809  u->chan = chan;
810 
811  AST_LIST_LOCK(&mod->users);
812  AST_LIST_INSERT_HEAD(&mod->users, u, entry);
813  AST_LIST_UNLOCK(&mod->users);
814 
815  if (mod->ref_debug) {
816  ao2_ref(mod->ref_debug, +1);
817  }
818 
819  ast_atomic_fetchadd_int(&mod->usecount, +1);
820 
822 
823  return u;
824 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
void ast_update_use_count(void)
Notify when usecount has been changed.
Definition: loader.c:2528
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define NULL
Definition: resample.c:96
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ast_channel * chan
Definition: loader.c:128
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:710
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
Definition: search.h:40

◆ __ast_module_user_hangup_all()

void __ast_module_user_hangup_all ( struct ast_module )

Definition at line 853 of file loader.c.

References ao2_ref, ast_atomic_fetchadd_int(), ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_softhangup(), AST_SOFTHANGUP_APPUNLOAD, ast_update_use_count(), ast_module_user::chan, ast_module::ref_debug, ast_module::usecount, and ast_module::users.

Referenced by ast_unload_resource().

854 {
855  struct ast_module_user *u;
856 
857  AST_LIST_LOCK(&mod->users);
858  while ((u = AST_LIST_REMOVE_HEAD(&mod->users, entry))) {
859  if (u->chan) {
861  }
862 
863  if (mod->ref_debug) {
864  ao2_ref(mod->ref_debug, -1);
865  }
866 
867  ast_atomic_fetchadd_int(&mod->usecount, -1);
868  ast_free(u);
869  }
870  AST_LIST_UNLOCK(&mod->users);
871 
873 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
void ast_update_use_count(void)
Notify when usecount has been changed.
Definition: loader.c:2528
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
#define ao2_ref(o, delta)
Definition: astobj2.h:464
int ast_softhangup(struct ast_channel *chan, int reason)
Softly hangup up a channel.
Definition: channel.c:2472
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
struct ast_channel * chan
Definition: loader.c:128
#define ast_free(a)
Definition: astmm.h:182
Definition: search.h:40

◆ __ast_module_user_remove()

void __ast_module_user_remove ( struct ast_module ,
struct ast_module_user  
)

Definition at line 826 of file loader.c.

References ao2_ref, ast_atomic_fetchadd_int(), ast_free, AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, ast_update_use_count(), ast_module::ref_debug, ast_module::usecount, and ast_module::users.

Referenced by ast_func_read(), ast_func_read2(), ast_func_write(), and pbx_exec().

827 {
828  if (!u) {
829  return;
830  }
831 
832  AST_LIST_LOCK(&mod->users);
833  u = AST_LIST_REMOVE(&mod->users, u, entry);
834  AST_LIST_UNLOCK(&mod->users);
835  if (!u) {
836  /*
837  * Was not in the list. Either a bad pointer or
838  * __ast_module_user_hangup_all() has been called.
839  */
840  return;
841  }
842 
843  if (mod->ref_debug) {
844  ao2_ref(mod->ref_debug, -1);
845  }
846 
847  ast_atomic_fetchadd_int(&mod->usecount, -1);
848  ast_free(u);
849 
851 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
void ast_update_use_count(void)
Notify when usecount has been changed.
Definition: loader.c:2528
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
Definition: linkedlists.h:855
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ast_free(a)
Definition: astmm.h:182
Definition: search.h:40

◆ ast_load_resource()

enum ast_module_load_result ast_load_resource ( const char *  resource_name)

Load a module.

Parameters
resource_nameThe name of the module to load.

This function is run by the PBX to load the modules. It performs all loading and initialization tasks. Basically, to load a module, just give it the name of the module and it will do the rest.

Returns
See possible enum values for ast_module_load_result.

Definition at line 1819 of file loader.c.

References AST_DLLIST_LOCK, AST_DLLIST_UNLOCK, ast_test_suite_event_notify, load_resource(), and NULL.

Referenced by ast_ari_asterisk_load_module(), handle_load(), and manager_moduleload().

1820 {
1821  int res;
1823  res = load_resource(resource_name, 0, NULL, 0, 0);
1824  if (!res) {
1825  ast_test_suite_event_notify("MODULE_LOAD", "Message: %s", resource_name);
1826  }
1828 
1829  return res;
1830 }
#define AST_DLLIST_UNLOCK(head)
Attempts to unlock a list.
Definition: dlinkedlists.h:122
#define NULL
Definition: resample.c:96
#define ast_test_suite_event_notify(s, f,...)
Definition: test.h:196
#define AST_DLLIST_LOCK(head)
Locks a list.
Definition: dlinkedlists.h:45
static enum ast_module_load_result load_resource(const char *resource_name, unsigned int suppress_logging, struct module_vector *module_priorities, int required, int preload)
Definition: loader.c:1763

◆ ast_loader_register()

int ast_loader_register ( int(*)(void)  updater)

Add a procedure to be run when modules have been updated.

Parameters
updaterThe function to run when modules have been updated.

This function adds the given function to a linked list of functions to be run when the modules are updated.

Return values
0on success
-1on failure.

Definition at line 2666 of file loader.c.

References AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_malloc, tmp(), and loadupdate::updater.

2667 {
2668  struct loadupdate *tmp;
2669 
2670  if (!(tmp = ast_malloc(sizeof(*tmp))))
2671  return -1;
2672 
2673  tmp->updater = v;
2677 
2678  return 0;
2679 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
int(* updater)(void)
Definition: loader.c:625
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
static int tmp()
Definition: bt_open.c:389
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:710
Definition: search.h:40

◆ ast_loader_unregister()

int ast_loader_unregister ( int(*)(void)  updater)

Remove a procedure to be run when modules are updated.

Parameters
updaterThe updater function to unregister.

This removes the given function from the updater list.

Return values
0on success
-1on failure.

Definition at line 2681 of file loader.c.

References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, and loadupdate::updater.

2682 {
2683  struct loadupdate *cur;
2684 
2687  if (cur->updater == v) {
2689  break;
2690  }
2691  }
2694 
2695  return cur ? 0 : -1;
2696 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
int(* updater)(void)
Definition: loader.c:625
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
Definition: search.h:40
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528

◆ ast_module_check()

int ast_module_check ( const char *  name)

Check if module with the name given is loaded.

Parameters
nameModule name, like "chan_sip.so"
Return values
1if true
0if false

Check if module with the name given is loaded.

Definition at line 2653 of file loader.c.

References ast_strlen_zero(), find_resource(), and NULL.

Referenced by ast_ari_asterisk_get_module(), ast_ari_asterisk_load_module(), ast_ari_asterisk_reload_module(), ast_ari_asterisk_unload_module(), AST_TEST_DEFINE(), ifmodule_read(), and manager_modulecheck().

2654 {
2655  struct ast_module *cur;
2656 
2657  if (ast_strlen_zero(name))
2658  return 0; /* FALSE */
2659 
2660  cur = find_resource(name, 1);
2661 
2662  return (cur != NULL);
2663 }
static const char name[]
Definition: format_mp3.c:68
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
static struct ast_module * find_resource(const char *resource, int do_lock)
Definition: loader.c:937

◆ ast_module_helper()

char* ast_module_helper ( const char *  line,
const char *  word,
int  pos,
int  state,
int  rpos,
enum ast_module_helper_type  type 
)

Match modules names for the Asterisk cli.

Parameters
lineUnused by this function, but this should be the line we are matching.
wordThe partial name to match.
posThe position the word we are completing is in.
stateThe possible match to return.
rposThe position we should be matching. This should be the same as pos.
typeThe type of action that will be performed by CLI.
Return values
Apossible completion of the partial match.
NULLif no matches were found.

Definition at line 1374 of file loader.c.

References AST_DLLIST_LOCK, AST_DLLIST_TRAVERSE, AST_DLLIST_UNLOCK, AST_MODULE_HELPER_LOAD, ast_strdup, module_load_helper(), module_matches_helper_type(), NULL, and ast_module::resource.

Referenced by handle_debug(), handle_load(), handle_modlist(), handle_reload(), handle_trace(), and handle_unload().

1375 {
1376  struct ast_module *mod;
1377  int which = 0;
1378  int wordlen = strlen(word);
1379  char *ret = NULL;
1380 
1381  if (pos != rpos) {
1382  return NULL;
1383  }
1384 
1385  if (type == AST_MODULE_HELPER_LOAD) {
1387 
1388  return NULL;
1389  }
1390 
1393  if (!module_matches_helper_type(mod, type)) {
1394  continue;
1395  }
1396 
1397  if (!strncasecmp(word, mod->resource, wordlen) && ++which > state) {
1398  ret = ast_strdup(mod->resource);
1399  break;
1400  }
1401  }
1403 
1404  return ret;
1405 }
static const char type[]
Definition: chan_ooh323.c:109
#define AST_DLLIST_UNLOCK(head)
Attempts to unlock a list.
Definition: dlinkedlists.h:122
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
#define AST_DLLIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: dlinkedlists.h:575
static int module_matches_helper_type(struct ast_module *mod, enum ast_module_helper_type type)
Definition: loader.c:1299
static void module_load_helper(const char *word)
Definition: loader.c:1361
Definition: search.h:40
char resource[0]
Definition: loader.c:333
#define AST_DLLIST_LOCK(head)
Locks a list.
Definition: dlinkedlists.h:45
short word

◆ ast_module_name()

const char* ast_module_name ( const struct ast_module mod)

Get the name of a module.

Parameters
modA pointer to the module.
Returns
the name of the module
Return values
NULLif mod or mod->info is NULL

Definition at line 615 of file loader.c.

References ast_module::info, ast_module_info::name, and NULL.

Referenced by acf_retrieve_docs(), ast_register_application2(), resource_list_recursive_decline(), start_resource_list(), and unload_dynamic_module().

616 {
617  if (!mod || !mod->info) {
618  return NULL;
619  }
620 
621  return mod->info->name;
622 }
#define NULL
Definition: resample.c:96
const char * name
Definition: module.h:350
const struct ast_module_info * info
Definition: loader.c:294

◆ ast_module_register()

void ast_module_register ( const struct ast_module_info )

Definition at line 659 of file loader.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_find, ao2_link, ao2_ref, ao2_t_alloc_options, ast_debug, AST_DLLIST_INSERT_TAIL, AST_DLLIST_LOCK, AST_DLLIST_UNLOCK, AST_LIST_HEAD_INIT, ast_opt_ref_debug, ast_std_calloc(), AST_VECTOR_INIT, ast_module::builtin, builtin_module_list, ast_module::enhances, ast_module::flags, ast_module::info, sip_to_pjsip::info(), loader_ready, ast_module_info::name, NULL, OBJ_SEARCH_KEY, ast_module::optional_modules, ast_module::ref_debug, ast_module::reffed_deps, ast_module::requires, ast_module::resource, resource_being_loaded, ast_module_info::self, and ast_module::users.

Referenced by get_name_from_resource(), and loader_builtin_init().

660 {
661  struct ast_module *mod;
662 
663  if (!loader_ready) {
664  mod = ast_std_calloc(1, sizeof(*mod) + strlen(info->name) + 1);
665  if (!mod) {
666  /* We haven't even reached main() yet, if we can't
667  * allocate memory at this point just give up. */
668  fprintf(stderr, "Allocation failure during startup.\n");
669  exit(2);
670  }
671  strcpy(mod->resource, info->name); /* safe */
672  mod->info = info;
673  mod->flags.builtin = 1;
675 
676  /* ast_module_register for built-in modules is run again during module preload. */
677  return;
678  }
679 
680  /*
681  * This lock protects resource_being_loaded as well as the module
682  * list. Normally we already have a lock on module_list when we
683  * begin the load but locking again from here prevents corruption
684  * if an asterisk module is dlopen'ed from outside the module loader.
685  */
687  mod = resource_being_loaded;
688  if (!mod) {
690  return;
691  }
692 
693  ast_debug(5, "Registering module %s\n", info->name);
694 
695  /* This tells load_dynamic_module that we're registered. */
697 
698  mod->info = info;
699  if (ast_opt_ref_debug) {
701  }
702  AST_LIST_HEAD_INIT(&mod->users);
703  AST_VECTOR_INIT(&mod->requires, 0);
705  AST_VECTOR_INIT(&mod->enhances, 0);
706  AST_VECTOR_INIT(&mod->reffed_deps, 0);
707 
710 
711  /* give the module a copy of its own handle, for later use in registrations and the like */
712  *((struct ast_module **) &(info->self)) = mod;
713 
714 #if defined(HAVE_PERMANENT_DLOPEN)
715  if (mod->flags.builtin != 1) {
716  struct info_list_obj *obj_tmp = ao2_find(info_list, info->name,
718 
719  if (!obj_tmp) {
720  obj_tmp = info_list_obj_alloc(info->name, info);
721  if (obj_tmp) {
722  ao2_link(info_list, obj_tmp);
723  ao2_ref(obj_tmp, -1);
724  }
725  } else {
726  ao2_ref(obj_tmp, -1);
727  }
728  }
729 #endif
730 }
static unsigned int loader_ready
Definition: loader.c:150
struct module_user_list users
Definition: loader.c:302
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
static struct module_list builtin_module_list
Definition: loader.c:364
#define AST_DLLIST_UNLOCK(head)
Attempts to unlock a list.
Definition: dlinkedlists.h:122
#define ao2_t_alloc_options(data_size, destructor_fn, options, debug_msg)
Allocate and initialize an object.
Definition: astobj2.h:404
struct ast_module::@385 flags
#define NULL
Definition: resample.c:96
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:444
#define AST_DLLIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
struct ast_vector_string enhances
Definition: loader.c:309
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113
const struct ast_module_info * info
Definition: loader.c:294
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ast_vector_string optional_modules
Definition: loader.c:307
struct ast_vector_string requires
Definition: loader.c:305
def info(msg)
void * ref_debug
Definition: loader.c:296
#define AST_LIST_HEAD_INIT(head)
Initializes a list head structure.
Definition: linkedlists.h:625
static struct ast_module *volatile resource_being_loaded
Definition: loader.c:650
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
void * ast_std_calloc(size_t nmemb, size_t size) attribute_malloc
Definition: astmm.c:1756
unsigned int builtin
Definition: loader.c:326
Definition: search.h:40
char resource[0]
Definition: loader.c:333
#define AST_DLLIST_LOCK(head)
Locks a list.
Definition: dlinkedlists.h:45
struct module_vector reffed_deps
Vector holding pointers to modules we have a reference to.
Definition: loader.c:317
#define ast_opt_ref_debug
Definition: options.h:135
#define ao2_link(container, obj)
Definition: astobj2.h:1549

◆ ast_module_reload()

enum ast_module_reload_result ast_module_reload ( const char *  name)

Reload asterisk modules.

Parameters
namethe name of the module to reload

This function reloads the specified module, or if no modules are specified, it will reload all loaded modules.

Note
Modules are reloaded using their reload() functions, not unloading them and loading them again.
Return values
Theast_module_reload_result status of the module load request

Definition at line 1562 of file loader.c.

References ast_config_AST_CONFIG_DIR, AST_DLLIST_LOCK, AST_DLLIST_TRAVERSE, AST_DLLIST_UNLOCK, ast_lastreloadtime, ast_lock_path(), AST_LOCK_SUCCESS, AST_LOCK_TIMEOUT, ast_log, AST_LOG_WARNING, AST_MODULE_LOAD_SUCCESS, AST_MODULE_RELOAD_ERROR, AST_MODULE_RELOAD_IN_PROGRESS, AST_MODULE_RELOAD_NOT_FOUND, AST_MODULE_RELOAD_NOT_IMPLEMENTED, AST_MODULE_RELOAD_QUEUED, AST_MODULE_RELOAD_SUCCESS, AST_MODULE_RELOAD_UNINITIALIZED, ast_mutex_trylock, ast_mutex_unlock, ast_opt_lock_confdir, ast_sd_notify(), ast_tvnow(), ast_unlock_path(), ast_verb, ast_module::declined, ast_module_info::description, ast_module::flags, ast_module::info, LOG_WARNING, publish_reload_message(), queue_reload_request(), ast_module_info::reload, reloadlock, ast_module::resource, resource_name_baselen(), resource_name_match(), and ast_module::running.

Referenced by action_reload(), action_updateconfig(), ast_ari_asterisk_reload_module(), ast_process_pending_reloads(), handle_cli_ael_reload(), handle_cli_moh_reload(), handle_core_reload(), handle_reload(), manager_moduleload(), monitor_sig_flags(), reload(), and reload_exec().

1563 {
1564  struct ast_module *cur;
1566  size_t name_baselen = name ? resource_name_baselen(name) : 0;
1567 
1568  /* If we aren't fully booted, we just pretend we reloaded but we queue this
1569  up to run once we are booted up. */
1570  if (!modules_loaded) {
1573  goto module_reload_exit;
1574  }
1575 
1576  if (ast_mutex_trylock(&reloadlock)) {
1577  ast_verb(3, "The previous reload command didn't finish yet\n");
1579  goto module_reload_exit;
1580  }
1581  ast_sd_notify("RELOAD=1");
1583 
1584  if (ast_opt_lock_confdir) {
1585  int try;
1586  int lockres;
1587  for (try = 1, lockres = AST_LOCK_TIMEOUT; try < 6 && (lockres == AST_LOCK_TIMEOUT); try++) {
1589  if (lockres == AST_LOCK_TIMEOUT) {
1590  ast_log(LOG_WARNING, "Failed to grab lock on %s, try %d\n", ast_config_AST_CONFIG_DIR, try);
1591  }
1592  }
1593  if (lockres != AST_LOCK_SUCCESS) {
1594  ast_log(AST_LOG_WARNING, "Cannot grab lock on %s\n", ast_config_AST_CONFIG_DIR);
1596  goto module_reload_done;
1597  }
1598  }
1599 
1602  const struct ast_module_info *info = cur->info;
1603 
1604  if (name && resource_name_match(name, name_baselen, cur->resource)) {
1605  continue;
1606  }
1607 
1608  if (!cur->flags.running || cur->flags.declined) {
1609  if (res == AST_MODULE_RELOAD_NOT_FOUND) {
1611  }
1612  if (!name) {
1613  continue;
1614  }
1615  break;
1616  }
1617 
1618  if (!info->reload) { /* cannot be reloaded */
1619  if (res == AST_MODULE_RELOAD_NOT_FOUND) {
1621  }
1622  if (!name) {
1623  continue;
1624  }
1625  break;
1626  }
1627  ast_verb(3, "Reloading module '%s' (%s)\n", cur->resource, info->description);
1628  if (info->reload() == AST_MODULE_LOAD_SUCCESS) {
1630  } else if (res == AST_MODULE_RELOAD_NOT_FOUND) {
1632  }
1633  if (name) {
1634  break;
1635  }
1636  }
1638 
1639  if (ast_opt_lock_confdir) {
1641  }
1642 module_reload_done:
1644  ast_sd_notify("READY=1");
1645 
1646 module_reload_exit:
1648  return res;
1649 }
const char * description
Definition: module.h:352
unsigned int running
Definition: loader.c:320
static const char name[]
Definition: format_mp3.c:68
ast_module_reload_result
Possible return types for ast_module_reload.
Definition: module.h:109
#define LOG_WARNING
Definition: logger.h:274
#define AST_DLLIST_UNLOCK(head)
Attempts to unlock a list.
Definition: dlinkedlists.h:122
static void publish_reload_message(const char *name, enum ast_module_reload_result result)
Definition: loader.c:1554
#define AST_LOG_WARNING
Definition: logger.h:279
static int resource_name_match(const char *name1, size_t baselen1, const char *name2)
Definition: loader.c:928
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
struct ast_module::@385 flags
int ast_unlock_path(const char *path)
Unlock a path.
Definition: main/app.c:2413
#define ast_verb(level,...)
Definition: logger.h:455
enum AST_LOCK_RESULT ast_lock_path(const char *path)
Lock a filesystem path.
Definition: main/app.c:2397
#define ast_log
Definition: astobj2.c:42
#define ast_mutex_trylock(a)
Definition: lock.h:189
const struct ast_module_info * info
Definition: loader.c:294
#define AST_DLLIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: dlinkedlists.h:575
int ast_sd_notify(const char *state)
a wrapper for sd_notify(): notify systemd of any state changes.
Definition: io.c:392
static int modules_loaded
Internal flag to indicate all modules have been initially loaded.
Definition: loader.c:291
struct timeval ast_lastreloadtime
Definition: asterisk.c:337
unsigned int declined
Definition: loader.c:322
int(* reload)(void)
Definition: module.h:346
const char * ast_config_AST_CONFIG_DIR
Definition: options.c:151
def info(msg)
static size_t resource_name_baselen(const char *name)
Definition: loader.c:917
static void queue_reload_request(const char *module)
Definition: loader.c:1432
static ast_mutex_t reloadlock
Definition: loader.c:631
Definition: search.h:40
char resource[0]
Definition: loader.c:333
#define AST_DLLIST_LOCK(head)
Locks a list.
Definition: dlinkedlists.h:45
#define ast_opt_lock_confdir
Definition: options.h:133
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ ast_module_support_level_to_string()

const char* ast_module_support_level_to_string ( enum ast_module_support_level  support_level)

Definition at line 2755 of file loader.c.

Referenced by identify_module(), modlist_modentry(), and process_module_list().

2756 {
2758 }
const char * support_level_map[]
Definition: loader.c:2748
enum ast_module_support_level support_level
Definition: module.h:416

◆ ast_module_unregister()

void ast_module_unregister ( const struct ast_module_info )

Definition at line 768 of file loader.c.

References ast_debug, AST_DLLIST_LOCK, AST_DLLIST_REMOVE_CURRENT, AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN, AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END, AST_DLLIST_UNLOCK, ast_module::info, module_destroy(), ast_module_info::name, NULL, and ast_module::usecount.

Referenced by get_name_from_resource().

769 {
770  struct ast_module *mod = NULL;
771 
772  /* it is assumed that the users list in the module structure
773  will already be empty, or we cannot have gotten to this
774  point
775  */
778  if (mod->info == info) {
780  break;
781  }
782  }
785 
786  if (mod && !mod->usecount) {
787  /*
788  * We are intentionally leaking mod if usecount is not zero.
789  * This is necessary if the module is being forcefully unloaded.
790  * In addition module_destroy is not safe to run after exit()
791  * is called. ast_module_unregister is run during cleanup of
792  * the process when libc releases each module's shared object
793  * library.
794  */
795  ast_debug(5, "Unregistering module %s\n", info->name);
796  module_destroy(mod);
797  }
798 }
#define AST_DLLIST_UNLOCK(head)
Attempts to unlock a list.
Definition: dlinkedlists.h:122
static void module_destroy(struct ast_module *mod)
Definition: loader.c:744
#define AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: dlinkedlists.h:887
int usecount
Definition: loader.c:300
#define AST_DLLIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: dlinkedlists.h:752
#define NULL
Definition: resample.c:96
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:444
const struct ast_module_info * info
Definition: loader.c:294
def info(msg)
#define AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END
Closes a safe loop traversal block.
Definition: dlinkedlists.h:920
Definition: search.h:40
#define AST_DLLIST_LOCK(head)
Locks a list.
Definition: dlinkedlists.h:45

◆ ast_register_application2()

int ast_register_application2 ( const char *  app,
int(*)(struct ast_channel *, const char *)  execute,
const char *  synopsis,
const char *  description,
void *  mod 
)

Register an application.

Parameters
appShort name of the application
executea function callback to execute the application. It should return non-zero if the channel needs to be hung up.
synopsisa short description (one line synopsis) of the application
descriptionlong description with all of the details about the use of the application
modmodule this application belongs to

This registers an application with Asterisk's internal application list.

Note
The individual applications themselves are responsible for registering and unregistering and unregistering their own CLI commands.
Return values
0success
-1failure.

Register an application.

Definition at line 103 of file pbx_app.c.

References ast_app::arguments, ast_calloc, ast_free, ast_log, ast_module_name(), AST_RWLIST_INSERT_BEFORE_CURRENT, AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, AST_STATIC_DOC, ast_string_field_init, ast_string_field_set, ast_strlen_zero(), ast_verb, AST_XML_DOC, ast_xmldoc_build_arguments(), ast_xmldoc_build_description(), ast_xmldoc_build_seealso(), ast_xmldoc_build_synopsis(), ast_xmldoc_build_syntax(), COLOR_BRCYAN, COLORIZE, COLORIZE_FMT, ast_app::docsrc, ast_app::execute, LOG_WARNING, pbx_findapp_nolock(), ast_app::seealso, ast_app::syntax, and tmp().

Referenced by ast_msg_init(), load_module(), load_pbx_builtins(), and load_pbx_variables().

104 {
105  struct ast_app *tmp;
106  struct ast_app *cur;
107  int length;
108 #ifdef AST_XML_DOCS
109  char *tmpxml;
110 #endif
111 
113  cur = pbx_findapp_nolock(app);
114  if (cur) {
115  ast_log(LOG_WARNING, "Already have an application '%s'\n", app);
117  return -1;
118  }
119 
120  length = sizeof(*tmp) + strlen(app) + 1;
121 
122  if (!(tmp = ast_calloc(1, length))) {
124  return -1;
125  }
126 
127  if (ast_string_field_init(tmp, 128)) {
129  ast_free(tmp);
130  return -1;
131  }
132 
133  strcpy(tmp->name, app);
134  tmp->execute = execute;
135  tmp->module = mod;
136 
137 #ifdef AST_XML_DOCS
138  /* Try to lookup the docs in our XML documentation database */
140  /* load synopsis */
141  tmpxml = ast_xmldoc_build_synopsis("application", app, ast_module_name(tmp->module));
142  ast_string_field_set(tmp, synopsis, tmpxml);
143  ast_free(tmpxml);
144 
145  /* load description */
146  tmpxml = ast_xmldoc_build_description("application", app, ast_module_name(tmp->module));
147  ast_string_field_set(tmp, description, tmpxml);
148  ast_free(tmpxml);
149 
150  /* load syntax */
151  tmpxml = ast_xmldoc_build_syntax("application", app, ast_module_name(tmp->module));
152  ast_string_field_set(tmp, syntax, tmpxml);
153  ast_free(tmpxml);
154 
155  /* load arguments */
156  tmpxml = ast_xmldoc_build_arguments("application", app, ast_module_name(tmp->module));
157  ast_string_field_set(tmp, arguments, tmpxml);
158  ast_free(tmpxml);
159 
160  /* load seealso */
161  tmpxml = ast_xmldoc_build_seealso("application", app, ast_module_name(tmp->module));
162  ast_string_field_set(tmp, seealso, tmpxml);
163  ast_free(tmpxml);
164  tmp->docsrc = AST_XML_DOC;
165  } else {
166 #endif
169 #ifdef AST_XML_DOCS
170  tmp->docsrc = AST_STATIC_DOC;
171  }
172 #endif
173 
174  /* Store in alphabetical order */
175  AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, cur, list) {
176  if (strcasecmp(tmp->name, cur->name) < 0) {
178  break;
179  }
180  }
182  if (!cur)
183  AST_RWLIST_INSERT_TAIL(&apps, tmp, list);
184 
185  ast_verb(2, "Registered application '" COLORIZE_FMT "'\n", COLORIZE(COLOR_BRCYAN, 0, tmp->name));
186 
188 
189  return 0;
190 }
int(* execute)(struct ast_channel *chan, const char *data)
Definition: pbx_app.c:46
const ast_string_field description
Definition: pbx_app.c:53
static SQLHSTMT execute(struct odbc_obj *obj, void *data, int silent)
Common execution function for SQL queries.
Definition: func_odbc.c:454
Registered applications container.
Definition: pbx_app.c:67
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define LOG_WARNING
Definition: logger.h:274
static int tmp()
Definition: bt_open.c:389
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
char * ast_xmldoc_build_description(const char *type, const char *name, const char *module)
Generate description documentation from XML.
Definition: xmldoc.c:2250
char * ast_xmldoc_build_synopsis(const char *type, const char *name, const char *module)
Generate synopsis documentation from XML.
Definition: xmldoc.c:2227
char * ast_xmldoc_build_arguments(const char *type, const char *name, const char *module)
Generate the [arguments] tag based on type of node (&#39;application&#39;, &#39;function&#39; or &#39;agi&#39;) and name...
Definition: xmldoc.c:2075
#define ast_verb(level,...)
Definition: logger.h:455
#define COLOR_BRCYAN
Definition: term.h:60
#define COLORIZE(fg, bg, str)
Definition: term.h:68
#define ast_log
Definition: astobj2.c:42
static const char app[]
Definition: app_adsiprog.c:56
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
#define COLORIZE_FMT
Shortcut macros for coloring a set of text.
Definition: term.h:67
#define AST_RWLIST_INSERT_BEFORE_CURRENT
Definition: linkedlists.h:609
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
const ast_string_field syntax
Definition: pbx_app.c:53
static char * synopsis
Definition: func_enum.c:154
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
enum ast_doc_src docsrc
Definition: pbx_app.c:55
char * ast_xmldoc_build_syntax(const char *type, const char *name, const char *module)
Get the syntax for a specified application or function.
Definition: xmldoc.c:1253
char * ast_xmldoc_build_seealso(const char *type, const char *name, const char *module)
Parse the <see-also> node content.
Definition: xmldoc.c:1698
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:740
const char * ast_module_name(const struct ast_module *mod)
Get the name of a module.
Definition: loader.c:615
ast_app: A registered application
Definition: pbx_app.c:45
const ast_string_field seealso
Definition: pbx_app.c:53
static struct ast_app * pbx_findapp_nolock(const char *name)
Definition: pbx_app.c:69
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616
const ast_string_field arguments
Definition: pbx_app.c:53
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ ast_unload_resource()

int ast_unload_resource ( const char *  resource_name,
enum  ast_module_unload_mode 
)

Unload a module.

Parameters
resource_nameThe name of the module to unload.
ast_module_unload_modeThe force flag. This should be set using one of the AST_FORCE flags.

This function unloads a module. It will only unload modules that are not in use (usecount not zero), unless AST_FORCE_FIRM or AST_FORCE_HARD is specified. Setting AST_FORCE_FIRM or AST_FORCE_HARD will unload the module regardless of consequences (NOT RECOMMENDED).

Return values
0on success.
-1on error.

Definition at line 1229 of file loader.c.

References __ast_module_user_hangup_all(), AST_DLLIST_LOCK, AST_DLLIST_UNLOCK, AST_FORCE_FIRM, ast_log, ast_test_suite_event_notify, ast_update_use_count(), ast_verb, ast_module::declined, error(), find_resource(), ast_module::flags, ast_module::info, LOG_WARNING, publish_unload_message(), ast_module::resource, ast_module::running, ast_module_info::unload, unload_dynamic_module(), and ast_module::usecount.

Referenced by ast_ari_asterisk_unload_module(), handle_unload(), manager_moduleload(), and unload_module().

1230 {
1231  struct ast_module *mod;
1232  int res = -1;
1233  int error = 0;
1234 
1236 
1237  if (!(mod = find_resource(resource_name, 0))) {
1239  ast_log(LOG_WARNING, "Unload failed, '%s' could not be found\n", resource_name);
1240  return -1;
1241  }
1242 
1243  if (!mod->flags.running || mod->flags.declined) {
1244  ast_log(LOG_WARNING, "Unload failed, '%s' is not loaded.\n", resource_name);
1245  error = 1;
1246  }
1247 
1248  if (!error && (mod->usecount > 0)) {
1249  if (force)
1250  ast_log(LOG_WARNING, "Warning: Forcing removal of module '%s' with use count %d\n",
1251  resource_name, mod->usecount);
1252  else {
1253  ast_log(LOG_WARNING, "Soft unload failed, '%s' has use count %d\n", resource_name,
1254  mod->usecount);
1255  error = 1;
1256  }
1257  }
1258 
1259  if (!error) {
1260  /* Request any channels attached to the module to hangup. */
1262 
1263  ast_verb(1, "Unloading %s\n", mod->resource);
1264  res = mod->info->unload();
1265  if (res) {
1266  ast_log(LOG_WARNING, "Firm unload failed for %s\n", resource_name);
1267  if (force <= AST_FORCE_FIRM) {
1268  error = 1;
1269  } else {
1270  ast_log(LOG_WARNING, "** Dangerous **: Unloading resource anyway, at user request\n");
1271  }
1272  }
1273 
1274  if (!error) {
1275  /*
1276  * Request hangup on any channels that managed to get attached
1277  * while we called the module unload function.
1278  */
1280  sched_yield();
1281  }
1282  }
1283 
1284  if (!error)
1285  mod->flags.running = mod->flags.declined = 0;
1286 
1288 
1289  if (!error) {
1290  unload_dynamic_module(mod);
1291  ast_test_suite_event_notify("MODULE_UNLOAD", "Message: %s", resource_name);
1293  publish_unload_message(resource_name, "Success");
1294  }
1295 
1296  return res;
1297 }
unsigned int running
Definition: loader.c:320
void ast_update_use_count(void)
Notify when usecount has been changed.
Definition: loader.c:2528
void __ast_module_user_hangup_all(struct ast_module *mod)
Definition: loader.c:853
#define LOG_WARNING
Definition: logger.h:274
#define AST_DLLIST_UNLOCK(head)
Attempts to unlock a list.
Definition: dlinkedlists.h:122
static void publish_unload_message(const char *name, const char *status)
Definition: loader.c:1544
int usecount
Definition: loader.c:300
struct ast_module::@385 flags
#define ast_verb(level,...)
Definition: logger.h:455
#define ast_log
Definition: astobj2.c:42
const struct ast_module_info * info
Definition: loader.c:294
int(* unload)(void)
Definition: module.h:348
unsigned int declined
Definition: loader.c:322
#define ast_test_suite_event_notify(s, f,...)
Definition: test.h:196
static void unload_dynamic_module(struct ast_module *mod)
Definition: loader.c:1010
static struct ast_module * find_resource(const char *resource, int do_lock)
Definition: loader.c:937
int error(const char *format,...)
Definition: utils/frame.c:999
char resource[0]
Definition: loader.c:333
#define AST_DLLIST_LOCK(head)
Locks a list.
Definition: dlinkedlists.h:45

◆ ast_unregister_application()

int ast_unregister_application ( const char *  app)

Unregister an application.

Parameters
appname of the application (does not have to be the same string as the one that was registered)

This unregisters an application from Asterisk's internal application list.

Return values
0success
-1failure

Definition at line 392 of file pbx_app.c.

References ast_free, ast_rdlock_contexts(), AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_string_field_free_memory, ast_unlock_contexts(), ast_verb, NULL, and unreference_cached_app().

Referenced by __unload_module(), load_module(), message_shutdown(), unload_module(), unload_parking_applications(), unload_pbx_builtins(), and unload_pbx_variables().

393 {
394  struct ast_app *cur;
395  int cmp;
396 
397  /* Anticipate need for conlock in unreference_cached_app(), in order to avoid
398  * possible deadlock with pbx_extension_helper()/pbx_findapp()
399  */
401 
403  AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, cur, list) {
404  cmp = strcasecmp(app, cur->name);
405  if (cmp > 0) {
406  continue;
407  }
408  if (!cmp) {
409  /* Found it. */
412  ast_verb(2, "Unregistered application '%s'\n", cur->name);
414  ast_free(cur);
415  break;
416  }
417  /* Not in container. */
418  cur = NULL;
419  break;
420  }
423 
425 
426  return cur ? 0 : -1;
427 }
Registered applications container.
Definition: pbx_app.c:67
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
int ast_rdlock_contexts(void)
Read locks the context list.
Definition: pbx.c:8507
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:455
static const char app[]
Definition: app_adsiprog.c:56
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:569
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:8512
#define ast_free(a)
Definition: astmm.h:182
void unreference_cached_app(struct ast_app *app)
Definition: pbx.c:6179
ast_app: A registered application
Definition: pbx_app.c:45
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616

◆ ast_update_module_list()

int ast_update_module_list ( int(*)(const char *module, const char *description, int usecnt, const char *status, const char *like, enum ast_module_support_level support_level)  modentry,
const char *  like 
)

Ask for a list of modules, descriptions, use counts and status.

Parameters
modentryA callback to an updater function.
likeFor each of the modules loaded, modentry will be executed with the resource, description, and usecount values of each particular module.
Returns
the number of modules loaded

Definition at line 2567 of file loader.c.

References alpha_module_list_create(), AST_DLLIST_LOCK, AST_DLLIST_UNLOCK, AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_module_info::description, ast_module::flags, ast_module::info, ast_module::resource, ast_module::running, ast_module_info::support_level, and ast_module::usecount.

Referenced by ast_var_Modules(), and handle_modlist().

2571 {
2572  int total_mod_loaded = 0;
2573  struct module_vector alpha_module_list;
2574 
2576 
2577  if (!alpha_module_list_create(&alpha_module_list)) {
2578  int idx;
2579 
2580  for (idx = 0; idx < AST_VECTOR_SIZE(&alpha_module_list); idx++) {
2581  struct ast_module *cur = AST_VECTOR_GET(&alpha_module_list, idx);
2582 
2583  total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount,
2584  cur->flags.running ? "Running" : "Not Running", like, cur->info->support_level);
2585  }
2586  }
2587 
2589  AST_VECTOR_FREE(&alpha_module_list);
2590 
2591  return total_mod_loaded;
2592 }
const char * description
Definition: module.h:352
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174
unsigned int running
Definition: loader.c:320
#define AST_DLLIST_UNLOCK(head)
Attempts to unlock a list.
Definition: dlinkedlists.h:122
int usecount
Definition: loader.c:300
struct ast_module::@385 flags
const struct ast_module_info * info
Definition: loader.c:294
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
static int alpha_module_list_create(struct module_vector *alpha_module_list)
Definition: loader.c:2550
enum ast_module_support_level support_level
Definition: module.h:416
char resource[0]
Definition: loader.c:333
#define AST_DLLIST_LOCK(head)
Locks a list.
Definition: dlinkedlists.h:45
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611

◆ ast_update_module_list_condition()

int ast_update_module_list_condition ( int(*)(const char *module, const char *description, int usecnt, const char *status, const char *like, enum ast_module_support_level support_level, void *data, const char *condition)  modentry,
const char *  like,
void *  data,
const char *  condition 
)

Ask for a list of modules, descriptions, use counts and status.

Parameters
modentryA callback to an updater function
like
dataData passed into the callback for manipulation
conditionThe condition to meet

For each of the modules loaded, modentry will be executed with the resource, description, and usecount values of each particular module.

Returns
the number of conditions met
Since
13.5.0

Definition at line 2622 of file loader.c.

References alpha_module_list_create(), AST_DLLIST_LOCK, AST_DLLIST_UNLOCK, AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_module_info::description, ast_module::flags, ast_module::info, ast_module::resource, ast_module::running, ast_module_info::support_level, and ast_module::usecount.

Referenced by ast_ari_asterisk_get_module().

2628 {
2629  int conditions_met = 0;
2630  struct module_vector alpha_module_list;
2631 
2633 
2634  if (!alpha_module_list_create(&alpha_module_list)) {
2635  int idx;
2636 
2637  for (idx = 0; idx < AST_VECTOR_SIZE(&alpha_module_list); idx++) {
2638  struct ast_module *cur = AST_VECTOR_GET(&alpha_module_list, idx);
2639 
2640  conditions_met += modentry(cur->resource, cur->info->description, cur->usecount,
2641  cur->flags.running? "Running" : "Not Running", like, cur->info->support_level, data,
2642  condition);
2643  }
2644  }
2645 
2647  AST_VECTOR_FREE(&alpha_module_list);
2648 
2649  return conditions_met;
2650 }
const char * description
Definition: module.h:352
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174
unsigned int running
Definition: loader.c:320
#define AST_DLLIST_UNLOCK(head)
Attempts to unlock a list.
Definition: dlinkedlists.h:122
int usecount
Definition: loader.c:300
struct ast_module::@385 flags
const struct ast_module_info * info
Definition: loader.c:294
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
static int alpha_module_list_create(struct module_vector *alpha_module_list)
Definition: loader.c:2550
enum ast_module_support_level support_level
Definition: module.h:416
char resource[0]
Definition: loader.c:333
#define AST_DLLIST_LOCK(head)
Locks a list.
Definition: dlinkedlists.h:45
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611

◆ ast_update_module_list_data()

int ast_update_module_list_data ( int(*)(const char *module, const char *description, int usecnt, const char *status, const char *like, enum ast_module_support_level support_level, void *data)  modentry,
const char *  like,
void *  data 
)

Ask for a list of modules, descriptions, use counts and status.

Parameters
modentryA callback to an updater function
like
dataData passed into the callback for manipulation

For each of the modules loaded, modentry will be executed with the resource, description, and usecount values of each particular module.

Returns
the number of modules loaded
Since
13.5.0

Definition at line 2594 of file loader.c.

References alpha_module_list_create(), AST_DLLIST_LOCK, AST_DLLIST_UNLOCK, AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_module_info::description, ast_module::flags, ast_module::info, ast_module::resource, ast_module::running, ast_module_info::support_level, and ast_module::usecount.

Referenced by ast_ari_asterisk_list_modules().

2599 {
2600  int total_mod_loaded = 0;
2601  struct module_vector alpha_module_list;
2602 
2604 
2605  if (!alpha_module_list_create(&alpha_module_list)) {
2606  int idx;
2607 
2608  for (idx = 0; idx < AST_VECTOR_SIZE(&alpha_module_list); idx++) {
2609  struct ast_module *cur = AST_VECTOR_GET(&alpha_module_list, idx);
2610 
2611  total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount,
2612  cur->flags.running? "Running" : "Not Running", like, cur->info->support_level, data);
2613  }
2614  }
2615 
2617  AST_VECTOR_FREE(&alpha_module_list);
2618 
2619  return total_mod_loaded;
2620 }
const char * description
Definition: module.h:352
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174
unsigned int running
Definition: loader.c:320
#define AST_DLLIST_UNLOCK(head)
Attempts to unlock a list.
Definition: dlinkedlists.h:122
int usecount
Definition: loader.c:300
struct ast_module::@385 flags
const struct ast_module_info * info
Definition: loader.c:294
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
static int alpha_module_list_create(struct module_vector *alpha_module_list)
Definition: loader.c:2550
enum ast_module_support_level support_level
Definition: module.h:416
char resource[0]
Definition: loader.c:333
#define AST_DLLIST_LOCK(head)
Locks a list.
Definition: dlinkedlists.h:45
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611

◆ ast_update_use_count()

void ast_update_use_count ( void  )

Notify when usecount has been changed.

This function calulates use counts and notifies anyone trying to keep track of them. It should be called whenever your module's usecount changes.

Note
The ast_module_user_* functions take care of calling this function for you.

Definition at line 2528 of file loader.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, and loadupdate::updater.

Referenced by __ast_module_ref(), __ast_module_unref(), __ast_module_user_add(), __ast_module_user_hangup_all(), __ast_module_user_remove(), ast_unload_resource(), handle_request_do(), ooh323_hangup(), ooh323_new(), ooh323c_call_thread(), sip_request_call(), start_resource(), and unistim_new().

2529 {
2530  /* Notify any module monitors that the use count for a
2531  resource has changed */
2532  struct loadupdate *m;
2533 
2536  m->updater();
2538 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
int(* updater)(void)
Definition: loader.c:625
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
Definition: search.h:40

Variable Documentation

◆ ast_module_info

const struct ast_module_info* ast_module_info
static

Definition at line 540 of file module.h.