4 Copyright (C) 2002 Niels Möller
6 This file is part of GNU Nettle.
8 GNU Nettle is free software: you can redistribute it and/or
9 modify it under the terms of either:
11 * the GNU Lesser General Public License as published by the Free
12 Software Foundation; either version 3 of the License, or (at your
13 option) any later version.
17 * the GNU General Public License as published by the Free
18 Software Foundation; either version 2 of the License, or (at your
19 option) any later version.
21 or both in parallel, as here.
23 GNU Nettle is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 General Public License for more details.
28 You should have received copies of the GNU General Public License and
29 the GNU Lesser General Public License along with this program. If
30 not, see http://www.gnu.org/licenses/.
33 #ifndef NETTLE_SEXP_H_INCLUDED
34 #define NETTLE_SEXP_H_INCLUDED
37 #include "nettle-types.h"
44 #define sexp_iterator_first nettle_sexp_iterator_first
45 #define sexp_transport_iterator_first nettle_sexp_transport_iterator_first
46 #define sexp_iterator_next nettle_sexp_iterator_next
47 #define sexp_iterator_enter_list nettle_sexp_iterator_enter_list
48 #define sexp_iterator_exit_list nettle_sexp_iterator_exit_list
49 #define sexp_iterator_subexpr nettle_sexp_iterator_subexpr
50 #define sexp_iterator_get_uint32 nettle_sexp_iterator_get_uint32
51 #define sexp_iterator_check_type nettle_sexp_iterator_check_type
52 #define sexp_iterator_check_types nettle_sexp_iterator_check_types
53 #define sexp_iterator_assoc nettle_sexp_iterator_assoc
54 #define sexp_format nettle_sexp_format
55 #define sexp_vformat nettle_sexp_vformat
56 #define sexp_transport_format nettle_sexp_transport_format
57 #define sexp_transport_vformat nettle_sexp_transport_vformat
58 #define sexp_token_chars nettle_sexp_token_chars
61 { SEXP_ATOM, SEXP_LIST, SEXP_END };
66 const uint8_t *buffer;
68 /* Points at the start of the current sub expression. */
70 /* If type is SEXP_LIST, pos points at the start of the current
71 * element. Otherwise, it points at the end. */
77 size_t display_length;
78 const uint8_t *display;
85 /* All these functions return 1 on success, 0 on failure */
87 /* Initializes the iterator. */
89 sexp_iterator_first(struct sexp_iterator *iterator,
90 size_t length, const uint8_t *input);
92 /* NOTE: Decodes the input string in place */
94 sexp_transport_iterator_first(struct sexp_iterator *iterator,
95 size_t length, uint8_t *input);
98 sexp_iterator_next(struct sexp_iterator *iterator);
100 /* Current element must be a list. */
102 sexp_iterator_enter_list(struct sexp_iterator *iterator);
104 /* Skips the rest of the current list */
106 sexp_iterator_exit_list(struct sexp_iterator *iterator);
109 /* Skips out of as many lists as necessary to get back to the given
112 sexp_iterator_exit_lists(struct sexp_iterator *iterator,
116 /* Gets start and length of the current subexpression. Implies
117 * sexp_iterator_next. */
119 sexp_iterator_subexpr(struct sexp_iterator *iterator,
123 sexp_iterator_get_uint32(struct sexp_iterator *iterator,
127 /* Checks the type of the current expression, which should be a list
132 sexp_iterator_check_type(struct sexp_iterator *iterator,
136 sexp_iterator_check_types(struct sexp_iterator *iterator,
138 const char * const *types);
140 /* Current element must be a list. Looks up element of type
144 * For a matching key, the corresponding iterator is initialized
145 * pointing at the start of REST.
147 * On success, exits the current list.
150 sexp_iterator_assoc(struct sexp_iterator *iterator,
152 const char * const *keys,
153 struct sexp_iterator *values);
156 /* Output functions. What is a reasonable API for this? It seems
157 * ugly to have to reimplement string streams. */
159 /* Declared for real in buffer.h */
160 struct nettle_buffer;
162 /* Returns the number of output characters, or 0 on out of memory. If
163 * buffer == NULL, just compute length.
165 * Format strings can contained matched parentheses, tokens ("foo" in
166 * the format string is formatted as "3:foo"), whitespace (which
167 * separates tokens but is otherwise ignored) and the following
168 * formatting specifiers:
170 * %s String represented as size_t length, const uint8_t *data.
172 * %t Optional display type, represented as
173 * size_t display_length, const uint8_t *display,
174 * display == NULL means no display type.
176 * %i Non-negative small integer, uint32_t.
178 * %b Non-negative bignum, mpz_t.
180 * %l Literal string (no length added), typically a balanced
181 * subexpression. Represented as size_t length, const uint8_t
184 * %(, %) Allows insertion of unbalanced parenthesis.
188 * %0 For %s, %t and %l, says that there's no length argument,
189 * instead the string is NUL-terminated, and there's only one
190 * const uint8_t * argument.
194 sexp_format(struct nettle_buffer *buffer,
195 const char *format, ...);
198 sexp_vformat(struct nettle_buffer *buffer,
199 const char *format, va_list args);
202 sexp_transport_format(struct nettle_buffer *buffer,
203 const char *format, ...);
206 sexp_transport_vformat(struct nettle_buffer *buffer,
207 const char *format, va_list args);
213 #endif /* NETTLE_SEXP_H_INCLUDED */