Commit 1e43720c authored by Bastien Nocera's avatar Bastien Nocera Committed by Daniel Drake

Remove use of finger number in the API

Use well-defined strings instead of numbers to pass around
specific fingers in the public API.
parent ea4114b9
......@@ -72,19 +72,6 @@ static const char *verify_result_str(int result)
}
}
enum fp_finger {
LEFT_THUMB = 1, /** thumb (left hand) */
LEFT_INDEX, /** index finger (left hand) */
LEFT_MIDDLE, /** middle finger (left hand) */
LEFT_RING, /** ring finger (left hand) */
LEFT_LITTLE, /** little finger (left hand) */
RIGHT_THUMB, /** thumb (right hand) */
RIGHT_INDEX, /** index finger (right hand) */
RIGHT_MIDDLE, /** middle finger (right hand) */
RIGHT_RING, /** ring finger (right hand) */
RIGHT_LITTLE, /** little finger (right hand) */
};
static gboolean send_info_msg(pam_handle_t *pamh, const char *msg)
{
const struct pam_message mymsg = {
......@@ -127,24 +114,33 @@ static gboolean send_err_msg(pam_handle_t *pamh, const char *msg)
return (pc->conv(1, &msgp, &resp, pc->appdata_ptr) == PAM_SUCCESS);
}
struct {
const char *dbus_name;
const char *finger_name;
} fingers[11] = {
{ "left-thumb", "Left thumb" },
{ "left-index-finger", "Left index finger" },
{ "left-middle-finger", "Left middle finger" },
{ "left-ring-finger", "Left ring finger" },
{ "left-little-finger", "Left little finger" },
{ "right-thumb", "Right thumb" },
{ "right-index-finger", "Right index finger" },
{ "right-middle-finger", "Right middle finger" },
{ "right-ring-finger", "Right ring finger" },
{ "right-little-finger" "Right little finger" },
{ NULL, NULL }
};
static const char *fingerstr(enum fp_finger finger)
static const char *fingerstr(const char *finger_name)
{
const char *names[] = {
[LEFT_THUMB] = "left thumb",
[LEFT_INDEX] = "left index",
[LEFT_MIDDLE] = "left middle",
[LEFT_RING] = "left ring",
[LEFT_LITTLE] = "left little",
[RIGHT_THUMB] = "right thumb",
[RIGHT_INDEX] = "right index",
[RIGHT_MIDDLE] = "right middle",
[RIGHT_RING] = "right ring",
[RIGHT_LITTLE] = "right little",
};
if (finger < LEFT_THUMB || finger > RIGHT_LITTLE)
return "UNKNOWN";
return names[finger];
guint i;
for (i = 0; fingers[i].dbus_name != NULL; i++) {
if (g_str_equal (fingers[i].dbus_name, finger_name))
return fingers[i].finger_name;
}
return NULL;
}
static DBusGProxy *create_manager (DBusGConnection **ret_conn, GMainLoop **ret_loop)
......@@ -253,15 +249,15 @@ static void verify_result(GObject *object, int result, gpointer user_data)
}
}
static void verify_finger_selected(GObject *object, int finger, gpointer user_data)
static void verify_finger_selected(GObject *object, const char *finger_name, gpointer user_data)
{
verify_data *data = user_data;
char *msg;
if (finger == -1) {
if (g_str_equal (finger_name, "any")) {
msg = g_strdup_printf ("Scan finger on %s", data->driver);
} else {
msg = g_strdup_printf ("Scan %s finger on %s", fingerstr(finger), data->driver);
msg = g_strdup_printf ("Scan %s finger on %s", fingerstr(finger_name), data->driver);
}
D(g_message ("verify_finger_selected %s", msg));
send_info_msg (data->pamh, msg);
......
......@@ -33,6 +33,19 @@
#include "storage.h"
#include "egg-dbus-monitor.h"
static char *fingers[] = {
"left-thumb",
"left-index-finger",
"left-middle-finger",
"left-ring-finger",
"left-little-finger",
"right-thumb",
"right-index-finger",
"right-middle-finger",
"right-ring-finger",
"right-little-finger"
};
extern DBusGConnection *fprintd_dbus_conn;
static void fprint_device_claim(FprintDevice *rdev,
......@@ -41,11 +54,11 @@ static void fprint_device_claim(FprintDevice *rdev,
static void fprint_device_release(FprintDevice *rdev,
DBusGMethodInvocation *context);
static void fprint_device_verify_start(FprintDevice *rdev,
guint32 print_id, DBusGMethodInvocation *context);
const char *finger_name, DBusGMethodInvocation *context);
static void fprint_device_verify_stop(FprintDevice *rdev,
DBusGMethodInvocation *context);
static void fprint_device_enroll_start(FprintDevice *rdev,
guint32 finger_num, DBusGMethodInvocation *context);
const char *finger_name, DBusGMethodInvocation *context);
static void fprint_device_enroll_stop(FprintDevice *rdev,
DBusGMethodInvocation *context);
static void fprint_device_list_enrolled_fingers(FprintDevice *rdev,
......@@ -196,7 +209,7 @@ static void fprint_device_class_init(FprintDeviceClass *klass)
g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
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_INT);
g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_STRING);
}
static gboolean
......@@ -264,6 +277,33 @@ guint32 _fprint_device_get_id(FprintDevice *rdev)
return DEVICE_GET_PRIVATE(rdev)->id;
}
static const char *
finger_num_to_name (int finger_num)
{
if (finger_num == -1)
return "any";
if (finger_num < LEFT_THUMB || finger_num > RIGHT_LITTLE)
return NULL;
return fingers[finger_num - 1];
}
static int
finger_name_to_num (const char *finger_name)
{
guint i;
if (finger_name == NULL || *finger_name == '\0' || g_str_equal (finger_name, "any"))
return -1;
for (i = 0; i < G_N_ELEMENTS (fingers); i++) {
if (g_str_equal (finger_name, fingers[i]))
return i + 1;
}
/* Invalid, let's try that */
return -1;
}
static gboolean
_fprint_device_check_claimed (FprintDevice *rdev,
DBusGMethodInvocation *context,
......@@ -665,12 +705,13 @@ static void identify_cb(struct fp_dev *dev, int r,
}
static void fprint_device_verify_start(FprintDevice *rdev,
guint32 finger_num, DBusGMethodInvocation *context)
const char *finger_name, DBusGMethodInvocation *context)
{
FprintDevicePrivate *priv = DEVICE_GET_PRIVATE(rdev);
struct fp_print_data **gallery = NULL;
struct fp_print_data *data = NULL;
GError *error = NULL;
guint finger_num = finger_name_to_num (finger_name);
int r;
if (_fprint_device_check_claimed(rdev, context, &error) == FALSE) {
......@@ -769,7 +810,8 @@ static void fprint_device_verify_start(FprintDevice *rdev,
/* Emit VerifyFingerSelected telling the front-end which finger
* we selected for auth */
g_signal_emit(rdev, signals[SIGNAL_VERIFY_FINGER_SELECTED], 0, finger_num);
g_signal_emit(rdev, signals[SIGNAL_VERIFY_FINGER_SELECTED],
0, finger_num_to_name (finger_num));
if (r < 0) {
......@@ -860,13 +902,22 @@ static void enroll_stage_cb(struct fp_dev *dev, int result,
}
static void fprint_device_enroll_start(FprintDevice *rdev,
guint32 finger_num, DBusGMethodInvocation *context)
const char *finger_name, DBusGMethodInvocation *context)
{
FprintDevicePrivate *priv = DEVICE_GET_PRIVATE(rdev);
struct session_data *session = priv->session;
int finger_num = finger_name_to_num (finger_name);
GError *error = NULL;
int r;
if (finger_num == -1) {
g_set_error(&error, FPRINT_ERROR, FPRINT_ERROR_NO_SUCH_LOADED_PRINT,
"Invalid print name");
dbus_g_method_return_error(context, error);
g_error_free (error);
return;
}
if (_fprint_device_check_claimed(rdev, context, &error) == FALSE) {
dbus_g_method_return_error (context, error);
return;
......@@ -955,7 +1006,7 @@ static void fprint_device_list_enrolled_fingers(FprintDevice *rdev,
GError *error = NULL;
GSList *prints;
GSList *item;
GArray *ret;
GPtrArray *ret;
char *user, *sender;
user = _fprint_device_check_for_username (rdev,
......@@ -988,14 +1039,16 @@ static void fprint_device_list_enrolled_fingers(FprintDevice *rdev,
return;
}
ret = g_array_new(FALSE, FALSE, sizeof(int));
ret = g_ptr_array_new ();
for (item = prints; item; item = item->next) {
ret = g_array_append_val(ret, item->data);
int finger_num = GPOINTER_TO_INT (item->data);
g_ptr_array_add (ret, g_strdup (finger_num_to_name (finger_num)));
}
g_ptr_array_add (ret, NULL);
g_slist_free(prints);
dbus_g_method_return(context, ret);
dbus_g_method_return(context, g_ptr_array_free (ret, FALSE));
}
static void fprint_device_delete_enrolled_fingers(FprintDevice *rdev,
......
......@@ -6,7 +6,7 @@
<method name="ListEnrolledFingers">
<arg type="s" name="username" direction="in" />
<arg type="au" name="enrolled_fingers" direction="out" />
<arg type="as" name="enrolled_fingers" direction="out" />
<annotation name="org.freedesktop.DBus.GLib.Async" value="" />
</method>
......@@ -25,7 +25,7 @@
</method>
<method name="VerifyStart">
<arg type="u" name="print_id" direction="in" />
<arg type="s" name="finger_name" direction="in" />
<annotation name="org.freedesktop.DBus.GLib.Async" value="" />
</method>
......@@ -34,7 +34,7 @@
</method>
<signal name="VerifyFingerSelected">
<arg type="i" name="finger_num" />
<arg type="s" name="finger_name" />
</signal>
<signal name="VerifyStatus">
......@@ -42,7 +42,7 @@
</signal>
<method name="EnrollStart">
<arg type="u" name="finger_num" direction="in" />
<arg type="s" name="finger_name" direction="in" />
<annotation name="org.freedesktop.DBus.GLib.Async" value="" />
</method>
......
......@@ -57,19 +57,6 @@ static const char *enroll_result_str(int result)
}
}
enum fp_finger {
LEFT_THUMB = 1, /** thumb (left hand) */
LEFT_INDEX, /** index finger (left hand) */
LEFT_MIDDLE, /** middle finger (left hand) */
LEFT_RING, /** ring finger (left hand) */
LEFT_LITTLE, /** little finger (left hand) */
RIGHT_THUMB, /** thumb (right hand) */
RIGHT_INDEX, /** index finger (right hand) */
RIGHT_MIDDLE, /** middle finger (right hand) */
RIGHT_RING, /** ring finger (right hand) */
RIGHT_LITTLE, /** little finger (right hand) */
};
static void create_manager(void)
{
GError *error = NULL;
......@@ -138,7 +125,7 @@ static void do_enroll(DBusGProxy *dev)
&enroll_completed, NULL);
g_print("Enrolling right index finger.\n");
if (!net_reactivated_Fprint_Device_enroll_start(dev, RIGHT_INDEX, &error))
if (!net_reactivated_Fprint_Device_enroll_start(dev, "right-index-finger", &error))
g_error("EnrollStart failed: %s", error->message);
while (!enroll_completed)
......
......@@ -26,47 +26,6 @@
static DBusGProxy *manager = NULL;
static DBusGConnection *connection = NULL;
enum fp_finger {
LEFT_THUMB = 1, /** thumb (left hand) */
LEFT_INDEX, /** index finger (left hand) */
LEFT_MIDDLE, /** middle finger (left hand) */
LEFT_RING, /** ring finger (left hand) */
LEFT_LITTLE, /** little finger (left hand) */
RIGHT_THUMB, /** thumb (right hand) */
RIGHT_INDEX, /** index finger (right hand) */
RIGHT_MIDDLE, /** middle finger (right hand) */
RIGHT_RING, /** ring finger (right hand) */
RIGHT_LITTLE, /** little finger (right hand) */
};
static const char *fingerstr(guint32 fingernum)
{
switch (fingernum) {
case LEFT_THUMB:
return "Left thumb";
case LEFT_INDEX:
return "Left index finger";
case LEFT_MIDDLE:
return "Left middle finger";
case LEFT_RING:
return "Left ring finger";
case LEFT_LITTLE:
return "Left little finger";
case RIGHT_THUMB:
return "Right thumb";
case RIGHT_INDEX:
return "Right index finger";
case RIGHT_MIDDLE:
return "Right middle finger";
case RIGHT_RING:
return "Right ring finger";
case RIGHT_LITTLE:
return "Right little finger";
default:
return "Unknown finger";
}
}
static void create_manager(void)
{
GError *error = NULL;
......@@ -118,15 +77,14 @@ static DBusGProxy *open_device(void)
static void list_fingerprints(DBusGProxy *dev, const char *username)
{
GError *error = NULL;
GArray *fingers;
char **fingers;
GHashTable *props;
guint i;
int fingernum;
if (!net_reactivated_Fprint_Device_list_enrolled_fingers(dev, username, &fingers, &error))
g_error("ListEnrolledFingers failed: %s", error->message);
if (fingers->len == 0) {
if (fingers == NULL || g_strv_length (fingers) == 0) {
g_print("User %s has no fingers enrolled for this device.\n", username);
return;
}
......@@ -135,14 +93,13 @@ static void list_fingerprints(DBusGProxy *dev, const char *username)
g_error("GetProperties failed: %s", error->message);
g_print("Fingerprints for user %s on %s:\n", username, (char *) g_hash_table_lookup (props, "Name"));
for (i = 0; i < fingers->len; i++) {
fingernum = g_array_index(fingers, guint32, i);
g_print(" - #%d: %s\n", fingernum, fingerstr(fingernum));
g_hash_table_destroy (props);
for (i = 0; fingers[i] != NULL; i++) {
g_print(" - #%d: %s\n", i, fingers[i]);
}
fingernum = g_array_index(fingers, guint32, 0);
g_array_free(fingers, TRUE);
g_hash_table_destroy (props);
g_strfreev (fingers);
}
int main(int argc, char **argv)
......
......@@ -19,13 +19,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dbus/dbus-glib-bindings.h>
#include "manager-dbus-glue.h"
#include "device-dbus-glue.h"
static DBusGProxy *manager = NULL;
static DBusGConnection *connection = NULL;
static int finger_num = -1;
static char *finger_name = "any";
static gboolean g_fatal_warnings = FALSE;
static char **usernames = NULL;
......@@ -58,49 +59,6 @@ static const char *verify_result_str(int result)
}
}
enum fp_finger {
LEFT_THUMB = 1, /** thumb (left hand) */
LEFT_INDEX, /** index finger (left hand) */
LEFT_MIDDLE, /** middle finger (left hand) */
LEFT_RING, /** ring finger (left hand) */
LEFT_LITTLE, /** little finger (left hand) */
RIGHT_THUMB, /** thumb (right hand) */
RIGHT_INDEX, /** index finger (right hand) */
RIGHT_MIDDLE, /** middle finger (right hand) */
RIGHT_RING, /** ring finger (right hand) */
RIGHT_LITTLE, /** little finger (right hand) */
};
static const char *fingerstr(guint32 fingernum)
{
switch (fingernum) {
case LEFT_THUMB:
return "Left thumb";
case LEFT_INDEX:
return "Left index finger";
case LEFT_MIDDLE:
return "Left middle finger";
case LEFT_RING:
return "Left ring finger";
case LEFT_LITTLE:
return "Left little finger";
case RIGHT_THUMB:
return "Right thumb";
case RIGHT_INDEX:
return "Right index finger";
case RIGHT_MIDDLE:
return "Right middle finger";
case RIGHT_RING:
return "Right ring finger";
case RIGHT_LITTLE:
return "Right little finger";
case -1:
return "First fingerprint available";
default:
return "Unknown finger";
}
}
static void create_manager(void)
{
GError *error = NULL;
......@@ -155,26 +113,26 @@ static DBusGProxy *open_device(const char *username)
static void find_finger(DBusGProxy *dev, const char *username)
{
GError *error = NULL;
GArray *fingers;
char **fingers;
guint i;
int fingernum;
if (!net_reactivated_Fprint_Device_list_enrolled_fingers(dev, username, &fingers, &error))
g_error("ListEnrolledFingers failed: %s", error->message);
if (fingers->len == 0) {
if (fingers == NULL || g_strv_length (fingers) == 0) {
g_print("No fingers enrolled for this device.\n");
exit(1);
}
g_print("Listing enrolled fingers:\n");
for (i = 0; i < fingers->len; i++) {
fingernum = g_array_index(fingers, guint32, i);
g_print(" - #%d: %s\n", fingernum, fingerstr(fingernum));
for (i = 0; fingers[i] != NULL; i++) {
g_print(" - #%d: %s\n", i, fingers[i]);
}
fingernum = g_array_index(fingers, guint32, 0);
g_array_free(fingers, TRUE);
if (strcmp (finger_name, "any") == 0)
finger_name = fingers[0];
g_strfreev (fingers);
}
static void verify_result(GObject *object, int result, void *user_data)
......@@ -185,9 +143,9 @@ static void verify_result(GObject *object, int result, void *user_data)
*verify_completed = TRUE;
}
static void verify_finger_selected(GObject *object, int finger, void *user_data)
static void verify_finger_selected(GObject *object, const char *name, void *user_data)
{
g_print("Verifying: %s\n", fingerstr(finger));
g_print("Verifying: %s\n", name);
}
static void do_verify(DBusGProxy *dev)
......@@ -202,7 +160,7 @@ static void do_verify(DBusGProxy *dev)
dbus_g_proxy_connect_signal(dev, "VerifyFingerSelected", G_CALLBACK(verify_finger_selected),
NULL, NULL);
if (!net_reactivated_Fprint_Device_verify_start(dev, finger_num, &error))
if (!net_reactivated_Fprint_Device_verify_start(dev, finger_name, &error))
g_error("VerifyStart failed: %s", error->message);
while (!verify_completed)
......@@ -223,7 +181,7 @@ static void release_device(DBusGProxy *dev)
}
static const GOptionEntry entries[] = {
{ "finger", 'f', 0, G_OPTION_ARG_INT, &finger_num, "Finger selected to verify (default is automatic)", NULL },
{ "finger", 'f', 0, G_OPTION_ARG_STRING, &finger_name, "Finger selected to verify (default is automatic)", NULL },
{"g-fatal-warnings", 0, 0, G_OPTION_ARG_NONE, &g_fatal_warnings, "Make all warnings fatal", NULL},
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &usernames, NULL, "[username]" },
{ NULL }
......
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