Commit graph

319 commits

Author SHA1 Message Date
Beniamino Galvani 357edff198 examples: make 10-ifcfg-rh-routes.sh self-contained
Don't call the 'if{up,down}-routes' scripts because in next Fedora
versions network scripts will be deprecated and will not be present in
the default installation.

Instead, just copy and adapt the code from those scripts.

https://bugzilla.redhat.com/show_bug.cgi?id=1618419
2018-08-28 18:56:56 +02:00
Thomas Haller e1c7a2b5d0 all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.

    $ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    587
    $ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    21114

One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during

  g_object_set (obj, PROPERTY, (gint) value, NULL);

However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.

Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).

A simple style guide is instead: don't use these typedefs.

No manual actions, I only ran the bash script:

  FILES=($(git ls-files '*.[hc]'))
  sed -i \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>  /\1   /g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
      "${FILES[@]}"
2018-07-11 12:02:06 +02:00
Lubomir Rintel 59ccf5dc89 examples/python: drop nmex.py
It's not an example and not actually used.

https://github.com/NetworkManager/NetworkManager/pull/141
2018-06-29 20:05:39 +02:00
Lubomir Rintel 79fe82753d examples/qt/meson: drop dbus-glib dependency
It's not actually required.

(cherry picked from commit 22813fdc60)
2018-06-28 20:41:12 +02:00
Lubomir Rintel 1b6127d1bc examples/python: utilize nm_utils_get_timestamp_msec() 2018-06-15 16:23:30 +02:00
Lubomir Rintel 9c0db98094 Revert "example/python: avoid falling back to CLOCK_MONOTONIC"
This breaks client tests on avery old kernel (2.6.32, RHEL 6).

  Traceback (most recent call last):
    File "./clients/tests/test-client.py", line 699, in setUp
      self.srv = NMStubServer(self._testMethodName)
    File "./clients/tests/test-client.py", line 309, in __init__
      start = nmex.nm_boot_time_ns()
    File "/builddir/build/BUILD/NetworkManager-1.11.4/examples/python/nmex.py", line 54, in nm_boot_time_ns
      return sys_clock_gettime_ns(CLOCK_BOOTTIME)
    File "/builddir/build/BUILD/NetworkManager-1.11.4/examples/python/nmex.py", line 50, in sys_clock_gettime_ns
      return _sys_clock_gettime_ns(clock_id)
    File "/builddir/build/BUILD/NetworkManager-1.11.4/examples/python/nmex.py", line 39, in f
      raise OSError(errno_, os.strerror(errno_))
  OSError: [Errno 22] Invalid argument

This reverts commit 119e828dbe.
2018-06-15 08:36:22 +02:00
Lubomir Rintel 119e828dbe example/python: avoid falling back to CLOCK_MONOTONIC
According to the D-Bus API specification we return CLOCK_BOOTTIME only.
We don't support kernels too old to have it -- the fall back to
CLOCK_MONOTONIC is only there to be able to run unit tests on RHEL 6
kernel and will eventually go away.
2018-06-14 17:30:06 +02:00
Thomas Haller fd878d8261 examples: add ipv4.dhcp-client-id and ipv6.dhcp-duid to 30-anon.conf example 2018-06-12 14:45:40 +02:00
Lubomir Rintel e69d386975 all: use the elvis operator wherever possible
Coccinelle:

  @@
  expression a, b;
  @@
  -a ? a : b
  +a ?: b

Applied with:

  spatch --sp-file ternary.cocci --in-place --smpl-spacing --dir .

With some manual adjustments on spots that Cocci didn't catch for
reasons unknown.

Thanks to the marvelous effort of the GNU compiler developer we can now
spare a couple of bits that could be used for more important things,
like this commit message. Standards commitees yet have to catch up.
2018-05-10 14:36:58 +02:00
Beniamino Galvani 1b5925ce88 all: remove consecutive empty lines
Normalize coding style by removing consecutive empty lines from C
sources and headers.

https://github.com/NetworkManager/NetworkManager/pull/108
2018-04-30 16:24:52 +02:00
Thomas Haller 735dc41bd0 libnm: rework checkpoint API
The libnm API fir checkpoints was only introduced with 1.11. It
is not yet stable, so there is still time to adjust it. Note that
this changes API/ABI of the development branch.

Changes:

- we only add async variants of the checkpoint functions. I believe
  that synchronous D-Bus methods are fundamentally flawed, because
  they mess up the ordering of events.
  Rename the async functions by removing the "_async" suffix. This
  matches glib style, for which the async form is also not specially
  marked.

- for function that refere to a particular checkpoint (rollback and
  destroy), accept the D-Bus path as string, instead of an NMCheckpoint
  instance. This form is more flexible, because it allows to use
  the function without having a NMCheckpoint instance at hand. On the
  other hand, if one has a NMCheckpoint instance, he can trivially
  obtain the path to make the call.
2018-04-04 14:02:13 +02:00
Thomas Haller 2a30bef856 examples: improve checkpoint.py for python/gi
- make python2 and python3 compatible
- support Checkpoint create flags (requires recent libnm for GI
  of flags)
- support adjust-rollback-timeout command
- print elapsed time in show output
2018-04-04 14:02:13 +02:00
Thomas Haller d14b9b8215 examples: add python utils for examples
We need common operations from the python scripts.
For example, to print the boot-time.

