Browse Source

dbus: Add generic properties getter and setter

Witold Sowa 15 years ago
parent
commit
fcea0b7d1d

File diff suppressed because it is too large
+ 332 - 518
wpa_supplicant/dbus/dbus_new_handlers.c


+ 12 - 0
wpa_supplicant/dbus/dbus_new_handlers.h

@@ -25,6 +25,18 @@ struct bss_handler_args {
 	unsigned int id;
 };
 
+DBusMessage * wpas_dbus_simple_property_getter(DBusMessage *message,
+					       const int type,
+					       const void *val);
+
+DBusMessage * wpas_dbus_simple_property_setter(DBusMessage *message,
+					       const int type, void *val);
+
+DBusMessage * wpas_dbus_simple_array_property_getter(DBusMessage *message,
+						     const int type,
+						     const void *array,
+						     size_t array_len);
+
 DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
 						 struct wpa_global *global);
 

+ 7 - 55
wpa_supplicant/dbus/dbus_new_handlers_wps.c

@@ -254,39 +254,9 @@ out:
 DBusMessage * wpas_dbus_getter_process_credentials(
 	DBusMessage *message, struct wpa_supplicant *wpa_s)
 {
-	DBusMessage *reply = NULL;
-	DBusMessageIter iter, variant_iter;
 	dbus_bool_t process = (wpa_s->conf->wps_cred_processing != 1);
-
-	if (message == NULL)
-		reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
-	else
-		reply = dbus_message_new_method_return(message);
-
-	if (reply != NULL) {
-		dbus_message_iter_init_append(reply, &iter);
-		if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
-						      "b", &variant_iter) ||
-		    !dbus_message_iter_append_basic(&variant_iter,
-						    DBUS_TYPE_BOOLEAN,
-						    &process) ||
-		    !dbus_message_iter_close_container(&iter, &variant_iter)) {
-
-			perror("wpas_dbus_getter_process_credentials[dbus]: "
-			       "out of memory to put value into message.");
-			dbus_message_unref(reply);
-			reply = dbus_message_new_error(message,
-						       DBUS_ERROR_NO_MEMORY,
-						       NULL);
-		}
-	} else {
-		perror("wpas_dbus_getter_process_credentials[dbus]: out of "
-		       "memory to create reply message.");
-		reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
-					       NULL);
-	}
-
-	return reply;
+	return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
+						&process);
 }
 
 
@@ -303,29 +273,12 @@ DBusMessage * wpas_dbus_setter_process_credentials(
 	DBusMessage *message, struct wpa_supplicant *wpa_s)
 {
 	DBusMessage *reply = NULL;
-	DBusMessageIter iter, variant_iter;
 	dbus_bool_t process_credentials, old_pc;
 
-	if (!dbus_message_iter_init(message, &iter)) {
-		perror("wpas_dbus_getter_ap_scan[dbus]: out of "
-		       "memory to return scanning state.");
-		reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
-					       NULL);
-		goto out;
-	}
-
-	/* omit first and second argument and get value from third*/
-	dbus_message_iter_next(&iter);
-	dbus_message_iter_next(&iter);
-	dbus_message_iter_recurse(&iter, &variant_iter);
-
-	if (dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_BOOLEAN)
-	{
-		reply = wpas_dbus_error_invald_args(message,
-						    "BOOLEAN required");
-		goto out;
-	}
-	dbus_message_iter_get_basic(&variant_iter, &process_credentials);
+	reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_UINT32,
+						 &process_credentials);
+	if (reply)
+		return reply;
 
 	old_pc = (wpa_s->conf->wps_cred_processing != 1);
 	wpa_s->conf->wps_cred_processing = (process_credentials ? 2 : 1);
@@ -339,6 +292,5 @@ DBusMessage * wpas_dbus_setter_process_credentials(
 			WPAS_DBUS_NEW_IFACE_WPS,
 			"ProcessCredentials");
 
-out:
-	return reply;
+	return NULL;
 }

Some files were not shown because too many files changed in this diff