mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: load and save fingerprint to cloud storage
Very similar structure to the XML format. Raw data is again saved as a hex string (which implicitly provides us with its length). The rest of components are in a more human readable format. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
2b1db9da82
commit
31e688ec00
2 changed files with 68 additions and 1 deletions
|
@ -1016,6 +1016,59 @@ static void parse_settings_divecomputerid(char *line, struct membuffer *str, str
|
|||
create_device_node(state->devices, id.model, id.serial, id.nickname);
|
||||
}
|
||||
|
||||
struct fingerprint_helper {
|
||||
uint32_t model;
|
||||
uint32_t serial;
|
||||
uint32_t fdeviceid;
|
||||
uint32_t fdiveid;
|
||||
const char *hex_data;
|
||||
};
|
||||
|
||||
static void parse_fingerprint_keyvalue(void *_fph, const char *key, const char *value)
|
||||
{
|
||||
struct fingerprint_helper *fph = _fph;
|
||||
|
||||
if (!strcmp(key, "model")) {
|
||||
fph->model = get_hex(value);
|
||||
return;
|
||||
}
|
||||
if (!strcmp(key, "serial")) {
|
||||
fph->serial = get_hex(value);
|
||||
return;
|
||||
}
|
||||
if (!strcmp(key, "deviceid")) {
|
||||
fph->fdeviceid = get_hex(value);
|
||||
return;
|
||||
}
|
||||
if (!strcmp(key, "diveid")) {
|
||||
fph->fdiveid = get_hex(value);
|
||||
return;
|
||||
}
|
||||
if (!strcmp(key, "data")) {
|
||||
fph->hex_data = value;
|
||||
return;
|
||||
}
|
||||
report_error("Unknown fingerprint key/value pair (%s/%s)", key, value);
|
||||
}
|
||||
|
||||
|
||||
static void parse_settings_fingerprint(char *line, struct membuffer *str, struct git_parser_state *state)
|
||||
{
|
||||
struct fingerprint_helper fph = { 0, 0, 0, 0 };
|
||||
for (;;) {
|
||||
char c;
|
||||
while (isspace(c = *line))
|
||||
line++;
|
||||
if (!c)
|
||||
break;
|
||||
line = parse_keyvalue_entry(parse_fingerprint_keyvalue, &fph, line, str);
|
||||
}
|
||||
if (verbose > 1)
|
||||
SSRF_INFO("fingerprint %08x %08x %08x %08x %s\n", fph.model, fph.serial, fph.fdeviceid, fph.fdiveid, fph.hex_data);
|
||||
create_fingerprint_node_from_hex(&fingerprint_table, fph.model, fph.serial,
|
||||
fph.hex_data, fph.fdeviceid, fph.fdiveid);
|
||||
}
|
||||
|
||||
static void parse_picture_filename(char *line, struct membuffer *str, struct git_parser_state *state)
|
||||
{
|
||||
UNUSED(line);
|
||||
|
@ -1098,7 +1151,7 @@ static void trip_parser(char *line, struct membuffer *str, struct git_parser_sta
|
|||
static struct keyword_action settings_action[] = {
|
||||
#undef D
|
||||
#define D(x) { #x, parse_settings_ ## x }
|
||||
D(autogroup), D(divecomputerid), D(prefs), D(subsurface), D(units), D(userid), D(version)
|
||||
D(autogroup), D(divecomputerid), D(fingerprint), D(prefs), D(subsurface), D(units), D(userid), D(version)
|
||||
};
|
||||
|
||||
static void settings_parser(char *line, struct membuffer *str, struct git_parser_state *state)
|
||||
|
|
|
@ -869,6 +869,16 @@ static void save_one_device(struct membuffer *b, const struct device *d)
|
|||
put_string(b, "\n");
|
||||
}
|
||||
|
||||
static void save_one_fingerprint(struct membuffer *b, unsigned int i)
|
||||
{
|
||||
put_format(b, "fingerprint model=%08x serial=%08x deviceid=%08x diveid=%08x data=\"%s\"\n",
|
||||
fp_get_model(&fingerprint_table, i),
|
||||
fp_get_serial(&fingerprint_table, i),
|
||||
fp_get_deviceid(&fingerprint_table, i),
|
||||
fp_get_diveid(&fingerprint_table, i),
|
||||
fp_get_data(&fingerprint_table, i));
|
||||
}
|
||||
|
||||
static void save_settings(git_repository *repo, struct dir *tree)
|
||||
{
|
||||
struct membuffer b = { 0 };
|
||||
|
@ -876,6 +886,10 @@ static void save_settings(git_repository *repo, struct dir *tree)
|
|||
put_format(&b, "version %d\n", DATAFORMAT_VERSION);
|
||||
for (int i = 0; i < nr_devices(&device_table); i++)
|
||||
save_one_device(&b, get_device(&device_table, i));
|
||||
/* save the fingerprint data */
|
||||
for (unsigned int i = 0; i < nr_fingerprints(&fingerprint_table); i++)
|
||||
save_one_fingerprint(&b, i);
|
||||
|
||||
cond_put_format(autogroup, &b, "autogroup\n");
|
||||
save_units(&b);
|
||||
if (prefs.tankbar)
|
||||
|
|
Loading…
Add table
Reference in a new issue