dbus-uuidgen.c
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-uuidgen.c The guts of the dbus-uuidgen binary live in libdbus, in this file.
*
* Copyright (C) 2006 Red Hat, Inc.
*
* SPDX-License-Identifier: AFL-2.1 OR GPL-2.0-or-later
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <config.h>
#include "dbus-uuidgen.h"
#include "dbus-internals.h"
#include "dbus-string.h"
#include "dbus-protocol.h"
#ifdef DBUS_WIN
#error "dbus-uuidgen should not be needed on Windows"
#endif
static dbus_bool_t
return_uuid (DBusGUID *uuid,
char **uuid_p,
DBusError *error)
{
if (uuid_p)
{
DBusString encoded;
if (!_dbus_string_init (&encoded))
{
_DBUS_SET_OOM (error);
return FALSE;
}
if (!_dbus_uuid_encode (uuid, &encoded) ||
!_dbus_string_steal_data (&encoded, uuid_p))
{
_DBUS_SET_OOM (error);
_dbus_string_free (&encoded);
return FALSE;
}
_dbus_string_free (&encoded);
}
return TRUE;
}
dbus_bool_t
_dbus_get_uuid (const char *filename,
char **uuid_p,
dbus_bool_t create_if_not_found,
DBusError *error)
{
DBusGUID uuid;
if (filename)
{
DBusString filename_str;
_dbus_string_init_const (&filename_str, filename);
if (!_dbus_read_uuid_file (&filename_str, &uuid, create_if_not_found, error))
goto error;
}
else
{
if (!_dbus_read_local_machine_uuid (&uuid, create_if_not_found, error))
goto error;
}
if (!return_uuid(&uuid, uuid_p, error))
goto error;
return TRUE;
error:
_DBUS_ASSERT_ERROR_IS_SET (error);
return FALSE;
}
dbus_bool_t
_dbus_create_uuid (char **uuid_p,
DBusError *error)
{
DBusGUID uuid;
if (!_dbus_generate_uuid (&uuid, error))
return FALSE;
return return_uuid (&uuid, uuid_p, error);
}
_dbus_generate_uuid
dbus_bool_t _dbus_generate_uuid(DBusGUID *uuid, DBusError *error)
Generates a new UUID.
Definition dbus-internals.c:752
_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:931
_dbus_uuid_encode
dbus_bool_t _dbus_uuid_encode(const DBusGUID *uuid, DBusString *encoded)
Hex-encode a UUID.
Definition dbus-internals.c:788
_dbus_create_uuid
dbus_bool_t _dbus_create_uuid(char **uuid_p, DBusError *error)
Definition dbus-uuidgen.c:121
_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:85
TRUE
#define TRUE
Expands to "1".
Definition dbus-macros.h:41
FALSE
#define FALSE
Expands to "0".
Definition dbus-macros.h:44
_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:686
_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:4421
dbus_bool_t
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition dbus-types.h:37
DBusError
Object representing an exception.
Definition dbus-errors.h:51
DBusString
Definition dbus-string.h:47
DBusGUID
A globally unique ID ; we have one for each DBusServer, and also one for each machine with libdbus in...
Definition dbus-internals.h:458