⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 voip_cli_cmd.c

📁 telcobridges voip develop
💻 C
📖 第 1 页 / 共 5 页
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
 |
 |	Project:    	VOIP sample
 |
 |	Filename:   	voip_cli_cmd.c
 |
 |	Copyright:  	TelcoBridges 2002-2004, All Rights Reserved
 |
 |	Description:	This file contains commands implementation for the cli menu.
 |
 |	Notes:      	Tabs = 4
 |
 *-------------------------------------------------------------------------------------------------------------------------------
 |
 |	Revision:   	$Revision: 1.52.2.1 $
 |
 *------------------------------------------------------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------------------------------------------------------
 |  Includes
 *------------------------------------------------------------------------------------------------------------------------------*/

#include "voip_includes.h"


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Versioning
 *------------------------------------------------------------------------------------------------------------------------------*/
#ifdef WIN32
	/*@unused@*/ static char g_szFileVersion [] = "$Revision: 1.52.2.1 $";
#endif


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Defines
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Macros
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Types
 *------------------------------------------------------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------------------------------------------------------
 |  Global variables
 *------------------------------------------------------------------------------------------------------------------------------*/

/* Default values for prompt */
VOIP_DEFAULT_PROMPTS	g_DefaultPrompts =
{
	/* .Quit */
	{
		0				/* fConfirm */
	},

	/* .LogFind */
	{
		""				/* szSearchString */
	},

	/* .SelectPage */
	{
		1				/* un32Page */
	},

	/* .SelectStream */
	{
		1,				/* fGlobalStats */
		0,				/* un32InterfaceIndex */
		0,				/* un16RxIPPort */
		0,				/* un16TxIPPort */
		0				/* fResetStats */
	},

	/* .SetTraceLevel */
	{
		3,				/* un32TraceLevelStdout */
		3,				/* un32TraceLevelLogFile */
	},

	/* .ReloadConfig */
	{
		VOIP_DEFAULT_CONFIG_FILE_NAME	/* szConfigFileName */
	},

	/* .StartStressTest */
	{
		"127.0.0.1",	/* szStreamSocketIP */
		0,				/* un32FirstResTypeIndex */
		250,			/* un32NbConnectionsPerSecond */
		0,				/* un32MinConnectionDuration */
		4,				/* un32MaxConnectionDuration */
		1,				/* fAutoAbort */
		1,				/* fDisconnectAllRes */
		1,				/* fDoBertTests */
		-1				/* un32TestDurationSec */
	},

	/* .StopStressTest */
	{
		0				/* fConfirm */
	},

	/* .ResetStressTestStats */
	{
		0				/* fConfirm */
	},

	/* .NextDemoStep */
	{
		0				/* fConfirm */
	},

	/* .StartDemo */
	{
		1,				/* fSkipPauses */
		1				/* fAutoAbort */
	},

	/* .StopDemo */
	{
		0				/* fConfirm */
	},

	/* .AllocateConnection */
	{
		1,				/* un32NbConnections */
		0,				/* un32FirstResTypeIndex */
		0,				/* un32SecondResResourceTypeIndex */
		0,				/* un32FirstResTrunkNb */
		1,				/* un32FirstResTimeSlot */
		0,				/* un32FirstResMblPortNb */
		0,				/* un32FirstResMblStreamNb */
		0,				/* un32FirstResMblTimeSlot */
		"",				/* First prompt name */
		"",				/* First raw data filne name */
		0,				/* un32SecondResTrunkNb */
		1,				/* un32SecondResTimeSlot */
		0,				/* un32SecondResMblPortNb */
		0,				/* un32SecondResMblStreamNb */
		0,				/* un32SecondResMblTimeSlot */
		20000,			/* un16SecondResRxIPPort */
		20000,			/* un16SecondResTxIPPort */
		1,				/* un16SecondResIPPortIncrement */
		"127.0.0.1",	/* szSecondResStreamSocketIP */
		"G711A",		/* szSecondResPacketType */
		1				/* un32SecondResGroupTypeIndex */
	},

	/* .ClearConnection */
	{
		0,				/* fAll */
		0,				/* fIncludeInfiniteDurCall */
		0				/* un32ConnectionId */
	},
};


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Function Prototypes
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Implementation
 *------------------------------------------------------------------------------------------------------------------------------*/

