dbus-misc.c
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-misc.c A few assorted public functions that don't fit elsewhere
*
* Copyright (C) 2006 Red Hat, Inc.
*
* SPDX-License-Identifier: AFL-2.1 OR GPL-2.0-or-later
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <config.h>
#include "dbus-misc.h"
#include "dbus-internals.h"
#include "dbus-string.h"
#include <dbus/dbus-test-tap.h>
char *
dbus_try_get_local_machine_id (DBusError *error)
{
DBusString uuid;
char *s;
s = NULL;
if (!_dbus_string_init (&uuid))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
return NULL;
}
if (!_dbus_get_local_machine_uuid_encoded (&uuid, error))
{
_dbus_string_free (&uuid);
return NULL;
}
if (!_dbus_string_steal_data (&uuid, &s))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
_dbus_string_free (&uuid);
return NULL;
}
else
{
_dbus_string_free (&uuid);
return s;
}
}
char *
dbus_get_local_machine_id (void)
{
DBusError error = DBUS_ERROR_INIT;
char *s;
s = dbus_try_get_local_machine_id (&error);
/* The documentation says dbus_get_local_machine_id() only fails on OOM;
* this can actually also fail if the D-Bus installation is faulty
* (no UUID), but we have no good way to report that. Historically,
* _dbus_get_local_machine_uuid_encoded was responsible for issuing the
* warning; now we do that here. */
if (s == NULL)
{
if (!dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
_dbus_warn_check_failed ("%s", error.message);
dbus_error_free (&error);
return NULL;
}
return s;
}
void
dbus_get_version (int *major_version_p,
int *minor_version_p,
int *micro_version_p)
{
if (major_version_p)
*major_version_p = DBUS_MAJOR_VERSION;
if (minor_version_p)
*minor_version_p = DBUS_MINOR_VERSION;
if (micro_version_p)
*micro_version_p = DBUS_MICRO_VERSION;
}
/* End of public API */
DBUS_ERROR_INIT
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
Definition dbus-errors.h:64
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:304
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:356
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:213
_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:310
_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:983
NULL
#define NULL
A null pointer, defined appropriately for C or C++.
Definition dbus-macros.h:51
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:125
DBUS_MICRO_VERSION
#define DBUS_MICRO_VERSION
The COMPILE TIME micro version of libdbus, that is, the "Z" in "X.Y.Z", as an integer literal.
Definition dbus-arch-deps.h:57
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:76
DBUS_MINOR_VERSION
#define DBUS_MINOR_VERSION
The COMPILE TIME minor version of libdbus, that is, the "Y" in "X.Y.Z", as an integer literal.
Definition dbus-arch-deps.h:56
DBUS_MAJOR_VERSION
#define DBUS_MAJOR_VERSION
The COMPILE TIME major version of libdbus, that is, the "X" in "X.Y.Z", as an integer literal.
Definition dbus-arch-deps.h:55
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:213
DBUS_ERROR_NO_MEMORY
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
Definition dbus-protocol.h:363
_dbus_string_init
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition dbus-string.c:182
_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:686
_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_IN...
Definition dbus-string.c:278
DBusError
Object representing an exception.
Definition dbus-errors.h:51
DBusError::message
const char * message
public error message field
Definition dbus-errors.h:53
DBusString
Definition dbus-string.h:47