D-Bus  1.13.16
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  */
23 
24 #include <config.h>
25 #include "dbus-misc.h"
26 #include "dbus-internals.h"
27 #include "dbus-string.h"
28 #include <dbus/dbus-test-tap.h>
29 
73 char *
75 {
76  DBusString uuid;
77  char *s;
78 
79  s = NULL;
80 
81  if (!_dbus_string_init (&uuid))
82  {
84  return NULL;
85  }
86 
87  if (!_dbus_get_local_machine_uuid_encoded (&uuid, error))
88  {
89  _dbus_string_free (&uuid);
90  return NULL;
91  }
92 
93  if (!_dbus_string_steal_data (&uuid, &s))
94  {
96  _dbus_string_free (&uuid);
97  return NULL;
98  }
99  else
100  {
101  _dbus_string_free (&uuid);
102  return s;
103  }
104 
105 }
106 
122 char *
124 {
125  DBusError error = DBUS_ERROR_INIT;
126  char *s;
127 
128  s = dbus_try_get_local_machine_id (&error);
129 
130  /* The documentation says dbus_get_local_machine_id() only fails on OOM;
131  * this can actually also fail if the D-Bus installation is faulty
132  * (no UUID), but we have no good way to report that. Historically,
133  * _dbus_get_local_machine_uuid_encoded was responsible for issuing the
134  * warning; now we do that here. */
135  if (s == NULL)
136  {
138  _dbus_warn_check_failed ("%s", error.message);
139 
140  dbus_error_free (&error);
141  return NULL;
142  }
143 
144  return s;
145 }
146 
210 void
211 dbus_get_version (int *major_version_p,
212  int *minor_version_p,
213  int *micro_version_p)
214 {
215  if (major_version_p)
216  *major_version_p = DBUS_MAJOR_VERSION;
217  if (minor_version_p)
218  *minor_version_p = DBUS_MINOR_VERSION;
219  if (micro_version_p)
220  *micro_version_p = DBUS_MICRO_VERSION;
221 }
222 
223  /* End of public API */
_dbus_string_free
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as #_DBUS_STRING_I...
Definition: dbus-string.c:271
dbus_get_version
void dbus_get_version(int *major_version_p, int *minor_version_p, int *micro_version_p)
Gets the DYNAMICALLY LINKED version of libdbus.
Definition: dbus-misc.c:211
_dbus_string_init
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition: dbus-string.c:182
dbus_error_has_name
dbus_bool_t dbus_error_has_name(const DBusError *error, const char *name)
Checks whether the error is set and has the given name.
Definition: dbus-errors.c:302
DBusString
Definition: dbus-string.h:42
DBUS_ERROR_NO_MEMORY
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
Definition: dbus-protocol.h:361
DBUS_ERROR_INIT
#define DBUS_ERROR_INIT
Definition: dbus-errors.h:62
dbus_error_free
void dbus_error_free(DBusError *error)
Frees an error that's been set (or just initialized), then reinitializes the error as in dbus_error_i...
Definition: dbus-errors.c:211
DBusError
Object representing an exception.
Definition: dbus-errors.h:48
dbus_set_error
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
Definition: dbus-errors.c:354
_dbus_string_steal_data
dbus_bool_t _dbus_string_steal_data(DBusString *str, char **data_return)
Like _dbus_string_get_data(), but removes the gotten data from the original string.
Definition: dbus-string.c:665
dbus_get_local_machine_id
char * dbus_get_local_machine_id(void)
Obtains the machine UUID of the machine this process is running on.
Definition: dbus-misc.c:123
DBusError::message
const char * message
public error message field
Definition: dbus-errors.h:51
_dbus_get_local_machine_uuid_encoded
dbus_bool_t _dbus_get_local_machine_uuid_encoded(DBusString *uuid_str, DBusError *error)
Gets the hex-encoded UUID of the machine this function is executed on.
Definition: dbus-internals.c:951
dbus_try_get_local_machine_id
char * dbus_try_get_local_machine_id(DBusError *error)
Obtains the machine UUID of the machine this process is running on.
Definition: dbus-misc.c:74
_dbus_warn_check_failed
void _dbus_warn_check_failed(const char *format,...)
Prints a "critical" warning to stderr when an assertion fails; differs from _dbus_warn primarily in t...
Definition: dbus-internals.c:270
NULL
#define NULL