D-Bus 1.14.8

dbus-uuidgen.c
1/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2/* dbus-uuidgen.c The guts of the dbus-uuidgen binary live in libdbus, in this file.
3 *
4 * Copyright (C) 2006 Red Hat, Inc.
5 *
6 * Licensed under the Academic Free License version 2.1
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23#include <config.h>
24#include "dbus-uuidgen.h"
25#include "dbus-internals.h"
26#include "dbus-string.h"
27#include "dbus-protocol.h"
28
29#ifdef DBUS_WIN
30#error "dbus-uuidgen should not be needed on Windows"
31#endif
32
44 static dbus_bool_t
45return_uuid (DBusGUID *uuid,
46 char **uuid_p,
47 DBusError *error)
48{
49 if (uuid_p)
50 {
51 DBusString encoded;
52
53 if (!_dbus_string_init (&encoded))
54 {
55 _DBUS_SET_OOM (error);
56 return FALSE;
57 }
58
59 if (!_dbus_uuid_encode (uuid, &encoded) ||
60 !_dbus_string_steal_data (&encoded, uuid_p))
61 {
62 _DBUS_SET_OOM (error);
63 _dbus_string_free (&encoded);
64 return FALSE;
65 }
66 _dbus_string_free (&encoded);
67 }
68 return TRUE;
69}
70
82 dbus_bool_t
83_dbus_get_uuid (const char *filename,
84 char **uuid_p,
85 dbus_bool_t create_if_not_found,
86 DBusError *error)
87{
88 DBusGUID uuid;
89
90 if (filename)
91 {
92 DBusString filename_str;
93 _dbus_string_init_const (&filename_str, filename);
94 if (!_dbus_read_uuid_file (&filename_str, &uuid, create_if_not_found, error))
95 goto error;
96 }
97 else
98 {
99 if (!_dbus_read_local_machine_uuid (&uuid, create_if_not_found, error))
100 goto error;
101 }
102
103 if (!return_uuid(&uuid, uuid_p, error))
104 goto error;
105
106 return TRUE;
107
108 error:
109 _DBUS_ASSERT_ERROR_IS_SET (error);
110 return FALSE;
111}
112
118 dbus_bool_t
119_dbus_create_uuid (char **uuid_p,
120 DBusError *error)
121{
122 DBusGUID uuid;
123
124 if (!_dbus_generate_uuid (&uuid, error))
125 return FALSE;
126
127 return return_uuid (&uuid, uuid_p, error);
128}
129
_dbus_generate_uuid
dbus_bool_t _dbus_generate_uuid(DBusGUID *uuid, DBusError *error)
Generates a new UUID.
Definition: dbus-internals.c:720
_dbus_read_uuid_file
dbus_bool_t _dbus_read_uuid_file(const DBusString *filename, DBusGUID *uuid, dbus_bool_t create_if_not_found, DBusError *error)
Reads (and optionally writes) a uuid to a file.
Definition: dbus-internals.c:899
_dbus_uuid_encode
dbus_bool_t _dbus_uuid_encode(const DBusGUID *uuid, DBusString *encoded)
Hex-encode a UUID.
Definition: dbus-internals.c:756
_dbus_create_uuid
dbus_bool_t _dbus_create_uuid(char **uuid_p, DBusError *error)
Definition: dbus-uuidgen.c:119
_dbus_get_uuid
dbus_bool_t _dbus_get_uuid(const char *filename, char **uuid_p, dbus_bool_t create_if_not_found, DBusError *error)
For use by the dbus-uuidgen binary ONLY, do not call this.
Definition: dbus-uuidgen.c:83
TRUE
#define TRUE
Expands to "1".
FALSE
#define FALSE
Expands to "0".
_dbus_string_init
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition: dbus-string.c:182
_dbus_string_init_const
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
Definition: dbus-string.c:197
_dbus_string_steal_data
dbus_bool_t _dbus_string_steal_data(DBusString *str, char **data_return)
Like _dbus_string_get_data(), but removes the gotten data from the original string.
Definition: dbus-string.c:672
_dbus_string_free
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as _DBUS_STRING_IN...
Definition: dbus-string.c:278
_dbus_read_local_machine_uuid
dbus_bool_t _dbus_read_local_machine_uuid(DBusGUID *machine_id, dbus_bool_t create_if_not_found, DBusError *error)
Reads the uuid of the machine we're running on from the dbus configuration.
Definition: dbus-sysdeps-unix.c:4257
dbus_bool_t
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:35
DBusError
Object representing an exception.
Definition: dbus-errors.h:49
DBusString
Definition: dbus-string.h:43
DBusGUID
A globally unique ID ; we have one for each DBusServer, and also one for each machine with libdbus in...
Definition: dbus-internals.h:442