mirror of
https://gitlab.com/mishakmak/pam-fprint-grosshack.git
synced 2026-04-08 20:03:34 +02:00
Initial port to libfprint2
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
AC_INIT([fprintd], [0.9.0])
|
||||
AC_INIT([fprintd], [1.90.0])
|
||||
AM_INIT_AUTOMAKE([1.11 dist-xz no-dist-gzip check-news])
|
||||
AC_CONFIG_SRCDIR([src/main.c])
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
@ -17,7 +17,7 @@ AC_SUBST(GETTEXT_PACKAGE)
|
||||
AM_GLIB_GNU_GETTEXT
|
||||
IT_PROG_INTLTOOL([0.35.0])
|
||||
|
||||
PKG_CHECK_MODULES(FPRINT, [libfprint > 0.1.0])
|
||||
PKG_CHECK_MODULES(FPRINT, [libfprint2 >= 1.90.0])
|
||||
AC_SUBST(FPRINT_LIBS)
|
||||
AC_SUBST(FPRINT_CFLAGS)
|
||||
|
||||
|
||||
@ -24,7 +24,6 @@ libfprintd_la_LDFLAGS = -no-undefined
|
||||
|
||||
fprintd_SOURCES = \
|
||||
main.c \
|
||||
loop.c loop.h \
|
||||
file_storage.c file_storage.h storage.h
|
||||
fprintd_LDADD = libfprintd.la
|
||||
|
||||
|
||||
706
src/device.c
706
src/device.c
File diff suppressed because it is too large
Load Diff
@ -35,7 +35,7 @@
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
|
||||
#include <libfprint/fprint.h>
|
||||
#include <fprint.h>
|
||||
|
||||
#include "file_storage.h"
|
||||
|
||||
@ -43,21 +43,15 @@
|
||||
#define DIR_PERMS 0700
|
||||
|
||||
#define FP_FINGER_IS_VALID(finger) \
|
||||
((finger) >= LEFT_THUMB && (finger) <= RIGHT_LITTLE)
|
||||
((finger) >= FP_FINGER_LEFT_THUMB && (finger) <= FP_FINGER_RIGHT_LITTLE)
|
||||
|
||||
static char *get_path_to_storedir(uint16_t driver_id, uint32_t devtype, char *base_store)
|
||||
static char *get_path_to_storedir(const char *driver, const char * device_id, char *base_store)
|
||||
{
|
||||
char idstr[5];
|
||||
char devtypestr[9];
|
||||
|
||||
g_snprintf(idstr, sizeof(idstr), "%04x", driver_id);
|
||||
g_snprintf(devtypestr, sizeof(devtypestr), "%08x", devtype);
|
||||
|
||||
return g_build_filename(base_store, idstr, devtypestr, NULL);
|
||||
return g_build_filename(base_store, driver, device_id, NULL);
|
||||
}
|
||||
|
||||
static char *__get_path_to_print(uint16_t driver_id, uint32_t devtype,
|
||||
enum fp_finger finger, char *base_store)
|
||||
static char *__get_path_to_print(const char *driver, const char * device_id,
|
||||
FpFinger finger, char *base_store)
|
||||
{
|
||||
char *dirpath;
|
||||
char *path;
|
||||
@ -65,22 +59,26 @@ static char *__get_path_to_print(uint16_t driver_id, uint32_t devtype,
|
||||
|
||||
g_snprintf(fingername, 2, "%x", finger);
|
||||
|
||||
dirpath = get_path_to_storedir(driver_id, devtype, base_store);
|
||||
dirpath = get_path_to_storedir(driver, device_id, base_store);
|
||||
path = g_build_filename(dirpath, fingername, NULL);
|
||||
g_free(dirpath);
|
||||
return path;
|
||||
}
|
||||
|
||||
static char *get_path_to_print(struct fp_dev *dev, enum fp_finger finger, char *base_store)
|
||||
static char *get_path_to_print(FpDevice *dev, FpFinger finger, char *base_store)
|
||||
{
|
||||
return __get_path_to_print(fp_driver_get_driver_id(fp_dev_get_driver(dev)),
|
||||
fp_dev_get_devtype(dev), finger, base_store);
|
||||
return __get_path_to_print(fp_device_get_driver (dev),
|
||||
fp_device_get_device_id(dev),
|
||||
finger,
|
||||
base_store);
|
||||
}
|
||||
|
||||
static char *get_path_to_print_dscv(struct fp_dscv_dev *dev, enum fp_finger finger, char *base_store)
|
||||
static char *get_path_to_print_dscv(FpDevice *dev, FpFinger finger, char *base_store)
|
||||
{
|
||||
return __get_path_to_print(fp_driver_get_driver_id(fp_dscv_dev_get_driver(dev)),
|
||||
fp_dscv_dev_get_devtype(dev), finger, base_store);
|
||||
return __get_path_to_print(fp_device_get_driver (dev),
|
||||
fp_device_get_device_id(dev),
|
||||
finger,
|
||||
base_store);
|
||||
}
|
||||
|
||||
static char *file_storage_get_basestore_for_username(const char *username)
|
||||
@ -88,67 +86,58 @@ static char *file_storage_get_basestore_for_username(const char *username)
|
||||
return g_build_filename(FILE_STORAGE_PATH, username, NULL);
|
||||
}
|
||||
|
||||
/* if username == NULL function will use current username */
|
||||
int file_storage_print_data_save(struct fp_print_data *data,
|
||||
enum fp_finger finger, const char *username)
|
||||
int file_storage_print_data_save(FpPrint *print)
|
||||
{
|
||||
GError *err = NULL;
|
||||
char *path, *dirpath;
|
||||
size_t len;
|
||||
g_autoptr(GError) err = NULL;
|
||||
g_autofree char *path = NULL;
|
||||
g_autofree char *dirpath = NULL;
|
||||
g_autofree char *base_store = NULL;
|
||||
g_autofree char *buf = NULL;
|
||||
gsize len;
|
||||
int r;
|
||||
char *base_store = NULL;
|
||||
char *buf = NULL;
|
||||
|
||||
base_store = file_storage_get_basestore_for_username(username);
|
||||
base_store = file_storage_get_basestore_for_username(fp_print_get_username (print));
|
||||
|
||||
len = fp_print_data_get_data(data, (guchar **) &buf);
|
||||
if (!len) {
|
||||
g_free(base_store);
|
||||
if (!fp_print_serialize (print, (guchar **) &buf, &len, &err)) {
|
||||
g_warning ("Error serializing data: %s", err->message);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
path = __get_path_to_print(fp_print_data_get_driver_id(data), fp_print_data_get_devtype(data), finger, base_store);
|
||||
path = __get_path_to_print(fp_print_get_driver (print),
|
||||
fp_print_get_device_id (print),
|
||||
fp_print_get_finger (print),
|
||||
base_store);
|
||||
dirpath = g_path_get_dirname(path);
|
||||
r = g_mkdir_with_parents(dirpath, DIR_PERMS);
|
||||
if (r < 0) {
|
||||
g_debug("file_storage_print_data_save(): could not mkdir(\"%s\"): %s",
|
||||
dirpath, g_strerror(r));
|
||||
g_free(dirpath);
|
||||
g_free(path);
|
||||
goto out;
|
||||
return r;
|
||||
}
|
||||
g_free(dirpath);
|
||||
|
||||
//fp_dbg("saving to %s", path);
|
||||
g_file_set_contents(path, buf, len, &err);
|
||||
g_free(path);
|
||||
if (err) {
|
||||
r = err->code;
|
||||
g_debug("file_storage_print_data_save(): could not save '%s': %s",
|
||||
path, err->message);
|
||||
g_error_free(err);
|
||||
/* FIXME interpret error codes */
|
||||
goto out;
|
||||
return err->code;
|
||||
}
|
||||
|
||||
out:
|
||||
g_clear_pointer(&buf, free);
|
||||
g_clear_pointer(&base_store, g_free);
|
||||
return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int load_from_file(char *path, struct fp_print_data **data)
|
||||
static int load_from_file(char *path, FpPrint **print)
|
||||
{
|
||||
g_autoptr(GError) err = NULL;
|
||||
gsize length;
|
||||
char *contents;
|
||||
GError *err = NULL;
|
||||
struct fp_print_data *fdata;
|
||||
g_autofree char *contents = NULL;
|
||||
FpPrint *new;
|
||||
|
||||
//fp_dbg("from %s", path);
|
||||
g_file_get_contents(path, &contents, &length, &err);
|
||||
if (err) {
|
||||
int r = err->code;
|
||||
g_error_free(err);
|
||||
/* FIXME interpret more error codes */
|
||||
if (r == G_FILE_ERROR_NOENT)
|
||||
return -ENOENT;
|
||||
@ -156,71 +145,71 @@ static int load_from_file(char *path, struct fp_print_data **data)
|
||||
return r;
|
||||
}
|
||||
|
||||
fdata = fp_print_data_from_data((guchar *) contents, length);
|
||||
g_free(contents);
|
||||
if (!fdata)
|
||||
new = fp_print_deserialize ((guchar *) contents, length, &err);
|
||||
if (!new) {
|
||||
g_print ("Error deserializing data: %s", err->message);
|
||||
return -EIO;
|
||||
*data = fdata;
|
||||
}
|
||||
|
||||
*print = new;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int file_storage_print_data_load(struct fp_dev *dev,
|
||||
enum fp_finger finger, struct fp_print_data **data, const char *username)
|
||||
int file_storage_print_data_load(FpDevice *dev,
|
||||
FpFinger finger,
|
||||
const char *username,
|
||||
FpPrint **print)
|
||||
{
|
||||
gchar *path;
|
||||
struct fp_print_data *fdata = NULL;
|
||||
g_autofree gchar *path = NULL;
|
||||
g_autofree gchar *base_store = NULL;
|
||||
FpPrint *new = NULL;
|
||||
int r;
|
||||
char *base_store = NULL;
|
||||
|
||||
base_store = file_storage_get_basestore_for_username(username);
|
||||
|
||||
path = get_path_to_print(dev, finger, base_store);
|
||||
r = load_from_file(path, &fdata);
|
||||
r = load_from_file(path, &new);
|
||||
g_debug ("file_storage_print_data_load(): loaded '%s' %s",
|
||||
path, g_strerror(r));
|
||||
g_free(path);
|
||||
g_free(base_store);
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
if (!fp_dev_supports_print_data(dev, fdata)) {
|
||||
fp_print_data_free(fdata);
|
||||
if (!fp_print_compatible (new, dev)) {
|
||||
g_object_unref (new);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
*data = fdata;
|
||||
*print = new;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int file_storage_print_data_delete(struct fp_dscv_dev *dev,
|
||||
enum fp_finger finger, const char *username)
|
||||
int file_storage_print_data_delete(FpDevice *dev, FpFinger finger, const char *username)
|
||||
{
|
||||
g_autofree gchar *base_store = NULL;
|
||||
g_autofree gchar *path = NULL;
|
||||
int r;
|
||||
char *base_store, *path;
|
||||
|
||||
base_store = file_storage_get_basestore_for_username(username);
|
||||
|
||||
path = get_path_to_print_dscv(dev, finger, base_store);
|
||||
|
||||
r = g_unlink(path);
|
||||
g_debug("file_storage_print_data_delete(): unlink(\"%s\") %s",
|
||||
path, g_strerror(r));
|
||||
g_free(path);
|
||||
g_free(base_store);
|
||||
|
||||
/* FIXME: cleanup empty directory */
|
||||
return r;
|
||||
return g_unlink(path);
|
||||
}
|
||||
|
||||
static GSList *scan_dev_storedir(char *devpath, uint16_t driver_id,
|
||||
uint32_t devtype, GSList *list)
|
||||
static GSList *scan_dev_storedir(char *devpath,
|
||||
GSList *list)
|
||||
{
|
||||
GError *err = NULL;
|
||||
g_autoptr(GError) err = NULL;
|
||||
const gchar *ent;
|
||||
|
||||
GDir *dir = g_dir_open(devpath, 0, &err);
|
||||
if (!dir) {
|
||||
g_debug("scan_dev_storedir(): opendir(\"%s\") failed: %s", devpath, err->message);
|
||||
g_error_free(err);
|
||||
return list;
|
||||
}
|
||||
|
||||
@ -245,25 +234,22 @@ static GSList *scan_dev_storedir(char *devpath, uint16_t driver_id,
|
||||
return list;
|
||||
}
|
||||
|
||||
GSList *file_storage_discover_prints(struct fp_dscv_dev *dev, const char *username)
|
||||
GSList *file_storage_discover_prints(FpDevice *dev, const char *username)
|
||||
{
|
||||
GSList *list = NULL;
|
||||
char *base_store = NULL;
|
||||
char *storedir = NULL;
|
||||
g_autofree gchar *base_store = NULL;
|
||||
g_autofree gchar *storedir = NULL;
|
||||
|
||||
base_store = file_storage_get_basestore_for_username(username);
|
||||
|
||||
storedir = get_path_to_storedir(fp_driver_get_driver_id(fp_dscv_dev_get_driver(dev)),
|
||||
fp_dscv_dev_get_devtype(dev), base_store);
|
||||
storedir = get_path_to_storedir(fp_device_get_driver (dev),
|
||||
fp_device_get_device_id (dev),
|
||||
base_store);
|
||||
|
||||
g_debug ("file_storage_discover_prints() for user '%s' in '%s'",
|
||||
username, storedir);
|
||||
|
||||
list = scan_dev_storedir(storedir, fp_driver_get_driver_id(fp_dscv_dev_get_driver(dev)),
|
||||
fp_dscv_dev_get_devtype(dev), list);
|
||||
|
||||
g_free(base_store);
|
||||
g_free(storedir);
|
||||
list = scan_dev_storedir(storedir, list);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@ -22,20 +22,21 @@
|
||||
|
||||
#define FILE_STORAGE_H
|
||||
|
||||
int file_storage_print_data_save(struct fp_print_data *data,
|
||||
enum fp_finger finger, const char *username);
|
||||
int file_storage_print_data_save(FpPrint *print);
|
||||
|
||||
int file_storage_print_data_load(FpDevice *dev,
|
||||
FpFinger finger,
|
||||
const char *username,
|
||||
FpPrint **print);
|
||||
|
||||
int file_storage_print_data_load(struct fp_dev *dev,
|
||||
enum fp_finger finger, struct fp_print_data **data, const char *username);
|
||||
|
||||
int file_storage_print_data_delete(struct fp_dscv_dev *dev,
|
||||
enum fp_finger finger, const char *username);
|
||||
int file_storage_print_data_delete(FpDevice *dev,
|
||||
FpFinger finger,
|
||||
const char *username);
|
||||
|
||||
int file_storage_init(void);
|
||||
|
||||
int file_storage_deinit(void);
|
||||
|
||||
GSList *file_storage_discover_prints(struct fp_dscv_dev *dev, const char *username);
|
||||
GSList *file_storage_discover_prints(FpDevice *dev, const char *username);
|
||||
|
||||
#endif
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
|
||||
#include <glib.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
#include <fprint.h>
|
||||
|
||||
/* General */
|
||||
#define TIMEOUT 30
|
||||
@ -87,7 +88,7 @@ struct FprintDeviceClass {
|
||||
typedef struct FprintDevice FprintDevice;
|
||||
typedef struct FprintDeviceClass FprintDeviceClass;
|
||||
|
||||
FprintDevice *fprint_device_new(struct fp_dscv_dev *ddev);
|
||||
FprintDevice *fprint_device_new(FpDevice *dev);
|
||||
GType fprint_device_get_type(void);
|
||||
guint32 _fprint_device_get_id(FprintDevice *rdev);
|
||||
/* Print */
|
||||
|
||||
196
src/loop.c
196
src/loop.c
@ -1,196 +0,0 @@
|
||||
/*
|
||||
* fprint D-Bus daemon
|
||||
* Copyright (C) 2008 Daniel Drake <dsd@gentoo.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <libfprint/fprint.h>
|
||||
|
||||
#include <poll.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "loop.h"
|
||||
|
||||
struct fdsource {
|
||||
GSource source;
|
||||
GSList *pollfds;
|
||||
};
|
||||
|
||||
static gboolean source_prepare(GSource *source, gint *timeout)
|
||||
{
|
||||
int r;
|
||||
struct timeval tv;
|
||||
|
||||
r = fp_get_next_timeout(&tv);
|
||||
if (r == 0) {
|
||||
*timeout = -1;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!timerisset(&tv))
|
||||
return TRUE;
|
||||
|
||||
*timeout = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean source_check(GSource *source)
|
||||
{
|
||||
struct fdsource *_fdsource = (struct fdsource *) source;
|
||||
GSList *l;
|
||||
struct timeval tv;
|
||||
int r;
|
||||
|
||||
if (!_fdsource->pollfds)
|
||||
return FALSE;
|
||||
|
||||
for (l = _fdsource->pollfds; l != NULL; l = l->next) {
|
||||
GPollFD *pollfd = l->data;
|
||||
|
||||
if (pollfd->revents)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
r = fp_get_next_timeout(&tv);
|
||||
if (r == 1 && !timerisset(&tv))
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean source_dispatch(GSource *source, GSourceFunc callback,
|
||||
gpointer data)
|
||||
{
|
||||
struct timeval zerotimeout = {
|
||||
.tv_sec = 0,
|
||||
.tv_usec = 0,
|
||||
};
|
||||
|
||||
/* FIXME error handling */
|
||||
fp_handle_events_timeout(&zerotimeout);
|
||||
|
||||
/* FIXME whats the return value used for? */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void source_finalize(GSource *source)
|
||||
{
|
||||
struct fdsource *_fdsource = (struct fdsource *) source;
|
||||
GSList *l;
|
||||
|
||||
if (!_fdsource->pollfds)
|
||||
return;
|
||||
|
||||
for (l = _fdsource->pollfds; l != NULL; l = l->next) {
|
||||
GPollFD *pollfd = l->data;
|
||||
|
||||
g_source_remove_poll((GSource *) _fdsource, pollfd);
|
||||
g_slice_free(GPollFD, pollfd);
|
||||
_fdsource->pollfds = g_slist_delete_link(_fdsource->pollfds, l);
|
||||
}
|
||||
|
||||
g_slist_free(_fdsource->pollfds);
|
||||
}
|
||||
|
||||
static GSourceFuncs sourcefuncs = {
|
||||
.prepare = source_prepare,
|
||||
.check = source_check,
|
||||
.dispatch = source_dispatch,
|
||||
.finalize = source_finalize,
|
||||
};
|
||||
|
||||
static struct fdsource *fdsource = NULL;
|
||||
|
||||
static void pollfd_add(int fd, short events)
|
||||
{
|
||||
GPollFD *pollfd;
|
||||
|
||||
pollfd = g_slice_new(GPollFD);
|
||||
pollfd->fd = fd;
|
||||
pollfd->events = 0;
|
||||
pollfd->revents = 0;
|
||||
if (events & POLLIN)
|
||||
pollfd->events |= G_IO_IN;
|
||||
if (events & POLLOUT)
|
||||
pollfd->events |= G_IO_OUT;
|
||||
|
||||
fdsource->pollfds = g_slist_prepend(fdsource->pollfds, pollfd);
|
||||
g_source_add_poll((GSource *) fdsource, pollfd);
|
||||
}
|
||||
|
||||
static void pollfd_added_cb(int fd, short events)
|
||||
{
|
||||
g_debug("now monitoring fd %d", fd);
|
||||
pollfd_add(fd, events);
|
||||
}
|
||||
|
||||
static void pollfd_removed_cb(int fd)
|
||||
{
|
||||
GSList *l;
|
||||
|
||||
g_debug("no longer monitoring fd %d", fd);
|
||||
|
||||
if (!fdsource->pollfds) {
|
||||
g_debug("cannot remove from list as list is empty?");
|
||||
return;
|
||||
}
|
||||
|
||||
for (l = fdsource->pollfds; l != NULL; l = l->next) {
|
||||
GPollFD *pollfd = l->data;
|
||||
|
||||
if (pollfd->fd != fd)
|
||||
continue;
|
||||
|
||||
g_source_remove_poll((GSource *) fdsource, pollfd);
|
||||
g_slice_free(GPollFD, pollfd);
|
||||
fdsource->pollfds = g_slist_delete_link(fdsource->pollfds, l);
|
||||
return;
|
||||
}
|
||||
|
||||
g_error("couldn't find fd %d in list\n", fd);
|
||||
}
|
||||
|
||||
int setup_pollfds(void)
|
||||
{
|
||||
ssize_t numfds;
|
||||
size_t i;
|
||||
struct fp_pollfd *fpfds;
|
||||
GSource *gsource;
|
||||
|
||||
gsource = g_source_new(&sourcefuncs, sizeof(struct fdsource));
|
||||
fdsource = (struct fdsource *) gsource;
|
||||
fdsource->pollfds = NULL;
|
||||
|
||||
numfds = fp_get_pollfds(&fpfds);
|
||||
if (numfds < 0) {
|
||||
if (fpfds)
|
||||
free(fpfds);
|
||||
return (int) numfds;
|
||||
} else if (numfds > 0) {
|
||||
for (i = 0; i < numfds; i++) {
|
||||
struct fp_pollfd *fpfd = &fpfds[i];
|
||||
pollfd_add(fpfd->fd, fpfd->events);
|
||||
}
|
||||
}
|
||||
|
||||
free(fpfds);
|
||||
fp_set_pollfd_notifiers(pollfd_added_cb, pollfd_removed_cb);
|
||||
g_source_attach(gsource, NULL);
|
||||
return 0;
|
||||
}
|
||||
27
src/loop.h
27
src/loop.h
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Daniel Drake <dsd@gentoo.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef POLL_H
|
||||
|
||||
#define POLL_H
|
||||
|
||||
int setup_pollfds(void);
|
||||
|
||||
#endif
|
||||
|
||||
18
src/main.c
18
src/main.c
@ -25,12 +25,11 @@
|
||||
#include <dbus/dbus-glib-bindings.h>
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <libfprint/fprint.h>
|
||||
#include <fprint.h>
|
||||
#include <glib-object.h>
|
||||
#include <gmodule.h>
|
||||
|
||||
#include "fprintd.h"
|
||||
#include "loop.h"
|
||||
#include "storage.h"
|
||||
#include "file_storage.h"
|
||||
|
||||
@ -135,7 +134,6 @@ int main(int argc, char **argv)
|
||||
FprintManager *manager;
|
||||
DBusGProxy *driver_proxy;
|
||||
guint32 request_name_ret;
|
||||
int r = 0;
|
||||
|
||||
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
|
||||
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
||||
@ -190,20 +188,8 @@ int main(int argc, char **argv)
|
||||
set_storage_file ();
|
||||
store.init ();
|
||||
|
||||
r = fp_init();
|
||||
if (r < 0) {
|
||||
g_warning("fprint init failed with error %d\n", r);
|
||||
return r;
|
||||
}
|
||||
|
||||
loop = g_main_loop_new(NULL, FALSE);
|
||||
|
||||
r = setup_pollfds();
|
||||
if (r < 0) {
|
||||
g_warning("pollfd setup failed\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
g_debug("Launching FprintObject");
|
||||
|
||||
/* create the one instance of the Manager object to be shared between
|
||||
@ -218,8 +204,6 @@ int main(int argc, char **argv)
|
||||
|
||||
g_object_unref (manager);
|
||||
|
||||
err:
|
||||
fp_exit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
108
src/manager.c
108
src/manager.c
@ -22,7 +22,7 @@
|
||||
#include <dbus/dbus-glib-bindings.h>
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <libfprint/fprint.h>
|
||||
#include <fprint.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "fprintd.h"
|
||||
@ -41,6 +41,7 @@ G_DEFINE_TYPE(FprintManager, fprint_manager, G_TYPE_OBJECT);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FpContext *context;
|
||||
GSList *dev_registry;
|
||||
gboolean no_timeout;
|
||||
guint timeout_id;
|
||||
@ -53,6 +54,7 @@ static void fprint_manager_finalize(GObject *object)
|
||||
{
|
||||
FprintManagerPrivate *priv = FPRINT_MANAGER_GET_PRIVATE (object);
|
||||
|
||||
g_clear_object (&priv->context);
|
||||
g_slist_free(priv->dev_registry);
|
||||
|
||||
G_OBJECT_CLASS(parent_class)->finalize(object);
|
||||
@ -111,33 +113,80 @@ fprint_manager_in_use_notified (FprintDevice *rdev, GParamSpec *spec, FprintMana
|
||||
priv->timeout_id = g_timeout_add_seconds (TIMEOUT, (GSourceFunc) fprint_manager_timeout_cb, manager);
|
||||
}
|
||||
|
||||
static void
|
||||
device_added_cb (FprintManager *manager, FpDevice *device, FpContext *context)
|
||||
{
|
||||
FprintManagerPrivate *priv = FPRINT_MANAGER_GET_PRIVATE (manager);
|
||||
FprintDevice *rdev = fprint_device_new(device);
|
||||
g_autofree gchar *path = NULL;
|
||||
|
||||
g_signal_connect (G_OBJECT(rdev), "notify::in-use",
|
||||
G_CALLBACK (fprint_manager_in_use_notified), manager);
|
||||
|
||||
priv->dev_registry = g_slist_prepend (priv->dev_registry, rdev);
|
||||
path = get_device_path (rdev);
|
||||
dbus_g_connection_register_g_object(fprintd_dbus_conn, path,
|
||||
G_OBJECT(rdev));
|
||||
}
|
||||
|
||||
static void
|
||||
device_removed_cb (FprintManager *manager, FpDevice *device, FpContext *context)
|
||||
{
|
||||
FprintManagerPrivate *priv = FPRINT_MANAGER_GET_PRIVATE (manager);
|
||||
GSList *item;
|
||||
g_autofree gchar *path = NULL;
|
||||
|
||||
for (item = priv->dev_registry; item; item = item->next) {
|
||||
FprintDevice *rdev;
|
||||
g_autoptr(FpDevice) dev = NULL;
|
||||
|
||||
rdev = item->data;
|
||||
|
||||
g_object_get (rdev, "dev", &dev, NULL);
|
||||
if (dev != device)
|
||||
continue;
|
||||
|
||||
priv->dev_registry = g_slist_delete_link (priv->dev_registry, item);
|
||||
|
||||
dbus_g_connection_unregister_g_object(fprintd_dbus_conn, G_OBJECT(rdev));
|
||||
|
||||
g_signal_handlers_disconnect_by_data (rdev, manager);
|
||||
g_object_unref (rdev);
|
||||
|
||||
/* We cannot continue to iterate at this point, but we don't need to either */
|
||||
break;
|
||||
}
|
||||
|
||||
/* The device that disappeared might have been in-use.
|
||||
* Do we need to do anything else in this case to clean up more gracefully? */
|
||||
fprint_manager_in_use_notified (NULL, NULL, manager);
|
||||
}
|
||||
|
||||
static void
|
||||
fprint_manager_init (FprintManager *manager)
|
||||
{
|
||||
FprintManagerPrivate *priv = FPRINT_MANAGER_GET_PRIVATE (manager);
|
||||
struct fp_dscv_dev **discovered_devs = fp_discover_devs();
|
||||
struct fp_dscv_dev *ddev;
|
||||
int i = 0;
|
||||
|
||||
priv->context = fp_context_new ();
|
||||
|
||||
/* And register the signals for initial enumeration and hotplug. */
|
||||
g_signal_connect_object (priv->context,
|
||||
"device-added",
|
||||
(GCallback) device_added_cb,
|
||||
manager,
|
||||
G_CONNECT_SWAPPED);
|
||||
|
||||
g_signal_connect_object (priv->context,
|
||||
"device-removed",
|
||||
(GCallback) device_removed_cb,
|
||||
manager,
|
||||
G_CONNECT_SWAPPED);
|
||||
|
||||
/* Prepare everthing by enumerating all devices. */
|
||||
fp_context_enumerate (priv->context);
|
||||
|
||||
dbus_g_connection_register_g_object(fprintd_dbus_conn,
|
||||
"/net/reactivated/Fprint/Manager", G_OBJECT(manager));
|
||||
|
||||
if (discovered_devs == NULL)
|
||||
return;
|
||||
|
||||
while ((ddev = discovered_devs[i++]) != NULL) {
|
||||
FprintDevice *rdev = fprint_device_new(ddev);
|
||||
gchar *path;
|
||||
|
||||
g_signal_connect (G_OBJECT(rdev), "notify::in-use",
|
||||
G_CALLBACK (fprint_manager_in_use_notified), manager);
|
||||
|
||||
priv->dev_registry = g_slist_prepend(priv->dev_registry, rdev);
|
||||
path = get_device_path(rdev);
|
||||
dbus_g_connection_register_g_object(fprintd_dbus_conn, path,
|
||||
G_OBJECT(rdev));
|
||||
g_free(path);
|
||||
}
|
||||
}
|
||||
|
||||
FprintManager *fprint_manager_new(gboolean no_timeout)
|
||||
@ -159,10 +208,14 @@ static gboolean fprint_manager_get_devices(FprintManager *manager,
|
||||
GPtrArray **devices, GError **error)
|
||||
{
|
||||
FprintManagerPrivate *priv = FPRINT_MANAGER_GET_PRIVATE (manager);
|
||||
GSList *elem = g_slist_reverse(g_slist_copy(priv->dev_registry));
|
||||
GSList *elem;
|
||||
GSList *l;
|
||||
int num_open = g_slist_length(elem);
|
||||
GPtrArray *devs = g_ptr_array_sized_new(num_open);
|
||||
int num_open;
|
||||
GPtrArray *devs;
|
||||
|
||||
elem = g_slist_reverse(g_slist_copy(priv->dev_registry));
|
||||
num_open = g_slist_length(elem);
|
||||
devs = g_ptr_array_sized_new(num_open);
|
||||
|
||||
if (num_open > 0) {
|
||||
for (l = elem; l != NULL; l = l->next) {
|
||||
@ -181,8 +234,11 @@ static gboolean fprint_manager_get_default_device(FprintManager *manager,
|
||||
const char **device, GError **error)
|
||||
{
|
||||
FprintManagerPrivate *priv = FPRINT_MANAGER_GET_PRIVATE (manager);
|
||||
GSList *elem = priv->dev_registry;
|
||||
int num_open = g_slist_length(elem);
|
||||
GSList *elem;;
|
||||
int num_open;
|
||||
|
||||
elem = priv->dev_registry;
|
||||
num_open = g_slist_length(elem);
|
||||
|
||||
if (num_open > 0) {
|
||||
*device = get_device_path (g_slist_last (elem)->data);
|
||||
|
||||
@ -22,13 +22,15 @@
|
||||
|
||||
#define STORAGE_H
|
||||
|
||||
typedef int (*storage_print_data_save)(struct fp_print_data *data,
|
||||
enum fp_finger finger, const char *username);
|
||||
typedef int (*storage_print_data_load)(struct fp_dev *dev,
|
||||
enum fp_finger finger, struct fp_print_data **data, const char *username);
|
||||
typedef int (*storage_print_data_delete)(struct fp_dscv_dev *dev,
|
||||
enum fp_finger finger, const char *username);
|
||||
typedef GSList *(*storage_discover_prints)(struct fp_dscv_dev *dev, const char *username);
|
||||
typedef int (*storage_print_data_save)(FpPrint *print);
|
||||
typedef int (*storage_print_data_load)(FpDevice *dev,
|
||||
FpFinger finger,
|
||||
const char *username,
|
||||
FpPrint **print);
|
||||
typedef int (*storage_print_data_delete)(FpDevice *dev,
|
||||
FpFinger finger,
|
||||
const char *username);
|
||||
typedef GSList *(*storage_discover_prints)(FpDevice *dev, const char *username);
|
||||
typedef int (*storage_init)(void);
|
||||
typedef int (*storage_deinit)(void);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user