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

📄 voip_cli_cmd.c

📁 telcobridges voip develop
💻 C
📖 第 1 页 / 共 5 页
字号:
		return TBX_FALSE;
	}

	return TBX_TRUE;
}

TBX_BOOL VoipCliIsValidSecondResourceType( TBX_UINT32	in_un32SecondResTypeIndex )
{
	VOIP_RESOURCE_TYPE ResourceType;

	ResourceType = VoipCliIntegerToSecondResType( in_un32SecondResTypeIndex );
	if( ResourceType == VOIP_RESOURCE_TYPE_INVALID )
	{
		return TBX_FALSE;
	}

	return TBX_TRUE;
}

TBX_BOOL VoipCliIsValidPacketType( PTBX_CHAR in_pszString )
{
	TBX_STREAM_PACKET_TYPE PacketType;

	PacketType = VoipCliStringToPacketType( in_pszString );
	if( PacketType == TBX_STREAM_PACKET_TYPE_UNKNOWN )
	{
		return TBX_FALSE;
	}

	return TBX_TRUE;
}

TBX_BOOL VoipCliIsValidStreamSocketIP( PTBX_CHAR in_pszString )
{
	TBX_INT	unValueCount;
	TBX_INT	aunValue[5];

	if( strlen( in_pszString ) > ((4*3) + 3))
	{
		return TBX_FALSE;
	}

	unValueCount = sscanf( in_pszString, "%u.%u.%u.%u.%u", &aunValue[0], &aunValue[1], &aunValue[2], &aunValue[3], &aunValue[4] );
	if( unValueCount != 4 )
	{
		return TBX_FALSE;
	}

	if( (aunValue[0] > 255) || (aunValue[1] > 255) || (aunValue[2] > 255) || (aunValue[3] > 255) )
	{
		return TBX_FALSE;
	}

	return TBX_TRUE;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipCliCmdQuitInit		:	Prepare user prompts for the 'Quit' command
 |  VoipCliCmdQuitValidate	:	Validate each user's input (called once per prompt)
 |  VoipCliCmdQuitApply		:	Apply the command
 |
 |  in_pCmdContext			:	Context of the command-line.
 |
 |  Note					:	~
 |
 |  Return					:	TBX_RESULT_OK
 |								TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipCliCmdQuitInit(
	IN OUT	PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	/* Start gathering input for 'Quit' */
	io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_QUIT;

	/* Set prompt command */
	strcpy( io_pCmdContext->paszPrompt[0].szLine, "Are you sure? " );

	/* Save new default prompt values */
	g_DefaultPrompts.Quit.fConfirm = TBX_FALSE;

	/* Set default user input value */
	sprintf( io_pCmdContext->paszUserInput[0].szLine, "%s", (g_DefaultPrompts.Quit.fConfirm == TBX_TRUE) ? "YES":"NO" );
}

TBX_BOOL VoipCliCmdQuitValidate(
	IN OUT	PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	PTBX_CHAR	pszUserInput = io_pCmdContext->paszUserInput[ io_pCmdContext->un32CurrentPromptIdx ].szLine;

	/* Make uppercase */
	ToUpper( pszUserInput );

	switch( io_pCmdContext->un32CurrentPromptIdx )
	{
		case 0:	/* Validate quit confirm */
		{
			if( !VoipCliIsValidBoolValue( pszUserInput ) )
			{
				/* Restore a valid value */
				sprintf( pszUserInput, "%s", (g_DefaultPrompts.Quit.fConfirm == TBX_TRUE) ? "YES":"NO" );
				return TBX_FALSE;
			}

		} break;
	}

	return TBX_TRUE;
}

TBX_VOID VoipCliCmdQuitApply(
	IN OUT	PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	PVOIP_CLI_CONTEXT	pCliContext = &g_pContext->CliContext;
	TBX_BOOL			fConfirm;

	fConfirm = VoipCliStringToBool( io_pCmdContext->paszUserInput[ 0 ].szLine );

	if( fConfirm == TBX_TRUE )
	{
		/* Quit the application */
		VoipCliSendQuit();

		/* Scroll down (to see quitting logs) */
		TbxCliToolsLogScroll
		(
			pCliContext->hCliTools,
			TBX_FALSE,
			TBX_CLI_TOOLS_SCROLL_END
		);
	}

	/* No more input to take. Return to main menu input. */
	io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_NONE;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipCliCmdLogFindInit		:	Prepare user prompts for the 'Make call' command
 |  VoipCliCmdLogFindValidate	:	Validate each user's input (called once per prompt)
 |  VoipCliCmdLogFindApply		:	Apply the command
 |
 |  in_pCliContext				:	Context of the comand-line
 |
 |  Note						:	~
 |
 |  Return						:	TBX_RESULT_OK
 |									TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipCliCmdLogFindInit(
	IN		PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	/* Start gathering input for 'make call' */
	io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_LOG_FIND;

	/* Set prompt command */
	strcpy( io_pCmdContext->paszPrompt[0].szLine, "String to find (empty to stop search): "  );

	/* Set default user input value */
	sprintf( io_pCmdContext->paszUserInput[0].szLine, "%s", g_DefaultPrompts.LogFind.szSearchString );
}

TBX_BOOL VoipCliCmdLogFindValidate(
	IN		PTBX_CLI_TOOLS_CMD		io_pCmdContext )
{
	PTBX_CHAR	pszUserInput = io_pCmdContext->paszUserInput[ io_pCmdContext->un32CurrentPromptIdx ].szLine;

	switch( io_pCmdContext->un32CurrentPromptIdx )
	{
		case 0:	/* Validate string to find */
		{
			if( pszUserInput[0] == '\0' )
			{
				/* Cancel the find */
				io_pCmdContext->paszPrompt[1].szLine[0] = '\0';
			}
			else
			{
				/* Anything is good */
			}
		} break;
	}

	return TBX_TRUE;
}

TBX_VOID VoipCliCmdLogFindApply(
	IN		PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	PVOIP_CLI_CONTEXT	pCliContext = &g_pContext->CliContext;

	/* Save new default prompt values */
	strcpy( g_DefaultPrompts.LogFind.szSearchString,
		io_pCmdContext->paszUserInput[0].szLine );

	/* Search in log (previous occurence) */
	TbxCliToolsLogGotoString
	(
		pCliContext->hCliTools,
		g_DefaultPrompts.LogFind.szSearchString,
		TBX_FALSE,
		TBX_FALSE
	);

	/* Search in log (next occurence) */
	TbxCliToolsLogGotoString
	(
		pCliContext->hCliTools,
		g_DefaultPrompts.LogFind.szSearchString,
		TBX_TRUE,
		TBX_FALSE
	);

	/* No more input to take. Return to main menu input. */
	io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_NONE;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipCliCmdSelectPageInit		:	Prepare user prompts for the 'Select page' command
 |  VoipCliCmdSelectPageValidate	:	Validate each user's input (called once per prompt)
 |  VoipCliCmdSelectPageApply		:	Apply the command
 |
 |  in_pCmdContext					:	Context of the command-line.
 |
 |  Note							:	~
 |
 |  Return							:	TBX_RESULT_OK
 |										TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipCliCmdSelectPageInit(
	IN OUT	PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	/* Start gathering input for 'select page' */
	io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_SELECT_PAGE;

	/* Set prompt command */
	strcpy( io_pCmdContext->paszPrompt[0].szLine, "Enter page number: "  );

	/* Set default user input value */
	sprintf( io_pCmdContext->paszUserInput[0].szLine, "%u", (unsigned int)g_DefaultPrompts.SelectPage.un32Page );
}

TBX_BOOL VoipCliCmdSelectPageValidate(
	IN OUT	PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	PVOIP_CLI_CONTEXT	pCliContext = &g_pContext->CliContext;
	PTBX_CHAR			pszUserInput = io_pCmdContext->paszUserInput[ io_pCmdContext->un32CurrentPromptIdx ].szLine;

	/* Make uppercase */
	ToUpper( pszUserInput );

	switch( io_pCmdContext->un32CurrentPromptIdx )
	{
		case 0:	/* Validate page */
		{
			TBX_UINT32	un32Page = strtoul( pszUserInput, NULL, 10 );

			if( !VoipCliIsValidNumericValue( pszUserInput ) )
			{
				/* Restore a valid value */
				sprintf( pszUserInput, "%u", (int)g_DefaultPrompts.SelectPage.un32Page );
				return TBX_FALSE;
			}

			if( (un32Page == 0) || (un32Page > pCliContext->un32PageCount) )
			{
				TbxCliToolsLogPrint
				(
					pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL,
					"Invalid page number (%u). Must be between 1 and %u.\n",
					(unsigned int)un32Page,
					(unsigned int)pCliContext->un32PageCount
				);

				/* Restore a valid value */
				sprintf( pszUserInput, "%u", (int)g_DefaultPrompts.SelectPage.un32Page );
				return TBX_FALSE;
			}

		} break;
	}

	return TBX_TRUE;
}

TBX_VOID VoipCliCmdSelectPageApply(
	IN OUT	PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	PVOIP_CLI_CONTEXT	pCliContext = &g_pContext->CliContext;
	TBX_UINT32			un32Page;

	/* Save new default prompt values */
	g_DefaultPrompts.SelectPage.un32Page =
		(TBX_UINT32)strtoul( io_pCmdContext->paszUserInput[ 0 ].szLine, NULL, 0 );

	un32Page = g_DefaultPrompts.SelectPage.un32Page;
	pCliContext->un32PageIndex = (un32Page - 1);

	/* No more input to take. Return to main menu input. */
	io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_NONE;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipCliCmdSelectStreamInit		:	Prepare user prompts for the 'Select stream' command
 |  VoipCliCmdSelectStreamValidate	:	Validate each user's input (called once per prompt)
 |  VoipCliCmdSelectStreamApply		:	Apply the command
 |
 |  in_pCmdContext					:	Context of the command-line.
 |
 |  Note							:	~
 |
 |  Return							:	TBX_RESULT_OK
 |										TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipCliCmdSelectStreamInit(
	IN OUT	PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	/* Start gathering input for 'select page' */
	io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_SELECT_STREAM;

	/* Set prompt command */
	strcpy( io_pCmdContext->paszPrompt[0].szLine, "Get global accumulated statistics: " );
	strcpy( io_pCmdContext->paszPrompt[1].szLine, "Enter interace type(0=BASE, 1=VOIP): " );
	strcpy( io_pCmdContext->paszPrompt[2].szLine, "Enter Rx IP port: " );
	strcpy( io_pCmdContext->paszPrompt[3].szLine, "Enter Tx IP port: " );
	strcpy( io_pCmdContext->paszPrompt[4].szLine, "Reset stats: " );

	/* Set default user input value */
	sprintf( io_pCmdContext->paszUserInput[0].szLine, "%s", (g_DefaultPrompts.SelectStream.fGlobalStats == TBX_TRUE) ? "YES":"NO" );
	sprintf( io_pCmdContext->paszUserInput[1].szLine, "%u", (unsigned int)g_DefaultPrompts.SelectStream.un32InterfaceIndex );
	sprintf( io_pCmdContext->paszUserInput[2].szLine, "%u", (unsigned int)g_DefaultPrompts.SelectStream.un16RxIPPort );
	sprintf( io_pCmdContext->paszUserInput[3].szLine, "%u", (unsigned int)g_DefaultPrompts.SelectStream.un16TxIPPort );
	sprintf( io_pCmdContext->paszUserInput[4].szLine, "%s", (g_DefaultPrompts.SelectStream.fResetStats == TBX_TRUE) ? "YES":"NO" );
}

TBX_BOOL VoipCliCmdSelectStreamValidate(
	IN OUT	PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	PVOIP_CLI_CONTEXT	pCliContext = &g_pContext->CliContext;
	PTBX_CHAR			pszUserInput = io_pCmdContext->paszUserInput[ io_pCmdContext->un32CurrentPromptIdx ].szLine;

	/* Make uppercase */
	ToUpper( pszUserInput );

	switch( io_pCmdContext->un32CurrentPromptIdx )
	{
		case 0:	/* Validate global stats indication */
		{
			if( !VoipCliIsValidBoolValue( pszUserInput ) )
			{
				/* Restore a valid value */
				sprintf( pszUserInput, "%s", (g_DefaultPrompts.SelectStream.fGlobalStats == TBX_TRUE) ? "YES":"NO" );
				return TBX_FALSE;
			}

		} break;

		case 1:	/* Validate interface index */
		{
			TBX_UINT32	un32InterfaceIndex = strtoul( pszUserInput, NULL, 10 );

			if( !VoipCliIsValidNumericValue( pszUserInput ) )
			{
				/* Restore a valid value */
				sprintf( pszUserInput, "%u", (int)g_DefaultPrompts.SelectStream.un32InterfaceIndex );
				return TBX_FALSE;
			}

			if( un32InterfaceIndex > 1 )
			{
				TbxCliToolsLogPrint
				(
					pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL,
					"Invalid interface index (%u). Must be between 0 and 1.\n",
					(unsigned int)un32InterfaceIndex
				);

				/* Restore a valid value */
				sprintf( pszUserInput, "%u", (int)g_DefaultPrompts.SelectStream.un32InterfaceIndex );
				return TBX_FALSE;

⌨️ 快捷键说明

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