2016-06-23 11:55:46 +02:00
|
|
|
|
/* name-value.h - Parser and writer for a name-value format.
|
2016-04-08 19:21:12 +02:00
|
|
|
|
* Copyright (C) 2016 g10 Code GmbH
|
|
|
|
|
*
|
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
|
*
|
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of either
|
|
|
|
|
*
|
|
|
|
|
* - the GNU Lesser General Public License as published by the Free
|
|
|
|
|
* Software Foundation; either version 3 of the License, or (at
|
|
|
|
|
* your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* or
|
|
|
|
|
*
|
|
|
|
|
* - the GNU General Public License as published by the Free
|
|
|
|
|
* Software Foundation; either version 2 of the License, or (at
|
|
|
|
|
* your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* or both in parallel, as here.
|
|
|
|
|
*
|
|
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2016-11-05 12:02:19 +01:00
|
|
|
|
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
2016-04-08 19:21:12 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2016-06-23 11:55:46 +02:00
|
|
|
|
#ifndef GNUPG_COMMON_NAME_VALUE_H
|
|
|
|
|
#define GNUPG_COMMON_NAME_VALUE_H
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
2016-06-23 12:12:50 +02:00
|
|
|
|
struct name_value_container;
|
|
|
|
|
typedef struct name_value_container *nvc_t;
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
2016-06-23 12:12:50 +02:00
|
|
|
|
struct name_value_entry;
|
|
|
|
|
typedef struct name_value_entry *nve_t;
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Memory management, and dealing with entries. */
|
|
|
|
|
|
2016-06-23 13:17:25 +02:00
|
|
|
|
/* Allocate a name value container structure. */
|
2016-06-23 12:12:50 +02:00
|
|
|
|
nvc_t nvc_new (void);
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
2016-06-23 13:17:25 +02:00
|
|
|
|
/* Allocate a name value container structure for use with the extended
|
|
|
|
|
* private key format. */
|
|
|
|
|
nvc_t nvc_new_private_key (void);
|
|
|
|
|
|
|
|
|
|
/* Release a name value container structure. */
|
2016-06-23 12:12:50 +02:00
|
|
|
|
void nvc_release (nvc_t pk);
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
2023-11-21 08:34:04 +01:00
|
|
|
|
/* Return the modified flag and optionally clear it. */
|
|
|
|
|
int nvc_modified (nvc_t pk, int clear);
|
|
|
|
|
|
2016-04-08 19:21:12 +02:00
|
|
|
|
/* Get the name. */
|
2016-06-23 12:12:50 +02:00
|
|
|
|
char *nve_name (nve_t pke);
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
|
|
|
|
/* Get the value. */
|
2016-06-23 12:12:50 +02:00
|
|
|
|
char *nve_value (nve_t pke);
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Lookup and iteration. */
|
|
|
|
|
|
|
|
|
|
/* Get the first non-comment entry. */
|
2016-06-23 12:12:50 +02:00
|
|
|
|
nve_t nvc_first (nvc_t pk);
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
|
|
|
|
/* Get the first entry with the given name. */
|
2016-06-23 12:12:50 +02:00
|
|
|
|
nve_t nvc_lookup (nvc_t pk, const char *name);
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
|
|
|
|
/* Get the next non-comment entry. */
|
2016-06-23 12:12:50 +02:00
|
|
|
|
nve_t nve_next (nve_t entry);
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
|
|
|
|
/* Get the next entry with the given name. */
|
2016-06-23 12:12:50 +02:00
|
|
|
|
nve_t nve_next_value (nve_t entry, const char *name);
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
2019-05-07 11:01:15 +02:00
|
|
|
|
/* Return the string for the first entry in NVC with NAME or NULL. */
|
|
|
|
|
const char *nvc_get_string (nvc_t nvc, const char *name);
|
|
|
|
|
|
2023-01-24 09:29:04 +01:00
|
|
|
|
/* Return a boolean value (zero or non-zero) for the first entry in
|
|
|
|
|
* NVC with NAME. */
|
2022-08-11 10:55:00 +02:00
|
|
|
|
int nvc_get_boolean (nvc_t nvc, const char *name);
|
|
|
|
|
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Adding and modifying values. */
|
|
|
|
|
|
|
|
|
|
/* Add (NAME, VALUE) to PK. If an entry with NAME already exists, it
|
|
|
|
|
is not updated but the new entry is appended. */
|
2016-06-23 12:12:50 +02:00
|
|
|
|
gpg_error_t nvc_add (nvc_t pk, const char *name, const char *value);
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
|
|
|
|
/* Add (NAME, VALUE) to PK. If an entry with NAME already exists, it
|
|
|
|
|
is updated with VALUE. If multiple entries with NAME exist, the
|
|
|
|
|
first entry is updated. */
|
2016-06-23 12:12:50 +02:00
|
|
|
|
gpg_error_t nvc_set (nvc_t pk, const char *name, const char *value);
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
2023-11-21 08:34:04 +01:00
|
|
|
|
/* Update entry E to VALUE. PK is optional. */
|
|
|
|
|
gpg_error_t nve_set (nvc_t pk, nve_t e, const char *value);
|
2023-05-26 11:56:36 +02:00
|
|
|
|
|
2016-04-08 19:21:12 +02:00
|
|
|
|
/* Delete the given entry from PK. */
|
2016-06-23 12:12:50 +02:00
|
|
|
|
void nvc_delete (nvc_t pk, nve_t pke);
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
2019-05-07 11:01:15 +02:00
|
|
|
|
/* Delete the entries with NAME from PK. */
|
|
|
|
|
void nvc_delete_named (nvc_t pk, const char *name);
|
|
|
|
|
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Private key handling. */
|
|
|
|
|
|
|
|
|
|
/* Get the private key. */
|
2016-06-23 12:12:50 +02:00
|
|
|
|
gpg_error_t nvc_get_private_key (nvc_t pk, gcry_sexp_t *retsexp);
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
|
|
|
|
/* Set the private key. */
|
2016-06-23 12:12:50 +02:00
|
|
|
|
gpg_error_t nvc_set_private_key (nvc_t pk, gcry_sexp_t sexp);
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Parsing and serialization. */
|
|
|
|
|
|
2018-06-21 12:56:40 +02:00
|
|
|
|
/* Parse STREAM and return a newly allocated name-value container
|
2016-04-08 19:21:12 +02:00
|
|
|
|
structure in RESULT. If ERRLINEP is given, the line number the
|
|
|
|
|
parser was last considering is stored there. */
|
2016-06-23 12:12:50 +02:00
|
|
|
|
gpg_error_t nvc_parse (nvc_t *result, int *errlinep, estream_t stream);
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
2016-06-23 13:17:25 +02:00
|
|
|
|
/* Parse STREAM and return a newly allocated name value container
|
|
|
|
|
structure in RESULT - assuming the extended private key format. If
|
|
|
|
|
ERRLINEP is given, the line number the parser was last considering
|
|
|
|
|
is stored there. */
|
|
|
|
|
gpg_error_t nvc_parse_private_key (nvc_t *result, int *errlinep,
|
|
|
|
|
estream_t stream);
|
|
|
|
|
|
2016-04-08 19:21:12 +02:00
|
|
|
|
/* Write a representation of PK to STREAM. */
|
2016-06-23 12:12:50 +02:00
|
|
|
|
gpg_error_t nvc_write (nvc_t pk, estream_t stream);
|
2016-04-08 19:21:12 +02:00
|
|
|
|
|
2016-06-23 11:55:46 +02:00
|
|
|
|
#endif /* GNUPG_COMMON_NAME_VALUE_H */
|