fprintd: Reindent the source code following uncrustify rules

This commit is contained in:
Marco Trevisan (Treviño)
2020-12-03 23:55:48 +01:00
parent c18ebaf9da
commit f73429f062
14 changed files with 3589 additions and 3180 deletions

File diff suppressed because it is too large Load Diff

View File

@ -7,12 +7,12 @@
* 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.
@ -44,271 +44,297 @@
static char *storage_path = NULL;
static const char *get_storage_path(void)
static const char *
get_storage_path (void)
{
const char *path = NULL;
const char *path = NULL;
if (storage_path != NULL)
return storage_path;
if (storage_path != NULL)
return storage_path;
/* set by systemd >= 240 to an absolute path
* taking into account the StateDirectory
* unit file setting */
path = g_getenv ("STATE_DIRECTORY");
if (path != NULL) {
/* If multiple directories are set, then in the environment variable
* the paths are concatenated with colon (":"). */
if (strchr (path, ':')) {
g_auto(GStrv) elems = NULL;
elems = g_strsplit (path, ":", -1);
storage_path = g_strdup (elems[0]);
}
}
/* set by systemd >= 240 to an absolute path
* taking into account the StateDirectory
* unit file setting */
path = g_getenv ("STATE_DIRECTORY");
if (path != NULL)
{
/* If multiple directories are set, then in the environment variable
* the paths are concatenated with colon (":"). */
if (strchr (path, ':'))
{
g_auto(GStrv) elems = NULL;
elems = g_strsplit (path, ":", -1);
storage_path = g_strdup (elems[0]);
}
}
if (storage_path == NULL)
storage_path = g_strdup (FILE_STORAGE_PATH);
if (storage_path == NULL)
storage_path = g_strdup (FILE_STORAGE_PATH);
return storage_path;
return storage_path;
}
static char *get_path_to_storedir(const char *driver, const char * device_id, char *base_store)
static char *
get_path_to_storedir (const char *driver, const char * device_id, char *base_store)
{
return g_build_filename(base_store, driver, device_id, NULL);
return g_build_filename (base_store, driver, device_id, NULL);
}
static char *__get_path_to_print(const char *driver, const char * device_id,
FpFinger finger, char *base_store)
static char *
__get_path_to_print (const char *driver, const char * device_id,
FpFinger finger, char *base_store)
{
g_autofree char *dirpath = NULL;
char *path;
char fingername[2];
g_autofree char *dirpath = NULL;
char *path;
char fingername[2];
g_snprintf(fingername, 2, "%x", finger);
g_snprintf (fingername, 2, "%x", finger);
dirpath = get_path_to_storedir(driver, device_id, base_store);
path = g_build_filename(dirpath, fingername, NULL);
return path;
dirpath = get_path_to_storedir (driver, device_id, base_store);
path = g_build_filename (dirpath, fingername, NULL);
return path;
}
static char *get_path_to_print(FpDevice *dev, FpFinger finger, char *base_store)
static char *
get_path_to_print (FpDevice *dev, FpFinger finger, char *base_store)
{
return __get_path_to_print(fp_device_get_driver (dev),
fp_device_get_device_id(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(FpDevice *dev, FpFinger finger, char *base_store)
static char *
get_path_to_print_dscv (FpDevice *dev, FpFinger finger, char *base_store)
{
return __get_path_to_print(fp_device_get_driver (dev),
fp_device_get_device_id(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)
static char *
file_storage_get_basestore_for_username (const char *username)
{
return g_build_filename(get_storage_path(), username, NULL);
return g_build_filename (get_storage_path (), username, NULL);
}
int file_storage_print_data_save(FpPrint *print)
int
file_storage_print_data_save (FpPrint *print)
{
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;
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;
base_store = file_storage_get_basestore_for_username(fp_print_get_username (print));
base_store = file_storage_get_basestore_for_username (fp_print_get_username (print));
if (!fp_print_serialize (print, (guchar **) &buf, &len, &err)) {
g_warning ("Error serializing data: %s", err->message);
return -ENOMEM;
}
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_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));
return r;
}
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));
return r;
}
//fp_dbg("saving to %s", path);
g_file_set_contents(path, buf, len, &err);
if (err) {
g_debug("file_storage_print_data_save(): could not save '%s': %s",
path, err->message);
/* FIXME interpret error codes */
return err->code;
}
//fp_dbg("saving to %s", path);
g_file_set_contents (path, buf, len, &err);
if (err)
{
g_debug ("file_storage_print_data_save(): could not save '%s': %s",
path, err->message);
/* FIXME interpret error codes */
return err->code;
}
return 0;
return 0;
}
static int load_from_file(char *path, FpPrint **print)
static int
load_from_file (char *path, FpPrint **print)
{
g_autoptr(GError) err = NULL;
gsize length;
g_autofree char *contents = NULL;
FpPrint *new;
g_autoptr(GError) err = NULL;
gsize length;
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;
/* FIXME interpret more error codes */
if (r == G_FILE_ERROR_NOENT)
return -ENOENT;
else
return r;
}
//fp_dbg("from %s", path);
g_file_get_contents (path, &contents, &length, &err);
if (err)
{
int r = err->code;
/* FIXME interpret more error codes */
if (r == G_FILE_ERROR_NOENT)
return -ENOENT;
else
return r;
}
new = fp_print_deserialize ((guchar *) contents, length, &err);
if (!new) {
g_print ("Error deserializing data: %s", err->message);
return -EIO;
}
new = fp_print_deserialize ((guchar *) contents, length, &err);
if (!new)
{
g_print ("Error deserializing data: %s", err->message);
return -EIO;
}
*print = new;
return 0;
*print = new;
return 0;
}
int file_storage_print_data_load(FpDevice *dev,
FpFinger finger,
const char *username,
FpPrint **print)
int
file_storage_print_data_load (FpDevice *dev,
FpFinger finger,
const char *username,
FpPrint **print)
{
g_autofree gchar *path = NULL;
g_autofree gchar *base_store = NULL;
g_autoptr(FpPrint) new = NULL;
int r;
g_autofree gchar *path = NULL;
g_autofree gchar *base_store = NULL;
base_store = file_storage_get_basestore_for_username(username);
g_autoptr(FpPrint) new = NULL;
int r;
path = get_path_to_print(dev, finger, base_store);
r = load_from_file(path, &new);
g_debug ("file_storage_print_data_load(): loaded '%s' %s",
path, g_strerror(r));
if (r)
return r;
base_store = file_storage_get_basestore_for_username (username);
if (!fp_print_compatible (new, dev)) {
return -EINVAL;
}
path = get_path_to_print (dev, finger, base_store);
r = load_from_file (path, &new);
g_debug ("file_storage_print_data_load(): loaded '%s' %s",
path, g_strerror (r));
if (r)
return r;
*print = g_steal_pointer (&new);
return 0;
if (!fp_print_compatible (new, dev))
return -EINVAL;
*print = g_steal_pointer (&new);
return 0;
}
int file_storage_print_data_delete(FpDevice *dev, FpFinger 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;
g_autofree gchar *base_store = NULL;
g_autofree gchar *path = NULL;
int r;
base_store = file_storage_get_basestore_for_username(username);
base_store = file_storage_get_basestore_for_username (username);
path = get_path_to_print_dscv(dev, finger, base_store);
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));
r = g_unlink (path);
g_debug ("file_storage_print_data_delete(): unlink(\"%s\") %s",
path, g_strerror (r));
/* FIXME: cleanup empty directory */
return g_unlink(path);
/* FIXME: cleanup empty directory */
return g_unlink (path);
}
static GSList *scan_dev_storedir(char *devpath,
GSList *list)
static GSList *
scan_dev_storedir (char *devpath,
GSList *list)
{
g_autoptr(GError) err = NULL;
const gchar *ent;
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);
return list;
}
GDir *dir = g_dir_open (devpath, 0, &err);
while ((ent = g_dir_read_name(dir))) {
/* ent is an 1 hex character fp_finger code */
guint64 val;
gchar *endptr;
if (!dir)
{
g_debug ("scan_dev_storedir(): opendir(\"%s\") failed: %s", devpath, err->message);
return list;
}
if (*ent == 0 || strlen(ent) != 1)
continue;
while ((ent = g_dir_read_name (dir)))
{
/* ent is an 1 hex character fp_finger code */
guint64 val;
gchar *endptr;
val = g_ascii_strtoull(ent, &endptr, 16);
if (endptr == ent || !FP_FINGER_IS_VALID(val)) {
g_debug("scan_dev_storedir(): skipping print file '%s'", ent);
continue;
}
if (*ent == 0 || strlen (ent) != 1)
continue;
list = g_slist_prepend (list, GUINT_TO_POINTER (val));
}
val = g_ascii_strtoull (ent, &endptr, 16);
if (endptr == ent || !FP_FINGER_IS_VALID (val))
{
g_debug ("scan_dev_storedir(): skipping print file '%s'", ent);
continue;
}
g_dir_close(dir);
return list;
list = g_slist_prepend (list, GUINT_TO_POINTER (val));
}
g_dir_close (dir);
return list;
}
GSList *file_storage_discover_prints(FpDevice *dev, const char *username)
GSList *
file_storage_discover_prints (FpDevice *dev, const char *username)
{
GSList *list = NULL;
g_autofree gchar *base_store = NULL;
g_autofree gchar *storedir = NULL;
GSList *list = NULL;
g_autofree gchar *base_store = NULL;
g_autofree gchar *storedir = NULL;
base_store = file_storage_get_basestore_for_username(username);
base_store = file_storage_get_basestore_for_username (username);
storedir = get_path_to_storedir(fp_device_get_driver (dev),
fp_device_get_device_id (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);
g_debug ("file_storage_discover_prints() for user '%s' in '%s'",
username, storedir);
list = scan_dev_storedir(storedir, list);
list = scan_dev_storedir (storedir, list);
return list;
return list;
}
GSList *file_storage_discover_users(void)
GSList *
file_storage_discover_users (void)
{
g_autoptr(GError) err = NULL;
GSList *list = NULL;
const gchar *ent;
GDir *dir = g_dir_open(get_storage_path(), 0, &err);
g_autoptr(GError) err = NULL;
GSList *list = NULL;
const gchar *ent;
GDir *dir = g_dir_open (get_storage_path (), 0, &err);
if (!dir) {
return list;
}
if (!dir)
return list;
while ((ent = g_dir_read_name(dir))) {
/* ent is a username */
if (*ent == 0)
continue;
while ((ent = g_dir_read_name (dir)))
{
/* ent is a username */
if (*ent == 0)
continue;
list = g_slist_prepend(list, g_strdup (ent));
}
list = g_slist_prepend (list, g_strdup (ent));
}
g_dir_close(dir);
return list;
g_dir_close (dir);
return list;
}
int file_storage_init(void)
int
file_storage_init (void)
{
/* Nothing to do */
return 0;
/* Nothing to do */
return 0;
}
int file_storage_deinit(void)
int
file_storage_deinit (void)
{
g_clear_pointer (&storage_path, g_free);
return 0;
g_clear_pointer (&storage_path, g_free);
return 0;
}

View File

@ -6,12 +6,12 @@
* 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.
@ -20,20 +20,21 @@
#pragma once
int file_storage_print_data_save(FpPrint *print);
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 (FpDevice *dev,
FpFinger finger,
const char *username,
FpPrint **print);
int file_storage_print_data_delete(FpDevice *dev,
FpFinger 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_init (void);
int file_storage_deinit(void);
int file_storage_deinit (void);
GSList *file_storage_discover_prints(FpDevice *dev, const char *username);
GSList *file_storage_discover_users(void);
GSList *file_storage_discover_prints (FpDevice *dev,
const char *username);
GSList *file_storage_discover_users (void);

View File

@ -6,12 +6,12 @@
* 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.
@ -31,60 +31,63 @@
#define FPRINT_SERVICE_PATH "/net/reactivated/Fprint"
/* Errors */
GQuark fprint_error_quark(void);
GQuark fprint_error_quark (void);
#define FPRINT_ERROR fprint_error_quark()
#define FPRINT_ERROR fprint_error_quark ()
typedef enum {
/* developer didn't claim the device */
FPRINT_ERROR_CLAIM_DEVICE, /*< nick=net.reactivated.Fprint.Error.ClaimDevice >*/
/* device is already claimed by somebody else */
FPRINT_ERROR_ALREADY_IN_USE, /*< nick=net.reactivated.Fprint.Error.AlreadyInUse >*/
/* internal error occurred */
FPRINT_ERROR_INTERNAL, /*< nick=net.reactivated.Fprint.Error.Internal >*/
/* PolicyKit refused the action */
FPRINT_ERROR_PERMISSION_DENIED, /*< nick=net.reactivated.Fprint.Error.PermissionDenied >*/
/* No prints are enrolled */
FPRINT_ERROR_NO_ENROLLED_PRINTS, /*< nick=net.reactivated.Fprint.Error.NoEnrolledPrints >*/
/* No actions currently in progress */
FPRINT_ERROR_NO_ACTION_IN_PROGRESS, /*< nick=net.reactivated.Fprint.Error.NoActionInProgress >*/
/* the finger name passed was invalid */
FPRINT_ERROR_INVALID_FINGERNAME, /*< nick=net.reactivated.Fprint.Error.InvalidFingername >*/
/* device does not exist */
FPRINT_ERROR_NO_SUCH_DEVICE, /*< nick=net.reactivated.Fprint.Error.NoSuchDevice >*/
/* developer didn't claim the device */
FPRINT_ERROR_CLAIM_DEVICE, /*< nick=net.reactivated.Fprint.Error.ClaimDevice >*/
/* device is already claimed by somebody else */
FPRINT_ERROR_ALREADY_IN_USE, /*< nick=net.reactivated.Fprint.Error.AlreadyInUse >*/
/* internal error occurred */
FPRINT_ERROR_INTERNAL, /*< nick=net.reactivated.Fprint.Error.Internal >*/
/* PolicyKit refused the action */
FPRINT_ERROR_PERMISSION_DENIED, /*< nick=net.reactivated.Fprint.Error.PermissionDenied >*/
/* No prints are enrolled */
FPRINT_ERROR_NO_ENROLLED_PRINTS, /*< nick=net.reactivated.Fprint.Error.NoEnrolledPrints >*/
/* No actions currently in progress */
FPRINT_ERROR_NO_ACTION_IN_PROGRESS, /*< nick=net.reactivated.Fprint.Error.NoActionInProgress >*/
/* the finger name passed was invalid */
FPRINT_ERROR_INVALID_FINGERNAME, /*< nick=net.reactivated.Fprint.Error.InvalidFingername >*/
/* device does not exist */
FPRINT_ERROR_NO_SUCH_DEVICE, /*< nick=net.reactivated.Fprint.Error.NoSuchDevice >*/
} FprintError;
/* Enum of possible permissions, orders and nick matter here:
- The order controls the priority of a required permission when various are
accepted: the lowest the value, the more priorty it has.
- Nick must match the relative polkit rule.
*/
*/
typedef enum {
FPRINT_DEVICE_PERMISSION_NONE = 0,
FPRINT_DEVICE_PERMISSION_VERIFY = (1 << 0), /*< nick=net.reactivated.fprint.device.verify >*/
FPRINT_DEVICE_PERMISSION_ENROLL = (1 << 1), /*< nick=net.reactivated.fprint.device.enroll >*/
FPRINT_DEVICE_PERMISSION_SETUSERNAME = (1 << 2), /*< nick=net.reactivated.fprint.device.setusername >*/
FPRINT_DEVICE_PERMISSION_NONE = 0,
FPRINT_DEVICE_PERMISSION_VERIFY = (1 << 0), /*< nick=net.reactivated.fprint.device.verify >*/
FPRINT_DEVICE_PERMISSION_ENROLL = (1 << 1), /*< nick=net.reactivated.fprint.device.enroll >*/
FPRINT_DEVICE_PERMISSION_SETUSERNAME = (1 << 2), /*< nick=net.reactivated.fprint.device.setusername >*/
} FprintDevicePermission;
/* Manager */
#define FPRINT_TYPE_MANAGER (fprint_manager_get_type())
#define FPRINT_TYPE_MANAGER (fprint_manager_get_type ())
G_DECLARE_FINAL_TYPE (FprintManager, fprint_manager, FPRINT, MANAGER, GObject)
struct _FprintManager {
GObject parent;
struct _FprintManager
{
GObject parent;
};
FprintManager *fprint_manager_new (GDBusConnection *connection, gboolean no_timeout);
FprintManager *fprint_manager_new (GDBusConnection *connection,
gboolean no_timeout);
/* Device */
#define FPRINT_TYPE_DEVICE (fprint_device_get_type())
#define FPRINT_TYPE_DEVICE (fprint_device_get_type ())
G_DECLARE_FINAL_TYPE (FprintDevice, fprint_device, FPRINT, DEVICE,
FprintDBusDeviceSkeleton)
FprintDBusDeviceSkeleton)
struct _FprintDevice {
FprintDBusDeviceSkeleton parent;
struct _FprintDevice
{
FprintDBusDeviceSkeleton parent;
};
FprintDevice *fprint_device_new(FpDevice *dev);
guint32 _fprint_device_get_id(FprintDevice *rdev);
FprintDevice *fprint_device_new (FpDevice *dev);
guint32 _fprint_device_get_id (FprintDevice *rdev);
/* Print */
/* TODO */

View File

@ -7,12 +7,12 @@
* 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.
@ -44,171 +44,179 @@ static gboolean g_fatal_warnings = FALSE;
static void
set_storage_file (void)
{
store.init = &file_storage_init;
store.deinit = &file_storage_deinit;
store.print_data_save = &file_storage_print_data_save;
store.print_data_load = &file_storage_print_data_load;
store.print_data_delete = &file_storage_print_data_delete;
store.discover_prints = &file_storage_discover_prints;
store.discover_users = &file_storage_discover_users;
store.init = &file_storage_init;
store.deinit = &file_storage_deinit;
store.print_data_save = &file_storage_print_data_save;
store.print_data_load = &file_storage_print_data_load;
store.print_data_delete = &file_storage_print_data_delete;
store.discover_prints = &file_storage_discover_prints;
store.discover_users = &file_storage_discover_users;
}
static gboolean
load_storage_module (const char *module_name)
{
GModule *module;
g_autofree char *filename = NULL;
GModule *module;
g_autofree char *filename = NULL;
filename = g_module_build_path (PLUGINDIR, module_name);
module = g_module_open (filename, 0);
if (module == NULL)
return FALSE;
filename = g_module_build_path (PLUGINDIR, module_name);
module = g_module_open (filename, 0);
if (module == NULL)
return FALSE;
if (!g_module_symbol (module, "init", (gpointer *) &store.init) ||
!g_module_symbol (module, "deinit", (gpointer *) &store.deinit) ||
!g_module_symbol (module, "print_data_save", (gpointer *) &store.print_data_save) ||
!g_module_symbol (module, "print_data_load", (gpointer *) &store.print_data_load) ||
!g_module_symbol (module, "print_data_delete", (gpointer *) &store.print_data_delete) ||
!g_module_symbol (module, "discover_prints", (gpointer *) &store.discover_prints)) {
g_module_close (module);
return FALSE;
}
if (!g_module_symbol (module, "init", (gpointer *) &store.init) ||
!g_module_symbol (module, "deinit", (gpointer *) &store.deinit) ||
!g_module_symbol (module, "print_data_save", (gpointer *) &store.print_data_save) ||
!g_module_symbol (module, "print_data_load", (gpointer *) &store.print_data_load) ||
!g_module_symbol (module, "print_data_delete", (gpointer *) &store.print_data_delete) ||
!g_module_symbol (module, "discover_prints", (gpointer *) &store.discover_prints))
{
g_module_close (module);
return FALSE;
}
g_module_make_resident (module);
g_module_make_resident (module);
return TRUE;
return TRUE;
}
static gboolean
load_conf (void)
{
g_autofree char *filename = NULL;
g_autofree char *module_name = NULL;
g_autoptr(GKeyFile) file = NULL;
g_autoptr(GError) error = NULL;
g_autofree char *filename = NULL;
g_autofree char *module_name = NULL;
filename = g_build_filename (SYSCONFDIR, "fprintd.conf", NULL);
file = g_key_file_new ();
g_debug("About to load configuration file '%s'", filename);
if (!g_key_file_load_from_file (file, filename, G_KEY_FILE_NONE, &error)) {
g_warning ("Could not open \"%s\": %s\n", filename, error->message);
return FALSE;
}
g_autoptr(GKeyFile) file = NULL;
g_autoptr(GError) error = NULL;
module_name = g_key_file_get_string (file, "storage", "type", &error);
if (module_name == NULL)
return FALSE;
filename = g_build_filename (SYSCONFDIR, "fprintd.conf", NULL);
file = g_key_file_new ();
g_debug ("About to load configuration file '%s'", filename);
if (!g_key_file_load_from_file (file, filename, G_KEY_FILE_NONE, &error))
{
g_warning ("Could not open \"%s\": %s\n", filename, error->message);
return FALSE;
}
if (g_str_equal (module_name, "file")) {
set_storage_file ();
return TRUE;
}
module_name = g_key_file_get_string (file, "storage", "type", &error);
if (module_name == NULL)
return FALSE;
return load_storage_module (module_name);
if (g_str_equal (module_name, "file"))
{
set_storage_file ();
return TRUE;
}
return load_storage_module (module_name);
}
static const GOptionEntry entries[] = {
{"g-fatal-warnings", 0, 0, G_OPTION_ARG_NONE, &g_fatal_warnings, "Make all warnings fatal", NULL},
{"no-timeout", 't', 0, G_OPTION_ARG_NONE, &no_timeout, "Do not exit after unused for a while", NULL},
{ NULL }
{"g-fatal-warnings", 0, 0, G_OPTION_ARG_NONE, &g_fatal_warnings, "Make all warnings fatal", NULL},
{"no-timeout", 't', 0, G_OPTION_ARG_NONE, &no_timeout, "Do not exit after unused for a while", NULL},
{ NULL }
};
static gboolean sigterm_callback(gpointer data)
static gboolean
sigterm_callback (gpointer data)
{
GMainLoop *loop = data;
GMainLoop *loop = data;
g_main_loop_quit (loop);
return FALSE;
g_main_loop_quit (loop);
return FALSE;
}
static void
on_name_acquired (GDBusConnection *connection,
const char *name,
gpointer user_data)
const char *name,
gpointer user_data)
{
g_debug ("D-Bus service launched with name: %s", name);
g_debug ("D-Bus service launched with name: %s", name);
}
static void
on_name_lost (GDBusConnection *connection,
const char *name,
gpointer user_data)
const char *name,
gpointer user_data)
{
GMainLoop *loop = user_data;
GMainLoop *loop = user_data;
g_warning ("Failed to get name: %s", name);
g_warning ("Failed to get name: %s", name);
g_main_loop_quit (loop);
g_main_loop_quit (loop);
}
int main(int argc, char **argv)
int
main (int argc, char **argv)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(GMainLoop) loop = NULL;
g_autoptr(GError) error = NULL;
g_autoptr(FprintManager) manager = NULL;
g_autoptr(GDBusConnection) connection = NULL;
guint32 request_name_ret;
g_autoptr(GOptionContext) context = NULL;
g_autoptr(GMainLoop) loop = NULL;
g_autoptr(GError) error = NULL;
g_autoptr(FprintManager) manager = NULL;
g_autoptr(GDBusConnection) connection = NULL;
guint32 request_name_ret;
setlocale (LC_ALL, "");
setlocale (LC_ALL, "");
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
context = g_option_context_new ("Fingerprint handler daemon");
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
context = g_option_context_new ("Fingerprint handler daemon");
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) {
g_warning ("couldn't parse command-line options: %s\n", error->message);
return 1;
}
if (g_option_context_parse (context, &argc, &argv, &error) == FALSE)
{
g_warning ("couldn't parse command-line options: %s\n", error->message);
return 1;
}
if (g_fatal_warnings) {
GLogLevelFlags fatal_mask;
if (g_fatal_warnings)
{
GLogLevelFlags fatal_mask;
fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
g_log_set_always_fatal (fatal_mask);
}
fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
g_log_set_always_fatal (fatal_mask);
}
/* Obtain a connection to the system bus */
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (!G_IS_DBUS_CONNECTION (connection)) {
g_warning("Failed to open connection to bus: %s", error->message);
return 1;
}
/* Obtain a connection to the system bus */
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (!G_IS_DBUS_CONNECTION (connection))
{
g_warning ("Failed to open connection to bus: %s", error->message);
return 1;
}
/* Load the configuration file,
* and the default storage plugin */
if (!load_conf())
set_storage_file ();
store.init ();
/* Load the configuration file,
* and the default storage plugin */
if (!load_conf ())
set_storage_file ();
store.init ();
loop = g_main_loop_new(NULL, FALSE);
g_unix_signal_add (SIGTERM, sigterm_callback, loop);
loop = g_main_loop_new (NULL, FALSE);
g_unix_signal_add (SIGTERM, sigterm_callback, loop);
g_debug("Launching FprintObject");
g_debug ("Launching FprintObject");
/* create the one instance of the Manager object to be shared between
* all fprintd users. This blocks until all the devices are enumerated */
manager = fprint_manager_new (connection, no_timeout);
/* create the one instance of the Manager object to be shared between
* all fprintd users. This blocks until all the devices are enumerated */
manager = fprint_manager_new (connection, no_timeout);
/* Obtain the well-known name after the manager has been initialized.
* Otherwise a client immediately enumerating the devices will not see
* any. */
request_name_ret = g_bus_own_name_on_connection (connection,
FPRINT_SERVICE_NAME,
G_BUS_NAME_OWNER_FLAGS_NONE,
on_name_acquired,
on_name_lost,
loop, NULL);
/* Obtain the well-known name after the manager has been initialized.
* Otherwise a client immediately enumerating the devices will not see
* any. */
request_name_ret = g_bus_own_name_on_connection (connection,
FPRINT_SERVICE_NAME,
G_BUS_NAME_OWNER_FLAGS_NONE,
on_name_acquired,
on_name_lost,
loop, NULL);
g_debug("entering main loop");
g_main_loop_run(loop);
g_bus_unown_name (request_name_ret);
g_debug("main loop completed");
g_debug ("entering main loop");
g_main_loop_run (loop);
g_bus_unown_name (request_name_ret);
g_debug ("main loop completed");
return 0;
return 0;
}

