/* * This file is a part of VyQChat. * * Copyright (C) 2002-2004 Pawel Stolowski * * VyQChat is free software; you can redestribute it and/or modify it * under terms of GNU General Public License by Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY. See GPL for more details. */ #include "uuid.h" #include #include #include UUID::UUID(): QByteArray(UUID_LEN)/*{{{*/ { }/*}}}*/ UUID::UUID(const QString &str): QByteArray(UUID_LEN)/*{{{*/ { if (str == QString::null) generate(); else { if (!set(str)) generate(); } }/*}}}*/ UUID::~UUID()/*{{{*/ { }/*}}}*/ void UUID::generate()/*{{{*/ { int rfd = open("/dev/random", O_RDONLY); read(rfd, (void *)data(), UUID_LEN); close(rfd); }/*}}}*/ void UUID::set(const unsigned char *data)/*{{{*/ { duplicate(reinterpret_cast(data), UUID_LEN); }/*}}}*/ bool UUID::set(const QString &str)/*{{{*/ { if (str.length() != 2*UUID_LEN) return false; int k = 0; for (int i=0; i= '0' && c <= '9') val |= c - '0'; else if (c >= 'a' && c <= 'f') val |= c - 'a' + 10; else if (c >= 'A' && c <= 'F') val |= c - 'A' + 10; else return false; val <<= 4; } at(i) = val; } return true; }/*}}}*/ QString UUID::asString() const/*{{{*/ { QString r; for (int i=0; i