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

📄 chpars.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * Copyright (C) Ericsson Mobile Communications AB, 2000.
 * Licensed to AU-System AB.
 * All rights reserved.
 *
 * This software is covered by the license agreement between
 * the end user and AU-System AB, and may be used and copied
 * only in accordance with the terms of the said agreement.
 *
 * Neither Ericsson Mobile Communications AB nor AU-System AB
 * assumes any responsibility or liability for any errors or inaccuracies in
 * this software, or any consequential, incidental or indirect damage arising
 * out of the use of the Generic WAP Client software.
 */
/*========================================================================

	WAP WTA Implementation Project

==========================================================================

	File: chpars.c

	Description:

	Author: Jens Pommer, AU-System Radio AB

	Revision history:
	Date    Sign	Comment
	990722  CEF		First version
	990815	JPR		Functionality added
	991105	JPR		Correction Ch_GetTitle and Ch_GetAbstract
	000204	JPR		Updated to support new WBXML-decoder
	000207	JPR		Corrections
	000210	JPR		Functions updated
	000223	JPR		Correction in Ch_IsResourceFresh
	000224	JPR		Function Ch_ValidateChannelContent added
	000630	JPR		Updated for WAP 1.2.1
	000814	JPR		Handling of PIs corrected
	001011	ASPN	Lower-case filenames
	010119	NKE		Updated Ch_BuildStructure for the new decoder in wbxmldec.c.
	010126	NKE		Changed Ch_BuildStructure

=========================================================================*/

/* Private include statements */

#include "chpars.h"
#include "wbxmldec.h"
#include "wtachtok.h"
#include "wtachelm.h"
#include "wtachdef.h"
#include "wtachdec.h"
#include "hdrutil.h"
#include "headdef.h"

/*========================================================================
	INTERNAL FUNCTIONS
=========================================================================*/

/*========================================================================
	Ch_ValidateChannelContent
==========================================================================
	The function validates the decoded structure and checks that all
	REQUIRED attributes are specified, and all mandatory elements are
	included. If the validation is OK, TRUE is returned. Otherwise FALSE
	is returned.
	
	Input :	Structure of channel content (pELEMENTTYPE)
	Output:	BOOL
==========================================================================*/
BOOL Ch_ValidateChannelContent (pELEMENTTYPE pChannel)
{
	pELEMENTTYPE pContent=NULL;

	/* Check if channel exists */
	if (( pChannel != NULL ) && ( pChannel->iType == Ch_Type_channel ))
	{
		/* Maxspace ??? */

		/* ChannelId */
		if (((pCH_CHANNELELEMENT)(pChannel))->pwchChannelID == NULL )
		{
			return FALSE;
		}

		/* Get channel content. At least title MUST be defined - DTD */
		pContent=Ch_GetContent ( pChannel );

		/* Check if title exists */
		if (( pContent != NULL ) && ( pContent->iType == Ch_Type_title ))
		{
			pContent = pContent->pNextElement;

			/* Check if abstract exists */
			if (( pContent!= NULL ) && ( pContent->iType == Ch_Type_abstract ))
			{
				/* Step past abstract */
				pContent = pContent->pNextElement;
			}

			/* Check if all resources have their url defined */
			while ( pContent!=NULL )
			{
				if ( pContent->iType == Ch_Type_resource )
				{
					if ( ((pCH_RESOURCEELEMENT)(pContent))->pbHref == NULL )
					{
						/* No url */
						return FALSE;
					}
				}
				else
				{
					/* Not a resource */
					return FALSE;
				}

				/* Next */
				pContent = pContent->pNextElement;
			}

			/* Tests passed */
			return TRUE;
		}
	}

	return FALSE;
}


/*========================================================================
	EXTERNAL FUNCTIONS
=========================================================================*/


