Skip to content

Commit 44ae7c9

Browse files
author
Saikiran
committed
Add "REPORT_TYPE":"CACHED" to cache reports
[Description] To differentiate between normal and cached reports, set "REPORT_TYPE": "CACHED" for cached reports. This makes it clear in the report that it's a cached one.  [Solution] Modified the logic to include "REPORT_TYPE":"CACHED" in cached reports. [Testing] Verified that cached reports now include "REPORT_TYPE":"CACHED".
1 parent 7be609f commit 44ae7c9

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

source/bulkdata/profile.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,8 @@ static void* CollectAndReport(void* data)
686686
Vector_RemoveItem(profile->cachedReportList, (void*) thirdCachedReport, NULL);
687687
free(thirdCachedReport);
688688
}
689+
// Before caching the report, add "REPORT_TYPE": "CACHED"
690+
tagReportAsCached(&jsonReport);
689691
Vector_PushBack(profile->cachedReportList, jsonReport);
690692

691693
T2Info("Report Cached, No. of reportes cached = %lu\n", (unsigned long )Vector_Size(profile->cachedReportList));

source/bulkdata/profilexconf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ static void* CollectAndReportXconf(void* data)
344344
Vector_RemoveItem(profile->cachedReportList, (void*) thirdCachedReport, NULL);
345345
free(thirdCachedReport);
346346
}
347+
// Before caching the report, add "REPORT_TYPE": "CACHED"
348+
// tagReportAsCached(&jsonReport);
347349
Vector_PushBack(profile->cachedReportList, strdup(jsonReport));
348350
profile->reportInProgress = false;
349351
/* CID 187010: Dereference before null check */
@@ -414,6 +416,8 @@ static void* CollectAndReportXconf(void* data)
414416
Vector_RemoveItem(profile->cachedReportList, (void*) thirdCachedReport, NULL);
415417
free(thirdCachedReport);
416418
}
419+
// Before caching the report, add "REPORT_TYPE": "CACHED"
420+
tagReportAsCached(&jsonReport);
417421
Vector_PushBack(profile->cachedReportList, strdup(jsonReport));
418422

419423
T2Info("Report Cached, No. of reportes cached = %lu\n", (unsigned long)Vector_Size(profile->cachedReportList));

source/reportgen/reportgen.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,3 +876,61 @@ char *prepareHttpUrl(T2HTTP *http)
876876

877877
return httpUrl;
878878
}
879+
880+
void tagReportAsCached(char **jsonReport)
881+
{
882+
if (!jsonReport)
883+
{
884+
T2Error("jsonReport is NULL\n");
885+
return;
886+
}
887+
888+
cJSON *jsonReportObj = cJSON_Parse(*jsonReport);
889+
if (!jsonReportObj)
890+
{
891+
T2Error("Failed to parse JSON report\n");
892+
return;
893+
}
894+
895+
cJSON *reportTypeEntry = cJSON_CreateObject();
896+
if (!reportTypeEntry)
897+
{
898+
T2Error("Failed to create REPORT_TYPE object\n");
899+
destroyJSONReport(jsonReportObj);
900+
return;
901+
}
902+
cJSON_AddStringToObject(reportTypeEntry, "REPORT_TYPE", "CACHED");
903+
cJSON *searchResult = cJSON_GetObjectItemCaseSensitive(jsonReportObj, "searchResult");
904+
if (searchResult && cJSON_IsArray(searchResult))
905+
{
906+
T2Info("Inserting REPORT_TYPE: CACHED at index 1 of searchResult array\n");
907+
cJSON_InsertItemInArray(searchResult, 1, reportTypeEntry);
908+
}
909+
else
910+
{
911+
cJSON *reportArray = cJSON_GetObjectItemCaseSensitive(jsonReportObj, "Report");
912+
if (reportArray && cJSON_IsArray(reportArray))
913+
{
914+
T2Info("Inserting REPORT_TYPE: CACHED at beginning of Report array\n");
915+
cJSON_InsertItemInArray(reportArray, 0, reportTypeEntry);
916+
}
917+
else
918+
{
919+
T2Error("Neither 'searchResult' nor 'Report' arrays found in the JSON\n");
920+
destroyJSONReport(reportTypeEntry);
921+
destroyJSONReport(jsonReportObj);
922+
return;
923+
}
924+
}
925+
926+
char *updatedJsonReport = cJSON_PrintUnformatted(jsonReportObj);
927+
if (updatedJsonReport)
928+
{
929+
free(*jsonReport); // Freeing the old report only after the new one is generated
930+
*jsonReport = updatedJsonReport;
931+
}
932+
933+
destroyJSONReport(jsonReportObj);
934+
}
935+
936+

source/reportgen/reportgen.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,6 @@ T2ERROR prepareJSONReport(cJSON* jsonObj, char** reportBuff);
7979

8080
char *prepareHttpUrl(T2HTTP *http);
8181

82+
void tagReportAsCached(char **jsonReport);
83+
8284
#endif /* _REPORTGEN_H_ */

0 commit comments

Comments
 (0)