2004-07-27 16:24:48 +00:00
|
|
|
/* nmclienttest - test app for NetworkManager
|
|
|
|
|
*
|
|
|
|
|
* Dan Williams <dcbw@redhat.com>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*
|
|
|
|
|
* (C) Copyright 2004 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
2004-06-24 14:18:37 +00:00
|
|
|
#include <glib.h>
|
2004-07-27 16:24:48 +00:00
|
|
|
#include <dbus/dbus.h>
|
2004-06-24 14:18:37 +00:00
|
|
|
#include <dbus/dbus-glib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char * get_active_device (DBusConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *message;
|
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
DBusMessageIter iter;
|
|
|
|
|
DBusError error;
|
|
|
|
|
char *device_path;
|
|
|
|
|
|
|
|
|
|
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
|
|
|
|
|
"/org/freedesktop/NetworkManager",
|
|
|
|
|
"org.freedesktop.NetworkManager",
|
|
|
|
|
"getActiveDevice");
|
|
|
|
|
if (message == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
2004-08-29 Colin Walters <walters@verbum.org>
* test/nminfotest.c: Include string.h and stdlib.h.
(get_network_string_property, get_networks_of_type): Return NULL.
* test/nmclienttest.c (get_device_name, get_active_device): Return
NULL.
* src/backends/NetworkManagerRedHat.c (nm_system_device_stop_dhcp): Just
use strlen, fgets always NULL-terminates the string.
* src/NetworkManagerDbus.c (nm_dbus_nmi_filter,
dbus_message_get_member): Remove /* in comment.
* src/NetworkManagerUtils.c (LOCKING_DEBUG): Ditto.
* src/NetworkManager.c (quit): Unused, delete.
(nm_data_free): Cast arg to GFunc.
* panel-applet/NMWirelessAppletDbus.c: Need to include
string.h, and dbus-glib-lowlevel.h (the latter is needed
for dbus_connection_setup_with_g_main at present).
(nmwa_dbus_update_wireless_network_list): Parenthesize
assignment in conditional.
(nmwa_dbus_worker): Return NULL.
* panel-applet/NMWirelessApplet.c (nmwa_redraw)
(nmwa_get_menu_pos, nmwa_toplevel_menu_activate)
(nmwa_menu_add_text_item, nmwa_setup_widgets): Kill unused variables.
(nmwa_populate_menu): Return NULL on failure, instead of just
return;
* initscript/NMLaunchHelper.c (g_timeout_add): Cast arg to GSourceFunc.
* info-daemon/NetworkManagerInfoNetworksDialog.c (nmi_networks_dialog_init): Kill unused
variables.
* info-daemon/NetworkManagerInfo.c (nmi_print_usage): Unused,
delete.
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@105 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2004-08-29 06:06:51 +00:00
|
|
|
return NULL;
|
2004-06-24 14:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
|
|
|
|
if (dbus_error_is_set (&error))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
|
|
|
|
|
dbus_message_unref (message);
|
2004-08-29 Colin Walters <walters@verbum.org>
* test/nminfotest.c: Include string.h and stdlib.h.
(get_network_string_property, get_networks_of_type): Return NULL.
* test/nmclienttest.c (get_device_name, get_active_device): Return
NULL.
* src/backends/NetworkManagerRedHat.c (nm_system_device_stop_dhcp): Just
use strlen, fgets always NULL-terminates the string.
* src/NetworkManagerDbus.c (nm_dbus_nmi_filter,
dbus_message_get_member): Remove /* in comment.
* src/NetworkManagerUtils.c (LOCKING_DEBUG): Ditto.
* src/NetworkManager.c (quit): Unused, delete.
(nm_data_free): Cast arg to GFunc.
* panel-applet/NMWirelessAppletDbus.c: Need to include
string.h, and dbus-glib-lowlevel.h (the latter is needed
for dbus_connection_setup_with_g_main at present).
(nmwa_dbus_update_wireless_network_list): Parenthesize
assignment in conditional.
(nmwa_dbus_worker): Return NULL.
* panel-applet/NMWirelessApplet.c (nmwa_redraw)
(nmwa_get_menu_pos, nmwa_toplevel_menu_activate)
(nmwa_menu_add_text_item, nmwa_setup_widgets): Kill unused variables.
(nmwa_populate_menu): Return NULL on failure, instead of just
return;
* initscript/NMLaunchHelper.c (g_timeout_add): Cast arg to GSourceFunc.
* info-daemon/NetworkManagerInfoNetworksDialog.c (nmi_networks_dialog_init): Kill unused
variables.
* info-daemon/NetworkManagerInfo.c (nmi_print_usage): Unused,
delete.
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@105 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2004-08-29 06:06:51 +00:00
|
|
|
return NULL;
|
2004-06-24 14:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reply == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf( stderr, "dbus reply message was NULL\n" );
|
|
|
|
|
dbus_message_unref (message);
|
2004-08-29 Colin Walters <walters@verbum.org>
* test/nminfotest.c: Include string.h and stdlib.h.
(get_network_string_property, get_networks_of_type): Return NULL.
* test/nmclienttest.c (get_device_name, get_active_device): Return
NULL.
* src/backends/NetworkManagerRedHat.c (nm_system_device_stop_dhcp): Just
use strlen, fgets always NULL-terminates the string.
* src/NetworkManagerDbus.c (nm_dbus_nmi_filter,
dbus_message_get_member): Remove /* in comment.
* src/NetworkManagerUtils.c (LOCKING_DEBUG): Ditto.
* src/NetworkManager.c (quit): Unused, delete.
(nm_data_free): Cast arg to GFunc.
* panel-applet/NMWirelessAppletDbus.c: Need to include
string.h, and dbus-glib-lowlevel.h (the latter is needed
for dbus_connection_setup_with_g_main at present).
(nmwa_dbus_update_wireless_network_list): Parenthesize
assignment in conditional.
(nmwa_dbus_worker): Return NULL.
* panel-applet/NMWirelessApplet.c (nmwa_redraw)
(nmwa_get_menu_pos, nmwa_toplevel_menu_activate)
(nmwa_menu_add_text_item, nmwa_setup_widgets): Kill unused variables.
(nmwa_populate_menu): Return NULL on failure, instead of just
return;
* initscript/NMLaunchHelper.c (g_timeout_add): Cast arg to GSourceFunc.
* info-daemon/NetworkManagerInfoNetworksDialog.c (nmi_networks_dialog_init): Kill unused
variables.
* info-daemon/NetworkManagerInfo.c (nmi_print_usage): Unused,
delete.
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@105 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2004-08-29 06:06:51 +00:00
|
|
|
return NULL;
|
2004-06-24 14:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* now analyze reply */
|
|
|
|
|
dbus_message_iter_init (reply, &iter);
|
|
|
|
|
char *string;
|
|
|
|
|
string = dbus_message_iter_get_string (&iter);
|
|
|
|
|
if (!string)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "NetworkManager returned a NULL active device object path" );
|
2004-08-29 Colin Walters <walters@verbum.org>
* test/nminfotest.c: Include string.h and stdlib.h.
(get_network_string_property, get_networks_of_type): Return NULL.
* test/nmclienttest.c (get_device_name, get_active_device): Return
NULL.
* src/backends/NetworkManagerRedHat.c (nm_system_device_stop_dhcp): Just
use strlen, fgets always NULL-terminates the string.
* src/NetworkManagerDbus.c (nm_dbus_nmi_filter,
dbus_message_get_member): Remove /* in comment.
* src/NetworkManagerUtils.c (LOCKING_DEBUG): Ditto.
* src/NetworkManager.c (quit): Unused, delete.
(nm_data_free): Cast arg to GFunc.
* panel-applet/NMWirelessAppletDbus.c: Need to include
string.h, and dbus-glib-lowlevel.h (the latter is needed
for dbus_connection_setup_with_g_main at present).
(nmwa_dbus_update_wireless_network_list): Parenthesize
assignment in conditional.
(nmwa_dbus_worker): Return NULL.
* panel-applet/NMWirelessApplet.c (nmwa_redraw)
(nmwa_get_menu_pos, nmwa_toplevel_menu_activate)
(nmwa_menu_add_text_item, nmwa_setup_widgets): Kill unused variables.
(nmwa_populate_menu): Return NULL on failure, instead of just
return;
* initscript/NMLaunchHelper.c (g_timeout_add): Cast arg to GSourceFunc.
* info-daemon/NetworkManagerInfoNetworksDialog.c (nmi_networks_dialog_init): Kill unused
variables.
* info-daemon/NetworkManagerInfo.c (nmi_print_usage): Unused,
delete.
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@105 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2004-08-29 06:06:51 +00:00
|
|
|
return NULL;
|
2004-06-24 14:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf (stderr, "Active device: '%s'\n", string );
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
|
|
|
|
|
device_path = g_strdup (string);
|
|
|
|
|
return (device_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void get_device_name (DBusConnection *connection, char *path)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *message;
|
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
DBusMessageIter iter;
|
|
|
|
|
DBusError error;
|
|
|
|
|
|
|
|
|
|
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
|
|
|
|
|
path,
|
|
|
|
|
"org.freedesktop.NetworkManager",
|
|
|
|
|
"getName");
|
|
|
|
|
if (message == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
|
|
|
|
if (dbus_error_is_set (&error))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reply == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf( stderr, "dbus reply message was NULL\n" );
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* now analyze reply */
|
|
|
|
|
dbus_message_iter_init (reply, &iter);
|
|
|
|
|
char *string;
|
|
|
|
|
string = dbus_message_iter_get_string (&iter);
|
|
|
|
|
if (!string)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "NetworkManager returned a NULL active device object path" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf (stderr, "Active device name: '%s'\n", string );
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-13 17:43:16 +00:00
|
|
|
|
|
|
|
|
int get_object_signal_strength (DBusConnection *connection, char *path)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *message;
|
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
DBusMessageIter iter;
|
|
|
|
|
DBusError error;
|
|
|
|
|
|
|
|
|
|
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
|
|
|
|
|
path,
|
|
|
|
|
"org.freedesktop.NetworkManager.Devices",
|
|
|
|
|
"getStrength");
|
|
|
|
|
if (message == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
if (dbus_error_is_set (&error))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reply == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf( stderr, "dbus reply message was NULL\n" );
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* now analyze reply */
|
|
|
|
|
dbus_message_iter_init (reply, &iter);
|
|
|
|
|
int qual = dbus_message_iter_get_int32 (&iter);
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
|
|
|
|
|
return (qual);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-08-11 19:31:41 +00:00
|
|
|
void get_nm_status (DBusConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *message;
|
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
DBusMessageIter iter;
|
|
|
|
|
DBusError error;
|
|
|
|
|
|
|
|
|
|
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
|
|
|
|
|
"/org/freedesktop/NetworkManager",
|
|
|
|
|
"org.freedesktop.NetworkManager",
|
|
|
|
|
"status");
|
|
|
|
|
if (message == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
|
|
|
|
if (dbus_error_is_set (&error))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reply == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf( stderr, "dbus reply message was NULL\n" );
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* now analyze reply */
|
|
|
|
|
dbus_message_iter_init (reply, &iter);
|
|
|
|
|
char *string;
|
|
|
|
|
string = dbus_message_iter_get_string (&iter);
|
|
|
|
|
if (!string)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "NetworkManager returned a NULL status" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf (stderr, "NM Status: '%s'\n", string );
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-24 14:18:37 +00:00
|
|
|
void get_device_active_network (DBusConnection *connection, char *path)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *message;
|
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
DBusMessageIter iter;
|
|
|
|
|
DBusError error;
|
|
|
|
|
|
|
|
|
|
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
|
|
|
|
|
path,
|
|
|
|
|
"org.freedesktop.NetworkManager",
|
|
|
|
|
"getActiveNetwork");
|
|
|
|
|
if (message == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
|
|
|
|
if (dbus_error_is_set (&error))
|
|
|
|
|
{
|
2004-09-09 20:02:59 +00:00
|
|
|
if (strstr (error.name, "NoActiveNetwork"))
|
|
|
|
|
fprintf (stderr, " This device is not associated with a wireless network\n");
|
|
|
|
|
else
|
|
|
|
|
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
|
2004-06-24 14:18:37 +00:00
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reply == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf( stderr, "dbus reply message was NULL\n" );
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* now analyze reply */
|
|
|
|
|
dbus_message_iter_init (reply, &iter);
|
|
|
|
|
char *string;
|
|
|
|
|
string = dbus_message_iter_get_string (&iter);
|
|
|
|
|
if (!string)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "NetworkManager returned a NULL active device object path" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf (stderr, "Active device's Network: '%s' ", string );
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
|
|
|
|
|
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
|
|
|
|
|
string,
|
|
|
|
|
"org.freedesktop.NetworkManager",
|
|
|
|
|
"getName");
|
|
|
|
|
if (message == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
|
|
|
|
if (dbus_error_is_set (&error))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reply == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf( stderr, "dbus reply message was NULL\n" );
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* now analyze reply */
|
|
|
|
|
dbus_message_iter_init (reply, &iter);
|
|
|
|
|
string = dbus_message_iter_get_string (&iter);
|
|
|
|
|
if (!string)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "NetworkManager returned a NULL active device object path" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf (stderr, " (%s)\n", string );
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int get_device_type (DBusConnection *connection, char *path)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *message;
|
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
DBusMessageIter iter;
|
|
|
|
|
DBusError error;
|
|
|
|
|
|
|
|
|
|
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
|
|
|
|
|
path,
|
|
|
|
|
"org.freedesktop.NetworkManager",
|
|
|
|
|
"getType");
|
|
|
|
|
if (message == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
|
|
|
|
if (dbus_error_is_set (&error))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reply == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf( stderr, "dbus reply message was NULL\n" );
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* now analyze reply */
|
|
|
|
|
dbus_message_iter_init (reply, &iter);
|
2004-09-13 17:43:16 +00:00
|
|
|
int type = dbus_message_iter_get_int32 (&iter);
|
2004-06-24 14:18:37 +00:00
|
|
|
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
|
|
|
|
|
return (type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-09-13 17:43:16 +00:00
|
|
|
const char * get_network_name (DBusConnection *connection, const char *path)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *message2;
|
|
|
|
|
DBusMessage *reply2;
|
|
|
|
|
DBusMessageIter iter2;
|
|
|
|
|
DBusError error2;
|
|
|
|
|
|
|
|
|
|
message2 = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
|
|
|
|
|
path,
|
|
|
|
|
"org.freedesktop.NetworkManager",
|
|
|
|
|
"getName");
|
|
|
|
|
if (message2 == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error2);
|
|
|
|
|
reply2 = dbus_connection_send_with_reply_and_block (connection, message2, -1, &error2);
|
|
|
|
|
dbus_message_unref (message2);
|
|
|
|
|
if (dbus_error_is_set (&error2))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s raised:\n %s\n\n", error2.name, error2.message);
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reply2 == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf( stderr, "dbus reply message was NULL\n" );
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* now analyze reply */
|
|
|
|
|
dbus_message_iter_init (reply2, &iter2);
|
|
|
|
|
const char *string2 = dbus_message_iter_get_string (&iter2);
|
|
|
|
|
if (!string2)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "NetworkManager returned a NULL network name" );
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (reply2);
|
|
|
|
|
|
|
|
|
|
return (string2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-06-24 14:18:37 +00:00
|
|
|
void get_device_networks (DBusConnection *connection, const char *path)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *message;
|
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
DBusMessageIter iter;
|
|
|
|
|
DBusError error;
|
|
|
|
|
|
|
|
|
|
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
|
|
|
|
|
path,
|
|
|
|
|
"org.freedesktop.NetworkManager",
|
|
|
|
|
"getNetworks");
|
|
|
|
|
if (message == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
|
|
|
|
if (dbus_error_is_set (&error))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reply == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf( stderr, "dbus reply message was NULL\n" );
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* now analyze reply */
|
|
|
|
|
dbus_message_iter_init (reply, &iter);
|
|
|
|
|
char **networks;
|
|
|
|
|
int num_networks;
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_iter_get_string_array (&iter, &networks, &num_networks))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "NetworkManager returned no device list" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
|
|
|
|
|
int i;
|
2004-09-09 20:02:59 +00:00
|
|
|
fprintf( stderr, " Networks:\n" );
|
2004-06-24 14:18:37 +00:00
|
|
|
for (i = 0; i < num_networks; i++)
|
|
|
|
|
{
|
2004-09-13 17:43:16 +00:00
|
|
|
const char *name = get_network_name (connection, networks[i]);
|
2004-06-24 14:18:37 +00:00
|
|
|
|
2004-09-13 17:43:16 +00:00
|
|
|
fprintf( stderr, " %s (%s) Strength: %d%%\n", networks[i], name,
|
|
|
|
|
get_object_signal_strength (connection, networks[i]) );
|
|
|
|
|
dbus_free (name);
|
2004-06-24 14:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_free_string_array (networks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void get_devices (DBusConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *message;
|
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
DBusMessageIter iter;
|
|
|
|
|
DBusError error;
|
|
|
|
|
|
|
|
|
|
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
|
|
|
|
|
"/org/freedesktop/NetworkManager",
|
|
|
|
|
"org.freedesktop.NetworkManager",
|
|
|
|
|
"getDevices");
|
|
|
|
|
if (message == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
|
|
|
|
if (dbus_error_is_set (&error))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reply == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf( stderr, "dbus reply message was NULL\n" );
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* now analyze reply */
|
|
|
|
|
dbus_message_iter_init (reply, &iter);
|
|
|
|
|
char **devices;
|
|
|
|
|
int num_devices;
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_iter_get_string_array (&iter, &devices, &num_devices))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "NetworkManager returned no device list" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
fprintf( stderr, "Devices:\n" );
|
|
|
|
|
for (i = 0; i < num_devices; i++)
|
2004-09-09 20:02:59 +00:00
|
|
|
{
|
|
|
|
|
int type;
|
|
|
|
|
|
2004-09-13 17:43:16 +00:00
|
|
|
fprintf (stderr, " %s", devices[i]);
|
2004-09-09 20:02:59 +00:00
|
|
|
if ((type = get_device_type (connection, devices[i])) == 2)
|
|
|
|
|
{
|
2004-09-13 17:43:16 +00:00
|
|
|
fprintf (stderr, " Strength: %d%%\n", get_object_signal_strength (connection, devices[i]));
|
|
|
|
|
fprintf (stderr, " Device type: '%d'\n", type );
|
2004-09-09 20:02:59 +00:00
|
|
|
get_device_active_network (connection, devices[i]);
|
|
|
|
|
get_device_networks (connection, devices[i]);
|
2004-09-13 17:43:16 +00:00
|
|
|
fprintf (stderr, "\n");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "\n Device type: '%d'\n", type );
|
|
|
|
|
fprintf (stderr, "\n");
|
2004-09-09 20:02:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
2004-06-24 14:18:37 +00:00
|
|
|
|
|
|
|
|
dbus_free_string_array (devices);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main( int argc, char *argv[] )
|
|
|
|
|
{
|
|
|
|
|
DBusConnection *connection;
|
|
|
|
|
DBusError error;
|
|
|
|
|
|
|
|
|
|
g_type_init ();
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
|
|
|
|
|
if (connection == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Error connecting to system bus: %s\n", error.message);
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *path;
|
|
|
|
|
|
2004-08-11 19:31:41 +00:00
|
|
|
get_nm_status (connection);
|
2004-06-24 14:18:37 +00:00
|
|
|
path = get_active_device (connection);
|
|
|
|
|
get_device_name (connection, path);
|
|
|
|
|
get_devices (connection);
|
|
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|