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

A request context. More...

#include <compy/droppable.h>
#include <compy/priv/compiler_attrs.h>
#include <compy/types/message_body.h>
#include <compy/types/status_code.h>
#include <compy/writer.h>
#include <stdarg.h>
#include <stdint.h>
#include <interface99.h>
#include <slice99.h>
Include dependency graph for context.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct Compy_Context Compy_Context
 An opaque type used to conveniently respond to RTSP clients.
 

Functions

Compy_ContextCompy_Context_new (Compy_Writer w, uint32_t cseq) COMPY_PRIV_MUST_USE
 Creates a new Compy context.
 
Compy_Writer Compy_Context_get_writer (const Compy_Context *ctx) COMPY_PRIV_MUST_USE
 Retrieves the writer specified in Compy_Context_new.
 
uint32_t Compy_Context_get_cseq (const Compy_Context *ctx) COMPY_PRIV_MUST_USE
 Retrieves cseq specified in Compy_Context_new.
 
ssize_t Compy_Context_get_ret (const Compy_Context *ctx) COMPY_PRIV_MUST_USE
 Retrieves the RTSP respond return value.
 
void compy_vheader (Compy_Context *ctx, CharSlice99 key, const char *restrict fmt, va_list list) COMPY_PRIV_GCC_ATTR(format(printf
 Appends an RTSP header to the request context.
 
void void compy_header (Compy_Context *ctx, CharSlice99 key, const char *restrict fmt,...) COMPY_PRIV_GCC_ATTR(format(printf
 The compy_vheader twin.
 
void void void compy_body (Compy_Context *ctx, Compy_MessageBody body)
 Sets an RTSP body in the request context.
 
ssize_t compy_respond (Compy_Context *ctx, Compy_StatusCode code, const char *reason)
 Writes an RTSP response to the underlying writer.
 
ssize_t compy_respond_ok (Compy_Context *ctx)
 A shortcut for compy_respond(ctx, COMPY_STATUS_OK, "OK").
 
ssize_t compy_respond_internal_error (Compy_Context *ctx)
 A shortcut for compy_respond(ctx, COMPY_STATUS_INTERNAL_SERVER_ERROR, "Internal error").
 
 declImplExtern99 (Compy_Droppable, Compy_Context)
 Implements Compy_Droppable_IFACE for Compy_Context.
 

Detailed Description

A request context.

Function Documentation

◆ compy_body()

void void void compy_body ( Compy_Context ctx,
Compy_MessageBody  body 
)

Sets an RTSP body in the request context.

Parameters
[out]ctxThe request context to modify.
[in]bodyThe RTSP body.
Precondition
ctx != NULL

◆ Compy_Context_get_cseq()

uint32_t Compy_Context_get_cseq ( const Compy_Context ctx)

Retrieves cseq specified in Compy_Context_new.

Precondition
ctx != NULL

◆ Compy_Context_get_ret()

ssize_t Compy_Context_get_ret ( const Compy_Context ctx)

Retrieves the RTSP respond return value.

If you have not responded yet, the result is 0.

Precondition
ctx != NULL

◆ Compy_Context_get_writer()

Compy_Writer Compy_Context_get_writer ( const Compy_Context ctx)

Retrieves the writer specified in Compy_Context_new.

Precondition
ctx != NULL

◆ Compy_Context_new()

Compy_Context * Compy_Context_new ( Compy_Writer  w,
uint32_t  cseq 
)

Creates a new Compy context.

Parameters
[in]wThe writer to be provided with the response.
[in]cseqThe sequence number for an RTSP request/response pair.
Precondition
w.self && w.vptr

◆ compy_respond()

ssize_t compy_respond ( Compy_Context ctx,
Compy_StatusCode  code,
const char *  reason 
)

Writes an RTSP response to the underlying writer.

The CSeq and Content-Length headers will be written automatically as first headers.

Parameters
[out]ctxThe request context to write the response to.
[in]codeThe RTSP status code.
[in]reasonThe RTSP reason phrase.
Precondition
ctx != NULL
reason is a null-terminated string.
Returns
The number of bytes written or a negative value on error.

◆ compy_vheader()

void compy_vheader ( Compy_Context ctx,
CharSlice99  key,
const char *restrict  fmt,
va_list  list 
)

Appends an RTSP header to the request context.

Parameters
[out]ctxThe request context to modify.
[in]keyThe header key.
[in]fmtThe printf-like format string (header value).
[in]listThe variadic function arguments.
Precondition
ctx != NULL
ctx must contain strictly less than COMPY_HEADER_MAP_CAPACITY headers.
fmt != NULL

◆ declImplExtern99()

declImplExtern99 ( Compy_Droppable  ,
Compy_Context   
)

Implements Compy_Droppable_IFACE for Compy_Context.

See Interface99 for the macro usage.