The upcoming "factory settings" feature will need to read and write entries using the raw database key, because the key comes from a configuration file that does not have the "basekeyname" and the port name separated. --- src/modules/module-device-restore.c | 60 +++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/src/modules/module-device-restore.c b/src/modules/module-device-restore.c index 05b7301..e334ff6 100644 --- a/src/modules/module-device-restore.c +++ b/src/modules/module-device-restore.c @@ -355,21 +355,18 @@ static void perportentry_free(struct perportentry* e) { pa_xfree(e); } -static pa_bool_t perportentry_write(struct userdata *u, const char *basekeyname, const char *port, const struct perportentry *e) { +static bool perportentry_write_raw_name(struct userdata *u, const char *name, const struct perportentry *e) { pa_tagstruct *t; pa_datum key, data; - pa_bool_t r; + bool r; uint32_t i; pa_format_info *f; uint8_t n_formats; - char *name; pa_assert(u); - pa_assert(basekeyname); + pa_assert(name); pa_assert(e); - name = pa_sprintf_malloc("%s:%s", basekeyname, (port ? port : "null")); - n_formats = pa_idxset_size(e->formats); t = pa_tagstruct_new(NULL, 0); @@ -390,27 +387,38 @@ static pa_bool_t perportentry_write(struct userdata *u, const char *basekeyname, data.data = (void*)pa_tagstruct_data(t, &data.size); - r = (pa_database_set(u->database, &key, &data, TRUE) == 0); + r = (pa_database_set(u->database, &key, &data, true) == 0); pa_tagstruct_free(t); + + return r; +} + +static bool perportentry_write(struct userdata *u, const char *basekeyname, const char *port, const struct perportentry *e) { + bool r; + char *name; + + pa_assert(u); + pa_assert(basekeyname); + pa_assert(e); + + name = pa_sprintf_malloc("%s:%s", basekeyname, (port ? port : "null")); + r = perportentry_write_raw_name(u, name, e); pa_xfree(name); return r; } -static struct perportentry* perportentry_read(struct userdata *u, const char *basekeyname, const char *port) { +static struct perportentry *perportentry_read_raw_name(struct userdata *u, const char *name) { pa_datum key, data; struct perportentry *e = NULL; pa_tagstruct *t = NULL; uint8_t i, n_formats; - char *name; pa_assert(u); - pa_assert(basekeyname); - - name = pa_sprintf_malloc("%s:%s", basekeyname, (port ? port : "null")); + pa_assert(name); - key.data = name; + key.data = (char *) name; key.size = strlen(name); pa_zero(data); @@ -457,7 +465,6 @@ static struct perportentry* perportentry_read(struct userdata *u, const char *ba pa_tagstruct_free(t); pa_datum_free(&data); - pa_xfree(name); return e; @@ -470,18 +477,29 @@ fail: pa_datum_free(&data); + return NULL; +} + +static struct perportentry* perportentry_read(struct userdata *u, const char *basekeyname, const char *port) { + struct perportentry *e = NULL; + char *name; + + pa_assert(u); + pa_assert(basekeyname); + + name = pa_sprintf_malloc("%s:%s", basekeyname, (port ? port : "null")); + e = perportentry_read_raw_name(u, name); + pa_xfree(name); + + if (e) + return e; + #ifdef ENABLE_LEGACY_DATABASE_ENTRY_FORMAT /* Try again with a null port. This is used when dealing with migration from older versions */ - if (port) { - pa_xfree(name); + if (port) return perportentry_read(u, basekeyname, NULL); - } #endif - pa_log_debug("Database contains invalid data for key: %s", name); - - pa_xfree(name); - return NULL; } -- 1.7.10.4