Compy 0.2.0
A lightweight RTSP 1.0 server library for embedded systems
Loading...
Searching...
No Matches
util.h File Reference

Utilitary stuff. More...

#include <compy/option.h>
#include <compy/types/error.h>
#include <compy/types/header_map.h>
#include <stdbool.h>
#include <stdint.h>
#include <slice99.h>
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Compy_PortPair
 An RTP/RTCP port pair specified as a range, e.g., client_port=3456-3457. More...
 
struct  Compy_ChannelPair
 An RTP/RTCP channel pair specified as a range, e.g., interleaved=4-5. More...
 
struct  Compy_TransportConfig
 The RTSP transport configuration. More...
 

Macros

#define COMPY_CRLF   (CharSlice99_from_str("\r\n"))
 Carriage-return + new-line represented as a data slice.
 
#define COMPY_DEFAULT_PORT   554
 The default RTSP port.
 
#define COMPY_DEFAULT_RTSPS_PORT   322
 The default RTSPS port.
 
#define COMPY_REQUIRE_ONVIF_BACKCHANNEL    (CharSlice99_from_str("www.onvif.org/ver20/backchannel"))
 The ONVIF backchannel feature tag.
 

Typedefs

typedef struct Compy_Context Compy_Context
 

Enumerations

enum  Compy_LowerTransport { Compy_LowerTransport_TCP , Compy_LowerTransport_UDP }
 An RTSP lower transport. More...
 

Functions

const char * Compy_LowerTransport_str (Compy_LowerTransport self)
 Converts self to a string representation ("TCP" for Compy_LowerTransport_TCP and "UDP" for Compy_LowerTransport_UDP).
 
 COMPY_DEF_OPTION (Compy_PortPair)
 Defines Compy_PortPairOption.
 
 COMPY_DEF_OPTION (Compy_ChannelPair)
 Defines Compy_ChannelPairOption.
 
int compy_parse_transport (Compy_TransportConfig *restrict config, CharSlice99 header_value) COMPY_PRIV_MUST_USE
 Parses the Transport header.
 
bool compy_require_has_tag (const Compy_HeaderMap *restrict headers, CharSlice99 tag) COMPY_PRIV_MUST_USE
 Checks whether a Require header is present in headers and contains the feature tag tag.
 
void compy_respond_option_not_supported (Compy_Context *ctx, CharSlice99 tag)
 Responds with 551 Option not supported and an Unsupported header listing tag.
 
uint32_t compy_interleaved_header (uint8_t channel_id, uint16_t payload_len) COMPY_PRIV_MUST_USE
 Returns a four-octet interleaved binary data header.
 
void compy_parse_interleaved_header (const uint8_t data[restrict static 4], uint8_t *restrict channel_id, uint16_t *restrict payload_len)
 Parses an four-octet interleaved binary data header data.
 

Detailed Description

Utilitary stuff.

Macro Definition Documentation

◆ COMPY_REQUIRE_ONVIF_BACKCHANNEL

#define COMPY_REQUIRE_ONVIF_BACKCHANNEL    (CharSlice99_from_str("www.onvif.org/ver20/backchannel"))

The ONVIF backchannel feature tag.

See also
https://www.onvif.org/specs/stream/ONVIF-Streaming-Spec.pdf Section 5.3.1

Enumeration Type Documentation

◆ Compy_LowerTransport

An RTSP lower transport.

Enumerator
Compy_LowerTransport_TCP 

TCP.

Compy_LowerTransport_UDP 

UDP.

Function Documentation

◆ COMPY_DEF_OPTION() [1/2]

COMPY_DEF_OPTION ( Compy_ChannelPair  )

Defines Compy_ChannelPairOption.

See Datatype99 for the macro usage.

◆ COMPY_DEF_OPTION() [2/2]

COMPY_DEF_OPTION ( Compy_PortPair  )

Defines Compy_PortPairOption.

See Datatype99 for the macro usage.

◆ compy_interleaved_header()

uint32_t compy_interleaved_header ( uint8_t  channel_id,
uint16_t  payload_len 
)

Returns a four-octet interleaved binary data header.

Parameters
[in]channel_idThe one-byte channel identifier.
[in]payload_lenThe length of the encapsulated binary data (network byte order).
See also
https://datatracker.ietf.org/doc/html/rfc2326#section-10.12

◆ compy_parse_interleaved_header()

void compy_parse_interleaved_header ( const uint8_t  data[restrict static 4],
uint8_t *restrict  channel_id,
uint16_t *restrict  payload_len 
)

Parses an four-octet interleaved binary data header data.

Parameters
[in]dataThe header to parse.
[out]channel_idThe one-byte channel identifier.
[out]payload_lenThe length of the encapsulated binary data (host byte order).
Precondition
channel_id != NULL
payload_len != NULL
See also
https://datatracker.ietf.org/doc/html/rfc2326#section-10.12

◆ compy_parse_transport()

int compy_parse_transport ( Compy_TransportConfig *restrict  config,
CharSlice99  header_value 
)

Parses the Transport header.

Parameters
[out]configThe result of parsing. It remains unchanged on failure.
[in]header_valueThe value of the Transport header.
Returns
0 on success, -1 on failure.
Precondition
config != NULL

◆ compy_require_has_tag()

bool compy_require_has_tag ( const Compy_HeaderMap *restrict  headers,
CharSlice99  tag 
)

Checks whether a Require header is present in headers and contains the feature tag tag.

The Require header value is compared as a whole against tag (not comma-separated). For multiple tags, check each separately.

Parameters
[in]headersThe request header map.
[in]tagThe feature tag to look for.
Returns
true if the Require header is present and matches tag.
Precondition
headers != NULL

◆ compy_respond_option_not_supported()

void compy_respond_option_not_supported ( Compy_Context ctx,
CharSlice99  tag 
)

Responds with 551 Option not supported and an Unsupported header listing tag.

Use this when a request contains a Require header with a feature tag the server does not understand, per RFC 2326 Section 12.32.

Parameters
[in]ctxThe request context.
[in]tagThe unsupported feature tag value.
Precondition
ctx != NULL