cell_common.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* cell_common.h -- generated by by Trunnel v1.5.1.
  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_CELL_EXTENSION_FIELDS)
  10. struct 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 cell_extension_fields_st cell_extension_fields_t;
  18. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_CELL_EXTENSION)
  19. struct cell_extension_st {
  20. uint8_t num;
  21. TRUNNEL_DYNARRAY_HEAD(, struct cell_extension_fields_st *) fields;
  22. uint8_t trunnel_error_code_;
  23. };
  24. #endif
  25. typedef struct cell_extension_st cell_extension_t;
  26. /** Return a newly allocated cell_extension_fields with all elements
  27. * set to zero.
  28. */
  29. cell_extension_fields_t *cell_extension_fields_new(void);
  30. /** Release all storage held by the cell_extension_fields in 'victim'.
  31. * (Do nothing if 'victim' is NULL.)
  32. */
  33. void cell_extension_fields_free(cell_extension_fields_t *victim);
  34. /** Try to parse a cell_extension_fields from the buffer in 'input',
  35. * using up to 'len_in' bytes from the input buffer. On success,
  36. * return the number of bytes consumed and set *output to the newly
  37. * allocated cell_extension_fields_t. On failure, return -2 if the
  38. * input appears truncated, and -1 if the input is otherwise invalid.
  39. */
  40. ssize_t cell_extension_fields_parse(cell_extension_fields_t **output, const uint8_t *input, const size_t len_in);
  41. /** Return the number of bytes we expect to need to encode the
  42. * cell_extension_fields in 'obj'. On failure, return a negative
  43. * value. Note that this value may be an overestimate, and can even be
  44. * an underestimate for certain unencodeable objects.
  45. */
  46. ssize_t cell_extension_fields_encoded_len(const cell_extension_fields_t *obj);
  47. /** Try to encode the cell_extension_fields from 'input' into the
  48. * buffer at 'output', using up to 'avail' bytes of the output buffer.
  49. * On success, return the number of bytes used. On failure, return -2
  50. * if the buffer was not long enough, and -1 if the input was invalid.
  51. */
  52. ssize_t cell_extension_fields_encode(uint8_t *output, size_t avail, const cell_extension_fields_t *input);
  53. /** Check whether the internal state of the cell_extension_fields in
  54. * 'obj' is consistent. Return NULL if it is, and a short message if
  55. * it is not.
  56. */
  57. const char *cell_extension_fields_check(const cell_extension_fields_t *obj);
  58. /** Clear any errors that were set on the object 'obj' by its setter
  59. * functions. Return true iff errors were cleared.
  60. */
  61. int cell_extension_fields_clear_errors(cell_extension_fields_t *obj);
  62. /** Return the value of the field_type field of the
  63. * cell_extension_fields_t in 'inp'
  64. */
  65. uint8_t cell_extension_fields_get_field_type(const cell_extension_fields_t *inp);
  66. /** Set the value of the field_type field of the
  67. * cell_extension_fields_t in 'inp' to 'val'. Return 0 on success;
  68. * return -1 and set the error code on 'inp' on failure.
  69. */
  70. int cell_extension_fields_set_field_type(cell_extension_fields_t *inp, uint8_t val);
  71. /** Return the value of the field_len field of the
  72. * cell_extension_fields_t in 'inp'
  73. */
  74. uint8_t cell_extension_fields_get_field_len(const cell_extension_fields_t *inp);
  75. /** Set the value of the field_len field of the
  76. * cell_extension_fields_t in 'inp' to 'val'. Return 0 on success;
  77. * return -1 and set the error code on 'inp' on failure.
  78. */
  79. int cell_extension_fields_set_field_len(cell_extension_fields_t *inp, uint8_t val);
  80. /** Return the length of the dynamic array holding the field field of
  81. * the cell_extension_fields_t in 'inp'.
  82. */
  83. size_t cell_extension_fields_getlen_field(const cell_extension_fields_t *inp);
  84. /** Return the element at position 'idx' of the dynamic array field
  85. * field of the cell_extension_fields_t in 'inp'.
  86. */
  87. uint8_t cell_extension_fields_get_field(cell_extension_fields_t *inp, size_t idx);
  88. /** As cell_extension_fields_get_field, but take and return a const
  89. * pointer
  90. */
  91. uint8_t cell_extension_fields_getconst_field(const cell_extension_fields_t *inp, size_t idx);
  92. /** Change the element at position 'idx' of the dynamic array field
  93. * field of the cell_extension_fields_t in 'inp', so that it will hold
  94. * the value 'elt'.
  95. */
  96. int cell_extension_fields_set_field(cell_extension_fields_t *inp, size_t idx, uint8_t elt);
  97. /** Append a new element 'elt' to the dynamic array field field of the
  98. * cell_extension_fields_t in 'inp'.
  99. */
  100. int cell_extension_fields_add_field(cell_extension_fields_t *inp, uint8_t elt);
  101. /** Return a pointer to the variable-length array field field of
  102. * 'inp'.
  103. */
  104. uint8_t * cell_extension_fields_getarray_field(cell_extension_fields_t *inp);
  105. /** As cell_extension_fields_get_field, but take and return a const
  106. * pointer
  107. */
  108. const uint8_t * cell_extension_fields_getconstarray_field(const cell_extension_fields_t *inp);
  109. /** Change the length of the variable-length array field field of
  110. * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success;
  111. * return -1 and set the error code on 'inp' on failure.
  112. */
  113. int cell_extension_fields_setlen_field(cell_extension_fields_t *inp, size_t newlen);
  114. /** Return a newly allocated cell_extension with all elements set to
  115. * zero.
  116. */
  117. cell_extension_t *cell_extension_new(void);
  118. /** Release all storage held by the cell_extension in 'victim'. (Do
  119. * nothing if 'victim' is NULL.)
  120. */
  121. void cell_extension_free(cell_extension_t *victim);
  122. /** Try to parse a cell_extension from the buffer in 'input', using up
  123. * to 'len_in' bytes from the input buffer. On success, return the
  124. * number of bytes consumed and set *output to the newly allocated
  125. * cell_extension_t. On failure, return -2 if the input appears
  126. * truncated, and -1 if the input is otherwise invalid.
  127. */
  128. ssize_t cell_extension_parse(cell_extension_t **output, const uint8_t *input, const size_t len_in);
  129. /** Return the number of bytes we expect to need to encode the
  130. * cell_extension in 'obj'. On failure, return a negative value. Note
  131. * that this value may be an overestimate, and can even be an
  132. * underestimate for certain unencodeable objects.
  133. */
  134. ssize_t cell_extension_encoded_len(const cell_extension_t *obj);
  135. /** Try to encode the cell_extension from 'input' into the buffer at
  136. * 'output', using up to 'avail' bytes of the output buffer. On
  137. * success, return the number of bytes used. On failure, return -2 if
  138. * the buffer was not long enough, and -1 if the input was invalid.
  139. */
  140. ssize_t cell_extension_encode(uint8_t *output, size_t avail, const cell_extension_t *input);
  141. /** Check whether the internal state of the cell_extension in 'obj' is
  142. * consistent. Return NULL if it is, and a short message if it is not.
  143. */
  144. const char *cell_extension_check(const cell_extension_t *obj);
  145. /** Clear any errors that were set on the object 'obj' by its setter
  146. * functions. Return true iff errors were cleared.
  147. */
  148. int cell_extension_clear_errors(cell_extension_t *obj);
  149. /** Return the value of the num field of the cell_extension_t in 'inp'
  150. */
  151. uint8_t cell_extension_get_num(const cell_extension_t *inp);
  152. /** Set the value of the num field of the cell_extension_t in 'inp' to
  153. * 'val'. Return 0 on success; return -1 and set the error code on
  154. * 'inp' on failure.
  155. */
  156. int cell_extension_set_num(cell_extension_t *inp, uint8_t val);
  157. /** Return the length of the dynamic array holding the fields field of
  158. * the cell_extension_t in 'inp'.
  159. */
  160. size_t cell_extension_getlen_fields(const cell_extension_t *inp);
  161. /** Return the element at position 'idx' of the dynamic array field
  162. * fields of the cell_extension_t in 'inp'.
  163. */
  164. struct cell_extension_fields_st * cell_extension_get_fields(cell_extension_t *inp, size_t idx);
  165. /** As cell_extension_get_fields, but take and return a const pointer
  166. */
  167. const struct cell_extension_fields_st * cell_extension_getconst_fields(const cell_extension_t *inp, size_t idx);
  168. /** Change the element at position 'idx' of the dynamic array field
  169. * fields of the cell_extension_t in 'inp', so that it will hold the
  170. * value 'elt'. Free the previous value, if any.
  171. */
  172. int cell_extension_set_fields(cell_extension_t *inp, size_t idx, struct cell_extension_fields_st * elt);
  173. /** As cell_extension_set_fields, but does not free the previous
  174. * value.
  175. */
  176. int cell_extension_set0_fields(cell_extension_t *inp, size_t idx, struct cell_extension_fields_st * elt);
  177. /** Append a new element 'elt' to the dynamic array field fields of
  178. * the cell_extension_t in 'inp'.
  179. */
  180. int cell_extension_add_fields(cell_extension_t *inp, struct cell_extension_fields_st * elt);
  181. /** Return a pointer to the variable-length array field fields of
  182. * 'inp'.
  183. */
  184. struct cell_extension_fields_st * * cell_extension_getarray_fields(cell_extension_t *inp);
  185. /** As cell_extension_get_fields, but take and return a const pointer
  186. */
  187. const struct cell_extension_fields_st * const * cell_extension_getconstarray_fields(const cell_extension_t *inp);
  188. /** Change the length of the variable-length array field fields of
  189. * 'inp' to 'newlen'.Fill extra elements with NULL; free removed
  190. * elements. Return 0 on success; return -1 and set the error code on
  191. * 'inp' on failure.
  192. */
  193. int cell_extension_setlen_fields(cell_extension_t *inp, size_t newlen);
  194. #endif