SmolRTSP  0.1.3
A small, portable, extensible RTSP 1.0 implementation in C99
header_map.h File Reference

An RTSP header map. More...

#include <smolrtsp/priv/compiler_attrs.h>
#include <smolrtsp/types/error.h>
#include <smolrtsp/types/header.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
#include <slice99.h>
Include dependency graph for header_map.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SmolRTSP_HeaderMap
 An RTSP header map. More...
 

Macros

#define SmolRTSP_HeaderMap_from_array(...)
 Creates new SmolRTSP_HeaderMap from an array expression of SmolRTSP_Header. More...
 
#define SMOLRTSP_HEADER_MAP_CAPACITY   32
 The maximum number of headers in SmolRTSP_HeaderMap.headers.
 

Functions

SmolRTSP_HeaderMap SmolRTSP_HeaderMap_empty (void) SMOLRTSP_PRIV_MUST_USE
 Returns an empty header map suitable for further parsing.
 
bool SmolRTSP_HeaderMap_find (const SmolRTSP_HeaderMap *restrict self, CharSlice99 key, CharSlice99 *restrict value) SMOLRTSP_PRIV_MUST_USE
 Finds a value associated with key within self. More...
 
bool SmolRTSP_HeaderMap_contains_key (const SmolRTSP_HeaderMap *restrict self, CharSlice99 key) SMOLRTSP_PRIV_MUST_USE
 Returns whether key is present in self. More...
 
void SmolRTSP_HeaderMap_append (SmolRTSP_HeaderMap *restrict self, SmolRTSP_Header h)
 Appends a new header to a header map. More...
 
ssize_t SmolRTSP_HeaderMap_serialize (const SmolRTSP_HeaderMap *restrict self, SmolRTSP_Writer w) SMOLRTSP_PRIV_MUST_USE
 Serialises self into w. More...
 
SmolRTSP_ParseResult SmolRTSP_HeaderMap_parse (SmolRTSP_HeaderMap *restrict self, CharSlice99 input) SMOLRTSP_PRIV_MUST_USE
 Parses data to self. More...
 
bool SmolRTSP_HeaderMap_eq (const SmolRTSP_HeaderMap *restrict lhs, const SmolRTSP_HeaderMap *restrict rhs) SMOLRTSP_PRIV_MUST_USE
 Tests lhs and rhs for equality. More...
 
bool SmolRTSP_HeaderMap_is_full (const SmolRTSP_HeaderMap *restrict self) SMOLRTSP_PRIV_MUST_USE
 Tests whether self is full (no more space left for an additional header) or not. More...
 
int smolrtsp_scanf_header (const SmolRTSP_HeaderMap *restrict headers, CharSlice99 key, const char *restrict fmt,...) SMOLRTSP_PRIV_MUST_USE SMOLRTSP_PRIV_GCC_ATTR(format(scanf
 Attempts to parse a header. More...
 

Detailed Description

An RTSP header map.

Macro Definition Documentation

◆ SmolRTSP_HeaderMap_from_array

#define SmolRTSP_HeaderMap_from_array (   ...)
Value:
.headers = __VA_ARGS__, \
.len = SLICE99_ARRAY_LEN((SmolRTSP_Header[])__VA_ARGS__), \
})
An RTSP header map.
Definition: header_map.h:37
An RTSP header.
Definition: header.h:22

Creates new SmolRTSP_HeaderMap from an array expression of SmolRTSP_Header.

Function Documentation

◆ SmolRTSP_HeaderMap_append()

void SmolRTSP_HeaderMap_append ( SmolRTSP_HeaderMap *restrict  self,
SmolRTSP_Header  h 
)

Appends a new header to a header map.

Parameters
[out]selfThe header map to modify.
[in]hThe new header to be appended.
Precondition
self != NULL
!SmolRTSP_HeaderMap_is_full(self)

◆ SmolRTSP_HeaderMap_contains_key()

bool SmolRTSP_HeaderMap_contains_key ( const SmolRTSP_HeaderMap *restrict  self,
CharSlice99  key 
)

Returns whether key is present in self.

Precondition
self != NULL

◆ SmolRTSP_HeaderMap_eq()

bool SmolRTSP_HeaderMap_eq ( const SmolRTSP_HeaderMap *restrict  lhs,
const SmolRTSP_HeaderMap *restrict  rhs 
)

Tests lhs and rhs for equality.

Precondition
lhs != NULL
rhs != NULL

◆ SmolRTSP_HeaderMap_find()

bool SmolRTSP_HeaderMap_find ( const SmolRTSP_HeaderMap *restrict  self,
CharSlice99  key,
CharSlice99 *restrict  value 
)

Finds a value associated with key within self.

If key has been found within self, this function assigns value to this key (no copying occurs) and returns true. Otherwise, returns false and value remains unchanged.

Parameters
[in]selfThe header map to be searched for key.
[in]keyThe key to be searched in self.
[out]valueThe header value to be assigned, if found. If NULL, no assignment is performed.
Precondition
self != NULL

◆ SmolRTSP_HeaderMap_is_full()

bool SmolRTSP_HeaderMap_is_full ( const SmolRTSP_HeaderMap *restrict  self)

Tests whether self is full (no more space left for an additional header) or not.

Returns
true if self is full, false otherwise.
Precondition
self != NULL

◆ SmolRTSP_HeaderMap_parse()

SmolRTSP_ParseResult SmolRTSP_HeaderMap_parse ( SmolRTSP_HeaderMap *restrict  self,
CharSlice99  input 
)

Parses data to self.

Precondition
self != NULL

◆ SmolRTSP_HeaderMap_serialize()

ssize_t SmolRTSP_HeaderMap_serialize ( const SmolRTSP_HeaderMap *restrict  self,
SmolRTSP_Writer  w 
)

Serialises self into w.

Parameters
[in]selfThe instance to be serialised.
[in]wThe writer to be provided with serialised data.
Returns
The number of bytes written or a negative value on error.
Precondition
self != NULL
w.self && w.vptr

◆ smolrtsp_scanf_header()

int smolrtsp_scanf_header ( const SmolRTSP_HeaderMap *restrict  headers,
CharSlice99  key,
const char *restrict  fmt,
  ... 
)

Attempts to parse a header.

Parameters
[in]headersThe header map to search key in.
[in]keyThe header key to search for.
[in]fmtThe scanf-like format string.
Returns
The number of scanned parameters or -1 if key is not found.
Precondition
headers != NULL
fmt != NULL