Skip to content

Commit

Permalink
Merge pull request xmidt-org#68 from vasuki01/poke_US
Browse files Browse the repository at this point in the history
Added to support new response code 202 in webpa
  • Loading branch information
sadhyama authored and rsuru718 committed Oct 7, 2024
2 parents e93bd45 + 7ee9f36 commit ce1763b
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
41 changes: 41 additions & 0 deletions src/wdmp-c.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,44 @@
/* External Functions */
/*----------------------------------------------------------------------------*/

void write_to_file(char *payload);
/*----------------------------------------------------------------------------*/
/* External Functions */
/*----------------------------------------------------------------------------*/
void write_to_file(char *payload)
{
FILE *fp = NULL;
fp = fopen("/tmp/webpa_request.txt", "a");
if(fp == NULL)
{
WdmpError("Error: Cannot open /tmp/webpa_request.txt\n");
return;
}
size_t payload_len = strlen(payload);
char *payload_cpy = (char*)malloc(sizeof(payload_len+2));
if(payload_cpy == NULL)
{
WdmpError("Error: Memory Allocation Failed\n");
fclose(fp);
return;
}
strcpy(payload_cpy, payload);
payload_cpy[payload_len] = '\n';
payload_cpy[payload_len+1] = '\0';
fprintf(fp, "%s", payload_cpy);
if(payload_cpy != NULL)
{
free(payload_cpy);
}
if(fp != NULL)
{
fclose(fp);
}
return;
}



void wdmp_parse_generic_request(char * payload, PAYLOAD_TYPE payload_type, req_struct **reqObj)
{
cJSON *request = NULL;
Expand All @@ -58,6 +96,9 @@ void wdmp_parse_generic_request(char * payload, PAYLOAD_TYPE payload_type, req_s
return;
}

WdmpPrint("Obtained Raw Payload is %s\n", payload);
write_to_file(payload);

request = cJSON_Parse(payload);
if (request != NULL)
{
Expand Down
6 changes: 5 additions & 1 deletion src/wdmp_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ void wdmp_form_get_response(res_struct *resObj, cJSON *response)

WdmpPrint("resObj->retStatus : %d\n",resObj->retStatus[0]);
getStatusCode(&statusCode, paramCount, resObj->retStatus);

result = (char *) malloc(sizeof(char) * MAX_RESULT_LEN);

if(resObj->u.paramRes->params)
Expand Down Expand Up @@ -840,6 +839,11 @@ void wdmp_form_table_response(res_struct *resObj, cJSON *response)
*statusCode = WDMP_STATUS_ATOMIC_GET_SET_FAILED;
break;
}
else if (ret[i] == WDMP_ERR_SESSION_IN_PROGRESS)
{
*statusCode = WDMP_STATUS_PREVIOUS_REQUEST_INPROGRESS;
break;
}
else
{
*statusCode = WDMP_STATUS_GENERAL_FALURE;
Expand Down
3 changes: 2 additions & 1 deletion src/wdmp_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ typedef enum
{
WDMP_STATUS_SUCCESS = 200,
WDMP_ADDROW_STATUS_SUCCESS = 201,
WDMP_STATUS_PREVIOUS_REQUEST_INPROGRESS = 202,
WDMP_STATUS_GENERAL_FALURE = 520,
WDMP_STATUS_CID_TEST_FAILED = 550,
WDMP_STATUS_CMC_TEST_FAILED = 551,
Expand All @@ -51,7 +52,7 @@ typedef enum
#if ! defined(DEVICE_EXTENDER)
#define WdmpError(...) cimplog_error(LOGGING_MODULE, __VA_ARGS__)
#define WdmpInfo(...) cimplog_info(LOGGING_MODULE, __VA_ARGS__)
#define WdmpPrint(...) cimplog_debug(LOGGING_MODULE, __VA_ARGS__)
#define WdmpPrint(...) cimplog_info(LOGGING_MODULE, __VA_ARGS__)
#else
#define WdmpError(...) printf(__VA_ARGS__)
#define WdmpInfo(...) printf(__VA_ARGS__)
Expand Down
27 changes: 27 additions & 0 deletions tests/simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,32 @@ void test_get_status_code()
}
}

void test_get_status_code_inprogress()
{
WDMP_RESPONSE_STATUS_CODE statusCode;
WDMP_STATUS * ret = NULL;
int paramCount = 3;

WdmpInfo("\n***************************************************** \n\n");

ret = (WDMP_STATUS *) malloc(sizeof(WDMP_STATUS)*paramCount);

ret[0] = WDMP_SUCCESS;
ret[1] = WDMP_SUCCESS;
ret[2] = WDMP_ERR_SESSION_IN_PROGRESS;

getStatusCode(&statusCode, paramCount, ret);

CU_ASSERT_EQUAL( WDMP_STATUS_PREVIOUS_REQUEST_INPROGRESS, statusCode );

WdmpInfo("statusCode : %d\n",statusCode);

if(ret)
{
free(ret);
}
}

void test_map_wdmp_status()
{
WDMP_STATUS status;
Expand Down Expand Up @@ -2554,6 +2580,7 @@ void add_response_form_suites ( CU_pSuite *suite )
CU_add_test( *suite, "Delete row Response Form", delete_row_res_form );
CU_add_test( *suite, "Table response Form", table_res_form );
CU_add_test( *suite, "Get status code", test_get_status_code );
CU_add_test( *suite, "Get status code session inprogress", test_get_status_code_inprogress );
CU_add_test( *suite, "Map wdmp status", test_map_wdmp_status );
CU_add_test( *suite, "Negative Get Response Form", neg_get_res_form );
CU_add_test( *suite, "Get Wildcard empty Response Form", get_wildcard_empty_value_res_form);
Expand Down

0 comments on commit ce1763b

Please sign in to comment.