Commit f73429f0 authored by Marco Trevisan's avatar Marco Trevisan
Browse files

fprintd: Reindent the source code following uncrustify rules

parent c18ebaf9
/*
* Helper functions to translate statuses and actions to strings
* Copyright (C) 2008 Bastien Nocera <hadess@hadess.net>
*
*
* Experimental code. This will be moved out of fprintd into it's own
* package once the system has matured.
*
......@@ -9,12 +9,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,115 +28,128 @@
#define GNUC_UNUSED __attribute__((__unused__))
static bool str_equal (const char *a, const char *b)
static bool
str_equal (const char *a, const char *b)
{
if (a == NULL && b == NULL)
return true;
if (a == NULL || b == NULL)
return false;
return (strcmp (a, b) == 0);
if (a == NULL && b == NULL)
return true;
if (a == NULL || b == NULL)
return false;
return strcmp (a, b) == 0;
}
struct {
const char *dbus_name;
const char *place_str_generic;
const char *place_str_specific;
const char *swipe_str_generic;
const char *swipe_str_specific;
struct
{
const char *dbus_name;
const char *place_str_generic;
const char *place_str_specific;
const char *swipe_str_generic;
const char *swipe_str_specific;
} fingers[] = {
{ "any",
N_("Place your finger on the fingerprint reader"),
N_("Place your finger on %s"),
N_("Swipe your finger across the fingerprint reader"),
N_("Swipe your finger across %s") },
{ "left-thumb",
N_("Place your left thumb on the fingerprint reader"),
N_("Place your left thumb on %s"),
N_("Swipe your left thumb across the fingerprint reader"),
N_("Swipe your left thumb across %s") },
{ "left-index-finger",
N_("Place your left index finger on the fingerprint reader"),
N_("Place your left index finger on %s"),
N_("Swipe your left index finger across the fingerprint reader"),
N_("Swipe your left index finger across %s") },
{ "left-middle-finger",
N_("Place your left middle finger on the fingerprint reader"),
N_("Place your left middle finger on %s"),
N_("Swipe your left middle finger across the fingerprint reader"),
N_("Swipe your left middle finger across %s") },
{ "left-ring-finger",
N_("Place your left ring finger on the fingerprint reader"),
N_("Place your left ring finger on %s"),
N_("Swipe your left ring finger across the fingerprint reader"),
N_("Swipe your left ring finger across %s") },
{ "left-little-finger",
N_("Place your left little finger on the fingerprint reader"),
N_("Place your left little finger on %s"),
N_("Swipe your left little finger across the fingerprint reader"),
N_("Swipe your left little finger across %s") },
{ "right-thumb",
N_("Place your right thumb on the fingerprint reader"),
N_("Place your right thumb on %s"),
N_("Swipe your right thumb across the fingerprint reader"),
N_("Swipe your right thumb across %s") },
{ "right-index-finger",
N_("Place your right index finger on the fingerprint reader"),
N_("Place your right index finger on %s"),
N_("Swipe your right index finger across the fingerprint reader"),
N_("Swipe your right index finger across %s") },
{ "right-middle-finger",
N_("Place your right middle finger on the fingerprint reader"),
N_("Place your right middle finger on %s"),
N_("Swipe your right middle finger across the fingerprint reader"),
N_("Swipe your right middle finger across %s") },
{ "right-ring-finger",
N_("Place your right ring finger on the fingerprint reader"),
N_("Place your right ring finger on %s"),
N_("Swipe your right ring finger across the fingerprint reader"),
N_("Swipe your right ring finger across %s") },
{ "right-little-finger",
N_("Place your right little finger on the fingerprint reader"),
N_("Place your right little finger on %s"),
N_("Swipe your right little finger across the fingerprint reader"),
N_("Swipe your right little finger across %s") },
{ NULL, NULL, NULL, NULL, NULL }
{ "any",
N_("Place your finger on the fingerprint reader"),
N_("Place your finger on %s"),
N_("Swipe your finger across the fingerprint reader"),
N_("Swipe your finger across %s") },
{ "left-thumb",
N_("Place your left thumb on the fingerprint reader"),
N_("Place your left thumb on %s"),
N_("Swipe your left thumb across the fingerprint reader"),
N_("Swipe your left thumb across %s") },
{ "left-index-finger",
N_("Place your left index finger on the fingerprint reader"),
N_("Place your left index finger on %s"),
N_("Swipe your left index finger across the fingerprint reader"),
N_("Swipe your left index finger across %s") },
{ "left-middle-finger",
N_("Place your left middle finger on the fingerprint reader"),
N_("Place your left middle finger on %s"),
N_("Swipe your left middle finger across the fingerprint reader"),
N_("Swipe your left middle finger across %s") },
{ "left-ring-finger",
N_("Place your left ring finger on the fingerprint reader"),
N_("Place your left ring finger on %s"),
N_("Swipe your left ring finger across the fingerprint reader"),
N_("Swipe your left ring finger across %s") },
{ "left-little-finger",
N_("Place your left little finger on the fingerprint reader"),
N_("Place your left little finger on %s"),
N_("Swipe your left little finger across the fingerprint reader"),
N_("Swipe your left little finger across %s") },
{ "right-thumb",
N_("Place your right thumb on the fingerprint reader"),
N_("Place your right thumb on %s"),
N_("Swipe your right thumb across the fingerprint reader"),
N_("Swipe your right thumb across %s") },
{ "right-index-finger",
N_("Place your right index finger on the fingerprint reader"),
N_("Place your right index finger on %s"),
N_("Swipe your right index finger across the fingerprint reader"),
N_("Swipe your right index finger across %s") },
{ "right-middle-finger",
N_("Place your right middle finger on the fingerprint reader"),
N_("Place your right middle finger on %s"),
N_("Swipe your right middle finger across the fingerprint reader"),
N_("Swipe your right middle finger across %s") },
{ "right-ring-finger",
N_("Place your right ring finger on the fingerprint reader"),
N_("Place your right ring finger on %s"),
N_("Swipe your right ring finger across the fingerprint reader"),
N_("Swipe your right ring finger across %s") },
{ "right-little-finger",
N_("Place your right little finger on the fingerprint reader"),
N_("Place your right little finger on %s"),
N_("Swipe your right little finger across the fingerprint reader"),
N_("Swipe your right little finger across %s") },
{ NULL, NULL, NULL, NULL, NULL }
};
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
GNUC_UNUSED static char *finger_str_to_msg(const char *finger_name, const char *driver_name, bool is_swipe)
GNUC_UNUSED static char *
finger_str_to_msg (const char *finger_name, const char *driver_name, bool is_swipe)
{
int i;
if (finger_name == NULL)
return NULL;
for (i = 0; fingers[i].dbus_name != NULL; i++) {
if (!str_equal (fingers[i].dbus_name, finger_name))
continue;
if (is_swipe == false) {
if (driver_name) {
char *s;
int ret;
ret = asprintf (&s, TR (fingers[i].place_str_specific), driver_name);
return ret >= 0 ? s : NULL;
} else {
return strdup (TR (fingers[i].place_str_generic));
}
} else {
if (driver_name) {
char *s;
int ret;
ret = asprintf (&s, TR (fingers[i].swipe_str_specific), driver_name);
return ret >= 0 ? s : NULL;
} else {
return strdup (TR (fingers[i].swipe_str_generic));
}
}
}
return NULL;
int i;
if (finger_name == NULL)
return NULL;
for (i = 0; fingers[i].dbus_name != NULL; i++)
{
if (!str_equal (fingers[i].dbus_name, finger_name))
continue;
if (is_swipe == false)
{
if (driver_name)
{
char *s;
int ret;
ret = asprintf (&s, TR (fingers[i].place_str_specific), driver_name);
return ret >= 0 ? s : NULL;
}
else
{
return strdup (TR (fingers[i].place_str_generic));
}
}
else
{
if (driver_name)
{
char *s;
int ret;
ret = asprintf (&s, TR (fingers[i].swipe_str_specific), driver_name);
return ret >= 0 ? s : NULL;
}
else
{
return strdup (TR (fingers[i].swipe_str_generic));
}
}
}
return NULL;
}
#pragma GCC diagnostic pop
......@@ -146,25 +159,27 @@ GNUC_UNUSED static char *finger_str_to_msg(const char *finger_name, const char *
* verify-match
* verify-unknown-error
*/
GNUC_UNUSED static const char *verify_result_str_to_msg(const char *result, bool is_swipe)
GNUC_UNUSED static const char *
verify_result_str_to_msg (const char *result, bool is_swipe)
{
if (result == NULL)
return NULL;
if (strcmp (result, "verify-retry-scan") == 0) {
if (is_swipe == false)
return TR (N_("Place your finger on the reader again"));
else
return TR (N_("Swipe your finger again"));
}
if (strcmp (result, "verify-swipe-too-short") == 0)
return TR (N_("Swipe was too short, try again"));
if (strcmp (result, "verify-finger-not-centered") == 0)
return TR (N_("Your finger was not centered, try swiping your finger again"));
if (strcmp (result, "verify-remove-and-retry") == 0)
return TR (N_("Remove your finger, and try swiping your finger again"));
return NULL;
if (result == NULL)
return NULL;
if (strcmp (result, "verify-retry-scan") == 0)
{
if (is_swipe == false)
return TR (N_("Place your finger on the reader again"));
else
return TR (N_("Swipe your finger again"));
}
if (strcmp (result, "verify-swipe-too-short") == 0)
return TR (N_("Swipe was too short, try again"));
if (strcmp (result, "verify-finger-not-centered") == 0)
return TR (N_("Your finger was not centered, try swiping your finger again"));
if (strcmp (result, "verify-remove-and-retry") == 0)
return TR (N_("Remove your finger, and try swiping your finger again"));
return NULL;
}
/* Cases not handled:
......@@ -172,24 +187,25 @@ GNUC_UNUSED static const char *verify_result_str_to_msg(const char *result, bool
* enroll-failed
* enroll-unknown-error
*/
GNUC_UNUSED static const char *enroll_result_str_to_msg(const char *result, bool is_swipe)
GNUC_UNUSED static const char *
enroll_result_str_to_msg (const char *result, bool is_swipe)
{
if (result == NULL)
return NULL;
if (strcmp (result, "enroll-retry-scan") == 0 || strcmp (result, "enroll-stage-passed") == 0) {
if (is_swipe == false)
return TR (N_("Place your finger on the reader again"));
else
return TR (N_("Swipe your finger again"));
}
if (strcmp (result, "enroll-swipe-too-short") == 0)
return TR (N_("Swipe was too short, try again"));
if (strcmp (result, "enroll-finger-not-centered") == 0)
return TR (N_("Your finger was not centered, try swiping your finger again"));
if (strcmp (result, "enroll-remove-and-retry") == 0)
return TR (N_("Remove your finger, and try swiping your finger again"));
return NULL;
if (result == NULL)
return NULL;
if (strcmp (result, "enroll-retry-scan") == 0 || strcmp (result, "enroll-stage-passed") == 0)
{
if (is_swipe == false)
return TR (N_("Place your finger on the reader again"));
else
return TR (N_("Swipe your finger again"));
}
if (strcmp (result, "enroll-swipe-too-short") == 0)
return TR (N_("Swipe was too short, try again"));
if (strcmp (result, "enroll-finger-not-centered") == 0)
return TR (N_("Your finger was not centered, try swiping your finger again"));
if (strcmp (result, "enroll-remove-and-retry") == 0)
return TR (N_("Remove your finger, and try swiping your finger again"));
return NULL;
}
This diff is collapsed.
......@@ -23,35 +23,36 @@
/* Define auto-pointers functions, based on GLib Macros */
#define _CLEANUP_FUNC(func) __attribute__((cleanup(func)))
#define _CLEANUP_FUNC(func) __attribute__((cleanup (func)))
#define _PF_AUTOPTR_FUNC_NAME(TypeName) pf_autoptr_cleanup_##TypeName
#define _PF_AUTOPTR_TYPENAME(TypeName) TypeName##_pf_autoptr
#define _PF_AUTOPTR_FUNC_NAME(TypeName) pf_autoptr_cleanup_ ## TypeName
#define _PF_AUTOPTR_TYPENAME(TypeName) TypeName ## _pf_autoptr
#define PF_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, cleanup) \
typedef TypeName *_PF_AUTOPTR_TYPENAME (TypeName); \
static __attribute__((__unused__)) inline void \
_PF_AUTOPTR_FUNC_NAME (TypeName) (TypeName **_ptr) \
{ if (_ptr) (cleanup) (*_ptr); }
typedef TypeName *_PF_AUTOPTR_TYPENAME (TypeName); \
static __attribute__((__unused__)) inline void \
_PF_AUTOPTR_FUNC_NAME (TypeName) (TypeName **_ptr) \
{ if (_ptr) (cleanup) (*_ptr); }
#define PF_DEFINE_AUTO_CLEAN_FUNC(TypeName, cleanup) \
static __attribute__((__unused__)) inline void \
_PF_AUTOPTR_FUNC_NAME (TypeName) (TypeName *_ptr) \
{ cleanup (_ptr); }
static __attribute__((__unused__)) inline void \
_PF_AUTOPTR_FUNC_NAME (TypeName) (TypeName *_ptr) \
{ cleanup (_ptr); }
static inline void
autoptr_cleanup_generic_free (void *p)
{
void **pp = (void**)p;
void **pp = (void **) p;
free (*pp);
}
#define pf_autofree _CLEANUP_FUNC (autoptr_cleanup_generic_free)
#define pf_autoptr(TypeName) \
_CLEANUP_FUNC (_PF_AUTOPTR_FUNC_NAME (TypeName)) \
_PF_AUTOPTR_TYPENAME (TypeName)
_CLEANUP_FUNC (_PF_AUTOPTR_FUNC_NAME (TypeName)) \
_PF_AUTOPTR_TYPENAME (TypeName)
#define pf_auto(TypeName) \
_CLEANUP_FUNC (_PF_AUTOPTR_FUNC_NAME (TypeName)) TypeName
_CLEANUP_FUNC (_PF_AUTOPTR_FUNC_NAME (TypeName)) TypeName
PF_DEFINE_AUTOPTR_CLEANUP_FUNC (sd_bus, sd_bus_unref)
PF_DEFINE_AUTOPTR_CLEANUP_FUNC (sd_bus_message, sd_bus_message_unref)
......
This diff is collapsed.
......@@ -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;
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]);
}
}
if (storage_path == NULL)
storage_path = g_strdup (FILE_STORAGE_PATH);
return storage_path;
const char *path = NULL;
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]);
}
}
if (storage_path == NULL)
storage_path = g_strdup (FILE_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;
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;
}
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;
}
return 0;
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));
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;
}
//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);