From 2ca2d5e62cf079d6425c0d47da7905fa79ab126b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 3 Dec 2020 21:58:17 +0100 Subject: [PATCH] device: Use a switch to check current action so we can be more selective For example we were allowing to verify stop while doing other actions different from enrolling (such as delete or open/close). --- src/device.c | 143 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 84 insertions(+), 59 deletions(-) diff --git a/src/device.c b/src/device.c index 51144f9..15adfde 100644 --- a/src/device.c +++ b/src/device.c @@ -1101,16 +1101,20 @@ static gboolean fprint_device_verify_start (FprintDBusDevice *dbus_dev, session = session_data_get (priv); - if (priv->current_action != ACTION_NONE) { - if (priv->current_action == ACTION_ENROLL) { - g_set_error(&error, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, - "Enrollment in progress"); - } else { - g_set_error(&error, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, - "Verification already in progress"); - } - g_dbus_method_invocation_return_gerror (invocation, error); - return TRUE; + switch (priv->current_action) { + case ACTION_NONE: + break; + case ACTION_VERIFY: + case ACTION_IDENTIFY: + g_dbus_method_invocation_return_error_literal ( + invocation, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, + "Verification already in progress"); + return TRUE; + default: + g_dbus_method_invocation_return_error_literal ( + invocation, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, + "Another operation is already in progress"); + return TRUE; } if (finger_num == -1) { @@ -1202,18 +1206,22 @@ static gboolean fprint_device_verify_stop (FprintDBusDevice *dbus_dev, return TRUE; } - if (priv->current_action == ACTION_NONE) { - g_dbus_method_invocation_return_error_literal (invocation, - FPRINT_ERROR, - FPRINT_ERROR_NO_ACTION_IN_PROGRESS, - "No verification in progress"); - return TRUE; - } else if (priv->current_action == ACTION_ENROLL) { - g_dbus_method_invocation_return_error_literal (invocation, - FPRINT_ERROR, - FPRINT_ERROR_ALREADY_IN_USE, - "Enrollment in progress"); - return TRUE; + switch (priv->current_action) { + case ACTION_VERIFY: + case ACTION_IDENTIFY: + break; + case ACTION_NONE: + g_dbus_method_invocation_return_error_literal ( + invocation, FPRINT_ERROR, + FPRINT_ERROR_NO_ACTION_IN_PROGRESS, + "No verification in progress"); + return TRUE; + default: + g_dbus_method_invocation_return_error_literal ( + invocation, FPRINT_ERROR, + FPRINT_ERROR_ALREADY_IN_USE, + "Another operation is already in progress"); + return TRUE; } if (priv->current_cancellable) { @@ -1423,16 +1431,19 @@ static gboolean fprint_device_enroll_start (FprintDBusDevice *dbus_dev, return TRUE; } - if (priv->current_action != ACTION_NONE) { - if (priv->current_action == ACTION_ENROLL) { - g_set_error(&error, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, - "Enrollment already in progress"); - } else { - g_set_error(&error, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, - "Verification in progress"); - } - g_dbus_method_invocation_return_gerror (invocation, error); - return TRUE; + switch (priv->current_action) { + case ACTION_NONE: + break; + case ACTION_ENROLL: + g_dbus_method_invocation_return_error_literal ( + invocation, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, + "Enrollment already in progress"); + return TRUE; + default: + g_dbus_method_invocation_return_error_literal ( + invocation, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, + "Another operation is already in progress"); + return TRUE; } g_debug("start enrollment device %d finger %d", priv->id, finger_num); @@ -1467,20 +1478,21 @@ static gboolean fprint_device_enroll_stop (FprintDBusDevice *dbus_dev, return TRUE; } - if (priv->current_action != ACTION_ENROLL) { - if (priv->current_action == ACTION_NONE) { - g_set_error (&error, FPRINT_ERROR, FPRINT_ERROR_NO_ACTION_IN_PROGRESS, - "No enrollment in progress"); - } else if (priv->current_action == ACTION_VERIFY) { - g_set_error (&error, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, - "Verification in progress"); - } else if (priv->current_action == ACTION_IDENTIFY) { - g_set_error (&error, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, - "Identification in progress"); - } else - g_assert_not_reached (); - g_dbus_method_invocation_return_gerror (invocation, error); - return TRUE; + switch (priv->current_action) { + case ACTION_ENROLL: + break; + case ACTION_NONE: + g_dbus_method_invocation_return_error_literal ( + invocation, FPRINT_ERROR, + FPRINT_ERROR_NO_ACTION_IN_PROGRESS, + "No enrollment in progress"); + return TRUE; + default: + g_dbus_method_invocation_return_error_literal ( + invocation, FPRINT_ERROR, + FPRINT_ERROR_ALREADY_IN_USE, + "Another operation is already in progress"); + return TRUE; } if (priv->current_cancellable) { @@ -1632,12 +1644,19 @@ static gboolean fprint_device_delete_enrolled_fingers (FprintDBusDevice *dbus_de log_offending_client (invocation); #endif - if (priv->current_action != ACTION_NONE) { - g_dbus_method_invocation_return_error_literal (invocation, - FPRINT_ERROR, - FPRINT_ERROR_ALREADY_IN_USE, - "Another operation is already in progress"); - return TRUE; + switch (priv->current_action) { + case ACTION_NONE: + break; + case ACTION_DELETE: + g_dbus_method_invocation_return_error_literal ( + invocation, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, + "Deletion already in progress"); + return TRUE; + default: + g_dbus_method_invocation_return_error_literal ( + invocation, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, + "Another operation is already in progress"); + return TRUE; } priv->current_action = ACTION_DELETE; @@ -1690,13 +1709,19 @@ static gboolean fprint_device_delete_enrolled_fingers2 (FprintDBusDevice *dbus_d return TRUE; } - if (priv->current_action != ACTION_NONE) { - g_dbus_method_invocation_return_error_literal (invocation, - FPRINT_ERROR, - FPRINT_ERROR_ALREADY_IN_USE, - "Another operation is already in progress"); - g_dbus_method_invocation_return_gerror (invocation, error); - return TRUE; + switch (priv->current_action) { + case ACTION_NONE: + break; + case ACTION_DELETE: + g_dbus_method_invocation_return_error_literal ( + invocation, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, + "Deletion already in progress"); + return TRUE; + default: + g_dbus_method_invocation_return_error_literal ( + invocation, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, + "Another operation is already in progress"); + return TRUE; } priv->current_action = ACTION_DELETE;