From 2285838cbbfb28b164bfee04ae789fc59b476c29 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Sat, 28 Feb 2009 07:08:19 -0500 Subject: [PATCH] ifcfg-rh: move reader/writer to separate utility library --- system-settings/plugins/ifcfg-rh/Makefile.am | 34 ++++++++++++++----- system-settings/plugins/ifcfg-rh/common.h | 2 +- system-settings/plugins/ifcfg-rh/errors.c | 35 ++++++++++++++++++++ system-settings/plugins/ifcfg-rh/plugin.c | 11 ------ system-settings/plugins/ifcfg-rh/plugin.h | 2 -- system-settings/plugins/ifcfg-rh/reader.c | 25 ++++++++------ 6 files changed, 76 insertions(+), 33 deletions(-) create mode 100644 system-settings/plugins/ifcfg-rh/errors.c diff --git a/system-settings/plugins/ifcfg-rh/Makefile.am b/system-settings/plugins/ifcfg-rh/Makefile.am index 53eeceb91..08fd51d23 100644 --- a/system-settings/plugins/ifcfg-rh/Makefile.am +++ b/system-settings/plugins/ifcfg-rh/Makefile.am @@ -1,25 +1,40 @@ pkglib_LTLIBRARIES = libnm-settings-plugin-ifcfg-rh.la -libnm_settings_plugin_ifcfg_rh_la_SOURCES = \ +noinst_LTLIBRARIES = libifcfg-rh-io.la + +libifcfg_rh_io_la_SOURCES = \ shvar.c \ shvar.h \ + reader.c \ + reader.h \ + sha1.c \ + sha1.h \ + errors.c \ + common.h + +libifcfg_rh_io_la_CPPFLAGS = \ + $(GLIB_CFLAGS) \ + $(DBUS_CFLAGS) \ + -DG_DISABLE_DEPRECATED \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/libnm-util \ + -DSYSCONFDIR=\"$(sysconfdir)\" + +libifcfg_rh_io_la_LIBADD = $(GLIB_LIBS) + +libnm_settings_plugin_ifcfg_rh_la_SOURCES = \ plugin.c \ plugin.h \ nm-ifcfg-connection.c \ - nm-ifcfg-connection.h \ - reader.c \ - reader.h \ - common.h \ - sha1.c \ - sha1.h + nm-ifcfg-connection.h libnm_settings_plugin_ifcfg_rh_la_CPPFLAGS = \ $(GLIB_CFLAGS) \ $(GMODULE_CFLAGS) \ $(DBUS_CFLAGS) \ -DG_DISABLE_DEPRECATED \ - -I${top_srcdir}/system-settings/src \ + -I$(top_srcdir)/system-settings/src \ -I$(top_srcdir)/include \ -I$(top_srcdir)/libnm-glib \ -I$(top_srcdir)/libnm-util \ @@ -32,7 +47,8 @@ libnm_settings_plugin_ifcfg_rh_la_LIBADD = \ $(GMODULE_LIBS) \ $(top_builddir)/libnm-util/libnm-util.la \ $(top_builddir)/libnm-glib/libnm_glib.la \ - $(top_builddir)/marshallers/libmarshallers.la + $(top_builddir)/marshallers/libmarshallers.la \ + libifcfg-rh-io.la if NO_GIO libnm_settings_plugin_ifcfg_rh_la_LIBADD += \ diff --git a/system-settings/plugins/ifcfg-rh/common.h b/system-settings/plugins/ifcfg-rh/common.h index 812bebcb2..9793662cd 100644 --- a/system-settings/plugins/ifcfg-rh/common.h +++ b/system-settings/plugins/ifcfg-rh/common.h @@ -15,7 +15,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * (C) Copyright 2008 Red Hat, Inc. + * (C) Copyright 2008 - 2009 Red Hat, Inc. */ #ifndef __COMMON_H__ diff --git a/system-settings/plugins/ifcfg-rh/errors.c b/system-settings/plugins/ifcfg-rh/errors.c new file mode 100644 index 000000000..25039104a --- /dev/null +++ b/system-settings/plugins/ifcfg-rh/errors.c @@ -0,0 +1,35 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (C) Copyright 2008 - 2009 Red Hat, Inc. + */ + +#include +#include "common.h" + +GQuark +ifcfg_plugin_error_quark (void) +{ + static GQuark error_quark = 0; + + if (G_UNLIKELY (error_quark == 0)) + error_quark = g_quark_from_static_string ("ifcfg-plugin-error-quark"); + + return error_quark; +} + + diff --git a/system-settings/plugins/ifcfg-rh/plugin.c b/system-settings/plugins/ifcfg-rh/plugin.c index b673615ad..b2f3100ae 100644 --- a/system-settings/plugins/ifcfg-rh/plugin.c +++ b/system-settings/plugins/ifcfg-rh/plugin.c @@ -87,17 +87,6 @@ typedef struct { } SCPluginIfcfgPrivate; -GQuark -ifcfg_plugin_error_quark (void) -{ - static GQuark error_quark = 0; - - if (G_UNLIKELY (error_quark == 0)) - error_quark = g_quark_from_static_string ("ifcfg-plugin-error-quark"); - - return error_quark; -} - static void check_unmanaged (gpointer key, gpointer data, gpointer user_data) { diff --git a/system-settings/plugins/ifcfg-rh/plugin.h b/system-settings/plugins/ifcfg-rh/plugin.h index 3ad9fd4ea..d820a26e0 100644 --- a/system-settings/plugins/ifcfg-rh/plugin.h +++ b/system-settings/plugins/ifcfg-rh/plugin.h @@ -46,7 +46,5 @@ struct _SCPluginIfcfgClass { GType sc_plugin_ifcfg_get_type (void); -GQuark ifcfg_plugin_error_quark (void); - #endif /* _PLUGIN_H_ */ diff --git a/system-settings/plugins/ifcfg-rh/reader.c b/system-settings/plugins/ifcfg-rh/reader.c index bb87baaf4..1759e6774 100644 --- a/system-settings/plugins/ifcfg-rh/reader.c +++ b/system-settings/plugins/ifcfg-rh/reader.c @@ -53,7 +53,12 @@ #include "sha1.h" #include "reader.h" -#include "nm-system-config-interface.h" + +#define PLUGIN_PRINT(pname, fmt, args...) \ + { g_message (" " pname ": " fmt, ##args); } + +#define PLUGIN_WARN(pname, fmt, args...) \ + { g_warning (" " pname ": " fmt, ##args); } #define TYPE_ETHERNET "Ethernet" #define TYPE_WIRELESS "Wireless" @@ -143,7 +148,7 @@ make_connection_setting (const char *file, if (errno == 0) g_object_set (s_con, NM_SETTING_CONNECTION_TIMESTAMP, tmp, NULL); else - PLUGIN_PRINT (IFCFG_PLUGIN_NAME, " warning: invalid LAST_CONNECT time"); + PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: invalid LAST_CONNECT time"); g_free (value); } @@ -188,7 +193,7 @@ get_one_ip4_addr (shvarFile *ifcfg, goto error; \ if (dns) { \ if (!nm_setting_ip4_config_add_dns (s_ip4, dns)) \ - PLUGIN_PRINT (IFCFG_PLUGIN_NAME, " warning: duplicate DNS server %s", tag); \ + PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: duplicate DNS server %s", tag); \ } \ } @@ -339,7 +344,7 @@ make_ip4_setting (shvarFile *ifcfg, GError **error) if (addr) { if (!nm_setting_ip4_config_add_address (s_ip4, addr)) - PLUGIN_PRINT (IFCFG_PLUGIN_NAME, " warning: duplicate IP4 address"); + PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: duplicate IP4 address"); } GET_ONE_DNS("DNS1"); @@ -357,7 +362,7 @@ make_ip4_setting (shvarFile *ifcfg, GError **error) for (item = searches; *item; item++) { if (strlen (*item)) { if (!nm_setting_ip4_config_add_dns_search (s_ip4, *item)) - PLUGIN_PRINT (IFCFG_PLUGIN_NAME, " warning: duplicate DNS domain '%s'", *item); + PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: duplicate DNS domain '%s'", *item); } } g_strfreev (searches); @@ -377,7 +382,7 @@ make_ip4_setting (shvarFile *ifcfg, GError **error) for (item = searches; *item; item++) { if (strlen (*item)) { if (!nm_setting_ip4_config_add_dns_search (s_ip4, *item)) - PLUGIN_PRINT (IFCFG_PLUGIN_NAME, " warning: duplicate DNS search '%s'", *item); + PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: duplicate DNS search '%s'", *item); } } g_strfreev (searches); @@ -730,9 +735,9 @@ fill_wpa_ciphers (shvarFile *ifcfg, else if (group && !strcmp (*iter, "WEP40")) nm_setting_wireless_security_add_group (wsec, "wep40"); else { - PLUGIN_PRINT (IFCFG_PLUGIN_NAME, " warning: ignoring invalid %s cipher '%s'", - group ? "CIPHER_GROUP" : "CIPHER_PAIRWISE", - *iter); + PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: ignoring invalid %s cipher '%s'", + group ? "CIPHER_GROUP" : "CIPHER_PAIRWISE", + *iter); } } @@ -1099,7 +1104,7 @@ make_wired_setting (shvarFile *ifcfg, gboolean unmanaged, GError **error) g_object_set (s_wired, NM_SETTING_WIRED_MTU, mtu, NULL); } else { /* Shouldn't be fatal... */ - PLUGIN_PRINT (IFCFG_PLUGIN_NAME, " warning: invalid MTU '%s'", value); + PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: invalid MTU '%s'", value); } g_free (value); }