00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 #include "dbus-uuidgen.h"
00024 #include "dbus-internals.h"
00025 #include "dbus-string.h"
00026 #include "dbus-protocol.h"
00027 
00028 #ifdef DBUS_WIN
00029 #error "dbus-uuidgen should not be needed on Windows"
00030 #endif
00031 
00043 static dbus_bool_t
00044 return_uuid (DBusGUID   *uuid,
00045              char      **uuid_p,
00046              DBusError  *error)
00047 {
00048   if (uuid_p)
00049     {
00050       DBusString encoded;
00051       _dbus_string_init (&encoded);
00052       if (!_dbus_uuid_encode (uuid, &encoded) ||
00053           !_dbus_string_steal_data (&encoded, uuid_p))
00054         {
00055           _DBUS_SET_OOM (error);
00056           _dbus_string_free (&encoded);
00057           return FALSE;
00058         }
00059       _dbus_string_free (&encoded);
00060     }
00061   return TRUE;
00062 }
00063 
00075 dbus_bool_t
00076 dbus_internal_do_not_use_get_uuid (const char *filename,
00077                                    char      **uuid_p,
00078                                    dbus_bool_t create_if_not_found,
00079                                    DBusError  *error)
00080 {
00081   DBusGUID uuid;
00082   
00083   if (filename)
00084     {
00085       DBusString filename_str;
00086       _dbus_string_init_const (&filename_str, filename);
00087       if (!_dbus_read_uuid_file (&filename_str, &uuid, create_if_not_found, error))
00088         goto error;
00089     }
00090   else
00091     {
00092       if (!_dbus_read_local_machine_uuid (&uuid, create_if_not_found, error))
00093         goto error;
00094     }
00095 
00096   if (!return_uuid(&uuid, uuid_p, error))
00097     goto error;
00098 
00099   return TRUE;
00100   
00101  error:
00102   _DBUS_ASSERT_ERROR_IS_SET (error);
00103   return FALSE;
00104 }
00105 
00114 dbus_bool_t
00115 dbus_internal_do_not_use_create_uuid (char      **uuid_p)
00116 {
00117   DBusGUID uuid;
00118 
00119   _dbus_generate_uuid (&uuid);
00120   return return_uuid (&uuid, uuid_p, NULL);
00121 }
00122