nm_rs/auto/
functions.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir
3// from gtk-girs (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5
6#[cfg(feature = "v1_40")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v1_40")))]
8use crate::Connection;
9#[cfg(feature = "v1_14")]
10#[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
11use crate::SriovVF;
12use crate::{
13    DeviceWifiCapabilities, NM80211ApFlags, NM80211ApSecurityFlags, UtilsSecurityType, WepKeyType,
14    ffi,
15};
16#[cfg(feature = "v1_12")]
17#[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
18use crate::{TCAction, TCQdisc, TCTfilter};
19use glib::translate::*;
20
21/// ## `filename`
22/// name of the file to attempt to read into a new #NMConnection
23///
24/// # Returns
25///
26/// a new #NMConnection imported from @path, or [`None`]
27/// on error or if the file with @filename was not recognized as a WireGuard config
28#[cfg(feature = "v1_40")]
29#[cfg_attr(docsrs, doc(cfg(feature = "v1_40")))]
30#[doc(alias = "nm_conn_wireguard_import")]
31pub fn conn_wireguard_import(filename: &str) -> Result<Connection, glib::Error> {
32    assert_initialized_main_thread!();
33    unsafe {
34        let mut error = std::ptr::null_mut();
35        let ret = ffi::nm_conn_wireguard_import(filename.to_glib_none().0, &mut error);
36        if error.is_null() {
37            Ok(from_glib_full(ret))
38        } else {
39            Err(from_glib_full(error))
40        }
41    }
42}
43
44/// Checks whether @optname is a valid option name for a channels setting.
45/// ## `optname`
46/// the option name to check
47///
48/// # Returns
49///
50/// [`true`], if @optname is valid
51#[cfg(feature = "v1_46")]
52#[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
53#[doc(alias = "nm_ethtool_optname_is_channels")]
54pub fn ethtool_optname_is_channels(optname: Option<&str>) -> bool {
55    assert_initialized_main_thread!();
56    unsafe {
57        from_glib(ffi::nm_ethtool_optname_is_channels(
58            optname.to_glib_none().0,
59        ))
60    }
61}
62
63/// Checks whether @optname is a valid option name for a coalesce setting.
64/// ## `optname`
65/// the option name to check
66///
67/// # Returns
68///
69/// [`true`], if @optname is valid
70#[cfg(feature = "v1_26")]
71#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
72#[doc(alias = "nm_ethtool_optname_is_coalesce")]
73pub fn ethtool_optname_is_coalesce(optname: Option<&str>) -> bool {
74    assert_initialized_main_thread!();
75    unsafe {
76        from_glib(ffi::nm_ethtool_optname_is_coalesce(
77            optname.to_glib_none().0,
78        ))
79    }
80}
81
82/// Checks whether @optname is a valid option name for an eee setting.
83/// ## `optname`
84/// the option name to check
85///
86/// # Returns
87///
88/// [`true`], if @optname is valid
89#[cfg(feature = "v1_46")]
90#[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
91#[doc(alias = "nm_ethtool_optname_is_eee")]
92pub fn ethtool_optname_is_eee(optname: Option<&str>) -> bool {
93    assert_initialized_main_thread!();
94    unsafe { from_glib(ffi::nm_ethtool_optname_is_eee(optname.to_glib_none().0)) }
95}
96
97/// Checks whether @optname is a valid option name for an offload feature.
98/// ## `optname`
99/// the option name to check
100///
101/// # Returns
102///
103/// [`true`], if @optname is valid
104///
105/// Note that nm_ethtool_optname_is_feature() was first added to the libnm header files
106/// in 1.14.0 but forgot to actually add to the library. This happened belatedly in 1.20.0 and
107/// the stable versions 1.18.2, 1.16.4 and 1.14.8 (with linker version "libnm_1_14_8").
108#[cfg(feature = "v1_20")]
109#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
110#[doc(alias = "nm_ethtool_optname_is_feature")]
111pub fn ethtool_optname_is_feature(optname: Option<&str>) -> bool {
112    assert_initialized_main_thread!();
113    unsafe { from_glib(ffi::nm_ethtool_optname_is_feature(optname.to_glib_none().0)) }
114}
115
116/// Checks whether @optname is a valid option name for a fec setting.
117/// ## `optname`
118/// the option name to check
119///
120/// # Returns
121///
122/// [`true`], if @optname is valid
123#[cfg(feature = "v1_52")]
124#[cfg_attr(docsrs, doc(cfg(feature = "v1_52")))]
125#[doc(alias = "nm_ethtool_optname_is_fec")]
126pub fn ethtool_optname_is_fec(optname: Option<&str>) -> bool {
127    assert_initialized_main_thread!();
128    unsafe { from_glib(ffi::nm_ethtool_optname_is_fec(optname.to_glib_none().0)) }
129}
130
131/// Checks whether @optname is a valid option name for a pause setting.
132/// ## `optname`
133/// the option name to check
134///
135/// # Returns
136///
137/// [`true`], if @optname is valid
138#[cfg(feature = "v1_32")]
139#[cfg_attr(docsrs, doc(cfg(feature = "v1_32")))]
140#[doc(alias = "nm_ethtool_optname_is_pause")]
141pub fn ethtool_optname_is_pause(optname: Option<&str>) -> bool {
142    assert_initialized_main_thread!();
143    unsafe { from_glib(ffi::nm_ethtool_optname_is_pause(optname.to_glib_none().0)) }
144}
145
146/// Checks whether @optname is a valid option name for a ring setting.
147/// ## `optname`
148/// the option name to check
149///
150/// # Returns
151///
152/// [`true`], if @optname is valid
153#[cfg(feature = "v1_26")]
154#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
155#[doc(alias = "nm_ethtool_optname_is_ring")]
156pub fn ethtool_optname_is_ring(optname: Option<&str>) -> bool {
157    assert_initialized_main_thread!();
158    unsafe { from_glib(ffi::nm_ethtool_optname_is_ring(optname.to_glib_none().0)) }
159}
160
161//#[cfg(feature = "v1_30")]
162//#[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
163//#[doc(alias = "nm_keyfile_read")]
164//pub fn keyfile_read(keyfile: /*Ignored*/&glib::KeyFile, base_dir: &str, handler_flags: KeyfileHandlerFlags, handler: /*Unimplemented*/FnMut(/*Ignored*/glib::KeyFile, &Connection, &KeyfileHandlerType, &KeyfileHandlerData) -> bool, user_data: /*Unimplemented*/Option<Basic: Pointer>) -> Result<Connection, glib::Error> {
165//    unsafe { TODO: call ffi:nm_keyfile_read() }
166//}
167
168//#[cfg(feature = "v1_30")]
169//#[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
170//#[doc(alias = "nm_keyfile_write")]
171//pub fn keyfile_write(connection: &impl IsA<Connection>, handler_flags: KeyfileHandlerFlags, handler: /*Unimplemented*/FnMut(&Connection, /*Ignored*/glib::KeyFile, &KeyfileHandlerType, &KeyfileHandlerData) -> bool, user_data: /*Unimplemented*/Option<Basic: Pointer>) -> Result</*Ignored*/glib::KeyFile, glib::Error> {
172//    unsafe { TODO: call ffi:nm_keyfile_write() }
173//}
174
175/// Given a set of device capabilities, and a desired security type to check
176/// against, determines whether the combination of device capabilities and
177/// desired security type are valid for AP/Hotspot connections.
178/// ## `type_`
179/// the security type to check device capabilities against,
180/// e.g. #NMU_SEC_STATIC_WEP
181/// ## `wifi_caps`
182/// bitfield of the capabilities of the specific Wi-Fi device, e.g.
183/// #NM_WIFI_DEVICE_CAP_CIPHER_WEP40
184///
185/// # Returns
186///
187/// [`true`] if the device capabilities are compatible with the desired
188/// @type_, [`false`] if they are not.
189#[doc(alias = "nm_utils_ap_mode_security_valid")]
190pub fn utils_ap_mode_security_valid(
191    type_: UtilsSecurityType,
192    wifi_caps: DeviceWifiCapabilities,
193) -> bool {
194    assert_initialized_main_thread!();
195    unsafe {
196        from_glib(ffi::nm_utils_ap_mode_security_valid(
197            type_.into_glib(),
198            wifi_caps.into_glib(),
199        ))
200    }
201}
202
203/// ## `base64_key`
204/// the (possibly invalid) base64 encode key.
205/// ## `required_key_len`
206/// the expected (binary) length of the key after
207///   decoding. If the length does not match, the validation fails.
208///
209/// # Returns
210///
211/// [`true`] if the input key is a valid base64 encoded key
212///   with @required_key_len bytes.
213///
214/// ## `out_key`
215/// an optional output buffer for the binary
216///   key. If given, it will be filled with exactly @required_key_len
217///   bytes.
218#[cfg(feature = "v1_16")]
219#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
220#[doc(alias = "nm_utils_base64secret_decode")]
221pub fn utils_base64secret_decode(base64_key: &str) -> Option<u8> {
222    assert_initialized_main_thread!();
223    let required_key_len = base64_key.len() as _;
224    unsafe {
225        let mut out_key = std::mem::MaybeUninit::uninit();
226        let ret = from_glib(ffi::nm_utils_base64secret_decode(
227            base64_key.to_glib_none().0,
228            required_key_len,
229            out_key.as_mut_ptr(),
230        ));
231        if ret {
232            Some(out_key.assume_init())
233        } else {
234            None
235        }
236    }
237}
238
239/// Converts the byte array @src into a hexadecimal string. If @final_len is
240/// greater than -1, the returned string is terminated at that index
241/// (returned_string[final_len] == '\0'),
242/// ## `src`
243/// an array of bytes
244/// ## `final_len`
245/// an index where to cut off the returned string, or -1
246///
247/// # Returns
248///
249/// the textual form of @bytes
250#[doc(alias = "nm_utils_bin2hexstr")]
251pub fn utils_bin2hexstr(src: &[u8], final_len: i32) -> glib::GString {
252    assert_initialized_main_thread!();
253    let len = src.len() as _;
254    unsafe {
255        from_glib_full(ffi::nm_utils_bin2hexstr(
256            src.to_glib_none().0.cast_const() as *const std::ffi::c_void,
257            len,
258            final_len,
259        ))
260    }
261}
262
263/// Convert bonding mode from integer value to descriptive name.
264/// See https://www.kernel.org/doc/Documentation/networking/bonding.txt for
265/// available modes.
266/// ## `mode`
267/// bonding mode as a numeric value
268///
269/// # Returns
270///
271/// bonding mode string, or NULL on error
272#[cfg(feature = "v1_2")]
273#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
274#[doc(alias = "nm_utils_bond_mode_int_to_string")]
275pub fn utils_bond_mode_int_to_string(mode: i32) -> glib::GString {
276    assert_initialized_main_thread!();
277    unsafe { from_glib_none(ffi::nm_utils_bond_mode_int_to_string(mode)) }
278}
279
280/// Convert bonding mode from string representation to numeric value.
281/// See https://www.kernel.org/doc/Documentation/networking/bonding.txt for
282/// available modes.
283/// The @mode string can be either a descriptive name or a number (as string).
284/// ## `mode`
285/// bonding mode as string
286///
287/// # Returns
288///
289/// numeric bond mode, or -1 on error
290#[cfg(feature = "v1_2")]
291#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
292#[doc(alias = "nm_utils_bond_mode_string_to_int")]
293pub fn utils_bond_mode_string_to_int(mode: &str) -> i32 {
294    assert_initialized_main_thread!();
295    unsafe { ffi::nm_utils_bond_mode_string_to_int(mode.to_glib_none().0) }
296}
297
298/// Determines if a connection of type @virtual_type can (in the
299/// general case) work with connections of type @other_type.
300///
301/// If @virtual_type is `NM_TYPE_SETTING_VLAN`, then this checks if
302/// @other_type is a valid type for the parent of a VLAN.
303///
304/// If @virtual_type is a "controller" type (eg, `NM_TYPE_SETTING_BRIDGE`),
305/// then this checks if @other_type is a valid type for a port of that
306/// controller.
307///
308/// Note that even if this returns [`true`] it is not guaranteed that
309/// <emphasis>every</emphasis> connection of type @other_type is
310/// compatible with @virtual_type; it may depend on the exact
311/// configuration of the two connections, or on the capabilities of an
312/// underlying device driver.
313/// ## `virtual_type`
314/// a virtual connection type
315/// ## `other_type`
316/// a connection type to test against @virtual_type
317///
318/// # Returns
319///
320/// [`true`] or [`false`]
321#[doc(alias = "nm_utils_check_virtual_device_compatibility")]
322pub fn utils_check_virtual_device_compatibility(
323    virtual_type: glib::types::Type,
324    other_type: glib::types::Type,
325) -> bool {
326    assert_initialized_main_thread!();
327    unsafe {
328        from_glib(ffi::nm_utils_check_virtual_device_compatibility(
329            virtual_type.into_glib(),
330            other_type.into_glib(),
331        ))
332    }
333}
334
335/// This ensures that all NMSetting GTypes are created. For example,
336/// after this call, g_type_from_name("NMSettingConnection") will work.
337///
338/// This cannot fail and does nothing if the type already exists.
339#[cfg(feature = "v1_42")]
340#[cfg_attr(docsrs, doc(cfg(feature = "v1_42")))]
341#[doc(alias = "nm_utils_ensure_gtypes")]
342pub fn utils_ensure_gtypes() {
343    assert_initialized_main_thread!();
344    unsafe {
345        ffi::nm_utils_ensure_gtypes();
346    }
347}
348
349/// Converts a string to the matching enum value.
350///
351/// If the enum is a `G_TYPE_FLAGS` the function returns the logical OR of values
352/// matching the comma-separated tokens in the string; if an unknown token is found
353/// the function returns [`false`] and stores a pointer to a newly allocated string
354/// containing the unrecognized token in @err_token.
355/// ## `type_`
356/// the `GType` of the enum
357/// ## `str`
358/// the input string
359///
360/// # Returns
361///
362/// [`true`] if the conversion was successful, [`false`] otherwise
363///
364/// ## `out_value`
365/// the output value
366///
367/// ## `err_token`
368/// location to store
369///   the first unrecognized token
370#[cfg(feature = "v1_2")]
371#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
372#[doc(alias = "nm_utils_enum_from_str")]
373pub fn utils_enum_from_str(
374    type_: glib::types::Type,
375    str: &str,
376) -> Option<(i32, Option<glib::GString>)> {
377    assert_initialized_main_thread!();
378    unsafe {
379        let mut out_value = std::mem::MaybeUninit::uninit();
380        let mut err_token = std::ptr::null_mut();
381        let ret = from_glib(ffi::nm_utils_enum_from_str(
382            type_.into_glib(),
383            str.to_glib_none().0,
384            out_value.as_mut_ptr(),
385            &mut err_token,
386        ));
387        if ret {
388            Some((out_value.assume_init(), from_glib_full(err_token)))
389        } else {
390            None
391        }
392    }
393}
394
395/// Returns the list of possible values for a given enum.
396/// ## `type_`
397/// the `GType` of the enum
398/// ## `from`
399/// the first element to be returned
400/// ## `to`
401/// the last element to be returned
402///
403/// # Returns
404///
405/// a NULL-terminated dynamically-allocated array of static strings
406/// or [`None`] on error
407#[cfg(feature = "v1_2")]
408#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
409#[doc(alias = "nm_utils_enum_get_values")]
410pub fn utils_enum_get_values(type_: glib::types::Type, from: i32, to: i32) -> Vec<glib::GString> {
411    assert_initialized_main_thread!();
412    unsafe {
413        FromGlibPtrContainer::from_glib_container(ffi::nm_utils_enum_get_values(
414            type_.into_glib(),
415            from,
416            to,
417        ))
418    }
419}
420
421/// Converts an enum value to its string representation. If the enum is a
422/// `G_TYPE_FLAGS` the function returns a comma-separated list of matching values.
423/// If the value has no corresponding string representation, it is converted
424/// to a number. For enums it is converted to a decimal number, for flags
425/// to an (unsigned) hex number.
426/// ## `type_`
427/// the `GType` of the enum
428/// ## `value`
429/// the value to be translated
430///
431/// # Returns
432///
433/// a newly allocated string or [`None`]
434#[cfg(feature = "v1_2")]
435#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
436#[doc(alias = "nm_utils_enum_to_str")]
437pub fn utils_enum_to_str(type_: glib::types::Type, value: i32) -> glib::GString {
438    assert_initialized_main_thread!();
439    unsafe { from_glib_full(ffi::nm_utils_enum_to_str(type_.into_glib(), value)) }
440}
441
442/// This function does a quick printable character conversion of the SSID, simply
443/// replacing embedded NULLs and non-printable characters with the hexadecimal
444/// representation of that character.  Intended for debugging only, should not
445/// be used for display of SSIDs.
446///
447/// Warning: this function uses a static buffer. It is not thread-safe. Don't
448///   use this function.
449///
450/// # Deprecated since 1.46
451///
452/// use nm_utils_ssid_to_utf8() or nm_utils_bin2hexstr().
453/// ## `ssid`
454/// pointer to a buffer containing the SSID data
455///
456/// # Returns
457///
458/// pointer to the escaped SSID, which uses an internal static buffer
459/// and will be overwritten by subsequent calls to this function
460#[cfg_attr(feature = "v1_46", deprecated = "Since 1.46")]
461#[allow(deprecated)]
462#[doc(alias = "nm_utils_escape_ssid")]
463pub fn utils_escape_ssid(ssid: &[u8]) -> glib::GString {
464    assert_initialized_main_thread!();
465    let len = ssid.len() as _;
466    unsafe { from_glib_none(ffi::nm_utils_escape_ssid(ssid.to_glib_none().0, len)) }
467}
468
469/// Tests if @filename has a valid extension for an X.509 certificate file
470/// (".cer", ".crt", ".der", or ".pem"), and contains a certificate in a format
471/// recognized by NetworkManager.
472/// ## `filename`
473/// name of the file to test
474///
475/// # Returns
476///
477/// [`true`] if the file is a certificate, [`false`] if it is not
478#[doc(alias = "nm_utils_file_is_certificate")]
479pub fn utils_file_is_certificate(filename: &str) -> bool {
480    assert_initialized_main_thread!();
481    unsafe { from_glib(ffi::nm_utils_file_is_certificate(filename.to_glib_none().0)) }
482}
483
484/// Tests if @filename is a PKCS#<!-- -->12 file.
485/// ## `filename`
486/// name of the file to test
487///
488/// # Returns
489///
490/// [`true`] if the file is PKCS#<!-- -->12, [`false`] if it is not
491#[doc(alias = "nm_utils_file_is_pkcs12")]
492pub fn utils_file_is_pkcs12(filename: &str) -> bool {
493    assert_initialized_main_thread!();
494    unsafe { from_glib(ffi::nm_utils_file_is_pkcs12(filename.to_glib_none().0)) }
495}
496
497/// Tests if @filename has a valid extension for an X.509 private key file
498/// (".der", ".key", ".pem", or ".p12"), and contains a private key in a format
499/// recognized by NetworkManager.
500/// ## `filename`
501/// name of the file to test
502///
503/// # Returns
504///
505/// [`true`] if the file is a private key, [`false`] if it is not
506///
507/// ## `out_encrypted`
508/// on return, whether the file is encrypted
509#[doc(alias = "nm_utils_file_is_private_key")]
510pub fn utils_file_is_private_key(filename: &str) -> Option<bool> {
511    assert_initialized_main_thread!();
512    unsafe {
513        let mut out_encrypted = std::mem::MaybeUninit::uninit();
514        let ret = from_glib(ffi::nm_utils_file_is_private_key(
515            filename.to_glib_none().0,
516            out_encrypted.as_mut_ptr(),
517        ));
518        if ret {
519            Some(from_glib(out_encrypted.assume_init()))
520        } else {
521            None
522        }
523    }
524}
525
526//#[doc(alias = "nm_utils_file_search_in_paths")]
527//pub fn utils_file_search_in_paths<P: FnMut(&str) -> bool>(progname: &str, try_first: Option<&str>, paths: Option<&str>, file_test_flags: /*Ignored*/glib::FileTest, predicate: P) -> Result<glib::GString, glib::Error> {
528//    unsafe { TODO: call ffi:nm_utils_file_search_in_paths() }
529//}
530
531//#[cfg(feature = "v1_8")]
532//#[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
533//#[doc(alias = "nm_utils_format_variant_attributes")]
534//pub fn utils_format_variant_attributes(attributes: /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 2, id: 226 }, attr_separator: glib::Char, key_value_separator: glib::Char) -> glib::GString {
535//    unsafe { TODO: call ffi:nm_utils_format_variant_attributes() }
536//}
537
538/// Gets current time in milliseconds of CLOCK_BOOTTIME.
539///
540/// # Returns
541///
542/// time in milliseconds
543#[cfg(feature = "v1_12")]
544#[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
545#[doc(alias = "nm_utils_get_timestamp_msec")]
546pub fn utils_get_timestamp_msec() -> i64 {
547    assert_initialized_main_thread!();
548    unsafe { ffi::nm_utils_get_timestamp_msec() }
549}
550
551//#[doc(alias = "nm_utils_hexstr2bin")]
552//pub fn utils_hexstr2bin(hex: &str) -> /*Ignored*/glib::Bytes {
553//    unsafe { TODO: call ffi:nm_utils_hexstr2bin() }
554//}
555
556//#[doc(alias = "nm_utils_hwaddr_atoba")]
557//pub fn utils_hwaddr_atoba(asc: &str) -> /*Ignored*/glib::ByteArray {
558//    unsafe { TODO: call ffi:nm_utils_hwaddr_atoba() }
559//}
560
561/// Parses @asc and converts it to binary form in @buffer.
562/// Bytes in @asc can be separated by colons (:), or hyphens (-), but not mixed.
563/// ## `asc`
564/// the ASCII representation of a hardware address
565/// ## `buffer`
566/// buffer to store the result into
567///
568/// # Returns
569///
570/// @buffer, or [`None`] if @asc couldn't be parsed
571///   or would be shorter or longer than @length.
572#[doc(alias = "nm_utils_hwaddr_aton")]
573pub fn utils_hwaddr_aton(asc: &str, buffer: &[u8]) -> u8 {
574    assert_initialized_main_thread!();
575    let length = buffer.len() as _;
576    unsafe {
577        ffi::nm_utils_hwaddr_aton(
578            asc.to_glib_none().0,
579            buffer.to_glib_none().0 as glib::ffi::gpointer,
580            length,
581        )
582        .read()
583    }
584}
585
586/// Parses @asc to see if it is a valid hardware address of the given
587/// length, and if so, returns it in canonical form (uppercase, with
588/// leading 0s as needed, and with colons rather than hyphens).
589/// ## `asc`
590/// the ASCII representation of a hardware address
591/// ## `length`
592/// the length of address that @asc is expected to convert to
593///   (or -1 to accept any length up to `NM_UTILS_HWADDR_LEN_MAX`)
594///
595/// # Returns
596///
597/// the canonicalized address if @asc appears to
598///   be a valid hardware address of the indicated length, [`None`] if not.
599#[doc(alias = "nm_utils_hwaddr_canonical")]
600pub fn utils_hwaddr_canonical(asc: &str) -> glib::GString {
601    assert_initialized_main_thread!();
602    let length = asc.len() as _;
603    unsafe { from_glib_full(ffi::nm_utils_hwaddr_canonical(asc.to_glib_none().0, length)) }
604}
605
606/// Returns the length in octets of a hardware address of type @type_.
607///
608/// Before 1.28, it was an error to call this function with any value other than
609/// <literal>ARPHRD_ETHER</literal> or <literal>ARPHRD_INFINIBAND</literal>.
610/// ## `type_`
611/// the type of address; either <literal>ARPHRD_ETHER</literal> or
612/// <literal>ARPHRD_INFINIBAND</literal>
613///
614/// # Returns
615///
616/// the length or zero if the type is unrecognized.
617#[doc(alias = "nm_utils_hwaddr_len")]
618pub fn utils_hwaddr_len(type_: i32) -> usize {
619    assert_initialized_main_thread!();
620    unsafe { ffi::nm_utils_hwaddr_len(type_) }
621}
622
623//#[doc(alias = "nm_utils_hwaddr_matches")]
624//pub fn utils_hwaddr_matches(hwaddr1: /*Unimplemented*/Option<Basic: Pointer>, hwaddr1_len: isize, hwaddr2: /*Unimplemented*/Option<Basic: Pointer>, hwaddr2_len: isize) -> bool {
625//    unsafe { TODO: call ffi:nm_utils_hwaddr_matches() }
626//}
627
628/// Converts @addr to textual form.
629/// ## `addr`
630/// a binary hardware address
631///
632/// # Returns
633///
634/// the textual form of @addr
635#[doc(alias = "nm_utils_hwaddr_ntoa")]
636pub fn utils_hwaddr_ntoa(addr: &[u8]) -> glib::GString {
637    assert_initialized_main_thread!();
638    let length = addr.len() as _;
639    unsafe {
640        from_glib_full(ffi::nm_utils_hwaddr_ntoa(
641            addr.to_glib_none().0.cast_const() as *const std::ffi::c_void,
642            length,
643        ))
644    }
645}
646
647/// Parses @asc to see if it is a valid hardware address of the given
648/// length.
649/// ## `asc`
650/// the ASCII representation of a hardware address
651/// ## `length`
652/// the length of address that @asc is expected to convert to
653///   (or -1 to accept any length up to `NM_UTILS_HWADDR_LEN_MAX`)
654///
655/// # Returns
656///
657/// [`true`] if @asc appears to be a valid hardware address
658///   of the indicated length, [`false`] if not.
659#[doc(alias = "nm_utils_hwaddr_valid")]
660pub fn utils_hwaddr_valid(asc: &str) -> bool {
661    assert_initialized_main_thread!();
662    let length = asc.len() as _;
663    unsafe { from_glib(ffi::nm_utils_hwaddr_valid(asc.to_glib_none().0, length)) }
664}
665
666/// Validate the network interface name.
667///
668/// # Deprecated since 1.6
669///
670/// Use nm_utils_is_valid_iface_name() instead, with better error reporting.
671/// ## `name`
672/// Name of interface
673///
674/// # Returns
675///
676/// [`true`] if interface name is valid, otherwise [`false`] is returned.
677///
678/// Before 1.20, this function did not accept [`None`] as @name argument. If you
679///   want to run against older versions of libnm, don't pass [`None`].
680#[cfg_attr(feature = "v1_6", deprecated = "Since 1.6")]
681#[allow(deprecated)]
682#[doc(alias = "nm_utils_iface_valid_name")]
683pub fn utils_iface_valid_name(name: Option<&str>) -> bool {
684    assert_initialized_main_thread!();
685    unsafe { from_glib(ffi::nm_utils_iface_valid_name(name.to_glib_none().0)) }
686}
687
688/// Wrapper for inet_ntop.
689/// ## `inaddr`
690/// the address that should be converted to string.
691/// ## `dst`
692/// the destination buffer, it must contain at least
693///  <literal>INET_ADDRSTRLEN</literal> or `NM_INET_ADDRSTRLEN`
694///  characters. If set to [`None`], it will return a pointer to an internal, static
695///  buffer (shared with nm_utils_inet6_ntop()).  Beware, that the internal
696///  buffer will be overwritten with ever new call of nm_utils_inet4_ntop() or
697///  nm_utils_inet6_ntop() that does not provide its own @dst buffer. Since
698///  1.28, the internal buffer is thread local and thus thread safe. Before
699///  it was not thread safe. When in doubt, pass your own
700///  @dst buffer to avoid these issues.
701///
702/// # Returns
703///
704/// the input buffer @dst, or a pointer to an
705///  internal, static buffer. This function cannot fail.
706#[doc(alias = "nm_utils_inet4_ntop")]
707pub fn utils_inet4_ntop(inaddr: u32, dst: &str) -> glib::GString {
708    assert_initialized_main_thread!();
709    unsafe { from_glib_none(ffi::nm_utils_inet4_ntop(inaddr, dst.to_glib_none().0)) }
710}
711
712//#[doc(alias = "nm_utils_inet6_ntop")]
713//pub fn utils_inet6_ntop(in6addr: /*Unimplemented*/Option<Basic: Pointer>, dst: &str) -> glib::GString {
714//    unsafe { TODO: call ffi:nm_utils_inet6_ntop() }
715//}
716
717//#[doc(alias = "nm_utils_ip4_addresses_from_variant")]
718//pub fn utils_ip4_addresses_from_variant(value: /*Ignored*/&glib::Variant) -> (Vec<IPAddress>, Option<glib::GString>) {
719//    unsafe { TODO: call ffi:nm_utils_ip4_addresses_from_variant() }
720//}
721
722//#[doc(alias = "nm_utils_ip4_addresses_to_variant")]
723//pub fn utils_ip4_addresses_to_variant(addresses: &[&IPAddress], gateway: Option<&str>) -> /*Ignored*/glib::Variant {
724//    unsafe { TODO: call ffi:nm_utils_ip4_addresses_to_variant() }
725//}
726
727//#[doc(alias = "nm_utils_ip4_dns_from_variant")]
728//pub fn utils_ip4_dns_from_variant(value: /*Ignored*/&glib::Variant) -> glib::GString {
729//    unsafe { TODO: call ffi:nm_utils_ip4_dns_from_variant() }
730//}
731
732//#[doc(alias = "nm_utils_ip4_dns_to_variant")]
733//pub fn utils_ip4_dns_to_variant(dns: &str) -> /*Ignored*/glib::Variant {
734//    unsafe { TODO: call ffi:nm_utils_ip4_dns_to_variant() }
735//}
736
737/// When the Internet was originally set up, various ranges of IP addresses were
738/// segmented into three network classes: A, B, and C.  This function will return
739/// a prefix that is associated with the IP address specified defining where it
740/// falls in the predefined classes.
741/// ## `ip`
742/// an IPv4 address (in network byte order)
743///
744/// # Returns
745///
746/// the default class prefix for the given IP
747#[doc(alias = "nm_utils_ip4_get_default_prefix")]
748pub fn utils_ip4_get_default_prefix(ip: u32) -> u32 {
749    assert_initialized_main_thread!();
750    unsafe { ffi::nm_utils_ip4_get_default_prefix(ip) }
751}
752
753/// ## `netmask`
754/// an IPv4 netmask in network byte order.
755///   Usually the netmask has all leading bits up to the prefix
756///   set so that the netmask is identical to having the first
757///   prefix bits of the address set.
758///   If that is not the case and there are "holes" in the
759///   mask, the prefix is determined based on the lowest bit
760///   set.
761///
762/// # Returns
763///
764/// the CIDR prefix represented by the netmask
765#[doc(alias = "nm_utils_ip4_netmask_to_prefix")]
766pub fn utils_ip4_netmask_to_prefix(netmask: u32) -> u32 {
767    assert_initialized_main_thread!();
768    unsafe { ffi::nm_utils_ip4_netmask_to_prefix(netmask) }
769}
770
771/// ## `prefix`
772/// a CIDR prefix, must be not larger than 32.
773///
774/// # Returns
775///
776/// the netmask represented by the prefix, in network byte order
777#[doc(alias = "nm_utils_ip4_prefix_to_netmask")]
778pub fn utils_ip4_prefix_to_netmask(prefix: u32) -> u32 {
779    assert_initialized_main_thread!();
780    unsafe { ffi::nm_utils_ip4_prefix_to_netmask(prefix) }
781}
782
783//#[doc(alias = "nm_utils_ip4_routes_from_variant")]
784//pub fn utils_ip4_routes_from_variant(value: /*Ignored*/&glib::Variant) -> Vec<IPRoute> {
785//    unsafe { TODO: call ffi:nm_utils_ip4_routes_from_variant() }
786//}
787
788//#[doc(alias = "nm_utils_ip4_routes_to_variant")]
789//pub fn utils_ip4_routes_to_variant(routes: &[&IPRoute]) -> /*Ignored*/glib::Variant {
790//    unsafe { TODO: call ffi:nm_utils_ip4_routes_to_variant() }
791//}
792
793//#[doc(alias = "nm_utils_ip6_addresses_from_variant")]
794//pub fn utils_ip6_addresses_from_variant(value: /*Ignored*/&glib::Variant) -> (Vec<IPAddress>, Option<glib::GString>) {
795//    unsafe { TODO: call ffi:nm_utils_ip6_addresses_from_variant() }
796//}
797
798//#[doc(alias = "nm_utils_ip6_addresses_to_variant")]
799//pub fn utils_ip6_addresses_to_variant(addresses: &[&IPAddress], gateway: Option<&str>) -> /*Ignored*/glib::Variant {
800//    unsafe { TODO: call ffi:nm_utils_ip6_addresses_to_variant() }
801//}
802
803//#[doc(alias = "nm_utils_ip6_dns_from_variant")]
804//pub fn utils_ip6_dns_from_variant(value: /*Ignored*/&glib::Variant) -> glib::GString {
805//    unsafe { TODO: call ffi:nm_utils_ip6_dns_from_variant() }
806//}
807
808//#[doc(alias = "nm_utils_ip6_dns_to_variant")]
809//pub fn utils_ip6_dns_to_variant(dns: &str) -> /*Ignored*/glib::Variant {
810//    unsafe { TODO: call ffi:nm_utils_ip6_dns_to_variant() }
811//}
812
813//#[doc(alias = "nm_utils_ip6_routes_from_variant")]
814//pub fn utils_ip6_routes_from_variant(value: /*Ignored*/&glib::Variant) -> Vec<IPRoute> {
815//    unsafe { TODO: call ffi:nm_utils_ip6_routes_from_variant() }
816//}
817
818//#[doc(alias = "nm_utils_ip6_routes_to_variant")]
819//pub fn utils_ip6_routes_to_variant(routes: &[&IPRoute]) -> /*Ignored*/glib::Variant {
820//    unsafe { TODO: call ffi:nm_utils_ip6_routes_to_variant() }
821//}
822
823//#[cfg(feature = "v1_42")]
824//#[cfg_attr(docsrs, doc(cfg(feature = "v1_42")))]
825//#[doc(alias = "nm_utils_ip_addresses_from_variant")]
826//pub fn utils_ip_addresses_from_variant(value: /*Ignored*/&glib::Variant, family: i32) -> Vec<IPAddress> {
827//    unsafe { TODO: call ffi:nm_utils_ip_addresses_from_variant() }
828//}
829
830//#[cfg(feature = "v1_42")]
831//#[cfg_attr(docsrs, doc(cfg(feature = "v1_42")))]
832//#[doc(alias = "nm_utils_ip_addresses_to_variant")]
833//pub fn utils_ip_addresses_to_variant(addresses: &[&IPAddress]) -> /*Ignored*/glib::Variant {
834//    unsafe { TODO: call ffi:nm_utils_ip_addresses_to_variant() }
835//}
836
837//#[cfg(feature = "v1_42")]
838//#[cfg_attr(docsrs, doc(cfg(feature = "v1_42")))]
839//#[doc(alias = "nm_utils_ip_routes_from_variant")]
840//pub fn utils_ip_routes_from_variant(value: /*Ignored*/&glib::Variant, family: i32) -> Vec<IPRoute> {
841//    unsafe { TODO: call ffi:nm_utils_ip_routes_from_variant() }
842//}
843
844//#[cfg(feature = "v1_42")]
845//#[cfg_attr(docsrs, doc(cfg(feature = "v1_42")))]
846//#[doc(alias = "nm_utils_ip_routes_to_variant")]
847//pub fn utils_ip_routes_to_variant(routes: &[&IPRoute]) -> /*Ignored*/glib::Variant {
848//    unsafe { TODO: call ffi:nm_utils_ip_routes_to_variant() }
849//}
850
851/// Checks if @ip contains a valid IP address of the given family.
852/// ## `family`
853/// <literal>AF_INET</literal> or <literal>AF_INET6</literal>, or
854///   <literal>AF_UNSPEC</literal> to accept either
855/// ## `ip`
856/// an IP address
857///
858/// # Returns
859///
860/// [`true`] or [`false`]
861#[doc(alias = "nm_utils_ipaddr_valid")]
862pub fn utils_ipaddr_valid(family: i32, ip: &str) -> bool {
863    assert_initialized_main_thread!();
864    unsafe { from_glib(ffi::nm_utils_ipaddr_valid(family, ip.to_glib_none().0)) }
865}
866
867/// Different manufacturers use different mechanisms for not broadcasting the
868/// AP's SSID.  This function attempts to detect blank/empty SSIDs using a
869/// number of known SSID-cloaking methods.
870/// ## `ssid`
871/// pointer to a buffer containing the SSID data
872///
873/// # Returns
874///
875/// [`true`] if the SSID is "empty", [`false`] if it is not
876#[doc(alias = "nm_utils_is_empty_ssid")]
877pub fn utils_is_empty_ssid(ssid: &[u8]) -> bool {
878    assert_initialized_main_thread!();
879    let len = ssid.len() as _;
880    unsafe { from_glib(ffi::nm_utils_is_empty_ssid(ssid.to_glib_none().0, len)) }
881}
882
883/// ## `str`
884/// the JSON string to test
885///
886/// # Returns
887///
888/// whether the passed string is valid JSON.
889///   If libnm is not compiled with libjansson support, this check will
890///   also return [`true`] for possibly invalid inputs. If that is a problem
891///   for you, you must validate the JSON yourself.
892#[cfg(feature = "v1_6")]
893#[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
894#[doc(alias = "nm_utils_is_json_object")]
895pub fn utils_is_json_object(str: &str) -> Result<(), glib::Error> {
896    assert_initialized_main_thread!();
897    unsafe {
898        let mut error = std::ptr::null_mut();
899        let is_ok = ffi::nm_utils_is_json_object(str.to_glib_none().0, &mut error);
900        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
901        if error.is_null() {
902            Ok(())
903        } else {
904            Err(from_glib_full(error))
905        }
906    }
907}
908
909/// Checks if @str is a UUID
910///
911/// # Deprecated since 1.32
912///
913/// older versions of NetworkManager had a wrong
914///   understanding of what makes a valid UUID. This function can thus
915///   accept some inputs as valid, which in fact are not valid UUIDs.
916/// ## `str`
917/// a string that might be a UUID
918///
919/// # Returns
920///
921/// [`true`] if @str is a UUID, [`false`] if not
922///
923/// In older versions, nm_utils_is_uuid() did not accept [`None`] as @str
924/// argument. Don't pass [`None`] if you run against older versions of libnm.
925#[cfg_attr(feature = "v1_32", deprecated = "Since 1.32")]
926#[allow(deprecated)]
927#[doc(alias = "nm_utils_is_uuid")]
928pub fn utils_is_uuid(str: Option<&str>) -> bool {
929    assert_initialized_main_thread!();
930    unsafe { from_glib(ffi::nm_utils_is_uuid(str.to_glib_none().0)) }
931}
932
933/// Validate the network interface name.
934///
935/// This function is a 1:1 copy of the kernel's interface validation
936/// function in net/core/dev.c.
937/// ## `name`
938/// Name of interface
939///
940/// # Returns
941///
942/// [`true`] if interface name is valid, otherwise [`false`] is returned.
943///
944/// Before 1.20, this function did not accept [`None`] as @name argument. If you
945///   want to run against older versions of libnm, don't pass [`None`].
946#[cfg(feature = "v1_6")]
947#[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
948#[doc(alias = "nm_utils_is_valid_iface_name")]
949pub fn utils_is_valid_iface_name(name: Option<&str>) -> Result<(), glib::Error> {
950    assert_initialized_main_thread!();
951    unsafe {
952        let mut error = std::ptr::null_mut();
953        let is_ok = ffi::nm_utils_is_valid_iface_name(name.to_glib_none().0, &mut error);
954        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
955        if error.is_null() {
956            Ok(())
957        } else {
958            Err(from_glib_full(error))
959        }
960    }
961}
962
963//#[cfg(feature = "v1_8")]
964//#[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
965//#[doc(alias = "nm_utils_parse_variant_attributes")]
966//pub fn utils_parse_variant_attributes(string: &str, attr_separator: glib::Char, key_value_separator: glib::Char, ignore_unknown: bool, spec: &VariantAttributeSpec) -> Result</*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 2, id: 226 }, glib::Error> {
967//    unsafe { TODO: call ffi:nm_utils_parse_variant_attributes() }
968//}
969
970/// The only purpose of this function is to give access to g_print()
971/// or g_printerr() from pygobject. libnm can do debug logging by
972/// setting LIBNM_CLIENT_DEBUG and uses thereby g_printerr() or
973/// g_print(). A plain "print()" function in python is not in sync
974/// with these functions (it implements additional buffering). By
975/// using nm_utils_print(), the same logging mechanisms can be used.
976///
977/// LIBNM_CLIENT_DEBUG is a list of keywords separated by commas. The keyword
978/// "trace" enables printing messages of the lowest up to the highest severity.
979/// Likewise, the severities "debug", "warn" ("warning") and "error" are honored
980/// in similar way. Setting the flags "ERROR" or "WARN" ("WARNING") implies that
981/// respective levels are enabled, but also are ERROR messages printed with
982/// g_critical() and WARN messages with g_warning(). Together with G_DEBUG="fatal-warnings"
983/// or G_DEBUG="fatal-critical" this can be used to abort the program on errors.
984/// Note that all &lt;error&gt; messages imply an unexpected data on the D-Bus API
985/// (due to a bug). &lt;warn&gt; also implies unexepected data, but that can happen
986/// when using different versions of libnm and daemon. For testing, it is
987/// good to turn these into assertions.
988///
989/// By default, messages are printed to stderr, unless LIBNM_CLIENT_DEBUG
990/// contains "stdout" flag. Also, libnm honors LIBNM_CLIENT_DEBUG_FILE
991/// environment. If this is set to a filename pattern (accepting "%`p`" for the
992/// process ID), then the debug log is written to that file instead of
993/// stderr/stdout. With @output_mode zero, the same location will be written.
994///
995/// LIBNM_CLIENT_DEBUG_FILE is supported since 1.44. "ERROR", "WARN" and "WARNING"
996/// are supported since 1.46.
997/// ## `output_mode`
998/// if 1 it uses g_print(). If 2, it uses g_printerr().
999///   If 0, it uses the same output as internal libnm debug logging
1000///   does. That is, depending on LIBNM_CLIENT_DEBUG's "stdout" flag
1001///   it uses g_print() or g_printerr() and if LIBNM_CLIENT_DEBUG_FILE is
1002///   set, it writes the output to file instead
1003/// ## `msg`
1004/// the message to print. The function does not append
1005///   a trailing newline.
1006#[cfg(feature = "v1_30")]
1007#[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
1008#[doc(alias = "nm_utils_print")]
1009pub fn utils_print(output_mode: i32, msg: &str) {
1010    assert_initialized_main_thread!();
1011    unsafe {
1012        ffi::nm_utils_print(output_mode, msg.to_glib_none().0);
1013    }
1014}
1015
1016/// Earlier versions of the Linux kernel added a NULL byte to the end of the
1017/// SSID to enable easy printing of the SSID on the console or in a terminal,
1018/// but this behavior was problematic (SSIDs are simply byte arrays, not strings)
1019/// and thus was changed.  This function compensates for that behavior at the
1020/// cost of some compatibility with odd SSIDs that may legitimately have trailing
1021/// NULLs, even though that is functionally pointless.
1022/// ## `ssid1`
1023/// the first SSID to compare
1024/// ## `ssid2`
1025/// the second SSID to compare
1026/// ## `ignore_trailing_null`
1027/// [`true`] to ignore one trailing NULL byte
1028///
1029/// # Returns
1030///
1031/// [`true`] if the SSIDs are the same, [`false`] if they are not
1032#[doc(alias = "nm_utils_same_ssid")]
1033pub fn utils_same_ssid(ssid1: &[u8], ssid2: &[u8], ignore_trailing_null: bool) -> bool {
1034    assert_initialized_main_thread!();
1035    let len1 = ssid1.len() as _;
1036    let len2 = ssid2.len() as _;
1037    unsafe {
1038        from_glib(ffi::nm_utils_same_ssid(
1039            ssid1.to_glib_none().0,
1040            len1,
1041            ssid2.to_glib_none().0,
1042            len2,
1043            ignore_trailing_null.into_glib(),
1044        ))
1045    }
1046}
1047
1048/// Given a set of device capabilities, and a desired security type to check
1049/// against, determines whether the combination of device, desired security
1050/// type, and AP capabilities intersect.
1051///
1052/// NOTE: this function cannot handle checking security for AP/Hotspot mode;
1053/// use nm_utils_ap_mode_security_valid() instead.
1054/// ## `type_`
1055/// the security type to check AP flags and device capabilities against,
1056/// e.g. #NMU_SEC_STATIC_WEP
1057/// ## `wifi_caps`
1058/// bitfield of the capabilities of the specific Wi-Fi device, e.g.
1059/// #NM_WIFI_DEVICE_CAP_CIPHER_WEP40
1060/// ## `have_ap`
1061/// whether the @ap_flags, @ap_wpa, and @ap_rsn arguments are valid
1062/// ## `adhoc`
1063/// whether the capabilities being tested are from an Ad-Hoc AP (IBSS)
1064/// ## `ap_flags`
1065/// bitfield of AP capabilities, e.g. #NM_802_11_AP_FLAGS_PRIVACY
1066/// ## `ap_wpa`
1067/// bitfield of AP capabilities derived from the AP's WPA beacon,
1068/// e.g. (#NM_802_11_AP_SEC_PAIR_TKIP | #NM_802_11_AP_SEC_KEY_MGMT_PSK)
1069/// ## `ap_rsn`
1070/// bitfield of AP capabilities derived from the AP's RSN/WPA2 beacon,
1071/// e.g. (#NM_802_11_AP_SEC_PAIR_CCMP | #NM_802_11_AP_SEC_PAIR_TKIP)
1072///
1073/// # Returns
1074///
1075/// [`true`] if the device capabilities and AP capabilities intersect and are
1076/// compatible with the desired @type_, [`false`] if they are not
1077#[doc(alias = "nm_utils_security_valid")]
1078pub fn utils_security_valid(
1079    type_: UtilsSecurityType,
1080    wifi_caps: DeviceWifiCapabilities,
1081    have_ap: bool,
1082    adhoc: bool,
1083    ap_flags: NM80211ApFlags,
1084    ap_wpa: NM80211ApSecurityFlags,
1085    ap_rsn: NM80211ApSecurityFlags,
1086) -> bool {
1087    assert_initialized_main_thread!();
1088    unsafe {
1089        from_glib(ffi::nm_utils_security_valid(
1090            type_.into_glib(),
1091            wifi_caps.into_glib(),
1092            have_ap.into_glib(),
1093            adhoc.into_glib(),
1094            ap_flags.into_glib(),
1095            ap_wpa.into_glib(),
1096            ap_rsn.into_glib(),
1097        ))
1098    }
1099}
1100
1101/// Converts a string to a SR-IOV virtual function object.
1102/// ## `str`
1103/// the input string
1104///
1105/// # Returns
1106///
1107/// the virtual function object
1108#[cfg(feature = "v1_14")]
1109#[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
1110#[doc(alias = "nm_utils_sriov_vf_from_str")]
1111pub fn utils_sriov_vf_from_str(str: &str) -> Result<SriovVF, glib::Error> {
1112    assert_initialized_main_thread!();
1113    unsafe {
1114        let mut error = std::ptr::null_mut();
1115        let ret = ffi::nm_utils_sriov_vf_from_str(str.to_glib_none().0, &mut error);
1116        if error.is_null() {
1117            Ok(from_glib_full(ret))
1118        } else {
1119            Err(from_glib_full(error))
1120        }
1121    }
1122}
1123
1124/// Converts a SR-IOV virtual function object to its string representation.
1125/// ## `vf`
1126/// the `NMSriovVF`
1127/// ## `omit_index`
1128/// if [`true`], the VF index will be omitted from output string
1129///
1130/// # Returns
1131///
1132/// a newly allocated string or [`None`] on error
1133#[cfg(feature = "v1_14")]
1134#[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
1135#[doc(alias = "nm_utils_sriov_vf_to_str")]
1136pub fn utils_sriov_vf_to_str(vf: &SriovVF, omit_index: bool) -> Result<glib::GString, glib::Error> {
1137    assert_initialized_main_thread!();
1138    unsafe {
1139        let mut error = std::ptr::null_mut();
1140        let ret =
1141            ffi::nm_utils_sriov_vf_to_str(vf.to_glib_none().0, omit_index.into_glib(), &mut error);
1142        if error.is_null() {
1143            Ok(from_glib_full(ret))
1144        } else {
1145            Err(from_glib_full(error))
1146        }
1147    }
1148}
1149
1150/// Wi-Fi SSIDs are byte arrays, they are _not_ strings.  Thus, an SSID may
1151/// contain embedded NULLs and other unprintable characters.  Often it is
1152/// useful to print the SSID out for debugging purposes, but that should be the
1153/// _only_ use of this function.  Do not use this function for any persistent
1154/// storage of the SSID, since the printable SSID returned from this function
1155/// cannot be converted back into the real SSID of the access point.
1156///
1157/// This function does almost everything humanly possible to convert the input
1158/// into a printable UTF-8 string, using roughly the following procedure:
1159///
1160/// 1) if the input data is already UTF-8 safe, no conversion is performed
1161/// 2) attempts to get the current system language from the LANG environment
1162///    variable, and depending on the language, uses a table of alternative
1163///    encodings to try.  For example, if LANG=hu_HU, the table may first try
1164///    the ISO-8859-2 encoding, and if that fails, try the Windows-1250 encoding.
1165///    If all fallback encodings fail, replaces non-UTF-8 characters with '?'.
1166/// 3) If the system language was unable to be determined, falls back to the
1167///    ISO-8859-1 encoding, then to the Windows-1251 encoding.
1168/// 4) If step 3 fails, replaces non-UTF-8 characters with '?'.
1169///
1170/// Again, this function should be used for debugging and display purposes
1171/// _only_.
1172/// ## `ssid`
1173/// pointer to a buffer containing the SSID data
1174///
1175/// # Returns
1176///
1177/// an allocated string containing a UTF-8
1178/// representation of the SSID, which must be freed by the caller using g_free().
1179/// Returns [`None`] on errors.
1180#[doc(alias = "nm_utils_ssid_to_utf8")]
1181pub fn utils_ssid_to_utf8(ssid: &[u8]) -> glib::GString {
1182    assert_initialized_main_thread!();
1183    let len = ssid.len() as _;
1184    unsafe { from_glib_full(ffi::nm_utils_ssid_to_utf8(ssid.to_glib_none().0, len)) }
1185}
1186
1187/// Parses the tc style string action representation of the queueing
1188/// discipline to a `NMTCAction` instance. Supports a subset of the tc language.
1189/// ## `str`
1190/// the string representation of a action
1191///
1192/// # Returns
1193///
1194/// the `NMTCAction` or [`None`]
1195#[cfg(feature = "v1_12")]
1196#[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
1197#[doc(alias = "nm_utils_tc_action_from_str")]
1198pub fn utils_tc_action_from_str(str: &str) -> Result<TCAction, glib::Error> {
1199    assert_initialized_main_thread!();
1200    unsafe {
1201        let mut error = std::ptr::null_mut();
1202        let ret = ffi::nm_utils_tc_action_from_str(str.to_glib_none().0, &mut error);
1203        if error.is_null() {
1204            Ok(from_glib_full(ret))
1205        } else {
1206            Err(from_glib_full(error))
1207        }
1208    }
1209}
1210
1211/// Turns the `NMTCAction` into a tc style string representation of the queueing
1212/// discipline.
1213/// ## `action`
1214/// the `NMTCAction`
1215///
1216/// # Returns
1217///
1218/// formatted string or [`None`]
1219#[cfg(feature = "v1_12")]
1220#[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
1221#[doc(alias = "nm_utils_tc_action_to_str")]
1222pub fn utils_tc_action_to_str(action: &TCAction) -> Result<glib::GString, glib::Error> {
1223    assert_initialized_main_thread!();
1224    unsafe {
1225        let mut error = std::ptr::null_mut();
1226        let ret = ffi::nm_utils_tc_action_to_str(action.to_glib_none().0, &mut error);
1227        if error.is_null() {
1228            Ok(from_glib_full(ret))
1229        } else {
1230            Err(from_glib_full(error))
1231        }
1232    }
1233}
1234
1235/// Parses the tc style string qdisc representation of the queueing
1236/// discipline to a `NMTCQdisc` instance. Supports a subset of the tc language.
1237/// ## `str`
1238/// the string representation of a qdisc
1239///
1240/// # Returns
1241///
1242/// the `NMTCQdisc` or [`None`]
1243#[cfg(feature = "v1_12")]
1244#[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
1245#[doc(alias = "nm_utils_tc_qdisc_from_str")]
1246pub fn utils_tc_qdisc_from_str(str: &str) -> Result<TCQdisc, glib::Error> {
1247    assert_initialized_main_thread!();
1248    unsafe {
1249        let mut error = std::ptr::null_mut();
1250        let ret = ffi::nm_utils_tc_qdisc_from_str(str.to_glib_none().0, &mut error);
1251        if error.is_null() {
1252            Ok(from_glib_full(ret))
1253        } else {
1254            Err(from_glib_full(error))
1255        }
1256    }
1257}
1258
1259/// Turns the `NMTCQdisc` into a tc style string representation of the queueing
1260/// discipline.
1261/// ## `qdisc`
1262/// the `NMTCQdisc`
1263///
1264/// # Returns
1265///
1266/// formatted string or [`None`]
1267#[cfg(feature = "v1_12")]
1268#[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
1269#[doc(alias = "nm_utils_tc_qdisc_to_str")]
1270pub fn utils_tc_qdisc_to_str(qdisc: &TCQdisc) -> Result<glib::GString, glib::Error> {
1271    assert_initialized_main_thread!();
1272    unsafe {
1273        let mut error = std::ptr::null_mut();
1274        let ret = ffi::nm_utils_tc_qdisc_to_str(qdisc.to_glib_none().0, &mut error);
1275        if error.is_null() {
1276            Ok(from_glib_full(ret))
1277        } else {
1278            Err(from_glib_full(error))
1279        }
1280    }
1281}
1282
1283/// Parses the tc style string tfilter representation of the queueing
1284/// discipline to a `NMTCTfilter` instance. Supports a subset of the tc language.
1285/// ## `str`
1286/// the string representation of a tfilter
1287///
1288/// # Returns
1289///
1290/// the `NMTCTfilter` or [`None`]
1291#[cfg(feature = "v1_12")]
1292#[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
1293#[doc(alias = "nm_utils_tc_tfilter_from_str")]
1294pub fn utils_tc_tfilter_from_str(str: &str) -> Result<TCTfilter, glib::Error> {
1295    assert_initialized_main_thread!();
1296    unsafe {
1297        let mut error = std::ptr::null_mut();
1298        let ret = ffi::nm_utils_tc_tfilter_from_str(str.to_glib_none().0, &mut error);
1299        if error.is_null() {
1300            Ok(from_glib_full(ret))
1301        } else {
1302            Err(from_glib_full(error))
1303        }
1304    }
1305}
1306
1307/// Turns the `NMTCTfilter` into a tc style string representation of the queueing
1308/// discipline.
1309/// ## `tfilter`
1310/// the `NMTCTfilter`
1311///
1312/// # Returns
1313///
1314/// formatted string or [`None`]
1315#[cfg(feature = "v1_12")]
1316#[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
1317#[doc(alias = "nm_utils_tc_tfilter_to_str")]
1318pub fn utils_tc_tfilter_to_str(tfilter: &TCTfilter) -> Result<glib::GString, glib::Error> {
1319    assert_initialized_main_thread!();
1320    unsafe {
1321        let mut error = std::ptr::null_mut();
1322        let ret = ffi::nm_utils_tc_tfilter_to_str(tfilter.to_glib_none().0, &mut error);
1323        if error.is_null() {
1324            Ok(from_glib_full(ret))
1325        } else {
1326            Err(from_glib_full(error))
1327        }
1328    }
1329}
1330
1331///
1332/// # Returns
1333///
1334/// a newly allocated UUID suitable for use as the #NMSettingConnection
1335/// object's #NMSettingConnection:id: property.  Should be freed with g_free()
1336#[doc(alias = "nm_utils_uuid_generate")]
1337pub fn utils_uuid_generate() -> glib::GString {
1338    assert_initialized_main_thread!();
1339    unsafe { from_glib_full(ffi::nm_utils_uuid_generate()) }
1340}
1341
1342///
1343/// # Returns
1344///
1345/// the version ID of the libnm version. That is, the `NM_VERSION`
1346///   at runtime.
1347#[cfg(feature = "v1_6")]
1348#[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
1349#[doc(alias = "nm_utils_version")]
1350pub fn utils_version() -> u32 {
1351    assert_initialized_main_thread!();
1352    unsafe { ffi::nm_utils_version() }
1353}
1354
1355/// Checks if @key is a valid WEP key
1356/// ## `key`
1357/// a string that might be a WEP key
1358/// ## `wep_type`
1359/// the #NMWepKeyType type of the WEP key
1360///
1361/// # Returns
1362///
1363/// [`true`] if @key is a WEP key, [`false`] if not
1364#[doc(alias = "nm_utils_wep_key_valid")]
1365pub fn utils_wep_key_valid(key: &str, wep_type: WepKeyType) -> bool {
1366    assert_initialized_main_thread!();
1367    unsafe {
1368        from_glib(ffi::nm_utils_wep_key_valid(
1369            key.to_glib_none().0,
1370            wep_type.into_glib(),
1371        ))
1372    }
1373}
1374
1375/// Utility function to return 2.4 GHz Wi-Fi frequencies (802.11bg band).
1376///
1377/// # Returns
1378///
1379/// zero-terminated array of frequencies numbers (in MHz)
1380#[cfg(feature = "v1_2")]
1381#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
1382#[doc(alias = "nm_utils_wifi_2ghz_freqs")]
1383pub fn utils_wifi_2ghz_freqs() -> u32 {
1384    assert_initialized_main_thread!();
1385    unsafe { ffi::nm_utils_wifi_2ghz_freqs().read() }
1386}
1387
1388/// Utility function to return 5 GHz Wi-Fi frequencies (802.11a band).
1389///
1390/// # Returns
1391///
1392/// zero-terminated array of frequencies numbers (in MHz)
1393#[cfg(feature = "v1_2")]
1394#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
1395#[doc(alias = "nm_utils_wifi_5ghz_freqs")]
1396pub fn utils_wifi_5ghz_freqs() -> u32 {
1397    assert_initialized_main_thread!();
1398    unsafe { ffi::nm_utils_wifi_5ghz_freqs().read() }
1399}
1400
1401/// Utility function to translate a Wi-Fi channel to its corresponding frequency.
1402/// ## `channel`
1403/// channel
1404/// ## `band`
1405/// frequency band for wireless ("a" or "bg")
1406///
1407/// # Returns
1408///
1409/// the frequency represented by the channel of the band,
1410///          or -1 when the freq is invalid, or 0 when the band
1411///          is invalid
1412#[doc(alias = "nm_utils_wifi_channel_to_freq")]
1413pub fn utils_wifi_channel_to_freq(channel: u32, band: &str) -> u32 {
1414    assert_initialized_main_thread!();
1415    unsafe { ffi::nm_utils_wifi_channel_to_freq(channel, band.to_glib_none().0) }
1416}
1417
1418/// Utility function to find out next/previous Wi-Fi channel for a channel.
1419/// ## `channel`
1420/// current channel
1421/// ## `direction`
1422/// whether going downward (0 or less) or upward (1 or more)
1423/// ## `band`
1424/// frequency band for wireless ("a" or "bg")
1425///
1426/// # Returns
1427///
1428/// the next channel in the specified direction or 0
1429#[doc(alias = "nm_utils_wifi_find_next_channel")]
1430pub fn utils_wifi_find_next_channel(channel: u32, direction: i32, band: &str) -> u32 {
1431    assert_initialized_main_thread!();
1432    unsafe { ffi::nm_utils_wifi_find_next_channel(channel, direction, band.to_glib_none().0) }
1433}
1434
1435/// Utility function to translate a Wi-Fi frequency to its corresponding channel.
1436/// ## `freq`
1437/// frequency
1438///
1439/// # Returns
1440///
1441/// the channel represented by the frequency or 0
1442#[doc(alias = "nm_utils_wifi_freq_to_channel")]
1443pub fn utils_wifi_freq_to_channel(freq: u32) -> u32 {
1444    assert_initialized_main_thread!();
1445    unsafe { ffi::nm_utils_wifi_freq_to_channel(freq) }
1446}
1447
1448/// Utility function to verify Wi-Fi channel validity.
1449/// ## `channel`
1450/// channel
1451/// ## `band`
1452/// frequency band for wireless ("a" or "bg")
1453///
1454/// # Returns
1455///
1456/// [`true`] or [`false`]
1457#[doc(alias = "nm_utils_wifi_is_channel_valid")]
1458pub fn utils_wifi_is_channel_valid(channel: u32, band: &str) -> bool {
1459    assert_initialized_main_thread!();
1460    unsafe {
1461        from_glib(ffi::nm_utils_wifi_is_channel_valid(
1462            channel,
1463            band.to_glib_none().0,
1464        ))
1465    }
1466}
1467
1468/// Converts @strength into a 4-character-wide graphical representation of
1469/// strength suitable for printing to stdout.
1470///
1471/// Previous versions used to take a guess at the terminal type and possibly
1472/// return a wide UTF-8 encoded string. Now it always returns a 7-bit
1473/// clean strings of one to 0 to 4 asterisks. Users that actually need
1474/// the functionality are encouraged to make their implementations instead.
1475/// ## `strength`
1476/// the access point strength, from 0 to 100
1477///
1478/// # Returns
1479///
1480/// the graphical representation of the access point strength
1481#[doc(alias = "nm_utils_wifi_strength_bars")]
1482pub fn utils_wifi_strength_bars(strength: u8) -> glib::GString {
1483    assert_initialized_main_thread!();
1484    unsafe { from_glib_none(ffi::nm_utils_wifi_strength_bars(strength)) }
1485}
1486
1487/// Checks if @psk is a valid WPA PSK
1488/// ## `psk`
1489/// a string that might be a WPA PSK
1490///
1491/// # Returns
1492///
1493/// [`true`] if @psk is a WPA PSK, [`false`] if not
1494#[doc(alias = "nm_utils_wpa_psk_valid")]
1495pub fn utils_wpa_psk_valid(psk: &str) -> bool {
1496    assert_initialized_main_thread!();
1497    unsafe { from_glib(ffi::nm_utils_wpa_psk_valid(psk.to_glib_none().0)) }
1498}