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;
//ReleaseStringUTFChars for strUri
(*env)->ReleaseStringUTFChars(env, uri, strUri);
+ free(headerOpt);
+
// destroy remote endpoint
CADestroyEndpoint(endpoint);
}
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;
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;
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");
}
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;
g_last_request_token = token;
}
+ if (headerOpt)
+ {
+ free(headerOpt);
+ }
+
// destroy remote endpoint
CADestroyEndpoint(endpoint);
free(group);
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)
OICFree(cadata->errorInfo);
}
- OICFree(cadata->options);
OICFree(cadata);
OIC_LOG(DEBUG, TAG, "OUT");
}
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));
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));
return;
}
-