Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../usr/include/fstrm
File: control.h
/*
[0] Fix | Delete
* Copyright (c) 2014 by Farsight Security, Inc.
[1] Fix | Delete
*
[2] Fix | Delete
* Permission is hereby granted, free of charge, to any person obtaining
[3] Fix | Delete
* a copy of this software and associated documentation files (the
[4] Fix | Delete
* "Software"), to deal in the Software without restriction, including
[5] Fix | Delete
* without limitation the rights to use, copy, modify, merge, publish,
[6] Fix | Delete
* distribute, sublicense, and/or sell copies of the Software, and to
[7] Fix | Delete
* permit persons to whom the Software is furnished to do so, subject to
[8] Fix | Delete
* the following conditions:
[9] Fix | Delete
*
[10] Fix | Delete
* The above copyright notice and this permission notice shall be included
[11] Fix | Delete
* in all copies or substantial portions of the Software.
[12] Fix | Delete
*
[13] Fix | Delete
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
[14] Fix | Delete
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
[15] Fix | Delete
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
[16] Fix | Delete
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
[17] Fix | Delete
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
[18] Fix | Delete
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
[19] Fix | Delete
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[20] Fix | Delete
*
[21] Fix | Delete
*/
[22] Fix | Delete
[23] Fix | Delete
#ifndef FSTRM_CONTROL_H
[24] Fix | Delete
#define FSTRM_CONTROL_H
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* \defgroup fstrm_control fstrm_control
[28] Fix | Delete
*
[29] Fix | Delete
* `fstrm_control` is an interface for encoding and decoding Frame Streams
[30] Fix | Delete
* control frames.
[31] Fix | Delete
*
[32] Fix | Delete
* Two types of frames are possible in a Frame Streams byte stream: **data
[33] Fix | Delete
* frames** and **control frames**. Both are variable length byte sequences
[34] Fix | Delete
* prefixed by a 32-bit big endian unsigned integer (the **frame length**)
[35] Fix | Delete
* specifying the length of the following byte sequence. If this frame length
[36] Fix | Delete
* value is greater than zero, the **frame length** specifies the **data frame
[37] Fix | Delete
* length**, and a data frame follows it. If the frame length is zero (i.e., it
[38] Fix | Delete
* is the four byte sequence `00 00 00 00`), this is an **escape sequence**,
[39] Fix | Delete
* which means that a control frame follows. The control frame itself is
[40] Fix | Delete
* prefixed by a 32-bit big endian unsigned integer (the **control frame
[41] Fix | Delete
* length**) specifying the length of the following **control frame payload**.
[42] Fix | Delete
*
[43] Fix | Delete
* There are two types of control frames used for uni-directional streams:
[44] Fix | Delete
* `START` and `STOP`. These control frame types bracket the stream of data
[45] Fix | Delete
* frames. `START` indicates the beginning of the stream and communicates
[46] Fix | Delete
* metadata about the stream to follow, and `STOP` indicates the end of the
[47] Fix | Delete
* stream.
[48] Fix | Delete
*
[49] Fix | Delete
* Bi-directional streams make use of three additional control frame types:
[50] Fix | Delete
* `READY`, `ACCEPT`, and `FINISH`. These control frame types are used in a
[51] Fix | Delete
* simple handshake protocol between sender and receiver.
[52] Fix | Delete
*
[53] Fix | Delete
* A uni-directional Frame Streams byte stream normally consists of the
[54] Fix | Delete
* following:
[55] Fix | Delete
*
[56] Fix | Delete
* 1. The `START` control frame.
[57] Fix | Delete
* 2. A sequence of zero or more data frames or control frames that are not of
[58] Fix | Delete
* the control frame types `START`, `STOP`, `ACCEPT`, `READY`, or
[59] Fix | Delete
* `FINISH`.
[60] Fix | Delete
* 3. The `STOP` control frame.
[61] Fix | Delete
*
[62] Fix | Delete
* The `START` and `STOP` control frames are not optional. The `START` control
[63] Fix | Delete
* frame must appear at the beginning of the byte stream, and the `STOP` control
[64] Fix | Delete
* frame must appear at the end of the byte stream. (If the byte stream has an
[65] Fix | Delete
* end.) `START` control frames must not appear anywhere other than at the
[66] Fix | Delete
* beginning of the byte stream, and `STOP` control frames must not appear
[67] Fix | Delete
* anywhere other than at the end of the byte stream. Only one `START` control
[68] Fix | Delete
* frame and only one `STOP` control frame may appear in a Frame Streams byte
[69] Fix | Delete
* stream.
[70] Fix | Delete
*
[71] Fix | Delete
* Control frames may optionally include zero or more **control frame fields**.
[72] Fix | Delete
* There is currently one type of control frame field defined: `CONTENT_TYPE`.
[73] Fix | Delete
* This field specifies a variable length byte sequence describing the encoding
[74] Fix | Delete
* of data frames that appear in the Frame Streams byte stream. This field is
[75] Fix | Delete
* used by cooperating programs to unambiguously identify how to interpret the
[76] Fix | Delete
* data frames in a particular Frame Streams byte stream. For instance, this
[77] Fix | Delete
* field may specify a particular schema to use to interpret the data frames
[78] Fix | Delete
* appearing in the byte stream. Zero, one, or more `CONTENT_TYPE` fields may
[79] Fix | Delete
* appear in `READY` or `ACCEPT` control frames. Zero or one `CONTENT_TYPE`
[80] Fix | Delete
* fields may appear in `START` control frames. No `CONTENT_TYPE` fields may
[81] Fix | Delete
* appear in `STOP` or `FINISH` control frames.
[82] Fix | Delete
*
[83] Fix | Delete
* A uni-directional Frame Streams encoder would normally produce a byte stream
[84] Fix | Delete
* as follows:
[85] Fix | Delete
*
[86] Fix | Delete
* 1. Write the `START` **control frame**.
[87] Fix | Delete
* + At the start of the byte stream, write the four byte **escape
[88] Fix | Delete
* sequence** `00 00 00 00` that precedes control frames.
[89] Fix | Delete
* + Write the **control frame length** as a 32-bit big endian unsigned
[90] Fix | Delete
* integer.
[91] Fix | Delete
* + Write the **control frame payload**. It must be a `START` control
[92] Fix | Delete
* frame. It may optionally specify a `CONTENT_TYPE` field.
[93] Fix | Delete
* 2. Write zero or more **data frames**.
[94] Fix | Delete
* 3. Write the `STOP` **control frame**.
[95] Fix | Delete
* + At the start of the byte stream, write the four byte **escape
[96] Fix | Delete
* sequence** `00 00 00 00` that precedes control frames.
[97] Fix | Delete
* + Write the **control frame length** as a 32-bit big endian unsigned
[98] Fix | Delete
* integer.
[99] Fix | Delete
* + Write the **control frame payload**. It must be a `STOP` control
[100] Fix | Delete
* frame.
[101] Fix | Delete
*
[102] Fix | Delete
* A uni-directional Frame Streams decoder would normally process the byte
[103] Fix | Delete
* stream as follows:
[104] Fix | Delete
*
[105] Fix | Delete
* 1. Read the `START` control frame.
[106] Fix | Delete
* + At the start of the byte stream, read the four byte **escape
[107] Fix | Delete
* sequence** `00 00 00 00` that precedes control frames.
[108] Fix | Delete
* + Read the 32-bit big endian unsigned integer specifying the **control
[109] Fix | Delete
* frame length**.
[110] Fix | Delete
* + Decode the **control frame payload**. It must be a `START` control
[111] Fix | Delete
* frame. It may optionally specify a `CONTENT_TYPE` field.
[112] Fix | Delete
* 2. Repeatedly read data frames or control frames following the `START`
[113] Fix | Delete
* control frame.
[114] Fix | Delete
* + Read the **frame length**, a 32-bit big endian unsigned integer.
[115] Fix | Delete
* + If the **frame length** is zero, a control frame follows:
[116] Fix | Delete
* + Read the 32-bit big endian unsigned integer specifying the
[117] Fix | Delete
* **control frame length**.
[118] Fix | Delete
* + Decode the **control frame payload**. If it is a `STOP`
[119] Fix | Delete
* control frame, the end of the Frame Streams byte stream has
[120] Fix | Delete
* occurred, and no frames follow. Break out of the decoding loop
[121] Fix | Delete
* and halt processing. (`READY`, `ACCEPT`, `START`, and `FINISH`
[122] Fix | Delete
* may not occur here. For forward compatibility, control frames of
[123] Fix | Delete
* types other than the types `READY`, `ACCEPT`, `START`, `STOP`,
[124] Fix | Delete
* and `FINISH` must be ignored here. No control frames specified
[125] Fix | Delete
* in the future may alter the encoding of succeeding frames.)
[126] Fix | Delete
* + If the **frame length** is non-zero, it specifies the number of bytes
[127] Fix | Delete
* in the following **data frame**. Consume these bytes from the byte
[128] Fix | Delete
* stream.
[129] Fix | Delete
*
[130] Fix | Delete
* The functions fstrm_control_encode() and fstrm_control_decode() are provided
[131] Fix | Delete
* to encode and decode control frames. See the detailed descriptions of those
[132] Fix | Delete
* functions for code examples showing their usage.
[133] Fix | Delete
*
[134] Fix | Delete
* @{
[135] Fix | Delete
*/
[136] Fix | Delete
[137] Fix | Delete
/**
[138] Fix | Delete
* The maximum length in bytes of an "Accept", "Start", or "Stop" control frame
[139] Fix | Delete
* payload. This excludes the escape sequence and the control frame length.
[140] Fix | Delete
*/
[141] Fix | Delete
#define FSTRM_CONTROL_FRAME_LENGTH_MAX 512
[142] Fix | Delete
[143] Fix | Delete
/**
[144] Fix | Delete
* The maximum length in bytes of a "Content Type" control frame field payload.
[145] Fix | Delete
* This excludes the field type and payload length.
[146] Fix | Delete
*/
[147] Fix | Delete
#define FSTRM_CONTROL_FIELD_CONTENT_TYPE_LENGTH_MAX 256
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* Control frame types.
[151] Fix | Delete
*/
[152] Fix | Delete
typedef enum {
[153] Fix | Delete
/** Control frame type value for "Accept" control frames. */
[154] Fix | Delete
FSTRM_CONTROL_ACCEPT = 0x01,
[155] Fix | Delete
[156] Fix | Delete
/** Control frame type value for "Start" control frames. */
[157] Fix | Delete
FSTRM_CONTROL_START = 0x02,
[158] Fix | Delete
[159] Fix | Delete
/** Control frame type value for "Stop" control frames. */
[160] Fix | Delete
FSTRM_CONTROL_STOP = 0x03,
[161] Fix | Delete
[162] Fix | Delete
/** Control frame type value for "Ready" control frames. */
[163] Fix | Delete
FSTRM_CONTROL_READY = 0x04,
[164] Fix | Delete
[165] Fix | Delete
/** Control frame type value for "Finish" control frames. */
[166] Fix | Delete
FSTRM_CONTROL_FINISH = 0x05,
[167] Fix | Delete
} fstrm_control_type;
[168] Fix | Delete
[169] Fix | Delete
/**
[170] Fix | Delete
* Control frame field types. These are optional fields that can appear in
[171] Fix | Delete
* control frames.
[172] Fix | Delete
*/
[173] Fix | Delete
typedef enum {
[174] Fix | Delete
/**
[175] Fix | Delete
* Control frame field type value for the "Content Type" control frame
[176] Fix | Delete
* option.
[177] Fix | Delete
*/
[178] Fix | Delete
FSTRM_CONTROL_FIELD_CONTENT_TYPE = 0x01,
[179] Fix | Delete
} fstrm_control_field;
[180] Fix | Delete
[181] Fix | Delete
/**
[182] Fix | Delete
* Flags for controlling the behavior of the encoding and decoding functions.
[183] Fix | Delete
*/
[184] Fix | Delete
typedef enum {
[185] Fix | Delete
/**
[186] Fix | Delete
* Set to control whether to include the control frame header in
[187] Fix | Delete
* encoding/decoding operations.
[188] Fix | Delete
*
[189] Fix | Delete
* Causes fstrm_control_encode() and fstrm_control_encoded_size() to
[190] Fix | Delete
* include the control frame header containing the escape sequence and
[191] Fix | Delete
* control frame payload length in the encoded output. Otherwise, only
[192] Fix | Delete
* the control frame payload itself is encoded.
[193] Fix | Delete
*
[194] Fix | Delete
* Tells fstrm_control_decode() that the input buffer to be decoded
[195] Fix | Delete
* begins with the control frame header containing the escape sequence
[196] Fix | Delete
* and control frame payload length. (Note that this requires the caller
[197] Fix | Delete
* to peek at the input buffer to calculate the right buffer length.)
[198] Fix | Delete
* Otherwise, the input buffer begins with the control frame payload.
[199] Fix | Delete
*/
[200] Fix | Delete
FSTRM_CONTROL_FLAG_WITH_HEADER = (1 << 0),
[201] Fix | Delete
} fstrm_control_flag;
[202] Fix | Delete
[203] Fix | Delete
/**
[204] Fix | Delete
* Convert an `fstrm_control_type` enum value to a string representation.
[205] Fix | Delete
* Unknown values are represented as `"FSTRM_CONTROL_UNKNOWN"`.
[206] Fix | Delete
*
[207] Fix | Delete
* \param type The `fstrm_control_type` enum value.
[208] Fix | Delete
* \return The string representation of the enum value. (Always non-NULL.)
[209] Fix | Delete
*/
[210] Fix | Delete
const char *
[211] Fix | Delete
fstrm_control_type_to_str(fstrm_control_type type);
[212] Fix | Delete
[213] Fix | Delete
/**
[214] Fix | Delete
* Convert an `fstrm_control_field` enum value to a string representation.
[215] Fix | Delete
* Unknown values are represented as `"FSTRM_CONTROL_FIELD_UNKNOWN"`.
[216] Fix | Delete
*
[217] Fix | Delete
* \param f_type The `fstrm_control_field` enum value.
[218] Fix | Delete
* \return The string representation of the enum value. (Always non-NULL.)
[219] Fix | Delete
*/
[220] Fix | Delete
const char *
[221] Fix | Delete
fstrm_control_field_type_to_str(fstrm_control_field f_type);
[222] Fix | Delete
[223] Fix | Delete
/**
[224] Fix | Delete
* Initialize an `fstrm_control` object. This object represents Frame Streams
[225] Fix | Delete
* control frames and is used for encoding and decoding control frames.
[226] Fix | Delete
*
[227] Fix | Delete
* \return
[228] Fix | Delete
* An `fstrm_control` object.
[229] Fix | Delete
*/
[230] Fix | Delete
struct fstrm_control *
[231] Fix | Delete
fstrm_control_init(void);
[232] Fix | Delete
[233] Fix | Delete
/**
[234] Fix | Delete
* Destroy an `fstrm_control` object.
[235] Fix | Delete
*
[236] Fix | Delete
* \param[in] c
[237] Fix | Delete
* Pointer to an `fstrm_control` object.
[238] Fix | Delete
*/
[239] Fix | Delete
void
[240] Fix | Delete
fstrm_control_destroy(struct fstrm_control **c);
[241] Fix | Delete
[242] Fix | Delete
/**
[243] Fix | Delete
* Reinitialize an `fstrm_control` object. This resets the internal state to
[244] Fix | Delete
* default values.
[245] Fix | Delete
*
[246] Fix | Delete
* \param c
[247] Fix | Delete
* `fstrm_control` object.
[248] Fix | Delete
*/
[249] Fix | Delete
void
[250] Fix | Delete
fstrm_control_reset(struct fstrm_control *c);
[251] Fix | Delete
[252] Fix | Delete
/**
[253] Fix | Delete
* Retrieve the type of the control frame.
[254] Fix | Delete
*
[255] Fix | Delete
* \param c
[256] Fix | Delete
* `fstrm_control` object.
[257] Fix | Delete
* \param[out] type
[258] Fix | Delete
* Type of the control frame.
[259] Fix | Delete
*
[260] Fix | Delete
* \retval #fstrm_res_success
[261] Fix | Delete
* \retval #fstrm_res_failure
[262] Fix | Delete
*/
[263] Fix | Delete
fstrm_res
[264] Fix | Delete
fstrm_control_get_type(
[265] Fix | Delete
const struct fstrm_control *c,
[266] Fix | Delete
fstrm_control_type *type);
[267] Fix | Delete
[268] Fix | Delete
/**
[269] Fix | Delete
* Set the type of the control frame.
[270] Fix | Delete
*
[271] Fix | Delete
* \param c
[272] Fix | Delete
* `fstrm_control` object.
[273] Fix | Delete
* \param[in] type
[274] Fix | Delete
* Type of the control frame.
[275] Fix | Delete
*
[276] Fix | Delete
* \retval #fstrm_res_success
[277] Fix | Delete
* \retval #fstrm_res_failure
[278] Fix | Delete
*/
[279] Fix | Delete
fstrm_res
[280] Fix | Delete
fstrm_control_set_type(
[281] Fix | Delete
struct fstrm_control *c,
[282] Fix | Delete
fstrm_control_type type);
[283] Fix | Delete
[284] Fix | Delete
/**
[285] Fix | Delete
* Retrieve the number of "Content Type" fields present in the control frame.
[286] Fix | Delete
*
[287] Fix | Delete
* \param c
[288] Fix | Delete
* `fstrm_control` object.
[289] Fix | Delete
* \param[out] n_content_type
[290] Fix | Delete
* The number of "Content Type" fields.
[291] Fix | Delete
*
[292] Fix | Delete
* \retval #fstrm_res_success
[293] Fix | Delete
* \retval #fstrm_res_failure
[294] Fix | Delete
*/
[295] Fix | Delete
fstrm_res
[296] Fix | Delete
fstrm_control_get_num_field_content_type(
[297] Fix | Delete
const struct fstrm_control *c,
[298] Fix | Delete
size_t *n_content_type);
[299] Fix | Delete
[300] Fix | Delete
/**
[301] Fix | Delete
* Retrieve a "Content Type" field from the control frame. This function
[302] Fix | Delete
* returns a reference which must not be modified. Control frames may contain
[303] Fix | Delete
* zero, one, or more "Content Type" fields.
[304] Fix | Delete
*
[305] Fix | Delete
* \see fstrm_control_get_num_field_content_type()
[306] Fix | Delete
*
[307] Fix | Delete
* \param c
[308] Fix | Delete
* `fstrm_control` object.
[309] Fix | Delete
* \param[in] idx
[310] Fix | Delete
* The index of the "Content Type" field to retrieve.
[311] Fix | Delete
* \param[out] content_type
[312] Fix | Delete
* Pointer to where the reference to the "Content Type" string will be
[313] Fix | Delete
* stored. Note that this string is not NUL-terminated and may contain
[314] Fix | Delete
* embedded NULs.
[315] Fix | Delete
* \param[out] len_content_type
[316] Fix | Delete
* The number of bytes in `content_type`.
[317] Fix | Delete
*
[318] Fix | Delete
* \retval #fstrm_res_success
[319] Fix | Delete
* The control frame has a "Content Type" field.
[320] Fix | Delete
* \retval #fstrm_res_failure
[321] Fix | Delete
* The control frame does not have a "Content Type" field.
[322] Fix | Delete
*/
[323] Fix | Delete
fstrm_res
[324] Fix | Delete
fstrm_control_get_field_content_type(
[325] Fix | Delete
const struct fstrm_control *c,
[326] Fix | Delete
const size_t idx,
[327] Fix | Delete
const uint8_t **content_type,
[328] Fix | Delete
size_t *len_content_type);
[329] Fix | Delete
[330] Fix | Delete
/**
[331] Fix | Delete
* Add a "Content Type" field to the control frame. This function makes a copy
[332] Fix | Delete
* of the provided string. This function may be called multiple times, in which
[333] Fix | Delete
* case multiple "Content Type" fields will be added to the control frame.
[334] Fix | Delete
*
[335] Fix | Delete
* The "Content Type" fields are removed on a call to fstrm_control_reset().
[336] Fix | Delete
*
[337] Fix | Delete
* \param c
[338] Fix | Delete
* `fstrm_control` object.
[339] Fix | Delete
* \param[in] content_type
[340] Fix | Delete
* The "Content Type" string to copy. Note that this string is not
[341] Fix | Delete
* NUL-terminated and may contain embedded NULs.
[342] Fix | Delete
* \param[in] len_content_type
[343] Fix | Delete
* The number of bytes in `content_type`.
[344] Fix | Delete
*
[345] Fix | Delete
* \retval #fstrm_res_success
[346] Fix | Delete
* The "Content Type" field was successfully added.
[347] Fix | Delete
* \retval #fstrm_res_failure
[348] Fix | Delete
* The "Content Type" string is too long.
[349] Fix | Delete
*/
[350] Fix | Delete
fstrm_res
[351] Fix | Delete
fstrm_control_add_field_content_type(
[352] Fix | Delete
struct fstrm_control *c,
[353] Fix | Delete
const uint8_t *content_type,
[354] Fix | Delete
size_t len_content_type);
[355] Fix | Delete
[356] Fix | Delete
/**
[357] Fix | Delete
* Check if the control frame matches a particular content type value. That is,
[358] Fix | Delete
* the content type given in the `match` and `len_match` parameters is checked
[359] Fix | Delete
* for compatibility with the content types (if any) specified in the control
[360] Fix | Delete
* frame.
[361] Fix | Delete
*
[362] Fix | Delete
* \param c
[363] Fix | Delete
* `fstrm_control` object.
[364] Fix | Delete
* \param match
[365] Fix | Delete
* The "Content Type" string to match. Note that this string is not
[366] Fix | Delete
* NUL-terminated and may contain embedded NULs. May be NULL, in which case
[367] Fix | Delete
* the control frame must not have any content type fields in order to
[368] Fix | Delete
* match.
[369] Fix | Delete
* \param len_match
[370] Fix | Delete
* The number of bytes in `match`.
[371] Fix | Delete
*
[372] Fix | Delete
* \retval #fstrm_res_success
[373] Fix | Delete
* A match was found.
[374] Fix | Delete
* \retval #fstrm_res_failure
[375] Fix | Delete
* A match was not found.
[376] Fix | Delete
*/
[377] Fix | Delete
fstrm_res
[378] Fix | Delete
fstrm_control_match_field_content_type(
[379] Fix | Delete
const struct fstrm_control *c,
[380] Fix | Delete
const uint8_t *match,
[381] Fix | Delete
const size_t len_match);
[382] Fix | Delete
[383] Fix | Delete
/**
[384] Fix | Delete
* Decode a control frame from a buffer. The buffer starts with either the
[385] Fix | Delete
* escape sequence or the control frame payload depending on whether the
[386] Fix | Delete
* `FSTRM_CONTROL_FLAG_WITH_HEADER` flag is set or not. In either case, the
[387] Fix | Delete
* 'len_control_frame' parameter must be exact. Underflow or overflow is not
[388] Fix | Delete
* permitted.
[389] Fix | Delete
*
[390] Fix | Delete
* The following code example shows a function that decodes a control frame
[391] Fix | Delete
* payload:
[392] Fix | Delete
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[393] Fix | Delete
static fstrm_res
[394] Fix | Delete
decode_control_frame(const void *control_frame, size_t len_control_frame)
[395] Fix | Delete
{
[396] Fix | Delete
fstrm_res res;
[397] Fix | Delete
fstrm_control_type c_type;
[398] Fix | Delete
struct fstrm_control *c;
[399] Fix | Delete
uint32_t flags = 0;
[400] Fix | Delete
[401] Fix | Delete
c = fstrm_control_init();
[402] Fix | Delete
[403] Fix | Delete
res = fstrm_control_decode(c, control_frame, len_control_frame, flags);
[404] Fix | Delete
if (res != fstrm_res_success) {
[405] Fix | Delete
puts("fstrm_control_decode() failed.");
[406] Fix | Delete
fstrm_control_destroy(&c);
[407] Fix | Delete
return res;
[408] Fix | Delete
}
[409] Fix | Delete
[410] Fix | Delete
res = fstrm_control_get_type(c, &c_type);
[411] Fix | Delete
if (res != fstrm_res_success) {
[412] Fix | Delete
puts("fstrm_control_get_type() failed.");
[413] Fix | Delete
fstrm_control_destroy(&c);
[414] Fix | Delete
return res;
[415] Fix | Delete
}
[416] Fix | Delete
printf("The control frame is of type %s (%u).\n",
[417] Fix | Delete
fstrm_control_type_to_str(c_type), c_type);
[418] Fix | Delete
[419] Fix | Delete
size_t n_content_type;
[420] Fix | Delete
res = fstrm_control_get_num_field_content_type(c, &n_content_type);
[421] Fix | Delete
if (res != fstrm_res_success) {
[422] Fix | Delete
puts("fstrm_control_get_num_field_content_type() failed.");
[423] Fix | Delete
fstrm_control_destroy(&c);
[424] Fix | Delete
return res;
[425] Fix | Delete
}
[426] Fix | Delete
[427] Fix | Delete
const uint8_t *content_type;
[428] Fix | Delete
size_t len_content_type;
[429] Fix | Delete
for (size_t idx = 0; idx < n_content_type; idx++) {
[430] Fix | Delete
res = fstrm_control_get_field_content_type(c, idx,
[431] Fix | Delete
&content_type, &len_content_type);
[432] Fix | Delete
if (res == fstrm_res_success) {
[433] Fix | Delete
printf("The control frame has a CONTENT_TYPE field of length %zd.\n",
[434] Fix | Delete
len_content_type);
[435] Fix | Delete
}
[436] Fix | Delete
}
[437] Fix | Delete
[438] Fix | Delete
fstrm_control_destroy(&c);
[439] Fix | Delete
return fstrm_res_success;
[440] Fix | Delete
}
[441] Fix | Delete
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[442] Fix | Delete
*
[443] Fix | Delete
* \param c
[444] Fix | Delete
* `fstrm_control` object. Its state will be overwritten.
[445] Fix | Delete
* \param[in] control_frame
[446] Fix | Delete
* Buffer containing the serialized control frame.
[447] Fix | Delete
* \param[in] len_control_frame
[448] Fix | Delete
* The number of bytes in `control_frame`. This parameter must specify the
[449] Fix | Delete
* exact number of bytes in the control frame.
[450] Fix | Delete
* \param flags
[451] Fix | Delete
* Flags controlling the decoding process. See #fstrm_control_flag.
[452] Fix | Delete
*
[453] Fix | Delete
* \retval #fstrm_res_success
[454] Fix | Delete
* \retval #fstrm_res_failure
[455] Fix | Delete
*/
[456] Fix | Delete
fstrm_res
[457] Fix | Delete
fstrm_control_decode(
[458] Fix | Delete
struct fstrm_control *c,
[459] Fix | Delete
const void *control_frame,
[460] Fix | Delete
size_t len_control_frame,
[461] Fix | Delete
const uint32_t flags);
[462] Fix | Delete
[463] Fix | Delete
/**
[464] Fix | Delete
* Calculate the number of bytes needed to serialize the control frame.
[465] Fix | Delete
*
[466] Fix | Delete
* \param c
[467] Fix | Delete
* `fstrm_control` object.
[468] Fix | Delete
* \param[out] len_control_frame
[469] Fix | Delete
* The number of bytes needed to encode `c`.
[470] Fix | Delete
* \param flags
[471] Fix | Delete
* Flags controlling the encoding process. See #fstrm_control_flag.
[472] Fix | Delete
*
[473] Fix | Delete
* \retval #fstrm_res_success
[474] Fix | Delete
* \retval #fstrm_res_failure
[475] Fix | Delete
*/
[476] Fix | Delete
fstrm_res
[477] Fix | Delete
fstrm_control_encoded_size(
[478] Fix | Delete
const struct fstrm_control *c,
[479] Fix | Delete
size_t *len_control_frame,
[480] Fix | Delete
const uint32_t flags);
[481] Fix | Delete
[482] Fix | Delete
/**
[483] Fix | Delete
* Encode a control frame into a buffer. Since a Frame Streams control frame is
[484] Fix | Delete
* a variable length byte sequence of up to #FSTRM_CONTROL_FRAME_LENGTH_MAX
[485] Fix | Delete
* bytes, this function can be used in two different ways. The first way is to
[486] Fix | Delete
* call fstrm_control_encoded_size() to obtain the exact number of bytes needed
[487] Fix | Delete
* to encode the frame, and then pass a buffer of this exact size to
[488] Fix | Delete
* fstrm_control_encode(). The following example shows this usage:
[489] Fix | Delete
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[490] Fix | Delete
fstrm_res res;
[491] Fix | Delete
struct fstrm_control *c;
[492] Fix | Delete
uint8_t *control_frame;
[493] Fix | Delete
size_t len_control_frame;
[494] Fix | Delete
uint32_t flags = 0;
[495] Fix | Delete
[496] Fix | Delete
c = fstrm_control_init();
[497] Fix | Delete
res = fstrm_control_set_type(c, FSTRM_CONTROL_START);
[498] Fix | Delete
if (res != fstrm_res_success) {
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function