Fix some more fax test errors due to needing the peer in a bridge

In r389799, a number of fax errors in gateway mode were fixed by using the
appropriate function to get a channel's peer while in a bridge. This patch
does two things:
(1) It uses the same function in res_fax_spandsp while starting the fax
    gateway. Without this, the fax gateway will not actually start up, as
    res_fax_spandsp also must inspect the channel's peer in a two-party
    bridge
(2) It refactors some ao2 objects in sendfax_exec to use RAII_VAR. This was
    reverted in r389799 as some off nominal paths were getting hit without
    the fix in (1) that indicated an ao2 object issue; this turned out to
    be a red herring (which is an odd phrase)


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@389827 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Matthew Jordan
2013-05-27 01:33:12 +00:00
parent a0f6d1848b
commit 2d2a47fae3
2 changed files with 5 additions and 25 deletions

View File

@@ -2285,8 +2285,8 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
{ {
char *parse, *filenames, *c, modems[128] = ""; char *parse, *filenames, *c, modems[128] = "";
int channel_alive, file_count; int channel_alive, file_count;
struct ast_fax_session_details *details; RAII_VAR(struct ast_fax_session_details *, details, NULL, ao2_cleanup);
struct ast_fax_session *s; RAII_VAR(struct ast_fax_session *, s, NULL, ao2_cleanup);
struct ast_fax_tech_token *token = NULL; struct ast_fax_tech_token *token = NULL;
struct ast_fax_document *doc; struct ast_fax_document *doc;
AST_DECLARE_APP_ARGS(args, AST_DECLARE_APP_ARGS(args,
@@ -2321,7 +2321,6 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
ast_string_field_set(details, resultstr, "can't send a fax on a channel with a T.38 gateway"); ast_string_field_set(details, resultstr, "can't send a fax on a channel with a T.38 gateway");
set_channel_variables(chan, details); set_channel_variables(chan, details);
ast_log(LOG_ERROR, "executing SendFAX on a channel with a T.38 Gateway is not supported\n"); ast_log(LOG_ERROR, "executing SendFAX on a channel with a T.38 Gateway is not supported\n");
ao2_ref(details, -1);
return -1; return -1;
} }
@@ -2330,7 +2329,6 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
ast_string_field_set(details, resultstr, "maxrate is less than minrate"); ast_string_field_set(details, resultstr, "maxrate is less than minrate");
set_channel_variables(chan, details); set_channel_variables(chan, details);
ast_log(LOG_ERROR, "maxrate %d is less than minrate %d\n", details->maxrate, details->minrate); ast_log(LOG_ERROR, "maxrate %d is less than minrate %d\n", details->maxrate, details->minrate);
ao2_ref(details, -1);
return -1; return -1;
} }
@@ -2340,7 +2338,6 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
ast_string_field_set(details, error, "INVALID_ARGUMENTS"); ast_string_field_set(details, error, "INVALID_ARGUMENTS");
ast_string_field_set(details, resultstr, "incompatible 'modems' and 'minrate' settings"); ast_string_field_set(details, resultstr, "incompatible 'modems' and 'minrate' settings");
set_channel_variables(chan, details); set_channel_variables(chan, details);
ao2_ref(details, -1);
return -1; return -1;
} }
@@ -2350,7 +2347,6 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
ast_string_field_set(details, error, "INVALID_ARGUMENTS"); ast_string_field_set(details, error, "INVALID_ARGUMENTS");
ast_string_field_set(details, resultstr, "incompatible 'modems' and 'maxrate' settings"); ast_string_field_set(details, resultstr, "incompatible 'modems' and 'maxrate' settings");
set_channel_variables(chan, details); set_channel_variables(chan, details);
ao2_ref(details, -1);
return -1; return -1;
} }
@@ -2359,7 +2355,6 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
ast_string_field_set(details, resultstr, "invalid arguments"); ast_string_field_set(details, resultstr, "invalid arguments");
set_channel_variables(chan, details); set_channel_variables(chan, details);
ast_log(LOG_WARNING, "%s requires an argument (filename[&filename[&filename]][,options])\n", app_sendfax); ast_log(LOG_WARNING, "%s requires an argument (filename[&filename[&filename]][,options])\n", app_sendfax);
ao2_ref(details, -1);
return -1; return -1;
} }
parse = ast_strdupa(data); parse = ast_strdupa(data);
@@ -2371,7 +2366,6 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
ast_string_field_set(details, error, "INVALID_ARGUMENTS"); ast_string_field_set(details, error, "INVALID_ARGUMENTS");
ast_string_field_set(details, resultstr, "invalid arguments"); ast_string_field_set(details, resultstr, "invalid arguments");
set_channel_variables(chan, details); set_channel_variables(chan, details);
ao2_ref(details, -1);
return -1; return -1;
} }
if (ast_strlen_zero(args.filenames)) { if (ast_strlen_zero(args.filenames)) {
@@ -2379,7 +2373,6 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
ast_string_field_set(details, resultstr, "invalid arguments"); ast_string_field_set(details, resultstr, "invalid arguments");
set_channel_variables(chan, details); set_channel_variables(chan, details);
ast_log(LOG_WARNING, "%s requires an argument (filename[&filename[&filename]],options])\n", app_sendfax); ast_log(LOG_WARNING, "%s requires an argument (filename[&filename[&filename]],options])\n", app_sendfax);
ao2_ref(details, -1);
return -1; return -1;
} }
@@ -2389,7 +2382,6 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
ast_string_field_set(details, resultstr, "invalid arguments"); ast_string_field_set(details, resultstr, "invalid arguments");
set_channel_variables(chan, details); set_channel_variables(chan, details);
ast_log(LOG_WARNING, "%s does not support polling\n", app_sendfax); ast_log(LOG_WARNING, "%s does not support polling\n", app_sendfax);
ao2_ref(details, -1);
return -1; return -1;
} }
@@ -2403,7 +2395,6 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
ast_string_field_set(details, resultstr, "error reading file"); ast_string_field_set(details, resultstr, "error reading file");
set_channel_variables(chan, details); set_channel_variables(chan, details);
ast_log(LOG_ERROR, "access failure. Verify '%s' exists and check permissions.\n", args.filenames); ast_log(LOG_ERROR, "access failure. Verify '%s' exists and check permissions.\n", args.filenames);
ao2_ref(details, -1);
return -1; return -1;
} }
@@ -2412,7 +2403,6 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
ast_string_field_set(details, resultstr, "error allocating memory"); ast_string_field_set(details, resultstr, "error allocating memory");
set_channel_variables(chan, details); set_channel_variables(chan, details);
ast_log(LOG_ERROR, "System cannot provide memory for session requirements.\n"); ast_log(LOG_ERROR, "System cannot provide memory for session requirements.\n");
ao2_ref(details, -1);
return -1; return -1;
} }
@@ -2457,7 +2447,6 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
ast_string_field_set(details, resultstr, "error reserving fax session"); ast_string_field_set(details, resultstr, "error reserving fax session");
set_channel_variables(chan, details); set_channel_variables(chan, details);
ast_log(LOG_ERROR, "Unable to reserve FAX session.\n"); ast_log(LOG_ERROR, "Unable to reserve FAX session.\n");
ao2_ref(details, -1);
return -1; return -1;
} }
@@ -2468,8 +2457,6 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
set_channel_variables(chan, details); set_channel_variables(chan, details);
ast_log(LOG_WARNING, "Channel '%s' failed answer attempt.\n", ast_channel_name(chan)); ast_log(LOG_WARNING, "Channel '%s' failed answer attempt.\n", ast_channel_name(chan));
fax_session_release(s, token); fax_session_release(s, token);
ao2_ref(s, -1);
ao2_ref(details, -1);
return -1; return -1;
} }
} }
@@ -2480,8 +2467,6 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
ast_string_field_set(details, resultstr, "error negotiating T.38"); ast_string_field_set(details, resultstr, "error negotiating T.38");
set_channel_variables(chan, details); set_channel_variables(chan, details);
fax_session_release(s, token); fax_session_release(s, token);
ao2_ref(s, -1);
ao2_ref(details, -1);
return -1; return -1;
} }
} else { } else {
@@ -2494,8 +2479,6 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
ast_string_field_set(details, resultstr, "error negotiating T.38"); ast_string_field_set(details, resultstr, "error negotiating T.38");
set_channel_variables(chan, details); set_channel_variables(chan, details);
fax_session_release(s, token); fax_session_release(s, token);
ao2_ref(s, -1);
ao2_ref(details, -1);
ast_log(LOG_ERROR, "error initializing channel '%s' in T.38 mode\n", ast_channel_name(chan)); ast_log(LOG_ERROR, "error initializing channel '%s' in T.38 mode\n", ast_channel_name(chan));
return -1; return -1;
} }
@@ -2523,9 +2506,6 @@ static int sendfax_exec(struct ast_channel *chan, const char *data)
ast_log(AST_LOG_ERROR, "Error publishing SendFAX status message\n"); ast_log(AST_LOG_ERROR, "Error publishing SendFAX status message\n");
} }
ao2_ref(s, -1);
ao2_ref(details, -1);
/* If the channel hungup return -1; otherwise, return 0 to continue in the dialplan */ /* If the channel hungup return -1; otherwise, return 0 to continue in the dialplan */
return (!channel_alive) ? -1 : 0; return (!channel_alive) ? -1 : 0;
} }

