percent[0] = '\0';
comp_command_t *cmd = g_new0(comp_command_t, 1);
- cmd->command = g_strdup("5");
+ cmd->command = g_strdup(COMP_REQ_SEND_DATA);
cmd->uuid = g_strdup(uuid_dev);
if (strchr(ip, ':')) /* IPv6 Adress */
return ret;
}
memcpy(cmd->arg1, data, len);
+#ifdef SUPPORT_BASE64_ENCODING
+ cmd->arg1_len = len;
+#endif
LOG_DEBUG("UUID %s host %s", cmd->uuid, cmd->host);
LOG_ERR("[Request Create Group] to %s", uuid);
comp_command_t *cmd = g_new0(comp_command_t, 1);
- cmd->command = g_strdup("1");
+ cmd->command = g_strdup(COMP_REQ_CREATE_GROUP);
cmd->uuid = g_strdup(uuid);
cmd->arg1 = g_strdup(group_name);
LOG_ERR("[Request Invite] to %s", uuid);
comp_command_t *cmd = g_new0(comp_command_t, 1);
- cmd->command = g_strdup("2");
+ cmd->command = g_strdup(COMP_REQ_INVITE_DEVICE);
cmd->uuid = g_strdup(uuid);
cmd->arg1 = g_strdup(group_name);
cmd->arg2 = g_strdup(target_uuid);
LOG_ERR("[Request Eject] to %s", uuid);
comp_command_t *cmd = g_new0(comp_command_t, 1);
- cmd->command = g_strdup("3");
+ cmd->command = g_strdup(COMP_REQ_EJECT_DEVICE);
cmd->uuid = g_strdup(uuid);
cmd->arg1 = g_strdup(group_name);
cmd->arg2 = g_strdup(target_uuid);
LOG_ERR("[Request Delete Group] to %s", uuid);
comp_command_t *cmd = g_new0(comp_command_t, 1);
- cmd->command = g_strdup("4");
+ cmd->command = g_strdup(COMP_REQ_DELETE_GROUP);
cmd->uuid = g_strdup(uuid);
cmd->arg1 = g_strdup(group_name);
#include <tzplatform_config.h>
-#include <iotivity_config.h>
-#include <platform_features.h>
+
#include <utlist.h>
+#include <base64.h>
#include <srmutility.h>
+#include <iotivity_config.h>
+#include <platform_features.h>
#include <ocprovisioningmanager.h>
#include <comp_iot.h>
iotcon_query_lookup(query, "CMD", &command);
- if (strcmp(command, "1") == 0) {
+ if (strcmp(command, COMP_REQ_CREATE_GROUP) == 0) {
LOG_DEBUG("Request create group");
char *group_name;
iotcon_query_lookup(query, "name", &group_name);
arg = g_strdup(group_name);
free(group_name);
- } else if (strcmp(command, "2") == 0) {
+ } else if (strcmp(command, COMP_REQ_INVITE_DEVICE) == 0) {
LOG_DEBUG("Request invite");
char *group_name;
char *uuid;
free(group_name);
free(uuid);
- } else if (strcmp(command, "3") == 0) {
+ } else if (strcmp(command, COMP_REQ_EJECT_DEVICE) == 0) {
LOG_DEBUG("Request eject");
char *group_name;
char *uuid;
free(group_name);
free(uuid);
- } else if (strcmp(command, "4") == 0) {
+ } else if (strcmp(command, COMP_REQ_DELETE_GROUP) == 0) {
LOG_DEBUG("Request delete group");
arg = g_strdup("DELETED");
} else {
+#ifdef SUPPORT_BASE64_ENCODING
+ int payload_len;
char *data = NULL;
+
LOG_DEBUG("Receive Data");
+
+ iotcon_query_lookup(query, "data", &data);
+ payload_len = strlen(data);
+
+ 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_query_lookup(query, "data", &data);
+ LOG_DEBUG("Receive Data = %s", data);
arg = g_strdup(data);
free(data);
+#endif
}
notify_request_result(command, arg, result);
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_query_h query = NULL;
ret = iotcon_remote_resource_clone(resource, &resource_clone);
- if (IOTCON_ERROR_NONE != ret)
+ if (IOTCON_ERROR_NONE != ret) {
+ LOG_ERR("iotcon_remote_resource_clone failed = %d", ret);
return IOTCON_FUNC_CONTINUE;
+ }
ret = iotcon_query_create(&query);
- if (IOTCON_ERROR_NONE != ret)
+ if (IOTCON_ERROR_NONE != ret) {
+ LOG_ERR("iotcon_query_create failed = %d", ret);
return IOTCON_FUNC_CONTINUE;
+ }
iotcon_query_add(query, "CMD", cmd->command);
+ LOG_DEBUG("CMD = %s", cmd->command);
- if (strcmp(cmd->command, "1") == 0) { //request create group
+ if (strcmp(cmd->command, COMP_REQ_CREATE_GROUP) == 0) { //request create group
iotcon_query_add(query, "name", cmd->arg1);
- } else if (strcmp(cmd->command, "2") == 0) { //request invite
+ } else if (strcmp(cmd->command, COMP_REQ_INVITE_DEVICE) == 0) { //request invite
iotcon_query_add(query, "name", cmd->arg1);
iotcon_query_add(query, "id", cmd->arg2);
iotcon_query_add(query, "PIN", cmd->arg3);
- } else if (strcmp(cmd->command, "3") == 0) { //request eject
+ } else if (strcmp(cmd->command, COMP_REQ_EJECT_DEVICE) == 0) { //request eject
iotcon_query_add(query, "name", cmd->arg1);
iotcon_query_add(query, "id", cmd->arg2);
- } else if (strcmp(cmd->command, "4") == 0) { //request delete group
+ } else if (strcmp(cmd->command, COMP_REQ_DELETE_GROUP) == 0) { //request delete group
iotcon_query_add(query, "name", cmd->arg1);
- } else if (strcmp(cmd->command, "5") == 0) { /* Send Data */
+ } else { /* Send Data */
+#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_query_add(query, "data", b64Buf);
+ LOG_DEBUG("b64BufSize =%d outSize = %d b64Buf = %s", b64BufSize, outSize, b64Buf);
+ g_free(b64Buf);
+#else
iotcon_query_add(query, "data", cmd->arg1);
+#endif
}
ret = iotcon_remote_resource_get(resource_clone, query, _on_get, cmd);
LOG_DEBUG("Set Resource Type : %s", get_error_message(ret));
- if (cmd && (g_strcmp0(cmd->command, "5") == 0))
+ if (cmd && (g_strcmp0(cmd->command, COMP_REQ_CREATE_GROUP) == 0 ||
+ g_strcmp0(cmd->command, COMP_REQ_SEND_DATA) == 0))
ret = iotcon_find_resource(cmd->host,
IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP,
query, _found_resource, user_data);