Helper Functions

std::string CreateJingleContentFromSdp(std::string _sdp)
This API creates Jingle Content stanzas from standard SDP received from AFE. The API should be called after MakeOffer and MakeAnswer API call of AFE


Parameters:

sdpStandard SDP returned by MakeOffer and MakeAnswer API.

Return value:

jingleMessageJingle Content stanzas


std::string CreateSdpFromJingleMessage(std::string _jingleMessage)
This API creates standard SDP from Jingle message. The API should be called before MakeAnswer and ProcessAnswer API call of AFE


Parameters:

jingleMessageFully formed Jingle message

Return value:

standard SDP


EAfErrorType GetLastError(int iChannelOrSession);
This function returns the last error associated with a channel or session that occurred.

Parameters:

int iChannelOrSession The channel or session ID.

Return value:

EAfErrorTypeThe error code.


EAfError Type Description
EAfErrNone No error has occurred
EAfErrUnknown An unknown error occurred
EAfErrNotAValidChannel A channel operation was performed on the session
EAfErrNotAValidSession A session operation was performed on the channel
EAfErrNotAValidObject Not a valid session or channel id
EAfErrInvalidParameter An invalid parameter was passed to the function
EAfErrClosedChannel This operation cannot be performed on a closed channel


std::string GetHostType(const std::string& sHost);
This function returns the host type found in a given host description string sHost. For example, for the host description string “public sip.eyeball.com 5060 tcp” this function will return AF_HOST_PUBLIC. 

For details about host description strings please see 6.3. AFE: Host Types. Parameters:

const std::string& sHost The host description to parse.

Return value:

std::stringThe function returns the host type.


std::string SetHostType(std::string& sHost, const std::string& sType);
This function adds a host type (valid host types are  AF_HOST_PUBLIC,  AF_HOST_RELAY,  AF_HOST_FIREWALL,  AF_HOST_LOCAL,  AF_HOST_DNS_SRV) to the host description found in sHost. 

For further details about host descriptions please see .6.3. AFE: Host Types Parameters:

std::string& sHost An existing host description. This parameter also holds the result after the function returns.
const std::string& sType The host type, e.g., AF_HOST_LOCAL or AF_HOST_RELAY

Return value:

std::stringThe function returns the updated host description list.


std::string GetHostAddress(const std::string& sHost);
This function returns the address found in a given host description string sHost. For example, for the host description string "public sip.eyeball.com 5060 tcp" this function will return "sip.eyeball.com"

For details about host description strings please see 6.3. AFE: Host Types. Parameters:

const std::string& sHostThe host description to parse.

Return value:

std::stringThe function returns the host address.


std::string SetHostAddress(std::string& sHost, const std::string& sAddress);
This function adds a host address to the host description found in sHost. The function does not check for correct syntax of the existing host description sHost, e.g. it does not check whether a host address is already set. 

For details about host description strings please see 6.3. AFE: Host Types Parameters:

std::string& sHost An existing host description. This parameter also holds the result after the function returns.
const std::string& sAddress The host type, e.g. “sip.eyeball.com” or “192.168.0.101”

Return value:

std::string The function returns the updated host description list.


int GetHostPort(const std::string& sHost);
This function returns the port found in a given host description string sHost. For example, for the host description string "public sip.eyeball.com 5060 tcp" this function will return "5060". 

For details about host description strings please see 6.3. AFE: Host Types. Parameters:

const std::string& sHost The host description to parse.

Return value:

intThe function returns the port.


std::string SetHostPort(std::string& sHost, int iPort);
This function adds a port to the host description found in sHost. The function does not check for correct syntax of the existing host description sHost, e.g. it does not check whether a host port is already set. 

For details about host description strings please see 6.3. AFE: Host Types.
Parameters:

std::string& sHost An existing host description. This parameter also holds the result after the function returns.
int iPort The host port.

Return value:

std::stringThe function returns the updated host description list.


std::string GetHostProtocol(const std::string& sHost);
This function returns the protocol found in a given host description string sHost. For example, for the host description string “public sip.eyeball.com 5060 tcp” this function will return AF_PROTOCOL_TCP (“tcp”). 


For details about host description strings please see 6.3. AFE: Host Types.

Parameters:

const std::string& sHost The host description to parse.

Return value:

std::stringThe function returns the host protocol.


std::string SetHostProtocol(std::string& sHost, const std::string& sProtocol);
This function adds a host protocol to the host description found in sHost. The function does not check for correct syntax of the existing host description sHost, e.g. it does not check whether a host protocol is already set. 


For details about host description strings please see 6.3. AFE: Host Types.

Parameters:

std::string& sHostAn existing host description. This parameter also holds the result after the function returns.
const std::string& sProtocolThe host protocol, e.g. AF_PROTOCOL_UDP or AF_PROTOCOL_TCP

Return value:

std::string The function returns the updated host description list.


int GetHostListSize(const std::string& sHostList);
This function returns the number of host descriptions in a host description list. For example, for the host list string “local 192.168.0.2 5060 UDP; firewall 64.85.36.112 1234 UDP; relay 64.85.36.33 9876 UDP” it will return 3. The function performs only a basic syntax check of sHostList, it should not be used to check whether a list of host descriptions has a valid syntax. 


