libfprint/fpi-log.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * FpiLog - Internal logging functions | ||
| 3 | * Copyright (C) 2020 Benjamin Berg <bberg@redhat.com> | ||
| 4 | * Copyright (C) 2025 Joshua Grisham <josh@joshuagrisham.com> | ||
| 5 | * Copyright (C) 2026 Marco Trevisan (TreviƱo) <mail@3v1n0.net> | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include "fpi-log.h" | ||
| 23 | |||
| 24 | /** | ||
| 25 | * fpi_log_is_debug_transfer_enabled: | ||
| 26 | * | ||
| 27 | * Checks if the %FP_DEBUG_TRANSFER environment variable is set. | ||
| 28 | * | ||
| 29 | * Returns: %TRUE if %FP_DEBUG_TRANSFER is set, %FALSE otherwise | ||
| 30 | */ | ||
| 31 | gboolean | ||
| 32 | 57000 | fpi_log_is_debug_transfer_enabled (void) | |
| 33 | { | ||
| 34 | 57000 | static gsize debug_transfer_enabled = 0; | |
| 35 | |||
| 36 |
3/4✓ Branch 2 → 3 taken 30 times.
✓ Branch 2 → 9 taken 56970 times.
✓ Branch 4 → 5 taken 30 times.
✗ Branch 4 → 9 not taken.
|
57000 | if (g_once_init_enter (&debug_transfer_enabled)) |
| 37 | { | ||
| 38 |
1/2✓ Branch 6 → 7 taken 30 times.
✗ Branch 6 → 8 not taken.
|
30 | gsize enabled = g_getenv ("FP_DEBUG_TRANSFER") != NULL ? TRUE : G_MAXSIZE; |
| 39 | 30 | g_once_init_leave (&debug_transfer_enabled, enabled); | |
| 40 | } | ||
| 41 | |||
| 42 | 57000 | return debug_transfer_enabled == TRUE; | |
| 43 | } | ||
| 44 | |||
| 45 | /** | ||
| 46 | * fpi_dbg_hex_dump_data: | ||
| 47 | * @buf: Bytes buffer to dump | ||
| 48 | * @len: Length of @buf to dump | ||
| 49 | * | ||
| 50 | * Prints hex dump of @buf to fp_dbg() | ||
| 51 | */ | ||
| 52 | void | ||
| 53 | ✗ | (fpi_dbg_hex_dump_data) (const gchar *log_domain, | |
| 54 | const guint8 *buf, | ||
| 55 | gsize len) | ||
| 56 | { | ||
| 57 | ✗ | g_autoptr(GString) line = NULL; | |
| 58 | |||
| 59 | ✗ | if (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, log_domain)) | |
| 60 | return; | ||
| 61 | |||
| 62 | ✗ | if (G_UNLIKELY (len == 0 || !buf)) | |
| 63 | return; | ||
| 64 | |||
| 65 | ✗ | line = g_string_new (""); | |
| 66 | |||
| 67 | ✗ | for (gint i = 0; i < len; i++) | |
| 68 | ✗ | g_string_append_printf (line, "%02x", buf[i]); | |
| 69 | |||
| 70 | ✗ | if (line->len) | |
| 71 | ✗ | g_log (log_domain, G_LOG_LEVEL_DEBUG, "%s", line->str); | |
| 72 | } | ||
| 73 | |||
| 74 | /** | ||
| 75 | * fpi_dbg_hex_dump_bytes: | ||
| 76 | * @bytes: #GBytes to dump | ||
| 77 | * | ||
| 78 | * Prints hex dump of @bytes to fp_dbg() | ||
| 79 | */ | ||
| 80 | void | ||
| 81 | ✗ | (fpi_dbg_hex_dump_bytes) (const gchar *log_domain, | |
| 82 | GBytes *bytes) | ||
| 83 | { | ||
| 84 | ✗ | gsize length = 0; | |
| 85 | ✗ | const guint8 *data = g_bytes_get_data (bytes, &length); | |
| 86 | |||
| 87 | ✗ | (fpi_dbg_hex_dump_data) (log_domain, data, length); | |
| 88 | ✗ | } | |
| 89 |