summaryrefslogtreecommitdiff
path: root/res
diff options
context:
space:
mode:
authorCorey Farrell <git@cfware.com>2017-12-29 19:24:02 -0500
committerCorey Farrell <git@cfware.com>2018-01-03 17:23:36 -0500
commit55f1d69c43d2c6c87eec50fd3eed7a77ba2e912b (patch)
tree0749060ca9d29dc796152f1654a340f091f4f600 /res
parent7f4facc5e4a96ccae10283da998044becc4fbe11 (diff)
loader: Create ast_module_running_ref.
This function returns NULL if the module in question is not running. I did not change ast_module_ref as most callers do not check the result and they always call ast_module_unref. Make use of this function when running registered items from: * app_stack API's * bridge technologies * CLI commands * File formats * Manager Actions * RTP engines * Sorcery Wizards * Timing Interfaces * Translators * AGI Commands * Fax Technologies ASTERISK-20346 #close Change-Id: Ia16fd28e188b2fc0b9d18b8a5d9cacc31df73fcc
Diffstat (limited to 'res')
-rw-r--r--res/res_agi.c29
-rw-r--r--res/res_fax.c8
2 files changed, 20 insertions, 17 deletions
diff --git a/res/res_agi.c b/res/res_agi.c
index 85914c018..393a50351 100644
--- a/res/res_agi.c
+++ b/res/res_agi.c
@@ -4040,14 +4040,19 @@ static enum agi_result agi_handle_command(struct ast_channel *chan, AGI *agi, ch
parse_args(buf, &argc, argv);
c = find_command(argv, 0);
- if (c && (!dead || (dead && c->dead))) {
- /* if this command wasn't registered by res_agi, be sure to usecount
- the module we are using */
- if (c->mod != ast_module_info->self)
- ast_module_ref(c->mod);
+ if (!c || !ast_module_running_ref(c->mod)) {
+ ami_res = "Invalid or unknown command";
+ resultcode = 510;
+
+ ast_agi_send(agi->fd, chan, "%d %s\n", resultcode, ami_res);
+
+ publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+
+ return AGI_RESULT_SUCCESS;
+ }
+
+ if (!dead || (dead && c->dead)) {
res = c->handler(chan, agi, argc, argv);
- if (c->mod != ast_module_info->self)
- ast_module_unref(c->mod);
switch (res) {
case RESULT_SHOWUSAGE:
ami_res = "Usage";
@@ -4094,21 +4099,15 @@ static enum agi_result agi_handle_command(struct ast_channel *chan, AGI *agi, ch
break;
}
- } else if (c) {
+ } else {
ami_res = "Command Not Permitted on a dead channel or intercept routine";
resultcode = 511;
ast_agi_send(agi->fd, chan, "%d %s\n", resultcode, ami_res);
publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
- } else {
- ami_res = "Invalid or unknown command";
- resultcode = 510;
-
- ast_agi_send(agi->fd, chan, "%d %s\n", resultcode, ami_res);
-
- publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
}
+ ast_module_unref(c->mod);
return AGI_RESULT_SUCCESS;
}
diff --git a/res/res_fax.c b/res/res_fax.c
index 093845246..4be5aee75 100644
--- a/res/res_fax.c
+++ b/res/res_fax.c
@@ -1161,8 +1161,10 @@ static struct ast_fax_session *fax_session_reserve(struct ast_fax_session_detail
if ((faxmod->tech->caps & details->caps) != details->caps) {
continue;
}
+ if (!ast_module_running_ref(faxmod->tech->module)) {
+ continue;
+ }
ast_debug(4, "Reserving a FAX session from '%s'.\n", faxmod->tech->description);
- ast_module_ref(faxmod->tech->module);
s->tech = faxmod->tech;
break;
}
@@ -1279,8 +1281,10 @@ static struct ast_fax_session *fax_session_new(struct ast_fax_session_details *d
if ((faxmod->tech->caps & details->caps) != details->caps) {
continue;
}
+ if (!ast_module_running_ref(faxmod->tech->module)) {
+ continue;
+ }
ast_debug(4, "Requesting a new FAX session from '%s'.\n", faxmod->tech->description);
- ast_module_ref(faxmod->tech->module);
if (reserved) {
/* Balance module ref from reserved session */
ast_module_unref(reserved->tech->module);