1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along
13 * with this program; if not, write to the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 *
16 * (C) Copyright 2011 Red Hat, Inc.
17 */
18
19 /*
20 * The example shows how to list connections from System Settings service using direct
21 * D-Bus call of ListConnections method.
22 * The example uses dbus-glib, libnm-util libraries.
23 *
24 * Compile with:
25 * gcc -Wall `pkg-config --libs --cflags glib-2.0 dbus-glib-1 libnm-util` list-connections-dbus.c -o list-connections-dbus
26 */
27
28 #include <glib.h>
29 #include <dbus/dbus-glib.h>
30 #include <stdio.h>
31
32 #include <NetworkManager.h>
33 #include <nm-utils.h>
34
35 #define DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH (dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH))
36
37 static void
38 list_connections (DBusGProxy *proxy)
39 {
40 int i;
41 GError *error = NULL;
42 GPtrArray *con_array;
43
44 /* Call ListConnections D-Bus method */
(1) Event check_return: |
Calling function "dbus_g_proxy_call(DBusGProxy *, char const *, GError **, GType, ...)" without checking return value (as is done elsewhere 24 out of 30 times). |
(7) Event unchecked_value: |
No check of the return value of "dbus_g_proxy_call(proxy, "ListConnections", &error, 0UL, dbus_g_type_get_collection("GPtrArray", dbus_g_object_path_get_g_type()), &con_array, 0UL)". |
Also see events: |
[example_checked][example_checked][example_checked][example_checked][example_checked] |
45 dbus_g_proxy_call (proxy, "ListConnections", &error,
46 /* No input arguments */
47 G_TYPE_INVALID,
48 DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, &con_array, /* Return values */
49 G_TYPE_INVALID);
50
51 for (i = 0; con_array && i < con_array->len; i++) {
52 char *connection_path = g_ptr_array_index (con_array, i);
53 printf ("%s\n", connection_path);
54 g_free (connection_path);
55 }
56 g_ptr_array_free (con_array, TRUE);
57 }
58
59 int main (int argc, char *argv[])
60 {
61 DBusGConnection *bus;
62 DBusGProxy *proxy;
63
64 /* Initialize GType system */
65 g_type_init ();
66
67 /* Get system bus */
68 bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
69
70 /* Create a D-Bus proxy; NM_DBUS_* defined in NetworkManager.h */
71 proxy = dbus_g_proxy_new_for_name (bus,
72 NM_DBUS_SERVICE,
73 NM_DBUS_PATH_SETTINGS,
74 NM_DBUS_IFACE_SETTINGS);
75
76 /* List connections of system settings service */
77 list_connections (proxy);
78
79 g_object_unref (proxy);
80 dbus_g_connection_unref (bus);
81
82 return 0;
83 }
84