mirror of
git://git.gnupg.org/gnupg.git
synced 2025-03-28 22:49:59 +01:00
common: New function nve_set.
* common/name-value.c (nve_set): New. (nvc_set): Use nve_set. (nvc_delete_named): New. (nvc_get_string): New. (nvc_get_boolean): New. -- This function is required to allow updating a specific line. The other new functions are backported from master
This commit is contained in:
parent
f2a81e3745
commit
706adf6691
@ -476,27 +476,36 @@ nvc_set (nvc_t pk, const char *name, const char *value)
|
|||||||
|
|
||||||
e = nvc_lookup (pk, name);
|
e = nvc_lookup (pk, name);
|
||||||
if (e)
|
if (e)
|
||||||
{
|
return nve_set (e, value);
|
||||||
char *v;
|
|
||||||
|
|
||||||
v = xtrystrdup (value);
|
|
||||||
if (v == NULL)
|
|
||||||
return my_error_from_syserror ();
|
|
||||||
|
|
||||||
free_strlist_wipe (e->raw_value);
|
|
||||||
e->raw_value = NULL;
|
|
||||||
if (e->value)
|
|
||||||
wipememory (e->value, strlen (e->value));
|
|
||||||
xfree (e->value);
|
|
||||||
e->value = v;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
return nvc_add (pk, name, value);
|
return nvc_add (pk, name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Update entry E to VALUE. */
|
||||||
|
gpg_error_t
|
||||||
|
nve_set (nve_t e, const char *value)
|
||||||
|
{
|
||||||
|
char *v;
|
||||||
|
|
||||||
|
if (!e)
|
||||||
|
return GPG_ERR_INV_ARG;
|
||||||
|
|
||||||
|
v = xtrystrdup (value? value:"");
|
||||||
|
if (!v)
|
||||||
|
return my_error_from_syserror ();
|
||||||
|
|
||||||
|
free_strlist_wipe (e->raw_value);
|
||||||
|
e->raw_value = NULL;
|
||||||
|
if (e->value)
|
||||||
|
wipememory (e->value, strlen (e->value));
|
||||||
|
xfree (e->value);
|
||||||
|
e->value = v;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Delete the given entry from PK. */
|
/* Delete the given entry from PK. */
|
||||||
void
|
void
|
||||||
nvc_delete (nvc_t pk, nve_t entry)
|
nvc_delete (nvc_t pk, nve_t entry)
|
||||||
@ -514,6 +523,20 @@ nvc_delete (nvc_t pk, nve_t entry)
|
|||||||
nve_release (entry, pk->private_key_mode);
|
nve_release (entry, pk->private_key_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Delete the entries with NAME from PK. */
|
||||||
|
void
|
||||||
|
nvc_delete_named (nvc_t pk, const char *name)
|
||||||
|
{
|
||||||
|
nve_t e;
|
||||||
|
|
||||||
|
if (!valid_name (name))
|
||||||
|
return;
|
||||||
|
|
||||||
|
while ((e = nvc_lookup (pk, name)))
|
||||||
|
nvc_delete (pk, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Lookup and iteration. */
|
/* Lookup and iteration. */
|
||||||
@ -563,6 +586,46 @@ nve_next_value (nve_t entry, const char *name)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Return the string for the first entry in NVC with NAME. If an
|
||||||
|
* entry with NAME is missing in NVC or its value is the empty string
|
||||||
|
* NULL is returned. Note that the returned string is a pointer
|
||||||
|
* into NVC. */
|
||||||
|
const char *
|
||||||
|
nvc_get_string (nvc_t nvc, const char *name)
|
||||||
|
{
|
||||||
|
nve_t item;
|
||||||
|
|
||||||
|
if (!nvc)
|
||||||
|
return NULL;
|
||||||
|
item = nvc_lookup (nvc, name);
|
||||||
|
if (!item)
|
||||||
|
return NULL;
|
||||||
|
return nve_value (item);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Return true if NAME exists and its value is true; that is either
|
||||||
|
* "yes", "true", or a decimal value unequal to 0. */
|
||||||
|
int
|
||||||
|
nvc_get_boolean (nvc_t nvc, const char *name)
|
||||||
|
{
|
||||||
|
nve_t item;
|
||||||
|
const char *s;
|
||||||
|
|
||||||
|
if (!nvc)
|
||||||
|
return 0;
|
||||||
|
item = nvc_lookup (nvc, name);
|
||||||
|
if (!item)
|
||||||
|
return 0;
|
||||||
|
s = nve_value (item);
|
||||||
|
if (s && (atoi (s)
|
||||||
|
|| !ascii_strcasecmp (s, "yes")
|
||||||
|
|| !ascii_strcasecmp (s, "true")))
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Private key handling. */
|
/* Private key handling. */
|
||||||
|
@ -72,6 +72,12 @@ nve_t nve_next (nve_t entry);
|
|||||||
/* Get the next entry with the given name. */
|
/* Get the next entry with the given name. */
|
||||||
nve_t nve_next_value (nve_t entry, const char *name);
|
nve_t nve_next_value (nve_t entry, const char *name);
|
||||||
|
|
||||||
|
/* Return the string for the first entry in NVC with NAME or NULL. */
|
||||||
|
const char *nvc_get_string (nvc_t nvc, const char *name);
|
||||||
|
|
||||||
|
/* Return a boolean value for the first entry in NVC with NAME. */
|
||||||
|
int nvc_get_boolean (nvc_t nvc, const char *name);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Adding and modifying values. */
|
/* Adding and modifying values. */
|
||||||
@ -85,9 +91,15 @@ gpg_error_t nvc_add (nvc_t pk, const char *name, const char *value);
|
|||||||
first entry is updated. */
|
first entry is updated. */
|
||||||
gpg_error_t nvc_set (nvc_t pk, const char *name, const char *value);
|
gpg_error_t nvc_set (nvc_t pk, const char *name, const char *value);
|
||||||
|
|
||||||
|
/* Update entry E to VALUE. */
|
||||||
|
gpg_error_t nve_set (nve_t e, const char *value);
|
||||||
|
|
||||||
/* Delete the given entry from PK. */
|
/* Delete the given entry from PK. */
|
||||||
void nvc_delete (nvc_t pk, nve_t pke);
|
void nvc_delete (nvc_t pk, nve_t pke);
|
||||||
|
|
||||||
|
/* Delete the entries with NAME from PK. */
|
||||||
|
void nvc_delete_named (nvc_t pk, const char *name);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Private key handling. */
|
/* Private key handling. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user