00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include "win32_uuid.h"
00024
00025 #include "xapian/error.h"
00026
00027 #include <cstring>
00028
00029 using namespace std;
00030
00032 const size_t UUID_SIZE = 16;
00033
00035 const size_t UUID_STRING_SIZE = 36;
00036
00037 void
00038 uuid_generate(uuid_t uu)
00039 {
00040 UUID uuid;
00041 if (rare(UuidCreate(&uuid) != RPC_S_OK)) {
00042
00043
00044
00045
00046
00047 throw Xapian::DatabaseCreateError("Cannot create UUID");
00048 }
00049 memcpy(uu, &uuid, UUID_SIZE);
00050 }
00051
00052 int
00053 uuid_parse(const char * in, uuid_t uu)
00054 {
00055 UUID uuid;
00056 if (UuidFromString((unsigned char*)in, &uuid) != RPC_S_OK)
00057 return -1;
00058 memcpy(uu, &uuid, UUID_SIZE);
00059 return 0;
00060 }
00061
00062 void uuid_unparse_lower(const uuid_t uu, char * out)
00063 {
00064 UUID uuid;
00065 char *uuidstr;
00066 memcpy(&uuid, uu, UUID_SIZE);
00067 if (rare(UuidToString(&uuid, (unsigned char **)(&uuidstr)) != RPC_S_OK)) {
00068
00069
00070 throw std::bad_alloc();
00071 }
00072 memcpy(out, strlwr(uuidstr), UUID_STRING_SIZE);
00073 out[UUID_STRING_SIZE] = '\0';
00074 RpcStringFree((unsigned char**)(&uuidstr));
00075 }
00076
00077 void uuid_clear(uuid_t uu)
00078 {
00079 memset(uu, 0, UUID_SIZE);
00080 }
00081
00082 int uuid_is_null(const uuid_t uu)
00083 {
00084 unsigned i = 0;
00085 while (i < UUID_SIZE) {
00086 if (uu[i++])
00087 return 0;
00088 }
00089 return 1;
00090 }