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

An RTSP header map. More...

#include <compy/priv/compiler_attrs.h>
#include <compy/types/error.h>
#include <compy/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  Compy_HeaderMap
 An RTSP header map. More...
 

Macros

#define Compy_HeaderMap_from_array(...)
 Creates new Compy_HeaderMap from an array expression of Compy_Header.
 
#define COMPY_HEADER_MAP_CAPACITY   32
 The maximum number of headers in Compy_HeaderMap.headers.
 

Functions

Compy_HeaderMap Compy_HeaderMap_empty (void) COMPY_PRIV_MUST_USE
 Returns an empty header map suitable for further parsing.
 
bool Compy_HeaderMap_find (const Compy_HeaderMap *restrict self, CharSlice99 key, CharSlice99 *restrict value) COMPY_PRIV_MUST_USE
 Finds a value associated with key within self.
 
bool Compy_HeaderMap_contains_key (const Compy_HeaderMap *restrict self, CharSlice99 key) COMPY_PRIV_MUST_USE
 Returns whether key is present in self.
 
void Compy_HeaderMap_append (Compy_HeaderMap *restrict self, Compy_Header h)
 Appends a new header to a header map.
 
ssize_t Compy_HeaderMap_serialize (const Compy_HeaderMap *restrict self, Compy_Writer w) COMPY_PRIV_MUST_USE
 Serialises self into w.
 
Compy_ParseResult Compy_HeaderMap_parse (Compy_HeaderMap *restrict self, CharSlice99 input) COMPY_PRIV_MUST_USE
 Parses data to self.
 
bool Compy_HeaderMap_eq (const Compy_HeaderMap *restrict lhs, const Compy_HeaderMap *restrict rhs) COMPY_PRIV_MUST_USE
 Tests lhs and rhs for equality.
 
bool Compy_HeaderMap_is_full (const Compy_HeaderMap *restrict self) COMPY_PRIV_MUST_USE
 Tests whether self is full (no more space left for an additional header) or not.
 
int compy_scanf_header (const Compy_HeaderMap *restrict headers, CharSlice99 key, const char *restrict fmt,...) COMPY_PRIV_MUST_USE COMPY_PRIV_GCC_ATTR(format(scanf
 Attempts to parse a header.
 

Detailed Description

An RTSP header map.

Macro Definition Documentation

◆ Compy_HeaderMap_from_array

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

Creates new Compy_HeaderMap from an array expression of Compy_Header.

Function Documentation

◆ Compy_HeaderMap_append()

void Compy_HeaderMap_append ( Compy_HeaderMap *restrict  self,
Compy_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
!Compy_HeaderMap_is_full(self)

◆ Compy_HeaderMap_contains_key()

bool Compy_HeaderMap_contains_key ( const Compy_HeaderMap *restrict  self,
CharSlice99  key 
)

Returns whether key is present in self.

Precondition
self != NULL

◆ Compy_HeaderMap_eq()

bool Compy_HeaderMap_eq ( const Compy_HeaderMap *restrict  lhs,
const Compy_HeaderMap *restrict  rhs 
)

Tests lhs and rhs for equality.

Precondition
lhs != NULL
rhs != NULL

◆ Compy_HeaderMap_find()

bool Compy_HeaderMap_find ( const Compy_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

◆ Compy_HeaderMap_is_full()

bool Compy_HeaderMap_is_full ( const Compy_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

◆ Compy_HeaderMap_parse()

Compy_ParseResult Compy_HeaderMap_parse ( Compy_HeaderMap *restrict  self,
CharSlice99  input 
)

Parses data to self.

Precondition
self != NULL

◆ Compy_HeaderMap_serialize()

ssize_t Compy_HeaderMap_serialize ( const Compy_HeaderMap *restrict  self,
Compy_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

◆ compy_scanf_header()

int compy_scanf_header ( const Compy_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