taskrambler  0.1.9
Web server and task management solution.
_format3or5.c
Go to the documentation of this file.
1 /**
2  * \file
3  *
4  * \author Georg Hopp
5  *
6  * \copyright
7  * Copyright © 2013 Georg Hopp
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 // for memcpy
24 #include <string.h>
25 
26 // for ntohl and similar
27 #include <arpa/inet.h>
28 
29 // for already available uuid functionality
30 #include <uuid/uuid.h>
31 
32 #include "class.h"
33 #include "uuid.h"
34 
35 void
36 _uuidFormat3or5(Uuid uuid, unsigned char hash[16], int version)
37 {
38  /* convert UUID to local byte order */
39  memcpy((uuid->uuid).value, hash, 16);
40 
41  (uuid->uuid).elements.time_low =
42  ntohl((uuid->uuid).elements.time_low);
43  (uuid->uuid).elements.time_mid =
44  ntohs((uuid->uuid).elements.time_mid);
45  (uuid->uuid).elements.time_hi_version =
46  ntohs((uuid->uuid).elements.time_hi_version);
47 
48  /* put in the variant and version bits */
49  (uuid->uuid).elements.time_hi_version &= 0x0FFF;
50  (uuid->uuid).elements.time_hi_version |= (version << 12);
51  (uuid->uuid).elements.clk_seq_hi_res &= 0x3F;
52  (uuid->uuid).elements.clk_seq_hi_res |= 0x80;
53 }
54 
55 // vim: set ts=4 sw=4:
void _uuidFormat3or5(Uuid uuid, unsigned char hash[16], int version)
Definition: _format3or5.c:36