From 1b731756bc076d4e177a543a5feaf7cca42b9171 Mon Sep 17 00:00:00 2001 From: "jihwan.seo" Date: Thu, 25 Jun 2015 14:13:26 +0900 Subject: [PATCH] [IOT-583] fixed Option Parameter is not support HeaderOption in RequestInfo and responseInfo parameter was not supporting since there are no logic related to it after IPv6 merged. trus. i'll be support through SendRequest and SendResponse Change-Id: Ic200ebe29e130baac95991570183beb8f9fb7148 Signed-off-by: jihwan.seo Reviewed-on: https://gerrit.iotivity.org/gerrit/1422 Tested-by: jenkins-iotivity Reviewed-by: Erich Keane --- .../android/sample_service/jni/ResourceModel.c | 24 +++++++ .../csdk/connectivity/samples/linux/sample_main.c | 73 +++++++++++++++++++++- resource/csdk/connectivity/src/camessagehandler.c | 32 +++++++++- 3 files changed, 126 insertions(+), 3 deletions(-) diff --git a/resource/csdk/connectivity/samples/android/sample_service/jni/ResourceModel.c b/resource/csdk/connectivity/samples/android/sample_service/jni/ResourceModel.c index fb464aa..fa88631 100644 --- a/resource/csdk/connectivity/samples/android/sample_service/jni/ResourceModel.c +++ b/resource/csdk/connectivity/samples/android/sample_service/jni/ResourceModel.c @@ -425,6 +425,28 @@ Java_org_iotivity_ca_service_RMInterface_RMSendReqestToAll(JNIEnv *env, jobject LOGI("resourceUri - %s", strUri); requestData.resourceUri = (CAURI_t)strUri; + uint8_t optionNum = 2; + CAHeaderOption_t *headerOpt = (CAHeaderOption_t*) calloc(1, + sizeof(CAHeaderOption_t) * optionNum); + if (NULL == headerOpt) + { + LOGE("Memory allocation failed"); + return; + } + + char* FirstOptionData = "Hello"; + headerOpt[0].optionID = 3000; + memcpy(headerOpt[0].optionData, FirstOptionData, strlen(FirstOptionData)); + headerOpt[0].optionLength = (uint16_t) strlen(FirstOptionData); + + char* SecondOptionData2 = "World"; + headerOpt[1].optionID = 3001; + memcpy(headerOpt[1].optionData, SecondOptionData2, strlen(SecondOptionData2)); + headerOpt[1].optionLength = (uint16_t) strlen(SecondOptionData2); + + requestData.numOptions = optionNum; + requestData.options = headerOpt; + CARequestInfo_t requestInfo = { 0 }; requestInfo.method = CA_GET; requestInfo.isMulticast = true; @@ -448,6 +470,8 @@ Java_org_iotivity_ca_service_RMInterface_RMSendReqestToAll(JNIEnv *env, jobject //ReleaseStringUTFChars for strUri (*env)->ReleaseStringUTFChars(env, uri, strUri); + free(headerOpt); + // destroy remote endpoint CADestroyEndpoint(endpoint); } diff --git a/resource/csdk/connectivity/samples/linux/sample_main.c b/resource/csdk/connectivity/samples/linux/sample_main.c index f3ef50e..a070e04 100644 --- a/resource/csdk/connectivity/samples/linux/sample_main.c +++ b/resource/csdk/connectivity/samples/linux/sample_main.c @@ -88,6 +88,7 @@ void get_resource_uri(char *URI, char *resourceURI, int length); int get_secure_information(CAPayload_t payLoad); int get_address_set(const char *pAddress, addressSet_t* outAddress); void parsing_coap_uri(const char* uri, addressSet_t* address); +CAHeaderOption_t* get_option_data(CAInfo_t* requestData); static CAToken_t g_last_request_token = NULL; @@ -488,6 +489,7 @@ void send_request() snprintf(requestData.payload, length, NORMAL_INFO_DATA, resourceURI); } requestData.type = msgType; + CAHeaderOption_t* headerOpt = get_option_data(&requestData); CARequestInfo_t requestInfo = { 0 }; requestInfo.method = CA_GET; @@ -501,13 +503,17 @@ void send_request() printf("Could not send request : %d\n", res); } + if (headerOpt) + { + free(headerOpt); + } + //destroy token CADestroyToken(token); // destroy remote endpoint CADestroyEndpoint(endpoint); free(requestData.payload); - printf("=============================================\n"); } @@ -628,6 +634,8 @@ void send_request_all() requestData.type = CA_MSG_NONCONFIRM; requestData.resourceUri = (CAURI_t)resourceURI; + CAHeaderOption_t* headerOpt = get_option_data(&requestData); + CARequestInfo_t requestInfo = { 0 }; requestInfo.method = CA_GET; requestInfo.info = requestData; @@ -646,6 +654,11 @@ void send_request_all() g_last_request_token = token; } + if (headerOpt) + { + free(headerOpt); + } + // destroy remote endpoint CADestroyEndpoint(endpoint); free(group); @@ -1323,6 +1336,64 @@ CAResult_t get_input_data(char *buf, int32_t length) return CA_STATUS_OK; } +CAHeaderOption_t* get_option_data(CAInfo_t* requestData) +{ + char optionNumBuf[MAX_BUF_LEN] = { 0 }; + char optionData[MAX_OPT_LEN] = { 0 } ; + + printf("Option Num : "); + if (CA_STATUS_OK != get_input_data(optionNumBuf, MAX_BUF_LEN)) + { + return NULL; + } + int optionNum = atoi(optionNumBuf); + + CAHeaderOption_t * headerOpt = NULL; + if (0 >= optionNum) + { + printf("there is no headerOption!\n"); + return NULL; + } + else + { + headerOpt = (CAHeaderOption_t *)calloc(1, optionNum * sizeof(CAHeaderOption_t)); + if (NULL == headerOpt) + { + printf("Memory allocation failed!\n"); + return NULL; + } + + int i; + for (i = 0; i < optionNum; i++) + { + char getOptionID[MAX_BUF_LEN] = { 0 } ; + + printf("[%d] Option ID : ", i + 1); + if (CA_STATUS_OK != get_input_data(getOptionID, MAX_BUF_LEN)) + { + free(headerOpt); + return NULL; + } + int optionID = atoi(getOptionID); + headerOpt[i].optionID = optionID; + + printf("[%d] Option Data : ", i + 1); + if (CA_STATUS_OK != get_input_data(optionData, MAX_OPT_LEN)) + { + free(headerOpt); + return NULL; + } + + memcpy(headerOpt[i].optionData, optionData, strlen(optionData)); + + headerOpt[i].optionLength = (uint16_t) strlen(optionData); + } + requestData->numOptions = optionNum; + requestData->options = headerOpt; + } + return headerOpt; +} + void parsing_coap_uri(const char* uri, addressSet_t* address) { if (NULL == uri) diff --git a/resource/csdk/connectivity/src/camessagehandler.c b/resource/csdk/connectivity/src/camessagehandler.c index f221843..200a9f4 100644 --- a/resource/csdk/connectivity/src/camessagehandler.c +++ b/resource/csdk/connectivity/src/camessagehandler.c @@ -187,7 +187,6 @@ static void CADataDestroyer(void *data, uint32_t size) OICFree(cadata->errorInfo); } - OICFree(cadata->options); OICFree(cadata); OIC_LOG(DEBUG, TAG, "OUT"); } @@ -574,6 +573,21 @@ CAResult_t CADetachRequestMessage(const CAEndpoint_t *object, const CARequestInf data->remoteEndpoint = remoteEndpoint; data->requestInfo = requestInfo; data->responseInfo = NULL; + data->options = NULL; + data->numOptions = 0; + if (NULL != requestInfo->info.options && 0 < requestInfo->info.numOptions) + { + uint8_t numOptions = requestInfo->info.numOptions; + // copy data + CAHeaderOption_t *headerOption = (CAHeaderOption_t *) OICMalloc(sizeof(CAHeaderOption_t) + * numOptions); + CA_MEMORY_ALLOC_CHECK(headerOption); + + memcpy(headerOption, requestInfo->info.options, sizeof(CAHeaderOption_t) * numOptions); + + data->options = headerOption; + data->numOptions = numOptions; + } // add thread CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t)); @@ -622,6 +636,21 @@ CAResult_t CADetachResponseMessage(const CAEndpoint_t *object, data->remoteEndpoint = remoteEndpoint; data->requestInfo = NULL; data->responseInfo = responseInfo; + data->options = NULL; + data->numOptions = 0; + if (NULL != responseInfo->info.options && 0 < responseInfo->info.numOptions) + { + uint8_t numOptions = responseInfo->info.numOptions; + // copy data + CAHeaderOption_t *headerOption = (CAHeaderOption_t *) OICMalloc(sizeof(CAHeaderOption_t) + * numOptions); + CA_MEMORY_ALLOC_CHECK(headerOption); + + memcpy(headerOption, responseInfo->info.options, sizeof(CAHeaderOption_t) * numOptions); + + data->options = headerOption; + data->numOptions = numOptions; + } // add thread CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t)); @@ -887,4 +916,3 @@ void CAErrorHandler(const CAEndpoint_t *endpoint, return; } - -- 2.7.4