View File

@ -7,12 +7,12 @@
* 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.
@ -28,294 +28,316 @@
#include "fprintd.h"
static void fprint_manager_constructed (GObject *object);
static gboolean fprint_manager_get_devices(FprintManager *manager,
GPtrArray **devices, GError **error);
static gboolean fprint_manager_get_default_device(FprintManager *manager,
const char **device, GError **error);
static gboolean fprint_manager_get_devices (FprintManager *manager,
GPtrArray **devices,
GError **error);
static gboolean fprint_manager_get_default_device (FprintManager *manager,
const char **device,
GError **error);
typedef struct
{
GDBusConnection *connection;
GDBusObjectManager *object_manager;
FprintDBusManager *dbus_manager;
FpContext *context;
gboolean no_timeout;
guint timeout_id;
GDBusConnection *connection;
GDBusObjectManager *object_manager;
FprintDBusManager *dbus_manager;
FpContext *context;
gboolean no_timeout;
guint timeout_id;
} FprintManagerPrivate;
G_DEFINE_TYPE_WITH_CODE(FprintManager, fprint_manager, G_TYPE_OBJECT, G_ADD_PRIVATE (FprintManager))
G_DEFINE_TYPE_WITH_CODE (FprintManager, fprint_manager, G_TYPE_OBJECT, G_ADD_PRIVATE (FprintManager))
enum {
PROP_0,
FPRINT_MANAGER_CONNECTION,
N_PROPS
PROP_0,
FPRINT_MANAGER_CONNECTION,
N_PROPS
};
static GParamSpec *properties[N_PROPS];
static void fprint_manager_finalize(GObject *object)
static void
fprint_manager_finalize (GObject *object)
{
FprintManagerPrivate *priv = fprint_manager_get_instance_private (FPRINT_MANAGER (object));
FprintManagerPrivate *priv = fprint_manager_get_instance_private (FPRINT_MANAGER (object));
g_clear_object (&priv->object_manager);
g_clear_object (&priv->dbus_manager);
g_clear_object (&priv->connection);
g_clear_object (&priv->context);
g_clear_object (&priv->object_manager);
g_clear_object (&priv->dbus_manager);
g_clear_object (&priv->connection);
g_clear_object (&priv->context);
G_OBJECT_CLASS(fprint_manager_parent_class)->finalize(object);
G_OBJECT_CLASS (fprint_manager_parent_class)->finalize (object);
}
static FprintDevice *
fprint_dbus_object_skeleton_get_device (FprintDBusObjectSkeleton *object) {
FprintDevice *rdev;
fprint_dbus_object_skeleton_get_device (FprintDBusObjectSkeleton *object)
{
FprintDevice *rdev;
g_object_get (object, "device", &rdev, NULL);
return rdev;
g_object_get (object, "device", &rdev, NULL);
return rdev;
}
static void fprint_manager_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
static void
fprint_manager_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
FprintManager *self = FPRINT_MANAGER (object);
FprintManagerPrivate *priv = fprint_manager_get_instance_private (self);
FprintManager *self = FPRINT_MANAGER (object);
FprintManagerPrivate *priv = fprint_manager_get_instance_private (self);
switch (property_id) {
case FPRINT_MANAGER_CONNECTION:
priv->connection = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
switch (property_id)
{
case FPRINT_MANAGER_CONNECTION:
priv->connection = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void fprint_manager_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
static void
fprint_manager_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
{
FprintManager *self = FPRINT_MANAGER (object);
FprintManagerPrivate *priv = fprint_manager_get_instance_private (self);
FprintManager *self = FPRINT_MANAGER (object);
FprintManagerPrivate *priv = fprint_manager_get_instance_private (self);
switch (property_id) {
case FPRINT_MANAGER_CONNECTION:
g_value_set_object (value, priv->connection);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
switch (property_id)
{
case FPRINT_MANAGER_CONNECTION:
g_value_set_object (value, priv->connection);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void fprint_manager_class_init(FprintManagerClass *klass)
static void
fprint_manager_class_init (FprintManagerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = fprint_manager_constructed;
object_class->set_property = fprint_manager_set_property;
object_class->get_property = fprint_manager_get_property;
object_class->finalize = fprint_manager_finalize;
object_class->constructed = fprint_manager_constructed;
object_class->set_property = fprint_manager_set_property;
object_class->get_property = fprint_manager_get_property;
object_class->finalize = fprint_manager_finalize;
properties[FPRINT_MANAGER_CONNECTION] =
g_param_spec_object ("connection",
"Connection",
"Set GDBus connection property",
G_TYPE_DBUS_CONNECTION,
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE);
properties[FPRINT_MANAGER_CONNECTION] =
g_param_spec_object ("connection",
"Connection",
"Set GDBus connection property",
G_TYPE_DBUS_CONNECTION,
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE);
g_object_class_install_properties (object_class, N_PROPS, properties);
g_object_class_install_properties (object_class, N_PROPS, properties);
}
static gchar *get_device_path(FprintDevice *rdev)
static gchar *
get_device_path (FprintDevice *rdev)
{
return g_strdup_printf (FPRINT_SERVICE_PATH "/Device/%d",
_fprint_device_get_id(rdev));
return g_strdup_printf (FPRINT_SERVICE_PATH "/Device/%d",
_fprint_device_get_id (rdev));
}
static gboolean
fprint_manager_timeout_cb (FprintManager *manager)
{
//FIXME kill all the devices
exit(0);
return FALSE;
//FIXME kill all the devices
exit (0);
return FALSE;
}
static void
fprint_manager_in_use_notified (FprintDevice *rdev, GParamSpec *spec, FprintManager *manager)
{
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
guint num_devices_used = 0;
g_autolist(GDBusObject) devices = NULL;
GList *l;
gboolean in_use;
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
guint num_devices_used = 0;
if (priv->timeout_id > 0) {
g_source_remove (priv->timeout_id);
priv->timeout_id = 0;
}
if (priv->no_timeout)
return;
g_autolist (GDBusObject) devices = NULL;
GList *l;
gboolean in_use;
devices = g_dbus_object_manager_get_objects (priv->object_manager);
if (priv->timeout_id > 0)
{
g_source_remove (priv->timeout_id);
priv->timeout_id = 0;
}
if (priv->no_timeout)
return;
for (l = devices; l != NULL; l = l->next) {
g_autoptr(FprintDevice) dev = NULL;
FprintDBusObjectSkeleton *object = l->data;
devices = g_dbus_object_manager_get_objects (priv->object_manager);
dev = fprint_dbus_object_skeleton_get_device (object);
g_object_get (G_OBJECT(dev), "in-use", &in_use, NULL);
if (in_use != FALSE)
num_devices_used++;
}
for (l = devices; l != NULL; l = l->next)
{
g_autoptr(FprintDevice) dev = NULL;
FprintDBusObjectSkeleton *object = l->data;
if (num_devices_used == 0)
priv->timeout_id = g_timeout_add_seconds (TIMEOUT, (GSourceFunc) fprint_manager_timeout_cb, manager);
dev = fprint_dbus_object_skeleton_get_device (object);
g_object_get (G_OBJECT (dev), "in-use", &in_use, NULL);
if (in_use != FALSE)
num_devices_used++;
}
if (num_devices_used == 0)
priv->timeout_id = g_timeout_add_seconds (TIMEOUT, (GSourceFunc) fprint_manager_timeout_cb, manager);
}
static gboolean
handle_get_devices (FprintManager *manager, GDBusMethodInvocation *invocation,
FprintDBusManager *skeleton)
FprintDBusManager *skeleton)
{
g_autoptr(GPtrArray) devices = NULL;
g_autoptr(GError) error = NULL;
g_autoptr(GPtrArray) devices = NULL;
g_autoptr(GError) error = NULL;
if (!fprint_manager_get_devices (manager, &devices, &error)) {
g_dbus_method_invocation_return_gerror (invocation, error);
return TRUE;
}
if (!fprint_manager_get_devices (manager, &devices, &error))
{
g_dbus_method_invocation_return_gerror (invocation, error);
return TRUE;
}
fprint_dbus_manager_complete_get_devices (skeleton, invocation,
(const gchar *const *)
devices->pdata);
fprint_dbus_manager_complete_get_devices (skeleton, invocation,
(const gchar *const *)
devices->pdata);
return TRUE;
return TRUE;
}
static gboolean
handle_get_default_device (FprintManager *manager,
GDBusMethodInvocation *invocation,
FprintDBusManager *skeleton)
handle_get_default_device (FprintManager *manager,
GDBusMethodInvocation *invocation,
FprintDBusManager *skeleton)
{
const gchar *device;
g_autoptr(GError) error = NULL;
const gchar *device;
if (!fprint_manager_get_default_device (manager, &device, &error)) {
g_dbus_method_invocation_return_gerror (invocation, error);
return TRUE;
}
g_autoptr(GError) error = NULL;
fprint_dbus_manager_complete_get_default_device (skeleton, invocation,
device);
if (!fprint_manager_get_default_device (manager, &device, &error))
{
g_dbus_method_invocation_return_gerror (invocation, error);
return TRUE;
}
return TRUE;
fprint_dbus_manager_complete_get_default_device (skeleton, invocation,
device);
return TRUE;
}
static void
device_added_cb (FprintManager *manager, FpDevice *device, FpContext *context)
{
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
g_autoptr(FprintDBusObjectSkeleton) object = NULL;
g_autoptr(FprintDevice) rdev = NULL;
g_autofree gchar *path = NULL;
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
rdev = fprint_device_new(device);
g_autoptr(FprintDBusObjectSkeleton) object = NULL;
g_autoptr(FprintDevice) rdev = NULL;
g_autofree gchar *path = NULL;
g_signal_connect (G_OBJECT(rdev), "notify::in-use",
G_CALLBACK (fprint_manager_in_use_notified), manager);
rdev = fprint_device_new (device);
path = get_device_path (rdev);
g_signal_connect (G_OBJECT (rdev), "notify::in-use",
G_CALLBACK (fprint_manager_in_use_notified), manager);
object = fprint_dbus_object_skeleton_new (path);
fprint_dbus_object_skeleton_set_device (object,
FPRINT_DBUS_DEVICE (rdev));
g_dbus_object_manager_server_export (
G_DBUS_OBJECT_MANAGER_SERVER (priv->object_manager),
G_DBUS_OBJECT_SKELETON (object));
path = get_device_path (rdev);
object = fprint_dbus_object_skeleton_new (path);
fprint_dbus_object_skeleton_set_device (object,
FPRINT_DBUS_DEVICE (rdev));
g_dbus_object_manager_server_export (
G_DBUS_OBJECT_MANAGER_SERVER (priv->object_manager),
G_DBUS_OBJECT_SKELETON (object));
}
static void
device_removed_cb (FprintManager *manager, FpDevice *device, FpContext *context)
{
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
g_autolist (FprintDBusObjectSkeleton) objects = NULL;
GList *item;
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
objects = g_dbus_object_manager_get_objects (priv->object_manager);
g_autolist (FprintDBusObjectSkeleton) objects = NULL;
GList *item;
for (item = objects; item; item = item->next) {
g_autoptr(FprintDevice) rdev = NULL;
g_autoptr(FpDevice) dev = NULL;
FprintDBusObjectSkeleton *object = item->data;
objects = g_dbus_object_manager_get_objects (priv->object_manager);
rdev = fprint_dbus_object_skeleton_get_device (object);
g_object_get (rdev, "dev", &dev, NULL);
if (dev != device)
continue;
for (item = objects; item; item = item->next)
{
g_autoptr(FprintDevice) rdev = NULL;
g_autoptr(FpDevice) dev = NULL;
FprintDBusObjectSkeleton *object = item->data;
g_dbus_object_manager_server_unexport (
G_DBUS_OBJECT_MANAGER_SERVER (priv->object_manager),
g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (rdev)));
rdev = fprint_dbus_object_skeleton_get_device (object);
g_object_get (rdev, "dev", &dev, NULL);
if (dev != device)
continue;
g_signal_handlers_disconnect_by_data (rdev, manager);
g_dbus_object_manager_server_unexport (
G_DBUS_OBJECT_MANAGER_SERVER (priv->object_manager),
g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (rdev)));
/* We cannot continue to iterate at this point, but we don't need to either */
break;
}
g_signal_handlers_disconnect_by_data (rdev, manager);
/* 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);
/* 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_constructed (GObject *object)
static void
fprint_manager_constructed (GObject *object)
{
FprintManager *manager = FPRINT_MANAGER (object);
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
GDBusObjectManagerServer *object_manager_server;
FprintManager *manager = FPRINT_MANAGER (object);
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
GDBusObjectManagerServer *object_manager_server;
object_manager_server =
g_dbus_object_manager_server_new (FPRINT_SERVICE_PATH "/Device");
object_manager_server =
g_dbus_object_manager_server_new (FPRINT_SERVICE_PATH "/Device");
priv->object_manager = G_DBUS_OBJECT_MANAGER (object_manager_server);
priv->dbus_manager = fprint_dbus_manager_skeleton_new ();
priv->context = fp_context_new ();
priv->object_manager = G_DBUS_OBJECT_MANAGER (object_manager_server);
priv->dbus_manager = fprint_dbus_manager_skeleton_new ();
priv->context = fp_context_new ();
g_signal_connect_object (priv->dbus_manager,
"handle-get-devices",
G_CALLBACK (handle_get_devices),
manager,
G_CONNECT_SWAPPED);
g_signal_connect_object (priv->dbus_manager,
"handle-get-default-device",
G_CALLBACK (handle_get_default_device),
manager,
G_CONNECT_SWAPPED);
g_signal_connect_object (priv->dbus_manager,
"handle-get-devices",
G_CALLBACK (handle_get_devices),
manager,
G_CONNECT_SWAPPED);
g_signal_connect_object (priv->dbus_manager,
"handle-get-default-device",
G_CALLBACK (handle_get_default_device),
manager,
G_CONNECT_SWAPPED);
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->dbus_manager),
priv->connection,
FPRINT_SERVICE_PATH "/Manager", NULL);
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->dbus_manager),
priv->connection,
FPRINT_SERVICE_PATH "/Manager", NULL);
g_dbus_object_manager_server_set_connection (object_manager_server,
priv->connection);
g_dbus_object_manager_server_set_connection (object_manager_server,
priv->connection);
/* 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);
/* 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);
g_signal_connect_object (priv->context,
"device-removed",
(GCallback) device_removed_cb,
manager,
G_CONNECT_SWAPPED);
/* Prepare everything by enumerating all devices.
* This blocks the main loop until the existing devices are enumerated
*/
fp_context_enumerate (priv->context);
/* Prepare everything by enumerating all devices.
* This blocks the main loop until the existing devices are enumerated
*/
fp_context_enumerate (priv->context);
G_OBJECT_CLASS (fprint_manager_parent_class)->constructed (object);
G_OBJECT_CLASS (fprint_manager_parent_class)->constructed (object);
}
static void
@ -323,99 +345,113 @@ fprint_manager_init (FprintManager *manager)
{
}
FprintManager *fprint_manager_new (GDBusConnection *connection, gboolean no_timeout)
FprintManager *
fprint_manager_new (GDBusConnection *connection, gboolean no_timeout)
{
FprintManagerPrivate *priv;
GObject *object;
FprintManagerPrivate *priv;
GObject *object;
object = g_object_new (FPRINT_TYPE_MANAGER, "connection", connection, NULL);
priv = fprint_manager_get_instance_private (FPRINT_MANAGER (object));
priv->no_timeout = no_timeout;
object = g_object_new (FPRINT_TYPE_MANAGER, "connection", connection, NULL);
priv = fprint_manager_get_instance_private (FPRINT_MANAGER (object));
priv->no_timeout = no_timeout;
if (!priv->no_timeout)
priv->timeout_id = g_timeout_add_seconds (TIMEOUT, (GSourceFunc) fprint_manager_timeout_cb, object);
if (!priv->no_timeout)
priv->timeout_id = g_timeout_add_seconds (TIMEOUT, (GSourceFunc) fprint_manager_timeout_cb, object);
return FPRINT_MANAGER (object);
return FPRINT_MANAGER (object);
}
static gboolean fprint_manager_get_devices(FprintManager *manager,
GPtrArray **devices, GError **error)
static gboolean
fprint_manager_get_devices (FprintManager *manager,
GPtrArray **devices, GError **error)
{
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
g_autolist (FprintDBusObjectSkeleton) objects = NULL;
GList *l;
int num_open;
GPtrArray *devs;
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
objects = g_dbus_object_manager_get_objects (priv->object_manager);
objects = g_list_reverse (objects);
g_autolist (FprintDBusObjectSkeleton) objects = NULL;
GList *l;
int num_open;
GPtrArray *devs;
num_open = g_list_length (objects);
devs = g_ptr_array_sized_new(num_open);
objects = g_dbus_object_manager_get_objects (priv->object_manager);
objects = g_list_reverse (objects);
if (num_open > 0) {
for (l = objects; l != NULL; l = l->next) {
g_autoptr(FprintDevice) rdev = NULL;
FprintDBusObjectSkeleton *object = l->data;
const char *path;
num_open = g_list_length (objects);
devs = g_ptr_array_sized_new (num_open);
rdev = fprint_dbus_object_skeleton_get_device (object);
path = g_dbus_interface_skeleton_get_object_path (
G_DBUS_INTERFACE_SKELETON (rdev));
g_ptr_array_add (devs, (char *) path);
}
}
g_ptr_array_add (devs, NULL);
if (num_open > 0)
{
for (l = objects; l != NULL; l = l->next)
{
g_autoptr(FprintDevice) rdev = NULL;
FprintDBusObjectSkeleton *object = l->data;
const char *path;
*devices = devs;
return TRUE;
rdev = fprint_dbus_object_skeleton_get_device (object);
path = g_dbus_interface_skeleton_get_object_path (
G_DBUS_INTERFACE_SKELETON (rdev));
g_ptr_array_add (devs, (char *) path);
}
}
g_ptr_array_add (devs, NULL);
*devices = devs;
return TRUE;
}
static gboolean fprint_manager_get_default_device(FprintManager *manager,
const char **device, GError **error)
static gboolean
fprint_manager_get_default_device (FprintManager *manager,
const char **device, GError **error)
{
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
g_autolist (FprintDBusObjectSkeleton) objects = NULL;
int num_open;
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
objects = g_dbus_object_manager_get_objects (priv->object_manager);
num_open = g_list_length (objects);
g_autolist (FprintDBusObjectSkeleton) objects = NULL;
int num_open;
if (num_open > 0) {
g_autoptr(FprintDevice) rdev = NULL;
FprintDBusObjectSkeleton *object = g_list_last (objects)->data;
objects = g_dbus_object_manager_get_objects (priv->object_manager);
num_open = g_list_length (objects);
rdev = fprint_dbus_object_skeleton_get_device (object);
*device = g_dbus_interface_skeleton_get_object_path (
G_DBUS_INTERFACE_SKELETON (rdev));
return TRUE;
} else {
g_set_error (error, FPRINT_ERROR, FPRINT_ERROR_NO_SUCH_DEVICE,
"No devices available");
*device = NULL;
return FALSE;
}
if (num_open > 0)
{
g_autoptr(FprintDevice) rdev = NULL;
FprintDBusObjectSkeleton *object = g_list_last (objects)->data;
rdev = fprint_dbus_object_skeleton_get_device (object);
*device = g_dbus_interface_skeleton_get_object_path (
G_DBUS_INTERFACE_SKELETON (rdev));
return TRUE;
}
else
{
g_set_error (error, FPRINT_ERROR, FPRINT_ERROR_NO_SUCH_DEVICE,
"No devices available");
*device = NULL;
return FALSE;
}
}
GQuark fprint_error_quark (void)
GQuark
fprint_error_quark (void)
{
static volatile gsize quark = 0;
if (g_once_init_enter (&quark)) {
g_autoptr(GEnumClass) errors_enum = NULL;
GQuark domain;
unsigned i;
static volatile gsize quark = 0;
domain = g_quark_from_static_string ("fprintd-error-quark");
errors_enum = g_type_class_ref (FPRINT_TYPE_ERROR);
if (g_once_init_enter (&quark))
{
g_autoptr(GEnumClass) errors_enum = NULL;
GQuark domain;
unsigned i;
for (i = 0; i < errors_enum->n_values; ++i) {
GEnumValue *value = &errors_enum->values[i];
domain = g_quark_from_static_string ("fprintd-error-quark");
errors_enum = g_type_class_ref (FPRINT_TYPE_ERROR);
g_dbus_error_register_error (domain, value->value,
value->value_nick);
}
for (i = 0; i < errors_enum->n_values; ++i)
{
GEnumValue *value = &errors_enum->values[i];
g_once_init_leave (&quark, domain);
}
return (GQuark) quark;
g_dbus_error_register_error (domain, value->value,
value->value_nick);
}
g_once_init_leave (&quark, domain);
}
return (GQuark) quark;
}

View File

@ -6,12 +6,12 @@
* 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.
@ -28,19 +28,21 @@ typedef int (*storage_print_data_load)(FpDevice *dev,
typedef int (*storage_print_data_delete)(FpDevice *dev,
FpFinger finger,
const char *username);
typedef GSList *(*storage_discover_prints)(FpDevice *dev, const char *username);
typedef GSList *(*storage_discover_prints)(FpDevice *dev,
const char *username);
typedef GSList *(*storage_discover_users)(void);
typedef int (*storage_init)(void);
typedef int (*storage_deinit)(void);
struct storage {
storage_init init;
storage_deinit deinit;
storage_print_data_save print_data_save;
storage_print_data_load print_data_load;
storage_print_data_delete print_data_delete;
storage_discover_prints discover_prints;
storage_discover_users discover_users;
struct storage
{
storage_init init;
storage_deinit deinit;
storage_print_data_save print_data_save;
storage_print_data_load print_data_load;
storage_print_data_delete print_data_delete;
storage_discover_prints discover_prints;
storage_discover_users discover_users;
};
typedef struct storage fp_storage;