/*========================================================================
	Ch_BuildStructure
==========================================================================*/
pDECSTR Ch_BuildStructure (BYTE *pbData, BYTE *pbEnd, INT16 iCharset, 
						   UINT8 iContentLevel, UINT8 iViewID)
{
	pWBXMLDECODESTR pDecStr=NULL;
	pELEMENTTYPE pStructure=NULL;
	BOOL finished;

	/* IS THIS PARAMETER NEEDED? (Error handling) */
	iViewID=iViewID;

	/* Create tWBXMLDECODESTR and init the attributes */
	pDecStr=WBXML_CreateWBXMLDecStr();

	if (pDecStr!=NULL)
	{
		/* Set the function pointers */
		pDecStr->DTD_CreateElement=Ch_CreateElement;
		pDecStr->DTD_DeleteElement=Ch_DeleteElement;
		pDecStr->DTD_ValidContent=Ch_ValidContent;
		pDecStr->DTD_GetContent=Ch_GetContent;
		pDecStr->DTD_AppSpecParseMod=Ch_AppSpecParseMod;
		pDecStr->DTD_StoreAttributeValue=Ch_StoreAttributeValue;
		pDecStr->DTD_GetAttributeValue=Ch_GetAttributeValue;
		pDecStr->DTD_LiteralAttributeToToken=Ch_LiteralAttributeToToken;
		pDecStr->DTD_LiteralTagToToken=Ch_LiteralTagToToken;
		pDecStr->DTD_CheckPublicID=Ch_CheckPublicID;

		/* Store data in the decode struct */
		pDecStr->bContentType='\x16';	/* text/vnd.wap.channelc */
		pDecStr->iCharset=iCharset;
		pDecStr->iContentLevel=iContentLevel;
		pDecStr->pbCurByte=pbData;
		pDecStr->pbEnd=pbEnd;
		pDecStr->iDecodeResult=0;		
		pDecStr->pAppSpec=NULL;

		/* Parse prolog */
		if (WBXML_DecodeProlog(pDecStr))
		{
			/* Step past all PI:s */
			WBXML_StepPastAllPIs (pDecStr);

			/* Parse channel */
			WBXML_InitDecode(pDecStr, FALSE);
			pStructure = WBXML_Decode(pDecStr, &finished);

			/* Step past all PI:s */
			WBXML_StepPastAllPIs (pDecStr);
		}

		/* Check if any errors or warnings */
		if ( pDecStr->iDecodeResult == 0 )
		{
			/* Validate structure */
			if (Ch_ValidateChannelContent (pStructure))
			{
				/* Store the structure under the application specific pointer
				   in the decode struct. */
				pDecStr->pAppSpec=pStructure;

				/* Return the decode struct */
				return pDecStr;
			}
		}

		/* Error - delete */
		Ch_DeleteElement(pDecStr,&pStructure);

		/* Delete decode struct */
		WBXML_DeleteWBXMLDecStr(&pDecStr);
	}

	/* Error */
	return NULL;
}


/*========================================================================
	Ch_DeleteStructure
==========================================================================*/
void Ch_DeleteStructure (pDECSTR* ppDecStr)
{
	if (*ppDecStr!=NULL)
	{
		/* Get the top element */
		pELEMENTTYPE pStructure=(*ppDecStr)->pAppSpec;

		/* Delete structure */
		Ch_DeleteElement(*ppDecStr,&pStructure);
		(*ppDecStr)->pAppSpec=NULL;

		/* Delete decode struct */
		WBXML_DeleteWBXMLDecStr(ppDecStr);
	}
}


/*========================================================================
	Ch_GetAbstract
==========================================================================*/
WCHAR* Ch_GetAbstract (pDECSTR pDecStr)
{
	pELEMENTTYPE pContent=NULL;
	pELEMENTTYPE pText=NULL;

	if (pDecStr!=NULL)
	{
		pContent=pDecStr->pAppSpec;

		/* Check type */
		if ((pContent!=NULL)&&(pContent->iType==Ch_Type_channel))
		{
			pContent=Ch_GetContent (pContent);

			while (pContent!=NULL)
			{
				/* Check if abstract element */
				if (pContent->iType==Ch_Type_abstract)
				{
					/* Get text */
					pText=Ch_GetContent (pContent);

					/* Only #PCDATA allowed as content */
					if (pText!=NULL)
					{
						return XML_GetString (pText,pDecStr);
					}
				}

				/* Get next */
				pContent=XML_GetNextElement (pContent);
			}
		}
	}

	/* Return NULL*/
	return NULL;
}


