1 /* extension.h -- generated by Trunnel v1.5.3.
2 * https://gitweb.torproject.org/trunnel.git
3 * You probably shouldn't edit this file.
5 #ifndef TRUNNEL_EXTENSION_H
6 #define TRUNNEL_EXTENSION_H
11 #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_EXTENSION_FIELD)
12 struct trn_extension_field_st
{
15 TRUNNEL_DYNARRAY_HEAD(, uint8_t) field
;
16 uint8_t trunnel_error_code_
;
19 typedef struct trn_extension_field_st trn_extension_field_t
;
20 #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_EXTENSION)
21 struct trn_extension_st
{
23 TRUNNEL_DYNARRAY_HEAD(, struct trn_extension_field_st
*) fields
;
24 uint8_t trunnel_error_code_
;
27 typedef struct trn_extension_st trn_extension_t
;
28 /** Return a newly allocated trn_extension_field with all elements set
31 trn_extension_field_t
*trn_extension_field_new(void);
32 /** Release all storage held by the trn_extension_field in 'victim'.
33 * (Do nothing if 'victim' is NULL.)
35 void trn_extension_field_free(trn_extension_field_t
*victim
);
36 /** Try to parse a trn_extension_field from the buffer in 'input',
37 * using up to 'len_in' bytes from the input buffer. On success,
38 * return the number of bytes consumed and set *output to the newly
39 * allocated trn_extension_field_t. On failure, return -2 if the input
40 * appears truncated, and -1 if the input is otherwise invalid.
42 ssize_t
trn_extension_field_parse(trn_extension_field_t
**output
, const uint8_t *input
, const size_t len_in
);
43 /** Return the number of bytes we expect to need to encode the
44 * trn_extension_field in 'obj'. On failure, return a negative value.
45 * Note that this value may be an overestimate, and can even be an
46 * underestimate for certain unencodeable objects.
48 ssize_t
trn_extension_field_encoded_len(const trn_extension_field_t
*obj
);
49 /** Try to encode the trn_extension_field from 'input' into the buffer
50 * at 'output', using up to 'avail' bytes of the output buffer. On
51 * success, return the number of bytes used. On failure, return -2 if
52 * the buffer was not long enough, and -1 if the input was invalid.
54 ssize_t
trn_extension_field_encode(uint8_t *output
, size_t avail
, const trn_extension_field_t
*input
);
55 /** Check whether the internal state of the trn_extension_field in
56 * 'obj' is consistent. Return NULL if it is, and a short message if
59 const char *trn_extension_field_check(const trn_extension_field_t
*obj
);
60 /** Clear any errors that were set on the object 'obj' by its setter
61 * functions. Return true iff errors were cleared.
63 int trn_extension_field_clear_errors(trn_extension_field_t
*obj
);
64 /** Return the value of the field_type field of the
65 * trn_extension_field_t in 'inp'
67 uint8_t trn_extension_field_get_field_type(const trn_extension_field_t
*inp
);
68 /** Set the value of the field_type field of the trn_extension_field_t
69 * in 'inp' to 'val'. Return 0 on success; return -1 and set the error
70 * code on 'inp' on failure.
72 int trn_extension_field_set_field_type(trn_extension_field_t
*inp
, uint8_t val
);
73 /** Return the value of the field_len field of the
74 * trn_extension_field_t in 'inp'
76 uint8_t trn_extension_field_get_field_len(const trn_extension_field_t
*inp
);
77 /** Set the value of the field_len field of the trn_extension_field_t
78 * in 'inp' to 'val'. Return 0 on success; return -1 and set the error
79 * code on 'inp' on failure.
81 int trn_extension_field_set_field_len(trn_extension_field_t
*inp
, uint8_t val
);
82 /** Return the length of the dynamic array holding the field field of
83 * the trn_extension_field_t in 'inp'.
85 size_t trn_extension_field_getlen_field(const trn_extension_field_t
*inp
);
86 /** Return the element at position 'idx' of the dynamic array field
87 * field of the trn_extension_field_t in 'inp'.
89 uint8_t trn_extension_field_get_field(trn_extension_field_t
*inp
, size_t idx
);
90 /** As trn_extension_field_get_field, but take and return a const
93 uint8_t trn_extension_field_getconst_field(const trn_extension_field_t
*inp
, size_t idx
);
94 /** Change the element at position 'idx' of the dynamic array field
95 * field of the trn_extension_field_t in 'inp', so that it will hold
98 int trn_extension_field_set_field(trn_extension_field_t
*inp
, size_t idx
, uint8_t elt
);
99 /** Append a new element 'elt' to the dynamic array field field of the
100 * trn_extension_field_t in 'inp'.
102 int trn_extension_field_add_field(trn_extension_field_t
*inp
, uint8_t elt
);
103 /** Return a pointer to the variable-length array field field of
106 uint8_t * trn_extension_field_getarray_field(trn_extension_field_t
*inp
);
107 /** As trn_extension_field_get_field, but take and return a const
110 const uint8_t * trn_extension_field_getconstarray_field(const trn_extension_field_t
*inp
);
111 /** Change the length of the variable-length array field field of
112 * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success;
113 * return -1 and set the error code on 'inp' on failure.
115 int trn_extension_field_setlen_field(trn_extension_field_t
*inp
, size_t newlen
);
116 /** Return a newly allocated trn_extension with all elements set to
119 trn_extension_t
*trn_extension_new(void);
120 /** Release all storage held by the trn_extension in 'victim'. (Do
121 * nothing if 'victim' is NULL.)
123 void trn_extension_free(trn_extension_t
*victim
);
124 /** Try to parse a trn_extension from the buffer in 'input', using up
125 * to 'len_in' bytes from the input buffer. On success, return the
126 * number of bytes consumed and set *output to the newly allocated
127 * trn_extension_t. On failure, return -2 if the input appears
128 * truncated, and -1 if the input is otherwise invalid.
130 ssize_t
trn_extension_parse(trn_extension_t
**output
, const uint8_t *input
, const size_t len_in
);
131 /** Return the number of bytes we expect to need to encode the
132 * trn_extension in 'obj'. On failure, return a negative value. Note
133 * that this value may be an overestimate, and can even be an
134 * underestimate for certain unencodeable objects.
136 ssize_t
trn_extension_encoded_len(const trn_extension_t
*obj
);
137 /** Try to encode the trn_extension from 'input' into the buffer at
138 * 'output', using up to 'avail' bytes of the output buffer. On
139 * success, return the number of bytes used. On failure, return -2 if
140 * the buffer was not long enough, and -1 if the input was invalid.
142 ssize_t
trn_extension_encode(uint8_t *output
, size_t avail
, const trn_extension_t
*input
);
143 /** Check whether the internal state of the trn_extension in 'obj' is
144 * consistent. Return NULL if it is, and a short message if it is not.
146 const char *trn_extension_check(const trn_extension_t
*obj
);
147 /** Clear any errors that were set on the object 'obj' by its setter
148 * functions. Return true iff errors were cleared.
150 int trn_extension_clear_errors(trn_extension_t
*obj
);
151 /** Return the value of the num field of the trn_extension_t in 'inp'
153 uint8_t trn_extension_get_num(const trn_extension_t
*inp
);
154 /** Set the value of the num field of the trn_extension_t in 'inp' to
155 * 'val'. Return 0 on success; return -1 and set the error code on
158 int trn_extension_set_num(trn_extension_t
*inp
, uint8_t val
);
159 /** Return the length of the dynamic array holding the fields field of
160 * the trn_extension_t in 'inp'.
162 size_t trn_extension_getlen_fields(const trn_extension_t
*inp
);
163 /** Return the element at position 'idx' of the dynamic array field
164 * fields of the trn_extension_t in 'inp'.
166 struct trn_extension_field_st
* trn_extension_get_fields(trn_extension_t
*inp
, size_t idx
);
167 /** As trn_extension_get_fields, but take and return a const pointer
169 const struct trn_extension_field_st
* trn_extension_getconst_fields(const trn_extension_t
*inp
, size_t idx
);
170 /** Change the element at position 'idx' of the dynamic array field
171 * fields of the trn_extension_t in 'inp', so that it will hold the
172 * value 'elt'. Free the previous value, if any.
174 int trn_extension_set_fields(trn_extension_t
*inp
, size_t idx
, struct trn_extension_field_st
* elt
);
175 /** As trn_extension_set_fields, but does not free the previous value.
177 int trn_extension_set0_fields(trn_extension_t
*inp
, size_t idx
, struct trn_extension_field_st
* elt
);
178 /** Append a new element 'elt' to the dynamic array field fields of
179 * the trn_extension_t in 'inp'.
181 int trn_extension_add_fields(trn_extension_t
*inp
, struct trn_extension_field_st
* elt
);
182 /** Return a pointer to the variable-length array field fields of
185 struct trn_extension_field_st
* * trn_extension_getarray_fields(trn_extension_t
*inp
);
186 /** As trn_extension_get_fields, but take and return a const pointer
188 const struct trn_extension_field_st
* const * trn_extension_getconstarray_fields(const trn_extension_t
*inp
);
189 /** Change the length of the variable-length array field fields of
190 * 'inp' to 'newlen'.Fill extra elements with NULL; free removed
191 * elements. Return 0 on success; return -1 and set the error code on
194 int trn_extension_setlen_fields(trn_extension_t
*inp
, size_t newlen
);