Yate
IAXEngine Class Reference

IAX engine class. More...

#include <yateiax.h>

Inheritance diagram for IAXEngine:
DebugEnabler Mutex Lockable

Public Member Functions

 IAXEngine (const char *iface, int port, u_int32_t format, u_int32_t capab, const NamedList *params=0, const char *name="iaxengine")
 
virtual ~IAXEngine ()
 
const Stringname () const
 
u_int8_t callerNumType () const
 
u_int8_t callingPres () const
 
IAXTransactionaddFrame (const SocketAddr &addr, IAXFrame *frame)
 
IAXTransactionaddFrame (const SocketAddr &addr, const unsigned char *buf, unsigned int len)
 
IAXTransactionfindTransaction (const SocketAddr &addr, u_int16_t rCallNo)
 
virtual void processMedia (IAXTransaction *transaction, DataBlock &data, u_int32_t tStamp, int type, bool mark)
 
bool process ()
 
unsigned int challengeTout () const
 
u_int16_t maxFullFrameDataLen () const
 
u_int32_t format (bool audio=true) const
 
u_int32_t capability () const
 
void getOutDataAdjust (unsigned int &thres, unsigned int &over, unsigned int &under) const
 
void initOutDataAdjust (const NamedList &params, IAXTransaction *tr=0)
 
void initialize (const NamedList &params)
 
void readSocket (SocketAddr &addr)
 
bool writeSocket (const void *buf, int len, const SocketAddr &addr, IAXFullFrame *frame=0, unsigned int *sent=0)
 
bool writeSocket (const SocketAddr &addr, IAXFullFrame *frame)
 
void runGetEvents ()
 
void removeTransaction (IAXTransaction *transaction)
 
bool haveTransactions ()
 
u_int32_t transactionCount ()
 
void keepAlive (const SocketAddr &addr)
 
virtual bool mediaFormatChanged (IAXTransaction *trans, int type, u_int32_t format)
 
virtual bool checkCallToken (const SocketAddr &addr, IAXFullFrame &frame)
 
bool acceptFormatAndCapability (IAXTransaction *trans, unsigned int *caps=0, int type=IAXFormat::Audio)
 
virtual void defaultEventHandler (IAXEvent *event)
 
bool exiting () const
 
virtual void setExiting ()
 
void enableTrunking (IAXTransaction *trans, const NamedList *params, const String &prefix=String::empty())
 
void enableTrunking (IAXTransaction *trans, IAXTrunkInfo &data)
 
void initTrunkIn (IAXTransaction *trans, const NamedList *params, const String &prefix=String::empty())
 
void initTrunkIn (IAXTransaction *trans, IAXTrunkInfo &data)
 
bool trunkInfo (RefPointer< IAXTrunkInfo > &info)
 
void sendInval (IAXFullFrame *frame, const SocketAddr &addr)
 
void runProcessTrunkFrames ()
 
Socketsocket ()
 
const SocketAddraddr () const
 
void setFormats (u_int32_t caps, u_int32_t fmtAudio, u_int32_t fmtVideo)
 
- Public Member Functions inherited from DebugEnabler
 DebugEnabler (int level=TelEngine::debugLevel(), bool enabled=true)
 
int debugLevel () const
 
int debugLevel (int level)
 
bool debugEnabled () const
 
void debugEnabled (bool enable)
 
const char * debugName () const
 
bool debugAt (int level) const
 
bool debugChained () const
 
void debugChain (const DebugEnabler *chain=0)
 
void debugCopy (const DebugEnabler *original=0)
 
- Public Member Functions inherited from Mutex
 Mutex (bool recursive=false, const char *name=0)
 
 Mutex (const Mutex &original)
 
 ~Mutex ()
 
Mutexoperator= (const Mutex &original)
 
virtual bool lock (long maxwait=-1)
 
virtual bool unlock ()
 
virtual bool locked () const
 
const char * owner () const
 
bool recursive () const
 
- Public Member Functions inherited from Lockable
virtual ~Lockable ()
 
virtual bool check (long maxwait=-1)
 
