cb7ca52e3df435a49d8d6fc1efe89ac106d1cdac
[NetworkManager.git] / libnm-core / 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 #include "nm-setting.h"
26 #include "nm-connection.h"
27 #include "nm-core-enum-types.h"
28
29 #include "nm-core-internal.h"
30
31 /**
32  * NMSettingVerifyResult:
33  * @NM_SETTING_VERIFY_SUCCESS: the setting verifies successfully
34  * @NM_SETTING_VERIFY_ERROR: the setting has a serious misconfiguration
35  * @NM_SETTING_VERIFY_NORMALIZABLE: the setting is valid but has properties
36  * that should be normalized
37  * @NM_SETTING_VERIFY_NORMALIZABLE_ERROR: the setting is invalid but the
38  * errors can be fixed by nm_connection_normalize().
39  */
40 typedef enum {
41         NM_SETTING_VERIFY_SUCCESS       = TRUE,
42         NM_SETTING_VERIFY_ERROR         = FALSE,
43         NM_SETTING_VERIFY_NORMALIZABLE  = 2,
44         NM_SETTING_VERIFY_NORMALIZABLE_ERROR = 3,
45 } NMSettingVerifyResult;
46
47 void _nm_register_setting (const char *name,
48                            const GType type,
49                            const guint32 priority);
50
51 #define _nm_register_setting(name, priority) \
52         G_STMT_START { \
53                 _nm_register_setting (NM_SETTING_ ## name ## _SETTING_NAME "", g_define_type_id, priority); \
54         } G_STMT_END
55
56 gboolean _nm_setting_is_base_type (NMSetting *setting);
57 gboolean _nm_setting_type_is_base_type (GType type);
58 gint _nm_setting_compare_priority (gconstpointer a, gconstpointer b);
59
60 typedef enum NMSettingUpdateSecretResult {
61         NM_SETTING_UPDATE_SECRET_ERROR              = FALSE,
62         NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED   = TRUE,
63         NM_SETTING_UPDATE_SECRET_SUCCESS_UNCHANGED  = 2,
64 } NMSettingUpdateSecretResult;
65
66 NMSettingUpdateSecretResult _nm_setting_update_secrets (NMSetting *setting,
67                                                         GVariant *secrets,
68                                                         GError **error);
69 gboolean _nm_setting_clear_secrets (NMSetting *setting);
70 gboolean _nm_setting_clear_secrets_with_flags (NMSetting *setting,
71                                                NMSettingClearSecretsWithFlagsFn func,
72                                                gpointer user_data);
73
74
75 /* The property of the #NMSetting should be considered during comparisons that
76  * use the %NM_SETTING_COMPARE_FLAG_INFERRABLE flag. Properties that don't have
77  * this flag, are ignored when doing an infrerrable comparison.  This flag should
78  * be set on all properties that are read from the kernel or the system when a
79  * connection is generated.  eg, IP addresses/routes can be read from the
80  * kernel, but the 'autoconnect' property cannot, so
81  * %NM_SETTING_IP4_CONFIG_ADDRESSES gets the INFERRABLE flag, but
82  * %NM_SETTING_CONNECTION_AUTOCONNECT would not.
83  *
84  * This flag should not be used with properties where the default cannot be
85  * read separately from the current value, like MTU or wired duplex mode.
86  */
87 #define NM_SETTING_PARAM_INFERRABLE (1 << (4 + G_PARAM_USER_SHIFT))
88
89 /* This is a legacy property, which clients should not send to the daemon. */
90 #define NM_SETTING_PARAM_LEGACY (1 << (5 + G_PARAM_USER_SHIFT))
91
92 /* When a connection is active and gets modified, usually the change
93  * to the settings-connection does not propagate automatically to the
94  * applied-connection of the device. For certain properties like the
95  * firewall zone and the metered property, this is different.
96  *
97  * Such fields can be ignored during nm_connection_compare() with the
98  * NMSettingCompareFlag NM_SETTING_COMPARE_FLAG_IGNORE_REAPPLY_IMMEDIATELY.
99  */
100 #define NM_SETTING_PARAM_REAPPLY_IMMEDIATELY (1 << (6 + G_PARAM_USER_SHIFT))
101
102 /* Ensure the setting's GType is registered at library load time */
103 #define NM_SETTING_REGISTER_TYPE(x) \
104 static void __attribute__((constructor)) register_setting (void) \
105 { nm_g_type_init (); g_type_ensure (x); }
106
107 GVariant *_nm_setting_get_deprecated_virtual_interface_name (NMSetting *setting,
108                                                              NMConnection *connection,
109                                                              const char *property);
110
111 NMSettingVerifyResult _nm_setting_verify (NMSetting *setting,
112                                           NMConnection *connection,
113                                           GError **error);
114
115 gboolean _nm_setting_verify_secret_string (const char *str,
116                                            const char *setting_name,
117                                            const char *property,
118                                            GError **error);
119
120 gboolean _nm_setting_slave_type_is_valid (const char *slave_type, const char **out_port_type);
121
122 GVariant   *_nm_setting_to_dbus       (NMSetting *setting,
123                                        NMConnection *connection,
124                                        NMConnectionSerializationFlags flags);
125
126 NMSetting  *_nm_setting_new_from_dbus (GType setting_type,
127                                        GVariant *setting_dict,
128                                        GVariant *connection_dict,
129                                        GError **error);
130
131 typedef GVariant * (*NMSettingPropertyGetFunc)    (NMSetting     *setting,
132                                                    const char    *property);
133 typedef GVariant * (*NMSettingPropertySynthFunc)  (NMSetting     *setting,
134                                                    NMConnection  *connection,
135                                                    const char    *property);
136 typedef void       (*NMSettingPropertySetFunc)    (NMSetting     *setting,
137                                                    GVariant      *connection_dict,
138                                                    const char    *property,
139                                                    GVariant      *value);
140 typedef void       (*NMSettingPropertyNotSetFunc) (NMSetting     *setting,
141                                                    GVariant      *connection_dict,
142                                                    const char    *property);
143
144 void _nm_setting_class_add_dbus_only_property (NMSettingClass *setting_class,
145                                                const char *property_name,
146                                                const GVariantType *dbus_type,
147                                                NMSettingPropertySynthFunc synth_func,
148                                                NMSettingPropertySetFunc set_func);
149
150 void _nm_setting_class_override_property (NMSettingClass *setting_class,
151                                           const char *property_name,
152                                           const GVariantType *dbus_type,
153                                           NMSettingPropertyGetFunc get_func,
154                                           NMSettingPropertySetFunc set_func,
155                                           NMSettingPropertyNotSetFunc not_set_func);
156
157 typedef GVariant * (*NMSettingPropertyTransformToFunc) (const GValue *from);
158 typedef void (*NMSettingPropertyTransformFromFunc) (GVariant *from, GValue *to);
159
160 void _nm_setting_class_transform_property (NMSettingClass *setting_class,
161                                            const char *property_name,
162                                            const GVariantType *dbus_type,
163                                            NMSettingPropertyTransformToFunc to_dbus,
164                                            NMSettingPropertyTransformFromFunc from_dbus);
165
166 gboolean _nm_setting_use_legacy_property (NMSetting *setting,
167                                           GVariant *connection_dict,
168                                           const char *legacy_property,
169                                           const char *new_property);
170
171 GPtrArray  *_nm_setting_need_secrets (NMSetting *setting);
172
173 #endif  /* NM_SETTING_PRIVATE_H */