cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
sdp.c File Reference

Minimal SDP (RFC 4566) parse/generate for DataChannel offers/answers. More...

#include "webrtc_internal.h"
#include <stdio.h>
#include <string.h>
Include dependency graph for sdp.c:

Go to the source code of this file.

Functions

int cwist_sdp_parse (const char *sdp, size_t len, cwist_sdp_info *info)
 Parse an SDP blob into a cwist_sdp_info structure.
 
int cwist_sdp_write_answer (char *out, size_t cap, const char *fingerprint, const char *ufrag, const char *pwd, const char *mid, const char *host, uint16_t port)
 Generate an SDP answer for an ICE-lite DataChannel endpoint.
 
int cwist_sdp_write_offer (char *out, size_t cap, const char *fingerprint, const char *ufrag, const char *pwd, const char *mid)
 Generate an SDP offer for a full (non-lite) DataChannel endpoint.
 

Detailed Description

Minimal SDP (RFC 4566) parse/generate for DataChannel offers/answers.

Supports only the subset of SDP needed for a single SCTP DataChannel m-section: ICE credentials, DTLS fingerprint/setup, mid, and ice-lite. Parsing extracts fields into a cwist_sdp_info struct; generation produces offer or answer strings with CRLF line endings.

Definition in file sdp.c.

Function Documentation

◆ cwist_sdp_parse()

int cwist_sdp_parse ( const char *  sdp,
size_t  len,
cwist_sdp_info *  info 
)

Parse an SDP blob into a cwist_sdp_info structure.

Parse the fields the ICE-lite agent needs from an SDP description.

Parameters
sdpSDP text (not required to be NUL-terminated).
lenLength of sdp in bytes.
infoOutput structure; zeroed first, then filled from recognized lines.
Returns
0 on success, -1 if ice-ufrag or ice-pwd is missing or empty.
Note
Lines longer than 511 bytes are truncated. If an attribute appears more than once, the last occurrence wins. Sets info->has_lite when "a=ice-lite" appears.

Definition at line 43 of file sdp.c.

References cap.

Referenced by cwist_webrtc_handle_offer().

◆ cwist_sdp_write_answer()

int cwist_sdp_write_answer ( char *  out,
size_t  cap,
const char *  fingerprint,
const char *  ufrag,
const char *  pwd,
const char *  mid,
const char *  host,
uint16_t  port 
)

Generate an SDP answer for an ICE-lite DataChannel endpoint.

Write an ICE-lite, DTLS-passive DataChannel answer.

Parameters
outOutput buffer, receives CRLF-terminated SDP answer.
capCapacity of out in bytes.
fingerprintDTLS certificate fingerprint (hex, colon-separated).
ufragICE username fragment.
pwdICE password.
midMedia section ID (also used in the BUNDLE group).
hostLocal host address for the a=candidate line.
portLocal UDP port for the a=candidate line.
Returns
0 on success, -1 if the output was truncated or encoding failed.
Note
Declares ice-lite and hardcodes a=setup:passive, since the ICE-lite answering endpoint takes the passive DTLS role, and emits a single host candidate followed by end-of-candidates.

Definition at line 129 of file sdp.c.

References cap.

Referenced by cwist_webrtc_handle_offer().

◆ cwist_sdp_write_offer()

int cwist_sdp_write_offer ( char *  out,
size_t  cap,
const char *  fingerprint,
const char *  ufrag,
const char *  pwd,
const char *  mid 
)

Generate an SDP offer for a full (non-lite) DataChannel endpoint.

Write a DTLS-active DataChannel offer (loopback tests).

Parameters
outOutput buffer, receives CRLF-terminated SDP offer.
capCapacity of out in bytes.
fingerprintDTLS certificate fingerprint (hex, colon-separated).
ufragICE username fragment.
pwdICE password.
midMedia section ID (also used in the BUNDLE group).
Returns
0 on success, -1 if the output was truncated or encoding failed.
Note
Thin wrapper over write_session() with setup "active", no ice-lite, and a fixed session ID; the full agent offering endpoint takes the active DTLS role.

Definition at line 168 of file sdp.c.

References cap.