mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-15 07:00:05 -05:00
pipewire: add pw_properties_add_string()
Equivalent to the existing pw_properties_update_string() but only adds new properties from the given string, it doesn't overwrite existing ones.
This commit is contained in:
parent
81cc466752
commit
b179e81070
2 changed files with 48 additions and 3 deletions
|
|
@ -146,8 +146,7 @@ struct pw_properties *pw_properties_new_dict(const struct spa_dict *dict)
|
|||
return &impl->this;
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
int pw_properties_update_string(struct pw_properties *props, const char *str, size_t size)
|
||||
static int update_from_string(struct pw_properties *props, const char *str, size_t size, bool overwrite)
|
||||
{
|
||||
struct properties *impl = SPA_CONTAINER_OF(props, struct properties, this);
|
||||
struct spa_json it[2];
|
||||
|
|
@ -176,12 +175,42 @@ int pw_properties_update_string(struct pw_properties *props, const char *str, si
|
|||
if ((val = malloc(len+1)) != NULL)
|
||||
spa_json_parse_string(value, len, val);
|
||||
}
|
||||
count += pw_properties_set(&impl->this, key, val);
|
||||
if (overwrite || pw_properties_get(&impl->this, key) == NULL)
|
||||
count += pw_properties_set(&impl->this, key, val);
|
||||
free(val);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the properties from the given string, adding any new
|
||||
* keys from \a str but leaving existing keys in \a props unmodified.
|
||||
*
|
||||
* \a str should be a whitespace separated list of key=value
|
||||
* strings or a json object, see pw_properties_new_string().
|
||||
*
|
||||
* \return The number of properties added
|
||||
*/
|
||||
SPA_EXPORT
|
||||
int pw_properties_add_string(struct pw_properties *props, const char *str, size_t size)
|
||||
{
|
||||
return update_from_string(props, str, size, false);
|
||||
}
|
||||
|
||||
/** Update the properties from the given string, overwriting any
|
||||
* existing keys with the new values from \a str.
|
||||
*
|
||||
* \a str should be a whitespace separated list of key=value
|
||||
* strings or a json object, see pw_properties_new_string().
|
||||
*
|
||||
* \return The number of properties added or updated
|
||||
*/
|
||||
SPA_EXPORT
|
||||
int pw_properties_update_string(struct pw_properties *props, const char *str, size_t size)
|
||||
{
|
||||
return update_from_string(props, str, size, true);
|
||||
}
|
||||
|
||||
/** Make a new properties object from the given str
|
||||
*
|
||||
* \a object should be a whitespace separated list of key=value
|
||||
|
|
|
|||
|
|
@ -70,8 +70,24 @@ int pw_properties_update_ignore(struct pw_properties *props,
|
|||
|
||||
int pw_properties_update(struct pw_properties *oldprops,
|
||||
const struct spa_dict *dict);
|
||||
/**
|
||||
* Update the properties from the given string updating \a props to
|
||||
* - all key/value pairs from \a str
|
||||
* - all key/value pairs from \a props that were not given in \a str
|
||||
*
|
||||
* \return The number of properties added or updated
|
||||
*/
|
||||
int pw_properties_update_string(struct pw_properties *props,
|
||||
const char *str, size_t size);
|
||||
/**
|
||||
* Update the properties from the given string updating \a props to
|
||||
* - all key/value pairs from \a props
|
||||
* - all key/value pairs from \a str that were not given in \a str
|
||||
*
|
||||
* \return The number of properties added
|
||||
*/
|
||||
int pw_properties_add_string(struct pw_properties *props,
|
||||
const char *str, size_t size);
|
||||
|
||||
int pw_properties_add(struct pw_properties *oldprops,
|
||||
const struct spa_dict *dict);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue