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
83 changes: 0 additions & 83 deletions src/crud_tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,6 @@ int processCrudRequest( wrp_msg_t *reqMsg, wrp_msg_t **responseMsg)
case WRP_MSG_TYPE__UPDATE:
ParodusInfo( "UPDATE request\n" );

if (strstr(reqMsg->u.crud.dest, "/parodus/method"))
{
ParodusInfo("Processing method invocation request\n");
ret = processMethodRequest(reqMsg, &resp_msg);
*responseMsg = resp_msg;
if (ret != 0)
{
ParodusError("Failed to Invoke method\n");
return -1;
}
break;
}

ret = updateObject( reqMsg, &resp_msg );
if(ret ==0)
{
Expand Down Expand Up @@ -119,73 +106,3 @@ int processCrudRequest( wrp_msg_t *reqMsg, wrp_msg_t **responseMsg)

return 0;
}


int processMethodRequest(wrp_msg_t *reqMsg, wrp_msg_t **response)
{
int ret = -1;
char *methodResponse = NULL;

ParodusInfo("Processing method request\n");

if (!reqMsg || !reqMsg->u.crud.payload)
{
ParodusError("Invalid method request - missing payload\n");
if (response && *response)
(*response)->u.crud.status = 400;
return -1;
}

// Parse JSON payload from reqMsg
cJSON *jsonPayload = cJSON_Parse(reqMsg->u.crud.payload);
if (!jsonPayload)
{
ParodusError("Failed to parse method payload\n");
if (response && *response)
(*response)->u.crud.status = 400;
return -1;
}

// Extract the Method name field
cJSON *methodObj = cJSON_GetObjectItem(jsonPayload, "method");
if (!cJSON_IsString(methodObj) || methodObj->valuestring == NULL)
{
ParodusError("Missing or invalid 'Method' field in payload\n");
cJSON_Delete(jsonPayload);
if (response && *response)
(*response)->u.crud.status = 400;
return -1;
}

const char *methodName = methodObj->valuestring;
if (!methodName || !strstr(methodName, "()"))
{
ParodusError("Invalid RBUS method name. Methods Must include (): %s\n", methodName ? methodName : "NULL");
return -1;
}
ParodusInfo("Received UPDATE method: '%s'\n", methodName);

#ifdef ENABLE_WEBCFGBIN
ret = rbus_methodHandler(methodName, jsonPayload, &methodResponse);
#endif
if (response && *response)
{
(*response)->u.crud.status = (ret == 0) ? 200 : 500;
if (methodResponse)
{
ParodusInfo("Response from method call:%s\n", methodResponse);
(*response)->u.crud.payload = strdup(methodResponse);
(*response)->u.crud.payload_size = strlen(methodResponse);
}
}

if (ret == 0)
ParodusInfo("rbus_methodHandler Success. ret: %d\n", ret);
else
ParodusError("rbus_methodHandler failed. ret: %d\n", ret);

if (methodResponse)
free(methodResponse);
cJSON_Delete(jsonPayload);
return ret;
}
4 changes: 0 additions & 4 deletions src/crud_tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

#include <wrp-c.h>
#include "ParodusInternal.h"
#ifdef ENABLE_WEBCFGBIN
#include "xmidtsend_rbus.h"
#endif

/**
* @brief processCrudRequest function to process CRUD operations.
Expand All @@ -32,4 +29,3 @@
* @return 0 in success case and -1 in error case
*/
int processCrudRequest(wrp_msg_t * reqMsg, wrp_msg_t **resMsg);
int processMethodRequest(wrp_msg_t *reqMsg, wrp_msg_t **response);
107 changes: 0 additions & 107 deletions src/xmidtsend_rbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1783,110 +1783,3 @@ void mapXmidtStatusToStatusMessage(int status, char **message)
ParodusInfo("Xmidt status message: %s\n", result);
*message = result;
}

