diff --git a/src/wdmp-c.c b/src/wdmp-c.c index e369968..953e773 100644 --- a/src/wdmp-c.c +++ b/src/wdmp-c.c @@ -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; @@ -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) { diff --git a/src/wdmp_internal.c b/src/wdmp_internal.c index d7cde82..b172803 100644 --- a/src/wdmp_internal.c +++ b/src/wdmp_internal.c @@ -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) @@ -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; diff --git a/src/wdmp_internal.h b/src/wdmp_internal.h index 36e6c60..9462a34 100644 --- a/src/wdmp_internal.h +++ b/src/wdmp_internal.h @@ -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, @@ -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__) diff --git a/tests/simple.c b/tests/simple.c index f5e3af4..5b0cf35 100644 --- a/tests/simple.c +++ b/tests/simple.c @@ -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; @@ -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);