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

An RTSP requests controller. More...

#include <smolrtsp/context.h>
#include <smolrtsp/droppable.h>
#include <smolrtsp/types/request.h>
#include <smolrtsp/writer.h>
#include <stddef.h>
#include <interface99.h>
Include dependency graph for controller.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SmolRTSP_Controller_IFACE
 A controller that handles incoming RTSP requests. More...
 
#define SmolRTSP_Controller_EXTENDS   (SmolRTSP_Droppable)
 The superinterfaces of SmolRTSP_Controller_IFACE.
 

Enumerations

enum  SmolRTSP_ControlFlow { SmolRTSP_ControlFlow_Break , SmolRTSP_ControlFlow_Continue }
 Whether to stop or continue some processing. More...
 

Functions

 interface99 (SmolRTSP_Controller)
 Defines the SmolRTSP_Controller interface. More...
 
void smolrtsp_dispatch (SmolRTSP_Writer conn, SmolRTSP_Controller controller, const SmolRTSP_Request *restrict req)
 Dispatches an incoming request to controller. More...
 

Detailed Description

An RTSP requests controller.

Macro Definition Documentation

◆ SmolRTSP_Controller_IFACE

#define SmolRTSP_Controller_IFACE
Value:
\
/* \
* Handles `OPTIONS` as defined in \
* <https://datatracker.ietf.org/doc/html/rfc2326#section-10.1>. \
*/ \
vfunc99( \
void, options, VSelf99, SmolRTSP_Context *ctx, \
const SmolRTSP_Request *req) \
\
/* \
* Handles `OPTIONS` as defined in \
* <https://datatracker.ietf.org/doc/html/rfc2326#section-10.2>. \
*/ \
vfunc99( \
void, describe, VSelf99, SmolRTSP_Context *ctx, \
const SmolRTSP_Request *req) \
\
/* \
* Handles `OPTIONS` as defined in \
* <https://datatracker.ietf.org/doc/html/rfc2326#section-10.4>. \
*/ \
vfunc99( \
void, setup, VSelf99, SmolRTSP_Context *ctx, \
const SmolRTSP_Request *req) \
\
/* \
* Handles `OPTIONS` as defined in \
* <https://datatracker.ietf.org/doc/html/rfc2326#section-10.5>. \
*/ \
vfunc99( \
void, play, VSelf99, SmolRTSP_Context *ctx, \
const SmolRTSP_Request *req) \
\
/* \
* Handles `OPTIONS` as defined in \
* <https://datatracker.ietf.org/doc/html/rfc2326#section-10.7>. \
*/ \
vfunc99( \
void, teardown, VSelf99, SmolRTSP_Context *ctx, \
const SmolRTSP_Request *req) \
\
/* \
* Handles a command that is neither of the above. \
*/ \
vfunc99( \
void, unknown, VSelf99, SmolRTSP_Context *ctx, \
const SmolRTSP_Request *req) \
\
/* \
* A method that is invoked _before_ the actual request handling. \
*/ \
vfunc99( \
SmolRTSP_ControlFlow, before, VSelf99, SmolRTSP_Context *ctx, \
const SmolRTSP_Request *req) \
\
/* \
* A method that is invoked _after_ request handling. \
*/ \
vfunc99( \
void, after, VSelf99, ssize_t ret, SmolRTSP_Context *ctx, \
const SmolRTSP_Request *req)
struct SmolRTSP_Context SmolRTSP_Context
An opaque type used to conveniently respond to RTSP clients.
Definition: context.h:23
SmolRTSP_ControlFlow
Whether to stop or continue some processing.
Definition: controller.h:20
An RTSP request.
Definition: request.h:21

A controller that handles incoming RTSP requests.

All RTSP command handlers accept the following parameters:

  • ctx – a request context used to respond to your RTSP client.
  • req – a fully parsed request object.

Enumeration Type Documentation

◆ SmolRTSP_ControlFlow

Whether to stop or continue some processing.

Enumerator
SmolRTSP_ControlFlow_Break 

Break processing.

SmolRTSP_ControlFlow_Continue 

Continue processing.

Function Documentation

◆ interface99()

interface99 ( SmolRTSP_Controller  )

Defines the SmolRTSP_Controller interface.

See Interface99 for the macro usage.

◆ smolrtsp_dispatch()

void smolrtsp_dispatch ( SmolRTSP_Writer  conn,
SmolRTSP_Controller  controller,
const SmolRTSP_Request *restrict  req 
)

Dispatches an incoming request to controller.

The algorithm is as follows:

  1. Setup a request context SmolRTSP_Context. Later you can use it to configure an RTSP response via smolrtsp_header, smolrtsp_body, and similar.
  2. Invoke the before method of controller. Here you should do some preliminary stuff like logging a request or setting up initial response headers via smolrtsp_header. If before returns SmolRTSP_ControlFlow_Break, jump to step #4.
  3. Invoke a corresponding command handler of controller. Here you should handle the request and respond to your client via smolrtsp_respond/smolrtsp_respond_ok or similar.
  4. Invoke the after method of controller. Here you automatically receive the return value of smolrtsp_respond_* (invoked during one of the previous steps). If it is <0, it means that something bad happened so that the handler has not been able to respond properly.
  5. Drop the request context.
Parameters
[out]connThe writer to send RTSP responses.
[in]controllerThe controller to handle the incoming request req.
[in]reqThe fully parsed RTSP request object.
Precondition
conn.self && conn.vptr
controller.self && controller.vptr
req != NULL