[asterisk-commits] app dial.c: Factor out a connected line update routine. (asterisk[certified/13.1])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Sep 28 14:07:01 CDT 2015


Joshua Colp has submitted this change and it was merged.

Change subject: app_dial.c: Factor out a connected line update routine.
......................................................................


app_dial.c: Factor out a connected line update routine.

Replace inlined code with update_connected_line_from_peer().

ASTERISK-25423
Reported by: John Hardin

Change-Id: Ia14f18def417645cd7fb453e1bdac682630a5091
---
M apps/app_dial.c
1 file changed, 32 insertions(+), 39 deletions(-)

Approvals:
  Anonymous Coward #1000019: Verified
  Matt Jordan: Looks good to me, approved
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/apps/app_dial.c b/apps/app_dial.c
index b6c0751..86167a1 100644
--- a/apps/app_dial.c
+++ b/apps/app_dial.c
@@ -1038,6 +1038,34 @@
 	}
 }
 
+/*!
+ * \internal
+ * \brief Update connected line on chan from peer.
+ * \since 13.6.0
+ *
+ * \param chan Channel to get connected line updated.
+ * \param peer Channel providing connected line information.
+ * \param is_caller Non-zero if chan is the calling channel.
+ *
+ * \return Nothing
+ */
+static void update_connected_line_from_peer(struct ast_channel *chan, struct ast_channel *peer, int is_caller)
+{
+	struct ast_party_connected_line connected_caller;
+
+	ast_party_connected_line_init(&connected_caller);
+
+	ast_channel_lock(peer);
+	ast_connected_line_copy_from_caller(&connected_caller, ast_channel_caller(peer));
+	ast_channel_unlock(peer);
+	connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
+	if (ast_channel_connected_line_sub(peer, chan, &connected_caller, 0)
+		&& ast_channel_connected_line_macro(peer, chan, &connected_caller, is_caller, 0)) {
+		ast_channel_update_connected_line(chan, &connected_caller, NULL);
+	}
+	ast_party_connected_line_free(&connected_caller);
+}
+
 static struct ast_channel *wait_for_answer(struct ast_channel *in,
 	struct dial_head *out_chans, int *to, struct ast_flags64 *peerflags,
 	char *opt_args[],
@@ -1058,7 +1086,6 @@
 	int single = outgoing && !AST_LIST_NEXT(outgoing, node);
 	int caller_entertained = outgoing
 		&& ast_test_flag64(outgoing, OPT_MUSICBACK | OPT_RINGBACK);
-	struct ast_party_connected_line connected_caller;
 	struct ast_str *featurecode = ast_str_alloca(AST_FEATURE_MAX_LEN + 1);
 	int cc_recall_core_id;
 	int is_cc_recall;
@@ -1066,7 +1093,6 @@
 	int num_ringing = 0;
 	struct timeval start = ast_tvnow();
 
-	ast_party_connected_line_init(&connected_caller);
 	if (single) {
 		/* Turn off hold music, etc */
 		if (!caller_entertained) {
@@ -1087,15 +1113,7 @@
 
 		if (!ast_test_flag64(outgoing, OPT_IGNORE_CONNECTEDLINE)
 			&& !ast_test_flag64(outgoing, DIAL_CALLERID_ABSENT)) {
-			ast_channel_lock(outgoing->chan);
-			ast_connected_line_copy_from_caller(&connected_caller, ast_channel_caller(outgoing->chan));
-			ast_channel_unlock(outgoing->chan);
-			connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
-			if (ast_channel_connected_line_sub(outgoing->chan, in, &connected_caller, 0) &&
-				ast_channel_connected_line_macro(outgoing->chan, in, &connected_caller, 1, 0)) {
-				ast_channel_update_connected_line(in, &connected_caller, NULL);
-			}
-			ast_party_connected_line_free(&connected_caller);
+			update_connected_line_from_peer(in, outgoing->chan, 1);
 		}
 	}
 
@@ -1156,15 +1174,7 @@
 								ast_channel_update_connected_line(in, &o->connected, NULL);
 							}
 						} else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
-							ast_channel_lock(c);
-							ast_connected_line_copy_from_caller(&connected_caller, ast_channel_caller(c));
-							ast_channel_unlock(c);
-							connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
-							if (ast_channel_connected_line_sub(c, in, &connected_caller, 0) &&
-								ast_channel_connected_line_macro(c, in, &connected_caller, 1, 0)) {
-								ast_channel_update_connected_line(in, &connected_caller, NULL);
-							}
-							ast_party_connected_line_free(&connected_caller);
+							update_connected_line_from_peer(in, c, 1);
 						}
 					}
 					if (o->aoc_s_rate_list) {
@@ -1222,16 +1232,7 @@
 				if (single && o->chan
 					&& !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)
 					&& !ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
-					ast_channel_lock(o->chan);
-					ast_connected_line_copy_from_caller(&connected_caller,
-						ast_channel_caller(o->chan));
-					ast_channel_unlock(o->chan);
-					connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
-					if (ast_channel_connected_line_sub(o->chan, in, &connected_caller, 0) &&
-						ast_channel_connected_line_macro(o->chan, in, &connected_caller, 1, 0)) {
-						ast_channel_update_connected_line(in, &connected_caller, NULL);
-					}
-					ast_party_connected_line_free(&connected_caller);
+					update_connected_line_from_peer(in, o->chan, 1);
 				}
 				continue;
 			}
@@ -1262,15 +1263,7 @@
 									ast_channel_update_connected_line(in, &o->connected, NULL);
 								}
 							} else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
-								ast_channel_lock(c);
-								ast_connected_line_copy_from_caller(&connected_caller, ast_channel_caller(c));
-								ast_channel_unlock(c);
-								connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
-								if (ast_channel_connected_line_sub(c, in, &connected_caller, 0) &&
-									ast_channel_connected_line_macro(c, in, &connected_caller, 1, 0)) {
-									ast_channel_update_connected_line(in, &connected_caller, NULL);
-								}
-								ast_party_connected_line_free(&connected_caller);
+								update_connected_line_from_peer(in, c, 1);
 							}
 						}
 						if (o->aoc_s_rate_list) {

-- 
To view, visit https://gerrit.asterisk.org/1325
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia14f18def417645cd7fb453e1bdac682630a5091
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: certified/13.1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>



More information about the asterisk-commits mailing list