[asterisk-commits] irroot: branch irroot/distrotech-customers-1.8 r339205 - /team/irroot/distrot...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Oct 4 02:37:31 CDT 2011


Author: irroot
Date: Tue Oct  4 02:37:28 2011
New Revision: 339205

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=339205
Log:
More complete backport of res_fax.c

Modified:
    team/irroot/distrotech-customers-1.8/res/res_fax.c

Modified: team/irroot/distrotech-customers-1.8/res/res_fax.c
URL: http://svnview.digium.com/svn/asterisk/team/irroot/distrotech-customers-1.8/res/res_fax.c?view=diff&rev=339205&r1=339204&r2=339205
==============================================================================
--- team/irroot/distrotech-customers-1.8/res/res_fax.c (original)
+++ team/irroot/distrotech-customers-1.8/res/res_fax.c Tue Oct  4 02:37:28 2011
@@ -98,6 +98,9 @@
 					<option name="f">
 						<para>Allow audio fallback FAX transfer on T.38 capable channels.</para>
 					</option>
+					<option name="F">
+						<para>Force usage of audio mode on T.38 capable channels.</para>
+					</option>
 					<option name="s">
 						<para>Send progress Manager events (overrides statusevents setting in res_fax.conf).</para>
 					</option>
@@ -130,6 +133,9 @@
 					</option>
 					<option name="f">
 						<para>Allow audio fallback FAX transfer on T.38 capable channels.</para>
+					</option>
+					<option name="F">
+						<para>Force usage of audio mode on T.38 capable channels.</para>
 					</option>
 					<option name="s">
 						<para>Send progress Manager events (overrides statusevents setting in res_fax.conf).</para>
@@ -340,6 +346,7 @@
 	OPT_STATUS      = (1 << 3),
 	OPT_ALLOWAUDIO  = (1 << 5),
 	OPT_REQUEST_T38 = (1 << 6),
+	OPT_FORCE_AUDIO = (1 << 7),
 };
 
 AST_APP_OPTIONS(fax_exec_options, BEGIN_OPTIONS
@@ -347,6 +354,7 @@
 	AST_APP_OPTION('c', OPT_CALLERMODE),
 	AST_APP_OPTION('d', OPT_DEBUG),
 	AST_APP_OPTION('f', OPT_ALLOWAUDIO),
+	AST_APP_OPTION('F', OPT_FORCE_AUDIO),
 	AST_APP_OPTION('s', OPT_STATUS),
 	AST_APP_OPTION('z', OPT_REQUEST_T38),
 END_OPTIONS);
@@ -575,7 +583,6 @@
 	}
 	return 0;
 }
-
 static char *ast_fax_caps_to_str(enum ast_fax_capabilities caps, char *buf, size_t bufsize)
 {
 	char *out = buf;
@@ -621,9 +628,10 @@
 		if (!first) {
 			ast_build_string(&buf, &size, ",");
 		}
-		ast_build_string(&buf, &size, "T38_GATEWAY");
+		ast_build_string(&buf, &size, "GATEWAY");
 		first = 0;
 	}
+
 
 	return out;
 }
