Patchwork [1/3] dbus: utility to create dbus message from wpabuf array

login
register
mail settings
Submitter reinette chatre
Date Feb. 22, 2012, 8:59 p.m.
Message ID <1329944347-6465-2-git-send-email-reinette.chatre@intel.com>
Download mbox | patch
Permalink /patch/142529/
State Accepted
Commit 96c4f3a70754a142318264de963b0ec41271987c
Headers show

Comments

reinette chatre - Feb. 22, 2012, 8:59 p.m.
From: Jayant Sane <jayant.sane@intel.com>

If a wpabuf array is used to store basic typed data that we would like to
send over D-Bus then this utility will be of help when it places the data
in a variant with format aa? (array of an array of type ?, with ? indicating
any basic type).

Signed-hostap: Jayant Sane <jayant.sane@intel.com>
Signed-hostap: Angie Chinchilla <angie.v.chinchilla@intel.com>
intended-for: hostap-1
---
 wpa_supplicant/dbus/dbus_new_handlers.c |   67 +++++++++++++++++++++++++++++++
 wpa_supplicant/dbus/dbus_new_handlers.h |    6 +++
 2 files changed, 73 insertions(+), 0 deletions(-)

Patch

diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c
index da67bea..a07b793 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers.c
+++ b/wpa_supplicant/dbus/dbus_new_handlers.c
@@ -446,6 +446,73 @@  dbus_bool_t wpas_dbus_simple_array_property_getter(DBusMessageIter *iter,
 	return TRUE;
 }
 
+/**
+ * wpas_dbus_simple_array_array_property_getter - Get array array type property
+ * @iter: Pointer to incoming dbus message iterator
+ * @type: DBus type of property array elements (must be basic type)
+ * @array: pointer to array of elements to put into response message
+ * @array_len: length of above array
+ * @error: a pointer to an error to fill on failure
+ * Returns: TRUE if the request succeeded, FALSE if it failed
+ *
+ * Generic getter for array type properties. Array elements type is
+ * required to be basic.
+ */
+dbus_bool_t wpas_dbus_simple_array_array_property_getter(DBusMessageIter *iter,
+						   const int type,
+						   struct wpabuf **array,
+						   size_t array_len,
+						   DBusError *error)
+{
+	DBusMessageIter variant_iter, array_iter;
+	char type_str[] = "aa?";
+	char inner_type_str[] = "a?";
+	const char *sub_type_str;
+	int i;
+
+	if (!dbus_type_is_basic(type)) {
+		dbus_set_error(error, DBUS_ERROR_FAILED,
+				"%s: given type is not basic", __func__);
+		return FALSE;
+	}
+
+	sub_type_str = wpa_dbus_type_as_string(type);
+	type_str[2] = sub_type_str[0];
+	inner_type_str[1] = sub_type_str[0];
+
+	if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+					      type_str, &variant_iter)) {
+		dbus_set_error(error, DBUS_ERROR_FAILED,
+				"%s: failed to construct message 1", __func__);
+		return FALSE;
+	}
+	if (!dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
+					      inner_type_str, &array_iter)) {
+		dbus_set_error(error, DBUS_ERROR_FAILED,
+				"%s: failed to construct message 2", __func__);
+		return FALSE;
+	}
+
+	for (i = 0; i < array_len; i++) {
+		wpa_dbus_dict_bin_array_add_element(&array_iter,
+						      wpabuf_head(array[i]),
+							wpabuf_len(array[i]));
+
+	}
+	if (!dbus_message_iter_close_container(&variant_iter, &array_iter)) {
+		dbus_set_error(error, DBUS_ERROR_FAILED,
+				"%s: failed to close message 2", __func__);
+		return FALSE;
+	}
+
+	if (!dbus_message_iter_close_container(iter, &variant_iter)) {
+		dbus_set_error(error, DBUS_ERROR_FAILED,
+				"%s: failed to close message 1", __func__);
+		return FALSE;
+	}
+
+	return TRUE;
+}
 
 /**
  * wpas_dbus_handler_create_interface - Request registration of a network iface
diff --git a/wpa_supplicant/dbus/dbus_new_handlers.h b/wpa_supplicant/dbus/dbus_new_handlers.h
index c0272d5..0049be8 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers.h
+++ b/wpa_supplicant/dbus/dbus_new_handlers.h
@@ -41,6 +41,12 @@  dbus_bool_t wpas_dbus_simple_array_property_getter(DBusMessageIter *iter,
 						   size_t array_len,
 						   DBusError *error);
 
+dbus_bool_t wpas_dbus_simple_array_array_property_getter(DBusMessageIter *iter,
+						   const int type,
+						   struct wpabuf **array,
+						   size_t array_len,
+						   DBusError *error);
+
 DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
 						 struct wpa_global *global);