Added version type and some comments
[distributed.git] / src / libs / net / uuid.h
bloba9ba3851355c7e52bb6415f7423d5bcd2a09a11c
1 //
2 // Copyright (C) 2008 Francesco Salvestrini
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this program; if not, write to the Free Software Foundation, Inc.,
16 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #ifndef LIBS_NET_UUID_H
20 #define LIBS_NET_UUID_H
22 #include "config.h"
24 #include <string>
26 namespace Net {
27 class UUID {
28 public:
29 UUID(void);
30 ~UUID(void);
31 UUID(const std::string & u);
33 void clear(void);
35 // Operators
36 operator std::string(void);
37 bool operator ==(const UUID & rhs);
38 UUID & operator =(const UUID & rhs);
39 friend std::ostream & operator <<(std::ostream & stream,
40 UUID obj);
41 friend std::istream & operator >>(std::istream & stream,
42 UUID & obj);
44 typedef enum {
45 UNKNOWN = 0,
46 IETF_RFC4122_TIMEBASED = 1,
47 DCE_SECURITY_POSIX_UID = 2,
48 IETF_RFC4122_NAMEBASED_MD5 = 3,
49 IETF_RFC4122_RANDOM = 4,
50 IETF_RFC4122_NAMEBASED_SHA1 = 5
51 } version_t;
53 protected:
55 private:
56 // From RFC4122
58 // The fields are encoded as 16 octets, with the sizes and order of the
59 // fields defined above, and with each field encoded with the Most
60 // Significant Byte first (known as network byte order). Note that the
61 // field names, particularly for multiplexed fields, follow historical
62 // practice.
64 // 0 1 2 3
65 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
66 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
67 // | time_low |
68 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
69 // | time_mid | time_hi_and_version |
70 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71 // |clk_seq_hi_res | clk_seq_low | node (0-1) |
72 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73 // | node (2-5) |
74 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76 struct uuid {
77 uint32_t time_low;
78 uint16_t time_mid;
79 uint16_t time_hi_and_version;
80 uint16_t clock_seq;
81 uint8_t node[6];
82 } uuid_;
84 bool grab_4hex(const std::string & u,
85 std::string::size_type s,
86 std::string::size_type e,
87 uint16_t & v);
88 bool grab_8hex(const std::string & u,
89 std::string::size_type s,
90 std::string::size_type e,
91 uint32_t & v);
92 bool grab_12hex(const std::string & u,
93 std::string::size_type s,
94 std::string::size_type e,
95 uint8_t * v);
99 #endif // LIBS_NET_UUID_H