sync with trunk

This commit is contained in:
Richard Aas 2011-12-08 13:59:02 +00:00
commit 1495f02e3e
21 changed files with 623 additions and 26 deletions

View file

@ -5,6 +5,7 @@
*/
/** BFCP Version */
enum {BFCP_VERSION = 1};
/** BFCP Primitives */
@ -71,6 +72,7 @@ enum bfcp_err {
BFCP_ERR_USE_TLS = 9
};
/** BFCP Priority */
enum bfcp_prio {
BFCP_PRIO_LOWEST = 0,
BFCP_PRIO_LOW = 1,
@ -79,51 +81,60 @@ enum bfcp_prio {
BFCP_PRIO_HIGHEST = 4
};
/** BFCP Request status */
struct bfcp_reqstat {
enum bfcp_rstat stat;
uint8_t qpos;
};
/** BFCP Error code */
struct bfcp_errcode {
enum bfcp_err code;
uint8_t *details; /* optional */
size_t len;
};
/** BFCP supported attributes */
struct bfcp_supattr {
enum bfcp_attrib *attrv;
size_t attrc;
};
/** BFCP supported primitives */
struct bfcp_supprim {
enum bfcp_prim *primv;
size_t primc;
};
/** BFCP overall request status */
struct bfcp_overall_reqstat {
uint16_t freqid;
struct bfcp_reqstat reqstat;
char *statinfo;
};
/** BFCP beneficiary information */
struct bfcp_beneficiary_info {
uint16_t bfid;
char *dname;
char *uri;
};
/** BFCP requested by information */
struct bfcp_reqby_info {
uint16_t rbid;
char *dname;
char *uri;
};
/** BFCP floor request status */
struct bfcp_floor_reqstat {
uint16_t floorid;
struct bfcp_reqstat reqstat;
char *statinfo;
};
/** BFCP floor request info */
struct bfcp_floor_reqinfo {
uint16_t freqid;
struct bfcp_overall_reqstat ors;
@ -135,6 +146,7 @@ struct bfcp_floor_reqinfo {
char *ppi;
};
/** BFCP Attribute */
struct bfcp_attr {
struct le le;
enum bfcp_attrib type;
@ -168,6 +180,7 @@ struct bfcp_attr {
} v;
};
/** BFCP Transport */
enum bfcp_transp {
BFCP_TRANSP_TCP = 0,
BFCP_TRANSP_TLS = 1
@ -178,6 +191,14 @@ enum bfcp_transp {
struct bfcp_msg;
/**
* Defines the BFCP attribute handler
*
* @param attr BFCP attribute
* @param arg Handler argument
*
* @return True to stop processing, false to continue
*/
typedef bool (bfcp_attr_h)(const struct bfcp_attr *attr, void *arg);
int bfcp_msg_vencode(struct mbuf *mb, enum bfcp_prim prim,
@ -185,7 +206,8 @@ int bfcp_msg_vencode(struct mbuf *mb, enum bfcp_prim prim,
uint32_t attrc, va_list ap);
int bfcp_msg_encode(struct mbuf *mb, enum bfcp_prim prim, uint32_t confid,
uint16_t tid, uint16_t userid, uint32_t attrc, ...);
int bfcp_msg_decode(struct bfcp_msg **msgp, struct mbuf *mb);
int bfcp_msg_decode(struct bfcp_msg **msgp, struct mbuf *mb,
const struct sa *src);
struct bfcp_attr *bfcp_msg_attr(const struct bfcp_msg *msg,
enum bfcp_attrib type);
struct bfcp_attr *bfcp_msg_attr_apply(const struct bfcp_msg *msg,
@ -195,7 +217,6 @@ enum bfcp_prim bfcp_msg_prim(const struct bfcp_msg *msg);
uint32_t bfcp_msg_confid(const struct bfcp_msg *msg);
uint16_t bfcp_msg_tid(const struct bfcp_msg *msg);
uint16_t bfcp_msg_userid(const struct bfcp_msg *msg);
void bfcp_msg_set_src(struct bfcp_msg *msg, const struct sa *src);
const struct sa *bfcp_msg_src(const struct bfcp_msg *msg);
@ -219,7 +240,21 @@ struct tls;
struct bfcp_sock;
struct bfcp_ctrans;
/**
* Defines the BFCP message handler
*
* @param msg BFCP message
* @param arg Handler argument
*/
typedef void (bfcp_msg_h)(const struct bfcp_msg *msg, void *arg);
/**
* Defines the BFCP response handler
*
* @param err Error code
* @param msg BFCP message
* @param arg Handler argument
*/
typedef void (bfcp_resp_h)(int err, const struct bfcp_msg *msg, void *arg);

View file

@ -4,16 +4,20 @@
* Copyright (C) 2010 Creytiv.com
*/
/** ICE mode */
enum ice_mode {
ICE_MODE_FULL,
ICE_MODE_LITE
};
/** ICE Component ID */
enum ice_compid {
ICE_COMPID_RTP = 1,
ICE_COMPID_RTCP = 2
};
/** ICE Nomination */
enum ice_nomination {
ICE_NOMINATION_REGULAR = 0,
ICE_NOMINATION_AGGRESSIVE

View file

@ -79,8 +79,9 @@ int nat_filtering_start(struct nat_filtering *nf);
* Binding Lifetime Discovery
*/
/** Defines the NAT lifetime interval */
struct nat_lifetime;
/** Defines the NAT lifetime interval */
struct nat_lifetime_interval {
uint32_t min; /**< Minimum lifetime interval in [seconds] */
uint32_t cur; /**< Current lifetime interval in [seconds] */

127
mk/CMakeLists.txt Normal file
View file

@ -0,0 +1,127 @@
cmake_minimum_required(VERSION 2.8.2)
project(re)
set(CMAKE_VERBOSE_MAKEFILE ON)
SET(RE_ROOT ${PROJECT_SOURCE_DIR}/..)
SET(RE_SRC_PREFIX ../src)
# include header files for the IDEs
file(GLOB_RECURSE HEADER_FILES src/*.h include/*.h)
if(UNIX)
# get make db and extract information via regex's
execute_process(COMMAND make --no-print-directory --just-print --print-data-base info OUTPUT_VARIABLE RE_MAKEDB OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${RE_ROOT})
# get list of source files in SRCS = ...
STRING(REGEX MATCH "[\n\r]SRCS = ([^\n\r]+)" RE_SRCS "${RE_MAKEDB}")
STRING(REGEX REPLACE "[\n\r]SRCS = " "" RE_SRCS "${RE_SRCS}")
# convert into list and prefix every element with 'src/'
SET(RE_SRCS "${RE_SRC_PREFIX}/${RE_SRCS}")
STRING(REPLACE " " ";${RE_SRC_PREFIX}/" RE_SRCS ${RE_SRCS})
# get CFLAGS
STRING(REGEX MATCH "[\n\r]CFLAGS = ([^\n\r]+)" RE_CFLAGS "${RE_MAKEDB}")
STRING(REGEX REPLACE "[\n\r]CFLAGS = " "" RE_CFLAGS "${RE_CFLAGS}")
# remove anything that is not a macro define
STRING(REGEX REPLACE "-[^D][^ ]*" "" RE_CFLAGS "${RE_CFLAGS}" )
# get EXTRA_CFLAGS
STRING(REGEX MATCH "[\n\r]EXTRA_CFLAGS := ([^\n\r]+)" RE_EXTRA_CFLAGS "${RE_MAKEDB}")
STRING(REGEX REPLACE "[\n\r]EXTRA_CFLAGS := " "" RE_EXTRA_CFLAGS "${RE_EXTRA_CFLAGS}")
if (RE_EXTRA_CFLAGS)
# not tested
STRING(REGEX REPLACE "\\$\\(EXTRA_CFLAGS\\)" ${RE_EXTRA_CFLAGS} RE_CFLAGS "${RE_CFLAGS}")
else()
STRING(REGEX REPLACE "\\$\\(EXTRA_CFLAGS\\)" "" RE_CFLAGS "${RE_CFLAGS}")
endif()
# get OS
STRING(REGEX MATCH "[\n\r]OS := ([^\n\r]+)" RE_OS "${RE_MAKEDB}")
STRING(REGEX REPLACE "[\n\r]OS := " "" RE_OS "${RE_OS}")
STRING(REGEX REPLACE "\\$\\(OS\\)" ${RE_OS} RE_CFLAGS "${RE_CFLAGS}")
# get VERSION
STRING(REGEX MATCH "[\n\r]VERSION := ([^\n\r]+)" RE_VERSION "${RE_MAKEDB}")
STRING(REGEX REPLACE "[\n\r]VERSION := " "" RE_VERSION "${RE_VERSION}")
STRING(REGEX REPLACE "\\$\\(VERSION\\)" ${RE_VERSION} RE_CFLAGS "${RE_CFLAGS}")
# get ARCH
STRING(REGEX MATCH "[\n\r]ARCH := ([^\n\r]+)" RE_ARCH "${RE_MAKEDB}")
STRING(REGEX REPLACE "[\n\r]ARCH := " "" RE_ARCH "${RE_ARCH}")
STRING(REGEX REPLACE "\\$\\(ARCH\\)" ${RE_ARCH} RE_CFLAGS "${RE_CFLAGS}")
# escaping '\': makefiles do need it, but it breaks xcode - not sure who's "right"
if (CMAKE_GENERATOR MATCHES Xcode)
STRING(REGEX REPLACE "\\\\" "" RE_CFLAGS "${RE_CFLAGS}" )
endif()
message("libre sources: ${RE_SRCS}")
message("libre cflags: ${RE_CFLAGS}")
message("libre extra_cflags: ${RE_EXTRA_CFLAGS}")
message("libre OS: ${RE_OS}")
message("libre arch: ${RE_ARCH}")
message("libre version: ${RE_VERSION}")
elseif(WIN32)
# hard-coded on Win32
if(MSVC)
SET(RE_CFLAGS
"-DWIN32 -D_CONSOLE -D_CRT_SECURE_NO_DEPRECATE -DHAVE_SELECT -DHAVE_IO_H"
)
elseif(MINGW)
SET(RE_CFLAGS
"-DHAVE_STDBOOL_H -DHAVE_INET6 -DHAVE_SELECT -DHAVE_IO_H"
)
add_definitions(-Wall -D_WIN32_WINNT=0x0501)
endif()
# quotes get eaten in generator
add_definitions(-DOS=\"win32\" -DWIN32 -DARCH=\"i386\" -DVERSION=\"0.3.0\")
# on windows we cannot rely on make and have to do this by hand
file(GLOB_RECURSE RE_SRCS RELATIVE ${PROJECT_SOURCE_DIR} ${RE_ROOT}/src/*.c)
# remove files to compile depending on the compiler flags
if (RE_CFLAGS MATCHES USE_ZLIB)
LIST(REMOVE_ITEM RE_SRCS "${RE_SRC_PREFIX}/crc32/crc32.c")
endif()
if (NOT RE_CFLAGS MATCHES HAVE_PTHREAD_RWLOCK)
LIST(REMOVE_ITEM RE_SRCS "${RE_SRC_PREFIX}/lock/rwlock.c")
endif()
if (NOT RE_CFLAGS MATCHES HAVE_GETIFADDRS)
LIST(REMOVE_ITEM RE_SRCS "${RE_SRC_PREFIX}/net/ifaddrs.c")
endif()
if (NOT RE_CFLAGS MATCHES HAVE_EPOLL)
LIST(REMOVE_ITEM RE_SRCS "${RE_SRC_PREFIX}/main/epoll.c")
endif()
if (NOT RE_CFLAGS MATCHES USE_OPENSSL)
LIST(REMOVE_ITEM RE_SRCS "${RE_SRC_PREFIX}/tls/openssl/tls.c")
LIST(REMOVE_ITEM RE_SRCS "${RE_SRC_PREFIX}/tls/openssl/tls_tcp.c")
endif()
if (NOT RE_CFLAGS MATCHES HAVE_PTHREAD)
LIST(REMOVE_ITEM RE_SRCS "${RE_SRC_PREFIX}/lock/lock.c")
endif()
# remove files not to be comiled for win32 in any case
LIST(REMOVE_ITEM RE_SRCS "${RE_SRC_PREFIX}/httpauth/basic.c")
LIST(REMOVE_ITEM RE_SRCS "${RE_SRC_PREFIX}/mod/dl.c")
LIST(REMOVE_ITEM RE_SRCS "${RE_SRC_PREFIX}/net/posix/pif.c")
LIST(REMOVE_ITEM RE_SRCS "${RE_SRC_PREFIX}/net/linux/rt.c")
LIST(REMOVE_ITEM RE_SRCS "${RE_SRC_PREFIX}/dns/res.c")
LIST(REMOVE_ITEM RE_SRCS "${RE_SRC_PREFIX}/dns/darwin/srv.c")
LIST(REMOVE_ITEM RE_SRCS "${RE_SRC_PREFIX}/net/bsd/brt.c")
endif()
include_directories(${RE_ROOT}/include)
add_library(re ${RE_SRCS} ${HEADER_FILES})
SET_TARGET_PROPERTIES(re PROPERTIES
COMPILE_FLAGS ${RE_CFLAGS}
)

View file

@ -92,7 +92,6 @@ EXCLUDE = test.c \
src/md5/md5.h src/md5/md5.c \
src/dns include/re_dns.h \
src/httpauth include/re_httpauth.h \
src/ice include/re_ice.h \
src/sdp include/re_sdp.h \
src/sip/ include/re_sip.h \
src/sipsess/ include/re_sipsess.h \

View file

@ -482,11 +482,19 @@ ifneq ($(HAVE_SYSLOG),)
CFLAGS += -DHAVE_SYSLOG
endif
HAVE_INET_NTOP := 1
CFLAGS += -DHAVE_FORK
ifneq ($(HAVE_INET_NTOP),)
CFLAGS += -DHAVE_INET_NTOP
endif
CFLAGS += -DHAVE_PWD_H
ifneq ($(OS),darwin)
CFLAGS += -DHAVE_POLL # Darwin: poll() does not support devices
HAVE_INET_PTON := 1
endif
ifneq ($(HAVE_INET_PTON),)
CFLAGS += -DHAVE_INET_PTON
endif
CFLAGS += -DHAVE_SELECT -DHAVE_SELECT_H

View file

@ -535,6 +535,13 @@ int bfcp_attr_decode(struct bfcp_attr **attrp, struct mbuf *mb)
}
/**
* Get the BFCP attribute name
*
* @param attr BFCP attribute
*
* @return String with BFCP attribute name
*/
const char *bfcp_attr_name(enum bfcp_attrib attr)
{
switch (attr) {
@ -738,6 +745,13 @@ bool bfcp_attr_isgrouped(enum bfcp_attrib attr)
}
/**
* Get the BFCP Error code name
*
* @param code BFCP Error code
*
* @return String with error code
*/
const char *bfcp_errcode_name(enum bfcp_err code)
{
switch (code) {

View file

@ -29,6 +29,19 @@ static void destructor(void *arg)
}
/**
* Encode a BFCP message with variable arguments
*
* @param mb Mbuf to encode into
* @param prim BFCP Primitive
* @param confid Conference ID
* @param tid Transaction ID
* @param userid User ID
* @param attrc Number of attributes
* @param ap Variable argument of attributes
*
* @return 0 if success, otherwise errorcode
*/
int bfcp_msg_vencode(struct mbuf *mb, enum bfcp_prim prim,
uint32_t confid, uint16_t tid, uint16_t userid,
uint32_t attrc, va_list ap)
@ -69,6 +82,18 @@ int bfcp_msg_vencode(struct mbuf *mb, enum bfcp_prim prim,
}
/**
* Encode a BFCP message
*
* @param mb Mbuf to encode into
* @param prim BFCP Primitive
* @param confid Conference ID
* @param tid Transaction ID
* @param userid User ID
* @param attrc Number of attributes
*
* @return 0 if success, otherwise errorcode
*/
int bfcp_msg_encode(struct mbuf *mb, enum bfcp_prim prim, uint32_t confid,
uint16_t tid, uint16_t userid, uint32_t attrc, ...)
{
@ -83,7 +108,17 @@ int bfcp_msg_encode(struct mbuf *mb, enum bfcp_prim prim, uint32_t confid,
}
int bfcp_msg_decode(struct bfcp_msg **msgp, struct mbuf *mb)
/**
* Decode a BFCP message from a buffer
*
* @param msgp Pointer to allocated and decoded BFCP message
* @param mb Mbuf to decode from
* @param src Source network address (optional)
*
* @return 0 if success, otherwise errorcode
*/
int bfcp_msg_decode(struct bfcp_msg **msgp, struct mbuf *mb,
const struct sa *src)
{
struct bfcp_msg *msg;
size_t start, extra;
@ -117,6 +152,9 @@ int bfcp_msg_decode(struct bfcp_msg **msgp, struct mbuf *mb)
list_append(&msg->attrl, &attr->le, attr);
}
if (src)
msg->src = *src;
out:
if (err)
mem_deref(msg);
@ -129,10 +167,18 @@ int bfcp_msg_decode(struct bfcp_msg **msgp, struct mbuf *mb)
static bool attr_match(const struct bfcp_attr *attr, void *arg)
{
return attr->type == *(uint8_t *)arg;
return attr->type == *(enum bfcp_attrib *)arg;
}
/**
* Get a BFCP attribute from a BFCP message
*
* @param msg BFCP message
* @param type Attribute type
*
* @return Matching BFCP attribute if found, otherwise NULL
*/
struct bfcp_attr *bfcp_msg_attr(const struct bfcp_msg *msg,
enum bfcp_attrib type)
{
@ -140,6 +186,15 @@ struct bfcp_attr *bfcp_msg_attr(const struct bfcp_msg *msg,
}
/**
* Apply a function handler to all attributes in a BFCP message
*
* @param msg BFCP message
* @param h Handler
* @param arg Handler argument
*
* @return BFCP attribute returned by handler, or NULL
*/
struct bfcp_attr *bfcp_msg_attr_apply(const struct bfcp_msg *msg,
bfcp_attr_h *h, void *arg)
{
@ -166,6 +221,14 @@ static bool attr_print(const struct bfcp_attr *attr, void *arg)
}
/**
* Print a BFCP message
*
* @param pf Print function
* @param msg BFCP message
*
* @return 0 if success, otherwise errorcode
*/
int bfcp_msg_print(struct re_printf *pf, const struct bfcp_msg *msg)
{
int err;
@ -183,30 +246,65 @@ int bfcp_msg_print(struct re_printf *pf, const struct bfcp_msg *msg)
}
/**
* Get the BFCP primitive of a BFCP message
*
* @param msg BFCP message
*
* @return The BFCP primitive
*/
enum bfcp_prim bfcp_msg_prim(const struct bfcp_msg *msg)
{
return msg ? msg->hdr.prim : 0;
}
/**
* Get the Conference ID of a BFCP message
*
* @param msg BFCP message
*
* @return The Conference ID
*/
uint32_t bfcp_msg_confid(const struct bfcp_msg *msg)
{
return msg ? msg->hdr.confid : 0;
}
/**
* Get the Transaction ID of a BFCP message
*
* @param msg BFCP message
*
* @return The Transaction ID
*/
uint16_t bfcp_msg_tid(const struct bfcp_msg *msg)
{
return msg ? msg->hdr.tid : 0;
}
/**
* Get the User ID of a BFCP message
*
* @param msg BFCP message
*
* @return The User ID
*/
uint16_t bfcp_msg_userid(const struct bfcp_msg *msg)
{
return msg ? msg->hdr.userid : 0;
}
/**
* Get the BFCP Request status name
*
* @param rstat Request status
*
* @return String with BFCP Request status name
*/
const char *bfcp_reqstat_name(enum bfcp_rstat rstat)
{
switch (rstat) {
@ -223,6 +321,13 @@ const char *bfcp_reqstat_name(enum bfcp_rstat rstat)
}
/**
* Get the BFCP primitive name
*
* @param prim BFCP primitive
*
* @return String with BFCP primitive name
*/
const char *bfcp_prim_name(enum bfcp_prim prim)
{
switch (prim) {
@ -245,15 +350,13 @@ const char *bfcp_prim_name(enum bfcp_prim prim)
}
void bfcp_msg_set_src(struct bfcp_msg *msg, const struct sa *src)
{
if (!msg || !src)
return;
msg->src = *src;
}
/**
* Get the source network address of a BFCP message
*
* @param msg BFCP message
*
* @return Source network address
*/
const struct sa *bfcp_msg_src(const struct bfcp_msg *msg)
{
return msg ? &msg->src : NULL;

View file

@ -14,6 +14,16 @@
#include "bfcp.h"
/**
* Send BFCP reply
*
* @param sock BFCP socket
* @param req BFCP request to reply to
* @param prim BFCP primitive
* @param attrc Number of attributes
*
* @return 0 if success, otherwise errorcode
*/
int bfcp_reply(struct bfcp_sock *sock, const struct bfcp_msg *req,
enum bfcp_prim prim, uint32_t attrc, ...)
{
@ -48,6 +58,15 @@ int bfcp_reply(struct bfcp_sock *sock, const struct bfcp_msg *req,
}
/**
* Send BFCP error reply
*
* @param sock BFCP socket
* @param req BFCP request to reply to
* @param code BFCP Error code
*
* @return 0 if success, otherwise errorcode
*/
int bfcp_ereply(struct bfcp_sock *sock, const struct bfcp_msg *req,
enum bfcp_err code, ...)
{

View file

@ -107,6 +107,21 @@ struct bfcp_ctrans *bfcp_ctrans_find(struct bfcp_sock *sock, uint16_t tid)
}
/**
* Send a BFCP request with variable number of attributes
*
* @param ctp Pointer to allocated transaction (optional)
* @param sock BFCP socket
* @param dst Destination network address
* @param prim BFCP primitive
* @param confid Conference ID
* @param userid User ID
* @param resph Response handler (optional)
* @param arg Handler argument
* @param attrc Number of BFCP attributes
*
* @return 0 if success, otherwise errorcode
*/
int bfcp_request(struct bfcp_ctrans **ctp, struct bfcp_sock *sock,
const struct sa *dst,
enum bfcp_prim prim, uint32_t confid, uint16_t userid,

View file

@ -126,7 +126,7 @@ static void tcp_recv_handler(struct mbuf *mb, void *arg)
pos = conn->mbrx->pos;
err = bfcp_msg_decode(&msg, conn->mbrx);
err = bfcp_msg_decode(&msg, conn->mbrx, &conn->paddr);
if (err) {
if (err == ENODATA) {
conn->mbrx->pos = pos;
@ -135,8 +135,6 @@ static void tcp_recv_handler(struct mbuf *mb, void *arg)
break;
}
bfcp_msg_set_src(msg, &conn->paddr);
ct = bfcp_ctrans_find(conn->bs, bfcp_msg_tid(msg));
if (ct) {
bfcp_ctrans_completed(ct, 0, msg);
@ -217,6 +215,18 @@ static struct bfcp_conn *findconn(const struct bfcp_sock *bs,
}
/**
* Listen on a BFCP socket
*
* @param sockp Pointer to allocated BFCP socket object
* @param transp BFCP transport
* @param tls TLS context, used for secure transport (optional)
* @param laddr Local network address (optional)
* @param msgh BFCP message handler (optional)
* @param arg Handler argument
*
* @return 0 if success, otherwise errorcode
*/
int bfcp_listen(struct bfcp_sock **sockp, enum bfcp_transp transp,
struct tls *tls, const struct sa *laddr,
bfcp_msg_h *msgh, void *arg)

View file

@ -16,6 +16,13 @@
#include "bfcp.h"
/**
* Check if BFCP transport is reliable
*
* @param tp BFCP transport
*
* @return True if reliable, false if un-reliable
*/
bool bfcp_transp_reliable(enum bfcp_transp tp)
{
switch (tp) {
@ -27,6 +34,13 @@ bool bfcp_transp_reliable(enum bfcp_transp tp)
}
/**
* Get the BFCP Transport protocol, suitable for SDP
*
* @param tp BFCP transport
*
* @return String with BFCP transport protocol
*/
const char *bfcp_transp_proto(enum bfcp_transp tp)
{
switch (tp) {

View file

@ -260,6 +260,9 @@ bool icem_candpair_iscompleted(const struct candpair *cp)
/**
* Compare local and remote candidates of two candidate pairs
*
* @param cp1 First Candidate pair
* @param cp2 Second Candidate pair
*
* @return true if match
*/
bool icem_candpair_cmp(const struct candpair *cp1, const struct candpair *cp2)
@ -275,6 +278,12 @@ bool icem_candpair_cmp(const struct candpair *cp1, const struct candpair *cp2)
* Find the highest-priority candidate-pair in a given list, with
* optional match parameters
*
* @param lst List of candidate pairs
* @param lcand Local candidate (optional)
* @param rcand Remote candidate (optional)
*
* @return Matching candidate pair if found, otherwise NULL
*
* note: assume list is sorted by priority
*/
struct candpair *icem_candpair_find(const struct list *lst,

View file

@ -138,6 +138,10 @@ static void candpair_set_states(struct icem *icem)
* the agent forms candidate pairs, computes a candidate pair priority,
* orders the pairs by priority, prunes them, and sets their states.
* These steps are described in this section.
*
* @param icem ICE Media object
*
* @return 0 if success, otherwise errorcode
*/
int icem_checklist_form(struct icem *icem)
{
@ -270,6 +274,14 @@ void icem_checklist_update(struct icem *icem)
}
/**
* Get the Local address of the Selected Candidate pair, if available
*
* @param icem ICE Media object
* @param compid Component ID
*
* @return Local address if available, otherwise NULL
*/
const struct sa *icem_selected_laddr(const struct icem *icem, uint8_t compid)
{
const struct icem_comp *comp = icem_comp_find(icem, compid);

View file

@ -215,6 +215,14 @@ static int start_gathering(struct icem *icem, const struct sa *stun_srv,
}
/**
* Gather Server Reflexive candidates using STUN Server
*
* @param icem ICE Media object
* @param stun_srv STUN Server network address
*
* @return 0 if success, otherwise errorcode
*/
int icem_gather_srflx(struct icem *icem, const struct sa *stun_srv)
{
if (!icem || !stun_srv)
@ -224,6 +232,16 @@ int icem_gather_srflx(struct icem *icem, const struct sa *stun_srv)
}
/**
* Gather Relayed and Server Reflexive candidates using TURN Server
*
* @param icem ICE Media object
* @param stun_srv TURN Server network address
* @param username TURN Server username
* @param password TURN Server password
*
* @return 0 if success, otherwise errorcode
*/
int icem_gather_relay(struct icem *icem, const struct sa *stun_srv,
const char *username, const char *password)
{

View file

@ -53,6 +53,15 @@ static void ice_destructor(void *arg)
}
/**
* Allocate a new ICE Session
*
* @param icep Pointer to allocated ICE Session object
* @param mode ICE Mode; Full-mode or Lite-mode
* @param offerer True if we are SDP offerer, otherwise false
*
* @return 0 if success, otherwise errorcode
*/
int ice_alloc(struct ice **icep, enum ice_mode mode, bool offerer)
{
struct ice *ice;
@ -81,12 +90,25 @@ int ice_alloc(struct ice **icep, enum ice_mode mode, bool offerer)
}
/**
* Get the ICE Configuration
*
* @param ice ICE Session
*
* @return ICE Configuration
*/
struct ice_conf *ice_conf(struct ice *ice)
{
return ice ? &ice->conf : NULL;
}
/**
* Set the offerer flag on the ICE Session
*
* @param ice ICE Session
* @param offerer True if offerer, otherwise false
*/
void ice_set_offerer(struct ice *ice, bool offerer)
{
if (!ice)
@ -96,6 +118,13 @@ void ice_set_offerer(struct ice *ice, bool offerer)
}
/**
* Start the Connectivity checks on the ICE Session
*
* @param ice ICE Session
*
* @return 0 if success, otherwise errorcode
*/
int ice_conncheck_start(struct ice *ice)
{
struct le *le;
@ -111,6 +140,14 @@ int ice_conncheck_start(struct ice *ice)
}
/**
* Print debug information for the ICE Session
*
* @param pf Print function for debug output
* @param ice ICE Session
*
* @return 0 if success, otherwise errorcode
*/
int ice_debug(struct re_printf *pf, const struct ice *ice)
{
struct le *le;
@ -133,18 +170,39 @@ int ice_debug(struct re_printf *pf, const struct ice *ice)
}
/**
* Get the list of ICE Media objects (struct icem) for the ICE Session
*
* @param ice ICE Session
*
* @return List of ICE Media objects
*/
struct list *ice_medialist(const struct ice *ice)
{
return ice ? (struct list *)&ice->ml : NULL;
}
/**
* Get the local Username fragment for the ICE Session
*
* @param ice ICE Session
*
* @return Local Username-fragment
*/
const char *ice_ufrag(const struct ice *ice)
{
return ice ? ice->lufrag : NULL;
}
/**
* Get the local password for the ICE Session
*
* @param ice ICE Session
*
* @return Local password
*/
const char *ice_pwd(const struct ice *ice)
{
return ice ? ice->lpwd : NULL;

View file

@ -38,6 +38,19 @@ static void icem_destructor(void *data)
}
/**
* Add a new ICE Media object to the ICE Session
*
* @param icemp Pointer to allocated ICE Media object
* @param ice ICE Session
* @param proto Transport protocol
* @param layer Protocol stack layer
* @param gh Gather handler
* @param chkh Connectivity check handler
* @param arg Handler argument
*
* @return 0 if success, otherwise errorcode
*/
int icem_alloc(struct icem **icemp, struct ice *ice, int proto, int layer,
ice_gather_h *gh, ice_connchk_h *chkh, void *arg)
{
@ -95,6 +108,12 @@ int icem_alloc(struct icem **icemp, struct ice *ice, int proto, int layer,
}
/**
* Set the name of the ICE Media object, used for debugging
*
* @param icem ICE Media object
* @param name Media name
*/
void icem_set_name(struct icem *icem, const char *name)
{
if (!icem)
@ -104,6 +123,15 @@ void icem_set_name(struct icem *icem, const char *name)
}
/**
* Add a new component to the ICE Media object
*
* @param icem ICE Media object
* @param compid Component ID
* @param sock Application protocol socket
*
* @return 0 if success, otherwise errorcode
*/
int icem_comp_add(struct icem *icem, uint8_t compid, void *sock)
{
struct icem_comp *comp;
@ -125,6 +153,17 @@ int icem_comp_add(struct icem *icem, uint8_t compid, void *sock)
}
/**
* Add a new candidate to the ICE Media object
*
* @param icem ICE Media object
* @param compid Component ID
* @param lprio Local priority
* @param ifname Name of the network interface
* @param addr Local network address
*
* @return 0 if success, otherwise errorcode
*/
int icem_cand_add(struct icem *icem, uint8_t compid, uint16_t lprio,
const char *ifname, const struct sa *addr)
{
@ -159,6 +198,14 @@ void icem_cand_redund_elim(struct icem *icem)
}
/**
* Get the Default Candidate
*
* @param icem ICE Media object
* @param compid Component ID
*
* @return Default Candidate address if set, otherwise NULL
*/
const struct sa *icem_cand_default(struct icem *icem, uint8_t compid)
{
const struct icem_comp *comp = icem_comp_find(icem, compid);
@ -202,6 +249,15 @@ bool icem_verify_support(struct icem *icem, uint8_t compid,
}
/**
* Add a TURN Channel for the selected remote address
*
* @param icem ICE Media object
* @param compid Component ID
* @param raddr Remote network address
*
* @return 0 if success, otherwise errorcode
*/
int icem_add_chan(struct icem *icem, uint8_t compid, const struct sa *raddr)
{
struct icem_comp *comp;
@ -240,6 +296,11 @@ static void purge_relayed(struct icem *icem, struct icem_comp *comp)
}
/**
* Update the ICE Media object
*
* @param icem ICE Media object
*/
void icem_update(struct icem *icem)
{
struct le *le;
@ -261,12 +322,27 @@ void icem_update(struct icem *icem)
}
/**
* Get the ICE Mismatch flag of the ICE Media object
*
* @param icem ICE Media object
*
* @return True if ICE mismatch, otherwise false
*/
bool icem_mismatch(const struct icem *icem)
{
return icem ? icem->mismatch : true;
}
/**
* Print debug information for the ICE Media
*
* @param pf Print function for debug output
* @param icem ICE Media object
*
* @return 0 if success, otherwise errorcode
*/
int icem_debug(struct re_printf *pf, const struct icem *icem)
{
struct le *le;
@ -303,6 +379,13 @@ int icem_debug(struct re_printf *pf, const struct icem *icem)
}
/**
* Get the list of Local Candidates (struct cand)
*
* @param icem ICE Media object
*
* @return List of Local Candidates
*/
struct list *icem_lcandl(const struct icem *icem)
{
return icem ? (struct list *)&icem->lcandl : NULL;

View file

@ -55,6 +55,14 @@ static enum ice_transp transp_resolve(const struct pl *transp)
}
/**
* Encode SDP candidate attribute
*
* @param pf Print function
* @param cand Candidate to encode
*
* @return 0 if success, otherwise errorcode
*/
int ice_cand_encode(struct re_printf *pf, const struct cand *cand)
{
int err;
@ -75,6 +83,13 @@ int ice_cand_encode(struct re_printf *pf, const struct cand *cand)
}
/**
* Check if remote candidates are available
*
* @param icem ICE Media object
*
* @return True if available, otherwise false
*/
bool ice_remotecands_avail(const struct icem *icem)
{
if (!icem)
@ -85,7 +100,14 @@ bool ice_remotecands_avail(const struct icem *icem)
}
/* "remote-candidates" Attribute */
/**
* Encode the SDP "remote-candidates" Attribute
*
* @param pf Print function
* @param icem ICE Media object
*
* @return 0 if success, otherwise errorcode
*/
int ice_remotecands_encode(struct re_printf *pf, const struct icem *icem)
{
struct le *le;
@ -234,6 +256,15 @@ static int cand_decode(struct icem *icem, const char *val)
}
/**
* Decode SDP session attributes
*
* @param ice ICE Session
* @param name Name of the SDP attribute
* @param value Value of the SDP attribute (optional)
*
* @return 0 if success, otherwise errorcode
*/
int ice_sdp_decode(struct ice *ice, const char *name, const char *value)
{
if (!ice)
@ -256,6 +287,15 @@ int ice_sdp_decode(struct ice *ice, const char *name, const char *value)
}
/**
* Decode SDP media attributes
*
* @param icem ICE Media object
* @param name Name of the SDP attribute
* @param value Value of the SDP attribute (optional)
*
* @return 0 if success, otherwise errorcode
*/
int icem_sdp_decode(struct icem *icem, const char *name, const char *value)
{
if (!icem)

View file

@ -96,7 +96,12 @@ void ice_switch_local_role(struct ice *ice)
/**
* Remove duplicate elements from list, preserving order
*
* note: O (n ^ 2)
* @param list Linked list
* @param uh Unique handler (return object to remove)
*
* @return Number of elements removed
*
* @note: O (n ^ 2)
*/
uint32_t ice_list_unique(struct list *list, list_unique_h *uh)
{

View file

@ -1,6 +1,8 @@
/**
* @file sha1.c SHA-1 in C
*/
/*
By Steve Reid <sreid@sea-to-sky.net>
100% Public Domain
@ -213,8 +215,9 @@ void SHA1_Update(SHA1_CTX* context, const uint8_t* data, const size_t len)
size_t i, j;
j = (context->count[0] >> 3) & 63;
if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++;
context->count[1] += (len >> 29);
if ((context->count[0] += (uint32_t)(len << 3)) < (len << 3))
context->count[1]++;
context->count[1] += (uint32_t)(len >> 29);
if ((j + len) > 63) {
memcpy(&context->buffer[j], data, (i = 64-j));
SHA1_Transform(context->state, context->buffer);

View file

@ -49,6 +49,15 @@ static bool inspos_handler(struct le *le, void *arg)
}
static bool inspos_handler_0(struct le *le, void *arg)
{
struct tmr *tmr = le->data;
const uint64_t now = *(uint64_t *)arg;
return tmr->jfs > now;
}
#if TMR_DEBUG
static void call_handler(tmr_h *th, void *arg)
{
@ -233,12 +242,23 @@ void tmr_start(struct tmr *tmr, uint64_t delay, tmr_h *th, void *arg)
tmr->jfs = delay + tmr_jiffies();
le = list_apply(tmrl, false, inspos_handler, &tmr->jfs);
if (le) {
list_insert_after(tmrl, le, &tmr->le, tmr);
if (delay == 0) {
le = list_apply(tmrl, true, inspos_handler_0, &tmr->jfs);
if (le) {
list_insert_before(tmrl, le, &tmr->le, tmr);
}
else {
list_append(tmrl, &tmr->le, tmr);
}
}
else {
list_prepend(tmrl, &tmr->le, tmr);
le = list_apply(tmrl, false, inspos_handler, &tmr->jfs);
if (le) {
list_insert_after(tmrl, le, &tmr->le, tmr);
}
else {
list_prepend(tmrl, &tmr->le, tmr);
}
}
#ifdef HAVE_ACTSCHED