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

📄 parse.c

📁 telcobridges pri develop,30b+d
💻 C
📖 第 1 页 / 共 5 页
字号:
				break;

			/* Gateway port */
			case TB640_ISDN_PARSING_TOKEN_GATEWAY_PORT:
				if( g_AppContext->un32GatewayPortNumber <=  ( TBX_API_MAX_EXTRA_GW_PORTS + 1 ) )
				{
					/* insert the new gateway port in the array and increment the number of gateway port */
					g_AppContext->aun32GatewayPort[g_AppContext->un32GatewayPortNumber] = atoi (pszArgument);
					g_AppContext->un32GatewayPortNumber++;
					fGatewayPortConfigured = TBX_TRUE;
				}
				break;

			/* Make connection with the CTBus? */
			case TB640_ISDN_PARSING_TOKEN_CTBUS_CONNECTION:
				/* Process the CTBus configuration */
				fCTBusConnConfigured = TBX_TRUE;
				result = TB640IsdnParseCTBusConfigurationLine (
					pszArgument,
					pszLine,
					un32Line,
					(pszArgument-pszLine),
					&(g_AppContext->fCTBusConnection));
				if (TBX_RESULT_FAILURE (result))
					TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				break;

			/* Make connection with the CTBus? */
			case TB640_ISDN_PARSING_TOKEN_DO_CONNECTION:
				/* Process the CTBus configuration */
				fDoConnConfigured = TBX_TRUE;
				result = TB640IsdnParseDoConfigurationLine (
					pszArgument,
					pszLine,
					un32Line,
					(pszArgument-pszLine),
					&(g_AppContext->fDoConnection));
				if (TBX_RESULT_FAILURE (result))
					TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				break;

			case TB640_ISDN_PARSING_TOKEN_UNKNOWN:
			default:
				TB640_ISDN_PARSE_ERROR_DISPLAY (un32Line, 0, pszLine, "Syntax error (unknown token)");
				TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				break;
			}
		}

		/* Check for mandatory token */
		if (!fLogFilenamePresent)
		{
			TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "Missing LOG_FILENAME token in configuration file\n");
			TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
		}
		if (!fLogFileLevelPresent)
		{
			TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "Missing LOG_FILE_LEVEL token in configuration file\n");
			TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
		}
		if (!fLogDisplayLevelPresent)
		{
			TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "Missing LOG_DISPLAY_LEVEL token in configuration file\n");
			TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
		}
		if (!fUniqueIdPresent)
		{
			TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "Missing APP_UNIQUE_ID token in configuration file\n");
			TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
		}
		if (!fRefreshRateConfigured)
		{
			TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "Missing MIN_REFRESH token in configuration file\n");
			g_AppContext->un32MinRefreshDelayMsec = 10;
			fRefreshRateConfigured = TBX_TRUE;
		}
		if (!fGatewayPortConfigured)
		{
			TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "Missing TBX_GW_PORT token in configuration file (using env. variables)\n");
			g_AppContext->aun32GatewayPort[0] = (TBX_UINT32)0;
			g_AppContext->un32GatewayPortNumber = 1;
			fGatewayPortConfigured = TBX_TRUE;
		}

		/* End of the code (skip to cleanup) */
		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Print error message */
		TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "%s (Result = 0x%08X, %s, line %d)\n", TBX_ERROR_DESCRIPTION, TBX_ERROR_RESULT, __FILE__, TBX_ERROR_LINE);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
		/* Close open file */
		if (pFileIn != NULL)
		{
			fclose (pFileIn);
			pFileIn = NULL;
		}
	}

	RETURN;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640IsdnParseDoConfigurationLine:	Parses the content of a do connection configuration line and stores
 |										them into our structure
 |
 |  in_pszLine		:	Pointer to the text line
 |  in_pszOriginalLine:	Pointer to the original text line
 |	in_un32Line		:	Line number in the configuration file
 |	in_un32Index	:	Index of the argument in the original string
 |	out_pfDoConn	:	Output flag from the configuration file
 |
 |  Note			:	Line must be converted in CAPS
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640IsdnParseDoConfigurationLine(
  IN		const PTBX_CHAR				in_pszLine,
  IN		const PTBX_CHAR				in_pszOriginalLine,
  IN		TBX_UINT32					in_un32Line,
  IN		TBX_UINT32					in_un32Index,
  IN		PTBX_BOOL					out_pfDoConn)
{
	TBX_CHAR					szLine [TB640_ISDN_MAX_CONFIGURATION_LINE_LENGTH];
	TBX_UINT32					un32Setting;
	TBX_UINT32					un32SizeOfEntry;
	TBX_BOOL					fDoConnConfig;
	PTBX_CHAR					pArg;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variable */
		strcpy (szLine, in_pszLine);
		un32Setting = 0;

		/* Begin parsing */
		pArg = strtok (szLine, TB640_ISDN_LINE_PARSING_DELIMITERS);
		while (NULL != pArg)
		{
			switch (un32Setting)
			{
			/* First argument is the CTBus config */
			case 0:
				{
					TB640_ISDN_PARSE_GET_PARAMETER (								\
					  g_aParseBoolean, 												\
					  &(fDoConnConfig),						 						\
					  "Invalid value. Expecting CTBus connection enable [TRUE/FALSE]");

					*out_pfDoConn = fDoConnConfig;
				}
				break;

			default:
				/* Too many argument found */
				TB640_ISDN_PARSE_ERROR_DISPLAY (in_un32Line, (pArg-szLine+in_un32Index), in_pszOriginalLine, "Too many arguments");
				TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				break;
			}

			/* Process the next argument */
			un32Setting++;

			/* Get the next token */
			pArg = strtok (NULL, TB640_ISDN_LINE_PARSING_DELIMITERS);
		}

		/* End of the code (skip to cleanup) */
		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Print error message */
		TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "%s (Result = 0x%08X, %s, line %d)\n", TBX_ERROR_DESCRIPTION, TBX_ERROR_RESULT, __FILE__, TBX_ERROR_LINE);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
	}

	RETURN;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640IsdnParseTrunkConfigurationLine:	Parses the content of a trunk configuration line and stores them into our structure
 |
 |  in_pszLine		:	Pointer to the text line
 |  in_pszOriginalLine:	Pointer to the original text line
 |	in_un32Line		:	Line number in the configuration file
 |	in_un32Index	:	Index of the argument in the original string
 |	in_un32Adapter	:	Adapter index in our internal array
 |	out_pun32TrunkNb:	Pointer to a variable that will contain the trunk number
 |
 |  Note			:	Line must be converted in CAPS
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640IsdnParseTrunkConfigurationLine(
  IN		const PTBX_CHAR				in_pszLine,
  IN		const PTBX_CHAR				in_pszOriginalLine,
  IN		TBX_UINT32					in_un32Line,
  IN		TBX_UINT32					in_un32Index,
  IN		TBX_UINT32					in_un32Adapter,
  OUT		PTBX_UINT32					out_pun32TrunkNb)
{
	TBX_CHAR					szLine [TB640_ISDN_MAX_CONFIGURATION_LINE_LENGTH];
	TBX_UINT32					un32IdleValue;
	TBX_UINT32					un32Setting;
	TBX_UINT32					un32TrunkNb;
	TBX_UINT32					un32SizeOfEntry;
	PTBX_CHAR					pArg;
	PTB640_ISDN_ADAPTER_INFO	pAdapterInfo;
	PTB640_ISDN_TRUNK_INFO		pTrunkInfo;
	PTB640_TRUNK_CFG			pTrunkCfg;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variable */
		strcpy (szLine, in_pszLine);
		un32Setting = 0;

		/* Begin parsing */
		pArg = strtok (szLine, TB640_ISDN_LINE_PARSING_DELIMITERS);
		while (NULL != pArg)
		{
			switch (un32Setting)
			{
			/* First argument is the trunk number */
			case 0:
				/* Within range ? */
				un32TrunkNb = atoi (pArg);
				if (un32TrunkNb >= TB640_ISDN_MAX_SUPPORTED_TRUNKS_PER_ADAPTER)
				{
					TB640_ISDN_PARSE_ERROR_DISPLAY (in_un32Line, (pArg-szLine+in_un32Index), in_pszOriginalLine, "Numbers from 0 to 63 only");
					TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				}
				*out_pun32TrunkNb = un32TrunkNb;
				pAdapterInfo = &(g_AppContext->ahAdapterInfo [in_un32Adapter]);
				pTrunkInfo = &(pAdapterInfo->aTrunkInfo [un32TrunkNb]);
				pTrunkCfg = &(pTrunkInfo->TrunkConfiguration);

				/* Trunk already configured ? */
				if (pTrunkCfg->Type != 0)
				{
					TB640_ISDN_PARSE_ERROR_DISPLAY (in_un32Line, (pArg-szLine+in_un32Index), in_pszOriginalLine, "Trunk already configured");
					TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				}

				/* Initialize parameters not in the configuration file */
				pTrunkCfg->un32StructVersion = 1;

				break;

			/* Second argument is the trunk type */
			case 1:
				/* Get the trunk type */
				TB640_ISDN_PARSE_GET_PARAMETER (g_aParseTrunkTypes, &(pTrunkCfg->Type), "Invalid value. Expecting trunk type [E1/T1/J1]");
				break;

			/* Third argument is the trunk framing */
			case 2:
				TB640_ISDN_PARSE_GET_TRUNK_PARAMETER (Framing,												\
				  g_aParseTrunkE1Framing, 		"Invalid value. Expecting framing [DFRAME/MFRAME/AUTO]",	\
				  g_aParseTrunkT1Framing, 		"Invalid value. Expecting framing [SF/ESF/SLC96]",			\
				  g_aParseTrunkJ1Framing,		"Invalid value. Expecting framing [SF/ESF/SLC96]");
				break;

			/* Fourth argument is the trunk encoding */
			case 3:
				TB640_ISDN_PARSE_GET_TRUNK_PARAMETER (Encoding,											\
				  g_aParseTrunkE1Encoding, 		"Invalid value. Expecting encoding [HDB3/AMI]",			\
				  g_aParseTrunkT1Encoding, 		"Invalid value. Expecting encoding [B8ZS/AMI/CLEAR]",	\
				  g_aParseTrunkJ1Encoding,		"Invalid value. Expecting encoding [B8ZS/AMI/CLEAR]");
				break;

			/* Fifth argument is the trunk line termination */
			case 4:
				TB640_ISDN_PARSE_GET_TRUNK_PARAMETER (Termination,										\
				  g_aParseTrunkE1Termination, 	"Invalid value. Expecting termination [SHORT/LONG]",	\
				  g_aParseTrunkT1Termination, 	"Invalid value. Expecting termination [SHORT/LONG]",	\
				  g_aParseTrunkJ1Termination,	"Invalid value. Expecting termination [SHORT/LONG]");
				break;

			/* Sixth argument is the trunk loop-time setting */
			case 5:
				TB640_ISDN_PARSE_GET_TRUNK_PARAMETER (fLoopTime,									\
				  g_aParseBoolean, 				"Invalid value. Expecting loop-time [TRUE/FALSE]",	\
				  g_aParseBoolean, 				"Invalid value. Expecting loop-time [TRUE/FALSE]",	\
				  g_aParseBoolean,				"Invalid value. Expecting loop-time [TRUE/FALSE]");
				break;

			/* Seventh argument is the trunk idle code setting */
			case 6:
				un32IdleValue = atoi (pArg);
				if (un32TrunkNb > TB640_ISDN_MAX_IDLE_CODE_VALUE)
				{
					TB640_ISDN_PARSE_ERROR_DISPLAY (in_un32Line, (pArg-szLine+in_un32Index), in_pszOriginalLine, "Invalid value. Expecting idle code [0...127]");
					TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				}
				if (pTrunkCfg->Type == TB640_TRUNK_TYPE_E1)
					pTrunkCfg->Cfg.E1.byIdleCode = (TBX_UINT8)un32IdleValue;
				else if (pTrunkCfg->Type == TB640_TRUNK_TYPE_T1)
					pTrunkCfg->Cfg.T1.byIdleCode = (TBX_UINT8)un32IdleValue;
				else
					pTrunkCfg->Cfg.J1.byIdleCode = (TBX_UINT8)un32IdleValue;
				break;

			default:
				/* Too many argument found */
				TB640_ISDN_PARSE_ERROR_DISPLAY (in_un32Line, (pArg-szLine+in_un32Index), in_pszOriginalLine, "Too many arguments");
				TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				break;
			}

⌨️ 快捷键说明

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