-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrrdEventProcess.c
More file actions
701 lines (652 loc) · 31.3 KB
/
rrdEventProcess.c
File metadata and controls
701 lines (652 loc) · 31.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2018 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "rrdRunCmdThread.h"
#include "rrdJsonParser.h"
#include "rrdEventProcess.h"
#define COMMAND_DELIM ';'
#define RRD_TMP_DIR "/tmp/"
static void processIssueType(data_buf *rbuf);
static void processIssueTypeInDynamicProfile(data_buf *rbuf, issueNodeData *pIssueNode);
static void processIssueTypeInStaticProfile(data_buf *rbuf, issueNodeData *pIssueNode);
static void processIssueTypeInInstalledPackage(data_buf *rbuf, issueNodeData *pIssueNode);
static void removeSpecialCharacterfromIssueTypeList(char *str);
static int issueTypeSplitter(char *input_str, const char delimeter, char ***args);
static void freeParsedJson(cJSON *jsonParsed);
/*
* @function processWebCfgTypeEvent
* @brief Processes a web configuration type event by decoding the data and freeing the buffer data.
* @param data_buf *rbuf - Buffer containing event data and metadata.
* @return void
*/
void processWebCfgTypeEvent(data_buf *rbuf)
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Entering.. \n", __FUNCTION__, __LINE__);
if(rbuf && rbuf->mdata)
{
decodeWebCfgData(rbuf->mdata);
free(rbuf->mdata);
}
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Exiting...\n", __FUNCTION__, __LINE__);
return;
}
/*
* @function processIssueTypeEvent
* @brief Processes an issue type event by splitting the issue types from the input data buffer,
* initializing command buffers and handling each issue type individually.
* @param data_buf *rbuf - Buffer containing event data and metadata.
* @return void
*/
void processIssueTypeEvent(data_buf *rbuf)
{
char **cmdMap = NULL;
int index = 0, count = 0, dataMsgLen = 0;
data_buf *cmdBuff = NULL;
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Entering.. \n", __FUNCTION__, __LINE__);
if (NULL != rbuf)
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: IssueType List [%s]... \n", __FUNCTION__, __LINE__, rbuf->mdata);
count = issueTypeSplitter(rbuf->mdata, ',', &cmdMap);
if (count > 0)
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: IssueType Count [%d]... \n", __FUNCTION__, __LINE__, count);
for (index = 0; index < count; index++)
{
cmdBuff = NULL;
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: IssueType [%s]... \n", __FUNCTION__, __LINE__, cmdMap[index]);
cmdBuff = (data_buf *)malloc(sizeof(data_buf));
if (cmdBuff)
{
dataMsgLen = strlen(cmdMap[index]) + 1;
RRD_data_buff_init(cmdBuff, EVENT_MSG, RRD_DEEPSLEEP_INVALID_DEFAULT); /* Setting Deafult Values*/
cmdBuff->inDynamic = rbuf->inDynamic;
if(cmdBuff->inDynamic)
{
cmdBuff->jsonPath = rbuf->jsonPath;
}
cmdBuff->appendMode = rbuf->appendMode;
cmdBuff->mdata = (char *)calloc(1, dataMsgLen);
if (cmdBuff->mdata)
{
strncpy((char *)cmdBuff->mdata, cmdMap[index], dataMsgLen);
processIssueType(cmdBuff);
}
else
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Memory Allocation Failed... \n", __FUNCTION__, __LINE__);
}
if(cmdBuff)
{
free(cmdBuff);
cmdBuff = NULL;
}
}
else
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Memory Allocation Failed... \n", __FUNCTION__, __LINE__);
}
if( cmdMap[index])
{
free(cmdMap[index]);
cmdMap[index] = NULL;
}
}
if( cmdMap)
{
free(cmdMap);
cmdMap = NULL;
}
}
}
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Exiting...\n", __FUNCTION__, __LINE__);
return;
}
/*
* @function processIssueType
* @brief Processes the given issue type by extracting issue node data and determining
* whether to handle it as a dynamic or static profile.
* @param data_buf *rbuf - Buffer containing event data and metadata.
* @return void
*/
static void processIssueType(data_buf *rbuf)
{
issueNodeData *pIssueNode = NULL;
issueData *dynamicprofiledata = NULL;
issueData *staticprofiledata = NULL;
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Entering.. \n", __FUNCTION__, __LINE__);
if (rbuf->mdata != NULL) // issue data exits
{
pIssueNode = (issueNodeData *)malloc(sizeof(issueNodeData));
if(pIssueNode)
{
getIssueInfo((char *)rbuf->mdata, pIssueNode); // issue data extract
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Extracted Node %s and Sub Node %s \n", __FUNCTION__, __LINE__, pIssueNode->Node, pIssueNode->subNode);
if (rbuf->appendMode)
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Received append request to process static and dynamic profiles... \n", __FUNCTION__, __LINE__);
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Reading dynamic profile command info... \n", __FUNCTION__, __LINE__);
dynamicprofiledata = processIssueTypeInDynamicProfileappend(rbuf, pIssueNode);
if (dynamicprofiledata == NULL)
{
RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Dynamic Profie Info not found, Download RDM package... \n", __FUNCTION__, __LINE__);
}
else
{
RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Read complete for Dynamic Profile: RFCValue: %s, Command: %s, Timeout: %d... \n", __FUNCTION__, __LINE__, dynamicprofiledata->rfcvalue, dynamicprofiledata->command, dynamicprofiledata->timeout);
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Reading static profile command info... \n", __FUNCTION__, __LINE__);
staticprofiledata = processIssueTypeInStaticProfileappend(rbuf, pIssueNode);
if (staticprofiledata == NULL)
{
RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Static Command Info not found for IssueType!!! \n", __FUNCTION__, __LINE__);
// Free dynamicprofiledata since we can't proceed
if (dynamicprofiledata != NULL)
{
if (dynamicprofiledata->rfcvalue != NULL)
{
free(dynamicprofiledata->rfcvalue);
}
if (dynamicprofiledata->command != NULL)
{
free(dynamicprofiledata->command);
}
free(dynamicprofiledata);
}
}
else
{
RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Read complete for Static Profile: RFCValue: %s, Command: %s, Timeout: %d... \n", __FUNCTION__, __LINE__, staticprofiledata->rfcvalue, staticprofiledata->command, staticprofiledata->timeout);
// Check if commands are NULL before using them
if (dynamicprofiledata->command == NULL || staticprofiledata->command == NULL)
{
RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Command is NULL in dynamic or static profile... \n", __FUNCTION__, __LINE__);
// Free dynamicprofiledata
if (dynamicprofiledata != NULL)
{
if (dynamicprofiledata->rfcvalue != NULL)
{
free(dynamicprofiledata->rfcvalue);
}
if (dynamicprofiledata->command != NULL)
{
free(dynamicprofiledata->command);
}
free(dynamicprofiledata);
}
// Free staticprofiledata
if (staticprofiledata != NULL)
{
if (staticprofiledata->rfcvalue != NULL)
{
free(staticprofiledata->rfcvalue);
}
if (staticprofiledata->command != NULL)
{
free(staticprofiledata->command);
}
free(staticprofiledata);
}
}
else
{
//Remove the double quotes
size_t staticstrlen = strlen(staticprofiledata->command);
size_t dynamicstrlen = strlen(dynamicprofiledata->command);
if (staticstrlen > 0 && staticprofiledata->command[staticstrlen - 1] == '"') {
staticprofiledata->command[staticstrlen - 1] = '\0';
staticstrlen--; // Update length after removing trailing quote
}
if (dynamicprofiledata->command[0] == '"') {
dynamicprofiledata->command[0] = COMMAND_DELIM;
}
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Static Profile Commands: %s, Dynamic Profile Commands: %s\n", __FUNCTION__, __LINE__, staticprofiledata->command, dynamicprofiledata->command);
size_t appendstrlen = (staticstrlen + dynamicstrlen + 1);
char *appendcommandstr = (char *)realloc(staticprofiledata->command, appendstrlen);
if (appendcommandstr == NULL) {
RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Memory Allocation Failed... \n", __FUNCTION__, __LINE__);
// Free staticprofiledata on realloc failure
if (staticprofiledata != NULL)
{
if (staticprofiledata->rfcvalue != NULL)
{
free(staticprofiledata->rfcvalue);
}
if (staticprofiledata->command != NULL)
{
free(staticprofiledata->command);
}
free(staticprofiledata);
staticprofiledata = NULL; // Set to NULL to prevent double-free
}
// Free dynamicprofiledata on realloc failure
if (dynamicprofiledata != NULL)
{
if (dynamicprofiledata->rfcvalue != NULL)
{
free(dynamicprofiledata->rfcvalue);
}
if (dynamicprofiledata->command != NULL)
{
free(dynamicprofiledata->command);
}
free(dynamicprofiledata);
dynamicprofiledata = NULL; // Set to NULL to prevent double-free
}
}
else
{
strcat(appendcommandstr, dynamicprofiledata->command);
staticprofiledata->command = appendcommandstr;
RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Updated command after append from dynamic and static profile: %s \n", __FUNCTION__, __LINE__, staticprofiledata->command);
RDK_LOG(RDK_LOG_DEBUG,LOG_REMDEBUG,"[%s:%d]: Executing Commands in Runtime Service... \n",__FUNCTION__,__LINE__);
checkIssueNodeInfo(pIssueNode, NULL, rbuf, false, staticprofiledata);
// NOTE: staticprofiledata is freed by executeCommands() via checkIssueNodeInfo()
// Do NOT free staticprofiledata here to avoid double-free
}
// Free dynamicprofiledata after use
if (dynamicprofiledata != NULL)
{
if (dynamicprofiledata->rfcvalue != NULL)
{
free(dynamicprofiledata->rfcvalue);
}
if (dynamicprofiledata->command != NULL)
{
free(dynamicprofiledata->command);
}
free(dynamicprofiledata);
}
}
}
}
}
else if (rbuf->inDynamic)
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Checking if Issue marked inDynamic... \n", __FUNCTION__, __LINE__);
processIssueTypeInDynamicProfile(rbuf, pIssueNode);
}
else
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Issue not marked as inDynamic... \n", __FUNCTION__, __LINE__);
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Checking Issue from Static... \n", __FUNCTION__, __LINE__);
processIssueTypeInStaticProfile(rbuf, pIssueNode);
}
//CID-336989: Resource leak
}
else
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Memory Allocation Failed... \n", __FUNCTION__, __LINE__);
}
}
else
{
/* Fix for warning Wformat-overflow : directive argument is null*/
RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Value is empty for RFC Parameter \n", __FUNCTION__, __LINE__);
}
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Exiting...\n", __FUNCTION__, __LINE__);
return;
}
/*
* @function processIssueTypeInDynamicProfile
* @brief Processes the given issue type by checking if the issue exists in the dynamic profile JSON.
* If the issue is found, it handles the issue appropriately.
* @param data_buf *rbuf - Buffer containing event data and metadata.
* @param issueNodeData *pIssueNode - Pointer to structure containing issue node data.
* @return void
*/
static void processIssueTypeInDynamicProfile(data_buf *rbuf, issueNodeData *pIssueNode)
{
cJSON *jsonParsed = NULL;
bool isDynamicIssue=false;
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Entering.. \n", __FUNCTION__, __LINE__);
RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Issue Marked as inDynamic... \n", __FUNCTION__, __LINE__);
RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Checking Dynamic Profile... \n", __FUNCTION__, __LINE__);
if (rbuf->jsonPath == NULL) // Dynamic Profile JSON does not exists
{
RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Dynamic Profile JSON Not Found... \n", __FUNCTION__, __LINE__);
free(rbuf->mdata);
rbuf->mdata = NULL;
}
else
{
jsonParsed = readAndParseJSON(rbuf->jsonPath); // Parse Dynamic Profile JSON from Package
if (jsonParsed == NULL)
{
RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Dynamic JSON Parse/Read failed... %s\n", __FUNCTION__, __LINE__, rbuf->jsonPath);
free(rbuf->mdata);
rbuf->mdata = NULL;
free(rbuf->jsonPath);
rbuf->jsonPath = NULL;
}
else
{
isDynamicIssue = findIssueInParsedJSON(pIssueNode, jsonParsed);
if (!isDynamicIssue) // Issue Data not in Dynamic Profile JSON
{
RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Issue Data not found in Dynamic JSON %s... \n", __FUNCTION__, __LINE__, rbuf->jsonPath);
free(rbuf->mdata);
rbuf->mdata = NULL;
free(rbuf->jsonPath);
rbuf->jsonPath = NULL;
}
else
{
// Issue found in Dynamic Prof JSON
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Issue Data Node: %s and Sub-Node: %s found in Dynamic JSON File %s...\n", __FUNCTION__, __LINE__, pIssueNode->Node, pIssueNode->subNode, rbuf->jsonPath);
checkIssueNodeInfo(pIssueNode, jsonParsed, rbuf, false, NULL);
}
}
freeParsedJson(jsonParsed);
}
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Exiting...\n", __FUNCTION__, __LINE__);
return;
}
/*
* @function processIssueTypeInStaticProfile
* @brief Processes the given issue type by checking if the issue exists in the static profile JSON.
* If the issue is found, it handles the issue appropriately. If not found, it will further
* check in the installed package.
* @param data_buf *rbuf - Buffer containing event data and metadata.
* @param issueNodeData *pIssueNode - Pointer to structure containing issue node data.
* @return void
*/
static void processIssueTypeInStaticProfile(data_buf *rbuf, issueNodeData *pIssueNode)
{
cJSON *jsonParsed = NULL;
bool isStaticIssue = false;
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Entering.. \n", __FUNCTION__, __LINE__);
RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Checking Static Profile... \n", __FUNCTION__, __LINE__);
#if !defined(GTEST_ENABLE)
jsonParsed = readAndParseJSON(RRD_JSON_FILE);
#else
jsonParsed = readAndParseJSON(rbuf->jsonPath);
#endif
if (jsonParsed == NULL)
{ // Static Profile JSON Parsing or Read Fail
RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Static Profile Parse/Read failed... %s\n", __FUNCTION__, __LINE__, RRD_JSON_FILE);
processIssueTypeInInstalledPackage(rbuf, pIssueNode);
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Exiting...\n", __FUNCTION__, __LINE__);
return;
}
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Static Profile Parse And Read Success... %s\n", __FUNCTION__, __LINE__, RRD_JSON_FILE);
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Check if Issue in Parsed Static JSON... %s\n", __FUNCTION__, __LINE__, RRD_JSON_FILE);
isStaticIssue = findIssueInParsedJSON(pIssueNode, jsonParsed);
if (isStaticIssue)
{
RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Issue Data Node: %s and Sub-Node: %s found in Static JSON File %s... \n", __FUNCTION__, __LINE__, pIssueNode->Node, pIssueNode->subNode, RRD_JSON_FILE);
// CID 336988: Double free (USE_AFTER_FREE)
if(rbuf)
{
checkIssueNodeInfo(pIssueNode, jsonParsed, rbuf, false, NULL); // sanity Check and Get Command List
}
}
else
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d] Issue Data Not found in Static JSON File... \n", __FUNCTION__, __LINE__);
processIssueTypeInInstalledPackage(rbuf, pIssueNode);
}
freeParsedJson(jsonParsed);
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Exiting...\n", __FUNCTION__, __LINE__);
return;
}
issueData* processIssueTypeInDynamicProfileappend(data_buf *rbuf, issueNodeData *pIssueNode)
{
issueData *dynamicdata = NULL;
cJSON *jsonParsed = NULL;
char *dynJSONPath = NULL;
int rrdjsonlen = 0, persistentAppslen = 0, prefixlen = 0;
bool isDynamicIssue = false;
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Entering.. \n", __FUNCTION__, __LINE__);
rrdjsonlen = strlen(RRD_JSON_FILE);
#ifdef IARMBUS_SUPPORT
persistentAppslen = strlen(RRD_MEDIA_APPS);
#else
persistentAppslen = strlen(RRD_TMP_DIR);
#endif
prefixlen = strlen(RDM_PKG_PREFIX);
dynJSONPath = (char *)malloc(persistentAppslen + prefixlen + strlen(pIssueNode->Node) + rrdjsonlen + 1);
if(dynJSONPath == NULL)
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Memory Allocation Failed... \n", __FUNCTION__, __LINE__);
return dynamicdata;
}
#ifdef IARMBUS_SUPPORT
sprintf(dynJSONPath, "%s%s%s%s", RRD_MEDIA_APPS, RDM_PKG_PREFIX, pIssueNode->Node, RRD_JSON_FILE);
#else
sprintf(dynJSONPath, "%s%s%s%s", RRD_TMP_DIR, RDM_PKG_PREFIX, pIssueNode->Node, RRD_JSON_FILE);
#endif
RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Checking Dynamic Profile... \n", __FUNCTION__, __LINE__);
jsonParsed = readAndParseJSON(dynJSONPath);
if (jsonParsed == NULL)
{
RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Dynamic Profile Parse/Read failed... %s\n", __FUNCTION__, __LINE__, dynJSONPath);
RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Going to RDM Request... \n", __FUNCTION__, __LINE__);
#if !defined(GTEST_ENABLE)
RRDRdmManagerDownloadRequest(pIssueNode, dynJSONPath, rbuf, false); //goto RDM_RRD_REQ_LABEL;
#endif
}
else
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Dynamic Profile Parse And Read Success... %s\n", __FUNCTION__, __LINE__, dynJSONPath);
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Check if Issue in Parsed Dynamic JSON... %s\n", __FUNCTION__, __LINE__, dynJSONPath);
isDynamicIssue = findIssueInParsedJSON(pIssueNode, jsonParsed);
if (isDynamicIssue)
{
// Issue Data in Dynamic Profile JSON
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Issue Data Node:%s and Sub-Node:%s found in Dynamic JSON File %s...\n", __FUNCTION__, __LINE__, pIssueNode->Node, pIssueNode->subNode, dynJSONPath);
free(dynJSONPath);
// Get the command for received Issue Type of the Issue Category
dynamicdata = getIssueCommandInfo(pIssueNode, jsonParsed, rbuf->mdata);
RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Dynamic Profile Data: RFCValue: %s, Command: %s, Timeout: %d... \n", __FUNCTION__, __LINE__, dynamicdata->rfcvalue, dynamicdata->command, dynamicdata->timeout);
}
else
{
// Issue Data not in Dynamic Profile JSON
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Requested Issue Data not found in Dynamic Profile JSON!!! \n", __FUNCTION__, __LINE__);
}
}
freeParsedJson(jsonParsed);
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Exiting...\n", __FUNCTION__, __LINE__);
return dynamicdata;
}
issueData* processIssueTypeInStaticProfileappend(data_buf *rbuf, issueNodeData *pIssueNode)
{
cJSON *jsonParsed = NULL;
bool isStaticIssue = false;
issueData *staticdata = NULL;
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Entering.. \n", __FUNCTION__, __LINE__);
RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Reading Static Profile Commands... \n", __FUNCTION__, __LINE__);
jsonParsed = readAndParseJSON(RRD_JSON_FILE);
if (jsonParsed == NULL)
{ // Static Profile JSON Parsing or Read Fail
RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Static Profile Parse/Read failed... %s\n", __FUNCTION__, __LINE__, RRD_JSON_FILE);
return staticdata;
}
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Static Profile Parse And Read Success... %s\n", __FUNCTION__, __LINE__, RRD_JSON_FILE);
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Check if Issue in Parsed Static JSON... %s\n", __FUNCTION__, __LINE__, RRD_JSON_FILE);
isStaticIssue = findIssueInParsedJSON(pIssueNode, jsonParsed);
if (isStaticIssue)
{
// Issue in Static Profile JSON
RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Issue Data Node: %s and Sub-Node: %s found in Static JSON File %s... \n", __FUNCTION__, __LINE__, pIssueNode->Node, pIssueNode->subNode, RRD_JSON_FILE);
// Get the command for received Issue Type of the Issue Category
staticdata = getIssueCommandInfo(pIssueNode, jsonParsed, rbuf->mdata);
RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Static Profile Data: RFCValue: %s, Command: %s, Timeout: %d... \n", __FUNCTION__, __LINE__, staticdata->rfcvalue, staticdata->command, staticdata->timeout);
}
else
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d] Issue Data Not found in Static JSON File... \n", __FUNCTION__, __LINE__);
}
freeParsedJson(jsonParsed);
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Exiting...\n", __FUNCTION__, __LINE__);
return staticdata;
}
/*
* @function processIssueTypeInInstalledPackage
* @brief Processes the given issue type by checking if the issue exists in the installed package's dynamic profile JSON.
* If the issue is found, it handles the issue appropriately. If the JSON read or parse fails, it sends an RDM request.
* @param data_buf *rbuf - Buffer containing event data and metadata.
* @param issueNodeData *pIssueNode - Pointer to structure containing issue node data.
* @return void
*/
static void processIssueTypeInInstalledPackage(data_buf *rbuf, issueNodeData *pIssueNode)
{
cJSON *jsonParsed = NULL;
char *dynJSONPath = NULL;
int rrdjsonlen = 0, persistentAppslen = 0, prefixlen = 0, suffixlen = 0;
bool isDynamicIssue = false;
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Entering.. \n", __FUNCTION__, __LINE__);
#if !defined(GTEST_ENABLE)
rrdjsonlen = strlen(RRD_JSON_FILE);
#ifdef IARMBUS_SUPPORT
persistentAppslen = strlen(RRD_MEDIA_APPS);
#else
persistentAppslen = strlen(RRD_TMP_DIR);
#endif
prefixlen = strlen(RDM_PKG_PREFIX);
suffixlen = strlen(RDM_PKG_SUFFIX);
dynJSONPath = (char *)malloc(persistentAppslen + prefixlen + suffixlen + strlen(pIssueNode->Node) + rrdjsonlen + 1);
#else
int utjsonlen = strlen(rbuf->jsonPath);
dynJSONPath = (char *)malloc(utjsonlen + 1);
#endif
if(dynJSONPath == NULL)
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Memory Allocation Failed... \n", __FUNCTION__, __LINE__);
return;
}
#if !defined(GTEST_ENABLE)
#ifdef IARMBUS_SUPPORT
sprintf(dynJSONPath, "%s%s%s%s", RRD_MEDIA_APPS, RDM_PKG_PREFIX, pIssueNode->Node, RRD_JSON_FILE);
#else
sprintf(dynJSONPath, "%s%s%s%s", RRD_TMP_DIR, RDM_PKG_PREFIX, pIssueNode->Node, RRD_JSON_FILE);
#endif
#else
sprintf(dynJSONPath, "%s", rbuf->jsonPath);
#endif
RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Checking Dynamic Profile... \n", __FUNCTION__, __LINE__);
jsonParsed = readAndParseJSON(dynJSONPath);
if (jsonParsed == NULL)
{
RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Dynamic Profile Parse/Read failed... %s\n", __FUNCTION__, __LINE__, dynJSONPath);
RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Going to RDM Request... \n", __FUNCTION__, __LINE__);
#if !defined(GTEST_ENABLE)
RRDRdmManagerDownloadRequest(pIssueNode, dynJSONPath, rbuf, false); //goto RDM_RRD_REQ_LABEL;
#endif
}
else
{
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Dynamic Profile Parse And Read Success... %s\n", __FUNCTION__, __LINE__, dynJSONPath);
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Check if Issue in Parsed Dynamic JSON... %s\n", __FUNCTION__, __LINE__, dynJSONPath);
isDynamicIssue = findIssueInParsedJSON(pIssueNode, jsonParsed);
if (isDynamicIssue)
{
// Issue Data in Dynamic Profile JSON
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Issue Data Node:%s and Sub-Node:%s found in Dynamic JSON File %s...\n", __FUNCTION__, __LINE__, pIssueNode->Node, pIssueNode->subNode, dynJSONPath);
free(dynJSONPath);
checkIssueNodeInfo(pIssueNode, jsonParsed, rbuf, false, NULL);
}
else
{
// Issue Data not in Dynamic Profile JSON
#if !defined(GTEST_ENABLE)
RRDRdmManagerDownloadRequest(pIssueNode, dynJSONPath, rbuf, false);
#endif
}
}
freeParsedJson(jsonParsed);
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Exiting...\n", __FUNCTION__, __LINE__);
return;
}
/*
* @function freeParsedJson
* @brief Frees the memory allocated to a parsed cJSON object.
* @param cJSON *jsonParsed - Pointer to the parsed JSON object to be freed.
* @return void
*/
static void freeParsedJson(cJSON *jsonParsed)
{
if(jsonParsed)
{
cJSON_Delete(jsonParsed);
RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Free static JSON Parsed...\n", __FUNCTION__, __LINE__);
}
}
/*
* @function removeSpecialCharacterfromIssueTypeList
* @brief Removes special characters from the issue type list, retaining only alphanumeric
* characters, commas, and periods.
* @param char *str - The string from which special characters will be removed.
* @return void
*/
static void removeSpecialCharacterfromIssueTypeList(char *str)
{
int source = 0;
int destination = 0;
while (str[source] != '\0')
{
if (isalnum(str[source]) || str[source] == ',' || str[source] == '.')
{
str[destination] = str[source];
++destination;
}
++source;
}
str[destination] = '\0';
}
/*
* @function issueTypeSplitter
* @brief Splits a given string into tokens based on a specified delimiter, and removes any
* special characters from the string before splitting.
* @param char *input_str - The input string to be split.
* @param const char delimiter - The character used to split the string.
* @param char ***args - Pointer to an array of strings where the tokens will be stored.
* @return int - The number of tokens found in the string.
*/
static int issueTypeSplitter(char *input_str, const char delimeter, char ***args)
{
int cnt = 1, i = 0;
char *str = input_str;
removeSpecialCharacterfromIssueTypeList(str);
while (*str == delimeter)
str++;
char *str2 = str;
while (*(str2++))
if (*str2 == delimeter && *(str2 + 1) != delimeter && *(str2 + 1) != 0)
cnt++;
(*args) = (char **)malloc(sizeof(char *) * cnt);
if (*args == NULL)
{
cnt = 0;
}
else
{
for (i = 0; i < cnt; i++)
{
char *ts = str;
while (*str != delimeter && *str != 0)
str++;
int len = (str - ts + 1);
(*args)[i] = (char *)malloc(sizeof(char) * len);
memcpy((*args)[i], ts, sizeof(char) * (len - 1));
(*args)[i][len - 1] = 0;
while (*str == delimeter)
str++;
}
}
return cnt;
}