Commit Graph

120 Commits

Author SHA1 Message Date
Thomas Haller
81499355b0 libnm: don't require initialized @out_encrypted argument in nm_utils_file_is_private_key()
No need to require the caller to initialize the optional out-argument.
Otherwise we get:

  (nm-connection-editor:2471): libnm-CRITICAL **: nm_utils_file_is_private_key: assertion 'out_encrypted == NULL || *out_encrypted == FALSE' failed

https://bugzilla.gnome.org/show_bug.cgi?id=763578

Fixes: 1c4f41c610
2016-05-13 14:26:32 +02:00
Beniamino Galvani
82f8a54854 libnm-core: use jansson to compare and check team configurations
Optionally link libnm-core against jansson JSON library and use it to
validate and compare team configurations.
2016-04-18 21:50:51 +02:00
Thomas Haller
5f83ef9925 build: drop internal field __nm_git_sha from libraries
The problem is that you cannot be sure which patches
were applied on top of a source tree, so the __nm_git_sha
value is unreliable.

Also, after running autoreconf during the package build,
NM_GIT_SHA is reset as well.
2016-03-30 15:48:56 +02:00
Thomas Haller
fafc90526b shared: move _nm_utils_ascii_str_to_int64() to "shared/nm-shared-utils.h"
_nm_utils_ascii_str_to_int64() was declared in libnm-core's internal
header "nm-core-internal.h" and thus available for libnm-core, libnm,
NetworkManager and related.

It also means, the function was not available in libnm-util, libnm-glib,
clients or dispatcher. So, we either reimplemented it (nmc_string_to_int_base)
or struggle with the awkward strtol* API.
2016-03-26 12:10:53 +01:00
Lubomir Rintel
1c5d8d0aec all: fix a couple more gvariant iteration leaks 2016-03-08 17:44:15 +01:00
Thomas Haller
8bace23beb all: cleanup includes and let "nm-default.h" include "config.h"
- All internal source files (except "examples", which are not internal)
  should include "config.h" first. As also all internal source
  files should include "nm-default.h", let "config.h" be included
  by "nm-default.h" and include "nm-default.h" as first in every
  source file.
  We already wanted to include "nm-default.h" before other headers
  because it might contains some fixes (like "nm-glib.h" compatibility)
  that is required first.

- After including "nm-default.h", we optinally allow for including the
  corresponding header file for the source file at hand. The idea
  is to ensure that each header file is self contained.

- Don't include "config.h" or "nm-default.h" in any header file
  (except "nm-sd-adapt.h"). Public headers anyway must not include
  these headers, and internal headers are never included after
  "nm-default.h", as of the first previous point.

- Include all internal headers with quotes instead of angle brackets.
  In practice it doesn't matter, because in our public headers we must
  include other headers with angle brackets. As we use our public
  headers also to compile our interal source files, effectively the
  result must be the same. Still do it for consistency.

- Except for <config.h> itself. Include it with angle brackets as suggested by
  https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers
2016-02-19 17:53:25 +01:00
Thomas Haller
e663b88c59 all/trivial: rename STRLEN() macro to NM_STRLEN()
We should not have defines/macros in header files without a nm/NM
prefix. STRLEN() was one of the few offenders.

https://mail.gnome.org/archives/networkmanager-list/2016-February/msg00048.html
2016-02-14 11:34:42 +01:00
Thomas Haller
2c2d9d2e4c build: cleanup default includes
- "gsystem-local-alloc.h" and <gio/gio.h> are already included via
  "nm-default.h". No need to include them separately.

- include "nm-macros-internal.h" via "nm-default.h" and drop all
  explict includes.

- in the modified files, ensure that we always include "config.h"
  and "nm-default.h" first. As second, include the header file
  for the current source file (if applicable). Then follow external
  includes and finally internal nm includes.

- include nm headers inside source code files with quotes

- internal header files don't need to include default headers.
  They can savely assume that "nm-default.h" is already included
  and with it glib, nm-glib.h, nm-macros-internal.h, etc.
