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

📄 voip_parse.c

📁 telcobridges voip develop
💻 C
📖 第 1 页 / 共 5 页
字号:
			case VOIP_PARSING_TOKEN_PAUSE:
				if( SubGroup == VOIP_PARSING_GROUP_DEMO )
				{
					/* Process the pause configuration line */
					Result = VoipParsePauseConfigurationLine(
						pAdapterContext,
						pszArgument,
						pszLine,
						un32Line,
						(pszArgument-pszLine) );
				}
				else
				{
					Result = TBX_RESULT_NOT_SUPPORTED;
				}
				if (TBX_RESULT_FAILURE (Result) == TBX_TRUE)
				{
					VOIP_PARSE_ERROR_DISPLAY (un32Line, (pszToken-pszLine), pszLine, "Disconnect configuration line error");
					TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				}
				break;

			/* Title line processing */
			case VOIP_PARSING_TOKEN_TITLE:
				if( SubGroup == VOIP_PARSING_GROUP_DEMO )
				{
					/* Process the pause configuration line */
					Result = VoipParseTitleConfigurationLine(
						pAdapterContext,
						pszArgument,
						pszLine,
						un32Line,
						(pszArgument-pszLine) );
				}
				else
				{
					Result = TBX_RESULT_NOT_SUPPORTED;
				}
				if (TBX_RESULT_FAILURE (Result) == TBX_TRUE)
				{
					VOIP_PARSE_ERROR_DISPLAY (un32Line, (pszToken-pszLine), pszLine, "Title configuration line error");
					TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				}
				break;

			case VOIP_PARSING_TOKEN_UNKNOWN:
			default:
				VOIP_PARSE_ERROR_DISPLAY (un32Line, 0, pszLine, "Syntax error (unknown or not relevant token)");
				TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				break;
			}
		}

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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Print error message */
		TbxCliToolsLogPrint(
			pCliContext->hCliTools,
			TRACE_LEVEL_ERROR, NULL,
			"VoipParseAndLoadConfiguration: %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;
}


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Utility functions
 *------------------------------------------------------------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipParseToken	:	Parses the current line and returns the token type if known
 |
 |  in_pszLine		:	Pointer to the text line
 |	out_pTokenType	:	Pointer to a variable that will contain the token type
 |	out_ppszToken	:	Pointer to a variable that will contain a pointer to the token after the found token
 |						(of NULL if no token is discovered)
 |	out_ppszArgument:	Pointer to a variable that will contain a pointer to the argument following the token after the found
 |						token (of NULL if no token is discovered).
 |
 |  Note			:	Line must be converted in CAPS
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
VoipParseToken(
  IN		const PTBX_CHAR			in_pszLine,
  OUT		PVOIP_PARSING_TOKEN		out_pTokenType,
  OUT		PTBX_CHAR *				out_ppszToken,
  OUT		PTBX_CHAR *				out_ppszArgument)
{
	PVOIP_CLI_CONTEXT	pCliContext;
	TBX_CHAR			szLine [VOIP_MAX_CONFIGURATION_LINE_LENGTH];
	TBX_UINT32			un32SizeOfEntry;
	PTBX_CHAR			pszParsePtr;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variable */
		pCliContext	= &g_pContext->CliContext;
		strcpy (szLine, in_pszLine);

		/* Initialize output arguments */
		*out_pTokenType = VOIP_PARSING_TOKEN_UNKNOWN;
		*out_ppszToken = NULL;
		*out_ppszArgument = NULL;

		/* Found the first text string */
		pszParsePtr = strtok (szLine, VOIP_PARSING_DELIMITERS);
		if (pszParsePtr != NULL)
		{
			/* Check if this is a comment */
			if (pszParsePtr[0] == '#')
			{
				*out_pTokenType = VOIP_PARSING_TOKEN_COMMENT;
				*out_ppszToken = (in_pszLine + (pszParsePtr - szLine));
				*out_ppszArgument = (in_pszLine + (pszParsePtr - szLine)) + 1;
			}
			else
			{
				/* Get the value of the token */
				VoipCompareEntries (pszParsePtr, g_aParseMainConfigItems, (PTBX_UINT32)out_pTokenType, &un32SizeOfEntry);
				if (*out_pTokenType != VOIP_PARSING_TOKEN_UNKNOWN)
				{
					*out_ppszToken = (in_pszLine + (pszParsePtr - szLine));
					*out_ppszArgument = (in_pszLine + (pszParsePtr - szLine)) + un32SizeOfEntry;
				}
			}
		}
		else
		{
			/* Empty line */
			*out_pTokenType = VOIP_PARSING_TOKEN_COMMENT;
			*out_ppszToken = (in_pszLine + (pszParsePtr - szLine));
			*out_ppszArgument = (in_pszLine + (pszParsePtr - szLine)) + 1;
		}

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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Print error message */
		TbxCliToolsLogPrint(
			pCliContext->hCliTools,
			TRACE_LEVEL_ERROR,
			"VoipParseToken: %s (Result 0x%08X, %s, line %d)\n",
			TBX_ERROR_DESCRIPTION,
			TBX_ERROR_RESULT,
			__FILE__,
			TBX_ERROR_LINE);
	}

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipCompareEntries:	Compare a string with a number of entries to find a specific value
 |
 |  in_pszLine				:	Pointer to the text line
 |	in_paParsingEntries		:	Pointer to an array of parsing entries
 |	out_pun32Value			:	Pointer to a variable that will contain the value of the compared string
 |								(does nothing if it isn't found)
 |	out_pun32SizeOfEntry	:	Pointer to a variable that will contain the size of the found token (0 otherwise)
 |
 |  Note					:	Line must be converted in CAPS
 |
 |  Return					:	TBX_RESULT_OK
 |								TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
VoipCompareEntries(
  IN		const PTBX_CHAR		in_pszLine,
  IN		PVOIP_PARSING_ENTRY	in_paParsingEntries,
  OUT		PTBX_UINT32			out_pun32Value,
  OUT		PTBX_UINT32			out_pun32SizeOfEntry)
{
	TBX_CHAR	szDummyErrorString[ 256 ];

	szDummyErrorString[0] = '\0';
	return VoipCompareEntriesBuildErrString
	(
		in_pszLine,
		in_paParsingEntries,
		out_pun32Value,
		out_pun32SizeOfEntry,
		szDummyErrorString
	);
}

TBX_RESULT
VoipCompareEntriesBuildErrString(
  IN		const PTBX_CHAR		in_pszLine,
  IN		PVOIP_PARSING_ENTRY	in_paParsingEntries,
  OUT		PTBX_UINT32			out_pun32Value,
  OUT		PTBX_UINT32			out_pun32SizeOfEntry,
  OUT		TBX_CHAR			out_szErrorString[ 256 ] )
{
	PVOIP_CLI_CONTEXT	pCliContext;
	TBX_UINT32			un32Count;
	PVOIP_PARSING_ENTRY	pParsingEntry;
	TBX_BOOL			fFirst = TBX_TRUE;
	TBX_UINT32			un32LongestMatchedString;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		pCliContext	= &g_pContext->CliContext;
		un32LongestMatchedString	=	0;
		/* Initialize output arguments */
		strncat( out_szErrorString, "[ ", (sizeof(TBX_CHAR)*256)-strlen(out_szErrorString)-1 );
		out_szErrorString[ (sizeof(TBX_CHAR)*256) - 1 ] = '\0';

		/* Check for other tokens */
		un32Count = 0;
		do
		{
			/* Get the parsing entry pointer */
			pParsingEntry = &(in_paParsingEntries [un32Count++]);

			/* See if this token corresponds to what we have */
			if (pParsingEntry->pszIdentifier != NULL)
			{
				if (strncmp(pParsingEntry->pszIdentifier, in_pszLine, strlen(pParsingEntry->pszIdentifier)) == 0 )
				{
					if( strlen( pParsingEntry->pszIdentifier ) > un32LongestMatchedString )
					{
						*out_pun32Value = pParsingEntry->un32Value;
						un32LongestMatchedString = strlen( pParsingEntry->pszIdentifier );
					}
					if( out_pun32SizeOfEntry != NULL )
					{
						*out_pun32SizeOfEntry = strlen (pParsingEntry->pszIdentifier);
					}
				}

				if( !fFirst )
				{
					strncat( out_szErrorString, ", ", (sizeof(TBX_CHAR)*256)-strlen(out_szErrorString)-1 );
					out_szErrorString[ (sizeof(TBX_CHAR)*256) - 1 ] = '\0';
				}
				strncat( out_szErrorString, pParsingEntry->pszIdentifier, (sizeof(TBX_CHAR)*256)-strlen(out_szErrorString)-1 );
				out_szErrorString[ (sizeof(TBX_CHAR)*256) - 1 ] = '\0';
				fFirst = TBX_FALSE;
			}

		} while (pParsingEntry->pszIdentifier != NULL);

		strncat( out_szErrorString, " ]", (sizeof(TBX_CHAR)*256)-strlen(out_szErrorString)-1 );
		out_szErrorString[ (sizeof(TBX_CHAR)*256) - 1 ] = '\0';

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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Print error message */
		TbxCliToolsLogPrint(
			pCliContext->hCliTools,
			TRACE_LEVEL_ERROR,
			"VoipCompareEntriesBuildErrString: %s (Result 0x%08X, %s, line %d)\n",
			TBX_ERROR_DESCRIPTION,
			TBX_ERROR_RESULT,
			__FILE__,
			TBX_ERROR_LINE);
	}

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipGetTokenString	:	Search in an array of parsing token entries and return the first matching token string with the
 |							given token value.
 |
 |	in_paParsingEntries	:	Pointer to an array of token parsing entries
 |	in_un32Value		:	Searching token value
 |
 |  Note				:
 |
 |  Return				:	The string pointer or NULL if not found.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
PTBX_CHAR VoipGetTokenString(
  IN		PVOIP_PARSING_ENTRY	in_paParsingEntries,
  IN		TBX_UINT32			in_un32Value )
{
	PVOIP_CLI_CONTEXT	pCliContext;
	PVOIP_PARSING_ENTRY	pParsingEntry;
	PTBX_CHAR			pszToken = NULL;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		pCliContext = &g_pContext->CliContext;

		/* Check for tokens value */
		pParsi

⌨️ 快捷键说明

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