libnm-util: add non-failing versions of nm_connection_new_from_hash() and replace...
[NetworkManager.git] / libnm-util / nm-setting-private.h
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /*
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the
15  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  * Boston, MA 02110-1301 USA.
17  *
18  * Copyright 2011 Red Hat, Inc.
19  */
20
21 #ifndef NM_SETTING_PRIVATE_H
22 #define NM_SETTING_PRIVATE_H
23
24 #include "nm-default.h"
25
26 #include "nm-connection.h"
27
28 #define NM_SETTING_SECRET_FLAGS_ALL \
29         (NM_SETTING_SECRET_FLAG_NONE | \
30          NM_SETTING_SECRET_FLAG_AGENT_OWNED | \
31          NM_SETTING_SECRET_FLAG_NOT_SAVED | \
32          NM_SETTING_SECRET_FLAG_NOT_REQUIRED)
33
34 /**
35  * NMSettingVerifyResult:
36  * @NM_SETTING_VERIFY_SUCCESS: the setting verifies successfully
37  * @NM_SETTING_VERIFY_ERROR: the setting has a serious misconfiguration
38  * @NM_SETTING_VERIFY_NORMALIZABLE: the setting is valid but has properties
39  * that should be normalized
40  * @NM_SETTING_VERIFY_NORMALIZABLE_ERROR: the setting is invalid but the
41  * errors can be fixed by nm_connection_normalize().
42  */
43 typedef enum {
44         NM_SETTING_VERIFY_SUCCESS       = TRUE,
45         NM_SETTING_VERIFY_ERROR         = FALSE,
46         NM_SETTING_VERIFY_NORMALIZABLE  = 2,
47         NM_SETTING_VERIFY_NORMALIZABLE_ERROR = 3,
48 } NMSettingVerifyResult;
49
50 void _nm_register_setting (const char *name,
51                            const GType type,
52                            const guint32 priority,
53                            const GQuark error_quark);
54
55 /* Ensure, that name is a compile time constant string. Put the function name in parenthesis to suppress expansion. */
56 #define _nm_register_setting(name, type, priority, error_quark)    _nm_register_setting ((name ""), type, priority, error_quark)
57
58 gboolean _nm_setting_is_base_type (NMSetting *setting);
59 gboolean _nm_setting_type_is_base_type (GType type);
60 guint32 _nm_setting_get_setting_priority (NMSetting *setting);
61 GType _nm_setting_lookup_setting_type (const char *name);
62 GType _nm_setting_lookup_setting_type_by_quark (GQuark error_quark);
63 gint _nm_setting_compare_priority (gconstpointer a, gconstpointer b);
64
65 gboolean _nm_setting_get_property (NMSetting *setting, const char *name, GValue *value);
66
67 NMConnection *_nm_connection_new_from_hash (GHashTable *hash);
68 void          _nm_connection_replace_settings (NMConnection *connection,
69                                                GHashTable *new_settings);
70
71 typedef enum NMSettingUpdateSecretResult {
72         NM_SETTING_UPDATE_SECRET_ERROR              = FALSE,
73         NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED   = TRUE,
74         NM_SETTING_UPDATE_SECRET_SUCCESS_UNCHANGED  = 2,
75 } NMSettingUpdateSecretResult;
76
77 NMSettingUpdateSecretResult _nm_setting_update_secrets (NMSetting *setting,
78                                                         GHashTable *secrets,
79                                                         GError **error);
80 gboolean _nm_setting_clear_secrets (NMSetting *setting);
81 gboolean _nm_setting_clear_secrets_with_flags (NMSetting *setting,
82                                                NMSettingClearSecretsWithFlagsFn func,
83                                                gpointer user_data);
84
85
86 /* NM_SETTING_COMPARE_FLAG_INFERRABLE: check whether a device-generated
87  * connection can be replaced by a already-defined connection. This flag only
88  * takes into account properties marked with the %NM_SETTING_PARAM_INFERRABLE
89  * flag.
90  */
91 #define NM_SETTING_COMPARE_FLAG_INFERRABLE 0x80000000
92
93 /* The property of the #NMSetting should be considered during comparisons that
94  * use the %NM_SETTING_COMPARE_FLAG_INFERRABLE flag. Properties that don't have
95  * this flag, are ignored when doing an infrerrable comparison.  This flag should
96  * be set on all properties that are read from the kernel or the system when a
97  * connection is generated.  eg, IP addresses/routes can be read from the
98  * kernel, but the 'autoconnect' property cannot, so
99  * %NM_SETTING_IP4_CONFIG_ADDRESSES gets the INFERRABLE flag, but
100  * %NM_SETTING_CONNECTION_AUTOCONNECT would not.
101  *
102  * This flag should not be used with properties where the default cannot be
103  * read separately from the current value, like MTU or wired duplex mode.
104  */
105 #define NM_SETTING_PARAM_INFERRABLE (1 << (4 + G_PARAM_USER_SHIFT))
106
107 /* Ensure the setting's GType is registered at library load time */
108 #define NM_SETTING_REGISTER_TYPE(x) \
109 static void __attribute__((constructor)) register_setting (void) \
110 { nm_g_type_init (); g_type_ensure (x); }
111
112 NMSetting *nm_setting_find_in_list (GSList *settings_list, const char *setting_name);
113
114 NMSettingVerifyResult _nm_setting_verify_deprecated_virtual_iface_name (const char *interface_name,
115                                                                         gboolean allow_missing,
116                                                                         const char *setting_name,
117                                                                         const char *setting_property,
118                                                                         GQuark error_quark,
119                                                                         gint e_invalid_property,
120                                                                         gint e_missing_property,
121                                                                         GSList *all_settings,
122                                                                         GError **error);
123
124 NMSettingVerifyResult _nm_setting_verify (NMSetting *setting,
125                                           GSList    *all_settings,
126                                           GError    **error);
127
128 #endif  /* NM_SETTING_PRIVATE_H */