virtual bool unlockAll ()
 

Static Public Member Functions

static int getPort (const NamedList &params, const String &param="port")
 
static void getMD5FromChallenge (String &md5data, const String &challenge, const String &password)
 
static bool isMD5ChallengeCorrect (const String &md5data, const String &challenge, const String &password)
 
static void buildAddrSecret (String &buf, const String &secret, const SocketAddr &addr)
 
static int addrSecretAge (const String &buf, const String &secret, const SocketAddr &addr)
 
static void addKeyword (NamedList &list, const char *param, const TokenDict *tokens, unsigned int val)
 
static void decodeDateTime (u_int32_t dt, unsigned int &year, unsigned int &month, unsigned int &day, unsigned int &hour, unsigned int &minute, unsigned int &sec)
 
static unsigned int overallTout (unsigned int interval=IAX2_RETRANS_INTERVAL_DEF, unsigned int nRetrans=IAX2_RETRANS_COUNT_DEF)
 
- Static Public Member Functions inherited from Mutex
static int count ()
 
static int locks ()
 
static bool efficientTimedLock ()
 
- Static Public Member Functions inherited from Lockable
static void wait (unsigned long maxwait)
 
static unsigned long wait ()
 
static void startUsingNow ()
 
static void enableSafety (bool safe=true)
 
static bool safety ()
 

Protected Member Functions

bool processTrunkFrames (const Time &time=Time())
 
virtual void processEvent (IAXEvent *event)
 
IAXEventgetEvent (const Time &now=Time())
 
u_int16_t generateCallNo ()
 
void releaseCallNo (u_int16_t lcallno)
 
IAXTransactionstartLocalTransaction (IAXTransaction::Type type, const SocketAddr &addr, IAXIEList &ieList, bool refTrans=false, bool startTrans=true)
 
bool bind (const char *iface, int port, bool force)
 
- Protected Member Functions inherited from DebugEnabler
void debugName (const char *name)
 

Protected Attributes

int m_trunking
 

Detailed Description

IAX engine class.

This class holds all information needded to manipulate all IAX transactions and events

Constructor & Destructor Documentation

◆ IAXEngine()

IAXEngine ( const char * iface,
int port,
u_int32_t format,
u_int32_t capab,
const NamedList * params = 0,
const char * name = "iaxengine" )

Constructor

Parameters
ifaceAddress of the interface to use, default all (0.0.0.0)
portUDP port to run the protocol on
formatDefault media format
capabMedia capabilities of this engine
paramsOptional extra parameter list
nameEngine name

References format(), and name().

◆ ~IAXEngine()

virtual ~IAXEngine ( )
virtual

Destructor Closes all transactions belonging to this engine and flush all queues

Member Function Documentation

◆ acceptFormatAndCapability()

bool acceptFormatAndCapability ( IAXTransaction * trans,
unsigned int * caps = 0,
int type = IAXFormat::Audio )

Process the initial received format and capability. If accepted on exit will set the transaction format and capability

Parameters
transTransaction that received the new format
capsOptional codecs to set in transaction before processing
typeMedia type
Returns
True if accepted

◆ addFrame() [1/2]

IAXTransaction * addFrame ( const SocketAddr & addr,
const unsigned char * buf,
unsigned int len )

Add a raw frame to the transaction list

Parameters
addrAddress from which the message was received
bufPointer to the start of the buffer holding the IAX frame
lenLength of the message buffer
Returns
Pointer to the transaction or 0

References addr().

◆ addFrame() [2/2]

IAXTransaction * addFrame ( const SocketAddr & addr,
IAXFrame * frame )

Add a parsed frame to the transaction list

Parameters
addrAddress from which the frame was received
frameA parsed IAX frame
Returns
Pointer to the transaction or 0 to deref the frame

References addr().

◆ addKeyword()

static void addKeyword ( NamedList & list,
const char * param,
const TokenDict * tokens,
unsigned int val )
inlinestatic

Add string (keyword) if found in a dictionary or integer parameter to a named list

