g_free(device_info.deviceName);
-#if 0
- int ret = iotcon_initialize(data_dir);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_initialize: Failed %s", get_error_message(ret));
- return false;
- }
- LOG_DEBUG("iotcon_initialize : %s", get_error_message(ret));
-#endif
-
OicUuid_t uuid;
ret = GetDoxmDeviceID(&uuid);
/* Do Self-Ownership Transfer */
ret = OCSecure::configSelfOwnership();
-#if 0
- ret = OCConfigSelfOwnership();
-#endif
if (OC_STACK_OK != ret ) {
LOG_ERR( "OCConfigSelfOwnership() error = [%d][%s]", ret, get_error_message(ret));
}
memcpy(arg, out, len);
LOG_DEBUG("successfully decoded to base64. %s", arg);
-
- iotcon_query_remove(query, "data");
#else
if (!rep.getValue("data", data))
LOG_ERR("data not found");
}
return OC_EH_OK;
- //get resource element from comp resource list or, parsing resource uri
-
- //if request type is "get" and resource type is "group",
- //then OWNER send device information to CLIENT(Device info Exchange)
- //if request type is "put" and resource type is "operation",
- //then It is join request. CLIENT send device information to OWNER(Device info Exchange)
- //resource type "operation" don't have "get" request type.
-
-#if 0
- int ret;
- iotcon_request_type_e type;
-
- ret = iotcon_request_get_request_type(request, &type);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- LOG_DEBUG("iotcon request type %d", type);
- if (IOTCON_REQUEST_POST == type) {
- iotcon_response_h response = NULL;
- iotcon_representation_h req_repr;
- iotcon_attributes_h attributes;
- char *cmd;
- char *arg = NULL;
- int result;
- comp_request_type_e command;
-
- ret = iotcon_request_get_representation(request, &req_repr);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_request_get_representation() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_representation_get_attributes(req_repr, &attributes);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_representation_get_attributes() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_attributes_get_str(attributes, "CMD", &cmd);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_attributes_get_bool() Fail(%d)", ret);
- return;
- }
-
- LOG_DEBUG("cmd %s", cmd);
-
- command = string2command(cmd);
-
- if (command == COMP_REQ_CREATE_GROUP) {
- LOG_DEBUG("Request create group");
- char *group_name;
- iotcon_attributes_get_str(attributes, "name", &group_name);
-
- LOG_DEBUG("group_name : %s", group_name);
- result = comp_group_create(group_name);
- arg = g_strdup(group_name);
-
- } else if (command == COMP_REQ_INVITE_DEVICE) {
- LOG_DEBUG("Request invite");
- char *group_name;
- char *uuid;
-
- iotcon_attributes_get_str(attributes, "name", &group_name);
- iotcon_attributes_get_str(attributes, "id", &uuid);
-
- LOG_DEBUG("group_name : %s, UUID : %s", group_name, uuid);
-
- result = comp_group_invite(group_name, uuid, "12341234");
- arg = g_strdup(uuid);
-
- } else if (command == COMP_REQ_EJECT_DEVICE) {
- LOG_DEBUG("Request eject");
- char *group_name;
- char *uuid;
- comp_context_t *comp_ctx = comp_context_get_context();
-
- iotcon_attributes_get_str(attributes, "name", &group_name);
- iotcon_attributes_get_str(attributes, "id", &uuid);
-
- LOG_DEBUG("group_name : %s, Self UUID : %s Target UUID : %s",
- group_name, comp_ctx->device_uuid, uuid);
-
- result = comp_group_dismiss(comp_ctx->device_uuid, uuid);
- arg = g_strdup(uuid);
-
- } else if (command == COMP_REQ_DELETE_GROUP) {
- LOG_DEBUG("Request delete group");
- arg = g_strdup("DELETED");
- } else if (command == COMP_REQ_SEND_DATA) {
-#ifdef SUPPORT_BASE64_ENCODING
- int payload_len;
- char *data = NULL;
-
- LOG_DEBUG("Receive Data");
-
- iotcon_attributes_get_str(attributes, "data", &data);
- /*
- * BASE64 encoding/decoding system use '=' as padding byte
- * But, query parameter does not allow use '=' character.Basically,
- * So, in order to use BASE64 as query parameters, we need additioinal length param
- * such as 'len=xx'
- */
- payload_len = strlen(data); /* This data may be cliped the last padding 1~2 bytes ('='/'==') */
-
- LOG_DEBUG("data = %s payload_len = %d", data, payload_len);
-
- size_t outSize = B64DECODE_OUT_SAFESIZE(payload_len + 1);
- uint8_t* out = g_malloc0(outSize);
- if (NULL == out) {
- LOG_ERR("Can't allocate memory for base64 str");
- return;
- }
- uint32_t len = 0;
-
- if(B64_OK == b64Decode(data, payload_len, out, outSize, &len)) {
- LOG_ERR("Base64 decoding failed.");
- return;
- }
- memcpy(arg, out, len);
-
- LOG_DEBUG("successfully decoded to base64. %s", arg);
-
- iotcon_query_remove(query, "data");
-#else
- char *data = NULL;
- iotcon_attributes_get_str(attributes, "data", &data);
- LOG_DEBUG("Receive Data = %s", data);
- arg = g_strdup(data);
-#endif
- } else {
- LOG_ERR("Unknown request command");
- }
-
- notify_request_result(cmd, arg, result);
-
- free(arg);
-
- ret = iotcon_response_create(request, &response);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_response_set_result(response, IOTCON_RESPONSE_OK);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_response_set_result Faild = %d", ret);
- iotcon_response_destroy(response);
- return;
- }
-
- ret = iotcon_response_send(response);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_response_send Faild = %d", ret);
- iotcon_response_destroy(response);
- return;
- }
-
- iotcon_response_destroy(response);
- }
-#endif
}
int comp_iot_add_resource(comp_resource_type_e resource_type, const char *uri)
return COMP_ERROR_NONE;
}
-static bool _get_res_type_cb(const char *string, void *user_data)
-{
- char **resource_type = (char **)user_data;
-
- *resource_type = g_strdup(string);
-
- LOG_DEBUG("resource type : %s", *resource_type);
-
- return IOTCON_FUNC_CONTINUE;
-}
-
int found_group_count = 0;
static void _clear_user_data(void *user_data)
}
}
-#if 0
-static void _on_get(iotcon_remote_resource_h resource, iotcon_error_e err,
- iotcon_request_type_e request_type, iotcon_response_h response, void *user_data)
-{
- last_get_result = err;
-
- int ret;
- iotcon_response_result_e response_result;
-
- ret = iotcon_response_get_result(response, &response_result);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_response_get_result() Fail(%d)", ret);
- return;
- }
-
- if (IOTCON_RESPONSE_OK != response_result) {
- LOG_ERR("_on_get Response error(%d)", response_result);
- return;
- }
-
- /* get the resource host address */
- char *resource_host = NULL;
- iotcon_remote_resource_get_host_address(resource, &resource_host);
- LOG_DEBUG("resource host : %s", resource_host);
-
- iotcon_remote_resource_destroy(resource);
-
- _clear_user_data(user_data);
-}
-#endif
-
static void _on_post(const HeaderOptions& /*headerOptions*/,
const OCRepresentation& rep, const int eCode)
{
char* b64Buf = g_malloc0(b64BufSize);
if (NULL == b64Buf) {
_clear_user_data(cmd);
- return IOTCON_FUNC_CONTINUE;
+ return TRUE;
}
b64Encode((const char *)cmd->arg1, cmd->arg1_len,
b64Buf, b64BufSize, &outSize);
LOG_ERR("Exception in foundResource: %s", e.what());
}
- return IOTCON_FUNC_CONTINUE;
-#if 0
- int ret;
- char *resource_uri_path = NULL;
- iotcon_resource_types_h resource_types;
- char *resource_device_id;
- char *resource_host;
- char *resource_type;
- comp_group_type_e group_type = COMP_GROUP_GROUP_ERROR;
-
- /* Callback: When no more resource available.
- As timeout is configured by IOTCON Library*/
- if (resource == NULL) {
- LOG_ERR("No more resource available to find !!");
- return IOTCON_FUNC_CONTINUE;
- }
-
- /* get the resource URI */
- ret = iotcon_remote_resource_get_uri_path(resource, &resource_uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("Failed to get resource uri path");
- return IOTCON_FUNC_CONTINUE;
- }
-
-
- LOG_DEBUG("Resource Found: Resource uri : %s", resource_uri_path);
-
- /* get the resource device id */
- ret = iotcon_remote_resource_get_device_id(resource, &resource_device_id);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("Failed to get resource device id");
- return IOTCON_FUNC_CONTINUE;
- }
- LOG_DEBUG("resource device id : %s", resource_device_id);
-
- /* get the resource host address */
- ret = iotcon_remote_resource_get_host_address(resource, &resource_host);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("Failed to get resource host address");
- return IOTCON_FUNC_CONTINUE;
- }
- LOG_DEBUG("resource host : %s", resource_host);
-
- ret = iotcon_remote_resource_get_types(resource, &resource_types);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("Failed to get resource types");
- return IOTCON_FUNC_CONTINUE;
- }
-
- ret = iotcon_resource_types_foreach(resource_types, _get_res_type_cb,
- &resource_type);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("Failed to get foreach resource types");
- return IOTCON_FUNC_CONTINUE;
- }
-
- if (strcmp(resource_type, "core.comp.group") == 0) {
- comp_context_t *comp_ctx = comp_context_get_context();
- comp_check_null_ret_error("comp_ctx", comp_ctx, IOTCON_FUNC_CONTINUE);
-
- if (strcmp(resource_device_id, comp_ctx->device_uuid) == 0)
- group_type = COMP_GROUP_GROUP_LOCAL;
- else
- group_type = COMP_GROUP_GROUP_REMOTE;
-
- char *sp = NULL;
- char *temp = strdup(resource_uri_path);
- char *ptr = strtok_r(temp, "/", &sp);
- ptr = strtok_r(NULL, "/", &sp);
- ptr = strtok_r(NULL, "/", &sp);
-
- LOG_DEBUG("group name is %s", ptr);
- comp_group_add_new(resource_uri_path, resource_device_id,
- ptr, resource_host, resource_type, group_type);
- found_group_count++;
-
- g_free(resource_type);
- if (temp) {
- free(temp);
- temp = NULL;
- }
-
- return IOTCON_FUNC_CONTINUE;
- } else if (strcmp(resource_type, "core.comp.data") == 0) {
- comp_command_t *cmd = (comp_command_t *)user_data;
-
- if (cmd != NULL && strcmp(cmd->uuid, resource_device_id) == 0) {
- LOG_DEBUG("Request to Remote Device");
-
- iotcon_remote_resource_h resource_clone = NULL;
- iotcon_representation_h repr;
- iotcon_attributes_h attributes;
-
- ret = iotcon_remote_resource_clone(resource, &resource_clone);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_remote_resource_clone failed = %d", ret);
- return IOTCON_FUNC_CONTINUE;
- }
-
- ret = iotcon_representation_create(&repr);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_representation_create() Fail(%d)", ret);
- return IOTCON_FUNC_CONTINUE;
- }
-
- ret = iotcon_attributes_create(&attributes);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_attributes_create() Fail(%d)", ret);
- iotcon_representation_destroy(repr);
- return IOTCON_FUNC_CONTINUE;
- }
-
- LOG_DEBUG("CMD = %s", command2string(cmd->command));
-
- if (cmd->command == COMP_REQ_CREATE_GROUP) { //request create group
- iotcon_attributes_add_str(attributes, "CMD", "1");
- iotcon_attributes_add_str(attributes, "name", cmd->arg1);
- } else if (cmd->command == COMP_REQ_INVITE_DEVICE) { //request invite
- iotcon_attributes_add_str(attributes, "CMD", "2");
- iotcon_attributes_add_str(attributes, "name", cmd->arg1);
- iotcon_attributes_add_str(attributes, "id", cmd->arg2);
- iotcon_attributes_add_str(attributes, "PIN", cmd->arg3);
- } else if (cmd->command == COMP_REQ_EJECT_DEVICE) { //request eject
- iotcon_attributes_add_str(attributes, "CMD", "3");
- iotcon_attributes_add_str(attributes, "name", cmd->arg1);
- iotcon_attributes_add_str(attributes, "id", cmd->arg2);
- } else if (cmd->command == COMP_REQ_DELETE_GROUP) { //request delete group
- iotcon_attributes_add_str(attributes, "CMD", "4");
- iotcon_attributes_add_str(attributes, "name", cmd->arg1);
- } else { /* Send Data */
- iotcon_attributes_add_str(attributes, "CMD", "5");
-#ifdef SUPPORT_BASE64_ENCODING
- uint32_t outSize = 0;
- size_t b64BufSize = B64ENCODE_OUT_SAFESIZE((cmd->arg1_len + 1));
- char* b64Buf = g_malloc0(b64BufSize);
- if (NULL == b64Buf) {
- iotcon_remote_resource_destroy(resource_clone);
- _clear_user_data(cmd);
- return IOTCON_FUNC_CONTINUE;
- }
- b64Encode((const char *)cmd->arg1, cmd->arg1_len, b64Buf,
- b64BufSize, &outSize);
- b64Buf[b64BufSize] = '\0';
- iotcon_attributes_add_str(attributes, "data", b64Buf);
- LOG_DEBUG("b64BufSize =%d outSize = %d b64Buf = %s", b64BufSize,
- outSize, b64Buf);
- g_free(b64Buf);
-#else
- iotcon_attributes_add_str(attributes, "data", cmd->arg1);
-#endif
- }
-
- ret = iotcon_representation_set_attributes(repr, attributes);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_representation_set_attributes() Fail(%d)", ret);
- iotcon_attributes_destroy(attributes);
- iotcon_representation_destroy(repr);
- return IOTCON_FUNC_CONTINUE;
- }
-
- iotcon_attributes_destroy(attributes);
-
- ret = iotcon_remote_resource_post(resource_clone, repr, NULL,
- _on_get, NULL);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_remote_resource_put() Fail(%d)", ret);
- iotcon_remote_resource_destroy(resource_clone);
- _clear_user_data(cmd);
- return IOTCON_FUNC_CONTINUE;
- }
-
- iotcon_representation_destroy(repr);
- }
-
- }
-
- return IOTCON_FUNC_CONTINUE;
-#endif
+ return TRUE;
}
static gboolean _timeout_cb(gpointer data)
ret = e.code();
}
-#if 0
- ret = iotcon_set_timeout(timeout);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("Failed to set timeout value");
- _clear_user_data(user_data);
- return COMP_ERROR_OPERATION_FAILED;
- }
-
- ret = iotcon_query_create(&query);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("Failed to create iotcon query");
- _clear_user_data(user_data);
- return COMP_ERROR_OPERATION_FAILED;
- }
-
- ret = iotcon_query_set_resource_type(query,
- comp_resource_get_type(resource_type));
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("Failed to set iotcon query resource type");
- _clear_user_data(user_data);
- return COMP_ERROR_OPERATION_FAILED;
- }
-
- LOG_DEBUG("Set Resource Type : %s", get_error_message(ret));
-
- ret = iotcon_set_timeout(timeout);
- if (IOTCON_ERROR_NONE != ret) {
- LOG_ERR("iotcon_set_timeout: Failed %s", get_error_message(ret));
- }
-
- if (cmd->command == COMP_REQ_SEND_DATA_ALL)
- ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS,
- IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP,
- query, _found_resource, user_data);
- else
- ret = iotcon_find_resource(cmd->host,
- IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP,
- query, _found_resource, user_data);
-#endif
-
cmd->resource_type = resource_type;
cmd->tid = g_timeout_add_seconds(timeout + 1, _timeout_cb, cmd);