return ret;
}
-EXPORT_API void mdg_group_destroy(mdg_group_s *group)
-{
- CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
-
- mdg_check_null_ret("group", group);
-
- if (group->device_id) {
- g_free(group->device_id);
- group->device_id = NULL;
- }
- if (group->group_name) {
- g_free(group->group_name);
- group->group_name = NULL;
- }
-
- g_free(group);
- group = NULL;
-}
-
EXPORT_API int mdg_group_find(mdg_h handle, int timeout,
mdg_group_found_cb found_cb, mdg_group_find_finish_cb finish_cb,
void *user_data)
mdg_check_null_ret_error("channel", channel, MDG_ERROR_INVALID_PARAMETER);
*len = read(_channel->client_sockfd, *data, MAXBUF);
- if (ret == -1) {
+ if (*len == -1) {
char buf[128];
strerror_r(errno, buf, 128);
_ERR("read() error : %s", buf);
CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
- mdg_group_s *group = (mdg_group_s *)data;
- mdg_check_null_ret_error("group", group, MDG_ERROR_INVALID_PARAMETER);
-
- if (group->device_id) {
- g_free(group->device_id);
- group->device_id = NULL;
- }
- if (group->group_name) {
- g_free(group->group_name);
- group->group_name = NULL;
- }
+ mdg_check_null_ret_error("data", data, MDG_ERROR_INVALID_PARAMETER);
- g_free(group);
- group = NULL;
+ mdg_clean_group((mdg_group_s *)data);
return ret;
}
CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
- mdg_device_s * device = (mdg_device_s *)data;
mdg_check_null_ret_error("data", data, MDG_ERROR_INVALID_PARAMETER);
- if (device->device_id) {
- g_free(device->device_id);
- device->device_id = NULL;
- }
-
- if (device->model_name) {
- g_free(device->model_name);
- device->model_name = NULL;
- }
-
- if (device->device_name) {
- g_free(device->device_name);
- device->device_name = NULL;
- }
-
- if (device->platform_ver) {
- g_free(device->platform_ver);
- device->platform_ver = NULL;
- }
-
- if (device->vendor_id) {
- g_free(device->vendor_id);
- device->vendor_id = NULL;
- }
-
- if (device->profile) {
- g_free(device->profile);
- device->profile = NULL;
- }
-
- g_free(device);
- device = NULL;
+ mdg_clean_device((mdg_device_s *)data);
return ret;
}
case MDG_EVENT_GROUP_FOUND: {
mdg_group_s *group = NULL;
- group = mdg_get_group_from_variant(va);
if (handle->group_found_cb.found_cb) {
+ group = mdg_get_group_from_variant(va);
+
handle->group_found_cb.found_cb(group->type, group,
handle->group_found_cb.user_data);
+
+ mdg_clean_group(group);
} else {
_ERR("The callback not exists");
}
case MDG_EVENT_DEVICE_FOUND: {
mdg_device_s *device = NULL;
- device = mdg_get_device_from_variant(va);
if (handle->device_found_cb.found_cb) {
+ device = mdg_get_device_from_variant(va);
+
handle->device_found_cb.found_cb(device,
handle->device_found_cb.user_data);
+
+ mdg_clean_device(device);
} else {
_ERR("The callback not exists");
}
}
handle->device_invite_finish_cb.finish_cb(ret, device,
handle->device_invite_finish_cb.user_data);
+
+ mdg_clean_device(device);
} else {
_ERR("The callback not exists");
}
unsigned char *data = NULL;
int data_len = 0;
- mdg_get_data_from_variant(va, &device_id, &channel_id, &msg_id, &data, &data_len);
- mdg_device_s *device = (mdg_device_s *)(handle->send_data_finish_cb.device);
if (handle->send_data_finish_cb.finish_cb) {
+ mdg_device_s *device = (mdg_device_s *)(handle->send_data_finish_cb.device);
+ mdg_get_data_from_variant(va, &device_id, &channel_id, &msg_id, &data, &data_len);
+
handle->send_data_finish_cb.finish_cb(ret, device, channel_id, msg_id, data, data_len,
handle->send_data_finish_cb.user_data);
+ mdg_clean_device(device);
+ if (data != NULL)
+ free(data);
} else {
_ERR("The callback not exists");
}
sscanf(channel->remote_address, "coaps://%s", (char *)tempaddr);
ret_ptr = strtok_r(tempaddr, ":", &temp_for_strtok);
+ if (ret_ptr == NULL) {
+ _ERR("strtok failed");
+ ret = MDG_ERROR_OPERATION_FAILED;
+ goto REQUEST_OPEN_CHANNEL_FINISH_EXIT;
+ }
+
_ERR("Address is %s", ret_ptr);
inet_pton(AF_INET, ret_ptr, &serveraddr.sin_addr.s_addr);
} else {
_ERR("The callback not exists");
}
+
+ mdg_clean_channel(channel);
+
break;
}
case MDG_EVENT_RECEIVE_DATA: {
char *channel_id;
int msg_id;
unsigned char *data;
- int data_len;
+ int data_len = 0;
mdg_get_data_from_variant(va, &device_id, &channel_id, &msg_id, &data, &data_len);
if (channel != NULL)
channel->receive_data_cb(0, device_id, channel_id, msg_id, data, data_len, channel->receive_data_cb_user_data);
+
+ if (data != NULL)
+ free(data);
+
break;
}
case MDG_EVENT_INVITED: {
mdg_group_s *group = NULL;
- group = mdg_get_group_from_variant(va);
-
if (handle->invited_event_cb.invited_event_cb) {
+ group = mdg_get_group_from_variant(va);
+
handle->invited_event_cb.invited_event_cb(group, handle->invited_event_cb.user_data);
+
+ mdg_clean_group(group);
} else {
_ERR("The callback not exists");
}
case MDG_EVENT_EJECTED: {
mdg_group_s *group = NULL;
- group = mdg_get_group_from_variant(va);
-
if (handle->ejected_event_cb.ejected_event_cb) {
+ group = mdg_get_group_from_variant(va);
+
handle->ejected_event_cb.ejected_event_cb(group, handle->ejected_event_cb.user_data);
+
+ mdg_clean_group(group);
} else {
_ERR("The callback not exists");
}
goto RECEIVE_OPEN_CHANNEL_EXIT;
}
- setsockopt(channel->server_sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv_timeo, sizeof(tv_timeo));
- setsockopt(channel->server_sockfd, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling));
+ if (setsockopt(channel->server_sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv_timeo, sizeof(tv_timeo)) < 0) {
+ ret = MDG_ERROR_OPERATION_FAILED;
+ strerror_r(errno, buf, 128);
+ _ERR("setsockopt error : %s", buf);
+ goto RECEIVE_OPEN_CHANNEL_EXIT;
+ }
+
+ if (setsockopt(channel->server_sockfd, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling)) < 0) {
+ ret = MDG_ERROR_OPERATION_FAILED;
+ strerror_r(errno, buf, 128);
+ _ERR("setsockopt error : %s", buf);
+ goto RECEIVE_OPEN_CHANNEL_EXIT;
+ }
serveraddr.sin_family = AF_INET;
serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
serveraddr.sin_port = htons(8675);
+ memset(&serveraddr.sin_zero, 0, sizeof(serveraddr.sin_zero));
if (bind(channel->server_sockfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)) < 0) {
ret = MDG_ERROR_OPERATION_FAILED;
} else {
_ERR("The callback not exists");
}
+
+ mdg_clean_channel(channel);
+
break;
}
default:
gpointer *user_data)
{
GDBusProxy *proxy = G_DBUS_PROXY(object);
- gchar *name_owner = g_dbus_proxy_get_name_owner(proxy);
- mdg_manager_s *handle = (mdg_manager_s *)user_data;
mdg_check_null_ret("user_data", user_data);
+ mdg_manager_s *handle = (mdg_manager_s *)user_data;
+ gchar *name_owner = g_dbus_proxy_get_name_owner(proxy);
LOGD("Name owner notify [%s]", name_owner);
return va;
}
+
+void mdg_clean_group (mdg_group_s *group)
+{
+ if (group == NULL)
+ return;
+
+ if (group->device_id) {
+ g_free(group->device_id);
+ group->device_id = NULL;
+ }
+ if (group->group_name) {
+ g_free(group->group_name);
+ group->group_name = NULL;
+ }
+
+ g_free(group);
+ group = NULL;
+}
+
+void mdg_clean_device (mdg_device_s *device)
+{
+ if (device == NULL)
+ return;
+
+ if (device->device_id) {
+ g_free(device->device_id);
+ device->device_id = NULL;
+ }
+
+ if (device->model_name) {
+ g_free(device->model_name);
+ device->model_name = NULL;
+ }
+
+ if (device->device_name) {
+ g_free(device->device_name);
+ device->device_name = NULL;
+ }
+
+ if (device->platform_ver) {
+ g_free(device->platform_ver);
+ device->platform_ver = NULL;
+ }
+
+ if (device->vendor_id) {
+ g_free(device->vendor_id);
+ device->vendor_id = NULL;
+ }
+
+ if (device->profile) {
+ g_free(device->profile);
+ device->profile = NULL;
+ }
+
+ g_free(device);
+ device = NULL;
+}
+
+void mdg_clean_channel (mdg_channel_s *channel)
+{
+ if (channel == NULL)
+ return;
+
+ if (channel->device_id) {
+ g_free(channel->device_id);
+ channel->device_id = NULL;
+ }
+
+ if (channel->channel_id) {
+ g_free(channel->channel_id);
+ channel->channel_id = NULL;
+ }
+
+ if (channel->remote_address) {
+ g_free(channel->remote_address);
+ channel->remote_address = NULL;
+ }
+
+ g_free(channel);
+ channel = NULL;
+}
+