#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_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 |
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 | ) |
Value:
AST_MODULE_INFO(keystr, AST_MODFLAG_DEFAULT, desc, \ .load = load_module, \ .unload = unload_module, \ )
| #define ast_module_user_add | ( | chan | ) | __ast_module_user_add(ast_module_info->self, chan) |
Definition at line 240 of file module.h.
Referenced by canmatch(), dundi_query_read(), dundi_result_read(), dundifunc_read(), exec(), exists(), local_new(), login_exec(), matchmore(), nbs_new(), smdi_msg_read(), and smdi_msg_retrieve_read().
| #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) |
Definition at line 241 of file module.h.
Referenced by canmatch(), dundi_query_read(), dundi_result_read(), dundifunc_read(), exec(), exists(), local_hangup(), login_exec(), matchmore(), nbs_destroy(), smdi_msg_read(), and smdi_msg_retrieve_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 |
| 0 | success | |
| -1 | failure. |
Definition at line 390 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. |
| 0 | success | |
| -1 | failure. |
Definition at line 406 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.
00190 { 00191 AST_MODFLAG_DEFAULT = 0, 00192 AST_MODFLAG_GLOBAL_SYMBOLS = (1 << 0), 00193 AST_MODFLAG_LOAD_ORDER = (1 << 1), 00194 };
Definition at line 60 of file module.h.
00060 { 00061 AST_MODULE_LOAD_SUCCESS = 0, /*!< Module loaded and configured */ 00062 AST_MODULE_LOAD_DECLINE = 1, /*!< Module is not configured */ 00063 AST_MODULE_LOAD_SKIP = 2, /*!< Module was skipped for some reason */ 00064 AST_MODULE_LOAD_PRIORITY = 3, /*!< Module is not loaded yet, but is added to prioity heap */ 00065 AST_MODULE_LOAD_FAILURE = -1, /*!< Module could not be loaded properly */ 00066 };
Definition at line 53 of file module.h.
00053 { 00054 AST_FORCE_SOFT = 0, /*!< Softly unload a module, only if not in use */ 00055 AST_FORCE_FIRM = 1, /*!< Firmly unload a module, even if in use */ 00056 AST_FORCE_HARD = 2, /*!< as FIRM, plus dlclose() on the module. Not recommended 00057 as it may cause crashes */ 00058 };
| struct ast_module_user* __ast_module_user_add | ( | struct ast_module * | , | |
| struct ast_channel * | ||||
| ) | [read] |
Definition at line 194 of file loader.c.
References ast_atomic_fetchadd_int(), ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_update_use_count(), ast_module_user::chan, ast_module::usecount, and ast_module::users.
Referenced by ast_func_read(), ast_func_read2(), ast_func_write(), and pbx_exec().
00196 { 00197 struct ast_module_user *u = ast_calloc(1, sizeof(*u)); 00198 00199 if (!u) 00200 return NULL; 00201 00202 u->chan = chan; 00203 00204 AST_LIST_LOCK(&mod->users); 00205 AST_LIST_INSERT_HEAD(&mod->users, u, entry); 00206 AST_LIST_UNLOCK(&mod->users); 00207 00208 ast_atomic_fetchadd_int(&mod->usecount, +1); 00209 00210 ast_update_use_count(); 00211 00212 return u; 00213 }
| void __ast_module_user_hangup_all | ( | struct ast_module * | ) |
Definition at line 226 of file loader.c.
References 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::usecount, and ast_module::users.
Referenced by ast_unload_resource().
00227 { 00228 struct ast_module_user *u; 00229 00230 AST_LIST_LOCK(&mod->users); 00231 while ((u = AST_LIST_REMOVE_HEAD(&mod->users, entry))) { 00232 ast_softhangup(u->chan, AST_SOFTHANGUP_APPUNLOAD); 00233 ast_atomic_fetchadd_int(&mod->usecount, -1); 00234 ast_free(u); 00235 } 00236 AST_LIST_UNLOCK(&mod->users); 00237 00238 ast_update_use_count(); 00239 }
| void __ast_module_user_remove | ( | struct ast_module * | , | |
| struct ast_module_user * | ||||
| ) |
Definition at line 215 of file loader.c.
References ast_atomic_fetchadd_int(), ast_free, AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, ast_update_use_count(), ast_module::usecount, and ast_module::users.
Referenced by ast_func_read(), ast_func_read2(), ast_func_write(), and pbx_exec().
00216 { 00217 AST_LIST_LOCK(&mod->users); 00218 AST_LIST_REMOVE(&mod->users, u, entry); 00219 AST_LIST_UNLOCK(&mod->users); 00220 ast_atomic_fetchadd_int(&mod->usecount, -1); 00221 ast_free(u); 00222 00223 ast_update_use_count(); 00224 }
| enum ast_module_load_result ast_load_resource | ( | const char * | resource_name | ) |
Load a module.
| resource_name | The name of the module to load. |
Definition at line 817 of file loader.c.
References AST_LIST_LOCK, AST_LIST_UNLOCK, and load_resource().
Referenced by file_ok_sel(), handle_load(), load_module(), manager_moduleload(), and reload().
00818 { 00819 int res; 00820 AST_LIST_LOCK(&module_list); 00821 res = load_resource(resource_name, 0, NULL); 00822 AST_LIST_UNLOCK(&module_list); 00823 00824 return res; 00825 }
| 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. |
| 0 | on success | |
| -1 | on failure. |
Definition at line 1117 of file loader.c.
References AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_malloc, and loadupdate::updater.
Referenced by show_console().
01118 { 01119 struct loadupdate *tmp; 01120 01121 if (!(tmp = ast_malloc(sizeof(*tmp)))) 01122 return -1; 01123 01124 tmp->updater = v; 01125 AST_LIST_LOCK(&updaters); 01126 AST_LIST_INSERT_HEAD(&updaters, tmp, entry); 01127 AST_LIST_UNLOCK(&updaters); 01128 01129 return 0; 01130 }
| int ast_loader_unregister | ( | int(*)(void) | updater | ) |
Remove a procedure to be run when modules are updated.
| updater | The updater function to unregister. |
| 0 | on success | |
| -1 | on failure. |
Definition at line 1132 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.
Referenced by exit_now().
01133 { 01134 struct loadupdate *cur; 01135 01136 AST_LIST_LOCK(&updaters); 01137 AST_LIST_TRAVERSE_SAFE_BEGIN(&updaters, cur, entry) { 01138 if (cur->updater == v) { 01139 AST_LIST_REMOVE_CURRENT(entry); 01140 break; 01141 } 01142 } 01143 AST_LIST_TRAVERSE_SAFE_END; 01144 AST_LIST_UNLOCK(&updaters); 01145 01146 return cur ? 0 : -1; 01147 }
| 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 1104 of file loader.c.
References ast_strlen_zero(), and find_resource().
Referenced by ifmodule_read(), load_module(), manager_modulecheck(), and unload_module().
01105 { 01106 struct ast_module *cur; 01107 01108 if (ast_strlen_zero(name)) 01109 return 0; /* FALSE */ 01110 01111 cur = find_resource(name, 1); 01112 01113 return (cur != NULL); 01114 }
| 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 528 of file loader.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strdup, ast_module::info, name, ast_module_info::reload, and ast_module::resource.
Referenced by conf_run(), handle_modlist(), handle_reload(), handle_unload(), and load_module().
00529 { 00530 struct ast_module *cur; 00531 int i, which=0, l = strlen(word); 00532 char *ret = NULL; 00533 00534 if (pos != rpos) 00535 return NULL; 00536 00537 AST_LIST_LOCK(&module_list); 00538 AST_LIST_TRAVERSE(&module_list, cur, entry) { 00539 if (!strncasecmp(word, cur->resource, l) && 00540 (cur->info->reload || !needsreload) && 00541 ++which > state) { 00542 ret = ast_strdup(cur->resource); 00543 break; 00544 } 00545 } 00546 AST_LIST_UNLOCK(&module_list); 00547 00548 if (!ret) { 00549 for (i=0; !ret && reload_classes[i].name; i++) { 00550 if (!strncasecmp(word, reload_classes[i].name, l) && ++which > state) 00551 ret = ast_strdup(reload_classes[i].name); 00552 } 00553 } 00554 00555 return ret; 00556 }
| struct ast_module* ast_module_ref | ( | struct ast_module * | ) | [read] |
Definition at line 1149 of file loader.c.
References ast_atomic_fetchadd_int(), ast_update_use_count(), and ast_module::usecount.
Referenced by __oh323_new(), agi_handle_command(), alsa_new(), ast_agi_register(), ast_iax2_new(), ast_rtp_instance_new(), ast_timer_open(), dahdi_new(), find_best_technology(), fn_wrapper(), gtalk_new(), handle_cli_file_convert(), handle_orig(), load_module(), mgcp_new(), mute_add_audiohook(), newpvt(), oss_new(), phone_check_exception(), phone_new(), sip_new(), skinny_new(), smdi_load(), and usbradio_new().
01150 { 01151 ast_atomic_fetchadd_int(&mod->usecount, +1); 01152 ast_update_use_count(); 01153 01154 return mod; 01155 }
| void ast_module_register | ( | const struct ast_module_info * | ) |
Definition at line 132 of file loader.c.
References ast_calloc, AST_LIST_HEAD_INIT, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, embedding, ast_module::info, ast_module::resource, and ast_module::users.
00133 { 00134 struct ast_module *mod; 00135 00136 if (embedding) { 00137 if (!(mod = ast_calloc(1, sizeof(*mod) + strlen(info->name) + 1))) 00138 return; 00139 strcpy(mod->resource, info->name); 00140 } else { 00141 mod = resource_being_loaded; 00142 } 00143 00144 mod->info = info; 00145 AST_LIST_HEAD_INIT(&mod->users); 00146 00147 /* during startup, before the loader has been initialized, 00148 there are no threads, so there is no need to take the lock 00149 on this list to manipulate it. it is also possible that it 00150 might be unsafe to use the list lock at that point... so 00151 let's avoid it altogether 00152 */ 00153 if (embedding) { 00154 AST_LIST_INSERT_TAIL(&embedded_module_list, mod, entry); 00155 } else { 00156 AST_LIST_LOCK(&module_list); 00157 /* it is paramount that the new entry be placed at the tail of 00158 the list, otherwise the code that uses dlopen() to load 00159 dynamic modules won't be able to find out if the module it 00160 just opened was registered or failed to load 00161 */ 00162 AST_LIST_INSERT_TAIL(&module_list, mod, entry); 00163 AST_LIST_UNLOCK(&module_list); 00164 } 00165 00166 /* give the module a copy of its own handle, for later use in registrations and the like */ 00167 *((struct ast_module **) &(info->self)) = mod; 00168 }
| 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 443 of file loader.c.
References AST_LIST_HEAD_DESTROY, AST_LIST_HEAD_NOLOCK_STATIC, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, free, ast_module::info, ast_module_info::unload, and ast_module::users.
Referenced by quit_handler().
00444 { 00445 struct ast_module *mod; 00446 AST_LIST_HEAD_NOLOCK_STATIC(local_module_list, ast_module); 00447 00448 /* We have to call the unload() callbacks in reverse order that the modules 00449 * exist in the module list so it is the reverse order of how they were 00450 * loaded. */ 00451 00452 AST_LIST_LOCK(&module_list); 00453 while ((mod = AST_LIST_REMOVE_HEAD(&module_list, entry))) 00454 AST_LIST_INSERT_HEAD(&local_module_list, mod, entry); 00455 AST_LIST_UNLOCK(&module_list); 00456 00457 while ((mod = AST_LIST_REMOVE_HEAD(&local_module_list, entry))) { 00458 if (mod->info->unload) 00459 mod->info->unload(); 00460 /* Since this should only be called when shutting down "gracefully", 00461 * all channels should be down before we get to this point, meaning 00462 * there will be no module users left. */ 00463 AST_LIST_HEAD_DESTROY(&mod->users); 00464 free(mod); 00465 } 00466 }
| void ast_module_unref | ( | struct ast_module * | ) |
Definition at line 1157 of file loader.c.
References ast_atomic_fetchadd_int(), ast_update_use_count(), and ast_module::usecount.
Referenced by agi_handle_command(), alsa_hangup(), ast_agi_unregister(), ast_bridge_check(), ast_rtp_instance_new(), ast_smdi_interface_destroy(), ast_timer_close(), dahdi_destroy_channel_bynum(), dahdi_hangup(), destroy(), destroy_bridge(), destroy_callback(), filestream_destructor(), gtalk_hangup(), handle_cli_file_convert(), handle_orig(), iax2_predestroy(), instance_destructor(), mgcp_hangup(), oh323_hangup(), oss_hangup(), phone_check_exception(), phone_hangup(), sip_hangup(), skinny_hangup(), smart_bridge_operation(), and usbradio_hangup().
01158 { 01159 ast_atomic_fetchadd_int(&mod->usecount, -1); 01160 ast_update_use_count(); 01161 }
| void ast_module_unregister | ( | const struct ast_module_info * | ) |
Definition at line 170 of file loader.c.
References ast_free, AST_LIST_HEAD_DESTROY, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_module::info, and ast_module::users.
00171 { 00172 struct ast_module *mod = NULL; 00173 00174 /* it is assumed that the users list in the module structure 00175 will already be empty, or we cannot have gotten to this 00176 point 00177 */ 00178 AST_LIST_LOCK(&module_list); 00179 AST_LIST_TRAVERSE_SAFE_BEGIN(&module_list, mod, entry) { 00180 if (mod->info == info) { 00181 AST_LIST_REMOVE_CURRENT(entry); 00182 break; 00183 } 00184 } 00185 AST_LIST_TRAVERSE_SAFE_END; 00186 AST_LIST_UNLOCK(&module_list); 00187 00188 if (mod) { 00189 AST_LIST_HEAD_DESTROY(&mod->users); 00190 ast_free(mod); 00191 } 00192 }
| 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 |
| 0 | success | |
| -1 | failure. |
Definition at line 5366 of file pbx.c.
References ast_app::arguments, ast_calloc, ast_free, ast_log(), AST_RWLIST_INSERT_BEFORE_CURRENT, AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE, 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, COLOR_BRCYAN, ast_app::execute, LOG_WARNING, ast_app::module, ast_app::name, ast_app::seealso, ast_app::syntax, and term_color().
Referenced by ast_features_init(), and load_pbx().
05367 { 05368 struct ast_app *tmp, *cur = NULL; 05369 char tmps[80]; 05370 int length, res; 05371 #ifdef AST_XML_DOCS 05372 char *tmpxml; 05373 #endif 05374 05375 AST_RWLIST_WRLOCK(&apps); 05376 AST_RWLIST_TRAVERSE(&apps, tmp, list) { 05377 if (!(res = strcasecmp(app, tmp->name))) { 05378 ast_log(LOG_WARNING, "Already have an application '%s'\n", app); 05379 AST_RWLIST_UNLOCK(&apps); 05380 return -1; 05381 } else if (res < 0) 05382 break; 05383 } 05384 05385 length = sizeof(*tmp) + strlen(app) + 1; 05386 05387 if (!(tmp = ast_calloc(1, length))) { 05388 AST_RWLIST_UNLOCK(&apps); 05389 return -1; 05390 } 05391 05392 if (ast_string_field_init(tmp, 128)) { 05393 AST_RWLIST_UNLOCK(&apps); 05394 ast_free(tmp); 05395 return -1; 05396 } 05397 05398 #ifdef AST_XML_DOCS 05399 /* Try to lookup the docs in our XML documentation database */ 05400 if (ast_strlen_zero(synopsis) && ast_strlen_zero(description)) { 05401 /* load synopsis */ 05402 tmpxml = ast_xmldoc_build_synopsis("application", app); 05403 ast_string_field_set(tmp, synopsis, tmpxml); 05404 ast_free(tmpxml); 05405 05406 /* load description */ 05407 tmpxml = ast_xmldoc_build_description("application", app); 05408 ast_string_field_set(tmp, description, tmpxml); 05409 ast_free(tmpxml); 05410 05411 /* load syntax */ 05412 tmpxml = ast_xmldoc_build_syntax("application", app); 05413 ast_string_field_set(tmp, syntax, tmpxml); 05414 ast_free(tmpxml); 05415 05416 /* load arguments */ 05417 tmpxml = ast_xmldoc_build_arguments("application", app); 05418 ast_string_field_set(tmp, arguments, tmpxml); 05419 ast_free(tmpxml); 05420 05421 /* load seealso */ 05422 tmpxml = ast_xmldoc_build_seealso("application", app); 05423 ast_string_field_set(tmp, seealso, tmpxml); 05424 ast_free(tmpxml); 05425 tmp->docsrc = AST_XML_DOC; 05426 } else { 05427 #endif 05428 ast_string_field_set(tmp, synopsis, synopsis); 05429 ast_string_field_set(tmp, description, description); 05430 #ifdef AST_XML_DOCS 05431 tmp->docsrc = AST_STATIC_DOC; 05432 } 05433 #endif 05434 05435 strcpy(tmp->name, app); 05436 tmp->execute = execute; 05437 tmp->module = mod; 05438 05439 /* Store in alphabetical order */ 05440 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, cur, list) { 05441 if (strcasecmp(tmp->name, cur->name) < 0) { 05442 AST_RWLIST_INSERT_BEFORE_CURRENT(tmp, list); 05443 break; 05444 } 05445 } 05446 AST_RWLIST_TRAVERSE_SAFE_END; 05447 if (!cur) 05448 AST_RWLIST_INSERT_TAIL(&apps, tmp, list); 05449 05450 ast_verb(2, "Registered application '%s'\n", term_color(tmps, tmp->name, COLOR_BRCYAN, 0, sizeof(tmps))); 05451 05452 AST_RWLIST_UNLOCK(&apps); 05453 05454 return 0; 05455 }
| 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. |
| 0 | on success. | |
| -1 | on error. |
Definition at line 468 of file loader.c.
References __ast_module_user_hangup_all(), AST_FORCE_FIRM, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_log(), ast_update_use_count(), ast_module::declined, find_resource(), ast_module::flags, ast_module::info, ast_module::lib, LOG_WARNING, ast_module_info::restore_globals, ast_module::running, ast_module_info::unload, and ast_module::usecount.
Referenced by exit_now(), handle_unload(), manager_moduleload(), reload(), remove_module(), and unload_module().
00469 { 00470 struct ast_module *mod; 00471 int res = -1; 00472 int error = 0; 00473 00474 AST_LIST_LOCK(&module_list); 00475 00476 if (!(mod = find_resource(resource_name, 0))) { 00477 AST_LIST_UNLOCK(&module_list); 00478 ast_log(LOG_WARNING, "Unload failed, '%s' could not be found\n", resource_name); 00479 return 0; 00480 } 00481 00482 if (!(mod->flags.running || mod->flags.declined)) 00483 error = 1; 00484 00485 if (!error && (mod->usecount > 0)) { 00486 if (force) 00487 ast_log(LOG_WARNING, "Warning: Forcing removal of module '%s' with use count %d\n", 00488 resource_name, mod->usecount); 00489 else { 00490 ast_log(LOG_WARNING, "Soft unload failed, '%s' has use count %d\n", resource_name, 00491 mod->usecount); 00492 error = 1; 00493 } 00494 } 00495 00496 if (!error) { 00497 __ast_module_user_hangup_all(mod); 00498 res = mod->info->unload(); 00499 00500 if (res) { 00501 ast_log(LOG_WARNING, "Firm unload failed for %s\n", resource_name); 00502 if (force <= AST_FORCE_FIRM) 00503 error = 1; 00504 else 00505 ast_log(LOG_WARNING, "** Dangerous **: Unloading resource anyway, at user request\n"); 00506 } 00507 } 00508 00509 if (!error) 00510 mod->flags.running = mod->flags.declined = 0; 00511 00512 AST_LIST_UNLOCK(&module_list); 00513 00514 if (!error && !mod->lib && mod->info && mod->info->restore_globals) 00515 mod->info->restore_globals(); 00516 00517 #ifdef LOADABLE_MODULES 00518 if (!error) 00519 unload_dynamic_module(mod); 00520 #endif 00521 00522 if (!error) 00523 ast_update_use_count(); 00524 00525 return res; 00526 }
| 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) |
| 0 | success | |
| -1 | failure |
Definition at line 6689 of file pbx.c.
References ast_free, 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_verb, ast_app::name, and unreference_cached_app().
Referenced by __unload_module(), load_module(), and unload_module().
06690 { 06691 struct ast_app *tmp; 06692 06693 AST_RWLIST_WRLOCK(&apps); 06694 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, tmp, list) { 06695 if (!strcasecmp(app, tmp->name)) { 06696 unreference_cached_app(tmp); 06697 AST_RWLIST_REMOVE_CURRENT(list); 06698 ast_verb(2, "Unregistered application '%s'\n", tmp->name); 06699 ast_string_field_free_memory(tmp); 06700 ast_free(tmp); 06701 break; 06702 } 06703 } 06704 AST_RWLIST_TRAVERSE_SAFE_END; 06705 AST_RWLIST_UNLOCK(&apps); 06706 06707 return tmp ? 0 : -1; 06708 }
| 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 1083 of file loader.c.
References AST_LIST_TRAVERSE, AST_LIST_TRYLOCK, AST_LIST_UNLOCK, ast_module_info::description, ast_module::info, ast_module::resource, and ast_module::usecount.
Referenced by ast_var_Modules(), handle_modlist(), and mod_update().
01085 { 01086 struct ast_module *cur; 01087 int unlock = -1; 01088 int total_mod_loaded = 0; 01089 01090 if (AST_LIST_TRYLOCK(&module_list)) 01091 unlock = 0; 01092 01093 AST_LIST_TRAVERSE(&module_list, cur, entry) { 01094 total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount, like); 01095 } 01096 01097 if (unlock) 01098 AST_LIST_UNLOCK(&module_list); 01099 01100 return total_mod_loaded; 01101 }
| 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 1071 of file loader.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, and loadupdate::updater.
Referenced by __ast_module_user_add(), __ast_module_user_hangup_all(), __ast_module_user_remove(), ast_module_ref(), ast_module_unref(), ast_unload_resource(), exit_now(), handle_request_do(), load_module(), oh323_request(), scheduler_process_request_queue(), sip_request_call(), start_resource(), and unistim_new().
01072 { 01073 /* Notify any module monitors that the use count for a 01074 resource has changed */ 01075 struct loadupdate *m; 01076 01077 AST_LIST_LOCK(&updaters); 01078 AST_LIST_TRAVERSE(&updaters, m, entry) 01079 m->updater(); 01080 AST_LIST_UNLOCK(&updaters); 01081 }
struct ast_module_info* ast_module_info [static] |
1.5.6