[SVRDBEditor] Edit Doxm MOM attribute 14/186114/1
authorVitalii Irkha <v.irkha@samsung.com>
Tue, 17 Jul 2018 13:36:20 +0000 (16:36 +0300)
committerAmit KS <amit.s12@samsung.com>
Tue, 7 Aug 2018 08:21:46 +0000 (13:51 +0530)
Added Edit mom functionality to svrdbeditor tool

https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/307
(cherry picked from commit 86952a25462ae462e52af83368c153c00b4e8374)

Change-Id: Ieff8984afb72bdbad80281ed44967bfa8ac55440
Signed-off-by: Vice73d5846ecb99fb04e87860b94afbaeff0ddcb4talii Irkha <v.irkha@samsung.com>
Signed-off-by: Amit KS <amit.s12@samsung.com>
resource/csdk/security/tool/svrdbeditor_src/svrdbeditordoxm.c

index efc5c7543b0874b7acdd2ca4fc821dbe4c2b41b3..c0bfda2eaccbd2a6bfb23d65ea0e2408197e9979 100644 (file)
@@ -63,15 +63,30 @@ static const unsigned int DOXM_SCT_NUMBER[DOXM_SCT_CNT] =
     PIN_PASSWORD, ASYMMETRIC_ENCRYPTION_KEY
 };
 
+#ifdef MULTIPLE_OWNER
+static const char *DOXM_MOM_STRING[OIC_NUMBER_OF_MOM_TYPE] =
+{
+    "OIC_MULTIPLE_OWNER_DISABLE", "OIC_MULTIPLE_OWNER_ENABLE", "OIC_MULTIPLE_OWNER_TIMELY_ENABLE"
+};
+
+static const unsigned int DOXM_MOM_NUMBER[OIC_NUMBER_OF_MOM_TYPE] =
+{
+        OIC_MULTIPLE_OWNER_DISABLE, OIC_MULTIPLE_OWNER_ENABLE, OIC_MULTIPLE_OWNER_TIMELY_ENABLE
+};
+#endif //MULTIPLE_OWNER
+
 typedef enum DoxmModifyType
 {
     DOXM_EDIT_OXM = 1,
     DOXM_EDIT_OXMSEL,
     DOXM_EDIT_SCT,
+#ifdef MULTIPLE_OWNER
+    DOXM_EDIT_MOM,
+#endif //MULTIPLE_OWNER
     DOXM_EDIT_OWNED,
     DOXM_EDIT_DEVICEID,
     DOXM_EDIT_OWNER,
-    DOXM_EDIT_ROWNERID = 7,
+    DOXM_EDIT_ROWNERID,
     DOXM_SAVE = 98,
     DOXM_CANCEL = 99
 } DoxmModifyType;
@@ -388,6 +403,46 @@ static int InputSct(OicSecCredType_t *sct)
     return 0;
 }
 
+#ifdef MULTIPLE_OWNER
+static int InputMom(OicSecMomType_t *mom_mode)
+{
+    unsigned int sel = 0;
+    OicSecMomType_t tmpMom = 0;
+    bool isFirstEntry = false;
+    PRINT_PROG("\nInput the Supported Mom Types\n");
+    for (;;)
+    {
+        for (size_t i = 0; i < OIC_NUMBER_OF_MOM_TYPE; i++)
+        {
+            ((tmpMom == DOXM_MOM_NUMBER[i]) && isFirstEntry) ? PRINT_DATA("\t%zu. %s\n", i, DOXM_MOM_STRING[i]) :
+            PRINT_NORMAL("\t%zu. %s\n", i, DOXM_MOM_STRING[i]);
+            isFirstEntry = true;
+        }
+        PRINT_NORMAL("\t%d. Save\n", DOXM_SAVE);
+        PRINT_NORMAL("\t%d. Cancel\n", DOXM_CANCEL);
+        sel = InputNumber("Select number: ");
+        if (sel < OIC_NUMBER_OF_MOM_TYPE)
+        {
+            tmpMom ^= DOXM_MOM_NUMBER[sel];
+        }
+        else if (DOXM_SAVE == sel)
+        {
+            break;
+        }
+        else if (DOXM_CANCEL == sel)
+        {
+            return -1;
+        }
+        else
+        {
+            PRINT_WARN("Wrong number.");
+        }
+    }
+    *mom_mode = tmpMom;
+    return 0;
+}
+#endif //MULTIPLE_OWNER
+
 static bool InputOwned(void)
 {
     char ans = 0;
@@ -447,6 +502,16 @@ static OicSecDoxm_t *InputDoxmData(void)
         return NULL;
     }
 
+#ifdef MULTIPLE_OWNER
+    ret = InputMom(&(doxm->mom->mode));
+    if (0 != ret)
+    {
+        PRINT_ERR("Failed InputMom\n");
+        DeleteDoxmBinData(doxm);
+        return NULL;
+    }
+#endif //MULTIPLE_OWNER
+
     doxm->owned = InputOwned();
 
     PRINT_PROG(
@@ -496,6 +561,9 @@ static int ModifyDoxm(void)
     PRINT_DATA("\t%2d. Edit oxms\n", DOXM_EDIT_OXM);
     PRINT_DATA("\t%2d. Edit oxmSel\n", DOXM_EDIT_OXMSEL);
     PRINT_DATA("\t%2d. Edit sct\n", DOXM_EDIT_SCT);
+#ifdef MULTIPLE_OWNER
+    PRINT_DATA("\t%2d. Edit mom\n", DOXM_EDIT_MOM);
+#endif //MULTIPLE_OWNER
     PRINT_DATA("\t%2d. Edit owned\n", DOXM_EDIT_OWNED);
     PRINT_DATA("\t%2d. Edit deviceID\n", DOXM_EDIT_DEVICEID);
     PRINT_DATA("\t%2d. Edit owner\n", DOXM_EDIT_OWNER);
@@ -525,6 +593,15 @@ static int ModifyDoxm(void)
                 return -1;
             }
             break;
+#ifdef MULTIPLE_OWNER
+        case DOXM_EDIT_MOM:
+            if (0 != InputMom(&(g_doxm->mom->mode)))
+            {
+                PRINT_ERR("Failed InputMom");
+                return -1;
+            }
+            break;
+#endif
         case DOXM_EDIT_OWNED:
             g_doxm->owned = InputOwned();
             break;