Parameters
listDestination list
paramParameter to add to the list
tokensThe dictionary used to find the given value
valThe value to find/add to the list

References NamedList::addParam().

◆ addr()

const SocketAddr & addr ( ) const
inline

Retrieve the socket address on wgich we are bound

Returns
Local address we are bound on

Referenced by addFrame(), addFrame(), addrSecretAge(), buildAddrSecret(), checkCallToken(), findTransaction(), keepAlive(), readSocket(), sendInval(), startLocalTransaction(), writeSocket(), and writeSocket().

◆ addrSecretAge()

static int addrSecretAge ( const String & buf,
const String & secret,
const SocketAddr & addr )
static

Decode a secret built using buildAddrSecret()

Parameters
bufInput buffer
secretExtra secret to check
addrSocket address
Returns
Secret age, negative if invalid

References addr().

◆ bind()

bool bind ( const char * iface,
int port,
bool force )
protected

Bind the socket. Terminate it before trying

Parameters
ifaceAddress of the interface to use, default all (0.0.0.0)
portUDP port to run the protocol on
forceForce binding if failed on required port
Returns
True on success

References Mutex::Mutex().

◆ buildAddrSecret()

static void buildAddrSecret ( String & buf,
const String & secret,
const SocketAddr & addr )
static

Build a time signed secret used to authenticate an IP address

Parameters
bufDestination buffer
secretExtra secret to add to MD5 sum
addrSocket address

References addr().

◆ callerNumType()

u_int8_t callerNumType ( ) const
inline

Retrieve the default caller number type

Returns
Default caller number type

◆ callingPres()

u_int8_t callingPres ( ) const
inline

Retrieve the default caller number presentation and screening concatenated value

Returns
Default caller number presentation and screening

◆ capability()

u_int32_t capability ( ) const
inline

Get the media capability of this engine

Returns
The media capability of this engine

◆ challengeTout()

unsigned int challengeTout ( ) const
inline

Get the timeout interval sent challenge

Returns
Sent challenge timeout interval

◆ checkCallToken()

virtual bool checkCallToken ( const SocketAddr & addr,
IAXFullFrame & frame )
virtual

Check call token on incoming call requests. This method is called by the engine when processing an incoming call request

Parameters
addrThe address from where the call request was received
frameReceived frame
Returns
True if accepted, false to ignore the call

References addr().

◆ decodeDateTime()

static void decodeDateTime ( u_int32_t dt,
unsigned int & year,
unsigned int & month,
unsigned int & day,
unsigned int & hour,
unsigned int & minute,
unsigned int & sec )
static

Decode a DATETIME value

Parameters
dtValue to decode
yearThe year component of the date
monthThe month component of the date
dayThe day component of the date
hourThe hour component of the time
minuteThe minute component of the time
secThe seconds component of the time

◆ defaultEventHandler()

virtual void defaultEventHandler ( IAXEvent * event)
virtual

Default event handler. event MUST NOT be deleted

Parameters
eventThe event to handle

◆ enableTrunking() [1/2]

void enableTrunking ( IAXTransaction * trans,
const NamedList * params,
const String & prefix = String::empty() )

Enable trunking for the given transaction. Allocate a trunk meta frame if needed. Trunk data is ignored if a trunk object for transaction remote address already exists

Parameters
transTransaction to enable trunking for
paramsTrunk parameters list, may be 0
prefixTrunk parameters name prefix

References String::empty().

◆ enableTrunking() [2/2]

void enableTrunking ( IAXTransaction * trans,
IAXTrunkInfo & data )

Enable trunking for the given transaction. Allocate a trunk meta frame if needed. Trunk data is ignored if a trunk object for transaction remote address already exists

Parameters
transTransaction to enable trunking for
dataTrunk info to use

◆ exiting()

bool exiting ( ) const
inline

Check if the engine is exiting

Returns
True if the engine is exiting

◆ findTransaction()

IAXTransaction * findTransaction ( const SocketAddr & addr,
u_int16_t rCallNo )

Find a complete transaction. This method is thread safe

Parameters
addrRemote address
rCallNoRemote transaction call number
Returns
Referrenced pointer to the transaction or 0

