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

📄 parse.c

📁 telcobridges cas develop
💻 C
📖 第 1 页 / 共 5 页
字号:
		else
		{
			pStackCfg->CasTrunkType = TB640_CAS_TRUNK_TYPE_T1_J1;
		}

		/* Begin parsing */
		pArg = strtok (szLine, TB640_CAS_LINE_PARSING_DELIMITERS);
		while (NULL != pArg)
		{
			switch (un32Setting)
			{
			/* First argument is the stack variant */
			case 0:
				TB640_CAS_PARSE_GET_PARAMETER (									\
				  g_aParseStackVariant, 										\
				  &(pStackCfg->CasVariant), 									\
				  "Invalid value. Expecting stack variant [WINK/GROUND/LOOP/FXO/MDR1/R2CHINA/R2KOREA/R2SINGAPORE/R2BANGLADESH/R2GENERIC]");
				break;

			/* Second argument is the stack side */
			case 1:
				TB640_CAS_PARSE_GET_PARAMETER (									\
				  g_aParseStackSide, 											\
				  &(pStackCfg->ProtocolSide), 									\
				  "Invalid value. Expecting protocol side [USER/NETWORK]");
				break;

			/* Third argument is the "fUsingVerboseNotifications" */
			case 2:
				{
					TBX_BOOL		fUsingVerboseNotif = TBX_FALSE;

					TB640_CAS_PARSE_GET_PARAMETER (									\
					  g_aParseBoolean, 												\
					  &(fUsingVerboseNotif),										\
					  "Invalid value. Expecting \"using verbose notifications\" [TRUE/FALSE]");
					if (fUsingVerboseNotif)
					{
						pStackCfg->Options |= TB640_CAS_STACK_OPTIONS_VERBOSE_NOTIFICATIONS;
					}
				}
				break;
			}

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

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

			/* Get to variant specific configuration parameters */
			if (un32Setting >= 3)
			{
				break;
			}
		}

		/* Set the expected number of parameters */
		switch (pStackCfg->CasVariant)
		{
		/* For R1 wink based variants */
		case TB640_CAS_VARIANT_WINK_START:
		case TB640_CAS_VARIANT_FXS_GROUND_START:
		case TB640_CAS_VARIANT_FXS_LOOP_START:
		case TB640_CAS_VARIANT_FXO:
			un32NbExpectedSetting = 4;
			break;

		/* For Taiwan modified R1 variants */
		case TB640_CAS_VARIANT_TAIWAN_R1:
			un32NbExpectedSetting = 5;
			break;

		/* For R2 variants */
		case TB640_CAS_VARIANT_R2_CHINA:
			strcpy (pTrunkInfo->aun8R2PossibleRefuseDigits, "2345");
			pTrunkInfo->un8R2NbRefusalDigit = strlen(pTrunkInfo->aun8R2PossibleRefuseDigits);
			un32NbExpectedSetting = 5;
			break;

		case TB640_CAS_VARIANT_R2_KOREA:
			strcpy (pTrunkInfo->aun8R2PossibleRefuseDigits, "23458");
			pTrunkInfo->un8R2NbRefusalDigit = strlen(pTrunkInfo->aun8R2PossibleRefuseDigits);
			un32NbExpectedSetting = 5;
			break;

		case TB640_CAS_VARIANT_R2_SINGAPORE:
			strcpy (pTrunkInfo->aun8R2PossibleRefuseDigits, "23467");
			pTrunkInfo->un8R2NbRefusalDigit = strlen(pTrunkInfo->aun8R2PossibleRefuseDigits);
			un32NbExpectedSetting = 5;
			break;

		case TB640_CAS_VARIANT_R2_BANGLADESH:
			strcpy (pTrunkInfo->aun8R2PossibleRefuseDigits, "23458");
			pTrunkInfo->un8R2NbRefusalDigit = strlen(pTrunkInfo->aun8R2PossibleRefuseDigits);
			un32NbExpectedSetting = 5;
			break;

		case TB640_CAS_VARIANT_R2_GENERIC:
			strcpy (pTrunkInfo->aun8R2PossibleRefuseDigits, "2345890BCDEF");
			pTrunkInfo->un8R2NbRefusalDigit = strlen(pTrunkInfo->aun8R2PossibleRefuseDigits);
			un32NbExpectedSetting = 5;
			break;

		case TB640_CAS_VARIANT_FIRST:
		case TB640_CAS_VARIANT_LAST:
		case TB640_CAS_VARIANT_RESERVED:
			break;
		}

		/* Continue parsing for procotol specific parameters */
		while (NULL != pArg)
		{
			/* Variant specific */
			switch (pStackCfg->CasVariant)
			{

			/* For R1 wink based variants */
			case TB640_CAS_VARIANT_WINK_START:
			case TB640_CAS_VARIANT_FXS_GROUND_START:
			case TB640_CAS_VARIANT_FXS_LOOP_START:
			case TB640_CAS_VARIANT_FXO:
				switch (un32Setting)
				{
				case 3:
					{
						TBX_BOOL	fUseDid = TBX_TRUE;

						TB640_CAS_PARSE_GET_PARAMETER (									\
						  g_aParseBoolean, 												\
						  &fUseDid,														\
						  "Invalid value. Expecting \"using direct inward dialing\" [TRUE/FALSE]");
						if (fUseDid)
						{
							pStackCfg->Options |= TB640_CAS_STACK_OPTIONS_R1_USE_DID;
						}
					}
					break;

				case 4:
					{
						TBX_BOOL	fUseDtmf = TBX_TRUE;
						TB640_CAS_PARSE_GET_PARAMETER (									\
						  g_aParseBoolean, 												\
						  &fUseDtmf,													\
						  "Invalid value. Expecting \"using DTMF digits\" [TRUE/FALSE]");
						if (!fUseDtmf)
						{
							pStackCfg->Options |= TB640_CAS_STACK_OPTIONS_R1_USE_MFR1_TONES;
						}
					}
					break;

				default:
					TB640_CAS_PARSE_ERROR_DISPLAY (in_un32Line, (pArg-szLine+in_un32Index), in_pszOriginalLine, "Too many arguments");
					TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
					break;
				}
				break;


			/* For Taiwan modified R1 variants */
			case TB640_CAS_VARIANT_TAIWAN_R1:
				switch (un32Setting)
				{
				case 3:
					pStackCfg->un8TMR1NbExpectedDigits = atoi(pArg);
					break;

				case 4:
					TB640_CAS_PARSE_GET_PARAMETER (									\
					  g_aParseMdr1Stage, 											\
					  &(pStackCfg->Stage2Behavior),									\
					  "Invalid value. Expecting stage 2 behavior [NOTUSED/ANI/PTS]");
					break;

				case 5:
					TB640_CAS_PARSE_GET_PARAMETER (									\
					  g_aParseMdr1Stage, 											\
					  &(pStackCfg->Stage3Behavior),									\
					  "Invalid value. Expecting stage 3 behavior [NOTUSED/ANI/PTS]");
					break;

				default:
					TB640_CAS_PARSE_ERROR_DISPLAY (in_un32Line, (pArg-szLine+in_un32Index), in_pszOriginalLine, "Too many arguments");
					TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
					break;
				}
				break;


			/* For R2 variants */
			case TB640_CAS_VARIANT_R2_CHINA:
			case TB640_CAS_VARIANT_R2_KOREA:
			case TB640_CAS_VARIANT_R2_SINGAPORE:
			case TB640_CAS_VARIANT_R2_BANGLADESH:
			case TB640_CAS_VARIANT_R2_GENERIC:
				switch (un32Setting)
				{
				case 3:
					strncpy (pStackCfg->R2BackwardDigits, pArg, sizeof(pStackCfg->R2BackwardDigits));
					pStackCfg->R2BackwardDigits[ sizeof(pStackCfg->R2BackwardDigits) - 1 ] = '\0';
					break;

				case 4:
					strncpy (pTrunkInfo->szCategory, pArg, sizeof(pTrunkInfo->szCategory));
					pTrunkInfo->szCategory[ sizeof(pTrunkInfo->szCategory) - 1 ] = '\0';
					if ((pStackCfg->CasVariant == TB640_CAS_VARIANT_R2_CHINA) &&
						(strlen(pTrunkInfo->szCategory) != 2))
					{
						TB640_CAS_PARSE_ERROR_DISPLAY (in_un32Line, (pArg-szLine+in_un32Index), in_pszOriginalLine, "R2 China requires 2 digits for category [answer to A-6 followed by answer to A-3]");
						TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
					}
					if ((pStackCfg->CasVariant == TB640_CAS_VARIANT_R2_SINGAPORE) &&
						(strlen(pTrunkInfo->szCategory) != 2))
					{
						TB640_CAS_PARSE_ERROR_DISPLAY (in_un32Line, (pArg-szLine+in_un32Index), in_pszOriginalLine, "R2 Singapore requires 2 digits for category [answer to A-6/A-3 followed by answer to A-7]");
						TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
					}
					break;

				case 5:
					/* Store the refusal digit */
					pTrunkInfo->un8R2RefuseDigit = pArg[0];
					break;

				default:
					TB640_CAS_PARSE_ERROR_DISPLAY (in_un32Line, (pArg-szLine+in_un32Index), in_pszOriginalLine, "Too many arguments");
					TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
					break;
				}
				break;

			default:
				TB640_CAS_PARSE_ERROR_DISPLAY (in_un32Line, (pArg-szLine+in_un32Index), in_pszOriginalLine, "Unknown CAS variant");
				TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				break;
			}

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

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

		/* Make sure we have all the configuration parameters */
		if (un32NbExpectedSetting != (un32Setting-1))
		{
			TB640_CAS_PARSE_ERROR_DISPLAY (in_un32Line, strlen(in_pszOriginalLine), in_pszOriginalLine, "Missing configuration parameters");
			TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
		}

		/* Set the timers */
		TB640_CAS_SET_DEFAULT_TIMERS (&pStackCfg->Timers, (pStackCfg->Options & TB640_CAS_STACK_OPTIONS_R1_USE_DID));

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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Print error message */
		TB640_CAS_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;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640CasParseCTBusConfigurationLine:	Parses the content of a CTBus 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_pfCTBusConn	:	Output flag from the configuration file
 |
 |  Note			:	Line must be converted in CAPS
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640CasParseCTBusConfigurationLine(
  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_pfCTBusConn)
{
	TBX_CHAR					szLine [TB640_CAS_MAX_CONFIGURATION_LINE_LENGTH];
	TBX_UINT32					un32Setting;
	TBX_UINT32					un32SizeOfEntry;
	PTBX_CHAR					pArg;
	TBX_BOOL					fCTBusConfig;

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

		/* Begin parsing */
		pArg = strtok (szLine, TB640_CAS_LINE_PARSING_DELIMITERS);
		while (NULL != pArg)
		{
			switch (un32Setting)
			{
			/* First argument is the CTBus config */
			case 0:
				{
					TB640_CAS_PARSE_GET_PARAMETER (									\
					  g_aParseBoolean, 												\
					  &(fCTBusConfig),										\
					  "Invalid value. Expecting CTBus connection enable [TRUE/FALSE]");
						
					*out_pfCTBusConn = fCTBusConfig;
				}
				break;
		
			default:
				/* Too many argument found */
				TB640_CAS_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_CAS_LINE_PARSING_DELIMITERS);
		}

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

⌨️ 快捷键说明

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