X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fc_common%2Focrandom%2Fsrc%2Focrandom.c;h=e0dcdc57778d7099b773907304f4d890e9e1e070;hb=9a19f4a70b1df5398a41ef7c6471d3c0d7121fa5;hp=118aeeeb3a424421b3ea5a3a9dea9964c51b004c;hpb=1f38dc188968757d7eec20816b7964b052fe5a32;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/c_common/ocrandom/src/ocrandom.c b/resource/c_common/ocrandom/src/ocrandom.c index 118aeee..e0dcdc5 100644 --- a/resource/c_common/ocrandom/src/ocrandom.c +++ b/resource/c_common/ocrandom/src/ocrandom.c @@ -30,7 +30,8 @@ #define _POSIX_C_SOURCE 200809L #endif -#include "platform_features.h" +#include "iotivity_config.h" + #ifdef HAVE_FCNTL_H #include #endif @@ -40,6 +41,11 @@ #ifdef HAVE_STDLIB_H #include #endif +#ifdef HAVE_STRING_H +#include +#elif defined(HAVE_STRINGS_H) +#include +#endif #ifdef HAVE_SYS_TIME_H #include #endif @@ -135,7 +141,7 @@ int8_t OCSeedRandom() gettimeofday(&tv, NULL); currentTime = tv.tv_sec * (uint64_t)1000000 + tv.tv_usec; #endif -#if defined(__unix__) || defined(__APPLE__) +#if defined(__unix__) || defined(__APPLE__) || defined(__TIZENRT__) int32_t fd = open("/dev/urandom", O_RDONLY); if (fd >= 0) { @@ -327,7 +333,6 @@ OCRandomUuidResult OCGenerateUuidString(char uuidString[UUID_STRING_SIZE]) } else { - close(fd); return RAND_UUID_READ_ERROR; } #elif defined(HAVE_UUID_UUID_H) @@ -374,3 +379,39 @@ OCRandomUuidResult OCConvertUuidToString(const uint8_t uuid[UUID_SIZE], return RAND_UUID_OK; } + +OCRandomUuidResult OCConvertStringToUuid(const char uuidString[UUID_STRING_SIZE], + uint8_t uuid[UUID_SIZE]) +{ + if(NULL == uuidString || NULL == uuid) + { + return RAND_UUID_INVALID_PARAM; + } + + size_t urnIdx = 0; + size_t uuidIdx = 0; + size_t strUuidLen = 0; + char convertedUuid[UUID_SIZE * 2] = {0}; + + strUuidLen = strlen(uuidString); + if((UUID_STRING_SIZE - 1) == strUuidLen) + { + for(uuidIdx=0, urnIdx=0; uuidIdx < UUID_SIZE ; uuidIdx++, urnIdx+=2) + { + if(*(uuidString + urnIdx) == '-') + { + urnIdx++; + } + sscanf(uuidString + urnIdx, "%2hhx", &convertedUuid[uuidIdx]); + } + } + else + { + return RAND_UUID_CONVERT_ERROR; + } + + memcpy(uuid, convertedUuid, UUID_SIZE); + + return RAND_UUID_OK; +} +