Move such utils to a separate nmex.py file ("ex" for
example). This file should contain helper functions that
are pure python (or, if the have requirements, load them
only on demand, so that examples that need those have
additional dependencies). It should also be simple to extract
individual helpers from nmex, so that the user can take an
example, merge parts of nmex.py in, and modify it to his needs.
2018-04-04 14:02:13 +02:00
Thomas Haller ab8312a18e checkpoint: generate GIR information for NMCheckpointCreateFlags
Note that this changes API for checkpoint_create_async() in Python
via GIR. Previously it would require an integer argument, now a flags
argument. But this API is still unstable, it will be introduced with
1.12.
2018-04-04 14:02:13 +02:00
Thomas Haller 28da0154fc all: drop trailing spaces 2018-02-07 13:32:04 +01:00
Thomas Haller e4839accf5 all: replace non-leading tabs with spaces
We commonly only allow tabs at the beginning of a line, not
afterwards. The reason for this style is so that the code
looks formated right with tabstop=4 and tabstop=8.
2018-02-07 13:32:04 +01:00
Thomas Haller 9ef17869b5 version: drop NM_VERSION_MAX_ALLOWED defines for internal build
It already defaults to the right value. We only need to define
NM_VERSION_MIN_REQUIRED, so that parts of our internal build
can make use of deprecated API.
2018-01-23 10:50:34 +01:00
Thomas Haller 8a040c6883 version: combine NM_VERSION_CUR_STABLE and NM_VERSION_NEXT_STABLE
We don't need to have two version defines "CUR" and "NEXT".

The main purpose of these macros (if not their only), is to
make NM_AVAILABLE_IN_* and NM_DEPRECATED_IN_* macros work.

1) At the precise commit of a release, "CUR" and "NEXT" must be identical,
because whenever the user configures NM_VERSION_MIN_REQUIRED and
NM_VERSION_MAX_ALLOWED, then they both compare against the current
version, at which point "CUR" == "NEXT".

2) Every other commit aside the release, is a development version that leads
up the the next coming release. But as far as versioning is concerned, such
a development version should be treated like that future release. It's unstable
API and it may or may not be close to later API of the release. But
we shall treat it as that version. Hence, also in this case, we want to
set both "NM_VERSION_CUR_STABLE" and again NEXT to the future version.

This makes NM_VERSION_NEXT_STABLE redundant.

Previously, the separation between current and next version would for
example allow that NM_VERSION_CUR_STABLE is the previously release
stable API, and NM_VERSION_NEXT_STABLE is the version of the next upcoming
stable API. So, we could allow "examples" to make use of development
API, but other(?) internal code still restrict to unstable API. But it's
unclear which other code would want to avoid current development.

