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

A request context. More...

#include <smolrtsp/droppable.h>
#include <smolrtsp/priv/compiler_attrs.h>
#include <smolrtsp/types/message_body.h>
#include <smolrtsp/types/status_code.h>
#include <smolrtsp/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 SmolRTSP_Context SmolRTSP_Context
 An opaque type used to conveniently respond to RTSP clients.
 

Functions

SmolRTSP_ContextSmolRTSP_Context_new (SmolRTSP_Writer w, uint32_t cseq) SMOLRTSP_PRIV_MUST_USE
 Creates a new SmolRTSP context. More...
 
SmolRTSP_Writer SmolRTSP_Context_get_writer (const SmolRTSP_Context *ctx) SMOLRTSP_PRIV_MUST_USE
 Retrieves the writer specified in SmolRTSP_Context_new. More...
 
uint32_t SmolRTSP_Context_get_cseq (const SmolRTSP_Context *ctx) SMOLRTSP_PRIV_MUST_USE
 Retrieves cseq specified in SmolRTSP_Context_new. More...
 
ssize_t SmolRTSP_Context_get_ret (const SmolRTSP_Context *ctx) SMOLRTSP_PRIV_MUST_USE
 Retrieves the RTSP respond return value. More...
 
void smolrtsp_vheader (SmolRTSP_Context *ctx, CharSlice99 key, const char *restrict fmt, va_list list) SMOLRTSP_PRIV_GCC_ATTR(format(printf
 Appends an RTSP header to the request context. More...
 
void void smolrtsp_header (SmolRTSP_Context *ctx, CharSlice99 key, const char *restrict fmt,...) SMOLRTSP_PRIV_GCC_ATTR(format(printf
 The smolrtsp_vheader twin.
 
void void void smolrtsp_body (SmolRTSP_Context *ctx, SmolRTSP_MessageBody body)
 Sets an RTSP body in the request context. More...
 
ssize_t smolrtsp_respond (SmolRTSP_Context *ctx, SmolRTSP_StatusCode code, const char *reason)
 Writes an RTSP response to the underlying writer. More...
 
ssize_t smolrtsp_respond_ok (SmolRTSP_Context *ctx)
 A shortcut for smolrtsp_respond(ctx, SMOLRTSP_STATUS_OK, "OK").
 
ssize_t smolrtsp_respond_internal_error (SmolRTSP_Context *ctx)
 A shortcut for smolrtsp_respond(ctx, SMOLRTSP_STATUS_INTERNAL_SERVER_ERROR, "Internal error").
 
 declImplExtern99 (SmolRTSP_Droppable, SmolRTSP_Context)
 Implements SmolRTSP_Droppable_IFACE for SmolRTSP_Context. More...
 

Detailed Description

A request context.

Function Documentation

◆ declImplExtern99()

declImplExtern99 ( SmolRTSP_Droppable  ,
SmolRTSP_Context   
)

Implements SmolRTSP_Droppable_IFACE for SmolRTSP_Context.

See Interface99 for the macro usage.

◆ smolrtsp_body()

void void void smolrtsp_body ( SmolRTSP_Context ctx,
SmolRTSP_MessageBody  body 
)

Sets an RTSP body in the request context.

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

◆ SmolRTSP_Context_get_cseq()

uint32_t SmolRTSP_Context_get_cseq ( const SmolRTSP_Context ctx)

Retrieves cseq specified in SmolRTSP_Context_new.

Precondition
ctx != NULL

◆ SmolRTSP_Context_get_ret()

ssize_t SmolRTSP_Context_get_ret ( const SmolRTSP_Context ctx)

Retrieves the RTSP respond return value.

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

Precondition
ctx != NULL

◆ SmolRTSP_Context_get_writer()

SmolRTSP_Writer SmolRTSP_Context_get_writer ( const SmolRTSP_Context ctx)

Retrieves the writer specified in SmolRTSP_Context_new.

Precondition
ctx != NULL

◆ SmolRTSP_Context_new()

SmolRTSP_Context* SmolRTSP_Context_new ( SmolRTSP_Writer  w,
uint32_t  cseq 
)

Creates a new SmolRTSP 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

◆ smolrtsp_respond()

ssize_t smolrtsp_respond ( SmolRTSP_Context ctx,
SmolRTSP_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.

◆ smolrtsp_vheader()

void smolrtsp_vheader ( SmolRTSP_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 SMOLRTSP_HEADER_MAP_CAPACITY headers.
fmt != NULL