For details about host description strings please see 6.3. AFE: Host Types.

Parameters:

const std::string& sHostListA string with a list of host descriptions, separated by semi-colon.

Return value:

intThe function returns the number of host descriptions in the host description list.


std::string GetHostFromList(const std::string& sHostList, int iIndex);
This function returns the host description at a given (zero-based) position in a host description list. For example, for the host list string “local 192.168.0.2 5060 UDP; firewall 64.85.36.112 1234 UDP; relay 64.85.36.33 9876 UDP” and given iIndex=1 the function will return “firewall 64.85.36.112 1234 UDP”. 


For details about host description strings please see 6.3. AFE: Host Types.

Parameters:

const std::string& sHostListA string with a list of host descriptions.
int iIndexThe position (zero-based) of the desired host description.

Return value:

std::stringThe function returns the host descriptions at the position given by iIndex in the host description list.


std::string AddHostToList(std::string& sHostList, const std::string& sHost);
This function adds a host description (created by CreateHost) to an existing host description list. For example, when adding the host “relay 64.85.36.33 9876 UDP” to the existing list “local 192.168.0.2 5060 UDP; firewall 64.85.36.112 1234 UDP” the function will return “local 192.168.0.2 5060 UDP; firewall 64.85.36.112 1234 UDP; relay 64.85.36.33 9876 UDP”. When sHostList is empty, the function returns sHost. 


For details about host description strings please see 6.3. AFE: Host Types.

Parameters:

std::string& sHostListA string with a list of host descriptions.
const std::string& sHost The host description to add.

Return value:

std::stringThe function returns the updated host description list.


std::string CreateHost(const std::string& sType, const std::string& sAddress, int iPort, const std::string& sProtocol, const struct AfConnectionParams *pConnectionParams);
This function creates a new host description from the given parameters. The function checks whether the port is in the range 0-65535. 
For details about host description strings please see section 6.3. AFE: Host Types.


Parameters:

const std::string& sTypeThe host type such as AF_HOST_LOCAL or AF_HOST_PUBLIC.
const std::string& sAddress The IP address or hostname.
int iPort The port.
const std::string& sProtocolThe protocol such as AF_PROTOCOL_UDP or AF_PROTOCOL_TCP.
const struct
AfConnectionParams
*pConnectionParams
This can be used to customize the STUN UDP and TCP timing parameters. It can also be used to specify TCP timeout value for proxy server and for the server to communicate with the Connect API.
struct AfConnectionParams
{
     int iRTO;
     int iRc;
     int iRm;
     int iTi;
};

The members iRTO, iRc, iRm and iTi are described in STUN RFC 5389. These are used for configuring STUN UDP retransmission mechanism and TCP timeout. iRTO and iTi are specified in milliseconds.The parameter iTi is the timeout for TCP and can be used for configuring the timeout for connecting to the proxy server or other TCP servers. When pConnectionParams is NULL, the default timing parameters are used with iRTO = 500, iRc = 7, iRm = 16, and iTi = 39500.

Return value:

std::string& The function returns the created host description.


void SetLogFilePath(const char* filePath)
The purpose of this API is to enable/set logging path, to facilitate AFE logging on non-jailbroken iPhones/iPads. This API should be called after initialization of AFE.

Parameter:

const char* filepathExpected logging path.
void SetLogFileOptions(const int sizeInMB, const int noOfLogFile);
This function sets the number of log files to be created and size of the each log files.
This API should be called after initialization of AnyFirewallEngine.
Every time when the application is started it writes log in the first log file. i.e in AFEngine0.log. If the size of the current log file exceeds maximum size, it will write logs in the next log file. When the size of the last log file exceeds maximum size, it will clean the first log file and start writing logs in the first log file.
If second parameter is set to 0 or less than 0, it will take default number of log files. If this API is not called, AFE will take default log file size and default number of log files. Here default number of log files is set to 2 (two) and default log file size is set to 1MB.

Parameter:

const int sizeInMBSize of each log file in megabytes.
const int noOfLogFileNumber of log files to be created.


void Log(const std::string& sMessage)
This function prints the message given in sMessage into AFE log.
Parameters:
String sMessage
The message that we want to print in log


Enable logging option in different platform:

AFE Log for Windows

In order to enable logging, EnableAfeLogging.reg available in the installation directory is used. It inserts the key LogAF into registry. The log file, AFEngineX.log, will be created in following directory:

C:\EyeballSDKLogs

In order to create log file in a specific directory,copy the following text in EnableAfeLogging.reg.

"LogDR"=" <logDirectory> "
For example:
"LogDR"="C:\EyeballSDKLogs"

AFE Log for Linux and Mac

In order to enable logging, create a file named 'LogAF.cfg' in \etc directory and copy the following text:
loglevel =10
LogAll
The log file, AFEngineX.log, will be created on following directory:

  • On Linux, it will be available in /root/.
  • On Mac, log file will be available in tmp folder.
    In order to create log file in a specific directory,copy the following text in LogAF.cfg