Also, the points 1) and 2) were badly understood. Note that for our
previousy releases, we usually didn't bump the macros at the stable
release (and if we did, we didn't set them to be the same). While using
two macros might be more powerful, it is hard to grok and easy to
forget to bump the macros a the right time. One macro shall suffice.

All this also means, that *immediately* after making a new release, we shall
bump the version number in `configure.ac` and "NM_VERSION_CUR_STABLE".
2018-01-23 10:50:34 +01:00
Lubomir Rintel 8a46b25cfa all: require glib 2.40
RHEL 7.1 and Ubuntu 14.04 LTS both have this.

https://bugzilla.gnome.org/show_bug.cgi?id=792323
2018-01-18 11:45:36 +01:00
Iñigo Martínez 5e16bcf268 meson: Improve dependency system
Some targets are missing dependencies on some generated sources in
the meson port. These makes the build to fail due to missing source
files on a highly parallelized build.

These dependencies have been resolved by taking advantage of meson's
internal dependencies which can be used to pass source files,
include directories, libraries and compiler flags.

One of such internal dependencies called `core_dep` was already in
use. However, in order to avoid any confusion with another new
internal dependency called `nm_core_dep`, which is used to include
directories and source files from the `libnm-core` directory, the
`core_dep` dependency has been renamed to `nm_dep`.

These changes have allowed minimizing the build details which are
inherited by using those dependencies. The parallelized build has
also been improved.
2018-01-10 12:20:17 +01:00
Iñigo Martínez 0735b35dd0 build: use template files for enum types' sources generation
Source files for enum types are generated by passing segments of the
source code of the files to the `glib-mkenums` command.

This patch removes those parameters where source code is used from
meson build files by moving those segmeents to template files.

https://mail.gnome.org/archives/networkmanager-list/2017-December/msg00057.html
2017-12-18 11:25:06 +01:00
Iñigo Martínez 03637ad8b5 build: add initial support for meson build system
meson is a build system focused on speed an ease of use, which
helps speeding up the software development. This patch adds meson
support along autotools.

[thaller@redhat.com: rebased patch and adjusted for iwd support]

https://mail.gnome.org/archives/networkmanager-list/2017-December/msg00022.html
2017-12-13 15:48:50 +01:00
Thomas Haller 8388f4ea1d examples: add python/gi example nm-connection-update-stable-id.py
The example script touches the stable-id of a connection.
It does so blocking autoconnect, and was originally written
to test that functionality.
2017-12-05 19:57:24 +01:00
Yifan J 797d9c4403 python: make dbus, gi examples, and debug-helper.py python3 ready
https://bugzilla.gnome.org/show_bug.cgi?id=791121
2017-12-04 11:21:40 +01:00
Beniamino Galvani 77d3b1555e examples: add checkpoint example using python gobject-introspection 2017-11-09 10:12:30 +01:00
Thomas Haller f4458dd157 examples: add python example using VPN import code
Show how to load and use the VPN plugins from python.
2017-11-06 18:37:05 +01:00
Lubomir Rintel d529641756 examples/js: add a javascript example
Converted from python/gi/get_ip.py.
2017-11-06 11:47:05 +01:00
Lucas Rangit Magasweran 843ea77e93 examples: linker requires that library dependencies follow use
On modern distributions, ld runs with the '--as-needed' option
enabled by default, meaning library dependencies must come after
files that require them. Also, this allows indirect linking so the
build commands can be simplified.

The alternative is to add the '-Wl,--no-as-needed' gcc option or
use the top-level Makefile.

Tested on:
 * Ubuntu 16.04.3 with gcc Ubuntu 5.4.1-8ubuntu1
 * Fedora 24 with gcc Red Hat 6.1.1-3

Signed-off-by: Lucas Magasweran <lucas.magasweran@ieee.org>

https://mail.gnome.org/archives/networkmanager-list/2017-September/msg00022.html
https://mail.gnome.org/archives/networkmanager-list/2017-September/msg00023.html
https://mail.gnome.org/archives/networkmanager-list/2017-September/msg00025.html
2017-09-21 13:14:56 +02:00
Thomas Haller adcbcb15e5 examples: add setting-user-data.py
Add an example python script to show and set setting's
user-data. This is useful, as nmcli still doesn't support
user data.

(cherry picked from commit 447c766f52)
2017-05-06 14:53:09 +02:00
Thomas Haller 6198c2a5a4 build: declare build dependencies requiring "nm-core-enum-types.h"
cat <<-EOF > /tmp/glib-mkenums
	#!/bin/bash
	sleep 15 && /usr/bin/glib-mkenums "\$@"
	EOF

	chmod +x /tmp/glib-mkenums

	(export PATH="/tmp:$PATH" &&
	 git clean -fdx &&
	 ./autogen.sh &&
	 make -j20 all-am)

(cherry picked from commit 68ab166f38)
2017-03-29 11:26:27 +02:00
Thomas Haller b869d9cc0d device: add spec "driver:" to match devices
Changing the MAC address of devices is known to fail with
certain drivers. Add a device-spec to allow disabling it
for for such devices.

Related: https://bugzilla.gnome.org/show_bug.cgi?id=777523
2017-03-17 17:40:00 +01:00
Thomas Haller 831286df30 include: use double-quotes to include our own headers
In practice, this should only matter when there are multiple
header files with the same name. That is something we try
to avoid already, by giving headers a distinct name.

When building NetworkManager itself, we clearly want to use
double-quotes for including our own headers.
But we also want to do that in our public headers. For example:

  ./a.c
    #include <stdio.h>
    #include <nm-1.h>
    void main() {
        printf ("INCLUDED %s/nm-2.h\n", SYMB);
    }

  ./1/nm-1.h
    #include <nm-2.h>

  ./1/nm-2.h
    #define SYMB "1"

  ./2/nm-2.h
    #define SYMB "2"

$ cc -I./2 -I./1 ./a.c
$ ./a.out
INCLUDED 2/nm-2.h

Exceptions to this are
  - headers in "shared/nm-utils" that include <NetworkManager.h>. These
    headers are copied into projects and hence used like headers owned by
    those projects.
  - examples/C
2017-03-09 14:12:35 +01:00
Thomas Haller 6fa069fad1 example: add example configuration snippet '30-anon.conf' 2017-01-09 14:50:33 +01:00
Beniamino Galvani 8af465d579 examples: add DNS example with python and GObject introspection 2016-12-12 22:06:24 +01:00
Thomas Haller 2837da9b30 examples/python: fix "import gi" in example
Otherwise there is a warning:

  from gi.repository import GLib, NM
  __main__:1: PyGIWarning: NM was imported without specifying a version first. Use gi.require_version(NM, 1.0) before import to ensure that the right version gets loaded.
2016-11-16 11:50:30 +01:00
Thomas Haller 351851cf27 build: merge "examples/Makefile.am" into toplevel Makefile 2016-10-21 17:37:57 +02:00
Thomas Haller b648772fc4 build: merge "examples/C/qt/Makefile.am" into toplevel Makefile 2016-10-21 17:37:57 +02:00
Thomas Haller 742d36c476 build: merge "examples/C/glib/Makefile.am" into toplevel Makefile 2016-10-21 17:37:57 +02:00
Beniamino Galvani 1ab616b59c checkpoint: make python example accept multiple devices and timeout
Add a timeout parameter and allow passing multiple interfaces to make
the script more useful for testing purposes.
2016-09-26 15:10:39 +02:00
Beniamino Galvani 048801add3 checkpoint: add python D-Bus example 2016-08-17 14:55:34 +02:00
Beniamino Galvani 76348adb8e examples: fix crash in add-connection-libnm
Reported-by: Ali Nematollahi <alirezan1@gmail.com>
2016-04-20 07:48:17 +02:00
Thomas Haller 05f17ace71 man: fix typo in NetworkManager.conf manual and 10-ifcfg-rh-routes.sh comment 2016-03-31 20:46:52 +02:00
Lubomir Rintel 3a2803b42c docs: replace spec.html with docbook D-Bus API reference
May use a lot of improvement (actually documenting the names and
objects that use the interfaces in question), but at least this looks a
lot better on developer.gnome.org.
2016-03-26 11:28:19 +01:00
Adrian Likins 6c59443ad5 Fix missing commas in list-devices devtypes dict. 2016-03-02 18:43:28 +01:00
Thomas Haller 1b00009169 device: add new NMDeviceType NM_DEVICE_TYPE_VETH
Based-on-patch-by: Jiří Klimeš <jklimes@redhat.com>
2016-02-23 23:15:37 +01:00
Thomas Haller 71962881a8 examples: add missing device-types to examples
Based-on-patch-by: Jiří Klimeš <jklimes@redhat.com>
2016-02-23 15:24:39 +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
Dan Williams 91f06323c7 examples: avoid compile errors around NM versioning 2016-01-28 12:27:14 -06:00
Thomas Haller bc7ad75d99 contrib/rpm: install pre-up dispatcher script "10-ifcfg-rh-routes.sh" as no-wait
The main reason to introduce the "no-wait.d" dispatcher directory was
"10-ifcfg-rh-routes.sh", which (as a pre-up script) delays activation.
We even extracted the script to a separate package on RHEL to avoid
delays by default.

Invoke the script via no-wait.d.
2016-01-08 14:27:18 +01:00
Thomas Haller db80ec05ab build: rename directory "include" to "shared"
Up to now, the "include" directory contained (only) header files that were
used project-wide by libs, core, clients, et al.

Since the directory now also contains a non-header file, the "include"
name is misleading. Instead of adding yet another directory that is
project-wide, with non-header-only content, rename the "include"
directory to "shared".
2015-12-24 11:42:37 +01:00
Thomas Haller 14bb9419a0 examples: add README for python-networkmanager NetworkManager library 2015-12-07 16:06:46 +01:00
Thomas Haller 5b732c3b9f examples: add README for examples/python/gi 2015-12-07 15:59:20 +01:00
Dan Williams 4db851f852 libnm/libnm-glib: add NMClient.get_all_devices() method and AllDevices property
Mirror new NetworkManager API to return both real devices and
device placeholders.
2015-12-04 12:16:41 +01:00
Thomas Haller 8d1233e67e python: use gi.require_version() in generate-setting-docs.py and examples
gi now emits a warning when not loading a specific library
version [1]:

  ./generate-setting-docs.py:21: PyGIWarning: NM was imported without specifying a version first. Use gi.require_version(NM, 1.0) before import to ensure that the right version gets loaded.
    from gi.repository import NM, GObject

Seems require_version() is reasonably old to just always use it without
breaking on older versions [2].

[1] Related: https://bugzilla.gnome.org/show_bug.cgi?id=727379
[2] https://git.gnome.org/browse/pygobject/commit/?id=76758efb6579752237a0dc4d56cf9518de6c6e55
2015-11-11 10:56:05 +01:00
Beniamino Galvani bd4df767c6 examples: add python GI example for retrieving LLDP neighbors 2015-10-12 14:44:31 +02:00
Thomas Haller 7bf10a75db build: extract version macros from "nm-version.h" to new header file "nm-version-macros.h"
For libnm library, "nm-dbus-interface.h" contains defines like the D-Bus
paths of NetworkManager. It is desirable to have this header usable without
having a dependency on "glib.h", for example for a QT application. For that,
commit c0852964a8 removed that dependancy.

For libnm-glib library, the analog to "nm-dbus-interface.h" is
"NetworkManager.h", and the same applies there. Commit
159e827a72 removed that include.
However, that broke build on PackageKit [1] which expected to get the
version macros by including "NetworkManager.h". So at least for libnm-glib,
we need to preserve old behavior so that a user including
"NetworkManager.h" gets the version macros, but not "glib.h".

Extract the version macros to a new header file "nm-version-macros.h".
This header doesn't include "glib.h" and can be included from
"NetworkManager.h". This gives as previous behavior and a glib-free
include.

For libnm we still don't include "nm-version-macros.h" to "nm-dbus-interface.h".
Very few users will actually need the version macros, but not using
libnm.
Users that use libnm, should just include (libnm's) "NetworkManager.h" to
get all headers.
As a special case, a user who doesn't want to use glib/libnm, but still
needs both "nm-dbus-interface.h" and "nm-version-macros.h", can include
them both separately.

[1] https://github.com/hughsie/PackageKit/issues/85

Fixes: 4545a7fe96
2015-09-30 23:10:29 +02:00
Jiří Klimeš 8e3ae81566 examples: generate UUID in add-wifi-eap-connection.py
so that it can be run multiple times.
2015-09-17 14:49:04 +02:00
Jiří Klimeš a25bbde641 examples: add a python example for adding WPA PSK Wi-Fi connection
and rename add-system-wifi-connection.py to add-wifi-eap-connection.py
2015-09-17 14:46:19 +02:00
Jiří Klimeš cb64067b7a examples: add flags and mode parsing to show-wifi-networks.[lua|py] 2015-08-24 12:33:04 +02:00
Dan Williams d1d048c93d examples: add python+dbus example to print active access point 2015-07-08 09:31:22 -05:00
Jiří Klimeš eebfe56a90 examples: python: add an D-Bus example creating and activating a bond 2015-06-23 15:06:31 +02:00
Jiří Klimeš 1e923cb923 examples: add wifi-hotspot.py script to Makefile.am
Fixes: 1af8e2f132
2015-06-23 15:04:43 +02:00
Dan Williams 1af8e2f132 examples: add DBus + Python example for starting/stopping a WiFi hotspot 2015-05-18 15:11:12 -05:00
Petr Vorel 1e646f30f2 examples: bash: print errors int stderr
+ whitespace

Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
2015-03-18 15:07:59 -05:00
Srdjan Grubor 0e1fe1fe4e examples: update Python NM example to print detailed connection state
Current Python NM example has a very crude connection state output
and the global NM connectivity is not used in them either.

https://bugzilla.gnome.org/show_bug.cgi?id=746045
2015-03-12 10:39:00 +01:00
Petr Vorel 4213c17b44 examples: python: print into stderr
https://mail.gnome.org/archives/networkmanager-list/2015-March/msg00024.html

Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
2015-03-10 12:17:59 +01:00
Thomas Haller 2171084378 examples/trvial: replace tabs by whitespace in python example 2015-03-10 12:17:23 +01:00
Jiří Klimeš 6b5de0ab5f examples: add a Python example deactivating connections by type (bgo #732826)
https://bugzilla.gnome.org/show_bug.cgi?id=732826
2015-03-05 15:59:52 +01:00
Jiří Klimeš 489f80e3c0 examples: add a Lua example deactivating connections by type (bgo #732826)
https://bugzilla.gnome.org/show_bug.cgi?id=732826
2015-03-05 15:59:32 +01:00
Jiří Klimeš 37becd2ee6 examples: add a Lua example setting user name for a VPN connection 2015-02-11 13:34:38 +01:00
Jiří Klimeš 21c9c7e21c examples: add a Lua example getting IP configuration of a device
Unfortunately, there is a bug in lgi library causing the incorrect values
being returned and the example crashes. I am going to send a patch to lgi
to fix the issues.
2015-02-10 10:35:41 +01:00
Jiří Klimeš f124848b60 examples: add a Lua example showing basic NetworkManager information 2015-02-09 10:11:18 +01:00
Jiří Klimeš 3d991b8e32 examples: add a Lua example for getting Wi-Fi access points 2015-02-09 10:11:12 +01:00
Jiří Klimeš 6be3d7cbad examples: add some examples in Lua using lgi library
[libnm]     https://developer.gnome.org/libnm/1.0/
[lgi]       https://github.com/pavouk/lgi
[lgi-guide] https://github.com/pavouk/lgi/blob/master/docs/guide.md

On most distribution just install lua-lgi.

Note:
There is a bug in lgi. It doesn't handle GPtrArray corectly. It results in
crashing on list-devices.lua and list-connections.lua.
I will send a patch to lgi to fix the issue.
2015-01-30 14:41:13 +01:00
Dan Winship 8de1bec803 dispatcher: fix ifcfg-rh example dispatcher script (rh #1160013)
Routing table entries for a device get flushed when the device is
deactivated, but rules table entries don't, so we have to flush them
by hand.
2015-01-27 13:51:45 -05:00
Dan Winship f79d62692e ifcfg-rh: allow handling complex routing rules via dispatcher (rh #1160013)
If a connection has an associated "rule-NAME" or "rule6-NAME" file,
don't try to read in the routes, since NetworkManager won't be able to
parse them correctly. Instead, log a warning that they will need to be
applied via a dispatcher script, and provide a script that would do
that in examples/dispatcher/.
2015-01-12 09:53:24 -05:00
Dan Winship 66936decfa examples: update python examples
Update the raw D-Bus python examples to use newer APIs where
appropriate (and split the add-connection example into 1.0-only and
0.9-compatible versions). Update the gi-based python examples for the
various API changes since they were last updated.

Also add a comment to the ruby add-connection example pointing out
that it's still using the old settings APIs.
2014-11-15 09:31:49 -05:00
Dan Winship 3bfb163a74 all: consistently include config.h
config.h should be included from every .c file, and it should be
included before any other include. Fix that.

(As a side effect of how I did this, this also changes us to
consistently use "config.h" rather than <config.h>. To the extent that
it matters [which is not much], quotes are more correct anyway, since
we're talking about a file in our own build tree, not a system
include.)
2014-11-13 17:18:42 -05:00
Dan Winship 3f30c6f1c2 libnm-core: extract NMSettingIPConfig superclass out of IP4, IP6 classes
Split a base NMSettingIPConfig class out of NMSettingIP4Config and
NMSettingIP6Config, and update things accordingly.

Further simplifications of now-redundant IPv4-vs-IPv6 code are
possible, and should happen in the future.
2014-11-07 07:49:40 -05:00
Thomas Haller 0923769285 test,examples: fix scripts to avoid 'has_key' for Python 3
'has_key' on Dictionaries is removed from Python3 in favor of 'in'.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-31 16:39:00 +01:00
Dan Winship 6ae4224850 libnm: change GSList to GPtrArray in libnm methods
libnm mostly used GPtrArrays in its APIs, except that arrays of
connections were usually GSLists. Fix this and make them GPtrArrays
too (and rename nm_client_list_connections() to
nm_client_get_connections() to match everything else).
2014-10-28 17:17:17 -04:00
Dan Winship 6f3d1f9526 libnm: merge NMRemoteSettings into NMClient
Make NMRemoteSettings internal and have NMClient wrap all of its APIs,
just like it does with NMManager.
2014-10-10 12:40:19 -04:00
Dan Winship 2237ea3ddb libnm: make sync/async APIs more GLib-like
Make synchronous APIs take GCancellables, and make asynchronous APIs
use GAsyncReadyCallbacks and have names ending in "_async", with
"_finish" functions to retrieve the results.

Also, make nm_client_activate_connection_finish(),
nm_client_add_and_activate_finish(), and
nm_remote_settings_add_connection_finish() be (transfer full) rather
than (transfer none), because the refcounting semantics become
slightly confusing in some edge cases otherwise.
2014-09-25 09:29:20 -04:00
Dan Winship 6ca10677d6 libnm: merge saved and unsaved connection methods
Merge nm_remote_settings_add_connection() and
nm_remote_settings_add_connection_unsaved(), and likewise
nm_remote_connection_commit_changes() and
nm_remote_connection_commit_changes_unsaved(), by adding a boolean
flag to each saying whether to save to disk.
2014-09-25 09:29:20 -04:00
Jiří Klimeš 4359e556e4 tui,examples: accept null SSID gracefully
Signed-off-by: Jiří Klimeš <jklimes@redhat.com>

https://bugzilla.gnome.org/show_bug.cgi?id=736802
2014-09-19 09:07:16 -04:00
Dan Winship 6793a32a8c libnm: port to GDBus
Port libnm-core/libnm to GDBus.

The NetworkManager daemon continues to use dbus-glib; the
previously-added connection hash/variant conversion methods are now
moved to NetworkManagerUtils (along with a few other utilities that
are now only needed by the daemon code).
2014-09-18 11:51:09 -04:00
Jiří Klimeš 85909d080f examples: fix python GI examples to work after libnm changes 2014-09-05 13:48:56 +02:00
Dan Winship 9e5ddb5830 examples: port dbus-glib-based examples to gdbus
Port the dbus-glib-based examples to GDBus.

Also, don't use libnm in them at all; there's not much point in
examples that use the D-Bus API directly if they're just going to fall
back to libnm for the hard stuff... (And also, this avoids the problem
that GDBus uses GVariant, while the libnm-core APIs currently still
use GHashTables.)

Also fix up some comment grammar and copyright style, and add emacs
modelines where missing.

Also rename the existing GDBus-based examples to have names ending in
"-gdbus", not "-GDBus", since there's no reason to gratuitously
capitalize here.
2014-09-04 18:19:22 -04:00
Dan Winship 3e5b3833aa libnm: change empty-GPtrArray-return semantics
libnm functions that return GPtrArrays of objects had a rule that if
the array was empty, they would return NULL rather than a 0-length
array. As it turns out, this is just a nuisance to clients, since in
most places the code for the non-empty case would end up doing the
right thing for the empty case as well (and where it doesn't, we can
check "array->len == 0" just as easily as "array == NULL"). So just
return the 0-length array instead.
2014-09-04 09:21:05 -04:00
Dan Winship 20dc44bda9 libnm: drop NM_TYPE_SSID, use G_TYPE_BYTES
Make NMAccessPoint:ssid be G_TYPE_BYTES and update the corresponding
APIs accordingly.
2014-09-04 09:21:04 -04:00
Dan Winship 3fbabde4c3 libnm-core: replace GByteArray with pointer + length in some APIs
APIs that take arbitrary data should take it in the form of a pointer
and length, not a GByteArray, so that you can use them regardless of
what format you have the data in (GByteArray, GBytes, plain array,
etc).
2014-09-04 09:20:11 -04:00
Dan Winship 773d3f0ab6 libnm-core: rename NMConnection to/from_hash methods
Rename nm_connection_to_hash() to nm_connection_to_dbus(), and
nm_connection_new_from_hash() to nm_connection_new_from_dbus(). In
addition to clarifying that this is specifically the D-Bus
serialization format, these names will also work better in the
GDBus-based future where the serialization format is GVariant, not
GHashTable.

Also, move NMSettingHashFlags to nm-connection.h, and rename it
NMConnectionSerializationFlags.
2014-09-04 09:17:36 -04:00
Dan Winship e1ba13a426 libnm-core, libnm, core: make NMConnection an interface
The fact that NMRemoteConnection has to be an NMConnection and
therefore can't be an NMObject means that it needs to reimplement bits
of NMObject functionality (and likewise NMObject needs some special
magic to deal with it). Likewise, we will need a daemon-side
equivalent of NMObject as part of the gdbus port, and we would want
NMSettingsConnection to be able to inherit from this as well.

Solve this problem by making NMConnection into an interface, and
having NMRemoteConnection and NMSettingsConnection implement it. (We
use some hacks to keep the GHashTable of NMSettings objects inside
nm-connection.c rather than having to be implemented by the
implementations.)

Since NMConnection is no longer an instantiable type, this adds
NMSimpleConnection to replace the various non-D-Bus-based uses of
NMConnection throughout the code. nm_connection_new() becomes
nm_simple_connection_new(), nm_connection_new_from_hash() becomes
nm_simple_connection_new_from_hash(), and nm_connection_duplicate()
becomes nm_simple_connection_new_clone().
2014-08-16 10:17:53 -04:00
Dan Winship 57e802f3aa libnm: port NMRemoteSettings to NMObject
NMRemoteSettings duplicates a bunch of NMObject's functionality that
it doesn't need to. In libnm-glib, it wouldn't have been possible to
port NMRemoteSettings to NMObject without breaking ABI, but now in
libnm we can do that.

As a side effect of this, NMRemoteSettings gains a "connections"
property, and "connection-added" and "connection-removed" signals
(with the former replacing the old "new-connection" signal). This also
removes the "connections-loaded" signal, since the connections will
now always be loaded (via the initialization of the "connections"
property) during init()/init_async().

Also, this removes NMRemoteConnection's "removed" signal, since it's
redundant with the new NMRemoteSettings::connection-removed (and
having the signal on NMRemoteSettings instead is more consistent with
other objects).
2014-08-07 15:43:43 -04:00
Dan Winship 8ce06b814c libnm: synchronize NMClient and NMRemoteSettings "is NM running" properties
Rename NMClient:manager-running and NMRemoteSettings:service-running
to both be :nm-running.
2014-08-07 15:43:43 -04:00
Dan Winship d0b05b34d5 libnm: add NetworkManager.h, disallow including individual headers
Add NetworkManager.h, which includes all of the other NM header, and
require all external users of libnm to use that rather than the
individual headers.

(An exception is made for nm-dbus-interface.h,
nm-vpn-dbus-interface.h, and nm-version.h, which can be included
separately.)
2014-08-01 14:34:40 -04:00
Dan Winship 3ddce74803 libnm: rename NetworkManager.h and NetworkManagerVPN.h
"NetworkManager.h"'s name (and non-standard capitalization) suggest
that it's some sort of high-level super-important header, but it's
really just low-level D-Bus stuff. Rename it to "nm-dbus-interface.h"
and likewise "NetworkManagerVPN.h" to "nm-vpn-dbus-interface.h"
2014-08-01 14:34:40 -04:00
Dan Winship 258e74eb0c libnm: make the the use of GInitable mandatory
Remove _nm_object_ensure_inited(), etc; objects that implement
GInitable are now mandatory-to-init().

Remove constructor() implementations that sometimes return NULL; do
all the relevant checking in init() instead.

Make nm_client_new() and nm_remote_settings_new() take a GCancellable
and a GError**.
2014-08-01 14:34:40 -04:00
Dan Winship f441cf2b90 libnm: consistently use "INTERFACE" rather than "IFACE" in macros
Most D-Bus interface name macros used "INTERFACE" in their name (eg,
NM_DBUS_INTERFACE), but a few used "IFACE" instead (eg,
NM_DBUS_IFACE_SETTINGS). Make them consistent.
2014-08-01 14:34:06 -04:00
Dan Winship a7c4d53d03 all: port everything to libnm
Since the API has not changed at this point, this is mostly just a
matter of updating Makefiles, and changing references to the library
name in comments.

NetworkManager cannot link to libnm due to the duplicated type/symbol
names. So it links to libnm-core.la directly, which means that
NetworkManager gets a separate copy of that code from libnm.so.
Everything else links to libnm.
2014-08-01 14:34:05 -04:00
Dan Winship 30c74c6007 build: more srcdir!=builddir fixes
nm-version.h was getting disted, making srcdir!=builddir work for
tarball builds, but not for git builds.

Also, remove "-I${top_builddir}/include" from all Makefile.ams, since
there's nothing generated in include/ any more.
2014-07-15 11:37:19 -04:00
Dan Winship 7eb0288aa0 libnm-util: move NetworkManager.h, etc, from include/ to here
NetworkManager.h, NetworkManagerVPN.h, and nm-version.h are part of
the libnm-util API, so move them to libnm-util.

include/ still contains headers that are strictly NM-internal (eg,
nm-glib-compat.h).
2014-07-15 09:44:54 -04:00
Dan Williams 5a4e42bc51 examples: add Python dbus example indicating if WWAN is the default connection 2014-06-20 10:54:03 -05:00
Dan Williams e8fb3864d1 examples: add Python D-Bus and GI examples for updating IPv4 setting method 2014-06-10 16:20:35 -05:00
Jiří Klimeš b4544182a2 examples: fix get-active-connections-dbus-glib.c example 2014-06-09 10:16:09 +02:00
Thomas Haller b633711572 libnm-glib: don't use deprecated nm_access_point_get_hw_address()
nm_access_point_get_hw_address() is already deprecated since
pre-0.9.0-beta3 (f30e15a04d). However,
it also is defined as NM_DEPRECATED_IN_0_9_10, because there
are no deprecated macros for previous version.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-07 11:19:02 +02:00
Jiří Klimeš 98ae6e06d2 all: g_type_init() has been deprecated in GLib 2.35.0
g_type_init() deprecation:
https://bugzilla.gnome.org/show_bug.cgi?id=686161
2014-05-27 16:58:21 +02:00
Dan Williams b77b7510d6 examples: update 70-wifi-wired-exclusive.sh (bgo #513488)
Tighten up with suggestions from  Johannes Buchner and mention
his contribution.

Also fixes operation with current nmcli since it changed from
"802-3-ethernet" -> "ethernet" and thus the script was broken.

https://bugzilla.gnome.org/show_bug.cgi?id=513488
2014-04-28 17:07:02 -05:00
Thomas Haller 2748bcfebf examples: fix qt demo to work without STL support
The function toStdString() is only available when QT was
compiled with STL support. The configure script does
not check STL support and might build the QT examples
even if toStdString() is not available.

Fix this, by not using the function.

This fixes the previous commit f73e3669b3
that I pushed accidentally.

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

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-04-04 23:20:05 +02:00
Thomas Haller f73e3669b3 examples: fix qt demo to work without STL support
The function toStdString() is only available when QT was
compiled with STL support. The configure script does
not check STL support and might build the QT examples
even if toStdString() is not available.

Fix this, by not using the function.

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

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-04-04 17:06:08 +02:00
Jiří Klimeš 7211d82f77 examples: use correct Mbit/s for bitrates 2014-04-01 15:15:18 +02:00
Jiří Klimeš 524658f8a3 examples: fix Makefile.am to include all Python examples for distribution 2014-03-07 19:54:49 +01:00
Jiří Klimeš 3e44e7a9f8 example: simplify get-active-connections.py by using ID and Type properties 2014-03-05 16:17:13 +01:00
Jiří Klimeš 550ce1e631 examples: add a GOI Python example for getting active connections 2014-03-03 15:15:08 +01:00
Jiří Klimeš f24eee5ee3 examples: also print type of active connections 2014-03-03 14:28:51 +01:00
Jiří Klimeš d96d242bc6 examples: a Python GOI example for adding connections persistent vs. not saved 2014-01-24 12:24:01 +01:00
Jiří Klimeš 85272df6eb examples: update get_ips.py python example for DNS information 2014-01-23 12:56:45 +01:00
Jiří Klimeš 68fe50ff3a examples: add an python example (using GI) getting device IPs 2014-01-16 17:37:16 +01:00
William Jon McCann 74372f9f11 docs: update documentation links
Various GNOME services moved around so links need updating.
2013-12-17 12:07:51 -06:00
Jiří Klimeš aa54604f59 examples: update examples for new device types 2013-11-29 09:29:56 +01:00
Thomas Haller 97935382f4 coverity: fix various warnings detected with Coverity
These are (most likely) only warnings and not severe bugs.
Some of these changes are mostly made to get a clean run of
Coverity without any warnings.

Error found by running Coverity scan

https://bugzilla.redhat.com/show_bug.cgi?id=1025894

Co-Authored-By: Jiří Klimeš <jklimes@redhat.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-11-13 15:29:24 +01:00
Thomas Haller 3eb1d5e902 core: cleanup freeing of glib collections of pointers
When freeing one of the collections such as GArray, GPtrArray, GSList,
etc. it is common that the items inside the connections must be
freed/unrefed too.

The previous code often iterated over the collection first with
e.g. g_ptr_array_foreach and passing e.g. g_free as GFunc argument.
For one, this has the problem, that g_free has a different signature
GDestroyNotify then the expected GFunc. Moreover, this can be
simplified either by setting a clear function
(g_ptr_array_set_clear_func) or by passing the destroy function to the
free function (g_slist_free_full).

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-10-22 19:53:57 +02:00
Jiří Klimeš f820fbeeb3 examples: add an python example (using GI) showing Wi-Fi networks 2013-09-26 16:30:23 +02:00
Jiri Popelka a20fd994f4 examples: use GLib.MainLoop instead of deprecated GObject.MainLoop in python
jklimes:
made the change for new firewall-zone.py example as well.
2013-09-24 13:33:37 +02:00
Jiří Klimeš 8a04ab9135 examples: group python examples - dbus vs. gi
Move examples using dbus-python ('dbus' module) and GObject introspection into
their own directories.
2013-09-24 12:52:33 +02:00
Jiří Klimeš 217cb5fbca examples: add a python example getting/setting zone property using GI 2013-09-24 12:48:55 +02:00
Dan Winship bfce3f7dc8 build: switch from $(INCLUDES) to $(AM_CPPFLAGS) to make automake happy
Unfortunately, $(AM_CPPFLAGS) gets overridden by per-target _CPPFLAGS
variables, which $(INCLUDES) did not, so this requires some additional
changes.

In most places, I have just gotten rid of the per-target _CPPFLAGS
variables; in directories with a single target, the per-target
variable is unnecessary, and in directories with multiple targets, the
per-target variable is often undesirable, since it forces some files
to be compiled twice, even though there ends up being no difference
between the two files.
2013-08-22 11:49:16 -04:00
Thomas Haller 471fed3859 trivial: minor code cleanup in examples/python
There where cases, where TAB was mixed with SPACES. Replace TAB with SPACES.
Additionally, make the script nm-state.py executable

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-08-06 13:48:02 -05:00
Jiří Klimeš 8de9bfcf7d examples: update 70-wifi-wired-exclusive.sh for new nmcli syntax 2013-07-15 15:52:23 +02:00
Pavel Šimerda 5277719dce trivial: add gitignore for qt examples 2013-04-29 14:14:11 +02:00
Martin Pitt 6226fb9b59 libnm-util: Fix transfer annotations of nm_{connection,setting}_need_secrets()
The various need_secrets() implementation do allocate a fresh GPtrArray, but
add static strings to them without dup'ing. Thus callers must _not_ free the
array elements, only the array itself. Adjust documentation and annotations
accordingly.

Also adjust the corresponding comment in the goi-list-connections.py example.

https://bugzilla.gnome.org/show_bug.cgi?id=698175
2013-04-19 09:43:56 -04:00
Jiří Klimeš 82fb1978a4 all: use G_VALUE_INIT to initialize GValue variables
It makes the initializations more explicit.
G_VALUE_INIT is available since glib 2.30, and NM now require glib >= 2.32
2013-03-25 08:41:18 +01:00
Dan Winship 279a347abf examples: remove GLIB_CHECK_VERSION checks from GDBus examples 2013-02-26 13:07:32 +01:00
Jiří Klimeš 8a9759af4b examples: fix nm-state.py example 2012-12-07 15:13:22 +01:00
Jiří Klimeš 8a0e928aed cli/examples: NM_802_11_MODE_AP mode is not valid for NMAccessPoint objects 2012-11-01 15:40:27 +01:00
Colin Walters 1977fb6c49 build: clean up GLib-related pkg-config usage (bgo #687218)
We had separate checks for glib-2.0, gobject-2.0, gmodule-2.0, and
gio-unix-2.0.  It doesn't make sense to link a binary against all 4
because gio-unix-2.0 depends on glib-2.0 and gobject-2.0.  Doing this
actually breaks things in unusual circumstances.

Generally, few bits of NM actually just use glib, and not gio.  We
might as well coalesce those requirements together, even if it means
in some cases we "overlink".  Additionally, I chose for now to fold
gmodule-2.0 in as well, even though many fewer programs need it.  The
cost of overlinking is quite small.

The benefit of this is less repeated junk in Makefile.am, as well as
more centralized control over GLib.  A followup patch will allow us to
set -DGLIB_VERSION_MIN_REQUIRED in just one place, rather than having
to replicate it 4 times.

The NM configure is still suboptimal - for example, libpolkit-1
depends on gio-2.0, so really we should determine the compiler flags
all in one pass.  But it doesn't matter too much for now.
2012-10-31 21:08:18 +01:00
Jan Luebbe f9c72dee3e wifi: support ap-mode with wpa_supplicant
A new value for NM80211Mode is introduced (NM_802_11_MODE_AP) and the
new mode is passed to wpa_supplicant analogous to adhoc-mode.
The places which need to know the interface mode have been extended to
handle the new mode.

If the configuration does not contain a fixed frequency, a channel is
selected the same way as with adhoc-mode before.
2012-10-17 12:08:11 -05:00
Jiří Klimeš 784af22159 examples: fix python example file names in EXTRA_DIST 2012-09-24 13:22:24 +02:00
Jiří Klimeš 033e8d2a77 examples: fix add-system-connection.py -> add-connection.py rename
It fixes 'make dist' that fails otherwise.
Found by pavlix.
2012-09-24 12:59:09 +02:00
Dan Williams aaa5d2f70f examples: add dispatcher example for exclusive wired/wifi 2012-09-20 10:19:11 -05:00
Jiří Klimeš ef4b0f1d77 examples: add a shell example listing active Wi-Fi networks on Wi-Fi devices 2012-09-03 11:57:49 +02:00
Jiří Klimeš 02478a807d examples: add a shell example for disconnecting devices 2012-08-31 14:24:44 +02:00
Jiří Klimeš 9d3fd87dd2 examples: port update-secrets example to NM 0.9 API 2012-08-29 10:13:06 +02:00
Jiří Klimeš 3b3060f2a5 examples: add IP converting functions and rename add-system-connection.py 2012-08-24 12:50:50 +02:00
Jiří Klimeš 3fe99e7ebf examples: update examples for new device types 2012-08-24 09:48:19 +02:00
Jiří Klimeš 495fae7a7b examples: add a python GObject Introspection example
It demonstrates getting NMIP4Config object after activating a device.
2012-06-13 13:28:43 +02:00
Dan Williams 53f6539f54 examples: add simply python GObject Introspection example
Unfortunately since libnm-glib/libnm-util make heavy use of
GHashTable and GValue, functions that deal with these types
can't be used from Python when using GObject Introspection,
since pygobject can't handle conversion between python types
and GValue/GHashTable very well.  You'll likely encounter
assertions like:

ERROR:pygi-argument.c:1755:_pygi_argument_to_object: assertion failed: (g_type_info_get_tag (key_type_info) != GI_TYPE_TAG_VOID)
Aborted
2012-06-11 14:46:33 -05:00
Colin Walters 74ec56d956 build: fix srcdir != builddir for new generated headers 2012-02-22 16:27:28 -06:00
Jiří Klimeš 0b57cc68fd examples: fix dependency on GDBus (it's available only in GLib >= 2.26) 2012-02-14 09:03:21 +01:00
Jiří Klimeš 0c83e6e3b1 examples: add C example for monitoring overall NetworkManager state 2012-02-13 15:41:35 +01:00