@@ -875,7 +883,6 @@
 {
 	struct ast_fax_session *s;
 	struct fax_module *faxmod;
-	char caps[128] = "";
 
 	if (!(s = ao2_alloc(sizeof(*s), destroy_session))) {
 		return NULL;
@@ -901,6 +908,7 @@
 	AST_RWLIST_UNLOCK(&faxmodules);
 
 	if (!faxmod) {
+		char caps[128] = "";
 		ast_log(LOG_ERROR, "Could not locate a FAX technology module with capabilities (%s)\n", ast_fax_caps_to_str(details->caps, caps, sizeof(caps)));
 		ao2_ref(s, -1);
 		return NULL;
@@ -942,7 +950,6 @@
 {
 	struct ast_fax_session *s = NULL;
 	struct fax_module *faxmod;
-	char caps[128] = "";
 
 	if (reserved) {
 		s = reserved;
@@ -1018,6 +1025,7 @@
 		AST_RWLIST_UNLOCK(&faxmodules);
 
 		if (!faxmod) {
+			char caps[128] = "";
 			ast_log(LOG_ERROR, "Could not locate a FAX technology module with capabilities (%s)\n", ast_fax_caps_to_str(details->caps, caps, sizeof(caps)));
 			ao2_ref(s, -1);
 			return NULL;
@@ -1496,10 +1504,9 @@
 
 	set_channel_variables(chan, details);
 
+	ast_atomic_fetchadd_int(&faxregistry.fax_complete, 1);
 	if (!strcasecmp(details->result, "FAILED")) {
 		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
-	} else {
-		ast_atomic_fetchadd_int(&faxregistry.fax_complete, 1);
 	}
 
 	if (fax) {
@@ -1700,14 +1707,9 @@
 	pbx_builtin_setvar_helper(chan, "FAXBITRATE", NULL);
 	pbx_builtin_setvar_helper(chan, "FAXRESOLUTION", NULL);
 
-	/* if we ran receivefax then we attempted to receive a fax, even if we
-	 * never start a fax session */
-	ast_atomic_fetchadd_int(&faxregistry.fax_rx_attempts, 1);
-
 	/* Get a FAX session details structure from the channel's FAX datastore and create one if
 	 * it does not already exist. */
 	if (!(details = find_or_create_details(chan))) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		pbx_builtin_setvar_helper(chan, "FAXERROR", "MEMORY_ERROR");
 		pbx_builtin_setvar_helper(chan, "FAXSTATUSSTRING", "error allocating memory");
 		ast_log(LOG_ERROR, "System cannot provide memory for session requirements.\n");
@@ -1728,7 +1730,6 @@
 	}
 
 	if (details->maxrate < details->minrate) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		ast_string_field_set(details, error, "INVALID_ARGUMENTS");
 		ast_string_field_set(details, resultstr, "maxrate is less than minrate");
 		set_channel_variables(chan, details);
@@ -1738,7 +1739,6 @@
 	}
 
 	if (check_modem_rate(details->modems, details->minrate)) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		ast_fax_modem_to_str(details->modems, modems, sizeof(modems));
 		ast_log(LOG_ERROR, "'modems' setting '%s' is incompatible with 'minrate' setting %d\n", modems, details->minrate);
 		ast_string_field_set(details, error, "INVALID_ARGUMENTS");
@@ -1749,7 +1749,6 @@
 	}
 
 	if (check_modem_rate(details->modems, details->maxrate)) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		ast_fax_modem_to_str(details->modems, modems, sizeof(modems));
 		ast_log(LOG_ERROR, "'modems' setting '%s' is incompatible with 'maxrate' setting %d\n", modems, details->maxrate);
 		ast_string_field_set(details, error, "INVALID_ARGUMENTS");
@@ -1760,7 +1759,6 @@
 	}
 
 	if (ast_strlen_zero(data)) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		ast_string_field_set(details, error, "INVALID_ARGUMENTS");
 		ast_string_field_set(details, resultstr, "invalid arguments");
 		set_channel_variables(chan, details);
@@ -1773,7 +1771,6 @@
 
 	if (!ast_strlen_zero(args.options) &&
 	    ast_app_parse_options(fax_exec_options, &opts, NULL, args.options)) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		ast_string_field_set(details, error, "INVALID_ARGUMENTS");
 		ast_string_field_set(details, resultstr, "invalid arguments");
 		set_channel_variables(chan, details);
@@ -1781,7 +1778,6 @@
 		return -1;
 	}
 	if (ast_strlen_zero(args.filename)) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		ast_string_field_set(details, error, "INVALID_ARGUMENTS");
 		ast_string_field_set(details, resultstr, "invalid arguments");
 		set_channel_variables(chan, details);
@@ -1792,7 +1788,6 @@
 
 	/* check for unsupported FAX application options */
 	if (ast_test_flag(&opts, OPT_CALLERMODE) || ast_test_flag(&opts, OPT_CALLEDMODE)) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		ast_string_field_set(details, error, "INVALID_ARGUMENTS");
 		ast_string_field_set(details, resultstr, "invalid arguments");
 		set_channel_variables(chan, details);
@@ -1800,12 +1795,13 @@
 		ao2_ref(details, -1);
 		return -1;
 	}
+	
+	ast_atomic_fetchadd_int(&faxregistry.fax_rx_attempts, 1);
 
 	pbx_builtin_setvar_helper(chan, "FAXERROR", "Channel Problems");
 	pbx_builtin_setvar_helper(chan, "FAXSTATUSSTRING", "Error before FAX transmission started.");
 
 	if (!(doc = ast_calloc(1, sizeof(*doc) + strlen(args.filename) + 1))) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		ast_string_field_set(details, error, "MEMORY_ERROR");
 		ast_string_field_set(details, resultstr, "error allocating memory");
 		set_channel_variables(chan, details);
@@ -1833,12 +1829,12 @@
 
 	t38state = ast_channel_get_t38_state(chan);
 	if ((t38state == T38_STATE_UNAVAILABLE) || (t38state == T38_STATE_REJECTED) ||
-	    ast_test_flag(&opts, OPT_ALLOWAUDIO)) {
+	    ast_test_flag(&opts, OPT_ALLOWAUDIO) ||
+	    ast_test_flag(&opts, OPT_FORCE_AUDIO)) {
 		details->option.allow_audio = AST_FAX_OPTFLAG_TRUE;
 	}
 
 	if (!(s = fax_session_reserve(details, &token))) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		ast_string_field_set(details, resultstr, "error reserving fax session");
 		set_channel_variables(chan, details);
 		ast_log(LOG_ERROR, "Unable to reserve FAX session.\n");
@@ -1849,7 +1845,6 @@
 	/* make sure the channel is up */
 	if (chan->_state != AST_STATE_UP) {
 		if (ast_answer(chan)) {
-			ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 			ast_string_field_set(details, resultstr, "error answering channel");
 			set_channel_variables(chan, details);
 			ast_log(LOG_WARNING, "Channel '%s' failed answer attempt.\n", chan->name);
@@ -1860,20 +1855,22 @@
 		}
 	}
 
-	if (set_fax_t38_caps(chan, details)) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
-		ast_string_field_set(details, error, "T38_NEG_ERROR");
-		ast_string_field_set(details, resultstr, "error negotiating T.38");
-		set_channel_variables(chan, details);
-		fax_session_release(s, token);
-		ao2_ref(s, -1);
-		ao2_ref(details, -1);
-		return -1;
-	}
-
-	if (details->caps & AST_FAX_TECH_T38) {
+	if (!ast_test_flag(&opts, OPT_FORCE_AUDIO)) {
+		if (set_fax_t38_caps(chan, details)) {
+			ast_string_field_set(details, error, "T38_NEG_ERROR");
+			ast_string_field_set(details, resultstr, "error negotiating T.38");
+			set_channel_variables(chan, details);
+			fax_session_release(s, token);
+			ao2_ref(s, -1);
+			ao2_ref(details, -1);
+			return -1;
+		}
+	} else {
+		details->caps |= AST_FAX_TECH_AUDIO;
+	}
+
+	if (!ast_test_flag(&opts, OPT_FORCE_AUDIO) && (details->caps & AST_FAX_TECH_T38)) {
 		if (receivefax_t38_init(chan, details)) {
-			ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 			ast_string_field_set(details, error, "T38_NEG_ERROR");
 			ast_string_field_set(details, resultstr, "error negotiating T.38");
 			set_channel_variables(chan, details);
@@ -2180,14 +2177,9 @@
 	pbx_builtin_setvar_helper(chan, "FAXBITRATE", NULL);
 	pbx_builtin_setvar_helper(chan, "FAXRESOLUTION", NULL);
 
-	/* if we ran sendfax then we attempted to send a fax, even if we never
-	 * start a fax session */
-	ast_atomic_fetchadd_int(&faxregistry.fax_tx_attempts, 1);
-
 	/* Get a requirement structure and set it.  This structure is used
 	 * to tell the FAX technology module about the higher level FAX session */
 	if (!(details = find_or_create_details(chan))) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		pbx_builtin_setvar_helper(chan, "FAXERROR", "MEMORY_ERROR");
 		pbx_builtin_setvar_helper(chan, "FAXSTATUSSTRING", "error allocating memory");
 		ast_log(LOG_ERROR, "System cannot provide memory for session requirements.\n");
@@ -2208,7 +2200,6 @@
 	}
 
 	if (details->maxrate < details->minrate) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		ast_string_field_set(details, error, "INVALID_ARGUMENTS");
 		ast_string_field_set(details, resultstr, "maxrate is less than minrate");
 		set_channel_variables(chan, details);
@@ -2218,7 +2209,6 @@
 	}
 
 	if (check_modem_rate(details->modems, details->minrate)) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		ast_fax_modem_to_str(details->modems, modems, sizeof(modems));
 		ast_log(LOG_ERROR, "'modems' setting '%s' is incompatible with 'minrate' setting %d\n", modems, details->minrate);
 		ast_string_field_set(details, error, "INVALID_ARGUMENTS");
@@ -2229,7 +2219,6 @@
 	}
 
 	if (check_modem_rate(details->modems, details->maxrate)) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		ast_fax_modem_to_str(details->modems, modems, sizeof(modems));
 		ast_log(LOG_ERROR, "'modems' setting '%s' is incompatible with 'maxrate' setting %d\n", modems, details->maxrate);
 		ast_string_field_set(details, error, "INVALID_ARGUMENTS");