References addr().

◆ format()

u_int32_t format ( bool audio = true) const
inline

Get the default media format

Parameters
audioTrue to retrieve default audio format, false for video format
Returns
The default media format

Referenced by IAXEngine(), and mediaFormatChanged().

◆ generateCallNo()

u_int16_t generateCallNo ( )
protected

Generate call number. Update used call numbers list

Returns
Call number or 0 if none available

◆ getEvent()

IAXEvent * getEvent ( const Time & now = Time())
protected

Get an IAX event from the queue. This method is thread safe.

Parameters
nowCurrent time
Returns
Pointer to an IAXEvent or 0 if none is available

◆ getMD5FromChallenge()

static void getMD5FromChallenge ( String & md5data,
const String & challenge,
const String & password )
static

Get the MD5 data from a challenge and a password

Parameters
md5dataDestination String
challengeChallenge source
passwordPassword source

◆ getOutDataAdjust()

void getOutDataAdjust ( unsigned int & thres,
unsigned int & over,
unsigned int & under ) const
inline

Retrieve outgoing data timestamp adjust values

Parameters
thresAdjust outgoing data timestamp threshold
overValue used to adjust outgoing data timestamp on data overrun
underValue used to adjust outgoing data timestamp on data underrun

◆ getPort()

static int getPort ( const NamedList & params,
const String & param = "port" )
inlinestatic

Retrieve a port parameter

Parameters
paramsParameters list
paramParameter to retrieve
Returns
The port (default, 4569, if the parameter is missing or invalid)

References NamedList::getIntValue().

◆ haveTransactions()

bool haveTransactions ( )

Check if there are any transactions in the engine This method is thread safe

Returns
True if the engine holds at least 1 transaction

◆ initialize()

void initialize ( const NamedList & params)

(Re)Initialize the engine

Parameters
paramsParameter list

◆ initOutDataAdjust()

void initOutDataAdjust ( const NamedList & params,
IAXTransaction * tr = 0 )

Initialize outgoing data timestamp adjust values. This method is thread safe

Parameters
paramsParameters list
trOptional transaction to init, initialize the engine's data if 0

◆ initTrunkIn() [1/2]

void initTrunkIn ( IAXTransaction * trans,
const NamedList * params,
const String & prefix = String::empty() )

Init incoming trunking data for a given transaction

Parameters
transTransaction to init
paramsTrunk parameters list, may be 0
prefixTrunk parameters name prefix

References String::empty().

◆ initTrunkIn() [2/2]

void initTrunkIn ( IAXTransaction * trans,
IAXTrunkInfo & data )

Init incoming trunking data for a given transaction

Parameters
transTransaction to init
dataTrunk info to use

◆ isMD5ChallengeCorrect()

static bool isMD5ChallengeCorrect ( const String & md5data,
const String & challenge,
const String & password )
static

Test if a received response to an authentication request is correct

Parameters
md5dataData to compare with
challengeReceived challenge
passwordPassword source

◆ keepAlive()

void keepAlive ( const SocketAddr & addr)

Send an INVAL with call numbers set to 0 to a remote peer to keep it alive

Parameters
addrAddress to send to

References addr().

◆ maxFullFrameDataLen()

u_int16_t maxFullFrameDataLen ( ) const
inline

Get the maximum allowed frame length

Returns
The maximum allowed frame length

◆ mediaFormatChanged()

virtual bool mediaFormatChanged ( IAXTransaction * trans,
int type,
u_int32_t format )
inlinevirtual

Process a new format received with a full frame

Parameters
transTransaction that received the new format
typeMedia type
formatThe received format
Returns
True if accepted

References format().

◆ name()

const String & name ( ) const
inline

Retrieve the engine name

Returns
Engine name

Referenced by IAXEngine().

◆ overallTout()

static unsigned int overallTout ( unsigned int interval = IAX2_RETRANS_INTERVAL_DEF,
unsigned int nRetrans = IAX2_RETRANS_COUNT_DEF )
static

Calculate overall timeout from interval and retransmission counter