logDirectory=<logDirectory>
For example:
logDirectory=/root/EyballSDKLogs

AFE Log for iOS

In order to enable logging, create a file named 'LogAF.cfg' in /etc directory and copy the following text:
loglevel=10
LogAll
The log file, AFEngineX.log, will be created on following directory:

  • /var/EyeballSDKLogs/
  • A jailbroken device is needed for enabling logs. If the directory path is not available 'EyeballSDKLog' directory need to create within /var/ and the directory should have proper permission.
  • File will be accessible via 'WinSCP' of 'ssh'
    In order to create log file in a specific directory,copy the following text in LogAF.cfg

logDirectory=<logDirectory>
For example:
logDirectory=/var/EyballSDKLogs

AFE Log for Android

In order to enable logging, create a file named 'EyeballSDK.cfg' in * /sdcard/ directory and copy the following text:
loglevel=10
LogAll
The log file, AFEngineX.log, will be created on following directory:

  • /sdcard/EyeballSDKLogs/

In order to create log file in a specific directory,copy the following text in EyeballSDK.cfg
logDirectory=<logDirectory>

For example: logDirectory=/sdcard/EyballSDKLogs



int GetChannelOption(int iChannel, EAfOptionName eOptionName)
This function returns the value for the given channel option for the given channel.

Parameters:

int iChannel Channels ID whose option name value to get
EafOptionName eOptionName Name of the channel option whose value to get.

Return Value:

intReturns the option name value in integer.


bool ClearLoopbackRecvBuffer(int iChannel)
This function clears all the contents of the message buffer for the given loopback channel.


Parameter:

int iChannelThe channel ID whose control channel should be cleared

Return:

Returns true on success, false if the channel is not a loopback channel or a non-existent channel.


void SetCallbackForNewTurnPort(callback_function &cb, int iChannel)
AFE client can specify a fixed local port to use for TURN allocation. 


Please see function "Create" for details. If the client specifies a fixed local port to use for TURN allocation, then the client must use this callback function so that AFE can obtain new local port in case of failure. If the server sends error response with code 437 when AFE attempts to allocate relayed candidate, then the client provides a new local port by this callback function. Please see corresponding TURN RFC for error code 437: (http://tools.ietf.org/html/rfc5766#section-6.4)


Parameters:

callback_function &cb: This function is a pointer which takes input from a function reference in the following format: In C++:
int AfeClient::GetNewLocalPortForTurn(int oldLocalPort, int isTransportTypeUDP)
{
    …
    return newLocalPort;
}
callback_function callback=&(AfeClient::GetNewLocalPortForTurn);
SetCallbackForNewTurnPort(callback, channelId);
Function GetNewLocalPortForTurn must be a static member
In C:
int GetNewLocalPortForTurn(int oldLocalPort, int isTransportTypeUDP)
{
    …
    return newLocalPort;
}
callback_function callback = &(GetNewLocalPortForTurn);
af_set_callback_for_new_turn_port(callback, channelId);
GetNewLocalPortForTurn Function description:
int oldLocalPort  is the port used by AFE previously.
int isTransportTypeUDP is the value which determines if the transport is UDP or TCP.
If 1 then UDP, if 0 then TCP.

Return value: int new Local Port for turn


Return value:

int iChannelID of the associated channel
bool SetTurnAuthenticationToken(const int serverStoreID, const CAfStdString& authenticationToken)
This function is applicable only for AFE initialized with IETF mode. If AFE client wants to useIBM SameTimeserver as its TURN server, then it can specify AUTHENTICATION_TOKEN through this function. Long term credential required for standard TURN allocation will not be used then.
This function is part of configuring AFE, so, it SHOULD be called before the function DetectConnectivity.


Parameters:

const int serverStoreIDA unique server store id for individual server settings.
const CAfStdString& authenticationTokenA string which takes input in the following format:
CAfStdString authenticationToken; SetTURNAuthenticationToken(authenticationToken);

Returns:

boolTrue if it is set successfully, otherwise False.


CAfStdString* GetTURNAuthenticationToken(const int serverStoreID)
AFE client can retrieve AUTHENTICATION_TOKEN later if it was set by client earlier.


Parameters:

const int serverStoreIDA unique server store id for individual server settings.

Returns:

CAfStdString*This function returns CAfStdString AUTHENTICATION_TOKEN value.


bool DisableAllTurnAuthentication(const int serverStoreID)
This function is applicable only for AFE initialized with IETF mode.
It disables all types of TURN authentication - long-term credential mechanism (username, password) of standard TURN protocol and authentication token mechanism of IBM SameTime server.
If the client application invokes function  SetTURNUsernamePassword  or  SetTurnAuthenticationToken  later, authentication mechanism will be enabled and enforced then.
This function is part of configuring AFE. So it SHOULD be called before the function DetectConnectivity.


Parameters:

const int serverStoreIDA unique server store id for individual server settings.

Returns:

bool True if all TURN authentication mechanism disable successfully, otherwise False.