• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List

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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021  *
00022  */
00023 #include <config.h>
00024 #include "dbus-uuidgen.h"
00025 #include "dbus-internals.h"
00026 #include "dbus-string.h"
00027 #include "dbus-protocol.h"
00028 
00029 #ifdef DBUS_WIN
00030 #error "dbus-uuidgen should not be needed on Windows"
00031 #endif
00032 
00044 static dbus_bool_t
00045 return_uuid (DBusGUID   *uuid,
00046              char      **uuid_p,
00047              DBusError  *error)
00048 {
00049   if (uuid_p)
00050     {
00051       DBusString encoded;
00052 
00053       if (!_dbus_string_init (&encoded))
00054         {
00055           _DBUS_SET_OOM (error);
00056           return FALSE;
00057         }
00058 
00059       if (!_dbus_uuid_encode (uuid, &encoded) ||
00060           !_dbus_string_steal_data (&encoded, uuid_p))
00061         {
00062           _DBUS_SET_OOM (error);
00063           _dbus_string_free (&encoded);
00064           return FALSE;
00065         }
00066       _dbus_string_free (&encoded);
00067     }
00068   return TRUE;
00069 }
00070 
00082 dbus_bool_t
00083 dbus_internal_do_not_use_get_uuid (const char *filename,
00084                                    char      **uuid_p,
00085                                    dbus_bool_t create_if_not_found,
00086                                    DBusError  *error)
00087 {
00088   DBusGUID uuid;
00089   
00090   if (filename)
00091     {
00092       DBusString filename_str;
00093       _dbus_string_init_const (&filename_str, filename);
00094       if (!_dbus_read_uuid_file (&filename_str, &uuid, create_if_not_found, error))
00095         goto error;
00096     }
00097   else
00098     {
00099       if (!_dbus_read_local_machine_uuid (&uuid, create_if_not_found, error))
00100         goto error;
00101     }
00102 
00103   if (!return_uuid(&uuid, uuid_p, error))
00104     goto error;
00105 
00106   return TRUE;
00107   
00108  error:
00109   _DBUS_ASSERT_ERROR_IS_SET (error);
00110   return FALSE;
00111 }
00112 
00121 dbus_bool_t
00122 dbus_internal_do_not_use_create_uuid (char      **uuid_p)
00123 {
00124   DBusGUID uuid;
00125 
00126   _dbus_generate_uuid (&uuid);
00127   return return_uuid (&uuid, uuid_p, NULL);
00128 }
00129 

Generated on Mon Sep 6 2010 for D-Bus by  doxygen 1.7.1