Asterisk module definitions. More...
#include "asterisk/utils.h"
Go to the source code of this file.
Data Structures | |
| struct | ast_module_info |
Defines | |
| #define | __MODULE_INFO_GLOBALS |
| #define | __MODULE_INFO_SECTION |
| #define | AST_MODULE_CONFIG "modules.conf" |
| Module configuration file. | |
| #define | AST_MODULE_INFO(keystr, flags_to_set, desc, fields...) |
| #define | AST_MODULE_INFO_STANDARD(keystr, desc) |
| #define | ast_module_user_add(chan) __ast_module_user_add(ast_module_info->self, chan) |
| #define | ast_module_user_hangup_all() __ast_module_user_hangup_all(ast_module_info->self) |
| #define | ast_module_user_remove(user) __ast_module_user_remove(ast_module_info->self, user) |
| #define | ast_register_application(app, execute, synopsis, description) ast_register_application2(app, execute, synopsis, description, ast_module_info->self) |
| Register an application. | |
| #define | ast_register_application_xml(app, execute) ast_register_application(app, execute, NULL, NULL) |
| Register an application using XML documentation. | |
| #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. | |
Enumerations | |
| enum | ast_module_flags { AST_MODFLAG_DEFAULT = 0, AST_MODFLAG_GLOBAL_SYMBOLS = (1 << 0), AST_MODFLAG_LOAD_ORDER = (1 << 1) } |
| enum | ast_module_load_priority { AST_MODPRI_REALTIME_DEPEND = 10, AST_MODPRI_REALTIME_DEPEND2 = 20, AST_MODPRI_REALTIME_DRIVER = 30, AST_MODPRI_CHANNEL_DEPEND = 50, AST_MODPRI_CHANNEL_DRIVER = 60, AST_MODPRI_APP_DEPEND = 70, AST_MODPRI_DEVSTATE_PROVIDER = 80, AST_MODPRI_DEVSTATE_PLUGIN = 90, AST_MODPRI_CDR_DRIVER = 100, 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_unload_mode { AST_FORCE_SOFT = 0, AST_FORCE_FIRM = 1, AST_FORCE_HARD = 2 } |
Functions | |
| 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. | |
| int | ast_loader_register (int(*updater)(void)) |
| Add a procedure to be run when modules have been updated. | |
| int | ast_loader_unregister (int(*updater)(void)) |
| Remove a procedure to be run when modules are updated. | |
| int | ast_module_check (const char *name) |
| Check if module with the name given is loaded. | |
| char * | ast_module_helper (const char *line, const char *word, int pos, int state, int rpos, int needsreload) |
| Match modules names for the Asterisk cli. | |
| struct ast_module * | ast_module_ref (struct ast_module *) |
| void | ast_module_register (const struct ast_module_info *) |
| void | ast_module_shutdown (void) |
| Run the unload() callback for all loaded modules. | |
| void | ast_module_unref (struct ast_module *) |
| 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. | |
| int | ast_unload_resource (const char *resource_name, enum ast_module_unload_mode) |
| Unload a module. | |
| int | ast_unregister_application (const char *app) |
| Unregister an application. | |
| int | ast_update_module_list (int(*modentry)(const char *module, const char *description, int usecnt, const char *like), const char *like) |
| Ask for a list of modules, descriptions, and use counts. | |
| void | ast_update_use_count (void) |
| Notify when usecount has been changed. | |
Variables | |
| static struct ast_module_info * | ast_module_info |
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.
| #define AST_MODULE_CONFIG "modules.conf" |
| #define AST_MODULE_INFO | ( | keystr, | |
| flags_to_set, | |||
| desc, | |||
| fields... | |||
| ) |
| #define AST_MODULE_INFO_STANDARD | ( | keystr, | |
| desc | |||
| ) |
AST_MODULE_INFO(keystr, AST_MODFLAG_LOAD_ORDER, desc, \ .load = load_module, \ .unload = unload_module, \ .load_pri = AST_MODPRI_DEFAULT, \ )
| #define ast_module_user_add | ( | chan | ) | __ast_module_user_add(ast_module_info->self, chan) |
Definition at line 259 of file module.h.
Referenced by login_exec(), local_new(), nbs_new(), dundifunc_read(), dundi_query_read(), dundi_result_read(), exists(), canmatch(), matchmore(), exec(), smdi_msg_retrieve_read(), and smdi_msg_read().
| #define ast_module_user_hangup_all | ( | ) | __ast_module_user_hangup_all(ast_module_info->self) |
Definition at line 261 of file module.h.
Referenced by unload_module().
| #define ast_module_user_remove | ( | user | ) | __ast_module_user_remove(ast_module_info->self, user) |
Definition at line 260 of file module.h.
Referenced by login_exec(), local_hangup(), nbs_destroy(), dundifunc_read(), dundi_query_read(), dundi_result_read(), exists(), canmatch(), matchmore(), exec(), smdi_msg_retrieve_read(), and smdi_msg_read().
| #define ast_register_application | ( | app, | |
| execute, | |||
| synopsis, | |||
| description | |||
| ) | ast_register_application2(app, execute, synopsis, description, ast_module_info->self) |
Register an application.
| app | Short name of the application |
| execute | a function callback to execute the application. It should return non-zero if the channel needs to be hung up. |
| synopsis | a short description (one line synopsis) of the application |
| description | long description with all of the details about the use of the application |
This registers an application with Asterisk's internal application list.
| 0 | success |
| -1 | failure. |
Definition at line 412 of file module.h.
Referenced by load_module().
| #define ast_register_application_xml | ( | app, | |
| execute | |||
| ) | ast_register_application(app, execute, NULL, NULL) |
Register an application using XML documentation.
| app | Short name of the application |
| execute | a 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.
| 0 | success |
| -1 | failure. |
Definition at line 428 of file module.h.
Referenced by load_module().
| #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" |
| enum ast_module_flags |
Definition at line 190 of file module.h.
{
AST_MODFLAG_DEFAULT = 0,
AST_MODFLAG_GLOBAL_SYMBOLS = (1 << 0),
AST_MODFLAG_LOAD_ORDER = (1 << 1),
};
Definition at line 196 of file module.h.
{
AST_MODPRI_REALTIME_DEPEND = 10, /*!< Dependency for a realtime driver */
AST_MODPRI_REALTIME_DEPEND2 = 20, /*!< Second level dependency for a realtime driver (func_curl needs res_curl, but is needed by res_config_curl) */
AST_MODPRI_REALTIME_DRIVER = 30, /*!< A realtime driver, which provides configuration services for other modules */
AST_MODPRI_CHANNEL_DEPEND = 50, /*!< Channel driver dependency (may depend upon realtime, e.g. MOH) */
AST_MODPRI_CHANNEL_DRIVER = 60, /*!< Channel drivers (provide devicestate) */
AST_MODPRI_APP_DEPEND = 70, /*!< Dependency for an application */
AST_MODPRI_DEVSTATE_PROVIDER = 80, /*!< Applications and other modules that _provide_ devicestate (e.g. meetme) */
AST_MODPRI_DEVSTATE_PLUGIN = 90, /*!< Plugin for a module that provides devstate (e.g. res_calendar_*) */
AST_MODPRI_CDR_DRIVER = 100, /*!< CDR or CEL backend */
AST_MODPRI_DEFAULT = 128, /*!< Modules not otherwise defined (such as most apps) will load here */
AST_MODPRI_DEVSTATE_CONSUMER = 150, /*!< Certain modules, which consume devstate, need to load after all others (e.g. app_queue) */
};
Definition at line 60 of file module.h.
{
AST_MODULE_LOAD_SUCCESS = 0, /*!< Module loaded and configured */
AST_MODULE_LOAD_DECLINE = 1, /*!< Module is not configured */
AST_MODULE_LOAD_SKIP = 2, /*!< Module was skipped for some reason */
AST_MODULE_LOAD_PRIORITY = 3, /*!< Module is not loaded yet, but is added to prioity heap */
AST_MODULE_LOAD_FAILURE = -1, /*!< Module could not be loaded properly */
};
Definition at line 53 of file module.h.
{
AST_FORCE_SOFT = 0, /*!< Softly unload a module, only if not in use */
AST_FORCE_FIRM = 1, /*!< Firmly unload a module, even if in use */
AST_FORCE_HARD = 2, /*!< as FIRM, plus dlclose() on the module. Not recommended
as it may cause crashes */
};
| struct ast_module_user* __ast_module_user_add | ( | struct ast_module * | , |
| struct ast_channel * | |||
| ) | [read] |
Definition at line 195 of file loader.c.
References ast_calloc, ast_module_user::chan, AST_LIST_LOCK, ast_module::users, AST_LIST_INSERT_HEAD, AST_LIST_UNLOCK, ast_atomic_fetchadd_int(), ast_module::usecount, and ast_update_use_count().
Referenced by pbx_exec(), ast_func_read(), ast_func_read2(), and ast_func_write().
{
struct ast_module_user *u = ast_calloc(1, sizeof(*u));
if (!u)
return NULL;
u->chan = chan;
AST_LIST_LOCK(&mod->users);
AST_LIST_INSERT_HEAD(&mod->users, u, entry);
AST_LIST_UNLOCK(&mod->users);
ast_atomic_fetchadd_int(&mod->usecount, +1);
ast_update_use_count();
return u;
}
| void __ast_module_user_hangup_all | ( | struct ast_module * | ) |
Definition at line 227 of file loader.c.
References AST_LIST_LOCK, ast_module::users, AST_LIST_REMOVE_HEAD, ast_softhangup(), ast_module_user::chan, AST_SOFTHANGUP_APPUNLOAD, ast_atomic_fetchadd_int(), ast_module::usecount, ast_free, AST_LIST_UNLOCK, and ast_update_use_count().
Referenced by ast_unload_resource().
{
struct ast_module_user *u;
AST_LIST_LOCK(&mod->users);
while ((u = AST_LIST_REMOVE_HEAD(&mod->users, entry))) {
ast_softhangup(u->chan, AST_SOFTHANGUP_APPUNLOAD);
ast_atomic_fetchadd_int(&mod->usecount, -1);
ast_free(u);
}
AST_LIST_UNLOCK(&mod->users);
ast_update_use_count();
}
| void __ast_module_user_remove | ( | struct ast_module * | , |
| struct ast_module_user * | |||
| ) |
Definition at line 216 of file loader.c.
References AST_LIST_LOCK, ast_module::users, AST_LIST_REMOVE, AST_LIST_UNLOCK, ast_atomic_fetchadd_int(), ast_module::usecount, ast_free, and ast_update_use_count().
Referenced by pbx_exec(), ast_func_read(), ast_func_read2(), and ast_func_write().
{
AST_LIST_LOCK(&mod->users);
AST_LIST_REMOVE(&mod->users, u, entry);
AST_LIST_UNLOCK(&mod->users);
ast_atomic_fetchadd_int(&mod->usecount, -1);
ast_free(u);
ast_update_use_count();
}
| enum ast_module_load_result ast_load_resource | ( | const char * | resource_name | ) |
Load a module.
| resource_name | The 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.
Definition at line 876 of file loader.c.
References AST_LIST_LOCK, load_resource(), and AST_LIST_UNLOCK.
Referenced by handle_load(), load_module(), and manager_moduleload().
{
int res;
AST_LIST_LOCK(&module_list);
res = load_resource(resource_name, 0, NULL, 0);
AST_LIST_UNLOCK(&module_list);
return res;
}
| int ast_loader_register | ( | int(*)(void) | updater | ) |
Add a procedure to be run when modules have been updated.
| updater | The 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.
| 0 | on success |
| -1 | on failure. |
Definition at line 1192 of file loader.c.
References ast_malloc, loadupdate::updater, AST_LIST_LOCK, AST_LIST_INSERT_HEAD, and AST_LIST_UNLOCK.
{
struct loadupdate *tmp;
if (!(tmp = ast_malloc(sizeof(*tmp))))
return -1;
tmp->updater = v;
AST_LIST_LOCK(&updaters);
AST_LIST_INSERT_HEAD(&updaters, tmp, entry);
AST_LIST_UNLOCK(&updaters);
return 0;
}
| int ast_loader_unregister | ( | int(*)(void) | updater | ) |
Remove a procedure to be run when modules are updated.
| updater | The updater function to unregister. |
This removes the given function from the updater list.
| 0 | on success |
| -1 | on failure. |
Definition at line 1207 of file loader.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE_SAFE_BEGIN, loadupdate::updater, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_END, and AST_LIST_UNLOCK.
{
struct loadupdate *cur;
AST_LIST_LOCK(&updaters);
AST_LIST_TRAVERSE_SAFE_BEGIN(&updaters, cur, entry) {
if (cur->updater == v) {
AST_LIST_REMOVE_CURRENT(entry);
break;
}
}
AST_LIST_TRAVERSE_SAFE_END;
AST_LIST_UNLOCK(&updaters);
return cur ? 0 : -1;
}
| int ast_module_check | ( | const char * | name | ) |
Check if module with the name given is loaded.
| name | Module name, like "chan_sip.so" |
| 1 | if true |
| 0 | if false |
Definition at line 1179 of file loader.c.
References ast_strlen_zero(), and find_resource().
Referenced by load_module(), ifmodule_read(), manager_modulecheck(), and unload_module().
{
struct ast_module *cur;
if (ast_strlen_zero(name))
return 0; /* FALSE */
cur = find_resource(name, 1);
return (cur != NULL);
}
| char* ast_module_helper | ( | const char * | line, |
| const char * | word, | ||
| int | pos, | ||
| int | state, | ||
| int | rpos, | ||
| int | needsreload | ||
| ) |
Match modules names for the Asterisk cli.
| line | Unused by this function, but this should be the line we are matching. |
| word | The partial name to match. |
| pos | The position the word we are completing is in. |
| state | The possible match to return. |
| rpos | The position we should be matching. This should be the same as pos. |
| needsreload | This should be 1 if we need to reload this module and 0 otherwise. This function will only return modules that are reloadble if this is 1. |
| A | possible completion of the partial match. |
| NULL | if no matches were found. |
Definition at line 565 of file loader.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, ast_module::resource, ast_module::info, ast_module_info::reload, ast_strdup, AST_LIST_UNLOCK, reload_classes::name, and name.
Referenced by conf_run(), load_module(), handle_reload(), handle_unload(), and handle_modlist().
{
struct ast_module *cur;
int i, which=0, l = strlen(word);
char *ret = NULL;
if (pos != rpos)
return NULL;
AST_LIST_LOCK(&module_list);
AST_LIST_TRAVERSE(&module_list, cur, entry) {
if (!strncasecmp(word, cur->resource, l) &&
(cur->info->reload || !needsreload) &&
++which > state) {
ret = ast_strdup(cur->resource);
break;
}
}
AST_LIST_UNLOCK(&module_list);
if (!ret) {
for (i=0; !ret && reload_classes[i].name; i++) {
if (!strncasecmp(word, reload_classes[i].name, l) && ++which > state)
ret = ast_strdup(reload_classes[i].name);
}
}
return ret;
}
| struct ast_module* ast_module_ref | ( | struct ast_module * | ) | [read] |
Definition at line 1224 of file loader.c.
References ast_atomic_fetchadd_int(), ast_module::usecount, and ast_update_use_count().
Referenced by load_module(), find_best_technology(), alsa_new(), my_module_ref(), dahdi_new(), gtalk_new(), __oh323_new(), ast_iax2_new(), mgcp_new(), oss_new(), phone_new(), phone_check_exception(), sip_handle_cc(), sip_new(), skinny_new(), usbradio_new(), data_result_generate_node(), fn_wrapper(), ast_agi_register(), agi_handle_command(), handle_orig(), handle_cli_file_convert(), ast_fax_tech_register(), fax_session_reserve(), fax_session_new(), moh_files_alloc(), moh_alloc(), mute_add_audiohook(), smdi_load(), ast_srtp_create(), ast_rtp_instance_new(), ast_timer_open(), and newpvt().
{
if (!mod) {
return NULL;
}
ast_atomic_fetchadd_int(&mod->usecount, +1);
ast_update_use_count();
return mod;
}
| void ast_module_register | ( | const struct ast_module_info * | ) |
Definition at line 133 of file loader.c.
References embedding, ast_calloc, ast_module::resource, resource_being_loaded, ast_module::info, AST_LIST_HEAD_INIT, ast_module::users, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, and AST_LIST_UNLOCK.
{
struct ast_module *mod;
if (embedding) {
if (!(mod = ast_calloc(1, sizeof(*mod) + strlen(info->name) + 1)))
return;
strcpy(mod->resource, info->name);
} else {
mod = resource_being_loaded;
}
mod->info = info;
AST_LIST_HEAD_INIT(&mod->users);
/* during startup, before the loader has been initialized,
there are no threads, so there is no need to take the lock
on this list to manipulate it. it is also possible that it
might be unsafe to use the list lock at that point... so
let's avoid it altogether
*/
if (embedding) {
AST_LIST_INSERT_TAIL(&embedded_module_list, mod, entry);
} else {
AST_LIST_LOCK(&module_list);
/* it is paramount that the new entry be placed at the tail of
the list, otherwise the code that uses dlopen() to load
dynamic modules won't be able to find out if the module it
just opened was registered or failed to load
*/
AST_LIST_INSERT_TAIL(&module_list, mod, entry);
AST_LIST_UNLOCK(&module_list);
}
/* give the module a copy of its own handle, for later use in registrations and the like */
*((struct ast_module **) &(info->self)) = mod;
}
| void ast_module_shutdown | ( | void | ) |
Run the unload() callback for all loaded modules.
This function should be called when Asterisk is shutting down gracefully.
Definition at line 465 of file loader.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE_SAFE_BEGIN, ast_module::usecount, AST_LIST_REMOVE_CURRENT, ast_module::flags, ast_module::running, ast_module::declined, ast_module::info, ast_module_info::unload, AST_LIST_HEAD_DESTROY, ast_module::users, free, AST_LIST_TRAVERSE_SAFE_END, and AST_LIST_UNLOCK.
Referenced by quit_handler().
{
struct ast_module *mod;
int somethingchanged = 1, final = 0;
AST_LIST_LOCK(&module_list);
/*!\note Some resources, like timers, are started up dynamically, and thus
* may be still in use, even if all channels are dead. We must therefore
* check the usecount before asking modules to unload. */
do {
if (!somethingchanged) {
/*!\note If we go through the entire list without changing
* anything, ignore the usecounts and unload, then exit. */
final = 1;
}
/* Reset flag before traversing the list */
somethingchanged = 0;
AST_LIST_TRAVERSE_SAFE_BEGIN(&module_list, mod, entry) {
if (!final && mod->usecount) {
continue;
}
AST_LIST_REMOVE_CURRENT(entry);
if (mod->flags.running && !mod->flags.declined && mod->info->unload) {
mod->info->unload();
}
AST_LIST_HEAD_DESTROY(&mod->users);
free(mod);
somethingchanged = 1;
}
AST_LIST_TRAVERSE_SAFE_END;
} while (somethingchanged && !final);
AST_LIST_UNLOCK(&module_list);
}
| void ast_module_unref | ( | struct ast_module * | ) |
Definition at line 1236 of file loader.c.
References ast_atomic_fetchadd_int(), ast_module::usecount, and ast_update_use_count().
Referenced by destroy_bridge(), ast_bridge_check(), smart_bridge_operation(), alsa_hangup(), my_module_unref(), dahdi_hangup(), dahdi_destroy_channel_bynum(), gtalk_hangup(), oh323_hangup(), iax2_predestroy(), mgcp_hangup(), oss_hangup(), phone_hangup(), phone_check_exception(), sip_cc_monitor_destructor(), sip_hangup(), skinny_hangup(), usbradio_hangup(), data_result_generate_node(), filestream_destructor(), ast_agi_unregister(), agi_handle_command(), handle_orig(), handle_cli_file_convert(), ast_fax_tech_unregister(), destroy_session(), local_ast_moh_cleanup(), destroy_callback(), ast_smdi_interface_destroy(), ast_srtp_destroy(), instance_destructor(), ast_rtp_instance_new(), ast_timer_close(), and destroy().
{
if (!mod) {
return;
}
ast_atomic_fetchadd_int(&mod->usecount, -1);
ast_update_use_count();
}
| void ast_module_unregister | ( | const struct ast_module_info * | ) |
Definition at line 171 of file loader.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE_SAFE_BEGIN, ast_module::info, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, AST_LIST_HEAD_DESTROY, ast_module::users, and ast_free.
{
struct ast_module *mod = NULL;
/* it is assumed that the users list in the module structure
will already be empty, or we cannot have gotten to this
point
*/
AST_LIST_LOCK(&module_list);
AST_LIST_TRAVERSE_SAFE_BEGIN(&module_list, mod, entry) {
if (mod->info == info) {
AST_LIST_REMOVE_CURRENT(entry);
break;
}
}
AST_LIST_TRAVERSE_SAFE_END;
AST_LIST_UNLOCK(&module_list);
if (mod) {
AST_LIST_HEAD_DESTROY(&mod->users);
ast_free(mod);
}
}
| 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.
| app | Short name of the application |
| execute | a function callback to execute the application. It should return non-zero if the channel needs to be hung up. |
| synopsis | a short description (one line synopsis) of the application |
| description | long description with all of the details about the use of the application |
| mod | module this application belongs to |
This registers an application with Asterisk's internal application list.
| 0 | success |
| -1 | failure. |
Definition at line 5643 of file pbx.c.
References AST_RWLIST_WRLOCK, AST_RWLIST_TRAVERSE, ast_log(), LOG_WARNING, AST_RWLIST_UNLOCK, ast_calloc, ast_string_field_init, ast_free, ast_strlen_zero(), ast_xmldoc_build_synopsis(), ast_string_field_set, ast_xmldoc_build_description(), ast_xmldoc_build_syntax(), ast_app::syntax, ast_xmldoc_build_arguments(), ast_app::arguments, ast_xmldoc_build_seealso(), ast_app::seealso, ast_app::docsrc, AST_XML_DOC, AST_STATIC_DOC, ast_app::execute, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_INSERT_BEFORE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_INSERT_TAIL, ast_verb, term_color(), and COLOR_BRCYAN.
Referenced by ast_cc_init(), ast_features_init(), and load_pbx().
{
struct ast_app *tmp, *cur = NULL;
char tmps[80];
int length, res;
#ifdef AST_XML_DOCS
char *tmpxml;
#endif
AST_RWLIST_WRLOCK(&apps);
AST_RWLIST_TRAVERSE(&apps, tmp, list) {
if (!(res = strcasecmp(app, tmp->name))) {
ast_log(LOG_WARNING, "Already have an application '%s'\n", app);
AST_RWLIST_UNLOCK(&apps);
return -1;
} else if (res < 0)
break;
}
length = sizeof(*tmp) + strlen(app) + 1;
if (!(tmp = ast_calloc(1, length))) {
AST_RWLIST_UNLOCK(&apps);
return -1;
}
if (ast_string_field_init(tmp, 128)) {
AST_RWLIST_UNLOCK(&apps);
ast_free(tmp);
return -1;
}
#ifdef AST_XML_DOCS
/* Try to lookup the docs in our XML documentation database */
if (ast_strlen_zero(synopsis) && ast_strlen_zero(description)) {
/* load synopsis */
tmpxml = ast_xmldoc_build_synopsis("application", app);
ast_string_field_set(tmp, synopsis, tmpxml);
ast_free(tmpxml);
/* load description */
tmpxml = ast_xmldoc_build_description("application", app);
ast_string_field_set(tmp, description, tmpxml);
ast_free(tmpxml);
/* load syntax */
tmpxml = ast_xmldoc_build_syntax("application", app);
ast_string_field_set(tmp, syntax, tmpxml);
ast_free(tmpxml);
/* load arguments */
tmpxml = ast_xmldoc_build_arguments("application", app);
ast_string_field_set(tmp, arguments, tmpxml);
ast_free(tmpxml);
/* load seealso */
tmpxml = ast_xmldoc_build_seealso("application", app);
ast_string_field_set(tmp, seealso, tmpxml);
ast_free(tmpxml);
tmp->docsrc = AST_XML_DOC;
} else {
#endif
ast_string_field_set(tmp, synopsis, synopsis);
ast_string_field_set(tmp, description, description);
#ifdef AST_XML_DOCS
tmp->docsrc = AST_STATIC_DOC;
}
#endif
strcpy(tmp->name, app);
tmp->execute = execute;
tmp->module = mod;
/* Store in alphabetical order */
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, cur, list) {
if (strcasecmp(tmp->name, cur->name) < 0) {
AST_RWLIST_INSERT_BEFORE_CURRENT(tmp, list);
break;
}
}
AST_RWLIST_TRAVERSE_SAFE_END;
if (!cur)
AST_RWLIST_INSERT_TAIL(&apps, tmp, list);
ast_verb(2, "Registered application '%s'\n", term_color(tmps, tmp->name, COLOR_BRCYAN, 0, sizeof(tmps)));
AST_RWLIST_UNLOCK(&apps);
return 0;
}
| int ast_unload_resource | ( | const char * | resource_name, |
| enum | ast_module_unload_mode | ||
| ) |
Unload a module.
| resource_name | The name of the module to unload. |
| ast_module_unload_mode | The 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).
| 0 | on success. |
| -1 | on error. |
Definition at line 503 of file loader.c.
References AST_LIST_LOCK, find_resource(), AST_LIST_UNLOCK, ast_log(), LOG_WARNING, ast_module::flags, ast_module::running, ast_module::declined, ast_module::usecount, __ast_module_user_hangup_all(), ast_module::info, ast_module_info::unload, AST_FORCE_FIRM, ast_module::lib, ast_module_info::restore_globals, unload_dynamic_module(), and ast_update_use_count().
Referenced by handle_unload(), manager_moduleload(), and unload_module().
{
struct ast_module *mod;
int res = -1;
int error = 0;
AST_LIST_LOCK(&module_list);
if (!(mod = find_resource(resource_name, 0))) {
AST_LIST_UNLOCK(&module_list);
ast_log(LOG_WARNING, "Unload failed, '%s' could not be found\n", resource_name);
return -1;
}
if (!mod->flags.running || mod->flags.declined) {
ast_log(LOG_WARNING, "Unload failed, '%s' is not loaded.\n", resource_name);
error = 1;
}
if (!error && (mod->usecount > 0)) {
if (force)
ast_log(LOG_WARNING, "Warning: Forcing removal of module '%s' with use count %d\n",
resource_name, mod->usecount);
else {
ast_log(LOG_WARNING, "Soft unload failed, '%s' has use count %d\n", resource_name,
mod->usecount);
error = 1;
}
}
if (!error) {
__ast_module_user_hangup_all(mod);
res = mod->info->unload();
if (res) {
ast_log(LOG_WARNING, "Firm unload failed for %s\n", resource_name);
if (force <= AST_FORCE_FIRM)
error = 1;
else
ast_log(LOG_WARNING, "** Dangerous **: Unloading resource anyway, at user request\n");
}
}
if (!error)
mod->flags.running = mod->flags.declined = 0;
AST_LIST_UNLOCK(&module_list);
if (!error && !mod->lib && mod->info && mod->info->restore_globals)
mod->info->restore_globals();
#ifdef LOADABLE_MODULES
if (!error)
unload_dynamic_module(mod);
#endif
if (!error)
ast_update_use_count();
return res;
}
| int ast_unregister_application | ( | const char * | app | ) |
Unregister an application.
| app | name 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.
| 0 | success |
| -1 | failure |
Definition at line 6984 of file pbx.c.
References AST_RWLIST_WRLOCK, AST_RWLIST_TRAVERSE_SAFE_BEGIN, unreference_cached_app(), AST_RWLIST_REMOVE_CURRENT, ast_verb, ast_string_field_free_memory, ast_free, AST_RWLIST_TRAVERSE_SAFE_END, and AST_RWLIST_UNLOCK.
Referenced by unload_module(), load_module(), and __unload_module().
{
struct ast_app *tmp;
AST_RWLIST_WRLOCK(&apps);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, tmp, list) {
if (!strcasecmp(app, tmp->name)) {
unreference_cached_app(tmp);
AST_RWLIST_REMOVE_CURRENT(list);
ast_verb(2, "Unregistered application '%s'\n", tmp->name);
ast_string_field_free_memory(tmp);
ast_free(tmp);
break;
}
}
AST_RWLIST_TRAVERSE_SAFE_END;
AST_RWLIST_UNLOCK(&apps);
return tmp ? 0 : -1;
}
| int ast_update_module_list | ( | int(*)(const char *module, const char *description, int usecnt, const char *like) | modentry, |
| const char * | like | ||
| ) |
Ask for a list of modules, descriptions, and use counts.
| modentry | A callback to an updater function. |
| like | For each of the modules loaded, modentry will be executed with the resource, description, and usecount values of each particular module. |
Definition at line 1158 of file loader.c.
References AST_LIST_TRYLOCK, AST_LIST_TRAVERSE, ast_module::resource, ast_module::info, ast_module_info::description, ast_module::usecount, and AST_LIST_UNLOCK.
Referenced by ast_var_Modules(), and handle_modlist().
{
struct ast_module *cur;
int unlock = -1;
int total_mod_loaded = 0;
if (AST_LIST_TRYLOCK(&module_list))
unlock = 0;
AST_LIST_TRAVERSE(&module_list, cur, entry) {
total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount, like);
}
if (unlock)
AST_LIST_UNLOCK(&module_list);
return total_mod_loaded;
}
| 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.
Definition at line 1146 of file loader.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, loadupdate::updater, and AST_LIST_UNLOCK.
Referenced by oh323_request(), handle_request_do(), sip_request_call(), unistim_new(), __ast_module_user_add(), __ast_module_user_remove(), __ast_module_user_hangup_all(), ast_unload_resource(), start_resource(), ast_module_ref(), and ast_module_unref().
{
/* Notify any module monitors that the use count for a
resource has changed */
struct loadupdate *m;
AST_LIST_LOCK(&updaters);
AST_LIST_TRAVERSE(&updaters, m, entry)
m->updater();
AST_LIST_UNLOCK(&updaters);
}
struct ast_module_info* ast_module_info [static] |