1 /* *****************************************************************
3 * Copyright 2017 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * *****************************************************************/
25 #include "oic_malloc.h"
26 #include "oic_string.h"
28 #include "srmresourcestrings.h"
29 #include "securevirtualresourcetypes.h"
30 #include "srmutility.h"
32 #include "svrdbeditorcommon.h"
34 #define STR_UUID_LENGTH (UUID_LENGTH * 2 + 4 + 1) // length + dash length + '\0'
35 #define STR_UUID_ZERO "0"
37 void PrintUuid(const OicUuid_t *uuid)
40 if (OC_STACK_OK == ConvertUuidToStr(uuid, &strUuid))
42 PRINT_DATA("%s\n", strUuid);
47 PRINT_ERR("Can not convert UUID to String");
51 void PrintIntArray(const int *array, size_t length)
53 for (size_t i = 0; i < length; i++)
55 PRINT_DATA("%d ", array[i]);
60 void PrintStringArray(const char **array, size_t length)
62 for (size_t i = 0; i < length; i++)
64 PRINT_DATA("%s ", array[i]);
69 void PrintInt(int value)
71 PRINT_DATA("%d\n", value);
74 void PrintString(const char *text)
76 PRINT_DATA("%s\n", text);
79 void PrintBuffer(const uint8_t *buf, size_t bufLen)
83 for (i = 0; i < bufLen; i++)
85 if (0 == (i + 1) % 20 || bufLen - 1 == i)
87 PRINT_DATA("%02X \n", buf[i]);
91 PRINT_DATA("%02X ", buf[i]);
96 int InputNumber(const char *infoText)
100 PRINT_PROG("%s", infoText);
101 for (int ret = 0; 1 != ret; )
103 ret = scanf("%d", &inputValue);
104 for ( ; 0x20 <= getchar(); ); // for removing overflow garbages
105 // '0x20<=code' is character region
111 char *InputString(const char *infoText)
113 char tmpStr[SVR_DB_PATH_LENGTH] = {0};
115 PRINT_PROG("%s", infoText);
116 for (int ret = 0; 1 != ret; )
118 ret = scanf("%1024s", tmpStr);
119 for ( ; 0x20 <= getchar(); ); // for removing overflow garbages
120 // '0x20<=code' is character region
123 return OICStrdup(tmpStr);
126 int InputUuid(OicUuid_t *uuid)
128 OCStackResult ocResult = OC_STACK_ERROR;
129 char strUuid[STR_UUID_LENGTH] = {0};
134 PRINT_ERR("Invalid parameter");
138 if (NULL == fgets(strUuid, STR_UUID_LENGTH, stdin))
140 PRINT_ERR("Failed fgets");
143 strLen = strlen(strUuid);
144 if ('\n' == strUuid[strLen - 1])
146 strUuid[strLen - 1] = '\0';
150 for ( ; 0x20 <= getchar(); ); // for removing overflow garbages
153 if (0 == strncmp(strUuid, STR_UUID_ZERO, sizeof(STR_UUID_ZERO)))
155 memset(uuid->id, 0x00, sizeof(uuid->id));
157 else if (0 == strncmp(strUuid, (char *)WILDCARD_SUBJECT_ID.id, sizeof(WILDCARD_SUBJECT_ID.id)))
159 memset(uuid->id, 0x00, sizeof(uuid->id));
160 memcpy(uuid->id, WILDCARD_SUBJECT_ID.id, WILDCARD_SUBJECT_ID_LEN);
164 ocResult = ConvertStrToUuid(strUuid, uuid);
165 if (OC_STACK_OK != ocResult)
167 PRINT_ERR("Failed ConvertStrToUuid");