[Asterisk-code-review] channel.c: Fix NewCallerid AMI event not been sent on Caller... (asterisk[11])

Ivan Poddubny asteriskteam at digium.com
Mon Sep 28 02:23:46 CDT 2015


Ivan Poddubny has uploaded a new change for review.

  https://gerrit.asterisk.org/1334

Change subject: channel.c: Fix NewCallerid AMI event not been sent on Caller ID change
......................................................................

channel.c: Fix NewCallerid AMI event not been sent on Caller ID change

Currently, NewCallerid is sent only when pointers to number or name
strings change, which is not always the case. The newly allocated string
may use the same memory, so pointers match, while the contect
is different. As a result, Caller ID updates are often not reported.

With this patch, actual strings are compared, not the pointers.

ASTERISK-25427 #close
Reported by: Ivan Poddubny

Change-Id: I2a1ac3a842f0e092c6058d1cd3e35443bece1b36
---
M main/channel.c
1 file changed, 16 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/34/1334/1

diff --git a/main/channel.c b/main/channel.c
index f26f865..f0efe30 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -7388,8 +7388,10 @@
 
 void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
 {
-	const char *pre_set_number;
-	const char *pre_set_name;
+	const char *old_number;
+	const char *old_name;
+	const char *new_number;
+	const char *new_name;
 
 	if (ast_channel_caller(chan) == caller) {
 		/* Don't set to self */
@@ -7397,14 +7399,19 @@
 	}
 
 	ast_channel_lock(chan);
-	pre_set_number =
-		S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL);
-	pre_set_name = S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, NULL);
+	old_number = S_COR(ast_channel_caller(chan)->id.number.valid,
+				ast_strdupa(ast_channel_caller(chan)->id.number.str), "");
+	old_name = S_COR(ast_channel_caller(chan)->id.name.valid,
+				ast_strdupa(ast_channel_caller(chan)->id.name.str), "");
+
 	ast_party_caller_set(ast_channel_caller(chan), caller, update);
-	if (S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL)
-			!= pre_set_number
-		|| S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, NULL)
-			!= pre_set_name) {
+
+	new_number = S_COR(ast_channel_caller(chan)->id.number.valid,
+				ast_channel_caller(chan)->id.number.str, "");
+	new_name = S_COR(ast_channel_caller(chan)->id.name.valid,
+				ast_channel_caller(chan)->id.name.str, "");
+
+	if (0 != strcmp(old_number, new_number) || 0 != strcmp(old_name, new_name)) {
 		/* The caller id name or number changed. */
 		report_new_callerid(chan);
 	}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2a1ac3a842f0e092c6058d1cd3e35443bece1b36
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 11
Gerrit-Owner: Ivan Poddubny <ivan.poddubny at gmail.com>



More information about the asterisk-code-review mailing list