int rbus_methodHandler(const char *methodName, cJSON *payloadJson, char **methodResponseOut)
{
rbusObject_t inParams = NULL, outParams = NULL;
rbusHandle_t rbus_handle = NULL;
rbusError_t rc;
*methodResponseOut = NULL;
int i = 0;


ParodusInfo("Invoking RBUS method: %s\n", methodName);

rbus_handle = get_parodus_rbus_Handle();
if (!rbus_handle)
{
ParodusError("rbus_methodHandler failed: rbus_handle is NULL\n");
return -1;
}

// Initialize inParams and fill with key-value pairs (excluding "Method")
rbusObject_Init(&inParams, "NULL");

cJSON *item = NULL;
cJSON_ArrayForEach(item, payloadJson)
{
if (!item->string) continue;

// Skip the "Method" key
if (strcmp(item->string, "method") == 0) continue;

if (cJSON_IsObject(item) && strcmp(item->string, "params") == 0)
{
cJSON *inner = NULL;
cJSON_ArrayForEach(inner, item)
{
if (!inner->string) continue;

if (cJSON_IsString(inner))
{
rbusValue_t val;
rbusValue_Init(&val);
rbusValue_SetString(val, inner->valuestring);
rbusObject_SetValue(inParams, inner->string, val);
rbusValue_Release(val);
}
else if (cJSON_IsNumber(inner))
{
rbusValue_t val;
rbusValue_Init(&val);
rbusValue_SetDouble(val, inner->valuedouble);
rbusObject_SetValue(inParams, inner->string, val);
rbusValue_Release(val);
}
else if (cJSON_IsBool(inner))
{
rbusValue_t val;
rbusValue_Init(&val);
rbusValue_SetBoolean(val, cJSON_IsTrue(inner));
rbusObject_SetValue(inParams, inner->string, val);
rbusValue_Release(val);
}
else
{
ParodusInfo("[DEBUG] Skipping unsupported nested type for key: %s\n", inner->string);
}
i++;
}
}
else
{
ParodusInfo("[DEBUG] Skipping unsupported type for key: %s\n", item->string);
}

}

// Call the RBUS method
rc = rbusMethod_Invoke(rbus_handle, methodName, inParams, &outParams);
rbusObject_Release(inParams);

if(rc != RBUS_ERROR_SUCCESS)
ParodusError("rbusMethod_Invoke failed for %s. ret: %d %s\n", methodName, rc, rbusError_ToString(rc));
else
ParodusInfo("rbusMethod_Invoke success. ret: %d %s\n", rc, rbusError_ToString(rc));

int status_code = -1;
const char *return_message = NULL;

rbusValue_t outVal = NULL;
if ((outVal = rbusObject_GetValue(outParams, "message")) != NULL)
return_message = rbusValue_GetString(outVal, NULL);

if ((outVal = rbusObject_GetValue(outParams, "statusCode")) != NULL)
status_code = rbusValue_GetInt32(outVal);

if (!return_message)
return_message = (rc == RBUS_ERROR_SUCCESS) ? "Success" : rbusError_ToString(rc);
if(status_code == -1)
status_code = (rc == RBUS_ERROR_SUCCESS) ? 0 : rc;

char *buf = NULL;
int n = asprintf(&buf, "{\"message\":\"%s\", \"statusCode\":%d}", return_message ? return_message : "NULL", status_code);
if (n > 0 && buf)
*methodResponseOut = buf;

rbusObject_Release(outParams);
return (rc == RBUS_ERROR_SUCCESS) ? 0 : -1;
}
3 changes: 0 additions & 3 deletions src/xmidtsend_rbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ typedef enum
DELETE
} MSG_STATUS;

#define MAX_BUF_SIZE 256

/*----------------------------------------------------------------------------*/
/* Function Prototypes */
/*----------------------------------------------------------------------------*/
Expand Down Expand Up @@ -121,7 +119,6 @@ void checkMaxQandOptimize(XmidtMsg *xmdMsg);
void checkMsgExpiry(XmidtMsg *xmdMsg);
void mapXmidtStatusToStatusMessage(int status, char **message);
int xmidtQOptmize();
int rbus_methodHandler(const char *methodName, cJSON *payloadJson, char **methodResponseOut);
#ifdef __cplusplus
}
#endif
Expand Down
42 changes: 2 additions & 40 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,51 +244,13 @@ target_link_libraries (test_crud_interface -lcmocka ${PARODUS_COMMON_LIBS} )
# test_crud_tasks
#-------------------------------------------------------------------------------
add_test(NAME test_crud_tasks COMMAND ${MEMORY_CHECK} ./test_crud_tasks)
set(XMIDT_SRC test_crud_tasks.c ../src/crud_tasks.c)
set(XMIDT_SRC ${XMIDT_SRC}
../src/close_retry.c
../src/time.c
../src/config.c
../src/nopoll_helpers.c
../src/nopoll_handlers.c
../src/connection.c
../src/heartBeat.c
../src/conn_interface.c
../src/upstream.c
../src/downstream.c
../src/string_helpers.c
../src/auth_token.c
../src/ParodusInternal.c
../src/networking.c
../src/mutex.c
../src/event_handler.c
../src/thread_tasks.c
../src/crud_interface.c
../src/service_alive.c
../src/client_list.c
../src/spin_thread.c
../src/partners_check.c
../src/token.c

)
add_executable(test_crud_tasks test_crud_tasks.c ../src/crud_tasks.c )
target_link_libraries (test_crud_tasks -lcmocka ${PARODUS_COMMON_LIBS} )

if (PARODUS_SECERT_ENABLE)
set(XMIDT_SRC ${XMIDT_SRC} ../src/rdkconfig_generic)
endif (PARODUS_SECERT_ENABLE)

if (ENABLE_WEBCFGBIN)
set(XMIDT_SRC ${XMIDT_SRC} ../src/upstream_rbus.c ../src/xmidtsend_rbus.c)
endif (ENABLE_WEBCFGBIN)

if (ENABLE_SESHAT)
set(XMIDT_SRC ${XMIDT_SRC} ../src/seshat_interface.c)
else()
set(XMIDT_SRC ${XMIDT_SRC} ../src/seshat_interface_stub.c)
endif (ENABLE_SESHAT)

add_executable(test_crud_tasks ${XMIDT_SRC})
target_link_libraries(test_crud_tasks -lcmocka -lcurl ${PARODUS_COMMON_LIBS} )

#-------------------------------------------------------------------------------
# test_crud_internal
#-------------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion tests/test_crud_tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
/* File Scoped Variables */
/*----------------------------------------------------------------------------*/
wrp_msg_t *response = NULL;
int numLoops;
/*----------------------------------------------------------------------------*/
/* Mocks */
/*----------------------------------------------------------------------------*/
Expand Down