dbus-uuidgen.c

00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
00002 /* dbus-uuidgen.c  The guts of the dbus-uuidgen binary live in libdbus, in this file.
00003  *
00004  * Copyright (C) 2006  Red Hat, Inc.
00005  *
00006  * Licensed under the Academic Free License version 2.1
00007  * 
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  * 
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 
00052       if (!_dbus_string_init (&encoded))
00053         {
00054           _DBUS_SET_OOM (error);
00055           return FALSE;
00056         }
00057 
00058       if (!_dbus_uuid_encode (uuid, &encoded) ||
00059           !_dbus_string_steal_data (&encoded, uuid_p))
00060         {
00061           _DBUS_SET_OOM (error);
00062           _dbus_string_free (&encoded);
00063           return FALSE;
00064         }
00065       _dbus_string_free (&encoded);
00066     }
00067   return TRUE;
00068 }
00069 
00081 dbus_bool_t
00082 dbus_internal_do_not_use_get_uuid (const char *filename,
00083                                    char      **uuid_p,
00084                                    dbus_bool_t create_if_not_found,
00085                                    DBusError  *error)
00086 {
00087   DBusGUID uuid;
00088   
00089   if (filename)
00090     {
00091       DBusString filename_str;
00092       _dbus_string_init_const (&filename_str, filename);
00093       if (!_dbus_read_uuid_file (&filename_str, &uuid, create_if_not_found, error))
00094         goto error;
00095     }
00096   else
00097     {
00098       if (!_dbus_read_local_machine_uuid (&uuid, create_if_not_found, error))
00099         goto error;
00100     }
00101 
00102   if (!return_uuid(&uuid, uuid_p, error))
00103     goto error;
00104 
00105   return TRUE;
00106   
00107  error:
00108   _DBUS_ASSERT_ERROR_IS_SET (error);
00109   return FALSE;
00110 }
00111 
00120 dbus_bool_t
00121 dbus_internal_do_not_use_create_uuid (char      **uuid_p)
00122 {
00123   DBusGUID uuid;
00124 
00125   _dbus_generate_uuid (&uuid);
00126   return return_uuid (&uuid, uuid_p, NULL);
00127 }
00128 

Generated on Thu Jan 22 16:37:06 2009 for D-Bus by  doxygen 1.5.1