diff options
author | Dan Williams <dcbw@redhat.com> | 2004-08-02 21:12:40 +0000 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2004-08-02 21:12:40 +0000 |
commit | 3151e9092e19756c5379f6b753e9a630246e8639 (patch) | |
tree | 29771d03d349f04fb507a4f4cfd4526c5e1fbe97 /test | |
parent | 8336b11023a3f781b13eb68d18c563ac1f5297f9 (diff) | |
download | NetworkManager-3151e9092e19756c5379f6b753e9a630246e8639.tar.gz |
2004-08-02 Dan Williams <dcbw@redhat.com>
* TODO
- new task: proper logging support
* info-daemon/NetworkManagerInfo.c
- Correct spelling of "canceled"
- Correct casting of objects for g_signal_connect()
* info-daemon/NetworkManagerInfoDbus.c
- Add defines for NetworkManager namespace and object path, and use them
- Add filter function to trap new signals from NetworkManager:
WirelessNetworkAppeared, WirelessNetworkDisappeared
* info-daemon/passphrase.glade
- Change name of "ok" button to "Login to Network..."
- Mark invisible
* src/NetworkManager.c
- Code and debug message cleanups
- Rename "nm_add_current_devices"->"nm_add_initial_devices"
- (nm_add_initial_devices) Check returned string array of devices
and don't try to add devices if array is NULL
- (main) Initialize libhal a bit later, make code a bit clearer
* src/NetworkManagerAP.[ch]
- New accessor and data member "matched": used to speed up AP list
diffing
- New accessor and data member "enc_method": will be used during key
fallback to cache which passphrase->key conversion actually works
so we don't have to do it every time
* src/NetworkManagerAPList.[ch]
- (nm_ap_list_find_ap_in_list) New: find an AP by essid in an AP list
- (nm_ap_list_diff) New: given two lists of access points, find the differences
between them, and send WirelessNetworkAppeared/Disappeared signals over
dbus in response to those differences
* src/NetworkManagerDbus.[ch]
- (nm_dbus_get_object_path_from_ap) New: given a device and an access point,
make an object path for that access point (NOTE that we don't yet check to
make sure that access point is actually in the device's AP list yet)
- (nm_dbus_get_ap_from_object_path) Renamed from nm_dbus_get_network_from_object_path
- (nm_dbus_signal_wireless_network_appeared, nm_dbus_signal_wireless_network_disappeared)
New: signal appearance/disappearance of wireless networks
- (nm_dbus_set_user_key_for_network) Mark the network/ap as invalid if the user cancelled
key entry
* src/NetworkManagerDevice.[ch]
- (nm_device_ap_list_clear) Use nm_ap_list_free rather than doing it ourselves
- (nm_device_ap_list_get) New: return the AP list (static function)
- (nm_device_do_normal_scan) Destroy old AP list later, so that we can diff the
new one resulting from the scan with the old one
* src/NetworkManagerWireless.c
- (nm_wireless_is_most_prefered_ap) "invalid" access points cannot be "best" access points
* test/nminfotest.c
- #define object paths and namespaces and use the #defines rather than static strings
- Test out user-key functionality of NetworkManagerInfo too
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@33 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
Diffstat (limited to 'test')
-rw-r--r-- | test/nminfotest.c | 151 |
1 files changed, 136 insertions, 15 deletions
diff --git a/test/nminfotest.c b/test/nminfotest.c index 9dbf608868..f5a6ad5d1f 100644 --- a/test/nminfotest.c +++ b/test/nminfotest.c @@ -21,9 +21,15 @@ #include <glib.h> #include <dbus/dbus.h> +#include <dbus/dbus-glib-lowlevel.h> #include <dbus/dbus-glib.h> #include <stdio.h> +#define NMI_DBUS_NMI_OBJECT_PATH_PREFIX "/org/freedesktop/NetworkManagerInfo" +#define NMI_DBUS_NMI_NAMESPACE "org.freedesktop.NetworkManagerInfo" +#define NM_DBUS_NM_OBJECT_PATH_PREFIX "/org/freedesktop/NetworkManager" +#define NM_DBUS_NM_NAMESPACE "org.freedesktop.NetworkManager" + char * get_network_string_property (DBusConnection *connection, char *network, char *method) { @@ -32,10 +38,10 @@ char * get_network_string_property (DBusConnection *connection, char *network, c DBusMessageIter iter; DBusError error; - message = dbus_message_new_method_call ("org.freedesktop.NetworkManagerInfo", - "/org/freedesktop/NetworkManagerInfo", - "org.freedesktop.NetworkManagerInfo", - method); + message = dbus_message_new_method_call (NMI_DBUS_NMI_NAMESPACE, + NMI_DBUS_NMI_OBJECT_PATH_PREFIX, + NMI_DBUS_NMI_NAMESPACE, + method); if (message == NULL) { fprintf (stderr, "Couldn't allocate the dbus message\n"); @@ -89,10 +95,10 @@ int get_network_prio (DBusConnection *connection, char *network) 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"); + message = dbus_message_new_method_call (NMI_DBUS_NMI_NAMESPACE, + NMI_DBUS_NMI_OBJECT_PATH_PREFIX, + NMI_DBUS_NMI_NAMESPACE, + "getAllowedNetworkPriority"); if (message == NULL) { fprintf (stderr, "Couldn't allocate the dbus message\n"); @@ -137,10 +143,10 @@ void get_allowed_networks (DBusConnection *connection) DBusMessageIter iter; DBusError error; - message = dbus_message_new_method_call ("org.freedesktop.NetworkManagerInfo", - "/org/freedesktop/NetworkManagerInfo", - "org.freedesktop.NetworkManagerInfo", - "getAllowedNetworks"); + message = dbus_message_new_method_call (NMI_DBUS_NMI_NAMESPACE, + NMI_DBUS_NMI_OBJECT_PATH_PREFIX, + NMI_DBUS_NMI_NAMESPACE, + "getAllowedNetworks"); if (message == NULL) { fprintf (stderr, "Couldn't allocate the dbus message\n"); @@ -191,13 +197,109 @@ void get_allowed_networks (DBusConnection *connection) dbus_free_string_array (networks); } +void get_user_key_for_network (DBusConnection *connection) +{ + DBusMessage *message; + + g_return_if_fail (connection != NULL); + + message = dbus_message_new_method_call (NMI_DBUS_NMI_NAMESPACE, NMI_DBUS_NMI_OBJECT_PATH_PREFIX, + NMI_DBUS_NMI_NAMESPACE, "getKeyForNetwork"); + if (message == NULL) + { + fprintf (stderr, "get_user_key_for_network(): Couldn't allocate the dbus message\n"); + return; + } + + dbus_message_append_args (message, DBUS_TYPE_STRING, "eth1", + DBUS_TYPE_STRING, "wireless-ap", + DBUS_TYPE_INVALID); + + if (!dbus_connection_send (connection, message, NULL)) + fprintf (stderr, "get_user_key_for_network(): could not send dbus message\n"); + + dbus_message_unref (message); +} + + +void set_user_key_for_network (DBusConnection *connection, DBusMessage *message, GMainLoop *loop) +{ + DBusError error; + char *device; + char *network; + char *passphrase; + + g_return_if_fail (connection != NULL); + g_return_if_fail (message != NULL); + + dbus_error_init (&error); + if (dbus_message_get_args (message, &error, + DBUS_TYPE_STRING, &device, + DBUS_TYPE_STRING, &network, + DBUS_TYPE_STRING, &passphrase, + DBUS_TYPE_INVALID)) + { + fprintf( stderr, "Device was '%s'\nNetwork was '%s'\nPassphrase was '%s'\n", device, network, passphrase); + + dbus_free (device); + dbus_free (network); + dbus_free (passphrase); + + g_main_loop_quit (loop); + } +} + + +static DBusHandlerResult nm_message_handler (DBusConnection *connection, DBusMessage *message, void *user_data) +{ + const char *method; + const char *path; + DBusMessage *reply_message = NULL; + gboolean handled = TRUE; + + g_return_val_if_fail (connection != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); + g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); + + method = dbus_message_get_member (message); + path = dbus_message_get_path (message); + + fprintf (stderr, "nm_dbus_nm_message_handler() got method %s for path %s\n", method, path); + + if (strcmp ("setKeyForNetwork", method) == 0) + set_user_key_for_network (connection, message, user_data); + else + handled = FALSE; + + return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED); +} + + +/* + * nm_dbus_nm_unregister_handler + * + * Nothing happens here. + * + */ +void nm_unregister_handler (DBusConnection *connection, void *user_data) +{ + /* do nothing */ +} + int main( int argc, char *argv[] ) { - DBusConnection *connection; - DBusError error; + DBusConnection *connection; + DBusConnection *connection2; + DBusError error; + DBusObjectPathVTable vtable = { &nm_unregister_handler, &nm_message_handler, NULL, NULL, NULL, NULL }; + dbus_bool_t success = FALSE; + GMainLoop *loop = NULL; + + loop = g_main_loop_new (NULL, FALSE); g_type_init (); + if (!g_thread_supported ()) + g_thread_init (NULL); dbus_error_init (&error); connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error); @@ -205,10 +307,29 @@ int main( int argc, char *argv[] ) { fprintf (stderr, "Error connecting to system bus: %s\n", error.message); dbus_error_free (&error); - return 1; + exit (1); + } + + dbus_connection_setup_with_g_main (connection, NULL); + dbus_error_init (&error); + dbus_bus_acquire_service (connection, NM_DBUS_NM_NAMESPACE, 0, &error); + if (dbus_error_is_set (&error)) + { + fprintf (stderr, "Could not acquire its service. dbus_bus_acquire_service() says: '%s'\n", error.message); + exit (1); + } + + success = dbus_connection_register_object_path (connection, NM_DBUS_NM_OBJECT_PATH_PREFIX, &vtable, loop); + if (!success) + { + fprintf (stderr, "Could not register a handler for NetworkManager. Not enough memory?\n"); + exit (1); } get_allowed_networks (connection); + get_user_key_for_network (connection); + + g_main_loop_run (loop); return 0; } |