TBX_BOOL VoipCliStringToBool( PTBX_CHAR in_pszString )
{
	TBX_BOOL	fValue = TBX_FALSE;

	if( strcmp(in_pszString, "Y") == 0 )
		fValue = TBX_TRUE;
	else if( strcmp(in_pszString, "N") == 0 )
		fValue = TBX_FALSE;
	else if( strcmp(in_pszString, "YES") == 0 )
		fValue = TBX_TRUE;
	else if( strcmp(in_pszString, "NO") == 0 )
		fValue = TBX_FALSE;
	else if( strcmp(in_pszString, "0") == 0 )
		fValue = TBX_TRUE;
	else if( strcmp(in_pszString, "1") == 0 )
		fValue = TBX_FALSE;
	else if( strcmp(in_pszString, "TRUE") == 0 )
		fValue = TBX_TRUE;
	else if( strcmp(in_pszString, "FALSE") == 0 )
		fValue = TBX_FALSE;

	return fValue;
}

TBX_STREAM_PACKET_TYPE VoipCliStringToPacketType( PTBX_CHAR in_pszString )
{
	TBX_STREAM_PACKET_TYPE PacketType;

	if( strcmp(in_pszString, "G711") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_PCMU;
	else if( strcmp(in_pszString, "G711A") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_PCMA;
	else if( strcmp(in_pszString, "G723") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_G723;
	else if( strcmp(in_pszString, "G726-16") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_G726_16;
	else if( strcmp(in_pszString, "G726-24") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_G726_24;
	else if( strcmp(in_pszString, "G726-32") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_G726_32;
	else if( strcmp(in_pszString, "G726-40") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_G726_40;
	else if( strcmp(in_pszString, "G728") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_G728;
	else if( strcmp(in_pszString, "G729AB") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_G729AB;
	else if( strcmp(in_pszString, "G729E") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_G729E;
	else if( strcmp(in_pszString, "AMR") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_AMR;
	else if( strcmp(in_pszString, "EFR") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_EFR;
	else if( strcmp(in_pszString, "G711-FAX") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_PASSTHRU_ULAW;
	else if( strcmp(in_pszString, "G711A-FAX") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_PASSTHRU_ALAW;
	else if( strcmp(in_pszString, "CLEAR") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_CLEAR_CHANNEL;
	else if( strcmp(in_pszString, "SMV") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_SMV;
	else if( strcmp(in_pszString, "EVRC") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_EVRC;
	else if( strcmp(in_pszString, "QCELP8") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_QCELP8;
	else if( strcmp(in_pszString, "QCELP13") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_QCELP13;
	else if( strcmp(in_pszString, "ILBC13") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_ILBC_13K;
	else if( strcmp(in_pszString, "ILBC15") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_ILBC_15K;
	else if( strcmp(in_pszString, "FR") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_FR;
	else if( strcmp(in_pszString, "T38") == 0 )
		PacketType = TBX_STREAM_PACKET_TYPE_IFP;
	else
		PacketType = TBX_STREAM_PACKET_TYPE_UNKNOWN;

	return PacketType;
}

TB640_VP_GROUP_TYPE VoipCliIntegerToVpGroupType( TBX_UINT32	un32GroupTypeIndex )
{
	TB640_VP_GROUP_TYPE VpGroupType;

	if( un32GroupTypeIndex == 0 )
	{
		VpGroupType = TB640_VP_GROUP_TYPE_0;
	}
	else
	{
		VpGroupType = TB640_VP_GROUP_TYPE_1;
	}

	return VpGroupType;
}

VOIP_RESOURCE_TYPE VoipCliIntegerToFirstResType( TBX_UINT32	un32ResTypeIndex )
{
	VOIP_RESOURCE_TYPE ResourceType;

	if( un32ResTypeIndex == 0 )
	{
		ResourceType = VOIP_RESOURCE_TYPE_TRUNK;
	}
	else if( un32ResTypeIndex == 1 )
	{
		ResourceType = VOIP_RESOURCE_TYPE_MBL_PORT;
	}
	else if( un32ResTypeIndex == 2 )
	{
		ResourceType = VOIP_RESOURCE_TYPE_PROMPT;
	}
	else if( un32ResTypeIndex == 3 )
	{
		ResourceType = VOIP_RESOURCE_TYPE_BERT;
	}
	else if( un32ResTypeIndex == 4 )
	{
		ResourceType = VOIP_RESOURCE_TYPE_RAW_DATA_FILE;
	}
	else
	{
		ResourceType = VOIP_RESOURCE_TYPE_INVALID;
	}

	return ResourceType;
}

VOIP_RESOURCE_TYPE VoipCliIntegerToSecondResType( TBX_UINT32	un32ResTypeIndex )
{
	VOIP_RESOURCE_TYPE ResourceType;

	if( un32ResTypeIndex == 0 )
	{
		ResourceType = VOIP_RESOURCE_TYPE_TRUNK;
	}
	else if( un32ResTypeIndex == 1 )
	{
		ResourceType = VOIP_RESOURCE_TYPE_MBL_PORT;
	}
	else if( un32ResTypeIndex == 2 )
	{
		ResourceType = VOIP_RESOURCE_TYPE_STREAM_SOCKET;
	}
	else
	{
		ResourceType = VOIP_RESOURCE_TYPE_INVALID;
	}

	return ResourceType;
}

TBX_BOOL VoipCliIsValidBoolValue( PTBX_CHAR in_pszString )
{
	if( (strcmp(in_pszString, "Y") == 0)	||
		(strcmp(in_pszString, "N") == 0)	||
		(strcmp(in_pszString, "YES") == 0)	||
		(strcmp(in_pszString, "NO") == 0)	||
		(strcmp(in_pszString, "0") == 0)	||
		(strcmp(in_pszString, "1") == 0)	||
		(strcmp(in_pszString, "TRUE") == 0)	||
		(strcmp(in_pszString, "FALSE") == 0) )
	{
		return TBX_TRUE;
	}

	return TBX_FALSE;
}

TBX_BOOL VoipCliIsValidNumericValue( PTBX_CHAR in_pszString )
{
	PVOIP_CLI_CONTEXT	pCliContext = &g_pContext->CliContext;
	PTBX_CHAR			pszString	= in_pszString;
	TBX_BOOL			fDigitEnded = TBX_FALSE;

	/* Skip initial white spaces */
	while( *pszString && isspace( (int)(*pszString) ) )
	{
		pszString++;
	}
	if( *pszString == '-' )
	{
		/* Accept negative values */
		pszString++;
	}

	while( *pszString )
	{
		if( isspace( (int)(*pszString)) )
		{
			fDigitEnded = TBX_TRUE;
		}
		else if( !isdigit( (int)(*pszString) ) || fDigitEnded )
		{
			TbxCliToolsLogPrint
			(
				pCliContext->hCliTools,
				TRACE_LEVEL_ERROR, NULL,
				"Must be a numeric value ('%s is not a numeric value)!\n",
				in_pszString
			);
			return TBX_FALSE;
		}
		pszString++;
	}
	return TBX_TRUE;
}

TBX_BOOL VoipCliIsValidFirstResourceType( TBX_UINT32	in_un32FirstResTypeIndex )
{
	VOIP_RESOURCE_TYPE ResourceType;

	ResourceType = VoipCliIntegerToFirstResType( in_un32FirstResTypeIndex );
	if( ResourceType == VOIP_RESOURCE_TYPE_INVALID )
	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -