subproto_request.h (7755B)
1 /* subproto_request.h -- generated by Trunnel v1.5.3. 2 * https://gitweb.torproject.org/trunnel.git 3 * You probably shouldn't edit this file. 4 */ 5 #ifndef TRUNNEL_SUBPROTO_REQUEST_H 6 #define TRUNNEL_SUBPROTO_REQUEST_H 7 8 #include <stdint.h> 9 #include "trunnel.h" 10 11 #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_SUBPROTO_REQUEST) 12 struct trn_subproto_request_st { 13 uint8_t protocol_id; 14 uint8_t proto_cap_number; 15 uint8_t trunnel_error_code_; 16 }; 17 #endif 18 typedef struct trn_subproto_request_st trn_subproto_request_t; 19 #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_SUBPROTO_REQUEST_EXT) 20 struct trn_subproto_request_ext_st { 21 TRUNNEL_DYNARRAY_HEAD(, struct trn_subproto_request_st *) reqs; 22 uint8_t trunnel_error_code_; 23 }; 24 #endif 25 typedef struct trn_subproto_request_ext_st trn_subproto_request_ext_t; 26 /** Return a newly allocated trn_subproto_request with all elements 27 * set to zero. 28 */ 29 trn_subproto_request_t *trn_subproto_request_new(void); 30 /** Release all storage held by the trn_subproto_request in 'victim'. 31 * (Do nothing if 'victim' is NULL.) 32 */ 33 void trn_subproto_request_free(trn_subproto_request_t *victim); 34 /** Try to parse a trn_subproto_request 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 trn_subproto_request_t. On failure, return -2 if the 38 * input appears truncated, and -1 if the input is otherwise invalid. 39 */ 40 ssize_t trn_subproto_request_parse(trn_subproto_request_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 * trn_subproto_request in 'obj'. On failure, return a negative value. 43 * Note that this value may be an overestimate, and can even be an 44 * underestimate for certain unencodeable objects. 45 */ 46 ssize_t trn_subproto_request_encoded_len(const trn_subproto_request_t *obj); 47 /** Try to encode the trn_subproto_request 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 trn_subproto_request_encode(uint8_t *output, size_t avail, const trn_subproto_request_t *input); 53 /** Check whether the internal state of the trn_subproto_request in 54 * 'obj' is consistent. Return NULL if it is, and a short message if 55 * it is not. 56 */ 57 const char *trn_subproto_request_check(const trn_subproto_request_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 trn_subproto_request_clear_errors(trn_subproto_request_t *obj); 62 /** Return the value of the protocol_id field of the 63 * trn_subproto_request_t in 'inp' 64 */ 65 uint8_t trn_subproto_request_get_protocol_id(const trn_subproto_request_t *inp); 66 /** Set the value of the protocol_id field of the 67 * trn_subproto_request_t in 'inp' to 'val'. Return 0 on success; 68 * return -1 and set the error code on 'inp' on failure. 69 */ 70 int trn_subproto_request_set_protocol_id(trn_subproto_request_t *inp, uint8_t val); 71 /** Return the value of the proto_cap_number field of the 72 * trn_subproto_request_t in 'inp' 73 */ 74 uint8_t trn_subproto_request_get_proto_cap_number(const trn_subproto_request_t *inp); 75 /** Set the value of the proto_cap_number field of the 76 * trn_subproto_request_t in 'inp' to 'val'. Return 0 on success; 77 * return -1 and set the error code on 'inp' on failure. 78 */ 79 int trn_subproto_request_set_proto_cap_number(trn_subproto_request_t *inp, uint8_t val); 80 /** Return a newly allocated trn_subproto_request_ext with all 81 * elements set to zero. 82 */ 83 trn_subproto_request_ext_t *trn_subproto_request_ext_new(void); 84 /** Release all storage held by the trn_subproto_request_ext in 85 * 'victim'. (Do nothing if 'victim' is NULL.) 86 */ 87 void trn_subproto_request_ext_free(trn_subproto_request_ext_t *victim); 88 /** Try to parse a trn_subproto_request_ext from the buffer in 89 * 'input', using up to 'len_in' bytes from the input buffer. On 90 * success, return the number of bytes consumed and set *output to the 91 * newly allocated trn_subproto_request_ext_t. On failure, return -2 92 * if the input appears truncated, and -1 if the input is otherwise 93 * invalid. 94 */ 95 ssize_t trn_subproto_request_ext_parse(trn_subproto_request_ext_t **output, const uint8_t *input, const size_t len_in); 96 /** Return the number of bytes we expect to need to encode the 97 * trn_subproto_request_ext in 'obj'. On failure, return a negative 98 * value. Note that this value may be an overestimate, and can even be 99 * an underestimate for certain unencodeable objects. 100 */ 101 ssize_t trn_subproto_request_ext_encoded_len(const trn_subproto_request_ext_t *obj); 102 /** Try to encode the trn_subproto_request_ext from 'input' into the 103 * buffer at 'output', using up to 'avail' bytes of the output buffer. 104 * On success, return the number of bytes used. On failure, return -2 105 * if the buffer was not long enough, and -1 if the input was invalid. 106 */ 107 ssize_t trn_subproto_request_ext_encode(uint8_t *output, size_t avail, const trn_subproto_request_ext_t *input); 108 /** Check whether the internal state of the trn_subproto_request_ext 109 * in 'obj' is consistent. Return NULL if it is, and a short message 110 * if it is not. 111 */ 112 const char *trn_subproto_request_ext_check(const trn_subproto_request_ext_t *obj); 113 /** Clear any errors that were set on the object 'obj' by its setter 114 * functions. Return true iff errors were cleared. 115 */ 116 int trn_subproto_request_ext_clear_errors(trn_subproto_request_ext_t *obj); 117 /** Return the length of the dynamic array holding the reqs field of 118 * the trn_subproto_request_ext_t in 'inp'. 119 */ 120 size_t trn_subproto_request_ext_getlen_reqs(const trn_subproto_request_ext_t *inp); 121 /** Return the element at position 'idx' of the dynamic array field 122 * reqs of the trn_subproto_request_ext_t in 'inp'. 123 */ 124 struct trn_subproto_request_st * trn_subproto_request_ext_get_reqs(trn_subproto_request_ext_t *inp, size_t idx); 125 /** As trn_subproto_request_ext_get_reqs, but take and return a const 126 * pointer 127 */ 128 const struct trn_subproto_request_st * trn_subproto_request_ext_getconst_reqs(const trn_subproto_request_ext_t *inp, size_t idx); 129 /** Change the element at position 'idx' of the dynamic array field 130 * reqs of the trn_subproto_request_ext_t in 'inp', so that it will 131 * hold the value 'elt'. Free the previous value, if any. 132 */ 133 int trn_subproto_request_ext_set_reqs(trn_subproto_request_ext_t *inp, size_t idx, struct trn_subproto_request_st * elt); 134 /** As trn_subproto_request_ext_set_reqs, but does not free the 135 * previous value. 136 */ 137 int trn_subproto_request_ext_set0_reqs(trn_subproto_request_ext_t *inp, size_t idx, struct trn_subproto_request_st * elt); 138 /** Append a new element 'elt' to the dynamic array field reqs of the 139 * trn_subproto_request_ext_t in 'inp'. 140 */ 141 int trn_subproto_request_ext_add_reqs(trn_subproto_request_ext_t *inp, struct trn_subproto_request_st * elt); 142 /** Return a pointer to the variable-length array field reqs of 'inp'. 143 */ 144 struct trn_subproto_request_st * * trn_subproto_request_ext_getarray_reqs(trn_subproto_request_ext_t *inp); 145 /** As trn_subproto_request_ext_get_reqs, but take and return a const 146 * pointer 147 */ 148 const struct trn_subproto_request_st * const * trn_subproto_request_ext_getconstarray_reqs(const trn_subproto_request_ext_t *inp); 149 /** Change the length of the variable-length array field reqs of 'inp' 150 * to 'newlen'.Fill extra elements with NULL; free removed elements. 151 * Return 0 on success; return -1 and set the error code on 'inp' on 152 * failure. 153 */ 154 int trn_subproto_request_ext_setlen_reqs(trn_subproto_request_ext_t *inp, size_t newlen); 155 156 157 #endif