mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-07-23 19:24:38 +00:00
2004-07-22 Dan Williams <dcbw@redhat.com>
* 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
This commit is contained in:
parent
1e4fbdcd95
commit
846858e487
26
ChangeLog
26
ChangeLog
|
@ -1,3 +1,29 @@
|
|||
2004-07-22 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* 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
|
||||
|
||||
2004-07-19 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* src/NetworkManagerDbus.c
|
||||
|
|
|
@ -56,6 +56,8 @@ ECHO_N = @ECHO_N@
|
|||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
GCONF_CFLAGS = @GCONF_CFLAGS@
|
||||
GCONF_LIBS = @GCONF_LIBS@
|
||||
GLADE_CFLAGS = @GLADE_CFLAGS@
|
||||
GLADE_LIBS = @GLADE_LIBS@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
|
|
105
configure
vendored
105
configure
vendored
|
@ -308,7 +308,7 @@ ac_includes_default="\
|
|||
# include <unistd.h>
|
||||
#endif"
|
||||
|
||||
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CYGPATH_W PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO AMTAR install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM AWK SET_MAKE am__leading_dot CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT DEPDIR am__include am__quote AMDEP_TRUE AMDEP_FALSE AMDEPBACKSLASH CCDEPMODE am__fastdepCC_TRUE am__fastdepCC_FALSE CPP EGREP IWLIB PKG_CONFIG NM_CFLAGS NM_LIBS GLADE_CFLAGS GLADE_LIBS LIBOBJS LTLIBOBJS'
|
||||
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CYGPATH_W PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO AMTAR install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM AWK SET_MAKE am__leading_dot CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT DEPDIR am__include am__quote AMDEP_TRUE AMDEP_FALSE AMDEPBACKSLASH CCDEPMODE am__fastdepCC_TRUE am__fastdepCC_FALSE CPP EGREP IWLIB PKG_CONFIG NM_CFLAGS NM_LIBS GLADE_CFLAGS GLADE_LIBS GCONF_CFLAGS GCONF_LIBS LIBOBJS LTLIBOBJS'
|
||||
ac_subst_files=''
|
||||
|
||||
# Initialize some variables set by options.
|
||||
|
@ -3717,6 +3717,107 @@ echo "$as_me: error: Library requirements (libglade-2.0) not met; consider adjus
|
|||
|
||||
|
||||
|
||||
|
||||
succeeded=no
|
||||
|
||||
if test -z "$PKG_CONFIG"; then
|
||||
# Extract the first word of "pkg-config", so it can be a program name with args.
|
||||
set dummy pkg-config; ac_word=$2
|
||||
echo "$as_me:$LINENO: checking for $ac_word" >&5
|
||||
echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
|
||||
if test "${ac_cv_path_PKG_CONFIG+set}" = set; then
|
||||
echo $ECHO_N "(cached) $ECHO_C" >&6
|
||||
else
|
||||
case $PKG_CONFIG in
|
||||
[\\/]* | ?:[\\/]*)
|
||||
ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path.
|
||||
;;
|
||||
*)
|
||||
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
|
||||
for as_dir in $PATH
|
||||
do
|
||||
IFS=$as_save_IFS
|
||||
test -z "$as_dir" && as_dir=.
|
||||
for ac_exec_ext in '' $ac_executable_extensions; do
|
||||
if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
|
||||
ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
|
||||
echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
|
||||
break 2
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
test -z "$ac_cv_path_PKG_CONFIG" && ac_cv_path_PKG_CONFIG="no"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
PKG_CONFIG=$ac_cv_path_PKG_CONFIG
|
||||
|
||||
if test -n "$PKG_CONFIG"; then
|
||||
echo "$as_me:$LINENO: result: $PKG_CONFIG" >&5
|
||||
echo "${ECHO_T}$PKG_CONFIG" >&6
|
||||
else
|
||||
echo "$as_me:$LINENO: result: no" >&5
|
||||
echo "${ECHO_T}no" >&6
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
if test "$PKG_CONFIG" = "no" ; then
|
||||
echo "*** The pkg-config script could not be found. Make sure it is"
|
||||
echo "*** in your path, or set the PKG_CONFIG environment variable"
|
||||
echo "*** to the full path to pkg-config."
|
||||
echo "*** Or see http://www.freedesktop.org/software/pkgconfig to get pkg-config."
|
||||
else
|
||||
PKG_CONFIG_MIN_VERSION=0.9.0
|
||||
if $PKG_CONFIG --atleast-pkgconfig-version $PKG_CONFIG_MIN_VERSION; then
|
||||
echo "$as_me:$LINENO: checking for gconf-2.0" >&5
|
||||
echo $ECHO_N "checking for gconf-2.0... $ECHO_C" >&6
|
||||
|
||||
if $PKG_CONFIG --exists "gconf-2.0" ; then
|
||||
echo "$as_me:$LINENO: result: yes" >&5
|
||||
echo "${ECHO_T}yes" >&6
|
||||
succeeded=yes
|
||||
|
||||
echo "$as_me:$LINENO: checking GCONF_CFLAGS" >&5
|
||||
echo $ECHO_N "checking GCONF_CFLAGS... $ECHO_C" >&6
|
||||
GCONF_CFLAGS=`$PKG_CONFIG --cflags "gconf-2.0"`
|
||||
echo "$as_me:$LINENO: result: $GCONF_CFLAGS" >&5
|
||||
echo "${ECHO_T}$GCONF_CFLAGS" >&6
|
||||
|
||||
echo "$as_me:$LINENO: checking GCONF_LIBS" >&5
|
||||
echo $ECHO_N "checking GCONF_LIBS... $ECHO_C" >&6
|
||||
GCONF_LIBS=`$PKG_CONFIG --libs "gconf-2.0"`
|
||||
echo "$as_me:$LINENO: result: $GCONF_LIBS" >&5
|
||||
echo "${ECHO_T}$GCONF_LIBS" >&6
|
||||
else
|
||||
GCONF_CFLAGS=""
|
||||
GCONF_LIBS=""
|
||||
## If we have a custom action on failure, don't print errors, but
|
||||
## do set a variable so people can do so.
|
||||
GCONF_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "gconf-2.0"`
|
||||
echo $GCONF_PKG_ERRORS
|
||||
fi
|
||||
|
||||
|
||||
|
||||
else
|
||||
echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer."
|
||||
echo "*** See http://www.freedesktop.org/software/pkgconfig"
|
||||
fi
|
||||
fi
|
||||
|
||||
if test $succeeded = yes; then
|
||||
:
|
||||
else
|
||||
{ { echo "$as_me:$LINENO: error: Library requirements (gconf-2.0) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them." >&5
|
||||
echo "$as_me: error: Library requirements (gconf-2.0) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them." >&2;}
|
||||
{ (exit 1); exit 1; }; }
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
ac_config_files="$ac_config_files Makefile src/Makefile dispatcher-daemon/Makefile info-daemon/Makefile test/Makefile initscript/Makefile"
|
||||
cat >confcache <<\_ACEOF
|
||||
# This file is a shell script that caches the results of configure
|
||||
|
@ -4427,6 +4528,8 @@ s,@NM_CFLAGS@,$NM_CFLAGS,;t t
|
|||
s,@NM_LIBS@,$NM_LIBS,;t t
|
||||
s,@GLADE_CFLAGS@,$GLADE_CFLAGS,;t t
|
||||
s,@GLADE_LIBS@,$GLADE_LIBS,;t t
|
||||
s,@GCONF_CFLAGS@,$GCONF_CFLAGS,;t t
|
||||
s,@GCONF_LIBS@,$GCONF_LIBS,;t t
|
||||
s,@LIBOBJS@,$LIBOBJS,;t t
|
||||
s,@LTLIBOBJS@,$LTLIBOBJS,;t t
|
||||
CEOF
|
||||
|
|
|
@ -19,6 +19,10 @@ PKG_CHECK_MODULES(GLADE, libglade-2.0)
|
|||
AC_SUBST(GLADE_CFLAGS)
|
||||
AC_SUBST(GLADE_LIBS)
|
||||
|
||||
PKG_CHECK_MODULES(GCONF, gconf-2.0)
|
||||
AC_SUBST(GCONF_CFLAGS)
|
||||
AC_SUBST(GCONF_LIBS)
|
||||
|
||||
AC_OUTPUT([
|
||||
Makefile
|
||||
src/Makefile
|
||||
|
|
|
@ -56,6 +56,8 @@ ECHO_N = @ECHO_N@
|
|||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
GCONF_CFLAGS = @GCONF_CFLAGS@
|
||||
GCONF_LIBS = @GCONF_LIBS@
|
||||
GLADE_CFLAGS = @GLADE_CFLAGS@
|
||||
GLADE_LIBS = @GLADE_LIBS@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
INCLUDES = \
|
||||
$(NM_CFLAGS) \
|
||||
$(GLADE_CFLAGS) \
|
||||
$(GCONF_CFLAGS)
|
||||
-Wall \
|
||||
-DDBUS_API_SUBJECT_TO_CHANGE \
|
||||
-DG_DISABLE_DEPRECATED \
|
||||
-DGTK_DISABLE_DEPRECATED \
|
||||
-DBINDIR=\"$(bindir)\" \
|
||||
-DDATADIR=\"$(datadir)\"
|
||||
|
||||
|
@ -11,5 +14,5 @@ bin_PROGRAMS = NetworkManagerInfo
|
|||
NetworkManagerInfo_SOURCES = NetworkManagerInfo.c \
|
||||
NetworkManagerInfoDbus.c
|
||||
|
||||
NetworkManagerInfo_LDADD = $(NM_LIBS) $(GLADE_LIBS)
|
||||
NetworkManagerInfo_LDADD = $(NM_LIBS) $(GLADE_LIBS) $(GCONF_LIBS)
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <string.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <glade/glade.h>
|
||||
#include <gconf/gconf-client.h>
|
||||
|
||||
#include "NetworkManagerInfoDbus.h"
|
||||
#include "NetworkManagerInfo.h"
|
||||
|
@ -49,18 +50,18 @@ static void nmi_clear_dialog (GtkWidget *dialog, GtkWidget *entry)
|
|||
g_return_if_fail (dialog != NULL);
|
||||
g_return_if_fail (entry != NULL);
|
||||
|
||||
data = g_object_get_qdata (G_OBJECT (dialog), g_quark_from_static_string ("device"));
|
||||
data = g_object_get_data (G_OBJECT (dialog), "device");
|
||||
if (data)
|
||||
{
|
||||
g_free (data);
|
||||
g_object_set_qdata (G_OBJECT (dialog), g_quark_from_static_string ("device"), NULL);
|
||||
g_object_set_data (G_OBJECT (dialog), "device", NULL);
|
||||
}
|
||||
|
||||
data = g_object_get_qdata (G_OBJECT (dialog), g_quark_from_static_string ("network"));
|
||||
data = g_object_get_data (G_OBJECT (dialog), "network");
|
||||
if (data)
|
||||
{
|
||||
g_free (data);
|
||||
g_object_set_qdata (G_OBJECT (dialog), g_quark_from_static_string ("network"), NULL);
|
||||
g_object_set_data (G_OBJECT (dialog), "network", NULL);
|
||||
}
|
||||
|
||||
gtk_entry_set_text (GTK_ENTRY (entry), "");
|
||||
|
@ -86,8 +87,8 @@ static void ok_button_clicked (GtkWidget *ok_button, gpointer user_data)
|
|||
{
|
||||
GtkWidget *entry = glade_xml_get_widget (info->xml, "passphrase_entry");
|
||||
const char *passphrase = gtk_entry_get_text (GTK_ENTRY (entry));
|
||||
const char *device = g_object_get_qdata (G_OBJECT (dialog), g_quark_from_static_string ("device"));
|
||||
const char *network = g_object_get_qdata (G_OBJECT (dialog), g_quark_from_static_string ("network"));
|
||||
const char *device = g_object_get_data (G_OBJECT (dialog), "device");
|
||||
const char *network = g_object_get_data (G_OBJECT (dialog), "network");
|
||||
|
||||
nmi_dbus_return_user_key (info->connection, device, network, passphrase);
|
||||
nmi_clear_dialog (dialog, entry);
|
||||
|
@ -111,8 +112,8 @@ static void cancel_button_clicked (GtkWidget *cancel_button, gpointer user_data)
|
|||
|
||||
if (GTK_WIDGET_TOPLEVEL (dialog))
|
||||
{
|
||||
const char *device = g_object_get_qdata (G_OBJECT (dialog), g_quark_from_static_string ("device"));
|
||||
const char *network = g_object_get_qdata (G_OBJECT (dialog), g_quark_from_static_string ("network"));
|
||||
const char *device = g_object_get_data (G_OBJECT (dialog), "device");
|
||||
const char *network = g_object_get_data (G_OBJECT (dialog), "network");
|
||||
|
||||
nmi_dbus_return_user_key (info->connection, device, network, "***cancelled***");
|
||||
nmi_clear_dialog (dialog, glade_xml_get_widget (info->xml, "passphrase_entry"));
|
||||
|
@ -148,8 +149,8 @@ void nmi_show_user_key_dialog (const char *device, const char *network, NMIAppIn
|
|||
gtk_label_set_label (GTK_LABEL (label), new_label_text);
|
||||
}
|
||||
|
||||
g_object_set_qdata (G_OBJECT (dialog), g_quark_from_static_string ("device"), g_strdup (device));
|
||||
g_object_set_qdata (G_OBJECT (dialog), g_quark_from_static_string ("network"), g_strdup (network));
|
||||
g_object_set_data (G_OBJECT (dialog), "device", g_strdup (device));
|
||||
g_object_set_data (G_OBJECT (dialog), "network", g_strdup (network));
|
||||
|
||||
gtk_widget_show (dialog);
|
||||
}
|
||||
|
@ -211,6 +212,20 @@ static void nmi_interface_init (NMIAppInfo *info)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmi_gconf_notify_callback
|
||||
*
|
||||
* Callback from gconf when wireless networking key/values have changed.
|
||||
*
|
||||
*/
|
||||
void nmi_gconf_notify_callback (GConfClient *client, guint connection_id, GConfEntry *entry, gpointer user_data)
|
||||
{
|
||||
NMIAppInfo *info = (NMIAppInfo *)user_data;
|
||||
|
||||
g_return_if_fail (info != NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmi_print_usage
|
||||
*
|
||||
|
@ -243,6 +258,7 @@ int main( int argc, char *argv[] )
|
|||
int err;
|
||||
NMIAppInfo *app_info = NULL;
|
||||
GMainLoop *loop;
|
||||
guint notify_id;
|
||||
|
||||
/* Parse options */
|
||||
while (1)
|
||||
|
@ -342,6 +358,15 @@ int main( int argc, char *argv[] )
|
|||
dbus_connection_setup_with_g_main (dbus_connection, NULL);
|
||||
app_info->connection = dbus_connection;
|
||||
|
||||
/* Grab a connection to the GConf daemon. We also want to
|
||||
* get change notifications for our wireless networking data.
|
||||
*/
|
||||
app_info->gconf_client = gconf_client_get_default ();
|
||||
gconf_client_add_dir (app_info->gconf_client, NMI_GCONF_WIRELESS_NETWORKING_PATH,
|
||||
GCONF_CLIENT_PRELOAD_NONE, NULL);
|
||||
notify_id = gconf_client_notify_add (app_info->gconf_client, NMI_GCONF_WIRELESS_NETWORKING_PATH,
|
||||
nmi_gconf_notify_callback, app_info, NULL, NULL);
|
||||
|
||||
/* Create our own dbus service */
|
||||
err = nmi_dbus_service_init (dbus_connection, app_info);
|
||||
if (err == -1)
|
||||
|
@ -354,6 +379,8 @@ int main( int argc, char *argv[] )
|
|||
loop = g_main_loop_new (NULL, FALSE);
|
||||
g_main_loop_run (loop);
|
||||
|
||||
gconf_client_notify_remove (app_info->gconf_client, notify_id);
|
||||
g_object_unref (G_OBJECT (app_info->gconf_client));
|
||||
g_free (app_info);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -27,15 +27,20 @@
|
|||
#include <glade/glade.h>
|
||||
#include <glib.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
#include <gconf/gconf-client.h>
|
||||
|
||||
struct NMIAppInfo
|
||||
{
|
||||
GladeXML *xml;
|
||||
DBusConnection *connection;
|
||||
GConfClient *gconf_client;
|
||||
};
|
||||
typedef struct NMIAppInfo NMIAppInfo;
|
||||
|
||||
|
||||
#define NMI_GCONF_WIRELESS_NETWORKING_PATH "/system/networking/wireless"
|
||||
|
||||
|
||||
void nmi_show_user_key_dialog (const char *device, const char *network, NMIAppInfo *info);
|
||||
void nmi_cancel_user_key_dialog (NMIAppInfo *info);
|
||||
|
||||
|
|
|
@ -57,6 +57,41 @@ static DBusMessage *nmi_dbus_create_error_message (DBusMessage *message, const c
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmi_dbus_get_key_for_network
|
||||
*
|
||||
* Throw up the user key dialog
|
||||
*
|
||||
*/
|
||||
static void nmi_dbus_get_key_for_network (NMIAppInfo *info, DBusMessage *message)
|
||||
{
|
||||
DBusMessageIter iter;
|
||||
char *dbus_string;
|
||||
char *device = NULL;
|
||||
char *network = NULL;
|
||||
|
||||
dbus_message_iter_init (message, &iter);
|
||||
/* Grab device */
|
||||
dbus_string = dbus_message_iter_get_string (&iter);
|
||||
device = (dbus_string == NULL ? NULL : strdup (dbus_string));
|
||||
dbus_free (dbus_string);
|
||||
|
||||
/* Grab network to get key for */
|
||||
if (dbus_message_iter_next (&iter))
|
||||
{
|
||||
dbus_string = dbus_message_iter_get_string (&iter);
|
||||
network = (dbus_string == NULL ? NULL : strdup (dbus_string));
|
||||
dbus_free (dbus_string);
|
||||
}
|
||||
|
||||
if (device && network)
|
||||
nmi_show_user_key_dialog (device, network, info);
|
||||
|
||||
g_free (device);
|
||||
g_free (network);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmi_dbus_dbus_return_user_key
|
||||
*
|
||||
|
@ -98,6 +133,205 @@ void nmi_dbus_return_user_key (DBusConnection *connection, const char *device,
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmi_dbus_get_allowed_networks
|
||||
*
|
||||
* Grab a list of allowed access points from GConf and return it in the form
|
||||
* of a string array in a dbus message.
|
||||
*
|
||||
*/
|
||||
static DBusMessage *nmi_dbus_get_allowed_networks (NMIAppInfo *info, DBusMessage *message)
|
||||
{
|
||||
GSList *dir_list = NULL;
|
||||
GSList *element = NULL;
|
||||
DBusMessage *reply_message = NULL;
|
||||
DBusMessageIter iter;
|
||||
DBusMessageIter iter_array;
|
||||
gchar *path = NULL;
|
||||
|
||||
/* List all allowed access points that gconf knows about */
|
||||
path = g_strdup_printf ("%s/allowed_networks", NMI_GCONF_WIRELESS_NETWORKING_PATH);
|
||||
element = dir_list = gconf_client_all_dirs (info->gconf_client, path, NULL);
|
||||
g_free (path);
|
||||
|
||||
reply_message = dbus_message_new_method_return (message);
|
||||
dbus_message_iter_init (reply_message, &iter);
|
||||
dbus_message_iter_append_array (&iter, &iter_array, DBUS_TYPE_STRING);
|
||||
|
||||
if (!dir_list)
|
||||
dbus_message_iter_append_string (&iter_array, "");
|
||||
else
|
||||
{
|
||||
gboolean value_added = FALSE;
|
||||
|
||||
/* Append the essid of every allowed access point we know of
|
||||
* to a string array in the dbus message.
|
||||
*/
|
||||
while (element)
|
||||
{
|
||||
gchar key[100];
|
||||
GConfValue *value;
|
||||
|
||||
g_snprintf (&key[0], 99, "%s/essid", element->data);
|
||||
value = gconf_client_get (info->gconf_client, key, NULL);
|
||||
if (value && gconf_value_get_string (value))
|
||||
{
|
||||
dbus_message_iter_append_string (&iter_array, gconf_value_get_string (value));
|
||||
value_added = TRUE;
|
||||
gconf_value_free (value);
|
||||
}
|
||||
|
||||
g_free (element->data);
|
||||
element = element->next;
|
||||
}
|
||||
g_slist_free (dir_list);
|
||||
|
||||
/* Make sure that there's at least one array element if all the gconf calls failed */
|
||||
if (!value_added)
|
||||
dbus_message_iter_append_string (&iter_array, "");
|
||||
}
|
||||
|
||||
return (reply_message);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmi_dbus_get_allowed_network_prio
|
||||
*
|
||||
* If the specified allowed network exists, get its priority from gconf
|
||||
* and pass it back as a dbus message.
|
||||
*
|
||||
*/
|
||||
static DBusMessage *nmi_dbus_get_allowed_network_prio (NMIAppInfo *info, DBusMessage *message)
|
||||
{
|
||||
DBusMessage *reply_message = NULL;
|
||||
gchar *key = NULL;
|
||||
char *network = NULL;
|
||||
GConfValue *value;
|
||||
DBusMessageIter iter;
|
||||
|
||||
dbus_message_iter_init (message, &iter);
|
||||
network = dbus_message_iter_get_string (&iter);
|
||||
if (!network)
|
||||
{
|
||||
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_NMI_NAMESPACE, "InvalidNetwork",
|
||||
"NetworkManagerInfo::getAllowedNetworkPriority called with invalid network.");
|
||||
return (reply_message);
|
||||
}
|
||||
|
||||
/* List all allowed access points that gconf knows about */
|
||||
key = g_strdup_printf ("%s/allowed_networks/%s/priority", NMI_GCONF_WIRELESS_NETWORKING_PATH, network);
|
||||
value = gconf_client_get (info->gconf_client, key, NULL);
|
||||
g_free (key);
|
||||
|
||||
if (value)
|
||||
{
|
||||
reply_message = dbus_message_new_method_return (message);
|
||||
dbus_message_iter_init (reply_message, &iter);
|
||||
dbus_message_iter_append_uint32 (&iter, gconf_value_get_int (value));
|
||||
gconf_value_free (value);
|
||||
}
|
||||
else
|
||||
{
|
||||
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_NMI_NAMESPACE, "BadNetworkData",
|
||||
"NetworkManagerInfo::getAllowedNetworkPriority could not access data for network '%s'", network);
|
||||
}
|
||||
|
||||
return (reply_message);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmi_dbus_get_allowed_network_essid
|
||||
*
|
||||
* If the specified allowed network exists, get its essid from gconf
|
||||
* and pass it back as a dbus message.
|
||||
*
|
||||
*/
|
||||
static DBusMessage *nmi_dbus_get_allowed_network_essid (NMIAppInfo *info, DBusMessage *message)
|
||||
{
|
||||
DBusMessage *reply_message = NULL;
|
||||
gchar *key = NULL;
|
||||
char *network = NULL;
|
||||
GConfValue *value;
|
||||
DBusMessageIter iter;
|
||||
|
||||
dbus_message_iter_init (message, &iter);
|
||||
network = dbus_message_iter_get_string (&iter);
|
||||
if (!network)
|
||||
{
|
||||
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_NMI_NAMESPACE, "InvalidNetwork",
|
||||
"NetworkManagerInfo::getAllowedNetworkEssid called with invalid network.");
|
||||
return (reply_message);
|
||||
}
|
||||
|
||||
/* List all allowed access points that gconf knows about */
|
||||
key = g_strdup_printf ("%s/allowed_networks/%s/essid", NMI_GCONF_WIRELESS_NETWORKING_PATH, network);
|
||||
value = gconf_client_get (info->gconf_client, key, NULL);
|
||||
g_free (key);
|
||||
|
||||
if (value)
|
||||
{
|
||||
reply_message = dbus_message_new_method_return (message);
|
||||
dbus_message_iter_init (reply_message, &iter);
|
||||
dbus_message_iter_append_string (&iter, gconf_value_get_string (value));
|
||||
gconf_value_free (value);
|
||||
}
|
||||
else
|
||||
{
|
||||
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_NMI_NAMESPACE, "BadNetworkData",
|
||||
"NetworkManagerInfo::getAllowedNetworkEssid could not access data for network '%s'", network);
|
||||
}
|
||||
|
||||
return (reply_message);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmi_dbus_get_allowed_network_key
|
||||
*
|
||||
* If the specified allowed network exists, get its key from gconf
|
||||
* and pass it back as a dbus message.
|
||||
*
|
||||
*/
|
||||
static DBusMessage *nmi_dbus_get_allowed_network_key (NMIAppInfo *info, DBusMessage *message)
|
||||
{
|
||||
DBusMessage *reply_message = NULL;
|
||||
gchar *key = NULL;
|
||||
char *network = NULL;
|
||||
GConfValue *value;
|
||||
DBusMessageIter iter;
|
||||
|
||||
dbus_message_iter_init (message, &iter);
|
||||
network = dbus_message_iter_get_string (&iter);
|
||||
if (!network)
|
||||
{
|
||||
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_NMI_NAMESPACE, "InvalidNetwork",
|
||||
"NetworkManagerInfo::getAllowedNetworkKey called with invalid network.");
|
||||
return (reply_message);
|
||||
}
|
||||
|
||||
/* List all allowed access points that gconf knows about */
|
||||
key = g_strdup_printf ("%s/allowed_networks/%s/key", NMI_GCONF_WIRELESS_NETWORKING_PATH, network);
|
||||
value = gconf_client_get (info->gconf_client, key, NULL);
|
||||
g_free (key);
|
||||
|
||||
/* In the case of the key, we don't error out if no key was found in gconf */
|
||||
reply_message = dbus_message_new_method_return (message);
|
||||
dbus_message_iter_init (reply_message, &iter);
|
||||
|
||||
if (value)
|
||||
{
|
||||
dbus_message_iter_append_string (&iter, gconf_value_get_string (value));
|
||||
gconf_value_free (value);
|
||||
}
|
||||
else
|
||||
dbus_message_iter_append_string (&iter, "");
|
||||
|
||||
return (reply_message);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmi_dbus_nmi_message_handler
|
||||
*
|
||||
|
@ -122,32 +356,7 @@ static DBusHandlerResult nmi_dbus_nmi_message_handler (DBusConnection *connectio
|
|||
{
|
||||
GtkWidget *dialog = glade_xml_get_widget (info->xml, "passphrase_dialog");
|
||||
if (!GTK_WIDGET_VISIBLE (dialog))
|
||||
{
|
||||
DBusMessageIter iter;
|
||||
char *dbus_string;
|
||||
char *device = NULL;
|
||||
char *network = NULL;
|
||||
|
||||
dbus_message_iter_init (message, &iter);
|
||||
/* Grab device */
|
||||
dbus_string = dbus_message_iter_get_string (&iter);
|
||||
device = (dbus_string == NULL ? NULL : strdup (dbus_string));
|
||||
dbus_free (dbus_string);
|
||||
|
||||
/* Grab network to get key for */
|
||||
if (dbus_message_iter_next (&iter))
|
||||
{
|
||||
dbus_string = dbus_message_iter_get_string (&iter);
|
||||
network = (dbus_string == NULL ? NULL : strdup (dbus_string));
|
||||
dbus_free (dbus_string);
|
||||
}
|
||||
|
||||
if (device && network)
|
||||
nmi_show_user_key_dialog (device, network, info);
|
||||
|
||||
g_free (device);
|
||||
g_free (network);
|
||||
}
|
||||
nmi_dbus_get_key_for_network (info, message);
|
||||
}
|
||||
else if (strcmp ("cancelGetKeyForNetwork", method) == 0)
|
||||
{
|
||||
|
@ -155,12 +364,24 @@ static DBusHandlerResult nmi_dbus_nmi_message_handler (DBusConnection *connectio
|
|||
if (GTK_WIDGET_VISIBLE (dialog))
|
||||
nmi_cancel_user_key_dialog (info);
|
||||
}
|
||||
else if (strcmp ("getAllowedNetworks", method) == 0)
|
||||
reply_message = nmi_dbus_get_allowed_networks (info, message);
|
||||
else if (strcmp ("getAllowedNetworkPriority", method) == 0)
|
||||
reply_message = nmi_dbus_get_allowed_network_prio (info, message);
|
||||
else if (strcmp ("getAllowedNetworkEssid", method) == 0)
|
||||
reply_message = nmi_dbus_get_allowed_network_essid (info, message);
|
||||
else if (strcmp ("getAllowedNetworkKey", method) == 0)
|
||||
reply_message = nmi_dbus_get_allowed_network_key (info, message);
|
||||
else
|
||||
{
|
||||
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_NMI_NAMESPACE, "UnknownMethod",
|
||||
"NetworkManagerInfo knows nothing about the method %s for object %s", method, path);
|
||||
}
|
||||
|
||||
if (reply_message)
|
||||
{
|
||||
dbus_connection_send (connection, reply_message, NULL);
|
||||
dbus_message_unref (reply_message);
|
||||
}
|
||||
|
||||
return (DBUS_HANDLER_RESULT_HANDLED);
|
||||
|
|
|
@ -56,6 +56,8 @@ ECHO_N = @ECHO_N@
|
|||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
GCONF_CFLAGS = @GCONF_CFLAGS@
|
||||
GCONF_LIBS = @GCONF_LIBS@
|
||||
GLADE_CFLAGS = @GLADE_CFLAGS@
|
||||
GLADE_LIBS = @GLADE_LIBS@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
|
|
|
@ -4,6 +4,7 @@ INCLUDES = \
|
|||
$(NM_CFLAGS) \
|
||||
-Wall \
|
||||
-DDBUS_API_SUBJECT_TO_CHANGE \
|
||||
-DG_DISABLE_DEPRECATED \
|
||||
-DBINDIR=\"$(bindir)\" \
|
||||
-DDATADIR=\"$(datadir)\"
|
||||
|
||||
|
|
|
@ -56,6 +56,8 @@ ECHO_N = @ECHO_N@
|
|||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
GCONF_CFLAGS = @GCONF_CFLAGS@
|
||||
GCONF_LIBS = @GCONF_LIBS@
|
||||
GLADE_CFLAGS = @GLADE_CFLAGS@
|
||||
GLADE_LIBS = @GLADE_LIBS@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
|
@ -115,6 +117,7 @@ INCLUDES = \
|
|||
$(NM_CFLAGS) \
|
||||
-Wall \
|
||||
-DDBUS_API_SUBJECT_TO_CHANGE \
|
||||
-DG_DISABLE_DEPRECATED \
|
||||
-DBINDIR=\"$(bindir)\" \
|
||||
-DDATADIR=\"$(datadir)\"
|
||||
|
||||
|
|
|
@ -129,27 +129,21 @@ NMDevice *nm_dbus_get_device_from_object_path (const char *path)
|
|||
* Returns the network (ap) associated with a dbus object path
|
||||
*
|
||||
*/
|
||||
NMAccessPoint *nm_dbus_get_network_from_object_path (const char *path, NMDevice *dev, int *ap_index)
|
||||
NMAccessPoint *nm_dbus_get_network_from_object_path (const char *path, NMDevice *dev)
|
||||
{
|
||||
NMAccessPoint *ap = NULL;
|
||||
int i = 0;
|
||||
char compare_path[100];
|
||||
|
||||
*ap_index = -1;
|
||||
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
|
||||
while ((ap = nm_device_ap_list_get_ap_by_index (dev, i)) != NULL)
|
||||
{
|
||||
snprintf (compare_path, 100, "%s/%s/Networks/%d", NM_DBUS_DEVICES_OBJECT_PATH_PREFIX, nm_device_get_iface (dev), i);
|
||||
snprintf (compare_path, 100, "%s/%s/Networks/%s", NM_DBUS_DEVICES_OBJECT_PATH_PREFIX,
|
||||
nm_device_get_iface (dev), nm_ap_get_essid (ap));
|
||||
if (strncmp (path, compare_path, strlen (compare_path)) == 0)
|
||||
{
|
||||
*ap_index = i;
|
||||
break;
|
||||
}
|
||||
else
|
||||
ap = NULL;
|
||||
|
||||
ap = NULL;
|
||||
i++;
|
||||
}
|
||||
|
||||
|
@ -547,10 +541,9 @@ static DBusMessage *nm_dbus_devices_handle_networks_request (DBusConnection *con
|
|||
NMAccessPoint *ap;
|
||||
DBusMessage *reply_message = NULL;
|
||||
DBusMessageIter iter;
|
||||
int ap_index;
|
||||
|
||||
ap = nm_dbus_get_network_from_object_path (path, dev, &ap_index);
|
||||
if (!ap || (ap_index == -1))
|
||||
ap = nm_dbus_get_network_from_object_path (path, dev);
|
||||
if (!ap)
|
||||
{
|
||||
reply_message = nm_dbus_create_error_message (message, NM_DBUS_NM_NAMESPACE, "NetworkNotFound",
|
||||
"The requested network does not exist for this device.");
|
||||
|
@ -632,24 +625,16 @@ static DBusMessage *nm_dbus_devices_handle_request (DBusConnection *connection,
|
|||
dbus_message_iter_append_uint32 (&iter, nm_device_get_ip4_address (dev));
|
||||
else if (strcmp ("getActiveNetwork", request) == 0)
|
||||
{
|
||||
NMAccessPoint *ap = NULL;
|
||||
int i = 0;
|
||||
|
||||
while ((ap = nm_device_ap_list_get_ap_by_index (dev, i)) != NULL)
|
||||
{
|
||||
if (nm_null_safe_strcmp (nm_ap_get_essid (ap), nm_device_get_essid (dev)) == 0)
|
||||
{
|
||||
object_path = g_strdup_printf ("%s/%s/Networks/%d", NM_DBUS_DEVICES_OBJECT_PATH_PREFIX, nm_device_get_iface (dev), i);
|
||||
dbus_message_iter_append_string (&iter, object_path);
|
||||
g_free (object_path);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
ap = NULL;
|
||||
}
|
||||
NMAccessPoint *ap = nm_device_ap_list_get_ap_by_essid (dev, nm_device_get_essid (dev));
|
||||
|
||||
/* If we didn't find the devices current network among the known networks, just append a blank item */
|
||||
if (!ap)
|
||||
if (ap)
|
||||
{
|
||||
object_path = g_strdup_printf ("%s/%s/Networks/%s", NM_DBUS_DEVICES_OBJECT_PATH_PREFIX,
|
||||
nm_device_get_iface (dev), nm_ap_get_essid (ap));
|
||||
dbus_message_iter_append_string (&iter, object_path);
|
||||
g_free (object_path);
|
||||
}
|
||||
else
|
||||
dbus_message_iter_append_string (&iter, "");
|
||||
}
|
||||
else if (strcmp ("getNetworks", request) == 0)
|
||||
|
@ -659,10 +644,10 @@ static DBusMessage *nm_dbus_devices_handle_request (DBusConnection *connection,
|
|||
int i = 0;
|
||||
|
||||
dbus_message_iter_append_array (&iter, &iter_array, DBUS_TYPE_STRING);
|
||||
|
||||
while ((ap = nm_device_ap_list_get_ap_by_index (dev, i)) != NULL)
|
||||
{
|
||||
object_path = g_strdup_printf ("%s/%s/Networks/%d", NM_DBUS_DEVICES_OBJECT_PATH_PREFIX, nm_device_get_iface (dev), i);
|
||||
object_path = g_strdup_printf ("%s/%s/Networks/%s", NM_DBUS_DEVICES_OBJECT_PATH_PREFIX,
|
||||
nm_device_get_iface (dev), nm_ap_get_essid (ap));
|
||||
dbus_message_iter_append_string (&iter_array, object_path);
|
||||
g_free (object_path);
|
||||
|
||||
|
|
|
@ -4,7 +4,10 @@ INCLUDES = \
|
|||
-DBINDIR=\"$(bindir)\" \
|
||||
-DDATADIR=\"$(datadir)\"
|
||||
|
||||
noinst_PROGRAMS = nmtest
|
||||
noinst_PROGRAMS = nmtest nminfotest
|
||||
|
||||
nmtest_SOURCES = nmclienttest.c
|
||||
nmtest_LDADD = $(NM_LIBS)
|
||||
|
||||
nminfotest_SOURCES = nminfotest.c
|
||||
nminfotest_LDADD = $(NM_LIBS)
|
||||
|
|
|
@ -56,6 +56,8 @@ ECHO_N = @ECHO_N@
|
|||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
GCONF_CFLAGS = @GCONF_CFLAGS@
|
||||
GCONF_LIBS = @GCONF_LIBS@
|
||||
GLADE_CFLAGS = @GLADE_CFLAGS@
|
||||
GLADE_LIBS = @GLADE_LIBS@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
|
@ -116,17 +118,24 @@ INCLUDES = \
|
|||
-DDATADIR=\"$(datadir)\"
|
||||
|
||||
|
||||
noinst_PROGRAMS = nmtest
|
||||
noinst_PROGRAMS = nmtest nminfotest
|
||||
|
||||
nmtest_SOURCES = nmclienttest.c
|
||||
nmtest_LDADD = $(NM_LIBS)
|
||||
|
||||
nminfotest_SOURCES = nminfotest.c
|
||||
nminfotest_LDADD = $(NM_LIBS)
|
||||
subdir = test
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_CLEAN_FILES =
|
||||
noinst_PROGRAMS = nmtest$(EXEEXT)
|
||||
noinst_PROGRAMS = nmtest$(EXEEXT) nminfotest$(EXEEXT)
|
||||
PROGRAMS = $(noinst_PROGRAMS)
|
||||
|
||||
am_nminfotest_OBJECTS = nminfotest.$(OBJEXT)
|
||||
nminfotest_OBJECTS = $(am_nminfotest_OBJECTS)
|
||||
nminfotest_DEPENDENCIES =
|
||||
nminfotest_LDFLAGS =
|
||||
am_nmtest_OBJECTS = nmclienttest.$(OBJEXT)
|
||||
nmtest_OBJECTS = $(am_nmtest_OBJECTS)
|
||||
nmtest_DEPENDENCIES =
|
||||
|
@ -135,14 +144,15 @@ nmtest_LDFLAGS =
|
|||
DEFAULT_INCLUDES = -I. -I$(srcdir)
|
||||
depcomp = $(SHELL) $(top_srcdir)/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/nmclienttest.Po
|
||||
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/nmclienttest.Po \
|
||||
@AMDEP_TRUE@ ./$(DEPDIR)/nminfotest.Po
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
|
||||
DIST_SOURCES = $(nmtest_SOURCES)
|
||||
DIST_SOURCES = $(nminfotest_SOURCES) $(nmtest_SOURCES)
|
||||
DIST_COMMON = $(srcdir)/Makefile.in Makefile.am
|
||||
SOURCES = $(nmtest_SOURCES)
|
||||
SOURCES = $(nminfotest_SOURCES) $(nmtest_SOURCES)
|
||||
|
||||
all: all-am
|
||||
|
||||
|
@ -156,6 +166,9 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
|||
|
||||
clean-noinstPROGRAMS:
|
||||
-test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS)
|
||||
nminfotest$(EXEEXT): $(nminfotest_OBJECTS) $(nminfotest_DEPENDENCIES)
|
||||
@rm -f nminfotest$(EXEEXT)
|
||||
$(LINK) $(nminfotest_LDFLAGS) $(nminfotest_OBJECTS) $(nminfotest_LDADD) $(LIBS)
|
||||
nmtest$(EXEEXT): $(nmtest_OBJECTS) $(nmtest_DEPENDENCIES)
|
||||
@rm -f nmtest$(EXEEXT)
|
||||
$(LINK) $(nmtest_LDFLAGS) $(nmtest_OBJECTS) $(nmtest_LDADD) $(LIBS)
|
||||
|
@ -167,6 +180,7 @@ distclean-compile:
|
|||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nmclienttest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nminfotest.Po@am__quote@
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
|
||||
|
|
192
test/nminfotest.c
Normal file
192
test/nminfotest.c
Normal file
|
@ -0,0 +1,192 @@
|
|||
#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;
|
||||
}
|
Loading…
Reference in a new issue