mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-08 11:50:22 +01:00
2005-02-25 Dan Williams <dcbw@redhat.com>
* info-daemon/NetworkManagerInfoDbus.c - (nmi_dbus_get_network_properties): whack usage of DbusMessageIter * test/nminfotest.c - Whack usage of DbusMessageIter - Clean up DbusError and DbusMessage handling and freeing - Remove unused unregister handler * test/nmtest.c - Whack usage of DbusMessageIter * test/nmtestdevices.c - Whack usage of DbusMessageIter git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@471 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
a183dbea42
commit
12bc1bb923
5 changed files with 83 additions and 86 deletions
16
ChangeLog
16
ChangeLog
|
|
@ -1,3 +1,19 @@
|
|||
2005-02-25 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* info-daemon/NetworkManagerInfoDbus.c
|
||||
- (nmi_dbus_get_network_properties): whack usage of DbusMessageIter
|
||||
|
||||
* test/nminfotest.c
|
||||
- Whack usage of DbusMessageIter
|
||||
- Clean up DbusError and DbusMessage handling and freeing
|
||||
- Remove unused unregister handler
|
||||
|
||||
* test/nmtest.c
|
||||
- Whack usage of DbusMessageIter
|
||||
|
||||
* test/nmtestdevices.c
|
||||
- Whack usage of DbusMessageIter
|
||||
|
||||
2005-02-25 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* NetworkManager.h
|
||||
|
|
|
|||
|
|
@ -339,7 +339,7 @@ static DBusMessage *nmi_dbus_get_networks (NMIAppInfo *info, DBusMessage *messag
|
|||
*/
|
||||
static DBusMessage *nmi_dbus_get_network_properties (NMIAppInfo *info, DBusMessage *message)
|
||||
{
|
||||
DBusMessage *reply_message = NULL;
|
||||
DBusMessage *reply = NULL;
|
||||
gchar *gconf_key = NULL;
|
||||
char *network = NULL;
|
||||
GConfValue *value;
|
||||
|
|
@ -363,9 +363,9 @@ static DBusMessage *nmi_dbus_get_network_properties (NMIAppInfo *info, DBusMessa
|
|||
|| !nmi_network_type_valid (type)
|
||||
|| (strlen (network) <= 0))
|
||||
{
|
||||
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments",
|
||||
reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments",
|
||||
"NetworkManagerInfo::getNetworkProperties called with invalid arguments.");
|
||||
return (reply_message);
|
||||
return (reply);
|
||||
}
|
||||
|
||||
escaped_network = gconf_escape_key (network, strlen (network));
|
||||
|
|
@ -434,59 +434,57 @@ static DBusMessage *nmi_dbus_get_network_properties (NMIAppInfo *info, DBusMessa
|
|||
{
|
||||
if (!essid)
|
||||
{
|
||||
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadNetworkData",
|
||||
reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadNetworkData",
|
||||
"NetworkManagerInfo::getNetworkProperties could not access essid for network '%s'", network);
|
||||
}
|
||||
else if (timestamp < 0)
|
||||
{
|
||||
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadNetworkData",
|
||||
reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadNetworkData",
|
||||
"NetworkManagerInfo::getNetworkProperties could not access timestamp for network '%s'", network);
|
||||
}
|
||||
else if (key_type < 0)
|
||||
{
|
||||
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadNetworkData",
|
||||
reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadNetworkData",
|
||||
"NetworkManagerInfo::getNetworkProperties could not access key_type for network '%s'", network);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DBusMessageIter iter;
|
||||
DBusMessageIter iter_array;
|
||||
gboolean success = FALSE;
|
||||
|
||||
reply_message = dbus_message_new_method_return (message);
|
||||
dbus_message_iter_init (reply_message, &iter);
|
||||
|
||||
/* Add general properties to dbus reply */
|
||||
dbus_message_iter_append_string (&iter, essid);
|
||||
dbus_message_iter_append_int32 (&iter, timestamp);
|
||||
dbus_message_iter_append_string (&iter, key);
|
||||
dbus_message_iter_append_int32 (&iter, key_type);
|
||||
dbus_message_iter_append_int32 (&iter, auth_method);
|
||||
dbus_message_iter_append_boolean(&iter, trusted);
|
||||
|
||||
dbus_message_iter_append_array (&iter, &iter_array, DBUS_TYPE_STRING);
|
||||
char **array = NULL;
|
||||
int num_items = 0;
|
||||
|
||||
/* Add a string array of access point MAC addresses if the array is valid */
|
||||
if (ap_addrs_value && (ap_addrs_value->type == GCONF_VALUE_LIST) && (gconf_value_get_list_type (ap_addrs_value) == GCONF_VALUE_STRING))
|
||||
if ( ap_addrs_value
|
||||
&& (ap_addrs_value->type == GCONF_VALUE_LIST)
|
||||
&& (gconf_value_get_list_type (ap_addrs_value) == GCONF_VALUE_STRING))
|
||||
{
|
||||
GSList *list = gconf_value_get_list (ap_addrs_value);
|
||||
GSList *elem = list;
|
||||
GSList *list = gconf_value_get_list (ap_addrs_value);
|
||||
GSList *elt;
|
||||
int i;
|
||||
|
||||
while (elem != NULL)
|
||||
num_items = g_slist_length (list);
|
||||
if (num_items > 0)
|
||||
array = g_malloc0 (sizeof (char *) * num_items);
|
||||
|
||||
for (elt = list, i = 0; elt; elt = g_slist_next (elt), i++)
|
||||
{
|
||||
const char *string = gconf_value_get_string ((GConfValue *)elem->data);
|
||||
if (string)
|
||||
{
|
||||
dbus_message_iter_append_string (&iter_array, string);
|
||||
success = TRUE;
|
||||
}
|
||||
elem = g_slist_next (elem);
|
||||
const char *string;
|
||||
if ((string = gconf_value_get_string ((GConfValue *)elt->data)))
|
||||
array[i] = g_strdup (string);
|
||||
}
|
||||
}
|
||||
|
||||
if (!success)
|
||||
dbus_message_iter_append_string (&iter_array, "");
|
||||
reply = dbus_message_new_method_return (message);
|
||||
|
||||
/* Add general properties to dbus reply */
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, essid,
|
||||
DBUS_TYPE_INT32, timestamp,
|
||||
DBUS_TYPE_STRING, key,
|
||||
DBUS_TYPE_INT32, key_type,
|
||||
DBUS_TYPE_INT32, auth_method,
|
||||
DBUS_TYPE_BOOLEAN, trusted,
|
||||
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, array, num_items,
|
||||
DBUS_TYPE_INVALID);
|
||||
}
|
||||
gconf_value_free (ap_addrs_value);
|
||||
|
||||
|
|
@ -495,7 +493,7 @@ static DBusMessage *nmi_dbus_get_network_properties (NMIAppInfo *info, DBusMessa
|
|||
|
||||
g_free (escaped_network);
|
||||
dbus_free (network);
|
||||
return (reply_message);
|
||||
return (reply);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ char * get_network_string_property (DBusConnection *connection, char *network, c
|
|||
{
|
||||
DBusMessage *message;
|
||||
DBusMessage *reply;
|
||||
DBusMessageIter iter;
|
||||
DBusError error;
|
||||
char *string, *ret_string;
|
||||
char *string = NULL;
|
||||
char *ret_string = NULL;
|
||||
|
||||
message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, method);
|
||||
if (message == NULL)
|
||||
|
|
@ -48,33 +48,33 @@ char * get_network_string_property (DBusConnection *connection, char *network, c
|
|||
dbus_message_append_args (message, DBUS_TYPE_STRING, network, DBUS_TYPE_INT32, type, DBUS_TYPE_INVALID);
|
||||
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);
|
||||
dbus_message_unref (message);
|
||||
dbus_error_free (&error);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (reply == NULL)
|
||||
{
|
||||
fprintf( stderr, "dbus reply message was NULL\n" );
|
||||
dbus_message_unref (message);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* now analyze reply */
|
||||
dbus_message_iter_init (reply, &iter);
|
||||
string = dbus_message_iter_get_string (&iter);
|
||||
if (!string)
|
||||
dbus_error_init (&error);
|
||||
if (dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &string, DBUS_TYPE_INVALID) && string)
|
||||
{
|
||||
fprintf (stderr, "NetworkManagerInfo returned a NULL string for method '%s'", method );
|
||||
return NULL;
|
||||
ret_string = g_strdup (string);
|
||||
dbus_free (string);
|
||||
}
|
||||
ret_string = g_strdup (string);
|
||||
dbus_free (string);
|
||||
|
||||
dbus_message_unref (reply);
|
||||
dbus_message_unref (message);
|
||||
|
||||
if (!string)
|
||||
fprintf (stderr, "NetworkManagerInfo returned a NULL string for method '%s'", method );
|
||||
|
||||
if (dbus_error_is_set (&error))
|
||||
dbus_error_free (&error);
|
||||
|
||||
return (ret_string);
|
||||
}
|
||||
|
|
@ -83,9 +83,8 @@ gboolean get_network_trusted (DBusConnection *connection, char *network, NMNetwo
|
|||
{
|
||||
DBusMessage *message;
|
||||
DBusMessage *reply;
|
||||
DBusMessageIter iter;
|
||||
DBusError error;
|
||||
gboolean trusted = FALSE;
|
||||
gboolean trusted = FALSE;
|
||||
|
||||
g_return_val_if_fail (connection != NULL, -1);
|
||||
g_return_val_if_fail (network != NULL, -1);
|
||||
|
|
@ -100,17 +99,18 @@ gboolean get_network_trusted (DBusConnection *connection, char *network, NMNetwo
|
|||
dbus_error_init (&error);
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, network, DBUS_TYPE_INT32, type, DBUS_TYPE_INVALID);
|
||||
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);
|
||||
dbus_message_unref (message);
|
||||
dbus_error_free (&error);
|
||||
dbus_message_unref (reply);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (reply == NULL)
|
||||
{
|
||||
fprintf( stderr, "dbus reply message was NULL\n" );
|
||||
dbus_message_unref (message);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
|
@ -122,7 +122,6 @@ gboolean get_network_trusted (DBusConnection *connection, char *network, NMNetwo
|
|||
dbus_error_free (&error);
|
||||
|
||||
dbus_message_unref (reply);
|
||||
dbus_message_unref (message);
|
||||
|
||||
return (trusted);
|
||||
}
|
||||
|
|
@ -148,30 +147,31 @@ void get_networks_of_type (DBusConnection *connection, NMNetworkType type)
|
|||
dbus_error_init (&error);
|
||||
dbus_message_append_args (message, DBUS_TYPE_INT32, type, DBUS_TYPE_INVALID);
|
||||
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);
|
||||
dbus_message_unref (message);
|
||||
dbus_error_free (&error);
|
||||
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);
|
||||
if (!dbus_message_iter_get_string_array (&iter, &networks, &num_networks))
|
||||
dbus_error_init (&error);
|
||||
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
|
||||
&networks, &num_networks, DBUS_TYPE_INVALID))
|
||||
{
|
||||
fprintf (stderr, "NetworkManagerInfo returned no network list" );
|
||||
dbus_message_unref (reply);
|
||||
return;
|
||||
}
|
||||
|
||||
dbus_message_unref (reply);
|
||||
dbus_message_unref (message);
|
||||
|
||||
if (!networks)
|
||||
fprintf( stderr, "No networks found\n" );
|
||||
|
|
@ -275,24 +275,12 @@ static DBusHandlerResult nm_message_handler (DBusConnection *connection, DBusMes
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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;
|
||||
DBusConnection *connection2;
|
||||
DBusError error;
|
||||
DBusObjectPathVTable vtable = { &nm_unregister_handler, &nm_message_handler, NULL, NULL, NULL, NULL };
|
||||
DBusObjectPathVTable vtable = { NULL, &nm_message_handler, NULL, NULL, NULL, NULL };
|
||||
dbus_bool_t success = FALSE;
|
||||
GMainLoop *loop = NULL;
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,6 @@ static int nmwa_dbus_call_nm_method (DBusConnection *con, const char *path, cons
|
|||
char **dbus_string_array = NULL;
|
||||
int num_items = 0;
|
||||
dbus_bool_t ret = TRUE;
|
||||
DBusMessageIter iter;
|
||||
|
||||
g_return_val_if_fail (con != NULL, RETURN_FAILURE);
|
||||
g_return_val_if_fail (path != NULL, RETURN_FAILURE);
|
||||
|
|
@ -121,8 +120,7 @@ static int nmwa_dbus_call_nm_method (DBusConnection *con, const char *path, cons
|
|||
ret = dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &dbus_string, DBUS_TYPE_INVALID);
|
||||
break;
|
||||
case DBUS_TYPE_STRING_ARRAY:
|
||||
dbus_message_iter_init (reply, &iter);
|
||||
ret = dbus_message_iter_get_string_array (&iter, &dbus_string_array, &num_items);
|
||||
ret = dbus_message_get_args (reply, &error, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &dbus_string_array, &num_items, DBUS_TYPE_INVALID);
|
||||
break;
|
||||
case DBUS_TYPE_INT32:
|
||||
ret = dbus_message_get_args (reply, &error, DBUS_TYPE_INT32, &dbus_int, DBUS_TYPE_INVALID);
|
||||
|
|
@ -317,7 +315,6 @@ void set_device_network (DBusConnection *connection, const char *path, const cha
|
|||
{
|
||||
DBusMessage *message;
|
||||
DBusMessage *reply;
|
||||
DBusMessageIter iter;
|
||||
DBusError error;
|
||||
|
||||
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ void create_device (DBusConnection *connection, NMDeviceType type)
|
|||
{
|
||||
DBusMessage *message;
|
||||
DBusMessage *reply;
|
||||
DBusMessageIter iter;
|
||||
DBusError error;
|
||||
char *string;
|
||||
|
||||
|
|
@ -51,35 +50,34 @@ void create_device (DBusConnection *connection, NMDeviceType type)
|
|||
dbus_error_init (&error);
|
||||
dbus_message_append_args (message, DBUS_TYPE_INT32, type, DBUS_TYPE_INVALID);
|
||||
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);
|
||||
dbus_error_free (&error);
|
||||
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)
|
||||
dbus_error_init (&error);
|
||||
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &string, DBUS_TYPE_INVALID) || !string)
|
||||
{
|
||||
fprintf (stderr, "NetworkManager returned a NULL test device ID, test device could not be created." );
|
||||
dbus_message_unref (reply);
|
||||
if (dbus_error_is_set (&error))
|
||||
dbus_error_free (&error);
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf (stderr, "New test device ID: '%s'\n", string );
|
||||
|
||||
dbus_free (string);
|
||||
dbus_message_unref (reply);
|
||||
dbus_message_unref (message);
|
||||
dbus_free (string);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue