From 6234ce9cc175dc9438f1ad15e930a2c4f8478353 Mon Sep 17 00:00:00 2001
From: Hemlata <hemlata.bhatt@iopsys.eu>
Date: Thu, 9 Sep 2021 10:07:11 +0000
Subject: [PATCH] Voice: From header handling for UK numbers

---
 channels/chan_brcm.c | 34 +++++++++++++++++++++++-----------
 channels/chan_brcm.h |  2 +-
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/channels/chan_brcm.c b/channels/chan_brcm.c
index ad9b5f5af2..8766ae7aa5 100644
--- a/channels/chan_brcm.c
+++ b/channels/chan_brcm.c
@@ -4026,8 +4026,8 @@ static int brcm_signal_callerid(struct ast_channel *chan, struct brcm_subchannel
 		CLID_STRING clid_string;
 		struct timeval utc_time;
 		struct ast_tm local_time;
-		char number[CLID_MAX_NUMBER];
-		char name[CLID_MAX_NAME];
+                char number[CLID_MAX_NUMBER] = "";
+                char name[CLID_MAX_NAME] = "";
 
 		/* Add datetime to caller id string, format: MMDDHHMM */
 		utc_time = ast_tvnow();
@@ -4048,19 +4048,31 @@ static int brcm_signal_callerid(struct ast_channel *chan, struct brcm_subchannel
 				} else {
 					strcpy(number, "O\0");
 				}
-
-				if (ast_channel_connected(chan)->id.name.valid) {
-					strncpy(name, ast_channel_connected(chan)->id.name.str, CLID_MAX_NAME);
-					name[CLID_MAX_NAME - 1] = '\0';
-				} else {
-					strcpy(name, "O\0");
+                                if (ast_channel_connected(chan)->id.name.valid) {
+                                    if(!ast_channel_caller(chan)->id.number.presentation) //if clir is not set
+                                    {   /*We have received a request with userinfo portion as "anonymous",but clir=0 ,no calling party name is sent */
+                                        if(strcasecmp("anonymous",ast_channel_connected(chan)->id.number.str)==0)
+                                           ast_debug(2,"Caller number is %s and clir=0 ",ast_channel_connected(chan)->id.number.str);
+                                        else if(ast_channel_connected(chan)->id.name.str)
+                                        {
+                                            /*if "userinfo" comes as "unsubscribed",no calling party number and name is displayed */
+                                            if(strcasecmp("unsubscribed",ast_channel_connected(chan)->id.number.str)!=0){
+                                                strncpy(name, ast_channel_connected(chan)->id.name.str, CLID_MAX_NAME-1);
+                                            }
+                                        }
+                                    else
+                                    {
+                                        strncpy(name, ast_channel_connected(chan)->id.name.str, CLID_MAX_NAME-1);
+                                    }
 				}
-			} else {
+                             } else
+                                    strcpy(name, "O\0");
+                            } else {
 				/* Number and/or name available but presentation is not allowed */
 				strcpy(number, "P\0");
 				strcpy(name, "P\0");
-			}
-		} else {
+                        }
+                } else {
 			/* Name and number not available. Will probably not be reached */
 			strcpy(number, "0\0");
 			strcpy(name, "0\0");
diff --git a/channels/chan_brcm.h b/channels/chan_brcm.h
index 375d1dd78c..bfb7867ce8 100644
--- a/channels/chan_brcm.h
+++ b/channels/chan_brcm.h
@@ -224,7 +224,7 @@ typedef struct {
 
 /* Caller ID */
 #define CLID_MAX_DATE	10
-#define CLID_MAX_NUMBER	16
+#define CLID_MAX_NUMBER	21
 #define CLID_MAX_NAME	16
 typedef struct CLID_STRING
 {
-- 
GitLab