Commit f7186c7f authored by Bastien Nocera's avatar Bastien Nocera Committed by Daniel Drake

Remove all uses of enums in the API

The clients aren't supposed to know the magic numbers for enums,
so use strings instead.
parent f39e1475
......@@ -5,8 +5,6 @@ Enforce command sequences:
force VerifyStop after non-retry verify result comes in
etc
Rethink enums and results passed, should be strings and D-Bus errors
Verify PAM messages fit with GDM/gnome-screensaver
Add API docs (see doc/dbus and doc subdir):
......
......@@ -143,6 +143,19 @@ static const char *fingerstr(const char *finger_name)
return NULL;
}
static const char *resulstr(const char *result)
{
if (g_str_equal (result, "verify-retry-scan"))
return "Try scanning your finger again";
if (g_str_equal (result, "verify-swipe-too-short"))
return "Swipe was too short, try scanning your finger again";
if (g_str_equal (result, "verify-finger-not-centered"))
return "Your finger was not centered, try scanning your finger again";
if (g_str_equal (result, "verify-remove-and-retry"))
return "Remove your finger, and try scanning your finger again";
g_assert_not_reached ();
}
static DBusGProxy *create_manager (DBusGConnection **ret_conn, GMainLoop **ret_loop)
{
DBusGConnection *connection;
......@@ -223,8 +236,7 @@ static DBusGProxy *open_device(DBusGConnection *connection, DBusGProxy *manager,
typedef struct {
guint max_tries;
int result;
gboolean verify_completed;
char *result;
gboolean timed_out;
pam_handle_t *pamh;
GMainLoop *loop;
......@@ -232,17 +244,22 @@ typedef struct {
char *driver;
} verify_data;
static void verify_result(GObject *object, int result, gpointer user_data)
static void verify_result(GObject *object, const char *result, gpointer user_data)
{
verify_data *data = user_data;
const char *msg;
D(g_message("Verify result: %s (%d)\n", verify_result_str(result), result));
if (result == VERIFY_NO_MATCH || result == VERIFY_MATCH) {
data->verify_completed = TRUE;
data->result = result;
D(g_message("Verify result: %s\n", result));
if (g_str_equal (result, "verify-no-match") ||
g_str_equal (result, "verify-match") ||
g_str_equal (result, "verify-unknown-error")) {
data->result = g_strdup (result);
g_main_loop_quit (data->loop);
return;
}
msg = resulstr (result);
send_err_msg (data->pamh, msg);
}
static void verify_finger_selected(GObject *object, const char *finger_name, gpointer user_data)
......@@ -265,10 +282,7 @@ static gboolean verify_timeout_cb (gpointer user_data)
verify_data *data = user_data;
data->timed_out = TRUE;
data->verify_completed = TRUE;
send_info_msg (data->pamh, "Verification timed out");
g_main_loop_quit (data->loop);
return FALSE;
......@@ -312,9 +326,7 @@ static int do_verify(DBusGConnection *connection, GMainLoop *loop, pam_handle_t
timeout_id = g_source_attach (source, g_main_loop_get_context (loop));
g_source_set_callback (source, verify_timeout_cb, data, NULL);
data->verify_completed = FALSE;
data->timed_out = FALSE;
data->result = 0;
if (!dbus_g_proxy_call (dev, "VerifyStart", &error, G_TYPE_UINT, -1, G_TYPE_INVALID, G_TYPE_INVALID)) {
D(g_message("VerifyStart failed: %s", error->message));
......@@ -337,18 +349,21 @@ static int do_verify(DBusGConnection *connection, GMainLoop *loop, pam_handle_t
ret = PAM_AUTHINFO_UNAVAIL;
break;
} else {
if (data->result == VERIFY_NO_MATCH) {
if (g_str_equal (data->result, "verify-no-match")) {
send_err_msg (data->pamh, "Failed to match fingerprint");
ret = PAM_AUTH_ERR;
} else if (data->result == VERIFY_MATCH)
} else if (g_str_equal (data->result, "verify-match"))
ret = PAM_SUCCESS;
else if (data->result < 0)
else if (g_str_equal (data->result, "verify-unknown-error"))
ret = PAM_AUTHINFO_UNAVAIL;
else {
send_info_msg (data->pamh, verify_result_str (data->result));
send_info_msg (data->pamh, "An unknown error occured");
ret = PAM_AUTH_ERR;
g_free (data->result);
break;
}
g_free (data->result);
data->result = NULL;
}
data->max_tries--;
}
......
......@@ -203,13 +203,13 @@ static void fprint_device_class_init(FprintDeviceClass *klass)
signals[SIGNAL_VERIFY_STATUS] = g_signal_new("verify-status",
G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST, 0, NULL, NULL,
g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
signals[SIGNAL_ENROLL_STATUS] = g_signal_new("enroll-status",
G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST, 0, NULL, NULL,
g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
signals[SIGNAL_VERIFY_FINGER_SELECTED] = g_signal_new("verify-finger-selected",
G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST, 0, NULL, NULL,
g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_STRING);
g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
}
static gboolean
......@@ -304,6 +304,50 @@ finger_name_to_num (const char *finger_name)
return -1;
}
static const char *
verify_result_to_name (int result)
{
switch (result) {
case FP_VERIFY_NO_MATCH:
return "verify-no-match";
case FP_VERIFY_MATCH:
return "verify-match";
case FP_VERIFY_RETRY:
return "verify-retry-scan";
case FP_VERIFY_RETRY_TOO_SHORT:
return "verify-swipe-too-short";
case FP_VERIFY_RETRY_CENTER_FINGER:
return "verify-finger-not-centered";
case FP_VERIFY_RETRY_REMOVE_FINGER:
return "verify-remove-and-retry";
default:
return "verify-unknown-error";
}
}
static const char *
enroll_result_to_name (int result)
{
switch (result) {
case FP_ENROLL_COMPLETE:
return "enroll-completed";
case FP_ENROLL_FAIL:
return "enroll-failed";
case FP_ENROLL_PASS:
return "enroll-stage-passed";
case FP_ENROLL_RETRY:
return "enroll-retry-scan";
case FP_ENROLL_RETRY_TOO_SHORT:
return "enroll-swipe-too-short";
case FP_ENROLL_RETRY_CENTER_FINGER:
return "enroll-finger-not-centered";
case FP_ENROLL_RETRY_REMOVE_FINGER:
return "enroll-remove-and-retry";
default:
return "enroll-unknown-error";
}
}
static gboolean
_fprint_device_check_claimed (FprintDevice *rdev,
DBusGMethodInvocation *context,
......@@ -688,9 +732,10 @@ static void verify_cb(struct fp_dev *dev, int r, struct fp_img *img,
void *user_data)
{
struct FprintDevice *rdev = user_data;
g_message("verify_cb: result %d", r);
const char *name = verify_result_to_name (r);
g_message("verify_cb: result %s (%d)", name, r);
g_signal_emit(rdev, signals[SIGNAL_VERIFY_STATUS], 0, r);
g_signal_emit(rdev, signals[SIGNAL_VERIFY_STATUS], 0, name);
fp_img_free(img);
}
......@@ -698,9 +743,10 @@ static void identify_cb(struct fp_dev *dev, int r,
size_t match_offset, struct fp_img *img, void *user_data)
{
struct FprintDevice *rdev = user_data;
g_message("identify_cb: result %d", r);
const char *name = verify_result_to_name (r);
g_message("identify_cb: result %s (%d)", name, r);
g_signal_emit(rdev, signals[SIGNAL_VERIFY_STATUS], 0, r);
g_signal_emit(rdev, signals[SIGNAL_VERIFY_STATUS], 0, name);
fp_img_free(img);
}
......@@ -896,7 +942,7 @@ static void enroll_stage_cb(struct fp_dev *dev, int result,
result = FP_ENROLL_FAIL;
}
g_signal_emit(rdev, signals[SIGNAL_ENROLL_STATUS], 0, result);
g_signal_emit(rdev, signals[SIGNAL_ENROLL_STATUS], 0, enroll_result_to_name (result));
fp_img_free(img);
fp_print_data_free(print);
}
......
......@@ -38,7 +38,7 @@
</signal>
<signal name="VerifyStatus">
<arg type="i" name="result" />
<arg type="s" name="result" />
</signal>
<method name="EnrollStart">
......@@ -51,7 +51,7 @@
</method>
<signal name="EnrollStatus">
<arg type="i" name="result" />
<arg type="s" name="result" />
</signal>
<method name="GetProperties">
......
......@@ -25,38 +25,6 @@
static DBusGProxy *manager = NULL;
static DBusGConnection *connection = NULL;
enum enroll_result {
ENROLL_COMPLETE = 1,
ENROLL_FAIL,
ENROLL_PASS,
ENROLL_RETRY = 100,
ENROLL_RETRY_TOO_SHORT = 101,
ENROLL_RETRY_CENTER_FINGER = 102,
ENROLL_RETRY_REMOVE_FINGER = 103,
};
static const char *enroll_result_str(int result)
{
switch (result) {
case ENROLL_COMPLETE:
return "Enroll completed.";
case ENROLL_FAIL:
return "Enroll failed :(";
case ENROLL_PASS:
return "Enroll stage passed. Please scan again for next stage.";
case ENROLL_RETRY:
return "Retry scan";
case ENROLL_RETRY_TOO_SHORT:
return "Swipe too short, please retry";
case ENROLL_RETRY_CENTER_FINGER:
return "Finger not centered, please retry";
case ENROLL_RETRY_REMOVE_FINGER:
return "Please remove finger and retry";
default:
return "Unknown";
}
}
static void create_manager(void)
{
GError *error = NULL;
......@@ -97,11 +65,13 @@ static DBusGProxy *open_device(const char *username)
return dev;
}
static void enroll_result(GObject *object, int result, void *user_data)
static void enroll_result(GObject *object, const char *result, void *user_data)
{
gboolean *enroll_completed = user_data;
g_print("Enroll result: %s (%d)\n", enroll_result_str(result), result);
if (result == ENROLL_COMPLETE || result == ENROLL_FAIL)
g_print("Enroll result: %s\n", result);
if (g_str_equal(result, "enroll-completed") ||
g_str_equal(result, "enroll-failed") ||
g_str_equal(result, "enroll-unknown-error"))
*enroll_completed = TRUE;
}
......
......@@ -30,35 +30,6 @@ static char *finger_name = "any";
static gboolean g_fatal_warnings = FALSE;
static char **usernames = NULL;
enum fp_verify_result {
VERIFY_NO_MATCH = 0,
VERIFY_MATCH = 1,
VERIFY_RETRY = 100,
VERIFY_RETRY_TOO_SHORT = 101,
VERIFY_RETRY_CENTER_FINGER = 102,
VERIFY_RETRY_REMOVE_FINGER = 103,
};
static const char *verify_result_str(int result)
{
switch (result) {
case VERIFY_NO_MATCH:
return "No match";
case VERIFY_MATCH:
return "Match!";
case VERIFY_RETRY:
return "Retry scan";
case VERIFY_RETRY_TOO_SHORT:
return "Swipe too short, please retry";
case VERIFY_RETRY_CENTER_FINGER:
return "Finger not centered, please retry";
case VERIFY_RETRY_REMOVE_FINGER:
return "Please remove finger and retry";
default:
return "Unknown";
}
}
static void create_manager(void)
{
GError *error = NULL;
......@@ -125,11 +96,13 @@ static void find_finger(DBusGProxy *dev, const char *username)
g_strfreev (fingers);
}
static void verify_result(GObject *object, int result, void *user_data)
static void verify_result(GObject *object, const char *result, void *user_data)
{
gboolean *verify_completed = user_data;
g_print("Verify result: %s (%d)\n", verify_result_str(result), result);
if (result == VERIFY_NO_MATCH || result == VERIFY_MATCH)
g_print("Verify result: %s\n", result);
if (g_str_equal (result, "verify-no-match") ||
g_str_equal (result, "verify-match") ||
g_str_equal (result, "verify-unknown-error"))
*verify_completed = TRUE;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment