22 #include "webpa_notification.h"
28 #include "safec_lib.h"
30 #define DEVICE_ESTB_MAC_PARAM "Device.DeviceInfo.X_COMCAST-COM_STB_MAC"
31 #define WEBPA_UNKNOWN_PARAM_VALUE "Unknown"
32 #define WEBPA_NOTIFY_SRC_LEN 32
35 char **g_notifyParamList = NULL;
36 unsigned int g_notifyListSize = 0;
37 const char* webpaNotifyConfigFile = NULL;
38 char* notificationSource = NULL;
40 static void macToLower(
char macValue[],
char macConverted[]);
50 if(NULL != nofityConfigFile)
52 webpaNotifyConfigFile = nofityConfigFile;
53 RDK_LOG(RDK_LOG_INFO,LOG_PARODUS_IF,
"Notify Configuration file set %s \n",webpaNotifyConfigFile);
57 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
"Unable to set Notify Configuration file\n");
70 char convertedMac[32]= {
'\0'};
71 char deviceMac[32] = {
'\0'};
73 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"Entering .... %s \n", __FUNCTION__);
75 if(NULL == notificationSource)
77 char *getParamList[1];
78 getParamList[0]= (
char*) calloc(1,MAX_PARAMETER_LENGTH);
79 strncpy(getParamList[0],DEVICE_ESTB_MAC_PARAM,MAX_PARAMETER_LENGTH);
80 param_t **parametervalArr = (param_t **) malloc(
sizeof(param_t **));
83 *parametervalArr = NULL;
85 ret = (WDMP_STATUS *) malloc(
sizeof(WDMP_STATUS));
86 retCount = (
size_t *) malloc(
sizeof(
size_t));
87 getValues(
const_cast<const char**
>(getParamList), 1, ¶metervalArr, &retCount, &ret);
88 notificationSource = (
char*) malloc(WEBPA_NOTIFY_SRC_LEN);
89 if((NULL != parametervalArr) && (NULL != *parametervalArr) && (NULL != (*parametervalArr)[0].value))
91 strncpy(deviceMac,
const_cast<const char*
>((*parametervalArr)[0].value),WEBPA_NOTIFY_SRC_LEN);
92 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"[%s] Calling MacToLower for MAC: %s ", __FUNCTION__,deviceMac);
93 macToLower(deviceMac,convertedMac);
94 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"[%s] Converted MAC: %s ", __FUNCTION__,convertedMac);
95 snprintf(notificationSource, WEBPA_NOTIFY_SRC_LEN,
"mac:%s", convertedMac);
96 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"[%s] Notify Source :- %s ", __FUNCTION__,notificationSource);
100 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
"[%s] Unable to get Notification Source .!! \n", __FUNCTION__);
101 strncpy(notificationSource, WEBPA_UNKNOWN_PARAM_VALUE,
sizeof(WEBPA_UNKNOWN_PARAM_VALUE));
104 WAL_FREE(getParamList[0]);
108 if(NULL != parametervalArr)
110 if(NULL != *parametervalArr) {
111 WAL_FREE((*parametervalArr)[0].value);
112 WAL_FREE((*parametervalArr)[0].name);
114 WAL_FREE(parametervalArr);
117 return notificationSource;
125 static void macToLower(
char macValue[],
char macConverted[])
131 strncpy(tmp, macValue,
sizeof(tmp));
132 token[i] = strtok(tmp,
":");
135 strncat(macConverted, token[i],31);
136 macConverted[31]=
'\0';
139 while ((token[i] = strtok(NULL,
":")) != NULL)
141 strncat(macConverted, token[i],31);
142 macConverted[31]=
'\0';
145 macConverted[31]=
'\0';
146 for(j = 0; macConverted[j]; j++)
148 macConverted[j] = tolower(macConverted[j]);
159 char *temp_ptr = NULL;
160 char *notifycfg_file_content = NULL;
167 if(NULL == webpaNotifyConfigFile)
169 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
"WebPA notification file path not set");
172 RDK_LOG(RDK_LOG_INFO,LOG_PARODUS_IF,
"Inside getnotifyparamList trying to open %s\n", webpaNotifyConfigFile);
173 fp = fopen(webpaNotifyConfigFile,
"r");
176 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
"Failed to open cfg file %s\n", webpaNotifyConfigFile);
179 fseek(fp, 0, SEEK_END);
180 ch_count = ftell(fp);
183 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
"WebPA notification file is Empty %s\n", webpaNotifyConfigFile);
187 fseek(fp, 0, SEEK_SET);
188 notifycfg_file_content = (
char *) malloc(
sizeof(
char) * (ch_count + 1));
189 fread(notifycfg_file_content, 1, ch_count,fp);
190 notifycfg_file_content[ch_count] =
'\0';
193 cJSON *notify_cfg = cJSON_Parse(notifycfg_file_content);
194 cJSON *notifyArray = cJSON_GetObjectItem(notify_cfg,
"Notify");
195 if(NULL != notifyArray)
197 *ptrnotifyListSize =(int)cJSON_GetArraySize(notifyArray);
198 *notifyParamList = (
char **)malloc(
sizeof(
char *) **ptrnotifyListSize);
199 for (i = 0 ; i < cJSON_GetArraySize(notifyArray) ; i++)
201 temp_ptr = cJSON_GetArrayItem(notifyArray, i)->valuestring;
204 (*notifyParamList)[i] = (
char *)malloc(
sizeof(
char ) * (strlen(temp_ptr)+1));
205 rc=strcpy_s((*notifyParamList)[i],(strlen(temp_ptr)+1),temp_ptr);
210 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"Notify Param = %s\n", temp_ptr);
214 if(NULL != notifyParamList && NULL != ptrnotifyListSize)
216 g_notifyParamList = *notifyParamList;
217 g_notifyListSize = *ptrnotifyListSize;
222 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
"Unable to parse Configuration file");
224 if(notifycfg_file_content)
226 free(notifycfg_file_content);