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.
4 * Copyright (C) 2006 Red Hat, Inc.
6 * Licensed under the Academic Free License version 2.1
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.
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.
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
24 #include "dbus-uuidgen.h"
25 #include "dbus-internals.h"
26 #include "dbus-string.h"
27 #include "dbus-protocol.h"
30 #error "dbus-uuidgen should not be needed on Windows"
34 * @defgroup DBusInternalsUuidgen dbus-uuidgen implementation
35 * @ingroup DBusInternals
36 * @brief Functions for dbus-uuidgen binary
38 * These are not considered part of the ABI, and if you call them
39 * you will get screwed by future changes.
45 return_uuid (DBusGUID *uuid,
53 if (!_dbus_string_init (&encoded))
55 _DBUS_SET_OOM (error);
59 if (!_dbus_uuid_encode (uuid, &encoded) ||
60 !_dbus_string_steal_data (&encoded, uuid_p))
62 _DBUS_SET_OOM (error);
63 _dbus_string_free (&encoded);
66 _dbus_string_free (&encoded);
72 * For use by the dbus-uuidgen binary ONLY, do not call this.
73 * We can and will change this function without modifying
76 * @param filename the file or #NULL for the machine ID file
77 * @param uuid_p out param to return the uuid
78 * @param create_if_not_found whether to create it if not already there
79 * @param error error return
80 * @returns #FALSE if error is set
83 dbus_internal_do_not_use_get_uuid (const char *filename,
85 dbus_bool_t create_if_not_found,
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))
99 if (!_dbus_read_local_machine_uuid (&uuid, create_if_not_found, error))
103 if (!return_uuid(&uuid, uuid_p, error))
109 _DBUS_ASSERT_ERROR_IS_SET (error);
114 * For use by the dbus-uuidgen binary ONLY, do not call this.
115 * We can and will change this function without modifying
116 * the libdbus soname.
118 * @param uuid_p out param to return the uuid
119 * @returns #FALSE if no memory
122 dbus_internal_do_not_use_create_uuid (char **uuid_p)
126 _dbus_generate_uuid (&uuid);
127 return return_uuid (&uuid, uuid_p, NULL);