X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fprovisioning%2Fexamples%2FcloudWrapper.cpp;h=fefd85ae7db3218becfd3532dd14a038291c0dea;hb=7f00f942c39b7bc27c7eeecf213a239c3fe4173c;hp=aa124dcc1f7ad6eebad1e370a4ea9fbf57272eba;hpb=edcfc3d2329da7b914771c0dcff5f42c9b74fd93;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/provisioning/examples/cloudWrapper.cpp b/resource/provisioning/examples/cloudWrapper.cpp index aa124dc..fefd85a 100644 --- a/resource/provisioning/examples/cloudWrapper.cpp +++ b/resource/provisioning/examples/cloudWrapper.cpp @@ -1,24 +1,22 @@ -/* - * //****************************************************************** - * // - * // Copyright 2016 Samsung Electronics All Rights Reserved. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - */ +/* ***************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * *****************************************************************/ #include "logger.h" #include "occloudprovisioning.h" @@ -52,6 +50,15 @@ using namespace OC; +/** + * Skip special characters from stdin + * */ +static void skipSpecialCharacters() +{ + for( ; 0x20<=getchar(); ); // for removing overflow garbages + // '0x20<=code' is character region +} + static bool readOptional(const char* description) { if (NULL == description) @@ -60,12 +67,17 @@ static bool readOptional(const char* description) } printf("Do you want to Enter %s (y/n):\n", description); - char choice = 0; + char temp, choice = 0; while(1) { - scanf("%c", &choice); - getchar(); + for (int ret = 0; 1 != ret; ) + { + ret = scanf("%c", &temp); + skipSpecialCharacters(); + } + + choice = temp; switch (choice) { @@ -87,11 +99,25 @@ static bool readOptional(const char* description) */ void readString(char* item, int length, const char* description, const char* example) { + char *input = (char*)OICCalloc(length, sizeof(char)); + if (NULL == input) + { + OIC_LOG(INFO, TAG, "input is NULL"); + return; + } + printf("Enter %s (f.e. %s):\n", description, example); char temp[8] = { 0 }; snprintf(temp, sizeof(temp), "%%%ds", length - 1); - scanf(temp, item); - getchar(); + + for (int ret = 0; 1 != ret; ) + { + ret = scanf(temp, input); + skipSpecialCharacters(); + } + + strncpy(item, input, length); + OICFree(input); } /** @@ -119,9 +145,17 @@ static void readOptionalString(char* item, int length, const char* description, */ void readInteger(int* item, const char* description, const char* example) { + int temp; + printf("Enter %s (f.e. %s):\n", description, example); - scanf("%d", item); - getchar(); + + for (int ret = 0; 1 != ret; ) + { + ret = scanf("%d", &temp); + skipSpecialCharacters(); + } + + *item = temp; } /**