/*========================================================================
	Ch_GetTitle
==========================================================================*/
WCHAR* Ch_GetTitle (pDECSTR pDecStr)
{
	pELEMENTTYPE pContent=NULL;
	pELEMENTTYPE pText=NULL;

	if (pDecStr!=NULL)
	{
		pContent=pDecStr->pAppSpec;

		/* Check type */
		if ((pContent!=NULL)&&(pContent->iType==Ch_Type_channel))
		{
			pContent=Ch_GetContent (pContent);

			while (pContent!=NULL)
			{
				/* Check if abstract element */
				if (pContent->iType==Ch_Type_title)
				{
					/* Get text */
					pText=Ch_GetContent (pContent);

					/* Only #PCDATA allowed as content */
					if (pText!=NULL)
					{
						return XML_GetString (pText,pDecStr);
					}
				}

				/* Get next */
				pContent=XML_GetNextElement (pContent);
			}
		}
	}

	/* Return NULL*/
	return NULL;
}

/*========================================================================
	Ch_Getuseraccessible
==========================================================================
Purpose:  The function returns the value of the useraccessible attribute.
======================================================================== */
BOOL Ch_Getuseraccessible (pDECSTR pDecStr)
{
	pELEMENTTYPE pChannel=NULL;

	if (pDecStr!=NULL)
	{
		pChannel=pDecStr->pAppSpec;

		/* Check type */
		if ((pChannel!=NULL)&&(pChannel->iType==Ch_Type_channel))
		{
			return (((CH_CHANNELELEMENT*)(pChannel))->fUserAccessible);
		}
	}
	return FALSE;
}


/*========================================================================
	Ch_GetSuccessUrl
==========================================================================*/
BYTE* Ch_GetSuccessUrl (pDECSTR pDecStr)
{
	BYTE *pbCopy=NULL;
	pELEMENTTYPE pChannel=NULL;

	if (pDecStr!=NULL)
	{
		pChannel=pDecStr->pAppSpec;

		/* Check type */
		if ((pChannel!=NULL)&&(pChannel->iType==Ch_Type_channel))
		{
			if (((CH_CHANNELELEMENT*)(pChannel))->pbSuccess!=NULL)
			{
				/* Get copy of success url */
				pbCopy=B_CopyByteString (
					((CH_CHANNELELEMENT*)(pChannel))->pbSuccess,-1);

				/* return copy */
				return pbCopy;
			}
		}
	}

	return NULL;
}


/*========================================================================
	Ch_GetFailureUrl
==========================================================================*/
BYTE* Ch_GetFailureUrl (pDECSTR pDecStr)
{
	BYTE *pbCopy=NULL;
	pELEMENTTYPE pChannel=NULL;

	if (pDecStr!=NULL)
	{
		pChannel=pDecStr->pAppSpec;

		/* Check type */
		if ((pChannel!=NULL)&&(pChannel->iType==Ch_Type_channel))
		{
			if (((CH_CHANNELELEMENT*)(pChannel))->pbFailure!=NULL)
			{
				/* Get copy of failure url */
				pbCopy=B_CopyByteString (
					((CH_CHANNELELEMENT*)(pChannel))->pbFailure,-1);

				/* return copy */
				return pbCopy;
			}
		}
	}

	return NULL;
}


/*========================================================================
	Ch_GetBaseUrl
==========================================================================*/
BYTE* Ch_GetBaseUrl (pDECSTR pDecStr)
{
	BYTE *pbCopy=NULL;
	pELEMENTTYPE pChannel=NULL;

	if (pDecStr!=NULL)
	{
		pChannel=pDecStr->pAppSpec;

		/* Check type */
		if ((pChannel!=NULL)&&(pChannel->iType==Ch_Type_channel))
		{
			if (((CH_CHANNELELEMENT*)(pChannel))->pbBase!=NULL)
			{
				/* Get copy of base url */
				pbCopy=B_CopyByteString (
					((CH_CHANNELELEMENT*)(pChannel))->pbBase,-1);

				/* return copy */
				return pbCopy;
			}
		}
	}

	return NULL;	
}


/*========================================================================
	Ch_GetEventID
==========================================================================*/
WCHAR* Ch_GetEventID (pDECSTR pDecStr)
{
	WCHAR *pwchCopy=NULL;

⌨️ 快捷键说明

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