shared: move _nm_utils_ascii_str_to_int64() to "shared/nm-shared-utils.h"
[NetworkManager.git] / libnm-core / nm-core-internal.h
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
3 /*
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301 USA.
18  *
19  * (C) Copyright 2014 Red Hat, Inc.
20  */
21
22 #ifndef NM_CORE_NM_INTERNAL_H
23 #define NM_CORE_NM_INTERNAL_H
24
25 /* This header file contain functions that are provided as private API
26  * by libnm-core. It will contain functions to give privileged access to
27  * libnm-core. This can be useful for NetworkManager and libnm.so
28  * which both are special users of libnm-core.
29  * It also exposes some utility functions for reuse.
30  *
31  * These functions are not exported and are only available to components that link
32  * statically against libnm-core. This basically means libnm-core, libnm, NetworkManager
33  * and some test programs.
34  **/
35
36
37 #include "nm-default.h"
38 #include "nm-connection.h"
39 #include "nm-core-enum-types.h"
40 #include "nm-setting-8021x.h"
41 #include "nm-setting-adsl.h"
42 #include "nm-setting-bluetooth.h"
43 #include "nm-setting-bond.h"
44 #include "nm-setting-bridge-port.h"
45 #include "nm-setting-bridge.h"
46 #include "nm-setting-cdma.h"
47 #include "nm-setting-connection.h"
48 #include "nm-setting-dcb.h"
49 #include "nm-setting-generic.h"
50 #include "nm-setting-gsm.h"
51 #include "nm-setting-infiniband.h"
52 #include "nm-setting-ip-tunnel.h"
53 #include "nm-setting-ip4-config.h"
54 #include "nm-setting-ip6-config.h"
55 #include "nm-setting-macvlan.h"
56 #include "nm-setting-olpc-mesh.h"
57 #include "nm-setting-ppp.h"
58 #include "nm-setting-pppoe.h"
59 #include "nm-setting-serial.h"
60 #include "nm-setting-team-port.h"
61 #include "nm-setting-team.h"
62 #include "nm-setting-tun.h"
63 #include "nm-setting-vlan.h"
64 #include "nm-setting-vpn.h"
65 #include "nm-setting-vxlan.h"
66 #include "nm-setting-wimax.h"
67 #include "nm-setting-wired.h"
68 #include "nm-setting-wireless-security.h"
69 #include "nm-setting-wireless.h"
70 #include "nm-setting.h"
71 #include "nm-simple-connection.h"
72 #include "nm-utils.h"
73 #include "nm-vpn-dbus-interface.h"
74 #include "nm-core-types-internal.h"
75
76 /* NM_SETTING_COMPARE_FLAG_INFERRABLE: check whether a device-generated
77  * connection can be replaced by a already-defined connection. This flag only
78  * takes into account properties marked with the %NM_SETTING_PARAM_INFERRABLE
79  * flag.
80  */
81 #define NM_SETTING_COMPARE_FLAG_INFERRABLE ((NMSettingCompareFlags) 0x80000000)
82
83 /* NM_SETTING_COMPARE_FLAG_IGNORE_REAPPLY_IMMEDIATELY: this flag is used for properties
84  * that automatically get re-applied on an active connection when the settings
85  * connection is modified. For most properties, the applied-connection is distinct
86  * from the setting-connection and changes don't propagate. Exceptions are the
87  * firewall-zone and the metered property.
88  */
89 #define NM_SETTING_COMPARE_FLAG_IGNORE_REAPPLY_IMMEDIATELY ((NMSettingCompareFlags) 0x40000000)
90
91 /* NM_SETTING_COMPARE_FLAG_NONE: for convenience, define a special flag NONE -- which
92  * equals to numeric zero (NM_SETTING_COMPARE_FLAG_EXACT).
93  */
94 #define NM_SETTING_COMPARE_FLAG_NONE ((NMSettingCompareFlags) 0)
95
96
97 #define NM_SETTING_SECRET_FLAGS_ALL \
98         (NM_SETTING_SECRET_FLAG_NONE | \
99          NM_SETTING_SECRET_FLAG_AGENT_OWNED | \
100          NM_SETTING_SECRET_FLAG_NOT_SAVED | \
101          NM_SETTING_SECRET_FLAG_NOT_REQUIRED)
102
103 guint32 _nm_setting_get_setting_priority (NMSetting *setting);
104
105 gboolean _nm_setting_get_property (NMSetting *setting, const char *name, GValue *value);
106
107 GSList *    _nm_utils_hash_values_to_slist (GHashTable *hash);
108
109 GHashTable *_nm_utils_copy_strdict (GHashTable *strdict);
110
111 typedef gpointer (*NMUtilsCopyFunc) (gpointer);
112
113 GPtrArray *_nm_utils_copy_slist_to_array (const GSList *list,
114                                           NMUtilsCopyFunc copy_func,
115                                           GDestroyNotify unref_func);
116 GSList    *_nm_utils_copy_array_to_slist (const GPtrArray *array,
117                                           NMUtilsCopyFunc copy_func);
118
119 GPtrArray *_nm_utils_copy_array (const GPtrArray *array,
120                                  NMUtilsCopyFunc copy_func,
121                                  GDestroyNotify free_func);
122 GPtrArray *_nm_utils_copy_object_array (const GPtrArray *array);
123
124 gssize _nm_utils_ptrarray_find_first (gpointer *list, gssize len, gconstpointer needle);
125
126 gssize _nm_utils_ptrarray_find_binary_search (gpointer *list, gsize len, gpointer needle, GCompareDataFunc cmpfcn, gpointer user_data);
127
128 gboolean    _nm_utils_string_in_list   (const char *str,
129                                         const char **valid_strings);
130
131 gssize      _nm_utils_strv_find_first (char **list, gssize len, const char *needle);
132
133 char **_nm_utils_strv_cleanup (char **strv,
134                                gboolean strip_whitespace,
135                                gboolean skip_empty,
136                                gboolean skip_repeated);
137
138 char **     _nm_utils_strsplit_set (const char *str,
139                                     const char *delimiters,
140                                     int max_tokens);
141
142 GSList *    _nm_utils_strv_to_slist (char **strv, gboolean deep_copy);
143 char **     _nm_utils_slist_to_strv (GSList *slist, gboolean deep_copy);
144
145 GPtrArray * _nm_utils_strv_to_ptrarray (char **strv);
146 char **     _nm_utils_ptrarray_to_strv (GPtrArray *ptrarray);
147 gboolean    _nm_utils_strv_equal (char **strv1, char **strv2);
148
149 gboolean _nm_utils_check_file (const char *filename,
150                                gint64 check_owner,
151                                NMUtilsCheckFilePredicate check_file,
152                                gpointer user_data,
153                                struct stat *out_st,
154                                GError **error);
155
156 gboolean _nm_utils_check_module_file (const char *name,
157                                       int check_owner,
158                                       NMUtilsCheckFilePredicate check_file,
159                                       gpointer user_data,
160                                       GError **error);
161
162 #define NM_UTILS_UUID_TYPE_LEGACY            0
163 #define NM_UTILS_UUID_TYPE_VARIANT3          1
164
165 char *nm_utils_uuid_generate_from_string (const char *s, gssize slen, int uuid_type, gpointer type_args);
166
167 /* arbitrarily choosen namespace UUID for _nm_utils_uuid_generate_from_strings() */
168 #define NM_UTILS_UUID_NS "b425e9fb-7598-44b4-9e3b-5a2e3aaa4905"
169
170 char *_nm_utils_uuid_generate_from_strings (const char *string1, ...) G_GNUC_NULL_TERMINATED;
171
172 void _nm_dbus_errors_init (void);
173
174 extern gboolean _nm_utils_is_manager_process;
175
176 GByteArray *nm_utils_rsa_key_encrypt (const guint8 *data,
177                                       gsize len,
178                                       const char *in_password,
179                                       char **out_password,
180                                       GError **error);
181
182 gulong _nm_dbus_signal_connect_data (GDBusProxy *proxy,
183                                      const char *signal_name,
184                                      const GVariantType *signature,
185                                      GCallback c_handler,
186                                      gpointer data,
187                                      GClosureNotify destroy_data,
188                                      GConnectFlags connect_flags);
189 #define _nm_dbus_signal_connect(proxy, name, signature, handler, data) \
190         _nm_dbus_signal_connect_data (proxy, name, signature, handler, data, NULL, (GConnectFlags) 0)
191
192 GVariant *_nm_dbus_proxy_call_finish (GDBusProxy           *proxy,
193                                       GAsyncResult         *res,
194                                       const GVariantType   *reply_type,
195                                       GError              **error);
196
197 GVariant *_nm_dbus_proxy_call_sync   (GDBusProxy           *proxy,
198                                       const gchar          *method_name,
199                                       GVariant             *parameters,
200                                       const GVariantType   *reply_type,
201                                       GDBusCallFlags        flags,
202                                       gint                  timeout_msec,
203                                       GCancellable         *cancellable,
204                                       GError              **error);
205
206 gboolean _nm_dbus_error_has_name (GError     *error,
207                                   const char *dbus_error_name);
208
209 /***********************************************************/
210
211 gboolean _nm_vpn_plugin_info_check_file (const char *filename,
212                                          gboolean check_absolute,
213                                          gboolean do_validate_filename,
214                                          gint64 check_owner,
215                                          NMUtilsCheckFilePredicate check_file,
216                                          gpointer user_data,
217                                          GError **error);
218
219 const char *_nm_vpn_plugin_info_get_default_dir_etc (void);
220 const char *_nm_vpn_plugin_info_get_default_dir_lib (void);
221 const char *_nm_vpn_plugin_info_get_default_dir_user (void);
222
223 GSList *_nm_vpn_plugin_info_list_load_dir (const char *dirname,
224                                            gboolean do_validate_filename,
225                                            gint64 check_owner,
226                                            NMUtilsCheckFilePredicate check_file,
227                                            gpointer user_data);
228
229 /***********************************************************/
230
231 typedef struct {
232         const char *name;
233         gboolean numeric;
234         gboolean ipv6_only;
235 } NMUtilsDNSOptionDesc;
236
237 extern const NMUtilsDNSOptionDesc _nm_utils_dns_option_descs[];
238
239 gboolean    _nm_utils_dns_option_validate (const char *option, char **out_name,
240                                            long *out_value, gboolean ipv6,
241                                            const NMUtilsDNSOptionDesc *option_descs);
242 int         _nm_utils_dns_option_find_idx (GPtrArray *array, const char *option);
243
244 /***********************************************************/
245
246 typedef struct _NMUtilsStrStrDictKey NMUtilsStrStrDictKey;
247 guint                 _nm_utils_strstrdictkey_hash   (gconstpointer a);
248 gboolean              _nm_utils_strstrdictkey_equal  (gconstpointer a, gconstpointer b);
249 NMUtilsStrStrDictKey *_nm_utils_strstrdictkey_create (const char *v1, const char *v2);
250
251 #define _nm_utils_strstrdictkey_static(v1, v2) \
252     ( (NMUtilsStrStrDictKey *) ("\03" v1 "\0" v2 "") )
253
254 /***********************************************************/
255
256 gboolean _nm_setting_vlan_set_priorities (NMSettingVlan *setting,
257                                           NMVlanPriorityMap map,
258                                           const NMVlanQosMapping *qos_map,
259                                           guint n_qos_map);
260 void     _nm_setting_vlan_get_priorities (NMSettingVlan *setting,
261                                           NMVlanPriorityMap map,
262                                           NMVlanQosMapping **out_qos_map,
263                                           guint *out_n_qos_map);
264
265 /***********************************************************/
266
267 #endif