2016-02-12 15:36:01 +01:00
Jiří Klimeš
174d66a3d0 libnm-core: add missing transfer annotation for nm_utils_enum_get_values()
Fixes: 13a981fc38
2015-12-12 22:24:35 +01:00
Beniamino Galvani
13a981fc38 libnm-core: add nm_utils_enum_get_values()
Add function nm_utils_enum_get_values() which returns a string array
containing the enum values. It can be used, for example, to build a
list of allowed values for user.
2015-12-01 17:39:40 +01:00
Jiří Klimeš
4485b4ec2f nmcli: wake-on-lan property set/get fixes
- accept a numeric value (decimal or hex (0x prefix))
- display a numeric value of the property in addition to the strings
- add/accept spaces between string names

to behave similar to other flags' properties.
2015-09-15 11:46:37 +02:00
Beniamino Galvani
0969d16ad8 libnm: backport enum conversion utilities to 1.0.6
Backport to 1.0.6 the following symbols:

  - nm_utils_enum_from_str
  - nm_utils_enum_to_str

added to 1.0.6 with commit f4ce6760e0ebb66aee3df35e9618be656355f318
2015-08-25 10:23:57 +02:00
Thomas Haller
b2a66d59c8 Revert "all: change "Since: 1.2" to "Since: 1.0.4"/"Since: 1.0.6" for backported API"
API should be added with "Since:" of the next release on the same branch.
That means, new API on 1.1 branch (development), should be "Since: 1.2"
and new API on 1.0 branch (stable) will be "Since: 1.0.x". Similarly, new
API on master is NM_AVAILABLE_IN_1_2 and will be added with the linker
version libnl_1_2 -- never the versions of minor releases.

It is also strongly advised that for the 1.0 branch, we only add API
that was previously formerly added on master. IOW, that we only do true
backports of API that already exists on master.

API that gets backported, must also be added to master via NM_BACKPORT_SYMBOL().
That gives ABI compatibility and an application that was build against 1.0.x
will work with 1.y.z version (y > 0) without need for recompiling -- provided
that 1.y.z also contains that API.

There is one important caveat: if a major branch (e.g. current master) has a
linker section of backported APIs (e.g. libnm_1_0_6), we must do the minor release
(1.0.6) before the next major release (1.2). The reason is that after the major
release, the linker section (libnm_1_0_6) must not be extended and thus
the minor release (1.0.6) must be already released at that point.

In general, users should avoid using backported API because it limits
the ability to upgrade to arbitrary later versions. But together with the
previous point (that we only backport API to minor releases), a user that
uses backported API can be sure that a 1.y.z version is ABI compatible with
1.0.x, if the 1.y.z release date was after the release date of 1.0.x.

This reverts commit 02a136682c.
2015-08-25 09:04:35 +02:00
Jiří Klimeš
02a136682c all: change "Since: 1.2" to "Since: 1.0.4"/"Since: 1.0.6" for backported API 2015-08-21 10:43:53 +02:00
Jiří Klimeš
3d044b443a libnm: symbols for getting Wi-Fi frequencies have been backported to 1.0.6
Backport to 1.0.6 the following symbols:
  - nm_utils_wifi_2ghz_freqs;
  - nm_utils_wifi_5ghz_freqs;

Backported by commit 77bf69c3dc6ef6c17741cdf0f81af911378596e0
2015-08-21 10:22:31 +02:00
Jiří Klimeš
1a6b631690 libnm: add utility functions for getting 2.4 GHz and 5 GHz Wi-Fi frequencies
nm_utils_wifi_2ghz_freqs()
nm_utils_wifi_5ghz_freqs()
2015-08-21 09:32:09 +02:00
Thomas Haller
1889e9c568 libnm/vpn: set special error code when loading vpn plugin fails due to missing file
VPN plugins are usually split into different packages. It might
be that the plugin file is simply not installed. We want the caller
to be able to recognize that conditation to fail gracefully.
Thus return a certain error code.
2015-08-20 12:42:20 +02:00
Thomas Haller
3dfbbb227e libnm: require exact vpn plugin filename
Originally, nm-applet loaded the vpn plugins by passing the filename
to g_module_open(). Thereby, g_module_open() allowed for missing file
extension and tries to complete the name with a system-dependent suffix.

When porting to libnm, we kept that behavior but did more elaborate
checks on the file, like checking owner and permissions.

