diff --git a/CHANGELOG.md b/CHANGELOG.md index 3830826..6f2ff9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - fix memory leaks - Fixed memory leak in upstream event message flow - Fixed crash in CRUD request processing +- Fixed issue on RETRIEVE respone processing ## [1.0.1] - 2018-07-18 ### Added diff --git a/src/upstream.c b/src/upstream.c index 919b5a0..35ccd37 100644 --- a/src/upstream.c +++ b/src/upstream.c @@ -211,7 +211,6 @@ void *processUpstreamMessage() int matchFlag = 0; int status = -1; char *serviceName = NULL; - char *macId = NULL; char *destService, *destApplication =NULL; char *sourceService, *sourceApplication =NULL; int sendStatus =-1; @@ -363,7 +362,6 @@ void *processUpstreamMessage() ParodusInfo(" Received upstream data with MsgType: %d dest: '%s' transaction_uuid: %s status: %d\n",msgType, msg->u.crud.dest, msg->u.crud.transaction_uuid, msg->u.crud.status ); if(WRP_MSG_TYPE__RETREIVE == msgType && msg->u.crud.dest !=NULL && msg->u.crud.source != NULL) { - macId = wrp_get_msg_element(WRP_ID_ELEMENT__ID, msg, DEST); destService = wrp_get_msg_element(WRP_ID_ELEMENT__SERVICE, msg, DEST); destApplication = wrp_get_msg_element(WRP_ID_ELEMENT__APPLICATION, msg, DEST); sourceService = wrp_get_msg_element(WRP_ID_ELEMENT__SERVICE, msg, SOURCE); @@ -372,55 +370,48 @@ void *processUpstreamMessage() Expecting dest format as mac:xxxxxxxxxxxx/parodus/cloud-status Parse dest field and check destService is "parodus" and destApplication is "cloud-status" */ - if(macId != NULL) - { - if(destService != NULL && destApplication != NULL && strcmp(destService,"parodus")== 0 && strcmp(destApplication,"cloud-status")== 0) + if(destService != NULL && destApplication != NULL && strcmp(destService,"parodus")== 0 && strcmp(destApplication,"cloud-status")== 0) + { + retrieve_msg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) ); + memset(retrieve_msg, 0, sizeof(wrp_msg_t)); + retrieve_msg->msg_type = msg->msg_type; + retrieve_msg->u.crud.transaction_uuid = strdup(msg->u.crud.transaction_uuid); + retrieve_msg->u.crud.source = strdup(msg->u.crud.source); + retrieve_msg->u.crud.dest = strdup(msg->u.crud.dest); + addCRUDmsgToQueue(retrieve_msg); + } + else if(sourceService != NULL && sourceApplication != NULL && strcmp(sourceService,"parodus")== 0 && strcmp(sourceApplication,"cloud-status")== 0 && strncmp(msg->u.crud.dest,"mac:", 4)==0) + { + /* Handle cloud-status retrieve response here to send it to registered client + Expecting src format as mac:xxxxxxxxxxxx/parodus/cloud-status and dest as mac: + Parse src field and check sourceService is "parodus" and sourceApplication is "cloud-status" + */ + serviceName = wrp_get_msg_element(WRP_ID_ELEMENT__SERVICE, msg, DEST); + if ( serviceName != NULL) { - retrieve_msg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) ); - memset(retrieve_msg, 0, sizeof(wrp_msg_t)); - retrieve_msg->msg_type = msg->msg_type; - retrieve_msg->u.crud.transaction_uuid = strdup(msg->u.crud.transaction_uuid); - retrieve_msg->u.crud.source = strdup(msg->u.crud.source); - retrieve_msg->u.crud.dest = strdup(msg->u.crud.dest); - addCRUDmsgToQueue(retrieve_msg); - } - else if(sourceService != NULL && sourceApplication != NULL && strcmp(sourceService,"parodus")== 0 && strcmp(sourceApplication,"cloud-status")== 0 && strncmp(msg->u.crud.dest,"mac:", 4)==0) - { - /* Handle cloud-status retrieve response here to send it to registered client - Expecting src format as mac:xxxxxxxxxxxx/parodus/cloud-status and dest as mac: - Parse src field and check sourceService is "parodus" and sourceApplication is "cloud-status" - */ - serviceName = wrp_get_msg_element(WRP_ID_ELEMENT__SERVICE, msg, DEST); - if ( serviceName != NULL) + //Send Client cloud-status response back to registered client + ParodusInfo("Sending cloud-status response to %s client\n",serviceName); + sendStatus=sendMsgtoRegisteredClients(serviceName,(const char **)&message->msg,message->len); + if(sendStatus ==1) { - //Send Client cloud-status response back to registered client - ParodusInfo("Sending cloud-status response to %s client\n",serviceName); - sendStatus=sendMsgtoRegisteredClients(serviceName,(const char **)&message->msg,message->len); - if(sendStatus ==1) - { - ParodusInfo("Send upstreamMsg successfully to registered client %s\n", serviceName); - } - else - { - ParodusError("Failed to send upstreamMsg to registered client %s\n", serviceName); - } - free(serviceName); - serviceName = NULL; + ParodusInfo("Send upstreamMsg successfully to registered client %s\n", serviceName); } else { - ParodusError("serviceName is NULL,not sending cloud-status response to client\n"); + ParodusError("Failed to send upstreamMsg to registered client %s\n", serviceName); } + free(serviceName); + serviceName = NULL; } else { - ParodusInfo("sendUpstreamMsgToServer \n"); - sendUpstreamMsgToServer(&message->msg, message->len); + ParodusError("serviceName is NULL,not sending cloud-status response to client\n"); } } else { - ParodusError("MAC is null, not handling retrieve wrp message \n"); + ParodusInfo("sendUpstreamMsgToServer \n"); + sendUpstreamMsgToServer(&message->msg, message->len); } if(sourceService !=NULL) { diff --git a/tests/test_upstream.c b/tests/test_upstream.c index d7fee18..cf6c2ce 100644 --- a/tests/test_upstream.c +++ b/tests/test_upstream.c @@ -776,82 +776,6 @@ void test_processUpstreamMsg_sendToClient() free(UpStreamMsgQ); UpStreamMsgQ = NULL; } -void test_processUpstreamMessageNullCheck() -{ - numLoops = 1; - metaPackSize = 20; - UpStreamMsgQ = (UpStreamMsg *) malloc(sizeof(UpStreamMsg)); - UpStreamMsgQ->msg = strdup("First Message"); - UpStreamMsgQ->len = 13; - UpStreamMsgQ->next= NULL; - temp = (wrp_msg_t *) malloc(sizeof(wrp_msg_t)); - memset(temp,0,sizeof(wrp_msg_t)); - temp->msg_type = WRP_MSG_TYPE__RETREIVE; - temp->u.crud.dest = strdup("mac:14cfe2142xxx/parodus/cloud-status"); - temp->u.crud.source = strdup("mac:14cfe2142xxx/config"); - temp->u.crud.transaction_uuid = strdup("123"); - will_return(wrp_to_struct, 12); - expect_function_call(wrp_to_struct); - expect_function_call(addCRUDmsgToQueue); - will_return(nn_freemsg, 0); - expect_function_call(nn_freemsg); - expect_function_call(wrp_free_struct); - processUpstreamMessage(); - free(temp); - free(UpStreamMsgQ); - UpStreamMsgQ = NULL; -} -void err_processUpstreamMessageNullCheck() -{ - numLoops = 1; - metaPackSize = 20; - UpStreamMsgQ = (UpStreamMsg *) malloc(sizeof(UpStreamMsg)); - UpStreamMsgQ->msg = strdup("First Message"); - UpStreamMsgQ->len = 13; - UpStreamMsgQ->next= NULL; - temp = (wrp_msg_t *) malloc(sizeof(wrp_msg_t)); - memset(temp,0,sizeof(wrp_msg_t)); - temp->msg_type = WRP_MSG_TYPE__RETREIVE; - temp->u.crud.dest = strdup("mac:/parodus/cloud-status"); - temp->u.crud.source = strdup("mac:14cfe2142xxx/config"); - temp->u.crud.transaction_uuid = strdup("123"); - will_return(wrp_to_struct, 12); - expect_function_call(wrp_to_struct); - will_return(nn_freemsg, 0); - expect_function_call(nn_freemsg); - expect_function_call(wrp_free_struct); - - processUpstreamMessage(); - free(temp); - free(UpStreamMsgQ); - UpStreamMsgQ = NULL; -} -void err_processUpstreamMessageWithoutMac() -{ - numLoops = 1; - metaPackSize = 20; - UpStreamMsgQ = (UpStreamMsg *) malloc(sizeof(UpStreamMsg)); - UpStreamMsgQ->msg = strdup("First Message"); - UpStreamMsgQ->len = 13; - UpStreamMsgQ->next= NULL; - temp = (wrp_msg_t *) malloc(sizeof(wrp_msg_t)); - memset(temp,0,sizeof(wrp_msg_t)); - temp->msg_type = WRP_MSG_TYPE__RETREIVE; - temp->u.crud.dest = strdup("/parodus/cloud-status"); - temp->u.crud.source = strdup("mac:14cfe2142xxx/config"); - temp->u.crud.transaction_uuid = strdup("123"); - will_return(wrp_to_struct, 12); - expect_function_call(wrp_to_struct); - will_return(nn_freemsg, 0); - expect_function_call(nn_freemsg); - expect_function_call(wrp_free_struct); - - processUpstreamMessage(); - free(temp); - free(UpStreamMsgQ); - UpStreamMsgQ = NULL; -} - /*----------------------------------------------------------------------------*/ /* External Functions */ /*----------------------------------------------------------------------------*/ @@ -884,9 +808,6 @@ int main(void) cmocka_unit_test(test_processUpstreamMsgCrud_nnfree), cmocka_unit_test(test_processUpstreamMsg_cloud_status), cmocka_unit_test(test_processUpstreamMsg_sendToClient), - cmocka_unit_test(test_processUpstreamMessageNullCheck), - cmocka_unit_test(err_processUpstreamMessageNullCheck), - cmocka_unit_test(err_processUpstreamMessageWithoutMac), }; return cmocka_run_group_tests(tests, NULL, NULL);