]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
channel.c: Fix NewCallerid AMI event not been sent on Caller ID change 34/1334/3
authorIvan Poddubny <ivan.poddubny@gmail.com>
Mon, 28 Sep 2015 06:36:30 +0000 (09:36 +0300)
committerIvan Poddubny <ivan.poddubny@gmail.com>
Mon, 28 Sep 2015 19:20:05 +0000 (22:20 +0300)
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 content
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

main/channel.c

index f26f8652fa4218e654d13023db2e2b4646d5a4d8..ef50e94a74633cd70c071675564697d60f9cc461 100644 (file)
@@ -7388,8 +7388,10 @@ void ast_channel_set_caller(struct ast_channel *chan, const struct ast_party_cal
 
 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 @@ void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_par
        }
 
        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 = ast_strdupa(S_COR(ast_channel_caller(chan)->id.number.valid,
+               ast_channel_caller(chan)->id.number.str, ""));
+       old_name = ast_strdupa(S_COR(ast_channel_caller(chan)->id.name.valid,
+               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);
        }