mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-06 10:30:39 +01:00
* configure.in - Add checks for GConf libs & headers & flags * info-daemon/Makefile.am - Add GConf flags & libs to compile/link stages of NetworkManagerInfo * info-daemon/NetworkManagerInfo.[ch] - Don't use gquarks for data storage, just use normal data storage - Add gconf bits to watch /system/networking/wireless/allowed_networks * info-daemon/NetworkManagerDbus.[ch] - Add method call for getting allowed networks - Add method calls for getting an allowed network's essid, priority, and key - Hook the method calls up to GConf - Split user key dialog code into separate function (nmi_dbus_get_key_for_network) - nmi_dbus_nmi_message_handler(): make sure to unref the reply message after sending * src/NetworkManagerDbus.[ch] - Switch for enumeration of networks to using essid instead * test/Makefile.am test/nminfotest.c - Add test program for NetworkManagerInfo git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@19 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
192 lines
4.5 KiB
C
192 lines
4.5 KiB
C
#include <glib.h>
|
|
#include <dbus/dbus-glib.h>
|
|
#include <stdio.h>
|
|
|
|
|
|
char * get_network_string_property (DBusConnection *connection, char *network, char *method)
|
|
{
|
|
DBusMessage *message;
|
|
DBusMessage *reply;
|
|
DBusMessageIter iter;
|
|
DBusError error;
|
|
|
|
message = dbus_message_new_method_call ("org.freedesktop.NetworkManagerInfo",
|
|
"/org/freedesktop/NetworkManagerInfo",
|
|
"org.freedesktop.NetworkManagerInfo",
|
|
method);
|
|
if (message == NULL)
|
|
{
|
|
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
|
return;
|
|
}
|
|
|
|
dbus_message_iter_init (message, &iter);
|
|
dbus_message_iter_append_string (&iter, network);
|
|
|
|
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, *ret_string;
|
|
string = dbus_message_iter_get_string (&iter);
|
|
if (!string)
|
|
{
|
|
fprintf (stderr, "NetworkManagerInfo returned a NULL active device object path" );
|
|
return;
|
|
}
|
|
ret_string = g_strdup (string);
|
|
dbus_free (string);
|
|
|
|
dbus_message_unref (reply);
|
|
dbus_message_unref (message);
|
|
|
|
return (ret_string);
|
|
}
|
|
|
|
int get_network_prio (DBusConnection *connection, char *network)
|
|
{
|
|
DBusMessage *message;
|
|
DBusMessage *reply;
|
|
DBusMessageIter iter;
|
|
DBusError error;
|
|
|
|
g_return_val_if_fail (connection != NULL, -1);
|
|
g_return_val_if_fail (network != NULL, -1);
|
|
|
|
message = dbus_message_new_method_call ("org.freedesktop.NetworkManagerInfo",
|
|
"/org/freedesktop/NetworkManagerInfo",
|
|
"org.freedesktop.NetworkManagerInfo",
|
|
"getAllowedNetworkPriority");
|
|
if (message == NULL)
|
|
{
|
|
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
|
return (-1);
|
|
}
|
|
|
|
dbus_message_iter_init (message, &iter);
|
|
dbus_message_iter_append_string (&iter, network);
|
|
|
|
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);
|
|
int type;
|
|
type = dbus_message_iter_get_uint32 (&iter);
|
|
|
|
dbus_message_unref (reply);
|
|
dbus_message_unref (message);
|
|
|
|
return (type);
|
|
}
|
|
|
|
|
|
void get_allowed_networks (DBusConnection *connection)
|
|
{
|
|
DBusMessage *message;
|
|
DBusMessage *reply;
|
|
DBusMessageIter iter;
|
|
DBusError error;
|
|
|
|
message = dbus_message_new_method_call ("org.freedesktop.NetworkManagerInfo",
|
|
"/org/freedesktop/NetworkManagerInfo",
|
|
"org.freedesktop.NetworkManagerInfo",
|
|
"getAllowedNetworks");
|
|
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, "NetworkManagerInfo returned no network list" );
|
|
return;
|
|
}
|
|
|
|
dbus_message_unref (reply);
|
|
dbus_message_unref (message);
|
|
|
|
int i;
|
|
fprintf( stderr, "Networks:\n" );
|
|
for (i = 0; i < num_networks; i++)
|
|
{
|
|
char *essid = get_network_string_property (connection, networks[i], "getAllowedNetworkEssid");
|
|
char *key = get_network_string_property (connection, networks[i], "getAllowedNetworkKey");
|
|
|
|
fprintf( stderr, " %d:\t%s\t%s\n",
|
|
get_network_prio (connection, networks[i]), essid, key);
|
|
}
|
|
|
|
dbus_free_string_array (networks);
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
get_allowed_networks (connection);
|
|
|
|
return 0;
|
|
}
|