Parameters
intervalThe first retransmisssion interval
nRetransThe number of retransmissions
Returns
The overall timeout

◆ process()

bool process ( )

Event processor method. Keeps calling getEvent() and passing any events to processEvent() until there are no more events

Returns
True if at least one event was processed

◆ processEvent()

virtual void processEvent ( IAXEvent * event)
protectedvirtual

Default event for connection transactions handler. This method may be overriden to perform custom processing This method is thread safe

Parameters
eventEvent to process

◆ processMedia()

virtual void processMedia ( IAXTransaction * transaction,
DataBlock & data,
u_int32_t tStamp,
int type,
bool mark )
inlinevirtual

Process media from remote peer. Descendents must override this method

Parameters
transactionIAXTransaction that owns the call leg
dataMedia data
tStampMedia timestamp
typeMedia type
markMark flag

◆ processTrunkFrames()

bool processTrunkFrames ( const Time & time = Time())
protected

Process all trunk meta frames in the queue

Parameters
timeTime of the call
Returns
True if at least one frame was sent

◆ readSocket()

void readSocket ( SocketAddr & addr)

Read data from socket

Parameters
addrSocket to read from

References addr().

◆ releaseCallNo()

void releaseCallNo ( u_int16_t lcallno)
protected

Release a call number

Parameters
lcallnoCall number to release

◆ removeTransaction()

void removeTransaction ( IAXTransaction * transaction)

Removes a transaction from queue. Free the allocated local call number Does not delete it

Parameters
transactionTransaction to remove

◆ runGetEvents()

void runGetEvents ( )

Read events

◆ runProcessTrunkFrames()

void runProcessTrunkFrames ( )

Keep calling processTrunkFrames to send trunked media data

◆ sendInval()

void sendInval ( IAXFullFrame * frame,
const SocketAddr & addr )

Send an INVAL frame

Parameters
frameFrame for which to send an INVAL frame
addrThe address from where the call request was received

References addr().

◆ setExiting()

virtual void setExiting ( )
virtual

Set the exiting flag

◆ setFormats()

void setFormats ( u_int32_t caps,
u_int32_t fmtAudio,
u_int32_t fmtVideo )
inline

Send engine formats

Parameters
capsCapabilities
fmtAudioDefault audio format
fmtVideoDefault video format

◆ socket()

Socket & socket ( )
inline

Get the socket used for engine operation

Returns
Reference to the UDP socket

◆ startLocalTransaction()

IAXTransaction * startLocalTransaction ( IAXTransaction::Type type,
const SocketAddr & addr,
IAXIEList & ieList,
bool refTrans = false,
bool startTrans = true )
protected

Start a transaction based on a local request

Parameters
typeTransaction type
addrRemote address to send the request
ieListFirst frame IE list
refTransReturn a refferenced transaction pointer
startTransStart transaction
Returns
IAXTransaction pointer on success

References addr().

◆ transactionCount()

u_int32_t transactionCount ( )

Return the transactions count This method is thread safe

Returns
Transactions count

◆ trunkInfo()

bool trunkInfo ( RefPointer< IAXTrunkInfo > & info)
inline

Retrieve the default trunk info data

Parameters
infoDestination to be set with trunk info pointer
Returns
True if destination pointr is valid

◆ writeSocket() [1/2]

bool writeSocket ( const SocketAddr & addr,
IAXFullFrame * frame )
inline

Write a full frame to socket

Parameters
addrSocket to write to
frameFrame to write
Returns
True on success

References addr(), DataBlock::data(), IAXFrame::data(), DataBlock::length(), and writeSocket().

◆ writeSocket() [2/2]

bool writeSocket ( const void * buf,
int len,
const SocketAddr & addr,
IAXFullFrame * frame = 0,
unsigned int * sent = 0 )

Write data to socket.

Parameters
bufData to write
lenData length
addrSocket to write to
frameOptional frame to be printed
sentPointer to variable to be filled with the number of bytes sent
Returns
True on success

References addr().

Referenced by writeSocket().


The documentation for this class was generated from the following file: