Feature/getprof rrd#450
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for selecting Remote Debugger “profile data” category via a new TR-181 parameter, and updates the existing getProfileData implementation to return filtered JSON based on that selection.
Changes:
- Introduces
setProfileDataTR-181 parameter forDevice.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger. - Adds a setter to store the requested category and updates
getProfileDatato return filtered results accordingly. - Updates the generic data model XML to expose the new parameter.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
src/hostif/profiles/DeviceInfo/Device_DeviceInfo.h |
Adds new Remote Debugger parameter defines and static state for category selection. |
src/hostif/profiles/DeviceInfo/Device_DeviceInfo.cpp |
Implements setProfileData handling and refactors getProfileData JSON filtering. |
src/hostif/parodusClient/waldb/data-model/data-model-generic.xml |
Exposes setProfileData as a readWrite string parameter in the data model. |
src/hostif/handlers/src/hostIf_DeviceClient_ReqHandler.cpp |
Adds request routing for the new parameter (currently in the GET path). |
| else if (strcasecmp(stMsgData->paramName,"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.setProfileData") == 0) | ||
| { | ||
| ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggersetProfileData(stMsgData); | ||
| } |
There was a problem hiding this comment.
handleGetMsg is dispatching the readWrite parameter ...RDKRemoteDebugger.setProfileData by calling the setter. A GET for this parameter would unexpectedly mutate internal state (e.g., setting the category to an empty string) and bypass the normal SET path. This branch should be removed from handleGetMsg and handled via handleSetMsg (it already routes RFC params through set_xRDKCentralComRFC).
| else if (strcasecmp(stMsgData->paramName,"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.setProfileData") == 0) | |
| { | |
| ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggersetProfileData(stMsgData); | |
| } |
| // Check if setProfileData was called to determine response format | ||
| if (strcasecmp(m_rdkRemoteDebuggerProfileCategory.c_str(), "all") == 0) { | ||
| // Return filtered profile data for all categories - exclude Commands and Timeout fields | ||
| response = cJSON_CreateObject(); | ||
| if (!response) { | ||
| free(fileBuf); | ||
| cJSON_Delete(root); | ||
| return retStatus; | ||
| } | ||
| cJSON *arr = cJSON_CreateArray(); | ||
| if (!arr) | ||
| { | ||
|
|
||
| cJSON *category = NULL; | ||
| cJSON_ArrayForEach(category, root) { | ||
| if (cJSON_IsObject(category)) { | ||
| cJSON *issueTypesArray = cJSON_CreateArray(); | ||
| if (!issueTypesArray) { | ||
| free(fileBuf); | ||
| cJSON_Delete(root); | ||
| cJSON_Delete(response); | ||
| return retStatus; | ||
| } | ||
|
|
||
| cJSON *issueType = NULL; | ||
| cJSON_ArrayForEach(issueType, category) { | ||
| // Only add the issue type name, ignore Commands/Timeout/DebugCommands/DebugTimeout | ||
| if (cJSON_IsObject(issueType) && issueType->string) { | ||
| cJSON_AddItemToArray(issueTypesArray, cJSON_CreateString(issueType->string)); | ||
| } | ||
| } | ||
|
|
||
| if (cJSON_GetArraySize(issueTypesArray) > 0) { | ||
| cJSON_AddItemToObject(response, category->string, issueTypesArray); | ||
| } else { |
There was a problem hiding this comment.
When building the JSON response, cJSON_AddItemToObject(response, category->string, ...) assumes category->string is non-null. If /etc/rrd/remote_debugger.json ever contains an array (or any non-object root/child), category->string can be null and this will crash. Please validate root is an object and guard category->string before using it as an object key.
| return retStatus; | ||
| } | ||
|
|
||
| bytesRead = fread(fileBuf, 1U, (size_t)fileSz, fp); |
There was a problem hiding this comment.
fread's return value isn’t validated against the expected file size and ferror(fp) isn’t checked. A short read can lead to parsing truncated JSON and returning misleading data. Consider treating bytesRead != (size_t)fileSz as an error (or loop until EOF) and handle ferror explicitly.
| bytesRead = fread(fileBuf, 1U, (size_t)fileSz, fp); | |
| bytesRead = fread(fileBuf, 1U, (size_t)fileSz, fp); | |
| if (bytesRead != (size_t)fileSz) { | |
| if (ferror(fp)) { | |
| RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] fread failed for %s\n", __FUNCTION__, filename); | |
| } else { | |
| RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] Short read for %s: expected %ld bytes, got %zu bytes\n", | |
| __FUNCTION__, filename, fileSz, bytesRead); | |
| } | |
| fclose(fp); | |
| fp = nullptr; | |
| free(fileBuf); | |
| fileBuf = nullptr; | |
| return retStatus; | |
| } |
| char *outStr = nullptr; | ||
| size_t outLen = 0; | ||
|
|
||
| RDK_LOG(RDK_LOG_TRACE1, LOG_TR69HOSTIF, "[%s] Entering …\n", __FUNCTION__); |
There was a problem hiding this comment.
The log message contains a Unicode ellipsis character (…). Some embedded toolchains/log pipelines assume ASCII and can fail or garble logs; prefer plain ... in source strings for portability.
| RDK_LOG(RDK_LOG_TRACE1, LOG_TR69HOSTIF, "[%s] Entering …\n", __FUNCTION__); | |
| RDK_LOG(RDK_LOG_TRACE1, LOG_TR69HOSTIF, "[%s] Entering ...\n", __FUNCTION__); |
|
|
||
| RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s] Returning profile data: %s\n", __FUNCTION__, outStr); | ||
| retStatus = OK; |
There was a problem hiding this comment.
Logging the full generated JSON (outStr) at INFO level can be noisy and potentially large, impacting storage/performance on embedded targets. Consider logging only the selected category and output length (or downgrade to DEBUG).
|
|
||
| #ifdef USE_REMOTE_DEBUGGER | ||
| static string m_rdkRemoteDebuggerProfileCategory; | ||
| static string m_rdkRemoteDebuggerProfileData; |
There was a problem hiding this comment.
m_rdkRemoteDebuggerProfileData is declared/defined but not referenced anywhere in the codebase. Keeping unused static state increases confusion and maintenance cost; consider removing it or wiring it into the implementation.
| static string m_rdkRemoteDebuggerProfileData; |
No description provided.