2 * This file is part of the OpenPTS project.
4 * The Initial Developer of the Original Code is International
5 * Business Machines Corporation. Portions created by IBM
6 * Corporation are Copyright (C) 2010 International Business
7 * Machines Corporation. All Rights Reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the Common Public License as published by
11 * IBM Corporation; either version 1 of the License, or (at your option)
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 * Common Public License for more details.
19 * You should have received a copy of the Common Public License
20 * along with this program; if not, a copy can be viewed at
21 * http://www.opensource.org/licenses/cpl1.0.php.
26 * \brief UUID wrapper (libuuid part)
27 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
29 * cleanup 2011-01-20,21 SM
33 * Program UUID Description When
34 * ---------------------------------------------------------------------------------------------------
35 * ptscd CID Colelctor ID System install => /var/lib/openpts/uuid (UUID of sign key)
36 * RM RM ID RM Gen xid in RM, path /var/lib/openpts/$UUID/rm_files
37 * RunID ID of this daemon Daemon start => /var/lib/openpts/run_uuid
38 * openpts VID Verifier ID 1st run => uuid=XXX in 'HOME/.openpts/openpts.conf' file
39 * RM => 'HOME/.openpts/hostname/$UUID/rm_files
41 * Unit Test: check_uuid.c
58 #define SEP_LINE "------------------------------------------------------------------------------------"
60 /******************************/
62 /******************************/
65 * Create new UUID (DCE1.1 v1 time and node base)
71 uuid = malloc(sizeof(PTS_UUID)); // BYTE[16]
77 uuid_generate_time(uu);
80 return (PTS_UUID *)uuid;
86 void freeUuid(PTS_UUID *uuid) {
89 ERROR("null input\n");
100 PTS_UUID *getUuidFromString(char *str) {
105 rc = uuid_parse(str, uu);
107 ERROR("getUuidFromString() - uuid_parse fail, rc=%d, UUID='%s'\n",
112 uuid = malloc(sizeof(PTS_UUID));
117 memcpy(uuid, uu, 16);
125 char * getStringOfUuid(PTS_UUID *uuid) {
129 str_uuid = malloc(37);
130 if (str_uuid == NULL) {
131 ERROR("no memory\n");
135 memcpy(uu, uuid, 16);
137 uuid_unparse(uu, str_uuid);
148 int tm_sec; Seconds. [0-60] (1 leap second)
149 int tm_min; Minutes. [0-59]
150 int tm_hour; Hours. [0-23]
151 int tm_mday; Day. [1-31]
152 int tm_mon; Month. [0-11]
153 int tm_year; Year - 1900.
154 int tm_wday; Day of week. [0-6]
155 int tm_yday; Days in year.[0-365]
156 int tm_isdst; DST. [-1/0/1]
157 long int __tm_gmtoff; Seconds east of UTC.
158 __const char *__tm_zone; Timezone abbreviation.
174 PTS_DateTime * getDateTimeOfUuid(PTS_UUID *uuid) {
183 ERROR("null input\n");
188 memcpy(uu, uuid, 16);
189 t = uuid_time(uu, &tv);
190 // TODO gmtime or local?
191 gmtime_r((const time_t *) &t, &time);
193 pdt = malloc(sizeof(PTS_DateTime));
195 ERROR("no memory\n");
198 memcpy(pdt, &time, (9*4));
206 PTS_DateTime * getDateTime() {
213 // TODO gmtime or local?
214 gmtime_r((const time_t *) &t, &ttm);
216 pdt = malloc(sizeof(PTS_DateTime));
218 ERROR("no memory\n");
221 memcpy(pdt, &ttm, (9*4));