[asterisk-commits] file: branch file/originate_dial r387096 - /team/file/originate_dial/main/pbx.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 1 08:02:16 CDT 2013


Author: file
Date: Wed May  1 08:02:12 2013
New Revision: 387096

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387096
Log:
Reduce duplicated code and apply provided callerid information.

Modified:
    team/file/originate_dial/main/pbx.c

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=387096&r1=387095&r2=387096
==============================================================================
--- team/file/originate_dial/main/pbx.c (original)
+++ team/file/originate_dial/main/pbx.c Wed May  1 08:02:12 2013
@@ -10020,7 +10020,9 @@
 	return NULL;
 }
 
-int ast_pbx_outgoing_exten(const char *type, struct ast_format_cap *cap, const char *addr, int timeout, const char *context, const char *exten, int priority, int *reason, int synchronous, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **channel, int early_media)
+static int pbx_outgoing_attempt(const char *type, struct ast_format_cap *cap, const char *addr, int timeout, const char *context,
+	const char *exten, int priority, const char *app, const char *appdata, int *reason, int synchronous, const char *cid_num,
+	const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **channel, int early_media)
 {
 	RAII_VAR(struct pbx_outgoing *, outgoing, ao2_alloc(sizeof(*outgoing), pbx_outgoing_destroy), ao2_cleanup);
 	struct ast_channel *dialed;
@@ -10030,9 +10032,14 @@
 		return -1;
 	}
 
-	ast_copy_string(outgoing->context, context, sizeof(outgoing->context));
-	ast_copy_string(outgoing->exten, exten, sizeof(outgoing->exten));
-	outgoing->priority = priority;
+	if (!ast_strlen_zero(app)) {
+		ast_copy_string(outgoing->app, app, sizeof(outgoing->app));
+		outgoing->appdata = ast_strdup(appdata);
+	} else {
+		ast_copy_string(outgoing->context, context, sizeof(outgoing->context));
+		ast_copy_string(outgoing->exten, exten, sizeof(outgoing->exten));
+		outgoing->priority = priority;
+	}
 
 	if (!(outgoing->dial = ast_dial_create())) {
 		return -1;
@@ -10054,6 +10061,22 @@
 
 	if (account) {
 		ast_cdr_setaccount(dialed, account);
+	}
+
+	if (!ast_strlen_zero(cid_num) && !ast_strlen_zero(cid_name)) {
+		struct ast_party_connected_line connected;
+
+		ast_party_connected_line_set_init(&connected, ast_channel_connected(dialed));
+
+		ast_set_callerid(dialed, cid_num, cid_name, cid_num);
+		connected.id.number.valid = 1;
+		connected.id.number.str = (char *) cid_num;
+		connected.id.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
+		connected.id.name.valid = 1;
+		connected.id.name.str = (char *) cid_name;
+		connected.id.name.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
+
+		ast_channel_set_connected_line(dialed, &connected, NULL);
 	}
 
 	ast_mutex_init(&outgoing->lock);
@@ -10090,7 +10113,7 @@
 	}
 
 	if (ast_dial_state(outgoing->dial) != AST_DIAL_RESULT_ANSWERED &&
-		ast_exists_extension(NULL, context, "failed", 1, NULL)) {
+		ast_strlen_zero(app) &&	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) {
@@ -10119,75 +10142,20 @@
 	return 0;
 }
 
+int ast_pbx_outgoing_exten(const char *type, struct ast_format_cap *cap, const char *addr, int timeout, const char *context, const char *exten, int priority, int *reason, int synchronous, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **channel, int early_media)
+{
+	return pbx_outgoing_attempt(type, cap, addr, timeout, context, exten, priority, NULL, NULL, reason, synchronous, cid_num,
+		cid_name, vars, account, channel, early_media);
+}
+
 int ast_pbx_outgoing_app(const char *type, struct ast_format_cap *cap, const char *addr, int timeout, const char *app, const char *appdata, int *reason, int synchronous, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel)
 {
-	RAII_VAR(struct pbx_outgoing *, outgoing, ao2_alloc(sizeof(*outgoing), pbx_outgoing_destroy), ao2_cleanup);
-	struct ast_channel *dialed;
-	pthread_t thread;
-
-	if (ast_strlen_zero(app) || !outgoing) {
+	if (ast_strlen_zero(app)) {
 		return -1;
 	}
 
-	ast_copy_string(outgoing->app, app, sizeof(outgoing->app));
-	outgoing->appdata = ast_strdup(appdata);
-
-	if (!(outgoing->dial = ast_dial_create())) {
-		return -1;
-	}
-
-	if (ast_dial_append(outgoing->dial, type, addr)) {
-		return -1;
-	}
-
-	ast_dial_set_global_timeout(outgoing->dial, timeout);
-
-	if (ast_dial_prerun(outgoing->dial, NULL, cap)) {
-		return -1;
-	}
-
-	dialed = ast_dial_channel(outgoing->dial, 0);
-
-	ast_set_variables(dialed, vars);
-
-	if (account) {
-		ast_cdr_setaccount(dialed, account);
-	}
-
-	ast_mutex_init(&outgoing->lock);
-	ast_cond_init(&outgoing->cond, NULL);
-
-	ao2_ref(outgoing, +1);
-
-	if (ast_pthread_create_detached(&thread, NULL, pbx_outgoing_exec, outgoing)) {
-		ast_log(LOG_WARNING, "Unable to spawn dialing thread for '%s/%s'\n", type, addr);
-		ao2_ref(outgoing, -1);
-		return -1;
-	}
-
-	/* Wait for dialing to complete */
-	if (synchronous) {
-		ast_mutex_lock(&outgoing->lock);
-		while (!outgoing->dialed) {
-			ast_cond_wait(&outgoing->cond, &outgoing->lock);
-		}
-		ast_mutex_unlock(&outgoing->lock);
-	}
-
-	/* Wait for execution to complete */
-	if (synchronous > 1) {
-		ast_mutex_lock(&outgoing->lock);
-		while (!outgoing->executed) {
-			ast_cond_wait(&outgoing->cond, &outgoing->lock);
-		}
-		ast_mutex_unlock(&outgoing->lock);
-	}
-
-	if (reason) {
-		*reason = ast_dial_reason(outgoing->dial, 0);
-	}
-
-	return 0;
+	return pbx_outgoing_attempt(type, cap, addr, timeout, NULL, NULL, 0, app, appdata, reason, synchronous, cid_num,
+		cid_name, vars, account, locked_channel, 0);
 }
 
 /* this is the guts of destroying a context --




More information about the asterisk-commits mailing list