29 #include <cjson/cJSON.h>
31 #include <telemetry_busmessage_sender.h>
32 #include "safec_lib.h"
54 #define RFC_CONFIG_DATA "/tmp/rfc_configdata.txt"
55 #define RFC_SSH_CONFIG_DATA "/tmp/RFC/.RFC_SSHWhiteList.list"
80 return (item->type & 0xFF) == cJSON_Array;
91 static int saveToFile(cJSON * arrayNode,
const char* filename)
93 printf(
"dcmjsonparser: Entering %s\n", __FUNCTION__);
97 fp = fopen(filename,
"w+");
100 int arraySize = cJSON_GetArraySize(arrayNode);
101 for(i =0;i<arraySize;i++)
103 cJSON * aItem = cJSON_GetArrayItem(arrayNode,i);
104 status = fprintf(fp,
"%s\n",aItem->valuestring);
106 printf(
"dcmjsonparser: %s:%d Warning failed to write to file %s \n",__FUNCTION__, __LINE__,strerror(errno));
113 printf(
"dcmjsonparser: Failed to open %s : %s\n",filename,strerror(errno));
127 cJSON * arrayNode = NULL;
136 else if (NULL != node->child)
139 if( NULL != childNode)
141 arrayNode = childNode;
169 printf(
"dcmjsonparser: Entering %s\n", __FUNCTION__);
171 if(NULL != childNode)
174 printf(
"dcmjsonparser: SSHWhiteList processed successfully\n");
204 void main(
int argc,
char **argv)
206 char *data = NULL,*dcmResponse = NULL;
207 cJSON *paramObj = NULL, *childObj = NULL,*json=NULL,*configData=NULL,*effectiveImmediate=NULL;
208 FILE *fileRead = NULL,*fileWrite =NULL;
217 printf(
"dcmjsonparser: Pass valid arguments \n");
222 dcmResponse = argv[1];
225 t2_init(
"dcm-parser");
227 printf(
"dcmjsonparser: dcm response file name %s\n",dcmResponse);
229 fileRead = fopen( dcmResponse,
"r+" );
230 if( fileRead == NULL )
232 printf(
"dcmjsonparser: Error opening file in read mode\n" );
236 fseek( fileRead, 0, SEEK_END );
237 len = ftell( fileRead );
238 fseek( fileRead, 0, SEEK_SET );
239 data = (
char* )malloc( len + 1 );
240 fread( data, 1, len, fileRead );
245 json = cJSON_Parse( data );
249 printf(
"dcmjsonparser: json parse error: [%s]\n", cJSON_GetErrorPtr() );
250 t2_event_d(
"SYS_INFO_WEBPA_Config_Corruption", 1);
254 printf(
"dcmjsonparser: cjson parse success\n" );
259 printf(
"dcmjsonparser: Error opening file in write mode\n" );
264 paramObj = cJSON_GetObjectItem( json,
"featureControl" );
265 if( paramObj != NULL )
267 cJSON * configset_id = cJSON_GetObjectItem( paramObj,
"configset-id" );
268 if(configset_id !=NULL)
270 char *configset = cJSON_GetObjectItem( paramObj,
"configset-id" )->valuestring;
273 printf(
"dcmjsonparser: configset-id is %s\n", configset );
277 printf(
"dcmjsonparser: configset-id value is NULL\n");
282 printf(
"dcmjsonparser: configset-id not recieved in response\n");
284 cJSON * configset_label = cJSON_GetObjectItem( paramObj,
"configset-label" );
285 if(configset_label !=NULL)
287 char *configset = cJSON_GetObjectItem( paramObj,
"configset-label" )->valuestring;
290 printf(
"dcmjsonparser: configset-label is %s\n", configset );
294 printf(
"dcmjsonparser: configset-label value is NULL\n");
299 printf(
"dcmjsonparser: configset-label not recieved in response\n");
302 childObj = cJSON_GetObjectItem( paramObj,
"features" );
305 int subitemSize = cJSON_GetArraySize( childObj );
306 printf(
"dcmjsonparser: features array size is %d\n",subitemSize);
307 int length = strlen(
"sshwhitelist");
308 for( i = 0; i < subitemSize; i++ )
310 cJSON* subitem = cJSON_GetArrayItem( childObj, i );
311 cJSON* featureName = cJSON_GetObjectItem(subitem,
"name" );
312 cJSON* listType = cJSON_GetObjectItem(subitem,
"listType");
313 if (featureName != NULL && listType != NULL)
315 rc = strcasecmp_s(
"sshwhitelist",length, featureName->valuestring, &ind);
317 if ((!ind) && (rc == EOK))
319 printf(
"dcmjsonparser: SSHWhiteList feature found!!\n");
324 effectiveImmediate = cJSON_GetObjectItem( subitem,
"effectiveImmediate" );
325 int effectiveImmediatevalue;
326 if(effectiveImmediate !=NULL)
328 effectiveImmediatevalue=effectiveImmediate->valueint;
329 printf(
"dcmjsonparser: effectiveImmediate is %d\n",effectiveImmediatevalue);
333 printf(
"dcmjsonparser: featureControl.features.effectiveImmediate object is not present\n");
336 configData = cJSON_GetObjectItem( subitem,
"configData" );
337 if(configData !=NULL)
339 cJSON *configObject = configData->child;
340 while( configObject )
342 char *configKey = configObject->string;
343 char *configValue = configObject->valuestring;
344 printf(
"dcmjsonparser: key is %s\n",configKey);
345 printf(
"dcmjsonparser: value is %s\n",configValue);
346 if(strncmp(configKey,
"tr181.",6)==0)
349 fprintf(fileWrite,
"%s#~%s#~%d\n", configKey,configValue,effectiveImmediatevalue );
351 configObject = configObject->next;
358 printf(
"dcmjsonparser: featureControl.features object is not present\n");
363 printf(
"dcmjsonparser: featureControl object is not present\n");