From a63867a40b009509bf172ebd3088eb8f2d474322 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 5 Oct 2016 17:51:33 +0200 Subject: [PATCH 1/7] build: use NetworkManager logging domain for device and settings plugins First of all, G_LOG_DOMAIN only matters when using g_log() directly. Inside core, we always want to log via nm-logging. Every call to a g_log() is a bug in the first place (like a failed assertion that logs a g_critical() during g_return_if_fail()). So, for all practic purposes, the logging domain is not used. For nm-logging, the G_LOG_DOMAIN has no effect. Unless we find a proper use of this domain, G_LOG_DOMAIN should not differ from what the rest of core. --- src/devices/adsl/Makefile.am | 2 +- src/devices/bluetooth/Makefile.am | 2 +- src/devices/team/Makefile.am | 2 +- src/devices/wifi/Makefile.am | 2 +- src/devices/wifi/tests/Makefile.am | 2 +- src/devices/wwan/Makefile.am | 2 +- src/settings/plugins/ibft/Makefile.am | 2 +- src/settings/plugins/ibft/tests/Makefile.am | 2 +- src/settings/plugins/ifcfg-rh/Makefile.am | 2 +- src/settings/plugins/ifcfg-rh/tests/Makefile.am | 2 +- src/settings/plugins/ifnet/Makefile.am | 4 ++-- src/settings/plugins/ifnet/tests/Makefile.am | 2 +- src/settings/plugins/ifupdown/Makefile.am | 2 +- src/settings/plugins/ifupdown/tests/Makefile.am | 2 +- src/settings/plugins/keyfile/Makefile.am | 2 +- src/settings/plugins/keyfile/tests/Makefile.am | 2 +- 16 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/devices/adsl/Makefile.am b/src/devices/adsl/Makefile.am index d7f23970b..a1908de4e 100644 --- a/src/devices/adsl/Makefile.am +++ b/src/devices/adsl/Makefile.am @@ -14,7 +14,7 @@ AM_CPPFLAGS = \ -I$(top_builddir)/shared \ -I${top_builddir}/libnm-core \ -I${top_srcdir}/libnm-core \ - -DG_LOG_DOMAIN=\""NetworkManager-adsl"\" \ + -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ $(GUDEV_CFLAGS) diff --git a/src/devices/bluetooth/Makefile.am b/src/devices/bluetooth/Makefile.am index 7ac7bff0e..951807aa4 100644 --- a/src/devices/bluetooth/Makefile.am +++ b/src/devices/bluetooth/Makefile.am @@ -16,7 +16,7 @@ AM_CPPFLAGS = \ -I$(top_builddir)/shared \ -I${top_builddir}/libnm-core \ -I${top_srcdir}/libnm-core \ - -DG_LOG_DOMAIN=\""NetworkManager-bluetooth"\" \ + -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ $(GLIB_CFLAGS) diff --git a/src/devices/team/Makefile.am b/src/devices/team/Makefile.am index f2ad28d1c..da9d5b2e7 100644 --- a/src/devices/team/Makefile.am +++ b/src/devices/team/Makefile.am @@ -15,7 +15,7 @@ AM_CPPFLAGS = \ -I$(top_builddir)/shared \ -I${top_builddir}/libnm-core \ -I${top_srcdir}/libnm-core \ - -DG_LOG_DOMAIN=\""NetworkManager-team"\" \ + -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ $(GLIB_CFLAGS) diff --git a/src/devices/wifi/Makefile.am b/src/devices/wifi/Makefile.am index 04a9cca09..121a874f2 100644 --- a/src/devices/wifi/Makefile.am +++ b/src/devices/wifi/Makefile.am @@ -18,7 +18,7 @@ AM_CPPFLAGS = \ -I$(top_builddir)/shared \ -I${top_builddir}/libnm-core \ -I${top_srcdir}/libnm-core \ - -DG_LOG_DOMAIN=\""NetworkManager-wifi"\" \ + -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ $(GLIB_CFLAGS) diff --git a/src/devices/wifi/tests/Makefile.am b/src/devices/wifi/tests/Makefile.am index 80f552fb9..4ad66261b 100644 --- a/src/devices/wifi/tests/Makefile.am +++ b/src/devices/wifi/tests/Makefile.am @@ -8,7 +8,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src \ -I$(top_srcdir)/src/devices/wifi \ -I$(top_builddir)/src \ - -DG_LOG_DOMAIN=\""NetworkManager-wifi"\" \ + -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ $(GLIB_CFLAGS) diff --git a/src/devices/wwan/Makefile.am b/src/devices/wwan/Makefile.am index 845951d14..7f7e6e8b4 100644 --- a/src/devices/wwan/Makefile.am +++ b/src/devices/wwan/Makefile.am @@ -15,7 +15,7 @@ AM_CPPFLAGS = \ -I$(top_builddir)/shared \ -I${top_srcdir}/libnm-core \ -I${top_builddir}/libnm-core \ - -DG_LOG_DOMAIN=\""NetworkManager-wwan"\" \ + -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ $(GLIB_CFLAGS) \ $(LIBSYSTEMD_CFLAGS) \ diff --git a/src/settings/plugins/ibft/Makefile.am b/src/settings/plugins/ibft/Makefile.am index d19f36f2d..7a0957f80 100644 --- a/src/settings/plugins/ibft/Makefile.am +++ b/src/settings/plugins/ibft/Makefile.am @@ -20,7 +20,7 @@ AM_CPPFLAGS = \ -I$(top_builddir)/libnm-core \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ $(GLIB_CFLAGS) \ - -DG_LOG_DOMAIN=\""NetworkManager-ibft"\" \ + -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DSYSCONFDIR=\"$(sysconfdir)\" \ -DSBINDIR=\"$(sbindir)\" diff --git a/src/settings/plugins/ibft/tests/Makefile.am b/src/settings/plugins/ibft/tests/Makefile.am index 15710f27e..2c8df4209 100644 --- a/src/settings/plugins/ibft/tests/Makefile.am +++ b/src/settings/plugins/ibft/tests/Makefile.am @@ -15,7 +15,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/platform \ -I$(top_srcdir)/src/settings \ -I$(srcdir)/../ \ - -DG_LOG_DOMAIN=\""NetworkManager-ibft"\" \ + -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DTEST_IBFT_DIR=\"$(abs_srcdir)\" \ -DTEST_SCRATCH_DIR=\"$(abs_builddir)/\" diff --git a/src/settings/plugins/ifcfg-rh/Makefile.am b/src/settings/plugins/ifcfg-rh/Makefile.am index d2899a26a..2792d68c6 100644 --- a/src/settings/plugins/ifcfg-rh/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/Makefile.am @@ -50,7 +50,7 @@ AM_CPPFLAGS = \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ $(GLIB_CFLAGS) \ $(NSS_CFLAGS) \ - -DG_LOG_DOMAIN=\""NetworkManager-ifcfg-rh"\" \ + -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DSYSCONFDIR=\"$(sysconfdir)\" \ -DSBINDIR=\"$(sbindir)\" diff --git a/src/settings/plugins/ifcfg-rh/tests/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/Makefile.am index 4a28a81a2..134191c5d 100644 --- a/src/settings/plugins/ifcfg-rh/tests/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/tests/Makefile.am @@ -17,7 +17,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/platform \ -I$(top_srcdir)/src/settings \ -I$(srcdir)/../ \ - -DG_LOG_DOMAIN=\""NetworkManager-ifcfg-rh"\" \ + -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DTEST_IFCFG_DIR=\"$(abs_srcdir)\" \ -DTEST_SCRATCH_DIR=\"$(abs_builddir)/\" \ diff --git a/src/settings/plugins/ifnet/Makefile.am b/src/settings/plugins/ifnet/Makefile.am index 68e80356e..0d90aad34 100644 --- a/src/settings/plugins/ifnet/Makefile.am +++ b/src/settings/plugins/ifnet/Makefile.am @@ -10,7 +10,7 @@ AM_CPPFLAGS = \ -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ - -DG_LOG_DOMAIN=\""NetworkManager-ifnet"\" \ + -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ $(GLIB_CFLAGS) \ -DSYSCONFDIR=\"$(sysconfdir)\" @@ -24,7 +24,7 @@ libnm_settings_plugin_ifnet_la_SOURCES = \ nm-ifnet-connection.c \ nm-ifnet-connection.h \ plugin.c \ - plugin.h + plugin.h libnm_settings_plugin_ifnet_la_LDFLAGS = -module -avoid-version diff --git a/src/settings/plugins/ifnet/tests/Makefile.am b/src/settings/plugins/ifnet/tests/Makefile.am index 0cdcb8154..bdecfa10e 100644 --- a/src/settings/plugins/ifnet/tests/Makefile.am +++ b/src/settings/plugins/ifnet/tests/Makefile.am @@ -13,7 +13,7 @@ AM_CPPFLAGS= \ -I$(top_srcdir)/src \ -I$(top_srcdir)/src/settings \ -I$(top_srcdir)/src/platform \ - -DG_LOG_DOMAIN=\""NetworkManager-ifnet"\" \ + -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ $(CHECK_CFLAGS) \ $(GLIB_CFLAGS) \ diff --git a/src/settings/plugins/ifupdown/Makefile.am b/src/settings/plugins/ifupdown/Makefile.am index 94b0be54e..dbea6be61 100644 --- a/src/settings/plugins/ifupdown/Makefile.am +++ b/src/settings/plugins/ifupdown/Makefile.am @@ -9,7 +9,7 @@ AM_CPPFLAGS = \ -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ - -DG_LOG_DOMAIN=\""NetworkManager-ifupdown"\" \ + -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ $(GLIB_CFLAGS) \ $(GUDEV_CFLAGS) \ diff --git a/src/settings/plugins/ifupdown/tests/Makefile.am b/src/settings/plugins/ifupdown/tests/Makefile.am index 1dab1ce79..6a4dcdf80 100644 --- a/src/settings/plugins/ifupdown/tests/Makefile.am +++ b/src/settings/plugins/ifupdown/tests/Makefile.am @@ -10,7 +10,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src \ -I$(top_srcdir)/src/settings \ -I$(srcdir)/../ \ - -DG_LOG_DOMAIN=\""NetworkManager-ifupdown"\" \ + -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ $(GLIB_CFLAGS) \ -DTEST_ENI_DIR=\"$(abs_srcdir)\" diff --git a/src/settings/plugins/keyfile/Makefile.am b/src/settings/plugins/keyfile/Makefile.am index 08119dae9..42c618898 100644 --- a/src/settings/plugins/keyfile/Makefile.am +++ b/src/settings/plugins/keyfile/Makefile.am @@ -9,7 +9,7 @@ AM_CPPFLAGS = \ -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ - -DG_LOG_DOMAIN=\""NetworkManager-keyfile"\" \ + -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ $(GLIB_CFLAGS) \ -DNMCONFDIR=\"$(nmconfdir)\" diff --git a/src/settings/plugins/keyfile/tests/Makefile.am b/src/settings/plugins/keyfile/tests/Makefile.am index fd08b896e..a697787fe 100644 --- a/src/settings/plugins/keyfile/tests/Makefile.am +++ b/src/settings/plugins/keyfile/tests/Makefile.am @@ -14,7 +14,7 @@ AM_CPPFLAGS = \ -I$(srcdir)/../ \ $(GLIB_CFLAGS) \ $(CODE_COVERAGE_CFLAGS) \ - -DG_LOG_DOMAIN=\""NetworkManager-keyfile"\" \ + -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DTEST_KEYFILES_DIR=\"$(abs_srcdir)/keyfiles\" \ -DTEST_SCRATCH_DIR=\"$(abs_builddir)/keyfiles\" \ From 93c8381965890eb388a5d576cf36f12209b09471 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 5 Oct 2016 17:44:58 +0200 Subject: [PATCH 2/7] keyfile: rename files Setting plugins should have their own name prefix (nms) and keyfile should have as prefix "nms-kf". As a first step, rename the files. --- src/Makefile.am | 20 +++++++++---------- src/settings/nm-settings.c | 2 +- src/settings/plugins/keyfile/Makefile.am | 20 +++++++++---------- ...-connection.c => nms-keyfile-connection.c} | 10 ++++++---- ...-connection.h => nms-keyfile-connection.h} | 0 .../{plugin.c => nms-keyfile-plugin.c} | 9 +++++---- .../{plugin.h => nms-keyfile-plugin.h} | 0 .../{reader.c => nms-keyfile-reader.c} | 5 +++-- .../{reader.h => nms-keyfile-reader.h} | 0 .../keyfile/{utils.c => nms-keyfile-utils.c} | 3 ++- .../keyfile/{utils.h => nms-keyfile-utils.h} | 0 .../{writer.c => nms-keyfile-writer.c} | 6 ++++-- .../{writer.h => nms-keyfile-writer.h} | 0 .../plugins/keyfile/tests/Makefile.am | 6 +++--- .../plugins/keyfile/tests/test-keyfile.c | 6 +++--- 15 files changed, 47 insertions(+), 40 deletions(-) rename src/settings/plugins/keyfile/{nm-keyfile-connection.c => nms-keyfile-connection.c} (97%) rename src/settings/plugins/keyfile/{nm-keyfile-connection.h => nms-keyfile-connection.h} (100%) rename src/settings/plugins/keyfile/{plugin.c => nms-keyfile-plugin.c} (99%) rename src/settings/plugins/keyfile/{plugin.h => nms-keyfile-plugin.h} (100%) rename src/settings/plugins/keyfile/{reader.c => nms-keyfile-reader.c} (99%) rename src/settings/plugins/keyfile/{reader.h => nms-keyfile-reader.h} (100%) rename src/settings/plugins/keyfile/{utils.c => nms-keyfile-utils.c} (99%) rename src/settings/plugins/keyfile/{utils.h => nms-keyfile-utils.h} (100%) rename src/settings/plugins/keyfile/{writer.c => nms-keyfile-writer.c} (99%) rename src/settings/plugins/keyfile/{writer.h => nms-keyfile-writer.h} (100%) diff --git a/src/Makefile.am b/src/Makefile.am index f5213834d..7d2a37f1b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -384,16 +384,16 @@ libNetworkManager_la_SOURCES = \ settings/nm-settings.c \ settings/nm-settings.h \ \ - settings/plugins/keyfile/nm-keyfile-connection.c \ - settings/plugins/keyfile/nm-keyfile-connection.h \ - settings/plugins/keyfile/plugin.c \ - settings/plugins/keyfile/plugin.h \ - settings/plugins/keyfile/reader.c \ - settings/plugins/keyfile/reader.h \ - settings/plugins/keyfile/utils.c \ - settings/plugins/keyfile/utils.h \ - settings/plugins/keyfile/writer.c \ - settings/plugins/keyfile/writer.h \ + settings/plugins/keyfile/nms-keyfile-connection.c \ + settings/plugins/keyfile/nms-keyfile-connection.h \ + settings/plugins/keyfile/nms-keyfile-plugin.c \ + settings/plugins/keyfile/nms-keyfile-plugin.h \ + settings/plugins/keyfile/nms-keyfile-reader.c \ + settings/plugins/keyfile/nms-keyfile-reader.h \ + settings/plugins/keyfile/nms-keyfile-utils.c \ + settings/plugins/keyfile/nms-keyfile-utils.h \ + settings/plugins/keyfile/nms-keyfile-writer.c \ + settings/plugins/keyfile/nms-keyfile-writer.h \ \ supplicant-manager/nm-supplicant-config.c \ supplicant-manager/nm-supplicant-config.h \ diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index aafb54375..229e25244 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -69,7 +69,7 @@ #include "nm-auth-utils.h" #include "nm-auth-subject.h" #include "nm-session-monitor.h" -#include "plugins/keyfile/plugin.h" +#include "plugins/keyfile/nms-keyfile-plugin.h" #include "nm-agent-manager.h" #include "nm-config.h" #include "nm-audit-manager.h" diff --git a/src/settings/plugins/keyfile/Makefile.am b/src/settings/plugins/keyfile/Makefile.am index 42c618898..d2a51cf35 100644 --- a/src/settings/plugins/keyfile/Makefile.am +++ b/src/settings/plugins/keyfile/Makefile.am @@ -21,22 +21,22 @@ noinst_LTLIBRARIES = \ ##### I/O library for testcases ##### libkeyfile_io_la_SOURCES = \ - reader.c \ - reader.h \ - writer.c \ - writer.h \ - utils.c \ - utils.h + nms-keyfile-reader.c \ + nms-keyfile-reader.h \ + nms-keyfile-writer.c \ + nms-keyfile-writer.h \ + nms-keyfile-utils.c \ + nms-keyfile-utils.h libkeyfile_io_la_LIBADD = $(GLIB_LIBS) ##################################### libnm_settings_plugin_keyfile_la_SOURCES = \ - nm-keyfile-connection.c \ - nm-keyfile-connection.h \ - plugin.c \ - plugin.h + nms-keyfile-connection.c \ + nms-keyfile-connection.h \ + nms-keyfile-plugin.c \ + nms-keyfile-plugin.h libnm_settings_plugin_keyfile_la_LIBADD = \ libkeyfile-io.la diff --git a/src/settings/plugins/keyfile/nm-keyfile-connection.c b/src/settings/plugins/keyfile/nms-keyfile-connection.c similarity index 97% rename from src/settings/plugins/keyfile/nm-keyfile-connection.c rename to src/settings/plugins/keyfile/nms-keyfile-connection.c index 97a5ee4c5..1cda3c0ed 100644 --- a/src/settings/plugins/keyfile/nm-keyfile-connection.c +++ b/src/settings/plugins/keyfile/nms-keyfile-connection.c @@ -21,6 +21,8 @@ #include "nm-default.h" +#include "nms-keyfile-connection.h" + #include #include @@ -29,10 +31,10 @@ #include "nm-utils.h" #include "nm-settings-plugin.h" -#include "nm-keyfile-connection.h" -#include "reader.h" -#include "writer.h" -#include "utils.h" + +#include "nms-keyfile-reader.h" +#include "nms-keyfile-writer.h" +#include "nms-keyfile-utils.h" G_DEFINE_TYPE (NMKeyfileConnection, nm_keyfile_connection, NM_TYPE_SETTINGS_CONNECTION) diff --git a/src/settings/plugins/keyfile/nm-keyfile-connection.h b/src/settings/plugins/keyfile/nms-keyfile-connection.h similarity index 100% rename from src/settings/plugins/keyfile/nm-keyfile-connection.h rename to src/settings/plugins/keyfile/nms-keyfile-connection.h diff --git a/src/settings/plugins/keyfile/plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c similarity index 99% rename from src/settings/plugins/keyfile/plugin.c rename to src/settings/plugins/keyfile/nms-keyfile-plugin.c index 40014128b..94c7e81e9 100644 --- a/src/settings/plugins/keyfile/plugin.c +++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.c @@ -21,7 +21,7 @@ #include "nm-default.h" -#include "plugin.h" +#include "nms-keyfile-plugin.h" #include #include @@ -38,9 +38,10 @@ #include "nm-core-internal.h" #include "nm-settings-plugin.h" -#include "nm-keyfile-connection.h" -#include "writer.h" -#include "utils.h" + +#include "nms-keyfile-connection.h" +#include "nms-keyfile-writer.h" +#include "nms-keyfile-utils.h" /*****************************************************************************/ diff --git a/src/settings/plugins/keyfile/plugin.h b/src/settings/plugins/keyfile/nms-keyfile-plugin.h similarity index 100% rename from src/settings/plugins/keyfile/plugin.h rename to src/settings/plugins/keyfile/nms-keyfile-plugin.h diff --git a/src/settings/plugins/keyfile/reader.c b/src/settings/plugins/keyfile/nms-keyfile-reader.c similarity index 99% rename from src/settings/plugins/keyfile/reader.c rename to src/settings/plugins/keyfile/nms-keyfile-reader.c index 264b26a43..037315730 100644 --- a/src/settings/plugins/keyfile/reader.c +++ b/src/settings/plugins/keyfile/nms-keyfile-reader.c @@ -20,12 +20,13 @@ #include "nm-default.h" +#include "nms-keyfile-reader.h" + #include #include -#include "reader.h" - #include "nm-keyfile-internal.h" + #include "NetworkManagerUtils.h" static const char * diff --git a/src/settings/plugins/keyfile/reader.h b/src/settings/plugins/keyfile/nms-keyfile-reader.h similarity index 100% rename from src/settings/plugins/keyfile/reader.h rename to src/settings/plugins/keyfile/nms-keyfile-reader.h diff --git a/src/settings/plugins/keyfile/utils.c b/src/settings/plugins/keyfile/nms-keyfile-utils.c similarity index 99% rename from src/settings/plugins/keyfile/utils.c rename to src/settings/plugins/keyfile/nms-keyfile-utils.c index b5c306e4c..8b955f53f 100644 --- a/src/settings/plugins/keyfile/utils.c +++ b/src/settings/plugins/keyfile/nms-keyfile-utils.c @@ -20,10 +20,11 @@ #include "nm-default.h" +#include "nms-keyfile-utils.h" + #include #include -#include "utils.h" #include "nm-setting-wired.h" #include "nm-setting-wireless.h" #include "nm-setting-wireless-security.h" diff --git a/src/settings/plugins/keyfile/utils.h b/src/settings/plugins/keyfile/nms-keyfile-utils.h similarity index 100% rename from src/settings/plugins/keyfile/utils.h rename to src/settings/plugins/keyfile/nms-keyfile-utils.h diff --git a/src/settings/plugins/keyfile/writer.c b/src/settings/plugins/keyfile/nms-keyfile-writer.c similarity index 99% rename from src/settings/plugins/keyfile/writer.c rename to src/settings/plugins/keyfile/nms-keyfile-writer.c index c8eb88009..ec472aaa4 100644 --- a/src/settings/plugins/keyfile/writer.c +++ b/src/settings/plugins/keyfile/nms-keyfile-writer.c @@ -21,16 +21,18 @@ #include "nm-default.h" +#include "nms-keyfile-writer.h" + #include #include #include #include #include -#include "writer.h" -#include "utils.h" #include "nm-keyfile-internal.h" +#include "nms-keyfile-utils.h" + typedef struct { const char *keyfile_dir; } WriteInfo; diff --git a/src/settings/plugins/keyfile/writer.h b/src/settings/plugins/keyfile/nms-keyfile-writer.h similarity index 100% rename from src/settings/plugins/keyfile/writer.h rename to src/settings/plugins/keyfile/nms-keyfile-writer.h diff --git a/src/settings/plugins/keyfile/tests/Makefile.am b/src/settings/plugins/keyfile/tests/Makefile.am index a697787fe..05689559e 100644 --- a/src/settings/plugins/keyfile/tests/Makefile.am +++ b/src/settings/plugins/keyfile/tests/Makefile.am @@ -24,9 +24,9 @@ noinst_PROGRAMS = test-keyfile test_keyfile_SOURCES = \ test-keyfile.c \ - ../reader.c \ - ../writer.c \ - ../utils.c + ../nms-keyfile-reader.c \ + ../nms-keyfile-writer.c \ + ../nms-keyfile-utils.c test_keyfile_LDADD = \ $(top_builddir)/src/libNetworkManager.la \ diff --git a/src/settings/plugins/keyfile/tests/test-keyfile.c b/src/settings/plugins/keyfile/tests/test-keyfile.c index 8c4c79813..4eebf04a9 100644 --- a/src/settings/plugins/keyfile/tests/test-keyfile.c +++ b/src/settings/plugins/keyfile/tests/test-keyfile.c @@ -30,9 +30,9 @@ #include "nm-core-internal.h" -#include "reader.h" -#include "writer.h" -#include "utils.h" +#include "nms-keyfile-reader.h" +#include "nms-keyfile-writer.h" +#include "nms-keyfile-utils.h" #include "nm-test-utils-core.h" From 5d80a8a78b6764656dfa03e1c8af17d7f77b6dce Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 5 Oct 2016 18:12:23 +0200 Subject: [PATCH 3/7] keyfile: rename public keyfile functions and names --- src/settings/nm-settings.c | 2 +- .../plugins/keyfile/nms-keyfile-connection.c | 60 ++++---- .../plugins/keyfile/nms-keyfile-connection.h | 30 ++-- .../plugins/keyfile/nms-keyfile-plugin.c | 136 +++++++++--------- .../plugins/keyfile/nms-keyfile-plugin.h | 26 ++-- .../plugins/keyfile/nms-keyfile-reader.c | 2 +- .../plugins/keyfile/nms-keyfile-reader.h | 8 +- .../plugins/keyfile/nms-keyfile-utils.c | 6 +- .../plugins/keyfile/nms-keyfile-utils.h | 29 ++-- .../plugins/keyfile/nms-keyfile-writer.c | 28 ++-- .../plugins/keyfile/nms-keyfile-writer.h | 26 ++-- .../plugins/keyfile/tests/test-keyfile.c | 68 ++++----- 12 files changed, 210 insertions(+), 211 deletions(-) diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index 229e25244..6e52b2db3 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -800,7 +800,7 @@ add_keyfile_plugin (NMSettings *self) { gs_unref_object GObject *keyfile_plugin = NULL; - keyfile_plugin = nm_settings_keyfile_plugin_new (); + keyfile_plugin = nms_keyfile_plugin_new (); g_assert (keyfile_plugin); if (!add_plugin (self, NM_SETTINGS_PLUGIN (keyfile_plugin))) g_return_if_reached (); diff --git a/src/settings/plugins/keyfile/nms-keyfile-connection.c b/src/settings/plugins/keyfile/nms-keyfile-connection.c index 1cda3c0ed..0a80073a8 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-connection.c +++ b/src/settings/plugins/keyfile/nms-keyfile-connection.c @@ -36,12 +36,12 @@ #include "nms-keyfile-writer.h" #include "nms-keyfile-utils.h" -G_DEFINE_TYPE (NMKeyfileConnection, nm_keyfile_connection, NM_TYPE_SETTINGS_CONNECTION) +G_DEFINE_TYPE (NMSKeyfileConnection, nms_keyfile_connection, NM_TYPE_SETTINGS_CONNECTION) -NMKeyfileConnection * -nm_keyfile_connection_new (NMConnection *source, - const char *full_path, - GError **error) +NMSKeyfileConnection * +nms_keyfile_connection_new (NMConnection *source, + const char *full_path, + GError **error) { GObject *object; NMConnection *tmp; @@ -54,7 +54,7 @@ nm_keyfile_connection_new (NMConnection *source, if (source) tmp = g_object_ref (source); else { - tmp = nm_keyfile_plugin_connection_from_file (full_path, error); + tmp = nms_keyfile_reader_from_file (full_path, error); if (!tmp) return NULL; @@ -70,7 +70,7 @@ nm_keyfile_connection_new (NMConnection *source, update_unsaved = FALSE; } - object = (GObject *) g_object_new (NM_TYPE_KEYFILE_CONNECTION, + object = (GObject *) g_object_new (NMS_TYPE_KEYFILE_CONNECTION, NM_SETTINGS_CONNECTION_FILENAME, full_path, NULL); @@ -85,7 +85,7 @@ nm_keyfile_connection_new (NMConnection *source, } g_object_unref (tmp); - return (NMKeyfileConnection *) object; + return (NMSKeyfileConnection *) object; } static void @@ -97,12 +97,12 @@ commit_changes (NMSettingsConnection *connection, char *path = NULL; GError *error = NULL; - if (!nm_keyfile_plugin_write_connection (NM_CONNECTION (connection), - nm_settings_connection_get_filename (connection), - NM_FLAGS_ALL (commit_reason, NM_SETTINGS_CONNECTION_COMMIT_REASON_USER_ACTION - | NM_SETTINGS_CONNECTION_COMMIT_REASON_ID_CHANGED), - &path, - &error)) { + if (!nms_keyfile_writer_connection (NM_CONNECTION (connection), + nm_settings_connection_get_filename (connection), + NM_FLAGS_ALL (commit_reason, NM_SETTINGS_CONNECTION_COMMIT_REASON_USER_ACTION + | NM_SETTINGS_CONNECTION_COMMIT_REASON_ID_CHANGED), + &path, + &error)) { callback (connection, error, user_data); g_clear_error (&error); return; @@ -115,27 +115,27 @@ commit_changes (NMSettingsConnection *connection, nm_settings_connection_set_filename (connection, path); if (old_path) { - nm_log_info (LOGD_SETTINGS, "keyfile: update "NM_KEYFILE_CONNECTION_LOG_FMT" and rename from \"%s\"", - NM_KEYFILE_CONNECTION_LOG_ARG (connection), + nm_log_info (LOGD_SETTINGS, "keyfile: update "NMS_KEYFILE_CONNECTION_LOG_FMT" and rename from \"%s\"", + NMS_KEYFILE_CONNECTION_LOG_ARG (connection), old_path); } else { - nm_log_info (LOGD_SETTINGS, "keyfile: update "NM_KEYFILE_CONNECTION_LOG_FMT" and persist connection", - NM_KEYFILE_CONNECTION_LOG_ARG (connection)); + nm_log_info (LOGD_SETTINGS, "keyfile: update "NMS_KEYFILE_CONNECTION_LOG_FMT" and persist connection", + NMS_KEYFILE_CONNECTION_LOG_ARG (connection)); } } else { - nm_log_info (LOGD_SETTINGS, "keyfile: update "NM_KEYFILE_CONNECTION_LOG_FMT, - NM_KEYFILE_CONNECTION_LOG_ARG (connection)); + nm_log_info (LOGD_SETTINGS, "keyfile: update "NMS_KEYFILE_CONNECTION_LOG_FMT, + NMS_KEYFILE_CONNECTION_LOG_ARG (connection)); } g_free (path); - NM_SETTINGS_CONNECTION_CLASS (nm_keyfile_connection_parent_class)->commit_changes (connection, - commit_reason, - callback, - user_data); + NM_SETTINGS_CONNECTION_CLASS (nms_keyfile_connection_parent_class)->commit_changes (connection, + commit_reason, + callback, + user_data); } -static void +static void do_delete (NMSettingsConnection *connection, NMSettingsConnectionDeleteFunc callback, gpointer user_data) @@ -146,20 +146,20 @@ do_delete (NMSettingsConnection *connection, if (path) g_unlink (path); - NM_SETTINGS_CONNECTION_CLASS (nm_keyfile_connection_parent_class)->delete (connection, - callback, - user_data); + NM_SETTINGS_CONNECTION_CLASS (nms_keyfile_connection_parent_class)->delete (connection, + callback, + user_data); } /* GObject */ static void -nm_keyfile_connection_init (NMKeyfileConnection *connection) +nms_keyfile_connection_init (NMSKeyfileConnection *connection) { } static void -nm_keyfile_connection_class_init (NMKeyfileConnectionClass *keyfile_connection_class) +nms_keyfile_connection_class_init (NMSKeyfileConnectionClass *keyfile_connection_class) { NMSettingsConnectionClass *settings_class = NM_SETTINGS_CONNECTION_CLASS (keyfile_connection_class); diff --git a/src/settings/plugins/keyfile/nms-keyfile-connection.h b/src/settings/plugins/keyfile/nms-keyfile-connection.h index 31dbe754a..95f503dc1 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-connection.h +++ b/src/settings/plugins/keyfile/nms-keyfile-connection.h @@ -19,30 +19,30 @@ * Copyright (C) 2008 - 2012 Red Hat, Inc. */ -#ifndef __NETWORKMANAGER_KEYFILE_CONNECTION_H__ -#define __NETWORKMANAGER_KEYFILE_CONNECTION_H__ +#ifndef __NMS_KEYFILE_CONNECTION_H__ +#define __NMS_KEYFILE_CONNECTION_H__ #include -#define NM_TYPE_KEYFILE_CONNECTION (nm_keyfile_connection_get_type ()) -#define NM_KEYFILE_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_KEYFILE_CONNECTION, NMKeyfileConnection)) -#define NM_KEYFILE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_KEYFILE_CONNECTION, NMKeyfileConnectionClass)) -#define NM_IS_KEYFILE_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_KEYFILE_CONNECTION)) -#define NM_IS_KEYFILE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_KEYFILE_CONNECTION)) -#define NM_KEYFILE_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_KEYFILE_CONNECTION, NMKeyfileConnectionClass)) +#define NMS_TYPE_KEYFILE_CONNECTION (nms_keyfile_connection_get_type ()) +#define NMS_KEYFILE_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMS_TYPE_KEYFILE_CONNECTION, NMSKeyfileConnection)) +#define NMS_KEYFILE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMS_TYPE_KEYFILE_CONNECTION, NMSKeyfileConnectionClass)) +#define NMS_IS_KEYFILE_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMS_TYPE_KEYFILE_CONNECTION)) +#define NMS_IS_KEYFILE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMS_TYPE_KEYFILE_CONNECTION)) +#define NMS_KEYFILE_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMS_TYPE_KEYFILE_CONNECTION, NMSKeyfileConnectionClass)) typedef struct { NMSettingsConnection parent; -} NMKeyfileConnection; +} NMSKeyfileConnection; typedef struct { NMSettingsConnectionClass parent; -} NMKeyfileConnectionClass; +} NMSKeyfileConnectionClass; -GType nm_keyfile_connection_get_type (void); +GType nms_keyfile_connection_get_type (void); -NMKeyfileConnection *nm_keyfile_connection_new (NMConnection *source, - const char *filename, - GError **error); +NMSKeyfileConnection *nms_keyfile_connection_new (NMConnection *source, + const char *filename, + GError **error); -#endif /* __NETWORKMANAGER_KEYFILE_CONNECTION_H__ */ +#endif /* __NMS_KEYFILE_CONNECTION_H__ */ diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c index 94c7e81e9..e3414bb5a 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-plugin.c +++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.c @@ -53,49 +53,49 @@ typedef struct { gulong monitor_id; NMConfig *config; -} SettingsPluginKeyfilePrivate; +} NMSKeyfilePluginPrivate; -struct _SettingsPluginKeyfile { +struct _NMSKeyfilePlugin { GObject parent; - SettingsPluginKeyfilePrivate _priv; + NMSKeyfilePluginPrivate _priv; }; -struct _SettingsPluginKeyfileClass { +struct _NMSKeyfilePluginClass { GObjectClass parent; }; static void settings_plugin_interface_init (NMSettingsPluginInterface *plugin_iface); -G_DEFINE_TYPE_EXTENDED (SettingsPluginKeyfile, settings_plugin_keyfile, G_TYPE_OBJECT, 0, +G_DEFINE_TYPE_EXTENDED (NMSKeyfilePlugin, nms_keyfile_plugin, G_TYPE_OBJECT, 0, G_IMPLEMENT_INTERFACE (NM_TYPE_SETTINGS_PLUGIN, settings_plugin_interface_init)) -#define SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE(self) _NM_GET_PRIVATE (self, SettingsPluginKeyfile, SETTINGS_IS_PLUGIN_KEYFILE) +#define NMS_KEYFILE_PLUGIN_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMSKeyfilePlugin, NMS_IS_KEYFILE_PLUGIN) /*****************************************************************************/ static void connection_removed_cb (NMSettingsConnection *obj, gpointer user_data) { - g_hash_table_remove (SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ((SettingsPluginKeyfile *) user_data)->connections, + g_hash_table_remove (NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) user_data)->connections, nm_connection_get_uuid (NM_CONNECTION (obj))); } /* Monitoring */ static void -remove_connection (SettingsPluginKeyfile *self, NMKeyfileConnection *connection) +remove_connection (NMSKeyfilePlugin *self, NMSKeyfileConnection *connection) { gboolean removed; g_return_if_fail (connection != NULL); - nm_log_info (LOGD_SETTINGS, "keyfile: removed " NM_KEYFILE_CONNECTION_LOG_FMT, NM_KEYFILE_CONNECTION_LOG_ARG (connection)); + nm_log_info (LOGD_SETTINGS, "keyfile: removed " NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection)); /* Removing from the hash table should drop the last reference */ g_object_ref (connection); g_signal_handlers_disconnect_by_func (connection, connection_removed_cb, self); - removed = g_hash_table_remove (SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (self)->connections, + removed = g_hash_table_remove (NMS_KEYFILE_PLUGIN_GET_PRIVATE (self)->connections, nm_connection_get_uuid (NM_CONNECTION (connection))); nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (connection)); g_object_unref (connection); @@ -103,10 +103,10 @@ remove_connection (SettingsPluginKeyfile *self, NMKeyfileConnection *connection) g_return_if_fail (removed); } -static NMKeyfileConnection * -find_by_path (SettingsPluginKeyfile *self, const char *path) +static NMSKeyfileConnection * +find_by_path (NMSKeyfilePlugin *self, const char *path) { - SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (self); + NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE (self); GHashTableIter iter; NMSettingsConnection *candidate = NULL; @@ -115,7 +115,7 @@ find_by_path (SettingsPluginKeyfile *self, const char *path) g_hash_table_iter_init (&iter, priv->connections); while (g_hash_table_iter_next (&iter, NULL, (gpointer) &candidate)) { if (g_strcmp0 (path, nm_settings_connection_get_filename (candidate)) == 0) - return NM_KEYFILE_CONNECTION (candidate); + return NMS_KEYFILE_CONNECTION (candidate); } return NULL; } @@ -151,18 +151,18 @@ find_by_path (SettingsPluginKeyfile *self, const char *path) * * Returns: the updated connection. * */ -static NMKeyfileConnection * -update_connection (SettingsPluginKeyfile *self, +static NMSKeyfileConnection * +update_connection (NMSKeyfilePlugin *self, NMConnection *source, const char *full_path, - NMKeyfileConnection *connection, + NMSKeyfileConnection *connection, gboolean protect_existing_connection, GHashTable *protected_connections, GError **error) { - SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (self); - NMKeyfileConnection *connection_new; - NMKeyfileConnection *connection_by_uuid; + NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE (self); + NMSKeyfileConnection *connection_new; + NMSKeyfileConnection *connection_by_uuid; GError *local = NULL; const char *uuid; @@ -172,7 +172,7 @@ update_connection (SettingsPluginKeyfile *self, if (full_path) nm_log_dbg (LOGD_SETTINGS, "keyfile: loading from file \"%s\"...", full_path); - connection_new = nm_keyfile_connection_new (source, full_path, &local); + connection_new = nms_keyfile_connection_new (source, full_path, &local); if (!connection_new) { /* Error; remove the connection */ if (source) @@ -195,12 +195,12 @@ update_connection (SettingsPluginKeyfile *self, if ( (protect_existing_connection && connection_by_uuid != NULL) || (protected_connections && g_hash_table_contains (protected_connections, connection))) { - NMKeyfileConnection *conflicting = (protect_existing_connection && connection_by_uuid != NULL) ? connection_by_uuid : connection; + NMSKeyfileConnection *conflicting = (protect_existing_connection && connection_by_uuid != NULL) ? connection_by_uuid : connection; if (source) - nm_log_warn (LOGD_SETTINGS, "keyfile: cannot update protected "NM_KEYFILE_CONNECTION_LOG_FMT" connection due to conflicting UUID %s", NM_KEYFILE_CONNECTION_LOG_ARG (conflicting), uuid); + nm_log_warn (LOGD_SETTINGS, "keyfile: cannot update protected "NMS_KEYFILE_CONNECTION_LOG_FMT" connection due to conflicting UUID %s", NMS_KEYFILE_CONNECTION_LOG_ARG (conflicting), uuid); else - nm_log_warn (LOGD_SETTINGS, "keyfile: cannot load %s due to conflicting UUID for "NM_KEYFILE_CONNECTION_LOG_FMT, full_path, NM_KEYFILE_CONNECTION_LOG_ARG (conflicting)); + nm_log_warn (LOGD_SETTINGS, "keyfile: cannot load %s due to conflicting UUID for "NMS_KEYFILE_CONNECTION_LOG_FMT, full_path, NMS_KEYFILE_CONNECTION_LOG_ARG (conflicting)); g_object_unref (connection_new); g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Cannot update protected connection due to conflicting UUID"); @@ -216,9 +216,9 @@ update_connection (SettingsPluginKeyfile *self, && ( (!connection && protect_existing_connection) || (protected_connections && g_hash_table_contains (protected_connections, connection_by_uuid)))) { if (source) - nm_log_warn (LOGD_SETTINGS, "keyfile: cannot update connection due to conflicting UUID for "NM_KEYFILE_CONNECTION_LOG_FMT, NM_KEYFILE_CONNECTION_LOG_ARG (connection_by_uuid)); + nm_log_warn (LOGD_SETTINGS, "keyfile: cannot update connection due to conflicting UUID for "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_by_uuid)); else - nm_log_warn (LOGD_SETTINGS, "keyfile: cannot load %s due to conflicting UUID for "NM_KEYFILE_CONNECTION_LOG_FMT, full_path, NM_KEYFILE_CONNECTION_LOG_ARG (connection_by_uuid)); + nm_log_warn (LOGD_SETTINGS, "keyfile: cannot load %s due to conflicting UUID for "NMS_KEYFILE_CONNECTION_LOG_FMT, full_path, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_by_uuid)); g_object_unref (connection_new); g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Skip updating protected connection during reload"); @@ -236,17 +236,17 @@ update_connection (SettingsPluginKeyfile *self, NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS)) { /* Nothing to do... except updating the path. */ if (old_path && g_strcmp0 (old_path, full_path) != 0) - nm_log_info (LOGD_SETTINGS, "keyfile: rename \"%s\" to "NM_KEYFILE_CONNECTION_LOG_FMT" without other changes", old_path, NM_KEYFILE_CONNECTION_LOG_ARG (connection_new)); + nm_log_info (LOGD_SETTINGS, "keyfile: rename \"%s\" to "NMS_KEYFILE_CONNECTION_LOG_FMT" without other changes", old_path, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); } else { /* An existing connection changed. */ if (source) - nm_log_info (LOGD_SETTINGS, "keyfile: update "NM_KEYFILE_CONNECTION_LOG_FMT" from %s", NM_KEYFILE_CONNECTION_LOG_ARG (connection_new), NM_KEYFILE_CONNECTION_LOG_PATH (old_path)); + nm_log_info (LOGD_SETTINGS, "keyfile: update "NMS_KEYFILE_CONNECTION_LOG_FMT" from %s", NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new), NMS_KEYFILE_CONNECTION_LOG_PATH (old_path)); else if (!g_strcmp0 (old_path, nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_new)))) - nm_log_info (LOGD_SETTINGS, "keyfile: update "NM_KEYFILE_CONNECTION_LOG_FMT, NM_KEYFILE_CONNECTION_LOG_ARG (connection_new)); + nm_log_info (LOGD_SETTINGS, "keyfile: update "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); else if (old_path) - nm_log_info (LOGD_SETTINGS, "keyfile: rename \"%s\" to "NM_KEYFILE_CONNECTION_LOG_FMT, old_path, NM_KEYFILE_CONNECTION_LOG_ARG (connection_new)); + nm_log_info (LOGD_SETTINGS, "keyfile: rename \"%s\" to "NMS_KEYFILE_CONNECTION_LOG_FMT, old_path, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); else - nm_log_info (LOGD_SETTINGS, "keyfile: update and persist "NM_KEYFILE_CONNECTION_LOG_FMT, NM_KEYFILE_CONNECTION_LOG_ARG (connection_new)); + nm_log_info (LOGD_SETTINGS, "keyfile: update and persist "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (connection_by_uuid), NM_CONNECTION (connection_new), @@ -264,9 +264,9 @@ update_connection (SettingsPluginKeyfile *self, return connection_by_uuid; } else { if (source) - nm_log_info (LOGD_SETTINGS, "keyfile: add connection "NM_KEYFILE_CONNECTION_LOG_FMT, NM_KEYFILE_CONNECTION_LOG_ARG (connection_new)); + nm_log_info (LOGD_SETTINGS, "keyfile: add connection "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); else - nm_log_info (LOGD_SETTINGS, "keyfile: new connection "NM_KEYFILE_CONNECTION_LOG_FMT, NM_KEYFILE_CONNECTION_LOG_ARG (connection_new)); + nm_log_info (LOGD_SETTINGS, "keyfile: new connection "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); g_hash_table_insert (priv->connections, g_strdup (uuid), connection_new); g_signal_connect (connection_new, NM_SETTINGS_CONNECTION_REMOVED, @@ -290,13 +290,13 @@ dir_changed (GFileMonitor *monitor, gpointer user_data) { NMSettingsPlugin *config = NM_SETTINGS_PLUGIN (user_data); - SettingsPluginKeyfile *self = SETTINGS_PLUGIN_KEYFILE (config); - NMKeyfileConnection *connection; + NMSKeyfilePlugin *self = NMS_KEYFILE_PLUGIN (config); + NMSKeyfileConnection *connection; char *full_path; gboolean exists; full_path = g_file_get_path (file); - if (nm_keyfile_plugin_utils_should_ignore_file (full_path)) { + if (nms_keyfile_utils_should_ignore_file (full_path)) { g_free (full_path); return; } @@ -309,12 +309,12 @@ dir_changed (GFileMonitor *monitor, switch (event_type) { case G_FILE_MONITOR_EVENT_DELETED: if (!exists && connection) - remove_connection (SETTINGS_PLUGIN_KEYFILE (config), connection); + remove_connection (NMS_KEYFILE_PLUGIN (config), connection); break; case G_FILE_MONITOR_EVENT_CREATED: case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: if (exists) - update_connection (SETTINGS_PLUGIN_KEYFILE (config), NULL, full_path, connection, TRUE, NULL, NULL); + update_connection (NMS_KEYFILE_PLUGIN (config), NULL, full_path, connection, TRUE, NULL, NULL); break; default: break; @@ -328,7 +328,7 @@ config_changed_cb (NMConfig *config, NMConfigData *config_data, NMConfigChangeFlags changes, NMConfigData *old_data, - SettingsPluginKeyfile *self) + NMSKeyfilePlugin *self) { gs_free char *old_value = NULL, *new_value = NULL; @@ -342,12 +342,12 @@ config_changed_cb (NMConfig *config, static void setup_monitoring (NMSettingsPlugin *config) { - SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ((SettingsPluginKeyfile *) config); + NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) config); GFile *file; GFileMonitor *monitor; if (nm_config_get_monitor_connection_files (nm_config_get ())) { - file = g_file_new_for_path (nm_keyfile_plugin_get_path ()); + file = g_file_new_for_path (nms_keyfile_utils_get_path ()); monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL); g_object_unref (file); @@ -367,7 +367,7 @@ static GHashTable * _paths_from_connections (GHashTable *connections) { GHashTableIter iter; - NMKeyfileConnection *connection; + NMSKeyfileConnection *connection; GHashTable *paths = g_hash_table_new (g_str_hash, g_str_equal); g_hash_table_iter_init (&iter, connections); @@ -403,23 +403,23 @@ _sort_paths (const char **f1, const char **f2, GHashTable *paths) static void read_connections (NMSettingsPlugin *config) { - SettingsPluginKeyfile *self = SETTINGS_PLUGIN_KEYFILE (config); - SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (self); + NMSKeyfilePlugin *self = NMS_KEYFILE_PLUGIN (config); + NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE (self); GDir *dir; GError *error = NULL; const char *item; GHashTable *alive_connections; GHashTableIter iter; - NMKeyfileConnection *connection; + NMSKeyfileConnection *connection; GPtrArray *dead_connections = NULL; guint i; GPtrArray *filenames; GHashTable *paths; - dir = g_dir_open (nm_keyfile_plugin_get_path (), 0, &error); + dir = g_dir_open (nms_keyfile_utils_get_path (), 0, &error); if (!dir) { nm_log_warn (LOGD_SETTINGS, "keyfile: cannot read directory '%s': %s", - nm_keyfile_plugin_get_path (), + nms_keyfile_utils_get_path (), error->message); g_clear_error (&error); return; @@ -429,9 +429,9 @@ read_connections (NMSettingsPlugin *config) filenames = g_ptr_array_new_with_free_func (g_free); while ((item = g_dir_read_name (dir))) { - if (nm_keyfile_plugin_utils_should_ignore_file (item)) + if (nms_keyfile_utils_should_ignore_file (item)) continue; - g_ptr_array_add (filenames, g_build_filename (nm_keyfile_plugin_get_path (), item, NULL)); + g_ptr_array_add (filenames, g_build_filename (nms_keyfile_utils_get_path (), item, NULL)); } g_dir_close (dir); @@ -475,7 +475,7 @@ read_connections (NMSettingsPlugin *config) static GSList * get_connections (NMSettingsPlugin *config) { - SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ((SettingsPluginKeyfile *) config); + NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) config); if (!priv->initialized) { setup_monitoring (config); @@ -489,16 +489,16 @@ static gboolean load_connection (NMSettingsPlugin *config, const char *filename) { - SettingsPluginKeyfile *self = SETTINGS_PLUGIN_KEYFILE ((SettingsPluginKeyfile *) config); - NMKeyfileConnection *connection; - int dir_len = strlen (nm_keyfile_plugin_get_path ()); + NMSKeyfilePlugin *self = NMS_KEYFILE_PLUGIN ((NMSKeyfilePlugin *) config); + NMSKeyfileConnection *connection; + int dir_len = strlen (nms_keyfile_utils_get_path ()); - if ( strncmp (filename, nm_keyfile_plugin_get_path (), dir_len) != 0 + if ( strncmp (filename, nms_keyfile_utils_get_path (), dir_len) != 0 || filename[dir_len] != '/' || strchr (filename + dir_len + 1, '/') != NULL) return FALSE; - if (nm_keyfile_plugin_utils_should_ignore_file (filename + dir_len + 1)) + if (nms_keyfile_utils_should_ignore_file (filename + dir_len + 1)) return FALSE; connection = update_connection (self, NULL, filename, find_by_path (self, filename), TRUE, NULL, NULL); @@ -518,11 +518,11 @@ add_connection (NMSettingsPlugin *config, gboolean save_to_disk, GError **error) { - SettingsPluginKeyfile *self = SETTINGS_PLUGIN_KEYFILE (config); + NMSKeyfilePlugin *self = NMS_KEYFILE_PLUGIN (config); gs_free char *path = NULL; if (save_to_disk) { - if (!nm_keyfile_plugin_write_connection (connection, NULL, FALSE, &path, error)) + if (!nms_keyfile_writer_connection (connection, NULL, FALSE, &path, error)) return NULL; } return NM_SETTINGS_CONNECTION (update_connection (self, connection, path, NULL, FALSE, NULL, error)); @@ -531,7 +531,7 @@ add_connection (NMSettingsPlugin *config, static GSList * get_unmanaged_specs (NMSettingsPlugin *config) { - SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ((SettingsPluginKeyfile *) config); + NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) config); gs_free char *value = NULL; value = nm_config_data_get_value (nm_config_get_data (priv->config), @@ -549,10 +549,10 @@ get_property (GObject *object, guint prop_id, { switch (prop_id) { case NM_SETTINGS_PLUGIN_PROP_NAME: - g_value_set_string (value, KEYFILE_PLUGIN_NAME); + g_value_set_string (value, NMS_KEYFILE_PLUGIN_NAME); break; case NM_SETTINGS_PLUGIN_PROP_INFO: - g_value_set_string (value, KEYFILE_PLUGIN_INFO); + g_value_set_string (value, NMS_KEYFILE_PLUGIN_INFO); break; case NM_SETTINGS_PLUGIN_PROP_CAPABILITIES: g_value_set_uint (value, NM_SETTINGS_PLUGIN_CAP_MODIFY_CONNECTIONS); @@ -566,9 +566,9 @@ get_property (GObject *object, guint prop_id, /*****************************************************************************/ static void -settings_plugin_keyfile_init (SettingsPluginKeyfile *plugin) +nms_keyfile_plugin_init (NMSKeyfilePlugin *plugin) { - SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (plugin); + NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE (plugin); priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); } @@ -576,7 +576,7 @@ settings_plugin_keyfile_init (SettingsPluginKeyfile *plugin) static void constructed (GObject *object) { - SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ((SettingsPluginKeyfile *) object); + NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) object); priv->config = g_object_ref (nm_config_get ()); if (nm_config_data_has_value (nm_config_get_data_orig (priv->config), @@ -587,15 +587,15 @@ constructed (GObject *object) } GObject * -nm_settings_keyfile_plugin_new (void) +nms_keyfile_plugin_new (void) { - return g_object_new (SETTINGS_TYPE_PLUGIN_KEYFILE, NULL); + return g_object_new (NMS_TYPE_KEYFILE_PLUGIN, NULL); } static void dispose (GObject *object) { - SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ((SettingsPluginKeyfile *) object); + NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) object); if (priv->monitor) { nm_clear_g_signal_handler (priv->monitor, &priv->monitor_id); @@ -614,11 +614,11 @@ dispose (GObject *object) g_clear_object (&priv->config); } - G_OBJECT_CLASS (settings_plugin_keyfile_parent_class)->dispose (object); + G_OBJECT_CLASS (nms_keyfile_plugin_parent_class)->dispose (object); } static void -settings_plugin_keyfile_class_init (SettingsPluginKeyfileClass *req_class) +nms_keyfile_plugin_class_init (NMSKeyfilePluginClass *req_class) { GObjectClass *object_class = G_OBJECT_CLASS (req_class); diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.h b/src/settings/plugins/keyfile/nms-keyfile-plugin.h index 21f41c88d..ba62a88b9 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-plugin.h +++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.h @@ -19,21 +19,21 @@ * Copyright (C) 2008 - 2011 Red Hat, Inc. */ -#ifndef __NMKF_PLUGIN_H__ -#define __NMKF_PLUGIN_H__ +#ifndef __NMS_KEYFILE_PLUGIN_H__ +#define __NMS_KEYFILE_PLUGIN_H__ -#define SETTINGS_TYPE_PLUGIN_KEYFILE (settings_plugin_keyfile_get_type ()) -#define SETTINGS_PLUGIN_KEYFILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SETTINGS_TYPE_PLUGIN_KEYFILE, SettingsPluginKeyfile)) -#define SETTINGS_PLUGIN_KEYFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SETTINGS_TYPE_PLUGIN_KEYFILE, SettingsPluginKeyfileClass)) -#define SETTINGS_IS_PLUGIN_KEYFILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SETTINGS_TYPE_PLUGIN_KEYFILE)) -#define SETTINGS_IS_PLUGIN_KEYFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SETTINGS_TYPE_PLUGIN_KEYFILE)) -#define SETTINGS_PLUGIN_KEYFILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SETTINGS_TYPE_PLUGIN_KEYFILE, SettingsPluginKeyfileClass)) +#define NMS_TYPE_KEYFILE_PLUGIN (nms_keyfile_plugin_get_type ()) +#define NMS_KEYFILE_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMS_TYPE_KEYFILE_PLUGIN, NMSKeyfilePlugin)) +#define NMS_KEYFILE_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMS_TYPE_KEYFILE_PLUGIN, NMSKeyfilePluginClass)) +#define NMS_IS_KEYFILE_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMS_TYPE_KEYFILE_PLUGIN)) +#define NMS_IS_KEYFILE_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMS_TYPE_KEYFILE_PLUGIN)) +#define NMS_KEYFILE_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMS_TYPE_KEYFILE_PLUGIN, NMSKeyfilePluginClass)) -typedef struct _SettingsPluginKeyfile SettingsPluginKeyfile; -typedef struct _SettingsPluginKeyfileClass SettingsPluginKeyfileClass; +typedef struct _NMSKeyfilePlugin NMSKeyfilePlugin; +typedef struct _NMSKeyfilePluginClass NMSKeyfilePluginClass; -GType settings_plugin_keyfile_get_type (void); +GType nms_keyfile_plugin_get_type (void); -GObject *nm_settings_keyfile_plugin_new (void); +GObject *nms_keyfile_plugin_new (void); -#endif /* __NMKF_PLUGIN_H__ */ +#endif /* __NMS_KEYFILE_PLUGIN_H__ */ diff --git a/src/settings/plugins/keyfile/nms-keyfile-reader.c b/src/settings/plugins/keyfile/nms-keyfile-reader.c index 037315730..84bd3fece 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-reader.c +++ b/src/settings/plugins/keyfile/nms-keyfile-reader.c @@ -87,7 +87,7 @@ _handler_read (GKeyFile *keyfile, } NMConnection * -nm_keyfile_plugin_connection_from_file (const char *filename, GError **error) +nms_keyfile_reader_from_file (const char *filename, GError **error) { GKeyFile *key_file; struct stat statbuf; diff --git a/src/settings/plugins/keyfile/nms-keyfile-reader.h b/src/settings/plugins/keyfile/nms-keyfile-reader.h index 7bbc6005c..c52fea31d 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-reader.h +++ b/src/settings/plugins/keyfile/nms-keyfile-reader.h @@ -19,11 +19,11 @@ * Copyright (C) 2008 Red Hat, Inc. */ -#ifndef _KEYFILE_PLUGIN_READER_H -#define _KEYFILE_PLUGIN_READER_H +#ifndef __NMS_KEYFILE_READER_H__ +#define __NMS_KEYFILE_READER_H__ #include -NMConnection *nm_keyfile_plugin_connection_from_file (const char *filename, GError **error); +NMConnection *nms_keyfile_reader_from_file (const char *filename, GError **error); -#endif /* _KEYFILE_PLUGIN_READER_H */ +#endif /* __NMS_KEYFILE_READER_H__ */ diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.c b/src/settings/plugins/keyfile/nms-keyfile-utils.c index 8b955f53f..5b9fd69e6 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-utils.c +++ b/src/settings/plugins/keyfile/nms-keyfile-utils.c @@ -88,7 +88,7 @@ check_suffix (const char *base, const char *tag) #define DER_TAG ".der" gboolean -nm_keyfile_plugin_utils_should_ignore_file (const char *filename) +nms_keyfile_utils_should_ignore_file (const char *filename) { gs_free char *base = NULL; @@ -112,7 +112,7 @@ nm_keyfile_plugin_utils_should_ignore_file (const char *filename) } char * -nm_keyfile_plugin_utils_escape_filename (const char *filename) +nms_keyfile_utils_escape_filename (const char *filename) { GString *str; const char *f = filename; @@ -151,7 +151,7 @@ nm_keyfile_plugin_utils_escape_filename (const char *filename) /*****************************************************************************/ const char * -nm_keyfile_plugin_get_path (void) +nms_keyfile_utils_get_path (void) { static char *path = NULL; diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.h b/src/settings/plugins/keyfile/nms-keyfile-utils.h index 85aa54584..be7d668ac 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-utils.h +++ b/src/settings/plugins/keyfile/nms-keyfile-utils.h @@ -15,28 +15,27 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * (C) Copyright 2010 Red Hat, Inc. + * (C) Copyright 2010-2016 Red Hat, Inc. */ -#ifndef _UTILS_H_ -#define _UTILS_H_ +#ifndef __NMS_KEYFILE_UTILS_H__ +#define __NMS_KEYFILE_UTILS_H__ #include "NetworkManagerUtils.h" -#define KEYFILE_PLUGIN_NAME "keyfile" -#define KEYFILE_PLUGIN_INFO "(c) 2007 - 2015 Red Hat, Inc. To report bugs please use the NetworkManager mailing list." +#define NMS_KEYFILE_PLUGIN_NAME "keyfile" +#define NMS_KEYFILE_PLUGIN_INFO "(c) 2007 - 2016 Red Hat, Inc. To report bugs please use the NetworkManager mailing list." -#define NM_KEYFILE_CONNECTION_LOG_PATH(path) ((path) ?: "in-memory") -#define NM_KEYFILE_CONNECTION_LOG_FMT "%s (%s,\"%s\")" -#define NM_KEYFILE_CONNECTION_LOG_ARG(con) NM_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)) -#define NM_KEYFILE_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)" -#define NM_KEYFILE_CONNECTION_LOG_ARGD(con) NM_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)), (con) +#define NMS_KEYFILE_CONNECTION_LOG_PATH(path) ((path) ?: "in-memory") +#define NMS_KEYFILE_CONNECTION_LOG_FMT "%s (%s,\"%s\")" +#define NMS_KEYFILE_CONNECTION_LOG_ARG(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)) +#define NMS_KEYFILE_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)" +#define NMS_KEYFILE_CONNECTION_LOG_ARGD(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)), (con) -gboolean nm_keyfile_plugin_utils_should_ignore_file (const char *filename); +gboolean nms_keyfile_utils_should_ignore_file (const char *filename); -char *nm_keyfile_plugin_utils_escape_filename (const char *filename); +char *nms_keyfile_utils_escape_filename (const char *filename); -const char *nm_keyfile_plugin_get_path (void); - -#endif /* _UTILS_H_ */ +const char *nms_keyfile_utils_get_path (void); +#endif /* __NMS_KEYFILE_UTILS_H__ */ diff --git a/src/settings/plugins/keyfile/nms-keyfile-writer.c b/src/settings/plugins/keyfile/nms-keyfile-writer.c index ec472aaa4..a9a8122fe 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-writer.c +++ b/src/settings/plugins/keyfile/nms-keyfile-writer.c @@ -264,7 +264,7 @@ _internal_write_connection (NMConnection *connection, if (existing_path != NULL && !force_rename) { path = g_strdup (existing_path); } else { - char *filename_escaped = nm_keyfile_plugin_utils_escape_filename (id); + char *filename_escaped = nms_keyfile_utils_escape_filename (id); path = g_build_filename (keyfile_dir, filename_escaped, NULL); g_free (filename_escaped); @@ -290,7 +290,7 @@ _internal_write_connection (NMConnection *connection, else filename = g_strdup_printf ("%s-%s-%u", id, nm_connection_get_uuid (connection), i); - filename_escaped = nm_keyfile_plugin_utils_escape_filename (filename); + filename_escaped = nms_keyfile_utils_escape_filename (filename); g_free (path); path = g_strdup_printf ("%s/%s", keyfile_dir, filename_escaped); @@ -353,14 +353,14 @@ out: } gboolean -nm_keyfile_plugin_write_connection (NMConnection *connection, - const char *existing_path, - gboolean force_rename, - char **out_path, - GError **error) +nms_keyfile_writer_connection (NMConnection *connection, + const char *existing_path, + gboolean force_rename, + char **out_path, + GError **error) { return _internal_write_connection (connection, - nm_keyfile_plugin_get_path (), + nms_keyfile_utils_get_path (), 0, 0, existing_path, force_rename, @@ -369,12 +369,12 @@ nm_keyfile_plugin_write_connection (NMConnection *connection, } gboolean -nm_keyfile_plugin_write_test_connection (NMConnection *connection, - const char *keyfile_dir, - uid_t owner_uid, - pid_t owner_grp, - char **out_path, - GError **error) +nms_keyfile_writer_test_connection (NMConnection *connection, + const char *keyfile_dir, + uid_t owner_uid, + pid_t owner_grp, + char **out_path, + GError **error) { return _internal_write_connection (connection, keyfile_dir, diff --git a/src/settings/plugins/keyfile/nms-keyfile-writer.h b/src/settings/plugins/keyfile/nms-keyfile-writer.h index 894356518..4f43455d0 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-writer.h +++ b/src/settings/plugins/keyfile/nms-keyfile-writer.h @@ -19,22 +19,22 @@ * Copyright (C) 2008 - 2011 Red Hat, Inc. */ -#ifndef _KEYFILE_PLUGIN_WRITER_H -#define _KEYFILE_PLUGIN_WRITER_H +#ifndef __NMS_KEYFILE_WRITER_H__ +#define __NMS_KEYFILE_WRITER_H__ #include -gboolean nm_keyfile_plugin_write_connection (NMConnection *connection, - const char *existing_path, - gboolean force_rename, +gboolean nms_keyfile_writer_connection (NMConnection *connection, + const char *existing_path, + gboolean force_rename, + char **out_path, + GError **error); + +gboolean nms_keyfile_writer_test_connection (NMConnection *connection, + const char *keyfile_dir, + uid_t owner_uid, + pid_t owner_grp, char **out_path, GError **error); -gboolean nm_keyfile_plugin_write_test_connection (NMConnection *connection, - const char *keyfile_dir, - uid_t owner_uid, - pid_t owner_grp, - char **out_path, - GError **error); - -#endif /* _KEYFILE_PLUGIN_WRITER_H */ +#endif /* __NMS_KEYFILE_WRITER_H__ */ diff --git a/src/settings/plugins/keyfile/tests/test-keyfile.c b/src/settings/plugins/keyfile/tests/test-keyfile.c index 4eebf04a9..d9d70437b 100644 --- a/src/settings/plugins/keyfile/tests/test-keyfile.c +++ b/src/settings/plugins/keyfile/tests/test-keyfile.c @@ -69,7 +69,7 @@ keyfile_read_connection_from_file (const char *filename) g_assert (filename); - connection = nm_keyfile_plugin_connection_from_file (filename, &error); + connection = nms_keyfile_reader_from_file (filename, &error); g_assert_no_error (error); nmtst_assert_connection_verifies_without_normalization (connection); @@ -89,7 +89,7 @@ assert_reread (NMConnection *connection, gboolean normalize_connection, const ch g_assert (NM_IS_CONNECTION (connection)); g_assert (testfile && testfile[0]); - reread = nm_keyfile_plugin_connection_from_file (testfile, p_error); + reread = nms_keyfile_reader_from_file (testfile, p_error); g_assert_no_error (error); g_assert (NM_IS_CONNECTION (reread)); @@ -127,7 +127,7 @@ write_test_connection (NMConnection *connection, char **testfile) owner_uid = geteuid (); owner_grp = getegid (); - success = nm_keyfile_plugin_write_test_connection (connection, TEST_SCRATCH_DIR, owner_uid, owner_grp, testfile, p_error); + success = nms_keyfile_writer_test_connection (connection, TEST_SCRATCH_DIR, owner_uid, owner_grp, testfile, p_error); g_assert_no_error (error); g_assert (success); g_assert (*testfile && (*testfile)[0]); @@ -204,7 +204,7 @@ test_read_valid_wired_connection (void) "*ipv6.routes*semicolon at the end*routes1*"); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_INFO, "*ipv6.route*semicolon at the end*route6*"); - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Wired_Connection", NULL); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Wired_Connection", NULL); g_test_assert_expected_messages (); g_assert (connection); @@ -465,7 +465,7 @@ test_read_ip6_wired_connection (void) gs_free_error GError *error = NULL; gboolean success; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Wired_Connection_IP6", NULL); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Wired_Connection_IP6", NULL); g_assert (connection); success = nm_connection_verify (connection, &error); g_assert_no_error (error); @@ -576,7 +576,7 @@ test_read_wired_mac_case (void) "*ipv4.addresses*semicolon at the end*addresses2*"); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_INFO, "*ipv6.routes*semicolon at the end*routes1*"); - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Wired_Connection_MAC_Case", NULL); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Wired_Connection_MAC_Case", NULL); g_test_assert_expected_messages (); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -608,7 +608,7 @@ test_read_mac_old_format (void) char expected_mac[ETH_ALEN] = { 0x00, 0x11, 0xaa, 0xbb, 0xcc, 0x55 }; char expected_cloned_mac[ETH_ALEN] = { 0x00, 0x16, 0xaa, 0xbb, 0xcc, 0xfe }; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_MAC_Old_Format", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_MAC_Old_Format", &error); g_assert_no_error (error); g_assert (connection); @@ -642,7 +642,7 @@ test_read_mac_ib_old_format (void) 0x77, 0x88, 0x99, 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x90 }; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_MAC_IB_Old_Format", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_MAC_IB_Old_Format", &error); g_assert_no_error (error); g_assert (connection); @@ -671,7 +671,7 @@ test_read_valid_wireless_connection (void) const guint8 expected_bssid[ETH_ALEN] = { 0x00, 0x1a, 0x33, 0x44, 0x99, 0x82 }; gboolean success; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Wireless_Connection", NULL); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Wireless_Connection", NULL); g_assert (connection); success = nm_connection_verify (connection, &error); g_assert_no_error (error); @@ -775,7 +775,7 @@ test_read_string_ssid (void) const char *expected_ssid = "blah blah ssid 1234"; gboolean success; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_String_SSID", NULL); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_String_SSID", NULL); g_assert (connection); success = nm_connection_verify (connection, &error); g_assert_no_error (error); @@ -859,7 +859,7 @@ test_read_intlist_ssid (void) gsize ssid_len; const char *expected_ssid = "blah1234"; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Intlist_SSID", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Intlist_SSID", &error); g_assert_no_error (error); g_assert (connection); @@ -952,7 +952,7 @@ test_read_intlike_ssid (void) gsize ssid_len; const char *expected_ssid = "101"; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Intlike_SSID", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Intlike_SSID", &error); g_assert_no_error (error); g_assert (connection); @@ -983,7 +983,7 @@ test_read_intlike_ssid_2 (void) gsize ssid_len; const char *expected_ssid = "11;12;13;"; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Intlike_SSID_2", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Intlike_SSID_2", &error); g_assert_no_error (error); g_assert (connection); @@ -1132,7 +1132,7 @@ test_read_bt_dun_connection (void) const guint8 expected_bdaddr[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }; gboolean success; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/ATT_Data_Connect_BT", NULL); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/ATT_Data_Connect_BT", NULL); g_assert (connection); success = nm_connection_verify (connection, &error); g_assert_no_error (error); @@ -1235,7 +1235,7 @@ test_read_gsm_connection (void) gs_free_error GError *error = NULL; gboolean success; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/ATT_Data_Connect_Plain", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/ATT_Data_Connect_Plain", &error); g_assert_no_error (error); g_assert (connection); @@ -1340,7 +1340,7 @@ test_read_wired_8021x_tls_blob_connection (void) "* * keyfile: 802-1x.client-cert: certificate or key file '/CASA/dcbw/Desktop/certinfra/client.pem' does not exist*"); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "* * keyfile: 802-1x.private-key: certificate or key file '/CASA/dcbw/Desktop/certinfra/client.pem' does not exist*"); - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Wired_TLS_Blob", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Wired_TLS_Blob", &error); g_assert_no_error (error); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -1399,7 +1399,7 @@ test_read_wired_8021x_tls_bad_path_connection (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*does not exist*"); - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Wired_TLS_Path_Missing", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Wired_TLS_Path_Missing", &error); g_test_assert_expected_messages (); g_assert_no_error (error); g_assert (connection); @@ -1457,7 +1457,7 @@ test_read_wired_8021x_tls_old_connection (void) "* * keyfile: 802-1x.client-cert: certificate or key file '/CASA/dcbw/Desktop/certinfra/client.pem' does not exist*"); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "* * keyfile: 802-1x.private-key: certificate or key file '/CASA/dcbw/Desktop/certinfra/client.pem' does not exist*"); - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Wired_TLS_Old", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Wired_TLS_Old", &error); g_assert_no_error (error); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -1503,7 +1503,7 @@ test_read_wired_8021x_tls_new_connection (void) char *tmp2; gboolean success; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Wired_TLS_New", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Wired_TLS_New", &error); g_assert_no_error (error); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -1645,7 +1645,7 @@ test_write_wired_8021x_tls_connection_path (void) write_test_connection (connection, &testfile); /* Read the connection back in and compare it to the one we just wrote out */ - reread = nm_keyfile_plugin_connection_from_file (testfile, &error); + reread = nms_keyfile_reader_from_file (testfile, &error); if (!reread) { g_assert (error); g_warning ("Failed to re-read test connection: %s", error->message); @@ -1753,7 +1753,7 @@ test_write_wired_8021x_tls_connection_blob (void) g_assert (g_file_test (new_priv_key, G_FILE_TEST_EXISTS)); /* Read the connection back in and compare it to the one we just wrote out */ - reread = nm_keyfile_plugin_connection_from_file (testfile, &error); + reread = nms_keyfile_reader_from_file (testfile, &error); if (!reread) { g_assert (error); g_warning ("Failed to re-read test connection: %s", error->message); @@ -1800,7 +1800,7 @@ test_read_infiniband_connection (void) const char *expected_uuid = "4e80a56d-c99f-4aad-a6dd-b449bc398c57"; gboolean success; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_InfiniBand_Connection", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_InfiniBand_Connection", &error); g_assert_no_error (error); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -1886,7 +1886,7 @@ test_read_bridge_main (void) const char *expected_uuid = "8f061643-fe41-4d4c-a8d9-097d26e2ad3a"; gboolean success; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Bridge_Main", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Bridge_Main", &error); g_assert_no_error (error); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -1983,7 +1983,7 @@ test_read_bridge_component (void) const char *expected_uuid = "d7b4f96c-c45e-4298-bef8-f48574f8c1c0"; gboolean success; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Bridge_Component", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Bridge_Component", &error); g_assert_no_error (error); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -2073,7 +2073,7 @@ test_read_new_wired_group_name (void) gs_free_error GError *error = NULL; gboolean success; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_New_Wired_Group_Name", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR"/Test_New_Wired_Group_Name", &error); g_assert_no_error (error); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -2155,7 +2155,7 @@ test_read_new_wireless_group_names (void) gs_free_error GError *error = NULL; gboolean success; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_New_Wireless_Group_Names", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR"/Test_New_Wireless_Group_Names", &error); g_assert_no_error (error); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -2262,7 +2262,7 @@ test_read_missing_vlan_setting (void) gs_free_error GError *error = NULL; gboolean success; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Missing_Vlan_Setting", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR"/Test_Missing_Vlan_Setting", &error); g_assert_no_error (error); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -2284,7 +2284,7 @@ test_read_missing_vlan_flags (void) gs_free_error GError *error = NULL; gboolean success; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Missing_Vlan_Flags", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR"/Test_Missing_Vlan_Flags", &error); g_assert_no_error (error); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -2307,7 +2307,7 @@ test_read_missing_id_uuid (void) gs_free_error GError *error = NULL; gboolean success; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Missing_ID_UUID", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR"/Test_Missing_ID_UUID", &error); g_assert_no_error (error); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -2411,7 +2411,7 @@ test_read_enum_property (void) gs_free_error GError *error = NULL; gboolean success; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Enum_Property", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR"/Test_Enum_Property", &error); g_assert_no_error (error); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -2471,7 +2471,7 @@ test_read_flags_property (void) gs_free_error GError *error = NULL; gboolean success; - connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Flags_Property", &error); + connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR"/Test_Flags_Property", &error); g_assert_no_error (error); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -2530,18 +2530,18 @@ _escape_filename (const char *filename, gboolean would_be_ignored) g_assert (filename && filename[0]); - if (!!would_be_ignored != !!nm_keyfile_plugin_utils_should_ignore_file (filename)) { + if (!!would_be_ignored != !!nms_keyfile_utils_should_ignore_file (filename)) { if (would_be_ignored) g_error ("We expect filename \"%s\" to be ignored, but it isn't", filename); else g_error ("We expect filename \"%s\" not to be ignored, but it is", filename); } - esc = nm_keyfile_plugin_utils_escape_filename (filename); + esc = nms_keyfile_utils_escape_filename (filename); g_assert (esc && esc[0]); g_assert (!strchr (esc, '/')); - if (nm_keyfile_plugin_utils_should_ignore_file (esc)) + if (nms_keyfile_utils_should_ignore_file (esc)) g_error ("Escaping filename \"%s\" yielded \"%s\", but this is ignored", filename, esc); } From 8b1411712a68caed0869c888caba1b0f736ae26b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 5 Oct 2016 18:35:23 +0200 Subject: [PATCH 4/7] keyfile: refactor GObject type creation --- src/settings/nm-settings.c | 3 +- .../plugins/keyfile/nms-keyfile-connection.c | 113 ++++++++++-------- .../plugins/keyfile/nms-keyfile-connection.h | 9 +- .../plugins/keyfile/nms-keyfile-plugin.c | 4 +- .../plugins/keyfile/nms-keyfile-plugin.h | 2 +- .../plugins/keyfile/nms-keyfile-reader.c | 2 + .../plugins/keyfile/nms-keyfile-utils.c | 4 +- .../plugins/keyfile/nms-keyfile-writer.c | 3 + 8 files changed, 75 insertions(+), 65 deletions(-) diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index 6e52b2db3..514c7edb4 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -798,10 +798,9 @@ find_plugin (GSList *list, const char *pname) static void add_keyfile_plugin (NMSettings *self) { - gs_unref_object GObject *keyfile_plugin = NULL; + gs_unref_object NMSKeyfilePlugin *keyfile_plugin = NULL; keyfile_plugin = nms_keyfile_plugin_new (); - g_assert (keyfile_plugin); if (!add_plugin (self, NM_SETTINGS_PLUGIN (keyfile_plugin))) g_return_if_reached (); } diff --git a/src/settings/plugins/keyfile/nms-keyfile-connection.c b/src/settings/plugins/keyfile/nms-keyfile-connection.c index 0a80073a8..948290fa6 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-connection.c +++ b/src/settings/plugins/keyfile/nms-keyfile-connection.c @@ -36,57 +36,19 @@ #include "nms-keyfile-writer.h" #include "nms-keyfile-utils.h" +/*****************************************************************************/ + +struct _NMSKeyfileConnection { + NMSettingsConnection parent; +}; + +struct _NMSKeyfileConnectionClass { + NMSettingsConnectionClass parent; +}; + G_DEFINE_TYPE (NMSKeyfileConnection, nms_keyfile_connection, NM_TYPE_SETTINGS_CONNECTION) -NMSKeyfileConnection * -nms_keyfile_connection_new (NMConnection *source, - const char *full_path, - GError **error) -{ - GObject *object; - NMConnection *tmp; - const char *uuid; - gboolean update_unsaved = TRUE; - - g_assert (source || full_path); - - /* If we're given a connection already, prefer that instead of re-reading */ - if (source) - tmp = g_object_ref (source); - else { - tmp = nms_keyfile_reader_from_file (full_path, error); - if (!tmp) - return NULL; - - uuid = nm_connection_get_uuid (NM_CONNECTION (tmp)); - if (!uuid) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Connection in file %s had no UUID", full_path); - g_object_unref (tmp); - return NULL; - } - - /* If we just read the connection from disk, it's clearly not Unsaved */ - update_unsaved = FALSE; - } - - object = (GObject *) g_object_new (NMS_TYPE_KEYFILE_CONNECTION, - NM_SETTINGS_CONNECTION_FILENAME, full_path, - NULL); - - /* Update our settings with what was read from the file */ - if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object), - tmp, - update_unsaved, - NULL, - error)) { - g_object_unref (object); - object = NULL; - } - - g_object_unref (tmp); - return (NMSKeyfileConnection *) object; -} +/*****************************************************************************/ static void commit_changes (NMSettingsConnection *connection, @@ -151,19 +113,68 @@ do_delete (NMSettingsConnection *connection, user_data); } -/* GObject */ +/*****************************************************************************/ static void nms_keyfile_connection_init (NMSKeyfileConnection *connection) { } +NMSKeyfileConnection * +nms_keyfile_connection_new (NMConnection *source, + const char *full_path, + GError **error) +{ + GObject *object; + NMConnection *tmp; + const char *uuid; + gboolean update_unsaved = TRUE; + + g_assert (source || full_path); + + /* If we're given a connection already, prefer that instead of re-reading */ + if (source) + tmp = g_object_ref (source); + else { + tmp = nms_keyfile_reader_from_file (full_path, error); + if (!tmp) + return NULL; + + uuid = nm_connection_get_uuid (NM_CONNECTION (tmp)); + if (!uuid) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Connection in file %s had no UUID", full_path); + g_object_unref (tmp); + return NULL; + } + + /* If we just read the connection from disk, it's clearly not Unsaved */ + update_unsaved = FALSE; + } + + object = (GObject *) g_object_new (NMS_TYPE_KEYFILE_CONNECTION, + NM_SETTINGS_CONNECTION_FILENAME, full_path, + NULL); + + /* Update our settings with what was read from the file */ + if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object), + tmp, + update_unsaved, + NULL, + error)) { + g_object_unref (object); + object = NULL; + } + + g_object_unref (tmp); + return (NMSKeyfileConnection *) object; +} + static void nms_keyfile_connection_class_init (NMSKeyfileConnectionClass *keyfile_connection_class) { NMSettingsConnectionClass *settings_class = NM_SETTINGS_CONNECTION_CLASS (keyfile_connection_class); - /* Virtual methods */ settings_class->commit_changes = commit_changes; settings_class->delete = do_delete; } diff --git a/src/settings/plugins/keyfile/nms-keyfile-connection.h b/src/settings/plugins/keyfile/nms-keyfile-connection.h index 95f503dc1..3520f4212 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-connection.h +++ b/src/settings/plugins/keyfile/nms-keyfile-connection.h @@ -31,13 +31,8 @@ #define NMS_IS_KEYFILE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMS_TYPE_KEYFILE_CONNECTION)) #define NMS_KEYFILE_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMS_TYPE_KEYFILE_CONNECTION, NMSKeyfileConnectionClass)) -typedef struct { - NMSettingsConnection parent; -} NMSKeyfileConnection; - -typedef struct { - NMSettingsConnectionClass parent; -} NMSKeyfileConnectionClass; +typedef struct _NMSKeyfileConnection NMSKeyfileConnection; +typedef struct _NMSKeyfileConnectionClass NMSKeyfileConnectionClass; GType nms_keyfile_connection_get_type (void); diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c index e3414bb5a..d298b1908 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-plugin.c +++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.c @@ -346,7 +346,7 @@ setup_monitoring (NMSettingsPlugin *config) GFile *file; GFileMonitor *monitor; - if (nm_config_get_monitor_connection_files (nm_config_get ())) { + if (nm_config_get_monitor_connection_files (priv->config)) { file = g_file_new_for_path (nms_keyfile_utils_get_path ()); monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL); g_object_unref (file); @@ -586,7 +586,7 @@ constructed (GObject *object) nm_log_warn (LOGD_SETTINGS, "keyfile: 'hostname' option is deprecated and has no effect"); } -GObject * +NMSKeyfilePlugin * nms_keyfile_plugin_new (void) { return g_object_new (NMS_TYPE_KEYFILE_PLUGIN, NULL); diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.h b/src/settings/plugins/keyfile/nms-keyfile-plugin.h index ba62a88b9..41f47aacd 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-plugin.h +++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.h @@ -34,6 +34,6 @@ typedef struct _NMSKeyfilePluginClass NMSKeyfilePluginClass; GType nms_keyfile_plugin_get_type (void); -GObject *nms_keyfile_plugin_new (void); +NMSKeyfilePlugin *nms_keyfile_plugin_new (void); #endif /* __NMS_KEYFILE_PLUGIN_H__ */ diff --git a/src/settings/plugins/keyfile/nms-keyfile-reader.c b/src/settings/plugins/keyfile/nms-keyfile-reader.c index 84bd3fece..c09e68c03 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-reader.c +++ b/src/settings/plugins/keyfile/nms-keyfile-reader.c @@ -29,6 +29,8 @@ #include "NetworkManagerUtils.h" +/*****************************************************************************/ + static const char * _fmt_warn (const char *group, NMSetting *setting, const char *property_name, const char *message, char **out_message) { diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.c b/src/settings/plugins/keyfile/nms-keyfile-utils.c index 5b9fd69e6..03f06670f 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-utils.c +++ b/src/settings/plugins/keyfile/nms-keyfile-utils.c @@ -32,6 +32,8 @@ #define NM_CONFIG_KEYFILE_PATH_DEFAULT NMCONFDIR "/system-connections" +/*****************************************************************************/ + static const char temp_letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; @@ -166,5 +168,3 @@ nms_keyfile_utils_get_path (void) return path; } -/*****************************************************************************/ - diff --git a/src/settings/plugins/keyfile/nms-keyfile-writer.c b/src/settings/plugins/keyfile/nms-keyfile-writer.c index a9a8122fe..a36a53b90 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-writer.c +++ b/src/settings/plugins/keyfile/nms-keyfile-writer.c @@ -33,10 +33,13 @@ #include "nms-keyfile-utils.h" +/*****************************************************************************/ + typedef struct { const char *keyfile_dir; } WriteInfo; +/*****************************************************************************/ static gboolean write_cert_key_file (const char *path, From 4d194c38339e7851fe54e7f336773370e2dbbeed Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 Oct 2016 14:40:57 +0200 Subject: [PATCH 5/7] keyfile/build: don't build keyfile settings plugin as library We directly include keyfile sources in NetworkManager by compiling them into "libNetworkManager.la". Drop unused libraries from the Makefile. --- src/settings/plugins/keyfile/Makefile.am | 49 +------------------ .../plugins/keyfile/tests/Makefile.am | 5 +- 2 files changed, 2 insertions(+), 52 deletions(-) diff --git a/src/settings/plugins/keyfile/Makefile.am b/src/settings/plugins/keyfile/Makefile.am index d2a51cf35..3c6155b9c 100644 --- a/src/settings/plugins/keyfile/Makefile.am +++ b/src/settings/plugins/keyfile/Makefile.am @@ -1,48 +1 @@ -SUBDIRS = . tests - -@GNOME_CODE_COVERAGE_RULES@ - -AM_CPPFLAGS = \ - -I$(top_srcdir)/src \ - -I$(top_srcdir)/src/settings \ - -I$(top_srcdir)/shared \ - -I$(top_builddir)/shared \ - -I$(top_srcdir)/libnm-core \ - -I$(top_builddir)/libnm-core \ - -DG_LOG_DOMAIN=\""NetworkManager"\" \ - -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ - $(GLIB_CFLAGS) \ - -DNMCONFDIR=\"$(nmconfdir)\" - -noinst_LTLIBRARIES = \ - libkeyfile-io.la \ - libnm-settings-plugin-keyfile.la - -##### I/O library for testcases ##### - -libkeyfile_io_la_SOURCES = \ - nms-keyfile-reader.c \ - nms-keyfile-reader.h \ - nms-keyfile-writer.c \ - nms-keyfile-writer.h \ - nms-keyfile-utils.c \ - nms-keyfile-utils.h - -libkeyfile_io_la_LIBADD = $(GLIB_LIBS) - -##################################### - -libnm_settings_plugin_keyfile_la_SOURCES = \ - nms-keyfile-connection.c \ - nms-keyfile-connection.h \ - nms-keyfile-plugin.c \ - nms-keyfile-plugin.h - -libnm_settings_plugin_keyfile_la_LIBADD = \ - libkeyfile-io.la - -keyfiledir=$(sysconfdir)/NetworkManager/system-connections - -install-data-hook: - $(mkinstalldirs) -m 0755 $(DESTDIR)$(keyfiledir) - +SUBDIRS = tests diff --git a/src/settings/plugins/keyfile/tests/Makefile.am b/src/settings/plugins/keyfile/tests/Makefile.am index 05689559e..d7c48b192 100644 --- a/src/settings/plugins/keyfile/tests/Makefile.am +++ b/src/settings/plugins/keyfile/tests/Makefile.am @@ -23,10 +23,7 @@ AM_CPPFLAGS = \ noinst_PROGRAMS = test-keyfile test_keyfile_SOURCES = \ - test-keyfile.c \ - ../nms-keyfile-reader.c \ - ../nms-keyfile-writer.c \ - ../nms-keyfile-utils.c + test-keyfile.c test_keyfile_LDADD = \ $(top_builddir)/src/libNetworkManager.la \ From 34f65e6ef8e827a02719b187002938111facca69 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 Oct 2016 15:34:18 +0200 Subject: [PATCH 6/7] keyfile: fix calling parent implementation in NMSKeyfilePlugin:constructed() --- src/settings/plugins/keyfile/nms-keyfile-plugin.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c index d298b1908..5a7ae4f6c 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-plugin.c +++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.c @@ -570,6 +570,7 @@ nms_keyfile_plugin_init (NMSKeyfilePlugin *plugin) { NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE (plugin); + priv->config = g_object_ref (nm_config_get ()); priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); } @@ -578,7 +579,8 @@ constructed (GObject *object) { NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) object); - priv->config = g_object_ref (nm_config_get ()); + G_OBJECT_CLASS (nms_keyfile_plugin_parent_class)->constructed (object); + if (nm_config_data_has_value (nm_config_get_data_orig (priv->config), NM_CONFIG_KEYFILE_GROUP_KEYFILE, NM_CONFIG_KEYFILE_KEY_KEYFILE_HOSTNAME, From 1bea5d50488f54f4284a4c0014fd0deef4a94614 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 Oct 2016 15:39:12 +0200 Subject: [PATCH 7/7] keyfile: add logging macros to keyfile plugin --- .../plugins/keyfile/nms-keyfile-plugin.c | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c index 5a7ae4f6c..4c8dfad43 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-plugin.c +++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.c @@ -74,6 +74,16 @@ G_DEFINE_TYPE_EXTENDED (NMSKeyfilePlugin, nms_keyfile_plugin, G_TYPE_OBJECT, 0, /*****************************************************************************/ +#define _NMLOG_PREFIX_NAME "keyfile" +#define _NMLOG_DOMAIN LOGD_SETTINGS +#define _NMLOG(level, ...) \ + nm_log ((level), _NMLOG_DOMAIN, \ + "%s" _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \ + _NMLOG_PREFIX_NAME": " \ + _NM_UTILS_MACRO_REST (__VA_ARGS__)) + +/*****************************************************************************/ + static void connection_removed_cb (NMSettingsConnection *obj, gpointer user_data) { @@ -90,7 +100,7 @@ remove_connection (NMSKeyfilePlugin *self, NMSKeyfileConnection *connection) g_return_if_fail (connection != NULL); - nm_log_info (LOGD_SETTINGS, "keyfile: removed " NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection)); + _LOGI ("removed " NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection)); /* Removing from the hash table should drop the last reference */ g_object_ref (connection); @@ -170,15 +180,15 @@ update_connection (NMSKeyfilePlugin *self, g_return_val_if_fail (full_path || source, NULL); if (full_path) - nm_log_dbg (LOGD_SETTINGS, "keyfile: loading from file \"%s\"...", full_path); + _LOGD ("loading from file \"%s\"...", full_path); connection_new = nms_keyfile_connection_new (source, full_path, &local); if (!connection_new) { /* Error; remove the connection */ if (source) - nm_log_warn (LOGD_SETTINGS, "keyfile: error creating connection %s: %s", nm_connection_get_uuid (source), local->message); + _LOGW ("error creating connection %s: %s", nm_connection_get_uuid (source), local->message); else - nm_log_warn (LOGD_SETTINGS, "keyfile: error loading connection from file %s: %s", full_path, local->message); + _LOGW ("error loading connection from file %s: %s", full_path, local->message); if ( connection && !protect_existing_connection && (!protected_connections || !g_hash_table_contains (protected_connections, connection))) @@ -198,9 +208,9 @@ update_connection (NMSKeyfilePlugin *self, NMSKeyfileConnection *conflicting = (protect_existing_connection && connection_by_uuid != NULL) ? connection_by_uuid : connection; if (source) - nm_log_warn (LOGD_SETTINGS, "keyfile: cannot update protected "NMS_KEYFILE_CONNECTION_LOG_FMT" connection due to conflicting UUID %s", NMS_KEYFILE_CONNECTION_LOG_ARG (conflicting), uuid); + _LOGW ("cannot update protected "NMS_KEYFILE_CONNECTION_LOG_FMT" connection due to conflicting UUID %s", NMS_KEYFILE_CONNECTION_LOG_ARG (conflicting), uuid); else - nm_log_warn (LOGD_SETTINGS, "keyfile: cannot load %s due to conflicting UUID for "NMS_KEYFILE_CONNECTION_LOG_FMT, full_path, NMS_KEYFILE_CONNECTION_LOG_ARG (conflicting)); + _LOGW ("cannot load %s due to conflicting UUID for "NMS_KEYFILE_CONNECTION_LOG_FMT, full_path, NMS_KEYFILE_CONNECTION_LOG_ARG (conflicting)); g_object_unref (connection_new); g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Cannot update protected connection due to conflicting UUID"); @@ -216,9 +226,9 @@ update_connection (NMSKeyfilePlugin *self, && ( (!connection && protect_existing_connection) || (protected_connections && g_hash_table_contains (protected_connections, connection_by_uuid)))) { if (source) - nm_log_warn (LOGD_SETTINGS, "keyfile: cannot update connection due to conflicting UUID for "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_by_uuid)); + _LOGW ("cannot update connection due to conflicting UUID for "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_by_uuid)); else - nm_log_warn (LOGD_SETTINGS, "keyfile: cannot load %s due to conflicting UUID for "NMS_KEYFILE_CONNECTION_LOG_FMT, full_path, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_by_uuid)); + _LOGW ("cannot load %s due to conflicting UUID for "NMS_KEYFILE_CONNECTION_LOG_FMT, full_path, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_by_uuid)); g_object_unref (connection_new); g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Skip updating protected connection during reload"); @@ -236,17 +246,17 @@ update_connection (NMSKeyfilePlugin *self, NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS)) { /* Nothing to do... except updating the path. */ if (old_path && g_strcmp0 (old_path, full_path) != 0) - nm_log_info (LOGD_SETTINGS, "keyfile: rename \"%s\" to "NMS_KEYFILE_CONNECTION_LOG_FMT" without other changes", old_path, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); + _LOGI ("rename \"%s\" to "NMS_KEYFILE_CONNECTION_LOG_FMT" without other changes", old_path, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); } else { /* An existing connection changed. */ if (source) - nm_log_info (LOGD_SETTINGS, "keyfile: update "NMS_KEYFILE_CONNECTION_LOG_FMT" from %s", NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new), NMS_KEYFILE_CONNECTION_LOG_PATH (old_path)); + _LOGI ("update "NMS_KEYFILE_CONNECTION_LOG_FMT" from %s", NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new), NMS_KEYFILE_CONNECTION_LOG_PATH (old_path)); else if (!g_strcmp0 (old_path, nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_new)))) - nm_log_info (LOGD_SETTINGS, "keyfile: update "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); + _LOGI ("update "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); else if (old_path) - nm_log_info (LOGD_SETTINGS, "keyfile: rename \"%s\" to "NMS_KEYFILE_CONNECTION_LOG_FMT, old_path, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); + _LOGI ("rename \"%s\" to "NMS_KEYFILE_CONNECTION_LOG_FMT, old_path, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); else - nm_log_info (LOGD_SETTINGS, "keyfile: update and persist "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); + _LOGI ("update and persist "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (connection_by_uuid), NM_CONNECTION (connection_new), @@ -264,9 +274,9 @@ update_connection (NMSKeyfilePlugin *self, return connection_by_uuid; } else { if (source) - nm_log_info (LOGD_SETTINGS, "keyfile: add connection "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); + _LOGI ("add connection "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); else - nm_log_info (LOGD_SETTINGS, "keyfile: new connection "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); + _LOGI ("new connection "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new)); g_hash_table_insert (priv->connections, g_strdup (uuid), connection_new); g_signal_connect (connection_new, NM_SETTINGS_CONNECTION_REMOVED, @@ -302,7 +312,7 @@ dir_changed (GFileMonitor *monitor, } exists = g_file_test (full_path, G_FILE_TEST_EXISTS); - nm_log_dbg (LOGD_SETTINGS, "dir_changed(%s) = %d; file %s", full_path, event_type, exists ? "exists" : "does not exist"); + _LOGD ("dir_changed(%s) = %d; file %s", full_path, event_type, exists ? "exists" : "does not exist"); connection = find_by_path (self, full_path); @@ -418,7 +428,7 @@ read_connections (NMSettingsPlugin *config) dir = g_dir_open (nms_keyfile_utils_get_path (), 0, &error); if (!dir) { - nm_log_warn (LOGD_SETTINGS, "keyfile: cannot read directory '%s': %s", + _LOGW ("cannot read directory '%s': %s", nms_keyfile_utils_get_path (), error->message); g_clear_error (&error); @@ -585,7 +595,7 @@ constructed (GObject *object) NM_CONFIG_KEYFILE_GROUP_KEYFILE, NM_CONFIG_KEYFILE_KEY_KEYFILE_HOSTNAME, NM_CONFIG_GET_VALUE_RAW)) - nm_log_warn (LOGD_SETTINGS, "keyfile: 'hostname' option is deprecated and has no effect"); + _LOGW ("'hostname' option is deprecated and has no effect"); } NMSKeyfilePlugin *