2005-03-24 Dan Williams <dcbw@redhat.com>
* dhcpcd/dhcpcd.[ch] src/NetworkManagerDHCP.c - Switch names from "*_record_*" -> "*_element_*" to clarify things a bit (ie, dhcp_option_record_len -> dhcp_option_element_len) * src/NetworkManagerDbus.c - spacing cleanups * src/nm-dbus-dhcp.c - Make the API suck less. There is now only 1 type of each function, ie only "getInteger" and no longer also "getIntegerv". All types are returned encapsulated in a DBUS_TYPE_ARRAY, even for options that will never have more than 1 element. This should simplify things greatly. * test/nm-dhcp-opt-test.c - Make the tool not segfault - adapt to new DHCP Options API git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@506 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
21
ChangeLog
21
ChangeLog
@@ -1,3 +1,24 @@
|
||||
2005-03-24 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* dhcpcd/dhcpcd.[ch]
|
||||
src/NetworkManagerDHCP.c
|
||||
- Switch names from "*_record_*" -> "*_element_*" to clarify things a bit
|
||||
(ie, dhcp_option_record_len -> dhcp_option_element_len)
|
||||
|
||||
* src/NetworkManagerDbus.c
|
||||
- spacing cleanups
|
||||
|
||||
* src/nm-dbus-dhcp.c
|
||||
- Make the API suck less. There is now only 1 type of each function,
|
||||
ie only "getInteger" and no longer also "getIntegerv". All types
|
||||
are returned encapsulated in a DBUS_TYPE_ARRAY, even for options
|
||||
that will never have more than 1 element. This should simplify
|
||||
things greatly.
|
||||
|
||||
* test/nm-dhcp-opt-test.c
|
||||
- Make the tool not segfault
|
||||
- adapt to new DHCP Options API
|
||||
|
||||
2005-03-22 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* src/NetworkManager.c
|
||||
|
@@ -284,7 +284,7 @@ int dhcp_interface_option_len (dhcp_interface *iface, int val)
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int dhcp_option_record_len (int val)
|
||||
int dhcp_option_element_len (int val)
|
||||
{
|
||||
if ((val >= 0) && (val < dhcp_opt_table_len))
|
||||
return (dhcp_opt_table[val].len_hint);
|
||||
@@ -302,7 +302,7 @@ const char *dhcp_option_name (int val)
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
dhcp_option_type dhcp_option_record_type (int val)
|
||||
dhcp_option_type dhcp_option_element_type (int val)
|
||||
{
|
||||
if ((val >= 0) && (val < dhcp_opt_table_len))
|
||||
return (dhcp_opt_table[val].type);
|
||||
|
@@ -141,8 +141,8 @@ void dhcp_interface_cease (struct dhcp_interface *iface);
|
||||
int dhcp_interface_option_present (struct dhcp_interface *iface, int val);
|
||||
int dhcp_interface_option_len (struct dhcp_interface *iface, int val);
|
||||
void *dhcp_interface_option_payload (struct dhcp_interface *iface, int val);
|
||||
int dhcp_option_record_len (int val);
|
||||
dhcp_option_type dhcp_option_record_type (int val);
|
||||
int dhcp_option_element_len (int val);
|
||||
dhcp_option_type dhcp_option_element_type (int val);
|
||||
int dhcp_option_id_by_name (const char *name);
|
||||
const char * dhcp_option_name (int val);
|
||||
|
||||
|
@@ -144,20 +144,20 @@ static void nm_device_dhcp_configure (NMDevice *dev)
|
||||
|
||||
if (dhcp_interface_option_present (dev->dhcp_iface, subnetMask))
|
||||
{
|
||||
memcpy (&temp, dhcp_interface_option_payload (dev->dhcp_iface, subnetMask), dhcp_option_record_len (subnetMask));
|
||||
memcpy (&temp, dhcp_interface_option_payload (dev->dhcp_iface, subnetMask), dhcp_option_element_len (subnetMask));
|
||||
nm_system_device_set_ip4_netmask (dev, temp);
|
||||
}
|
||||
|
||||
if (dhcp_interface_option_present (dev->dhcp_iface, broadcastAddr))
|
||||
{
|
||||
memcpy (&temp, dhcp_interface_option_payload (dev->dhcp_iface, broadcastAddr), dhcp_option_record_len (broadcastAddr));
|
||||
memcpy (&temp, dhcp_interface_option_payload (dev->dhcp_iface, broadcastAddr), dhcp_option_element_len (broadcastAddr));
|
||||
nm_system_device_set_ip4_broadcast (dev, temp);
|
||||
}
|
||||
|
||||
/* Default route */
|
||||
if (dhcp_interface_option_present (dev->dhcp_iface, routersOnSubnet))
|
||||
{
|
||||
memcpy (&temp, dhcp_interface_option_payload (dev->dhcp_iface, routersOnSubnet), dhcp_option_record_len (routersOnSubnet));
|
||||
memcpy (&temp, dhcp_interface_option_payload (dev->dhcp_iface, routersOnSubnet), dhcp_option_element_len (routersOnSubnet));
|
||||
nm_system_device_set_ip4_default_route (dev, temp);
|
||||
}
|
||||
|
||||
|
@@ -560,7 +560,6 @@ NMAccessPoint *nm_dbus_get_network_object (DBusConnection *connection, NMNetwork
|
||||
DBusError error;
|
||||
DBusMessage *reply;
|
||||
NMAccessPoint *ap = NULL;
|
||||
|
||||
const char *essid = NULL;
|
||||
gint timestamp_secs = -1;
|
||||
gint32 i;
|
||||
|
@@ -27,9 +27,9 @@
|
||||
#include "nm-dbus-dhcp.h"
|
||||
#include "dhcpcd/dhcpcd.h"
|
||||
|
||||
static int nm_dbus_dhcp_record_type (int id)
|
||||
static int nm_dbus_dhcp_element_type (int id)
|
||||
{
|
||||
switch (dhcp_option_record_type (id))
|
||||
switch (dhcp_option_element_type (id))
|
||||
{
|
||||
case DHCP_OPT_INVALID:
|
||||
return DBUS_TYPE_INVALID;
|
||||
@@ -49,90 +49,46 @@ static int nm_dbus_dhcp_record_type (int id)
|
||||
return DBUS_TYPE_INVALID;
|
||||
}
|
||||
|
||||
#define DBUS_REPLY_BYTYPE(Dtype, Ctype) do { \
|
||||
int __DBUS_REPLY_BYTYPE_len; \
|
||||
#define DBUS_REPLY_BYTYPE(Dtype, Ctype, as_blob) do { \
|
||||
int __len; \
|
||||
\
|
||||
if (dhcp_interface_option_present (dhcp_iface, data->opt_id) \
|
||||
&& (sizeof (Ctype) >= (__DBUS_REPLY_BYTYPE_len = dhcp_option_record_len (data->opt_id))) \
|
||||
&& (sizeof (Ctype) >= (__len = dhcp_option_element_len (data->opt_id))) \
|
||||
&& ((reply = dbus_message_new_method_return (message)) != NULL)) \
|
||||
{ \
|
||||
Ctype __DBUS_REPLY_BYTYPE_val; \
|
||||
void *__DBUS_REPLY_BYTYPE_blob; \
|
||||
Ctype *__blob; \
|
||||
int __count; \
|
||||
\
|
||||
__DBUS_REPLY_BYTYPE_blob = dhcp_interface_option_payload (dhcp_iface, data->opt_id); \
|
||||
if (__DBUS_REPLY_BYTYPE_len == 1) \
|
||||
__DBUS_REPLY_BYTYPE_val = ((unsigned char *)__DBUS_REPLY_BYTYPE_blob)[0]; \
|
||||
else if (__DBUS_REPLY_BYTYPE_len == 2) \
|
||||
__DBUS_REPLY_BYTYPE_val = ((dbus_uint16_t *)__DBUS_REPLY_BYTYPE_blob)[0]; \
|
||||
else \
|
||||
__DBUS_REPLY_BYTYPE_val = ((dbus_uint32_t *)__DBUS_REPLY_BYTYPE_blob)[0]; \
|
||||
dbus_message_append_args (reply, Dtype, &__DBUS_REPLY_BYTYPE_val, DBUS_TYPE_INVALID); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define DBUS_REPLY_BYTYPEV(Dtype, Ctype, Dappend) do { \
|
||||
int __DBUS_REPLY_BYTYPE_len; \
|
||||
\
|
||||
if (dhcp_interface_option_present (dhcp_iface, data->opt_id) \
|
||||
&& (sizeof (Ctype) >= (__DBUS_REPLY_BYTYPE_len = dhcp_option_record_len (data->opt_id))) \
|
||||
&& ((reply = dbus_message_new_method_return (message)) != NULL)) \
|
||||
{ \
|
||||
DBusMessageIter __DBUS_REPLY_BYTYPE_iter, __DBUS_REPLY_BYTYPE_sub; \
|
||||
void *__DBUS_REPLY_BYTYPE_blob; \
|
||||
int __DBUS_REPLY_BYTYPE_count; \
|
||||
\
|
||||
__DBUS_REPLY_BYTYPE_blob = dhcp_interface_option_payload (dhcp_iface, data->opt_id); \
|
||||
__DBUS_REPLY_BYTYPE_count = dhcp_interface_option_len (dhcp_iface, data->opt_id) / __DBUS_REPLY_BYTYPE_len; \
|
||||
dbus_message_iter_init_append (reply, &__DBUS_REPLY_BYTYPE_iter); \
|
||||
dbus_message_iter_append_fixed_array (&__DBUS_REPLY_BYTYPE_iter, Dtype, __DBUS_REPLY_BYTYPE_blob, __DBUS_REPLY_BYTYPE_count); \
|
||||
__blob = dhcp_interface_option_payload (dhcp_iface, data->opt_id); \
|
||||
__count = as_blob ? __len : (dhcp_interface_option_len (dhcp_iface, data->opt_id) / __len); \
|
||||
dbus_message_append_args (reply, DBUS_TYPE_ARRAY, Dtype, &__blob, __count, DBUS_TYPE_INVALID); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define DBUS_REPLY_STRING(Dtype, Ctype) do { \
|
||||
int __DBUS_REPLY_BYTYPE_len; \
|
||||
int __len; \
|
||||
\
|
||||
if (dhcp_interface_option_present (dhcp_iface, data->opt_id) \
|
||||
&& ((__DBUS_REPLY_BYTYPE_len = dhcp_option_record_len (data->opt_id)) == 1) \
|
||||
&& ((__len = dhcp_option_element_len (data->opt_id)) == 1) \
|
||||
&& ((reply = dbus_message_new_method_return (message)) != NULL)) \
|
||||
{ \
|
||||
Ctype __DBUS_REPLY_BYTYPE_val; \
|
||||
Ctype __val; \
|
||||
Ctype* __ptr = &__val; \
|
||||
\
|
||||
__DBUS_REPLY_BYTYPE_val = (Ctype)dhcp_interface_option_payload (dhcp_iface, data->opt_id); \
|
||||
dbus_message_append_args (reply, Dtype, &__DBUS_REPLY_BYTYPE_val, DBUS_TYPE_INVALID); \
|
||||
__val = (Ctype)dhcp_interface_option_payload (dhcp_iface, data->opt_id); \
|
||||
/* We always return an array even if there's only 1 element */ \
|
||||
dbus_message_append_args (reply, DBUS_TYPE_ARRAY, Dtype, &__ptr, 1, DBUS_TYPE_INVALID); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/*
|
||||
* nm_dbus_dhcp_get_len
|
||||
* nm_dbus_dhcp_get_element_type
|
||||
*
|
||||
* Gets the total length of the specified DHCP option.
|
||||
* Gets the length of individual elements within the specified DHCP option.
|
||||
*
|
||||
*/
|
||||
static DBusMessage *nm_dbus_dhcp_get_len (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
||||
{
|
||||
DBusMessage *reply = NULL;
|
||||
struct dhcp_interface *dhcp_iface;
|
||||
|
||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
||||
dhcp_iface = data->dhcp_iface;
|
||||
|
||||
if ((reply = dbus_message_new_method_return (message)) != NULL) {
|
||||
dbus_int32_t len;
|
||||
len = dhcp_interface_option_len (dhcp_iface, data->opt_id);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_UINT32, &len, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
/*
|
||||
* nm_dbus_dhcp_get_type
|
||||
*
|
||||
* Gets the type of the DHCP option.
|
||||
*
|
||||
*/
|
||||
static DBusMessage *nm_dbus_dhcp_get_type (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
||||
static DBusMessage *nm_dbus_dhcp_get_element_type (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
||||
{
|
||||
DBusMessage *reply = NULL;
|
||||
struct dhcp_interface *dhcp_iface;
|
||||
@@ -142,40 +98,7 @@ static DBusMessage *nm_dbus_dhcp_get_type (DBusConnection *connection, DBusMessa
|
||||
|
||||
if ((reply = dbus_message_new_method_return (message)) != NULL)
|
||||
{
|
||||
dbus_uint32_t type;
|
||||
|
||||
if (nm_dbus_dhcp_record_type (data->opt_id) == DBUS_TYPE_STRING) {
|
||||
type = DBUS_TYPE_STRING;
|
||||
} else if (dhcp_interface_option_len (dhcp_iface, data->opt_id) != dhcp_option_record_len (data->opt_id)) {
|
||||
type = DBUS_TYPE_ARRAY;
|
||||
} else {
|
||||
type = nm_dbus_dhcp_record_type (data->opt_id);
|
||||
}
|
||||
|
||||
dbus_message_append_args (reply, DBUS_TYPE_UINT32, &type, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_dbus_dhcp_get_record_type
|
||||
*
|
||||
* Gets the length of individual records within the specified DHCP option.
|
||||
*
|
||||
*/
|
||||
static DBusMessage *nm_dbus_dhcp_get_record_type (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
||||
{
|
||||
DBusMessage *reply = NULL;
|
||||
struct dhcp_interface *dhcp_iface;
|
||||
|
||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
||||
dhcp_iface = data->dhcp_iface;
|
||||
|
||||
if ((reply = dbus_message_new_method_return (message)) != NULL) {
|
||||
dbus_uint32_t type;
|
||||
type = nm_dbus_dhcp_record_type (data->opt_id);
|
||||
dbus_uint32_t type = nm_dbus_dhcp_element_type (data->opt_id);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_UINT32, &type, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
@@ -191,25 +114,12 @@ static DBusMessage *nm_dbus_dhcp_get_boolean (DBusConnection *connection, DBusMe
|
||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
||||
dhcp_iface = data->dhcp_iface;
|
||||
|
||||
DBUS_REPLY_BYTYPE (DBUS_TYPE_BOOLEAN, dbus_bool_t);
|
||||
DBUS_REPLY_BYTYPE (DBUS_TYPE_BOOLEAN, dbus_bool_t, FALSE);
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
|
||||
static DBusMessage *nm_dbus_dhcp_get_booleanv (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
||||
{
|
||||
DBusMessage *reply = NULL;
|
||||
struct dhcp_interface *dhcp_iface;
|
||||
|
||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
||||
dhcp_iface = data->dhcp_iface;
|
||||
|
||||
DBUS_REPLY_BYTYPEV (DBUS_TYPE_BOOLEAN, dbus_bool_t, boolean);
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
static DBusMessage *nm_dbus_dhcp_get_byte (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
||||
{
|
||||
DBusMessage *reply = NULL;
|
||||
@@ -218,21 +128,7 @@ static DBusMessage *nm_dbus_dhcp_get_byte (DBusConnection *connection, DBusMessa
|
||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
||||
dhcp_iface = data->dhcp_iface;
|
||||
|
||||
DBUS_REPLY_BYTYPE (DBUS_TYPE_BYTE, unsigned char);
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
|
||||
static DBusMessage *nm_dbus_dhcp_get_bytev (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
||||
{
|
||||
DBusMessage *reply = NULL;
|
||||
struct dhcp_interface *dhcp_iface;
|
||||
|
||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
||||
dhcp_iface = data->dhcp_iface;
|
||||
|
||||
DBUS_REPLY_BYTYPEV (DBUS_TYPE_BYTE, unsigned char, byte);
|
||||
DBUS_REPLY_BYTYPE (DBUS_TYPE_BYTE, unsigned char, FALSE);
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -246,21 +142,7 @@ static DBusMessage *nm_dbus_dhcp_get_integer (DBusConnection *connection, DBusMe
|
||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
||||
dhcp_iface = data->dhcp_iface;
|
||||
|
||||
DBUS_REPLY_BYTYPE (DBUS_TYPE_UINT32, dbus_uint32_t);
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
|
||||
static DBusMessage *nm_dbus_dhcp_get_integerv (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
||||
{
|
||||
DBusMessage *reply = NULL;
|
||||
struct dhcp_interface *dhcp_iface;
|
||||
|
||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
||||
dhcp_iface = data->dhcp_iface;
|
||||
|
||||
DBUS_REPLY_BYTYPEV (DBUS_TYPE_UINT32, dbus_uint32_t, uint32);
|
||||
DBUS_REPLY_BYTYPE (DBUS_TYPE_UINT32, dbus_uint32_t, FALSE);
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -279,6 +161,18 @@ static DBusMessage *nm_dbus_dhcp_get_string (DBusConnection *connection, DBusMes
|
||||
return reply;
|
||||
}
|
||||
|
||||
static DBusMessage *nm_dbus_dhcp_get_blob (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
||||
{
|
||||
DBusMessage *reply = NULL;
|
||||
struct dhcp_interface *dhcp_iface;
|
||||
|
||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
||||
dhcp_iface = data->dhcp_iface;
|
||||
|
||||
DBUS_REPLY_BYTYPE (DBUS_TYPE_BYTE, unsigned char, TRUE);
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
static DBusMessage *nm_dbus_dhcp_get_generic (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
||||
{
|
||||
@@ -288,25 +182,16 @@ static DBusMessage *nm_dbus_dhcp_get_generic (DBusConnection *connection, DBusMe
|
||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
||||
dhcp_iface = data->dhcp_iface;
|
||||
|
||||
switch (nm_dbus_dhcp_record_type (data->opt_id))
|
||||
switch (nm_dbus_dhcp_element_type (data->opt_id))
|
||||
{
|
||||
case DBUS_TYPE_BOOLEAN:
|
||||
if (dhcp_interface_option_len (dhcp_iface, data->opt_id) == dhcp_option_record_len (data->opt_id))
|
||||
DBUS_REPLY_BYTYPE (DBUS_TYPE_BOOLEAN, dbus_bool_t);
|
||||
else
|
||||
DBUS_REPLY_BYTYPEV (DBUS_TYPE_BOOLEAN, dbus_bool_t, boolean);
|
||||
DBUS_REPLY_BYTYPE (DBUS_TYPE_BOOLEAN, dbus_bool_t, FALSE);
|
||||
break;
|
||||
case DBUS_TYPE_BYTE:
|
||||
if (dhcp_interface_option_len (dhcp_iface, data->opt_id) == dhcp_option_record_len (data->opt_id))
|
||||
DBUS_REPLY_BYTYPE (DBUS_TYPE_BYTE, unsigned char);
|
||||
else
|
||||
DBUS_REPLY_BYTYPEV (DBUS_TYPE_BYTE, unsigned char, byte);
|
||||
DBUS_REPLY_BYTYPE (DBUS_TYPE_BYTE, unsigned char, FALSE);
|
||||
break;
|
||||
case DBUS_TYPE_UINT32:
|
||||
if (dhcp_interface_option_len (dhcp_iface, data->opt_id) == dhcp_option_record_len (data->opt_id))
|
||||
DBUS_REPLY_BYTYPE(DBUS_TYPE_UINT32, dbus_uint32_t);
|
||||
else
|
||||
DBUS_REPLY_BYTYPEV (DBUS_TYPE_UINT32, dbus_uint32_t, uint32);
|
||||
DBUS_REPLY_BYTYPE(DBUS_TYPE_UINT32, dbus_uint32_t, FALSE);
|
||||
break;
|
||||
case DBUS_TYPE_STRING:
|
||||
DBUS_REPLY_STRING (DBUS_TYPE_STRING, const char *);
|
||||
@@ -323,7 +208,8 @@ static DBusMessage *nm_dbus_dhcp_get_name (DBusConnection *connection, DBusMessa
|
||||
|
||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
||||
|
||||
if ((reply = dbus_message_new_method_return (message)) != NULL) {
|
||||
if ((reply = dbus_message_new_method_return (message)) != NULL)
|
||||
{
|
||||
const char *name;
|
||||
name = dhcp_option_name (data->opt_id);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
|
||||
@@ -413,16 +299,11 @@ NMDbusMethodList *nm_dbus_dhcp_methods_setup (void)
|
||||
{
|
||||
NMDbusMethodList *list = nm_dbus_method_list_new (nm_dbus_dhcp_validate);
|
||||
|
||||
nm_dbus_method_list_add_method (list, "getLen", nm_dbus_dhcp_get_len);
|
||||
nm_dbus_method_list_add_method (list, "getType", nm_dbus_dhcp_get_type);
|
||||
nm_dbus_method_list_add_method (list, "getRecordType", nm_dbus_dhcp_get_record_type);
|
||||
nm_dbus_method_list_add_method (list, "getElementType", nm_dbus_dhcp_get_element_type);
|
||||
nm_dbus_method_list_add_method (list, "getBoolean", nm_dbus_dhcp_get_boolean);
|
||||
nm_dbus_method_list_add_method (list, "getBooleanv", nm_dbus_dhcp_get_booleanv);
|
||||
nm_dbus_method_list_add_method (list, "getByte", nm_dbus_dhcp_get_byte);
|
||||
nm_dbus_method_list_add_method (list, "getBytev", nm_dbus_dhcp_get_bytev);
|
||||
nm_dbus_method_list_add_method (list, "getBlob", nm_dbus_dhcp_get_bytev); /* getBlob is an alias for getBytev */
|
||||
nm_dbus_method_list_add_method (list, "getBlob", nm_dbus_dhcp_get_blob);
|
||||
nm_dbus_method_list_add_method (list, "getInteger", nm_dbus_dhcp_get_integer);
|
||||
nm_dbus_method_list_add_method (list, "getIntegerv", nm_dbus_dhcp_get_integerv);
|
||||
nm_dbus_method_list_add_method (list, "getString", nm_dbus_dhcp_get_string);
|
||||
nm_dbus_method_list_add_method (list, "get", nm_dbus_dhcp_get_generic);
|
||||
nm_dbus_method_list_add_method (list, "getName", nm_dbus_dhcp_get_name);
|
||||
|
@@ -26,6 +26,10 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "NetworkManager.h"
|
||||
|
||||
/* Return codes for functions that use dbus */
|
||||
@@ -61,42 +65,6 @@ static char *dbus_type_to_string (int type)
|
||||
}
|
||||
|
||||
|
||||
gboolean get_one_arg (DBusMessage *message, int arg_type, int arg_type2, void **arg, int *item_count)
|
||||
{
|
||||
gboolean success = FALSE;
|
||||
|
||||
g_return_val_if_fail (message != NULL, FALSE);
|
||||
g_return_val_if_fail (arg != NULL, FALSE);
|
||||
|
||||
if (arg_type == DBUS_TYPE_ARRAY)
|
||||
{
|
||||
if (!item_count)
|
||||
return FALSE;
|
||||
success = dbus_message_get_args (message, NULL, DBUS_TYPE_ARRAY, arg_type2,
|
||||
arg, item_count, DBUS_TYPE_INVALID);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (arg_type)
|
||||
{
|
||||
case DBUS_TYPE_STRING:
|
||||
success = dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, arg, DBUS_TYPE_INVALID);
|
||||
break;
|
||||
case DBUS_TYPE_BYTE:
|
||||
case DBUS_TYPE_INT32:
|
||||
case DBUS_TYPE_UINT32:
|
||||
case DBUS_TYPE_BOOLEAN:
|
||||
success = dbus_message_get_args (message, NULL, arg_type, arg, DBUS_TYPE_INVALID);
|
||||
break;
|
||||
default:
|
||||
fprintf (stderr, "get_one_arg (): Unknown argument type!\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* call_nm_method
|
||||
*
|
||||
@@ -106,7 +74,7 @@ gboolean get_one_arg (DBusMessage *message, int arg_type, int arg_type2, void **
|
||||
* RETURN_FAILURE on failure
|
||||
* RETURN_NO_NM if NetworkManager service no longer exists
|
||||
*/
|
||||
static int call_nm_method (DBusConnection *con, const char *method, int opt, int arg_type, int arg_type2, void **arg, int *item_count)
|
||||
static int call_nm_method (DBusConnection *con, const char *method, int opt, gboolean is_array, int arg_type, void **arg, int *item_count)
|
||||
{
|
||||
DBusMessage *message;
|
||||
DBusMessage *reply;
|
||||
@@ -118,10 +86,7 @@ static int call_nm_method (DBusConnection *con, const char *method, int opt, int
|
||||
g_return_val_if_fail (method != NULL, RETURN_FAILURE);
|
||||
g_return_val_if_fail (arg != NULL, RETURN_FAILURE);
|
||||
|
||||
if ((arg_type == DBUS_TYPE_STRING) || (arg_type2 == DBUS_TYPE_ARRAY))
|
||||
g_return_val_if_fail (*arg == NULL, RETURN_FAILURE);
|
||||
|
||||
if (arg_type == DBUS_TYPE_ARRAY)
|
||||
if (is_array)
|
||||
{
|
||||
g_return_val_if_fail (item_count != NULL, RETURN_FAILURE);
|
||||
*item_count = 0;
|
||||
@@ -132,7 +97,7 @@ static int call_nm_method (DBusConnection *con, const char *method, int opt, int
|
||||
fprintf (stderr, "call_nm_method(): Couldn't allocate the dbus message\n");
|
||||
return (RETURN_FAILURE);
|
||||
}
|
||||
dbus_message_append_args (message, DBUS_TYPE_UINT32, opt, DBUS_TYPE_INVALID);
|
||||
dbus_message_append_args (message, DBUS_TYPE_UINT32, &opt, DBUS_TYPE_INVALID);
|
||||
|
||||
dbus_error_init (&error);
|
||||
reply = dbus_connection_send_with_reply_and_block (con, message, -1, &error);
|
||||
@@ -157,111 +122,47 @@ static int call_nm_method (DBusConnection *con, const char *method, int opt, int
|
||||
return (RETURN_FAILURE);
|
||||
}
|
||||
|
||||
ret = get_one_arg (reply, arg_type, arg_type2, arg, item_count);
|
||||
if (is_array)
|
||||
ret = dbus_message_get_args (reply, NULL, DBUS_TYPE_ARRAY, arg_type, arg, item_count, DBUS_TYPE_INVALID);
|
||||
else
|
||||
ret = dbus_message_get_args (reply, NULL, arg_type, arg, DBUS_TYPE_INVALID);
|
||||
|
||||
/*
|
||||
We simply don't unref the message, so that the values returned stay
|
||||
valid in the caller of this function.
|
||||
dbus_message_unref (reply);
|
||||
*/
|
||||
if (!ret)
|
||||
{
|
||||
fprintf (stderr, "call_nm_method(): error while getting args: name='%s' message='%s'\n", error.name, error.message);
|
||||
if (dbus_error_is_set (&error))
|
||||
dbus_error_free (&error);
|
||||
fprintf (stderr, "call_nm_method(): error while getting args.\n");
|
||||
return (RETURN_FAILURE);
|
||||
}
|
||||
|
||||
return (RETURN_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
int get_opt_type (DBusConnection *connection, int opt, gboolean record)
|
||||
{
|
||||
int ret;
|
||||
int type = -1;
|
||||
|
||||
ret = call_nm_method (connection, record ? "getRecordType" : "getType", opt, DBUS_TYPE_UINT32, DBUS_TYPE_INVALID, (void *)(&type), NULL);
|
||||
if (ret == RETURN_SUCCESS)
|
||||
return (type);
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
void print_array (DBusConnection *connection, int opt, int opt_type)
|
||||
void print_array (DBusConnection *connection, int opt)
|
||||
{
|
||||
int num_items;
|
||||
unsigned int *uint32 = NULL;
|
||||
int *int32 = NULL;
|
||||
gboolean *bool = NULL;
|
||||
unsigned char *byte = NULL;
|
||||
char **string = NULL;
|
||||
void *item = NULL;
|
||||
char *method = NULL;
|
||||
int ret;
|
||||
const char *name = NULL;
|
||||
int opt_type = -1;
|
||||
unsigned int foo;
|
||||
|
||||
switch (opt_type)
|
||||
{
|
||||
case DBUS_TYPE_UINT32:
|
||||
item = &uint32;
|
||||
method = "getIntegerv";
|
||||
break;
|
||||
|
||||
case DBUS_TYPE_BOOLEAN:
|
||||
item = &bool;
|
||||
method = "getBooleanv";
|
||||
break;
|
||||
|
||||
case DBUS_TYPE_BYTE:
|
||||
item = &byte;
|
||||
method = "getBytev";
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf (stderr, "%d: Type %c\n", opt, opt_type);
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
|
||||
ret = call_nm_method (connection, "getName", opt, DBUS_TYPE_STRING, DBUS_TYPE_INVALID, (void *)(&name), NULL);
|
||||
ret = call_nm_method (connection, "getName", opt, FALSE, DBUS_TYPE_STRING, (void *)(&name), NULL);
|
||||
if (ret != RETURN_SUCCESS)
|
||||
name = NULL;
|
||||
return;
|
||||
|
||||
ret = call_nm_method (connection, method, opt, DBUS_TYPE_ARRAY, opt_type, item, &num_items);
|
||||
if ((ret == RETURN_SUCCESS) && (num_items > 0))
|
||||
{
|
||||
int i;
|
||||
fprintf (stderr, "%d ('%s'): (%d records of type %s) ", opt, name, num_items, dbus_type_to_string (opt_type));
|
||||
for (i = 0; i < num_items; i++)
|
||||
{
|
||||
switch (opt_type)
|
||||
{
|
||||
case DBUS_TYPE_BYTE:
|
||||
fprintf (stderr, "%d, ", byte[i]);
|
||||
break;
|
||||
case DBUS_TYPE_BOOLEAN:
|
||||
fprintf (stderr, "%d, ", bool[i]);
|
||||
break;
|
||||
case DBUS_TYPE_UINT32:
|
||||
fprintf (stderr, "%u, ", uint32[i]);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
void print_one_item (DBusConnection *connection, int opt, int opt_type)
|
||||
{
|
||||
unsigned int uint32;
|
||||
int int32;
|
||||
gboolean bool;
|
||||
unsigned char byte;
|
||||
char *string = NULL;
|
||||
void *item = NULL;
|
||||
char *method = NULL;
|
||||
int ret;
|
||||
const char *name = NULL;
|
||||
ret = call_nm_method (connection, "getElementType", opt, FALSE, DBUS_TYPE_UINT32, (void *)(&opt_type), NULL);
|
||||
if (ret != RETURN_SUCCESS)
|
||||
return;
|
||||
|
||||
switch (opt_type)
|
||||
{
|
||||
@@ -291,27 +192,30 @@ void print_one_item (DBusConnection *connection, int opt, int opt_type)
|
||||
break;
|
||||
}
|
||||
|
||||
ret = call_nm_method (connection, "getName", opt, DBUS_TYPE_STRING, DBUS_TYPE_INVALID, (void *)(&name), NULL);
|
||||
if (ret != RETURN_SUCCESS)
|
||||
name = NULL;
|
||||
|
||||
ret = call_nm_method (connection, method, opt, opt_type, DBUS_TYPE_INVALID, item, NULL);
|
||||
if (ret == RETURN_SUCCESS)
|
||||
ret = call_nm_method (connection, method, opt, TRUE, opt_type, item, &num_items);
|
||||
if ((ret == RETURN_SUCCESS) && (num_items > 0))
|
||||
{
|
||||
fprintf (stderr, "%d ('%s'): (%s) ", opt, name, dbus_type_to_string (opt_type));
|
||||
int i;
|
||||
fprintf (stderr, "%d ('%s'): (%d %s of type %s) ", opt, name, num_items, num_items > 1 ? "elements" : "element", dbus_type_to_string (opt_type));
|
||||
for (i = 0; i < num_items; i++)
|
||||
{
|
||||
struct in_addr in;
|
||||
gboolean last = (i == num_items - 1) ? TRUE : FALSE;
|
||||
|
||||
switch (opt_type)
|
||||
{
|
||||
case DBUS_TYPE_BYTE:
|
||||
fprintf (stderr, "%d\n", byte);
|
||||
fprintf (stderr, "%d%s", byte[i], last ? "" : ", ");
|
||||
break;
|
||||
case DBUS_TYPE_BOOLEAN:
|
||||
fprintf (stderr, "%d\n", bool);
|
||||
fprintf (stderr, "%d%s", bool[i], last ? "" : ", ");
|
||||
break;
|
||||
case DBUS_TYPE_UINT32:
|
||||
fprintf (stderr, "%u\n", uint32);
|
||||
in.s_addr = uint32[i];
|
||||
fprintf (stderr, "%u (%s)%s", uint32[i], inet_ntoa(in), last ? "" : ", ");
|
||||
break;
|
||||
case DBUS_TYPE_STRING:
|
||||
fprintf (stderr, "'%s'\n", string);
|
||||
fprintf (stderr, "'%s'%s", string[i], last ? "" : ", ");
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -319,6 +223,10 @@ void print_one_item (DBusConnection *connection, int opt, int opt_type)
|
||||
break;
|
||||
}
|
||||
}
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
else
|
||||
fprintf (stderr, "%d ('%s'): could not get option value\n", opt, name);
|
||||
}
|
||||
|
||||
|
||||
@@ -336,20 +244,7 @@ void print_each_dhcp_option (DBusConnection *connection)
|
||||
|
||||
/* Loop through all available DHCP options and print each one. */
|
||||
for (i = 1; i < 62; i++)
|
||||
{
|
||||
int opt_type = get_opt_type (connection, i, FALSE);
|
||||
|
||||
if (opt_type == DBUS_TYPE_ARRAY)
|
||||
{
|
||||
int opt_type2;
|
||||
|
||||
/* get the array item type */
|
||||
opt_type2 = get_opt_type (connection, i, TRUE);
|
||||
print_array (connection, i, opt_type2);
|
||||
}
|
||||
else if (opt_type != -1)
|
||||
print_one_item (connection, i, opt_type);
|
||||
}
|
||||
print_array (connection, i);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user