Change to no longer trying to append the system suffix, but require
an exact path. That is no usability problem, because the plugin path
is specified in the .name files, and we just require them now to be the
full path (including the .so extension).
Note also, that this only affects new, libnm-based vpn plugins, thus there
is no change in behavior for legacy libnm-glib based plugins.

Fixes: eed0d0c58f
2015-08-18 12:08:11 +02:00
Thomas Haller
97ec44f593 libnm: fix gtkdoc for nm_utils_enum_to_str() and nm_utils_enum_from_str()
Fixes: 8be9814793
2015-08-05 16:35:26 +02:00
Thomas Haller
1766ab6e21 libnm: fix gtkdoc for _nm_utils_dns_option_*()
Fixes: 019943bb5d
2015-08-05 16:33:44 +02:00
Dan Winship
22e1a97e12 all: drop includes to <glib/gi18n.h> for "nm-default.h"
The localization headers are now included via "nm-default.h".

Also fixes several places, where we wrongly included <glib/gi18n-lib.h>
instead of <glib/gi18n.h>. For example under "clients/" directory.
2015-08-05 15:35:51 +02:00
Thomas Haller
19c3ea948a all: make use of new header file "nm-default.h" 2015-08-05 15:32:40 +02:00
Beniamino Galvani
d49fcd07d1 libnm-core: add _nm_utils_strv_equal() 2015-08-04 08:46:11 +02:00
Dan Williams
3a7db0dd9e introspection: fix some annotations
Fixes: eafa6c3584
Fixes: eed0d0c58f
Fixes: b5cc017ba4
Fixes: bce040daa2
2015-07-31 14:19:14 -05:00
Beniamino Galvani
e65854f609 libnm-core: strip nm_utils_enum_from_str() input string 2015-07-30 16:56:27 +02:00
Thomas Haller
b5cc017ba4 libnm: add _nm_utils_check_module_file() 2015-07-29 22:34:35 +02:00
Thomas Haller
ed381cb1e2 libnm: add _nm_utils_check_file() util 2015-07-29 22:34:35 +02:00
Thomas Haller
ec92ecedae libnm: add NMUtilsStrStrDictKey utility
When having a hash-of-hashes where each hash is indexed by a name,
(such as GKeyFile), you can either implement it as a hash-of-hashes
or define your own version of indexes that pack both levels of names
into one key.

This is an implementation of such a key. Use it as:

  GHashTable *hash = g_hash_table_new_full (_nm_utils_strstrdictkey_hash,
                                            _nm_utils_strstrdictkey_equal,
                                            g_free, _destroy_value);

and create keys via:

  NMUtilsStrStrDictKey *k = _nm_utils_strstrdictkey_create (s1, s2);

For lookup you can use static strings (note that the static string
might increase the size of the binary):

  g_hash_table_contains (hash, _nm_utils_strstrdictkey_static ("outer", "inner"))
2015-07-29 22:34:34 +02:00
Dan Winship
3452ee2a0e all: rename nm-glib-compat.h to nm-glib.h, use everywhere
Rather than randomly including one or more of <glib.h>,
<glib-object.h>, and <gio/gio.h> everywhere (and forgetting to include
"nm-glib-compat.h" most of the time), rename nm-glib-compat.h to
nm-glib.h, include <gio/gio.h> from there, and then change all .c
files in NM to include "nm-glib.h" rather than including the glib
headers directly.

(Public headers files still have to include the real glib headers,
since nm-glib.h isn't installed...)

Also, remove glib includes from header files that are already
including a base object header file (which must itself already include
the glib headers).
2015-07-24 13:25:47 -04:00
Thomas Haller
a67c1ec4b5 libnm-core: fix return value in nm_utils_enum_to_str()
Fixes: 8be9814793
2015-07-24 15:48:29 +02:00
Beniamino Galvani
8be9814793 libnm-core: add enum conversion utilities
Add functions nm_utils_enum_to_str() and nm_utils_enum_from_str()
which can be used to perform conversions between enum values and
strings, passing the GType automatically generated for every enum by
glib-mkenums.
2015-07-24 14:02:59 +02:00
Thomas Haller
2b55de8560 libnm-core: properly handle %NULL @ip in nm_utils_ipaddr_valid()
A is_valid() function should just accept NULL as input and
return "invalid". It certainly should not crash.

Fixes: 21c8a6b20e
2015-07-22 13:49:17 +02:00
Dan Williams
4e47d36d73 libnm-core: fix GOI annotations after 019943bb
Fixes: 019943bb
2015-07-17 17:31:17 -05:00
David Shea
568b4ad31f libnm: handle illegal characters in nm_utils_ssid_to_utf8() (rh #1243078)
g_convert_with_fallback() will fail if the SSID contains characters that
are not legal in the source encoding, which, if $LANG is not set, will
be ASCII. If this happens, replace all non-ASCII and non-printable
characters with '?'. It is possible that nm_utils_ssid_to_utf8() will
now return an empty string (e.g., the source string is actually
big-endian UTF-16 and g_strcanon() stops on the first byte), but it will
not return NULL.

https://bugzilla.redhat.com/show_bug.cgi?id=1243078
2015-07-16 14:22:03 +02:00
Thomas Haller
904e961464 all: remove #if GLIB_CHECK_VERSION conditionals around g_type_init()
g_type_init() is now provided by nm-glib-compat.h as nm_g_type_init().
2015-07-12 13:56:52 +02:00
Thomas Haller
ed632207cd libnm: add @deep_copy argument to _nm_utils_strv_to_slist() and _nm_utils_slist_to_strv() 2015-07-02 15:50:04 +02:00
Thomas Haller
885d187d23 libnm: add _nm_utils_strv_cleanup() function 2015-07-02 15:50:03 +02:00
Thomas Haller
650fec81e2 libnm: add _nm_utils_ptrarray_find_binary_search() helper 2015-07-01 16:02:09 +02:00
Thomas Haller
3377cd7e18 libnm: add _nm_utils_ptrarray_find_first() utility function 2015-06-17 11:41:43 +02:00
Thomas Haller
ef4e017cfa libnm/utils: add _nm_utils_strv_find_first() function 2015-06-11 19:58:51 +02:00
Thomas Haller
b8b1a01d96 build: rename file "include/nm-utils-internal.h" to "nm-macros-internal.h"
We already have "nm-utils*.h" and "NetworkManagerUtils.h" headers. Rename
"include/nm-utils-internal.h" to "nm-macros-internal.h". I think that
name is better, because this file is header-only, internal, and
repository-wide.

Also, it will never contain non-header-only declarations because
there is no backing object file under "include/".
It will only contain macros and inline functions.
2015-06-01 14:47:08 +02:00
Thomas Haller
670ca44721 libnm: rename DNSOptionDesc and @dns_option_descs to have an "nm"-prefix
Declarations in header files should always have an "nm" related
prefix.

Fixes: 019943bb5d
2015-05-20 12:42:19 +02:00
Beniamino Galvani
019943bb5d libnm-core: add dns-options property to NMSettingIPConfig 2015-05-13 17:15:34 +02:00
Dan Winship
4bac5afa2b libnm-core: trivial error message fixes 2015-04-17 14:55:42 -04:00
Thomas Haller
1eaddced10 make use of NM_MORE_ASSERTS, nm_assert() and NM_MORE_LOGGING 2015-04-10 18:09:32 +02:00
Thomas Haller
628f47285d libnm: accept unknown WEP key type in nm_utils_wep_key_valid()
libnm-core treated the UNKNOWN WEP key type as KEY. Relax that
and try to guess the correct type based on the key.

This is for example important if you have a valid connection with
  wep-key-type=0 (unknown)
If you request passwords for such a connection, the user cannot
enter them in password format -- but there is no UI indication
that the password must be KEY.
2015-03-20 13:02:04 +01:00
Thomas Haller
e82293ebf6 libnm: move _nm_utils_uuid_generate_from_strings() from src/ to libnm-core/ 2015-03-12 18:12:26 +01:00
Thomas Haller
c5d23737fd libnm: move _nm_utils_ascii_str_to_int64() from src/ to libnm-core/ 2015-03-12 18:12:26 +01:00
Thomas Haller
66be46309a libnm: fix memleak in nm_utils_ip_addresses_from_variant() 2015-02-09 11:51:05 +01:00
Thomas Haller
c4e197d064 libnm: fix memleak in nm_utils_hwaddr_canonical() 2015-01-29 14:59:42 +01:00