cell_common.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* cell_common.h -- generated by Trunnel v1.5.2.
  2. * https://gitweb.torproject.org/trunnel.git
  3. * You probably shouldn't edit this file.
  4. */
  5. #ifndef TRUNNEL_CELL_COMMON_H
  6. #define TRUNNEL_CELL_COMMON_H
  7. #include <stdint.h>
  8. #include "trunnel.h"
  9. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_EXTENSION_FIELDS)
  10. struct trn_cell_extension_fields_st {
  11. uint8_t field_type;
  12. uint8_t field_len;
  13. TRUNNEL_DYNARRAY_HEAD(, uint8_t) field;
  14. uint8_t trunnel_error_code_;
  15. };
  16. #endif
  17. typedef struct trn_cell_extension_fields_st trn_cell_extension_fields_t;
  18. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_EXTENSION)
  19. struct trn_cell_extension_st {
  20. uint8_t num;
  21. TRUNNEL_DYNARRAY_HEAD(, struct trn_cell_extension_fields_st *) fields;
  22. uint8_t trunnel_error_code_;
  23. };
  24. #endif
  25. typedef struct trn_cell_extension_st trn_cell_extension_t;
  26. /** Return a newly allocated trn_cell_extension_fields with all
  27. * elements set to zero.
  28. */
  29. trn_cell_extension_fields_t *trn_cell_extension_fields_new(void);
  30. /** Release all storage held by the trn_cell_extension_fields in
  31. * 'victim'. (Do nothing if 'victim' is NULL.)
  32. */
  33. void trn_cell_extension_fields_free(trn_cell_extension_fields_t *victim);
  34. /** Try to parse a trn_cell_extension_fields from the buffer in
  35. * 'input', using up to 'len_in' bytes from the input buffer. On
  36. * success, return the number of bytes consumed and set *output to the
  37. * newly allocated trn_cell_extension_fields_t. On failure, return -2
  38. * if the input appears truncated, and -1 if the input is otherwise
  39. * invalid.
  40. */
  41. ssize_t trn_cell_extension_fields_parse(trn_cell_extension_fields_t **output, const uint8_t *input, const size_t len_in);
  42. /** Return the number of bytes we expect to need to encode the
  43. * trn_cell_extension_fields in 'obj'. On failure, return a negative
  44. * value. Note that this value may be an overestimate, and can even be
  45. * an underestimate for certain unencodeable objects.
  46. */
  47. ssize_t trn_cell_extension_fields_encoded_len(const trn_cell_extension_fields_t *obj);
  48. /** Try to encode the trn_cell_extension_fields from 'input' into the
  49. * buffer at 'output', using up to 'avail' bytes of the output buffer.
  50. * On success, return the number of bytes used. On failure, return -2
  51. * if the buffer was not long enough, and -1 if the input was invalid.
  52. */
  53. ssize_t trn_cell_extension_fields_encode(uint8_t *output, size_t avail, const trn_cell_extension_fields_t *input);
  54. /** Check whether the internal state of the trn_cell_extension_fields
  55. * in 'obj' is consistent. Return NULL if it is, and a short message
  56. * if it is not.
  57. */
  58. const char *trn_cell_extension_fields_check(const trn_cell_extension_fields_t *obj);
  59. /** Clear any errors that were set on the object 'obj' by its setter
  60. * functions. Return true iff errors were cleared.
  61. */
  62. int trn_cell_extension_fields_clear_errors(trn_cell_extension_fields_t *obj);
  63. /** Return the value of the field_type field of the
  64. * trn_cell_extension_fields_t in 'inp'
  65. */
  66. uint8_t trn_cell_extension_fields_get_field_type(const trn_cell_extension_fields_t *inp);
  67. /** Set the value of the field_type field of the
  68. * trn_cell_extension_fields_t in 'inp' to 'val'. Return 0 on success;
  69. * return -1 and set the error code on 'inp' on failure.
  70. */
  71. int trn_cell_extension_fields_set_field_type(trn_cell_extension_fields_t *inp, uint8_t val);
  72. /** Return the value of the field_len field of the
  73. * trn_cell_extension_fields_t in 'inp'
  74. */
  75. uint8_t trn_cell_extension_fields_get_field_len(const trn_cell_extension_fields_t *inp);
  76. /** Set the value of the field_len field of the
  77. * trn_cell_extension_fields_t in 'inp' to 'val'. Return 0 on success;
  78. * return -1 and set the error code on 'inp' on failure.
  79. */
  80. int trn_cell_extension_fields_set_field_len(trn_cell_extension_fields_t *inp, uint8_t val);
  81. /** Return the length of the dynamic array holding the field field of
  82. * the trn_cell_extension_fields_t in 'inp'.
  83. */
  84. size_t trn_cell_extension_fields_getlen_field(const trn_cell_extension_fields_t *inp);
  85. /** Return the element at position 'idx' of the dynamic array field
  86. * field of the trn_cell_extension_fields_t in 'inp'.
  87. */
  88. uint8_t trn_cell_extension_fields_get_field(trn_cell_extension_fields_t *inp, size_t idx);
  89. /** As trn_cell_extension_fields_get_field, but take and return a
  90. * const pointer
  91. */
  92. uint8_t trn_cell_extension_fields_getconst_field(const trn_cell_extension_fields_t *inp, size_t idx);
  93. /** Change the element at position 'idx' of the dynamic array field
  94. * field of the trn_cell_extension_fields_t in 'inp', so that it will
  95. * hold the value 'elt'.
  96. */
  97. int trn_cell_extension_fields_set_field(trn_cell_extension_fields_t *inp, size_t idx, uint8_t elt);
  98. /** Append a new element 'elt' to the dynamic array field field of the
  99. * trn_cell_extension_fields_t in 'inp'.
  100. */
  101. int trn_cell_extension_fields_add_field(trn_cell_extension_fields_t *inp, uint8_t elt);
  102. /** Return a pointer to the variable-length array field field of
  103. * 'inp'.
  104. */
  105. uint8_t * trn_cell_extension_fields_getarray_field(trn_cell_extension_fields_t *inp);
  106. /** As trn_cell_extension_fields_get_field, but take and return a
  107. * const pointer
  108. */
  109. const uint8_t * trn_cell_extension_fields_getconstarray_field(const trn_cell_extension_fields_t *inp);
  110. /** Change the length of the variable-length array field field of
  111. * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success;
  112. * return -1 and set the error code on 'inp' on failure.
  113. */
  114. int trn_cell_extension_fields_setlen_field(trn_cell_extension_fields_t *inp, size_t newlen);
  115. /** Return a newly allocated trn_cell_extension with all elements set
  116. * to zero.
  117. */
  118. trn_cell_extension_t *trn_cell_extension_new(void);
  119. /** Release all storage held by the trn_cell_extension in 'victim'.
  120. * (Do nothing if 'victim' is NULL.)
  121. */
  122. void trn_cell_extension_free(trn_cell_extension_t *victim);
  123. /** Try to parse a trn_cell_extension from the buffer in 'input',
  124. * using up to 'len_in' bytes from the input buffer. On success,
  125. * return the number of bytes consumed and set *output to the newly
  126. * allocated trn_cell_extension_t. On failure, return -2 if the input
  127. * appears truncated, and -1 if the input is otherwise invalid.
  128. */
  129. ssize_t trn_cell_extension_parse(trn_cell_extension_t **output, const uint8_t *input, const size_t len_in);
  130. /** Return the number of bytes we expect to need to encode the
  131. * trn_cell_extension in 'obj'. On failure, return a negative value.
  132. * Note that this value may be an overestimate, and can even be an
  133. * underestimate for certain unencodeable objects.
  134. */
  135. ssize_t trn_cell_extension_encoded_len(const trn_cell_extension_t *obj);
  136. /** Try to encode the trn_cell_extension from 'input' into the buffer
  137. * at 'output', using up to 'avail' bytes of the output buffer. On
  138. * success, return the number of bytes used. On failure, return -2 if
  139. * the buffer was not long enough, and -1 if the input was invalid.
  140. */
  141. ssize_t trn_cell_extension_encode(uint8_t *output, size_t avail, const trn_cell_extension_t *input);
  142. /** Check whether the internal state of the trn_cell_extension in
  143. * 'obj' is consistent. Return NULL if it is, and a short message if
  144. * it is not.
  145. */
  146. const char *trn_cell_extension_check(const trn_cell_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.
  149. */
  150. int trn_cell_extension_clear_errors(trn_cell_extension_t *obj);
  151. /** Return the value of the num field of the trn_cell_extension_t in
  152. * 'inp'
  153. */
  154. uint8_t trn_cell_extension_get_num(const trn_cell_extension_t *inp);
  155. /** Set the value of the num field of the trn_cell_extension_t in
  156. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  157. * code on 'inp' on failure.
  158. */
  159. int trn_cell_extension_set_num(trn_cell_extension_t *inp, uint8_t val);
  160. /** Return the length of the dynamic array holding the fields field of
  161. * the trn_cell_extension_t in 'inp'.
  162. */
  163. size_t trn_cell_extension_getlen_fields(const trn_cell_extension_t *inp);
  164. /** Return the element at position 'idx' of the dynamic array field
  165. * fields of the trn_cell_extension_t in 'inp'.
  166. */
  167. struct trn_cell_extension_fields_st * trn_cell_extension_get_fields(trn_cell_extension_t *inp, size_t idx);
  168. /** As trn_cell_extension_get_fields, but take and return a const
  169. * pointer
  170. */
  171. const struct trn_cell_extension_fields_st * trn_cell_extension_getconst_fields(const trn_cell_extension_t *inp, size_t idx);
  172. /** Change the element at position 'idx' of the dynamic array field
  173. * fields of the trn_cell_extension_t in 'inp', so that it will hold
  174. * the value 'elt'. Free the previous value, if any.
  175. */
  176. int trn_cell_extension_set_fields(trn_cell_extension_t *inp, size_t idx, struct trn_cell_extension_fields_st * elt);
  177. /** As trn_cell_extension_set_fields, but does not free the previous
  178. * value.
  179. */
  180. int trn_cell_extension_set0_fields(trn_cell_extension_t *inp, size_t idx, struct trn_cell_extension_fields_st * elt);
  181. /** Append a new element 'elt' to the dynamic array field fields of
  182. * the trn_cell_extension_t in 'inp'.
  183. */
  184. int trn_cell_extension_add_fields(trn_cell_extension_t *inp, struct trn_cell_extension_fields_st * elt);
  185. /** Return a pointer to the variable-length array field fields of
  186. * 'inp'.
  187. */
  188. struct trn_cell_extension_fields_st * * trn_cell_extension_getarray_fields(trn_cell_extension_t *inp);
  189. /** As trn_cell_extension_get_fields, but take and return a const
  190. * pointer
  191. */
  192. const struct trn_cell_extension_fields_st * const * trn_cell_extension_getconstarray_fields(const trn_cell_extension_t *inp);
  193. /** Change the length of the variable-length array field fields of
  194. * 'inp' to 'newlen'.Fill extra elements with NULL; free removed
  195. * elements. Return 0 on success; return -1 and set the error code on
  196. * 'inp' on failure.
  197. */
  198. int trn_cell_extension_setlen_fields(trn_cell_extension_t *inp, size_t newlen);
  199. #endif