@@ -2240,7 +2229,6 @@
 	}
 
 	if (ast_strlen_zero(data)) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		ast_string_field_set(details, error, "INVALID_ARGUMENTS");
 		ast_string_field_set(details, resultstr, "invalid arguments");
 		set_channel_variables(chan, details);
@@ -2254,7 +2242,6 @@
 
 	if (!ast_strlen_zero(args.options) &&
 	    ast_app_parse_options(fax_exec_options, &opts, NULL, args.options)) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		ast_string_field_set(details, error, "INVALID_ARGUMENTS");
 		ast_string_field_set(details, resultstr, "invalid arguments");
 		set_channel_variables(chan, details);
@@ -2262,7 +2249,6 @@
 		return -1;
 	}
 	if (ast_strlen_zero(args.filenames)) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		ast_string_field_set(details, error, "INVALID_ARGUMENTS");
 		ast_string_field_set(details, resultstr, "invalid arguments");
 		set_channel_variables(chan, details);
@@ -2273,7 +2259,6 @@
 	
 	/* check for unsupported FAX application options */
 	if (ast_test_flag(&opts, OPT_CALLERMODE) || ast_test_flag(&opts, OPT_CALLEDMODE)) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		ast_string_field_set(details, error, "INVALID_ARGUMENTS");
 		ast_string_field_set(details, resultstr, "invalid arguments");
 		set_channel_variables(chan, details);
