[asterisk-commits] file: branch file/originate_dial r387028 - in /team/file/originate_dial: incl...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 30 16:29:34 CDT 2013


Author: file
Date: Tue Apr 30 16:29:30 2013
New Revision: 387028

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387028
Log:
Expose the cause code and execute failed extension.

Modified:
    team/file/originate_dial/include/asterisk/dial.h
    team/file/originate_dial/main/dial.c
    team/file/originate_dial/main/pbx.c

Modified: team/file/originate_dial/include/asterisk/dial.h
URL: http://svnview.digium.com/svn/asterisk/team/file/originate_dial/include/asterisk/dial.h?view=diff&rev=387028&r1=387027&r2=387028
==============================================================================
--- team/file/originate_dial/include/asterisk/dial.h (original)
+++ team/file/originate_dial/include/asterisk/dial.h Tue Apr 30 16:29:30 2013
@@ -145,6 +145,13 @@
  */
 int ast_dial_option_disable(struct ast_dial *dial, int num, enum ast_dial_option option);
 
+/*! \brief Get the reason an outgoing channel has failed
+ * \param dial Dial structure
+ * \param num Channel number to get the reason from
+ * \return Numerical cause code
+ */
+int ast_dial_reason(struct ast_dial *dial, int num);
+
 /*! \brief Set a callback for state changes
  * \param dial The dial structure to watch for state changes
  * \param callback the callback

Modified: team/file/originate_dial/main/dial.c
URL: http://svnview.digium.com/svn/asterisk/team/file/originate_dial/main/dial.c?view=diff&rev=387028&r1=387027&r2=387028
==============================================================================
--- team/file/originate_dial/main/dial.c (original)
+++ team/file/originate_dial/main/dial.c Tue Apr 30 16:29:30 2013
@@ -1106,6 +1106,17 @@
 	return 0;
 }
 
+int ast_dial_reason(struct ast_dial *dial, int num)
+{
+	struct ast_dial_channel *channel;
+
+	if (!dial || AST_LIST_EMPTY(&dial->channels) | !(channel = find_dial_channel(dial, num))) {
+		return -1;
+	}
+
+	return channel->cause;
+}
+
 void ast_dial_set_state_callback(struct ast_dial *dial, ast_dial_state_callback callback)
 {
 	dial->state_callback = callback;

Modified: team/file/originate_dial/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/team/file/originate_dial/main/pbx.c?view=diff&rev=387028&r1=387027&r2=387028
==============================================================================
--- team/file/originate_dial/main/pbx.c (original)
+++ team/file/originate_dial/main/pbx.c Tue Apr 30 16:29:30 2013
@@ -10072,6 +10072,37 @@
 		ast_mutex_unlock(&outgoing->lock);
 	}
 
+	if (reason) {
+		*reason = ast_dial_reason(outgoing->dial, 0);
+	}
+
+	if (ast_dial_state(outgoing->dial) != AST_DIAL_RESULT_ANSWERED &&
+		ast_exists_extension(NULL, context, "failed", 1, NULL)) {
+		struct ast_channel *failed = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", NULL, 0, "OutgoingSpoolFailed");
+
+		if (failed) {
+			char failed_reason[4] = "";
+
+			if (!ast_strlen_zero(context)) {
+				ast_channel_context_set(failed, context);
+			}
+
+			if (account) {
+				ast_cdr_setaccount(failed, account);
+			}
+
+			set_ext_pri(failed, "failed", 1);
+			ast_set_variables(failed, vars);
+			snprintf(failed_reason, sizeof(failed_reason), "%d", ast_dial_reason(outgoing->dial, 0));
+			pbx_builtin_setvar_helper(failed, "REASON", failed_reason);
+
+			if (ast_pbx_run(failed)) {
+				ast_log(LOG_ERROR, "Unable to run PBX on '%s'\n", ast_channel_name(failed));
+				ast_hangup(failed);
+			}
+		}
+	}
+
 	return 0;
 }
 
@@ -10124,6 +10155,10 @@
 			ast_cond_wait(&outgoing->cond, &outgoing->lock);
 		}
 		ast_mutex_unlock(&outgoing->lock);
+	}
+
+	if (reason) {
+		*reason = ast_dial_reason(outgoing->dial, 0);
 	}
 
 	return 0;




More information about the asterisk-commits mailing list