Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions source/bulkdata/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,8 @@ static void* CollectAndReport(void* data)
Vector_RemoveItem(profile->cachedReportList, (void*) thirdCachedReport, NULL);
free(thirdCachedReport);
}
// Before caching the report, add "REPORT_TYPE": "CACHED"
tagReportAsCached(&jsonReport);
Vector_PushBack(profile->cachedReportList, jsonReport);

T2Info("Report Cached, No. of reportes cached = %lu\n", (unsigned long )Vector_Size(profile->cachedReportList));
Expand Down
4 changes: 4 additions & 0 deletions source/bulkdata/profilexconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ static void* CollectAndReportXconf(void* data)
Vector_RemoveItem(profile->cachedReportList, (void*) thirdCachedReport, NULL);
free(thirdCachedReport);
}
// Before caching the report, add "REPORT_TYPE": "CACHED"
// tagReportAsCached(&jsonReport);
Vector_PushBack(profile->cachedReportList, strdup(jsonReport));
profile->reportInProgress = false;
/* CID 187010: Dereference before null check */
Expand Down Expand Up @@ -419,6 +421,8 @@ static void* CollectAndReportXconf(void* data)
Vector_RemoveItem(profile->cachedReportList, (void*) thirdCachedReport, NULL);
free(thirdCachedReport);
}
// Before caching the report, add "REPORT_TYPE": "CACHED"
tagReportAsCached(&jsonReport);
Vector_PushBack(profile->cachedReportList, strdup(jsonReport));

T2Info("Report Cached, No. of reportes cached = %lu\n", (unsigned long)Vector_Size(profile->cachedReportList));
Expand Down
58 changes: 58 additions & 0 deletions source/reportgen/reportgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -876,3 +876,61 @@ char *prepareHttpUrl(T2HTTP *http)

return httpUrl;
}

void tagReportAsCached(char **jsonReport)
{
if (!jsonReport)
{
T2Error("jsonReport is NULL\n");
return;
}

cJSON *jsonReportObj = cJSON_Parse(*jsonReport);
if (!jsonReportObj)
{
T2Error("Failed to parse JSON report\n");
return;
}

cJSON *reportTypeEntry = cJSON_CreateObject();
if (!reportTypeEntry)
{
T2Error("Failed to create REPORT_TYPE object\n");
destroyJSONReport(jsonReportObj);
return;
}
cJSON_AddStringToObject(reportTypeEntry, "REPORT_TYPE", "CACHED");
cJSON *searchResult = cJSON_GetObjectItemCaseSensitive(jsonReportObj, "searchResult");
if (searchResult && cJSON_IsArray(searchResult))
{
T2Info("Inserting REPORT_TYPE: CACHED at index 1 of searchResult array\n");
cJSON_InsertItemInArray(searchResult, 1, reportTypeEntry);
}
else
{
cJSON *reportArray = cJSON_GetObjectItemCaseSensitive(jsonReportObj, "Report");
if (reportArray && cJSON_IsArray(reportArray))
{
T2Info("Inserting REPORT_TYPE: CACHED at beginning of Report array\n");
cJSON_InsertItemInArray(reportArray, 0, reportTypeEntry);
}
else
{
T2Error("Neither 'searchResult' nor 'Report' arrays found in the JSON\n");
destroyJSONReport(reportTypeEntry);
destroyJSONReport(jsonReportObj);
return;
}
}

char *updatedJsonReport = cJSON_PrintUnformatted(jsonReportObj);
if (updatedJsonReport)
{
free(*jsonReport); // Freeing the old report only after the new one is generated
*jsonReport = updatedJsonReport;
}

destroyJSONReport(jsonReportObj);
}


2 changes: 2 additions & 0 deletions source/reportgen/reportgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@ T2ERROR prepareJSONReport(cJSON* jsonObj, char** reportBuff);

char *prepareHttpUrl(T2HTTP *http);

void tagReportAsCached(char **jsonReport);

#endif /* _REPORTGEN_H_ */