mot-agent: Fixed issue in cloning OCProvision device
authorSaurav Babu <saurav.babu@samsung.com>
Tue, 20 Feb 2018 13:46:19 +0000 (19:16 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:48 +0000 (19:38 +0900)
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
src/mot-agent/ma-subowner.c

index 9d453f2..e126fbe 100755 (executable)
@@ -429,14 +429,20 @@ static OCProvisionDev_t* _clone_ocprovision_dev(const OCProvisionDev_t* src)
                memcpy(newDev->doxm->mom, src->doxm->mom, sizeof(OicSecMom_t));
 
                if (src->doxm->subOwners) {
+                       int count = 0;
                        OicSecSubOwner_t* subowner = NULL;
                        OicSecSubOwner_t* temp = NULL;
                        OicSecSubOwner_t* temp2 = NULL;
+                       OicSecSubOwner_t* temp3 = NULL;
                        LL_FOREACH_SAFE(src->doxm->subOwners, subowner, temp) {
                                temp2 = g_try_malloc0(sizeof(OicSecSubOwner_t));
-                               memcpy(temp2, subowner, sizeof(OicSecSubOwner_t));
-                               LL_APPEND(newDev->doxm->subOwners, temp2);
+                               temp3 = subowner;
+                               temp3->next = NULL;
+                               memcpy(temp2, temp3, sizeof(OicSecSubOwner_t));
+                               LL_PREPEND(newDev->doxm->subOwners, temp2);
                        }
+                       LL_COUNT(newDev->doxm->subOwners, subowner, count);
+                       MA_LOGD("newdev subowner count %d", count);
                }
        }
 
@@ -973,11 +979,8 @@ static void _update_mot_dev_list(ma_req_cb_s *con, OCProvisionDev_t *list)
 
                if (!_get_dev_by_uuid(dev_list, uuid)) {
                        MA_LOGD("Add device %s to list", _get_readable_uuid(uuid));
-                       OCProvisionDev_t *temp2;
-                       OCProvisionDev_t *temp = iter;
-                       temp->next = NULL;
-                       temp2 = _clone_ocprovision_dev(temp);
-                       LL_APPEND(dev_list, temp2);
+                       OCProvisionDev_t *temp;
+                       temp = _clone_ocprovision_dev(iter);
 
                        /* Notify Mot Enabled Device added */
                        g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}"));
@@ -1011,21 +1014,19 @@ static void _update_mot_dev_list(ma_req_cb_s *con, OCProvisionDev_t *list)
                        g_variant_builder_add(&builder, "{sv}", "devStatus",
                                                          g_variant_new_uint32(iter->devStatus));
 
-                       if (con->cid == MA_DISC_MOT_ENB_DEVS)
+                       if (con->cid == MA_DISC_MOT_ENB_DEVS) {
                                ma_notify_mot_enb_dev_added(g_variant_builder_end(&builder));
-                       else
+                               LL_APPEND(g_client->g_motdev_list, temp);
+                       } else {
                                ma_notify_mowned_dev_added(g_variant_builder_end(&builder));
+                               LL_APPEND(g_client->g_mowned_list, temp);
+                       }
                } else {
                        MA_LOGD("Device %s already exist", _get_readable_uuid(uuid));
                }
 
                iter = iter->next;
        }
-
-       if (con->cid == MA_DISC_MOT_ENB_DEVS)
-               g_client->g_motdev_list = dev_list;
-       else if (con->cid == MA_DISC_MOWNED_DEVS)
-               g_client->g_mowned_list = dev_list;
 }
 
 static gpointer _disc_mot_env_devs_func(gpointer data)