Uncrustify everything except for nbis

This commit is contained in:
Marco Trevisan (Treviño)
2019-11-19 21:13:11 +01:00
committed by Benjamin Berg
parent fd5f511b33
commit d1fb1e26f3
60 changed files with 30386 additions and 28683 deletions

View File

@@ -24,212 +24,236 @@
#include "storage.h"
typedef struct _VerifyData {
GMainLoop *loop;
int ret_value;
typedef struct _VerifyData
{
GMainLoop *loop;
int ret_value;
} VerifyData;
static void
verify_data_free (VerifyData *verify_data)
{
g_main_loop_unref (verify_data->loop);
g_free (verify_data);
g_main_loop_unref (verify_data->loop);
g_free (verify_data);
}
G_DEFINE_AUTOPTR_CLEANUP_FUNC (VerifyData, verify_data_free)
FpDevice *discover_device (GPtrArray *devices)
FpDevice *discover_device (GPtrArray * devices)
{
FpDevice *dev;
if (!devices->len)
return NULL;
FpDevice *dev;
dev = g_ptr_array_index (devices, 0);
printf("Found device claimed by %s driver\n", fp_device_get_driver (dev));
return dev;
if (!devices->len)
return NULL;
dev = g_ptr_array_index (devices, 0);
printf ("Found device claimed by %s driver\n", fp_device_get_driver (dev));
return dev;
}
static void
on_device_closed (FpDevice *dev, GAsyncResult *res, void *user_data) {
VerifyData *verify_data = user_data;
g_autoptr(GError) error = NULL;
on_device_closed (FpDevice *dev, GAsyncResult *res, void *user_data)
{
VerifyData *verify_data = user_data;
fp_device_close_finish (dev, res, &error);
g_autoptr(GError) error = NULL;
if (error)
g_warning ("Failed closing device %s\n", error->message);
fp_device_close_finish (dev, res, &error);
g_main_loop_quit (verify_data->loop);
if (error)
g_warning ("Failed closing device %s\n", error->message);
g_main_loop_quit (verify_data->loop);
}
static void start_verification (FpDevice *dev, VerifyData *verify_data);
static void start_verification (FpDevice *dev,
VerifyData *verify_data);
static void
on_verify_completed (FpDevice *dev, GAsyncResult *res, void *user_data)
{
VerifyData *verify_data = user_data;
g_autoptr(FpPrint) print = NULL;
g_autoptr(GError) error = NULL;
char buffer[20];
gboolean match;
VerifyData *verify_data = user_data;
if (!fp_device_verify_finish (dev, res, &match, &print, &error)) {
g_warning ("Failed to verify print: %s", error->message);
g_main_loop_quit (verify_data->loop);
return;
}
g_autoptr(FpPrint) print = NULL;
g_autoptr(GError) error = NULL;
char buffer[20];
gboolean match;
if (match) {
g_print ("MATCH!\n");
if (fp_device_supports_capture (dev) &&
print_image_save (print, "verify.pgm")) {
g_print("Print image saved as verify.pgm");
}
if (!fp_device_verify_finish (dev, res, &match, &print, &error))
{
g_warning ("Failed to verify print: %s", error->message);
g_main_loop_quit (verify_data->loop);
return;
}
verify_data->ret_value = EXIT_SUCCESS;
} else {
g_print ("NO MATCH!\n");
verify_data->ret_value = EXIT_FAILURE;
}
if (match)
{
g_print ("MATCH!\n");
if (fp_device_supports_capture (dev) &&
print_image_save (print, "verify.pgm"))
g_print ("Print image saved as verify.pgm");
g_print ("Verify again? [Y/n]? ");
if (fgets (buffer, sizeof (buffer), stdin) &&
(buffer[0] == 'Y' || buffer[0] == 'y')) {
start_verification (dev, verify_data);
return;
}
verify_data->ret_value = EXIT_SUCCESS;
}
else
{
g_print ("NO MATCH!\n");
verify_data->ret_value = EXIT_FAILURE;
}
fp_device_close (dev, NULL, (GAsyncReadyCallback) on_device_closed,
verify_data);
g_print ("Verify again? [Y/n]? ");
if (fgets (buffer, sizeof (buffer), stdin) &&
(buffer[0] == 'Y' || buffer[0] == 'y'))
{
start_verification (dev, verify_data);
return;
}
fp_device_close (dev, NULL, (GAsyncReadyCallback) on_device_closed,
verify_data);
}
static void
on_list_completed (FpDevice *dev, GAsyncResult *res, gpointer user_data)
{
VerifyData *verify_data = user_data;
g_autoptr(GPtrArray) prints = NULL;
g_autoptr(GError) error = NULL;
VerifyData *verify_data = user_data;
prints = fp_device_list_prints_finish (dev, res, &error);
g_autoptr(GPtrArray) prints = NULL;
g_autoptr(GError) error = NULL;
if (!error) {
FpPrint *verify_print = NULL;
guint i;
prints = fp_device_list_prints_finish (dev, res, &error);
if (!prints->len)
g_warning ("No prints saved on device");
if (!error)
{
FpPrint *verify_print = NULL;
guint i;
for (i = 0; i < prints->len; ++i) {
FpPrint *print = prints->pdata[i];
if (!prints->len)
g_warning ("No prints saved on device");
if (fp_print_get_finger (print) == FP_FINGER_RIGHT_INDEX &&
g_strcmp0 (fp_print_get_username (print), g_get_user_name ()) == 0) {
if (!verify_print ||
(g_date_compare (fp_print_get_enroll_date (print),
fp_print_get_enroll_date (verify_print)) >= 0))
verify_print = print;
}
}
for (i = 0; i < prints->len; ++i)
{
FpPrint *print = prints->pdata[i];
if (!verify_print) {
g_warning ("Did you remember to enroll your right index "
"finger first?");
g_main_loop_quit (verify_data->loop);
return;
}
if (fp_print_get_finger (print) == FP_FINGER_RIGHT_INDEX &&
g_strcmp0 (fp_print_get_username (print), g_get_user_name ()) == 0)
{
if (!verify_print ||
(g_date_compare (fp_print_get_enroll_date (print),
fp_print_get_enroll_date (verify_print)) >= 0))
verify_print = print;
}
}
g_debug ("Comparing print with %s",
fp_print_get_description (verify_print));
if (!verify_print)
{
g_warning ("Did you remember to enroll your right index "
"finger first?");
g_main_loop_quit (verify_data->loop);
return;
}
g_print ("Print loaded. Time to verify!\n");
fp_device_verify (dev, verify_print, NULL,
(GAsyncReadyCallback) on_verify_completed,
verify_data);
} else {
g_warning ("Loading prints failed with error %s", error->message);
g_main_loop_quit (verify_data->loop);
}
g_debug ("Comparing print with %s",
fp_print_get_description (verify_print));
g_print ("Print loaded. Time to verify!\n");
fp_device_verify (dev, verify_print, NULL,
(GAsyncReadyCallback) on_verify_completed,
verify_data);
}
else
{
g_warning ("Loading prints failed with error %s", error->message);
g_main_loop_quit (verify_data->loop);
}
}
static void
start_verification (FpDevice *dev, VerifyData *verify_data)
{
if (fp_device_has_storage (dev)) {
g_print ("Creating finger template, using device storage...\n");
fp_device_list_prints (dev, NULL,
(GAsyncReadyCallback) on_list_completed,
verify_data);
} else {
g_print ("Loading previously enrolled right index finger data...\n");
g_autoptr(FpPrint) verify_print;
if (fp_device_has_storage (dev))
{
g_print ("Creating finger template, using device storage...\n");
fp_device_list_prints (dev, NULL,
(GAsyncReadyCallback) on_list_completed,
verify_data);
}
else
{
g_print ("Loading previously enrolled right index finger data...\n");
g_autoptr(FpPrint) verify_print;
verify_print = print_data_load (dev, FP_FINGER_RIGHT_INDEX);
verify_print = print_data_load (dev, FP_FINGER_RIGHT_INDEX);
if (!verify_print) {
g_warning ("Failed to load fingerprint data");
g_warning ("Did you remember to enroll your right index "
"finger first?");
g_main_loop_quit (verify_data->loop);
return;
}
if (!verify_print)
{
g_warning ("Failed to load fingerprint data");
g_warning ("Did you remember to enroll your right index "
"finger first?");
g_main_loop_quit (verify_data->loop);
return;
}
g_print ("Print loaded. Time to verify!\n");
fp_device_verify (dev, verify_print, NULL,
(GAsyncReadyCallback) on_verify_completed,
verify_data);
}
g_print ("Print loaded. Time to verify!\n");
fp_device_verify (dev, verify_print, NULL,
(GAsyncReadyCallback) on_verify_completed,
verify_data);
}
}
static void
on_device_opened (FpDevice *dev, GAsyncResult *res, void *user_data)
{
VerifyData *verify_data = user_data;
g_autoptr(GError) error = NULL;
VerifyData *verify_data = user_data;
if (!fp_device_open_finish (dev, res, &error)) {
g_warning ("Failed to open device: %s", error->message);
g_main_loop_quit (verify_data->loop);
return;
}
g_autoptr(GError) error = NULL;
g_print ("Opened device. ");
if (!fp_device_open_finish (dev, res, &error))
{
g_warning ("Failed to open device: %s", error->message);
g_main_loop_quit (verify_data->loop);
return;
}
start_verification (dev, verify_data);
g_print ("Opened device. ");
start_verification (dev, verify_data);
}
int main(void)
int
main (void)
{
g_autoptr (FpContext) ctx = NULL;
g_autoptr (VerifyData) verify_data = NULL;
GPtrArray *devices;
FpDevice *dev;
g_autoptr(FpContext) ctx = NULL;
g_autoptr(VerifyData) verify_data = NULL;
GPtrArray *devices;
FpDevice *dev;
setenv ("G_MESSAGES_DEBUG", "all", 0);
setenv ("LIBUSB_DEBUG", "3", 0);
setenv ("G_MESSAGES_DEBUG", "all", 0);
setenv ("LIBUSB_DEBUG", "3", 0);
ctx = fp_context_new ();
ctx = fp_context_new ();
devices = fp_context_get_devices (ctx);
if (!devices) {
g_warning("Impossible to get devices");
return EXIT_FAILURE;
}
devices = fp_context_get_devices (ctx);
if (!devices)
{
g_warning ("Impossible to get devices");
return EXIT_FAILURE;
}
dev = discover_device (devices);
if (!dev) {
g_warning("No devices detected.");
return EXIT_FAILURE;
}
dev = discover_device (devices);
if (!dev)
{
g_warning ("No devices detected.");
return EXIT_FAILURE;
}
verify_data = g_new0 (VerifyData, 1);
verify_data->ret_value = EXIT_FAILURE;
verify_data->loop = g_main_loop_new (NULL, FALSE);
verify_data = g_new0 (VerifyData, 1);
verify_data->ret_value = EXIT_FAILURE;
verify_data->loop = g_main_loop_new (NULL, FALSE);
fp_device_open (dev, NULL, (GAsyncReadyCallback) on_device_opened,
verify_data);
fp_device_open (dev, NULL, (GAsyncReadyCallback) on_device_opened,
verify_data);
g_main_loop_run (verify_data->loop);
g_main_loop_run (verify_data->loop);
return verify_data->ret_value;
return verify_data->ret_value;
}