@@ -2282,11 +2267,12 @@
 		return -1;
 	}
 
+	ast_atomic_fetchadd_int(&faxregistry.fax_tx_attempts, 1);
+
 	file_count = 0;
 	filenames = args.filenames;
 	while ((c = strsep(&filenames, "&"))) {
 		if (access(c, (F_OK | R_OK)) < 0) {
-			ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 			ast_string_field_set(details, error, "FILE_ERROR");
 			ast_string_field_set(details, resultstr, "error reading file");
 			set_channel_variables(chan, details);
@@ -2296,7 +2282,6 @@
 		}
 
 		if (!(doc = ast_calloc(1, sizeof(*doc) + strlen(c) + 1))) {
-			ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 			ast_string_field_set(details, error, "MEMORY_ERROR");
 			ast_string_field_set(details, resultstr, "error allocating memory");
 			set_channel_variables(chan, details);
@@ -2310,10 +2295,6 @@
 		file_count++;
 	}
 
-	if (file_count > 1) {
-		details->caps |= AST_FAX_TECH_MULTI_DOC;
-	}
-
 	ast_verb(3, "Channel '%s' sending FAX:\n", chan->name);
 	AST_LIST_TRAVERSE(&details->documents, doc, next) {
 		ast_verb(3, "   %s\n", doc->filename);
@@ -2321,6 +2302,10 @@
 
 	details->caps = AST_FAX_TECH_SEND;
 
+	if (file_count > 1) {
+		details->caps |= AST_FAX_TECH_MULTI_DOC;
+	}
+
 	/* check for debug */
 	if (ast_test_flag(&opts, OPT_DEBUG) || global_fax_debug) {
 		details->option.debug = AST_FAX_OPTFLAG_TRUE;
@@ -2333,7 +2318,8 @@
 
 	t38state = ast_channel_get_t38_state(chan);
 	if ((t38state == T38_STATE_UNAVAILABLE) || (t38state == T38_STATE_REJECTED) ||
-	    ast_test_flag(&opts, OPT_ALLOWAUDIO)) {
+	    ast_test_flag(&opts, OPT_ALLOWAUDIO) ||
+	    ast_test_flag(&opts, OPT_FORCE_AUDIO)) {
 		details->option.allow_audio = AST_FAX_OPTFLAG_TRUE;
 	}
 
@@ -2342,7 +2328,6 @@
 	}
 
 	if (!(s = fax_session_reserve(details, &token))) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 		ast_string_field_set(details, resultstr, "error reserving fax session");
 		set_channel_variables(chan, details);
 		ast_log(LOG_ERROR, "Unable to reserve FAX session.\n");
@@ -2353,7 +2338,6 @@
 	/* make sure the channel is up */
 	if (chan->_state != AST_STATE_UP) {
 		if (ast_answer(chan)) {
-			ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 			ast_string_field_set(details, resultstr, "error answering channel");
 			set_channel_variables(chan, details);
 			ast_log(LOG_WARNING, "Channel '%s' failed answer attempt.\n", chan->name);
@@ -2364,20 +2348,22 @@
 		}
 	}
 
-	if (set_fax_t38_caps(chan, details)) {
-		ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
-		ast_string_field_set(details, error, "T38_NEG_ERROR");
-		ast_string_field_set(details, resultstr, "error negotiating T.38");
-		set_channel_variables(chan, details);
-		fax_session_release(s, token);
-		ao2_ref(s, -1);
-		ao2_ref(details, -1);
-		return -1;
-	}
-
-	if (details->caps & AST_FAX_TECH_T38) {
+	if (!ast_test_flag(&opts, OPT_FORCE_AUDIO)) {
+		if (set_fax_t38_caps(chan, details)) {
+			ast_string_field_set(details, error, "T38_NEG_ERROR");
+			ast_string_field_set(details, resultstr, "error negotiating T.38");
+			set_channel_variables(chan, details);
+			fax_session_release(s, token);
+			ao2_ref(s, -1);
+			ao2_ref(details, -1);
+			return -1;
+		}
+	} else {
+		details->caps |= AST_FAX_TECH_AUDIO;
+	}
+
+	if (!ast_test_flag(&opts, OPT_FORCE_AUDIO) && (details->caps & AST_FAX_TECH_T38)) {
 		if (sendfax_t38_init(chan, details)) {
-			ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
 			ast_string_field_set(details, error, "T38_NEG_ERROR");
 			ast_string_field_set(details, resultstr, "error negotiating T.38");
 			set_channel_variables(chan, details);
@@ -2462,7 +2448,7 @@
 	if (gateway->s) {
 		fax_session_release(gateway->s, gateway->token);
 		gateway->token = NULL;
-		gateway->s->details->caps |= ~AST_FAX_TECH_GATEWAY;
+		gateway->s->details->caps &= ~AST_FAX_TECH_GATEWAY;
 
 		ao2_lock(faxregistry.container);
 		ao2_unlink(faxregistry.container, gateway->s);
@@ -2506,7 +2492,7 @@
 
 	details->caps = AST_FAX_TECH_GATEWAY;
 	if (details->gateway_timeout && !(gateway->s = fax_session_reserve(details, &gateway->token))) {
-		details->caps |= ~AST_FAX_TECH_GATEWAY;
+		details->caps &= ~AST_FAX_TECH_GATEWAY;
 		ast_log(LOG_ERROR, "Can't reserve a FAX session, gateway attempt failed.\n");
 		ao2_ref(gateway, -1);
 		return NULL;




More information about the asterisk-commits mailing list