View File

@@ -761,7 +761,7 @@ static int spandsp_fax_gateway_start(struct ast_fax_session *s) {
struct spandsp_pvt *p = s->tech_pvt; struct spandsp_pvt *p = s->tech_pvt;
struct ast_fax_t38_parameters *t38_param; struct ast_fax_t38_parameters *t38_param;
int i; int i;
struct ast_channel *peer; RAII_VAR(struct ast_channel *, peer, NULL, ao2_cleanup);
static struct ast_generator t30_gen = { static struct ast_generator t30_gen = {
.alloc = spandsp_fax_gw_gen_alloc, .alloc = spandsp_fax_gw_gen_alloc,
.release = spandsp_fax_gw_gen_release, .release = spandsp_fax_gw_gen_release,
@@ -782,7 +782,7 @@ static int spandsp_fax_gateway_start(struct ast_fax_session *s) {
p->ist38 = 1; p->ist38 = 1;
p->ast_t38_state = ast_channel_get_t38_state(s->chan); p->ast_t38_state = ast_channel_get_t38_state(s->chan);
if (!(peer = ast_bridged_channel(s->chan))) { if (!(peer = ast_channel_bridge_peer(s->chan))) {
ast_channel_unlock(s->chan); ast_channel_unlock(s->chan);
return -1; return -1;
} }