683ea3c797ecadea64cd2bc611192440088859aa
[platform/upstream/dbus.git] / dbus / dbus-misc.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-misc.c  A few assorted public functions that don't fit elsewhere
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23
24 #include <config.h>
25 #include "dbus-misc.h"
26 #include "dbus-internals.h"
27 #include "dbus-string.h"
28
29 /**
30  * @defgroup DBusMisc Miscellaneous
31  * @ingroup  DBus
32  * @brief Miscellaneous API that doesn't cleanly fit anywhere else
33  *
34  * @{
35  */
36
37 /**
38  * Obtains the machine UUID of the machine this process is running on.
39  *
40  * The returned string must be freed with dbus_free().
41  * 
42  * This UUID is guaranteed to remain the same until the next reboot
43  * (unless the sysadmin foolishly changes it and screws themselves).
44  * It will usually remain the same across reboots also, but hardware
45  * configuration changes or rebuilding the machine could break that.
46  *
47  * The idea is that two processes with the same machine ID should be
48  * able to use shared memory, UNIX domain sockets, process IDs, and other
49  * features of the OS that require both processes to be running
50  * on the same OS kernel instance.
51  *
52  * The machine ID can also be used to create unique per-machine
53  * instances. For example, you could use it in bus names or
54  * X selection names.
55  *
56  * The machine ID is preferred over the machine hostname, because
57  * the hostname is frequently set to "localhost.localdomain" and
58  * may also change at runtime.
59  *
60  * You can get the machine ID of a remote application by invoking the
61  * method GetMachineId from interface org.freedesktop.DBus.Peer.
62  *
63  * If the remote application has the same machine ID as the one
64  * returned by this function, then the remote application is on the
65  * same machine as your application.
66  *
67  * The UUID is not a UUID in the sense of RFC4122; the details
68  * are explained in the D-Bus specification.
69  *
70  * @returns a 32-byte-long hex-encoded UUID string, or #NULL if insufficient memory
71  */
72 char*
73 dbus_get_local_machine_id (void)
74 {
75   DBusString uuid;
76   char *s;
77
78   s = NULL;
79   _dbus_string_init (&uuid);
80   if (!_dbus_get_local_machine_uuid_encoded (&uuid) ||
81       !_dbus_string_steal_data (&uuid, &s))
82     {
83       _dbus_string_free (&uuid);
84       return FALSE;
85     }
86   else
87     {
88       _dbus_string_free (&uuid);
89       return s;
90     }
91
92 }
93
94 /** @} */ /* End of public API */
95
96 #ifdef DBUS_BUILD_TESTS
97
98 #ifndef DOXYGEN_SHOULD_SKIP_THIS
99
100 #include "dbus-test.h"
101 #include <stdlib.h>
102
103
104 dbus_bool_t
105 _dbus_misc_test (void)
106 {
107   
108   return TRUE;
109 }
110
111 #endif /* !DOXYGEN_SHOULD_SKIP_THIS */
112
113 #endif