NetworkManager/src/core/settings/nm-settings-plugin.c
Thomas Haller 615221a99c format: reformat source tree with clang-format 13.0
We use clang-format for automatic formatting of our source files.
Since clang-format is actively maintained software, the actual
formatting depends on the used version of clang-format. That is
unfortunate and painful, but really unavoidable unless clang-format
would be strictly bug-compatible.

So the version that we must use is from the current Fedora release, which
is also tested by our gitlab-ci. Previously, we were using Fedora 34 with
clang-tools-extra-12.0.1-1.fc34.x86_64.

As Fedora 35 comes along, we need to update our formatting as Fedora 35
comes with version "13.0.0~rc1-1.fc35".
An alternative would be to freeze on version 12, but that has different
problems (like, it's cumbersome to rebuild clang 12 on Fedora 35 and it
would be cumbersome for our developers which are on Fedora 35 to use a
clang that they cannot easily install).

The (differently painful) solution is to reformat from time to time, as we
switch to a new Fedora (and thus clang) version.
Usually we would expect that such a reformatting brings minor changes.
But this time, the changes are huge. That is mentioned in the release
notes [1] as

  Makes PointerAligment: Right working with AlignConsecutiveDeclarations. (Fixes https://llvm.org/PR27353)

[1] https://releases.llvm.org/13.0.0/tools/clang/docs/ReleaseNotes.html#clang-format
2021-11-29 09:31:09 +00:00

290 lines
9.3 KiB
C

/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2007 - 2018 Red Hat, Inc.
* Copyright (C) 2008 Novell, Inc.
*/
#include "src/core/nm-default-daemon.h"
#include "nm-settings-plugin.h"
#include "nm-utils.h"
#include "libnm-core-intern/nm-core-internal.h"
#include "nm-settings-connection.h"
/*****************************************************************************/
enum {
UNMANAGED_SPECS_CHANGED,
UNRECOGNIZED_SPECS_CHANGED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = {0};
G_DEFINE_TYPE(NMSettingsPlugin, nm_settings_plugin, G_TYPE_OBJECT)
/*****************************************************************************/
int
nm_settings_plugin_cmp_by_priority(const NMSettingsPlugin *a,
const NMSettingsPlugin *b,
const GSList *plugin_list)
{
nm_assert(NM_IS_SETTINGS_PLUGIN(a));
nm_assert(NM_IS_SETTINGS_PLUGIN(b));
if (a != b) {
int idx_a = g_slist_index((GSList *) plugin_list, a);
int idx_b = g_slist_index((GSList *) plugin_list, b);
/* the plugins must be found in the list. */
nm_assert(idx_a >= 0);
nm_assert(idx_b >= 0);
/* plugins that appear first in @plugin_list have higher priority.
* That means: smaller index -> higher priority. Reverse sort. */
NM_CMP_DIRECT(idx_b, idx_a);
}
return 0;
}
/*****************************************************************************/
GSList *
nm_settings_plugin_get_unmanaged_specs(NMSettingsPlugin *self)
{
NMSettingsPluginClass *klass;
g_return_val_if_fail(NM_IS_SETTINGS_PLUGIN(self), NULL);
klass = NM_SETTINGS_PLUGIN_GET_CLASS(self);
if (!klass->get_unmanaged_specs)
return NULL;
return klass->get_unmanaged_specs(self);
}
GSList *
nm_settings_plugin_get_unrecognized_specs(NMSettingsPlugin *self)
{
NMSettingsPluginClass *klass;
g_return_val_if_fail(NM_IS_SETTINGS_PLUGIN(self), NULL);
klass = NM_SETTINGS_PLUGIN_GET_CLASS(self);
if (!klass->get_unrecognized_specs)
return NULL;
return klass->get_unrecognized_specs(self);
}
void
nm_settings_plugin_reload_connections(NMSettingsPlugin *self,
NMSettingsPluginConnectionLoadCallback callback,
gpointer user_data)
{
NMSettingsPluginClass *klass;
g_return_if_fail(NM_IS_SETTINGS_PLUGIN(self));
g_return_if_fail(callback);
klass = NM_SETTINGS_PLUGIN_GET_CLASS(self);
if (klass->reload_connections)
klass->reload_connections(self, callback, user_data);
}
NMSettingsPluginConnectionLoadEntry *
nm_settings_plugin_create_connection_load_entries(const char *const *filenames, gsize *out_len)
{
NMSettingsPluginConnectionLoadEntry *entries;
gsize len;
gsize i;
len = NM_PTRARRAY_LEN(filenames);
if (len == 0) {
*out_len = 0;
return NULL;
}
entries = g_new(NMSettingsPluginConnectionLoadEntry, len);
for (i = 0; i < len; i++) {
entries[i] = (NMSettingsPluginConnectionLoadEntry){
.filename = filenames[i],
.error = NULL,
.handled = FALSE,
};
}
*out_len = len;
return entries;
}
void
nm_settings_plugin_load_connections(NMSettingsPlugin *self,
NMSettingsPluginConnectionLoadEntry *entries,
gsize n_entries,
NMSettingsPluginConnectionLoadCallback callback,
gpointer user_data)
{
NMSettingsPluginClass *klass;
g_return_if_fail(NM_IS_SETTINGS_PLUGIN(self));
klass = NM_SETTINGS_PLUGIN_GET_CLASS(self);
if (klass->load_connections)
klass->load_connections(self, entries, n_entries, callback, user_data);
}
void
nm_settings_plugin_load_connections_done(NMSettingsPlugin *self)
{
NMSettingsPluginClass *klass;
g_return_if_fail(NM_IS_SETTINGS_PLUGIN(self));
klass = NM_SETTINGS_PLUGIN_GET_CLASS(self);
if (klass->load_connections_done)
klass->load_connections_done(self);
}
gboolean
nm_settings_plugin_add_connection(NMSettingsPlugin *self,
NMConnection *connection,
NMSettingsStorage **out_storage,
NMConnection **out_connection,
GError **error)
{
NMSettingsPluginClass *klass;
g_return_val_if_fail(NM_IS_SETTINGS_PLUGIN(self), FALSE);
g_return_val_if_fail(NM_IS_CONNECTION(connection), FALSE);
#if NM_MORE_ASSERTS > 5
nm_assert(nm_connection_verify(connection, NULL));
#endif
NM_SET_OUT(out_storage, NULL);
NM_SET_OUT(out_connection, NULL);
klass = NM_SETTINGS_PLUGIN_GET_CLASS(self);
if (!klass->add_connection) {
g_set_error_literal(error,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_NOT_SUPPORTED,
"settings plugin does not support adding connections");
return FALSE;
}
return klass->add_connection(self, connection, out_storage, out_connection, error);
}
gboolean
nm_settings_plugin_update_connection(NMSettingsPlugin *self,
NMSettingsStorage *storage,
NMConnection *connection,
NMSettingsStorage **out_storage,
NMConnection **out_connection,
GError **error)
{
NMSettingsPluginClass *klass = NULL;
g_return_val_if_fail(NM_IS_SETTINGS_PLUGIN(self), FALSE);
g_return_val_if_fail(NM_IS_SETTINGS_STORAGE(storage), FALSE);
g_return_val_if_fail(nm_settings_storage_get_plugin(storage) == self, FALSE);
g_return_val_if_fail(NM_IS_CONNECTION(connection), FALSE);
#if NM_MORE_ASSERTS > 5
nm_assert(nm_connection_verify(connection, NULL));
nm_assert(nm_streq(nm_connection_get_uuid(connection), nm_settings_storage_get_uuid(storage)));
#endif
klass = NM_SETTINGS_PLUGIN_GET_CLASS(self);
NM_SET_OUT(out_storage, NULL);
NM_SET_OUT(out_connection, NULL);
if (!klass->update_connection) {
g_set_error(error,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_NOT_SUPPORTED,
"settings plugin does not support modifying connections");
return FALSE;
}
return klass->update_connection(self, storage, connection, out_storage, out_connection, error);
}
gboolean
nm_settings_plugin_delete_connection(NMSettingsPlugin *self,
NMSettingsStorage *storage,
GError **error)
{
NMSettingsPluginClass *klass = NULL;
g_return_val_if_fail(NM_IS_SETTINGS_PLUGIN(self), FALSE);
g_return_val_if_fail(NM_IS_SETTINGS_STORAGE(storage), FALSE);
g_return_val_if_fail(nm_settings_storage_get_plugin(storage) == self, FALSE);
klass = NM_SETTINGS_PLUGIN_GET_CLASS(self);
if (!klass->delete_connection) {
g_set_error(error,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_NOT_SUPPORTED,
"settings plugin does not support deleting connections");
return FALSE;
}
return klass->delete_connection(self, storage, error);
}
/*****************************************************************************/
void
_nm_settings_plugin_emit_signal_unmanaged_specs_changed(NMSettingsPlugin *self)
{
nm_assert(NM_IS_SETTINGS_PLUGIN(self));
g_signal_emit(self, signals[UNMANAGED_SPECS_CHANGED], 0);
}
void
_nm_settings_plugin_emit_signal_unrecognized_specs_changed(NMSettingsPlugin *self)
{
nm_assert(NM_IS_SETTINGS_PLUGIN(self));
g_signal_emit(self, signals[UNRECOGNIZED_SPECS_CHANGED], 0);
}
/*****************************************************************************/
static void
nm_settings_plugin_init(NMSettingsPlugin *self)
{}
static void
nm_settings_plugin_class_init(NMSettingsPluginClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
signals[UNMANAGED_SPECS_CHANGED] = g_signal_new(NM_SETTINGS_PLUGIN_UNMANAGED_SPECS_CHANGED,
G_OBJECT_CLASS_TYPE(object_class),
G_SIGNAL_RUN_FIRST,
0,
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
signals[UNRECOGNIZED_SPECS_CHANGED] =
g_signal_new(NM_SETTINGS_PLUGIN_UNRECOGNIZED_SPECS_CHANGED,
G_OBJECT_CLASS_TYPE(object_class),
G_SIGNAL_RUN_FIRST,
0,
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
}